Merge from emacs--devo--0, emacs--rel--22
[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 ;; For Emacs < 22.2.
31 (eval-and-compile
32   (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
33 (eval-when-compile
34   (require 'cl))
35
36 (defvar tool-bar-mode)
37 (defvar gnus-tmp-header)
38
39 (require 'gnus)
40 (require 'gnus-group)
41 (require 'gnus-spec)
42 (require 'gnus-range)
43 (require 'gnus-int)
44 (require 'gnus-undo)
45 (require 'gnus-util)
46 (require 'gmm-utils)
47 (require 'mm-decode)
48 (require 'nnoo)
49
50 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
51 (autoload 'gnus-cache-write-active "gnus-cache")
52 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
53 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
54 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
55 (autoload 'mm-uu-dissect "mm-uu")
56 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
57   "Deuglify broken Outlook (Express) articles and redisplay."
58   t)
59 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
60 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
61 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
62
63 (defcustom gnus-kill-summary-on-exit t
64   "*If non-nil, kill the summary buffer when you exit from it.
65 If nil, the summary will become a \"*Dead Summary*\" buffer, and
66 it will be killed sometime later."
67   :group 'gnus-summary-exit
68   :type 'boolean)
69
70 (defcustom gnus-summary-next-group-on-exit t
71   "If non-nil, go to the next unread newsgroup on summary exit.
72 See `gnus-group-goto-unread'."
73   :link '(custom-manual "(gnus)Group Maneuvering")
74   :group 'gnus-summary-exit
75   :version "23.1" ;; No Gnus
76   :type 'boolean)
77
78 (defcustom gnus-fetch-old-headers nil
79   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
80 If an unread article in the group refers to an older, already
81 read (or just marked as read) article, the old article will not
82 normally be displayed in the Summary buffer.  If this variable is
83 t, Gnus will attempt to grab the headers to the old articles, and
84 thereby build complete threads.  If it has the value `some', all
85 old headers will be fetched but only enough headers to connect
86 otherwise loose threads will be displayed.  This variable can
87 also be a number.  In that case, no more than that number of old
88 headers will be fetched.  If it has the value `invisible', all
89 old headers will be fetched, but none will be displayed.
90
91 The server has to support NOV for any of this to work.
92
93 This feature can seriously impact performance it ignores all
94 locally cached header entries."
95   :group 'gnus-thread
96   :type '(choice (const :tag "off" nil)
97                  (const :tag "on" t)
98                  (const some)
99                  (const invisible)
100                  number
101                  (sexp :menu-tag "other" t)))
102
103 (defcustom gnus-refer-thread-limit 500
104   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
105 If t, fetch all the available old headers."
106   :group 'gnus-thread
107   :type '(choice number
108                  (sexp :menu-tag "other" t)))
109
110 (defcustom gnus-summary-make-false-root 'adopt
111   "*nil means that Gnus won't gather loose threads.
112 If the root of a thread has expired or been read in a previous
113 session, the information necessary to build a complete thread has been
114 lost.  Instead of having many small sub-threads from this original thread
115 scattered all over the summary buffer, Gnus can gather them.
116
117 If non-nil, Gnus will try to gather all loose sub-threads from an
118 original thread into one large thread.
119
120 If this variable is non-nil, it should be one of `none', `adopt',
121 `dummy' or `empty'.
122
123 If this variable is `none', Gnus will not make a false root, but just
124 present the sub-threads after another.
125 If this variable is `dummy', Gnus will create a dummy root that will
126 have all the sub-threads as children.
127 If this variable is `adopt', Gnus will make one of the \"children\"
128 the parent and mark all the step-children as such.
129 If this variable is `empty', the \"children\" are printed with empty
130 subject fields.  (Or rather, they will be printed with a string
131 given by the `gnus-summary-same-subject' variable.)"
132   :group 'gnus-thread
133   :type '(choice (const :tag "off" nil)
134                  (const none)
135                  (const dummy)
136                  (const adopt)
137                  (const empty)))
138
139 (defcustom gnus-summary-make-false-root-always nil
140   "Always make a false dummy root."
141   :version "22.1"
142   :group 'gnus-thread
143   :type 'boolean)
144
145 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
146   "*A regexp to match subjects to be excluded from loose thread gathering.
147 As loose thread gathering is done on subjects only, that means that
148 there can be many false gatherings performed.  By rooting out certain
149 common subjects, gathering might become saner."
150   :group 'gnus-thread
151   :type 'regexp)
152
153 (defcustom gnus-summary-gather-subject-limit nil
154   "*Maximum length of subject comparisons when gathering loose threads.
155 Use nil to compare full subjects.  Setting this variable to a low
156 number will help gather threads that have been corrupted by
157 newsreaders chopping off subject lines, but it might also mean that
158 unrelated articles that have subject that happen to begin with the
159 same few characters will be incorrectly gathered.
160
161 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
162 comparing subjects."
163   :group 'gnus-thread
164   :type '(choice (const :tag "off" nil)
165                  (const fuzzy)
166                  (sexp :menu-tag "on" t)))
167
168 (defcustom gnus-simplify-subject-functions nil
169   "List of functions taking a string argument that simplify subjects.
170 The functions are applied recursively.
171
172 Useful functions to put in this list include:
173 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
174 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
175   :group 'gnus-thread
176   :type '(repeat function))
177
178 (defcustom gnus-simplify-ignored-prefixes nil
179   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
180   :group 'gnus-thread
181   :type '(choice (const :tag "off" nil)
182                  regexp))
183
184 (defcustom gnus-build-sparse-threads nil
185   "*If non-nil, fill in the gaps in threads.
186 If `some', only fill in the gaps that are needed to tie loose threads
187 together.  If `more', fill in all leaf nodes that Gnus can find.  If
188 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
189   :group 'gnus-thread
190   :type '(choice (const :tag "off" nil)
191                  (const some)
192                  (const more)
193                  (sexp :menu-tag "all" t)))
194
195 (defcustom gnus-summary-thread-gathering-function
196   'gnus-gather-threads-by-subject
197   "*Function used for gathering loose threads.
198 There are two pre-defined functions: `gnus-gather-threads-by-subject',
199 which only takes Subjects into consideration; and
200 `gnus-gather-threads-by-references', which compared the References
201 headers of the articles to find matches."
202   :group 'gnus-thread
203   :type '(radio (function-item gnus-gather-threads-by-subject)
204                 (function-item gnus-gather-threads-by-references)
205                 (function :tag "other")))
206
207 (defcustom gnus-summary-same-subject ""
208   "*String indicating that the current article has the same subject as the previous.
209 This variable will only be used if the value of
210 `gnus-summary-make-false-root' is `empty'."
211   :group 'gnus-summary-format
212   :type 'string)
213
214 (defcustom gnus-summary-goto-unread t
215   "*If t, many commands will go to the next unread article.
216 This applies to marking commands as well as other commands that
217 \"naturally\" select the next article, like, for instance, `SPC' at
218 the end of an article.
219
220 If nil, the marking commands do NOT go to the next unread article
221 \(they go to the next article instead).  If `never', commands that
222 usually go to the next unread article, will go to the next article,
223 whether it is read or not."
224   :group 'gnus-summary-marks
225   :link '(custom-manual "(gnus)Setting Marks")
226   :type '(choice (const :tag "off" nil)
227                  (const never)
228                  (sexp :menu-tag "on" t)))
229
230 (defcustom gnus-summary-default-score 0
231   "*Default article score level.
232 All scores generated by the score files will be added to this score.
233 If this variable is nil, scoring will be disabled."
234   :group 'gnus-score-default
235   :type '(choice (const :tag "disable")
236                  integer))
237
238 (defcustom gnus-summary-default-high-score 0
239   "*Default threshold for a high scored article.
240 An article will be highlighted as high scored if its score is greater
241 than this score."
242   :version "22.1"
243   :group 'gnus-score-default
244   :type 'integer)
245
246 (defcustom gnus-summary-default-low-score 0
247   "*Default threshold for a low scored article.
248 An article will be highlighted as low scored if its score is smaller
249 than this score."
250   :version "22.1"
251   :group 'gnus-score-default
252   :type 'integer)
253
254 (defcustom gnus-summary-zcore-fuzz 0
255   "*Fuzziness factor for the zcore in the summary buffer.
256 Articles with scores closer than this to `gnus-summary-default-score'
257 will not be marked."
258   :group 'gnus-summary-format
259   :type 'integer)
260
261 (defcustom gnus-simplify-subject-fuzzy-regexp nil
262   "*Strings to be removed when doing fuzzy matches.
263 This can either be a regular expression or list of regular expressions
264 that will be removed from subject strings if fuzzy subject
265 simplification is selected."
266   :group 'gnus-thread
267   :type '(repeat regexp))
268
269 (defcustom gnus-show-threads t
270   "*If non-nil, display threads in summary mode."
271   :group 'gnus-thread
272   :type 'boolean)
273
274 (defcustom gnus-thread-hide-subtree nil
275   "*If non-nil, hide all threads initially.
276 This can be a predicate specifier which says which threads to hide.
277 If threads are hidden, you have to run the command
278 `gnus-summary-show-thread' by hand or select an article."
279   :group 'gnus-thread
280   :type '(radio (sexp :format "Non-nil\n"
281                       :match (lambda (widget value)
282                                (not (or (consp value) (functionp value))))
283                       :value t)
284                 (const nil)
285                 (sexp :tag "Predicate specifier")))
286
287 (defcustom gnus-thread-hide-killed t
288   "*If non-nil, hide killed threads automatically."
289   :group 'gnus-thread
290   :type 'boolean)
291
292 (defcustom gnus-thread-ignore-subject t
293   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
294 If nil, articles that have different subjects from their parents will
295 start separate threads."
296   :group 'gnus-thread
297   :type 'boolean)
298
299 (defcustom gnus-thread-operation-ignore-subject t
300   "*If non-nil, subjects will be ignored when doing thread commands.
301 This affects commands like `gnus-summary-kill-thread' and
302 `gnus-summary-lower-thread'.
303
304 If this variable is nil, articles in the same thread with different
305 subjects will not be included in the operation in question.  If this
306 variable is `fuzzy', only articles that have subjects that are fuzzily
307 equal will be included."
308   :group 'gnus-thread
309   :type '(choice (const :tag "off" nil)
310                  (const fuzzy)
311                  (sexp :tag "on" t)))
312
313 (defcustom gnus-thread-indent-level 4
314   "*Number that says how much each sub-thread should be indented."
315   :group 'gnus-thread
316   :type 'integer)
317
318 (defcustom gnus-auto-extend-newsgroup t
319   "*If non-nil, extend newsgroup forward and backward when requested."
320   :group 'gnus-summary-choose
321   :type 'boolean)
322
323 (defcustom gnus-auto-select-first t
324   "If non-nil, select an article on group entry.
325 An article is selected automatically when entering a group
326 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
327 `gnus-summary-catchup-and-goto-next-group'.
328
329 Which article is selected is controlled by the variable
330 `gnus-auto-select-subject'.
331
332 If you want to prevent automatic selection of articles in some
333 newsgroups, set the variable to nil in `gnus-select-group-hook'."
334   ;; Commands include...
335   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
336   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
337   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
338   :group 'gnus-group-select
339   :type '(choice (const :tag "none" nil)
340                  (sexp :menu-tag "first" t)))
341
342 (defcustom gnus-auto-select-subject 'unread
343   "*Says what subject to place under point when entering a group.
344
345 This variable can either be the symbols `first' (place point on the
346 first subject), `unread' (place point on the subject line of the first
347 unread article), `best' (place point on the subject line of the
348 higest-scored article), `unseen' (place point on the subject line of
349 the first unseen article), `unseen-or-unread' (place point on the subject
350 line of the first unseen article or, if all article have been seen, on the
351 subject line of the first unread article), or a function to be called to
352 place point on some subject line."
353   :version "22.1"
354   :group 'gnus-group-select
355   :type '(choice (const best)
356                  (const unread)
357                  (const first)
358                  (const unseen)
359                  (const unseen-or-unread)))
360
361 (defcustom gnus-auto-select-next t
362   "*If non-nil, offer to go to the next group from the end of the previous.
363 If the value is t and the next newsgroup is empty, Gnus will exit
364 summary mode and go back to group mode.  If the value is neither nil
365 nor t, Gnus will select the following unread newsgroup.  In
366 particular, if the value is the symbol `quietly', the next unread
367 newsgroup will be selected without any confirmation, and if it is
368 `almost-quietly', the next group will be selected without any
369 confirmation if you are located on the last article in the group.
370 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
371 will go to the next group without confirmation."
372   :group 'gnus-summary-maneuvering
373   :type '(choice (const :tag "off" nil)
374                  (const quietly)
375                  (const almost-quietly)
376                  (const slightly-quietly)
377                  (sexp :menu-tag "on" t)))
378
379 (defcustom gnus-auto-select-same nil
380   "*If non-nil, select the next article with the same subject.
381 If there are no more articles with the same subject, go to
382 the first unread article."
383   :group 'gnus-summary-maneuvering
384   :type 'boolean)
385
386 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
387   "What article should be selected after exiting an ephemeral group.
388 Valid values include:
389
390 `next'
391   Select the next article.
392 `next-unread'
393   Select the next unread article.
394 `next-noselect'
395   Move the cursor to the next article.  This is the default.
396 `next-unread-noselect'
397   Move the cursor to the next unread article.
398
399 If it has any other value or there is no next (unread) article, the
400 article selected before entering to the ephemeral group will appear."
401   :version "23.1" ;; No Gnus
402   :group 'gnus-summary-maneuvering
403   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
404                  (const next) (const next-unread)
405                  (const next-noselect) (const next-unread-noselect)
406                  (sexp :tag "other" :value nil)))
407
408 (defcustom gnus-auto-goto-ignores 'unfetched
409   "*Says how to handle unfetched articles when maneuvering.
410
411 This variable can either be the symbols nil (maneuver to any
412 article), `undownloaded' (maneuvering while unplugged ignores articles
413 that have not been fetched), `always-undownloaded' (maneuvering always
414 ignores articles that have not been fetched), `unfetched' (maneuvering
415 ignores articles whose headers have not been fetched).
416
417 NOTE: The list of unfetched articles will always be nil when plugged
418 and, when unplugged, a subset of the undownloaded article list."
419   :version "22.1"
420   :group 'gnus-summary-maneuvering
421   :type '(choice (const :tag "None" nil)
422                  (const :tag "Undownloaded when unplugged" undownloaded)
423                  (const :tag "Undownloaded" always-undownloaded)
424                  (const :tag "Unfetched" unfetched)))
425
426 (defcustom gnus-summary-check-current nil
427   "*If non-nil, consider the current article when moving.
428 The \"unread\" movement commands will stay on the same line if the
429 current article is unread."
430   :group 'gnus-summary-maneuvering
431   :type 'boolean)
432
433 (defcustom gnus-auto-center-summary 2
434   "*If non-nil, always center the current summary buffer.
435 In particular, if `vertical' do only vertical recentering.  If non-nil
436 and non-`vertical', do both horizontal and vertical recentering."
437   :group 'gnus-summary-maneuvering
438   :type '(choice (const :tag "none" nil)
439                  (const vertical)
440                  (integer :tag "height")
441                  (sexp :menu-tag "both" t)))
442
443 (defvar gnus-auto-center-group t
444   "*If non-nil, always center the group buffer.")
445
446 (defcustom gnus-show-all-headers nil
447   "*If non-nil, don't hide any headers."
448   :group 'gnus-article-hiding
449   :group 'gnus-article-headers
450   :type 'boolean)
451
452 (defcustom gnus-summary-ignore-duplicates nil
453   "*If non-nil, ignore articles with identical Message-ID headers."
454   :group 'gnus-summary
455   :type 'boolean)
456
457 (defcustom gnus-single-article-buffer t
458   "*If non-nil, display all articles in the same buffer.
459 If nil, each group will get its own article buffer."
460   :group 'gnus-article-various
461   :type 'boolean)
462
463 (defcustom gnus-break-pages t
464   "*If non-nil, do page breaking on articles.
465 The page delimiter is specified by the `gnus-page-delimiter'
466 variable."
467   :group 'gnus-article-various
468   :type 'boolean)
469
470 (defcustom gnus-move-split-methods nil
471   "*Variable used to suggest where articles are to be moved to.
472 It uses the same syntax as the `gnus-split-methods' variable.
473 However, whereas `gnus-split-methods' specifies file names as targets,
474 this variable specifies group names."
475   :group 'gnus-summary-mail
476   :type '(repeat (choice (list :value (fun) function)
477                          (cons :value ("" "") regexp (repeat string))
478                          (sexp :value nil))))
479
480 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
481   "Function used to compute default prefix for article move/copy/etc prompts.
482 The function should take one argument, a group name, and return a
483 string with the suggested prefix."
484   :group 'gnus-summary-mail
485   :type 'function)
486
487 ;; FIXME: Although the custom type is `character' for the following variables,
488 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
489
490 (defcustom gnus-unread-mark ?           ;Whitespace
491   "*Mark used for unread articles."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-ticked-mark ?!
496   "*Mark used for ticked articles."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-dormant-mark ??
501   "*Mark used for dormant articles."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-del-mark ?r
506   "*Mark used for del'd articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-read-mark ?R
511   "*Mark used for read articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-expirable-mark ?E
516   "*Mark used for expirable articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-killed-mark ?K
521   "*Mark used for killed articles."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-spam-mark ?$
526   "*Mark used for spam articles."
527   :version "22.1"
528   :group 'gnus-summary-marks
529   :type 'character)
530
531 (defcustom gnus-souped-mark ?F
532   "*Mark used for souped articles."
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-kill-file-mark ?X
537   "*Mark used for articles killed by kill files."
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-low-score-mark ?Y
542   "*Mark used for articles with a low score."
543   :group 'gnus-summary-marks
544   :type 'character)
545
546 (defcustom gnus-catchup-mark ?C
547   "*Mark used for articles that are caught up."
548   :group 'gnus-summary-marks
549   :type 'character)
550
551 (defcustom gnus-replied-mark ?A
552   "*Mark used for articles that have been replied to."
553   :group 'gnus-summary-marks
554   :type 'character)
555
556 (defcustom gnus-forwarded-mark ?F
557   "*Mark used for articles that have been forwarded."
558   :version "22.1"
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-recent-mark ?N
563   "*Mark used for articles that are recent."
564   :version "22.1"
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-cached-mark ?*
569   "*Mark used for articles that are in the cache."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-saved-mark ?S
574   "*Mark used for articles that have been saved."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-unseen-mark ?.
579   "*Mark used for articles that haven't been seen."
580   :version "22.1"
581   :group 'gnus-summary-marks
582   :type 'character)
583
584 (defcustom gnus-no-mark ?               ;Whitespace
585   "*Mark used for articles that have no other secondary mark."
586   :version "22.1"
587   :group 'gnus-summary-marks
588   :type 'character)
589
590 (defcustom gnus-ancient-mark ?O
591   "*Mark used for ancient articles."
592   :group 'gnus-summary-marks
593   :type 'character)
594
595 (defcustom gnus-sparse-mark ?Q
596   "*Mark used for sparsely reffed articles."
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-canceled-mark ?G
601   "*Mark used for canceled articles."
602   :group 'gnus-summary-marks
603   :type 'character)
604
605 (defcustom gnus-duplicate-mark ?M
606   "*Mark used for duplicate articles."
607   :group 'gnus-summary-marks
608   :type 'character)
609
610 (defcustom gnus-undownloaded-mark ?-
611   "*Mark used for articles that weren't downloaded."
612   :version "22.1"
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-downloaded-mark ?+
617   "*Mark used for articles that were downloaded."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-downloadable-mark ?%
622   "*Mark used for articles that are to be downloaded."
623   :group 'gnus-summary-marks
624   :type 'character)
625
626 (defcustom gnus-unsendable-mark ?=
627   "*Mark used for articles that won't be sent."
628   :group 'gnus-summary-marks
629   :type 'character)
630
631 (defcustom gnus-score-over-mark ?+
632   "*Score mark used for articles with high scores."
633   :group 'gnus-summary-marks
634   :type 'character)
635
636 (defcustom gnus-score-below-mark ?-
637   "*Score mark used for articles with low scores."
638   :group 'gnus-summary-marks
639   :type 'character)
640
641 (defcustom gnus-empty-thread-mark ?     ;Whitespace
642   "*There is no thread under the article."
643   :group 'gnus-summary-marks
644   :type 'character)
645
646 (defcustom gnus-not-empty-thread-mark ?=
647   "*There is a thread under the article."
648   :group 'gnus-summary-marks
649   :type 'character)
650
651 (defcustom gnus-view-pseudo-asynchronously nil
652   "*If non-nil, Gnus will view pseudo-articles asynchronously."
653   :group 'gnus-extract-view
654   :type 'boolean)
655
656 (defcustom gnus-auto-expirable-marks
657   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
658         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
659         gnus-souped-mark gnus-duplicate-mark)
660   "*The list of marks converted into expiration if a group is auto-expirable."
661   :version "21.1"
662   :group 'gnus-summary
663   :type '(repeat character))
664
665 (defcustom gnus-inhibit-user-auto-expire t
666   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
667   :version "21.1"
668   :group 'gnus-summary
669   :type 'boolean)
670
671 (defcustom gnus-view-pseudos nil
672   "*If `automatic', pseudo-articles will be viewed automatically.
673 If `not-confirm', pseudos will be viewed automatically, and the user
674 will not be asked to confirm the command."
675   :group 'gnus-extract-view
676   :type '(choice (const :tag "off" nil)
677                  (const automatic)
678                  (const not-confirm)))
679
680 (defcustom gnus-view-pseudos-separately t
681   "*If non-nil, one pseudo-article will be created for each file to be viewed.
682 If nil, all files that use the same viewing command will be given as a
683 list of parameters to that command."
684   :group 'gnus-extract-view
685   :type 'boolean)
686
687 (defcustom gnus-insert-pseudo-articles t
688   "*If non-nil, insert pseudo-articles when decoding articles."
689   :group 'gnus-extract-view
690   :type 'boolean)
691
692 (defcustom gnus-summary-dummy-line-format
693   "   %(:                             :%) %S\n"
694   "*The format specification for the dummy roots in the summary buffer.
695 It works along the same lines as a normal formatting string,
696 with some simple extensions.
697
698 %S  The subject
699
700 General format specifiers can also be used.
701 See `(gnus)Formatting Variables'."
702   :link '(custom-manual "(gnus)Formatting Variables")
703   :group 'gnus-threading
704   :type 'string)
705
706 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
707   "*The format specification for the summary mode line.
708 It works along the same lines as a normal formatting string,
709 with some simple extensions:
710
711 %G  Group name
712 %p  Unprefixed group name
713 %A  Current article number
714 %z  Current article score
715 %V  Gnus version
716 %U  Number of unread articles in the group
717 %e  Number of unselected articles in the group
718 %Z  A string with unread/unselected article counts
719 %g  Shortish group name
720 %S  Subject of the current article
721 %u  User-defined spec
722 %s  Current score file name
723 %d  Number of dormant articles
724 %r  Number of articles that have been marked as read in this session
725 %E  Number of articles expunged by the score files"
726   :group 'gnus-summary-format
727   :type 'string)
728
729 (defcustom gnus-list-identifiers nil
730   "Regexp that matches list identifiers to be removed from subject.
731 This can also be a list of regexps."
732   :version "21.1"
733   :group 'gnus-summary-format
734   :group 'gnus-article-hiding
735   :type '(choice (const :tag "none" nil)
736                  (regexp :value ".*")
737                  (repeat :value (".*") regexp)))
738
739 (defcustom gnus-summary-mark-below 0
740   "*Mark all articles with a score below this variable as read.
741 This variable is local to each summary buffer and usually set by the
742 score file."
743   :group 'gnus-score-default
744   :type 'integer)
745
746 (defun gnus-widget-reversible-match (widget value)
747   "Ignoring WIDGET, convert VALUE to internal form.
748 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
749   ;; (debug value)
750   (or (symbolp value)
751       (and (listp value)
752            (eq (length value) 2)
753            (eq (nth 0 value) 'not)
754            (symbolp (nth 1 value)))))
755
756 (defun gnus-widget-reversible-to-internal (widget value)
757   "Ignoring WIDGET, convert VALUE to internal form.
758 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
759 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
760   ;; (debug value)
761   (if (atom value)
762       (list value nil)
763     (list (nth 1 value) t)))
764
765 (defun gnus-widget-reversible-to-external (widget value)
766   "Ignoring WIDGET, convert VALUE to external form.
767 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
768 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
769   ;; (debug value)
770   (if (nth 1 value)
771       (list 'not (nth 0 value))
772     (nth 0 value)))
773
774 (define-widget 'gnus-widget-reversible 'group
775   "A `group' that convert values."
776   :match 'gnus-widget-reversible-match
777   :value-to-internal 'gnus-widget-reversible-to-internal
778   :value-to-external 'gnus-widget-reversible-to-external)
779
780 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
781   "*List of functions used for sorting articles in the summary buffer.
782
783 Each function takes two articles and returns non-nil if the first
784 article should be sorted before the other.  If you use more than one
785 function, the primary sort function should be the last.  You should
786 probably always include `gnus-article-sort-by-number' in the list of
787 sorting functions -- preferably first.  Also note that sorting by date
788 is often much slower than sorting by number, and the sorting order is
789 very similar.  (Sorting by date means sorting by the time the message
790 was sent, sorting by number means sorting by arrival time.)
791
792 Each item can also be a list `(not F)' where F is a function;
793 this reverses the sort order.
794
795 Ready-made functions include `gnus-article-sort-by-number',
796 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
797 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
798 and `gnus-article-sort-by-score'.
799
800 When threading is turned on, the variable `gnus-thread-sort-functions'
801 controls how articles are sorted."
802   :group 'gnus-summary-sort
803   :type '(repeat (gnus-widget-reversible
804                   (choice (function-item gnus-article-sort-by-number)
805                           (function-item gnus-article-sort-by-author)
806                           (function-item gnus-article-sort-by-subject)
807                           (function-item gnus-article-sort-by-date)
808                           (function-item gnus-article-sort-by-score)
809                           (function-item gnus-article-sort-by-random)
810                           (function :tag "other"))
811                   (boolean :tag "Reverse order"))))
812
813
814 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
815   "*List of functions used for sorting threads in the summary buffer.
816 By default, threads are sorted by article number.
817
818 Each function takes two threads and returns non-nil if the first
819 thread should be sorted before the other.  If you use more than one
820 function, the primary sort function should be the last.  You should
821 probably always include `gnus-thread-sort-by-number' in the list of
822 sorting functions -- preferably first.  Also note that sorting by date
823 is often much slower than sorting by number, and the sorting order is
824 very similar.  (Sorting by date means sorting by the time the message
825 was sent, sorting by number means sorting by arrival time.)
826
827 Each list item can also be a list `(not F)' where F is a
828 function; this specifies reversed sort order.
829
830 Ready-made functions include `gnus-thread-sort-by-number',
831 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
832 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
833 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
834 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
835 and `gnus-thread-sort-by-total-score' (see
836 `gnus-thread-score-function').
837
838 When threading is turned off, the variable
839 `gnus-article-sort-functions' controls how articles are sorted."
840   :group 'gnus-summary-sort
841   :type '(repeat
842           (gnus-widget-reversible
843            (choice (function-item gnus-thread-sort-by-number)
844                    (function-item gnus-thread-sort-by-author)
845                    (function-item gnus-thread-sort-by-recipient)
846                    (function-item gnus-thread-sort-by-subject)
847                    (function-item gnus-thread-sort-by-date)
848                    (function-item gnus-thread-sort-by-score)
849                    (function-item gnus-thread-sort-by-most-recent-number)
850                    (function-item gnus-thread-sort-by-most-recent-date)
851                    (function-item gnus-thread-sort-by-random)
852                    (function-item gnus-thread-sort-by-total-score)
853                    (function :tag "other"))
854            (boolean :tag "Reverse order"))))
855
856 (defcustom gnus-thread-score-function '+
857   "*Function used for calculating the total score of a thread.
858
859 The function is called with the scores of the article and each
860 subthread and should then return the score of the thread.
861
862 Some functions you can use are `+', `max', or `min'."
863   :group 'gnus-summary-sort
864   :type 'function)
865
866 (defcustom gnus-summary-expunge-below nil
867   "All articles that have a score less than this variable will be expunged.
868 This variable is local to the summary buffers."
869   :group 'gnus-score-default
870   :type '(choice (const :tag "off" nil)
871                  integer))
872
873 (defcustom gnus-thread-expunge-below nil
874   "All threads that have a total score less than this variable will be expunged.
875 See `gnus-thread-score-function' for en explanation of what a
876 \"thread score\" is.
877
878 This variable is local to the summary buffers."
879   :group 'gnus-threading
880   :group 'gnus-score-default
881   :type '(choice (const :tag "off" nil)
882                  integer))
883
884 (defcustom gnus-summary-mode-hook nil
885   "*A hook for Gnus summary mode.
886 This hook is run before any variables are set in the summary buffer."
887   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
888   :group 'gnus-summary-various
889   :type 'hook)
890
891 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
892 (when (featurep 'xemacs)
893   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
894   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
895   (add-hook 'gnus-summary-mode-hook
896             'gnus-xmas-switch-horizontal-scrollbar-off))
897
898 (defcustom gnus-summary-menu-hook nil
899   "*Hook run after the creation of the summary mode menu."
900   :group 'gnus-summary-visual
901   :type 'hook)
902
903 (defcustom gnus-summary-exit-hook nil
904   "*A hook called on exit from the summary buffer.
905 It will be called with point in the group buffer."
906   :group 'gnus-summary-exit
907   :type 'hook)
908
909 (defcustom gnus-summary-prepare-hook nil
910   "*A hook called after the summary buffer has been generated.
911 If you want to modify the summary buffer, you can use this hook."
912   :group 'gnus-summary-various
913   :type 'hook)
914
915 (defcustom gnus-summary-prepared-hook nil
916   "*A hook called as the last thing after the summary buffer has been generated."
917   :group 'gnus-summary-various
918   :type 'hook)
919
920 (defcustom gnus-summary-generate-hook nil
921   "*A hook run just before generating the summary buffer.
922 This hook is commonly used to customize threading variables and the
923 like."
924   :group 'gnus-summary-various
925   :type 'hook)
926
927 (defcustom gnus-select-group-hook nil
928   "*A hook called when a newsgroup is selected.
929
930 If you'd like to simplify subjects like the
931 `gnus-summary-next-same-subject' command does, you can use the
932 following hook:
933
934  (add-hook gnus-select-group-hook
935            (lambda ()
936              (mapcar (lambda (header)
937                        (mail-header-set-subject
938                         header
939                         (gnus-simplify-subject
940                          (mail-header-subject header) 're-only)))
941                      gnus-newsgroup-headers)))"
942   :group 'gnus-group-select
943   :type 'hook)
944
945 (defcustom gnus-select-article-hook nil
946   "*A hook called when an article is selected."
947   :group 'gnus-summary-choose
948   :options '(gnus-agent-fetch-selected-article)
949   :type 'hook)
950
951 (defcustom gnus-visual-mark-article-hook
952   (list 'gnus-highlight-selected-summary)
953   "*Hook run after selecting an article in the summary buffer.
954 It is meant to be used for highlighting the article in some way.  It
955 is not run if `gnus-visual' is nil."
956   :group 'gnus-summary-visual
957   :type 'hook)
958
959 (defcustom gnus-parse-headers-hook nil
960   "*A hook called before parsing the headers."
961   :group 'gnus-various
962   :type 'hook)
963
964 (defcustom gnus-exit-group-hook nil
965   "*A hook called when exiting summary mode.
966 This hook is not called from the non-updating exit commands like `Q'."
967   :group 'gnus-various
968   :type 'hook)
969
970 (defcustom gnus-summary-update-hook
971   (list 'gnus-summary-highlight-line)
972   "*A hook called when a summary line is changed.
973 The hook will not be called if `gnus-visual' is nil.
974
975 The default function `gnus-summary-highlight-line' will
976 highlight the line according to the `gnus-summary-highlight'
977 variable."
978   :group 'gnus-summary-visual
979   :type 'hook)
980
981 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
982   "*A hook called when an article is selected for the first time.
983 The hook is intended to mark an article as read (or unread)
984 automatically when it is selected."
985   :group 'gnus-summary-choose
986   :type 'hook)
987
988 (defcustom gnus-group-no-more-groups-hook nil
989   "*A hook run when returning to group mode having no more (unread) groups."
990   :group 'gnus-group-select
991   :type 'hook)
992
993 (defcustom gnus-ps-print-hook nil
994   "*A hook run before ps-printing something from Gnus."
995   :group 'gnus-summary
996   :type 'hook)
997
998 (defcustom gnus-summary-article-move-hook nil
999   "*A hook called after an article is moved, copied, respooled, or crossposted."
1000   :version "22.1"
1001   :group 'gnus-summary
1002   :type 'hook)
1003
1004 (defcustom gnus-summary-article-delete-hook nil
1005   "*A hook called after an article is deleted."
1006   :version "22.1"
1007   :group 'gnus-summary
1008   :type 'hook)
1009
1010 (defcustom gnus-summary-article-expire-hook nil
1011   "*A hook called after an article is expired."
1012   :version "22.1"
1013   :group 'gnus-summary
1014   :type 'hook)
1015
1016 (defcustom gnus-summary-display-arrow
1017   (and (fboundp 'display-graphic-p)
1018        (display-graphic-p))
1019   "*If non-nil, display an arrow highlighting the current article."
1020   :version "22.1"
1021   :group 'gnus-summary
1022   :type 'boolean)
1023
1024 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1025   "Face used for highlighting the current article in the summary buffer."
1026   :group 'gnus-summary-visual
1027   :type 'face)
1028
1029 (defvar gnus-tmp-downloaded nil)
1030
1031 (defcustom gnus-summary-highlight
1032   '(((eq mark gnus-canceled-mark)
1033      . gnus-summary-cancelled)
1034     ((and uncached (> score default-high))
1035      . gnus-summary-high-undownloaded)
1036     ((and uncached (< score default-low))
1037      . gnus-summary-low-undownloaded)
1038     (uncached
1039      . gnus-summary-normal-undownloaded)
1040     ((and (> score default-high)
1041           (or (eq mark gnus-dormant-mark)
1042               (eq mark gnus-ticked-mark)))
1043      . gnus-summary-high-ticked)
1044     ((and (< score default-low)
1045           (or (eq mark gnus-dormant-mark)
1046               (eq mark gnus-ticked-mark)))
1047      . gnus-summary-low-ticked)
1048     ((or (eq mark gnus-dormant-mark)
1049          (eq mark gnus-ticked-mark))
1050      . gnus-summary-normal-ticked)
1051     ((and (> score default-high) (eq mark gnus-ancient-mark))
1052      . gnus-summary-high-ancient)
1053     ((and (< score default-low) (eq mark gnus-ancient-mark))
1054      . gnus-summary-low-ancient)
1055     ((eq mark gnus-ancient-mark)
1056      . gnus-summary-normal-ancient)
1057     ((and (> score default-high) (eq mark gnus-unread-mark))
1058      . gnus-summary-high-unread)
1059     ((and (< score default-low) (eq mark gnus-unread-mark))
1060      . gnus-summary-low-unread)
1061     ((eq mark gnus-unread-mark)
1062      . gnus-summary-normal-unread)
1063     ((> score default-high)
1064      . gnus-summary-high-read)
1065     ((< score default-low)
1066      . gnus-summary-low-read)
1067     (t
1068      . gnus-summary-normal-read))
1069   "*Controls the highlighting of summary buffer lines.
1070
1071 A list of (FORM . FACE) pairs.  When deciding how a particular
1072 summary line should be displayed, each form is evaluated.  The content
1073 of the face field after the first true form is used.  You can change
1074 how those summary lines are displayed, by editing the face field.
1075
1076 You can use the following variables in the FORM field.
1077
1078 score:        The article's score.
1079 default:      The default article score.
1080 default-high: The default score for high scored articles.
1081 default-low:  The default score for low scored articles.
1082 below:        The score below which articles are automatically marked as read.
1083 mark:         The article's mark.
1084 uncached:     Non-nil if the article is uncached."
1085   :group 'gnus-summary-visual
1086   :type '(repeat (cons (sexp :tag "Form" nil)
1087                        face)))
1088 (put 'gnus-summary-highlight 'risky-local-variable t)
1089
1090 (defcustom gnus-alter-header-function nil
1091   "Function called to allow alteration of article header structures.
1092 The function is called with one parameter, the article header vector,
1093 which it may alter in any way."
1094   :type '(choice (const :tag "None" nil)
1095                  function)
1096   :group 'gnus-summary)
1097
1098 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1099   "Function used to decode a string with encoded words.")
1100
1101 (defvar gnus-decode-encoded-address-function
1102   'mail-decode-encoded-address-string
1103   "Function used to decode addresses with encoded words.")
1104
1105 (defcustom gnus-extra-headers '(To Newsgroups)
1106   "*Extra headers to parse."
1107   :version "21.1"
1108   :group 'gnus-summary
1109   :type '(repeat symbol))
1110
1111 (defcustom gnus-ignored-from-addresses
1112   (and user-mail-address
1113        (not (string= user-mail-address ""))
1114        (regexp-quote user-mail-address))
1115   "*From headers that may be suppressed in favor of To headers.
1116 This can be a regexp or a list of regexps."
1117   :version "21.1"
1118   :group 'gnus-summary
1119   :type '(choice regexp
1120                  (repeat :tag "Regexp List" regexp)))
1121
1122 (defsubst gnus-ignored-from-addresses ()
1123   (gmm-regexp-concat gnus-ignored-from-addresses))
1124
1125 (defcustom gnus-summary-to-prefix "-> "
1126   "*String prefixed to the To field in the summary line when
1127 using `gnus-ignored-from-addresses'."
1128   :version "22.1"
1129   :group 'gnus-summary
1130   :type 'string)
1131
1132 (defcustom gnus-summary-newsgroup-prefix "=> "
1133   "*String prefixed to the Newsgroup field in the summary
1134 line when using `gnus-ignored-from-addresses'."
1135   :version "22.1"
1136   :group 'gnus-summary
1137   :type 'string)
1138
1139 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1140   "List of charsets that should be ignored.
1141 When these charsets are used in the \"charset\" parameter, the
1142 default charset will be used instead."
1143   :version "21.1"
1144   :type '(repeat symbol)
1145   :group 'gnus-charset)
1146
1147 (defcustom gnus-newsgroup-maximum-articles nil
1148   "The maximum number of articles a newsgroup.
1149 If this is a number, old articles in a newsgroup exceeding this number
1150 are silently ignored.  If it is nil, no article is ignored.  Note that
1151 setting this variable to a number might prevent you from reading very
1152 old articles."
1153   :group 'gnus-group-select
1154   :version "22.2"
1155   :type '(choice (const :tag "No limit" nil)
1156                  integer))
1157
1158 (gnus-define-group-parameter
1159  ignored-charsets
1160  :type list
1161  :function-document
1162  "Return the ignored charsets of GROUP."
1163  :variable gnus-group-ignored-charsets-alist
1164  :variable-default
1165  '(("alt\\.chinese\\.text" iso-8859-1))
1166  :variable-document
1167  "Alist of regexps (to match group names) and charsets that should be ignored.
1168 When these charsets are used in the \"charset\" parameter, the
1169 default charset will be used instead."
1170  :variable-group gnus-charset
1171  :variable-type '(repeat (cons (regexp :tag "Group")
1172                                (repeat symbol)))
1173  :parameter-type '(choice :tag "Ignored charsets"
1174                           :value nil
1175                           (repeat (symbol)))
1176  :parameter-document       "\
1177 List of charsets that should be ignored.
1178
1179 When these charsets are used in the \"charset\" parameter, the
1180 default charset will be used instead.")
1181
1182 (defcustom gnus-group-highlight-words-alist nil
1183   "Alist of group regexps and highlight regexps.
1184 This variable uses the same syntax as `gnus-emphasis-alist'."
1185   :version "21.1"
1186   :type '(repeat (cons (regexp :tag "Group")
1187                        (repeat (list (regexp :tag "Highlight regexp")
1188                                      (number :tag "Group for entire word" 0)
1189                                      (number :tag "Group for displayed part" 0)
1190                                      (symbol :tag "Face"
1191                                              gnus-emphasis-highlight-words)))))
1192   :group 'gnus-summary-visual)
1193
1194 (defcustom gnus-summary-show-article-charset-alist
1195   nil
1196   "Alist of number and charset.
1197 The article will be shown with the charset corresponding to the
1198 numbered argument.
1199 For example: ((1 . cn-gb-2312) (2 . big5))."
1200   :version "21.1"
1201   :type '(repeat (cons (number :tag "Argument" 1)
1202                        (symbol :tag "Charset")))
1203   :group 'gnus-charset)
1204
1205 (defcustom gnus-preserve-marks t
1206   "Whether marks are preserved when moving, copying and respooling messages."
1207   :version "21.1"
1208   :type 'boolean
1209   :group 'gnus-summary-marks)
1210
1211 (defcustom gnus-alter-articles-to-read-function nil
1212   "Function to be called to alter the list of articles to be selected."
1213   :type '(choice (const nil) function)
1214   :group 'gnus-summary)
1215
1216 (defcustom gnus-orphan-score nil
1217   "*All orphans get this score added.  Set in the score file."
1218   :group 'gnus-score-default
1219   :type '(choice (const nil)
1220                  integer))
1221
1222 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1223   "*A regexp to match MIME parts when saving multiple parts of a
1224 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1225 This regexp will be used by default when prompting the user for which
1226 type of files to save."
1227   :group 'gnus-summary
1228   :type 'regexp)
1229
1230 (defcustom gnus-read-all-available-headers nil
1231   "Whether Gnus should parse all headers made available to it.
1232 This is mostly relevant for slow back ends where the user may
1233 wish to widen the summary buffer to include all headers
1234 that were fetched.  Say, for nnultimate groups."
1235   :version "22.1"
1236   :group 'gnus-summary
1237   :type '(choice boolean regexp))
1238
1239 (defcustom gnus-summary-muttprint-program "muttprint"
1240   "Command (and optional arguments) used to run Muttprint."
1241   :version "22.1"
1242   :group 'gnus-summary
1243   :type 'string)
1244
1245 (defcustom gnus-article-loose-mime t
1246   "If non-nil, don't require MIME-Version header.
1247 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1248 supply the MIME-Version header or deliberately strip it from the mail.
1249 If non-nil (the default), Gnus will treat some articles as MIME
1250 even if the MIME-Version header is missing."
1251   :version "22.1"
1252   :type 'boolean
1253   :group 'gnus-article-mime)
1254
1255 (defcustom gnus-article-emulate-mime t
1256   "If non-nil, use MIME emulation for uuencode and the like.
1257 This means that Gnus will search message bodies for text that look
1258 like uuencoded bits, yEncoded bits, and so on, and present that using
1259 the normal Gnus MIME machinery."
1260   :version "22.1"
1261   :type 'boolean
1262   :group 'gnus-article-mime)
1263
1264 ;;; Internal variables
1265
1266 (defvar gnus-summary-display-cache nil)
1267 (defvar gnus-article-mime-handles nil)
1268 (defvar gnus-article-decoded-p nil)
1269 (defvar gnus-article-charset nil)
1270 (defvar gnus-article-ignored-charsets nil)
1271 (defvar gnus-scores-exclude-files nil)
1272 (defvar gnus-page-broken nil)
1273
1274 (defvar gnus-original-article nil)
1275 (defvar gnus-article-internal-prepare-hook nil)
1276 (defvar gnus-newsgroup-process-stack nil)
1277
1278 (defvar gnus-thread-indent-array nil)
1279 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1280 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1281   "Function called to sort the articles within a thread after it has been gathered together.")
1282
1283 (defvar gnus-summary-save-parts-type-history nil)
1284 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1285
1286 ;; Avoid highlighting in kill files.
1287 (defvar gnus-summary-inhibit-highlight nil)
1288 (defvar gnus-newsgroup-selected-overlay nil)
1289 (defvar gnus-inhibit-limiting nil)
1290 (defvar gnus-newsgroup-adaptive-score-file nil)
1291 (defvar gnus-current-score-file nil)
1292 (defvar gnus-current-move-group nil)
1293 (defvar gnus-current-copy-group nil)
1294 (defvar gnus-current-crosspost-group nil)
1295 (defvar gnus-newsgroup-display nil)
1296
1297 (defvar gnus-newsgroup-dependencies nil)
1298 (defvar gnus-newsgroup-adaptive nil)
1299 (defvar gnus-summary-display-article-function nil)
1300 (defvar gnus-summary-highlight-line-function nil
1301   "Function called after highlighting a summary line.")
1302
1303 (defvar gnus-summary-line-format-alist
1304   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1305     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1306     (?s gnus-tmp-subject-or-nil ?s)
1307     (?n gnus-tmp-name ?s)
1308     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1309         ?s)
1310     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1311             gnus-tmp-from) ?s)
1312     (?F gnus-tmp-from ?s)
1313     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1314     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1315     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1316     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1317     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1318     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1319     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1320     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1321     (?L gnus-tmp-lines ?s)
1322     (?O gnus-tmp-downloaded ?c)
1323     (?I gnus-tmp-indentation ?s)
1324     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1325     (?R gnus-tmp-replied ?c)
1326     (?\[ gnus-tmp-opening-bracket ?c)
1327     (?\] gnus-tmp-closing-bracket ?c)
1328     (?\> (make-string gnus-tmp-level ? ) ?s)
1329     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1330     (?i gnus-tmp-score ?d)
1331     (?z gnus-tmp-score-char ?c)
1332     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1333     (?U gnus-tmp-unread ?c)
1334     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1335         ?s)
1336     (?t (gnus-summary-number-of-articles-in-thread
1337          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1338         ?d)
1339     (?e (gnus-summary-number-of-articles-in-thread
1340          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1341         ?c)
1342     (?u gnus-tmp-user-defined ?s)
1343     (?P (gnus-pick-line-number) ?d)
1344     (?B gnus-tmp-thread-tree-header-string ?s)
1345     (user-date (gnus-user-date
1346                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1347   "An alist of format specifications that can appear in summary lines.
1348 These are paired with what variables they correspond with, along with
1349 the type of the variable (string, integer, character, etc).")
1350
1351 (defvar gnus-summary-dummy-line-format-alist
1352   `((?S gnus-tmp-subject ?s)
1353     (?N gnus-tmp-number ?d)
1354     (?u gnus-tmp-user-defined ?s)))
1355
1356 (defvar gnus-summary-mode-line-format-alist
1357   `((?G gnus-tmp-group-name ?s)
1358     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1359     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1360     (?A gnus-tmp-article-number ?d)
1361     (?Z gnus-tmp-unread-and-unselected ?s)
1362     (?V gnus-version ?s)
1363     (?U gnus-tmp-unread-and-unticked ?d)
1364     (?S gnus-tmp-subject ?s)
1365     (?e gnus-tmp-unselected ?d)
1366     (?u gnus-tmp-user-defined ?s)
1367     (?d (length gnus-newsgroup-dormant) ?d)
1368     (?t (length gnus-newsgroup-marked) ?d)
1369     (?h (length gnus-newsgroup-spam-marked) ?d)
1370     (?r (length gnus-newsgroup-reads) ?d)
1371     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1372     (?E gnus-newsgroup-expunged-tally ?d)
1373     (?s (gnus-current-score-file-nondirectory) ?s)))
1374
1375 ;; This is here rather than in gnus-art for compilation reasons.
1376 (defvar gnus-article-mode-line-format-alist
1377   (nconc '((?w (gnus-article-wash-status) ?s)
1378            (?m (gnus-article-mime-part-status) ?s))
1379          gnus-summary-mode-line-format-alist))
1380
1381 (defvar gnus-last-search-regexp nil
1382   "Default regexp for article search command.")
1383
1384 (defvar gnus-last-shell-command nil
1385   "Default shell command on article.")
1386
1387 (defvar gnus-newsgroup-agentized nil
1388   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1389 (defvar gnus-newsgroup-begin nil)
1390 (defvar gnus-newsgroup-end nil)
1391 (defvar gnus-newsgroup-last-rmail nil)
1392 (defvar gnus-newsgroup-last-mail nil)
1393 (defvar gnus-newsgroup-last-folder nil)
1394 (defvar gnus-newsgroup-last-file nil)
1395 (defvar gnus-newsgroup-last-directory nil)
1396 (defvar gnus-newsgroup-auto-expire nil)
1397 (defvar gnus-newsgroup-active nil)
1398
1399 (defvar gnus-newsgroup-data nil)
1400 (defvar gnus-newsgroup-data-reverse nil)
1401 (defvar gnus-newsgroup-limit nil)
1402 (defvar gnus-newsgroup-limits nil)
1403 (defvar gnus-summary-use-undownloaded-faces nil)
1404
1405 (defvar gnus-newsgroup-unreads nil
1406   "Sorted list of unread articles in the current newsgroup.")
1407
1408 (defvar gnus-newsgroup-unselected nil
1409   "Sorted list of unselected unread articles in the current newsgroup.")
1410
1411 (defvar gnus-newsgroup-reads nil
1412   "Alist of read articles and article marks in the current newsgroup.")
1413
1414 (defvar gnus-newsgroup-expunged-tally nil)
1415
1416 (defvar gnus-newsgroup-marked nil
1417   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1418
1419 (defvar gnus-newsgroup-spam-marked nil
1420   "List of ranges of articles that have been marked as spam.")
1421
1422 (defvar gnus-newsgroup-killed nil
1423   "List of ranges of articles that have been through the scoring process.")
1424
1425 (defvar gnus-newsgroup-cached nil
1426   "Sorted list of articles that come from the article cache.")
1427
1428 (defvar gnus-newsgroup-saved nil
1429   "List of articles that have been saved.")
1430
1431 (defvar gnus-newsgroup-kill-headers nil)
1432
1433 (defvar gnus-newsgroup-replied nil
1434   "List of articles that have been replied to in the current newsgroup.")
1435
1436 (defvar gnus-newsgroup-forwarded nil
1437   "List of articles that have been forwarded in the current newsgroup.")
1438
1439 (defvar gnus-newsgroup-recent nil
1440   "List of articles that have are recent in the current newsgroup.")
1441
1442 (defvar gnus-newsgroup-expirable nil
1443   "Sorted list of articles in the current newsgroup that can be expired.")
1444
1445 (defvar gnus-newsgroup-processable nil
1446   "List of articles in the current newsgroup that can be processed.")
1447
1448 (defvar gnus-newsgroup-downloadable nil
1449   "Sorted list of articles in the current newsgroup that can be processed.")
1450
1451 (defvar gnus-newsgroup-unfetched nil
1452   "Sorted list of articles in the current newsgroup whose headers have
1453 not been fetched into the agent.
1454
1455 This list will always be a subset of gnus-newsgroup-undownloaded.")
1456
1457 (defvar gnus-newsgroup-undownloaded nil
1458   "List of articles in the current newsgroup that haven't been downloaded.")
1459
1460 (defvar gnus-newsgroup-unsendable nil
1461   "List of articles in the current newsgroup that won't be sent.")
1462
1463 (defvar gnus-newsgroup-bookmarks nil
1464   "List of articles in the current newsgroup that have bookmarks.")
1465
1466 (defvar gnus-newsgroup-dormant nil
1467   "Sorted list of dormant articles in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-unseen nil
1470   "List of unseen articles in the current newsgroup.")
1471
1472 (defvar gnus-newsgroup-seen nil
1473   "Range of seen articles in the current newsgroup.")
1474
1475 (defvar gnus-newsgroup-articles nil
1476   "List of articles in the current newsgroup.")
1477
1478 (defvar gnus-newsgroup-scored nil
1479   "List of scored articles in the current newsgroup.")
1480
1481 (defvar gnus-newsgroup-headers nil
1482   "List of article headers in the current newsgroup.")
1483
1484 (defvar gnus-newsgroup-threads nil)
1485
1486 (defvar gnus-newsgroup-prepared nil
1487   "Whether the current group has been prepared properly.")
1488
1489 (defvar gnus-newsgroup-ancient nil
1490   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1491
1492 (defvar gnus-newsgroup-sparse nil)
1493
1494 (defvar gnus-current-article nil)
1495 (defvar gnus-article-current nil)
1496 (defvar gnus-current-headers nil)
1497 (defvar gnus-have-all-headers nil)
1498 (defvar gnus-last-article nil)
1499 (defvar gnus-newsgroup-history nil)
1500 (defvar gnus-newsgroup-charset nil)
1501 (defvar gnus-newsgroup-ephemeral-charset nil)
1502 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1503
1504 (defvar gnus-article-before-search nil)
1505
1506 (defvar gnus-summary-local-variables
1507   '(gnus-newsgroup-name
1508     gnus-newsgroup-begin gnus-newsgroup-end
1509     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1510     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1511     gnus-newsgroup-last-directory
1512     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1513     gnus-newsgroup-unselected gnus-newsgroup-marked
1514     gnus-newsgroup-spam-marked
1515     gnus-newsgroup-reads gnus-newsgroup-saved
1516     gnus-newsgroup-replied gnus-newsgroup-forwarded
1517     gnus-newsgroup-recent
1518     gnus-newsgroup-expirable
1519     gnus-newsgroup-processable gnus-newsgroup-killed
1520     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1521     gnus-newsgroup-unfetched
1522     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1523     gnus-newsgroup-seen gnus-newsgroup-articles
1524     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1525     gnus-newsgroup-headers gnus-newsgroup-threads
1526     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1527     gnus-current-article gnus-current-headers gnus-have-all-headers
1528     gnus-last-article gnus-article-internal-prepare-hook
1529     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1530     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1531     gnus-thread-expunge-below
1532     gnus-score-alist gnus-current-score-file
1533     (gnus-summary-expunge-below . global)
1534     (gnus-summary-mark-below . global)
1535     (gnus-orphan-score . global)
1536     gnus-newsgroup-active gnus-scores-exclude-files
1537     gnus-newsgroup-history gnus-newsgroup-ancient
1538     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1539     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1540     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1541     (gnus-newsgroup-expunged-tally . 0)
1542     gnus-cache-removable-articles gnus-newsgroup-cached
1543     gnus-newsgroup-data gnus-newsgroup-data-reverse
1544     gnus-newsgroup-limit gnus-newsgroup-limits
1545     gnus-newsgroup-charset gnus-newsgroup-display
1546     gnus-summary-use-undownloaded-faces)
1547   "Variables that are buffer-local to the summary buffers.")
1548
1549 (defvar gnus-newsgroup-variables nil
1550   "A list of variables that have separate values in different newsgroups.
1551 A list of newsgroup (summary buffer) local variables, or cons of
1552 variables and their default expressions to be evalled (when the default
1553 values are not nil), that should be made global while the summary buffer
1554 is active.
1555
1556 Note: The default expressions will be evaluated (using function `eval')
1557 before assignment to the local variable rather than just assigned to it.
1558 If the default expression is the symbol `global', that symbol will not
1559 be evaluated but the global value of the local variable will be used
1560 instead.
1561
1562 These variables can be used to set variables in the group parameters
1563 while still allowing them to affect operations done in other buffers.
1564 For example:
1565
1566 \(setq gnus-newsgroup-variables
1567      '(message-use-followup-to
1568        (gnus-visible-headers .
1569          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1570 ")
1571
1572 (eval-when-compile
1573   ;; Bind features so that require will believe that gnus-sum has
1574   ;; already been loaded (avoids infinite recursion)
1575   (let ((features (cons 'gnus-sum features)))
1576     (require 'gnus-art)))
1577
1578 ;; MIME stuff.
1579
1580 (defvar gnus-decode-encoded-word-methods
1581   '(mail-decode-encoded-word-string)
1582   "List of methods used to decode encoded words.
1583
1584 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1585 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1586 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1587 whose names match REGEXP.
1588
1589 For example:
1590 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1591  mail-decode-encoded-word-string
1592  (\"chinese\" . rfc1843-decode-string))")
1593
1594 (defvar gnus-decode-encoded-word-methods-cache nil)
1595
1596 (defun gnus-multi-decode-encoded-word-string (string)
1597   "Apply the functions from `gnus-encoded-word-methods' that match."
1598   (unless (and gnus-decode-encoded-word-methods-cache
1599                (eq gnus-newsgroup-name
1600                    (car gnus-decode-encoded-word-methods-cache)))
1601     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1602     (dolist (method gnus-decode-encoded-word-methods)
1603       (if (symbolp method)
1604           (nconc gnus-decode-encoded-word-methods-cache (list method))
1605         (if (and gnus-newsgroup-name
1606                  (string-match (car method) gnus-newsgroup-name))
1607             (nconc gnus-decode-encoded-word-methods-cache
1608                    (list (cdr method)))))))
1609   (dolist (method (cdr gnus-decode-encoded-word-methods-cache) string)
1610     (setq string (funcall method string))))
1611
1612 ;; Subject simplification.
1613
1614 (defun gnus-simplify-whitespace (str)
1615   "Remove excessive whitespace from STR."
1616   ;; Multiple spaces.
1617   (while (string-match "[ \t][ \t]+" str)
1618     (setq str (concat (substring str 0 (match-beginning 0))
1619                         " "
1620                         (substring str (match-end 0)))))
1621   ;; Leading spaces.
1622   (when (string-match "^[ \t]+" str)
1623     (setq str (substring str (match-end 0))))
1624   ;; Trailing spaces.
1625   (when (string-match "[ \t]+$" str)
1626     (setq str (substring str 0 (match-beginning 0))))
1627   str)
1628
1629 (defun gnus-simplify-all-whitespace (str)
1630   "Remove all whitespace from STR."
1631   (while (string-match "[ \t\n]+" str)
1632     (setq str (replace-match "" nil nil str)))
1633   str)
1634
1635 (defsubst gnus-simplify-subject-re (subject)
1636   "Remove \"Re:\" from subject lines."
1637   (if (string-match message-subject-re-regexp subject)
1638       (substring subject (match-end 0))
1639     subject))
1640
1641 (defun gnus-simplify-subject (subject &optional re-only)
1642   "Remove `Re:' and words in parentheses.
1643 If RE-ONLY is non-nil, strip leading `Re:'s only."
1644   (let ((case-fold-search t))           ;Ignore case.
1645     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1646     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1647       (setq subject (substring subject (match-end 0))))
1648     ;; Remove uninteresting prefixes.
1649     (when (and (not re-only)
1650                gnus-simplify-ignored-prefixes
1651                (string-match gnus-simplify-ignored-prefixes subject))
1652       (setq subject (substring subject (match-end 0))))
1653     ;; Remove words in parentheses from end.
1654     (unless re-only
1655       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1656         (setq subject (substring subject 0 (match-beginning 0)))))
1657     ;; Return subject string.
1658     subject))
1659
1660 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1661 ;; all whitespace.
1662 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1663   (goto-char (point-min))
1664   (while (re-search-forward regexp nil t)
1665     (replace-match (or newtext ""))))
1666
1667 (defun gnus-simplify-buffer-fuzzy ()
1668   "Simplify string in the buffer fuzzily.
1669 The string in the accessible portion of the current buffer is simplified.
1670 It is assumed to be a single-line subject.
1671 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1672 matter is removed.  Additional things can be deleted by setting
1673 `gnus-simplify-subject-fuzzy-regexp'."
1674   (let ((case-fold-search t)
1675         (modified-tick))
1676     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1677
1678     (while (not (eq modified-tick (buffer-modified-tick)))
1679       (setq modified-tick (buffer-modified-tick))
1680       (cond
1681        ((listp gnus-simplify-subject-fuzzy-regexp)
1682         (mapc 'gnus-simplify-buffer-fuzzy-step
1683               gnus-simplify-subject-fuzzy-regexp))
1684        (gnus-simplify-subject-fuzzy-regexp
1685         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1686       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1687       (gnus-simplify-buffer-fuzzy-step
1688        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1689       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1690
1691     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1692     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1693     (gnus-simplify-buffer-fuzzy-step " $")
1694     (gnus-simplify-buffer-fuzzy-step "^ +")))
1695
1696 (defun gnus-simplify-subject-fuzzy (subject)
1697   "Simplify a subject string fuzzily.
1698 See `gnus-simplify-buffer-fuzzy' for details."
1699   (save-excursion
1700     (gnus-set-work-buffer)
1701     (let ((case-fold-search t))
1702       ;; Remove uninteresting prefixes.
1703       (when (and gnus-simplify-ignored-prefixes
1704                  (string-match gnus-simplify-ignored-prefixes subject))
1705         (setq subject (substring subject (match-end 0))))
1706       (insert subject)
1707       (inline (gnus-simplify-buffer-fuzzy))
1708       (buffer-string))))
1709
1710 (defsubst gnus-simplify-subject-fully (subject)
1711   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1712   (cond
1713    (gnus-simplify-subject-functions
1714     (gnus-map-function gnus-simplify-subject-functions subject))
1715    ((null gnus-summary-gather-subject-limit)
1716     (gnus-simplify-subject-re subject))
1717    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1718     (gnus-simplify-subject-fuzzy subject))
1719    ((numberp gnus-summary-gather-subject-limit)
1720     (truncate-string-to-width (gnus-simplify-subject-re subject)
1721                               gnus-summary-gather-subject-limit))
1722    (t
1723     subject)))
1724
1725 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1726   "Check whether two subjects are equal.
1727 If optional argument SIMPLE-FIRST is t, first argument is already
1728 simplified."
1729   (cond
1730    ((null simple-first)
1731     (equal (gnus-simplify-subject-fully s1)
1732            (gnus-simplify-subject-fully s2)))
1733    (t
1734     (equal s1
1735            (gnus-simplify-subject-fully s2)))))
1736
1737 (defun gnus-summary-bubble-group ()
1738   "Increase the score of the current group.
1739 This is a handy function to add to `gnus-summary-exit-hook' to
1740 increase the score of each group you read."
1741   (gnus-group-add-score gnus-newsgroup-name))
1742
1743 \f
1744 ;;;
1745 ;;; Gnus summary mode
1746 ;;;
1747
1748 (put 'gnus-summary-mode 'mode-class 'special)
1749
1750 (defvar gnus-article-commands-menu)
1751
1752 ;; Non-orthogonal keys
1753
1754 (gnus-define-keys gnus-summary-mode-map
1755   " " gnus-summary-next-page
1756   "\177" gnus-summary-prev-page
1757   [delete] gnus-summary-prev-page
1758   [backspace] gnus-summary-prev-page
1759   "\r" gnus-summary-scroll-up
1760   "\M-\r" gnus-summary-scroll-down
1761   "n" gnus-summary-next-unread-article
1762   "p" gnus-summary-prev-unread-article
1763   "N" gnus-summary-next-article
1764   "P" gnus-summary-prev-article
1765   "\M-\C-n" gnus-summary-next-same-subject
1766   "\M-\C-p" gnus-summary-prev-same-subject
1767   "\M-n" gnus-summary-next-unread-subject
1768   "\M-p" gnus-summary-prev-unread-subject
1769   "." gnus-summary-first-unread-article
1770   "," gnus-summary-best-unread-article
1771   "\M-s" gnus-summary-search-article-forward
1772   "\M-r" gnus-summary-search-article-backward
1773   "\M-S" gnus-summary-repeat-search-article-forward
1774   "\M-R" gnus-summary-repeat-search-article-backward
1775   "<" gnus-summary-beginning-of-article
1776   ">" gnus-summary-end-of-article
1777   "j" gnus-summary-goto-article
1778   "^" gnus-summary-refer-parent-article
1779   "\M-^" gnus-summary-refer-article
1780   "u" gnus-summary-tick-article-forward
1781   "!" gnus-summary-tick-article-forward
1782   "U" gnus-summary-tick-article-backward
1783   "d" gnus-summary-mark-as-read-forward
1784   "D" gnus-summary-mark-as-read-backward
1785   "E" gnus-summary-mark-as-expirable
1786   "\M-u" gnus-summary-clear-mark-forward
1787   "\M-U" gnus-summary-clear-mark-backward
1788   "k" gnus-summary-kill-same-subject-and-select
1789   "\C-k" gnus-summary-kill-same-subject
1790   "\M-\C-k" gnus-summary-kill-thread
1791   "\M-\C-l" gnus-summary-lower-thread
1792   "e" gnus-summary-edit-article
1793   "#" gnus-summary-mark-as-processable
1794   "\M-#" gnus-summary-unmark-as-processable
1795   "\M-\C-t" gnus-summary-toggle-threads
1796   "\M-\C-s" gnus-summary-show-thread
1797   "\M-\C-h" gnus-summary-hide-thread
1798   "\M-\C-f" gnus-summary-next-thread
1799   "\M-\C-b" gnus-summary-prev-thread
1800   [(meta down)] gnus-summary-next-thread
1801   [(meta up)] gnus-summary-prev-thread
1802   "\M-\C-u" gnus-summary-up-thread
1803   "\M-\C-d" gnus-summary-down-thread
1804   "&" gnus-summary-execute-command
1805   "c" gnus-summary-catchup-and-exit
1806   "\C-w" gnus-summary-mark-region-as-read
1807   "\C-t" gnus-summary-toggle-truncation
1808   "?" gnus-summary-mark-as-dormant
1809   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1810   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1811   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1812   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1813   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1814   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1815   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1816   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1817   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1818   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1819   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1820   "=" gnus-summary-expand-window
1821   "\C-x\C-s" gnus-summary-reselect-current-group
1822   "\M-g" gnus-summary-rescan-group
1823   "w" gnus-summary-stop-page-breaking
1824   "\C-c\C-r" gnus-summary-caesar-message
1825   "f" gnus-summary-followup
1826   "F" gnus-summary-followup-with-original
1827   "C" gnus-summary-cancel-article
1828   "r" gnus-summary-reply
1829   "R" gnus-summary-reply-with-original
1830   "\C-c\C-f" gnus-summary-mail-forward
1831   "o" gnus-summary-save-article
1832   "\C-o" gnus-summary-save-article-mail
1833   "|" gnus-summary-pipe-output
1834   "\M-k" gnus-summary-edit-local-kill
1835   "\M-K" gnus-summary-edit-global-kill
1836   ;; "V" gnus-version
1837   "\C-c\C-d" gnus-summary-describe-group
1838   "q" gnus-summary-exit
1839   "Q" gnus-summary-exit-no-update
1840   "\C-c\C-i" gnus-info-find-node
1841   gnus-mouse-2 gnus-mouse-pick-article
1842   [follow-link] mouse-face
1843   "m" gnus-summary-mail-other-window
1844   "a" gnus-summary-post-news
1845   "i" gnus-summary-news-other-window
1846   "x" gnus-summary-limit-to-unread
1847   "s" gnus-summary-isearch-article
1848   "t" gnus-summary-toggle-header
1849   "g" gnus-summary-show-article
1850   "l" gnus-summary-goto-last-article
1851   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1852   "\C-d" gnus-summary-enter-digest-group
1853   "\M-\C-d" gnus-summary-read-document
1854   "\M-\C-e" gnus-summary-edit-parameters
1855   "\M-\C-a" gnus-summary-customize-parameters
1856   "\C-c\C-b" gnus-bug
1857   "*" gnus-cache-enter-article
1858   "\M-*" gnus-cache-remove-article
1859   "\M-&" gnus-summary-universal-argument
1860   "\C-l" gnus-recenter
1861   "I" gnus-summary-increase-score
1862   "L" gnus-summary-lower-score
1863   "\M-i" gnus-symbolic-argument
1864   "h" gnus-summary-select-article-buffer
1865
1866   "b" gnus-article-view-part
1867   "\M-t" gnus-summary-toggle-display-buttonized
1868
1869   "V" gnus-summary-score-map
1870   "X" gnus-uu-extract-map
1871   "S" gnus-summary-send-map)
1872
1873 ;; Sort of orthogonal keymap
1874 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1875   "t" gnus-summary-tick-article-forward
1876   "!" gnus-summary-tick-article-forward
1877   "d" gnus-summary-mark-as-read-forward
1878   "r" gnus-summary-mark-as-read-forward
1879   "c" gnus-summary-clear-mark-forward
1880   " " gnus-summary-clear-mark-forward
1881   "e" gnus-summary-mark-as-expirable
1882   "x" gnus-summary-mark-as-expirable
1883   "?" gnus-summary-mark-as-dormant
1884   "b" gnus-summary-set-bookmark
1885   "B" gnus-summary-remove-bookmark
1886   "#" gnus-summary-mark-as-processable
1887   "\M-#" gnus-summary-unmark-as-processable
1888   "S" gnus-summary-limit-include-expunged
1889   "C" gnus-summary-catchup
1890   "H" gnus-summary-catchup-to-here
1891   "h" gnus-summary-catchup-from-here
1892   "\C-c" gnus-summary-catchup-all
1893   "k" gnus-summary-kill-same-subject-and-select
1894   "K" gnus-summary-kill-same-subject
1895   "P" gnus-uu-mark-map)
1896
1897 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1898   "c" gnus-summary-clear-above
1899   "u" gnus-summary-tick-above
1900   "m" gnus-summary-mark-above
1901   "k" gnus-summary-kill-below)
1902
1903 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1904   "/" gnus-summary-limit-to-subject
1905   "n" gnus-summary-limit-to-articles
1906   "b" gnus-summary-limit-to-bodies
1907   "h" gnus-summary-limit-to-headers
1908   "w" gnus-summary-pop-limit
1909   "s" gnus-summary-limit-to-subject
1910   "a" gnus-summary-limit-to-author
1911   "u" gnus-summary-limit-to-unread
1912   "m" gnus-summary-limit-to-marks
1913   "M" gnus-summary-limit-exclude-marks
1914   "v" gnus-summary-limit-to-score
1915   "*" gnus-summary-limit-include-cached
1916   "D" gnus-summary-limit-include-dormant
1917   "T" gnus-summary-limit-include-thread
1918   "d" gnus-summary-limit-exclude-dormant
1919   "t" gnus-summary-limit-to-age
1920   "." gnus-summary-limit-to-unseen
1921   "x" gnus-summary-limit-to-extra
1922   "p" gnus-summary-limit-to-display-predicate
1923   "E" gnus-summary-limit-include-expunged
1924   "c" gnus-summary-limit-exclude-childless-dormant
1925   "C" gnus-summary-limit-mark-excluded-as-read
1926   "o" gnus-summary-insert-old-articles
1927   "N" gnus-summary-insert-new-articles
1928   "S" gnus-summary-limit-to-singletons
1929   "r" gnus-summary-limit-to-replied
1930   "R" gnus-summary-limit-to-recipient
1931   "A" gnus-summary-limit-to-address)
1932
1933 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1934   "n" gnus-summary-next-unread-article
1935   "p" gnus-summary-prev-unread-article
1936   "N" gnus-summary-next-article
1937   "P" gnus-summary-prev-article
1938   "\C-n" gnus-summary-next-same-subject
1939   "\C-p" gnus-summary-prev-same-subject
1940   "\M-n" gnus-summary-next-unread-subject
1941   "\M-p" gnus-summary-prev-unread-subject
1942   "f" gnus-summary-first-unread-article
1943   "b" gnus-summary-best-unread-article
1944   "j" gnus-summary-goto-article
1945   "g" gnus-summary-goto-subject
1946   "l" gnus-summary-goto-last-article
1947   "o" gnus-summary-pop-article)
1948
1949 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1950   "k" gnus-summary-kill-thread
1951   "E" gnus-summary-expire-thread
1952   "l" gnus-summary-lower-thread
1953   "i" gnus-summary-raise-thread
1954   "T" gnus-summary-toggle-threads
1955   "t" gnus-summary-rethread-current
1956   "^" gnus-summary-reparent-thread
1957   "\M-^" gnus-summary-reparent-children
1958   "s" gnus-summary-show-thread
1959   "S" gnus-summary-show-all-threads
1960   "h" gnus-summary-hide-thread
1961   "H" gnus-summary-hide-all-threads
1962   "n" gnus-summary-next-thread
1963   "p" gnus-summary-prev-thread
1964   "u" gnus-summary-up-thread
1965   "o" gnus-summary-top-thread
1966   "d" gnus-summary-down-thread
1967   "#" gnus-uu-mark-thread
1968   "\M-#" gnus-uu-unmark-thread)
1969
1970 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1971   "g" gnus-summary-prepare
1972   "c" gnus-summary-insert-cached-articles
1973   "d" gnus-summary-insert-dormant-articles
1974   "t" gnus-summary-insert-ticked-articles)
1975
1976 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1977   "c" gnus-summary-catchup-and-exit
1978   "C" gnus-summary-catchup-all-and-exit
1979   "E" gnus-summary-exit-no-update
1980   "Q" gnus-summary-exit
1981   "Z" gnus-summary-exit
1982   "n" gnus-summary-catchup-and-goto-next-group
1983   "p" gnus-summary-catchup-and-goto-prev-group
1984   "R" gnus-summary-reselect-current-group
1985   "G" gnus-summary-rescan-group
1986   "N" gnus-summary-next-group
1987   "s" gnus-summary-save-newsrc
1988   "P" gnus-summary-prev-group)
1989
1990 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1991   " " gnus-summary-next-page
1992   "n" gnus-summary-next-page
1993   "\177" gnus-summary-prev-page
1994   [delete] gnus-summary-prev-page
1995   "p" gnus-summary-prev-page
1996   "\r" gnus-summary-scroll-up
1997   "\M-\r" gnus-summary-scroll-down
1998   "<" gnus-summary-beginning-of-article
1999   ">" gnus-summary-end-of-article
2000   "b" gnus-summary-beginning-of-article
2001   "e" gnus-summary-end-of-article
2002   "^" gnus-summary-refer-parent-article
2003   "r" gnus-summary-refer-parent-article
2004   "D" gnus-summary-enter-digest-group
2005   "R" gnus-summary-refer-references
2006   "T" gnus-summary-refer-thread
2007   "g" gnus-summary-show-article
2008   "s" gnus-summary-isearch-article
2009   "P" gnus-summary-print-article
2010   "S" gnus-sticky-article
2011   "M" gnus-mailing-list-insinuate
2012   "t" gnus-article-babel)
2013
2014 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2015   "b" gnus-article-add-buttons
2016   "B" gnus-article-add-buttons-to-head
2017   "o" gnus-article-treat-overstrike
2018   "e" gnus-article-emphasize
2019   "w" gnus-article-fill-cited-article
2020   "Q" gnus-article-fill-long-lines
2021   "L" gnus-article-toggle-truncate-lines
2022   "C" gnus-article-capitalize-sentences
2023   "c" gnus-article-remove-cr
2024   "q" gnus-article-de-quoted-unreadable
2025   "6" gnus-article-de-base64-unreadable
2026   "Z" gnus-article-decode-HZ
2027   "A" gnus-article-treat-ansi-sequences
2028   "h" gnus-article-wash-html
2029   "u" gnus-article-unsplit-urls
2030   "s" gnus-summary-force-verify-and-decrypt
2031   "f" gnus-article-display-x-face
2032   "l" gnus-summary-stop-page-breaking
2033   "r" gnus-summary-caesar-message
2034   "m" gnus-summary-morse-message
2035   "t" gnus-summary-toggle-header
2036   "g" gnus-treat-smiley
2037   "v" gnus-summary-verbose-headers
2038   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2039   "p" gnus-article-verify-x-pgp-sig
2040   "d" gnus-article-treat-dumbquotes
2041   "i" gnus-summary-idna-message)
2042
2043 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2044   ;; mnemonic: deuglif*Y*
2045   "u" gnus-article-outlook-unwrap-lines
2046   "a" gnus-article-outlook-repair-attribution
2047   "c" gnus-article-outlook-rearrange-citation
2048   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2049
2050 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2051   "a" gnus-article-hide
2052   "h" gnus-article-hide-headers
2053   "b" gnus-article-hide-boring-headers
2054   "s" gnus-article-hide-signature
2055   "c" gnus-article-hide-citation
2056   "C" gnus-article-hide-citation-in-followups
2057   "l" gnus-article-hide-list-identifiers
2058   "B" gnus-article-strip-banner
2059   "P" gnus-article-hide-pem
2060   "\C-c" gnus-article-hide-citation-maybe)
2061
2062 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2063   "a" gnus-article-highlight
2064   "h" gnus-article-highlight-headers
2065   "c" gnus-article-highlight-citation
2066   "s" gnus-article-highlight-signature)
2067
2068 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2069   "f" gnus-article-treat-fold-headers
2070   "u" gnus-article-treat-unfold-headers
2071   "n" gnus-article-treat-fold-newsgroups)
2072
2073 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2074   "x" gnus-article-display-x-face
2075   "d" gnus-article-display-face
2076   "s" gnus-treat-smiley
2077   "D" gnus-article-remove-images
2078   "f" gnus-treat-from-picon
2079   "m" gnus-treat-mail-picon
2080   "n" gnus-treat-newsgroups-picon)
2081
2082 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2083   "w" gnus-article-decode-mime-words
2084   "c" gnus-article-decode-charset
2085   "v" gnus-mime-view-all-parts
2086   "b" gnus-article-view-part)
2087
2088 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2089   "z" gnus-article-date-ut
2090   "u" gnus-article-date-ut
2091   "l" gnus-article-date-local
2092   "p" gnus-article-date-english
2093   "e" gnus-article-date-lapsed
2094   "o" gnus-article-date-original
2095   "i" gnus-article-date-iso8601
2096   "s" gnus-article-date-user)
2097
2098 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2099   "t" gnus-article-remove-trailing-blank-lines
2100   "l" gnus-article-strip-leading-blank-lines
2101   "m" gnus-article-strip-multiple-blank-lines
2102   "a" gnus-article-strip-blank-lines
2103   "A" gnus-article-strip-all-blank-lines
2104   "s" gnus-article-strip-leading-space
2105   "e" gnus-article-strip-trailing-space
2106   "w" gnus-article-remove-leading-whitespace)
2107
2108 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2109   "v" gnus-version
2110   "f" gnus-summary-fetch-faq
2111   "d" gnus-summary-describe-group
2112   "h" gnus-summary-describe-briefly
2113   "i" gnus-info-find-node
2114   "c" gnus-group-fetch-charter
2115   "C" gnus-group-fetch-control)
2116
2117 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2118   "e" gnus-summary-expire-articles
2119   "\M-\C-e" gnus-summary-expire-articles-now
2120   "\177" gnus-summary-delete-article
2121   [delete] gnus-summary-delete-article
2122   [backspace] gnus-summary-delete-article
2123   "m" gnus-summary-move-article
2124   "r" gnus-summary-respool-article
2125   "w" gnus-summary-edit-article
2126   "c" gnus-summary-copy-article
2127   "B" gnus-summary-crosspost-article
2128   "q" gnus-summary-respool-query
2129   "t" gnus-summary-respool-trace
2130   "i" gnus-summary-import-article
2131   "I" gnus-summary-create-article
2132   "p" gnus-summary-article-posted-p)
2133
2134 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2135   "o" gnus-summary-save-article
2136   "m" gnus-summary-save-article-mail
2137   "F" gnus-summary-write-article-file
2138   "r" gnus-summary-save-article-rmail
2139   "f" gnus-summary-save-article-file
2140   "b" gnus-summary-save-article-body-file
2141   "B" gnus-summary-write-article-body-file
2142   "h" gnus-summary-save-article-folder
2143   "v" gnus-summary-save-article-vm
2144   "p" gnus-summary-pipe-output
2145   "P" gnus-summary-muttprint
2146   "s" gnus-soup-add-article)
2147
2148 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2149   "b" gnus-summary-display-buttonized
2150   "m" gnus-summary-repair-multipart
2151   "v" gnus-article-view-part
2152   "o" gnus-article-save-part
2153   "O" gnus-article-save-part-and-strip
2154   "r" gnus-article-replace-part
2155   "d" gnus-article-delete-part
2156   "t" gnus-article-view-part-as-type
2157   "j" gnus-article-jump-to-part
2158   "c" gnus-article-copy-part
2159   "C" gnus-article-view-part-as-charset
2160   "e" gnus-article-view-part-externally
2161   "H" gnus-article-browse-html-article
2162   "E" gnus-article-encrypt-body
2163   "i" gnus-article-inline-part
2164   "|" gnus-article-pipe-part)
2165
2166 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2167   "p" gnus-summary-mark-as-processable
2168   "u" gnus-summary-unmark-as-processable
2169   "U" gnus-summary-unmark-all-processable
2170   "v" gnus-uu-mark-over
2171   "s" gnus-uu-mark-series
2172   "r" gnus-uu-mark-region
2173   "g" gnus-uu-unmark-region
2174   "R" gnus-uu-mark-by-regexp
2175   "G" gnus-uu-unmark-by-regexp
2176   "t" gnus-uu-mark-thread
2177   "T" gnus-uu-unmark-thread
2178   "a" gnus-uu-mark-all
2179   "b" gnus-uu-mark-buffer
2180   "S" gnus-uu-mark-sparse
2181   "k" gnus-summary-kill-process-mark
2182   "y" gnus-summary-yank-process-mark
2183   "w" gnus-summary-save-process-mark
2184   "i" gnus-uu-invert-processable)
2185
2186 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2187   ;;"x" gnus-uu-extract-any
2188   "m" gnus-summary-save-parts
2189   "u" gnus-uu-decode-uu
2190   "U" gnus-uu-decode-uu-and-save
2191   "s" gnus-uu-decode-unshar
2192   "S" gnus-uu-decode-unshar-and-save
2193   "o" gnus-uu-decode-save
2194   "O" gnus-uu-decode-save
2195   "b" gnus-uu-decode-binhex
2196   "B" gnus-uu-decode-binhex
2197   "Y" gnus-uu-decode-yenc
2198   "p" gnus-uu-decode-postscript
2199   "P" gnus-uu-decode-postscript-and-save)
2200
2201 (gnus-define-keys
2202     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2203   "u" gnus-uu-decode-uu-view
2204   "U" gnus-uu-decode-uu-and-save-view
2205   "s" gnus-uu-decode-unshar-view
2206   "S" gnus-uu-decode-unshar-and-save-view
2207   "o" gnus-uu-decode-save-view
2208   "O" gnus-uu-decode-save-view
2209   "b" gnus-uu-decode-binhex-view
2210   "B" gnus-uu-decode-binhex-view
2211   "p" gnus-uu-decode-postscript-view
2212   "P" gnus-uu-decode-postscript-and-save-view)
2213
2214 (defvar gnus-article-post-menu nil)
2215
2216 (defconst gnus-summary-menu-maxlen 20)
2217
2218 (defun gnus-summary-menu-split (menu)
2219   ;; If we have lots of elements, divide them into groups of 20
2220   ;; and make a pane (or submenu) for each one.
2221   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2222       (let ((menu menu) sublists next
2223             (i 1))
2224         (while menu
2225           ;; Pull off the next gnus-summary-menu-maxlen elements
2226           ;; and make them the next element of sublist.
2227           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2228           (if next
2229               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2230                       nil))
2231           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2232                                              (aref (car (last menu)) 0)) menu)
2233                                sublists))
2234           (setq i (1+ i))
2235           (setq menu next))
2236         (nreverse sublists))
2237     ;; Few elements--put them all in one pane.
2238     menu))
2239
2240 (defun gnus-summary-make-menu-bar ()
2241   (gnus-turn-off-edit-menu 'summary)
2242
2243   (unless (boundp 'gnus-summary-misc-menu)
2244
2245     (easy-menu-define
2246       gnus-summary-kill-menu gnus-summary-mode-map ""
2247       (cons
2248        "Score"
2249        (nconc
2250         (list
2251          ["Customize" gnus-score-customize t])
2252         (gnus-make-score-map 'increase)
2253         (gnus-make-score-map 'lower)
2254         '(("Mark"
2255            ["Kill below" gnus-summary-kill-below t]
2256            ["Mark above" gnus-summary-mark-above t]
2257            ["Tick above" gnus-summary-tick-above t]
2258            ["Clear above" gnus-summary-clear-above t])
2259           ["Current score" gnus-summary-current-score t]
2260           ["Set score" gnus-summary-set-score t]
2261           ["Switch current score file..." gnus-score-change-score-file t]
2262           ["Set mark below..." gnus-score-set-mark-below t]
2263           ["Set expunge below..." gnus-score-set-expunge-below t]
2264           ["Edit current score file" gnus-score-edit-current-scores t]
2265           ["Edit score file..." gnus-score-edit-file t]
2266           ["Trace score" gnus-score-find-trace t]
2267           ["Find words" gnus-score-find-favourite-words t]
2268           ["Rescore buffer" gnus-summary-rescore t]
2269           ["Increase score..." gnus-summary-increase-score t]
2270           ["Lower score..." gnus-summary-lower-score t]))))
2271
2272     ;; Define both the Article menu in the summary buffer and the
2273     ;; equivalent Commands menu in the article buffer here for
2274     ;; consistency.
2275     (let ((innards
2276            `(("Hide"
2277               ["All" gnus-article-hide t]
2278               ["Headers" gnus-article-hide-headers t]
2279               ["Signature" gnus-article-hide-signature t]
2280               ["Citation" gnus-article-hide-citation t]
2281               ["List identifiers" gnus-article-hide-list-identifiers t]
2282               ["Banner" gnus-article-strip-banner t]
2283               ["Boring headers" gnus-article-hide-boring-headers t])
2284              ("Highlight"
2285               ["All" gnus-article-highlight t]
2286               ["Headers" gnus-article-highlight-headers t]
2287               ["Signature" gnus-article-highlight-signature t]
2288               ["Citation" gnus-article-highlight-citation t])
2289              ("MIME"
2290               ["Words" gnus-article-decode-mime-words t]
2291               ["Charset" gnus-article-decode-charset t]
2292               ["QP" gnus-article-de-quoted-unreadable t]
2293               ["Base64" gnus-article-de-base64-unreadable t]
2294               ["View MIME buttons" gnus-summary-display-buttonized t]
2295               ["View all" gnus-mime-view-all-parts t]
2296               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2297               ["Encrypt body" gnus-article-encrypt-body
2298                :active (not (gnus-group-read-only-p))
2299                ,@(if (featurep 'xemacs) nil
2300                    '(:help "Encrypt the message body on disk"))]
2301               ["Extract all parts..." gnus-summary-save-parts t]
2302               ("Multipart"
2303                ["Repair multipart" gnus-summary-repair-multipart t]
2304                ["Pipe part..." gnus-article-pipe-part t]
2305                ["Inline part" gnus-article-inline-part t]
2306                ["View part as type..." gnus-article-view-part-as-type t]
2307                ["Encrypt body" gnus-article-encrypt-body
2308                 :active (not (gnus-group-read-only-p))
2309                ,@(if (featurep 'xemacs) nil
2310                    '(:help "Encrypt the message body on disk"))]
2311                ["View part externally" gnus-article-view-part-externally t]
2312                ["View HTML parts in browser" gnus-article-browse-html-article t]
2313                ["View part with charset..." gnus-article-view-part-as-charset t]
2314                ["Copy part" gnus-article-copy-part t]
2315                ["Save part..." gnus-article-save-part t]
2316                ["View part" gnus-article-view-part t]))
2317              ("Date"
2318               ["Local" gnus-article-date-local t]
2319               ["ISO8601" gnus-article-date-iso8601 t]
2320               ["UT" gnus-article-date-ut t]
2321               ["Original" gnus-article-date-original t]
2322               ["Lapsed" gnus-article-date-lapsed t]
2323               ["User-defined" gnus-article-date-user t])
2324              ("Display"
2325               ["Remove images" gnus-article-remove-images t]
2326               ["Toggle smiley" gnus-treat-smiley t]
2327               ["Show X-Face" gnus-article-display-x-face t]
2328               ["Show picons in From" gnus-treat-from-picon t]
2329               ["Show picons in mail headers" gnus-treat-mail-picon t]
2330               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2331               ("View as different encoding"
2332                ,@(gnus-summary-menu-split
2333                   (mapcar
2334                    (lambda (cs)
2335                      ;; Since easymenu under Emacs doesn't allow
2336                      ;; lambda forms for menu commands, we should
2337                      ;; provide intern'ed function symbols.
2338                      (let ((command (intern (format "\
2339 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2340                        (fset command
2341                              `(lambda ()
2342                                 (interactive)
2343                                 (let ((gnus-summary-show-article-charset-alist
2344                                        '((1 . ,cs))))
2345                                   (gnus-summary-show-article 1))))
2346                        `[,(symbol-name cs) ,command t]))
2347                    (sort (if (fboundp 'coding-system-list)
2348                              (coding-system-list)
2349                            (mapcar 'car mm-mime-mule-charset-alist))
2350                          'string<)))))
2351              ("Washing"
2352               ("Remove Blanks"
2353                ["Leading" gnus-article-strip-leading-blank-lines t]
2354                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2355                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2356                ["All of the above" gnus-article-strip-blank-lines t]
2357                ["All" gnus-article-strip-all-blank-lines t]
2358                ["Leading space" gnus-article-strip-leading-space t]
2359                ["Trailing space" gnus-article-strip-trailing-space t]
2360                ["Leading space in headers"
2361                 gnus-article-remove-leading-whitespace t])
2362               ["Overstrike" gnus-article-treat-overstrike t]
2363               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2364               ["Emphasis" gnus-article-emphasize t]
2365               ["Word wrap" gnus-article-fill-cited-article t]
2366               ["Fill long lines" gnus-article-fill-long-lines t]
2367               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2368               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2369               ["Remove CR" gnus-article-remove-cr t]
2370               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2371               ["Base64" gnus-article-de-base64-unreadable t]
2372               ["Rot 13" gnus-summary-caesar-message
2373                ,@(if (featurep 'xemacs) '(t)
2374                    '(:help "\"Caesar rotate\" article by 13"))]
2375               ["De-IDNA" gnus-summary-idna-message t]
2376               ["Morse decode" gnus-summary-morse-message t]
2377               ["Unix pipe..." gnus-summary-pipe-message t]
2378               ["Add buttons" gnus-article-add-buttons t]
2379               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2380               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2381               ["Verbose header" gnus-summary-verbose-headers t]
2382               ["Toggle header" gnus-summary-toggle-header t]
2383               ["Unfold headers" gnus-article-treat-unfold-headers t]
2384               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2385               ["Html" gnus-article-wash-html t]
2386               ["Unsplit URLs" gnus-article-unsplit-urls t]
2387               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2388               ["Decode HZ" gnus-article-decode-HZ t]
2389               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2390               ("(Outlook) Deuglify"
2391                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2392                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2393                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2394                ["Full (Outlook) deuglify"
2395                 gnus-article-outlook-deuglify-article t])
2396               )
2397              ("Output"
2398               ["Save in default format..." gnus-summary-save-article
2399                ,@(if (featurep 'xemacs) '(t)
2400                    '(:help "Save article using default method"))]
2401               ["Save in file..." gnus-summary-save-article-file
2402                ,@(if (featurep 'xemacs) '(t)
2403                    '(:help "Save article in file"))]
2404               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2405               ["Save in MH folder..." gnus-summary-save-article-folder t]
2406               ["Save in VM folder..." gnus-summary-save-article-vm t]
2407               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2408               ["Save body in file..." gnus-summary-save-article-body-file t]
2409               ["Pipe through a filter..." gnus-summary-pipe-output t]
2410               ["Add to SOUP packet" gnus-soup-add-article t]
2411               ["Print with Muttprint..." gnus-summary-muttprint t]
2412               ["Print" gnus-summary-print-article
2413                ,@(if (featurep 'xemacs) '(t)
2414                    '(:help "Generate and print a PostScript image"))])
2415              ("Copy, move,... (Backend)"
2416               ,@(if (featurep 'xemacs) nil
2417                   '(:help "Copying, moving, expiring articles..."))
2418               ["Respool article..." gnus-summary-respool-article t]
2419               ["Move article..." gnus-summary-move-article
2420                (gnus-check-backend-function
2421                 'request-move-article gnus-newsgroup-name)]
2422               ["Copy article..." gnus-summary-copy-article t]
2423               ["Crosspost article..." gnus-summary-crosspost-article
2424                (gnus-check-backend-function
2425                 'request-replace-article gnus-newsgroup-name)]
2426               ["Import file..." gnus-summary-import-article
2427                (gnus-check-backend-function
2428                 'request-accept-article gnus-newsgroup-name)]
2429               ["Create article..." gnus-summary-create-article
2430                (gnus-check-backend-function
2431                 'request-accept-article gnus-newsgroup-name)]
2432               ["Check if posted" gnus-summary-article-posted-p t]
2433               ["Edit article" gnus-summary-edit-article
2434                (not (gnus-group-read-only-p))]
2435               ["Delete article" gnus-summary-delete-article
2436                (gnus-check-backend-function
2437                 'request-expire-articles gnus-newsgroup-name)]
2438               ["Query respool" gnus-summary-respool-query t]
2439               ["Trace respool" gnus-summary-respool-trace t]
2440               ["Delete expirable articles" gnus-summary-expire-articles-now
2441                (gnus-check-backend-function
2442                 'request-expire-articles gnus-newsgroup-name)])
2443              ("Extract"
2444               ["Uudecode" gnus-uu-decode-uu
2445                ,@(if (featurep 'xemacs) '(t)
2446                    '(:help "Decode uuencoded article(s)"))]
2447               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2448               ["Unshar" gnus-uu-decode-unshar t]
2449               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2450               ["Save" gnus-uu-decode-save t]
2451               ["Binhex" gnus-uu-decode-binhex t]
2452               ["Postscript" gnus-uu-decode-postscript t]
2453               ["All MIME parts" gnus-summary-save-parts t])
2454              ("Cache"
2455               ["Enter article" gnus-cache-enter-article t]
2456               ["Remove article" gnus-cache-remove-article t])
2457              ["Translate" gnus-article-babel t]
2458              ["Select article buffer" gnus-summary-select-article-buffer t]
2459              ["Make article buffer sticky" gnus-sticky-article t]
2460              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2461              ["Isearch article..." gnus-summary-isearch-article t]
2462              ["Beginning of the article" gnus-summary-beginning-of-article t]
2463              ["End of the article" gnus-summary-end-of-article t]
2464              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2465              ["Fetch referenced articles" gnus-summary-refer-references t]
2466              ["Fetch current thread" gnus-summary-refer-thread t]
2467              ["Fetch article with id..." gnus-summary-refer-article t]
2468              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2469              ["Redisplay" gnus-summary-show-article t]
2470              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2471       (easy-menu-define
2472         gnus-summary-article-menu gnus-summary-mode-map ""
2473         (cons "Article" innards))
2474
2475       (if (not (keymapp gnus-summary-article-menu))
2476           (easy-menu-define
2477             gnus-article-commands-menu gnus-article-mode-map ""
2478             (cons "Commands" innards))
2479         ;; in Emacs, don't share menu.
2480         (setq gnus-article-commands-menu
2481               (copy-keymap gnus-summary-article-menu))
2482         (define-key gnus-article-mode-map [menu-bar commands]
2483           (cons "Commands" gnus-article-commands-menu))))
2484
2485     (easy-menu-define
2486       gnus-summary-thread-menu gnus-summary-mode-map ""
2487       '("Threads"
2488         ["Find all messages in thread" gnus-summary-refer-thread t]
2489         ["Toggle threading" gnus-summary-toggle-threads t]
2490         ["Hide threads" gnus-summary-hide-all-threads t]
2491         ["Show threads" gnus-summary-show-all-threads t]
2492         ["Hide thread" gnus-summary-hide-thread t]
2493         ["Show thread" gnus-summary-show-thread t]
2494         ["Go to next thread" gnus-summary-next-thread t]
2495         ["Go to previous thread" gnus-summary-prev-thread t]
2496         ["Go down thread" gnus-summary-down-thread t]
2497         ["Go up thread" gnus-summary-up-thread t]
2498         ["Top of thread" gnus-summary-top-thread t]
2499         ["Mark thread as read" gnus-summary-kill-thread t]
2500         ["Mark thread as expired" gnus-summary-expire-thread t]
2501         ["Lower thread score" gnus-summary-lower-thread t]
2502         ["Raise thread score" gnus-summary-raise-thread t]
2503         ["Rethread current" gnus-summary-rethread-current t]))
2504
2505     (easy-menu-define
2506       gnus-summary-post-menu gnus-summary-mode-map ""
2507       `("Post"
2508         ["Send a message (mail or news)" gnus-summary-post-news
2509          ,@(if (featurep 'xemacs) '(t)
2510              '(:help "Compose a new message (mail or news)"))]
2511         ["Followup" gnus-summary-followup
2512          ,@(if (featurep 'xemacs) '(t)
2513              '(:help "Post followup to this article"))]
2514         ["Followup and yank" gnus-summary-followup-with-original
2515          ,@(if (featurep 'xemacs) '(t)
2516              '(:help "Post followup to this article, quoting its contents"))]
2517         ["Supersede article" gnus-summary-supersede-article t]
2518         ["Cancel article" gnus-summary-cancel-article
2519          ,@(if (featurep 'xemacs) '(t)
2520              '(:help "Cancel an article you posted"))]
2521         ["Reply" gnus-summary-reply t]
2522         ["Reply and yank" gnus-summary-reply-with-original t]
2523         ["Wide reply" gnus-summary-wide-reply t]
2524         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2525          ,@(if (featurep 'xemacs) '(t)
2526              '(:help "Mail a reply, quoting this article"))]
2527         ["Very wide reply" gnus-summary-very-wide-reply t]
2528         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2529          ,@(if (featurep 'xemacs) '(t)
2530              '(:help "Mail a very wide reply, quoting this article"))]
2531         ["Mail forward" gnus-summary-mail-forward t]
2532         ["Post forward" gnus-summary-post-forward t]
2533         ["Digest and mail" gnus-uu-digest-mail-forward t]
2534         ["Digest and post" gnus-uu-digest-post-forward t]
2535         ["Resend message" gnus-summary-resend-message t]
2536         ["Resend message edit" gnus-summary-resend-message-edit t]
2537         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2538         ["Send a mail" gnus-summary-mail-other-window t]
2539         ["Create a local message" gnus-summary-news-other-window t]
2540         ["Uuencode and post" gnus-uu-post-news
2541          ,@(if (featurep 'xemacs) '(t)
2542              '(:help "Post a uuencoded article"))]
2543         ["Followup via news" gnus-summary-followup-to-mail t]
2544         ["Followup via news and yank"
2545          gnus-summary-followup-to-mail-with-original t]
2546         ["Strip signature on reply"
2547          (lambda ()
2548            (interactive)
2549            (if (not (memq message-cite-function
2550                           '(message-cite-original-without-signature
2551                             message-cite-original)))
2552                ;; Stupid workaround for XEmacs not honoring :visible.
2553                (message "Can't toggle this value of `message-cite-function'")
2554              (setq message-cite-function
2555                    (if (eq message-cite-function
2556                            'message-cite-original-without-signature)
2557                        'message-cite-original
2558                      'message-cite-original-without-signature))))
2559          ;; XEmacs barfs on :visible.
2560          ,@(if (featurep 'xemacs) nil
2561              '(:visible (memq message-cite-function
2562                               '(message-cite-original-without-signature
2563                                 message-cite-original))))
2564          :style toggle
2565          :selected (eq message-cite-function
2566                        'message-cite-original-without-signature)
2567          ,@(if (featurep 'xemacs) nil
2568              '(:help "Strip signature from cited article when replying."))]
2569         ;;("Draft"
2570         ;;["Send" gnus-summary-send-draft t]
2571         ;;["Send bounced" gnus-resend-bounced-mail t])
2572         ))
2573
2574     (cond
2575      ((not (keymapp gnus-summary-post-menu))
2576       (setq gnus-article-post-menu gnus-summary-post-menu))
2577      ((not gnus-article-post-menu)
2578       ;; Don't share post menu.
2579       (setq gnus-article-post-menu
2580             (copy-keymap gnus-summary-post-menu))))
2581     (define-key gnus-article-mode-map [menu-bar post]
2582       (cons "Post" gnus-article-post-menu))
2583
2584     (easy-menu-define
2585       gnus-summary-misc-menu gnus-summary-mode-map ""
2586       `("Gnus"
2587         ("Mark Read"
2588          ["Mark as read" gnus-summary-mark-as-read-forward t]
2589          ["Mark same subject and select"
2590           gnus-summary-kill-same-subject-and-select t]
2591          ["Mark same subject" gnus-summary-kill-same-subject t]
2592          ["Catchup" gnus-summary-catchup
2593           ,@(if (featurep 'xemacs) '(t)
2594               '(:help "Mark unread articles in this group as read"))]
2595          ["Catchup all" gnus-summary-catchup-all t]
2596          ["Catchup to here" gnus-summary-catchup-to-here t]
2597          ["Catchup from here" gnus-summary-catchup-from-here t]
2598          ["Catchup region" gnus-summary-mark-region-as-read
2599           (gnus-mark-active-p)]
2600          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2601         ("Mark Various"
2602          ["Tick" gnus-summary-tick-article-forward t]
2603          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2604          ["Remove marks" gnus-summary-clear-mark-forward t]
2605          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2606          ["Set bookmark" gnus-summary-set-bookmark t]
2607          ["Remove bookmark" gnus-summary-remove-bookmark t])
2608         ("Registry Mark"
2609          ["Important"     gnus-registry-set-article-Important-mark    t]
2610          ["Not Important" gnus-registry-remove-article-Important-mark t]
2611          ["Work"          gnus-registry-set-article-Work-mark         t]
2612          ["Not Work"      gnus-registry-remove-article-Work-mark      t]
2613          ["Later"         gnus-registry-set-article-Later-mark        t]
2614          ["Not Later"     gnus-registry-remove-article-Later-mark     t]
2615          ["Personal"      gnus-registry-set-article-Personal-mark     t]
2616          ["Not Personal"  gnus-registry-remove-article-Personal-mark  t]
2617          ["To Do"         gnus-registry-set-article-To-Do-mark        t]
2618          ["Not To Do"     gnus-registry-remove-article-To-Do-mark     t])
2619         ("Limit to"
2620          ["Marks..." gnus-summary-limit-to-marks t]
2621          ["Subject..." gnus-summary-limit-to-subject t]
2622          ["Author..." gnus-summary-limit-to-author t]
2623          ["Recipient..." gnus-summary-limit-to-recipient t]
2624          ["Address..." gnus-summary-limit-to-address t]
2625          ["Age..." gnus-summary-limit-to-age t]
2626          ["Extra..." gnus-summary-limit-to-extra t]
2627          ["Score..." gnus-summary-limit-to-score t]
2628          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2629          ["Unread" gnus-summary-limit-to-unread t]
2630          ["Unseen" gnus-summary-limit-to-unseen t]
2631          ["Singletons" gnus-summary-limit-to-singletons t]
2632          ["Replied" gnus-summary-limit-to-replied t]
2633          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2634          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2635          ["Pop limit" gnus-summary-pop-limit t]
2636          ["Show dormant" gnus-summary-limit-include-dormant t]
2637          ["Hide childless dormant"
2638           gnus-summary-limit-exclude-childless-dormant t]
2639          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2640          ["Hide marked" gnus-summary-limit-exclude-marks t]
2641          ["Show expunged" gnus-summary-limit-include-expunged t])
2642         ("Process Mark"
2643          ["Set mark" gnus-summary-mark-as-processable t]
2644          ["Remove mark" gnus-summary-unmark-as-processable t]
2645          ["Remove all marks" gnus-summary-unmark-all-processable t]
2646          ["Invert marks" gnus-uu-invert-processable t]
2647          ["Mark above" gnus-uu-mark-over t]
2648          ["Mark series" gnus-uu-mark-series t]
2649          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2650          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2651          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2652          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2653          ["Mark all" gnus-uu-mark-all t]
2654          ["Mark buffer" gnus-uu-mark-buffer t]
2655          ["Mark sparse" gnus-uu-mark-sparse t]
2656          ["Mark thread" gnus-uu-mark-thread t]
2657          ["Unmark thread" gnus-uu-unmark-thread t]
2658          ("Process Mark Sets"
2659           ["Kill" gnus-summary-kill-process-mark t]
2660           ["Yank" gnus-summary-yank-process-mark
2661            gnus-newsgroup-process-stack]
2662           ["Save" gnus-summary-save-process-mark t]
2663           ["Run command on marked..." gnus-summary-universal-argument t]))
2664         ("Scroll article"
2665          ["Page forward" gnus-summary-next-page
2666           ,@(if (featurep 'xemacs) '(t)
2667               '(:help "Show next page of article"))]
2668          ["Page backward" gnus-summary-prev-page
2669           ,@(if (featurep 'xemacs) '(t)
2670               '(:help "Show previous page of article"))]
2671          ["Line forward" gnus-summary-scroll-up t])
2672         ("Move"
2673          ["Next unread article" gnus-summary-next-unread-article t]
2674          ["Previous unread article" gnus-summary-prev-unread-article t]
2675          ["Next article" gnus-summary-next-article t]
2676          ["Previous article" gnus-summary-prev-article t]
2677          ["Next unread subject" gnus-summary-next-unread-subject t]
2678          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2679          ["Next article same subject" gnus-summary-next-same-subject t]
2680          ["Previous article same subject" gnus-summary-prev-same-subject t]
2681          ["First unread article" gnus-summary-first-unread-article t]
2682          ["Best unread article" gnus-summary-best-unread-article t]
2683          ["Go to subject number..." gnus-summary-goto-subject t]
2684          ["Go to article number..." gnus-summary-goto-article t]
2685          ["Go to the last article" gnus-summary-goto-last-article t]
2686          ["Pop article off history" gnus-summary-pop-article t])
2687         ("Sort"
2688          ["Sort by number" gnus-summary-sort-by-number t]
2689          ["Sort by author" gnus-summary-sort-by-author t]
2690          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2691          ["Sort by subject" gnus-summary-sort-by-subject t]
2692          ["Sort by date" gnus-summary-sort-by-date t]
2693          ["Sort by score" gnus-summary-sort-by-score t]
2694          ["Sort by lines" gnus-summary-sort-by-lines t]
2695          ["Sort by characters" gnus-summary-sort-by-chars t]
2696          ["Randomize" gnus-summary-sort-by-random t]
2697          ["Original sort" gnus-summary-sort-by-original t])
2698         ("Help"
2699          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2700          ["Describe group" gnus-summary-describe-group t]
2701          ["Fetch charter" gnus-group-fetch-charter
2702           ,@(if (featurep 'xemacs) nil
2703               '(:help "Display the charter of the current group"))]
2704          ["Fetch control message" gnus-group-fetch-control
2705           ,@(if (featurep 'xemacs) nil
2706               '(:help "Display the archived control message for the current group"))]
2707          ["Read manual" gnus-info-find-node t])
2708         ("Modes"
2709          ["Pick and read" gnus-pick-mode t]
2710          ["Binary" gnus-binary-mode t])
2711         ("Regeneration"
2712          ["Regenerate" gnus-summary-prepare t]
2713          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2714          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2715          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2716          ["Toggle threading" gnus-summary-toggle-threads t])
2717         ["See old articles" gnus-summary-insert-old-articles t]
2718         ["See new articles" gnus-summary-insert-new-articles t]
2719         ["Filter articles..." gnus-summary-execute-command t]
2720         ["Run command on articles..." gnus-summary-universal-argument t]
2721         ["Search articles forward..." gnus-summary-search-article-forward t]
2722         ["Search articles backward..." gnus-summary-search-article-backward t]
2723         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2724         ["Expand window" gnus-summary-expand-window t]
2725         ["Expire expirable articles" gnus-summary-expire-articles
2726          (gnus-check-backend-function
2727           'request-expire-articles gnus-newsgroup-name)]
2728         ["Edit local kill file" gnus-summary-edit-local-kill t]
2729         ["Edit main kill file" gnus-summary-edit-global-kill t]
2730         ["Edit group parameters" gnus-summary-edit-parameters t]
2731         ["Customize group parameters" gnus-summary-customize-parameters t]
2732         ["Send a bug report" gnus-bug t]
2733         ("Exit"
2734          ["Catchup and exit" gnus-summary-catchup-and-exit
2735           ,@(if (featurep 'xemacs) '(t)
2736               '(:help "Mark unread articles in this group as read, then exit"))]
2737          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2738          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2739          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2740          ["Exit group" gnus-summary-exit
2741           ,@(if (featurep 'xemacs) '(t)
2742               '(:help "Exit current group, return to group selection mode"))]
2743          ["Exit group without updating" gnus-summary-exit-no-update t]
2744          ["Exit and goto next group" gnus-summary-next-group t]
2745          ["Exit and goto prev group" gnus-summary-prev-group t]
2746          ["Reselect group" gnus-summary-reselect-current-group t]
2747          ["Rescan group" gnus-summary-rescan-group t]
2748          ["Update dribble" gnus-summary-save-newsrc t])))
2749
2750     (gnus-run-hooks 'gnus-summary-menu-hook)))
2751
2752 (defvar gnus-summary-tool-bar-map nil)
2753
2754 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2755 ;; affect _new_ message buffers.  We might add a function that walks thru all
2756 ;; summary-mode buffers and force the update.
2757 (defun gnus-summary-tool-bar-update (&optional symbol value)
2758   "Update summary mode toolbar.
2759 Setter function for custom variables."
2760   (setq-default gnus-summary-tool-bar-map nil)
2761   (when symbol
2762     ;; When used as ":set" function:
2763     (set-default symbol value))
2764   (when (gnus-buffer-live-p gnus-summary-buffer)
2765     (with-current-buffer gnus-summary-buffer
2766       (gnus-summary-make-tool-bar))))
2767
2768 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2769                                      'gnus-summary-tool-bar-gnome
2770                                    'gnus-summary-tool-bar-retro)
2771   "Specifies the Gnus summary tool bar.
2772
2773 It can be either a list or a symbol refering to a list.  See
2774 `gmm-tool-bar-from-list' for the format of the list.  The
2775 default key map is `gnus-summary-mode-map'.
2776
2777 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2778 `gnus-summary-tool-bar-retro'."
2779   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2780                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2781                  (repeat :tag "User defined list" gmm-tool-bar-item)
2782                  (symbol))
2783   :version "23.1" ;; No Gnus
2784   :initialize 'custom-initialize-default
2785   :set 'gnus-summary-tool-bar-update
2786   :group 'gnus-summary)
2787
2788 (defcustom gnus-summary-tool-bar-gnome
2789   '((gnus-summary-post-news "mail/compose" nil)
2790     (gnus-summary-insert-new-articles "mail/inbox" nil
2791                                       :visible (or (not gnus-agent)
2792                                                    gnus-plugged))
2793     (gnus-summary-reply-with-original "mail/reply")
2794     (gnus-summary-reply "mail/reply" nil :visible nil)
2795     (gnus-summary-followup-with-original "mail/reply-all")
2796     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2797     (gnus-summary-mail-forward "mail/forward")
2798     (gnus-summary-save-article "mail/save")
2799     (gnus-summary-search-article-forward "search" nil :visible nil)
2800     (gnus-summary-print-article "print")
2801     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2802     ;; Some new commands that may need more suitable icons:
2803     (gnus-summary-save-newsrc "save" nil :visible nil)
2804     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2805     (gnus-summary-prev-article "left-arrow")
2806     (gnus-summary-next-article "right-arrow")
2807     (gnus-summary-next-page "next-page")
2808     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2809     ;;
2810     ;; Maybe some sort-by-... could be added:
2811     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2812     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2813     (gnus-summary-mark-as-expirable
2814      "delete" nil
2815      :visible (gnus-check-backend-function 'request-expire-articles
2816                                            gnus-newsgroup-name))
2817     (gnus-summary-mark-as-spam
2818      "mail/spam" t
2819      :visible (and (fboundp 'spam-group-ham-contents-p)
2820                    (spam-group-ham-contents-p gnus-newsgroup-name))
2821      :help "Mark as spam")
2822     (gnus-summary-mark-as-read-forward
2823      "mail/not-spam" nil
2824      :visible (and (fboundp 'spam-group-spam-contents-p)
2825                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2826     ;;
2827     (gnus-summary-exit "exit")
2828     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2829     (gnus-info-find-node "help"))
2830   "List of functions for the summary tool bar (GNOME style).
2831
2832 See `gmm-tool-bar-from-list' for the format of the list."
2833   :type '(repeat gmm-tool-bar-item)
2834   :version "23.1" ;; No Gnus
2835   :initialize 'custom-initialize-default
2836   :set 'gnus-summary-tool-bar-update
2837   :group 'gnus-summary)
2838
2839 (defcustom gnus-summary-tool-bar-retro
2840   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2841     (gnus-summary-next-unread-article "gnus/next-ur")
2842     (gnus-summary-post-news "gnus/post")
2843     (gnus-summary-followup-with-original "gnus/fuwo")
2844     (gnus-summary-followup "gnus/followup")
2845     (gnus-summary-reply-with-original "gnus/reply-wo")
2846     (gnus-summary-reply "gnus/reply")
2847     (gnus-summary-caesar-message "gnus/rot13")
2848     (gnus-uu-decode-uu "gnus/uu-decode")
2849     (gnus-summary-save-article-file "gnus/save-aif")
2850     (gnus-summary-save-article "gnus/save-art")
2851     (gnus-uu-post-news "gnus/uu-post")
2852     (gnus-summary-catchup "gnus/catchup")
2853     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2854     (gnus-summary-exit "gnus/exit-summ")
2855     ;; Some new command that may need more suitable icons:
2856     (gnus-summary-print-article "gnus/print" nil :visible nil)
2857     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2858     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2859     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2860     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2861     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2862     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2863     ;;
2864     (gnus-info-find-node "gnus/help" nil :visible nil))
2865   "List of functions for the summary tool bar (retro look).
2866
2867 See `gmm-tool-bar-from-list' for the format of the list."
2868   :type '(repeat gmm-tool-bar-item)
2869   :version "23.1" ;; No Gnus
2870   :initialize 'custom-initialize-default
2871   :set 'gnus-summary-tool-bar-update
2872   :group 'gnus-summary)
2873
2874 (defcustom gnus-summary-tool-bar-zap-list t
2875   "List of icon items from the global tool bar.
2876 These items are not displayed in the Gnus summary mode tool bar.
2877
2878 See `gmm-tool-bar-from-list' for the format of the list."
2879   :type 'gmm-tool-bar-zap-list
2880   :version "23.1" ;; No Gnus
2881   :initialize 'custom-initialize-default
2882   :set 'gnus-summary-tool-bar-update
2883   :group 'gnus-summary)
2884
2885 (defvar image-load-path)
2886
2887 (defun gnus-summary-make-tool-bar (&optional force)
2888   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2889 When FORCE, rebuild the tool bar."
2890   (when (and (not (featurep 'xemacs))
2891              (boundp 'tool-bar-mode)
2892              tool-bar-mode
2893              (or (not gnus-summary-tool-bar-map) force))
2894     (let* ((load-path
2895             (gmm-image-load-path-for-library "gnus"
2896                                              "mail/save.xpm"
2897                                              nil t))
2898            (image-load-path (cons (car load-path)
2899                                   (when (boundp 'image-load-path)
2900                                     image-load-path)))
2901            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2902                                         gnus-summary-tool-bar-zap-list
2903                                         'gnus-summary-mode-map)))
2904       (when map
2905         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2906         ;; uses it's value.
2907         (setq gnus-summary-tool-bar-map map))))
2908   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2909
2910 (defun gnus-score-set-default (var value)
2911   "A version of set that updates the GNU Emacs menu-bar."
2912   (set var value)
2913   ;; It is the message that forces the active status to be updated.
2914   (message ""))
2915
2916 (defun gnus-make-score-map (type)
2917   "Make a summary score map of type TYPE."
2918   (if t
2919       nil
2920     (let ((headers '(("author" "from" string)
2921                      ("subject" "subject" string)
2922                      ("article body" "body" string)
2923                      ("article head" "head" string)
2924                      ("xref" "xref" string)
2925                      ("extra header" "extra" string)
2926                      ("lines" "lines" number)
2927                      ("followups to author" "followup" string)))
2928           (types '((number ("less than" <)
2929                            ("greater than" >)
2930                            ("equal" =))
2931                    (string ("substring" s)
2932                            ("exact string" e)
2933                            ("fuzzy string" f)
2934                            ("regexp" r))))
2935           (perms '(("temporary" (current-time-string))
2936                    ("permanent" nil)
2937                    ("immediate" now)))
2938           header)
2939       (list
2940        (apply
2941         'nconc
2942         (list
2943          (if (eq type 'lower)
2944              "Lower score"
2945            "Increase score"))
2946         (let (outh)
2947           (while headers
2948             (setq header (car headers))
2949             (setq outh
2950                   (cons
2951                    (apply
2952                     'nconc
2953                     (list (car header))
2954                     (let ((ts (cdr (assoc (nth 2 header) types)))
2955                           outt)
2956                       (while ts
2957                         (setq outt
2958                               (cons
2959                                (apply
2960                                 'nconc
2961                                 (list (caar ts))
2962                                 (let ((ps perms)
2963                                       outp)
2964                                   (while ps
2965                                     (setq outp
2966                                           (cons
2967                                            (vector
2968                                             (caar ps)
2969                                             (list
2970                                              'gnus-summary-score-entry
2971                                              (nth 1 header)
2972                                              (if (or (string= (nth 1 header)
2973                                                               "head")
2974                                                      (string= (nth 1 header)
2975                                                               "body"))
2976                                                  ""
2977                                                (list 'gnus-summary-header
2978                                                      (nth 1 header)))
2979                                              (list 'quote (nth 1 (car ts)))
2980                                              (list 'gnus-score-delta-default
2981                                                    nil)
2982                                              (nth 1 (car ps))
2983                                              t)
2984                                             t)
2985                                            outp))
2986                                     (setq ps (cdr ps)))
2987                                   (list (nreverse outp))))
2988                                outt))
2989                         (setq ts (cdr ts)))
2990                       (list (nreverse outt))))
2991                    outh))
2992             (setq headers (cdr headers)))
2993           (list (nreverse outh))))))))
2994
2995
2996 (declare-function turn-on-gnus-mailing-list-mode "gnus-ml" ())
2997
2998 \f
2999
3000 (defun gnus-summary-mode (&optional group)
3001   "Major mode for reading articles.
3002
3003 All normal editing commands are switched off.
3004 \\<gnus-summary-mode-map>
3005 Each line in this buffer represents one article.  To read an
3006 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
3007 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
3008 respectively.
3009
3010 You can also post articles and send mail from this buffer.  To
3011 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
3012 of an article, type `\\[gnus-summary-reply]'.
3013
3014 There are approx. one gazillion commands you can execute in this
3015 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
3016
3017 The following commands are available:
3018
3019 \\{gnus-summary-mode-map}"
3020   (interactive)
3021   (kill-all-local-variables)
3022   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
3023     (gnus-summary-make-local-variables))
3024   (gnus-summary-make-local-variables)
3025   (setq gnus-newsgroup-name group)
3026   (when (gnus-visual-p 'summary-menu 'menu)
3027     (gnus-summary-make-menu-bar)
3028     (gnus-summary-make-tool-bar))
3029   (gnus-make-thread-indent-array)
3030   (gnus-simplify-mode-line)
3031   (setq major-mode 'gnus-summary-mode)
3032   (setq mode-name "Summary")
3033   (make-local-variable 'minor-mode-alist)
3034   (use-local-map gnus-summary-mode-map)
3035   (buffer-disable-undo)
3036   (setq buffer-read-only t              ;Disable modification
3037         show-trailing-whitespace nil)
3038   (setq truncate-lines t)
3039   (setq selective-display t)
3040   (setq selective-display-ellipses t)   ;Display `...'
3041   (gnus-summary-set-display-table)
3042   (gnus-set-default-directory)
3043   (make-local-variable 'gnus-summary-line-format)
3044   (make-local-variable 'gnus-summary-line-format-spec)
3045   (make-local-variable 'gnus-summary-dummy-line-format)
3046   (make-local-variable 'gnus-summary-dummy-line-format-spec)
3047   (make-local-variable 'gnus-summary-mark-positions)
3048   (gnus-make-local-hook 'pre-command-hook)
3049   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3050   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3051   (turn-on-gnus-mailing-list-mode)
3052   (mm-enable-multibyte)
3053   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3054   (gnus-update-summary-mark-positions))
3055
3056 (defun gnus-summary-make-local-variables ()
3057   "Make all the local summary buffer variables."
3058   (let (global)
3059     (dolist (local gnus-summary-local-variables)
3060       (if (consp local)
3061           (progn
3062             (if (eq (cdr local) 'global)
3063                 ;; Copy the global value of the variable.
3064                 (setq global (symbol-value (car local)))
3065               ;; Use the value from the list.
3066               (setq global (eval (cdr local))))
3067             (set (make-local-variable (car local)) global))
3068         ;; Simple nil-valued local variable.
3069         (set (make-local-variable local) nil)))))
3070
3071 (defun gnus-summary-clear-local-variables ()
3072   (let ((locals gnus-summary-local-variables))
3073     (while locals
3074       (if (consp (car locals))
3075           (and (symbolp (caar locals))
3076                (set (caar locals) nil))
3077         (and (symbolp (car locals))
3078              (set (car locals) nil)))
3079       (setq locals (cdr locals)))))
3080
3081 ;; Summary data functions.
3082
3083 (defmacro gnus-data-number (data)
3084   `(car ,data))
3085
3086 (defmacro gnus-data-set-number (data number)
3087   `(setcar ,data ,number))
3088
3089 (defmacro gnus-data-mark (data)
3090   `(nth 1 ,data))
3091
3092 (defmacro gnus-data-set-mark (data mark)
3093   `(setcar (nthcdr 1 ,data) ,mark))
3094
3095 (defmacro gnus-data-pos (data)
3096   `(nth 2 ,data))
3097
3098 (defmacro gnus-data-set-pos (data pos)
3099   `(setcar (nthcdr 2 ,data) ,pos))
3100
3101 (defmacro gnus-data-header (data)
3102   `(nth 3 ,data))
3103
3104 (defmacro gnus-data-set-header (data header)
3105   `(setf (nth 3 ,data) ,header))
3106
3107 (defmacro gnus-data-level (data)
3108   `(nth 4 ,data))
3109
3110 (defmacro gnus-data-unread-p (data)
3111   `(= (nth 1 ,data) gnus-unread-mark))
3112
3113 (defmacro gnus-data-read-p (data)
3114   `(/= (nth 1 ,data) gnus-unread-mark))
3115
3116 (defmacro gnus-data-pseudo-p (data)
3117   `(consp (nth 3 ,data)))
3118
3119 (defmacro gnus-data-find (number)
3120   `(assq ,number gnus-newsgroup-data))
3121
3122 (defmacro gnus-data-find-list (number &optional data)
3123   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3124      (memq (assq ,number bdata)
3125            bdata)))
3126
3127 (defmacro gnus-data-make (number mark pos header level)
3128   `(list ,number ,mark ,pos ,header ,level))
3129
3130 (defun gnus-data-enter (after-article number mark pos header level offset)
3131   (let ((data (gnus-data-find-list after-article)))
3132     (unless data
3133       (error "No such article: %d" after-article))
3134     (setcdr data (cons (gnus-data-make number mark pos header level)
3135                        (cdr data)))
3136     (setq gnus-newsgroup-data-reverse nil)
3137     (gnus-data-update-list (cddr data) offset)))
3138
3139 (defun gnus-data-enter-list (after-article list &optional offset)
3140   (when list
3141     (let ((data (and after-article (gnus-data-find-list after-article)))
3142           (ilist list))
3143       (if (not (or data
3144                    after-article))
3145           (let ((odata gnus-newsgroup-data))
3146             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3147             (when offset
3148               (gnus-data-update-list odata offset)))
3149         ;; Find the last element in the list to be spliced into the main
3150         ;; list.
3151         (setq list (last list))
3152         (if (not data)
3153             (progn
3154               (setcdr list gnus-newsgroup-data)
3155               (setq gnus-newsgroup-data ilist)
3156               (when offset
3157                 (gnus-data-update-list (cdr list) offset)))
3158           (setcdr list (cdr data))
3159           (setcdr data ilist)
3160           (when offset
3161             (gnus-data-update-list (cdr list) offset))))
3162       (setq gnus-newsgroup-data-reverse nil))))
3163
3164 (defun gnus-data-remove (article &optional offset)
3165   (let ((data gnus-newsgroup-data))
3166     (if (= (gnus-data-number (car data)) article)
3167         (progn
3168           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3169                 gnus-newsgroup-data-reverse nil)
3170           (when offset
3171             (gnus-data-update-list gnus-newsgroup-data offset)))
3172       (while (cdr data)
3173         (when (= (gnus-data-number (cadr data)) article)
3174           (setcdr data (cddr data))
3175           (when offset
3176             (gnus-data-update-list (cdr data) offset))
3177           (setq data nil
3178                 gnus-newsgroup-data-reverse nil))
3179         (setq data (cdr data))))))
3180
3181 (defmacro gnus-data-list (backward)
3182   `(if ,backward
3183        (or gnus-newsgroup-data-reverse
3184            (setq gnus-newsgroup-data-reverse
3185                  (reverse gnus-newsgroup-data)))
3186      gnus-newsgroup-data))
3187
3188 (defun gnus-data-update-list (data offset)
3189   "Add OFFSET to the POS of all data entries in DATA."
3190   (setq gnus-newsgroup-data-reverse nil)
3191   (while data
3192     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3193     (setq data (cdr data))))
3194
3195 (defun gnus-summary-article-pseudo-p (article)
3196   "Say whether this article is a pseudo article or not."
3197   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3198
3199 (defmacro gnus-summary-article-sparse-p (article)
3200   "Say whether this article is a sparse article or not."
3201   `(memq ,article gnus-newsgroup-sparse))
3202
3203 (defmacro gnus-summary-article-ancient-p (article)
3204   "Say whether this article is a sparse article or not."
3205   `(memq ,article gnus-newsgroup-ancient))
3206
3207 (defun gnus-article-parent-p (number)
3208   "Say whether this article is a parent or not."
3209   (let ((data (gnus-data-find-list number)))
3210     (and (cdr data)              ; There has to be an article after...
3211          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3212             (gnus-data-level (nth 1 data))))))
3213
3214 (defun gnus-article-children (number)
3215   "Return a list of all children to NUMBER."
3216   (let* ((data (gnus-data-find-list number))
3217          (level (gnus-data-level (car data)))
3218          children)
3219     (setq data (cdr data))
3220     (while (and data
3221                 (= (gnus-data-level (car data)) (1+ level)))
3222       (push (gnus-data-number (car data)) children)
3223       (setq data (cdr data)))
3224     children))
3225
3226 (defmacro gnus-summary-skip-intangible ()
3227   "If the current article is intangible, then jump to a different article."
3228   '(let ((to (get-text-property (point) 'gnus-intangible)))
3229      (and to (gnus-summary-goto-subject to))))
3230
3231 (defmacro gnus-summary-article-intangible-p ()
3232   "Say whether this article is intangible or not."
3233   '(get-text-property (point) 'gnus-intangible))
3234
3235 (defun gnus-article-read-p (article)
3236   "Say whether ARTICLE is read or not."
3237   (not (or (memq article gnus-newsgroup-marked)
3238            (memq article gnus-newsgroup-spam-marked)
3239            (memq article gnus-newsgroup-unreads)
3240            (memq article gnus-newsgroup-unselected)
3241            (memq article gnus-newsgroup-dormant))))
3242
3243 ;; Some summary mode macros.
3244
3245 (defmacro gnus-summary-article-number ()
3246   "The article number of the article on the current line.
3247 If there isn't an article number here, then we return the current
3248 article number."
3249   '(progn
3250      (gnus-summary-skip-intangible)
3251      (or (get-text-property (point) 'gnus-number)
3252          (gnus-summary-last-subject))))
3253
3254 (defmacro gnus-summary-article-header (&optional number)
3255   "Return the header of article NUMBER."
3256   `(gnus-data-header (gnus-data-find
3257                       ,(or number '(gnus-summary-article-number)))))
3258
3259 (defmacro gnus-summary-thread-level (&optional number)
3260   "Return the level of thread that starts with article NUMBER."
3261   `(if (and (eq gnus-summary-make-false-root 'dummy)
3262             (get-text-property (point) 'gnus-intangible))
3263        0
3264      (gnus-data-level (gnus-data-find
3265                        ,(or number '(gnus-summary-article-number))))))
3266
3267 (defmacro gnus-summary-article-mark (&optional number)
3268   "Return the mark of article NUMBER."
3269   `(gnus-data-mark (gnus-data-find
3270                     ,(or number '(gnus-summary-article-number)))))
3271
3272 (defmacro gnus-summary-article-pos (&optional number)
3273   "Return the position of the line of article NUMBER."
3274   `(gnus-data-pos (gnus-data-find
3275                    ,(or number '(gnus-summary-article-number)))))
3276
3277 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3278 (defmacro gnus-summary-article-subject (&optional number)
3279   "Return current subject string or nil if nothing."
3280   `(let ((headers
3281           ,(if number
3282                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3283              '(gnus-data-header (assq (gnus-summary-article-number)
3284                                       gnus-newsgroup-data)))))
3285      (and headers
3286           (vectorp headers)
3287           (mail-header-subject headers))))
3288
3289 (defmacro gnus-summary-article-score (&optional number)
3290   "Return current article score."
3291   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3292                   gnus-newsgroup-scored))
3293        gnus-summary-default-score 0))
3294
3295 (defun gnus-summary-article-children (&optional number)
3296   "Return a list of article numbers that are children of article NUMBER."
3297   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3298          (level (gnus-data-level (car data)))
3299          l children)
3300     (while (and (setq data (cdr data))
3301                 (> (setq l (gnus-data-level (car data))) level))
3302       (and (= (1+ level) l)
3303            (push (gnus-data-number (car data))
3304                  children)))
3305     (nreverse children)))
3306
3307 (defun gnus-summary-article-parent (&optional number)
3308   "Return the article number of the parent of article NUMBER."
3309   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3310                                     (gnus-data-list t)))
3311          (level (gnus-data-level (car data))))
3312     (if (zerop level)
3313         ()                              ; This is a root.
3314       ;; We search until we find an article with a level less than
3315       ;; this one.  That function has to be the parent.
3316       (while (and (setq data (cdr data))
3317                   (not (< (gnus-data-level (car data)) level))))
3318       (and data (gnus-data-number (car data))))))
3319
3320 (defun gnus-unread-mark-p (mark)
3321   "Say whether MARK is the unread mark."
3322   (= mark gnus-unread-mark))
3323
3324 (defun gnus-read-mark-p (mark)
3325   "Say whether MARK is one of the marks that mark as read.
3326 This is all marks except unread, ticked, dormant, and expirable."
3327   (not (or (= mark gnus-unread-mark)
3328            (= mark gnus-ticked-mark)
3329            (= mark gnus-spam-mark)
3330            (= mark gnus-dormant-mark)
3331            (= mark gnus-expirable-mark))))
3332
3333 (defmacro gnus-article-mark (number)
3334   "Return the MARK of article NUMBER.
3335 This macro should only be used when computing the mark the \"first\"
3336 time; i.e., when generating the summary lines.  After that,
3337 `gnus-summary-article-mark' should be used to examine the
3338 marks of articles."
3339   `(cond
3340     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3341     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3342     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3343     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3344     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3345     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3346     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3347     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3348            gnus-ancient-mark))))
3349
3350 ;; Saving hidden threads.
3351
3352 (defmacro gnus-save-hidden-threads (&rest forms)
3353   "Save hidden threads, eval FORMS, and restore the hidden threads."
3354   (let ((config (make-symbol "config")))
3355     `(let ((,config (gnus-hidden-threads-configuration)))
3356        (unwind-protect
3357            (save-excursion
3358              ,@forms)
3359          (gnus-restore-hidden-threads-configuration ,config)))))
3360 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3361 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3362
3363 (defun gnus-data-compute-positions ()
3364   "Compute the positions of all articles."
3365   (setq gnus-newsgroup-data-reverse nil)
3366   (let ((data gnus-newsgroup-data))
3367     (save-excursion
3368       (gnus-save-hidden-threads
3369         (gnus-summary-show-all-threads)
3370         (goto-char (point-min))
3371         (while data
3372           (while (get-text-property (point) 'gnus-intangible)
3373             (forward-line 1))
3374           (gnus-data-set-pos (car data) (+ (point) 3))
3375           (setq data (cdr data))
3376           (forward-line 1))))))
3377
3378 (defun gnus-hidden-threads-configuration ()
3379   "Return the current hidden threads configuration."
3380   (save-excursion
3381     (let (config)
3382       (goto-char (point-min))
3383       (while (search-forward "\r" nil t)
3384         (push (1- (point)) config))
3385       config)))
3386
3387 (defun gnus-restore-hidden-threads-configuration (config)
3388   "Restore hidden threads configuration from CONFIG."
3389   (save-excursion
3390     (let (point (inhibit-read-only t))
3391       (while (setq point (pop config))
3392         (when (and (< point (point-max))
3393                    (goto-char point)
3394                    (eq (char-after) ?\n))
3395           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3396
3397 ;; Various summary mode internalish functions.
3398
3399 (defun gnus-mouse-pick-article (e)
3400   (interactive "e")
3401   (mouse-set-point e)
3402   (gnus-summary-next-page nil t))
3403
3404 (defun gnus-summary-set-display-table ()
3405   "Change the display table.
3406 Odd characters have a tendency to mess
3407 up nicely formatted displays - we make all possible glyphs
3408 display only a single character."
3409
3410   ;; We start from the standard display table, if any.
3411   (let ((table (or (copy-sequence standard-display-table)
3412                    (make-display-table)))
3413         (i 32))
3414     ;; Nix out all the control chars...
3415     (while (>= (setq i (1- i)) 0)
3416       (aset table i [??]))
3417    ;; ... but not newline and cr, of course.  (cr is necessary for the
3418     ;; selective display).
3419     (aset table ?\n nil)
3420     (aset table ?\r nil)
3421     ;; We keep TAB as well.
3422     (aset table ?\t nil)
3423     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3424     ;; Emacs 23 (unicode), that are not set already.
3425     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3426                  160
3427                256)))
3428       (while (>= (setq i (1- i)) 127)
3429         ;; Only modify if the entry is nil.
3430         (unless (aref table i)
3431           (aset table i [??]))))
3432     (setq buffer-display-table table)))
3433
3434 (defun gnus-summary-set-article-display-arrow (pos)
3435   "Update the overlay arrow to point to line at position POS."
3436   (when (and gnus-summary-display-arrow
3437              (boundp 'overlay-arrow-position)
3438              (boundp 'overlay-arrow-string))
3439     (save-excursion
3440       (goto-char pos)
3441       (beginning-of-line)
3442       (unless overlay-arrow-position
3443         (setq overlay-arrow-position (make-marker)))
3444       (setq overlay-arrow-string "=>"
3445             overlay-arrow-position (set-marker overlay-arrow-position
3446                                                (point)
3447                                                (current-buffer))))))
3448
3449 (defun gnus-summary-setup-buffer (group)
3450   "Initialize summary buffer."
3451   (let ((buffer (gnus-summary-buffer-name group))
3452         (dead-name (concat "*Dead Summary "
3453                            (gnus-group-decoded-name group) "*")))
3454     ;; If a dead summary buffer exists, we kill it.
3455     (when (gnus-buffer-live-p dead-name)
3456       (gnus-kill-buffer dead-name))
3457     (if (get-buffer buffer)
3458         (progn
3459           (set-buffer buffer)
3460           (setq gnus-summary-buffer (current-buffer))
3461           (not gnus-newsgroup-prepared))
3462       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3463       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3464       (gnus-summary-mode group)
3465       (when gnus-carpal
3466         (gnus-carpal-setup-buffer 'summary))
3467       (when (gnus-group-quit-config group)
3468         (set (make-local-variable 'gnus-single-article-buffer) nil))
3469       (make-local-variable 'gnus-article-buffer)
3470       (make-local-variable 'gnus-article-current)
3471       (make-local-variable 'gnus-original-article-buffer)
3472       (setq gnus-newsgroup-name group)
3473       ;; Set any local variables in the group parameters.
3474       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3475       t)))
3476
3477 (defun gnus-set-global-variables ()
3478   "Set the global equivalents of the buffer-local variables.
3479 They are set to the latest values they had.  These reflect the summary
3480 buffer that was in action when the last article was fetched."
3481   (when (eq major-mode 'gnus-summary-mode)
3482     (setq gnus-summary-buffer (current-buffer))
3483     (let ((name gnus-newsgroup-name)
3484           (marked gnus-newsgroup-marked)
3485           (spam gnus-newsgroup-spam-marked)
3486           (unread gnus-newsgroup-unreads)
3487           (headers gnus-current-headers)
3488           (data gnus-newsgroup-data)
3489           (summary gnus-summary-buffer)
3490           (article-buffer gnus-article-buffer)
3491           (original gnus-original-article-buffer)
3492           (gac gnus-article-current)
3493           (reffed gnus-reffed-article-number)
3494           (score-file gnus-current-score-file)
3495           (default-charset gnus-newsgroup-charset)
3496           vlist)
3497       (let ((locals gnus-newsgroup-variables))
3498         (while locals
3499           (if (consp (car locals))
3500               (push (eval (caar locals)) vlist)
3501             (push (eval (car locals)) vlist))
3502           (setq locals (cdr locals)))
3503         (setq vlist (nreverse vlist)))
3504       (with-current-buffer gnus-group-buffer
3505         (setq gnus-newsgroup-name name
3506               gnus-newsgroup-marked marked
3507               gnus-newsgroup-spam-marked spam
3508               gnus-newsgroup-unreads unread
3509               gnus-current-headers headers
3510               gnus-newsgroup-data data
3511               gnus-article-current gac
3512               gnus-summary-buffer summary
3513               gnus-article-buffer article-buffer
3514               gnus-original-article-buffer original
3515               gnus-reffed-article-number reffed
3516               gnus-current-score-file score-file
3517               gnus-newsgroup-charset default-charset)
3518         (let ((locals gnus-newsgroup-variables))
3519           (while locals
3520             (if (consp (car locals))
3521                 (set (caar locals) (pop vlist))
3522               (set (car locals) (pop vlist)))
3523             (setq locals (cdr locals))))
3524         ;; The article buffer also has local variables.
3525         (when (gnus-buffer-live-p gnus-article-buffer)
3526           (set-buffer gnus-article-buffer)
3527           (setq gnus-summary-buffer summary))))))
3528
3529 (defun gnus-summary-article-unread-p (article)
3530   "Say whether ARTICLE is unread or not."
3531   (memq article gnus-newsgroup-unreads))
3532
3533 (defun gnus-summary-first-article-p (&optional article)
3534   "Return whether ARTICLE is the first article in the buffer."
3535   (if (not (setq article (or article (gnus-summary-article-number))))
3536       nil
3537     (eq article (caar gnus-newsgroup-data))))
3538
3539 (defun gnus-summary-last-article-p (&optional article)
3540   "Return whether ARTICLE is the last article in the buffer."
3541   (if (not (setq article (or article (gnus-summary-article-number))))
3542       ;; All non-existent numbers are the last article.  :-)
3543       t
3544     (not (cdr (gnus-data-find-list article)))))
3545
3546 (defun gnus-make-thread-indent-array (&optional n)
3547   (when (or n
3548             (progn (setq n 200) nil)
3549             (null gnus-thread-indent-array)
3550             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3551     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3552           gnus-thread-indent-array-level gnus-thread-indent-level)
3553     (while (>= n 0)
3554       (aset gnus-thread-indent-array n
3555             (make-string (* n gnus-thread-indent-level) ? ))
3556       (setq n (1- n)))))
3557
3558 (defun gnus-update-summary-mark-positions ()
3559   "Compute where the summary marks are to go."
3560   (save-excursion
3561     (when (gnus-buffer-exists-p gnus-summary-buffer)
3562       (set-buffer gnus-summary-buffer))
3563     (let ((spec gnus-summary-line-format-spec)
3564           pos)
3565       (save-excursion
3566         (gnus-set-work-buffer)
3567         (let ((gnus-tmp-unread ?Z)
3568               (gnus-replied-mark ?Z)
3569               (gnus-score-below-mark ?Z)
3570               (gnus-score-over-mark ?Z)
3571               (gnus-undownloaded-mark ?Z)
3572               (gnus-summary-line-format-spec spec)
3573               (gnus-newsgroup-downloadable '(0))
3574               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3575               case-fold-search ignores)
3576           ;; Here, all marks are bound to Z.
3577           (gnus-summary-insert-line header
3578                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3579           (goto-char (point-min))
3580           ;; Memorize the positions of the same characters as dummy marks.
3581           (while (re-search-forward "[A-D]" nil t)
3582             (push (point) ignores))
3583           (erase-buffer)
3584           ;; We use A-D as dummy marks in order to know column positions
3585           ;; where marks should be inserted.
3586           (setq gnus-tmp-unread ?A
3587                 gnus-replied-mark ?B
3588                 gnus-score-below-mark ?C
3589                 gnus-score-over-mark ?C
3590                 gnus-undownloaded-mark ?D)
3591           (gnus-summary-insert-line header
3592                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3593           ;; Ignore characters which aren't dummy marks.
3594           (dolist (p ignores)
3595             (delete-region (goto-char (1- p)) p)
3596             (insert ?Z))
3597           (goto-char (point-min))
3598           (setq pos (list (cons 'unread
3599                                 (and (search-forward "A" nil t)
3600                                      (- (point) (point-min) 1)))))
3601           (goto-char (point-min))
3602           (push (cons 'replied (and (search-forward "B" nil t)
3603                                     (- (point) (point-min) 1)))
3604                 pos)
3605           (goto-char (point-min))
3606           (push (cons 'score (and (search-forward "C" nil t)
3607                                   (- (point) (point-min) 1)))
3608                 pos)
3609           (goto-char (point-min))
3610           (push (cons 'download (and (search-forward "D" nil t)
3611                                      (- (point) (point-min) 1)))
3612                 pos)))
3613       (setq gnus-summary-mark-positions pos))))
3614
3615 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3616   "Insert a dummy root in the summary buffer."
3617   (beginning-of-line)
3618   (gnus-add-text-properties
3619    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3620    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3621
3622 (defun gnus-summary-extract-address-component (from)
3623   (or (car (funcall gnus-extract-address-components from))
3624       from))
3625
3626 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3627   (let ((mail-parse-charset gnus-newsgroup-charset)
3628         (ignored-from-addresses (gnus-ignored-from-addresses))
3629         ; Is it really necessary to do this next part for each summary line?
3630         ; Luckily, doesn't seem to slow things down much.
3631         (mail-parse-ignored-charsets
3632          (with-current-buffer gnus-summary-buffer
3633            gnus-newsgroup-ignored-charsets)))
3634     (or
3635      (and ignored-from-addresses
3636           (string-match ignored-from-addresses gnus-tmp-from)
3637           (let ((extra-headers (mail-header-extra header))
3638                 to
3639                 newsgroups)
3640             (cond
3641              ((setq to (cdr (assq 'To extra-headers)))
3642               (concat gnus-summary-to-prefix
3643                       (inline
3644                         (gnus-summary-extract-address-component
3645                          (funcall gnus-decode-encoded-address-function to)))))
3646              ((setq newsgroups
3647                     (or
3648                      (cdr (assq 'Newsgroups extra-headers))
3649                      (and
3650                       (memq 'Newsgroups gnus-extra-headers)
3651                       (eq (car (gnus-find-method-for-group
3652                                 gnus-newsgroup-name)) 'nntp)
3653                       (gnus-group-real-name gnus-newsgroup-name))))
3654               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3655      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3656
3657 (defun gnus-summary-insert-line (gnus-tmp-header
3658                                  gnus-tmp-level gnus-tmp-current
3659                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3660                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3661                                  &optional gnus-tmp-dummy gnus-tmp-score
3662                                  gnus-tmp-process)
3663   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3664       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3665                                           gnus-tmp-level)))
3666   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3667          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3668          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3669          (gnus-tmp-score-char
3670           (if (or (null gnus-summary-default-score)
3671                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3672                       gnus-summary-zcore-fuzz))
3673               ?                         ;Whitespace
3674             (if (< gnus-tmp-score gnus-summary-default-score)
3675                 gnus-score-below-mark gnus-score-over-mark)))
3676          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3677          (gnus-tmp-replied
3678           (cond (gnus-tmp-process gnus-process-mark)
3679                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3680                  gnus-cached-mark)
3681                 (gnus-tmp-replied gnus-replied-mark)
3682                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3683                  gnus-forwarded-mark)
3684                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3685                  gnus-saved-mark)
3686                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3687                  gnus-recent-mark)
3688                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3689                  gnus-unseen-mark)
3690                 (t gnus-no-mark)))
3691          (gnus-tmp-downloaded
3692           (cond (undownloaded
3693                  gnus-undownloaded-mark)
3694                 (gnus-newsgroup-agentized
3695                  gnus-downloaded-mark)
3696                 (t
3697                  gnus-no-mark)))
3698          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3699          (gnus-tmp-name
3700           (cond
3701            ((string-match "<[^>]+> *$" gnus-tmp-from)
3702             (let ((beg (match-beginning 0)))
3703               (or (and (string-match "^\".+\"" gnus-tmp-from)
3704                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3705                   (substring gnus-tmp-from 0 beg))))
3706            ((string-match "(.+)" gnus-tmp-from)
3707             (substring gnus-tmp-from
3708                        (1+ (match-beginning 0)) (1- (match-end 0))))
3709            (t gnus-tmp-from)))
3710          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3711          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3712          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3713          (inhibit-read-only t))
3714     (when (string= gnus-tmp-name "")
3715       (setq gnus-tmp-name gnus-tmp-from))
3716     (unless (numberp gnus-tmp-lines)
3717       (setq gnus-tmp-lines -1))
3718     (if (= gnus-tmp-lines -1)
3719         (setq gnus-tmp-lines "?")
3720       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3721       (gnus-put-text-property
3722      (point)
3723      (progn (eval gnus-summary-line-format-spec) (point))
3724        'gnus-number gnus-tmp-number)
3725     (when (gnus-visual-p 'summary-highlight 'highlight)
3726       (forward-line -1)
3727       (gnus-run-hooks 'gnus-summary-update-hook)
3728       (forward-line 1))))
3729
3730 (defun gnus-summary-update-line (&optional dont-update)
3731   "Update summary line after change."
3732   (when (and gnus-summary-default-score
3733              (not gnus-summary-inhibit-highlight))
3734     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3735            (article (gnus-summary-article-number))
3736            (score (gnus-summary-article-score article)))
3737       (unless dont-update
3738         (if (and gnus-summary-mark-below
3739                  (< (gnus-summary-article-score)
3740                     gnus-summary-mark-below))
3741             ;; This article has a low score, so we mark it as read.
3742             (when (memq article gnus-newsgroup-unreads)
3743               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3744           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3745             ;; This article was previously marked as read on account
3746             ;; of a low score, but now it has risen, so we mark it as
3747             ;; unread.
3748             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3749         (gnus-summary-update-mark
3750          (if (or (null gnus-summary-default-score)
3751                  (<= (abs (- score gnus-summary-default-score))
3752                      gnus-summary-zcore-fuzz))
3753              ?                          ;Whitespace
3754            (if (< score gnus-summary-default-score)
3755                gnus-score-below-mark gnus-score-over-mark))
3756          'score))
3757       ;; Do visual highlighting.
3758       (when (gnus-visual-p 'summary-highlight 'highlight)
3759         (gnus-run-hooks 'gnus-summary-update-hook)))))
3760
3761 (defvar gnus-tmp-new-adopts nil)
3762
3763 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3764   "Return the number of articles in THREAD.
3765 This may be 0 in some cases -- if none of the articles in
3766 the thread are to be displayed."
3767   (let* ((number
3768          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3769           (cond
3770            ((not (listp thread))
3771             1)
3772            ((and (consp thread) (cdr thread))
3773             (apply
3774              '+ 1 (mapcar
3775                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3776            ((null thread)
3777             1)
3778            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3779             1)
3780            (t 0))))
3781     (when (and level (zerop level) gnus-tmp-new-adopts)
3782       (incf number
3783             (apply '+ (mapcar
3784                        'gnus-summary-number-of-articles-in-thread
3785                        gnus-tmp-new-adopts))))
3786     (if char
3787         (if (> number 1) gnus-not-empty-thread-mark
3788           gnus-empty-thread-mark)
3789       number)))
3790
3791 (defsubst gnus-summary-line-message-size (head)
3792   "Return pretty-printed version of message size.
3793 This function is intended to be used in
3794 `gnus-summary-line-format-alist'."
3795   (let ((c (or (mail-header-chars head) -1)))
3796     (cond ((< c 0) "n/a")               ; chars not available
3797           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3798           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3799           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3800           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3801
3802
3803 (defun gnus-summary-set-local-parameters (group)
3804   "Go through the local params of GROUP and set all variable specs in that list."
3805   (let ((vars '(quit-config)))          ; Ignore quit-config.
3806     (dolist (elem (gnus-group-find-parameter group))
3807       (and (consp elem)                 ; Has to be a cons.
3808            (consp (cdr elem))           ; The cdr has to be a list.
3809            (symbolp (car elem))         ; Has to be a symbol in there.
3810            (not (memq (car elem) vars))
3811            (ignore-errors               ; So we set it.
3812              (push (car elem) vars)
3813              (make-local-variable (car elem))
3814              (set (car elem) (eval (nth 1 elem))))))))
3815
3816 (defun gnus-summary-read-group (group &optional show-all no-article
3817                                       kill-buffer no-display backward
3818                                       select-articles)
3819   "Start reading news in newsgroup GROUP.
3820 If SHOW-ALL is non-nil, already read articles are also listed.
3821 If NO-ARTICLE is non-nil, no article is selected initially.
3822 If NO-DISPLAY, don't generate a summary buffer."
3823   (let (result)
3824     (while (and group
3825                 (null (setq result
3826                             (let ((gnus-auto-select-next nil))
3827                               (or (gnus-summary-read-group-1
3828                                    group show-all no-article
3829                                    kill-buffer no-display
3830                                    select-articles)
3831                                   (setq show-all nil
3832                                         select-articles nil)))))
3833                 (eq gnus-auto-select-next 'quietly))
3834       (set-buffer gnus-group-buffer)
3835       ;; The entry function called above goes to the next
3836       ;; group automatically, so we go two groups back
3837       ;; if we are searching for the previous group.
3838       (when backward
3839         (gnus-group-prev-unread-group 2))
3840       (if (not (equal group (gnus-group-group-name)))
3841           (setq group (gnus-group-group-name))
3842         (setq group nil)))
3843     result))
3844
3845 (defun gnus-summary-read-group-1 (group show-all no-article
3846                                         kill-buffer no-display
3847                                         &optional select-articles)
3848   ;; Killed foreign groups can't be entered.
3849   ;;  (when (and (not (gnus-group-native-p group))
3850   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3851   ;;    (error "Dead non-native groups can't be entered"))
3852   (gnus-message 5 "Retrieving newsgroup: %s..."
3853                 (gnus-group-decoded-name group))
3854   (let* ((new-group (gnus-summary-setup-buffer group))
3855          (quit-config (gnus-group-quit-config group))
3856          (did-select (and new-group (gnus-select-newsgroup
3857                                      group show-all select-articles))))
3858     (cond
3859      ;; This summary buffer exists already, so we just select it.
3860      ((not new-group)
3861       (gnus-set-global-variables)
3862       (when kill-buffer
3863         (gnus-kill-or-deaden-summary kill-buffer))
3864       (gnus-configure-windows 'summary 'force)
3865       (gnus-set-mode-line 'summary)
3866       (gnus-summary-position-point)
3867       (message "")
3868       t)
3869      ;; We couldn't select this group.
3870      ((null did-select)
3871       (when (and (eq major-mode 'gnus-summary-mode)
3872                  (not (equal (current-buffer) kill-buffer)))
3873         (kill-buffer (current-buffer))
3874         (if (not quit-config)
3875             (progn
3876               ;; Update the info -- marks might need to be removed,
3877               ;; for instance.
3878               (gnus-summary-update-info)
3879               (set-buffer gnus-group-buffer)
3880               (gnus-group-jump-to-group group)
3881               (gnus-group-next-unread-group 1))
3882           (gnus-handle-ephemeral-exit quit-config)))
3883       (let ((grpinfo (gnus-get-info group)))
3884         (if (null (gnus-info-read grpinfo))
3885             (gnus-message 3 "Group %s contains no messages"
3886                           (gnus-group-decoded-name group))
3887           (gnus-message 3 "Can't select group")))
3888       nil)
3889      ;; The user did a `C-g' while prompting for number of articles,
3890      ;; so we exit this group.
3891      ((eq did-select 'quit)
3892       (and (eq major-mode 'gnus-summary-mode)
3893            (not (equal (current-buffer) kill-buffer))
3894            (kill-buffer (current-buffer)))
3895       (when kill-buffer
3896         (gnus-kill-or-deaden-summary kill-buffer))
3897       (if (not quit-config)
3898           (progn
3899             (set-buffer gnus-group-buffer)
3900             (gnus-group-jump-to-group group)
3901             (gnus-group-next-unread-group 1)
3902             (gnus-configure-windows 'group 'force))
3903         (gnus-handle-ephemeral-exit quit-config))
3904       ;; Finally signal the quit.
3905       (signal 'quit nil))
3906      ;; The group was successfully selected.
3907      (t
3908       (gnus-set-global-variables)
3909       ;; Save the active value in effect when the group was entered.
3910       (setq gnus-newsgroup-active
3911             (gnus-copy-sequence
3912              (gnus-active gnus-newsgroup-name)))
3913       ;; You can change the summary buffer in some way with this hook.
3914       (gnus-run-hooks 'gnus-select-group-hook)
3915       (when (memq 'summary (gnus-update-format-specifications
3916                             nil 'summary 'summary-mode 'summary-dummy))
3917         ;; The format specification for the summary line was updated,
3918         ;; so we need to update the mark positions as well.
3919         (gnus-update-summary-mark-positions))
3920       ;; Do score processing.
3921       (when gnus-use-scoring
3922         (gnus-possibly-score-headers))
3923       ;; Check whether to fill in the gaps in the threads.
3924       (when gnus-build-sparse-threads
3925         (gnus-build-sparse-threads))
3926       ;; Find the initial limit.
3927       (if show-all
3928           (let ((gnus-newsgroup-dormant nil))
3929             (gnus-summary-initial-limit show-all))
3930         (gnus-summary-initial-limit show-all))
3931       ;; Generate the summary buffer.
3932       (unless no-display
3933         (gnus-summary-prepare))
3934       (when gnus-use-trees
3935         (gnus-tree-open group)
3936         (setq gnus-summary-highlight-line-function
3937               'gnus-tree-highlight-article))
3938       ;; If the summary buffer is empty, but there are some low-scored
3939       ;; articles or some excluded dormants, we include these in the
3940       ;; buffer.
3941       (when (and (zerop (buffer-size))
3942                  (not no-display))
3943         (cond (gnus-newsgroup-dormant
3944                (gnus-summary-limit-include-dormant))
3945               ((and gnus-newsgroup-scored show-all)
3946                (gnus-summary-limit-include-expunged t))))
3947       ;; Function `gnus-apply-kill-file' must be called in this hook.
3948       (gnus-run-hooks 'gnus-apply-kill-hook)
3949       (if (and (zerop (buffer-size))
3950                (not no-display))
3951           (progn
3952             ;; This newsgroup is empty.
3953             (gnus-summary-catchup-and-exit nil t)
3954             (gnus-message 6 "No unread news")
3955             (when kill-buffer
3956               (gnus-kill-or-deaden-summary kill-buffer))
3957             ;; Return nil from this function.
3958             nil)
3959         ;; Hide conversation thread subtrees.  We cannot do this in
3960         ;; gnus-summary-prepare-hook since kill processing may not
3961         ;; work with hidden articles.
3962         (gnus-summary-maybe-hide-threads)
3963         (when kill-buffer
3964           (gnus-kill-or-deaden-summary kill-buffer))
3965         (gnus-summary-auto-select-subject)
3966         ;; Show first unread article if requested.
3967         (if (and (not no-article)
3968                  (not no-display)
3969                  gnus-newsgroup-unreads
3970                  gnus-auto-select-first)
3971             (progn
3972               (gnus-configure-windows 'summary)
3973               (let ((art (gnus-summary-article-number)))
3974                 (unless (and (not gnus-plugged)
3975                              (or (memq art gnus-newsgroup-undownloaded)
3976                                  (memq art gnus-newsgroup-downloadable)))
3977                   (gnus-summary-goto-article art))))
3978           ;; Don't select any articles.
3979           (gnus-summary-position-point)
3980           (gnus-configure-windows 'summary 'force)
3981           (gnus-set-mode-line 'summary))
3982         (when (and gnus-auto-center-group
3983                    (get-buffer-window gnus-group-buffer t))
3984           ;; Gotta use windows, because recenter does weird stuff if
3985           ;; the current buffer ain't the displayed window.
3986           (let ((owin (selected-window)))
3987             (select-window (get-buffer-window gnus-group-buffer t))
3988             (when (gnus-group-goto-group group)
3989               (recenter))
3990             (select-window owin)))
3991         ;; Mark this buffer as "prepared".
3992         (setq gnus-newsgroup-prepared t)
3993         (gnus-run-hooks 'gnus-summary-prepared-hook)
3994         (unless (gnus-ephemeral-group-p group)
3995           (gnus-group-update-group group))
3996         t)))))
3997
3998 (defun gnus-summary-auto-select-subject ()
3999   "Select the subject line on initial group entry."
4000   (goto-char (point-min))
4001   (cond
4002    ((eq gnus-auto-select-subject 'best)
4003     (gnus-summary-best-unread-subject))
4004    ((eq gnus-auto-select-subject 'unread)
4005     (gnus-summary-first-unread-subject))
4006    ((eq gnus-auto-select-subject 'unseen)
4007     (gnus-summary-first-unseen-subject))
4008    ((eq gnus-auto-select-subject 'unseen-or-unread)
4009     (gnus-summary-first-unseen-or-unread-subject))
4010    ((eq gnus-auto-select-subject 'first)
4011     ;; Do nothing.
4012     )
4013    ((functionp gnus-auto-select-subject)
4014     (funcall gnus-auto-select-subject))))
4015
4016 (defun gnus-summary-prepare ()
4017   "Generate the summary buffer."
4018   (interactive)
4019   (let ((inhibit-read-only t))
4020     (erase-buffer)
4021     (setq gnus-newsgroup-data nil
4022           gnus-newsgroup-data-reverse nil)
4023     (gnus-run-hooks 'gnus-summary-generate-hook)
4024     ;; Generate the buffer, either with threads or without.
4025     (when gnus-newsgroup-headers
4026       (gnus-summary-prepare-threads
4027        (if gnus-show-threads
4028            (gnus-sort-gathered-threads
4029             (funcall gnus-summary-thread-gathering-function
4030                      (gnus-sort-threads
4031                       (gnus-cut-threads (gnus-make-threads)))))
4032          ;; Unthreaded display.
4033          (gnus-sort-articles gnus-newsgroup-headers))))
4034     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
4035     ;; Call hooks for modifying summary buffer.
4036     (goto-char (point-min))
4037     (gnus-run-hooks 'gnus-summary-prepare-hook)))
4038
4039 (defsubst gnus-general-simplify-subject (subject)
4040   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4041   (setq subject
4042         (cond
4043          ;; Truncate the subject.
4044          (gnus-simplify-subject-functions
4045           (gnus-map-function gnus-simplify-subject-functions subject))
4046          ((numberp gnus-summary-gather-subject-limit)
4047           (setq subject (gnus-simplify-subject-re subject))
4048           (if (> (length subject) gnus-summary-gather-subject-limit)
4049               (substring subject 0 gnus-summary-gather-subject-limit)
4050             subject))
4051          ;; Fuzzily simplify it.
4052          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4053           (gnus-simplify-subject-fuzzy subject))
4054          ;; Just remove the leading "Re:".
4055          (t
4056           (gnus-simplify-subject-re subject))))
4057
4058   (if (and gnus-summary-gather-exclude-subject
4059            (string-match gnus-summary-gather-exclude-subject subject))
4060       nil                         ; This article shouldn't be gathered
4061     subject))
4062
4063 (defun gnus-summary-simplify-subject-query ()
4064   "Query where the respool algorithm would put this article."
4065   (interactive)
4066   (gnus-summary-select-article)
4067   (message "%s" (gnus-general-simplify-subject (gnus-summary-article-subject))))
4068
4069 (defun gnus-gather-threads-by-subject (threads)
4070   "Gather threads by looking at Subject headers."
4071   (if (not gnus-summary-make-false-root)
4072       threads
4073     (let ((hashtb (gnus-make-hashtable 1024))
4074           (prev threads)
4075           (result threads)
4076           subject hthread whole-subject)
4077       (while threads
4078         (setq subject (gnus-general-simplify-subject
4079                        (setq whole-subject (mail-header-subject
4080                                             (caar threads)))))
4081         (when subject
4082           (if (setq hthread (gnus-gethash subject hashtb))
4083               (progn
4084                 ;; We enter a dummy root into the thread, if we
4085                 ;; haven't done that already.
4086                 (unless (stringp (caar hthread))
4087                   (setcar hthread (list whole-subject (car hthread))))
4088                 ;; We add this new gathered thread to this gathered
4089                 ;; thread.
4090                 (setcdr (car hthread)
4091                         (nconc (cdar hthread) (list (car threads))))
4092                 ;; Remove it from the list of threads.
4093                 (setcdr prev (cdr threads))
4094                 (setq threads prev))
4095             ;; Enter this thread into the hash table.
4096             (gnus-sethash subject
4097                           (if gnus-summary-make-false-root-always
4098                               (progn
4099                                 ;; If you want a dummy root above all
4100                                 ;; threads...
4101                                 (setcar threads (list whole-subject
4102                                                       (car threads)))
4103                                 threads)
4104                             threads)
4105                           hashtb)))
4106         (setq prev threads)
4107         (setq threads (cdr threads)))
4108       result)))
4109
4110 (defun gnus-gather-threads-by-references (threads)
4111   "Gather threads by looking at References headers."
4112   (let ((idhashtb (gnus-make-hashtable 1024))
4113         (thhashtb (gnus-make-hashtable 1024))
4114         (prev threads)
4115         (result threads)
4116         ids references id gthread gid entered ref)
4117     (while threads
4118       (when (setq references (mail-header-references (caar threads)))
4119         (setq id (mail-header-id (caar threads))
4120               ids (inline (gnus-split-references references))
4121               entered nil)
4122         (while (setq ref (pop ids))
4123           (setq ids (delete ref ids))
4124           (if (not (setq gid (gnus-gethash ref idhashtb)))
4125               (progn
4126                 (gnus-sethash ref id idhashtb)
4127                 (gnus-sethash id threads thhashtb))
4128             (setq gthread (gnus-gethash gid thhashtb))
4129             (unless entered
4130               ;; We enter a dummy root into the thread, if we
4131               ;; haven't done that already.
4132               (unless (stringp (caar gthread))
4133                 (setcar gthread (list (mail-header-subject (caar gthread))
4134                                       (car gthread))))
4135               ;; We add this new gathered thread to this gathered
4136               ;; thread.
4137               (setcdr (car gthread)
4138                       (nconc (cdar gthread) (list (car threads)))))
4139             ;; Add it into the thread hash table.
4140             (gnus-sethash id gthread thhashtb)
4141             (setq entered t)
4142             ;; Remove it from the list of threads.
4143             (setcdr prev (cdr threads))
4144             (setq threads prev))))
4145       (setq prev threads)
4146       (setq threads (cdr threads)))
4147     result))
4148
4149 (defun gnus-sort-gathered-threads (threads)
4150   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4151   (let ((result threads))
4152     (while threads
4153       (when (stringp (caar threads))
4154         (setcdr (car threads)
4155                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4156       (setq threads (cdr threads)))
4157     result))
4158
4159 (defun gnus-thread-loop-p (root thread)
4160   "Say whether ROOT is in THREAD."
4161   (let ((stack (list thread))
4162         (infloop 0)
4163         th)
4164     (while (setq thread (pop stack))
4165       (setq th (cdr thread))
4166       (while (and th
4167                   (not (eq (caar th) root)))
4168         (pop th))
4169       (if th
4170           ;; We have found a loop.
4171           (let (ref-dep)
4172             (setcdr thread (delq (car th) (cdr thread)))
4173             (if (boundp (setq ref-dep (intern "none"
4174                                               gnus-newsgroup-dependencies)))
4175                 (setcdr (symbol-value ref-dep)
4176                         (nconc (cdr (symbol-value ref-dep))
4177                                (list (car th))))
4178               (set ref-dep (list nil (car th))))
4179             (setq infloop 1
4180                   stack nil))
4181         ;; Push all the subthreads onto the stack.
4182         (push (cdr thread) stack)))
4183     infloop))
4184
4185 (defun gnus-make-threads ()
4186   "Go through the dependency hashtb and find the roots.  Return all threads."
4187   (let (threads)
4188     (while (catch 'infloop
4189              (mapatoms
4190               (lambda (refs)
4191                 ;; Deal with self-referencing References loops.
4192                 (when (and (car (symbol-value refs))
4193                            (not (zerop
4194                                  (apply
4195                                   '+
4196                                   (mapcar
4197                                    (lambda (thread)
4198                                      (gnus-thread-loop-p
4199                                       (car (symbol-value refs)) thread))
4200                                    (cdr (symbol-value refs)))))))
4201                   (setq threads nil)
4202                   (throw 'infloop t))
4203                 (unless (car (symbol-value refs))
4204                   ;; These threads do not refer back to any other
4205                   ;; articles, so they're roots.
4206                   (setq threads (append (cdr (symbol-value refs)) threads))))
4207               gnus-newsgroup-dependencies)))
4208     threads))
4209
4210 ;; Build the thread tree.
4211 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4212   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4213
4214 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4215 if it was already present.
4216
4217 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4218 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4219 Message-IDs will be renamed to a unique Message-ID before being
4220 entered.
4221
4222 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4223   (let* ((id (mail-header-id header))
4224          (id-dep (and id (intern id dependencies)))
4225          parent-id ref ref-dep ref-header replaced)
4226     ;; Enter this `header' in the `dependencies' table.
4227     (cond
4228      ((not id-dep)
4229       (setq header nil))
4230      ;; The first two cases do the normal part: enter a new `header'
4231      ;; in the `dependencies' table.
4232      ((not (boundp id-dep))
4233       (set id-dep (list header)))
4234      ((null (car (symbol-value id-dep)))
4235       (setcar (symbol-value id-dep) header))
4236
4237      ;; From here the `header' was already present in the
4238      ;; `dependencies' table.
4239      (force-new
4240       ;; Overrides an existing entry;
4241       ;; just set the header part of the entry.
4242       (setcar (symbol-value id-dep) header)
4243       (setq replaced t))
4244
4245      ;; Renames the existing `header' to a unique Message-ID.
4246      ((not gnus-summary-ignore-duplicates)
4247       ;; An article with this Message-ID has already been seen.
4248       ;; We rename the Message-ID.
4249       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4250            (list header))
4251       (mail-header-set-id header id))
4252
4253      ;; The last case ignores an existing entry, except it adds any
4254      ;; additional Xrefs (in case the two articles came from different
4255      ;; servers.
4256      ;; Also sets `header' to `nil' meaning that the `dependencies'
4257      ;; table was *not* modified.
4258      (t
4259       (mail-header-set-xref
4260        (car (symbol-value id-dep))
4261        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4262                    "")
4263                (or (mail-header-xref header) "")))
4264       (setq header nil)))
4265
4266     (when (and header (not replaced))
4267       ;; First check that we are not creating a References loop.
4268       (setq parent-id (gnus-parent-id (mail-header-references header)))
4269       (setq ref parent-id)
4270       (while (and ref
4271                   (setq ref-dep (intern-soft ref dependencies))
4272                   (boundp ref-dep)
4273                   (setq ref-header (car (symbol-value ref-dep))))
4274         (if (string= id ref)
4275             ;; Yuk!  This is a reference loop.  Make the article be a
4276             ;; root article.
4277             (progn
4278               (mail-header-set-references (car (symbol-value id-dep)) "none")
4279               (setq ref nil)
4280               (setq parent-id nil))
4281           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4282       (setq ref-dep (intern (or parent-id "none") dependencies))
4283       (if (boundp ref-dep)
4284           (setcdr (symbol-value ref-dep)
4285                   (nconc (cdr (symbol-value ref-dep))
4286                          (list (symbol-value id-dep))))
4287         (set ref-dep (list nil (symbol-value id-dep)))))
4288     header))
4289
4290 (defun gnus-extract-message-id-from-in-reply-to (string)
4291   (if (string-match "<[^>]+>" string)
4292       (substring string (match-beginning 0) (match-end 0))
4293     nil))
4294
4295 (defun gnus-build-sparse-threads ()
4296   (let ((headers gnus-newsgroup-headers)
4297         (mail-parse-charset gnus-newsgroup-charset)
4298         (gnus-summary-ignore-duplicates t)
4299         header references generation relations
4300         subject child end new-child date)
4301     ;; First we create an alist of generations/relations, where
4302     ;; generations is how much we trust the relation, and the relation
4303     ;; is parent/child.
4304     (gnus-message 7 "Making sparse threads...")
4305     (save-excursion
4306       (nnheader-set-temp-buffer " *gnus sparse threads*")
4307       (while (setq header (pop headers))
4308         (when (and (setq references (mail-header-references header))
4309                    (not (string= references "")))
4310           (insert references)
4311           (setq child (mail-header-id header)
4312                 subject (mail-header-subject header)
4313                 date (mail-header-date header)
4314                 generation 0)
4315           (while (search-backward ">" nil t)
4316             (setq end (1+ (point)))
4317             (when (search-backward "<" nil t)
4318               (setq new-child (buffer-substring (point) end))
4319               (push (list (incf generation)
4320                           child (setq child new-child)
4321                           subject date)
4322                     relations)))
4323           (when child
4324             (push (list (1+ generation) child nil subject) relations))
4325           (erase-buffer)))
4326       (kill-buffer (current-buffer)))
4327     ;; Sort over trustworthiness.
4328     (dolist (relation (sort relations 'car-less-than-car))
4329       (when (gnus-dependencies-add-header
4330              (make-full-mail-header
4331               gnus-reffed-article-number
4332               (nth 3 relation) "" (or (nth 4 relation) "")
4333               (nth 1 relation)
4334               (or (nth 2 relation) "") 0 0 "")
4335              gnus-newsgroup-dependencies nil)
4336         (push gnus-reffed-article-number gnus-newsgroup-limit)
4337         (push gnus-reffed-article-number gnus-newsgroup-sparse)
4338         (push (cons gnus-reffed-article-number gnus-sparse-mark)
4339               gnus-newsgroup-reads)
4340         (decf gnus-reffed-article-number)))
4341     (gnus-message 7 "Making sparse threads...done")))
4342
4343 (defun gnus-build-old-threads ()
4344   ;; Look at all the articles that refer back to old articles, and
4345   ;; fetch the headers for the articles that aren't there.  This will
4346   ;; build complete threads - if the roots haven't been expired by the
4347   ;; server, that is.
4348   (let ((mail-parse-charset gnus-newsgroup-charset)
4349         id heads)
4350     (mapatoms
4351      (lambda (refs)
4352        (when (not (car (symbol-value refs)))
4353          (setq heads (cdr (symbol-value refs)))
4354          (while heads
4355            (if (memq (mail-header-number (caar heads))
4356                      gnus-newsgroup-dormant)
4357                (setq heads (cdr heads))
4358              (setq id (symbol-name refs))
4359              (while (and (setq id (gnus-build-get-header id))
4360                          (not (car (gnus-id-to-thread id)))))
4361              (setq heads nil)))))
4362      gnus-newsgroup-dependencies)))
4363
4364 (defsubst gnus-remove-odd-characters (string)
4365   "Translate STRING into something that doesn't contain weird characters."
4366   (mm-subst-char-in-string
4367    ?\r ?\-
4368    (mm-subst-char-in-string ?\n ?\- string t) t))
4369
4370 ;; This function has to be called with point after the article number
4371 ;; on the beginning of the line.
4372 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4373   (let ((eol (point-at-eol))
4374         (buffer (current-buffer))
4375         header references in-reply-to)
4376
4377     ;; overview: [num subject from date id refs chars lines misc]
4378     (unwind-protect
4379         (let (x)
4380           (narrow-to-region (point) eol)
4381           (unless (eobp)
4382             (forward-char))
4383
4384           (setq header
4385                 (make-full-mail-header
4386                  number                 ; number
4387                  (condition-case ()     ; subject
4388                      (gnus-remove-odd-characters
4389                       (funcall gnus-decode-encoded-word-function
4390                                (setq x (nnheader-nov-field))))
4391                    (error x))
4392                  (condition-case ()     ; from
4393                      (gnus-remove-odd-characters
4394                       (funcall gnus-decode-encoded-address-function
4395                                (setq x (nnheader-nov-field))))
4396                    (error x))
4397                  (nnheader-nov-field)   ; date
4398                  (nnheader-nov-read-message-id number)  ; id
4399                  (setq references (nnheader-nov-field)) ; refs
4400                  (nnheader-nov-read-integer) ; chars
4401                  (nnheader-nov-read-integer) ; lines
4402                  (unless (eobp)
4403                    (if (looking-at "Xref: ")
4404                        (goto-char (match-end 0)))
4405                    (nnheader-nov-field)) ; Xref
4406                  (nnheader-nov-parse-extra)))) ; extra
4407
4408       (widen))
4409
4410     (when (and (string= references "")
4411                (setq in-reply-to (mail-header-extra header))
4412                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4413       (mail-header-set-references
4414        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4415
4416     (when gnus-alter-header-function
4417       (funcall gnus-alter-header-function header))
4418     (gnus-dependencies-add-header header dependencies force-new)))
4419
4420 (defun gnus-build-get-header (id)
4421   "Look through the buffer of NOV lines and find the header to ID.
4422 Enter this line into the dependencies hash table, and return
4423 the id of the parent article (if any)."
4424   (let ((deps gnus-newsgroup-dependencies)
4425         found header)
4426     (prog1
4427         (with-current-buffer nntp-server-buffer
4428           (let ((case-fold-search nil))
4429             (goto-char (point-min))
4430             (while (and (not found)
4431                         (search-forward id nil t))
4432               (beginning-of-line)
4433               (setq found (looking-at
4434                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4435                                    (regexp-quote id))))
4436               (or found (beginning-of-line 2)))
4437             (when found
4438               (beginning-of-line)
4439               (and
4440                (setq header (gnus-nov-parse-line
4441                              (read (current-buffer)) deps))
4442                (gnus-parent-id (mail-header-references header))))))
4443       (when header
4444         (let ((number (mail-header-number header)))
4445           (push number gnus-newsgroup-limit)
4446           (push header gnus-newsgroup-headers)
4447           (if (memq number gnus-newsgroup-unselected)
4448               (progn
4449                 (setq gnus-newsgroup-unreads
4450                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4451                                                number))
4452                 (setq gnus-newsgroup-unselected
4453                       (delq number gnus-newsgroup-unselected)))
4454             (push number gnus-newsgroup-ancient)))))))
4455
4456 (defun gnus-build-all-threads ()
4457   "Read all the headers."
4458   (let ((gnus-summary-ignore-duplicates t)
4459         (mail-parse-charset gnus-newsgroup-charset)
4460         (dependencies gnus-newsgroup-dependencies)
4461         header article)
4462     (with-current-buffer nntp-server-buffer
4463       (let ((case-fold-search nil))
4464         (goto-char (point-min))
4465         (while (not (eobp))
4466           (ignore-errors
4467             (setq article (read (current-buffer))
4468                   header (gnus-nov-parse-line article dependencies)))
4469           (when header
4470             (with-current-buffer gnus-summary-buffer
4471               (push header gnus-newsgroup-headers)
4472               (if (memq (setq article (mail-header-number header))
4473                         gnus-newsgroup-unselected)
4474                   (progn
4475                     (setq gnus-newsgroup-unreads
4476                           (gnus-add-to-sorted-list
4477                            gnus-newsgroup-unreads article))
4478                     (setq gnus-newsgroup-unselected
4479                           (delq article gnus-newsgroup-unselected)))
4480                 (push article gnus-newsgroup-ancient)))
4481             (forward-line 1)))))))
4482
4483 (defun gnus-summary-update-article-line (article header)
4484   "Update the line for ARTICLE using HEADER."
4485   (let* ((id (mail-header-id header))
4486          (thread (gnus-id-to-thread id)))
4487     (unless thread
4488       (error "Article in no thread"))
4489     ;; Update the thread.
4490     (setcar thread header)
4491     (gnus-summary-goto-subject article)
4492     (let* ((datal (gnus-data-find-list article))
4493            (data (car datal))
4494            (inhibit-read-only t)
4495            (level (gnus-summary-thread-level)))
4496       (gnus-delete-line)
4497       (let ((inserted (- (point)
4498                          (progn
4499                            (gnus-summary-insert-line
4500                             header level nil
4501                             (memq article gnus-newsgroup-undownloaded)
4502                             (gnus-article-mark article)
4503                             (memq article gnus-newsgroup-replied)
4504                             (memq article gnus-newsgroup-expirable)
4505                             ;; Only insert the Subject string when it's different
4506                             ;; from the previous Subject string.
4507                             (if (and
4508                                  gnus-show-threads
4509                                  (gnus-subject-equal
4510                                   (condition-case ()
4511                                       (mail-header-subject
4512                                        (gnus-data-header
4513                                         (cadr
4514                                          (gnus-data-find-list
4515                                           article
4516                                           (gnus-data-list t)))))
4517                                     ;; Error on the side of excessive subjects.
4518                                     (error ""))
4519                                   (mail-header-subject header)))
4520                                 ""
4521                               (mail-header-subject header))
4522                             nil (cdr (assq article gnus-newsgroup-scored))
4523                             (memq article gnus-newsgroup-processable))
4524                            (point)))))
4525         (when (cdr datal)
4526           (gnus-data-update-list
4527            (cdr datal)
4528            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4529
4530 (defun gnus-summary-update-article (article &optional iheader)
4531   "Update ARTICLE in the summary buffer."
4532   (set-buffer gnus-summary-buffer)
4533   (let* ((header (gnus-summary-article-header article))
4534          (id (mail-header-id header))
4535          (data (gnus-data-find article))
4536          (thread (gnus-id-to-thread id))
4537          (references (mail-header-references header))
4538          (parent
4539           (gnus-id-to-thread
4540            (or (gnus-parent-id
4541                 (when (and references
4542                            (not (equal "" references)))
4543                   references))
4544                "none")))
4545          (inhibit-read-only t)
4546          (old (car thread)))
4547     (when thread
4548       (unless iheader
4549         (setcar thread nil)
4550         (when parent
4551           (delq thread parent)))
4552       (if (gnus-summary-insert-subject id header)
4553           ;; Set the (possibly) new article number in the data structure.
4554           (gnus-data-set-number data (gnus-id-to-article id))
4555         (setcar thread old)
4556         nil))))
4557
4558 (defun gnus-rebuild-thread (id &optional line)
4559   "Rebuild the thread containing ID.
4560 If LINE, insert the rebuilt thread starting on line LINE."
4561   (let ((inhibit-read-only t)
4562         old-pos current thread data)
4563     (if (not gnus-show-threads)
4564         (setq thread (list (car (gnus-id-to-thread id))))
4565       ;; Get the thread this article is part of.
4566       (setq thread (gnus-remove-thread id)))
4567     (setq old-pos (point-at-bol))
4568     (setq current (save-excursion
4569                     (and (re-search-backward "[\r\n]" nil t)
4570                          (gnus-summary-article-number))))
4571     ;; If this is a gathered thread, we have to go some re-gathering.
4572     (when (stringp (car thread))
4573       (let ((subject (car thread))
4574             roots thr)
4575         (setq thread (cdr thread))
4576         (while thread
4577           (unless (memq (setq thr (gnus-id-to-thread
4578                                    (gnus-root-id
4579                                     (mail-header-id (caar thread)))))
4580                         roots)
4581             (push thr roots))
4582           (setq thread (cdr thread)))
4583         ;; We now have all (unique) roots.
4584         (if (= (length roots) 1)
4585             ;; All the loose roots are now one solid root.
4586             (setq thread (car roots))
4587           (setq thread (cons subject (gnus-sort-threads roots))))))
4588     (let (threads)
4589       ;; We then insert this thread into the summary buffer.
4590       (when line
4591         (goto-char (point-min))
4592         (forward-line (1- line)))
4593       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4594         (if gnus-show-threads
4595             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4596           (gnus-summary-prepare-unthreaded thread))
4597         (setq data (nreverse gnus-newsgroup-data))
4598         (setq threads gnus-newsgroup-threads))
4599       ;; We splice the new data into the data structure.
4600       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4601       ;;!!! then we want to insert at the beginning of the buffer.
4602       ;;!!! That happens to be true with Gnus now, but that may
4603       ;;!!! change in the future.  Perhaps.
4604       (gnus-data-enter-list
4605        (if line nil current) data (- (point) old-pos))
4606       (setq gnus-newsgroup-threads
4607             (nconc threads gnus-newsgroup-threads))
4608       (gnus-data-compute-positions))))
4609
4610 (defun gnus-number-to-header (number)
4611   "Return the header for article NUMBER."
4612   (let ((headers gnus-newsgroup-headers))
4613     (while (and headers
4614                 (not (= number (mail-header-number (car headers)))))
4615       (pop headers))
4616     (when headers
4617       (car headers))))
4618
4619 (defun gnus-parent-headers (in-headers &optional generation)
4620   "Return the headers of the GENERATIONeth parent of HEADERS."
4621   (unless generation
4622     (setq generation 1))
4623   (let ((parent t)
4624         (headers in-headers)
4625         references)
4626     (while (and parent
4627                 (not (zerop generation))
4628                 (setq references (mail-header-references headers)))
4629       (setq headers (if (and references
4630                              (setq parent (gnus-parent-id references)))
4631                         (car (gnus-id-to-thread parent))
4632                       nil))
4633       (decf generation))
4634     (and (not (eq headers in-headers))
4635          headers)))
4636
4637 (defun gnus-id-to-thread (id)
4638   "Return the (sub-)thread where ID appears."
4639   (gnus-gethash id gnus-newsgroup-dependencies))
4640
4641 (defun gnus-id-to-article (id)
4642   "Return the article number of ID."
4643   (let ((thread (gnus-id-to-thread id)))
4644     (when (and thread
4645                (car thread))
4646       (mail-header-number (car thread)))))
4647
4648 (defun gnus-id-to-header (id)
4649   "Return the article headers of ID."
4650   (car (gnus-id-to-thread id)))
4651
4652 (defun gnus-article-displayed-root-p (article)
4653   "Say whether ARTICLE is a root(ish) article."
4654   (let ((level (gnus-summary-thread-level article))
4655         (refs (mail-header-references  (gnus-summary-article-header article)))
4656         particle)
4657     (cond
4658      ((null level) nil)
4659      ((zerop level) t)
4660      ((null refs) t)
4661      ((null (gnus-parent-id refs)) t)
4662      ((and (= 1 level)
4663            (null (setq particle (gnus-id-to-article
4664                                  (gnus-parent-id refs))))
4665            (null (gnus-summary-thread-level particle)))))))
4666
4667 (defun gnus-root-id (id)
4668   "Return the id of the root of the thread where ID appears."
4669   (let (last-id prev)
4670     (while (and id (setq prev (car (gnus-id-to-thread id))))
4671       (setq last-id id
4672             id (gnus-parent-id (mail-header-references prev))))
4673     last-id))
4674
4675 (defun gnus-articles-in-thread (thread)
4676   "Return the list of articles in THREAD."
4677   (cons (mail-header-number (car thread))
4678         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4679
4680 (defun gnus-remove-thread (id &optional dont-remove)
4681   "Remove the thread that has ID in it."
4682   (let (headers thread last-id)
4683     ;; First go up in this thread until we find the root.
4684     (setq last-id (gnus-root-id id)
4685           headers (message-flatten-list (gnus-id-to-thread last-id)))
4686     ;; We have now found the real root of this thread.  It might have
4687     ;; been gathered into some loose thread, so we have to search
4688     ;; through the threads to find the thread we wanted.
4689     (let ((threads gnus-newsgroup-threads)
4690           sub)
4691       (while threads
4692         (setq sub (car threads))
4693         (if (stringp (car sub))
4694             ;; This is a gathered thread, so we look at the roots
4695             ;; below it to find whether this article is in this
4696             ;; gathered root.
4697             (progn
4698               (setq sub (cdr sub))
4699               (while sub
4700                 (when (member (caar sub) headers)
4701                   (setq thread (car threads)
4702                         threads nil
4703                         sub nil))
4704                 (setq sub (cdr sub))))
4705           ;; It's an ordinary thread, so we check it.
4706           (when (eq (car sub) (car headers))
4707             (setq thread sub
4708                   threads nil)))
4709         (setq threads (cdr threads)))
4710       ;; If this article is in no thread, then it's a root.
4711       (if thread
4712           (unless dont-remove
4713             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4714         (setq thread (gnus-id-to-thread last-id)))
4715       (when thread
4716         (prog1
4717             thread                      ; We return this thread.
4718           (unless dont-remove
4719             (if (stringp (car thread))
4720                 (progn
4721                   ;; If we use dummy roots, then we have to remove the
4722                   ;; dummy root as well.
4723                   (when (eq gnus-summary-make-false-root 'dummy)
4724                     ;; We go to the dummy root by going to
4725                     ;; the first sub-"thread", and then one line up.
4726                     (gnus-summary-goto-article
4727                      (mail-header-number (caadr thread)))
4728                     (forward-line -1)
4729                     (gnus-delete-line)
4730                     (gnus-data-compute-positions))
4731                   (setq thread (cdr thread))
4732                   (while thread
4733                     (gnus-remove-thread-1 (car thread))
4734                     (setq thread (cdr thread))))
4735               (gnus-remove-thread-1 thread))))))))
4736
4737 (defun gnus-remove-thread-1 (thread)
4738   "Remove the thread THREAD recursively."
4739   (let ((number (mail-header-number (pop thread)))
4740         d)
4741     (setq thread (reverse thread))
4742     (while thread
4743       (gnus-remove-thread-1 (pop thread)))
4744     (when (setq d (gnus-data-find number))
4745       (goto-char (gnus-data-pos d))
4746       (gnus-summary-show-thread)
4747       (gnus-data-remove
4748        number
4749        (- (point-at-bol)
4750           (prog1
4751               (1+ (point-at-eol))
4752             (gnus-delete-line)))))))
4753
4754 (defun gnus-sort-threads-recursive (threads func)
4755   (sort (mapcar (lambda (thread)
4756                   (cons (car thread)
4757                         (and (cdr thread)
4758                              (gnus-sort-threads-recursive (cdr thread) func))))
4759                 threads) func))
4760
4761 (defun gnus-sort-threads-loop (threads func)
4762   (let* ((superthread (cons nil threads))
4763          (stack (list (cons superthread threads)))
4764          remaining-threads thread)
4765     (while stack
4766       (setq remaining-threads (cdr (car stack)))
4767       (if remaining-threads
4768           (progn (setq thread (car remaining-threads))
4769                  (setcdr (car stack) (cdr remaining-threads))
4770                  (if (cdr thread)
4771                      (push (cons thread (cdr thread)) stack)))
4772         (setq thread (caar stack))
4773         (setcdr thread (sort (cdr thread) func))
4774         (pop stack)))
4775     (cdr superthread)))
4776
4777 (defun gnus-sort-threads (threads)
4778   "Sort THREADS."
4779   (if (not gnus-thread-sort-functions)
4780       threads
4781     (gnus-message 8 "Sorting threads...")
4782     (prog1
4783         (condition-case nil
4784             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4785               (gnus-sort-threads-recursive
4786                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4787           ;; Even after binding max-lisp-eval-depth, the recursive
4788           ;; sorter might fail for very long threads.  In that case,
4789           ;; try using a (less well-tested) non-recursive sorter.
4790           (error (gnus-sort-threads-loop
4791                   threads (gnus-make-sort-function
4792                            gnus-thread-sort-functions))))
4793       (gnus-message 8 "Sorting threads...done"))))
4794
4795 (defun gnus-sort-articles (articles)
4796   "Sort ARTICLES."
4797   (when gnus-article-sort-functions
4798     (gnus-message 7 "Sorting articles...")
4799     (prog1
4800         (setq gnus-newsgroup-headers
4801               (sort articles (gnus-make-sort-function
4802                               gnus-article-sort-functions)))
4803       (gnus-message 7 "Sorting articles...done"))))
4804
4805 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4806 (defmacro gnus-thread-header (thread)
4807   "Return header of first article in THREAD.
4808 Note that THREAD must never, ever be anything else than a variable -
4809 using some other form will lead to serious barfage."
4810   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4811   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4812   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4813         (vector thread) 2))
4814
4815 (defsubst gnus-article-sort-by-number (h1 h2)
4816   "Sort articles by article number."
4817   (< (mail-header-number h1)
4818      (mail-header-number h2)))
4819
4820 (defun gnus-thread-sort-by-number (h1 h2)
4821   "Sort threads by root article number."
4822   (gnus-article-sort-by-number
4823    (gnus-thread-header h1) (gnus-thread-header h2)))
4824
4825 (defsubst gnus-article-sort-by-random (h1 h2)
4826   "Sort articles randomly."
4827   (zerop (random 2)))
4828
4829 (defun gnus-thread-sort-by-random (h1 h2)
4830   "Sort threads randomly."
4831   (gnus-article-sort-by-random
4832    (gnus-thread-header h1) (gnus-thread-header h2)))
4833
4834 (defsubst gnus-article-sort-by-lines (h1 h2)
4835   "Sort articles by article Lines header."
4836   (< (mail-header-lines h1)
4837      (mail-header-lines h2)))
4838
4839 (defun gnus-thread-sort-by-lines (h1 h2)
4840   "Sort threads by root article Lines header."
4841   (gnus-article-sort-by-lines
4842    (gnus-thread-header h1) (gnus-thread-header h2)))
4843
4844 (defsubst gnus-article-sort-by-chars (h1 h2)
4845   "Sort articles by octet length."
4846   (< (mail-header-chars h1)
4847      (mail-header-chars h2)))
4848
4849 (defun gnus-thread-sort-by-chars (h1 h2)
4850   "Sort threads by root article octet length."
4851   (gnus-article-sort-by-chars
4852    (gnus-thread-header h1) (gnus-thread-header h2)))
4853
4854 (defsubst gnus-article-sort-by-author (h1 h2)
4855   "Sort articles by root author."
4856   (gnus-string<
4857    (let ((extract (funcall
4858                    gnus-extract-address-components
4859                    (mail-header-from h1))))
4860      (or (car extract) (cadr extract) ""))
4861    (let ((extract (funcall
4862                    gnus-extract-address-components
4863                    (mail-header-from h2))))
4864      (or (car extract) (cadr extract) ""))))
4865
4866 (defun gnus-thread-sort-by-author (h1 h2)
4867   "Sort threads by root author."
4868   (gnus-article-sort-by-author
4869    (gnus-thread-header h1)  (gnus-thread-header h2)))
4870
4871 (defsubst gnus-article-sort-by-recipient (h1 h2)
4872   "Sort articles by recipient."
4873   (gnus-string<
4874    (let ((extract (funcall
4875                    gnus-extract-address-components
4876                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4877      (or (car extract) (cadr extract)))
4878    (let ((extract (funcall
4879                    gnus-extract-address-components
4880                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4881      (or (car extract) (cadr extract)))))
4882
4883 (defun gnus-thread-sort-by-recipient (h1 h2)
4884   "Sort threads by root recipient."
4885   (gnus-article-sort-by-recipient
4886    (gnus-thread-header h1) (gnus-thread-header h2)))
4887
4888 (defsubst gnus-article-sort-by-subject (h1 h2)
4889   "Sort articles by root subject."
4890   (gnus-string<
4891    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4892    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4893
4894 (defun gnus-thread-sort-by-subject (h1 h2)
4895   "Sort threads by root subject."
4896   (gnus-article-sort-by-subject
4897    (gnus-thread-header h1) (gnus-thread-header h2)))
4898
4899 (defsubst gnus-article-sort-by-date (h1 h2)
4900   "Sort articles by root article date."
4901   (time-less-p
4902    (gnus-date-get-time (mail-header-date h1))
4903    (gnus-date-get-time (mail-header-date h2))))
4904
4905 (defun gnus-thread-sort-by-date (h1 h2)
4906   "Sort threads by root article date."
4907   (gnus-article-sort-by-date
4908    (gnus-thread-header h1) (gnus-thread-header h2)))
4909
4910 (defsubst gnus-article-sort-by-score (h1 h2)
4911   "Sort articles by root article score.
4912 Unscored articles will be counted as having a score of zero."
4913   (> (or (cdr (assq (mail-header-number h1)
4914                     gnus-newsgroup-scored))
4915          gnus-summary-default-score 0)
4916      (or (cdr (assq (mail-header-number h2)
4917                     gnus-newsgroup-scored))
4918          gnus-summary-default-score 0)))
4919
4920 (defun gnus-thread-sort-by-score (h1 h2)
4921   "Sort threads by root article score."
4922   (gnus-article-sort-by-score
4923    (gnus-thread-header h1) (gnus-thread-header h2)))
4924
4925 (defun gnus-thread-sort-by-total-score (h1 h2)
4926   "Sort threads by the sum of all scores in the thread.
4927 Unscored articles will be counted as having a score of zero."
4928   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4929
4930 (defun gnus-thread-total-score (thread)
4931   ;; This function find the total score of THREAD.
4932   (cond
4933    ((null thread)
4934     0)
4935    ((consp thread)
4936     (if (stringp (car thread))
4937         (apply gnus-thread-score-function 0
4938                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4939       (gnus-thread-total-score-1 thread)))
4940    (t
4941     (gnus-thread-total-score-1 (list thread)))))
4942
4943 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4944   "Sort threads such that the thread with the most recently arrived article comes first."
4945   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4946
4947 (defun gnus-thread-highest-number (thread)
4948   "Return the highest article number in THREAD."
4949   (apply 'max (mapcar (lambda (header)
4950                         (mail-header-number header))
4951                       (message-flatten-list thread))))
4952
4953 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4954   "Sort threads such that the thread with the most recently dated article comes first."
4955   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4956
4957 (defun gnus-thread-latest-date (thread)
4958   "Return the highest article date in THREAD."
4959   (let ((previous-time 0))
4960     (apply 'max
4961            (mapcar
4962             (lambda (header)
4963               (setq previous-time
4964                     (condition-case ()
4965                         (time-to-seconds (mail-header-parse-date
4966                                           (mail-header-date header)))
4967                       (error previous-time))))
4968             (sort
4969              (message-flatten-list thread)
4970              (lambda (h1 h2)
4971                (< (mail-header-number h1)
4972                   (mail-header-number h2))))))))
4973
4974 (defun gnus-thread-total-score-1 (root)
4975   ;; This function find the total score of the thread below ROOT.
4976   (setq root (car root))
4977   (apply gnus-thread-score-function
4978          (or (append
4979               (mapcar 'gnus-thread-total-score
4980                       (cdr (gnus-id-to-thread (mail-header-id root))))
4981               (when (> (mail-header-number root) 0)
4982                 (list (or (cdr (assq (mail-header-number root)
4983                                      gnus-newsgroup-scored))
4984                           gnus-summary-default-score 0))))
4985              (list gnus-summary-default-score)
4986              '(0))))
4987
4988 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4989 (defvar gnus-tmp-prev-subject nil)
4990 (defvar gnus-tmp-false-parent nil)
4991 (defvar gnus-tmp-root-expunged nil)
4992 (defvar gnus-tmp-dummy-line nil)
4993
4994 (defun gnus-extra-header (type &optional header)
4995   "Return the extra header of TYPE."
4996   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4997       ""))
4998
4999 (defvar gnus-tmp-thread-tree-header-string "")
5000
5001 (defcustom gnus-sum-thread-tree-root "> "
5002   "With %B spec, used for the root of a thread.
5003 If nil, use subject instead."
5004   :version "22.1"
5005   :type '(radio (const :format "%v  " nil) string)
5006   :group 'gnus-thread)
5007
5008 (defcustom gnus-sum-thread-tree-false-root "> "
5009   "With %B spec, used for a false root of a thread.
5010 If nil, use subject instead."
5011   :version "22.1"
5012   :type '(radio (const :format "%v  " nil) string)
5013   :group 'gnus-thread)
5014
5015 (defcustom gnus-sum-thread-tree-single-indent ""
5016   "With %B spec, used for a thread with just one message.
5017 If nil, use subject instead."
5018   :version "22.1"
5019   :type '(radio (const :format "%v  " nil) string)
5020   :group 'gnus-thread)
5021
5022 (defcustom gnus-sum-thread-tree-vertical "| "
5023   "With %B spec, used for drawing a vertical line."
5024   :version "22.1"
5025   :type 'string
5026   :group 'gnus-thread)
5027
5028 (defcustom gnus-sum-thread-tree-indent "  "
5029   "With %B spec, used for indenting."
5030   :version "22.1"
5031   :type 'string
5032   :group 'gnus-thread)
5033
5034 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5035   "With %B spec, used for a leaf with brothers."
5036   :version "22.1"
5037   :type 'string
5038   :group 'gnus-thread)
5039
5040 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5041   "With %B spec, used for a leaf without brothers."
5042   :version "22.1"
5043   :type 'string
5044   :group 'gnus-thread)
5045
5046 (defcustom gnus-summary-display-while-building nil
5047   "If non-nil, show and update the summary buffer as it's being built.
5048 If the value is t, update the buffer after every line is inserted.  If
5049 the value is an integer (N), update the display every N lines."
5050   :version "22.1"
5051   :group 'gnus-thread
5052   :type '(choice (const :tag "off" nil)
5053                  number
5054                  (const :tag "frequently" t)))
5055
5056 (defun gnus-summary-prepare-threads (threads)
5057   "Prepare summary buffer from THREADS and indentation LEVEL.
5058 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5059 or a straight list of headers."
5060   (gnus-message 7 "Generating summary...")
5061
5062   (setq gnus-newsgroup-threads threads)
5063   (beginning-of-line)
5064
5065   (let ((gnus-tmp-level 0)
5066         (default-score (or gnus-summary-default-score 0))
5067         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5068         (building-line-count gnus-summary-display-while-building)
5069         (building-count (integerp gnus-summary-display-while-building))
5070         thread number subject stack state gnus-tmp-gathered beg-match
5071         new-roots gnus-tmp-new-adopts thread-end simp-subject
5072         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5073         gnus-tmp-replied gnus-tmp-subject-or-nil
5074         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5075         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5076         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5077         tree-stack)
5078
5079     (setq gnus-tmp-prev-subject nil
5080           gnus-tmp-thread-tree-header-string "")
5081
5082     (if (vectorp (car threads))
5083         ;; If this is a straight (sic) list of headers, then a
5084         ;; threaded summary display isn't required, so we just create
5085         ;; an unthreaded one.
5086         (gnus-summary-prepare-unthreaded threads)
5087
5088       ;; Do the threaded display.
5089
5090       (if gnus-summary-display-while-building
5091           (switch-to-buffer (buffer-name)))
5092       (while (or threads stack gnus-tmp-new-adopts new-roots)
5093
5094         (if (and (= gnus-tmp-level 0)
5095                  (or (not stack)
5096                      (= (caar stack) 0))
5097                  (not gnus-tmp-false-parent)
5098                  (or gnus-tmp-new-adopts new-roots))
5099             (if gnus-tmp-new-adopts
5100                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5101                       thread (list (car gnus-tmp-new-adopts))
5102                       gnus-tmp-header (caar thread)
5103                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5104               (when new-roots
5105                 (setq thread (list (car new-roots))
5106                       gnus-tmp-header (caar thread)
5107                       new-roots (cdr new-roots))))
5108
5109           (if threads
5110               ;; If there are some threads, we do them before the
5111               ;; threads on the stack.
5112               (setq thread threads
5113                     gnus-tmp-header (caar thread))
5114             ;; There were no current threads, so we pop something off
5115             ;; the stack.
5116             (setq state (car stack)
5117                   gnus-tmp-level (car state)
5118                   tree-stack (cadr state)
5119                   thread (caddr state)
5120                   stack (cdr stack)
5121                   gnus-tmp-header (caar thread))))
5122
5123         (setq gnus-tmp-false-parent nil)
5124         (setq gnus-tmp-root-expunged nil)
5125         (setq thread-end nil)
5126
5127         (if (stringp gnus-tmp-header)
5128             ;; The header is a dummy root.
5129             (cond
5130              ((eq gnus-summary-make-false-root 'adopt)
5131               ;; We let the first article adopt the rest.
5132               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5133                                                (cddar thread)))
5134               (setq gnus-tmp-gathered
5135                     (nconc (mapcar
5136                             (lambda (h) (mail-header-number (car h)))
5137                             (cddar thread))
5138                            gnus-tmp-gathered))
5139               (setq thread (cons (list (caar thread)
5140                                        (cadar thread))
5141                                  (cdr thread)))
5142               (setq gnus-tmp-level -1
5143                     gnus-tmp-false-parent t))
5144              ((eq gnus-summary-make-false-root 'empty)
5145               ;; We print adopted articles with empty subject fields.
5146               (setq gnus-tmp-gathered
5147                     (nconc (mapcar
5148                             (lambda (h) (mail-header-number (car h)))
5149                             (cddar thread))
5150                            gnus-tmp-gathered))
5151               (setq gnus-tmp-level -1))
5152              ((eq gnus-summary-make-false-root 'dummy)
5153               ;; We remember that we probably want to output a dummy
5154               ;; root.
5155               (setq gnus-tmp-dummy-line gnus-tmp-header)
5156               (setq gnus-tmp-prev-subject gnus-tmp-header))
5157              (t
5158               ;; We do not make a root for the gathered
5159               ;; sub-threads at all.
5160               (setq gnus-tmp-level -1)))
5161
5162           (setq number (mail-header-number gnus-tmp-header)
5163                 subject (mail-header-subject gnus-tmp-header)
5164                 simp-subject (gnus-simplify-subject-fully subject))
5165
5166           (cond
5167            ;; If the thread has changed subject, we might want to make
5168            ;; this subthread into a root.
5169            ((and (null gnus-thread-ignore-subject)
5170                  (not (zerop gnus-tmp-level))
5171                  gnus-tmp-prev-subject
5172                  (not (string= gnus-tmp-prev-subject simp-subject)))
5173             (setq new-roots (nconc new-roots (list (car thread)))
5174                   thread-end t
5175                   gnus-tmp-header nil))
5176            ;; If the article lies outside the current limit,
5177            ;; then we do not display it.
5178            ((not (memq number gnus-newsgroup-limit))
5179             (setq gnus-tmp-gathered
5180                   (nconc (mapcar
5181                           (lambda (h) (mail-header-number (car h)))
5182                           (cdar thread))
5183                          gnus-tmp-gathered))
5184             (setq gnus-tmp-new-adopts (if (cdar thread)
5185                                           (append gnus-tmp-new-adopts
5186                                                   (cdar thread))
5187                                         gnus-tmp-new-adopts)
5188                   thread-end t
5189                   gnus-tmp-header nil)
5190             (when (zerop gnus-tmp-level)
5191               (setq gnus-tmp-root-expunged t)))
5192            ;; Perhaps this article is to be marked as read?
5193            ((and gnus-summary-mark-below
5194                  (< (or (cdr (assq number gnus-newsgroup-scored))
5195                         default-score)
5196                     gnus-summary-mark-below)
5197                  ;; Don't touch sparse articles.
5198                  (not (gnus-summary-article-sparse-p number))
5199                  (not (gnus-summary-article-ancient-p number)))
5200             (setq gnus-newsgroup-unreads
5201                   (delq number gnus-newsgroup-unreads))
5202             (if gnus-newsgroup-auto-expire
5203                 (setq gnus-newsgroup-expirable
5204                       (gnus-add-to-sorted-list
5205                        gnus-newsgroup-expirable number))
5206               (push (cons number gnus-low-score-mark)
5207                     gnus-newsgroup-reads))))
5208
5209           (when gnus-tmp-header
5210             ;; We may have an old dummy line to output before this
5211             ;; article.
5212             (when (and gnus-tmp-dummy-line
5213                        (gnus-subject-equal
5214                         gnus-tmp-dummy-line
5215                         (mail-header-subject gnus-tmp-header)))
5216               (gnus-summary-insert-dummy-line
5217                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5218               (setq gnus-tmp-dummy-line nil))
5219
5220             ;; Compute the mark.
5221             (setq gnus-tmp-unread (gnus-article-mark number))
5222
5223             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5224                                   gnus-tmp-header gnus-tmp-level)
5225                   gnus-newsgroup-data)
5226
5227             ;; Actually insert the line.
5228             (setq
5229              gnus-tmp-subject-or-nil
5230              (cond
5231               ((and gnus-thread-ignore-subject
5232                     gnus-tmp-prev-subject
5233                     (not (string= gnus-tmp-prev-subject simp-subject)))
5234                subject)
5235               ((zerop gnus-tmp-level)
5236                (if (and (eq gnus-summary-make-false-root 'empty)
5237                         (memq number gnus-tmp-gathered)
5238                         gnus-tmp-prev-subject
5239                         (string= gnus-tmp-prev-subject simp-subject))
5240                    gnus-summary-same-subject
5241                  subject))
5242               (t gnus-summary-same-subject)))
5243             (if (and (eq gnus-summary-make-false-root 'adopt)
5244                      (= gnus-tmp-level 1)
5245                      (memq number gnus-tmp-gathered))
5246                 (setq gnus-tmp-opening-bracket ?\<
5247                       gnus-tmp-closing-bracket ?\>)
5248               (setq gnus-tmp-opening-bracket ?\[
5249                     gnus-tmp-closing-bracket ?\]))
5250             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5251                 (gnus-make-thread-indent-array
5252                  (max (* 2 (length gnus-thread-indent-array))
5253                       gnus-tmp-level)))
5254             (setq
5255              gnus-tmp-indentation
5256              (aref gnus-thread-indent-array gnus-tmp-level)
5257              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5258              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5259                                 gnus-summary-default-score 0)
5260              gnus-tmp-score-char
5261              (if (or (null gnus-summary-default-score)
5262                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5263                          gnus-summary-zcore-fuzz))
5264                  ?                      ;Whitespace
5265                (if (< gnus-tmp-score gnus-summary-default-score)
5266                    gnus-score-below-mark gnus-score-over-mark))
5267              gnus-tmp-replied
5268              (cond ((memq number gnus-newsgroup-processable)
5269                     gnus-process-mark)
5270                    ((memq number gnus-newsgroup-cached)
5271                     gnus-cached-mark)
5272                    ((memq number gnus-newsgroup-replied)
5273                     gnus-replied-mark)
5274                    ((memq number gnus-newsgroup-forwarded)
5275                     gnus-forwarded-mark)
5276                    ((memq number gnus-newsgroup-saved)
5277                     gnus-saved-mark)
5278                    ((memq number gnus-newsgroup-recent)
5279                     gnus-recent-mark)
5280                    ((memq number gnus-newsgroup-unseen)
5281                     gnus-unseen-mark)
5282                    (t gnus-no-mark))
5283              gnus-tmp-downloaded
5284              (cond ((memq number gnus-newsgroup-undownloaded)
5285                     gnus-undownloaded-mark)
5286                    (gnus-newsgroup-agentized
5287                     gnus-downloaded-mark)
5288                    (t
5289                     gnus-no-mark))
5290              gnus-tmp-from (mail-header-from gnus-tmp-header)
5291              gnus-tmp-name
5292              (cond
5293               ((string-match "<[^>]+> *$" gnus-tmp-from)
5294                (setq beg-match (match-beginning 0))
5295                (or (and (string-match "^\".+\"" gnus-tmp-from)
5296                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5297                    (substring gnus-tmp-from 0 beg-match)))
5298               ((string-match "(.+)" gnus-tmp-from)
5299                (substring gnus-tmp-from
5300                           (1+ (match-beginning 0)) (1- (match-end 0))))
5301               (t gnus-tmp-from))
5302
5303              ;; Do the %B string
5304              gnus-tmp-thread-tree-header-string
5305              (cond
5306               ((not gnus-show-threads) "")
5307               ((zerop gnus-tmp-level)
5308                (cond ((cdar thread)
5309                       (or gnus-sum-thread-tree-root subject))
5310                      (gnus-tmp-new-adopts
5311                       (or gnus-sum-thread-tree-false-root subject))
5312                      (t
5313                       (or gnus-sum-thread-tree-single-indent subject))))
5314               (t
5315                (concat (apply 'concat
5316                               (mapcar (lambda (item)
5317                                         (if (= item 1)
5318                                             gnus-sum-thread-tree-vertical
5319                                           gnus-sum-thread-tree-indent))
5320                                       (cdr (reverse tree-stack))))
5321                        (if (nth 1 thread)
5322                            gnus-sum-thread-tree-leaf-with-other
5323                          gnus-sum-thread-tree-single-leaf)))))
5324             (when (string= gnus-tmp-name "")
5325               (setq gnus-tmp-name gnus-tmp-from))
5326             (unless (numberp gnus-tmp-lines)
5327               (setq gnus-tmp-lines -1))
5328             (if (= gnus-tmp-lines -1)
5329                 (setq gnus-tmp-lines "?")
5330               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5331               (gnus-put-text-property
5332              (point)
5333              (progn (eval gnus-summary-line-format-spec) (point))
5334                'gnus-number number)
5335             (when gnus-visual-p
5336               (forward-line -1)
5337               (gnus-run-hooks 'gnus-summary-update-hook)
5338               (forward-line 1))
5339
5340             (setq gnus-tmp-prev-subject simp-subject)))
5341
5342         (when (nth 1 thread)
5343           (push (list (max 0 gnus-tmp-level)
5344                       (copy-sequence tree-stack)
5345                       (nthcdr 1 thread))
5346                 stack))
5347         (push (if (nth 1 thread) 1 0) tree-stack)
5348         (incf gnus-tmp-level)
5349         (setq threads (if thread-end nil (cdar thread)))
5350         (if gnus-summary-display-while-building
5351             (if building-count
5352                 (progn
5353                   ;; use a set frequency
5354                   (setq building-line-count (1- building-line-count))
5355                   (when (= building-line-count 0)
5356                     (sit-for 0)
5357                     (setq building-line-count
5358                           gnus-summary-display-while-building)))
5359               ;; always
5360               (sit-for 0)))
5361         (unless threads
5362           (setq gnus-tmp-level 0)))))
5363   (gnus-message 7 "Generating summary...done"))
5364
5365 (defun gnus-summary-prepare-unthreaded (headers)
5366   "Generate an unthreaded summary buffer based on HEADERS."
5367   (let (header number mark)
5368
5369     (beginning-of-line)
5370
5371     (while headers
5372       ;; We may have to root out some bad articles...
5373       (when (memq (setq number (mail-header-number
5374                                 (setq header (pop headers))))
5375                   gnus-newsgroup-limit)
5376         ;; Mark article as read when it has a low score.
5377         (when (and gnus-summary-mark-below
5378                    (< (or (cdr (assq number gnus-newsgroup-scored))
5379                           gnus-summary-default-score 0)
5380                       gnus-summary-mark-below)
5381                    (not (gnus-summary-article-ancient-p number)))
5382           (setq gnus-newsgroup-unreads
5383                 (delq number gnus-newsgroup-unreads))
5384           (if gnus-newsgroup-auto-expire
5385               (push number gnus-newsgroup-expirable)
5386             (push (cons number gnus-low-score-mark)
5387                   gnus-newsgroup-reads)))
5388
5389         (setq mark (gnus-article-mark number))
5390         (push (gnus-data-make number mark (1+ (point)) header 0)
5391               gnus-newsgroup-data)
5392         (gnus-summary-insert-line
5393          header 0 number
5394          (memq number gnus-newsgroup-undownloaded)
5395          mark (memq number gnus-newsgroup-replied)
5396          (memq number gnus-newsgroup-expirable)
5397          (mail-header-subject header) nil
5398          (cdr (assq number gnus-newsgroup-scored))
5399          (memq number gnus-newsgroup-processable))))))
5400
5401 (defun gnus-summary-remove-list-identifiers ()
5402   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5403   (let ((regexp (if (consp gnus-list-identifiers)
5404                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5405                   gnus-list-identifiers))
5406         changed subject)
5407     (when regexp
5408       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5409       (dolist (header gnus-newsgroup-headers)
5410         (setq subject (mail-header-subject header)
5411               changed nil)
5412         (while (string-match regexp subject)
5413           (setq subject
5414                 (concat (substring subject 0 (match-beginning 1))
5415                         (substring subject (match-end 0)))
5416                 changed t))
5417         (when changed
5418           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5419             (setq subject
5420                   (concat (substring subject 0 (match-beginning 1))
5421                           (substring subject (match-end 1)))))
5422           (mail-header-set-subject header subject))))))
5423
5424 (defun gnus-fetch-headers (articles)
5425   "Fetch headers of ARTICLES."
5426   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5427     (gnus-message 5 "Fetching headers for %s..." name)
5428     (prog1
5429         (if (eq 'nov
5430                 (setq gnus-headers-retrieved-by
5431                       (gnus-retrieve-headers
5432                        articles gnus-newsgroup-name
5433                        ;; We might want to fetch old headers, but
5434                        ;; not if there is only 1 article.
5435                        (and (or (and
5436                                  (not (eq gnus-fetch-old-headers 'some))
5437                                  (not (numberp gnus-fetch-old-headers)))
5438                                 (> (length articles) 1))
5439                             gnus-fetch-old-headers))))
5440             (gnus-get-newsgroup-headers-xover
5441              articles nil nil gnus-newsgroup-name t)
5442           (gnus-get-newsgroup-headers))
5443       (gnus-message 5 "Fetching headers for %s...done" name))))
5444
5445 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5446   "Select newsgroup GROUP.
5447 If READ-ALL is non-nil, all articles in the group are selected.
5448 If SELECT-ARTICLES, only select those articles from GROUP."
5449   (let* ((entry (gnus-group-entry group))
5450          ;;!!! Dirty hack; should be removed.
5451          (gnus-summary-ignore-duplicates
5452           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5453               t
5454             gnus-summary-ignore-duplicates))
5455          (info (nth 2 entry))
5456          charset articles fetched-articles cached)
5457
5458     (unless (gnus-check-server
5459              (set (make-local-variable 'gnus-current-select-method)
5460                   (gnus-find-method-for-group group)))
5461       (error "Couldn't open server"))
5462     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5463
5464     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5465         (gnus-activate-group group)     ; Or we can activate it...
5466         (progn                          ; Or we bug out.
5467           (when (equal major-mode 'gnus-summary-mode)
5468             (gnus-kill-buffer (current-buffer)))
5469           (error
5470            "Couldn't activate group %s: %s"
5471            (mm-decode-coding-string group charset)
5472            (mm-decode-coding-string (gnus-status-message group) charset))))
5473
5474     (unless (gnus-request-group group t)
5475         (when (equal major-mode 'gnus-summary-mode)
5476           (gnus-kill-buffer (current-buffer)))
5477         (error "Couldn't request group %s: %s"
5478                (mm-decode-coding-string group charset)
5479                (mm-decode-coding-string (gnus-status-message group) charset)))
5480
5481     (when gnus-agent
5482       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5483
5484       (setq gnus-summary-use-undownloaded-faces
5485             (gnus-agent-find-parameter
5486              group
5487              'agent-enable-undownloaded-faces)))
5488
5489     (setq gnus-newsgroup-name group
5490           gnus-newsgroup-unselected nil
5491           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5492
5493     (let ((display (gnus-group-find-parameter group 'display)))
5494       (setq gnus-newsgroup-display
5495             (cond
5496              ((not (zerop (or (car-safe read-all) 0)))
5497               ;; The user entered the group with C-u SPC/RET, let's show
5498               ;; all articles.
5499               'gnus-not-ignore)
5500              ((eq display 'all)
5501               'gnus-not-ignore)
5502              ((arrayp display)
5503               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5504              ((numberp display)
5505               ;; The following is probably the "correct" solution, but
5506               ;; it makes Gnus fetch all headers and then limit the
5507               ;; articles (which is slow), so instead we hack the
5508               ;; select-articles parameter instead. -- Simon Josefsson
5509               ;; <jas@kth.se>
5510               ;;
5511               ;; (gnus-byte-compile
5512               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5513               ;;                         display)))))
5514               (setq select-articles
5515                     (gnus-uncompress-range
5516                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5517                              (if (> tmp 0)
5518                                  tmp
5519                                1))
5520                            (cdr (gnus-active group)))))
5521               nil)
5522              (t
5523               nil))))
5524
5525     (gnus-summary-setup-default-charset)
5526
5527     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5528     (when (gnus-virtual-group-p group)
5529       (setq cached gnus-newsgroup-cached))
5530
5531     (setq gnus-newsgroup-unreads
5532           (gnus-sorted-ndifference
5533            (gnus-sorted-ndifference gnus-newsgroup-unreads
5534                                     gnus-newsgroup-marked)
5535            gnus-newsgroup-dormant))
5536
5537     (setq gnus-newsgroup-processable nil)
5538
5539     (gnus-update-read-articles group gnus-newsgroup-unreads)
5540
5541     ;; Adjust and set lists of article marks.
5542     (when info
5543       (gnus-adjust-marked-articles info))
5544     (if (setq articles select-articles)
5545         (setq gnus-newsgroup-unselected
5546               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5547       (setq articles (gnus-articles-to-read group read-all)))
5548
5549     (cond
5550      ((null articles)
5551       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5552       'quit)
5553      ((eq articles 0) nil)
5554      (t
5555       ;; Init the dependencies hash table.
5556       (setq gnus-newsgroup-dependencies
5557             (gnus-make-hashtable (length articles)))
5558       (gnus-set-global-variables)
5559       ;; Retrieve the headers and read them in.
5560
5561       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5562
5563       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5564       (when cached
5565         (setq gnus-newsgroup-cached cached))
5566
5567       ;; Suppress duplicates?
5568       (when gnus-suppress-duplicates
5569         (gnus-dup-suppress-articles))
5570
5571       ;; Set the initial limit.
5572       (setq gnus-newsgroup-limit (copy-sequence articles))
5573       ;; Remove canceled articles from the list of unread articles.
5574       (setq fetched-articles
5575             (mapcar (lambda (headers) (mail-header-number headers))
5576                     gnus-newsgroup-headers))
5577       (setq gnus-newsgroup-articles fetched-articles)
5578       (setq gnus-newsgroup-unreads
5579             (gnus-sorted-nintersection
5580              gnus-newsgroup-unreads fetched-articles))
5581       (gnus-compute-unseen-list)
5582
5583       ;; Removed marked articles that do not exist.
5584       (gnus-update-missing-marks
5585        (gnus-sorted-difference articles fetched-articles))
5586       ;; We might want to build some more threads first.
5587       (when (and gnus-fetch-old-headers
5588                  (eq gnus-headers-retrieved-by 'nov))
5589         (if (eq gnus-fetch-old-headers 'invisible)
5590             (gnus-build-all-threads)
5591           (gnus-build-old-threads)))
5592       ;; Let the Gnus agent mark articles as read.
5593       (when gnus-agent
5594         (gnus-agent-get-undownloaded-list))
5595       ;; Remove list identifiers from subject
5596       (when gnus-list-identifiers
5597         (gnus-summary-remove-list-identifiers))
5598       ;; Check whether auto-expire is to be done in this group.
5599       (setq gnus-newsgroup-auto-expire
5600             (gnus-group-auto-expirable-p group))
5601       ;; Set up the article buffer now, if necessary.
5602       (unless (and gnus-single-article-buffer
5603                    (equal gnus-article-buffer "*Article*"))
5604         (gnus-article-setup-buffer))
5605       ;; First and last article in this newsgroup.
5606       (when gnus-newsgroup-headers
5607         (setq gnus-newsgroup-begin
5608               (mail-header-number (car gnus-newsgroup-headers))
5609               gnus-newsgroup-end
5610               (mail-header-number
5611                (gnus-last-element gnus-newsgroup-headers))))
5612       ;; GROUP is successfully selected.
5613       (or gnus-newsgroup-headers t)))))
5614
5615 (defun gnus-compute-unseen-list ()
5616   ;; The `seen' marks are treated specially.
5617   (if (not gnus-newsgroup-seen)
5618       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5619     (setq gnus-newsgroup-unseen
5620           (gnus-inverse-list-range-intersection
5621            gnus-newsgroup-articles gnus-newsgroup-seen))))
5622
5623 (declare-function gnus-get-predicate "gnus-agent" (predicate))
5624
5625 (defun gnus-summary-display-make-predicate (display)
5626   (require 'gnus-agent)
5627   (when (= (length display) 1)
5628     (setq display (car display)))
5629   (unless gnus-summary-display-cache
5630     (dolist (elem (append '((unread . unread)
5631                             (read . read)
5632                             (unseen . unseen))
5633                           gnus-article-mark-lists))
5634       (push (cons (cdr elem)
5635                   (gnus-byte-compile
5636                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5637             gnus-summary-display-cache)))
5638   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5639         (gnus-category-predicate-cache gnus-summary-display-cache))
5640     (gnus-get-predicate display)))
5641
5642 ;; Uses the dynamically bound `number' variable.
5643 (defvar number)
5644 (defun gnus-article-marked-p (type &optional article)
5645   (let ((article (or article number)))
5646     (cond
5647      ((eq type 'tick)
5648       (memq article gnus-newsgroup-marked))
5649      ((eq type 'spam)
5650       (memq article gnus-newsgroup-spam-marked))
5651      ((eq type 'unsend)
5652       (memq article gnus-newsgroup-unsendable))
5653      ((eq type 'undownload)
5654       (memq article gnus-newsgroup-undownloaded))
5655      ((eq type 'download)
5656       (memq article gnus-newsgroup-downloadable))
5657      ((eq type 'unread)
5658       (memq article gnus-newsgroup-unreads))
5659      ((eq type 'read)
5660       (memq article gnus-newsgroup-reads))
5661      ((eq type 'dormant)
5662       (memq article gnus-newsgroup-dormant) )
5663      ((eq type 'expire)
5664       (memq article gnus-newsgroup-expirable))
5665      ((eq type 'reply)
5666       (memq article gnus-newsgroup-replied))
5667      ((eq type 'killed)
5668       (memq article gnus-newsgroup-killed))
5669      ((eq type 'bookmark)
5670       (assq article gnus-newsgroup-bookmarks))
5671      ((eq type 'score)
5672       (assq article gnus-newsgroup-scored))
5673      ((eq type 'save)
5674       (memq article gnus-newsgroup-saved))
5675      ((eq type 'cache)
5676       (memq article gnus-newsgroup-cached))
5677      ((eq type 'forward)
5678       (memq article gnus-newsgroup-forwarded))
5679      ((eq type 'seen)
5680       (not (memq article gnus-newsgroup-unseen)))
5681      ((eq type 'recent)
5682       (memq article gnus-newsgroup-recent))
5683      (t t))))
5684
5685 (defun gnus-articles-to-read (group &optional read-all)
5686   "Find out what articles the user wants to read."
5687   (let* ((articles
5688           ;; Select all articles if `read-all' is non-nil, or if there
5689           ;; are no unread articles.
5690           (if (or read-all
5691                   (and (zerop (length gnus-newsgroup-marked))
5692                        (zerop (length gnus-newsgroup-unreads)))
5693                   ;; Fetch all if the predicate is non-nil.
5694                   gnus-newsgroup-display)
5695               ;; We want to select the headers for all the articles in
5696               ;; the group, so we select either all the active
5697               ;; articles in the group, or (if that's nil), the
5698               ;; articles in the cache.
5699               (or
5700                (if gnus-newsgroup-maximum-articles
5701                    (let ((active (gnus-active group)))
5702                      (gnus-uncompress-range
5703                       (cons (max (car active)
5704                                  (- (cdr active)
5705                                     gnus-newsgroup-maximum-articles
5706                                     -1))
5707                             (cdr active))))
5708                  (gnus-uncompress-range (gnus-active group)))
5709                (gnus-cache-articles-in-group group))
5710             ;; Select only the "normal" subset of articles.
5711             (gnus-sorted-nunion
5712              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5713              gnus-newsgroup-unreads)))
5714          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5715          (scored (length scored-list))
5716          (number (length articles))
5717          (marked (+ (length gnus-newsgroup-marked)
5718                     (length gnus-newsgroup-dormant)))
5719          (select
5720           (cond
5721            ((numberp read-all)
5722             read-all)
5723            ((numberp gnus-newsgroup-display)
5724             gnus-newsgroup-display)
5725            (t
5726             (condition-case ()
5727                 (cond
5728                  ((and (or (<= scored marked) (= scored number))
5729                        (numberp gnus-large-newsgroup)
5730                        (> number gnus-large-newsgroup))
5731                   (let* ((cursor-in-echo-area nil)
5732                          (initial (gnus-parameter-large-newsgroup-initial
5733                                    gnus-newsgroup-name))
5734                          (input
5735                           (read-string
5736                            (format
5737                             "How many articles from %s (%s %d): "
5738                             (gnus-group-decoded-name gnus-newsgroup-name)
5739                             (if initial "max" "default")
5740                             number)
5741                            (if initial
5742                                (cons (number-to-string initial)
5743                                      0)))))
5744                     (if (string-match "^[ \t]*$" input) number input)))
5745                  ((and (> scored marked) (< scored number)
5746                        (> (- scored number) 20))
5747                   (let ((input
5748                          (read-string
5749                           (format "%s %s (%d scored, %d total): "
5750                                   "How many articles from"
5751                                   (gnus-group-decoded-name group)
5752                                   scored number))))
5753                     (if (string-match "^[ \t]*$" input)
5754                         number input)))
5755                  (t number))
5756               (quit
5757                (message "Quit getting the articles to read")
5758                nil))))))
5759     (setq select (if (stringp select) (string-to-number select) select))
5760     (if (or (null select) (zerop select))
5761         select
5762       (if (and (not (zerop scored)) (<= (abs select) scored))
5763           (progn
5764             (setq articles (sort scored-list '<))
5765             (setq number (length articles)))
5766         (setq articles (copy-sequence articles)))
5767
5768       (when (< (abs select) number)
5769         (if (< select 0)
5770             ;; Select the N oldest articles.
5771             (setcdr (nthcdr (1- (abs select)) articles) nil)
5772           ;; Select the N most recent articles.
5773           (setq articles (nthcdr (- number select) articles))))
5774       (setq gnus-newsgroup-unselected
5775             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5776       (when gnus-alter-articles-to-read-function
5777         (setq articles
5778               (sort
5779                (funcall gnus-alter-articles-to-read-function
5780                         gnus-newsgroup-name articles)
5781                '<)))
5782       articles)))
5783
5784 (defun gnus-killed-articles (killed articles)
5785   (let (out)
5786     (while articles
5787       (when (inline (gnus-member-of-range (car articles) killed))
5788         (push (car articles) out))
5789       (setq articles (cdr articles)))
5790     out))
5791
5792 (defun gnus-uncompress-marks (marks)
5793   "Uncompress the mark ranges in MARKS."
5794   (let ((uncompressed '(score bookmark))
5795         out)
5796     (while marks
5797       (if (memq (caar marks) uncompressed)
5798           (push (car marks) out)
5799         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5800       (setq marks (cdr marks)))
5801     out))
5802
5803 (defun gnus-article-mark-to-type (mark)
5804   "Return the type of MARK."
5805   (or (cadr (assq mark gnus-article-special-mark-lists))
5806       'list))
5807
5808 (defun gnus-article-unpropagatable-p (mark)
5809   "Return whether MARK should be propagated to back end."
5810   (memq mark gnus-article-unpropagated-mark-lists))
5811
5812 (defun gnus-adjust-marked-articles (info)
5813   "Set all article lists and remove all marks that are no longer valid."
5814   (let* ((marked-lists (gnus-info-marks info))
5815          (active (gnus-active (gnus-info-group info)))
5816          (min (car active))
5817          (max (cdr active))
5818          (types gnus-article-mark-lists)
5819          marks var articles article mark mark-type
5820          bgn end)
5821
5822     (dolist (marks marked-lists)
5823       (setq mark (car marks)
5824             mark-type (gnus-article-mark-to-type mark)
5825             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5826
5827       ;; We set the variable according to the type of the marks list,
5828       ;; and then adjust the marks to a subset of the active articles.
5829       (cond
5830        ;; Adjust "simple" lists - compressed yet unsorted
5831        ((eq mark-type 'list)
5832         ;; Simultaneously uncompress and clip to active range
5833         ;; See gnus-uncompress-range for a description of possible marks
5834         (let (l lh)
5835           (if (not (cadr marks))
5836               (set var nil)
5837             (setq articles (if (numberp (cddr marks))
5838                                (list (cdr marks))
5839                              (cdr marks))
5840                   lh (cons nil nil)
5841                   l lh)
5842
5843             (while (setq article (pop articles))
5844               (cond ((consp article)
5845                      (setq bgn (max (car article) min)
5846                            end (min (cdr article) max))
5847                      (while (<= bgn end)
5848                        (setq l (setcdr l (cons bgn nil))
5849                              bgn (1+ bgn))))
5850                     ((and (<= min article)
5851                           (>= max article))
5852                      (setq l (setcdr l (cons article nil))))))
5853             (set var (cdr lh)))))
5854        ;; Adjust assocs.
5855        ((eq mark-type 'tuple)
5856         (set var (setq articles (cdr marks)))
5857         (when (not (listp (cdr (symbol-value var))))
5858           (set var (list (symbol-value var))))
5859         (when (not (listp (cdr articles)))
5860           (setq articles (list articles)))
5861         (while articles
5862           (when (or (not (consp (setq article (pop articles))))
5863                     (< (car article) min)
5864                     (> (car article) max))
5865             (set var (delq article (symbol-value var))))))
5866        ;; Adjust ranges (sloppily).
5867        ((eq mark-type 'range)
5868         (cond
5869          ((eq mark 'seen)
5870           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5871           ;; It should be (seen (NUM1 . NUM2)).
5872           (when (numberp (cddr marks))
5873             (setcdr marks (list (cdr marks))))
5874           (setq articles (cdr marks))
5875           (while (and articles
5876                       (or (and (consp (car articles))
5877                                (> min (cdar articles)))
5878                           (and (numberp (car articles))
5879                                (> min (car articles)))))
5880             (pop articles))
5881           (set var articles))))))))
5882
5883 (defun gnus-update-missing-marks (missing)
5884   "Go through the list of MISSING articles and remove them from the mark lists."
5885   (when missing
5886     (let (var m)
5887       ;; Go through all types.
5888       (dolist (elem gnus-article-mark-lists)
5889         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5890           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5891           (when (symbol-value var)
5892             ;; This list has articles.  So we delete all missing
5893             ;; articles from it.
5894             (setq m missing)
5895             (while m
5896               (set var (delq (pop m) (symbol-value var))))))))))
5897
5898 (defun gnus-update-marks ()
5899   "Enter the various lists of marked articles into the newsgroup info list."
5900   (let ((types gnus-article-mark-lists)
5901         (info (gnus-get-info gnus-newsgroup-name))
5902         type list newmarked symbol delta-marks)
5903     (when info
5904       ;; Add all marks lists to the list of marks lists.
5905       (while (setq type (pop types))
5906         (setq list (symbol-value
5907                     (setq symbol
5908                           (intern (format "gnus-newsgroup-%s" (car type))))))
5909
5910         (when list
5911           ;; Get rid of the entries of the articles that have the
5912           ;; default score.
5913           (when (and (eq (cdr type) 'score)
5914                      gnus-save-score
5915                      list)
5916             (let* ((arts list)
5917                    (prev (cons nil list))
5918                    (all prev))
5919               (while arts
5920                 (if (or (not (consp (car arts)))
5921                         (= (cdar arts) gnus-summary-default-score))
5922                     (setcdr prev (cdr arts))
5923                   (setq prev arts))
5924                 (setq arts (cdr arts)))
5925               (setq list (cdr all)))))
5926
5927         (when (eq (cdr type) 'seen)
5928           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5929
5930         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5931           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5932
5933         (when (and (gnus-check-backend-function
5934                     'request-set-mark gnus-newsgroup-name)
5935                    (not (gnus-article-unpropagatable-p (cdr type))))
5936           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5937                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5938                  (add (gnus-remove-from-range
5939                        (gnus-copy-sequence list) old)))
5940             (when add
5941               (push (list add 'add (list (cdr type))) delta-marks))
5942             (when del
5943               (push (list del 'del (list (cdr type))) delta-marks))))
5944
5945         (when list
5946           (push (cons (cdr type) list) newmarked)))
5947
5948       (when delta-marks
5949         (unless (gnus-check-group gnus-newsgroup-name)
5950           (error "Can't open server for %s" gnus-newsgroup-name))
5951         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5952
5953       ;; Enter these new marks into the info of the group.
5954       (if (nthcdr 3 info)
5955           (setcar (nthcdr 3 info) newmarked)
5956         ;; Add the marks lists to the end of the info.
5957         (when newmarked
5958           (setcdr (nthcdr 2 info) (list newmarked))))
5959
5960       ;; Cut off the end of the info if there's nothing else there.
5961       (let ((i 5))
5962         (while (and (> i 2)
5963                     (not (nth i info)))
5964           (when (nthcdr (decf i) info)
5965             (setcdr (nthcdr i info) nil)))))))
5966
5967 (defun gnus-set-mode-line (where)
5968   "Set the mode line of the article or summary buffers.
5969 If WHERE is `summary', the summary mode line format will be used."
5970   ;; Is this mode line one we keep updated?
5971   (when (and (memq where gnus-updated-mode-lines)
5972              (symbol-value
5973               (intern (format "gnus-%s-mode-line-format-spec" where))))
5974     (let (mode-string)
5975       ;; We evaluate this in the summary buffer since these
5976       ;; variables are buffer-local to that buffer.
5977       (with-current-buffer gnus-summary-buffer
5978         ;; We bind all these variables that are used in the `eval' form
5979         ;; below.
5980         (let* ((mformat (symbol-value
5981                          (intern
5982                           (format "gnus-%s-mode-line-format-spec" where))))
5983                (gnus-tmp-group-name (gnus-mode-string-quote
5984                                      (gnus-group-decoded-name
5985                                       gnus-newsgroup-name)))
5986                (gnus-tmp-article-number (or gnus-current-article 0))
5987                (gnus-tmp-unread gnus-newsgroup-unreads)
5988                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5989                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5990                (gnus-tmp-unread-and-unselected
5991                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5992                             (zerop gnus-tmp-unselected))
5993                        "")
5994                       ((zerop gnus-tmp-unselected)
5995                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5996                       (t (format "{%d(+%d) more}"
5997                                  gnus-tmp-unread-and-unticked
5998                                  gnus-tmp-unselected))))
5999                (gnus-tmp-subject
6000                 (if (and gnus-current-headers
6001                          (vectorp gnus-current-headers))
6002                     (gnus-mode-string-quote
6003                      (mail-header-subject gnus-current-headers))
6004                   ""))
6005                bufname-length max-len
6006                gnus-tmp-header) ;; passed as argument to any user-format-funcs
6007           (setq mode-string (eval mformat))
6008           (setq bufname-length (if (string-match "%b" mode-string)
6009                                    (- (length
6010                                        (buffer-name
6011                                         (if (eq where 'summary)
6012                                             nil
6013                                           (get-buffer gnus-article-buffer))))
6014                                       2)
6015                                  0))
6016           (setq max-len (max 4 (if gnus-mode-non-string-length
6017                                    (- (window-width)
6018                                       gnus-mode-non-string-length
6019                                       bufname-length)
6020                                  (length mode-string))))
6021           ;; We might have to chop a bit of the string off...
6022           (when (> (length mode-string) max-len)
6023             (setq mode-string
6024                   (concat (truncate-string-to-width mode-string (- max-len 3))
6025                           "...")))
6026           ;; Pad the mode string a bit.
6027           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
6028       ;; Update the mode line.
6029       (setq mode-line-buffer-identification
6030             (gnus-mode-line-buffer-identification (list mode-string)))
6031       (set-buffer-modified-p t))))
6032
6033 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
6034   "Go through the HEADERS list and add all Xrefs to a hash table.
6035 The resulting hash table is returned, or nil if no Xrefs were found."
6036   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
6037          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
6038          (xref-hashtb (gnus-make-hashtable))
6039          start group entry number xrefs header)
6040     (while headers
6041       (setq header (pop headers))
6042       (when (and (setq xrefs (mail-header-xref header))
6043                  (not (memq (setq number (mail-header-number header))
6044                             unreads)))
6045         (setq start 0)
6046         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6047           (setq start (match-end 0))
6048           (setq group (if prefix
6049                           (concat prefix (substring xrefs (match-beginning 1)
6050                                                     (match-end 1)))
6051                         (substring xrefs (match-beginning 1) (match-end 1))))
6052           (setq number
6053                 (string-to-number (substring xrefs (match-beginning 2)
6054                                           (match-end 2))))
6055           (if (setq entry (gnus-gethash group xref-hashtb))
6056               (setcdr entry (cons number (cdr entry)))
6057             (gnus-sethash group (cons number nil) xref-hashtb)))))
6058     (and start xref-hashtb)))
6059
6060 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6061   "Look through all the headers and mark the Xrefs as read."
6062   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6063         name info xref-hashtb idlist method nth4)
6064     (save-excursion
6065       (set-buffer gnus-group-buffer)
6066       (when (setq xref-hashtb
6067                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6068         (mapatoms
6069          (lambda (group)
6070            (unless (string= from-newsgroup (setq name (symbol-name group)))
6071              (setq idlist (symbol-value group))
6072              ;; Dead groups are not updated.
6073              (and (prog1
6074                       (setq info (gnus-get-info name))
6075                     (when (stringp (setq nth4 (gnus-info-method info)))
6076                       (setq nth4 (gnus-server-to-method nth4))))
6077                   ;; Only do the xrefs if the group has the same
6078                   ;; select method as the group we have just read.
6079                   (or (gnus-methods-equal-p
6080                        nth4 (gnus-find-method-for-group from-newsgroup))
6081                       virtual
6082                       (equal nth4 (setq method (gnus-find-method-for-group
6083                                                 from-newsgroup)))
6084                       (and (equal (car nth4) (car method))
6085                            (equal (nth 1 nth4) (nth 1 method))))
6086                   gnus-use-cross-reference
6087                   (or (not (eq gnus-use-cross-reference t))
6088                       virtual
6089                       ;; Only do cross-references on subscribed
6090                       ;; groups, if that is what is wanted.
6091                       (<= (gnus-info-level info) gnus-level-subscribed))
6092                   (gnus-group-make-articles-read name idlist))))
6093          xref-hashtb)))))
6094
6095 (defun gnus-compute-read-articles (group articles)
6096   (let* ((entry (gnus-group-entry group))
6097          (info (nth 2 entry))
6098          (active (gnus-active group))
6099          ninfo)
6100     (when entry
6101       ;; First peel off all invalid article numbers.
6102       (when active
6103         (let ((ids articles)
6104               id first)
6105           (while (setq id (pop ids))
6106             (when (and first (> id (cdr active)))
6107               ;; We'll end up in this situation in one particular
6108               ;; obscure situation.  If you re-scan a group and get
6109               ;; a new article that is cross-posted to a different
6110               ;; group that has not been re-scanned, you might get
6111               ;; crossposted article that has a higher number than
6112               ;; Gnus believes possible.  So we re-activate this
6113               ;; group as well.  This might mean doing the
6114               ;; crossposting thingy will *increase* the number
6115               ;; of articles in some groups.  Tsk, tsk.
6116               (setq active (or (gnus-activate-group group) active)))
6117             (when (or (> id (cdr active))
6118                       (< id (car active)))
6119               (setq articles (delq id articles))))))
6120       ;; If the read list is nil, we init it.
6121       (if (and active
6122                (null (gnus-info-read info))
6123                (> (car active) 1))
6124           (setq ninfo (cons 1 (1- (car active))))
6125         (setq ninfo (gnus-info-read info)))
6126       ;; Then we add the read articles to the range.
6127       (gnus-add-to-range
6128        ninfo (setq articles (sort articles '<))))))
6129
6130 (defun gnus-group-make-articles-read (group articles)
6131   "Update the info of GROUP to say that ARTICLES are read."
6132   (let* ((num 0)
6133          (entry (gnus-group-entry group))
6134          (info (nth 2 entry))
6135          (active (gnus-active group))
6136          range)
6137     (when entry
6138       (setq range (gnus-compute-read-articles group articles))
6139       (with-current-buffer gnus-group-buffer
6140         (gnus-undo-register
6141           `(progn
6142              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6143              (gnus-info-set-read ',info ',(gnus-info-read info))
6144              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6145              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6146              (gnus-group-update-group ,group t))))
6147       ;; Add the read articles to the range.
6148       (gnus-info-set-read info range)
6149       (gnus-request-set-mark group (list (list range 'add '(read))))
6150       ;; Then we have to re-compute how many unread
6151       ;; articles there are in this group.
6152       (when active
6153         (cond
6154          ((not range)
6155           (setq num (- (1+ (cdr active)) (car active))))
6156          ((not (listp (cdr range)))
6157           (setq num (- (cdr active) (- (1+ (cdr range))
6158                                        (car range)))))
6159          (t
6160           (while range
6161             (if (numberp (car range))
6162                 (setq num (1+ num))
6163               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6164             (setq range (cdr range)))
6165           (setq num (- (cdr active) num))))
6166         ;; Update the number of unread articles.
6167         (setcar entry num)
6168         ;; Update the group buffer.
6169         (unless (gnus-ephemeral-group-p group)
6170           (gnus-group-update-group group t))))))
6171
6172 (defvar gnus-newsgroup-none-id 0)
6173
6174 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6175   (let ((cur nntp-server-buffer)
6176         (dependencies
6177          (or dependencies
6178              (with-current-buffer gnus-summary-buffer
6179                gnus-newsgroup-dependencies)))
6180         headers id end ref number
6181         (mail-parse-charset gnus-newsgroup-charset)
6182         (mail-parse-ignored-charsets
6183          (save-current-buffer (condition-case nil
6184                                   (set-buffer gnus-summary-buffer)
6185                                 (error))
6186                               gnus-newsgroup-ignored-charsets)))
6187     (with-current-buffer nntp-server-buffer
6188       ;; Translate all TAB characters into SPACE characters.
6189       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6190       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6191       (ietf-drums-unfold-fws)
6192       (gnus-run-hooks 'gnus-parse-headers-hook)
6193       (let ((case-fold-search t)
6194             in-reply-to header p lines chars)
6195         (goto-char (point-min))
6196         ;; Search to the beginning of the next header.  Error messages
6197         ;; do not begin with 2 or 3.
6198         (while (re-search-forward "^[23][0-9]+ " nil t)
6199           (setq id nil
6200                 ref nil)
6201           ;; This implementation of this function, with nine
6202           ;; search-forwards instead of the one re-search-forward and
6203           ;; a case (which basically was the old function) is actually
6204           ;; about twice as fast, even though it looks messier.  You
6205           ;; can't have everything, I guess.  Speed and elegance
6206           ;; doesn't always go hand in hand.
6207           (setq
6208            header
6209            (vector
6210             ;; Number.
6211             (prog1
6212                 (setq number (read cur))
6213               (end-of-line)
6214               (setq p (point))
6215               (narrow-to-region (point)
6216                                 (or (and (search-forward "\n.\n" nil t)
6217                                          (- (point) 2))
6218                                     (point))))
6219             ;; Subject.
6220             (progn
6221               (goto-char p)
6222               (if (search-forward "\nsubject:" nil t)
6223                   (funcall gnus-decode-encoded-word-function
6224                            (nnheader-header-value))
6225                 "(none)"))
6226             ;; From.
6227             (progn
6228               (goto-char p)
6229               (if (search-forward "\nfrom:" nil t)
6230                   (funcall gnus-decode-encoded-address-function
6231                            (nnheader-header-value))
6232                 "(nobody)"))
6233             ;; Date.
6234             (progn
6235               (goto-char p)
6236               (if (search-forward "\ndate:" nil t)
6237                   (nnheader-header-value) ""))
6238             ;; Message-ID.
6239             (progn
6240               (goto-char p)
6241               (setq id (if (re-search-forward
6242                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6243                            ;; We do it this way to make sure the Message-ID
6244                            ;; is (somewhat) syntactically valid.
6245                            (buffer-substring (match-beginning 1)
6246                                              (match-end 1))
6247                          ;; If there was no message-id, we just fake one
6248                          ;; to make subsequent routines simpler.
6249                          (nnheader-generate-fake-message-id number))))
6250             ;; References.
6251             (progn
6252               (goto-char p)
6253               (if (search-forward "\nreferences:" nil t)
6254                   (progn
6255                     (setq end (point))
6256                     (prog1
6257                         (nnheader-header-value)
6258                       (setq ref
6259                             (buffer-substring
6260                              (progn
6261                                (end-of-line)
6262                                (search-backward ">" end t)
6263                                (1+ (point)))
6264                              (progn
6265                                (search-backward "<" end t)
6266                                (point))))))
6267                 ;; Get the references from the in-reply-to header if there
6268                 ;; were no references and the in-reply-to header looks
6269                 ;; promising.
6270                 (if (and (search-forward "\nin-reply-to:" nil t)
6271                          (setq in-reply-to (nnheader-header-value))
6272                          (string-match "<[^>]+>" in-reply-to))
6273                     (let (ref2)
6274                       (setq ref (substring in-reply-to (match-beginning 0)
6275                                            (match-end 0)))
6276                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6277                         (setq ref2 (substring in-reply-to (match-beginning 0)
6278                                               (match-end 0)))
6279                         (when (> (length ref2) (length ref))
6280                           (setq ref ref2)))
6281                       ref)
6282                   (setq ref nil))))
6283             ;; Chars.
6284             (progn
6285               (goto-char p)
6286               (if (search-forward "\nchars: " nil t)
6287                   (if (numberp (setq chars (ignore-errors (read cur))))
6288                       chars -1)
6289                 -1))
6290             ;; Lines.
6291             (progn
6292               (goto-char p)
6293               (if (search-forward "\nlines: " nil t)
6294                   (if (numberp (setq lines (ignore-errors (read cur))))
6295                       lines -1)
6296                 -1))
6297             ;; Xref.
6298             (progn
6299               (goto-char p)
6300               (and (search-forward "\nxref:" nil t)
6301                    (nnheader-header-value)))
6302             ;; Extra.
6303             (when gnus-extra-headers
6304               (let ((extra gnus-extra-headers)
6305                     out)
6306                 (while extra
6307                   (goto-char p)
6308                   (when (search-forward
6309                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6310                     (push (cons (car extra) (nnheader-header-value))
6311                           out))
6312                   (pop extra))
6313                 out))))
6314           (when (equal id ref)
6315             (setq ref nil))
6316
6317           (when gnus-alter-header-function
6318             (funcall gnus-alter-header-function header)
6319             (setq id (mail-header-id header)
6320                   ref (gnus-parent-id (mail-header-references header))))
6321
6322           (when (setq header
6323                       (gnus-dependencies-add-header
6324                        header dependencies force-new))
6325             (push header headers))
6326           (goto-char (point-max))
6327           (widen))
6328         (nreverse headers)))))
6329
6330 ;; Goes through the xover lines and returns a list of vectors
6331 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6332                                                   force-new dependencies
6333                                                   group also-fetch-heads)
6334   "Parse the news overview data in the server buffer.
6335 Return a list of headers that match SEQUENCE (see
6336 `nntp-retrieve-headers')."
6337   ;; Get the Xref when the users reads the articles since most/some
6338   ;; NNTP servers do not include Xrefs when using XOVER.
6339   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6340   (let ((mail-parse-charset gnus-newsgroup-charset)
6341         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6342         (cur nntp-server-buffer)
6343         (dependencies (or dependencies gnus-newsgroup-dependencies))
6344         (allp (cond
6345                ((eq gnus-read-all-available-headers t)
6346                 t)
6347                ((and (stringp gnus-read-all-available-headers)
6348                      group)
6349                 (string-match gnus-read-all-available-headers group))
6350                (t
6351                 nil)))
6352         number headers header)
6353     (with-current-buffer nntp-server-buffer
6354       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6355       ;; Allow the user to mangle the headers before parsing them.
6356       (gnus-run-hooks 'gnus-parse-headers-hook)
6357       (goto-char (point-min))
6358       (gnus-parse-without-error
6359         (while (and (or sequence allp)
6360                     (not (eobp)))
6361           (setq number (read cur))
6362           (when (not allp)
6363             (while (and sequence
6364                         (< (car sequence) number))
6365               (setq sequence (cdr sequence))))
6366           (when (and (or allp
6367                          (and sequence
6368                               (eq number (car sequence))))
6369                      (progn
6370                        (setq sequence (cdr sequence))
6371                        (setq header (inline
6372                                       (gnus-nov-parse-line
6373                                        number dependencies force-new)))))
6374             (push header headers))
6375           (forward-line 1)))
6376       ;; A common bug in inn is that if you have posted an article and
6377       ;; then retrieves the active file, it will answer correctly --
6378       ;; the new article is included.  However, a NOV entry for the
6379       ;; article may not have been generated yet, so this may fail.
6380       ;; We work around this problem by retrieving the last few
6381       ;; headers using HEAD.
6382       (if (or (not also-fetch-heads)
6383               (not sequence))
6384           ;; We (probably) got all the headers.
6385           (nreverse headers)
6386         (let ((gnus-nov-is-evil t))
6387           (nconc
6388            (nreverse headers)
6389            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6390              (gnus-get-newsgroup-headers))))))))
6391
6392 (defun gnus-article-get-xrefs ()
6393   "Fill in the Xref value in `gnus-current-headers', if necessary.
6394 This is meant to be called in `gnus-article-internal-prepare-hook'."
6395   (let ((headers (with-current-buffer gnus-summary-buffer
6396                    gnus-current-headers)))
6397     (or (not gnus-use-cross-reference)
6398         (not headers)
6399         (and (mail-header-xref headers)
6400              (not (string= (mail-header-xref headers) "")))
6401         (let ((case-fold-search t)
6402               xref)
6403           (save-restriction
6404             (nnheader-narrow-to-headers)
6405             (goto-char (point-min))
6406             (when (or (and (not (eobp))
6407                            (eq (downcase (char-after)) ?x)
6408                            (looking-at "Xref:"))
6409                       (search-forward "\nXref:" nil t))
6410               (goto-char (1+ (match-end 0)))
6411               (setq xref (buffer-substring (point) (point-at-eol)))
6412               (mail-header-set-xref headers xref)))))))
6413
6414 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6415   "Find article ID and insert the summary line for that article.
6416 OLD-HEADER can either be a header or a line number to insert
6417 the subject line on."
6418   (let* ((line (and (numberp old-header) old-header))
6419          (old-header (and (vectorp old-header) old-header))
6420          (header (cond ((and old-header use-old-header)
6421                         old-header)
6422                        ((and (numberp id)
6423                              (gnus-number-to-header id))
6424                         (gnus-number-to-header id))
6425                        (t
6426                         (gnus-read-header id))))
6427          (number (and (numberp id) id))
6428          d)
6429     (when header
6430       ;; Rebuild the thread that this article is part of and go to the
6431       ;; article we have fetched.
6432       (when (and (not gnus-show-threads)
6433                  old-header)
6434         (when (and number
6435                    (setq d (gnus-data-find (mail-header-number old-header))))
6436           (goto-char (gnus-data-pos d))
6437           (gnus-data-remove
6438            number
6439            (- (point-at-bol)
6440               (prog1
6441                   (1+ (point-at-eol))
6442                 (gnus-delete-line))))))
6443       ;; Remove list identifiers from subject.
6444       (when gnus-list-identifiers
6445         (let ((gnus-newsgroup-headers (list header)))
6446           (gnus-summary-remove-list-identifiers)))
6447       (when old-header
6448         (mail-header-set-number header (mail-header-number old-header)))
6449       (setq gnus-newsgroup-sparse
6450             (delq (setq number (mail-header-number header))
6451                   gnus-newsgroup-sparse))
6452       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6453       (push number gnus-newsgroup-limit)
6454       (gnus-rebuild-thread (mail-header-id header) line)
6455       (gnus-summary-goto-subject number nil t))
6456     (when (and (numberp number)
6457                (> number 0))
6458       ;; We have to update the boundaries even if we can't fetch the
6459       ;; article if ID is a number -- so that the next `P' or `N'
6460       ;; command will fetch the previous (or next) article even
6461       ;; if the one we tried to fetch this time has been canceled.
6462       (when (> number gnus-newsgroup-end)
6463         (setq gnus-newsgroup-end number))
6464       (when (< number gnus-newsgroup-begin)
6465         (setq gnus-newsgroup-begin number))
6466       (setq gnus-newsgroup-unselected
6467             (delq number gnus-newsgroup-unselected)))
6468     ;; Report back a success?
6469     (and header (mail-header-number header))))
6470
6471 ;;; Process/prefix in the summary buffer
6472
6473 (defun gnus-summary-work-articles (n)
6474   "Return a list of articles to be worked upon.
6475 The prefix argument, the list of process marked articles, and the
6476 current article will be taken into consideration."
6477   (with-current-buffer gnus-summary-buffer
6478     (cond
6479      (n
6480       ;; A numerical prefix has been given.
6481       (setq n (prefix-numeric-value n))
6482       (let ((backward (< n 0))
6483             (n (abs (prefix-numeric-value n)))
6484             articles article)
6485         (save-excursion
6486           (while
6487               (and (> n 0)
6488                    (push (setq article (gnus-summary-article-number))
6489                          articles)
6490                    (if backward
6491                        (gnus-summary-find-prev nil article)
6492                      (gnus-summary-find-next nil article)))
6493             (decf n)))
6494         (nreverse articles)))
6495      ((and (gnus-region-active-p) (mark))
6496       (message "region active")
6497       ;; Work on the region between point and mark.
6498       (let ((max (max (point) (mark)))
6499             articles article)
6500         (save-excursion
6501           (goto-char (min (point) (mark)))
6502           (while
6503               (and
6504                (push (setq article (gnus-summary-article-number)) articles)
6505                (gnus-summary-find-next nil article)
6506                (< (point) max)))
6507           (nreverse articles))))
6508      (gnus-newsgroup-processable
6509       ;; There are process-marked articles present.
6510       ;; Save current state.
6511       (gnus-summary-save-process-mark)
6512       ;; Return the list.
6513       (reverse gnus-newsgroup-processable))
6514      (t
6515       ;; Just return the current article.
6516       (list (gnus-summary-article-number))))))
6517
6518 (defmacro gnus-summary-iterate (arg &rest forms)
6519   "Iterate over the process/prefixed articles and do FORMS.
6520 ARG is the interactive prefix given to the command.  FORMS will be
6521 executed with point over the summary line of the articles."
6522   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6523     `(let ((,articles (gnus-summary-work-articles ,arg)))
6524        (while ,articles
6525          (gnus-summary-goto-subject (car ,articles))
6526          ,@forms
6527          (pop ,articles)))))
6528
6529 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6530 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6531
6532 (defun gnus-summary-save-process-mark ()
6533   "Push the current set of process marked articles on the stack."
6534   (interactive)
6535   (push (copy-sequence gnus-newsgroup-processable)
6536         gnus-newsgroup-process-stack))
6537
6538 (defun gnus-summary-kill-process-mark ()
6539   "Push the current set of process marked articles on the stack and unmark."
6540   (interactive)
6541   (gnus-summary-save-process-mark)
6542   (gnus-summary-unmark-all-processable))
6543
6544 (defun gnus-summary-yank-process-mark ()
6545   "Pop the last process mark state off the stack and restore it."
6546   (interactive)
6547   (unless gnus-newsgroup-process-stack
6548     (error "Empty mark stack"))
6549   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6550
6551 (defun gnus-summary-process-mark-set (set)
6552   "Make SET into the current process marked articles."
6553   (gnus-summary-unmark-all-processable)
6554   (mapc 'gnus-summary-set-process-mark set))
6555
6556 ;;; Searching and stuff
6557
6558 (defun gnus-summary-search-group (&optional backward use-level)
6559   "Search for next unread newsgroup.
6560 If optional argument BACKWARD is non-nil, search backward instead."
6561   (with-current-buffer gnus-group-buffer
6562     (when (gnus-group-search-forward
6563            backward nil (if use-level (gnus-group-group-level) nil))
6564       (gnus-group-group-name))))
6565
6566 (defun gnus-summary-best-group (&optional exclude-group)
6567   "Find the name of the best unread group.
6568 If EXCLUDE-GROUP, do not go to this group."
6569   (with-current-buffer gnus-group-buffer
6570     (save-excursion
6571       (gnus-group-best-unread-group exclude-group))))
6572
6573 (defun gnus-summary-find-next (&optional unread article backward)
6574   (if backward
6575       (gnus-summary-find-prev unread article)
6576     (let* ((dummy (gnus-summary-article-intangible-p))
6577            (article (or article (gnus-summary-article-number)))
6578            (data (gnus-data-find-list article))
6579            result)
6580       (when (and (not dummy)
6581                  (or (not gnus-summary-check-current)
6582                      (not unread)
6583                      (not (gnus-data-unread-p (car data)))))
6584         (setq data (cdr data)))
6585       (when (setq result
6586                   (if unread
6587                       (progn
6588                         (while data
6589                           (unless (memq (gnus-data-number (car data))
6590                                         (cond
6591                                          ((eq gnus-auto-goto-ignores
6592                                               'always-undownloaded)
6593                                           gnus-newsgroup-undownloaded)
6594                                          (gnus-plugged
6595                                           nil)
6596                                          ((eq gnus-auto-goto-ignores
6597                                               'unfetched)
6598                                           gnus-newsgroup-unfetched)
6599                                          ((eq gnus-auto-goto-ignores
6600                                               'undownloaded)
6601                                           gnus-newsgroup-undownloaded)))
6602                             (when (gnus-data-unread-p (car data))
6603                               (setq result (car data)
6604                                     data nil)))
6605                           (setq data (cdr data)))
6606                         result)
6607                     (car data)))
6608         (goto-char (gnus-data-pos result))
6609         (gnus-data-number result)))))
6610
6611 (defun gnus-summary-find-prev (&optional unread article)
6612   (let* ((eobp (eobp))
6613          (article (or article (gnus-summary-article-number)))
6614          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6615          result)
6616     (when (and (not eobp)
6617                (or (not gnus-summary-check-current)
6618                    (not unread)
6619                    (not (gnus-data-unread-p (car data)))))
6620       (setq data (cdr data)))
6621     (when (setq result
6622                 (if unread
6623                     (progn
6624                       (while data
6625                         (unless (memq (gnus-data-number (car data))
6626                                       (cond
6627                                        ((eq gnus-auto-goto-ignores
6628                                             'always-undownloaded)
6629                                         gnus-newsgroup-undownloaded)
6630                                        (gnus-plugged
6631                                         nil)
6632                                        ((eq gnus-auto-goto-ignores
6633                                             'unfetched)
6634                                         gnus-newsgroup-unfetched)
6635                                        ((eq gnus-auto-goto-ignores
6636                                             'undownloaded)
6637                                         gnus-newsgroup-undownloaded)))
6638                           (when (gnus-data-unread-p (car data))
6639                             (setq result (car data)
6640                                   data nil)))
6641                         (setq data (cdr data)))
6642                       result)
6643                   (car data)))
6644       (goto-char (gnus-data-pos result))
6645       (gnus-data-number result))))
6646
6647 (defun gnus-summary-find-subject (subject &optional unread backward article)
6648   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6649          (article (or article (gnus-summary-article-number)))
6650          (articles (gnus-data-list backward))
6651          (arts (gnus-data-find-list article articles))
6652          result)
6653     (when (or (not gnus-summary-check-current)
6654               (not unread)
6655               (not (gnus-data-unread-p (car arts))))
6656       (setq arts (cdr arts)))
6657     (while arts
6658       (and (or (not unread)
6659                (gnus-data-unread-p (car arts)))
6660            (vectorp (gnus-data-header (car arts)))
6661            (gnus-subject-equal
6662             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6663            (setq result (car arts)
6664                  arts nil))
6665       (setq arts (cdr arts)))
6666     (and result
6667          (goto-char (gnus-data-pos result))
6668          (gnus-data-number result))))
6669
6670 (defun gnus-summary-search-forward (&optional unread subject backward)
6671   "Search forward for an article.
6672 If UNREAD, look for unread articles.  If SUBJECT, look for
6673 articles with that subject.  If BACKWARD, search backward instead."
6674   (cond (subject (gnus-summary-find-subject subject unread backward))
6675         (backward (gnus-summary-find-prev unread))
6676         (t (gnus-summary-find-next unread))))
6677
6678 (defun gnus-recenter (&optional n)
6679   "Center point in window and redisplay frame.
6680 Also do horizontal recentering."
6681   (interactive "P")
6682   (when (and gnus-auto-center-summary
6683              (not (eq gnus-auto-center-summary 'vertical)))
6684     (gnus-horizontal-recenter))
6685   (recenter n))
6686
6687 (defun gnus-summary-recenter ()
6688   "Center point in the summary window.
6689 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6690 displayed, no centering will be performed."
6691   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6692   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6693   (interactive)
6694   ;; The user has to want it.
6695   (when gnus-auto-center-summary
6696     (let* ((top (cond ((< (window-height) 4) 0)
6697                       ((< (window-height) 7) 1)
6698                       (t (if (numberp gnus-auto-center-summary)
6699                              gnus-auto-center-summary
6700                            (/ (1- (window-height)) 2)))))
6701            (height (1- (window-height)))
6702            (bottom (save-excursion (goto-char (point-max))
6703                                    (forward-line (- height))
6704                                    (point)))
6705            (window (get-buffer-window (current-buffer))))
6706       (when (get-buffer-window gnus-article-buffer)
6707         ;; Only do recentering when the article buffer is displayed,
6708         ;; Set the window start to either `bottom', which is the biggest
6709         ;; possible valid number, or the second line from the top,
6710         ;; whichever is the least.
6711         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6712           (if (> bottom top-pos)
6713               ;; Keep the second line from the top visible
6714               (set-window-start window top-pos)
6715             ;; Try to keep the bottom line visible; if it's partially
6716             ;; obscured, either scroll one more line to make it fully
6717             ;; visible, or revert to using TOP-POS.
6718             (save-excursion
6719               (goto-char (point-max))
6720               (forward-line -1)
6721               (let ((last-line-start (point)))
6722                 (goto-char bottom)
6723                 (set-window-start window (point) t)
6724                 (when (not (pos-visible-in-window-p last-line-start window))
6725                   (forward-line 1)
6726                   (set-window-start window (min (point) top-pos) t)))))))
6727       ;; Do horizontal recentering while we're at it.
6728       (when (and (get-buffer-window (current-buffer) t)
6729                  (not (eq gnus-auto-center-summary 'vertical)))
6730         (let ((selected (selected-window)))
6731           (select-window (get-buffer-window (current-buffer) t))
6732           (gnus-summary-position-point)
6733           (gnus-horizontal-recenter)
6734           (select-window selected))))))
6735
6736 (defun gnus-summary-jump-to-group (newsgroup)
6737   "Move point to NEWSGROUP in group mode buffer."
6738   ;; Keep update point of group mode buffer if visible.
6739   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6740       (save-window-excursion
6741         ;; Take care of tree window mode.
6742         (when (get-buffer-window gnus-group-buffer)
6743           (pop-to-buffer gnus-group-buffer))
6744         (gnus-group-jump-to-group newsgroup))
6745     (save-excursion
6746       ;; Take care of tree window mode.
6747       (if (get-buffer-window gnus-group-buffer 0)
6748           (pop-to-buffer gnus-group-buffer)
6749         (set-buffer gnus-group-buffer))
6750       (gnus-group-jump-to-group newsgroup))))
6751
6752 ;; This function returns a list of article numbers based on the
6753 ;; difference between the ranges of read articles in this group and
6754 ;; the range of active articles.
6755 (defun gnus-list-of-unread-articles (group)
6756   (let* ((read (gnus-info-read (gnus-get-info group)))
6757          (active (or (gnus-active group) (gnus-activate-group group)))
6758          (last (or (cdr active)
6759                    (error "Group %s couldn't be activated " group)))
6760          (bottom (if gnus-newsgroup-maximum-articles
6761                      (max (car active)
6762                           (- last gnus-newsgroup-maximum-articles -1))
6763                    (car active)))
6764          first nlast unread)
6765     ;; If none are read, then all are unread.
6766     (if (not read)
6767         (setq first bottom)
6768       ;; If the range of read articles is a single range, then the
6769       ;; first unread article is the article after the last read
6770       ;; article.  Sounds logical, doesn't it?
6771       (if (and (not (listp (cdr read)))
6772                (or (< (car read) bottom)
6773                    (progn (setq read (list read))
6774                           nil)))
6775           (setq first (max bottom (1+ (cdr read))))
6776         ;; `read' is a list of ranges.
6777         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6778                                   (caar read)))
6779                   1)
6780           (setq first bottom))
6781         (while read
6782           (when first
6783             (while (< first nlast)
6784               (setq unread (cons first unread)
6785                     first (1+ first))))
6786           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6787           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6788           (setq read (cdr read)))))
6789     ;; And add the last unread articles.
6790     (while (<= first last)
6791       (setq unread (cons first unread)
6792             first (1+ first)))
6793     ;; Return the list of unread articles.
6794     (delq 0 (nreverse unread))))
6795
6796 (defun gnus-list-of-read-articles (group)
6797   "Return a list of unread, unticked and non-dormant articles."
6798   (let* ((info (gnus-get-info group))
6799          (marked (gnus-info-marks info))
6800          (active (gnus-active group)))
6801     (and info active
6802          (gnus-list-range-difference
6803           (gnus-list-range-difference
6804            (gnus-sorted-complement
6805             (gnus-uncompress-range
6806              (if gnus-newsgroup-maximum-articles
6807                  (cons (max (car active)
6808                             (- (cdr active)
6809                                gnus-newsgroup-maximum-articles
6810                                -1))
6811                        (cdr active))
6812                active))
6813             (gnus-list-of-unread-articles group))
6814            (cdr (assq 'dormant marked)))
6815           (cdr (assq 'tick marked))))))
6816
6817 ;; This function returns a sequence of article numbers based on the
6818 ;; difference between the ranges of read articles in this group and
6819 ;; the range of active articles.
6820 (defun gnus-sequence-of-unread-articles (group)
6821   (let* ((read (gnus-info-read (gnus-get-info group)))
6822          (active (or (gnus-active group) (gnus-activate-group group)))
6823          (last (cdr active))
6824          (bottom (if gnus-newsgroup-maximum-articles
6825                      (max (car active)
6826                           (- last gnus-newsgroup-maximum-articles -1))
6827                    (car active)))
6828          first nlast unread)
6829     ;; If none are read, then all are unread.
6830     (if (not read)
6831         (setq first bottom)
6832       ;; If the range of read articles is a single range, then the
6833       ;; first unread article is the article after the last read
6834       ;; article.  Sounds logical, doesn't it?
6835       (if (and (not (listp (cdr read)))
6836                (or (< (car read) bottom)
6837                    (progn (setq read (list read))
6838                           nil)))
6839           (setq first (max bottom (1+ (cdr read))))
6840         ;; `read' is a list of ranges.
6841         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6842                                   (caar read)))
6843                   1)
6844           (setq first bottom))
6845         (while read
6846           (when first
6847             (push (cons first nlast) unread))
6848           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6849           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6850           (setq read (cdr read)))))
6851     ;; And add the last unread articles.
6852     (cond ((not (and first last))
6853            nil)
6854           ((< first last)
6855            (push (cons first last) unread))
6856           ((= first last)
6857            (push first unread)))
6858     ;; Return the sequence of unread articles.
6859     (delq 0 (nreverse unread))))
6860
6861 ;; Various summary commands
6862
6863 (defun gnus-summary-select-article-buffer ()
6864   "Reconfigure windows to show article buffer."
6865   (interactive)
6866   (if (not (gnus-buffer-live-p gnus-article-buffer))
6867       (error "There is no article buffer for this summary buffer")
6868     (gnus-configure-windows 'article)
6869     (select-window (get-buffer-window gnus-article-buffer))))
6870
6871 (defun gnus-summary-universal-argument (arg)
6872   "Perform any operation on all articles that are process/prefixed."
6873   (interactive "P")
6874   (let ((articles (gnus-summary-work-articles arg))
6875         func article)
6876     (if (eq
6877          (setq
6878           func
6879           (key-binding
6880            (read-key-sequence
6881             (substitute-command-keys
6882              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6883          'undefined)
6884         (gnus-error 1 "Undefined key")
6885       (save-excursion
6886         (while articles
6887           (gnus-summary-goto-subject (setq article (pop articles)))
6888           (let (gnus-newsgroup-processable)
6889             (command-execute func))
6890           (gnus-summary-remove-process-mark article)))))
6891   (gnus-summary-position-point))
6892
6893 (defun gnus-summary-toggle-truncation (&optional arg)
6894   "Toggle truncation of summary lines.
6895 With ARG, turn line truncation on if ARG is positive."
6896   (interactive "P")
6897   (setq truncate-lines
6898         (if (null arg) (not truncate-lines)
6899           (> (prefix-numeric-value arg) 0)))
6900   (redraw-display))
6901
6902 (defun gnus-summary-find-for-reselect ()
6903   "Return the number of an article to stay on across a reselect.
6904 The current article is considered, then following articles, then previous
6905 articles.  An article is sought which is not cancelled and isn't a temporary
6906 insertion from another group.  If there's no such then return a dummy 0."
6907   (let (found)
6908     (dolist (rev '(nil t))
6909       (unless found      ; don't demand the reverse list if we don't need it
6910         (let ((data (gnus-data-find-list
6911                      (gnus-summary-article-number) (gnus-data-list rev))))
6912           (while (and data (not found))
6913             (if (and (< 0 (gnus-data-number (car data)))
6914                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6915                 (setq found (gnus-data-number (car data))))
6916             (setq data (cdr data))))))
6917     (or found 0)))
6918
6919 (defun gnus-summary-reselect-current-group (&optional all rescan)
6920   "Exit and then reselect the current newsgroup.
6921 The prefix argument ALL means to select all articles."
6922   (interactive "P")
6923   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6924     (error "Ephemeral groups can't be reselected"))
6925   (let ((current-subject (gnus-summary-find-for-reselect))
6926         (group gnus-newsgroup-name))
6927     (setq gnus-newsgroup-begin nil)
6928     (gnus-summary-exit nil 'leave-hidden)
6929     ;; We have to adjust the point of group mode buffer because
6930     ;; point was moved to the next unread newsgroup by exiting.
6931     (gnus-summary-jump-to-group group)
6932     (when rescan
6933       (save-excursion
6934         (gnus-group-get-new-news-this-group 1)))
6935     (gnus-group-read-group all t)
6936     (gnus-summary-goto-subject current-subject nil t)))
6937
6938 (defun gnus-summary-rescan-group (&optional all)
6939   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6940   (interactive "P")
6941   (gnus-summary-reselect-current-group all t))
6942
6943 (defun gnus-summary-update-info (&optional non-destructive)
6944   (save-excursion
6945     (let ((group gnus-newsgroup-name))
6946       (when group
6947         (when gnus-newsgroup-kill-headers
6948           (setq gnus-newsgroup-killed
6949                 (gnus-compress-sequence
6950                  (gnus-sorted-union
6951                   (gnus-list-range-intersection
6952                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6953                   gnus-newsgroup-unreads)
6954                  t)))
6955         (unless (listp (cdr gnus-newsgroup-killed))
6956           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6957         (let ((headers gnus-newsgroup-headers))
6958           ;; Set the new ranges of read articles.
6959           (with-current-buffer gnus-group-buffer
6960             (gnus-undo-force-boundary))
6961           (gnus-update-read-articles
6962            group (gnus-sorted-union
6963                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6964           ;; Set the current article marks.
6965           (let ((gnus-newsgroup-scored
6966                  (if (and (not gnus-save-score)
6967                           (not non-destructive))
6968                      nil
6969                    gnus-newsgroup-scored)))
6970             (save-excursion
6971               (gnus-update-marks)))
6972           ;; Do the cross-ref thing.
6973           (when gnus-use-cross-reference
6974             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6975           ;; Do not switch windows but change the buffer to work.
6976           (set-buffer gnus-group-buffer)
6977           (unless (gnus-ephemeral-group-p group)
6978             (gnus-group-update-group group)))))))
6979
6980 (defun gnus-summary-save-newsrc (&optional force)
6981   "Save the current number of read/marked articles in the dribble buffer.
6982 The dribble buffer will then be saved.
6983 If FORCE (the prefix), also save the .newsrc file(s)."
6984   (interactive "P")
6985   (gnus-summary-update-info t)
6986   (if force
6987       (gnus-save-newsrc-file)
6988     (gnus-dribble-save)))
6989
6990 (declare-function gnus-cache-write-active "gnus-cache" (&optional force))
6991
6992 (defun gnus-summary-exit (&optional temporary leave-hidden)
6993   "Exit reading current newsgroup, and then return to group selection mode.
6994 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6995   (interactive)
6996   (gnus-set-global-variables)
6997   (when (gnus-buffer-live-p gnus-article-buffer)
6998     (with-current-buffer gnus-article-buffer
6999       (mm-destroy-parts gnus-article-mime-handles)
7000       ;; Set it to nil for safety reason.
7001       (setq gnus-article-mime-handle-alist nil)
7002       (setq gnus-article-mime-handles nil)))
7003   (gnus-kill-save-kill-buffer)
7004   (gnus-async-halt-prefetch)
7005   (let* ((group gnus-newsgroup-name)
7006          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
7007          (gnus-group-is-exiting-p t)
7008          (mode major-mode)
7009          (group-point nil)
7010          (buf (current-buffer)))
7011     (unless quit-config
7012       ;; Do adaptive scoring, and possibly save score files.
7013       (when gnus-newsgroup-adaptive
7014         (gnus-score-adaptive))
7015       (when gnus-use-scoring
7016         (gnus-score-save)))
7017     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
7018     ;; If we have several article buffers, we kill them at exit.
7019     (unless gnus-single-article-buffer
7020       (when (gnus-buffer-live-p gnus-article-buffer)
7021         (with-current-buffer gnus-article-buffer
7022           ;; Don't kill sticky article buffers
7023           (unless (eq major-mode 'gnus-sticky-article-mode)
7024             (gnus-kill-buffer gnus-article-buffer)
7025             (setq gnus-article-current nil))))
7026       (gnus-kill-buffer gnus-original-article-buffer))
7027     (when gnus-use-cache
7028       (gnus-cache-possibly-remove-articles)
7029       (gnus-cache-save-buffers))
7030     (gnus-async-prefetch-remove-group group)
7031     (when gnus-suppress-duplicates
7032       (gnus-dup-enter-articles))
7033     (when gnus-use-trees
7034       (gnus-tree-close group))
7035     (when gnus-use-cache
7036       (gnus-cache-write-active))
7037     ;; Remove entries for this group.
7038     (nnmail-purge-split-history (gnus-group-real-name group))
7039     ;; Make all changes in this group permanent.
7040     (unless quit-config
7041       (gnus-run-hooks 'gnus-exit-group-hook)
7042       (gnus-summary-update-info))
7043     (gnus-close-group group)
7044     ;; Make sure where we were, and go to next newsgroup.
7045     (set-buffer gnus-group-buffer)
7046     (unless quit-config
7047       (gnus-group-jump-to-group group))
7048     (gnus-run-hooks 'gnus-summary-exit-hook)
7049     (unless (or quit-config
7050                 (not gnus-summary-next-group-on-exit)
7051                 ;; If this group has disappeared from the summary
7052                 ;; buffer, don't skip forwards.
7053                 (not (string= group (gnus-group-group-name))))
7054       (gnus-group-next-unread-group 1))
7055     (setq group-point (point))
7056     (if temporary
7057         nil                             ;Nothing to do.
7058       (set-buffer buf)
7059       (if (not gnus-kill-summary-on-exit)
7060           (progn
7061             (gnus-deaden-summary)
7062             (setq mode nil))
7063         ;; We set all buffer-local variables to nil.  It is unclear why
7064         ;; this is needed, but if we don't, buffer-local variables are
7065         ;; not garbage-collected, it seems.  This would the lead to en
7066         ;; ever-growing Emacs.
7067         (gnus-summary-clear-local-variables)
7068         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7069           (gnus-summary-clear-local-variables))
7070         (when (get-buffer gnus-article-buffer)
7071           (bury-buffer gnus-article-buffer))
7072         ;; Return to group mode buffer.
7073         (when (eq mode 'gnus-summary-mode)
7074           (gnus-kill-buffer buf)))
7075       (setq gnus-current-select-method gnus-select-method)
7076       (set-buffer gnus-group-buffer)
7077       (if quit-config
7078           (gnus-handle-ephemeral-exit quit-config)
7079         (goto-char group-point)
7080         ;; If gnus-group-buffer is already displayed, make sure we also move
7081         ;; the cursor in the window that displays it.
7082         (let ((win (get-buffer-window (current-buffer) 0)))
7083           (if win (set-window-point win (point))))
7084         (unless leave-hidden
7085           (gnus-configure-windows 'group 'force)))
7086       ;; Clear the current group name.
7087       (unless quit-config
7088         (setq gnus-newsgroup-name nil)))))
7089
7090 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7091 (defun gnus-summary-exit-no-update (&optional no-questions)
7092   "Quit reading current newsgroup without updating read article info."
7093   (interactive)
7094   (let* ((group gnus-newsgroup-name)
7095          (gnus-group-is-exiting-p t)
7096          (gnus-group-is-exiting-without-update-p t)
7097          (quit-config (gnus-group-quit-config group)))
7098     (when (or no-questions
7099               gnus-expert-user
7100               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7101       (gnus-async-halt-prefetch)
7102       (run-hooks 'gnus-summary-prepare-exit-hook)
7103       (when (gnus-buffer-live-p gnus-article-buffer)
7104         (with-current-buffer gnus-article-buffer
7105           (mm-destroy-parts gnus-article-mime-handles)
7106           ;; Set it to nil for safety reason.
7107           (setq gnus-article-mime-handle-alist nil)
7108           (setq gnus-article-mime-handles nil)))
7109       ;; If we have several article buffers, we kill them at exit.
7110       (unless gnus-single-article-buffer
7111         (gnus-kill-buffer gnus-article-buffer)
7112         (gnus-kill-buffer gnus-original-article-buffer)
7113         (setq gnus-article-current nil))
7114       (if (not gnus-kill-summary-on-exit)
7115           (gnus-deaden-summary)
7116         (gnus-close-group group)
7117         (gnus-summary-clear-local-variables)
7118         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7119           (gnus-summary-clear-local-variables))
7120         (gnus-kill-buffer gnus-summary-buffer))
7121       (unless gnus-single-article-buffer
7122         (setq gnus-article-current nil))
7123       (when gnus-use-trees
7124         (gnus-tree-close group))
7125       (gnus-async-prefetch-remove-group group)
7126       (when (get-buffer gnus-article-buffer)
7127         (bury-buffer gnus-article-buffer))
7128       ;; Return to the group buffer.
7129       (gnus-configure-windows 'group 'force)
7130       ;; Clear the current group name.
7131       (setq gnus-newsgroup-name nil)
7132       (unless (gnus-ephemeral-group-p group)
7133         (gnus-group-update-group group))
7134       (when (equal (gnus-group-group-name) group)
7135         (gnus-group-next-unread-group 1))
7136       (when quit-config
7137         (gnus-handle-ephemeral-exit quit-config)))))
7138
7139 (defun gnus-handle-ephemeral-exit (quit-config)
7140   "Handle movement when leaving an ephemeral group.
7141 The state which existed when entering the ephemeral is reset."
7142   (if (not (buffer-name (car quit-config)))
7143       (gnus-configure-windows 'group 'force)
7144     (set-buffer (car quit-config))
7145     (cond ((eq major-mode 'gnus-summary-mode)
7146            (gnus-set-global-variables))
7147           ((eq major-mode 'gnus-article-mode)
7148            (save-current-buffer
7149              ;; The `gnus-summary-buffer' variable may point
7150              ;; to the old summary buffer when using a single
7151              ;; article buffer.
7152              (unless (gnus-buffer-live-p gnus-summary-buffer)
7153                (set-buffer gnus-group-buffer))
7154              (set-buffer gnus-summary-buffer)
7155              (gnus-set-global-variables))))
7156     (if (or (eq (cdr quit-config) 'article)
7157             (eq (cdr quit-config) 'pick))
7158         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7159             (gnus-configure-windows 'pick 'force)
7160           (gnus-configure-windows (cdr quit-config) 'force))
7161       (gnus-configure-windows (cdr quit-config) 'force))
7162     (when (eq major-mode 'gnus-summary-mode)
7163       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7164                                                      next-unread-noselect))
7165           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7166                                   'next-noselect)
7167                               (gnus-summary-next-subject 1 nil t))
7168                              ((eq gnus-auto-select-on-ephemeral-exit
7169                                   'next-unread-noselect)
7170                               (gnus-summary-next-subject 1 t t))))
7171             ;; Hide the article buffer which displays the article different
7172             ;; from the one that the cursor points to in the summary buffer.
7173             (gnus-configure-windows 'summary 'force))
7174         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7175                (gnus-summary-next-subject 1))
7176               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7177                (gnus-summary-next-subject 1 t))))
7178       (gnus-summary-recenter)
7179       (gnus-summary-position-point))))
7180
7181 ;;; Dead summaries.
7182
7183 (defvar gnus-dead-summary-mode-map nil)
7184
7185 (unless gnus-dead-summary-mode-map
7186   (setq gnus-dead-summary-mode-map (make-keymap))
7187   (suppress-keymap gnus-dead-summary-mode-map)
7188   (substitute-key-definition
7189    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7190   (dolist (key '("\C-d" "\r" "\177" [delete]))
7191     (define-key gnus-dead-summary-mode-map
7192       key 'gnus-summary-wake-up-the-dead))
7193   (dolist (key '("q" "Q"))
7194     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7195
7196 (defvar gnus-dead-summary-mode nil
7197   "Minor mode for Gnus summary buffers.")
7198
7199 (defun gnus-dead-summary-mode (&optional arg)
7200   "Minor mode for Gnus summary buffers."
7201   (interactive "P")
7202   (when (eq major-mode 'gnus-summary-mode)
7203     (make-local-variable 'gnus-dead-summary-mode)
7204     (setq gnus-dead-summary-mode
7205           (if (null arg) (not gnus-dead-summary-mode)
7206             (> (prefix-numeric-value arg) 0)))
7207     (when gnus-dead-summary-mode
7208       (add-minor-mode
7209        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7210
7211 (defun gnus-deaden-summary ()
7212   "Make the current summary buffer into a dead summary buffer."
7213   ;; Kill any previous dead summary buffer.
7214   (when (and gnus-dead-summary
7215              (buffer-name gnus-dead-summary))
7216     (with-current-buffer gnus-dead-summary
7217       (when gnus-dead-summary-mode
7218         (kill-buffer (current-buffer)))))
7219   ;; Make this the current dead summary.
7220   (setq gnus-dead-summary (current-buffer))
7221   (gnus-dead-summary-mode 1)
7222   (let ((name (buffer-name)))
7223     (when (string-match "Summary" name)
7224       (rename-buffer
7225        (concat (substring name 0 (match-beginning 0)) "Dead "
7226                (substring name (match-beginning 0)))
7227        t)
7228       (bury-buffer))))
7229
7230 (defun gnus-kill-or-deaden-summary (buffer)
7231   "Kill or deaden the summary BUFFER."
7232   (save-excursion
7233     (when (and (buffer-name buffer)
7234                (not gnus-single-article-buffer))
7235       (with-current-buffer buffer
7236         (gnus-kill-buffer gnus-article-buffer)
7237         (gnus-kill-buffer gnus-original-article-buffer)))
7238     (cond
7239      ;; Kill the buffer.
7240      (gnus-kill-summary-on-exit
7241       (when (and gnus-use-trees
7242                  (gnus-buffer-exists-p buffer))
7243         (with-current-buffer buffer
7244           (gnus-tree-close gnus-newsgroup-name)))
7245       (gnus-kill-buffer buffer))
7246      ;; Deaden the buffer.
7247      ((gnus-buffer-exists-p buffer)
7248       (with-current-buffer buffer
7249         (gnus-deaden-summary))))))
7250
7251 (defun gnus-summary-wake-up-the-dead (&rest args)
7252   "Wake up the dead summary buffer."
7253   (interactive)
7254   (gnus-dead-summary-mode -1)
7255   (let ((name (buffer-name)))
7256     (when (string-match "Dead " name)
7257       (rename-buffer
7258        (concat (substring name 0 (match-beginning 0))
7259                (substring name (match-end 0)))
7260        t)))
7261   (gnus-message 3 "This dead summary is now alive again"))
7262
7263 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7264 (defun gnus-summary-fetch-faq (&optional faq-dir)
7265   "Fetch the FAQ for the current group.
7266 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7267 in."
7268   (interactive
7269    (list
7270     (when current-prefix-arg
7271       (completing-read
7272        "FAQ dir: " (and (listp gnus-group-faq-directory)
7273                         (mapcar 'list
7274                                 gnus-group-faq-directory))))))
7275   (let (gnus-faq-buffer)
7276     (when (setq gnus-faq-buffer
7277                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7278       (gnus-configure-windows 'summary-faq))))
7279
7280 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7281 (defun gnus-summary-describe-group (&optional force)
7282   "Describe the current newsgroup."
7283   (interactive "P")
7284   (gnus-group-describe-group force gnus-newsgroup-name))
7285
7286 (defun gnus-summary-describe-briefly ()
7287   "Describe summary mode commands briefly."
7288   (interactive)
7289   (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")))
7290
7291 ;; Walking around group mode buffer from summary mode.
7292
7293 (defun gnus-summary-next-group (&optional no-article target-group backward)
7294   "Exit current newsgroup and then select next unread newsgroup.
7295 If prefix argument NO-ARTICLE is non-nil, no article is selected
7296 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7297 previous group instead."
7298   (interactive "P")
7299   ;; Stop pre-fetching.
7300   (gnus-async-halt-prefetch)
7301   (let ((current-group gnus-newsgroup-name)
7302         (current-buffer (current-buffer))
7303         entered)
7304     ;; First we semi-exit this group to update Xrefs and all variables.
7305     ;; We can't do a real exit, because the window conf must remain
7306     ;; the same in case the user is prompted for info, and we don't
7307     ;; want the window conf to change before that...
7308     (gnus-summary-exit t)
7309     (while (not entered)
7310       ;; Then we find what group we are supposed to enter.
7311       (set-buffer gnus-group-buffer)
7312       (gnus-group-jump-to-group current-group)
7313       (setq target-group
7314             (or target-group
7315                 (if (eq gnus-keep-same-level 'best)
7316                     (gnus-summary-best-group gnus-newsgroup-name)
7317                   (gnus-summary-search-group backward gnus-keep-same-level))))
7318       (if (not target-group)
7319           ;; There are no further groups, so we return to the group
7320           ;; buffer.
7321           (progn
7322             (gnus-message 5 "Returning to the group buffer")
7323             (setq entered t)
7324             (when (gnus-buffer-live-p current-buffer)
7325               (set-buffer current-buffer)
7326               (gnus-summary-exit))
7327             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7328         ;; We try to enter the target group.
7329         (gnus-group-jump-to-group target-group)
7330         (let ((unreads (gnus-group-group-unread)))
7331           (if (and (or (eq t unreads)
7332                        (and unreads (not (zerop unreads))))
7333                    (gnus-summary-read-group
7334                     target-group nil no-article
7335                     (and (buffer-name current-buffer) current-buffer)
7336                     nil backward))
7337               (setq entered t)
7338             (setq current-group target-group
7339                   target-group nil)))))))
7340
7341 (defun gnus-summary-prev-group (&optional no-article)
7342   "Exit current newsgroup and then select previous unread newsgroup.
7343 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7344   (interactive "P")
7345   (gnus-summary-next-group no-article nil t))
7346
7347 ;; Walking around summary lines.
7348
7349 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7350   "Go to the first subject satisfying any non-nil constraint.
7351 If UNREAD is non-nil, the article should be unread.
7352 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7353 If UNSEEN is non-nil, the article should be unseen.
7354 Returns the article selected or nil if there are no matching articles."
7355   (interactive "P")
7356   (cond
7357    ;; Empty summary.
7358    ((null gnus-newsgroup-data)
7359     (gnus-message 3 "No articles in the group")
7360     nil)
7361    ;; Pick the first article.
7362    ((not (or unread undownloaded unseen))
7363     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7364     (gnus-data-number (car gnus-newsgroup-data)))
7365    ;; Find the first unread article.
7366    (t
7367     (let ((data gnus-newsgroup-data))
7368       (while (and data
7369                   (let ((num (gnus-data-number (car data))))
7370                     (or (memq num gnus-newsgroup-unfetched)
7371                         (not (or (and unread
7372                                       (memq num gnus-newsgroup-unreads))
7373                                  (and undownloaded
7374                                       (memq num gnus-newsgroup-undownloaded))
7375                                  (and unseen
7376                                       (memq num gnus-newsgroup-unseen)))))))
7377         (setq data (cdr data)))
7378       (prog1
7379           (if data
7380               (progn
7381                 (goto-char (gnus-data-pos (car data)))
7382                 (gnus-data-number (car data)))
7383             (gnus-message 3 "No more%s articles"
7384                           (let* ((r (when unread " unread"))
7385                                  (d (when undownloaded " undownloaded"))
7386                                  (s (when unseen " unseen"))
7387                                  (l (delq nil (list r d s))))
7388                             (cond ((= 3 (length l))
7389                                    (concat r "," d ", or" s))
7390                                   ((= 2 (length l))
7391                                    (concat (car l) ", or" (cadr l)))
7392                                   ((= 1 (length l))
7393                                    (car l))
7394                                   (t
7395                                    ""))))
7396             nil
7397             )
7398         (gnus-summary-position-point))))))
7399
7400 (defun gnus-summary-next-subject (n &optional unread dont-display)
7401   "Go to next N'th summary line.
7402 If N is negative, go to the previous N'th subject line.
7403 If UNREAD is non-nil, only unread articles are selected.
7404 The difference between N and the actual number of steps taken is
7405 returned."
7406   (interactive "p")
7407   (let ((backward (< n 0))
7408         (n (abs n)))
7409     (while (and (> n 0)
7410                 (if backward
7411                     (gnus-summary-find-prev unread)
7412                   (gnus-summary-find-next unread)))
7413       (unless (zerop (setq n (1- n)))
7414         (gnus-summary-show-thread)))
7415     (when (/= 0 n)
7416       (gnus-message 7 "No more%s articles"
7417                     (if unread " unread" "")))
7418     (unless dont-display
7419       (gnus-summary-recenter)
7420       (gnus-summary-position-point))
7421     n))
7422
7423 (defun gnus-summary-next-unread-subject (n)
7424   "Go to next N'th unread summary line."
7425   (interactive "p")
7426   (gnus-summary-next-subject n t))
7427
7428 (defun gnus-summary-prev-subject (n &optional unread)
7429   "Go to previous N'th summary line.
7430 If optional argument UNREAD is non-nil, only unread article is selected."
7431   (interactive "p")
7432   (gnus-summary-next-subject (- n) unread))
7433
7434 (defun gnus-summary-prev-unread-subject (n)
7435   "Go to previous N'th unread summary line."
7436   (interactive "p")
7437   (gnus-summary-next-subject (- n) t))
7438
7439 (defun gnus-summary-goto-subjects (articles)
7440   "Insert the subject header for ARTICLES in the current buffer."
7441   (save-excursion
7442     (dolist (article articles)
7443       (gnus-summary-goto-subject article t)))
7444   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7445   (gnus-summary-position-point))
7446
7447 (defun gnus-summary-goto-subject (article &optional force silent)
7448   "Go to the subject line of ARTICLE.
7449 If FORCE, also allow jumping to articles not currently shown."
7450   (interactive "nArticle number: ")
7451   (unless (numberp article)
7452     (error "Article %s is not a number" article))
7453   (let ((b (point))
7454         (data (gnus-data-find article)))
7455     ;; We read in the article if we have to.
7456     (and (not data)
7457          force
7458          (gnus-summary-insert-subject
7459           article
7460           (if (or (numberp force) (vectorp force)) force)
7461           t)
7462          (setq data (gnus-data-find article)))
7463     (goto-char b)
7464     (if (not data)
7465         (progn
7466           (unless silent
7467             (gnus-message 3 "Can't find article %d" article))
7468           nil)
7469       (let ((pt (gnus-data-pos data)))
7470         (goto-char pt)
7471         (gnus-summary-set-article-display-arrow pt))
7472       (gnus-summary-position-point)
7473       article)))
7474
7475 ;; Walking around summary lines with displaying articles.
7476
7477 (defun gnus-summary-expand-window (&optional arg)
7478   "Make the summary buffer take up the entire Emacs frame.
7479 Given a prefix, will force an `article' buffer configuration."
7480   (interactive "P")
7481   (if arg
7482       (gnus-configure-windows 'article 'force)
7483     (gnus-configure-windows 'summary 'force)))
7484
7485 (defun gnus-summary-display-article (article &optional all-header)
7486   "Display ARTICLE in article buffer."
7487   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7488                (with-current-buffer gnus-article-buffer
7489                  (eq major-mode 'gnus-article-mode)))
7490     (gnus-article-setup-buffer))
7491   (gnus-set-global-variables)
7492   (with-current-buffer gnus-article-buffer
7493     (setq gnus-article-charset gnus-newsgroup-charset)
7494     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7495     (mm-enable-multibyte))
7496   (if (null article)
7497       nil
7498     (prog1
7499         (if gnus-summary-display-article-function
7500             (funcall gnus-summary-display-article-function article all-header)
7501           (gnus-article-prepare article all-header))
7502       (gnus-run-hooks 'gnus-select-article-hook)
7503       (when (and gnus-current-article
7504                  (not (zerop gnus-current-article)))
7505         (gnus-summary-goto-subject gnus-current-article))
7506       (gnus-summary-recenter)
7507       (when (and gnus-use-trees gnus-show-threads)
7508         (gnus-possibly-generate-tree article)
7509         (gnus-highlight-selected-tree article))
7510       ;; Successfully display article.
7511       (gnus-article-set-window-start
7512        (cdr (assq article gnus-newsgroup-bookmarks))))))
7513
7514 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7515   "Select the current article.
7516 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7517 non-nil, the article will be re-fetched even if it already present in
7518 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7519 be displayed."
7520   ;; Make sure we are in the summary buffer to work around bbdb bug.
7521   (unless (eq major-mode 'gnus-summary-mode)
7522     (set-buffer gnus-summary-buffer))
7523   (let ((article (or article (gnus-summary-article-number)))
7524         (all-headers (not (not all-headers))) ;Must be t or nil.
7525         gnus-summary-display-article-function)
7526     (and (not pseudo)
7527          (gnus-summary-article-pseudo-p article)
7528          (error "This is a pseudo-article"))
7529     (with-current-buffer gnus-summary-buffer
7530       (if (or (and gnus-single-article-buffer
7531                    (or (null gnus-current-article)
7532                        (null gnus-article-current)
7533                        (null (get-buffer gnus-article-buffer))
7534                        (not (eq article (cdr gnus-article-current)))
7535                        (not (equal (car gnus-article-current)
7536                                    gnus-newsgroup-name))))
7537               (and (not gnus-single-article-buffer)
7538                    (or (null gnus-current-article)
7539                        (not (eq gnus-current-article article))))
7540               force)
7541           ;; The requested article is different from the current article.
7542           (progn
7543             (gnus-summary-display-article article all-headers)
7544             (when (gnus-buffer-live-p gnus-article-buffer)
7545               (with-current-buffer gnus-article-buffer
7546                 (if (not gnus-article-decoded-p) ;; a local variable
7547                     (mm-disable-multibyte))))
7548             (gnus-article-set-window-start
7549              (cdr (assq article gnus-newsgroup-bookmarks)))
7550             article)
7551         'old))))
7552
7553 (defun gnus-summary-force-verify-and-decrypt ()
7554   "Display buttons for signed/encrypted parts and verify/decrypt them."
7555   (interactive)
7556   (let ((mm-verify-option 'known)
7557         (mm-decrypt-option 'known)
7558         (gnus-article-emulate-mime t)
7559         (gnus-buttonized-mime-types (append (list "multipart/signed"
7560                                                   "multipart/encrypted")
7561                                             gnus-buttonized-mime-types)))
7562     (gnus-summary-select-article nil 'force)))
7563
7564 (defun gnus-summary-set-current-mark (&optional current-mark)
7565   "Obsolete function."
7566   nil)
7567
7568 (defun gnus-summary-next-article (&optional unread subject backward push)
7569   "Select the next article.
7570 If UNREAD, only unread articles are selected.
7571 If SUBJECT, only articles with SUBJECT are selected.
7572 If BACKWARD, the previous article is selected instead of the next."
7573   (interactive "P")
7574   ;; Make sure we are in the summary buffer.
7575   (unless (eq major-mode 'gnus-summary-mode)
7576     (set-buffer gnus-summary-buffer))
7577   (cond
7578    ;; Is there such an article?
7579    ((and (gnus-summary-search-forward unread subject backward)
7580          (or (gnus-summary-display-article (gnus-summary-article-number))
7581              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7582     (gnus-summary-position-point))
7583    ;; If not, we try the first unread, if that is wanted.
7584    ((and subject
7585          gnus-auto-select-same
7586          (gnus-summary-first-unread-article))
7587     (gnus-summary-position-point)
7588     (gnus-message 6 "Wrapped"))
7589    ;; Try to get next/previous article not displayed in this group.
7590    ((and gnus-auto-extend-newsgroup
7591          (not unread) (not subject))
7592     (gnus-summary-goto-article
7593      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7594      nil (count-lines (point-min) (point))))
7595    ;; Go to next/previous group.
7596    (t
7597     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7598       (gnus-summary-jump-to-group gnus-newsgroup-name))
7599     (let ((cmd last-command-char)
7600           (point
7601            (with-current-buffer gnus-group-buffer
7602              (point)))
7603           (group
7604            (if (eq gnus-keep-same-level 'best)
7605                (gnus-summary-best-group gnus-newsgroup-name)
7606              (gnus-summary-search-group backward gnus-keep-same-level))))
7607       ;; For some reason, the group window gets selected.  We change
7608       ;; it back.
7609       (select-window (get-buffer-window (current-buffer)))
7610       ;; Select next unread newsgroup automagically.
7611       (cond
7612        ((or (not gnus-auto-select-next)
7613             (not cmd))
7614         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7615        ((or (eq gnus-auto-select-next 'quietly)
7616             (and (eq gnus-auto-select-next 'slightly-quietly)
7617                  push)
7618             (and (eq gnus-auto-select-next 'almost-quietly)
7619                  (gnus-summary-last-article-p)))
7620         ;; Select quietly.
7621         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7622             (gnus-summary-exit)
7623           (gnus-message 7 "No more%s articles (%s)..."
7624                         (if unread " unread" "")
7625                         (if group (concat "selecting " group)
7626                           "exiting"))
7627           (gnus-summary-next-group nil group backward)))
7628        (t
7629         (when (gnus-key-press-event-p last-input-event)
7630           (gnus-summary-walk-group-buffer
7631            gnus-newsgroup-name cmd unread backward point))))))))
7632
7633 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7634   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7635                       (?\C-p (gnus-group-prev-unread-group 1))))
7636         (cursor-in-echo-area t)
7637         keve key group ended prompt)
7638     (with-current-buffer gnus-group-buffer
7639       (goto-char start)
7640       (setq group
7641             (if (eq gnus-keep-same-level 'best)
7642                 (gnus-summary-best-group gnus-newsgroup-name)
7643               (gnus-summary-search-group backward gnus-keep-same-level))))
7644     (while (not ended)
7645       (setq prompt
7646             (format
7647              "No more%s articles%s " (if unread " unread" "")
7648              (if (and group
7649                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7650                  (format " (Type %s for %s [%s])"
7651                          (single-key-description cmd)
7652                          (gnus-group-decoded-name group)
7653                          (gnus-group-unread group))
7654                (format " (Type %s to exit %s)"
7655                        (single-key-description cmd)
7656                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7657       ;; Confirm auto selection.
7658       (setq key (car (setq keve (gnus-read-event-char prompt)))
7659             ended t)
7660       (cond
7661        ((assq key keystrokes)
7662         (let ((obuf (current-buffer)))
7663           (switch-to-buffer gnus-group-buffer)
7664           (when group
7665             (gnus-group-jump-to-group group))
7666           (eval (cadr (assq key keystrokes)))
7667           (setq group (gnus-group-group-name))
7668           (switch-to-buffer obuf))
7669         (setq ended nil))
7670        ((equal key cmd)
7671         (if (or (not group)
7672                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7673             (gnus-summary-exit)
7674           (gnus-summary-next-group nil group backward)))
7675        (t
7676         (push (cdr keve) unread-command-events))))))
7677
7678 (defun gnus-summary-next-unread-article ()
7679   "Select unread article after current one."
7680   (interactive)
7681   (gnus-summary-next-article
7682    (or (not (eq gnus-summary-goto-unread 'never))
7683        (gnus-summary-last-article-p (gnus-summary-article-number)))
7684    (and gnus-auto-select-same
7685         (gnus-summary-article-subject))))
7686
7687 (defun gnus-summary-prev-article (&optional unread subject)
7688   "Select the article before the current one.
7689 If UNREAD is non-nil, only unread articles are selected."
7690   (interactive "P")
7691   (gnus-summary-next-article unread subject t))
7692
7693 (defun gnus-summary-prev-unread-article ()
7694   "Select unread article before current one."
7695   (interactive)
7696   (gnus-summary-prev-article
7697    (or (not (eq gnus-summary-goto-unread 'never))
7698        (gnus-summary-first-article-p (gnus-summary-article-number)))
7699    (and gnus-auto-select-same
7700         (gnus-summary-article-subject))))
7701
7702 (defun gnus-summary-next-page (&optional lines circular stop)
7703   "Show next page of the selected article.
7704 If at the end of the current article, select the next article.
7705 LINES says how many lines should be scrolled up.
7706
7707 If CIRCULAR is non-nil, go to the start of the article instead of
7708 selecting the next article when reaching the end of the current
7709 article.
7710
7711 If STOP is non-nil, just stop when reaching the end of the message.
7712
7713 Also see the variable `gnus-article-skip-boring'."
7714   (interactive "P")
7715   (setq gnus-summary-buffer (current-buffer))
7716   (gnus-set-global-variables)
7717   (let ((article (gnus-summary-article-number))
7718         (article-window (get-buffer-window gnus-article-buffer t))
7719         endp)
7720     ;; If the buffer is empty, we have no article.
7721     (unless article
7722       (error "No article to select"))
7723     (gnus-configure-windows 'article)
7724     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7725         (if (and (eq gnus-summary-goto-unread 'never)
7726                  (not (gnus-summary-last-article-p article)))
7727             (gnus-summary-next-article)
7728           (gnus-summary-next-unread-article))
7729       (if (or (null gnus-current-article)
7730               (null gnus-article-current)
7731               (/= article (cdr gnus-article-current))
7732               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7733           ;; Selected subject is different from current article's.
7734           (gnus-summary-display-article article)
7735         (when article-window
7736           (gnus-eval-in-buffer-window gnus-article-buffer
7737             (setq endp (or (gnus-article-next-page lines)
7738                            (gnus-article-only-boring-p))))
7739           (when endp
7740             (cond (stop
7741                    (gnus-message 3 "End of message"))
7742                   (circular
7743                    (gnus-summary-beginning-of-article))
7744                   (lines
7745                    (gnus-message 3 "End of message"))
7746                   ((null lines)
7747                    (if (and (eq gnus-summary-goto-unread 'never)
7748                             (not (gnus-summary-last-article-p article)))
7749                        (gnus-summary-next-article)
7750                      (gnus-summary-next-unread-article))))))))
7751     (gnus-summary-recenter)
7752     (gnus-summary-position-point)))
7753
7754 (defun gnus-summary-prev-page (&optional lines move)
7755   "Show previous page of selected article.
7756 Argument LINES specifies lines to be scrolled down.
7757 If MOVE, move to the previous unread article if point is at
7758 the beginning of the buffer."
7759   (interactive "P")
7760   (let ((article (gnus-summary-article-number))
7761         (article-window (get-buffer-window gnus-article-buffer t))
7762         endp)
7763     (gnus-configure-windows 'article)
7764     (if (or (null gnus-current-article)
7765             (null gnus-article-current)
7766             (/= article (cdr gnus-article-current))
7767             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7768         ;; Selected subject is different from current article's.
7769         (gnus-summary-display-article article)
7770       (gnus-summary-recenter)
7771       (when article-window
7772         (gnus-eval-in-buffer-window gnus-article-buffer
7773           (setq endp (gnus-article-prev-page lines)))
7774         (when (and move endp)
7775           (cond (lines
7776                  (gnus-message 3 "Beginning of message"))
7777                 ((null lines)
7778                  (if (and (eq gnus-summary-goto-unread 'never)
7779                           (not (gnus-summary-first-article-p article)))
7780                      (gnus-summary-prev-article)
7781                    (gnus-summary-prev-unread-article))))))))
7782   (gnus-summary-position-point))
7783
7784 (defun gnus-summary-prev-page-or-article (&optional lines)
7785   "Show previous page of selected article.
7786 Argument LINES specifies lines to be scrolled down.
7787 If at the beginning of the article, go to the next article."
7788   (interactive "P")
7789   (gnus-summary-prev-page lines t))
7790
7791 (defun gnus-summary-scroll-up (lines)
7792   "Scroll up (or down) one line current article.
7793 Argument LINES specifies lines to be scrolled up (or down if negative)."
7794   (interactive "p")
7795   (gnus-configure-windows 'article)
7796   (gnus-summary-show-thread)
7797   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7798     (gnus-eval-in-buffer-window gnus-article-buffer
7799       (cond ((> lines 0)
7800              (when (gnus-article-next-page lines)
7801                (gnus-message 3 "End of message")))
7802             ((< lines 0)
7803              (gnus-article-prev-page (- lines))))))
7804   (gnus-summary-recenter)
7805   (gnus-summary-position-point))
7806
7807 (defun gnus-summary-scroll-down (lines)
7808   "Scroll down (or up) one line current article.
7809 Argument LINES specifies lines to be scrolled down (or up if negative)."
7810   (interactive "p")
7811   (gnus-summary-scroll-up (- lines)))
7812
7813 (defun gnus-summary-next-same-subject ()
7814   "Select next article which has the same subject as current one."
7815   (interactive)
7816   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7817
7818 (defun gnus-summary-prev-same-subject ()
7819   "Select previous article which has the same subject as current one."
7820   (interactive)
7821   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7822
7823 (defun gnus-summary-next-unread-same-subject ()
7824   "Select next unread article which has the same subject as current one."
7825   (interactive)
7826   (gnus-summary-next-article t (gnus-summary-article-subject)))
7827
7828 (defun gnus-summary-prev-unread-same-subject ()
7829   "Select previous unread article which has the same subject as current one."
7830   (interactive)
7831   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7832
7833 (defun gnus-summary-first-unread-article ()
7834   "Select the first unread article.
7835 Return nil if there are no unread articles."
7836   (interactive)
7837   (prog1
7838       (when (gnus-summary-first-subject t)
7839         (gnus-summary-show-thread)
7840         (gnus-summary-first-subject t)
7841         (gnus-summary-display-article (gnus-summary-article-number)))
7842     (gnus-summary-position-point)))
7843
7844 (defun gnus-summary-first-unread-subject ()
7845   "Place the point on the subject line of the first unread article.
7846 Return nil if there are no unread articles."
7847   (interactive)
7848   (prog1
7849       (when (gnus-summary-first-subject t)
7850         (gnus-summary-show-thread)
7851         (gnus-summary-first-subject t))
7852     (gnus-summary-position-point)))
7853
7854 (defun gnus-summary-first-unseen-subject ()
7855   "Place the point on the subject line of the first unseen article.
7856 Return nil if there are no unseen articles."
7857   (interactive)
7858   (prog1
7859       (when (gnus-summary-first-subject nil nil t)
7860         (gnus-summary-show-thread)
7861         (gnus-summary-first-subject nil nil t))
7862     (gnus-summary-position-point)))
7863
7864 (defun gnus-summary-first-unseen-or-unread-subject ()
7865   "Place the point on the subject line of the first unseen article or,
7866 if all article have been seen, on the subject line of the first unread
7867 article."
7868   (interactive)
7869   (prog1
7870       (unless (when (gnus-summary-first-subject nil nil t)
7871                 (gnus-summary-show-thread)
7872                 (gnus-summary-first-subject nil nil t))
7873         (when (gnus-summary-first-subject t)
7874           (gnus-summary-show-thread)
7875           (gnus-summary-first-subject t)))
7876     (gnus-summary-position-point)))
7877
7878 (defun gnus-summary-first-article ()
7879   "Select the first article.
7880 Return nil if there are no articles."
7881   (interactive)
7882   (prog1
7883       (when (gnus-summary-first-subject)
7884         (gnus-summary-show-thread)
7885         (gnus-summary-first-subject)
7886         (gnus-summary-display-article (gnus-summary-article-number)))
7887     (gnus-summary-position-point)))
7888
7889 (defun gnus-summary-best-unread-article (&optional arg)
7890   "Select the unread article with the highest score.
7891 If given a prefix argument, select the next unread article that has a
7892 score higher than the default score."
7893   (interactive "P")
7894   (let ((article (if arg
7895                      (gnus-summary-better-unread-subject)
7896                    (gnus-summary-best-unread-subject))))
7897     (if article
7898         (gnus-summary-goto-article article)
7899       (error "No unread articles"))))
7900
7901 (defun gnus-summary-best-unread-subject ()
7902   "Select the unread subject with the highest score."
7903   (interactive)
7904   (let ((best -1000000)
7905         (data gnus-newsgroup-data)
7906         article score)
7907     (while data
7908       (and (gnus-data-unread-p (car data))
7909            (> (setq score
7910                     (gnus-summary-article-score (gnus-data-number (car data))))
7911               best)
7912            (setq best score
7913                  article (gnus-data-number (car data))))
7914       (setq data (cdr data)))
7915     (when article
7916       (gnus-summary-goto-subject article))
7917     (gnus-summary-position-point)
7918     article))
7919
7920 (defun gnus-summary-better-unread-subject ()
7921   "Select the first unread subject that has a score over the default score."
7922   (interactive)
7923   (let ((data gnus-newsgroup-data)
7924         article score)
7925     (while (and (setq article (gnus-data-number (car data)))
7926                 (or (gnus-data-read-p (car data))
7927                     (not (> (gnus-summary-article-score article)
7928                             gnus-summary-default-score))))
7929       (setq data (cdr data)))
7930     (when article
7931       (gnus-summary-goto-subject article))
7932     (gnus-summary-position-point)
7933     article))
7934
7935 (defun gnus-summary-last-subject ()
7936   "Go to the last displayed subject line in the group."
7937   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7938     (when article
7939       (gnus-summary-goto-subject article))))
7940
7941 (defun gnus-summary-goto-article (article &optional all-headers force)
7942   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7943 If ALL-HEADERS is non-nil, no header lines are hidden.
7944 If FORCE, go to the article even if it isn't displayed.  If FORCE
7945 is a number, it is the line the article is to be displayed on."
7946   (interactive
7947    (list
7948     (completing-read
7949      "Article number or Message-ID: "
7950      (mapcar (lambda (number) (list (int-to-string number)))
7951              gnus-newsgroup-limit))
7952     current-prefix-arg
7953     t))
7954   (prog1
7955       (if (and (stringp article)
7956                (string-match "@\\|%40" article))
7957           (gnus-summary-refer-article article)
7958         (when (stringp article)
7959           (setq article (string-to-number article)))
7960         (if (gnus-summary-goto-subject article force)
7961             (gnus-summary-display-article article all-headers)
7962           (gnus-message 4 "Couldn't go to article %s" article) nil))
7963     (gnus-summary-position-point)))
7964
7965 (defun gnus-summary-goto-last-article ()
7966   "Go to the previously read article."
7967   (interactive)
7968   (prog1
7969       (when gnus-last-article
7970         (gnus-summary-goto-article gnus-last-article nil t))
7971     (gnus-summary-position-point)))
7972
7973 (defun gnus-summary-pop-article (number)
7974   "Pop one article off the history and go to the previous.
7975 NUMBER articles will be popped off."
7976   (interactive "p")
7977   (let (to)
7978     (setq gnus-newsgroup-history
7979           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7980     (if to
7981         (gnus-summary-goto-article (car to) nil t)
7982       (error "Article history empty")))
7983   (gnus-summary-position-point))
7984
7985 ;; Summary commands and functions for limiting the summary buffer.
7986
7987 (defun gnus-summary-limit-to-articles (n)
7988   "Limit the summary buffer to the next N articles.
7989 If not given a prefix, use the process marked articles instead."
7990   (interactive "P")
7991   (prog1
7992       (let ((articles (gnus-summary-work-articles n)))
7993         (setq gnus-newsgroup-processable nil)
7994         (gnus-summary-limit articles))
7995     (gnus-summary-position-point)))
7996
7997 (defun gnus-summary-pop-limit (&optional total)
7998   "Restore the previous limit.
7999 If given a prefix, remove all limits."
8000   (interactive "P")
8001   (when total
8002     (setq gnus-newsgroup-limits
8003           (list (mapcar (lambda (h) (mail-header-number h))
8004                         gnus-newsgroup-headers))))
8005   (unless gnus-newsgroup-limits
8006     (error "No limit to pop"))
8007   (prog1
8008       (gnus-summary-limit nil 'pop)
8009     (gnus-summary-position-point)))
8010
8011 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
8012   "Limit the summary buffer to articles that have subjects that match a regexp.
8013 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
8014   (interactive
8015    (list (read-string (if current-prefix-arg
8016                           "Exclude subject (regexp): "
8017                         "Limit to subject (regexp): "))
8018          nil current-prefix-arg))
8019   (unless header
8020     (setq header "subject"))
8021   (when (not (equal "" subject))
8022     (prog1
8023         (let ((articles (gnus-summary-find-matching
8024                          (or header "subject") subject 'all nil nil
8025                          not-matching)))
8026           (unless articles
8027             (error "Found no matches for \"%s\"" subject))
8028           (gnus-summary-limit articles))
8029       (gnus-summary-position-point))))
8030
8031 (defun gnus-summary-limit-to-author (from &optional not-matching)
8032   "Limit the summary buffer to articles that have authors that match a regexp.
8033 If NOT-MATCHING, excluding articles that have authors that match a regexp."
8034   (interactive
8035    (list (read-string (if current-prefix-arg
8036                           "Exclude author (regexp): "
8037                         "Limit to author (regexp): "))
8038          current-prefix-arg))
8039   (gnus-summary-limit-to-subject from "from" not-matching))
8040
8041 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8042   "Limit the summary buffer to articles with the given RECIPIENT.
8043
8044 If NOT-MATCHING, exclude RECIPIENT.
8045
8046 To and Cc headers are checked.  You need to include them in
8047 `nnmail-extra-headers'."
8048   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8049   (interactive
8050    (list (read-string (format "%s recipient (regexp): "
8051                               (if current-prefix-arg "Exclude" "Limit to")))
8052          current-prefix-arg))
8053   (when (not (equal "" recipient))
8054     (prog1 (let* ((to
8055                    (if (memq 'To nnmail-extra-headers)
8056                        (gnus-summary-find-matching
8057                         (cons 'extra 'To) recipient 'all nil nil
8058                         not-matching)
8059                      (gnus-message
8060                       1 "`To' isn't present in `nnmail-extra-headers'")
8061                      (sit-for 1)
8062                      nil))
8063                   (cc
8064                    (if (memq 'Cc nnmail-extra-headers)
8065                        (gnus-summary-find-matching
8066                         (cons 'extra 'Cc) recipient 'all nil nil
8067                         not-matching)
8068                      (gnus-message
8069                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8070                      (sit-for 1)
8071                      nil))
8072                   (articles
8073                    (if not-matching
8074                        ;; We need the numbers that are in both lists:
8075                        (mapcar (lambda (a)
8076                                  (and (memq a to) a))
8077                                cc)
8078                      (nconc to cc))))
8079              (unless articles
8080                (error "Found no matches for \"%s\"" recipient))
8081              (gnus-summary-limit articles))
8082       (gnus-summary-position-point))))
8083
8084 (defun gnus-summary-limit-to-address (address &optional not-matching)
8085   "Limit the summary buffer to articles with the given ADDRESS.
8086
8087 If NOT-MATCHING, exclude ADDRESS.
8088
8089 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8090 in `nnmail-extra-headers'."
8091   (interactive
8092    (list (read-string (format "%s address (regexp): "
8093                               (if current-prefix-arg "Exclude" "Limit to")))
8094          current-prefix-arg))
8095   (when (not (equal "" address))
8096     (prog1 (let* ((to
8097                    (if (memq 'To nnmail-extra-headers)
8098                        (gnus-summary-find-matching
8099                         (cons 'extra 'To) address 'all nil nil
8100                         not-matching)
8101                      (gnus-message
8102                       1 "`To' isn't present in `nnmail-extra-headers'")
8103                      (sit-for 1)
8104                      t))
8105                   (cc
8106                    (if (memq 'Cc nnmail-extra-headers)
8107                        (gnus-summary-find-matching
8108                         (cons 'extra 'Cc) address 'all nil nil
8109                         not-matching)
8110                      (gnus-message
8111                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8112                      (sit-for 1)
8113                      t))
8114                   (from
8115                    (gnus-summary-find-matching "from" address
8116                                                'all nil nil not-matching))
8117                   (articles
8118                    (if not-matching
8119                        ;; We need the numbers that are in all lists:
8120                        (if (eq cc t)
8121                            (if (eq to t)
8122                                from
8123                              (mapcar (lambda (a) (car (memq a from))) to))
8124                          (if (eq to t)
8125                              (mapcar (lambda (a) (car (memq a from))) cc)
8126                            (mapcar (lambda (a) (car (memq a from)))
8127                                    (mapcar (lambda (a) (car (memq a to)))
8128                                            cc))))
8129                      (nconc (if (eq to t) nil to)
8130                             (if (eq cc t) nil cc)
8131                             from))))
8132              (unless articles
8133                (error "Found no matches for \"%s\"" address))
8134              (gnus-summary-limit articles))
8135       (gnus-summary-position-point))))
8136
8137 (defun gnus-summary-limit-strange-charsets-predicate (header)
8138   (let ((string (concat (mail-header-subject header)
8139                         (mail-header-from header)))
8140         charset found)
8141     (dotimes (i (1- (length string)))
8142       (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8143       (when (string-match "unicode\\|big\\|japanese" charset)
8144         (setq found t)))
8145     found))
8146
8147 (defun gnus-summary-limit-to-predicate (predicate)
8148   "Limit to articles where PREDICATE returns non-nil.
8149 PREDICATE will be called with the header structures of the
8150 articles."
8151   (let ((articles nil)
8152         (case-fold-search t))
8153     (dolist (header gnus-newsgroup-headers)
8154       (when (funcall predicate header)
8155         (push (mail-header-number header) articles)))
8156     (gnus-summary-limit (nreverse articles))))
8157
8158 (defun gnus-summary-limit-to-age (age &optional younger-p)
8159   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8160 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8161 articles that are younger than AGE days."
8162   (interactive
8163    (let ((younger current-prefix-arg)
8164          (days-got nil)
8165          days)
8166      (while (not days-got)
8167        (setq days (if younger
8168                       (read-string "Limit to articles younger than (in days, older when negative): ")
8169                     (read-string
8170                      "Limit to articles older than (in days, younger when negative): ")))
8171        (when (> (length days) 0)
8172          (setq days (read days)))
8173        (if (numberp days)
8174            (progn
8175              (setq days-got t)
8176              (when (< days 0)
8177                (setq younger (not younger))
8178                (setq days (* days -1))))
8179          (message "Please enter a number.")
8180          (sleep-for 1)))
8181      (list days younger)))
8182   (prog1
8183       (let ((data gnus-newsgroup-data)
8184             (cutoff (days-to-time age))
8185             articles d date is-younger)
8186         (while (setq d (pop data))
8187           (when (and (vectorp (gnus-data-header d))
8188                      (setq date (mail-header-date (gnus-data-header d))))
8189             (setq is-younger (time-less-p
8190                               (time-since (condition-case ()
8191                                               (date-to-time date)
8192                                             (error '(0 0))))
8193                               cutoff))
8194             (when (if younger-p
8195                       is-younger
8196                     (not is-younger))
8197               (push (gnus-data-number d) articles))))
8198         (gnus-summary-limit (nreverse articles)))
8199     (gnus-summary-position-point)))
8200
8201 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8202   "Limit the summary buffer to articles that match an 'extra' header."
8203   (interactive
8204    (let ((header
8205           (intern
8206            (gnus-completing-read-with-default
8207             (symbol-name (car gnus-extra-headers))
8208             (if current-prefix-arg
8209                 "Exclude extra header"
8210               "Limit extra header")
8211             (mapcar (lambda (x)
8212                       (cons (symbol-name x) x))
8213                     gnus-extra-headers)
8214             nil
8215             t))))
8216      (list header
8217            (read-string (format "%s header %s (regexp): "
8218                                 (if current-prefix-arg "Exclude" "Limit to")
8219                                 header))
8220            current-prefix-arg)))
8221   (when (not (equal "" regexp))
8222     (prog1
8223         (let ((articles (gnus-summary-find-matching
8224                          (cons 'extra header) regexp 'all nil nil
8225                          not-matching)))
8226           (unless articles
8227             (error "Found no matches for \"%s\"" regexp))
8228           (gnus-summary-limit articles))
8229       (gnus-summary-position-point))))
8230
8231 (defun gnus-summary-limit-to-display-predicate ()
8232   "Limit the summary buffer to the predicated in the `display' group parameter."
8233   (interactive)
8234   (unless gnus-newsgroup-display
8235     (error "There is no `display' group parameter"))
8236   (let (articles)
8237     (dolist (number gnus-newsgroup-articles)
8238       (when (funcall gnus-newsgroup-display)
8239         (push number articles)))
8240     (gnus-summary-limit articles))
8241   (gnus-summary-position-point))
8242
8243 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8244 (make-obsolete
8245  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8246
8247 (defun gnus-summary-limit-to-unread (&optional all)
8248   "Limit the summary buffer to articles that are not marked as read.
8249 If ALL is non-nil, limit strictly to unread articles."
8250   (interactive "P")
8251   (if all
8252       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8253     (gnus-summary-limit-to-marks
8254      ;; Concat all the marks that say that an article is read and have
8255      ;; those removed.
8256      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8257            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8258            gnus-low-score-mark gnus-expirable-mark
8259            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8260            gnus-duplicate-mark gnus-souped-mark)
8261      'reverse)))
8262
8263 (defun gnus-summary-limit-to-headers (match &optional reverse)
8264   "Limit the summary buffer to articles that have headers that match MATCH.
8265 If REVERSE (the prefix), limit to articles that don't match."
8266   (interactive "sMatch headers (regexp): \nP")
8267   (gnus-summary-limit-to-bodies match reverse t))
8268
8269 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8270   "Limit the summary buffer to articles that have bodies that match MATCH.
8271 If REVERSE (the prefix), limit to articles that don't match."
8272   (interactive "sMatch body (regexp): \nP")
8273   (let ((articles nil)
8274         (gnus-select-article-hook nil)  ;Disable hook.
8275         (gnus-article-prepare-hook nil)
8276         (gnus-use-article-prefetch nil)
8277         (gnus-keep-backlog nil)
8278         (gnus-break-pages nil)
8279         (gnus-summary-display-arrow nil)
8280         (gnus-updated-mode-lines nil)
8281         (gnus-auto-center-summary nil)
8282         (gnus-display-mime-function nil))
8283     (dolist (data gnus-newsgroup-data)
8284       (let (gnus-mark-article-hook)
8285         (gnus-summary-select-article t t nil (gnus-data-number data)))
8286       (save-excursion
8287         (set-buffer gnus-article-buffer)
8288         (article-goto-body)
8289         (let* ((case-fold-search t)
8290                (found (if headersp
8291                           (re-search-backward match nil t)
8292                         (re-search-forward match nil t))))
8293           (when (or (and found
8294                          (not reverse))
8295                     (and (not found)
8296                          reverse))
8297             (push (gnus-data-number data) articles)))))
8298     (if (not articles)
8299         (message "No messages matched")
8300       (gnus-summary-limit articles)))
8301   (gnus-summary-position-point))
8302
8303 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8304   "Limit the summary buffer to articles that aren't part on any thread.
8305 If THREADSP (the prefix), limit to articles that are in threads."
8306   (interactive "P")
8307   (let ((articles nil)
8308         thread-articles
8309         threads)
8310     (dolist (thread gnus-newsgroup-threads)
8311       (if (stringp (car thread))
8312           (dolist (thread (cdr thread))
8313             (push thread threads))
8314         (push thread threads)))
8315     (dolist (thread threads)
8316       (setq thread-articles (gnus-articles-in-thread thread))
8317       (when (or (and threadsp
8318                      (> (length thread-articles) 1))
8319                 (and (not threadsp)
8320                      (= (length thread-articles) 1)))
8321         (setq articles (nconc thread-articles articles))))
8322     (if (not articles)
8323         (message "No messages matched")
8324       (gnus-summary-limit articles))
8325     (gnus-summary-position-point)))
8326
8327 (defun gnus-summary-limit-to-replied (&optional unreplied)
8328   "Limit the summary buffer to replied articles.
8329 If UNREPLIED (the prefix), limit to unreplied articles."
8330   (interactive "P")
8331   (if unreplied
8332       (gnus-summary-limit
8333        (gnus-set-difference gnus-newsgroup-articles
8334         gnus-newsgroup-replied))
8335     (gnus-summary-limit gnus-newsgroup-replied))
8336   (gnus-summary-position-point))
8337
8338 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8339 (make-obsolete 'gnus-summary-delete-marked-with
8340                'gnus-summary-limit-exclude-marks)
8341
8342 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8343   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8344 If REVERSE, limit the summary buffer to articles that are marked
8345 with MARKS.  MARKS can either be a string of marks or a list of marks.
8346 Returns how many articles were removed."
8347   (interactive "sMarks: ")
8348   (gnus-summary-limit-to-marks marks t))
8349
8350 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8351   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8352 If REVERSE (the prefix), limit the summary buffer to articles that are
8353 not marked with MARKS.  MARKS can either be a string of marks or a
8354 list of marks.
8355 Returns how many articles were removed."
8356   (interactive "sMarks: \nP")
8357   (prog1
8358       (let ((data gnus-newsgroup-data)
8359             (marks (if (listp marks) marks
8360                      (append marks nil))) ; Transform to list.
8361             articles)
8362         (while data
8363           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8364                   (memq (gnus-data-mark (car data)) marks))
8365             (push (gnus-data-number (car data)) articles))
8366           (setq data (cdr data)))
8367         (gnus-summary-limit articles))
8368     (gnus-summary-position-point)))
8369
8370 (defun gnus-summary-limit-to-score (score)
8371   "Limit to articles with score at or above SCORE."
8372   (interactive "NLimit to articles with score of at least: ")
8373   (let ((data gnus-newsgroup-data)
8374         articles)
8375     (while data
8376       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8377                 score)
8378         (push (gnus-data-number (car data)) articles))
8379       (setq data (cdr data)))
8380     (prog1
8381         (gnus-summary-limit articles)
8382       (gnus-summary-position-point))))
8383
8384 (defun gnus-summary-limit-to-unseen ()
8385   "Limit to unseen articles."
8386   (interactive)
8387   (prog1
8388       (gnus-summary-limit gnus-newsgroup-unseen)
8389     (gnus-summary-position-point)))
8390
8391 (defun gnus-summary-limit-include-thread (id)
8392   "Display all the hidden articles that is in the thread with ID in it.
8393 When called interactively, ID is the Message-ID of the current
8394 article."
8395   (interactive (list (mail-header-id (gnus-summary-article-header))))
8396   (let ((articles (gnus-articles-in-thread
8397                    (gnus-id-to-thread (gnus-root-id id)))))
8398     (prog1
8399         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8400       (gnus-summary-limit-include-matching-articles
8401        "subject"
8402        (regexp-quote (gnus-simplify-subject-re
8403                       (mail-header-subject (gnus-id-to-header id)))))
8404       (gnus-summary-position-point))))
8405
8406 (defun gnus-summary-limit-include-matching-articles (header regexp)
8407   "Display all the hidden articles that have HEADERs that match REGEXP."
8408   (interactive (list (read-string "Match on header: ")
8409                      (read-string "Regexp: ")))
8410   (let ((articles (gnus-find-matching-articles header regexp)))
8411     (prog1
8412         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8413       (gnus-summary-position-point))))
8414
8415 (defun gnus-summary-insert-dormant-articles ()
8416   "Insert all the dormant articles for this group into the current buffer."
8417   (interactive)
8418   (let ((gnus-verbose (max 6 gnus-verbose)))
8419     (if (not gnus-newsgroup-dormant)
8420         (gnus-message 3 "No dormant articles for this group")
8421       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8422
8423 (defun gnus-summary-insert-ticked-articles ()
8424   "Insert ticked articles for this group into the current buffer."
8425   (interactive)
8426   (let ((gnus-verbose (max 6 gnus-verbose)))
8427     (if (not gnus-newsgroup-marked)
8428         (gnus-message 3 "No ticked articles for this group")
8429       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8430
8431 (defun gnus-summary-limit-include-dormant ()
8432   "Display all the hidden articles that are marked as dormant.
8433 Note that this command only works on a subset of the articles currently
8434 fetched for this group."
8435   (interactive)
8436   (unless gnus-newsgroup-dormant
8437     (error "There are no dormant articles in this group"))
8438   (prog1
8439       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8440     (gnus-summary-position-point)))
8441
8442 (defun gnus-summary-limit-exclude-dormant ()
8443   "Hide all dormant articles."
8444   (interactive)
8445   (prog1
8446       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8447     (gnus-summary-position-point)))
8448
8449 (defun gnus-summary-limit-exclude-childless-dormant ()
8450   "Hide all dormant articles that have no children."
8451   (interactive)
8452   (let ((data (gnus-data-list t))
8453         articles d children)
8454     ;; Find all articles that are either not dormant or have
8455     ;; children.
8456     (while (setq d (pop data))
8457       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8458                 (and (setq children
8459                            (gnus-article-children (gnus-data-number d)))
8460                      (let (found)
8461                        (while children
8462                          (when (memq (car children) articles)
8463                            (setq children nil
8464                                  found t))
8465                          (pop children))
8466                        found)))
8467         (push (gnus-data-number d) articles)))
8468     ;; Do the limiting.
8469     (prog1
8470         (gnus-summary-limit articles)
8471       (gnus-summary-position-point))))
8472
8473 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8474   "Mark all unread excluded articles as read.
8475 If ALL, mark even excluded ticked and dormants as read."
8476   (interactive "P")
8477   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8478   (let ((articles (gnus-sorted-ndifference
8479                    (sort
8480                     (mapcar (lambda (h) (mail-header-number h))
8481                             gnus-newsgroup-headers)
8482                     '<)
8483                    gnus-newsgroup-limit))
8484         article)
8485     (setq gnus-newsgroup-unreads
8486           (gnus-sorted-intersection gnus-newsgroup-unreads
8487                                     gnus-newsgroup-limit))
8488     (if all
8489         (setq gnus-newsgroup-dormant nil
8490               gnus-newsgroup-marked nil
8491               gnus-newsgroup-reads
8492               (nconc
8493                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8494                gnus-newsgroup-reads))
8495       (while (setq article (pop articles))
8496         (unless (or (memq article gnus-newsgroup-dormant)
8497                     (memq article gnus-newsgroup-marked))
8498           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8499
8500 (defun gnus-summary-limit (articles &optional pop)
8501   (if pop
8502       ;; We pop the previous limit off the stack and use that.
8503       (setq articles (car gnus-newsgroup-limits)
8504             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8505     ;; We use the new limit, so we push the old limit on the stack.
8506     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8507   ;; Set the limit.
8508   (setq gnus-newsgroup-limit articles)
8509   (let ((total (length gnus-newsgroup-data))
8510         (data (gnus-data-find-list (gnus-summary-article-number)))
8511         (gnus-summary-mark-below nil)   ; Inhibit this.
8512         found)
8513     ;; This will do all the work of generating the new summary buffer
8514     ;; according to the new limit.
8515     (gnus-summary-prepare)
8516     ;; Hide any threads, possibly.
8517     (gnus-summary-maybe-hide-threads)
8518     ;; Try to return to the article you were at, or one in the
8519     ;; neighborhood.
8520     (when data
8521       ;; We try to find some article after the current one.
8522       (while data
8523         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8524           (setq data nil
8525                 found t))
8526         (setq data (cdr data))))
8527     (unless found
8528       ;; If there is no data, that means that we were after the last
8529       ;; article.  The same goes when we can't find any articles
8530       ;; after the current one.
8531       (goto-char (point-max))
8532       (gnus-summary-find-prev))
8533     (gnus-set-mode-line 'summary)
8534     ;; We return how many articles were removed from the summary
8535     ;; buffer as a result of the new limit.
8536     (- total (length gnus-newsgroup-data))))
8537
8538 (defsubst gnus-invisible-cut-children (threads)
8539   (let ((num 0))
8540     (while threads
8541       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8542         (incf num))
8543       (pop threads))
8544     (< num 2)))
8545
8546 (defsubst gnus-cut-thread (thread)
8547   "Go forwards in the thread until we find an article that we want to display."
8548   (when (or (eq gnus-fetch-old-headers 'some)
8549             (eq gnus-fetch-old-headers 'invisible)
8550             (numberp gnus-fetch-old-headers)
8551             (eq gnus-build-sparse-threads 'some)
8552             (eq gnus-build-sparse-threads 'more))
8553     ;; Deal with old-fetched headers and sparse threads.
8554     (while (and
8555             thread
8556             (or
8557              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8558              (gnus-summary-article-ancient-p
8559               (mail-header-number (car thread))))
8560             (if (or (<= (length (cdr thread)) 1)
8561                     (eq gnus-fetch-old-headers 'invisible))
8562                 (setq gnus-newsgroup-limit
8563                       (delq (mail-header-number (car thread))
8564                             gnus-newsgroup-limit)
8565                       thread (cadr thread))
8566               (when (gnus-invisible-cut-children (cdr thread))
8567                 (let ((th (cdr thread)))
8568                   (while th
8569                     (if (memq (mail-header-number (caar th))
8570                               gnus-newsgroup-limit)
8571                         (setq thread (car th)
8572                               th nil)
8573                       (setq th (cdr th))))))))))
8574   thread)
8575
8576 (defun gnus-cut-threads (threads)
8577   "Cut off all uninteresting articles from the beginning of THREADS."
8578   (when (or (eq gnus-fetch-old-headers 'some)
8579             (eq gnus-fetch-old-headers 'invisible)
8580             (numberp gnus-fetch-old-headers)
8581             (eq gnus-build-sparse-threads 'some)
8582             (eq gnus-build-sparse-threads 'more))
8583     (let ((th threads))
8584       (while th
8585         (setcar th (gnus-cut-thread (car th)))
8586         (setq th (cdr th)))))
8587   ;; Remove nixed out threads.
8588   (delq nil threads))
8589
8590 (defun gnus-summary-initial-limit (&optional show-if-empty)
8591   "Figure out what the initial limit is supposed to be on group entry.
8592 This entails weeding out unwanted dormants, low-scored articles,
8593 fetch-old-headers verbiage, and so on."
8594   ;; Most groups have nothing to remove.
8595   (if (or gnus-inhibit-limiting
8596           (and (null gnus-newsgroup-dormant)
8597                (eq gnus-newsgroup-display 'gnus-not-ignore)
8598                (not (eq gnus-fetch-old-headers 'some))
8599                (not (numberp gnus-fetch-old-headers))
8600                (not (eq gnus-fetch-old-headers 'invisible))
8601                (null gnus-summary-expunge-below)
8602                (not (eq gnus-build-sparse-threads 'some))
8603                (not (eq gnus-build-sparse-threads 'more))
8604                (null gnus-thread-expunge-below)
8605                (not gnus-use-nocem)))
8606       ()                                ; Do nothing.
8607     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8608     (setq gnus-newsgroup-limit nil)
8609     (mapatoms
8610      (lambda (node)
8611        (unless (car (symbol-value node))
8612          ;; These threads have no parents -- they are roots.
8613          (let ((nodes (cdr (symbol-value node)))
8614                thread)
8615            (while nodes
8616              (if (and gnus-thread-expunge-below
8617                       (< (gnus-thread-total-score (car nodes))
8618                          gnus-thread-expunge-below))
8619                  (gnus-expunge-thread (pop nodes))
8620                (setq thread (pop nodes))
8621                (gnus-summary-limit-children thread))))))
8622      gnus-newsgroup-dependencies)
8623     ;; If this limitation resulted in an empty group, we might
8624     ;; pop the previous limit and use it instead.
8625     (when (and (not gnus-newsgroup-limit)
8626                show-if-empty)
8627       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8628     gnus-newsgroup-limit))
8629
8630 (defun gnus-summary-limit-children (thread)
8631   "Return 1 if this subthread is visible and 0 if it is not."
8632   ;; First we get the number of visible children to this thread.  This
8633   ;; is done by recursing down the thread using this function, so this
8634   ;; will really go down to a leaf article first, before slowly
8635   ;; working its way up towards the root.
8636   (when thread
8637     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8638            (children
8639            (if (cdr thread)
8640                (apply '+ (mapcar 'gnus-summary-limit-children
8641                                  (cdr thread)))
8642              0))
8643           (number (mail-header-number (car thread)))
8644           score)
8645       (if (and
8646            (not (memq number gnus-newsgroup-marked))
8647            (or
8648             ;; If this article is dormant and has absolutely no visible
8649             ;; children, then this article isn't visible.
8650             (and (memq number gnus-newsgroup-dormant)
8651                  (zerop children))
8652             ;; If this is "fetch-old-headered" and there is no
8653             ;; visible children, then we don't want this article.
8654             (and (or (eq gnus-fetch-old-headers 'some)
8655                      (numberp gnus-fetch-old-headers))
8656                  (gnus-summary-article-ancient-p number)
8657                  (zerop children))
8658             ;; If this is "fetch-old-headered" and `invisible', then
8659             ;; we don't want this article.
8660             (and (eq gnus-fetch-old-headers 'invisible)
8661                  (gnus-summary-article-ancient-p number))
8662             ;; If this is a sparsely inserted article with no children,
8663             ;; we don't want it.
8664             (and (eq gnus-build-sparse-threads 'some)
8665                  (gnus-summary-article-sparse-p number)
8666                  (zerop children))
8667             ;; If we use expunging, and this article is really
8668             ;; low-scored, then we don't want this article.
8669             (when (and gnus-summary-expunge-below
8670                        (< (setq score
8671                                 (or (cdr (assq number gnus-newsgroup-scored))
8672                                     gnus-summary-default-score))
8673                           gnus-summary-expunge-below))
8674               ;; We increase the expunge-tally here, but that has
8675               ;; nothing to do with the limits, really.
8676               (incf gnus-newsgroup-expunged-tally)
8677               ;; We also mark as read here, if that's wanted.
8678               (when (and gnus-summary-mark-below
8679                          (< score gnus-summary-mark-below))
8680                 (setq gnus-newsgroup-unreads
8681                       (delq number gnus-newsgroup-unreads))
8682                 (if gnus-newsgroup-auto-expire
8683                     (push number gnus-newsgroup-expirable)
8684                   (push (cons number gnus-low-score-mark)
8685                         gnus-newsgroup-reads)))
8686               t)
8687             ;; Do the `display' group parameter.
8688             (and gnus-newsgroup-display
8689                  (not (funcall gnus-newsgroup-display)))
8690             ;; Check NoCeM things.
8691             (when (and gnus-use-nocem
8692                        (gnus-nocem-unwanted-article-p
8693                         (mail-header-id (car thread))))
8694               (setq gnus-newsgroup-unreads
8695                     (delq number gnus-newsgroup-unreads))
8696               t)))
8697           ;; Nope, invisible article.
8698           0
8699         ;; Ok, this article is to be visible, so we add it to the limit
8700         ;; and return 1.
8701         (push number gnus-newsgroup-limit)
8702         1))))
8703
8704 (defun gnus-expunge-thread (thread)
8705   "Mark all articles in THREAD as read."
8706   (let* ((number (mail-header-number (car thread))))
8707     (incf gnus-newsgroup-expunged-tally)
8708     ;; We also mark as read here, if that's wanted.
8709     (setq gnus-newsgroup-unreads
8710           (delq number gnus-newsgroup-unreads))
8711     (if gnus-newsgroup-auto-expire
8712         (push number gnus-newsgroup-expirable)
8713       (push (cons number gnus-low-score-mark)
8714             gnus-newsgroup-reads)))
8715   ;; Go recursively through all subthreads.
8716   (mapcar 'gnus-expunge-thread (cdr thread)))
8717
8718 ;; Summary article oriented commands
8719
8720 (defun gnus-summary-refer-parent-article (n)
8721   "Refer parent article N times.
8722 If N is negative, go to ancestor -N instead.
8723 The difference between N and the number of articles fetched is returned."
8724   (interactive "p")
8725   (let ((skip 1)
8726         error header ref)
8727     (when (not (natnump n))
8728       (setq skip (abs n)
8729             n 1))
8730     (while (and (> n 0)
8731                 (not error))
8732       (setq header (gnus-summary-article-header))
8733       (if (and (eq (mail-header-number header)
8734                    (cdr gnus-article-current))
8735                (equal gnus-newsgroup-name
8736                       (car gnus-article-current)))
8737           ;; If we try to find the parent of the currently
8738           ;; displayed article, then we take a look at the actual
8739           ;; References header, since this is slightly more
8740           ;; reliable than the References field we got from the
8741           ;; server.
8742           (with-current-buffer gnus-original-article-buffer
8743             (nnheader-narrow-to-headers)
8744             (unless (setq ref (message-fetch-field "references"))
8745               (when (setq ref (message-fetch-field "in-reply-to"))
8746                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8747             (widen))
8748         (setq ref
8749               ;; It's not the current article, so we take a bet on
8750               ;; the value we got from the server.
8751               (mail-header-references header)))
8752       (if (and ref
8753                (not (equal ref "")))
8754           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8755             (gnus-message 1 "Couldn't find parent"))
8756         (gnus-message 1 "No references in article %d"
8757                       (gnus-summary-article-number))
8758         (setq error t))
8759       (decf n))
8760     (gnus-summary-position-point)
8761     n))
8762
8763 (defun gnus-summary-refer-references ()
8764   "Fetch all articles mentioned in the References header.
8765 Return the number of articles fetched."
8766   (interactive)
8767   (let ((ref (mail-header-references (gnus-summary-article-header)))
8768         (current (gnus-summary-article-number))
8769         (n 0))
8770     (if (or (not ref)
8771             (equal ref ""))
8772         (error "No References in the current article")
8773       ;; For each Message-ID in the References header...
8774       (while (string-match "<[^>]*>" ref)
8775         (incf n)
8776         ;; ... fetch that article.
8777         (gnus-summary-refer-article
8778          (prog1 (match-string 0 ref)
8779            (setq ref (substring ref (match-end 0))))))
8780       (gnus-summary-goto-subject current)
8781       (gnus-summary-position-point)
8782       n)))
8783
8784 (defun gnus-summary-refer-thread (&optional limit)
8785   "Fetch all articles in the current thread.
8786 If LIMIT (the numerical prefix), fetch that many old headers instead
8787 of what's specified by the `gnus-refer-thread-limit' variable."
8788   (interactive "P")
8789   (let ((id (mail-header-id (gnus-summary-article-header)))
8790         (limit (if limit (prefix-numeric-value limit)
8791                  gnus-refer-thread-limit)))
8792     (unless (eq gnus-fetch-old-headers 'invisible)
8793       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8794       ;; Retrieve the headers and read them in.
8795       (if (eq (if (numberp limit)
8796                   (gnus-retrieve-headers
8797                    (list (min
8798                           (+ (mail-header-number
8799                               (gnus-summary-article-header))
8800                              limit)
8801                           gnus-newsgroup-end))
8802                    gnus-newsgroup-name (* limit 2))
8803                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8804                 ;; headers.
8805                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8806                                        gnus-newsgroup-name limit))
8807               'nov)
8808           (gnus-build-all-threads)
8809         (error "Can't fetch thread from back ends that don't support NOV"))
8810       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8811     (gnus-summary-limit-include-thread id)))
8812
8813 (defun gnus-summary-refer-article (message-id)
8814   "Fetch an article specified by MESSAGE-ID."
8815   (interactive "sMessage-ID: ")
8816   (when (and (stringp message-id)
8817              (not (zerop (length message-id))))
8818     (setq message-id (gnus-replace-in-string message-id " " ""))
8819     ;; Construct the correct Message-ID if necessary.
8820     ;; Suggested by tale@pawl.rpi.edu.
8821     (unless (string-match "^<" message-id)
8822       (setq message-id (concat "<" message-id)))
8823     (unless (string-match ">$" message-id)
8824       (setq message-id (concat message-id ">")))
8825     ;; People often post MIDs from URLs, so unhex it:
8826     (unless (string-match "@" message-id)
8827       (setq message-id (gnus-url-unhex-string message-id)))
8828     (let* ((header (gnus-id-to-header message-id))
8829            (sparse (and header
8830                         (gnus-summary-article-sparse-p
8831                          (mail-header-number header))
8832                         (memq (mail-header-number header)
8833                               gnus-newsgroup-limit)))
8834            number)
8835       (cond
8836        ;; If the article is present in the buffer we just go to it.
8837        ((and header
8838              (or (not (gnus-summary-article-sparse-p
8839                        (mail-header-number header)))
8840                  sparse))
8841         (prog1
8842             (gnus-summary-goto-article
8843              (mail-header-number header) nil t)
8844           (when sparse
8845             (gnus-summary-update-article (mail-header-number header)))))
8846        (t
8847         ;; We fetch the article.
8848         (catch 'found
8849           (dolist (gnus-override-method (gnus-refer-article-methods))
8850             (when (and (gnus-check-server gnus-override-method)
8851                        ;; Fetch the header,
8852                        (setq number (gnus-summary-insert-subject message-id)))
8853               ;; and display the article.
8854               (gnus-summary-select-article nil nil nil number)
8855               (throw 'found t)))
8856           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8857
8858 (defun gnus-refer-article-methods ()
8859   "Return a list of referable methods."
8860   (cond
8861    ;; No method, so we default to current and native.
8862    ((null gnus-refer-article-method)
8863     (list gnus-current-select-method gnus-select-method))
8864    ;; Current.
8865    ((eq 'current gnus-refer-article-method)
8866     (list gnus-current-select-method))
8867    ;; List of select methods.
8868    ((not (and (symbolp (car gnus-refer-article-method))
8869               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8870     (let (out)
8871       (dolist (method gnus-refer-article-method)
8872         (push (if (eq 'current method)
8873                   gnus-current-select-method
8874                 method)
8875               out))
8876       (nreverse out)))
8877    ;; One single select method.
8878    (t
8879     (list gnus-refer-article-method))))
8880
8881 (defun gnus-summary-edit-parameters ()
8882   "Edit the group parameters of the current group."
8883   (interactive)
8884   (gnus-group-edit-group gnus-newsgroup-name 'params))
8885
8886 (defun gnus-summary-customize-parameters ()
8887   "Customize the group parameters of the current group."
8888   (interactive)
8889   (gnus-group-customize gnus-newsgroup-name))
8890
8891 (defun gnus-summary-enter-digest-group (&optional force)
8892   "Enter an nndoc group based on the current article.
8893 If FORCE, force a digest interpretation.  If not, try
8894 to guess what the document format is."
8895   (interactive "P")
8896   (let ((conf gnus-current-window-configuration))
8897     (save-window-excursion
8898       (save-excursion
8899         (let (gnus-article-prepare-hook
8900               gnus-display-mime-function
8901               gnus-break-pages)
8902           (gnus-summary-select-article))))
8903     (setq gnus-current-window-configuration conf)
8904     (let* ((name (format "%s-%d"
8905                          (gnus-group-prefixed-name
8906                           gnus-newsgroup-name (list 'nndoc ""))
8907                          (with-current-buffer gnus-summary-buffer
8908                            gnus-current-article)))
8909            (ogroup gnus-newsgroup-name)
8910            (params (append (gnus-info-params (gnus-get-info ogroup))
8911                            (list (cons 'to-group ogroup))
8912                            (list (cons 'parent-group ogroup))
8913                            (list (cons 'save-article-group ogroup))))
8914            (case-fold-search t)
8915            (buf (current-buffer))
8916            dig to-address)
8917       (with-current-buffer gnus-original-article-buffer
8918         ;; Have the digest group inherit the main mail address of
8919         ;; the parent article.
8920         (when (setq to-address (or (gnus-fetch-field "reply-to")
8921                                    (gnus-fetch-field "from")))
8922           (setq params
8923                 (append
8924                  (list (cons 'to-address
8925                              (funcall gnus-decode-encoded-address-function
8926                                       to-address))))))
8927         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8928         (insert-buffer-substring gnus-original-article-buffer)
8929         ;; Remove lines that may lead nndoc to misinterpret the
8930         ;; document type.
8931         (narrow-to-region
8932          (goto-char (point-min))
8933          (or (search-forward "\n\n" nil t) (point)))
8934         (goto-char (point-min))
8935         (delete-matching-lines "^Path:\\|^From ")
8936         (widen))
8937       (unwind-protect
8938           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8939                     (gnus-newsgroup-ephemeral-ignored-charsets
8940                      gnus-newsgroup-ignored-charsets))
8941                 (gnus-group-read-ephemeral-group
8942                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8943                               (nndoc-article-type
8944                                ,(if force 'mbox 'guess)))
8945                  t nil nil nil
8946                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8947                                                         "ADAPT")))))
8948               ;; Make all postings to this group go to the parent group.
8949               (nconc (gnus-info-params (gnus-get-info name))
8950                      params)
8951             ;; Couldn't select this doc group.
8952             (switch-to-buffer buf)
8953             (gnus-set-global-variables)
8954             (gnus-configure-windows 'summary)
8955             (gnus-message 3 "Article couldn't be entered?"))
8956         (kill-buffer dig)))))
8957
8958 (defun gnus-summary-read-document (n)
8959   "Open a new group based on the current article(s).
8960 This will allow you to read digests and other similar
8961 documents as newsgroups.
8962 Obeys the standard process/prefix convention."
8963   (interactive "P")
8964   (let* ((ogroup gnus-newsgroup-name)
8965          (params (append (gnus-info-params (gnus-get-info ogroup))
8966                          (list (cons 'to-group ogroup))))
8967          group egroup groups vgroup)
8968     (dolist (article (gnus-summary-work-articles n))
8969       (setq group (format "%s-%d" gnus-newsgroup-name article))
8970       (gnus-summary-remove-process-mark article)
8971       (when (gnus-summary-display-article article)
8972         (save-excursion
8973           (with-temp-buffer
8974             (insert-buffer-substring gnus-original-article-buffer)
8975             ;; Remove some headers that may lead nndoc to make
8976             ;; the wrong guess.
8977             (message-narrow-to-head)
8978             (goto-char (point-min))
8979             (delete-matching-lines "^Path:\\|^From ")
8980             (widen)
8981             (if (setq egroup
8982                       (gnus-group-read-ephemeral-group
8983                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8984                                      (nndoc-article-type guess))
8985                        t nil t))
8986                 (progn
8987                   ;; Make all postings to this group go to the parent group.
8988                   (nconc (gnus-info-params (gnus-get-info egroup))
8989                          params)
8990                   (push egroup groups))
8991               ;; Couldn't select this doc group.
8992               (gnus-error 3 "Article couldn't be entered"))))))
8993     ;; Now we have selected all the documents.
8994     (cond
8995      ((not groups)
8996       (error "None of the articles could be interpreted as documents"))
8997      ((gnus-group-read-ephemeral-group
8998        (setq vgroup (format
8999                      "nnvirtual:%s-%s" gnus-newsgroup-name
9000                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
9001        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
9002        t
9003        (cons (current-buffer) 'summary)))
9004      (t
9005       (error "Couldn't select virtual nndoc group")))))
9006
9007 (defun gnus-summary-isearch-article (&optional regexp-p)
9008   "Do incremental search forward on the current article.
9009 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
9010   (interactive "P")
9011   (gnus-summary-select-article)
9012   (gnus-configure-windows 'article)
9013   (gnus-eval-in-buffer-window gnus-article-buffer
9014     (save-restriction
9015       (widen)
9016       (isearch-forward regexp-p))))
9017
9018 (defun gnus-summary-repeat-search-article-forward ()
9019   "Repeat the previous search forwards."
9020   (interactive)
9021   (unless gnus-last-search-regexp
9022     (error "No previous search"))
9023   (gnus-summary-search-article-forward gnus-last-search-regexp))
9024
9025 (defun gnus-summary-repeat-search-article-backward ()
9026   "Repeat the previous search backwards."
9027   (interactive)
9028   (unless gnus-last-search-regexp
9029     (error "No previous search"))
9030   (gnus-summary-search-article-forward gnus-last-search-regexp t))
9031
9032 (defun gnus-summary-search-article-forward (regexp &optional backward)
9033   "Search for an article containing REGEXP forward.
9034 If BACKWARD, search backward instead."
9035   (interactive
9036    (list (read-string
9037           (format "Search article %s (regexp%s): "
9038                   (if current-prefix-arg "backward" "forward")
9039                   (if gnus-last-search-regexp
9040                       (concat ", default " gnus-last-search-regexp)
9041                     "")))
9042          current-prefix-arg))
9043   (if (string-equal regexp "")
9044       (setq regexp (or gnus-last-search-regexp ""))
9045     (setq gnus-last-search-regexp regexp)
9046     (setq gnus-article-before-search gnus-current-article))
9047   ;; Intentionally set gnus-last-article.
9048   (setq gnus-last-article gnus-article-before-search)
9049   (let ((gnus-last-article gnus-last-article))
9050     (if (gnus-summary-search-article regexp backward)
9051         (gnus-summary-show-thread)
9052       (signal 'search-failed (list regexp)))))
9053
9054 (defun gnus-summary-search-article-backward (regexp)
9055   "Search for an article containing REGEXP backward."
9056   (interactive
9057    (list (read-string
9058           (format "Search article backward (regexp%s): "
9059                   (if gnus-last-search-regexp
9060                       (concat ", default " gnus-last-search-regexp)
9061                     "")))))
9062   (gnus-summary-search-article-forward regexp 'backward))
9063
9064 (defun gnus-summary-search-article (regexp &optional backward)
9065   "Search for an article containing REGEXP.
9066 Optional argument BACKWARD means do search for backward.
9067 `gnus-select-article-hook' is not called during the search."
9068   ;; We have to require this here to make sure that the following
9069   ;; dynamic binding isn't shadowed by autoloading.
9070   (require 'gnus-async)
9071   (require 'gnus-art)
9072   (let ((gnus-select-article-hook nil)  ;Disable hook.
9073         (gnus-article-prepare-hook nil)
9074         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9075         (gnus-use-article-prefetch nil)
9076         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9077         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9078         (gnus-visual nil)
9079         (gnus-keep-backlog nil)
9080         (gnus-break-pages nil)
9081         (gnus-summary-display-arrow nil)
9082         (gnus-updated-mode-lines nil)
9083         (gnus-auto-center-summary nil)
9084         (sum (current-buffer))
9085         (gnus-display-mime-function nil)
9086         (found nil)
9087         point)
9088     (gnus-save-hidden-threads
9089       (gnus-summary-select-article)
9090       (set-buffer gnus-article-buffer)
9091       (goto-char (window-point (get-buffer-window (current-buffer))))
9092       (when backward
9093         (forward-line -1))
9094       (while (not found)
9095         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9096         (if (if backward
9097                 (re-search-backward regexp nil t)
9098               (re-search-forward regexp nil t))
9099             ;; We found the regexp.
9100             (progn
9101               (setq found 'found)
9102               (beginning-of-line)
9103               (set-window-start
9104                (get-buffer-window (current-buffer))
9105                (point))
9106               (forward-line 1)
9107               (set-window-point
9108                (get-buffer-window (current-buffer))
9109                (point))
9110               (set-buffer sum)
9111               (setq point (point)))
9112           ;; We didn't find it, so we go to the next article.
9113           (set-buffer sum)
9114           (setq found 'not)
9115           (while (eq found 'not)
9116             (if (not (if backward (gnus-summary-find-prev)
9117                        (gnus-summary-find-next)))
9118                 ;; No more articles.
9119                 (setq found t)
9120               ;; Select the next article and adjust point.
9121               (unless (gnus-summary-article-sparse-p
9122                        (gnus-summary-article-number))
9123                 (setq found nil)
9124                 (gnus-summary-select-article)
9125                 (set-buffer gnus-article-buffer)
9126                 (widen)
9127                 (goto-char (if backward (point-max) (point-min))))))))
9128       (gnus-message 7 ""))
9129     ;; Return whether we found the regexp.
9130     (when (eq found 'found)
9131       (goto-char point)
9132       (gnus-summary-show-thread)
9133       (gnus-summary-goto-subject gnus-current-article)
9134       (gnus-summary-position-point)
9135       t)))
9136
9137 (defun gnus-find-matching-articles (header regexp)
9138   "Return a list of all articles that match REGEXP on HEADER.
9139 This search includes all articles in the current group that Gnus has
9140 fetched headers for, whether they are displayed or not."
9141   (let ((articles nil)
9142         ;; Can't eta-reduce because it's a macro.
9143         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9144         (case-fold-search t))
9145     (dolist (header gnus-newsgroup-headers)
9146       (when (string-match regexp (funcall func header))
9147         (push (mail-header-number header) articles)))
9148     (nreverse articles)))
9149
9150 (defun gnus-summary-find-matching (header regexp &optional backward unread
9151                                           not-case-fold not-matching)
9152   "Return a list of all articles that match REGEXP on HEADER.
9153 The search stars on the current article and goes forwards unless
9154 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9155 If UNREAD is non-nil, only unread articles will
9156 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9157 in the comparisons. If NOT-MATCHING, return a list of all articles that
9158 not match REGEXP on HEADER."
9159   (let ((case-fold-search (not not-case-fold))
9160         articles d func)
9161     (if (consp header)
9162         (if (eq (car header) 'extra)
9163             (setq func
9164                   `(lambda (h)
9165                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9166                          "")))
9167           (error "%s is an invalid header" header))
9168       (unless (fboundp (intern (concat "mail-header-" header)))
9169         (error "%s is not a valid header" header))
9170       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9171     (dolist (d (if (eq backward 'all)
9172                    gnus-newsgroup-data
9173                  (gnus-data-find-list
9174                   (gnus-summary-article-number)
9175                   (gnus-data-list backward))))
9176       (when (and (or (not unread)       ; We want all articles...
9177                      (gnus-data-unread-p d)) ; Or just unreads.
9178                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9179                  (if not-matching
9180                      (not (string-match
9181                            regexp
9182                            (funcall func (gnus-data-header d))))
9183                    (string-match regexp
9184                                  (funcall func (gnus-data-header d)))))
9185         (push (gnus-data-number d) articles))) ; Success!
9186     (nreverse articles)))
9187
9188 (defun gnus-summary-execute-command (header regexp command &optional backward)
9189   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9190 If HEADER is an empty string (or nil), the match is done on the entire
9191 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9192   (interactive
9193    (list (let ((completion-ignore-case t))
9194            (completing-read
9195             "Header name: "
9196             (mapcar (lambda (header) (list (format "%s" header)))
9197                     (append
9198                      '("Number" "Subject" "From" "Lines" "Date"
9199                        "Message-ID" "Xref" "References" "Body")
9200                      gnus-extra-headers))
9201             nil 'require-match))
9202          (read-string "Regexp: ")
9203          (read-key-sequence "Command: ")
9204          current-prefix-arg))
9205   (when (equal header "Body")
9206     (setq header ""))
9207   ;; Hidden thread subtrees must be searched as well.
9208   (gnus-summary-show-all-threads)
9209   ;; We don't want to change current point nor window configuration.
9210   (save-excursion
9211     (save-window-excursion
9212       (let (gnus-visual
9213             gnus-treat-strip-trailing-blank-lines
9214             gnus-treat-strip-leading-blank-lines
9215             gnus-treat-strip-multiple-blank-lines
9216             gnus-treat-hide-boring-headers
9217             gnus-treat-fold-newsgroups
9218             gnus-article-prepare-hook)
9219         (gnus-message 6 "Executing %s..." (key-description command))
9220         ;; We'd like to execute COMMAND interactively so as to give arguments.
9221         (gnus-execute header regexp
9222                       `(call-interactively ',(key-binding command))
9223                       backward)
9224         (gnus-message 6 "Executing %s...done" (key-description command))))))
9225
9226 (defun gnus-summary-beginning-of-article ()
9227   "Scroll the article back to the beginning."
9228   (interactive)
9229   (gnus-summary-select-article)
9230   (gnus-configure-windows 'article)
9231   (gnus-eval-in-buffer-window gnus-article-buffer
9232     (widen)
9233     (goto-char (point-min))
9234     (when gnus-break-pages
9235       (gnus-narrow-to-page))))
9236
9237 (defun gnus-summary-end-of-article ()
9238   "Scroll to the end of the article."
9239   (interactive)
9240   (gnus-summary-select-article)
9241   (gnus-configure-windows 'article)
9242   (gnus-eval-in-buffer-window gnus-article-buffer
9243     (widen)
9244     (goto-char (point-max))
9245     (recenter -3)
9246     (when gnus-break-pages
9247       (gnus-narrow-to-page))))
9248
9249 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9250   "Truncate to LEN and quote all \"(\"'s in STRING."
9251   (gnus-replace-in-string (if (and len (> (length string) len))
9252                               (substring string 0 len)
9253                             string)
9254                           "[()]" "\\\\\\&"))
9255
9256 (defun gnus-summary-print-article (&optional filename n)
9257   "Generate and print a PostScript image of the process-marked (mail) articles.
9258
9259 If used interactively, print the current article if none are
9260 process-marked.  With prefix arg, prompt the user for the name of the
9261 file to save in.
9262
9263 When used from Lisp, accept two optional args FILENAME and N.  N means
9264 to print the next N articles.  If N is negative, print the N previous
9265 articles.  If N is nil and articles have been marked with the process
9266 mark, print these instead.
9267
9268 If the optional first argument FILENAME is nil, send the image to the
9269 printer.  If FILENAME is a string, save the PostScript image in a file with
9270 that name.  If FILENAME is a number, prompt the user for the name of the file
9271 to save in."
9272   (interactive (list (ps-print-preprint current-prefix-arg)))
9273   (dolist (article (gnus-summary-work-articles n))
9274     (gnus-summary-select-article nil nil 'pseudo article)
9275     (gnus-eval-in-buffer-window gnus-article-buffer
9276       (gnus-print-buffer))
9277     (gnus-summary-remove-process-mark article))
9278   (ps-despool filename))
9279
9280 (defun gnus-print-buffer ()
9281   (let ((buffer (generate-new-buffer " *print*")))
9282     (unwind-protect
9283         (progn
9284           (copy-to-buffer buffer (point-min) (point-max))
9285           (set-buffer buffer)
9286           (gnus-remove-text-with-property 'gnus-decoration)
9287           (when (gnus-visual-p 'article-highlight 'highlight)
9288             ;; Copy-to-buffer doesn't copy overlay.  So redo
9289             ;; highlight.
9290             (let ((gnus-article-buffer buffer))
9291               (gnus-article-highlight-citation t)
9292               (gnus-article-highlight-signature)
9293               (gnus-article-emphasize)
9294               (gnus-article-delete-invisible-text)))
9295           (let ((ps-left-header
9296                  (list
9297                   (concat "("
9298                           (gnus-summary-print-truncate-and-quote
9299                            (mail-header-subject gnus-current-headers)
9300                            66) ")")
9301                   (concat "("
9302                           (gnus-summary-print-truncate-and-quote
9303                            (mail-header-from gnus-current-headers)
9304                            45) ")")))
9305                 (ps-right-header
9306                  (list
9307                   "/pagenumberstring load"
9308                   (concat "("
9309                           (mail-header-date gnus-current-headers) ")"))))
9310             (gnus-run-hooks 'gnus-ps-print-hook)
9311             (save-excursion
9312               (if ps-print-color-p
9313                   (ps-spool-buffer-with-faces)
9314                 (ps-spool-buffer)))))
9315       (kill-buffer buffer))))
9316
9317 (defun gnus-summary-show-article (&optional arg)
9318   "Force redisplaying of the current article.
9319 If ARG (the prefix) is a number, show the article with the charset
9320 defined in `gnus-summary-show-article-charset-alist', or the charset
9321 input.
9322 If ARG (the prefix) is non-nil and not a number, show the raw article
9323 without any article massaging functions being run.  Normally, the key
9324 strokes are `C-u g'."
9325   (interactive "P")
9326   (cond
9327    ((numberp arg)
9328     (gnus-summary-show-article t)
9329     (let ((gnus-newsgroup-charset
9330            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9331                (mm-read-coding-system
9332                 "View as charset: " ;; actually it is coding system.
9333                 (with-current-buffer gnus-article-buffer
9334                   (mm-detect-coding-region (point) (point-max))))))
9335           (gnus-newsgroup-ignored-charsets 'gnus-all))
9336       (gnus-summary-select-article nil 'force)
9337       (let ((deps gnus-newsgroup-dependencies)
9338             head header lines)
9339         (with-current-buffer gnus-original-article-buffer
9340           (save-restriction
9341             (message-narrow-to-head)
9342             (setq head (buffer-string))
9343             (goto-char (point-min))
9344             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9345               (goto-char (point-max))
9346               (widen)
9347               (setq lines (1- (count-lines (point) (point-max))))))
9348           (with-temp-buffer
9349             (insert (format "211 %d Article retrieved.\n"
9350                             (cdr gnus-article-current)))
9351             (insert head)
9352             (if lines (insert (format "Lines: %d\n" lines)))
9353             (insert ".\n")
9354             (let ((nntp-server-buffer (current-buffer)))
9355               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9356         (gnus-data-set-header
9357          (gnus-data-find (cdr gnus-article-current))
9358          header)
9359         (gnus-summary-update-article-line
9360          (cdr gnus-article-current) header)
9361         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9362           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9363    ((not arg)
9364     ;; Select the article the normal way.
9365     (gnus-summary-select-article nil 'force))
9366    (t
9367     ;; We have to require this here to make sure that the following
9368     ;; dynamic binding isn't shadowed by autoloading.
9369     (require 'gnus-async)
9370     (require 'gnus-art)
9371     ;; Bind the article treatment functions to nil.
9372     (let ((gnus-have-all-headers t)
9373           gnus-article-prepare-hook
9374           gnus-article-decode-hook
9375           gnus-display-mime-function
9376           gnus-break-pages)
9377       ;; Destroy any MIME parts.
9378       (when (gnus-buffer-live-p gnus-article-buffer)
9379         (with-current-buffer gnus-article-buffer
9380           (mm-destroy-parts gnus-article-mime-handles)
9381           ;; Set it to nil for safety reason.
9382           (setq gnus-article-mime-handle-alist nil)
9383           (setq gnus-article-mime-handles nil)))
9384       (gnus-summary-select-article nil 'force))))
9385   (gnus-summary-goto-subject gnus-current-article)
9386   (gnus-summary-position-point))
9387
9388 (defun gnus-summary-show-raw-article ()
9389   "Show the raw article without any article massaging functions being run."
9390   (interactive)
9391   (gnus-summary-show-article t))
9392
9393 (defun gnus-summary-verbose-headers (&optional arg)
9394   "Toggle permanent full header display.
9395 If ARG is a positive number, turn header display on.
9396 If ARG is a negative number, turn header display off."
9397   (interactive "P")
9398   (setq gnus-show-all-headers
9399         (cond ((or (not (numberp arg))
9400                    (zerop arg))
9401                (not gnus-show-all-headers))
9402               ((natnump arg)
9403                t)))
9404   (gnus-summary-show-article))
9405
9406 (defun gnus-summary-toggle-header (&optional arg)
9407   "Show the headers if they are hidden, or hide them if they are shown.
9408 If ARG is a positive number, show the entire header.
9409 If ARG is a negative number, hide the unwanted header lines."
9410   (interactive "P")
9411   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9412                      (get-buffer-window gnus-article-buffer t))))
9413     (with-current-buffer gnus-article-buffer
9414       (widen)
9415       (article-narrow-to-head)
9416       (let* ((inhibit-read-only t)
9417              (inhibit-point-motion-hooks t)
9418              (hidden (if (numberp arg)
9419                          (>= arg 0)
9420                        (or (not (looking-at "[^ \t\n]+:"))
9421                            (gnus-article-hidden-text-p 'headers))))
9422              s e)
9423         (delete-region (point-min) (point-max))
9424         (with-current-buffer gnus-original-article-buffer
9425           (goto-char (setq s (point-min)))
9426           (setq e (if (search-forward "\n\n" nil t)
9427                       (1- (point))
9428                     (point-max))))
9429         (insert-buffer-substring gnus-original-article-buffer s e)
9430         (run-hooks 'gnus-article-decode-hook)
9431         (if hidden
9432             (let ((gnus-treat-hide-headers nil)
9433                   (gnus-treat-hide-boring-headers nil))
9434               (gnus-delete-wash-type 'headers)
9435               (gnus-treat-article 'head))
9436           (gnus-treat-article 'head))
9437         (widen)
9438         (if window
9439             (set-window-start window (goto-char (point-min))))
9440         (if gnus-break-pages
9441             (gnus-narrow-to-page)
9442           (when (gnus-visual-p 'page-marker)
9443             (let ((inhibit-read-only t))
9444               (gnus-remove-text-with-property 'gnus-prev)
9445               (gnus-remove-text-with-property 'gnus-next))))
9446         (gnus-set-mode-line 'article)))))
9447
9448 (defun gnus-summary-show-all-headers ()
9449   "Make all header lines visible."
9450   (interactive)
9451   (gnus-summary-toggle-header 1))
9452
9453 (defun gnus-summary-caesar-message (&optional arg)
9454   "Caesar rotate the current article by 13.
9455 With a non-numerical prefix, also rotate headers.  A numerical
9456 prefix specifies how many places to rotate each letter forward."
9457   (interactive "P")
9458   (gnus-summary-select-article)
9459   (let ((mail-header-separator ""))
9460     (gnus-eval-in-buffer-window gnus-article-buffer
9461       (save-restriction
9462         (widen)
9463         (let ((start (window-start))
9464               (inhibit-read-only t))
9465           (if (equal arg '(4))
9466               (message-caesar-buffer-body nil t)
9467             (message-caesar-buffer-body arg))
9468           (set-window-start (get-buffer-window (current-buffer)) start)))))
9469   ;; Create buttons and stuff...
9470   (gnus-treat-article nil))
9471
9472 (declare-function idna-to-unicode "ext:idna" (str))
9473
9474 (defun gnus-summary-idna-message (&optional arg)
9475   "Decode IDNA encoded domain names in the current articles.
9476 IDNA encoded domain names looks like `xn--bar'.  If a string
9477 remain unencoded after running this function, it is likely an
9478 invalid IDNA string (`xn--bar' is invalid).
9479
9480 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9481 installed for this command to work."
9482   (interactive "P")
9483   (if (not (and (condition-case nil (require 'idna)
9484                   (file-error))
9485                 (mm-coding-system-p 'utf-8)
9486                 (executable-find (symbol-value 'idna-program))))
9487       (gnus-message
9488        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9489     (gnus-summary-select-article)
9490     (let ((mail-header-separator ""))
9491       (gnus-eval-in-buffer-window gnus-article-buffer
9492         (save-restriction
9493           (widen)
9494           (let ((start (window-start))
9495                 buffer-read-only)
9496             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9497               (replace-match (idna-to-unicode (match-string 1))))
9498             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9499
9500 (defun gnus-summary-morse-message (&optional arg)
9501   "Morse decode the current article."
9502   (interactive "P")
9503   (gnus-summary-select-article)
9504   (let ((mail-header-separator ""))
9505     (gnus-eval-in-buffer-window gnus-article-buffer
9506       (save-excursion
9507         (save-restriction
9508           (widen)
9509           (let ((pos (window-start))
9510                 (inhibit-read-only t))
9511             (goto-char (point-min))
9512             (when (message-goto-body)
9513               (gnus-narrow-to-body))
9514             (goto-char (point-min))
9515             (while (search-forward "·" (point-max) t)
9516               (replace-match "."))
9517             (unmorse-region (point-min) (point-max))
9518             (widen)
9519             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9520
9521 (defun gnus-summary-stop-page-breaking ()
9522   "Stop page breaking in the current article."
9523   (interactive)
9524   (gnus-summary-select-article)
9525   (gnus-eval-in-buffer-window gnus-article-buffer
9526     (widen)
9527     (when (gnus-visual-p 'page-marker)
9528       (let ((inhibit-read-only t))
9529         (gnus-remove-text-with-property 'gnus-prev)
9530         (gnus-remove-text-with-property 'gnus-next))
9531       (setq gnus-page-broken nil))))
9532
9533 (defun gnus-summary-move-article (&optional n to-newsgroup
9534                                             select-method action)
9535   "Move the current article to a different newsgroup.
9536 If N is a positive number, move the N next articles.
9537 If N is a negative number, move the N previous articles.
9538 If N is nil and any articles have been marked with the process mark,
9539 move those articles instead.
9540 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9541 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9542 re-spool using this method.
9543
9544 When called interactively with TO-NEWSGROUP being nil, the value of
9545 the variable `gnus-move-split-methods' is used for finding a default
9546 for the target newsgroup.
9547
9548 For this function to work, both the current newsgroup and the
9549 newsgroup that you want to move to have to support the `request-move'
9550 and `request-accept' functions.
9551
9552 ACTION can be either `move' (the default), `crosspost' or `copy'."
9553   (interactive "P")
9554   (unless action
9555     (setq action 'move))
9556   ;; Check whether the source group supports the required functions.
9557   (cond ((and (eq action 'move)
9558               (not (gnus-check-backend-function
9559                     'request-move-article gnus-newsgroup-name)))
9560          (error "The current group does not support article moving"))
9561         ((and (eq action 'crosspost)
9562               (not (gnus-check-backend-function
9563                     'request-replace-article gnus-newsgroup-name)))
9564          (error "The current group does not support article editing")))
9565   (let ((articles (gnus-summary-work-articles n))
9566         (prefix (if (gnus-check-backend-function
9567                      'request-move-article gnus-newsgroup-name)
9568                     (funcall gnus-move-group-prefix-function
9569                              gnus-newsgroup-name)
9570                   ""))
9571         (names '((move "Move" "Moving")
9572                  (copy "Copy" "Copying")
9573                  (crosspost "Crosspost" "Crossposting")))
9574         (copy-buf (save-excursion
9575                     (nnheader-set-temp-buffer " *copy article*")))
9576         art-group to-method new-xref article to-groups
9577         articles-to-update-marks encoded)
9578     (unless (assq action names)
9579       (error "Unknown action %s" action))
9580     ;; Read the newsgroup name.
9581     (when (and (not to-newsgroup)
9582                (not select-method))
9583       (if (and gnus-move-split-methods
9584                (not
9585                 (and (memq gnus-current-article articles)
9586                      (gnus-buffer-live-p gnus-original-article-buffer))))
9587           ;; When `gnus-move-split-methods' is non-nil, we have to
9588           ;; select an article to give `gnus-read-move-group-name' an
9589           ;; opportunity to suggest an appropriate default.  However,
9590           ;; we needn't render or mark the article.
9591           (let ((gnus-display-mime-function nil)
9592                 (gnus-article-prepare-hook nil)
9593                 (gnus-mark-article-hook nil))
9594             (gnus-summary-select-article nil nil nil (car articles))))
9595       (setq to-newsgroup (gnus-read-move-group-name
9596                           (cadr (assq action names))
9597                           (symbol-value
9598                            (intern (format "gnus-current-%s-group" action)))
9599                           articles prefix)
9600             encoded to-newsgroup
9601             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9602       (set (intern (format "gnus-current-%s-group" action))
9603            (mm-decode-coding-string
9604             to-newsgroup
9605             (gnus-group-name-charset to-method to-newsgroup))))
9606     (unless to-method
9607       (setq to-method (or select-method
9608                           (gnus-server-to-method
9609                            (gnus-group-method to-newsgroup)))))
9610     (setq to-newsgroup
9611           (or encoded
9612               (and to-newsgroup
9613                    (mm-encode-coding-string
9614                     to-newsgroup
9615                     (gnus-group-name-charset to-method to-newsgroup)))))
9616     ;; Check the method we are to move this article to...
9617     (unless (gnus-check-backend-function
9618              'request-accept-article (car to-method))
9619       (error "%s does not support article copying" (car to-method)))
9620     (unless (gnus-check-server to-method)
9621       (error "Can't open server %s" (car to-method)))
9622     (gnus-message 6 "%s to %s: %s..."
9623                   (caddr (assq action names))
9624                   (or (car select-method)
9625                       (gnus-group-decoded-name to-newsgroup))
9626                   articles)
9627     (while articles
9628       (setq article (pop articles))
9629       (setq
9630        art-group
9631        (cond
9632         ;; Move the article.
9633         ((eq action 'move)
9634          ;; Remove this article from future suppression.
9635          (gnus-dup-unsuppress-article article)
9636          (let* ((from-method (gnus-find-method-for-group
9637                               gnus-newsgroup-name))
9638                 (to-method (or select-method
9639                                (gnus-find-method-for-group to-newsgroup)))
9640                 (move-is-internal (gnus-method-equal from-method to-method)))
9641            (gnus-request-move-article
9642             article                     ; Article to move
9643             gnus-newsgroup-name         ; From newsgroup
9644             (nth 1 (gnus-find-method-for-group
9645                     gnus-newsgroup-name)) ; Server
9646             (list 'gnus-request-accept-article
9647                   to-newsgroup (list 'quote select-method)
9648                   (not articles) t)     ; Accept form
9649             (not articles)              ; Only save nov last time
9650             move-is-internal)))         ; is this move internal?
9651         ;; Copy the article.
9652         ((eq action 'copy)
9653          (with-current-buffer copy-buf
9654            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9655              (save-restriction
9656                (nnheader-narrow-to-headers)
9657                (dolist (hdr gnus-copy-article-ignored-headers)
9658                  (message-remove-header hdr t)))
9659              (gnus-request-accept-article
9660               to-newsgroup select-method (not articles) t))))
9661         ;; Crosspost the article.
9662         ((eq action 'crosspost)
9663          (let ((xref (message-tokenize-header
9664                       (mail-header-xref (gnus-summary-article-header article))
9665                       " ")))
9666            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9667                                   ":" (number-to-string article)))
9668            (unless xref
9669              (setq xref (list (system-name))))
9670            (setq new-xref
9671                  (concat
9672                   (mapconcat 'identity
9673                              (delete "Xref:" (delete new-xref xref))
9674                              " ")
9675                   " " new-xref))
9676            (with-current-buffer copy-buf
9677              ;; First put the article in the destination group.
9678              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9679              (when (consp (setq art-group
9680                                 (gnus-request-accept-article
9681                                  to-newsgroup select-method (not articles) t)))
9682                (setq new-xref (concat new-xref " " (car art-group)
9683                                       ":"
9684                                       (number-to-string (cdr art-group))))
9685                ;; Now we have the new Xrefs header, so we insert
9686                ;; it and replace the new article.
9687                (nnheader-replace-header "Xref" new-xref)
9688                (gnus-request-replace-article
9689                 (cdr art-group) to-newsgroup (current-buffer) t)
9690                art-group))))))
9691       (cond
9692        ((not art-group)
9693         (gnus-message 1 "Couldn't %s article %s: %s"
9694                       (cadr (assq action names)) article
9695                       (nnheader-get-report (car to-method))))
9696        ((eq art-group 'junk)
9697         (when (eq action 'move)
9698           (gnus-summary-mark-article article gnus-canceled-mark)
9699           (gnus-message 4 "Deleted article %s" article)
9700           ;; run the delete hook
9701           (run-hook-with-args 'gnus-summary-article-delete-hook
9702                               action
9703                               (gnus-data-header
9704                                (assoc article (gnus-data-list nil)))
9705                               gnus-newsgroup-name nil
9706                               select-method)))
9707        (t
9708         (let* ((pto-group (gnus-group-prefixed-name
9709                            (car art-group) to-method))
9710                (info (gnus-get-info pto-group))
9711                (to-group (gnus-info-group info))
9712                to-marks)
9713           ;; Update the group that has been moved to.
9714           (when (and info
9715                      (memq action '(move copy)))
9716             (unless (member to-group to-groups)
9717               (push to-group to-groups))
9718
9719             (unless (memq article gnus-newsgroup-unreads)
9720               (push 'read to-marks)
9721               (gnus-info-set-read
9722                info (gnus-add-to-range (gnus-info-read info)
9723                                        (list (cdr art-group)))))
9724
9725             ;; See whether the article is to be put in the cache.
9726             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9727                              gnus-article-mark-lists
9728                            (delete '(expirable . expire)
9729                                    (copy-sequence gnus-article-mark-lists))))
9730                   (to-article (cdr art-group)))
9731
9732               ;; Enter the article into the cache in the new group,
9733               ;; if that is required.
9734               (when gnus-use-cache
9735                 (gnus-cache-possibly-enter-article
9736                  to-group to-article
9737                  (memq article gnus-newsgroup-marked)
9738                  (memq article gnus-newsgroup-dormant)
9739                  (memq article gnus-newsgroup-unreads)))
9740
9741               (when gnus-preserve-marks
9742                 ;; Copy any marks over to the new group.
9743                 (when (and (equal to-group gnus-newsgroup-name)
9744                            (not (memq article gnus-newsgroup-unreads)))
9745                   ;; Mark this article as read in this group.
9746                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9747                   (setcdr (gnus-active to-group) to-article)
9748                   (setcdr gnus-newsgroup-active to-article))
9749
9750                 (while marks
9751                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9752                     (when (memq article (symbol-value
9753                                          (intern (format "gnus-newsgroup-%s"
9754                                                          (caar marks)))))
9755                       (push (cdar marks) to-marks)
9756                       ;; If the other group is the same as this group,
9757                       ;; then we have to add the mark to the list.
9758                       (when (equal to-group gnus-newsgroup-name)
9759                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9760                              (cons to-article
9761                                    (symbol-value
9762                                     (intern (format "gnus-newsgroup-%s"
9763                                                     (caar marks)))))))
9764                       ;; Copy the marks to other group.
9765                       (gnus-add-marked-articles
9766                        to-group (cdar marks) (list to-article) info)))
9767                   (setq marks (cdr marks)))
9768
9769                 (gnus-request-set-mark
9770                  to-group (list (list (list to-article) 'add to-marks))))
9771
9772               (gnus-dribble-enter
9773                (concat "(gnus-group-set-info '"
9774                        (gnus-prin1-to-string (gnus-get-info to-group))
9775                        ")"))))
9776
9777           ;; Update the Xref header in this article to point to
9778           ;; the new crossposted article we have just created.
9779           (when (eq action 'crosspost)
9780             (with-current-buffer copy-buf
9781               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9782               (nnheader-replace-header "Xref" new-xref)
9783               (gnus-request-replace-article
9784                article gnus-newsgroup-name (current-buffer) t)))
9785
9786           ;; run the move/copy/crosspost/respool hook
9787           (run-hook-with-args 'gnus-summary-article-move-hook
9788                               action
9789                               (gnus-data-header
9790                                (assoc article (gnus-data-list nil)))
9791                               gnus-newsgroup-name
9792                               to-newsgroup
9793                               select-method))
9794
9795         ;;;!!!Why is this necessary?
9796         (set-buffer gnus-summary-buffer)
9797
9798         (gnus-summary-goto-subject article)
9799         (when (eq action 'move)
9800           (gnus-summary-mark-article article gnus-canceled-mark))))
9801       (push article articles-to-update-marks))
9802
9803     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9804     ;; Re-activate all groups that have been moved to.
9805     (with-current-buffer gnus-group-buffer
9806       (let ((gnus-group-marked to-groups))
9807         (gnus-group-get-new-news-this-group nil t)))
9808
9809     (gnus-kill-buffer copy-buf)
9810     (gnus-summary-position-point)
9811     (gnus-set-mode-line 'summary)))
9812
9813 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9814   "Copy the current article to some other group.
9815 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9816 When called interactively, if TO-NEWSGROUP is nil, use the value of
9817 the variable `gnus-move-split-methods' for finding a default target
9818 newsgroup.
9819 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9820 re-spool using this method."
9821   (interactive "P")
9822   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9823
9824 (defun gnus-summary-crosspost-article (&optional n)
9825   "Crosspost the current article to some other group."
9826   (interactive "P")
9827   (gnus-summary-move-article n nil nil 'crosspost))
9828
9829 (defcustom gnus-summary-respool-default-method nil
9830   "Default method type for respooling an article.
9831 If nil, use to the current newsgroup method."
9832   :type 'symbol
9833   :group 'gnus-summary-mail)
9834
9835 (defun gnus-summary-respool-article (&optional n method)
9836   "Respool the current article.
9837 The article will be squeezed through the mail spooling process again,
9838 which means that it will be put in some mail newsgroup or other
9839 depending on `nnmail-split-methods'.
9840 If N is a positive number, respool the N next articles.
9841 If N is a negative number, respool the N previous articles.
9842 If N is nil and any articles have been marked with the process mark,
9843 respool those articles instead.
9844
9845 Respooling can be done both from mail groups and \"real\" newsgroups.
9846 In the former case, the articles in question will be moved from the
9847 current group into whatever groups they are destined to.  In the
9848 latter case, they will be copied into the relevant groups."
9849   (interactive
9850    (list current-prefix-arg
9851          (let* ((methods (gnus-methods-using 'respool))
9852                 (methname
9853                  (symbol-name (or gnus-summary-respool-default-method
9854                                   (car (gnus-find-method-for-group
9855                                         gnus-newsgroup-name)))))
9856                 (method
9857                  (gnus-completing-read-with-default
9858                   methname "Backend to use when respooling"
9859                   methods nil t nil 'gnus-mail-method-history))
9860                 ms)
9861            (cond
9862             ((zerop (length (setq ms (gnus-servers-using-backend
9863                                       (intern method)))))
9864              (list (intern method) ""))
9865             ((= 1 (length ms))
9866              (car ms))
9867             (t
9868              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9869                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9870                            ms-alist))))))))
9871   (unless method
9872     (error "No method given for respooling"))
9873   (if (assoc (symbol-name
9874               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9875              (gnus-methods-using 'respool))
9876       (gnus-summary-move-article n nil method)
9877     (gnus-summary-copy-article n nil method)))
9878
9879 (defun gnus-summary-import-article (file &optional edit)
9880   "Import an arbitrary file into a mail newsgroup."
9881   (interactive "fImport file: \nP")
9882   (let ((group gnus-newsgroup-name)
9883         (now (current-time))
9884         atts lines group-art)
9885     (unless (gnus-check-backend-function 'request-accept-article group)
9886       (error "%s does not support article importing" group))
9887     (or (file-readable-p file)
9888         (not (file-regular-p file))
9889         (error "Can't read %s" file))
9890     (with-current-buffer (gnus-get-buffer-create " *import file*")
9891       (erase-buffer)
9892       (nnheader-insert-file-contents file)
9893       (goto-char (point-min))
9894       (if (nnheader-article-p)
9895           (save-restriction
9896             (goto-char (point-min))
9897             (search-forward "\n\n" nil t)
9898             (narrow-to-region (point-min) (1- (point)))
9899             (goto-char (point-min))
9900             (unless (re-search-forward "^date:" nil t)
9901               (goto-char (point-max))
9902               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9903        ;; This doesn't look like an article, so we fudge some headers.
9904         (setq atts (file-attributes file)
9905               lines (count-lines (point-min) (point-max)))
9906         (insert "From: " (read-string "From: ") "\n"
9907                 "Subject: " (read-string "Subject: ") "\n"
9908                 "Date: " (message-make-date (nth 5 atts)) "\n"
9909                 "Message-ID: " (message-make-message-id) "\n"
9910                 "Lines: " (int-to-string lines) "\n"
9911                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9912       (setq group-art (gnus-request-accept-article group nil t))
9913       (kill-buffer (current-buffer)))
9914     (setq gnus-newsgroup-active (gnus-activate-group group))
9915     (forward-line 1)
9916     (gnus-summary-goto-article (cdr group-art) nil t)
9917     (when edit
9918       (gnus-summary-edit-article))))
9919
9920 (defun gnus-summary-create-article ()
9921   "Create an article in a mail newsgroup."
9922   (interactive)
9923   (let ((group gnus-newsgroup-name)
9924         (now (current-time))
9925         group-art)
9926     (unless (gnus-check-backend-function 'request-accept-article group)
9927       (error "%s does not support article importing" group))
9928     (with-current-buffer (gnus-get-buffer-create " *import file*")
9929       (erase-buffer)
9930       (goto-char (point-min))
9931       ;; This doesn't look like an article, so we fudge some headers.
9932       (insert "From: " (read-string "From: ") "\n"
9933               "Subject: " (read-string "Subject: ") "\n"
9934               "Date: " (message-make-date now) "\n"
9935               "Message-ID: " (message-make-message-id) "\n")
9936       (setq group-art (gnus-request-accept-article group nil t))
9937       (kill-buffer (current-buffer)))
9938     (setq gnus-newsgroup-active (gnus-activate-group group))
9939     (forward-line 1)
9940     (gnus-summary-goto-article (cdr group-art) nil t)
9941     (gnus-summary-edit-article)))
9942
9943 (defun gnus-summary-article-posted-p ()
9944   "Say whether the current (mail) article is available from news as well.
9945 This will be the case if the article has both been mailed and posted."
9946   (interactive)
9947   (let ((id (mail-header-references (gnus-summary-article-header)))
9948         (gnus-override-method (car (gnus-refer-article-methods))))
9949     (if (gnus-request-head id "")
9950         (gnus-message 2 "The current message was found on %s"
9951                       gnus-override-method)
9952       (gnus-message 2 "The current message couldn't be found on %s"
9953                     gnus-override-method)
9954       nil)))
9955
9956 (defun gnus-summary-expire-articles (&optional now)
9957   "Expire all articles that are marked as expirable in the current group."
9958   (interactive)
9959   (when (and (not gnus-group-is-exiting-without-update-p)
9960              (gnus-check-backend-function
9961               'request-expire-articles gnus-newsgroup-name))
9962     ;; This backend supports expiry.
9963     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9964            (expirable (if total
9965                           (progn
9966                             ;; We need to update the info for
9967                             ;; this group for `gnus-list-of-read-articles'
9968                             ;; to give us the right answer.
9969                             (gnus-run-hooks 'gnus-exit-group-hook)
9970                             (gnus-summary-update-info)
9971                             (gnus-list-of-read-articles gnus-newsgroup-name))
9972                         (setq gnus-newsgroup-expirable
9973                               (sort gnus-newsgroup-expirable '<))))
9974            (expiry-wait (if now 'immediate
9975                           (gnus-group-find-parameter
9976                            gnus-newsgroup-name 'expiry-wait)))
9977            (nnmail-expiry-target
9978             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9979                 nnmail-expiry-target))
9980            es)
9981       (when expirable
9982         ;; There are expirable articles in this group, so we run them
9983         ;; through the expiry process.
9984         (gnus-message 6 "Expiring articles...")
9985         (unless (gnus-check-group gnus-newsgroup-name)
9986           (error "Can't open server for %s" gnus-newsgroup-name))
9987         ;; The list of articles that weren't expired is returned.
9988         (save-excursion
9989           (if expiry-wait
9990               (let ((nnmail-expiry-wait-function nil)
9991                     (nnmail-expiry-wait expiry-wait))
9992                 (setq es (gnus-request-expire-articles
9993                           expirable gnus-newsgroup-name)))
9994             (setq es (gnus-request-expire-articles
9995                       expirable gnus-newsgroup-name)))
9996           (unless total
9997             (setq gnus-newsgroup-expirable es))
9998           ;; We go through the old list of expirable, and mark all
9999           ;; really expired articles as nonexistent.
10000           (unless (eq es expirable) ;If nothing was expired, we don't mark.
10001             (let ((gnus-use-cache nil))
10002               (dolist (article expirable)
10003                 (when (and (not (memq article es))
10004                            (gnus-data-find article))
10005                   (gnus-summary-mark-article article gnus-canceled-mark)
10006                   (run-hook-with-args 'gnus-summary-article-expire-hook
10007                                       'delete
10008                                       (gnus-data-header
10009                                        (assoc article (gnus-data-list nil)))
10010                                       gnus-newsgroup-name
10011                                       nil
10012                                       nil))))))
10013         (gnus-message 6 "Expiring articles...done")))))
10014
10015 (defun gnus-summary-expire-articles-now ()
10016   "Expunge all expirable articles in the current group.
10017 This means that *all* articles that are marked as expirable will be
10018 deleted forever, right now."
10019   (interactive)
10020   (or gnus-expert-user
10021       (gnus-yes-or-no-p
10022        "Are you really, really sure you want to delete all expirable messages? ")
10023       (error "Phew!"))
10024   (gnus-summary-expire-articles t))
10025
10026 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10027 (defun gnus-summary-delete-article (&optional n)
10028   "Delete the N next (mail) articles.
10029 This command actually deletes articles.  This is not a marking
10030 command.  The article will disappear forever from your life, never to
10031 return.
10032
10033 If N is negative, delete backwards.
10034 If N is nil and articles have been marked with the process mark,
10035 delete these instead.
10036
10037 If `gnus-novice-user' is non-nil you will be asked for
10038 confirmation before the articles are deleted."
10039   (interactive "P")
10040   (unless (gnus-check-backend-function 'request-expire-articles
10041                                        gnus-newsgroup-name)
10042     (error "The current newsgroup does not support article deletion"))
10043   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10044     (error "Couldn't open server"))
10045   ;; Compute the list of articles to delete.
10046   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10047         (nnmail-expiry-target 'delete)
10048         not-deleted)
10049     (if (and gnus-novice-user
10050              (not (gnus-yes-or-no-p
10051                    (format "Do you really want to delete %s forever? "
10052                            (if (> (length articles) 1)
10053                                (format "these %s articles" (length articles))
10054                              "this article")))))
10055         ()
10056       ;; Delete the articles.
10057       (setq not-deleted (gnus-request-expire-articles
10058                          articles gnus-newsgroup-name 'force))
10059       (while articles
10060         (gnus-summary-remove-process-mark (car articles))
10061         ;; The backend might not have been able to delete the article
10062         ;; after all.
10063         (unless (memq (car articles) not-deleted)
10064           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
10065         (let* ((article (car articles))
10066                (ghead  (gnus-data-header
10067                                     (assoc article (gnus-data-list nil)))))
10068           (run-hook-with-args 'gnus-summary-article-delete-hook
10069                               'delete ghead gnus-newsgroup-name nil
10070                               nil))
10071         (setq articles (cdr articles)))
10072       (when not-deleted
10073         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10074     (gnus-summary-position-point)
10075     (gnus-set-mode-line 'summary)
10076     not-deleted))
10077
10078 (defun gnus-summary-edit-article (&optional arg)
10079   "Edit the current article.
10080 This will have permanent effect only in mail groups.
10081 If ARG is nil, edit the decoded articles.
10082 If ARG is 1, edit the raw articles.
10083 If ARG is 2, edit the raw articles even in read-only groups.
10084 If ARG is 3, edit the articles with the current handles.
10085 Otherwise, allow editing of articles even in read-only
10086 groups."
10087   (interactive "P")
10088   (let (force raw current-handles)
10089     (cond
10090      ((null arg))
10091      ((eq arg 1)
10092       (setq raw t))
10093      ((eq arg 2)
10094       (setq raw t
10095             force t))
10096      ((eq arg 3)
10097       (setq current-handles
10098             (and (gnus-buffer-live-p gnus-article-buffer)
10099                  (with-current-buffer gnus-article-buffer
10100                    (prog1
10101                        gnus-article-mime-handles
10102                      (setq gnus-article-mime-handles nil))))))
10103      (t
10104       (setq force t)))
10105     (when (and raw (not force)
10106                (member gnus-newsgroup-name '("nndraft:delayed"
10107                                              "nndraft:drafts"
10108                                              "nndraft:queue")))
10109       (error "Can't edit the raw article in group %s"
10110              gnus-newsgroup-name))
10111     (with-current-buffer gnus-summary-buffer
10112       (let ((mail-parse-charset gnus-newsgroup-charset)
10113             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10114         (gnus-set-global-variables)
10115         (when (and (not force)
10116                    (gnus-group-read-only-p))
10117           (error "The current newsgroup does not support article editing"))
10118         (gnus-summary-show-article t)
10119         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10120           (with-current-buffer gnus-article-buffer
10121             (mm-enable-multibyte)))
10122         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10123             (setq raw t))
10124         (gnus-article-edit-article
10125          (if raw 'ignore
10126            `(lambda ()
10127               (let ((mbl mml-buffer-list))
10128                 (setq mml-buffer-list nil)
10129                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10130                   (mime-to-mml ,'current-handles))
10131                 (let ((mbl1 mml-buffer-list))
10132                   (setq mml-buffer-list mbl)
10133                   (set (make-local-variable 'mml-buffer-list) mbl1))
10134                 (gnus-make-local-hook 'kill-buffer-hook)
10135                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10136          `(lambda (no-highlight)
10137             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10138                   (message-options message-options)
10139                   (message-options-set-recipient)
10140                   (mail-parse-ignored-charsets
10141                    ',gnus-newsgroup-ignored-charsets)
10142                   (rfc2047-header-encoding-alist
10143                    ',(let ((charset (gnus-group-name-charset
10144                                      (gnus-find-method-for-group
10145                                       gnus-newsgroup-name)
10146                                      gnus-newsgroup-name)))
10147                        (append (list (cons "Newsgroups" charset)
10148                                      (cons "Followup-To" charset)
10149                                      (cons "Xref" charset))
10150                                rfc2047-header-encoding-alist))))
10151               ,(if (not raw) '(progn
10152                                 (mml-to-mime)
10153                                 (mml-destroy-buffers)
10154                                 (remove-hook 'kill-buffer-hook
10155                                              'mml-destroy-buffers t)
10156                                 (kill-local-variable 'mml-buffer-list)))
10157               (gnus-summary-edit-article-done
10158                ,(or (mail-header-references gnus-current-headers) "")
10159                ,(gnus-group-read-only-p)
10160                ,gnus-summary-buffer no-highlight))))))))
10161
10162 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10163
10164 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10165                                                  no-highlight)
10166   "Make edits to the current article permanent."
10167   (interactive)
10168   (save-excursion
10169    ;; The buffer restriction contains the entire article if it exists.
10170     (when (article-goto-body)
10171       (let ((lines (count-lines (point) (point-max)))
10172             (length (- (point-max) (point)))
10173             (case-fold-search t)
10174             (body (copy-marker (point))))
10175         (goto-char (point-min))
10176         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10177           (delete-region (match-beginning 1) (match-end 1))
10178           (insert (number-to-string length)))
10179         (goto-char (point-min))
10180         (when (re-search-forward
10181                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10182           (delete-region (match-beginning 1) (match-end 1))
10183           (insert (number-to-string length)))
10184         (goto-char (point-min))
10185         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10186           (delete-region (match-beginning 1) (match-end 1))
10187           (insert (number-to-string lines))))))
10188   ;; Replace the article.
10189   (let ((buf (current-buffer)))
10190     (with-temp-buffer
10191       (insert-buffer-substring buf)
10192
10193       (if (and (not read-only)
10194                (not (gnus-request-replace-article
10195                      (cdr gnus-article-current) (car gnus-article-current)
10196                      (current-buffer) t)))
10197           (error "Couldn't replace article")
10198         ;; Update the summary buffer.
10199         (if (and references
10200                  (equal (message-tokenize-header references " ")
10201                         (message-tokenize-header
10202                          (or (message-fetch-field "references") "") " ")))
10203             ;; We only have to update this line.
10204             (save-excursion
10205               (save-restriction
10206                 (message-narrow-to-head)
10207                 (let ((head (buffer-substring-no-properties
10208                              (point-min) (point-max)))
10209                       header)
10210                   (with-temp-buffer
10211                     (insert (format "211 %d Article retrieved.\n"
10212                                     (cdr gnus-article-current)))
10213                     (insert head)
10214                     (insert ".\n")
10215                     (let ((nntp-server-buffer (current-buffer)))
10216                       (setq header (car (gnus-get-newsgroup-headers
10217                                          nil t))))
10218                     (with-current-buffer gnus-summary-buffer
10219                       (gnus-data-set-header
10220                        (gnus-data-find (cdr gnus-article-current))
10221                        header)
10222                       (gnus-summary-update-article-line
10223                        (cdr gnus-article-current) header)
10224                       (if (gnus-summary-goto-subject
10225                            (cdr gnus-article-current) nil t)
10226                           (gnus-summary-update-secondary-mark
10227                            (cdr gnus-article-current))))))))
10228           ;; Update threads.
10229           (set-buffer (or buffer gnus-summary-buffer))
10230           (gnus-summary-update-article (cdr gnus-article-current))
10231           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10232               (gnus-summary-update-secondary-mark
10233                (cdr gnus-article-current))))
10234         ;; Prettify the article buffer again.
10235         (unless no-highlight
10236           (with-current-buffer gnus-article-buffer
10237             ;;;!!! Fix this -- article should be rehighlighted.
10238             ;;;(gnus-run-hooks 'gnus-article-display-hook)
10239             (set-buffer gnus-original-article-buffer)
10240             (gnus-request-article
10241              (cdr gnus-article-current)
10242              (car gnus-article-current) (current-buffer))))
10243         ;; Prettify the summary buffer line.
10244         (when (gnus-visual-p 'summary-highlight 'highlight)
10245           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10246
10247 (defun gnus-summary-edit-wash (key)
10248   "Perform editing command KEY in the article buffer."
10249   (interactive
10250    (list
10251     (progn
10252       (message "%s" (concat (this-command-keys) "- "))
10253       (read-char))))
10254   (message "")
10255   (gnus-summary-edit-article)
10256   (execute-kbd-macro (concat (this-command-keys) key))
10257   (gnus-article-edit-done))
10258
10259 ;;; Respooling
10260
10261 (defun gnus-summary-respool-query (&optional silent trace)
10262   "Query where the respool algorithm would put this article."
10263   (interactive)
10264   (let (gnus-mark-article-hook)
10265     (gnus-summary-select-article)
10266     (with-current-buffer gnus-original-article-buffer
10267       (let ((groups (nnmail-article-group 'identity trace)))
10268         (unless silent
10269           (if groups
10270               (message "This message would go to %s"
10271                        (mapconcat 'car groups ", "))
10272             (message "This message would go to no groups"))
10273           groups)))))
10274
10275 (defun gnus-summary-respool-trace ()
10276   "Trace where the respool algorithm would put this article.
10277 Display a buffer showing all fancy splitting patterns which matched."
10278   (interactive)
10279   (gnus-summary-respool-query nil t))
10280
10281 ;; Summary marking commands.
10282
10283 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10284   "Mark articles which has the same subject as read, and then select the next.
10285 If UNMARK is positive, remove any kind of mark.
10286 If UNMARK is negative, tick articles."
10287   (interactive "P")
10288   (when unmark
10289     (setq unmark (prefix-numeric-value unmark)))
10290   (let ((count
10291          (gnus-summary-mark-same-subject
10292           (gnus-summary-article-subject) unmark)))
10293     ;; Select next unread article.  If auto-select-same mode, should
10294     ;; select the first unread article.
10295     (gnus-summary-next-article t (and gnus-auto-select-same
10296                                       (gnus-summary-article-subject)))
10297     (gnus-message 7 "%d article%s marked as %s"
10298                   count (if (= count 1) " is" "s are")
10299                   (if unmark "unread" "read"))))
10300
10301 (defun gnus-summary-kill-same-subject (&optional unmark)
10302   "Mark articles which has the same subject as read.
10303 If UNMARK is positive, remove any kind of mark.
10304 If UNMARK is negative, tick articles."
10305   (interactive "P")
10306   (when unmark
10307     (setq unmark (prefix-numeric-value unmark)))
10308   (let ((count
10309          (gnus-summary-mark-same-subject
10310           (gnus-summary-article-subject) unmark)))
10311     ;; If marked as read, go to next unread subject.
10312     (when (null unmark)
10313       ;; Go to next unread subject.
10314       (gnus-summary-next-subject 1 t))
10315     (gnus-message 7 "%d articles are marked as %s"
10316                   count (if unmark "unread" "read"))))
10317
10318 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10319   "Mark articles with same SUBJECT as read, and return marked number.
10320 If optional argument UNMARK is positive, remove any kinds of marks.
10321 If optional argument UNMARK is negative, mark articles as unread instead."
10322   (let ((count 1))
10323     (save-excursion
10324       (cond
10325        ((null unmark)                   ; Mark as read.
10326         (while (and
10327                 (progn
10328                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10329                   (gnus-summary-show-thread) t)
10330                 (gnus-summary-find-subject subject))
10331           (setq count (1+ count))))
10332        ((> unmark 0)                    ; Tick.
10333         (while (and
10334                 (progn
10335                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10336                   (gnus-summary-show-thread) t)
10337                 (gnus-summary-find-subject subject))
10338           (setq count (1+ count))))
10339        (t                               ; Mark as unread.
10340         (while (and
10341                 (progn
10342                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10343                   (gnus-summary-show-thread) t)
10344                 (gnus-summary-find-subject subject))
10345           (setq count (1+ count)))))
10346       (gnus-set-mode-line 'summary)
10347       ;; Return the number of marked articles.
10348       count)))
10349
10350 (defun gnus-summary-mark-as-processable (n &optional unmark)
10351   "Set the process mark on the next N articles.
10352 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10353 the process mark instead.  The difference between N and the actual
10354 number of articles marked is returned."
10355   (interactive "P")
10356   (if (and (null n) (gnus-region-active-p))
10357       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10358     (setq n (prefix-numeric-value n))
10359     (let ((backward (< n 0))
10360           (n (abs n)))
10361       (while (and
10362               (> n 0)
10363               (if unmark
10364                   (gnus-summary-remove-process-mark
10365                    (gnus-summary-article-number))
10366                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10367               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10368         (setq n (1- n)))
10369       (when (/= 0 n)
10370         (gnus-message 7 "No more articles"))
10371       (gnus-summary-recenter)
10372       (gnus-summary-position-point)
10373       n)))
10374
10375 (defun gnus-summary-unmark-as-processable (n)
10376   "Remove the process mark from the next N articles.
10377 If N is negative, unmark backward instead.  The difference between N and
10378 the actual number of articles unmarked is returned."
10379   (interactive "P")
10380   (gnus-summary-mark-as-processable n t))
10381
10382 (defun gnus-summary-unmark-all-processable ()
10383   "Remove the process mark from all articles."
10384   (interactive)
10385   (save-excursion
10386     (while gnus-newsgroup-processable
10387       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10388   (gnus-summary-position-point))
10389
10390 (defun gnus-summary-add-mark (article type)
10391   "Mark ARTICLE with a mark of TYPE."
10392   (let ((vtype (car (assq type gnus-article-mark-lists)))
10393         var)
10394     (if (not vtype)
10395         (error "No such mark type: %s" type)
10396       (setq var (intern (format "gnus-newsgroup-%s" type)))
10397       (set var (cons article (symbol-value var)))
10398       (if (memq type '(processable cached replied forwarded recent saved))
10399           (gnus-summary-update-secondary-mark article)
10400         ;;; !!! This is bogus.  We should find out what primary
10401         ;;; !!! mark we want to set.
10402         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10403
10404 (defun gnus-summary-mark-as-expirable (n)
10405   "Mark N articles forward as expirable.
10406 If N is negative, mark backward instead.  The difference between N and
10407 the actual number of articles marked is returned."
10408   (interactive "p")
10409   (gnus-summary-mark-forward n gnus-expirable-mark))
10410
10411 (defun gnus-summary-mark-as-spam (n)
10412   "Mark N articles forward as spam.
10413 If N is negative, mark backward instead.  The difference between N and
10414 the actual number of articles marked is returned."
10415   (interactive "p")
10416   (gnus-summary-mark-forward n gnus-spam-mark))
10417
10418 (defun gnus-summary-mark-article-as-replied (article)
10419   "Mark ARTICLE as replied to and update the summary line.
10420 ARTICLE can also be a list of articles."
10421   (interactive (list (gnus-summary-article-number)))
10422   (let ((articles (if (listp article) article (list article))))
10423     (dolist (article articles)
10424       (unless (numberp article)
10425         (error "%s is not a number" article))
10426       (push article gnus-newsgroup-replied)
10427       (let ((inhibit-read-only t))
10428         (when (gnus-summary-goto-subject article nil t)
10429           (gnus-summary-update-secondary-mark article))))))
10430
10431 (defun gnus-summary-mark-article-as-forwarded (article)
10432   "Mark ARTICLE as forwarded and update the summary line.
10433 ARTICLE can also be a list of articles."
10434   (let ((articles (if (listp article) article (list article))))
10435     (dolist (article articles)
10436       (push article gnus-newsgroup-forwarded)
10437       (let ((inhibit-read-only t))
10438         (when (gnus-summary-goto-subject article nil t)
10439           (gnus-summary-update-secondary-mark article))))))
10440
10441 (defun gnus-summary-set-bookmark (article)
10442   "Set a bookmark in current article."
10443   (interactive (list (gnus-summary-article-number)))
10444   (when (or (not (get-buffer gnus-article-buffer))
10445             (not gnus-current-article)
10446             (not gnus-article-current)
10447             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10448     (error "No current article selected"))
10449   ;; Remove old bookmark, if one exists.
10450   (gnus-pull article gnus-newsgroup-bookmarks)
10451   ;; Set the new bookmark, which is on the form
10452   ;; (article-number . line-number-in-body).
10453   (push
10454    (cons article
10455          (with-current-buffer gnus-article-buffer
10456            (count-lines
10457             (min (point)
10458                  (save-excursion
10459                    (article-goto-body)
10460                    (point)))
10461             (point))))
10462    gnus-newsgroup-bookmarks)
10463   (gnus-message 6 "A bookmark has been added to the current article."))
10464
10465 (defun gnus-summary-remove-bookmark (article)
10466   "Remove the bookmark from the current article."
10467   (interactive (list (gnus-summary-article-number)))
10468   ;; Remove old bookmark, if one exists.
10469   (if (not (assq article gnus-newsgroup-bookmarks))
10470       (gnus-message 6 "No bookmark in current article.")
10471     (gnus-pull article gnus-newsgroup-bookmarks)
10472     (gnus-message 6 "Removed bookmark.")))
10473
10474 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10475 (defun gnus-summary-mark-as-dormant (n)
10476   "Mark N articles forward as dormant.
10477 If N is negative, mark backward instead.  The difference between N and
10478 the actual number of articles marked is returned."
10479   (interactive "p")
10480   (gnus-summary-mark-forward n gnus-dormant-mark))
10481
10482 (defun gnus-summary-set-process-mark (article)
10483   "Set the process mark on ARTICLE and update the summary line."
10484   (setq gnus-newsgroup-processable
10485         (cons article
10486               (delq article gnus-newsgroup-processable)))
10487   (when (gnus-summary-goto-subject article)
10488     (gnus-summary-show-thread)
10489     (gnus-summary-goto-subject article)
10490     (gnus-summary-update-secondary-mark article)))
10491
10492 (defun gnus-summary-remove-process-mark (&rest articles)
10493   "Remove the process mark from ARTICLES and update the summary line."
10494   (dolist (article articles)
10495     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10496     (when (gnus-summary-goto-subject article)
10497       (gnus-summary-show-thread)
10498       (gnus-summary-goto-subject article)
10499       (gnus-summary-update-secondary-mark article)))
10500   t)
10501
10502 (defun gnus-summary-set-saved-mark (article)
10503   "Set the process mark on ARTICLE and update the summary line."
10504   (push article gnus-newsgroup-saved)
10505   (when (gnus-summary-goto-subject article)
10506     (gnus-summary-update-secondary-mark article)))
10507
10508 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10509   "Mark N articles as read forwards.
10510 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10511 The difference between N and the actual number of articles marked is
10512 returned.
10513 If NO-EXPIRE, auto-expiry will be inhibited."
10514   (interactive "p")
10515   (gnus-summary-show-thread)
10516   (let ((backward (< n 0))
10517         (gnus-summary-goto-unread
10518          (and gnus-summary-goto-unread
10519               (not (eq gnus-summary-goto-unread 'never))
10520               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10521                                     gnus-ticked-mark gnus-dormant-mark)))))
10522         (n (abs n))
10523         (mark (or mark gnus-del-mark)))
10524     (while (and (> n 0)
10525                 (gnus-summary-mark-article nil mark no-expire)
10526                 (zerop (gnus-summary-next-subject
10527                         (if backward -1 1)
10528                         (and gnus-summary-goto-unread
10529                              (not (eq gnus-summary-goto-unread 'never)))
10530                         t)))
10531       (setq n (1- n)))
10532     (when (/= 0 n)
10533       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10534     (gnus-summary-recenter)
10535     (gnus-summary-position-point)
10536     (gnus-set-mode-line 'summary)
10537     n))
10538
10539 (defun gnus-summary-mark-article-as-read (mark)
10540   "Mark the current article quickly as read with MARK."
10541   (let ((article (gnus-summary-article-number)))
10542     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10543     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10544     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10545     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10546     (push (cons article mark) gnus-newsgroup-reads)
10547     ;; Possibly remove from cache, if that is used.
10548     (when gnus-use-cache
10549       (gnus-cache-enter-remove-article article))
10550     ;; Allow the backend to change the mark.
10551     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10552     ;; Check for auto-expiry.
10553     (when (and gnus-newsgroup-auto-expire
10554                (memq mark gnus-auto-expirable-marks))
10555       (setq mark gnus-expirable-mark)
10556       ;; Let the backend know about the mark change.
10557       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10558       (push article gnus-newsgroup-expirable))
10559     ;; Set the mark in the buffer.
10560     (gnus-summary-update-mark mark 'unread)
10561     t))
10562
10563 (defun gnus-summary-mark-article-as-unread (mark)
10564   "Mark the current article quickly as unread with MARK."
10565   (let* ((article (gnus-summary-article-number))
10566          (old-mark (gnus-summary-article-mark article)))
10567     ;; Allow the backend to change the mark.
10568     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10569     (if (eq mark old-mark)
10570         t
10571       (if (<= article 0)
10572           (progn
10573             (gnus-error 1 "Can't mark negative article numbers")
10574             nil)
10575         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10576         (setq gnus-newsgroup-spam-marked
10577               (delq article gnus-newsgroup-spam-marked))
10578         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10579         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10580         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10581         (cond ((= mark gnus-ticked-mark)
10582                (setq gnus-newsgroup-marked
10583                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10584                                               article)))
10585               ((= mark gnus-spam-mark)
10586                (setq gnus-newsgroup-spam-marked
10587                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10588                                               article)))
10589               ((= mark gnus-dormant-mark)
10590                (setq gnus-newsgroup-dormant
10591                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10592                                               article)))
10593               (t
10594                (setq gnus-newsgroup-unreads
10595                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10596                                               article))))
10597         (gnus-pull article gnus-newsgroup-reads)
10598
10599         ;; See whether the article is to be put in the cache.
10600         (and gnus-use-cache
10601              (vectorp (gnus-summary-article-header article))
10602              (save-excursion
10603                (gnus-cache-possibly-enter-article
10604                 gnus-newsgroup-name article
10605                 (= mark gnus-ticked-mark)
10606                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10607
10608         ;; Fix the mark.
10609         (gnus-summary-update-mark mark 'unread)
10610         t))))
10611
10612 (defun gnus-summary-mark-article (&optional article mark no-expire)
10613   "Mark ARTICLE with MARK.  MARK can be any character.
10614 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10615 `??' (dormant) and `?E' (expirable).
10616 If MARK is nil, then the default character `?r' is used.
10617 If ARTICLE is nil, then the article on the current line will be
10618 marked.
10619 If NO-EXPIRE, auto-expiry will be inhibited."
10620   ;; The mark might be a string.
10621   (when (stringp mark)
10622     (setq mark (aref mark 0)))
10623   ;; If no mark is given, then we check auto-expiring.
10624   (when (null mark)
10625     (setq mark gnus-del-mark))
10626   (when (and (not no-expire)
10627              gnus-newsgroup-auto-expire
10628              (memq mark gnus-auto-expirable-marks))
10629     (setq mark gnus-expirable-mark))
10630   (let ((article (or article (gnus-summary-article-number)))
10631         (old-mark (gnus-summary-article-mark article)))
10632     ;; Allow the backend to change the mark.
10633     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10634     (if (eq mark old-mark)
10635         t
10636       (unless article
10637         (error "No article on current line"))
10638       (if (not (if (or (= mark gnus-unread-mark)
10639                        (= mark gnus-ticked-mark)
10640                        (= mark gnus-spam-mark)
10641                        (= mark gnus-dormant-mark))
10642                    (gnus-mark-article-as-unread article mark)
10643                  (gnus-mark-article-as-read article mark)))
10644           t
10645         ;; See whether the article is to be put in the cache.
10646         (and gnus-use-cache
10647              (not (= mark gnus-canceled-mark))
10648              (vectorp (gnus-summary-article-header article))
10649              (save-excursion
10650                (gnus-cache-possibly-enter-article
10651                 gnus-newsgroup-name article
10652                 (= mark gnus-ticked-mark)
10653                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10654
10655         (when (gnus-summary-goto-subject article nil t)
10656           (let ((inhibit-read-only t))
10657             (gnus-summary-show-thread)
10658             ;; Fix the mark.
10659             (gnus-summary-update-mark mark 'unread)
10660             t))))))
10661
10662 (defun gnus-summary-update-secondary-mark (article)
10663   "Update the secondary (read, process, cache) mark."
10664   (gnus-summary-update-mark
10665    (cond ((memq article gnus-newsgroup-processable)
10666           gnus-process-mark)
10667          ((memq article gnus-newsgroup-cached)
10668           gnus-cached-mark)
10669          ((memq article gnus-newsgroup-replied)
10670           gnus-replied-mark)
10671          ((memq article gnus-newsgroup-forwarded)
10672           gnus-forwarded-mark)
10673          ((memq article gnus-newsgroup-saved)
10674           gnus-saved-mark)
10675          ((memq article gnus-newsgroup-recent)
10676           gnus-recent-mark)
10677          ((memq article gnus-newsgroup-unseen)
10678           gnus-unseen-mark)
10679          (t gnus-no-mark))
10680    'replied)
10681   (when (gnus-visual-p 'summary-highlight 'highlight)
10682     (gnus-run-hooks 'gnus-summary-update-hook))
10683   t)
10684
10685 (defun gnus-summary-update-download-mark (article)
10686   "Update the download mark."
10687   (gnus-summary-update-mark
10688    (cond ((memq article gnus-newsgroup-undownloaded)
10689           gnus-undownloaded-mark)
10690          (gnus-newsgroup-agentized
10691           gnus-downloaded-mark)
10692          (t
10693           gnus-no-mark))
10694    'download)
10695   (gnus-summary-update-line t)
10696   t)
10697
10698 (defun gnus-summary-update-mark (mark type)
10699   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10700         (inhibit-read-only t))
10701     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10702     (when forward
10703       (when (looking-at "\r")
10704         (incf forward))
10705       (when (<= (+ forward (point)) (point-max))
10706         ;; Go to the right position on the line.
10707         (goto-char (+ forward (point)))
10708         ;; Replace the old mark with the new mark.
10709         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10710         ;; Optionally update the marks by some user rule.
10711         (when (eq type 'unread)
10712           (gnus-data-set-mark
10713            (gnus-data-find (gnus-summary-article-number)) mark)
10714           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10715
10716 (defun gnus-mark-article-as-read (article &optional mark)
10717   "Enter ARTICLE in the pertinent lists and remove it from others."
10718   ;; Make the article expirable.
10719   (let ((mark (or mark gnus-del-mark)))
10720     (setq gnus-newsgroup-expirable
10721           (if (= mark gnus-expirable-mark)
10722               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10723             (delq article gnus-newsgroup-expirable)))
10724     ;; Remove from unread and marked lists.
10725     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10726     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10727     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10728     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10729     (push (cons article mark) gnus-newsgroup-reads)
10730     ;; Possibly remove from cache, if that is used.
10731     (when gnus-use-cache
10732       (gnus-cache-enter-remove-article article))
10733     t))
10734
10735 (defun gnus-mark-article-as-unread (article &optional mark)
10736   "Enter ARTICLE in the pertinent lists and remove it from others."
10737   (let ((mark (or mark gnus-ticked-mark)))
10738     (if (<= article 0)
10739         (progn
10740           (gnus-error 1 "Can't mark negative article numbers")
10741           nil)
10742       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10743             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10744             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10745             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10746             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10747
10748       ;; Unsuppress duplicates?
10749       (when gnus-suppress-duplicates
10750         (gnus-dup-unsuppress-article article))
10751
10752       (cond ((= mark gnus-ticked-mark)
10753              (setq gnus-newsgroup-marked
10754                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10755             ((= mark gnus-spam-mark)
10756              (setq gnus-newsgroup-spam-marked
10757                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10758                                             article)))
10759             ((= mark gnus-dormant-mark)
10760              (setq gnus-newsgroup-dormant
10761                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10762             (t
10763              (setq gnus-newsgroup-unreads
10764                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10765       (gnus-pull article gnus-newsgroup-reads)
10766       t)))
10767
10768 (defalias 'gnus-summary-mark-as-unread-forward
10769   'gnus-summary-tick-article-forward)
10770 (make-obsolete 'gnus-summary-mark-as-unread-forward
10771                'gnus-summary-tick-article-forward)
10772 (defun gnus-summary-tick-article-forward (n)
10773   "Tick N articles forwards.
10774 If N is negative, tick backwards instead.
10775 The difference between N and the number of articles ticked is returned."
10776   (interactive "p")
10777   (gnus-summary-mark-forward n gnus-ticked-mark))
10778
10779 (defalias 'gnus-summary-mark-as-unread-backward
10780   'gnus-summary-tick-article-backward)
10781 (make-obsolete 'gnus-summary-mark-as-unread-backward
10782                'gnus-summary-tick-article-backward)
10783 (defun gnus-summary-tick-article-backward (n)
10784   "Tick N articles backwards.
10785 The difference between N and the number of articles ticked is returned."
10786   (interactive "p")
10787   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10788
10789 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10790 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10791 (defun gnus-summary-tick-article (&optional article clear-mark)
10792   "Mark current article as unread.
10793 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10794 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10795   (interactive)
10796   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10797                                        gnus-ticked-mark)))
10798
10799 (defun gnus-summary-mark-as-read-forward (n)
10800   "Mark N articles as read forwards.
10801 If N is negative, mark backwards instead.
10802 The difference between N and the actual number of articles marked is
10803 returned."
10804   (interactive "p")
10805   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10806
10807 (defun gnus-summary-mark-as-read-backward (n)
10808   "Mark the N articles as read backwards.
10809 The difference between N and the actual number of articles marked is
10810 returned."
10811   (interactive "p")
10812   (gnus-summary-mark-forward
10813    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10814
10815 (defun gnus-summary-mark-as-read (&optional article mark)
10816   "Mark current article as read.
10817 ARTICLE specifies the article to be marked as read.
10818 MARK specifies a string to be inserted at the beginning of the line."
10819   (gnus-summary-mark-article article mark))
10820
10821 (defun gnus-summary-clear-mark-forward (n)
10822   "Clear marks from N articles forward.
10823 If N is negative, clear backward instead.
10824 The difference between N and the number of marks cleared is returned."
10825   (interactive "p")
10826   (gnus-summary-mark-forward n gnus-unread-mark))
10827
10828 (defun gnus-summary-clear-mark-backward (n)
10829   "Clear marks from N articles backward.
10830 The difference between N and the number of marks cleared is returned."
10831   (interactive "p")
10832   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10833
10834 (defun gnus-summary-mark-unread-as-read ()
10835   "Intended to be used by `gnus-mark-article-hook'."
10836   (when (memq gnus-current-article gnus-newsgroup-unreads)
10837     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10838
10839 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10840   "Intended to be used by `gnus-mark-article-hook'."
10841   (let ((mark (gnus-summary-article-mark)))
10842     (when (or (gnus-unread-mark-p mark)
10843               (gnus-read-mark-p mark))
10844       (gnus-summary-mark-article gnus-current-article
10845                                  (or new-mark gnus-read-mark)))))
10846
10847 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10848   "Intended to be used by `gnus-mark-article-hook'."
10849   (let ((mark (gnus-summary-article-mark)))
10850     (when (or (gnus-unread-mark-p mark)
10851               (gnus-read-mark-p mark))
10852       (gnus-summary-mark-article (gnus-summary-article-number)
10853                                  (or new-mark gnus-read-mark)))))
10854
10855 (defun gnus-summary-mark-unread-as-ticked ()
10856   "Intended to be used by `gnus-mark-article-hook'."
10857   (when (memq gnus-current-article gnus-newsgroup-unreads)
10858     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10859
10860 (defun gnus-summary-mark-region-as-read (point mark all)
10861   "Mark all unread articles between point and mark as read.
10862 If given a prefix, mark all articles between point and mark as read,
10863 even ticked and dormant ones."
10864   (interactive "r\nP")
10865   (save-excursion
10866     (let (article)
10867       (goto-char point)
10868       (beginning-of-line)
10869       (while (and
10870               (< (point) mark)
10871               (progn
10872                 (when (or all
10873                           (memq (setq article (gnus-summary-article-number))
10874                                 gnus-newsgroup-unreads))
10875                   (gnus-summary-mark-article article gnus-del-mark))
10876                 t)
10877               (gnus-summary-find-next))))))
10878
10879 (defun gnus-summary-mark-below (score mark)
10880   "Mark articles with score less than SCORE with MARK."
10881   (interactive "P\ncMark: ")
10882   (setq score (if score
10883                   (prefix-numeric-value score)
10884                 (or gnus-summary-default-score 0)))
10885   (with-current-buffer gnus-summary-buffer
10886     (goto-char (point-min))
10887     (while
10888         (progn
10889           (and (< (gnus-summary-article-score) score)
10890                (gnus-summary-mark-article nil mark))
10891           (gnus-summary-find-next)))))
10892
10893 (defun gnus-summary-kill-below (&optional score)
10894   "Mark articles with score below SCORE as read."
10895   (interactive "P")
10896   (gnus-summary-mark-below score gnus-killed-mark))
10897
10898 (defun gnus-summary-clear-above (&optional score)
10899   "Clear all marks from articles with score above SCORE."
10900   (interactive "P")
10901   (gnus-summary-mark-above score gnus-unread-mark))
10902
10903 (defun gnus-summary-tick-above (&optional score)
10904   "Tick all articles with score above SCORE."
10905   (interactive "P")
10906   (gnus-summary-mark-above score gnus-ticked-mark))
10907
10908 (defun gnus-summary-mark-above (score mark)
10909   "Mark articles with score over SCORE with MARK."
10910   (interactive "P\ncMark: ")
10911   (setq score (if score
10912                   (prefix-numeric-value score)
10913                 (or gnus-summary-default-score 0)))
10914   (with-current-buffer gnus-summary-buffer
10915     (goto-char (point-min))
10916     (while (and (progn
10917                   (when (> (gnus-summary-article-score) score)
10918                     (gnus-summary-mark-article nil mark))
10919                   t)
10920                 (gnus-summary-find-next)))))
10921
10922 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10923 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10924 (defun gnus-summary-limit-include-expunged (&optional no-error)
10925   "Display all the hidden articles that were expunged for low scores."
10926   (interactive)
10927   (let ((inhibit-read-only t))
10928     (let ((scored gnus-newsgroup-scored)
10929           headers h)
10930       (while scored
10931         (unless (gnus-summary-article-header (caar scored))
10932           (and (setq h (gnus-number-to-header (caar scored)))
10933                (< (cdar scored) gnus-summary-expunge-below)
10934                (push h headers)))
10935         (setq scored (cdr scored)))
10936       (if (not headers)
10937           (when (not no-error)
10938             (error "No expunged articles hidden"))
10939         (goto-char (point-min))
10940         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10941         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10942         (dolist (x headers)
10943           (push (mail-header-number x) gnus-newsgroup-limit))
10944         (gnus-summary-prepare-unthreaded (nreverse headers))
10945         (goto-char (point-min))
10946         (gnus-summary-position-point)
10947         t))))
10948
10949 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10950   "Mark all unread articles in this newsgroup as read.
10951 If prefix argument ALL is non-nil, ticked and dormant articles will
10952 also be marked as read.
10953 If QUIETLY is non-nil, no questions will be asked.
10954
10955 If TO-HERE is non-nil, it should be a point in the buffer.  All
10956 articles before (after, if REVERSE is set) this point will be marked
10957 as read.
10958
10959 Note that this function will only catch up the unread article
10960 in the current summary buffer limitation.
10961
10962 The number of articles marked as read is returned."
10963   (interactive "P")
10964   (prog1
10965       (save-excursion
10966         (when (or quietly
10967                   (not gnus-interactive-catchup) ;Without confirmation?
10968                   gnus-expert-user
10969                   (gnus-y-or-n-p
10970                    (if all
10971                        "Mark absolutely all articles as read? "
10972                      "Mark all unread articles as read? ")))
10973           (if (and not-mark
10974                    (not gnus-newsgroup-adaptive)
10975                    (not gnus-newsgroup-auto-expire)
10976                    (not gnus-suppress-duplicates)
10977                    (or (not gnus-use-cache)
10978                        (eq gnus-use-cache 'passive)))
10979               (progn
10980                 (when all
10981                   (setq gnus-newsgroup-marked nil
10982                         gnus-newsgroup-spam-marked nil
10983                         gnus-newsgroup-dormant nil))
10984                 (setq gnus-newsgroup-unreads
10985                       (gnus-sorted-nunion
10986                        (gnus-sorted-intersection gnus-newsgroup-unreads
10987                                                  gnus-newsgroup-downloadable)
10988                        (gnus-sorted-difference gnus-newsgroup-unfetched
10989                                                gnus-newsgroup-cached))))
10990             ;; We actually mark all articles as canceled, which we
10991             ;; have to do when using auto-expiry or adaptive scoring.
10992             (gnus-summary-show-all-threads)
10993             (if (and to-here reverse)
10994                 (progn
10995                   (goto-char to-here)
10996                   (gnus-summary-mark-current-read-and-unread-as-read
10997                    gnus-catchup-mark)
10998                   (while (gnus-summary-find-next (not all))
10999                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
11000               (when (gnus-summary-first-subject (not all))
11001                 (while (and
11002                         (if to-here (< (point) to-here) t)
11003                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
11004                         (gnus-summary-find-next (not all))))))
11005             (gnus-set-mode-line 'summary))
11006           t))
11007     (gnus-summary-position-point)))
11008
11009 (defun gnus-summary-catchup-to-here (&optional all)
11010   "Mark all unticked articles before the current one as read.
11011 If ALL is non-nil, also mark ticked and dormant articles as read."
11012   (interactive "P")
11013   (save-excursion
11014     (gnus-save-hidden-threads
11015       (let ((beg (point)))
11016         ;; We check that there are unread articles.
11017         (when (or all (gnus-summary-find-prev))
11018           (gnus-summary-catchup all t beg)))))
11019   (gnus-summary-position-point))
11020
11021 (defun gnus-summary-catchup-from-here (&optional all)
11022   "Mark all unticked articles after (and including) the current one as read.
11023 If ALL is non-nil, also mark ticked and dormant articles as read."
11024   (interactive "P")
11025   (save-excursion
11026     (gnus-save-hidden-threads
11027       (let ((beg (point)))
11028         ;; We check that there are unread articles.
11029         (when (or all (gnus-summary-find-next))
11030           (gnus-summary-catchup all t beg nil t)))))
11031   (gnus-summary-position-point))
11032
11033 (defun gnus-summary-catchup-all (&optional quietly)
11034   "Mark all articles in this newsgroup as read.
11035 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11036 instead, which marks only unread articles as read."
11037   (interactive "P")
11038   (gnus-summary-catchup t quietly))
11039
11040 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11041   "Mark all unread articles in this group as read, then exit.
11042 If prefix argument ALL is non-nil, all articles are marked as read.
11043 If QUIETLY is non-nil, no questions will be asked."
11044   (interactive "P")
11045   (when (gnus-summary-catchup all quietly nil 'fast)
11046     ;; Select next newsgroup or exit.
11047     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11048              (eq gnus-auto-select-next 'quietly))
11049         (gnus-summary-next-group nil)
11050       (gnus-summary-exit))))
11051
11052 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11053   "Mark all articles in this newsgroup as read, and then exit.
11054 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11055 instead, which marks only unread articles as read."
11056   (interactive "P")
11057   (gnus-summary-catchup-and-exit t quietly))
11058
11059 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11060   "Mark all articles in this group as read and select the next group.
11061 If given a prefix, mark all articles, unread as well as ticked, as
11062 read."
11063   (interactive "P")
11064   (save-excursion
11065     (gnus-summary-catchup all))
11066   (gnus-summary-next-group))
11067
11068 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11069   "Mark all articles in this group as read and select the previous group.
11070 If given a prefix, mark all articles, unread as well as ticked, as
11071 read."
11072   (interactive "P")
11073   (save-excursion
11074     (gnus-summary-catchup all))
11075   (gnus-summary-next-group nil nil t))
11076
11077 ;;;
11078 ;;; with article
11079 ;;;
11080
11081 (defmacro gnus-with-article (article &rest forms)
11082   "Select ARTICLE and perform FORMS in the original article buffer.
11083 Then replace the article with the result."
11084   `(progn
11085      ;; We don't want the article to be marked as read.
11086      (let (gnus-mark-article-hook)
11087        (gnus-summary-select-article t t nil ,article))
11088      (set-buffer gnus-original-article-buffer)
11089      ,@forms
11090      (if (not (gnus-check-backend-function
11091                'request-replace-article (car gnus-article-current)))
11092          (gnus-message 5 "Read-only group; not replacing")
11093        (unless (gnus-request-replace-article
11094                 ,article (car gnus-article-current)
11095                 (current-buffer) t)
11096          (error "Couldn't replace article")))
11097      ;; The cache and backlog have to be flushed somewhat.
11098      (when gnus-keep-backlog
11099        (gnus-backlog-remove-article
11100         (car gnus-article-current) (cdr gnus-article-current)))
11101      (when gnus-use-cache
11102        (gnus-cache-update-article
11103         (car gnus-article-current) (cdr gnus-article-current)))))
11104
11105 (put 'gnus-with-article 'lisp-indent-function 1)
11106 (put 'gnus-with-article 'edebug-form-spec '(form body))
11107
11108 ;; Thread-based commands.
11109
11110 (defun gnus-summary-articles-in-thread (&optional article)
11111   "Return a list of all articles in the current thread.
11112 If ARTICLE is non-nil, return all articles in the thread that starts
11113 with that article."
11114   (let* ((article (or article (gnus-summary-article-number)))
11115          (data (gnus-data-find-list article))
11116          (top-level (gnus-data-level (car data)))
11117          (top-subject
11118           (cond ((null gnus-thread-operation-ignore-subject)
11119                  (gnus-simplify-subject-re
11120                   (mail-header-subject (gnus-data-header (car data)))))
11121                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11122                  (gnus-simplify-subject-fuzzy
11123                   (mail-header-subject (gnus-data-header (car data)))))
11124                 (t nil)))
11125          (end-point (save-excursion
11126                       (if (gnus-summary-go-to-next-thread)
11127                           (point) (point-max))))
11128          articles)
11129     (while (and data
11130                 (< (gnus-data-pos (car data)) end-point))
11131       (when (or (not top-subject)
11132                 (string= top-subject
11133                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11134                              (gnus-simplify-subject-fuzzy
11135                               (mail-header-subject
11136                                (gnus-data-header (car data))))
11137                            (gnus-simplify-subject-re
11138                             (mail-header-subject
11139                              (gnus-data-header (car data)))))))
11140         (push (gnus-data-number (car data)) articles))
11141       (unless (and (setq data (cdr data))
11142                    (> (gnus-data-level (car data)) top-level))
11143         (setq data nil)))
11144     ;; Return the list of articles.
11145     (nreverse articles)))
11146
11147 (defun gnus-summary-rethread-current ()
11148   "Rethread the thread the current article is part of."
11149   (interactive)
11150   (let* ((gnus-show-threads t)
11151          (article (gnus-summary-article-number))
11152          (id (mail-header-id (gnus-summary-article-header)))
11153          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11154     (unless id
11155       (error "No article on the current line"))
11156     (gnus-rebuild-thread id)
11157     (gnus-summary-goto-subject article)))
11158
11159 (defun gnus-summary-reparent-thread ()
11160   "Make the current article child of the marked (or previous) article.
11161
11162 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11163 is non-nil or the Subject: of both articles are the same."
11164   (interactive)
11165   (unless (not (gnus-group-read-only-p))
11166     (error "The current newsgroup does not support article editing"))
11167   (unless (<= (length gnus-newsgroup-processable) 1)
11168     (error "No more than one article may be marked"))
11169   (let ((child (gnus-summary-article-number))
11170         ;; First grab the marked article, otherwise one line up.
11171         (parent (if (not (null gnus-newsgroup-processable))
11172                     (car gnus-newsgroup-processable)
11173                   (save-excursion
11174                     (if (eq (forward-line -1) 0)
11175                         (gnus-summary-article-number)
11176                       (error "Beginning of summary buffer"))))))
11177     (gnus-summary-reparent-children parent (list child))))
11178
11179 (defun gnus-summary-reparent-children (parent children)
11180   "Make PARENT the parent of CHILDREN.
11181 When called interactively, PARENT is the current article and CHILDREN
11182 are the process-marked articles."
11183   (interactive
11184    (list (gnus-summary-article-number)
11185          (gnus-summary-work-articles nil)))
11186   (dolist (child children)
11187     (save-window-excursion
11188       (let ((gnus-article-buffer " *reparent*"))
11189         (unless (not (eq parent child))
11190           (error "An article may not be self-referential"))
11191         (let ((message-id (mail-header-id
11192                            (gnus-summary-article-header parent))))
11193           (unless (and message-id (not (equal message-id "")))
11194             (error "No message-id in desired parent"))
11195           (gnus-with-article child
11196             (save-restriction
11197               (goto-char (point-min))
11198               (message-narrow-to-head)
11199               (if (re-search-forward "^References: " nil t)
11200                   (progn
11201                     (re-search-forward "^[^ \t]" nil t)
11202                     (forward-line -1)
11203                     (end-of-line)
11204                     (insert " " message-id))
11205                 (insert "References: " message-id "\n"))))
11206           (set-buffer gnus-summary-buffer)
11207           (gnus-summary-unmark-all-processable)
11208           (gnus-summary-update-article child)
11209           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11210             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11211           (gnus-summary-rethread-current)
11212           (gnus-message 3 "Article %d is now the child of article %d"
11213                         child parent))))))
11214
11215 (defun gnus-summary-toggle-threads (&optional arg)
11216   "Toggle showing conversation threads.
11217 If ARG is positive number, turn showing conversation threads on."
11218   (interactive "P")
11219   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11220     (setq gnus-show-threads
11221           (if (null arg) (not gnus-show-threads)
11222             (> (prefix-numeric-value arg) 0)))
11223     (gnus-summary-prepare)
11224     (gnus-summary-goto-subject current)
11225     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11226     (gnus-summary-position-point)))
11227
11228 (defun gnus-summary-show-all-threads ()
11229   "Show all threads."
11230   (interactive)
11231   (save-excursion
11232     (let ((buffer-read-only nil))
11233       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
11234   (gnus-summary-position-point))
11235
11236 (defun gnus-summary-show-thread ()
11237   "Show thread subtrees.
11238 Returns nil if no thread was there to be shown."
11239   (interactive)
11240   (let ((buffer-read-only nil)
11241         (orig (point))
11242         (end (point-at-eol))
11243         ;; Leave point at bol
11244         (beg (progn (beginning-of-line) (point))))
11245     (prog1
11246         ;; Any hidden lines here?
11247         (search-forward "\r" end t)
11248       (subst-char-in-region beg end ?\^M ?\n t)
11249       (goto-char orig)
11250       (gnus-summary-position-point))))
11251
11252 (defun gnus-summary-maybe-hide-threads ()
11253   "If requested, hide the threads that should be hidden."
11254   (when (and gnus-show-threads
11255              gnus-thread-hide-subtree)
11256     (gnus-summary-hide-all-threads
11257      (if (or (consp gnus-thread-hide-subtree)
11258              (functionp gnus-thread-hide-subtree))
11259          (gnus-make-predicate gnus-thread-hide-subtree)
11260        nil))))
11261
11262 ;;; Hiding predicates.
11263
11264 (defun gnus-article-unread-p (header)
11265   (memq (mail-header-number header) gnus-newsgroup-unreads))
11266
11267 (defun gnus-article-unseen-p (header)
11268   (memq (mail-header-number header) gnus-newsgroup-unseen))
11269
11270 (defun gnus-map-articles (predicate articles)
11271   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11272   (apply 'gnus-or (mapcar predicate
11273                           (mapcar (lambda (number)
11274                                     (gnus-summary-article-header number))
11275                                   articles))))
11276
11277 (defun gnus-summary-hide-all-threads (&optional predicate)
11278   "Hide all thread subtrees.
11279 If PREDICATE is supplied, threads that satisfy this predicate
11280 will not be hidden."
11281   (interactive)
11282   (save-excursion
11283     (goto-char (point-min))
11284     (let ((end nil))
11285       (while (not end)
11286         (when (or (not predicate)
11287                   (gnus-map-articles
11288                    predicate (gnus-summary-article-children)))
11289             (gnus-summary-hide-thread))
11290         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11291   (gnus-summary-position-point))
11292
11293 (defun gnus-summary-hide-thread ()
11294   "Hide thread subtrees.
11295 If PREDICATE is supplied, threads that satisfy this predicate
11296 will not be hidden.
11297 Returns nil if no threads were there to be hidden."
11298   (interactive)
11299   (let ((buffer-read-only nil)
11300         (start (point))
11301         (article (gnus-summary-article-number)))
11302     (goto-char start)
11303     ;; Go forward until either the buffer ends or the subthread ends.
11304     (when (and (not (eobp))
11305                (or (zerop (gnus-summary-next-thread 1 t))
11306                    (goto-char (point-max))))
11307       (prog1
11308           (if (and (> (point) start)
11309                    (search-backward "\n" start t))
11310               (progn
11311                 (subst-char-in-region start (point) ?\n ?\^M)
11312                 (gnus-summary-goto-subject article))
11313             (goto-char start)
11314             nil)))))
11315
11316 (defun gnus-summary-go-to-next-thread (&optional previous)
11317   "Go to the same level (or less) next thread.
11318 If PREVIOUS is non-nil, go to previous thread instead.
11319 Return the article number moved to, or nil if moving was impossible."
11320   (let ((level (gnus-summary-thread-level))
11321         (way (if previous -1 1))
11322         (beg (point)))
11323     (forward-line way)
11324     (while (and (not (eobp))
11325                 (< level (gnus-summary-thread-level)))
11326       (forward-line way))
11327     (if (eobp)
11328         (progn
11329           (goto-char beg)
11330           nil)
11331       (setq beg (point))
11332       (prog1
11333           (gnus-summary-article-number)
11334         (goto-char beg)))))
11335
11336 (defun gnus-summary-next-thread (n &optional silent)
11337   "Go to the same level next N'th thread.
11338 If N is negative, search backward instead.
11339 Returns the difference between N and the number of skips actually
11340 done.
11341
11342 If SILENT, don't output messages."
11343   (interactive "p")
11344   (let ((backward (< n 0))
11345         (n (abs n)))
11346     (while (and (> n 0)
11347                 (gnus-summary-go-to-next-thread backward))
11348       (decf n))
11349     (unless silent
11350       (gnus-summary-position-point))
11351     (when (and (not silent) (/= 0 n))
11352       (gnus-message 7 "No more threads"))
11353     n))
11354
11355 (defun gnus-summary-prev-thread (n)
11356   "Go to the same level previous N'th thread.
11357 Returns the difference between N and the number of skips actually
11358 done."
11359   (interactive "p")
11360   (gnus-summary-next-thread (- n)))
11361
11362 (defun gnus-summary-go-down-thread ()
11363   "Go down one level in the current thread."
11364   (let ((children (gnus-summary-article-children)))
11365     (when children
11366       (gnus-summary-goto-subject (car children)))))
11367
11368 (defun gnus-summary-go-up-thread ()
11369   "Go up one level in the current thread."
11370   (let ((parent (gnus-summary-article-parent)))
11371     (when parent
11372       (gnus-summary-goto-subject parent))))
11373
11374 (defun gnus-summary-down-thread (n)
11375   "Go down thread N steps.
11376 If N is negative, go up instead.
11377 Returns the difference between N and how many steps down that were
11378 taken."
11379   (interactive "p")
11380   (let ((up (< n 0))
11381         (n (abs n)))
11382     (while (and (> n 0)
11383                 (if up (gnus-summary-go-up-thread)
11384                   (gnus-summary-go-down-thread)))
11385       (setq n (1- n)))
11386     (gnus-summary-position-point)
11387     (when (/= 0 n)
11388       (gnus-message 7 "Can't go further"))
11389     n))
11390
11391 (defun gnus-summary-up-thread (n)
11392   "Go up thread N steps.
11393 If N is negative, go down instead.
11394 Returns the difference between N and how many steps down that were
11395 taken."
11396   (interactive "p")
11397   (gnus-summary-down-thread (- n)))
11398
11399 (defun gnus-summary-top-thread ()
11400   "Go to the top of the thread."
11401   (interactive)
11402   (while (gnus-summary-go-up-thread))
11403   (gnus-summary-article-number))
11404
11405 (defun gnus-summary-expire-thread ()
11406   "Mark articles under current thread as expired."
11407   (interactive)
11408   (gnus-summary-kill-thread 0))
11409
11410 (defun gnus-summary-kill-thread (&optional unmark)
11411   "Mark articles under current thread as read.
11412 If the prefix argument is positive, remove any kinds of marks.
11413 If the prefix argument is zero, mark thread as expired.
11414 If the prefix argument is negative, tick articles instead."
11415   (interactive "P")
11416   (when unmark
11417     (setq unmark (prefix-numeric-value unmark)))
11418   (let ((articles (gnus-summary-articles-in-thread))
11419         (hide (or (null unmark) (= unmark 0))))
11420     (save-excursion
11421       ;; Expand the thread.
11422       (gnus-summary-show-thread)
11423       ;; Mark all the articles.
11424       (while articles
11425         (gnus-summary-goto-subject (car articles))
11426         (cond ((null unmark)
11427                (gnus-summary-mark-article-as-read gnus-killed-mark))
11428               ((> unmark 0)
11429                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11430               ((= unmark 0)
11431                (gnus-summary-mark-article-as-unread gnus-expirable-mark))
11432               (t
11433                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11434         (setq articles (cdr articles))))
11435     ;; Hide killed subtrees when hide is true.
11436     (and hide
11437          gnus-thread-hide-killed
11438          (gnus-summary-hide-thread))
11439     ;; If hide is t, go to next unread subject.
11440     (when hide
11441       ;; Go to next unread subject.
11442       (gnus-summary-next-subject 1 t)))
11443   (gnus-set-mode-line 'summary))
11444
11445 ;; Summary sorting commands
11446
11447 (defun gnus-summary-sort-by-number (&optional reverse)
11448   "Sort the summary buffer by article number.
11449 Argument REVERSE means reverse order."
11450   (interactive "P")
11451   (gnus-summary-sort 'number reverse))
11452
11453 (defun gnus-summary-sort-by-random (&optional reverse)
11454   "Randomize the order in the summary buffer.
11455 Argument REVERSE means to randomize in reverse order."
11456   (interactive "P")
11457   (gnus-summary-sort 'random reverse))
11458
11459 (defun gnus-summary-sort-by-author (&optional reverse)
11460   "Sort the summary buffer by author name alphabetically.
11461 If `case-fold-search' is non-nil, case of letters is ignored.
11462 Argument REVERSE means reverse order."
11463   (interactive "P")
11464   (gnus-summary-sort 'author reverse))
11465
11466 (defun gnus-summary-sort-by-recipient (&optional reverse)
11467   "Sort the summary buffer by recipient name alphabetically.
11468 If `case-fold-search' is non-nil, case of letters is ignored.
11469 Argument REVERSE means reverse order."
11470   (interactive "P")
11471   (gnus-summary-sort 'recipient reverse))
11472
11473 (defun gnus-summary-sort-by-subject (&optional reverse)
11474   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11475 If `case-fold-search' is non-nil, case of letters is ignored.
11476 Argument REVERSE means reverse order."
11477   (interactive "P")
11478   (gnus-summary-sort 'subject reverse))
11479
11480 (defun gnus-summary-sort-by-date (&optional reverse)
11481   "Sort the summary buffer by date.
11482 Argument REVERSE means reverse order."
11483   (interactive "P")
11484   (gnus-summary-sort 'date reverse))
11485
11486 (defun gnus-summary-sort-by-score (&optional reverse)
11487   "Sort the summary buffer by score.
11488 Argument REVERSE means reverse order."
11489   (interactive "P")
11490   (gnus-summary-sort 'score reverse))
11491
11492 (defun gnus-summary-sort-by-lines (&optional reverse)
11493   "Sort the summary buffer by the number of lines.
11494 Argument REVERSE means reverse order."
11495   (interactive "P")
11496   (gnus-summary-sort 'lines reverse))
11497
11498 (defun gnus-summary-sort-by-chars (&optional reverse)
11499   "Sort the summary buffer by article length.
11500 Argument REVERSE means reverse order."
11501   (interactive "P")
11502   (gnus-summary-sort 'chars reverse))
11503
11504 (defun gnus-summary-sort-by-original (&optional reverse)
11505   "Sort the summary buffer using the default sorting method.
11506 Argument REVERSE means reverse order."
11507   (interactive "P")
11508   (let* ((inhibit-read-only t)
11509          (gnus-summary-prepare-hook nil))
11510     ;; We do the sorting by regenerating the threads.
11511     (gnus-summary-prepare)
11512     ;; Hide subthreads if needed.
11513     (gnus-summary-maybe-hide-threads)))
11514
11515 (defun gnus-summary-sort (predicate reverse)
11516   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11517   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11518          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11519          (gnus-thread-sort-functions
11520           (if (not reverse)
11521               thread
11522             `(lambda (t1 t2)
11523                (,thread t2 t1))))
11524          (gnus-sort-gathered-threads-function
11525           gnus-thread-sort-functions)
11526          (gnus-article-sort-functions
11527           (if (not reverse)
11528               article
11529             `(lambda (t1 t2)
11530                (,article t2 t1))))
11531          (inhibit-read-only t)
11532          (gnus-summary-prepare-hook nil))
11533     ;; We do the sorting by regenerating the threads.
11534     (gnus-summary-prepare)
11535     ;; Hide subthreads if needed.
11536     (gnus-summary-maybe-hide-threads)))
11537
11538 ;; Summary saving commands.
11539
11540 (defun gnus-summary-save-article (&optional n not-saved)
11541   "Save the current article using the default saver function.
11542 If N is a positive number, save the N next articles.
11543 If N is a negative number, save the N previous articles.
11544 If N is nil and any articles have been marked with the process mark,
11545 save those articles instead.
11546 The variable `gnus-default-article-saver' specifies the saver function.
11547
11548 If the optional second argument NOT-SAVED is non-nil, articles saved
11549 will not be marked as saved."
11550   (interactive "P")
11551   (require 'gnus-art)
11552   (let* ((articles (gnus-summary-work-articles n))
11553          (save-buffer (save-excursion
11554                         (nnheader-set-temp-buffer " *Gnus Save*")))
11555          (num (length articles))
11556          ;; Whether to save decoded articles or raw articles.
11557          (decode (when gnus-article-save-coding-system
11558                    (get gnus-default-article-saver :decode)))
11559          ;; When saving many articles in a single file, use the other
11560          ;; function to save articles other than the first one.
11561          (saver2 (get gnus-default-article-saver :function))
11562          (gnus-prompt-before-saving (if saver2
11563                                         t
11564                                       gnus-prompt-before-saving))
11565          (gnus-default-article-saver gnus-default-article-saver)
11566          header file)
11567     (dolist (article articles)
11568       (setq header (gnus-summary-article-header article))
11569       (if (not (vectorp header))
11570           ;; This is a pseudo-article.
11571           (if (assq 'name header)
11572               (gnus-copy-file (cdr (assq 'name header)))
11573             (gnus-message 1 "Article %d is unsaveable" article))
11574         ;; This is a real article.
11575         (save-window-excursion
11576           (let ((gnus-display-mime-function (when decode
11577                                               gnus-display-mime-function))
11578                 (gnus-article-prepare-hook (when decode
11579                                              gnus-article-prepare-hook)))
11580             (gnus-summary-select-article t nil nil article)
11581             (gnus-summary-goto-subject article)))
11582         (with-current-buffer save-buffer
11583           (erase-buffer)
11584           (insert-buffer-substring (if decode
11585                                        gnus-article-buffer
11586                                      gnus-original-article-buffer)))
11587         (setq file (gnus-article-save save-buffer file num))
11588         (gnus-summary-remove-process-mark article)
11589         (unless not-saved
11590           (gnus-summary-set-saved-mark article)))
11591       (when saver2
11592         (setq gnus-default-article-saver saver2
11593               saver2 nil)))
11594     (gnus-kill-buffer save-buffer)
11595     (gnus-summary-position-point)
11596     (gnus-set-mode-line 'summary)
11597     n))
11598
11599 (defun gnus-summary-pipe-output (&optional arg headers)
11600   "Pipe the current article to a subprocess.
11601 If N is a positive number, pipe the N next articles.
11602 If N is a negative number, pipe the N previous articles.
11603 If N is nil and any articles have been marked with the process mark,
11604 pipe those articles instead.
11605 If HEADERS (the symbolic prefix), include the headers, too."
11606   (interactive (gnus-interactive "P\ny"))
11607   (require 'gnus-art)
11608   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11609         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11610     (gnus-summary-save-article arg t))
11611   (let ((buffer (get-buffer "*Shell Command Output*")))
11612     (when (and buffer
11613                (not (zerop (buffer-size buffer))))
11614       (gnus-configure-windows 'pipe))))
11615
11616 (defun gnus-summary-save-article-mail (&optional arg)
11617   "Append the current article to a Unix mail box file.
11618 If N is a positive number, save the N next articles.
11619 If N is a negative number, save the N previous articles.
11620 If N is nil and any articles have been marked with the process mark,
11621 save those articles instead."
11622   (interactive "P")
11623   (require 'gnus-art)
11624   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11625     (gnus-summary-save-article arg)))
11626
11627 (defun gnus-summary-save-article-rmail (&optional arg)
11628   "Append the current article to an rmail file.
11629 If N is a positive number, save the N next articles.
11630 If N is a negative number, save the N previous articles.
11631 If N is nil and any articles have been marked with the process mark,
11632 save those articles instead."
11633   (interactive "P")
11634   (require 'gnus-art)
11635   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11636     (gnus-summary-save-article arg)))
11637
11638 (defun gnus-summary-save-article-file (&optional arg)
11639   "Append the current article to a file.
11640 If N is a positive number, save the N next articles.
11641 If N is a negative number, save the N previous articles.
11642 If N is nil and any articles have been marked with the process mark,
11643 save those articles instead."
11644   (interactive "P")
11645   (require 'gnus-art)
11646   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11647     (gnus-summary-save-article arg)))
11648
11649 (defun gnus-summary-write-article-file (&optional arg)
11650   "Write the current article to a file, deleting the previous file.
11651 If N is a positive number, save the N next articles.
11652 If N is a negative number, save the N previous articles.
11653 If N is nil and any articles have been marked with the process mark,
11654 save those articles instead."
11655   (interactive "P")
11656   (require 'gnus-art)
11657   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11658     (gnus-summary-save-article arg)))
11659
11660 (defun gnus-summary-save-article-body-file (&optional arg)
11661   "Append the current article body to a file.
11662 If N is a positive number, save the N next articles.
11663 If N is a negative number, save the N previous articles.
11664 If N is nil and any articles have been marked with the process mark,
11665 save those articles instead."
11666   (interactive "P")
11667   (require 'gnus-art)
11668   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11669     (gnus-summary-save-article arg)))
11670
11671 (defun gnus-summary-write-article-body-file (&optional arg)
11672   "Write the current article body to a file, deleting the previous file.
11673 If N is a positive number, save the N next articles.
11674 If N is a negative number, save the N previous articles.
11675 If N is nil and any articles have been marked with the process mark,
11676 save those articles instead."
11677   (interactive "P")
11678   (require 'gnus-art)
11679   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11680     (gnus-summary-save-article arg)))
11681
11682 (defun gnus-summary-muttprint (&optional arg)
11683   "Print the current article using Muttprint.
11684 If N is a positive number, save the N next articles.
11685 If N is a negative number, save the N previous articles.
11686 If N is nil and any articles have been marked with the process mark,
11687 save those articles instead."
11688   (interactive "P")
11689   (require 'gnus-art)
11690   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11691     (gnus-summary-save-article arg t)))
11692
11693 (defun gnus-summary-pipe-message (program)
11694   "Pipe the current article through PROGRAM."
11695   (interactive "sProgram: ")
11696   (gnus-summary-select-article)
11697   (let ((mail-header-separator ""))
11698     (gnus-eval-in-buffer-window gnus-article-buffer
11699       (save-restriction
11700         (widen)
11701         (let ((start (window-start))
11702               (inhibit-read-only t))
11703           (message-pipe-buffer-body program)
11704           (set-window-start (get-buffer-window (current-buffer)) start))))))
11705
11706 (defun gnus-get-split-value (methods)
11707   "Return a value based on the split METHODS."
11708   (let (split-name method result match)
11709     (when methods
11710       (with-current-buffer gnus-original-article-buffer
11711         (save-restriction
11712           (nnheader-narrow-to-headers)
11713           (while (and methods (not split-name))
11714             (goto-char (point-min))
11715             (setq method (pop methods))
11716             (setq match (car method))
11717             (when (cond
11718                    ((stringp match)
11719                     ;; Regular expression.
11720                     (ignore-errors
11721                       (re-search-forward match nil t)))
11722                    ((functionp match)
11723                     ;; Function.
11724                     (save-restriction
11725                       (widen)
11726                       (setq result (funcall match gnus-newsgroup-name))))
11727                    ((consp match)
11728                     ;; Form.
11729                     (save-restriction
11730                       (widen)
11731                       (setq result (eval match)))))
11732               (setq split-name (cdr method))
11733               (cond ((stringp result)
11734                      (push (expand-file-name
11735                             result gnus-article-save-directory)
11736                            split-name))
11737                     ((consp result)
11738                      (setq split-name (append result split-name)))))))))
11739     (nreverse split-name)))
11740
11741 (defun gnus-valid-move-group-p (group)
11742   (and (boundp group)
11743        (symbol-name group)
11744        (symbol-value group)
11745        (gnus-get-function (gnus-find-method-for-group
11746                            (symbol-name group)) 'request-accept-article t)))
11747
11748 (defun gnus-read-move-group-name (prompt default articles prefix)
11749   "Read a group name."
11750   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11751          (minibuffer-confirm-incomplete nil) ; XEmacs
11752          (prom
11753           (format "%s %s to"
11754                   prompt
11755                   (if (> (length articles) 1)
11756                       (format "these %d articles" (length articles))
11757                     "this article")))
11758          (to-newsgroup
11759           (let (active group)
11760             (when (or (null split-name) (= 1 (length split-name)))
11761               (setq active (gnus-make-hashtable (length gnus-active-hashtb)))
11762               (mapatoms (lambda (symbol)
11763                           (setq group (symbol-name symbol))
11764                           (when (string-match "[^\000-\177]" group)
11765                             (setq group (gnus-group-decoded-name group)))
11766                           (set (intern group active) group))
11767                         gnus-active-hashtb))
11768             (cond
11769              ((null split-name)
11770               (gnus-completing-read-with-default
11771                default prom active 'gnus-valid-move-group-p nil prefix
11772                'gnus-group-history))
11773              ((= 1 (length split-name))
11774               (gnus-completing-read-with-default
11775                (car split-name) prom active 'gnus-valid-move-group-p nil nil
11776                'gnus-group-history))
11777              (t
11778               (gnus-completing-read-with-default
11779                nil prom (mapcar 'list (nreverse split-name)) nil nil nil
11780                'gnus-group-history)))))
11781          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
11782          encoded)
11783     (when to-newsgroup
11784       (if (or (string= to-newsgroup "")
11785               (string= to-newsgroup prefix))
11786           (setq to-newsgroup default))
11787       (unless to-newsgroup
11788         (error "No group name entered"))
11789       (setq encoded (mm-encode-coding-string
11790                      to-newsgroup
11791                      (gnus-group-name-charset to-method to-newsgroup)))
11792       (or (gnus-active encoded)
11793           (gnus-activate-group encoded nil nil to-method)
11794           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11795                                      to-newsgroup))
11796               (or (and (gnus-request-create-group encoded to-method)
11797                        (gnus-activate-group encoded nil nil to-method)
11798                        (gnus-subscribe-group encoded))
11799                   (error "Couldn't create group %s" to-newsgroup)))
11800           (error "No such group: %s" to-newsgroup))
11801       encoded)))
11802
11803 (defvar gnus-summary-save-parts-counter)
11804 (declare-function mm-uu-dissect "mm-uu" (&optional noheader mime-type))
11805
11806 (defun gnus-summary-save-parts (type dir n &optional reverse)
11807   "Save parts matching TYPE to DIR.
11808 If REVERSE, save parts that do not match TYPE."
11809   (interactive
11810    (list (read-string "Save parts of type: "
11811                       (or (car gnus-summary-save-parts-type-history)
11812                           gnus-summary-save-parts-default-mime)
11813                       'gnus-summary-save-parts-type-history)
11814          (setq gnus-summary-save-parts-last-directory
11815                (read-file-name "Save to directory: "
11816                                gnus-summary-save-parts-last-directory
11817                                nil t))
11818          current-prefix-arg))
11819   (gnus-summary-iterate n
11820     (let ((gnus-display-mime-function nil)
11821           (gnus-inhibit-treatment t))
11822       (gnus-summary-select-article))
11823     (with-current-buffer gnus-article-buffer
11824       (let ((handles (or gnus-article-mime-handles
11825                          (mm-dissect-buffer nil gnus-article-loose-mime)
11826                          (and gnus-article-emulate-mime
11827                               (mm-uu-dissect))))
11828             (gnus-summary-save-parts-counter 1))
11829         (when handles
11830           (gnus-summary-save-parts-1 type dir handles reverse)
11831           (unless gnus-article-mime-handles ;; Don't destroy this case.
11832             (mm-destroy-parts handles)))))))
11833
11834 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11835   (if (stringp (car handle))
11836       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11837               (cdr handle))
11838     (when (if reverse
11839               (not (string-match type (mm-handle-media-type handle)))
11840             (string-match type (mm-handle-media-type handle)))
11841       (let ((file (expand-file-name
11842                    (gnus-map-function
11843                     mm-file-name-rewrite-functions
11844                     (file-name-nondirectory
11845                      (or
11846                       (mail-content-type-get
11847                        (mm-handle-disposition handle) 'filename)
11848                       (mail-content-type-get
11849                        (mm-handle-type handle) 'name)
11850                       (format "%s.%d.%d" gnus-newsgroup-name
11851                               (cdr gnus-article-current)
11852                               gnus-summary-save-parts-counter))))
11853                    dir)))
11854         (incf gnus-summary-save-parts-counter)
11855         (unless (file-exists-p file)
11856           (mm-save-part-to-file handle file))))))
11857
11858 ;; Summary extract commands
11859
11860 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11861   (let ((inhibit-read-only t)
11862         (article (gnus-summary-article-number))
11863         after-article b e)
11864     (unless (gnus-summary-goto-subject article)
11865       (error "No such article: %d" article))
11866     (gnus-summary-position-point)
11867     ;; If all commands are to be bunched up on one line, we collect
11868     ;; them here.
11869     (unless gnus-view-pseudos-separately
11870       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11871             files action)
11872         (while ps
11873           (setq action (cdr (assq 'action (car ps))))
11874           (setq files (list (cdr (assq 'name (car ps)))))
11875           (while (and ps (cdr ps)
11876                       (string= (or action "1")
11877                                (or (cdr (assq 'action (cadr ps))) "2")))
11878             (push (cdr (assq 'name (cadr ps))) files)
11879             (setcdr ps (cddr ps)))
11880           (when files
11881             (when (not (string-match "%s" action))
11882               (push " " files))
11883             (push " " files)
11884             (when (assq 'execute (car ps))
11885               (setcdr (assq 'execute (car ps))
11886                       (funcall (if (string-match "%s" action)
11887                                    'format 'concat)
11888                                action
11889                                (mapconcat
11890                                 (lambda (f)
11891                                   (if (equal f " ")
11892                                       f
11893                                     (shell-quote-argument f)))
11894                                 files " ")))))
11895           (setq ps (cdr ps)))))
11896     (if (and gnus-view-pseudos (not not-view))
11897         (while pslist
11898           (when (assq 'execute (car pslist))
11899             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11900                                   (eq gnus-view-pseudos 'not-confirm)))
11901           (setq pslist (cdr pslist)))
11902       (save-excursion
11903         (while pslist
11904           (setq after-article (or (cdr (assq 'article (car pslist)))
11905                                   (gnus-summary-article-number)))
11906           (gnus-summary-goto-subject after-article)
11907           (forward-line 1)
11908           (setq b (point))
11909           (insert "    " (file-name-nondirectory
11910                           (cdr (assq 'name (car pslist))))
11911                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11912           (setq e (point))
11913           (forward-line -1)             ; back to `b'
11914           (gnus-add-text-properties
11915            b (1- e) (list 'gnus-number gnus-reffed-article-number
11916                           gnus-mouse-face-prop gnus-mouse-face))
11917           (gnus-data-enter
11918            after-article gnus-reffed-article-number
11919            gnus-unread-mark b (car pslist) 0 (- e b))
11920           (setq gnus-newsgroup-unreads
11921                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11922                                          gnus-reffed-article-number))
11923           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11924           (setq pslist (cdr pslist)))))))
11925
11926 (defun gnus-pseudos< (p1 p2)
11927   (let ((c1 (cdr (assq 'action p1)))
11928         (c2 (cdr (assq 'action p2))))
11929     (and c1 c2 (string< c1 c2))))
11930
11931 (defun gnus-request-pseudo-article (props)
11932   (cond ((assq 'execute props)
11933          (gnus-execute-command (cdr (assq 'execute props)))))
11934   (let ((gnus-current-article (gnus-summary-article-number)))
11935     (gnus-run-hooks 'gnus-mark-article-hook)))
11936
11937 (defun gnus-execute-command (command &optional automatic)
11938   (save-excursion
11939     (gnus-article-setup-buffer)
11940     (set-buffer gnus-article-buffer)
11941     (setq buffer-read-only nil)
11942     (let ((command (if automatic command
11943                      (read-string "Command: " (cons command 0)))))
11944       (erase-buffer)
11945       (insert "$ " command "\n\n")
11946       (if gnus-view-pseudo-asynchronously
11947           (start-process "gnus-execute" (current-buffer) shell-file-name
11948                          shell-command-switch command)
11949         (call-process shell-file-name nil t nil
11950                       shell-command-switch command)))))
11951
11952 ;; Summary kill commands.
11953
11954 (defun gnus-summary-edit-global-kill (article)
11955   "Edit the \"global\" kill file."
11956   (interactive (list (gnus-summary-article-number)))
11957   (gnus-group-edit-global-kill article))
11958
11959 (defun gnus-summary-edit-local-kill ()
11960   "Edit a local kill file applied to the current newsgroup."
11961   (interactive)
11962   (setq gnus-current-headers (gnus-summary-article-header))
11963   (gnus-group-edit-local-kill
11964    (gnus-summary-article-number) gnus-newsgroup-name))
11965
11966 ;;; Header reading.
11967
11968 (defun gnus-read-header (id &optional header)
11969   "Read the headers of article ID and enter them into the Gnus system."
11970   (let ((group gnus-newsgroup-name)
11971         (gnus-override-method
11972          (or
11973           gnus-override-method
11974           (and (gnus-news-group-p gnus-newsgroup-name)
11975                (car (gnus-refer-article-methods)))))
11976         where)
11977     ;; First we check to see whether the header in question is already
11978     ;; fetched.
11979     (if (stringp id)
11980         ;; This is a Message-ID.
11981         (setq header (or header (gnus-id-to-header id)))
11982       ;; This is an article number.
11983       (setq header (or header (gnus-summary-article-header id))))
11984     (if (and header
11985              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11986         ;; We have found the header.
11987         header
11988       ;; We have to really fetch the header to this article.
11989       (with-current-buffer nntp-server-buffer
11990         (when (setq where (gnus-request-head id group))
11991           (nnheader-fold-continuation-lines)
11992           (goto-char (point-max))
11993           (insert ".\n")
11994           (goto-char (point-min))
11995           (insert "211 ")
11996           (princ (cond
11997                   ((numberp id) id)
11998                   ((cdr where) (cdr where))
11999                   (header (mail-header-number header))
12000                   (t gnus-reffed-article-number))
12001                  (current-buffer))
12002           (insert " Article retrieved.\n"))
12003         (if (or (not where)
12004                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
12005             ()                          ; Malformed head.
12006           (unless (gnus-summary-article-sparse-p (mail-header-number header))
12007             (when (and (stringp id)
12008                        (or
12009                         (not (string= (gnus-group-real-name group)
12010                                       (car where)))
12011                         (not (gnus-server-equal gnus-override-method
12012                                                 (gnus-group-method group)))))
12013               ;; If we fetched by Message-ID and the article came from
12014               ;; a different group (or server), we fudge some bogus
12015               ;; article numbers for this article.
12016               (mail-header-set-number header gnus-reffed-article-number))
12017             (with-current-buffer gnus-summary-buffer
12018               (decf gnus-reffed-article-number)
12019               (gnus-remove-header (mail-header-number header))
12020               (push header gnus-newsgroup-headers)
12021               (setq gnus-current-headers header)
12022               (push (mail-header-number header) gnus-newsgroup-limit)))
12023           header)))))
12024
12025 (defun gnus-remove-header (number)
12026   "Remove header NUMBER from `gnus-newsgroup-headers'."
12027   (if (and gnus-newsgroup-headers
12028            (= number (mail-header-number (car gnus-newsgroup-headers))))
12029       (pop gnus-newsgroup-headers)
12030     (let ((headers gnus-newsgroup-headers))
12031       (while (and (cdr headers)
12032                   (not (= number (mail-header-number (cadr headers)))))
12033         (pop headers))
12034       (when (cdr headers)
12035         (setcdr headers (cddr headers))))))
12036
12037 ;;;
12038 ;;; summary highlights
12039 ;;;
12040
12041 (defun gnus-highlight-selected-summary ()
12042   "Highlight selected article in summary buffer."
12043   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12044   (when gnus-summary-selected-face
12045     (save-excursion
12046       (let* ((beg (point-at-bol))
12047              (end (point-at-eol))
12048              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12049              (from (if (get-text-property beg gnus-mouse-face-prop)
12050                        beg
12051                      (or (next-single-property-change
12052                           beg gnus-mouse-face-prop nil end)
12053                          beg)))
12054              (to
12055               (if (= from end)
12056                   (- from 2)
12057                 (or (next-single-property-change
12058                      from gnus-mouse-face-prop nil end)
12059                     end))))
12060         ;; If no mouse-face prop on line we will have to = from = end,
12061         ;; so we highlight the entire line instead.
12062         (when (= (+ to 2) from)
12063           (setq from beg)
12064           (setq to end))
12065         (if gnus-newsgroup-selected-overlay
12066             ;; Move old overlay.
12067             (gnus-move-overlay
12068              gnus-newsgroup-selected-overlay from to (current-buffer))
12069           ;; Create new overlay.
12070           (gnus-overlay-put
12071            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12072            'face gnus-summary-selected-face))))))
12073
12074 (defvar gnus-summary-highlight-line-cached nil)
12075 (defvar gnus-summary-highlight-line-trigger nil)
12076
12077 (defun gnus-summary-highlight-line-0 ()
12078   (if (and (eq gnus-summary-highlight-line-trigger
12079                gnus-summary-highlight)
12080            gnus-summary-highlight-line-cached)
12081       gnus-summary-highlight-line-cached
12082     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12083           gnus-summary-highlight-line-cached
12084           (let* ((cond (list 'cond))
12085                  (c cond)
12086                  (list gnus-summary-highlight))
12087             (while list
12088               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12089                               nil))
12090               (setq c (cdr c)
12091                     list (cdr list)))
12092             (gnus-byte-compile (list 'lambda nil cond))))))
12093
12094 (defun gnus-summary-highlight-line ()
12095   "Highlight current line according to `gnus-summary-highlight'."
12096   (let* ((beg (point-at-bol))
12097          (article (or (gnus-summary-article-number) gnus-current-article))
12098          (score (or (cdr (assq article
12099                                gnus-newsgroup-scored))
12100                     gnus-summary-default-score 0))
12101          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12102          (inhibit-read-only t)
12103          (default gnus-summary-default-score)
12104          (default-high gnus-summary-default-high-score)
12105          (default-low gnus-summary-default-low-score)
12106          (uncached (and gnus-summary-use-undownloaded-faces
12107                         (memq article gnus-newsgroup-undownloaded)
12108                         (not (memq article gnus-newsgroup-cached)))))
12109     (let ((face (funcall (gnus-summary-highlight-line-0))))
12110       (unless (eq face (get-text-property beg 'face))
12111         (gnus-put-text-property-excluding-characters-with-faces
12112          beg (point-at-eol) 'face
12113          (setq face (if (boundp face) (symbol-value face) face)))
12114         (when gnus-summary-highlight-line-function
12115           (funcall gnus-summary-highlight-line-function article face))))))
12116
12117 (defun gnus-update-read-articles (group unread &optional compute)
12118   "Update the list of read articles in GROUP.
12119 UNREAD is a sorted list."
12120   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12121         (info (gnus-get-info group))
12122         (prev 1)
12123         read)
12124     (if (or (not info) (not active))
12125         ;; There is no info on this group if it was, in fact,
12126         ;; killed.  Gnus stores no information on killed groups, so
12127         ;; there's nothing to be done.
12128         ;; One could store the information somewhere temporarily,
12129         ;; perhaps...  Hmmm...
12130         ()
12131       ;; Remove any negative articles numbers.
12132       (while (and unread (< (car unread) 0))
12133         (setq unread (cdr unread)))
12134       ;; Remove any expired article numbers
12135       (while (and unread (< (car unread) (car active)))
12136         (setq unread (cdr unread)))
12137       ;; Compute the ranges of read articles by looking at the list of
12138       ;; unread articles.
12139       (while unread
12140         (when (/= (car unread) prev)
12141           (push (if (= prev (1- (car unread))) prev
12142                   (cons prev (1- (car unread))))
12143                 read))
12144         (setq prev (1+ (car unread)))
12145         (setq unread (cdr unread)))
12146       (when (<= prev (cdr active))
12147         (push (cons prev (cdr active)) read))
12148       (setq read (if (> (length read) 1) (nreverse read) read))
12149       (if compute
12150           read
12151         (save-excursion
12152           (let (setmarkundo)
12153             ;; Propagate the read marks to the backend.
12154             (when (gnus-check-backend-function 'request-set-mark group)
12155               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12156                     (add (gnus-remove-from-range read (gnus-info-read info))))
12157                 (when (or add del)
12158                   (unless (gnus-check-group group)
12159                     (error "Can't open server for %s" group))
12160                   (gnus-request-set-mark
12161                    group (delq nil (list (if add (list add 'add '(read)))
12162                                          (if del (list del 'del '(read))))))
12163                   (setq setmarkundo
12164                         `(gnus-request-set-mark
12165                           ,group
12166                           ',(delq nil (list
12167                                        (if del (list del 'add '(read)))
12168                                        (if add (list add 'del '(read))))))))))
12169             (set-buffer gnus-group-buffer)
12170             (gnus-undo-register
12171               `(progn
12172                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12173                  (gnus-info-set-read ',info ',(gnus-info-read info))
12174                  (gnus-get-unread-articles-in-group ',info
12175                                                     (gnus-active ,group))
12176                  (gnus-group-update-group ,group t)
12177                  ,setmarkundo))))
12178         ;; Enter this list into the group info.
12179         (gnus-info-set-read info read)
12180         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12181         (gnus-get-unread-articles-in-group info (gnus-active group))
12182         t))))
12183
12184 (defun gnus-offer-save-summaries ()
12185   "Offer to save all active summary buffers."
12186   (let (buffers)
12187     ;; Go through all buffers and find all summaries.
12188     (dolist (buffer (buffer-list))
12189       (when (and (setq buffer (buffer-name buffer))
12190                  (string-match "Summary" buffer)
12191                  (with-current-buffer buffer
12192                    ;; We check that this is, indeed, a summary buffer.
12193                    (and (eq major-mode 'gnus-summary-mode)
12194                         ;; Also make sure this isn't bogus.
12195                         gnus-newsgroup-prepared
12196                         ;; Also make sure that this isn't a
12197                         ;; dead summary buffer.
12198                         (not gnus-dead-summary-mode))))
12199         (push buffer buffers)))
12200     ;; Go through all these summary buffers and offer to save them.
12201     (when buffers
12202       (save-excursion
12203         (map-y-or-n-p
12204          "Update summary buffer %s? "
12205          (lambda (buf)
12206            (switch-to-buffer buf)
12207            (gnus-summary-exit))
12208          buffers)))))
12209
12210 (defun gnus-summary-setup-default-charset ()
12211   "Setup newsgroup default charset."
12212   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12213       (setq gnus-newsgroup-charset nil)
12214     (let* ((ignored-charsets
12215             (or gnus-newsgroup-ephemeral-ignored-charsets
12216                 (append
12217                  (and gnus-newsgroup-name
12218                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12219                  gnus-newsgroup-ignored-charsets))))
12220       (setq gnus-newsgroup-charset
12221             (or gnus-newsgroup-ephemeral-charset
12222                 (and gnus-newsgroup-name
12223                      (gnus-parameter-charset gnus-newsgroup-name))
12224                 gnus-default-charset))
12225       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12226            ignored-charsets))))
12227
12228 ;;;
12229 ;;; Mime Commands
12230 ;;;
12231
12232 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12233   "Display the current article buffer fully MIME-buttonized.
12234 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12235 treated as multipart/mixed."
12236   (interactive "P")
12237   (require 'gnus-art)
12238   (let ((gnus-unbuttonized-mime-types nil)
12239         (gnus-mime-display-multipart-as-mixed show-all-parts))
12240     (gnus-summary-show-article)))
12241
12242 (defun gnus-summary-repair-multipart (article)
12243   "Add a Content-Type header to a multipart article without one."
12244   (interactive (list (gnus-summary-article-number)))
12245   (gnus-with-article article
12246     (message-narrow-to-head)
12247     (message-remove-header "Mime-Version")
12248     (goto-char (point-max))
12249     (insert "Mime-Version: 1.0\n")
12250     (widen)
12251     (when (search-forward "\n--" nil t)
12252       (let ((separator (buffer-substring (point) (point-at-eol))))
12253         (message-narrow-to-head)
12254         (message-remove-header "Content-Type")
12255         (goto-char (point-max))
12256         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12257                         separator))
12258         (widen))))
12259   (let (gnus-mark-article-hook)
12260     (gnus-summary-select-article t t nil article)))
12261
12262 (defun gnus-summary-toggle-display-buttonized ()
12263   "Toggle the buttonizing of the article buffer."
12264   (interactive)
12265   (require 'gnus-art)
12266   (if (setq gnus-inhibit-mime-unbuttonizing
12267             (not gnus-inhibit-mime-unbuttonizing))
12268       (let ((gnus-unbuttonized-mime-types nil))
12269         (gnus-summary-show-article))
12270     (gnus-summary-show-article)))
12271
12272 ;;;
12273 ;;; Generic summary marking commands
12274 ;;;
12275
12276 (defvar gnus-summary-marking-alist
12277   '((read gnus-del-mark "d")
12278     (unread gnus-unread-mark "u")
12279     (ticked gnus-ticked-mark "!")
12280     (dormant gnus-dormant-mark "?")
12281     (expirable gnus-expirable-mark "e"))
12282   "An alist of names/marks/keystrokes.")
12283
12284 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12285 (defvar gnus-summary-mark-map)
12286
12287 (defun gnus-summary-make-all-marking-commands ()
12288   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12289   (dolist (elem gnus-summary-marking-alist)
12290     (apply 'gnus-summary-make-marking-command elem)))
12291
12292 (defun gnus-summary-make-marking-command (name mark keystroke)
12293   (let ((map (make-sparse-keymap)))
12294     (define-key gnus-summary-generic-mark-map keystroke map)
12295     (dolist (lway `((next "next" next nil "n")
12296                     (next-unread "next unread" next t "N")
12297                     (prev "previous" prev nil "p")
12298                     (prev-unread "previous unread" prev t "P")
12299                     (nomove "" nil nil ,keystroke)))
12300       (let ((func (gnus-summary-make-marking-command-1
12301                    mark (car lway) lway name)))
12302         (setq func (eval func))
12303         (define-key map (nth 4 lway) func)))))
12304
12305 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12306   `(defun ,(intern
12307             (format "gnus-summary-put-mark-as-%s%s"
12308                     name (if (eq way 'nomove)
12309                              ""
12310                            (concat "-" (symbol-name way)))))
12311      (n)
12312      ,(format
12313        "Mark the current article as %s%s.
12314 If N, the prefix, then repeat N times.
12315 If N is negative, move in reverse order.
12316 The difference between N and the actual number of articles marked is
12317 returned."
12318        name (cadr lway))
12319      (interactive "p")
12320      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12321
12322 (defun gnus-summary-generic-mark (n mark move unread)
12323   "Mark N articles with MARK."
12324   (unless (eq major-mode 'gnus-summary-mode)
12325     (error "This command can only be used in the summary buffer"))
12326   (gnus-summary-show-thread)
12327   (let ((nummove
12328          (cond
12329           ((eq move 'next) 1)
12330           ((eq move 'prev) -1)
12331           (t 0))))
12332     (if (zerop nummove)
12333         (setq n 1)
12334       (when (< n 0)
12335         (setq n (abs n)
12336               nummove (* -1 nummove))))
12337     (while (and (> n 0)
12338                 (gnus-summary-mark-article nil mark)
12339                 (zerop (gnus-summary-next-subject nummove unread t)))
12340       (setq n (1- n)))
12341     (when (/= 0 n)
12342       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12343     (gnus-summary-recenter)
12344     (gnus-summary-position-point)
12345     (gnus-set-mode-line 'summary)
12346     n))
12347
12348 (defun gnus-summary-insert-articles (articles)
12349   (when (setq articles
12350               (gnus-sorted-difference articles
12351                                       (mapcar (lambda (h)
12352                                                 (mail-header-number h))
12353                                               gnus-newsgroup-headers)))
12354     (setq gnus-newsgroup-headers
12355           (gnus-merge 'list
12356                       gnus-newsgroup-headers
12357                       (gnus-fetch-headers articles)
12358                       'gnus-article-sort-by-number))
12359     ;; Suppress duplicates?
12360     (when gnus-suppress-duplicates
12361       (gnus-dup-suppress-articles))
12362
12363     (if (and gnus-fetch-old-headers
12364              (eq gnus-headers-retrieved-by 'nov))
12365         ;; We might want to build some more threads first.
12366         (if (eq gnus-fetch-old-headers 'invisible)
12367             (gnus-build-all-threads)
12368           (gnus-build-old-threads))
12369       ;; Mark the inserted articles that are unread as unread.
12370       (setq gnus-newsgroup-unreads
12371             (gnus-sorted-nunion
12372              gnus-newsgroup-unreads
12373              (gnus-sorted-nintersection
12374               (gnus-list-of-unread-articles gnus-newsgroup-name)
12375               articles)))
12376       ;; Mark the inserted articles as selected so that the information
12377       ;; of the marks having been changed by a user may be updated when
12378       ;; exiting this group.  See `gnus-summary-update-info'.
12379       (dolist (art articles)
12380         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12381     ;; Let the Gnus agent mark articles as read.
12382     (when gnus-agent
12383       (gnus-agent-get-undownloaded-list))
12384     ;; Remove list identifiers from subject
12385     (when gnus-list-identifiers
12386       (gnus-summary-remove-list-identifiers))
12387     ;; First and last article in this newsgroup.
12388     (when gnus-newsgroup-headers
12389       (setq gnus-newsgroup-begin
12390             (mail-header-number (car gnus-newsgroup-headers))
12391             gnus-newsgroup-end
12392             (mail-header-number
12393              (gnus-last-element gnus-newsgroup-headers))))
12394     (when gnus-use-scoring
12395       (gnus-possibly-score-headers))))
12396
12397 (defun gnus-summary-insert-old-articles (&optional all)
12398   "Insert all old articles in this group.
12399 If ALL is non-nil, already read articles become readable.
12400 If ALL is a number, fetch this number of articles."
12401   (interactive "P")
12402   (prog1
12403       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12404             older len)
12405         (setq older
12406               ;; Some nntp servers lie about their active range.  When
12407               ;; this happens, the active range can be in the millions.
12408               ;; Use a compressed range to avoid creating a huge list.
12409               (gnus-range-difference (list gnus-newsgroup-active) old))
12410         (setq len (gnus-range-length older))
12411         (cond
12412          ((null older) nil)
12413          ((numberp all)
12414           (if (< all len)
12415               (let ((older-range (nreverse older)))
12416                 (setq older nil)
12417
12418                 (while (> all 0)
12419                   (let* ((r (pop older-range))
12420                          (min (if (numberp r) r (car r)))
12421                          (max (if (numberp r) r (cdr r))))
12422                     (while (and (<= min max)
12423                                 (> all 0))
12424                       (push max older)
12425                       (setq all (1- all)
12426                             max (1- max))))))
12427             (setq older (gnus-uncompress-range older))))
12428          (all
12429           (setq older (gnus-uncompress-range older)))
12430          (t
12431           (when (and (numberp gnus-large-newsgroup)
12432                    (> len gnus-large-newsgroup))
12433               (let* ((cursor-in-echo-area nil)
12434                      (initial (gnus-parameter-large-newsgroup-initial
12435                                gnus-newsgroup-name))
12436                      (input
12437                       (read-string
12438                        (format
12439                         "How many articles from %s (%s %d): "
12440                         (gnus-group-decoded-name gnus-newsgroup-name)
12441                         (if initial "max" "default")
12442                         len)
12443                        (if initial
12444                            (cons (number-to-string initial)
12445                                  0)))))
12446                 (unless (string-match "^[ \t]*$" input)
12447                   (setq all (string-to-number input))
12448                   (if (< all len)
12449                       (let ((older-range (nreverse older)))
12450                         (setq older nil)
12451
12452                         (while (> all 0)
12453                           (let* ((r (pop older-range))
12454                                  (min (if (numberp r) r (car r)))
12455                                  (max (if (numberp r) r (cdr r))))
12456                             (while (and (<= min max)
12457                                         (> all 0))
12458                               (push max older)
12459                               (setq all (1- all)
12460                                     max (1- max))))))))))
12461           (setq older (gnus-uncompress-range older))))
12462         (if (not older)
12463             (message "No old news.")
12464           (gnus-summary-insert-articles older)
12465           (gnus-summary-limit (gnus-sorted-nunion old older))))
12466     (gnus-summary-position-point)))
12467
12468 (defun gnus-summary-insert-new-articles ()
12469   "Insert all new articles in this group."
12470   (interactive)
12471   (prog1
12472       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12473             (old-active gnus-newsgroup-active)
12474             (nnmail-fetched-sources (list t))
12475             i new)
12476         (setq gnus-newsgroup-active
12477               (gnus-activate-group gnus-newsgroup-name 'scan))
12478         (setq i (cdr gnus-newsgroup-active))
12479         (while (> i (cdr old-active))
12480           (push i new)
12481           (decf i))
12482         (if (not new)
12483             (message "No gnus is bad news")
12484           (gnus-summary-insert-articles new)
12485           (setq gnus-newsgroup-unreads
12486                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12487           (gnus-summary-limit (gnus-sorted-nunion old new))))
12488     (gnus-summary-position-point)))
12489
12490 (gnus-summary-make-all-marking-commands)
12491
12492 (gnus-ems-redefine)
12493
12494 (provide 'gnus-sum)
12495
12496 (run-hooks 'gnus-sum-load-hook)
12497
12498 ;; Local Variables:
12499 ;; coding: iso-8859-1
12500 ;; End:
12501
12502 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12503 ;;; gnus-sum.el ends here