Debbugs group entry fixups
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996-2013 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 ;; For Emacs <22.2 and XEmacs.
28 (eval-and-compile
29   (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
30 (eval-when-compile
31   (require 'cl))
32 (eval-when-compile
33   (when (featurep 'xemacs)
34     (require 'easy-mmode))) ; for `define-minor-mode'
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 (autoload 'nnir-article-rsv "nnir" nil nil 'macro)
63 (autoload 'nnir-article-group "nnir" nil nil 'macro)
64
65 (defcustom gnus-kill-summary-on-exit t
66   "*If non-nil, kill the summary buffer when you exit from it.
67 If nil, the summary will become a \"*Dead Summary*\" buffer, and
68 it will be killed sometime later."
69   :group 'gnus-summary-exit
70   :type 'boolean)
71
72 (defcustom gnus-summary-next-group-on-exit t
73   "If non-nil, go to the next unread newsgroup on summary exit.
74 See `gnus-group-goto-unread'."
75   :link '(custom-manual "(gnus)Group Maneuvering")
76   :group 'gnus-summary-exit
77   :version "23.1" ;; No Gnus
78   :type 'boolean)
79
80 (defcustom gnus-summary-stop-at-end-of-message nil
81   "If non-nil, don't select the next message when using `SPC'."
82   :link '(custom-manual "(gnus)Group Maneuvering")
83   :group 'gnus-summary-maneuvering
84   :version "24.1"
85   :type 'boolean)
86
87 (defcustom gnus-fetch-old-headers nil
88   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
89 If an unread article in the group refers to an older, already
90 read (or just marked as read) article, the old article will not
91 normally be displayed in the Summary buffer.  If this variable is
92 t, Gnus will attempt to grab the headers to the old articles, and
93 thereby build complete threads.  If it has the value `some', all
94 old headers will be fetched but only enough headers to connect
95 otherwise loose threads will be displayed.  This variable can
96 also be a number.  In that case, no more than that number of old
97 headers will be fetched.  If it has the value `invisible', all
98 old headers will be fetched, but none will be displayed.
99
100 The server has to support NOV for any of this to work.
101
102 This feature can seriously impact performance it ignores all
103 locally cached header entries.  Setting it to t for groups for a
104 server that doesn't expire articles (such as news.gmane.org),
105 leads to very slow summary generation."
106   :group 'gnus-thread
107   :type '(choice (const :tag "off" nil)
108                  (const :tag "on" t)
109                  (const some)
110                  (const invisible)
111                  number
112                  (sexp :menu-tag "other" t)))
113
114 (defcustom gnus-refer-thread-limit 500
115   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
116 If t, fetch all the available old headers."
117   :group 'gnus-thread
118   :type '(choice number
119                  (sexp :menu-tag "other" t)))
120
121 (defcustom gnus-refer-thread-use-nnir nil
122   "*Use nnir to search an entire server when referring threads. A
123 nil value will only search for thread-related articles in the
124 current group."
125   :version "24.1"
126   :group 'gnus-thread
127   :type 'boolean)
128
129 (defcustom gnus-summary-make-false-root 'adopt
130   "*nil means that Gnus won't gather loose threads.
131 If the root of a thread has expired or been read in a previous
132 session, the information necessary to build a complete thread has been
133 lost.  Instead of having many small sub-threads from this original thread
134 scattered all over the summary buffer, Gnus can gather them.
135
136 If non-nil, Gnus will try to gather all loose sub-threads from an
137 original thread into one large thread.
138
139 If this variable is non-nil, it should be one of `none', `adopt',
140 `dummy' or `empty'.
141
142 If this variable is `none', Gnus will not make a false root, but just
143 present the sub-threads after another.
144 If this variable is `dummy', Gnus will create a dummy root that will
145 have all the sub-threads as children.
146 If this variable is `adopt', Gnus will make one of the \"children\"
147 the parent and mark all the step-children as such.
148 If this variable is `empty', the \"children\" are printed with empty
149 subject fields.  (Or rather, they will be printed with a string
150 given by the `gnus-summary-same-subject' variable.)"
151   :group 'gnus-thread
152   :type '(choice (const :tag "off" nil)
153                  (const none)
154                  (const dummy)
155                  (const adopt)
156                  (const empty)))
157
158 (defcustom gnus-summary-make-false-root-always nil
159   "Always make a false dummy root."
160   :version "22.1"
161   :group 'gnus-thread
162   :type 'boolean)
163
164 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
165   "*A regexp to match subjects to be excluded from loose thread gathering.
166 As loose thread gathering is done on subjects only, that means that
167 there can be many false gatherings performed.  By rooting out certain
168 common subjects, gathering might become saner."
169   :group 'gnus-thread
170   :type 'regexp)
171
172 (defcustom gnus-summary-gather-subject-limit nil
173   "*Maximum length of subject comparisons when gathering loose threads.
174 Use nil to compare full subjects.  Setting this variable to a low
175 number will help gather threads that have been corrupted by
176 newsreaders chopping off subject lines, but it might also mean that
177 unrelated articles that have subject that happen to begin with the
178 same few characters will be incorrectly gathered.
179
180 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
181 comparing subjects."
182   :group 'gnus-thread
183   :type '(choice (const :tag "off" nil)
184                  (const fuzzy)
185                  (sexp :menu-tag "on" t)))
186
187 (defcustom gnus-simplify-subject-functions nil
188   "List of functions taking a string argument that simplify subjects.
189 The functions are applied recursively.
190
191 Useful functions to put in this list include:
192 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
193 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
194   :group 'gnus-thread
195   :type '(repeat function))
196
197 (defcustom gnus-simplify-ignored-prefixes nil
198   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
199   :group 'gnus-thread
200   :type '(choice (const :tag "off" nil)
201                  regexp))
202
203 (defcustom gnus-build-sparse-threads nil
204   "*If non-nil, fill in the gaps in threads.
205 If `some', only fill in the gaps that are needed to tie loose threads
206 together.  If `more', fill in all leaf nodes that Gnus can find.  If
207 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
208   :group 'gnus-thread
209   :type '(choice (const :tag "off" nil)
210                  (const some)
211                  (const more)
212                  (sexp :menu-tag "all" t)))
213
214 (defcustom gnus-summary-thread-gathering-function
215   'gnus-gather-threads-by-subject
216   "*Function used for gathering loose threads.
217 There are two pre-defined functions: `gnus-gather-threads-by-subject',
218 which only takes Subjects into consideration; and
219 `gnus-gather-threads-by-references', which compared the References
220 headers of the articles to find matches."
221   :group 'gnus-thread
222   :type '(radio (function-item gnus-gather-threads-by-subject)
223                 (function-item gnus-gather-threads-by-references)
224                 (function :tag "other")))
225
226 (defcustom gnus-summary-same-subject ""
227   "*String indicating that the current article has the same subject as the previous.
228 This variable will only be used if the value of
229 `gnus-summary-make-false-root' is `empty'."
230   :group 'gnus-summary-format
231   :type 'string)
232
233 (defcustom gnus-summary-goto-unread nil
234   "*If t, many commands will go to the next unread article.
235 This applies to marking commands as well as other commands that
236 \"naturally\" select the next article, like, for instance, `SPC' at
237 the end of an article.
238
239 If nil, the marking commands do NOT go to the next unread article
240 \(they go to the next article instead).  If `never', commands that
241 usually go to the next unread article, will go to the next article,
242 whether it is read or not."
243   :version "24.1"
244   :group 'gnus-summary-marks
245   :link '(custom-manual "(gnus)Setting Marks")
246   :type '(choice (const :tag "off" nil)
247                  (const never)
248                  (sexp :menu-tag "on" t)))
249
250 (defcustom gnus-summary-default-score 0
251   "*Default article score level.
252 All scores generated by the score files will be added to this score.
253 If this variable is nil, scoring will be disabled."
254   :group 'gnus-score-default
255   :type '(choice (const :tag "disable")
256                  integer))
257
258 (defcustom gnus-summary-default-high-score 0
259   "*Default threshold for a high scored article.
260 An article will be highlighted as high scored if its score is greater
261 than this score."
262   :version "22.1"
263   :group 'gnus-score-default
264   :type 'integer)
265
266 (defcustom gnus-summary-default-low-score 0
267   "*Default threshold for a low scored article.
268 An article will be highlighted as low scored if its score is smaller
269 than this score."
270   :version "22.1"
271   :group 'gnus-score-default
272   :type 'integer)
273
274 (defcustom gnus-summary-zcore-fuzz 0
275   "*Fuzziness factor for the zcore in the summary buffer.
276 Articles with scores closer than this to `gnus-summary-default-score'
277 will not be marked."
278   :group 'gnus-summary-format
279   :type 'integer)
280
281 (defcustom gnus-simplify-subject-fuzzy-regexp nil
282   "*Strings to be removed when doing fuzzy matches.
283 This can either be a regular expression or list of regular expressions
284 that will be removed from subject strings if fuzzy subject
285 simplification is selected."
286   :group 'gnus-thread
287   :type '(repeat regexp))
288
289 (defcustom gnus-show-threads t
290   "*If non-nil, display threads in summary mode."
291   :group 'gnus-thread
292   :type 'boolean)
293
294 (defcustom gnus-thread-hide-subtree nil
295   "*If non-nil, hide all threads initially.
296 This can be a predicate specifier which says which threads to hide.
297 If threads are hidden, you have to run the command
298 `gnus-summary-show-thread' by hand or select an article."
299   :group 'gnus-thread
300   :type '(radio (sexp :format "Non-nil\n"
301                       :match (lambda (widget value)
302                                (not (or (consp value) (functionp value))))
303                       :value t)
304                 (const nil)
305                 (sexp :tag "Predicate specifier")))
306
307 (defcustom gnus-thread-hide-killed t
308   "*If non-nil, hide killed threads automatically."
309   :group 'gnus-thread
310   :type 'boolean)
311
312 (defcustom gnus-thread-ignore-subject t
313   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
314 If nil, articles that have different subjects from their parents will
315 start separate threads."
316   :group 'gnus-thread
317   :type 'boolean)
318
319 (defcustom gnus-thread-operation-ignore-subject t
320   "*If non-nil, subjects will be ignored when doing thread commands.
321 This affects commands like `gnus-summary-kill-thread' and
322 `gnus-summary-lower-thread'.
323
324 If this variable is nil, articles in the same thread with different
325 subjects will not be included in the operation in question.  If this
326 variable is `fuzzy', only articles that have subjects that are fuzzily
327 equal will be included."
328   :group 'gnus-thread
329   :type '(choice (const :tag "off" nil)
330                  (const fuzzy)
331                  (sexp :tag "on" t)))
332
333 (defcustom gnus-thread-indent-level 4
334   "*Number that says how much each sub-thread should be indented."
335   :group 'gnus-thread
336   :type 'integer)
337
338 (defcustom gnus-auto-extend-newsgroup t
339   "*If non-nil, extend newsgroup forward and backward when requested."
340   :group 'gnus-summary-choose
341   :type 'boolean)
342
343 (defcustom gnus-auto-select-first t
344   "If non-nil, select an article on group entry.
345 An article is selected automatically when entering a group
346 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
347 `gnus-summary-catchup-and-goto-next-group'.
348
349 Which article is selected is controlled by the variable
350 `gnus-auto-select-subject'.
351
352 If you want to prevent automatic selection of articles in some
353 newsgroups, set the variable to nil in `gnus-select-group-hook'."
354   ;; Commands include...
355   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
356   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
357   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
358   :group 'gnus-group-select
359   :type '(choice (const :tag "none" nil)
360                  (sexp :menu-tag "first" t)))
361
362 (defcustom gnus-auto-select-subject 'unseen-or-unread
363   "*Says what subject to place under point when entering a group.
364
365 This variable can either be the symbols `first' (place point on the
366 first subject), `unread' (place point on the subject line of the first
367 unread article), `best' (place point on the subject line of the
368 highest-scored article), `unseen' (place point on the subject line of
369 the first unseen article), `unseen-or-unread' (place point on the subject
370 line of the first unseen article or, if all articles have been seen, on the
371 subject line of the first unread article), or a function to be called to
372 place point on some subject line."
373   :version "24.1"
374   :group 'gnus-group-select
375   :type '(choice (const best)
376                  (const unread)
377                  (const first)
378                  (const unseen)
379                  (const unseen-or-unread)
380                  (function :tag "Function to call")))
381
382 (defcustom gnus-auto-select-next t
383   "*If non-nil, offer to go to the next group from the end of the previous.
384 If the value is t and the next newsgroup is empty, Gnus will exit
385 summary mode and go back to group mode.  If the value is neither nil
386 nor t, Gnus will select the following unread newsgroup.  In
387 particular, if the value is the symbol `quietly', the next unread
388 newsgroup will be selected without any confirmation, and if it is
389 `almost-quietly', the next group will be selected without any
390 confirmation if you are located on the last article in the group.
391 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
392 will go to the next group without confirmation."
393   :group 'gnus-summary-maneuvering
394   :type '(choice (const :tag "off" nil)
395                  (const quietly)
396                  (const almost-quietly)
397                  (const slightly-quietly)
398                  (sexp :menu-tag "on" t)))
399
400 (defcustom gnus-auto-select-same nil
401   "*If non-nil, select the next article with the same subject.
402 If there are no more articles with the same subject, go to
403 the first unread article."
404   :group 'gnus-summary-maneuvering
405   :type 'boolean)
406
407 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
408   "What article should be selected after exiting an ephemeral group.
409 Valid values include:
410
411 `next'
412   Select the next article.
413 `next-unread'
414   Select the next unread article.
415 `next-noselect'
416   Move the cursor to the next article.  This is the default.
417 `next-unread-noselect'
418   Move the cursor to the next unread article.
419
420 If it has any other value or there is no next (unread) article, the
421 article selected before entering to the ephemeral group will appear."
422   :version "23.1" ;; No Gnus
423   :group 'gnus-summary-maneuvering
424   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
425                  (const next) (const next-unread)
426                  (const next-noselect) (const next-unread-noselect)
427                  (sexp :tag "other" :value nil)))
428
429 (defcustom gnus-auto-goto-ignores 'unfetched
430   "*Says how to handle unfetched articles when maneuvering.
431
432 This variable can either be the symbols nil (maneuver to any
433 article), `undownloaded' (maneuvering while unplugged ignores articles
434 that have not been fetched), `always-undownloaded' (maneuvering always
435 ignores articles that have not been fetched), `unfetched' (maneuvering
436 ignores articles whose headers have not been fetched).
437
438 NOTE: The list of unfetched articles will always be nil when plugged
439 and, when unplugged, a subset of the undownloaded article list."
440   :version "22.1"
441   :group 'gnus-summary-maneuvering
442   :type '(choice (const :tag "None" nil)
443                  (const :tag "Undownloaded when unplugged" undownloaded)
444                  (const :tag "Undownloaded" always-undownloaded)
445                  (const :tag "Unfetched" unfetched)))
446
447 (defcustom gnus-summary-check-current nil
448   "*If non-nil, consider the current article when moving.
449 The \"unread\" movement commands will stay on the same line if the
450 current article is unread."
451   :group 'gnus-summary-maneuvering
452   :type 'boolean)
453
454 (defcustom gnus-auto-center-summary 
455   (max (or (bound-and-true-p scroll-margin) 0) 2)
456   "*If non-nil, always center the current summary buffer.
457 In particular, if `vertical' do only vertical recentering.  If non-nil
458 and non-`vertical', do both horizontal and vertical recentering."
459   :group 'gnus-summary-maneuvering
460   :type '(choice (const :tag "none" nil)
461                  (const vertical)
462                  (integer :tag "height")
463                  (sexp :menu-tag "both" t)))
464
465 (defcustom gnus-auto-center-group t
466   "If non-nil, always center the group buffer."
467   :group 'gnus-summary-maneuvering
468   :type 'boolean)
469
470 (defcustom gnus-show-all-headers nil
471   "*If non-nil, don't hide any headers."
472   :group 'gnus-article-hiding
473   :group 'gnus-article-headers
474   :type 'boolean)
475
476 (defcustom gnus-summary-ignore-duplicates nil
477   "*If non-nil, ignore articles with identical Message-ID headers."
478   :group 'gnus-summary
479   :type 'boolean)
480
481 (defcustom gnus-single-article-buffer nil
482   "*If non-nil, display all articles in the same buffer.
483 If nil, each group will get its own article buffer."
484   :version "24.1"
485   :group 'gnus-article-various
486   :type 'boolean)
487
488 (defcustom gnus-widen-article-window nil
489   "If non-nil, selecting the article buffer will display only the article buffer."
490   :version "24.1"
491   :group 'gnus-article-various
492   :type 'boolean)
493
494 (defcustom gnus-break-pages t
495   "*If non-nil, do page breaking on articles.
496 The page delimiter is specified by the `gnus-page-delimiter'
497 variable."
498   :group 'gnus-article-various
499   :type 'boolean)
500
501 (defcustom gnus-move-split-methods nil
502   "*Variable used to suggest where articles are to be moved to.
503 It uses the same syntax as the `gnus-split-methods' variable.
504 However, whereas `gnus-split-methods' specifies file names as targets,
505 this variable specifies group names."
506   :group 'gnus-summary-mail
507   :type '(repeat (choice (list :value (fun) function)
508                          (cons :value ("" "") regexp (repeat string))
509                          (sexp :value nil))))
510
511 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
512   "Function used to compute default prefix for article move/copy/etc prompts.
513 The function should take one argument, a group name, and return a
514 string with the suggested prefix."
515   :group 'gnus-summary-mail
516   :type 'function)
517
518 ;; FIXME: Although the custom type is `character' for the following variables,
519 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
520
521 (defcustom gnus-unread-mark ?           ;Whitespace
522   "*Mark used for unread articles."
523   :group 'gnus-summary-marks
524   :type 'character)
525
526 (defcustom gnus-ticked-mark ?!
527   "*Mark used for ticked articles."
528   :group 'gnus-summary-marks
529   :type 'character)
530
531 (defcustom gnus-dormant-mark ??
532   "*Mark used for dormant articles."
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-del-mark ?r
537   "*Mark used for del'd articles."
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-read-mark ?R
542   "*Mark used for read articles."
543   :group 'gnus-summary-marks
544   :type 'character)
545
546 (defcustom gnus-expirable-mark ?E
547   "*Mark used for expirable articles."
548   :group 'gnus-summary-marks
549   :type 'character)
550
551 (defcustom gnus-killed-mark ?K
552   "*Mark used for killed articles."
553   :group 'gnus-summary-marks
554   :type 'character)
555
556 (defcustom gnus-spam-mark ?$
557   "*Mark used for spam articles."
558   :version "22.1"
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-kill-file-mark ?X
563   "*Mark used for articles killed by kill files."
564   :group 'gnus-summary-marks
565   :type 'character)
566
567 (defcustom gnus-low-score-mark ?Y
568   "*Mark used for articles with a low score."
569   :group 'gnus-summary-marks
570   :type 'character)
571
572 (defcustom gnus-catchup-mark ?C
573   "*Mark used for articles that are caught up."
574   :group 'gnus-summary-marks
575   :type 'character)
576
577 (defcustom gnus-replied-mark ?A
578   "*Mark used for articles that have been replied to."
579   :group 'gnus-summary-marks
580   :type 'character)
581
582 (defcustom gnus-forwarded-mark ?F
583   "*Mark used for articles that have been forwarded."
584   :version "22.1"
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-recent-mark ?N
589   "*Mark used for articles that are recent."
590   :version "22.1"
591   :group 'gnus-summary-marks
592   :type 'character)
593
594 (defcustom gnus-cached-mark ?*
595   "*Mark used for articles that are in the cache."
596   :group 'gnus-summary-marks
597   :type 'character)
598
599 (defcustom gnus-saved-mark ?S
600   "*Mark used for articles that have been saved."
601   :group 'gnus-summary-marks
602   :type 'character)
603
604 (defcustom gnus-unseen-mark ?.
605   "*Mark used for articles that haven't been seen."
606   :version "22.1"
607   :group 'gnus-summary-marks
608   :type 'character)
609
610 (defcustom gnus-no-mark ?               ;Whitespace
611   "*Mark used for articles that have no other secondary mark."
612   :version "22.1"
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-ancient-mark ?O
617   "*Mark used for ancient articles."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-sparse-mark ?Q
622   "*Mark used for sparsely reffed articles."
623   :group 'gnus-summary-marks
624   :type 'character)
625
626 (defcustom gnus-canceled-mark ?G
627   "*Mark used for canceled articles."
628   :group 'gnus-summary-marks
629   :type 'character)
630
631 (defcustom gnus-duplicate-mark ?M
632   "*Mark used for duplicate articles."
633   :group 'gnus-summary-marks
634   :type 'character)
635
636 (defcustom gnus-undownloaded-mark ?-
637   "*Mark used for articles that weren't downloaded."
638   :version "22.1"
639   :group 'gnus-summary-marks
640   :type 'character)
641
642 (defcustom gnus-downloaded-mark ?+
643   "*Mark used for articles that were downloaded."
644   :group 'gnus-summary-marks
645   :type 'character)
646
647 (defcustom gnus-downloadable-mark ?%
648   "*Mark used for articles that are to be downloaded."
649   :group 'gnus-summary-marks
650   :type 'character)
651
652 (defcustom gnus-unsendable-mark ?=
653   "*Mark used for articles that won't be sent."
654   :group 'gnus-summary-marks
655   :type 'character)
656
657 (defcustom gnus-score-over-mark ?+
658   "*Score mark used for articles with high scores."
659   :group 'gnus-summary-marks
660   :type 'character)
661
662 (defcustom gnus-score-below-mark ?-
663   "*Score mark used for articles with low scores."
664   :group 'gnus-summary-marks
665   :type 'character)
666
667 (defcustom gnus-empty-thread-mark ?     ;Whitespace
668   "*There is no thread under the article."
669   :group 'gnus-summary-marks
670   :type 'character)
671
672 (defcustom gnus-not-empty-thread-mark ?=
673   "*There is a thread under the article."
674   :group 'gnus-summary-marks
675   :type 'character)
676
677 (defcustom gnus-view-pseudo-asynchronously nil
678   "*If non-nil, Gnus will view pseudo-articles asynchronously."
679   :group 'gnus-extract-view
680   :type 'boolean)
681
682 (defcustom gnus-auto-expirable-marks
683   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
684         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
685         gnus-duplicate-mark)
686   "*The list of marks converted into expiration if a group is auto-expirable."
687   :version "24.1"
688   :group 'gnus-summary
689   :type '(repeat character))
690
691 (defcustom gnus-inhibit-user-auto-expire t
692   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
693   :version "21.1"
694   :group 'gnus-summary
695   :type 'boolean)
696
697 (defcustom gnus-mark-copied-or-moved-articles-as-expirable nil
698   "If non-nil, mark articles copied or moved to auto-expire group as expirable.
699 If nil, the expirable marks will be unchanged except that the marks
700 will be removed when copying or moving articles to a group that has
701 not turned auto-expire on.  If non-nil, articles that have been read
702 will be marked as expirable when being copied or moved to a group in
703 which auto-expire is turned on."
704   :version "23.2"
705   :type 'boolean
706   :group 'gnus-summary-marks)
707
708 (defcustom gnus-view-pseudos nil
709   "*If `automatic', pseudo-articles will be viewed automatically.
710 If `not-confirm', pseudos will be viewed automatically, and the user
711 will not be asked to confirm the command."
712   :group 'gnus-extract-view
713   :type '(choice (const :tag "off" nil)
714                  (const automatic)
715                  (const not-confirm)))
716
717 (defcustom gnus-view-pseudos-separately t
718   "*If non-nil, one pseudo-article will be created for each file to be viewed.
719 If nil, all files that use the same viewing command will be given as a
720 list of parameters to that command."
721   :group 'gnus-extract-view
722   :type 'boolean)
723
724 (defcustom gnus-insert-pseudo-articles t
725   "*If non-nil, insert pseudo-articles when decoding articles."
726   :group 'gnus-extract-view
727   :type 'boolean)
728
729 (defcustom gnus-summary-dummy-line-format
730   "   %(:                             :%) %S\n"
731   "*The format specification for the dummy roots in the summary buffer.
732 It works along the same lines as a normal formatting string,
733 with some simple extensions.
734
735 %S  The subject
736
737 General format specifiers can also be used.
738 See `(gnus)Formatting Variables'."
739   :link '(custom-manual "(gnus)Formatting Variables")
740   :group 'gnus-threading
741   :type 'string)
742
743 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
744   "*The format specification for the summary mode line.
745 It works along the same lines as a normal formatting string,
746 with some simple extensions:
747
748 %G  Group name
749 %p  Unprefixed group name
750 %A  Current article number
751 %z  Current article score
752 %V  Gnus version
753 %U  Number of unread articles in the group
754 %e  Number of unselected articles in the group
755 %Z  A string with unread/unselected article counts
756 %g  Shortish group name
757 %S  Subject of the current article
758 %u  User-defined spec
759 %s  Current score file name
760 %d  Number of dormant articles
761 %r  Number of articles that have been marked as read in this session
762 %E  Number of articles expunged by the score files"
763   :group 'gnus-summary-format
764   :type 'string)
765
766 (defcustom gnus-list-identifiers nil
767   "Regexp that matches list identifiers to be removed from subject.
768 This can also be a list of regexps."
769   :version "21.1"
770   :group 'gnus-summary-format
771   :group 'gnus-article-hiding
772   :type '(choice (const :tag "none" nil)
773                  (regexp :value ".*")
774                  (repeat :value (".*") regexp)))
775
776 (defcustom gnus-summary-mark-below 0
777   "*Mark all articles with a score below this variable as read.
778 This variable is local to each summary buffer and usually set by the
779 score file."
780   :group 'gnus-score-default
781   :type 'integer)
782
783 (defun gnus-widget-reversible-match (widget value)
784   "Ignoring WIDGET, convert VALUE to internal form.
785 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
786   ;; (debug value)
787   (or (symbolp value)
788       (and (listp value)
789            (eq (length value) 2)
790            (eq (nth 0 value) 'not)
791            (symbolp (nth 1 value)))))
792
793 (defun gnus-widget-reversible-to-internal (widget value)
794   "Ignoring WIDGET, convert VALUE to internal form.
795 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
796 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
797   ;; (debug value)
798   (if (atom value)
799       (list value nil)
800     (list (nth 1 value) t)))
801
802 (defun gnus-widget-reversible-to-external (widget value)
803   "Ignoring WIDGET, convert VALUE to external form.
804 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
805 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
806   ;; (debug value)
807   (if (nth 1 value)
808       (list 'not (nth 0 value))
809     (nth 0 value)))
810
811 (define-widget 'gnus-widget-reversible 'group
812   "A `group' that convert values."
813   :match 'gnus-widget-reversible-match
814   :value-to-internal 'gnus-widget-reversible-to-internal
815   :value-to-external 'gnus-widget-reversible-to-external)
816
817 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
818   "*List of functions used for sorting articles in the summary buffer.
819
820 Each function takes two articles and returns non-nil if the first
821 article should be sorted before the other.  If you use more than one
822 function, the primary sort function should be the last.  You should
823 probably always include `gnus-article-sort-by-number' in the list of
824 sorting functions -- preferably first.  Also note that sorting by date
825 is often much slower than sorting by number, and the sorting order is
826 very similar.  (Sorting by date means sorting by the time the message
827 was sent, sorting by number means sorting by arrival time.)
828
829 Each item can also be a list `(not F)' where F is a function;
830 this reverses the sort order.
831
832 Ready-made functions include `gnus-article-sort-by-number',
833 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
834 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
835 and `gnus-article-sort-by-score'.
836
837 When threading is turned on, the variable `gnus-thread-sort-functions'
838 controls how articles are sorted."
839   :group 'gnus-summary-sort
840   :type '(repeat (gnus-widget-reversible
841                   (choice (function-item gnus-article-sort-by-number)
842                           (function-item gnus-article-sort-by-author)
843                           (function-item gnus-article-sort-by-subject)
844                           (function-item gnus-article-sort-by-date)
845                           (function-item gnus-article-sort-by-score)
846                           (function-item gnus-article-sort-by-random)
847                           (function :tag "other"))
848                   (boolean :tag "Reverse order"))))
849
850
851 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
852   "*List of functions used for sorting threads in the summary buffer.
853 By default, threads are sorted by article number.
854
855 Each function takes two threads and returns non-nil if the first
856 thread should be sorted before the other.  If you use more than one
857 function, the primary sort function should be the last.  You should
858 probably always include `gnus-thread-sort-by-number' in the list of
859 sorting functions -- preferably first.  Also note that sorting by date
860 is often much slower than sorting by number, and the sorting order is
861 very similar.  (Sorting by date means sorting by the time the message
862 was sent, sorting by number means sorting by arrival time.)
863
864 Each list item can also be a list `(not F)' where F is a
865 function; this specifies reversed sort order.
866
867 Ready-made functions include `gnus-thread-sort-by-number',
868 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
869 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
870 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
871 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
872 and `gnus-thread-sort-by-total-score' (see
873 `gnus-thread-score-function').
874
875 When threading is turned off, the variable
876 `gnus-article-sort-functions' controls how articles are sorted."
877   :group 'gnus-summary-sort
878   :type '(repeat
879           (gnus-widget-reversible
880            (choice (function-item gnus-thread-sort-by-number)
881                    (function-item gnus-thread-sort-by-author)
882                    (function-item gnus-thread-sort-by-recipient)
883                    (function-item gnus-thread-sort-by-subject)
884                    (function-item gnus-thread-sort-by-date)
885                    (function-item gnus-thread-sort-by-score)
886                    (function-item gnus-thread-sort-by-most-recent-number)
887                    (function-item gnus-thread-sort-by-most-recent-date)
888                    (function-item gnus-thread-sort-by-random)
889                    (function-item gnus-thread-sort-by-total-score)
890                    (function :tag "other"))
891            (boolean :tag "Reverse order"))))
892
893 (defcustom gnus-thread-score-function '+
894   "*Function used for calculating the total score of a thread.
895
896 The function is called with the scores of the article and each
897 subthread and should then return the score of the thread.
898
899 Some functions you can use are `+', `max', or `min'."
900   :group 'gnus-summary-sort
901   :type 'function)
902
903 (defcustom gnus-summary-expunge-below nil
904   "All articles that have a score less than this variable will be expunged.
905 This variable is local to the summary buffers."
906   :group 'gnus-score-default
907   :type '(choice (const :tag "off" nil)
908                  integer))
909
910 (defcustom gnus-thread-expunge-below nil
911   "All threads that have a total score less than this variable will be expunged.
912 See `gnus-thread-score-function' for en explanation of what a
913 \"thread score\" is.
914
915 This variable is local to the summary buffers."
916   :group 'gnus-threading
917   :group 'gnus-score-default
918   :type '(choice (const :tag "off" nil)
919                  integer))
920
921 (defcustom gnus-summary-mode-hook nil
922   "*A hook for Gnus summary mode.
923 This hook is run before any variables are set in the summary buffer."
924   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
925   :group 'gnus-summary-various
926   :type 'hook)
927
928 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
929 (when (featurep 'xemacs)
930   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
931   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
932   (add-hook 'gnus-summary-mode-hook
933             'gnus-xmas-switch-horizontal-scrollbar-off))
934
935 (defcustom gnus-summary-menu-hook nil
936   "*Hook run after the creation of the summary mode menu."
937   :group 'gnus-summary-visual
938   :type 'hook)
939
940 (defcustom gnus-summary-exit-hook nil
941   "*A hook called on exit from the summary buffer.
942 It will be called with point in the group buffer."
943   :group 'gnus-summary-exit
944   :type 'hook)
945
946 (defcustom gnus-summary-prepare-hook nil
947   "*A hook called after the summary buffer has been generated.
948 If you want to modify the summary buffer, you can use this hook."
949   :group 'gnus-summary-various
950   :type 'hook)
951
952 (defcustom gnus-summary-prepared-hook nil
953   "*A hook called as the last thing after the summary buffer has been generated."
954   :group 'gnus-summary-various
955   :type 'hook)
956
957 (defcustom gnus-summary-generate-hook nil
958   "*A hook run just before generating the summary buffer.
959 This hook is commonly used to customize threading variables and the
960 like."
961   :group 'gnus-summary-various
962   :type 'hook)
963
964 (defcustom gnus-select-group-hook nil
965   "*A hook called when a newsgroup is selected.
966
967 If you'd like to simplify subjects like the
968 `gnus-summary-next-same-subject' command does, you can use the
969 following hook:
970
971  (add-hook gnus-select-group-hook
972            (lambda ()
973              (mapcar (lambda (header)
974                        (mail-header-set-subject
975                         header
976                         (gnus-simplify-subject
977                          (mail-header-subject header) 're-only)))
978                      gnus-newsgroup-headers)))"
979   :group 'gnus-group-select
980   :type 'hook)
981
982 (defcustom gnus-select-article-hook nil
983   "*A hook called when an article is selected."
984   :group 'gnus-summary-choose
985   :options '(gnus-agent-fetch-selected-article)
986   :type 'hook)
987
988 (defcustom gnus-visual-mark-article-hook
989   (list 'gnus-highlight-selected-summary)
990   "*Hook run after selecting an article in the summary buffer.
991 It is meant to be used for highlighting the article in some way.  It
992 is not run if `gnus-visual' is nil."
993   :group 'gnus-summary-visual
994   :type 'hook)
995
996 (defcustom gnus-parse-headers-hook nil
997   "*A hook called before parsing the headers."
998   :group 'gnus-various
999   :type 'hook)
1000
1001 (defcustom gnus-exit-group-hook nil
1002   "*A hook called when exiting summary mode.
1003 This hook is not called from the non-updating exit commands like `Q'."
1004   :group 'gnus-various
1005   :type 'hook)
1006
1007 (defcustom gnus-summary-update-hook nil
1008   "*A hook called when a summary line is changed.
1009 The hook will not be called if `gnus-visual' is nil.
1010
1011 The default function `gnus-summary-highlight-line' will
1012 highlight the line according to the `gnus-summary-highlight'
1013 variable."
1014   :group 'gnus-summary-visual
1015   :type 'hook)
1016
1017 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
1018   "*A hook called when an article is selected for the first time.
1019 The hook is intended to mark an article as read (or unread)
1020 automatically when it is selected."
1021   :group 'gnus-summary-choose
1022   :type 'hook)
1023
1024 (defcustom gnus-group-no-more-groups-hook nil
1025   "*A hook run when returning to group mode having no more (unread) groups."
1026   :group 'gnus-group-select
1027   :type 'hook)
1028
1029 (defcustom gnus-ps-print-hook nil
1030   "*A hook run before ps-printing something from Gnus."
1031   :group 'gnus-summary
1032   :type 'hook)
1033
1034 (defcustom gnus-summary-article-move-hook nil
1035   "*A hook called after an article is moved, copied, respooled, or crossposted."
1036   :version "22.1"
1037   :group 'gnus-summary
1038   :type 'hook)
1039
1040 (defcustom gnus-summary-article-delete-hook nil
1041   "*A hook called after an article is deleted."
1042   :version "22.1"
1043   :group 'gnus-summary
1044   :type 'hook)
1045
1046 (defcustom gnus-summary-article-expire-hook nil
1047   "*A hook called after an article is expired."
1048   :version "22.1"
1049   :group 'gnus-summary
1050   :type 'hook)
1051
1052 (defcustom gnus-summary-display-arrow
1053   (and (fboundp 'display-graphic-p)
1054        (display-graphic-p))
1055   "*If non-nil, display an arrow highlighting the current article."
1056   :version "22.1"
1057   :group 'gnus-summary
1058   :type 'boolean)
1059
1060 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1061   "Face used for highlighting the current article in the summary buffer."
1062   :group 'gnus-summary-visual
1063   :type 'face)
1064
1065 (defvar gnus-tmp-downloaded nil)
1066
1067 (defcustom gnus-summary-highlight
1068   '(((eq mark gnus-canceled-mark)
1069      . gnus-summary-cancelled)
1070     ((and uncached (> score default-high))
1071      . gnus-summary-high-undownloaded)
1072     ((and uncached (< score default-low))
1073      . gnus-summary-low-undownloaded)
1074     (uncached
1075      . gnus-summary-normal-undownloaded)
1076     ((and (> score default-high)
1077           (or (eq mark gnus-dormant-mark)
1078               (eq mark gnus-ticked-mark)))
1079      . gnus-summary-high-ticked)
1080     ((and (< score default-low)
1081           (or (eq mark gnus-dormant-mark)
1082               (eq mark gnus-ticked-mark)))
1083      . gnus-summary-low-ticked)
1084     ((or (eq mark gnus-dormant-mark)
1085          (eq mark gnus-ticked-mark))
1086      . gnus-summary-normal-ticked)
1087     ((and (> score default-high) (eq mark gnus-ancient-mark))
1088      . gnus-summary-high-ancient)
1089     ((and (< score default-low) (eq mark gnus-ancient-mark))
1090      . gnus-summary-low-ancient)
1091     ((eq mark gnus-ancient-mark)
1092      . gnus-summary-normal-ancient)
1093     ((and (> score default-high) (eq mark gnus-unread-mark))
1094      . gnus-summary-high-unread)
1095     ((and (< score default-low) (eq mark gnus-unread-mark))
1096      . gnus-summary-low-unread)
1097     ((eq mark gnus-unread-mark)
1098      . gnus-summary-normal-unread)
1099     ((> score default-high)
1100      . gnus-summary-high-read)
1101     ((< score default-low)
1102      . gnus-summary-low-read)
1103     (t
1104      . gnus-summary-normal-read))
1105   "*Controls the highlighting of summary buffer lines.
1106
1107 A list of (FORM . FACE) pairs.  When deciding how a particular
1108 summary line should be displayed, each form is evaluated.  The content
1109 of the face field after the first true form is used.  You can change
1110 how those summary lines are displayed, by editing the face field.
1111
1112 You can use the following variables in the FORM field.
1113
1114 score:        The article's score.
1115 default:      The default article score.
1116 default-high: The default score for high scored articles.
1117 default-low:  The default score for low scored articles.
1118 below:        The score below which articles are automatically marked as read.
1119 mark:         The article's mark.
1120 uncached:     Non-nil if the article is uncached."
1121   :group 'gnus-summary-visual
1122   :type '(repeat (cons (sexp :tag "Form" nil)
1123                        face)))
1124 (put 'gnus-summary-highlight 'risky-local-variable t)
1125
1126 (defcustom gnus-alter-header-function nil
1127   "Function called to allow alteration of article header structures.
1128 The function is called with one parameter, the article header vector,
1129 which it may alter in any way."
1130   :type '(choice (const :tag "None" nil)
1131                  function)
1132   :group 'gnus-summary)
1133
1134 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1135   "Function used to decode a string with encoded words.")
1136
1137 (defvar gnus-decode-encoded-address-function
1138   'mail-decode-encoded-address-string
1139   "Function used to decode addresses with encoded words.")
1140
1141 (defcustom gnus-extra-headers '(To Cc Keywords Gcc Newsgroups)
1142   "*Extra headers to parse."
1143   :version "24.1"                       ; added Cc Keywords Gcc
1144   :group 'gnus-summary
1145   :type '(repeat symbol))
1146
1147 (defcustom gnus-ignored-from-addresses
1148   (and user-mail-address
1149        (not (string= user-mail-address ""))
1150        (regexp-quote user-mail-address))
1151   "*From headers that may be suppressed in favor of To headers.
1152 This can be a regexp or a list of regexps."
1153   :version "21.1"
1154   :group 'gnus-summary
1155   :type '(choice regexp
1156                  (repeat :tag "Regexp List" regexp)))
1157
1158 (defsubst gnus-ignored-from-addresses ()
1159   (gmm-regexp-concat gnus-ignored-from-addresses))
1160
1161 (defcustom gnus-summary-to-prefix "-> "
1162   "*String prefixed to the To field in the summary line when
1163 using `gnus-ignored-from-addresses'."
1164   :version "22.1"
1165   :group 'gnus-summary
1166   :type 'string)
1167
1168 (defcustom gnus-summary-newsgroup-prefix "=> "
1169   "*String prefixed to the Newsgroup field in the summary
1170 line when using the option `gnus-ignored-from-addresses'."
1171   :version "22.1"
1172   :group 'gnus-summary
1173   :type 'string)
1174
1175 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1176   "List of charsets that should be ignored.
1177 When these charsets are used in the \"charset\" parameter, the
1178 default charset will be used instead."
1179   :version "21.1"
1180   :type '(repeat symbol)
1181   :group 'gnus-charset)
1182
1183 (defcustom gnus-newsgroup-maximum-articles nil
1184   "The maximum number of articles a newsgroup.
1185 If this is a number, old articles in a newsgroup exceeding this number
1186 are silently ignored.  If it is nil, no article is ignored.  Note that
1187 setting this variable to a number might prevent you from reading very
1188 old articles."
1189   :group 'gnus-group-select
1190   :version "22.2"
1191   :type '(choice (const :tag "No limit" nil)
1192                  integer))
1193
1194 (gnus-define-group-parameter
1195  ignored-charsets
1196  :type list
1197  :function-document
1198  "Return the ignored charsets of GROUP."
1199  :variable gnus-group-ignored-charsets-alist
1200  :variable-default
1201  '(("alt\\.chinese\\.text" iso-8859-1))
1202  :variable-document
1203  "Alist of regexps (to match group names) and charsets that should be ignored.
1204 When these charsets are used in the \"charset\" parameter, the
1205 default charset will be used instead."
1206  :variable-group gnus-charset
1207  :variable-type '(repeat (cons (regexp :tag "Group")
1208                                (repeat symbol)))
1209  :parameter-type '(choice :tag "Ignored charsets"
1210                           :value nil
1211                           (repeat (symbol)))
1212  :parameter-document       "\
1213 List of charsets that should be ignored.
1214
1215 When these charsets are used in the \"charset\" parameter, the
1216 default charset will be used instead.")
1217
1218 (defcustom gnus-group-highlight-words-alist nil
1219   "Alist of group regexps and highlight regexps.
1220 This variable uses the same syntax as `gnus-emphasis-alist'."
1221   :version "21.1"
1222   :type '(repeat (cons (regexp :tag "Group")
1223                        (repeat (list (regexp :tag "Highlight regexp")
1224                                      (number :tag "Group for entire word" 0)
1225                                      (number :tag "Group for displayed part" 0)
1226                                      (symbol :tag "Face"
1227                                              gnus-emphasis-highlight-words)))))
1228   :group 'gnus-summary-visual)
1229
1230 (defcustom gnus-summary-show-article-charset-alist
1231   nil
1232   "Alist of number and charset.
1233 The article will be shown with the charset corresponding to the
1234 numbered argument.
1235 For example: ((1 . cn-gb-2312) (2 . big5))."
1236   :version "21.1"
1237   :type '(repeat (cons (number :tag "Argument" 1)
1238                        (symbol :tag "Charset")))
1239   :group 'gnus-charset)
1240
1241 (defcustom gnus-preserve-marks t
1242   "Whether marks are preserved when moving, copying and respooling messages."
1243   :version "21.1"
1244   :type 'boolean
1245   :group 'gnus-summary-marks)
1246
1247 (defcustom gnus-alter-articles-to-read-function nil
1248   "Function to be called to alter the list of articles to be selected."
1249   :type '(choice (const nil) function)
1250   :group 'gnus-summary)
1251
1252 (defcustom gnus-orphan-score nil
1253   "*All orphans get this score added.  Set in the score file."
1254   :group 'gnus-score-default
1255   :type '(choice (const nil)
1256                  integer))
1257
1258 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1259   "*A regexp to match MIME parts when saving multiple parts of a
1260 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1261 This regexp will be used by default when prompting the user for which
1262 type of files to save."
1263   :group 'gnus-summary
1264   :type 'regexp)
1265
1266 (defcustom gnus-read-all-available-headers nil
1267   "Whether Gnus should parse all headers made available to it.
1268 This is mostly relevant for slow back ends where the user may
1269 wish to widen the summary buffer to include all headers
1270 that were fetched."
1271   :version "22.1"
1272   :group 'gnus-summary
1273   :type '(choice boolean regexp))
1274
1275 (defcustom gnus-summary-pipe-output-default-command nil
1276   "Command (and optional arguments) used to pipe article to subprocess.
1277 This will be used as the default command if it is non-nil.  The value
1278 will be updated if you modify it when executing the command
1279 `gnus-summary-pipe-output' or the function `gnus-summary-save-in-pipe'."
1280   :version "23.1" ;; No Gnus
1281   :group 'gnus-summary
1282   :type '(radio (const :tag "None" nil) (string :tag "Command")))
1283
1284 (defcustom gnus-summary-muttprint-program "muttprint"
1285   "Command (and optional arguments) used to run Muttprint.
1286 The value will be updated if you modify it when executing the command
1287 `gnus-summary-muttprint'."
1288   :version "22.1"
1289   :group 'gnus-summary
1290   :type 'string)
1291
1292 (defcustom gnus-article-loose-mime t
1293   "If non-nil, don't require MIME-Version header.
1294 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1295 supply the MIME-Version header or deliberately strip it from the mail.
1296 If non-nil (the default), Gnus will treat some articles as MIME
1297 even if the MIME-Version header is missing."
1298   :version "22.1"
1299   :type 'boolean
1300   :group 'gnus-article-mime)
1301
1302 (defcustom gnus-article-emulate-mime t
1303   "If non-nil, use MIME emulation for uuencode and the like.
1304 This means that Gnus will search message bodies for text that look
1305 like uuencoded bits, yEncoded bits, and so on, and present that using
1306 the normal Gnus MIME machinery."
1307   :version "22.1"
1308   :type 'boolean
1309   :group 'gnus-article-mime)
1310
1311 ;;; Internal variables
1312
1313 (defvar gnus-summary-display-cache nil)
1314 (defvar gnus-article-mime-handles nil)
1315 (defvar gnus-article-decoded-p nil)
1316 (defvar gnus-article-charset nil)
1317 (defvar gnus-article-ignored-charsets nil)
1318 (defvar gnus-scores-exclude-files nil)
1319 (defvar gnus-page-broken nil)
1320
1321 (defvar gnus-original-article nil)
1322 (defvar gnus-article-internal-prepare-hook nil)
1323 (defvar gnus-newsgroup-process-stack nil)
1324
1325 (defvar gnus-thread-indent-array nil)
1326 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1327 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1328   "Function called to sort the articles within a thread after it has been gathered together.")
1329
1330 (defvar gnus-summary-save-parts-type-history nil)
1331 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1332
1333 ;; Avoid highlighting in kill files.
1334 (defvar gnus-summary-inhibit-highlight nil)
1335 (defvar gnus-newsgroup-selected-overlay nil)
1336 (defvar gnus-inhibit-limiting nil)
1337 (defvar gnus-newsgroup-adaptive-score-file nil)
1338 (defvar gnus-current-score-file nil)
1339 (defvar gnus-current-move-group nil)
1340 (defvar gnus-current-copy-group nil)
1341 (defvar gnus-current-crosspost-group nil)
1342 (defvar gnus-newsgroup-display nil)
1343
1344 (defvar gnus-newsgroup-dependencies nil)
1345 (defvar gnus-newsgroup-adaptive nil)
1346 (defvar gnus-summary-display-article-function nil)
1347 (defvar gnus-summary-highlight-line-function nil
1348   "Function called after highlighting a summary line.")
1349
1350 (defvar gnus-summary-line-format-alist
1351   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1352     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1353     (?s gnus-tmp-subject-or-nil ?s)
1354     (?n gnus-tmp-name ?s)
1355     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1356         ?s)
1357     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1358             gnus-tmp-from) ?s)
1359     (?F gnus-tmp-from ?s)
1360     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1361     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1362     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1363     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1364     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1365     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1366     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1367     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1368     (?L gnus-tmp-lines ?s)
1369     (?Z (or (nnir-article-rsv (mail-header-number gnus-tmp-header))
1370             0) ?d)
1371     (?G (or (nnir-article-group (mail-header-number gnus-tmp-header))
1372             "") ?s)
1373     (?g (or (gnus-group-short-name
1374              (nnir-article-group (mail-header-number gnus-tmp-header)))
1375             "") ?s)
1376     (?O gnus-tmp-downloaded ?c)
1377     (?I gnus-tmp-indentation ?s)
1378     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1379     (?R gnus-tmp-replied ?c)
1380     (?\[ gnus-tmp-opening-bracket ?c)
1381     (?\] gnus-tmp-closing-bracket ?c)
1382     (?\> (make-string gnus-tmp-level ? ) ?s)
1383     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1384     (?i gnus-tmp-score ?d)
1385     (?z gnus-tmp-score-char ?c)
1386     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1387     (?U gnus-tmp-unread ?c)
1388     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1389         ?s)
1390     (?t (gnus-summary-number-of-articles-in-thread
1391          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1392         ?d)
1393     (?e (gnus-summary-number-of-articles-in-thread
1394          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1395         ?c)
1396     (?u gnus-tmp-user-defined ?s)
1397     (?P (gnus-pick-line-number) ?d)
1398     (?B gnus-tmp-thread-tree-header-string ?s)
1399     (user-date (gnus-user-date
1400                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1401   "An alist of format specifications that can appear in summary lines.
1402 These are paired with what variables they correspond with, along with
1403 the type of the variable (string, integer, character, etc).")
1404
1405 (defvar gnus-summary-dummy-line-format-alist
1406   `((?S gnus-tmp-subject ?s)
1407     (?N gnus-tmp-number ?d)
1408     (?u gnus-tmp-user-defined ?s)))
1409
1410 (defvar gnus-summary-mode-line-format-alist
1411   `((?G gnus-tmp-group-name ?s)
1412     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1413     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1414     (?A gnus-tmp-article-number ?d)
1415     (?Z gnus-tmp-unread-and-unselected ?s)
1416     (?V gnus-version ?s)
1417     (?U gnus-tmp-unread-and-unticked ?d)
1418     (?S gnus-tmp-subject ?s)
1419     (?e gnus-tmp-unselected ?d)
1420     (?u gnus-tmp-user-defined ?s)
1421     (?d (length gnus-newsgroup-dormant) ?d)
1422     (?t (length gnus-newsgroup-marked) ?d)
1423     (?h (length gnus-newsgroup-spam-marked) ?d)
1424     (?r (length gnus-newsgroup-reads) ?d)
1425     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1426     (?E gnus-newsgroup-expunged-tally ?d)
1427     (?s (gnus-current-score-file-nondirectory) ?s)))
1428
1429 ;; This is here rather than in gnus-art for compilation reasons.
1430 (defvar gnus-article-mode-line-format-alist
1431   (nconc '((?w (gnus-article-wash-status) ?s)
1432            (?m (gnus-article-mime-part-status) ?s))
1433          gnus-summary-mode-line-format-alist))
1434
1435 (defvar gnus-last-search-regexp nil
1436   "Default regexp for article search command.")
1437
1438 (defvar gnus-last-shell-command nil
1439   "Default shell command on article.")
1440
1441 (defvar gnus-newsgroup-agentized nil
1442   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1443 (defvar gnus-newsgroup-begin nil)
1444 (defvar gnus-newsgroup-end nil)
1445 (defvar gnus-newsgroup-last-rmail nil)
1446 (defvar gnus-newsgroup-last-mail nil)
1447 (defvar gnus-newsgroup-last-folder nil)
1448 (defvar gnus-newsgroup-last-file nil)
1449 (defvar gnus-newsgroup-last-directory nil)
1450 (defvar gnus-newsgroup-auto-expire nil)
1451 (defvar gnus-newsgroup-active nil)
1452 (defvar gnus-newsgroup-highest nil)
1453
1454 (defvar gnus-newsgroup-data nil)
1455 (defvar gnus-newsgroup-data-reverse nil)
1456 (defvar gnus-newsgroup-limit nil)
1457 (defvar gnus-newsgroup-limits nil)
1458 (defvar gnus-summary-use-undownloaded-faces nil)
1459
1460 (defvar gnus-newsgroup-unreads nil
1461   "Sorted list of unread articles in the current newsgroup.")
1462
1463 (defvar gnus-newsgroup-unselected nil
1464   "Sorted list of unselected unread articles in the current newsgroup.")
1465
1466 (defvar gnus-newsgroup-reads nil
1467   "Alist of read articles and article marks in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-expunged-tally nil)
1470
1471 (defvar gnus-newsgroup-marked nil
1472   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1473
1474 (defvar gnus-newsgroup-spam-marked nil
1475   "List of ranges of articles that have been marked as spam.")
1476
1477 (defvar gnus-newsgroup-killed nil
1478   "List of ranges of articles that have been through the scoring process.")
1479
1480 (defvar gnus-newsgroup-cached nil
1481   "Sorted list of articles that come from the article cache.")
1482
1483 (defvar gnus-newsgroup-saved nil
1484   "List of articles that have been saved.")
1485
1486 (defvar gnus-newsgroup-kill-headers nil)
1487
1488 (defvar gnus-newsgroup-replied nil
1489   "List of articles that have been replied to in the current newsgroup.")
1490
1491 (defvar gnus-newsgroup-forwarded nil
1492   "List of articles that have been forwarded in the current newsgroup.")
1493
1494 (defvar gnus-newsgroup-expirable nil
1495   "Sorted list of articles in the current newsgroup that can be expired.")
1496
1497 (defvar gnus-newsgroup-processable nil
1498   "List of articles in the current newsgroup that can be processed.")
1499
1500 (defvar gnus-newsgroup-downloadable nil
1501   "Sorted list of articles in the current newsgroup that can be processed.")
1502
1503 (defvar gnus-newsgroup-unfetched nil
1504   "Sorted list of articles in the current newsgroup whose headers have
1505 not been fetched into the agent.
1506
1507 This list will always be a subset of gnus-newsgroup-undownloaded.")
1508
1509 (defvar gnus-newsgroup-undownloaded nil
1510   "List of articles in the current newsgroup that haven't been downloaded.")
1511
1512 (defvar gnus-newsgroup-unsendable nil
1513   "List of articles in the current newsgroup that won't be sent.")
1514
1515 (defvar gnus-newsgroup-bookmarks nil
1516   "List of articles in the current newsgroup that have bookmarks.")
1517
1518 (defvar gnus-newsgroup-dormant nil
1519   "Sorted list of dormant articles in the current newsgroup.")
1520
1521 (defvar gnus-newsgroup-unseen nil
1522   "List of unseen articles in the current newsgroup.")
1523
1524 (defvar gnus-newsgroup-seen nil
1525   "Range of seen articles in the current newsgroup.")
1526
1527 (defvar gnus-newsgroup-unexist nil
1528   "Range of unexistent articles in the current newsgroup.")
1529
1530 (defvar gnus-newsgroup-articles nil
1531   "List of articles in the current newsgroup.")
1532
1533 (defvar gnus-newsgroup-scored nil
1534   "List of scored articles in the current newsgroup.")
1535
1536 (defvar gnus-newsgroup-headers nil
1537   "List of article headers in the current newsgroup.")
1538
1539 (defvar gnus-newsgroup-threads nil)
1540
1541 (defvar gnus-newsgroup-prepared nil
1542   "Whether the current group has been prepared properly.")
1543
1544 (defvar gnus-newsgroup-ancient nil
1545   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1546
1547 (defvar gnus-newsgroup-sparse nil)
1548
1549 (defvar gnus-current-article nil)
1550 (defvar gnus-article-current nil)
1551 (defvar gnus-current-headers nil)
1552 (defvar gnus-have-all-headers nil)
1553 (defvar gnus-last-article nil)
1554 (defvar gnus-newsgroup-history nil)
1555 (defvar gnus-newsgroup-charset nil)
1556 (defvar gnus-newsgroup-ephemeral-charset nil)
1557 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1558
1559 (defvar gnus-article-before-search nil)
1560
1561 (defvar gnus-summary-local-variables
1562   '(gnus-newsgroup-name
1563
1564     ;; Marks lists
1565     gnus-newsgroup-unreads
1566     gnus-newsgroup-unselected
1567     gnus-newsgroup-marked
1568     gnus-newsgroup-spam-marked
1569     gnus-newsgroup-reads
1570     gnus-newsgroup-saved
1571     gnus-newsgroup-replied
1572     gnus-newsgroup-forwarded
1573     gnus-newsgroup-expirable
1574     gnus-newsgroup-killed
1575     gnus-newsgroup-unseen
1576     gnus-newsgroup-seen
1577     gnus-newsgroup-unexist
1578     gnus-newsgroup-cached
1579     gnus-newsgroup-downloadable
1580     gnus-newsgroup-undownloaded
1581     gnus-newsgroup-unsendable
1582
1583     gnus-newsgroup-begin gnus-newsgroup-end
1584     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1585     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1586     gnus-newsgroup-last-directory
1587     gnus-newsgroup-auto-expire
1588     gnus-newsgroup-processable
1589     gnus-newsgroup-unfetched
1590     gnus-newsgroup-articles
1591     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1592     gnus-newsgroup-headers gnus-newsgroup-threads
1593     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1594     gnus-current-article gnus-current-headers gnus-have-all-headers
1595     gnus-last-article gnus-article-internal-prepare-hook
1596     (gnus-summary-article-delete-hook . global)
1597     (gnus-summary-article-move-hook . global)
1598     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1599     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1600     gnus-thread-expunge-below
1601     gnus-score-alist gnus-current-score-file
1602     (gnus-summary-expunge-below . global)
1603     (gnus-summary-mark-below . global)
1604     (gnus-orphan-score . global)
1605     gnus-newsgroup-active gnus-scores-exclude-files
1606     gnus-newsgroup-highest
1607     gnus-newsgroup-history gnus-newsgroup-ancient
1608     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1609     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1610     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1611     (gnus-newsgroup-expunged-tally . 0)
1612     gnus-cache-removable-articles
1613     gnus-newsgroup-data gnus-newsgroup-data-reverse
1614     gnus-newsgroup-limit gnus-newsgroup-limits
1615     gnus-newsgroup-charset gnus-newsgroup-display
1616     gnus-summary-use-undownloaded-faces)
1617   "Variables that are buffer-local to the summary buffers.")
1618
1619 (defvar gnus-newsgroup-variables nil
1620   "A list of variables that have separate values in different newsgroups.
1621 A list of newsgroup (summary buffer) local variables, or cons of
1622 variables and their default expressions to be evalled (when the default
1623 values are not nil), that should be made global while the summary buffer
1624 is active.
1625
1626 Note: The default expressions will be evaluated (using function `eval')
1627 before assignment to the local variable rather than just assigned to it.
1628 If the default expression is the symbol `global', that symbol will not
1629 be evaluated but the global value of the local variable will be used
1630 instead.
1631
1632 These variables can be used to set variables in the group parameters
1633 while still allowing them to affect operations done in other buffers.
1634 For example:
1635
1636 \(setq gnus-newsgroup-variables
1637      '(message-use-followup-to
1638        (gnus-visible-headers .
1639          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1640 ")
1641
1642 (eval-when-compile
1643   ;; Bind features so that require will believe that gnus-sum has
1644   ;; already been loaded (avoids infinite recursion)
1645   (let ((features (cons 'gnus-sum features)))
1646     (require 'gnus-art)))
1647
1648 ;; MIME stuff.
1649
1650 (defvar gnus-decode-encoded-word-methods
1651   '(mail-decode-encoded-word-string)
1652   "List of methods used to decode encoded words.
1653
1654 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1655 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1656 \(REGEXP . FUNCTION), FUNCTION will be applied only to the newsgroups
1657 whose names match REGEXP.
1658
1659 For example:
1660 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1661  mail-decode-encoded-word-string
1662  (\"chinese\" . rfc1843-decode-string))")
1663
1664 (defvar gnus-decode-encoded-word-methods-cache nil)
1665
1666 (defun gnus-multi-decode-encoded-word-string (string)
1667   "Apply the functions from `gnus-encoded-word-methods' that match."
1668   (unless (and gnus-decode-encoded-word-methods-cache
1669                (eq gnus-newsgroup-name
1670                    (car gnus-decode-encoded-word-methods-cache)))
1671     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1672     (dolist (method gnus-decode-encoded-word-methods)
1673       (if (symbolp method)
1674           (nconc gnus-decode-encoded-word-methods-cache (list method))
1675         (if (and gnus-newsgroup-name
1676                  (string-match (car method) gnus-newsgroup-name))
1677             (nconc gnus-decode-encoded-word-methods-cache
1678                    (list (cdr method)))))))
1679   (dolist (method (cdr gnus-decode-encoded-word-methods-cache) string)
1680     (setq string (funcall method string))))
1681
1682 ;; Subject simplification.
1683
1684 (defun gnus-simplify-whitespace (str)
1685   "Remove excessive whitespace from STR."
1686   ;; Multiple spaces.
1687   (while (string-match "[ \t][ \t]+" str)
1688     (setq str (concat (substring str 0 (match-beginning 0))
1689                         " "
1690                         (substring str (match-end 0)))))
1691   ;; Leading spaces.
1692   (when (string-match "^[ \t]+" str)
1693     (setq str (substring str (match-end 0))))
1694   ;; Trailing spaces.
1695   (when (string-match "[ \t]+$" str)
1696     (setq str (substring str 0 (match-beginning 0))))
1697   str)
1698
1699 (defun gnus-simplify-all-whitespace (str)
1700   "Remove all whitespace from STR."
1701   (while (string-match "[ \t\n]+" str)
1702     (setq str (replace-match "" nil nil str)))
1703   str)
1704
1705 (defsubst gnus-simplify-subject-re (subject)
1706   "Remove \"Re:\" from subject lines."
1707   (if (string-match message-subject-re-regexp subject)
1708       (substring subject (match-end 0))
1709     subject))
1710
1711 (defun gnus-simplify-subject (subject &optional re-only)
1712   "Remove `Re:' and words in parentheses.
1713 If RE-ONLY is non-nil, strip leading `Re:'s only."
1714   (let ((case-fold-search t))           ;Ignore case.
1715     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1716     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1717       (setq subject (substring subject (match-end 0))))
1718     ;; Remove uninteresting prefixes.
1719     (when (and (not re-only)
1720                gnus-simplify-ignored-prefixes
1721                (string-match gnus-simplify-ignored-prefixes subject))
1722       (setq subject (substring subject (match-end 0))))
1723     ;; Remove words in parentheses from end.
1724     (unless re-only
1725       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1726         (setq subject (substring subject 0 (match-beginning 0)))))
1727     ;; Return subject string.
1728     subject))
1729
1730 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1731 ;; all whitespace.
1732 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1733   (goto-char (point-min))
1734   (while (re-search-forward regexp nil t)
1735     (replace-match (or newtext ""))))
1736
1737 (defun gnus-simplify-buffer-fuzzy (regexp)
1738   "Simplify string in the buffer fuzzily.
1739 The string in the accessible portion of the current buffer is simplified.
1740 It is assumed to be a single-line subject.
1741 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1742 matter is removed.  Additional things can be deleted by setting
1743 `gnus-simplify-subject-fuzzy-regexp'."
1744   (let ((case-fold-search t)
1745         (modified-tick))
1746     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1747
1748     (while (not (eq modified-tick (buffer-modified-tick)))
1749       (setq modified-tick (buffer-modified-tick))
1750       (cond
1751        ((listp regexp)
1752         (mapc 'gnus-simplify-buffer-fuzzy-step regexp))
1753        (regexp
1754         (gnus-simplify-buffer-fuzzy-step regexp)))
1755       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1756       (gnus-simplify-buffer-fuzzy-step
1757        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1758       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1759
1760     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1761     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1762     (gnus-simplify-buffer-fuzzy-step " $")
1763     (gnus-simplify-buffer-fuzzy-step "^ +")))
1764
1765 (defun gnus-simplify-subject-fuzzy (subject)
1766   "Simplify a subject string fuzzily.
1767 See `gnus-simplify-buffer-fuzzy' for details."
1768   (save-excursion
1769     (let ((regexp gnus-simplify-subject-fuzzy-regexp))
1770       (gnus-set-work-buffer)
1771       (let ((case-fold-search t))
1772         ;; Remove uninteresting prefixes.
1773         (when (and gnus-simplify-ignored-prefixes
1774                    (string-match gnus-simplify-ignored-prefixes subject))
1775           (setq subject (substring subject (match-end 0))))
1776         (insert subject)
1777         (inline (gnus-simplify-buffer-fuzzy regexp))
1778         (buffer-string)))))
1779
1780 (defsubst gnus-simplify-subject-fully (subject)
1781   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1782   (cond
1783    (gnus-simplify-subject-functions
1784     (gnus-map-function gnus-simplify-subject-functions subject))
1785    ((null gnus-summary-gather-subject-limit)
1786     (gnus-simplify-subject-re subject))
1787    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1788     (gnus-simplify-subject-fuzzy subject))
1789    ((numberp gnus-summary-gather-subject-limit)
1790     (truncate-string-to-width (gnus-simplify-subject-re subject)
1791                               gnus-summary-gather-subject-limit))
1792    (t
1793     subject)))
1794
1795 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1796   "Check whether two subjects are equal.
1797 If optional argument SIMPLE-FIRST is t, first argument is already
1798 simplified."
1799   (cond
1800    ((null simple-first)
1801     (equal (gnus-simplify-subject-fully s1)
1802            (gnus-simplify-subject-fully s2)))
1803    (t
1804     (equal s1
1805            (gnus-simplify-subject-fully s2)))))
1806
1807 (defun gnus-summary-bubble-group ()
1808   "Increase the score of the current group.
1809 This is a handy function to add to `gnus-summary-exit-hook' to
1810 increase the score of each group you read."
1811   (gnus-group-add-score gnus-newsgroup-name))
1812
1813 \f
1814 ;;;
1815 ;;; Gnus summary mode
1816 ;;;
1817
1818 (put 'gnus-summary-mode 'mode-class 'special)
1819
1820 (defvar gnus-article-commands-menu)
1821
1822 ;; Non-orthogonal keys
1823
1824 (gnus-define-keys gnus-summary-mode-map
1825   " " gnus-summary-next-page
1826   "\177" gnus-summary-prev-page
1827   [delete] gnus-summary-prev-page
1828   [backspace] gnus-summary-prev-page
1829   "\r" gnus-summary-scroll-up
1830   "\M-\r" gnus-summary-scroll-down
1831   "n" gnus-summary-next-unread-article
1832   "p" gnus-summary-prev-unread-article
1833   "N" gnus-summary-next-article
1834   "P" gnus-summary-prev-article
1835   "\M-\C-n" gnus-summary-next-same-subject
1836   "\M-\C-p" gnus-summary-prev-same-subject
1837   "\M-n" gnus-summary-next-unread-subject
1838   "\M-p" gnus-summary-prev-unread-subject
1839   "." gnus-summary-first-unread-article
1840   "," gnus-summary-best-unread-article
1841   "\M-s" gnus-summary-search-article-forward
1842   "\M-r" gnus-summary-search-article-backward
1843   "\M-S" gnus-summary-repeat-search-article-forward
1844   "\M-R" gnus-summary-repeat-search-article-backward
1845   "<" gnus-summary-beginning-of-article
1846   ">" gnus-summary-end-of-article
1847   "j" gnus-summary-goto-article
1848   "^" gnus-summary-refer-parent-article
1849   "\M-^" gnus-summary-refer-article
1850   "u" gnus-summary-tick-article-forward
1851   "!" gnus-summary-tick-article-forward
1852   "U" gnus-summary-tick-article-backward
1853   "d" gnus-summary-mark-as-read-forward
1854   "D" gnus-summary-mark-as-read-backward
1855   "E" gnus-summary-mark-as-expirable
1856   "\M-u" gnus-summary-clear-mark-forward
1857   "\M-U" gnus-summary-clear-mark-backward
1858   "k" gnus-summary-kill-same-subject-and-select
1859   "\C-k" gnus-summary-kill-same-subject
1860   "\M-\C-k" gnus-summary-kill-thread
1861   "\M-\C-l" gnus-summary-lower-thread
1862   "e" gnus-summary-edit-article
1863   "#" gnus-summary-mark-as-processable
1864   "\M-#" gnus-summary-unmark-as-processable
1865   "\M-\C-t" gnus-summary-toggle-threads
1866   "\M-\C-s" gnus-summary-show-thread
1867   "\M-\C-h" gnus-summary-hide-thread
1868   "\M-\C-f" gnus-summary-next-thread
1869   "\M-\C-b" gnus-summary-prev-thread
1870   [(meta down)] gnus-summary-next-thread
1871   [(meta up)] gnus-summary-prev-thread
1872   "\M-\C-u" gnus-summary-up-thread
1873   "\M-\C-d" gnus-summary-down-thread
1874   "&" gnus-summary-execute-command
1875   "c" gnus-summary-catchup-and-exit
1876   "\C-w" gnus-summary-mark-region-as-read
1877   "\C-t" gnus-summary-toggle-truncation
1878   "?" gnus-summary-mark-as-dormant
1879   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1880   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1881   "\C-c\C-s\C-m\C-n" gnus-summary-sort-by-most-recent-number
1882   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1883   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1884   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1885   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1886   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1887   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1888   "\C-c\C-s\C-m\C-d" gnus-summary-sort-by-most-recent-date
1889   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1890   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1891   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1892   "=" gnus-summary-expand-window
1893   "\C-x\C-s" gnus-summary-reselect-current-group
1894   "\M-g" gnus-summary-rescan-group
1895   "\C-c\C-r" gnus-summary-caesar-message
1896   "f" gnus-summary-followup
1897   "F" gnus-summary-followup-with-original
1898   "C" gnus-summary-cancel-article
1899   "r" gnus-summary-reply
1900   "R" gnus-summary-reply-with-original
1901   "\C-c\C-f" gnus-summary-mail-forward
1902   "o" gnus-summary-save-article
1903   "\C-o" gnus-summary-save-article-mail
1904   "|" gnus-summary-pipe-output
1905   "\M-k" gnus-summary-edit-local-kill
1906   "\M-K" gnus-summary-edit-global-kill
1907   ;; "V" gnus-version
1908   "\C-c\C-d" gnus-summary-describe-group
1909   "q" gnus-summary-exit
1910   "Q" gnus-summary-exit-no-update
1911   "\C-c\C-i" gnus-info-find-node
1912   gnus-mouse-2 gnus-mouse-pick-article
1913   [follow-link] mouse-face
1914   "m" gnus-summary-mail-other-window
1915   "a" gnus-summary-post-news
1916   "x" gnus-summary-limit-to-unread
1917   "s" gnus-summary-isearch-article
1918   "\t" gnus-summary-widget-forward
1919   [backtab] gnus-summary-widget-backward
1920   "t" gnus-summary-toggle-header
1921   "g" gnus-summary-show-article
1922   "l" gnus-summary-goto-last-article
1923   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1924   "\C-d" gnus-summary-enter-digest-group
1925   "\M-\C-d" gnus-summary-read-document
1926   "\M-\C-e" gnus-summary-edit-parameters
1927   "\M-\C-a" gnus-summary-customize-parameters
1928   "\C-c\C-b" gnus-bug
1929   "*" gnus-cache-enter-article
1930   "\M-*" gnus-cache-remove-article
1931   "\M-&" gnus-summary-universal-argument
1932   "\C-l" gnus-recenter
1933   "I" gnus-summary-increase-score
1934   "L" gnus-summary-lower-score
1935   "\M-i" gnus-symbolic-argument
1936   "h" gnus-summary-select-article-buffer
1937
1938   "b" gnus-article-view-part
1939   "\M-t" gnus-summary-toggle-display-buttonized
1940
1941   "V" gnus-summary-score-map
1942   "X" gnus-uu-extract-map
1943   "S" gnus-summary-send-map)
1944
1945 ;; Sort of orthogonal keymap
1946 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1947   "t" gnus-summary-tick-article-forward
1948   "!" gnus-summary-tick-article-forward
1949   "d" gnus-summary-mark-as-read-forward
1950   "r" gnus-summary-mark-as-read-forward
1951   "c" gnus-summary-clear-mark-forward
1952   " " gnus-summary-clear-mark-forward
1953   "e" gnus-summary-mark-as-expirable
1954   "x" gnus-summary-mark-as-expirable
1955   "?" gnus-summary-mark-as-dormant
1956   "b" gnus-summary-set-bookmark
1957   "B" gnus-summary-remove-bookmark
1958   "#" gnus-summary-mark-as-processable
1959   "\M-#" gnus-summary-unmark-as-processable
1960   "S" gnus-summary-limit-include-expunged
1961   "C" gnus-summary-catchup
1962   "H" gnus-summary-catchup-to-here
1963   "h" gnus-summary-catchup-from-here
1964   "\C-c" gnus-summary-catchup-all
1965   "k" gnus-summary-kill-same-subject-and-select
1966   "K" gnus-summary-kill-same-subject
1967   "P" gnus-uu-mark-map)
1968
1969 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1970   "c" gnus-summary-clear-above
1971   "u" gnus-summary-tick-above
1972   "m" gnus-summary-mark-above
1973   "k" gnus-summary-kill-below)
1974
1975 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1976   "/" gnus-summary-limit-to-subject
1977   "n" gnus-summary-limit-to-articles
1978   "b" gnus-summary-limit-to-bodies
1979   "h" gnus-summary-limit-to-headers
1980   "w" gnus-summary-pop-limit
1981   "s" gnus-summary-limit-to-subject
1982   "a" gnus-summary-limit-to-author
1983   "u" gnus-summary-limit-to-unread
1984   "m" gnus-summary-limit-to-marks
1985   "M" gnus-summary-limit-exclude-marks
1986   "v" gnus-summary-limit-to-score
1987   "*" gnus-summary-limit-include-cached
1988   "D" gnus-summary-limit-include-dormant
1989   "T" gnus-summary-limit-include-thread
1990   "d" gnus-summary-limit-exclude-dormant
1991   "t" gnus-summary-limit-to-age
1992   "." gnus-summary-limit-to-unseen
1993   "x" gnus-summary-limit-to-extra
1994   "p" gnus-summary-limit-to-display-predicate
1995   "E" gnus-summary-limit-include-expunged
1996   "c" gnus-summary-limit-exclude-childless-dormant
1997   "C" gnus-summary-limit-mark-excluded-as-read
1998   "o" gnus-summary-insert-old-articles
1999   "N" gnus-summary-insert-new-articles
2000   "S" gnus-summary-limit-to-singletons
2001   "r" gnus-summary-limit-to-replied
2002   "R" gnus-summary-limit-to-recipient
2003   "A" gnus-summary-limit-to-address)
2004
2005 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
2006   "n" gnus-summary-next-unread-article
2007   "p" gnus-summary-prev-unread-article
2008   "N" gnus-summary-next-article
2009   "P" gnus-summary-prev-article
2010   "\C-n" gnus-summary-next-same-subject
2011   "\C-p" gnus-summary-prev-same-subject
2012   "\M-n" gnus-summary-next-unread-subject
2013   "\M-p" gnus-summary-prev-unread-subject
2014   "f" gnus-summary-first-unread-article
2015   "b" gnus-summary-best-unread-article
2016   "j" gnus-summary-goto-article
2017   "g" gnus-summary-goto-subject
2018   "l" gnus-summary-goto-last-article
2019   "o" gnus-summary-pop-article)
2020
2021 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
2022   "k" gnus-summary-kill-thread
2023   "E" gnus-summary-expire-thread
2024   "l" gnus-summary-lower-thread
2025   "i" gnus-summary-raise-thread
2026   "T" gnus-summary-toggle-threads
2027   "t" gnus-summary-rethread-current
2028   "^" gnus-summary-reparent-thread
2029   "\M-^" gnus-summary-reparent-children
2030   "s" gnus-summary-show-thread
2031   "S" gnus-summary-show-all-threads
2032   "h" gnus-summary-hide-thread
2033   "H" gnus-summary-hide-all-threads
2034   "n" gnus-summary-next-thread
2035   "p" gnus-summary-prev-thread
2036   "u" gnus-summary-up-thread
2037   "o" gnus-summary-top-thread
2038   "d" gnus-summary-down-thread
2039   "#" gnus-uu-mark-thread
2040   "\M-#" gnus-uu-unmark-thread)
2041
2042 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
2043   "g" gnus-summary-prepare
2044   "c" gnus-summary-insert-cached-articles
2045   "d" gnus-summary-insert-dormant-articles
2046   "t" gnus-summary-insert-ticked-articles)
2047
2048 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
2049   "c" gnus-summary-catchup-and-exit
2050   "C" gnus-summary-catchup-all-and-exit
2051   "E" gnus-summary-exit-no-update
2052   "Q" gnus-summary-exit
2053   "Z" gnus-summary-exit
2054   "n" gnus-summary-catchup-and-goto-next-group
2055   "p" gnus-summary-catchup-and-goto-prev-group
2056   "R" gnus-summary-reselect-current-group
2057   "G" gnus-summary-rescan-group
2058   "N" gnus-summary-next-group
2059   "s" gnus-summary-save-newsrc
2060   "P" gnus-summary-prev-group)
2061
2062 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
2063   " " gnus-summary-next-page
2064   "n" gnus-summary-next-page
2065   "\177" gnus-summary-prev-page
2066   [delete] gnus-summary-prev-page
2067   "p" gnus-summary-prev-page
2068   "\r" gnus-summary-scroll-up
2069   "\M-\r" gnus-summary-scroll-down
2070   "<" gnus-summary-beginning-of-article
2071   ">" gnus-summary-end-of-article
2072   "b" gnus-summary-beginning-of-article
2073   "e" gnus-summary-end-of-article
2074   "^" gnus-summary-refer-parent-article
2075   "r" gnus-summary-refer-parent-article
2076   "C" gnus-summary-show-complete-article
2077   "D" gnus-summary-enter-digest-group
2078   "R" gnus-summary-refer-references
2079   "T" gnus-summary-refer-thread
2080   "W" gnus-warp-to-article
2081   "g" gnus-summary-show-article
2082   "s" gnus-summary-isearch-article
2083   "\t" gnus-summary-widget-forward
2084   [backtab] gnus-summary-widget-backward
2085   "P" gnus-summary-print-article
2086   "S" gnus-sticky-article
2087   "M" gnus-mailing-list-insinuate
2088   "t" gnus-article-babel)
2089
2090 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2091   "b" gnus-article-add-buttons
2092   "B" gnus-article-add-buttons-to-head
2093   "o" gnus-article-treat-overstrike
2094   "e" gnus-article-emphasize
2095   "w" gnus-article-fill-cited-article
2096   "Q" gnus-article-fill-long-lines
2097   "L" gnus-article-toggle-truncate-lines
2098   "C" gnus-article-capitalize-sentences
2099   "c" gnus-article-remove-cr
2100   "q" gnus-article-de-quoted-unreadable
2101   "6" gnus-article-de-base64-unreadable
2102   "Z" gnus-article-decode-HZ
2103   "A" gnus-article-treat-ansi-sequences
2104   "h" gnus-article-wash-html
2105   "u" gnus-article-unsplit-urls
2106   "s" gnus-summary-force-verify-and-decrypt
2107   "f" gnus-article-display-x-face
2108   "l" gnus-summary-stop-page-breaking
2109   "r" gnus-summary-caesar-message
2110   "m" gnus-summary-morse-message
2111   "t" gnus-summary-toggle-header
2112   "g" gnus-treat-smiley
2113   "v" gnus-summary-verbose-headers
2114   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2115   "p" gnus-article-verify-x-pgp-sig
2116   "d" gnus-article-treat-dumbquotes
2117   "U" gnus-article-treat-non-ascii
2118   "i" gnus-summary-idna-message)
2119
2120 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2121   ;; mnemonic: deuglif*Y*
2122   "u" gnus-article-outlook-unwrap-lines
2123   "a" gnus-article-outlook-repair-attribution
2124   "c" gnus-article-outlook-rearrange-citation
2125   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2126
2127 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2128   "a" gnus-article-hide
2129   "h" gnus-article-hide-headers
2130   "b" gnus-article-hide-boring-headers
2131   "s" gnus-article-hide-signature
2132   "c" gnus-article-hide-citation
2133   "C" gnus-article-hide-citation-in-followups
2134   "l" gnus-article-hide-list-identifiers
2135   "B" gnus-article-strip-banner
2136   "P" gnus-article-hide-pem
2137   "\C-c" gnus-article-hide-citation-maybe)
2138
2139 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2140   "a" gnus-article-highlight
2141   "h" gnus-article-highlight-headers
2142   "c" gnus-article-highlight-citation
2143   "s" gnus-article-highlight-signature)
2144
2145 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2146   "f" gnus-article-treat-fold-headers
2147   "u" gnus-article-treat-unfold-headers
2148   "n" gnus-article-treat-fold-newsgroups)
2149
2150 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2151   "x" gnus-article-display-x-face
2152   "d" gnus-article-display-face
2153   "s" gnus-treat-smiley
2154   "D" gnus-article-remove-images
2155   "W" gnus-article-show-images
2156   "f" gnus-treat-from-picon
2157   "m" gnus-treat-mail-picon
2158   "n" gnus-treat-newsgroups-picon
2159   "g" gnus-treat-from-gravatar
2160   "h" gnus-treat-mail-gravatar)
2161
2162 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2163   "w" gnus-article-decode-mime-words
2164   "c" gnus-article-decode-charset
2165   "v" gnus-mime-view-all-parts
2166   "b" gnus-article-view-part)
2167
2168 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2169   "z" gnus-article-date-ut
2170   "u" gnus-article-date-ut
2171   "l" gnus-article-date-local
2172   "p" gnus-article-date-english
2173   "e" gnus-article-date-lapsed
2174   "o" gnus-article-date-original
2175   "i" gnus-article-date-iso8601
2176   "s" gnus-article-date-user)
2177
2178 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2179   "t" gnus-article-remove-trailing-blank-lines
2180   "l" gnus-article-strip-leading-blank-lines
2181   "m" gnus-article-strip-multiple-blank-lines
2182   "a" gnus-article-strip-blank-lines
2183   "A" gnus-article-strip-all-blank-lines
2184   "s" gnus-article-strip-leading-space
2185   "e" gnus-article-strip-trailing-space
2186   "w" gnus-article-remove-leading-whitespace)
2187
2188 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2189   "v" gnus-version
2190   "d" gnus-summary-describe-group
2191   "h" gnus-summary-describe-briefly
2192   "i" gnus-info-find-node)
2193
2194 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2195   "e" gnus-summary-expire-articles
2196   "\M-\C-e" gnus-summary-expire-articles-now
2197   "\177" gnus-summary-delete-article
2198   [delete] gnus-summary-delete-article
2199   [backspace] gnus-summary-delete-article
2200   "m" gnus-summary-move-article
2201   "r" gnus-summary-respool-article
2202   "w" gnus-summary-edit-article
2203   "c" gnus-summary-copy-article
2204   "B" gnus-summary-crosspost-article
2205   "q" gnus-summary-respool-query
2206   "t" gnus-summary-respool-trace
2207   "i" gnus-summary-import-article
2208   "I" gnus-summary-create-article
2209   "p" gnus-summary-article-posted-p)
2210
2211 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2212   "o" gnus-summary-save-article
2213   "m" gnus-summary-save-article-mail
2214   "F" gnus-summary-write-article-file
2215   "r" gnus-summary-save-article-rmail
2216   "f" gnus-summary-save-article-file
2217   "b" gnus-summary-save-article-body-file
2218   "B" gnus-summary-write-article-body-file
2219   "h" gnus-summary-save-article-folder
2220   "v" gnus-summary-save-article-vm
2221   "p" gnus-summary-pipe-output
2222   "P" gnus-summary-muttprint)
2223
2224 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2225   "b" gnus-summary-display-buttonized
2226   "m" gnus-summary-repair-multipart
2227   "v" gnus-article-view-part
2228   "o" gnus-article-save-part
2229   "O" gnus-article-save-part-and-strip
2230   "r" gnus-article-replace-part
2231   "d" gnus-article-delete-part
2232   "t" gnus-article-view-part-as-type
2233   "j" gnus-article-jump-to-part
2234   "c" gnus-article-copy-part
2235   "C" gnus-article-view-part-as-charset
2236   "e" gnus-article-view-part-externally
2237   "H" gnus-article-browse-html-article
2238   "E" gnus-article-encrypt-body
2239   "i" gnus-article-inline-part
2240   "|" gnus-article-pipe-part)
2241
2242 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2243   "p" gnus-summary-mark-as-processable
2244   "u" gnus-summary-unmark-as-processable
2245   "U" gnus-summary-unmark-all-processable
2246   "v" gnus-uu-mark-over
2247   "s" gnus-uu-mark-series
2248   "r" gnus-uu-mark-region
2249   "g" gnus-uu-unmark-region
2250   "R" gnus-uu-mark-by-regexp
2251   "G" gnus-uu-unmark-by-regexp
2252   "t" gnus-uu-mark-thread
2253   "T" gnus-uu-unmark-thread
2254   "a" gnus-uu-mark-all
2255   "b" gnus-uu-mark-buffer
2256   "S" gnus-uu-mark-sparse
2257   "k" gnus-summary-kill-process-mark
2258   "y" gnus-summary-yank-process-mark
2259   "w" gnus-summary-save-process-mark
2260   "i" gnus-uu-invert-processable)
2261
2262 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2263   ;;"x" gnus-uu-extract-any
2264   "m" gnus-summary-save-parts
2265   "u" gnus-uu-decode-uu
2266   "U" gnus-uu-decode-uu-and-save
2267   "s" gnus-uu-decode-unshar
2268   "S" gnus-uu-decode-unshar-and-save
2269   "o" gnus-uu-decode-save
2270   "O" gnus-uu-decode-save
2271   "b" gnus-uu-decode-binhex
2272   "B" gnus-uu-decode-binhex
2273   "Y" gnus-uu-decode-yenc
2274   "p" gnus-uu-decode-postscript
2275   "P" gnus-uu-decode-postscript-and-save)
2276
2277 (gnus-define-keys
2278     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2279   "u" gnus-uu-decode-uu-view
2280   "U" gnus-uu-decode-uu-and-save-view
2281   "s" gnus-uu-decode-unshar-view
2282   "S" gnus-uu-decode-unshar-and-save-view
2283   "o" gnus-uu-decode-save-view
2284   "O" gnus-uu-decode-save-view
2285   "b" gnus-uu-decode-binhex-view
2286   "B" gnus-uu-decode-binhex-view
2287   "p" gnus-uu-decode-postscript-view
2288   "P" gnus-uu-decode-postscript-and-save-view)
2289
2290 (defvar gnus-article-post-menu nil)
2291
2292 (defconst gnus-summary-menu-maxlen 20)
2293
2294 (defun gnus-summary-menu-split (menu)
2295   ;; If we have lots of elements, divide them into groups of 20
2296   ;; and make a pane (or submenu) for each one.
2297   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2298       (let ((menu menu) sublists next
2299             (i 1))
2300         (while menu
2301           ;; Pull off the next gnus-summary-menu-maxlen elements
2302           ;; and make them the next element of sublist.
2303           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2304           (if next
2305               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2306                       nil))
2307           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2308                                              (aref (car (last menu)) 0)) menu)
2309                                sublists))
2310           (setq i (1+ i))
2311           (setq menu next))
2312         (nreverse sublists))
2313     ;; Few elements--put them all in one pane.
2314     menu))
2315
2316 (defun gnus-summary-make-menu-bar ()
2317   (gnus-turn-off-edit-menu 'summary)
2318
2319   (unless (boundp 'gnus-summary-misc-menu)
2320
2321     (easy-menu-define
2322       gnus-summary-kill-menu gnus-summary-mode-map ""
2323       (cons
2324        "Score"
2325        (nconc
2326         (list
2327          ["Customize" gnus-score-customize t])
2328         (gnus-make-score-map 'increase)
2329         (gnus-make-score-map 'lower)
2330         '(("Mark"
2331            ["Kill below" gnus-summary-kill-below t]
2332            ["Mark above" gnus-summary-mark-above t]
2333            ["Tick above" gnus-summary-tick-above t]
2334            ["Clear above" gnus-summary-clear-above t])
2335           ["Current score" gnus-summary-current-score t]
2336           ["Set score" gnus-summary-set-score t]
2337           ["Switch current score file..." gnus-score-change-score-file t]
2338           ["Set mark below..." gnus-score-set-mark-below t]
2339           ["Set expunge below..." gnus-score-set-expunge-below t]
2340           ["Edit current score file" gnus-score-edit-current-scores t]
2341           ["Edit score file..." gnus-score-edit-file t]
2342           ["Trace score" gnus-score-find-trace t]
2343           ["Find words" gnus-score-find-favourite-words t]
2344           ["Rescore buffer" gnus-summary-rescore t]
2345           ["Increase score..." gnus-summary-increase-score t]
2346           ["Lower score..." gnus-summary-lower-score t]))))
2347
2348     ;; Define both the Article menu in the summary buffer and the
2349     ;; equivalent Commands menu in the article buffer here for
2350     ;; consistency.
2351     (let ((innards
2352            `(("Hide"
2353               ["All" gnus-article-hide t]
2354               ["Headers" gnus-article-hide-headers t]
2355               ["Signature" gnus-article-hide-signature t]
2356               ["Citation" gnus-article-hide-citation t]
2357               ["List identifiers" gnus-article-hide-list-identifiers t]
2358               ["Banner" gnus-article-strip-banner t]
2359               ["Boring headers" gnus-article-hide-boring-headers t])
2360              ("Highlight"
2361               ["All" gnus-article-highlight t]
2362               ["Headers" gnus-article-highlight-headers t]
2363               ["Signature" gnus-article-highlight-signature t]
2364               ["Citation" gnus-article-highlight-citation t])
2365              ("MIME"
2366               ["Words" gnus-article-decode-mime-words t]
2367               ["Charset" gnus-article-decode-charset t]
2368               ["QP" gnus-article-de-quoted-unreadable t]
2369               ["Base64" gnus-article-de-base64-unreadable t]
2370               ["View MIME buttons" gnus-summary-display-buttonized t]
2371               ["View all" gnus-mime-view-all-parts t]
2372               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2373               ["Encrypt body" gnus-article-encrypt-body
2374                :active (not (gnus-group-read-only-p))
2375                ,@(if (featurep 'xemacs) nil
2376                    '(:help "Encrypt the message body on disk"))]
2377               ["Extract all parts..." gnus-summary-save-parts t]
2378               ("Multipart"
2379                ["Repair multipart" gnus-summary-repair-multipart t]
2380                ["Pipe part..." gnus-article-pipe-part t]
2381                ["Inline part" gnus-article-inline-part t]
2382                ["View part as type..." gnus-article-view-part-as-type t]
2383                ["Encrypt body" gnus-article-encrypt-body
2384                 :active (not (gnus-group-read-only-p))
2385                ,@(if (featurep 'xemacs) nil
2386                    '(:help "Encrypt the message body on disk"))]
2387                ["View part externally" gnus-article-view-part-externally t]
2388                ["View HTML parts in browser" gnus-article-browse-html-article t]
2389                ["View part with charset..." gnus-article-view-part-as-charset t]
2390                ["Copy part" gnus-article-copy-part t]
2391                ["Save part..." gnus-article-save-part t]
2392                ["View part" gnus-article-view-part t]))
2393              ("Date"
2394               ["Local" gnus-article-date-local t]
2395               ["ISO8601" gnus-article-date-iso8601 t]
2396               ["UT" gnus-article-date-ut t]
2397               ["Original" gnus-article-date-original t]
2398               ["Lapsed" gnus-article-date-lapsed t]
2399               ["User-defined" gnus-article-date-user t])
2400              ("Display"
2401               ["Remove images" gnus-article-remove-images t]
2402               ["Toggle smiley" gnus-treat-smiley t]
2403               ["Show X-Face" gnus-article-display-x-face t]
2404               ["Show picons in From" gnus-treat-from-picon t]
2405               ["Show picons in mail headers" gnus-treat-mail-picon t]
2406               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2407               ["Show Gravatars in From" gnus-treat-from-gravatar t]
2408               ["Show Gravatars in mail headers" gnus-treat-mail-gravatar t]
2409               ("View as different encoding"
2410                ,@(gnus-summary-menu-split
2411                   (mapcar
2412                    (lambda (cs)
2413                      ;; Since easymenu under Emacs doesn't allow
2414                      ;; lambda forms for menu commands, we should
2415                      ;; provide intern'ed function symbols.
2416                      (let ((command (intern (format "\
2417 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2418                        (fset command
2419                              `(lambda ()
2420                                 (interactive)
2421                                 (let ((gnus-summary-show-article-charset-alist
2422                                        '((1 . ,cs))))
2423                                   (gnus-summary-show-article 1))))
2424                        `[,(symbol-name cs) ,command t]))
2425                    (sort (if (fboundp 'coding-system-list)
2426                              (coding-system-list)
2427                            (mapcar 'car mm-mime-mule-charset-alist))
2428                          'string<)))))
2429              ("Washing"
2430               ("Remove Blanks"
2431                ["Leading" gnus-article-strip-leading-blank-lines t]
2432                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2433                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2434                ["All of the above" gnus-article-strip-blank-lines t]
2435                ["All" gnus-article-strip-all-blank-lines t]
2436                ["Leading space" gnus-article-strip-leading-space t]
2437                ["Trailing space" gnus-article-strip-trailing-space t]
2438                ["Leading space in headers"
2439                 gnus-article-remove-leading-whitespace t])
2440               ["Overstrike" gnus-article-treat-overstrike t]
2441               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2442               ["Non-ASCII" gnus-article-treat-non-ascii t]
2443               ["Emphasis" gnus-article-emphasize t]
2444               ["Word wrap" gnus-article-fill-cited-article t]
2445               ["Fill long lines" gnus-article-fill-long-lines t]
2446               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2447               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2448               ["Remove CR" gnus-article-remove-cr t]
2449               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2450               ["Base64" gnus-article-de-base64-unreadable t]
2451               ["Rot 13" gnus-summary-caesar-message
2452                ,@(if (featurep 'xemacs) '(t)
2453                    '(:help "\"Caesar rotate\" article by 13"))]
2454               ["De-IDNA" gnus-summary-idna-message t]
2455               ["Morse decode" gnus-summary-morse-message t]
2456               ["Unix pipe..." gnus-summary-pipe-message t]
2457               ["Add buttons" gnus-article-add-buttons t]
2458               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2459               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2460               ["Verbose header" gnus-summary-verbose-headers t]
2461               ["Toggle header" gnus-summary-toggle-header t]
2462               ["Unfold headers" gnus-article-treat-unfold-headers t]
2463               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2464               ["Html" gnus-article-wash-html t]
2465               ["Unsplit URLs" gnus-article-unsplit-urls t]
2466               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2467               ["Decode HZ" gnus-article-decode-HZ t]
2468               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2469               ("(Outlook) Deuglify"
2470                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2471                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2472                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2473                ["Full (Outlook) deuglify"
2474                 gnus-article-outlook-deuglify-article t])
2475               )
2476              ("Output"
2477               ["Save in default format..." gnus-summary-save-article
2478                ,@(if (featurep 'xemacs) '(t)
2479                    '(:help "Save article using default method"))]
2480               ["Save in file..." gnus-summary-save-article-file
2481                ,@(if (featurep 'xemacs) '(t)
2482                    '(:help "Save article in file"))]
2483               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2484               ["Save in MH folder..." gnus-summary-save-article-folder t]
2485               ["Save in VM folder..." gnus-summary-save-article-vm t]
2486               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2487               ["Save body in file..." gnus-summary-save-article-body-file t]
2488               ["Pipe through a filter..." gnus-summary-pipe-output t]
2489               ["Print with Muttprint..." gnus-summary-muttprint t]
2490               ["Print" gnus-summary-print-article
2491                ,@(if (featurep 'xemacs) '(t)
2492                    '(:help "Generate and print a PostScript image"))])
2493              ("Copy, move,... (Backend)"
2494               ,@(if (featurep 'xemacs) nil
2495                   '(:help "Copying, moving, expiring articles..."))
2496               ["Respool article..." gnus-summary-respool-article t]
2497               ["Move article..." gnus-summary-move-article
2498                (gnus-check-backend-function
2499                 'request-move-article gnus-newsgroup-name)]
2500               ["Copy article..." gnus-summary-copy-article t]
2501               ["Crosspost article..." gnus-summary-crosspost-article
2502                (gnus-check-backend-function
2503                 'request-replace-article gnus-newsgroup-name)]
2504               ["Import file..." gnus-summary-import-article
2505                (gnus-check-backend-function
2506                 'request-accept-article gnus-newsgroup-name)]
2507               ["Create article..." gnus-summary-create-article
2508                (gnus-check-backend-function
2509                 'request-accept-article gnus-newsgroup-name)]
2510               ["Check if posted" gnus-summary-article-posted-p t]
2511               ["Edit article" gnus-summary-edit-article
2512                (not (gnus-group-read-only-p))]
2513               ["Delete article" gnus-summary-delete-article
2514                (gnus-check-backend-function
2515                 'request-expire-articles gnus-newsgroup-name)]
2516               ["Query respool" gnus-summary-respool-query t]
2517               ["Trace respool" gnus-summary-respool-trace t]
2518               ["Delete expirable articles" gnus-summary-expire-articles-now
2519                (gnus-check-backend-function
2520                 'request-expire-articles gnus-newsgroup-name)])
2521              ("Extract"
2522               ["Uudecode" gnus-uu-decode-uu
2523                ,@(if (featurep 'xemacs) '(t)
2524                    '(:help "Decode uuencoded article(s)"))]
2525               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2526               ["Unshar" gnus-uu-decode-unshar t]
2527               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2528               ["Save" gnus-uu-decode-save t]
2529               ["Binhex" gnus-uu-decode-binhex t]
2530               ["PostScript" gnus-uu-decode-postscript t]
2531               ["All MIME parts" gnus-summary-save-parts t])
2532              ("Cache"
2533               ["Enter article" gnus-cache-enter-article t]
2534               ["Remove article" gnus-cache-remove-article t])
2535              ["Translate" gnus-article-babel t]
2536              ["Select article buffer" gnus-summary-select-article-buffer t]
2537              ["Make article buffer sticky" gnus-sticky-article t]
2538              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2539              ["Isearch article..." gnus-summary-isearch-article t]
2540              ["Beginning of the article" gnus-summary-beginning-of-article t]
2541              ["End of the article" gnus-summary-end-of-article t]
2542              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2543              ["Fetch referenced articles" gnus-summary-refer-references t]
2544              ["Fetch current thread" gnus-summary-refer-thread t]
2545              ["Fetch article with id..." gnus-summary-refer-article t]
2546              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2547              ["Redisplay" gnus-summary-show-article t]
2548              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2549       (easy-menu-define
2550         gnus-summary-article-menu gnus-summary-mode-map ""
2551         (cons "Article" innards))
2552
2553       (if (not (keymapp gnus-summary-article-menu))
2554           (easy-menu-define
2555             gnus-article-commands-menu gnus-article-mode-map ""
2556             (cons "Commands" innards))
2557         ;; in Emacs, don't share menu.
2558         (setq gnus-article-commands-menu
2559               (copy-keymap gnus-summary-article-menu))
2560         (define-key gnus-article-mode-map [menu-bar commands]
2561           (cons "Commands" gnus-article-commands-menu))))
2562
2563     (easy-menu-define
2564       gnus-summary-thread-menu gnus-summary-mode-map ""
2565       '("Threads"
2566         ["Find all messages in thread" gnus-summary-refer-thread t]
2567         ["Toggle threading" gnus-summary-toggle-threads t]
2568         ["Hide threads" gnus-summary-hide-all-threads t]
2569         ["Show threads" gnus-summary-show-all-threads t]
2570         ["Hide thread" gnus-summary-hide-thread t]
2571         ["Show thread" gnus-summary-show-thread t]
2572         ["Go to next thread" gnus-summary-next-thread t]
2573         ["Go to previous thread" gnus-summary-prev-thread t]
2574         ["Go down thread" gnus-summary-down-thread t]
2575         ["Go up thread" gnus-summary-up-thread t]
2576         ["Top of thread" gnus-summary-top-thread t]
2577         ["Mark thread as read" gnus-summary-kill-thread t]
2578         ["Mark thread as expired" gnus-summary-expire-thread t]
2579         ["Lower thread score" gnus-summary-lower-thread t]
2580         ["Raise thread score" gnus-summary-raise-thread t]
2581         ["Rethread current" gnus-summary-rethread-current t]))
2582
2583     (easy-menu-define
2584       gnus-summary-post-menu gnus-summary-mode-map ""
2585       `("Post"
2586         ["Send a message (mail or news)" gnus-summary-post-news
2587          ,@(if (featurep 'xemacs) '(t)
2588              '(:help "Compose a new message (mail or news)"))]
2589         ["Followup" gnus-summary-followup
2590          ,@(if (featurep 'xemacs) '(t)
2591              '(:help "Post followup to this article"))]
2592         ["Followup and yank" gnus-summary-followup-with-original
2593          ,@(if (featurep 'xemacs) '(t)
2594              '(:help "Post followup to this article, quoting its contents"))]
2595         ["Supersede article" gnus-summary-supersede-article t]
2596         ["Cancel article" gnus-summary-cancel-article
2597          ,@(if (featurep 'xemacs) '(t)
2598              '(:help "Cancel an article you posted"))]
2599         ["Reply" gnus-summary-reply t]
2600         ["Reply and yank" gnus-summary-reply-with-original t]
2601         ["Wide reply" gnus-summary-wide-reply t]
2602         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2603          ,@(if (featurep 'xemacs) '(t)
2604              '(:help "Mail a reply, quoting this article"))]
2605         ["Very wide reply" gnus-summary-very-wide-reply t]
2606         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2607          ,@(if (featurep 'xemacs) '(t)
2608              '(:help "Mail a very wide reply, quoting this article"))]
2609         ["Mail forward" gnus-summary-mail-forward t]
2610         ["Post forward" gnus-summary-post-forward t]
2611         ["Digest and mail" gnus-uu-digest-mail-forward t]
2612         ["Digest and post" gnus-uu-digest-post-forward t]
2613         ["Resend message" gnus-summary-resend-message t]
2614         ["Resend message edit" gnus-summary-resend-message-edit t]
2615         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2616         ["Send a mail" gnus-summary-mail-other-window t]
2617         ["Create a local message" gnus-summary-news-other-window t]
2618         ["Uuencode and post" gnus-uu-post-news
2619          ,@(if (featurep 'xemacs) '(t)
2620              '(:help "Post a uuencoded article"))]
2621         ["Followup via news" gnus-summary-followup-to-mail t]
2622         ["Followup via news and yank"
2623          gnus-summary-followup-to-mail-with-original t]
2624         ["Strip signature on reply"
2625          (lambda ()
2626            (interactive)
2627            (if (not (memq message-cite-function
2628                           '(message-cite-original-without-signature
2629                             message-cite-original)))
2630                ;; Stupid workaround for XEmacs not honoring :visible.
2631                (message "Can't toggle this value of `message-cite-function'")
2632              (setq message-cite-function
2633                    (if (eq message-cite-function
2634                            'message-cite-original-without-signature)
2635                        'message-cite-original
2636                      'message-cite-original-without-signature))))
2637          ;; XEmacs barfs on :visible.
2638          ,@(if (featurep 'xemacs) nil
2639              '(:visible (memq message-cite-function
2640                               '(message-cite-original-without-signature
2641                                 message-cite-original))))
2642          :style toggle
2643          :selected (eq message-cite-function
2644                        'message-cite-original-without-signature)
2645          ,@(if (featurep 'xemacs) nil
2646              '(:help "Strip signature from cited article when replying."))]
2647         ;;("Draft"
2648         ;;["Send" gnus-summary-send-draft t]
2649         ;;["Send bounced" gnus-resend-bounced-mail t])
2650         ))
2651
2652     (cond
2653      ((not (keymapp gnus-summary-post-menu))
2654       (setq gnus-article-post-menu gnus-summary-post-menu))
2655      ((not gnus-article-post-menu)
2656       ;; Don't share post menu.
2657       (setq gnus-article-post-menu
2658             (copy-keymap gnus-summary-post-menu))))
2659     (define-key gnus-article-mode-map [menu-bar post]
2660       (cons "Post" gnus-article-post-menu))
2661
2662     (easy-menu-define
2663       gnus-summary-misc-menu gnus-summary-mode-map ""
2664       `("Gnus"
2665         ("Mark Read"
2666          ["Mark as read" gnus-summary-mark-as-read-forward t]
2667          ["Mark same subject and select"
2668           gnus-summary-kill-same-subject-and-select t]
2669          ["Mark same subject" gnus-summary-kill-same-subject t]
2670          ["Catchup" gnus-summary-catchup
2671           ,@(if (featurep 'xemacs) '(t)
2672               '(:help "Mark unread articles in this group as read"))]
2673          ["Catchup all" gnus-summary-catchup-all t]
2674          ["Catchup to here" gnus-summary-catchup-to-here t]
2675          ["Catchup from here" gnus-summary-catchup-from-here t]
2676          ["Catchup region" gnus-summary-mark-region-as-read
2677           (gnus-mark-active-p)]
2678          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2679         ("Mark Various"
2680          ["Tick" gnus-summary-tick-article-forward t]
2681          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2682          ["Remove marks" gnus-summary-clear-mark-forward t]
2683          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2684          ["Set bookmark" gnus-summary-set-bookmark t]
2685          ["Remove bookmark" gnus-summary-remove-bookmark t])
2686         ("Limit to"
2687          ["Marks..." gnus-summary-limit-to-marks t]
2688          ["Subject..." gnus-summary-limit-to-subject t]
2689          ["Author..." gnus-summary-limit-to-author t]
2690          ["Recipient..." gnus-summary-limit-to-recipient t]
2691          ["Address..." gnus-summary-limit-to-address t]
2692          ["Age..." gnus-summary-limit-to-age t]
2693          ["Extra..." gnus-summary-limit-to-extra t]
2694          ["Score..." gnus-summary-limit-to-score t]
2695          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2696          ["Unread" gnus-summary-limit-to-unread t]
2697          ["Unseen" gnus-summary-limit-to-unseen t]
2698          ["Singletons" gnus-summary-limit-to-singletons t]
2699          ["Replied" gnus-summary-limit-to-replied t]
2700          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2701          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2702          ["Pop limit" gnus-summary-pop-limit t]
2703          ["Show dormant" gnus-summary-limit-include-dormant t]
2704          ["Hide childless dormant"
2705           gnus-summary-limit-exclude-childless-dormant t]
2706          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2707          ["Hide marked" gnus-summary-limit-exclude-marks t]
2708          ["Show expunged" gnus-summary-limit-include-expunged t])
2709         ("Process Mark"
2710          ["Set mark" gnus-summary-mark-as-processable t]
2711          ["Remove mark" gnus-summary-unmark-as-processable t]
2712          ["Remove all marks" gnus-summary-unmark-all-processable t]
2713          ["Invert marks" gnus-uu-invert-processable t]
2714          ["Mark above" gnus-uu-mark-over t]
2715          ["Mark series" gnus-uu-mark-series t]
2716          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2717          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2718          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2719          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2720          ["Mark all" gnus-uu-mark-all t]
2721          ["Mark buffer" gnus-uu-mark-buffer t]
2722          ["Mark sparse" gnus-uu-mark-sparse t]
2723          ["Mark thread" gnus-uu-mark-thread t]
2724          ["Unmark thread" gnus-uu-unmark-thread t]
2725          ("Process Mark Sets"
2726           ["Kill" gnus-summary-kill-process-mark t]
2727           ["Yank" gnus-summary-yank-process-mark
2728            gnus-newsgroup-process-stack]
2729           ["Save" gnus-summary-save-process-mark t]
2730           ["Run command on marked..." gnus-summary-universal-argument t]))
2731         ("Registry Marks")
2732         ("Scroll article"
2733          ["Page forward" gnus-summary-next-page
2734           ,@(if (featurep 'xemacs) '(t)
2735               '(:help "Show next page of article"))]
2736          ["Page backward" gnus-summary-prev-page
2737           ,@(if (featurep 'xemacs) '(t)
2738               '(:help "Show previous page of article"))]
2739          ["Line forward" gnus-summary-scroll-up t])
2740         ("Move"
2741          ["Next unread article" gnus-summary-next-unread-article t]
2742          ["Previous unread article" gnus-summary-prev-unread-article t]
2743          ["Next article" gnus-summary-next-article t]
2744          ["Previous article" gnus-summary-prev-article t]
2745          ["Next unread subject" gnus-summary-next-unread-subject t]
2746          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2747          ["Next article same subject" gnus-summary-next-same-subject t]
2748          ["Previous article same subject" gnus-summary-prev-same-subject t]
2749          ["First unread article" gnus-summary-first-unread-article t]
2750          ["Best unread article" gnus-summary-best-unread-article t]
2751          ["Go to subject number..." gnus-summary-goto-subject t]
2752          ["Go to article number..." gnus-summary-goto-article t]
2753          ["Go to the last article" gnus-summary-goto-last-article t]
2754          ["Pop article off history" gnus-summary-pop-article t])
2755         ("Sort"
2756          ["Sort by number" gnus-summary-sort-by-number t]
2757          ["Sort by most recent number" gnus-summary-sort-by-most-recent-number t]
2758          ["Sort by author" gnus-summary-sort-by-author t]
2759          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2760          ["Sort by subject" gnus-summary-sort-by-subject t]
2761          ["Sort by date" gnus-summary-sort-by-date t]
2762          ["Sort by most recent date" gnus-summary-sort-by-most-recent-date t]
2763          ["Sort by score" gnus-summary-sort-by-score t]
2764          ["Sort by lines" gnus-summary-sort-by-lines t]
2765          ["Sort by characters" gnus-summary-sort-by-chars t]
2766          ["Randomize" gnus-summary-sort-by-random t]
2767          ["Original sort" gnus-summary-sort-by-original t])
2768         ("Help"
2769          ["Describe group" gnus-summary-describe-group t]
2770          ["Read manual" gnus-info-find-node t])
2771         ("Modes"
2772          ["Pick and read" gnus-pick-mode t]
2773          ["Binary" gnus-binary-mode t])
2774         ("Regeneration"
2775          ["Regenerate" gnus-summary-prepare t]
2776          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2777          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2778          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2779          ["Toggle threading" gnus-summary-toggle-threads t])
2780         ["See old articles" gnus-summary-insert-old-articles t]
2781         ["See new articles" gnus-summary-insert-new-articles t]
2782         ["Filter articles..." gnus-summary-execute-command t]
2783         ["Run command on articles..." gnus-summary-universal-argument t]
2784         ["Search articles forward..." gnus-summary-search-article-forward t]
2785         ["Search articles backward..." gnus-summary-search-article-backward t]
2786         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2787         ["Expand window" gnus-summary-expand-window t]
2788         ["Expire expirable articles" gnus-summary-expire-articles
2789          (gnus-check-backend-function
2790           'request-expire-articles gnus-newsgroup-name)]
2791         ["Edit local kill file" gnus-summary-edit-local-kill t]
2792         ["Edit main kill file" gnus-summary-edit-global-kill t]
2793         ["Edit group parameters" gnus-summary-edit-parameters t]
2794         ["Customize group parameters" gnus-summary-customize-parameters t]
2795         ["Send a bug report" gnus-bug t]
2796         ("Exit"
2797          ["Catchup and exit" gnus-summary-catchup-and-exit
2798           ,@(if (featurep 'xemacs) '(t)
2799               '(:help "Mark unread articles in this group as read, then exit"))]
2800          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2801          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2802          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2803          ["Exit group" gnus-summary-exit
2804           ,@(if (featurep 'xemacs) '(t)
2805               '(:help "Exit current group, return to group selection mode"))]
2806          ["Exit group without updating" gnus-summary-exit-no-update t]
2807          ["Exit and goto next group" gnus-summary-next-group t]
2808          ["Exit and goto prev group" gnus-summary-prev-group t]
2809          ["Reselect group" gnus-summary-reselect-current-group t]
2810          ["Rescan group" gnus-summary-rescan-group t]
2811          ["Update dribble" gnus-summary-save-newsrc t])))
2812
2813     (gnus-run-hooks 'gnus-summary-menu-hook)))
2814
2815 (defvar gnus-summary-tool-bar-map nil)
2816
2817 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2818 ;; affect _new_ message buffers.  We might add a function that walks thru all
2819 ;; summary-mode buffers and force the update.
2820 (defun gnus-summary-tool-bar-update (&optional symbol value)
2821   "Update summary mode toolbar.
2822 Setter function for custom variables."
2823   (setq-default gnus-summary-tool-bar-map nil)
2824   (when symbol
2825     ;; When used as ":set" function:
2826     (set-default symbol value))
2827   (when (gnus-buffer-live-p gnus-summary-buffer)
2828     (with-current-buffer gnus-summary-buffer
2829       (gnus-summary-make-tool-bar))))
2830
2831 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2832                                      'gnus-summary-tool-bar-gnome
2833                                    'gnus-summary-tool-bar-retro)
2834   "Specifies the Gnus summary tool bar.
2835
2836 It can be either a list or a symbol referring to a list.  See
2837 `gmm-tool-bar-from-list' for the format of the list.  The
2838 default key map is `gnus-summary-mode-map'.
2839
2840 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2841 `gnus-summary-tool-bar-retro'."
2842   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2843                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2844                  (repeat :tag "User defined list" gmm-tool-bar-item)
2845                  (symbol))
2846   :version "23.1" ;; No Gnus
2847   :initialize 'custom-initialize-default
2848   :set 'gnus-summary-tool-bar-update
2849   :group 'gnus-summary)
2850
2851 (defcustom gnus-summary-tool-bar-gnome
2852   '((gnus-summary-post-news "mail/compose" nil)
2853     (gnus-summary-insert-new-articles "mail/inbox" nil
2854                                       :visible (or (not gnus-agent)
2855                                                    gnus-plugged))
2856     (gnus-summary-reply-with-original "mail/reply")
2857     (gnus-summary-reply "mail/reply" nil :visible nil)
2858     (gnus-summary-followup-with-original "mail/reply-all")
2859     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2860     (gnus-summary-mail-forward "mail/forward")
2861     (gnus-summary-save-article "mail/save")
2862     (gnus-summary-search-article-forward "search" nil :visible nil)
2863     (gnus-summary-print-article "print")
2864     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2865     ;; Some new commands that may need more suitable icons:
2866     (gnus-summary-save-newsrc "save" nil :visible nil)
2867     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2868     (gnus-summary-prev-article "left-arrow")
2869     (gnus-summary-next-article "right-arrow")
2870     (gnus-summary-next-page "next-page")
2871     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2872     ;;
2873     ;; Maybe some sort-by-... could be added:
2874     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2875     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2876     (gnus-summary-mark-as-expirable
2877      "delete" nil
2878      :visible (gnus-check-backend-function 'request-expire-articles
2879                                            gnus-newsgroup-name))
2880     (gnus-summary-mark-as-spam
2881      "mail/spam" t
2882      :visible (and (fboundp 'spam-group-ham-contents-p)
2883                    (spam-group-ham-contents-p gnus-newsgroup-name))
2884      :help "Mark as spam")
2885     (gnus-summary-mark-as-read-forward
2886      "mail/not-spam" nil
2887      :visible (and (fboundp 'spam-group-spam-contents-p)
2888                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2889     ;;
2890     (gnus-summary-exit "exit")
2891     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2892     (gnus-info-find-node "help"))
2893   "List of functions for the summary tool bar (GNOME style).
2894
2895 See `gmm-tool-bar-from-list' for the format of the list."
2896   :type '(repeat gmm-tool-bar-item)
2897   :version "23.1" ;; No Gnus
2898   :initialize 'custom-initialize-default
2899   :set 'gnus-summary-tool-bar-update
2900   :group 'gnus-summary)
2901
2902 (defcustom gnus-summary-tool-bar-retro
2903   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2904     (gnus-summary-next-unread-article "gnus/next-ur")
2905     (gnus-summary-post-news "gnus/post")
2906     (gnus-summary-followup-with-original "gnus/fuwo")
2907     (gnus-summary-followup "gnus/followup")
2908     (gnus-summary-reply-with-original "gnus/reply-wo")
2909     (gnus-summary-reply "gnus/reply")
2910     (gnus-summary-caesar-message "gnus/rot13")
2911     (gnus-uu-decode-uu "gnus/uu-decode")
2912     (gnus-summary-save-article-file "gnus/save-aif")
2913     (gnus-summary-save-article "gnus/save-art")
2914     (gnus-uu-post-news "gnus/uu-post")
2915     (gnus-summary-catchup "gnus/catchup")
2916     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2917     (gnus-summary-exit "gnus/exit-summ")
2918     ;; Some new command that may need more suitable icons:
2919     (gnus-summary-print-article "gnus/print" nil :visible nil)
2920     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2921     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2922     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2923     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2924     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2925     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2926     ;;
2927     (gnus-info-find-node "gnus/help" nil :visible nil))
2928   "List of functions for the summary tool bar (retro look).
2929
2930 See `gmm-tool-bar-from-list' for the format of the list."
2931   :type '(repeat gmm-tool-bar-item)
2932   :version "23.1" ;; No Gnus
2933   :initialize 'custom-initialize-default
2934   :set 'gnus-summary-tool-bar-update
2935   :group 'gnus-summary)
2936
2937 (defcustom gnus-summary-tool-bar-zap-list t
2938   "List of icon items from the global tool bar.
2939 These items are not displayed in the Gnus summary mode tool bar.
2940
2941 See `gmm-tool-bar-from-list' for the format of the list."
2942   :type 'gmm-tool-bar-zap-list
2943   :version "23.1" ;; No Gnus
2944   :initialize 'custom-initialize-default
2945   :set 'gnus-summary-tool-bar-update
2946   :group 'gnus-summary)
2947
2948 (defvar image-load-path)
2949 (defvar tool-bar-map)
2950
2951 (defun gnus-summary-make-tool-bar (&optional force)
2952   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2953 When FORCE, rebuild the tool bar."
2954   (when (and (not (featurep 'xemacs))
2955              (boundp 'tool-bar-mode)
2956              tool-bar-mode
2957              (or (not gnus-summary-tool-bar-map) force))
2958     (let* ((load-path
2959             (gmm-image-load-path-for-library "gnus"
2960                                              "mail/save.xpm"
2961                                              nil t))
2962            (image-load-path (cons (car load-path)
2963                                   (when (boundp 'image-load-path)
2964                                     image-load-path)))
2965            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2966                                         gnus-summary-tool-bar-zap-list
2967                                         'gnus-summary-mode-map)))
2968       (when map
2969         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2970         ;; uses its value.
2971         (setq gnus-summary-tool-bar-map map))))
2972   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2973
2974 (defun gnus-make-score-map (type)
2975   "Make a summary score map of type TYPE."
2976   (if t
2977       nil
2978     (let ((headers '(("author" "from" string)
2979                      ("subject" "subject" string)
2980                      ("article body" "body" string)
2981                      ("article head" "head" string)
2982                      ("xref" "xref" string)
2983                      ("extra header" "extra" string)
2984                      ("lines" "lines" number)
2985                      ("followups to author" "followup" string)))
2986           (types '((number ("less than" <)
2987                            ("greater than" >)
2988                            ("equal" =))
2989                    (string ("substring" s)
2990                            ("exact string" e)
2991                            ("fuzzy string" f)
2992                            ("regexp" r))))
2993           (perms '(("temporary" (current-time-string))
2994                    ("permanent" nil)
2995                    ("immediate" now)))
2996           header)
2997       (list
2998        (apply
2999         'nconc
3000         (list
3001          (if (eq type 'lower)
3002              "Lower score"
3003            "Increase score"))
3004         (let (outh)
3005           (while headers
3006             (setq header (car headers))
3007             (setq outh
3008                   (cons
3009                    (apply
3010                     'nconc
3011                     (list (car header))
3012                     (let ((ts (cdr (assoc (nth 2 header) types)))
3013                           outt)
3014                       (while ts
3015                         (setq outt
3016                               (cons
3017                                (apply
3018                                 'nconc
3019                                 (list (caar ts))
3020                                 (let ((ps perms)
3021                                       outp)
3022                                   (while ps
3023                                     (setq outp
3024                                           (cons
3025                                            (vector
3026                                             (caar ps)
3027                                             (list
3028                                              'gnus-summary-score-entry
3029                                              (nth 1 header)
3030                                              (if (or (string= (nth 1 header)
3031                                                               "head")
3032                                                      (string= (nth 1 header)
3033                                                               "body"))
3034                                                  ""
3035                                                (list 'gnus-summary-header
3036                                                      (nth 1 header)))
3037                                              (list 'quote (nth 1 (car ts)))
3038                                              (list 'gnus-score-delta-default
3039                                                    nil)
3040                                              (nth 1 (car ps))
3041                                              t)
3042                                             t)
3043                                            outp))
3044                                     (setq ps (cdr ps)))
3045                                   (list (nreverse outp))))
3046                                outt))
3047                         (setq ts (cdr ts)))
3048                       (list (nreverse outt))))
3049                    outh))
3050             (setq headers (cdr headers)))
3051           (list (nreverse outh))))))))
3052
3053
3054 (declare-function turn-on-gnus-mailing-list-mode "gnus-ml" ())
3055 (defvar bookmark-make-record-function)
3056 \f
3057 (defvar bidi-paragraph-direction)
3058
3059 (defun gnus-summary-mode (&optional group)
3060   "Major mode for reading articles.
3061
3062 All normal editing commands are switched off.
3063 \\<gnus-summary-mode-map>
3064 Each line in this buffer represents one article.  To read an
3065 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
3066 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
3067 respectively.
3068
3069 You can also post articles and send mail from this buffer.  To
3070 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
3071 of an article, type `\\[gnus-summary-reply]'.
3072
3073 There are approx. one gazillion commands you can execute in this
3074 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
3075
3076 The following commands are available:
3077
3078 \\{gnus-summary-mode-map}"
3079   (interactive)
3080   (kill-all-local-variables)
3081   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
3082     (gnus-summary-make-local-variables))
3083   (gnus-summary-make-local-variables)
3084   (setq gnus-newsgroup-name group)
3085   (when (gnus-visual-p 'summary-menu 'menu)
3086     (gnus-summary-make-menu-bar)
3087     (gnus-summary-make-tool-bar))
3088   (gnus-make-thread-indent-array)
3089   (gnus-simplify-mode-line)
3090   (setq major-mode 'gnus-summary-mode)
3091   (setq mode-name "Summary")
3092   (use-local-map gnus-summary-mode-map)
3093   (buffer-disable-undo)
3094   (setq buffer-read-only t              ;Disable modification
3095         show-trailing-whitespace nil)
3096   (setq truncate-lines t)
3097   ;; Force paragraph direction to be left-to-right.  Don't make it
3098   ;; bound globally in old Emacsen and XEmacsen.
3099   (set (make-local-variable 'bidi-paragraph-direction) 'left-to-right)
3100   (add-to-invisibility-spec '(gnus-sum . t))
3101   (gnus-summary-set-display-table)
3102   (gnus-set-default-directory)
3103   (make-local-variable 'gnus-summary-line-format)
3104   (make-local-variable 'gnus-summary-line-format-spec)
3105   (make-local-variable 'gnus-summary-dummy-line-format)
3106   (make-local-variable 'gnus-summary-dummy-line-format-spec)
3107   (make-local-variable 'gnus-summary-mark-positions)
3108   (gnus-make-local-hook 'pre-command-hook)
3109   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3110   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3111   (turn-on-gnus-mailing-list-mode)
3112   (mm-enable-multibyte)
3113   (set (make-local-variable 'bookmark-make-record-function)
3114        'gnus-summary-bookmark-make-record)
3115   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3116   (gnus-update-summary-mark-positions))
3117
3118 (defun gnus-summary-make-local-variables ()
3119   "Make all the local summary buffer variables."
3120   (let (global)
3121     (dolist (local gnus-summary-local-variables)
3122       (if (consp local)
3123           (progn
3124             (if (eq (cdr local) 'global)
3125                 ;; Copy the global value of the variable.
3126                 (setq global (symbol-value (car local)))
3127               ;; Use the value from the list.
3128               (setq global (eval (cdr local))))
3129             (set (make-local-variable (car local)) global))
3130         ;; Simple nil-valued local variable.
3131         (set (make-local-variable local) nil)))))
3132
3133 ;; Summary data functions.
3134
3135 (defmacro gnus-data-number (data)
3136   `(car ,data))
3137
3138 (defmacro gnus-data-set-number (data number)
3139   `(setcar ,data ,number))
3140
3141 (defmacro gnus-data-mark (data)
3142   `(nth 1 ,data))
3143
3144 (defmacro gnus-data-set-mark (data mark)
3145   `(setcar (nthcdr 1 ,data) ,mark))
3146
3147 (defmacro gnus-data-pos (data)
3148   `(nth 2 ,data))
3149
3150 (defmacro gnus-data-set-pos (data pos)
3151   `(setcar (nthcdr 2 ,data) ,pos))
3152
3153 (defmacro gnus-data-header (data)
3154   `(nth 3 ,data))
3155
3156 (defmacro gnus-data-set-header (data header)
3157   `(setf (nth 3 ,data) ,header))
3158
3159 (defmacro gnus-data-level (data)
3160   `(nth 4 ,data))
3161
3162 (defmacro gnus-data-unread-p (data)
3163   `(= (nth 1 ,data) gnus-unread-mark))
3164
3165 (defmacro gnus-data-read-p (data)
3166   `(/= (nth 1 ,data) gnus-unread-mark))
3167
3168 (defmacro gnus-data-pseudo-p (data)
3169   `(consp (nth 3 ,data)))
3170
3171 (defmacro gnus-data-find (number)
3172   `(assq ,number gnus-newsgroup-data))
3173
3174 (defmacro gnus-data-find-list (number &optional data)
3175   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3176      (memq (assq ,number bdata)
3177            bdata)))
3178
3179 (defmacro gnus-data-make (number mark pos header level)
3180   `(list ,number ,mark ,pos ,header ,level))
3181
3182 (defun gnus-data-enter (after-article number mark pos header level offset)
3183   (let ((data (gnus-data-find-list after-article)))
3184     (unless data
3185       (error "No such article: %d" after-article))
3186     (setcdr data (cons (gnus-data-make number mark pos header level)
3187                        (cdr data)))
3188     (setq gnus-newsgroup-data-reverse nil)
3189     (gnus-data-update-list (cddr data) offset)))
3190
3191 (defun gnus-data-enter-list (after-article list &optional offset)
3192   (when list
3193     (let ((data (and after-article (gnus-data-find-list after-article)))
3194           (ilist list))
3195       (if (not (or data
3196                    after-article))
3197           (let ((odata gnus-newsgroup-data))
3198             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3199             (when offset
3200               (gnus-data-update-list odata offset)))
3201         ;; Find the last element in the list to be spliced into the main
3202         ;; list.
3203         (setq list (last list))
3204         (if (not data)
3205             (progn
3206               (setcdr list gnus-newsgroup-data)
3207               (setq gnus-newsgroup-data ilist)
3208               (when offset
3209                 (gnus-data-update-list (cdr list) offset)))
3210           (setcdr list (cdr data))
3211           (setcdr data ilist)
3212           (when offset
3213             (gnus-data-update-list (cdr list) offset))))
3214       (setq gnus-newsgroup-data-reverse nil))))
3215
3216 (defun gnus-data-remove (article &optional offset)
3217   (let ((data gnus-newsgroup-data))
3218     (if (= (gnus-data-number (car data)) article)
3219         (progn
3220           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3221                 gnus-newsgroup-data-reverse nil)
3222           (when offset
3223             (gnus-data-update-list gnus-newsgroup-data offset)))
3224       (while (cdr data)
3225         (when (= (gnus-data-number (cadr data)) article)
3226           (setcdr data (cddr data))
3227           (when offset
3228             (gnus-data-update-list (cdr data) offset))
3229           (setq data nil
3230                 gnus-newsgroup-data-reverse nil))
3231         (setq data (cdr data))))))
3232
3233 (defmacro gnus-data-list (backward)
3234   `(if ,backward
3235        (or gnus-newsgroup-data-reverse
3236            (setq gnus-newsgroup-data-reverse
3237                  (reverse gnus-newsgroup-data)))
3238      gnus-newsgroup-data))
3239
3240 (defun gnus-data-update-list (data offset)
3241   "Add OFFSET to the POS of all data entries in DATA."
3242   (setq gnus-newsgroup-data-reverse nil)
3243   (while data
3244     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3245     (setq data (cdr data))))
3246
3247 (defun gnus-summary-article-pseudo-p (article)
3248   "Say whether this article is a pseudo article or not."
3249   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3250
3251 (defmacro gnus-summary-article-sparse-p (article)
3252   "Say whether this article is a sparse article or not."
3253   `(memq ,article gnus-newsgroup-sparse))
3254
3255 (defmacro gnus-summary-article-ancient-p (article)
3256   "Say whether this article is a sparse article or not."
3257   `(memq ,article gnus-newsgroup-ancient))
3258
3259 (defun gnus-article-children (number)
3260   "Return a list of all children to NUMBER."
3261   (let* ((data (gnus-data-find-list number))
3262          (level (gnus-data-level (car data)))
3263          children)
3264     (setq data (cdr data))
3265     (while (and data
3266                 (= (gnus-data-level (car data)) (1+ level)))
3267       (push (gnus-data-number (car data)) children)
3268       (setq data (cdr data)))
3269     children))
3270
3271 (defmacro gnus-summary-skip-intangible ()
3272   "If the current article is intangible, then jump to a different article."
3273   '(let ((to (get-text-property (point) 'gnus-intangible)))
3274      (and to (gnus-summary-goto-subject to))))
3275
3276 (defmacro gnus-summary-article-intangible-p ()
3277   "Say whether this article is intangible or not."
3278   '(get-text-property (point) 'gnus-intangible))
3279
3280 ;; Some summary mode macros.
3281
3282 (defmacro gnus-summary-article-number ()
3283   "The article number of the article on the current line.
3284 If there isn't an article number here, then we return the current
3285 article number."
3286   '(progn
3287      (gnus-summary-skip-intangible)
3288      (or (get-text-property (point) 'gnus-number)
3289          (gnus-summary-last-subject))))
3290
3291 (defmacro gnus-summary-article-header (&optional number)
3292   "Return the header of article NUMBER."
3293   `(gnus-data-header (gnus-data-find
3294                       ,(or number '(gnus-summary-article-number)))))
3295
3296 (defmacro gnus-summary-thread-level (&optional number)
3297   "Return the level of thread that starts with article NUMBER."
3298   `(if (and (eq gnus-summary-make-false-root 'dummy)
3299             (get-text-property (point) 'gnus-intangible))
3300        0
3301      (gnus-data-level (gnus-data-find
3302                        ,(or number '(gnus-summary-article-number))))))
3303
3304 (defmacro gnus-summary-article-mark (&optional number)
3305   "Return the mark of article NUMBER."
3306   `(gnus-data-mark (gnus-data-find
3307                     ,(or number '(gnus-summary-article-number)))))
3308
3309 (defmacro gnus-summary-article-pos (&optional number)
3310   "Return the position of the line of article NUMBER."
3311   `(gnus-data-pos (gnus-data-find
3312                    ,(or number '(gnus-summary-article-number)))))
3313
3314 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3315 (defmacro gnus-summary-article-subject (&optional number)
3316   "Return current subject string or nil if nothing."
3317   `(let ((headers
3318           ,(if number
3319                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3320              '(gnus-data-header (assq (gnus-summary-article-number)
3321                                       gnus-newsgroup-data)))))
3322      (and headers
3323           (vectorp headers)
3324           (mail-header-subject headers))))
3325
3326 (defmacro gnus-summary-article-score (&optional number)
3327   "Return current article score."
3328   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3329                   gnus-newsgroup-scored))
3330        gnus-summary-default-score 0))
3331
3332 (defun gnus-summary-article-children (&optional number)
3333   "Return a list of article numbers that are children of article NUMBER."
3334   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3335          (level (gnus-data-level (car data)))
3336          l children)
3337     (while (and (setq data (cdr data))
3338                 (> (setq l (gnus-data-level (car data))) level))
3339       (and (= (1+ level) l)
3340            (push (gnus-data-number (car data))
3341                  children)))
3342     (nreverse children)))
3343
3344 (defun gnus-summary-article-parent (&optional number)
3345   "Return the article number of the parent of article NUMBER."
3346   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3347                                     (gnus-data-list t)))
3348          (level (gnus-data-level (car data))))
3349     (if (zerop level)
3350         ()                              ; This is a root.
3351       ;; We search until we find an article with a level less than
3352       ;; this one.  That function has to be the parent.
3353       (while (and (setq data (cdr data))
3354                   (not (< (gnus-data-level (car data)) level))))
3355       (and data (gnus-data-number (car data))))))
3356
3357 (defun gnus-unread-mark-p (mark)
3358   "Say whether MARK is the unread mark."
3359   (= mark gnus-unread-mark))
3360
3361 (defun gnus-read-mark-p (mark)
3362   "Say whether MARK is one of the marks that mark as read.
3363 This is all marks except unread, ticked, dormant, and expirable."
3364   (not (or (= mark gnus-unread-mark)
3365            (= mark gnus-ticked-mark)
3366            (= mark gnus-spam-mark)
3367            (= mark gnus-dormant-mark)
3368            (= mark gnus-expirable-mark))))
3369
3370 (defmacro gnus-article-mark (number)
3371   "Return the MARK of article NUMBER.
3372 This macro should only be used when computing the mark the \"first\"
3373 time; i.e., when generating the summary lines.  After that,
3374 `gnus-summary-article-mark' should be used to examine the
3375 marks of articles."
3376   `(cond
3377     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3378     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3379     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3380     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3381     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3382     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3383     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3384     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3385            gnus-ancient-mark))))
3386
3387 ;; Saving hidden threads.
3388
3389 (defmacro gnus-save-hidden-threads (&rest forms)
3390   "Save hidden threads, eval FORMS, and restore the hidden threads."
3391   (let ((config (make-symbol "config")))
3392     `(let ((,config (gnus-hidden-threads-configuration)))
3393        (unwind-protect
3394            (save-excursion
3395              ,@forms)
3396          (gnus-restore-hidden-threads-configuration ,config)))))
3397 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3398 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3399
3400 (defun gnus-data-compute-positions ()
3401   "Compute the positions of all articles."
3402   (setq gnus-newsgroup-data-reverse nil)
3403   (let ((data gnus-newsgroup-data))
3404     (save-excursion
3405       (gnus-save-hidden-threads
3406         (gnus-summary-show-all-threads)
3407         (goto-char (point-min))
3408         (while data
3409           (while (get-text-property (point) 'gnus-intangible)
3410             (forward-line 1))
3411           (gnus-data-set-pos (car data) (+ (point) 3))
3412           (setq data (cdr data))
3413           (forward-line 1))))))
3414
3415 (defun gnus-hidden-threads-configuration ()
3416   "Return the current hidden threads configuration."
3417   (save-excursion
3418     (let (config)
3419       (goto-char (point-min))
3420       (while (not (eobp))
3421         (when (eq (get-char-property (point-at-eol) 'invisible) 'gnus-sum)
3422           (push (save-excursion (forward-line 0) (point)) config))
3423         (forward-line 1))
3424       config)))
3425
3426 (defun gnus-restore-hidden-threads-configuration (config)
3427   "Restore hidden threads configuration from CONFIG."
3428   (save-excursion
3429     (let (point (inhibit-read-only t))
3430       (while (setq point (pop config))
3431         (goto-char point)
3432         (gnus-summary-hide-thread)))))
3433
3434 ;; Various summary mode internalish functions.
3435
3436 (defun gnus-mouse-pick-article (e)
3437   (interactive "e")
3438   (mouse-set-point e)
3439   (gnus-summary-next-page nil t))
3440
3441 (defun gnus-summary-set-display-table ()
3442   "Change the display table.
3443 Odd characters have a tendency to mess
3444 up nicely formatted displays - we make all possible glyphs
3445 display only a single character."
3446
3447   ;; We start from the standard display table, if any.
3448   (let ((table (or (copy-sequence standard-display-table)
3449                    (make-display-table)))
3450         (i 32))
3451     ;; Nix out all the control chars...
3452     (while (>= (setq i (1- i)) 0)
3453       (gnus-put-display-table i [??] table))
3454    ;; ... but not newline and cr, of course.  (cr is necessary for the
3455     ;; selective display).
3456     (gnus-put-display-table ?\n nil table)
3457     (gnus-put-display-table ?\r nil table)
3458     ;; We keep TAB as well.
3459     (gnus-put-display-table ?\t nil table)
3460     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3461     ;; Emacs 23 (unicode), that are not set already.
3462     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3463                  160
3464                256)))
3465       (while (>= (setq i (1- i)) 127)
3466         ;; Only modify if the entry is nil.
3467         (unless (gnus-get-display-table i table)
3468           (gnus-put-display-table i [??] table))))
3469     (setq buffer-display-table table)))
3470
3471 (defun gnus-summary-set-article-display-arrow (pos)
3472   "Update the overlay arrow to point to line at position POS."
3473   (when gnus-summary-display-arrow
3474     (make-local-variable 'overlay-arrow-position)
3475     (make-local-variable 'overlay-arrow-string)
3476     (save-excursion
3477       (goto-char pos)
3478       (beginning-of-line)
3479       (unless overlay-arrow-position
3480         (setq overlay-arrow-position (make-marker)))
3481       (setq overlay-arrow-string "=>"
3482             overlay-arrow-position (set-marker overlay-arrow-position
3483                                                (point)
3484                                                (current-buffer))))))
3485
3486 (defun gnus-summary-setup-buffer (group)
3487   "Initialize summary buffer.
3488 If the setup was successful, non-nil is returned."
3489   (let ((buffer (gnus-summary-buffer-name group))
3490         (dead-name (concat "*Dead Summary "
3491                            (gnus-group-decoded-name group) "*")))
3492     ;; If a dead summary buffer exists, we kill it.
3493     (when (gnus-buffer-live-p dead-name)
3494       (gnus-kill-buffer dead-name))
3495     (if (get-buffer buffer)
3496         (progn
3497           (set-buffer buffer)
3498           (setq gnus-summary-buffer (current-buffer))
3499           (not gnus-newsgroup-prepared))
3500       (set-buffer (gnus-get-buffer-create buffer))
3501       (setq gnus-summary-buffer (current-buffer))
3502       (gnus-summary-mode group)
3503       (when (gnus-group-quit-config group)
3504         (set (make-local-variable 'gnus-single-article-buffer) nil))
3505       (make-local-variable 'gnus-article-buffer)
3506       (make-local-variable 'gnus-article-current)
3507       (make-local-variable 'gnus-original-article-buffer)
3508       (setq gnus-newsgroup-name group)
3509       ;; Set any local variables in the group parameters.
3510       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3511       t)))
3512
3513 (defun gnus-set-global-variables ()
3514   "Set the global equivalents of the buffer-local variables.
3515 They are set to the latest values they had.  These reflect the summary
3516 buffer that was in action when the last article was fetched."
3517   (when (eq major-mode 'gnus-summary-mode)
3518     (setq gnus-summary-buffer (current-buffer))
3519     (let ((name gnus-newsgroup-name)
3520           (marked gnus-newsgroup-marked)
3521           (spam gnus-newsgroup-spam-marked)
3522           (unread gnus-newsgroup-unreads)
3523           (headers gnus-current-headers)
3524           (data gnus-newsgroup-data)
3525           (summary gnus-summary-buffer)
3526           (article-buffer gnus-article-buffer)
3527           (original gnus-original-article-buffer)
3528           (gac gnus-article-current)
3529           (reffed gnus-reffed-article-number)
3530           (score-file gnus-current-score-file)
3531           (default-charset gnus-newsgroup-charset)
3532           vlist)
3533       (let ((locals gnus-newsgroup-variables))
3534         (while locals
3535           (if (consp (car locals))
3536               (push (eval (caar locals)) vlist)
3537             (push (eval (car locals)) vlist))
3538           (setq locals (cdr locals)))
3539         (setq vlist (nreverse vlist)))
3540       (with-temp-buffer
3541         (setq gnus-newsgroup-name name
3542               gnus-newsgroup-marked marked
3543               gnus-newsgroup-spam-marked spam
3544               gnus-newsgroup-unreads unread
3545               gnus-current-headers headers
3546               gnus-newsgroup-data data
3547               gnus-article-current gac
3548               gnus-summary-buffer summary
3549               gnus-article-buffer article-buffer
3550               gnus-original-article-buffer original
3551               gnus-reffed-article-number reffed
3552               gnus-current-score-file score-file
3553               gnus-newsgroup-charset default-charset)
3554         (let ((locals gnus-newsgroup-variables))
3555           (while locals
3556             (if (consp (car locals))
3557                 (set (caar locals) (pop vlist))
3558               (set (car locals) (pop vlist)))
3559             (setq locals (cdr locals))))))))
3560
3561 (defun gnus-summary-article-unread-p (article)
3562   "Say whether ARTICLE is unread or not."
3563   (memq article gnus-newsgroup-unreads))
3564
3565 (defun gnus-summary-first-article-p (&optional article)
3566   "Return whether ARTICLE is the first article in the buffer."
3567   (if (not (setq article (or article (gnus-summary-article-number))))
3568       nil
3569     (eq article (caar gnus-newsgroup-data))))
3570
3571 (defun gnus-summary-last-article-p (&optional article)
3572   "Return whether ARTICLE is the last article in the buffer."
3573   (if (not (setq article (or article (gnus-summary-article-number))))
3574       ;; All non-existent numbers are the last article.  :-)
3575       t
3576     (not (cdr (gnus-data-find-list article)))))
3577
3578 (defun gnus-make-thread-indent-array (&optional n)
3579   (when (or n
3580             (progn (setq n 200) nil)
3581             (null gnus-thread-indent-array)
3582             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3583     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3584           gnus-thread-indent-array-level gnus-thread-indent-level)
3585     (while (>= n 0)
3586       (aset gnus-thread-indent-array n
3587             (make-string (* n gnus-thread-indent-level) ? ))
3588       (setq n (1- n)))))
3589
3590 (defun gnus-update-summary-mark-positions ()
3591   "Compute where the summary marks are to go."
3592   (save-excursion
3593     (when (gnus-buffer-exists-p gnus-summary-buffer)
3594       (set-buffer gnus-summary-buffer))
3595     (let ((spec gnus-summary-line-format-spec)
3596           pos)
3597       (save-excursion
3598         (gnus-set-work-buffer)
3599         (let ((gnus-tmp-unread ?Z)
3600               (gnus-replied-mark ?Z)
3601               (gnus-score-below-mark ?Z)
3602               (gnus-score-over-mark ?Z)
3603               (gnus-undownloaded-mark ?Z)
3604               (gnus-summary-line-format-spec spec)
3605               (gnus-newsgroup-downloadable '(0))
3606               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3607               case-fold-search ignores)
3608           ;; Here, all marks are bound to Z.
3609           (gnus-summary-insert-line header
3610                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3611           (goto-char (point-min))
3612           ;; Memorize the positions of the same characters as dummy marks.
3613           (while (re-search-forward "[A-D]" nil t)
3614             (push (point) ignores))
3615           (erase-buffer)
3616           ;; We use A-D as dummy marks in order to know column positions
3617           ;; where marks should be inserted.
3618           (setq gnus-tmp-unread ?A
3619                 gnus-replied-mark ?B
3620                 gnus-score-below-mark ?C
3621                 gnus-score-over-mark ?C
3622                 gnus-undownloaded-mark ?D)
3623           (gnus-summary-insert-line header
3624                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3625           ;; Ignore characters which aren't dummy marks.
3626           (dolist (p ignores)
3627             (delete-region (goto-char (1- p)) p)
3628             (insert ?Z))
3629           (goto-char (point-min))
3630           (setq pos (list (cons 'unread
3631                                 (and (search-forward "A" nil t)
3632                                      (- (point) (point-min) 1)))))
3633           (goto-char (point-min))
3634           (push (cons 'replied (and (search-forward "B" nil t)
3635                                     (- (point) (point-min) 1)))
3636                 pos)
3637           (goto-char (point-min))
3638           (push (cons 'score (and (search-forward "C" nil t)
3639                                   (- (point) (point-min) 1)))
3640                 pos)
3641           (goto-char (point-min))
3642           (push (cons 'download (and (search-forward "D" nil t)
3643                                      (- (point) (point-min) 1)))
3644                 pos)))
3645       (setq gnus-summary-mark-positions pos))))
3646
3647 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3648   "Insert a dummy root in the summary buffer."
3649   (beginning-of-line)
3650   (gnus-add-text-properties
3651    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3652    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3653
3654 (defun gnus-summary-extract-address-component (from)
3655   (or (car (funcall gnus-extract-address-components from))
3656       from))
3657
3658 (defun gnus-summary-from-or-to-or-newsgroups (header from)
3659   (let ((mail-parse-charset gnus-newsgroup-charset)
3660         (ignored-from-addresses (gnus-ignored-from-addresses))
3661         ;; Is it really necessary to do this next part for each summary line?
3662         ;; Luckily, doesn't seem to slow things down much.
3663         (mail-parse-ignored-charsets
3664          (with-current-buffer gnus-summary-buffer
3665            gnus-newsgroup-ignored-charsets))
3666         (address (cadr (gnus-extract-address-components from))))
3667     (or
3668      (and ignored-from-addresses
3669           (string-match ignored-from-addresses address)
3670           (let ((extra-headers (mail-header-extra header))
3671                 to
3672                 newsgroups)
3673             (cond
3674              ((setq to (cdr (assq 'To extra-headers)))
3675               (concat gnus-summary-to-prefix
3676                       (inline
3677                         (gnus-summary-extract-address-component
3678                          (funcall gnus-decode-encoded-address-function to)))))
3679              ((setq newsgroups
3680                     (or
3681                      (cdr (assq 'Newsgroups extra-headers))
3682                      (and
3683                       (memq 'Newsgroups gnus-extra-headers)
3684                       (eq (car (gnus-find-method-for-group
3685                                 gnus-newsgroup-name)) 'nntp)
3686                       (gnus-group-real-name gnus-newsgroup-name))))
3687               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3688      (gnus-string-mark-left-to-right (gnus-summary-extract-address-component from)))))
3689
3690 (defun gnus-summary-insert-line (gnus-tmp-header
3691                                  gnus-tmp-level gnus-tmp-current
3692                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3693                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3694                                  &optional gnus-tmp-dummy gnus-tmp-score
3695                                  gnus-tmp-process)
3696   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3697       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3698                                           gnus-tmp-level)))
3699   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3700          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3701          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3702          (gnus-tmp-score-char
3703           (if (or (null gnus-summary-default-score)
3704                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3705                       gnus-summary-zcore-fuzz))
3706               ?                         ;Whitespace
3707             (if (< gnus-tmp-score gnus-summary-default-score)
3708                 gnus-score-below-mark gnus-score-over-mark)))
3709          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3710          (gnus-tmp-replied
3711           (cond (gnus-tmp-process gnus-process-mark)
3712                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3713                  gnus-cached-mark)
3714                 (gnus-tmp-replied gnus-replied-mark)
3715                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3716                  gnus-forwarded-mark)
3717                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3718                  gnus-saved-mark)
3719                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3720                  gnus-unseen-mark)
3721                 (t gnus-no-mark)))
3722          (gnus-tmp-downloaded
3723           (cond (undownloaded
3724                  gnus-undownloaded-mark)
3725                 (gnus-newsgroup-agentized
3726                  gnus-downloaded-mark)
3727                 (t
3728                  gnus-no-mark)))
3729          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3730          (gnus-tmp-name
3731           (cond
3732            ((string-match "<[^>]+> *$" gnus-tmp-from)
3733             (let ((beg (match-beginning 0)))
3734               (or (and (string-match "^\".+\"" gnus-tmp-from)
3735                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3736                   (substring gnus-tmp-from 0 beg))))
3737            ((string-match "(.+)" gnus-tmp-from)
3738             (substring gnus-tmp-from
3739                        (1+ (match-beginning 0)) (1- (match-end 0))))
3740            (t gnus-tmp-from)))
3741          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3742          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3743          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3744          (inhibit-read-only t))
3745     (when (string= gnus-tmp-name "")
3746       (setq gnus-tmp-name gnus-tmp-from))
3747     (unless (numberp gnus-tmp-lines)
3748       (setq gnus-tmp-lines -1))
3749     (if (= gnus-tmp-lines -1)
3750         (setq gnus-tmp-lines "?")
3751       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3752     (condition-case ()
3753         (gnus-put-text-property
3754          (point)
3755          (progn (eval gnus-summary-line-format-spec) (point))
3756          'gnus-number gnus-tmp-number)
3757       (error (gnus-message 5 "Error updating the summary line")))
3758     (when (gnus-visual-p 'summary-highlight 'highlight)
3759       (forward-line -1)
3760       (gnus-summary-highlight-line)
3761       (gnus-run-hooks 'gnus-summary-update-hook)
3762       (forward-line 1))))
3763
3764 (defun gnus-summary-update-line (&optional dont-update)
3765   "Update summary line after change."
3766   (when (and gnus-summary-default-score
3767              (not gnus-summary-inhibit-highlight))
3768     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3769            (article (gnus-summary-article-number))
3770            (score (gnus-summary-article-score article)))
3771       (unless dont-update
3772         (if (and gnus-summary-mark-below
3773                  (< (gnus-summary-article-score)
3774                     gnus-summary-mark-below))
3775             ;; This article has a low score, so we mark it as read.
3776             (when (memq article gnus-newsgroup-unreads)
3777               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3778           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3779             ;; This article was previously marked as read on account
3780             ;; of a low score, but now it has risen, so we mark it as
3781             ;; unread.
3782             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3783         (gnus-summary-update-mark
3784          (if (or (null gnus-summary-default-score)
3785                  (<= (abs (- score gnus-summary-default-score))
3786                      gnus-summary-zcore-fuzz))
3787              ?                          ;Whitespace
3788            (if (< score gnus-summary-default-score)
3789                gnus-score-below-mark gnus-score-over-mark))
3790          'score))
3791       ;; Do visual highlighting.
3792       (when (gnus-visual-p 'summary-highlight 'highlight)
3793         (gnus-summary-highlight-line)
3794         (gnus-run-hooks 'gnus-summary-update-hook)))))
3795
3796 (defvar gnus-tmp-new-adopts nil)
3797
3798 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3799   "Return the number of articles in THREAD.
3800 This may be 0 in some cases -- if none of the articles in
3801 the thread are to be displayed."
3802   (let* ((number
3803          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3804           (cond
3805            ((not (listp thread))
3806             1)
3807            ((and (consp thread) (cdr thread))
3808             (apply
3809              '+ 1 (mapcar
3810                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3811            ((null thread)
3812             1)
3813            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3814             1)
3815            (t 0))))
3816     (when (and level (zerop level) gnus-tmp-new-adopts)
3817       (incf number
3818             (apply '+ (mapcar
3819                        'gnus-summary-number-of-articles-in-thread
3820                        gnus-tmp-new-adopts))))
3821     (if char
3822         (if (> number 1) gnus-not-empty-thread-mark
3823           gnus-empty-thread-mark)
3824       number)))
3825
3826 (defsubst gnus-summary-line-message-size (head)
3827   "Return pretty-printed version of message size.
3828 This function is intended to be used in
3829 `gnus-summary-line-format-alist'."
3830   (let ((c (or (mail-header-chars head) -1)))
3831     (cond ((< c 0) "n/a")               ; chars not available
3832           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3833           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3834           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3835           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3836
3837 (defcustom gnus-user-date-format-alist
3838   '(((gnus-seconds-today) . "Today, %H:%M")
3839     ((+ 86400 (gnus-seconds-today)) . "Yesterday, %H:%M")
3840     (604800 . "%A %H:%M")               ; That's one week
3841     ((gnus-seconds-month) . "%A %d")
3842     ((gnus-seconds-year) . "%B %d")
3843     (t . "%b %d %Y"))                   ; This one is used when no other
3844                                         ; does match
3845   "Specifies date format depending on age of article.
3846 This is an alist of items (AGE . FORMAT).  AGE can be a number (of
3847 seconds) or a Lisp expression evaluating to a number.  When the age of
3848 the article is less than this number, then use `format-time-string'
3849 with the corresponding FORMAT for displaying the date of the article.
3850 If AGE is not a number or a Lisp expression evaluating to a
3851 non-number, then the corresponding FORMAT is used as a default value.
3852
3853 Note that the list is processed from the beginning, so it should be
3854 sorted by ascending AGE.  Also note that items following the first
3855 non-number AGE will be ignored.
3856
3857 You can use the functions `gnus-seconds-today', `gnus-seconds-month'
3858 and `gnus-seconds-year' in the AGE spec.  They return the number of
3859 seconds passed since the start of today, of this month, of this year,
3860 respectively."
3861   :version "24.1"
3862   :group 'gnus-summary-format
3863   :type '(alist :key-type sexp :value-type string))
3864
3865 (defun gnus-user-date (messy-date)
3866   "Format the messy-date according to `gnus-user-date-format-alist'.
3867 Returns \"  ?  \" if there's bad input or if another error occurs.
3868 Input should look like this: \"Sun, 14 Oct 2001 13:34:39 +0200\"."
3869   (condition-case ()
3870       (let* ((messy-date (gnus-float-time (gnus-date-get-time messy-date)))
3871              (now (gnus-float-time))
3872              ;;If we don't find something suitable we'll use this one
3873              (my-format "%b %d '%y"))
3874         (let* ((difference (- now messy-date))
3875                (templist gnus-user-date-format-alist)
3876                (top (eval (caar templist))))
3877           (while (if (numberp top) (< top difference) (not top))
3878             (progn
3879               (setq templist (cdr templist))
3880               (setq top (eval (caar templist)))))
3881           (if (stringp (cdr (car templist)))
3882               (setq my-format (cdr (car templist)))))
3883         (format-time-string (eval my-format) (seconds-to-time messy-date)))
3884     (error "  ?   ")))
3885
3886 (defun gnus-summary-set-local-parameters (group)
3887   "Go through the local params of GROUP and set all variable specs in that list."
3888   (let ((vars '(quit-config active)))   ; Ignore things that aren't
3889                                         ; really variables.
3890     (dolist (elem (gnus-group-find-parameter group))
3891       (and (consp elem)                 ; Has to be a cons.
3892            (consp (cdr elem))           ; The cdr has to be a list.
3893            (symbolp (car elem))         ; Has to be a symbol in there.
3894            (not (memq (car elem) vars))
3895            (ignore-errors
3896              (push (car elem) vars)
3897              ;; Variables like `gnus-show-threads' that are globally
3898              ;; bound, if used as group parameters, need to get to be
3899              ;; buffer-local, whereas just parameters like `gcc-self',
3900              ;; `timestamp', etc. should not be bound as variables.
3901              (if (boundp (car elem))
3902                  (set (make-local-variable (car elem)) (eval (nth 1 elem)))
3903                (eval (nth 1 elem))))))))
3904
3905 (defun gnus-summary-read-group (group &optional show-all no-article
3906                                       kill-buffer no-display backward
3907                                       select-articles)
3908   "Start reading news in newsgroup GROUP.
3909 If SHOW-ALL is non-nil, already read articles are also listed.
3910 If NO-ARTICLE is non-nil, no article is selected initially.
3911 If NO-DISPLAY, don't generate the summary buffer contents.
3912 If KILL-BUFFER, it should be a buffer that's killed once the new
3913 summary buffer has been generated.
3914 If BACKWARD, move point to the previous group in the group buffer
3915 If SELECT-ARTICLES, only select those articles from GROUP."
3916   (let (result)
3917     (while (and group
3918                 (null (setq result
3919                             (let ((gnus-auto-select-next nil))
3920                               (or (gnus-summary-read-group-1
3921                                    group show-all no-article
3922                                    kill-buffer no-display
3923                                    select-articles)
3924                                   (setq show-all nil
3925                                         select-articles nil)))))
3926                 (eq gnus-auto-select-next 'quietly))
3927       (set-buffer gnus-group-buffer)
3928       ;; The entry function called above goes to the next
3929       ;; group automatically, so we go two groups back
3930       ;; if we are searching for the previous group.
3931       (when backward
3932         (gnus-group-prev-unread-group 2))
3933       (if (not (equal group (gnus-group-group-name)))
3934           (setq group (gnus-group-group-name))
3935         (setq group nil)))
3936     result))
3937
3938 (defun gnus-summary-read-group-1 (group show-all no-article
3939                                         kill-buffer no-display
3940                                         &optional select-articles)
3941   ;; Killed foreign groups can't be entered.
3942   ;;  (when (and (not (gnus-group-native-p group))
3943   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3944   ;;    (error "Dead non-native groups can't be entered"))
3945   (gnus-message 7 "Retrieving newsgroup: %s..."
3946                 (gnus-group-decoded-name group))
3947   (let* ((new-group (gnus-summary-setup-buffer group))
3948          (quit-config (gnus-group-quit-config group))
3949          (did-select (and new-group (gnus-select-newsgroup
3950                                      group show-all select-articles))))
3951     (cond
3952      ;; This summary buffer exists already, so we just select it.
3953      ((not new-group)
3954       (gnus-set-global-variables)
3955       (when kill-buffer
3956         (gnus-kill-or-deaden-summary kill-buffer))
3957       (gnus-configure-windows 'summary 'force)
3958       (gnus-set-mode-line 'summary)
3959       (gnus-summary-position-point)
3960       (message "")
3961       t)
3962      ;; We couldn't select this group.
3963      ((null did-select)
3964       (when (and (eq major-mode 'gnus-summary-mode)
3965                  (not (equal (current-buffer) kill-buffer)))
3966         (kill-buffer (current-buffer))
3967         (if (not quit-config)
3968             (progn
3969               ;; Update the info -- marks might need to be removed,
3970               ;; for instance.
3971               (gnus-summary-update-info)
3972               (set-buffer gnus-group-buffer)
3973               (gnus-group-jump-to-group group)
3974               (gnus-group-next-unread-group 1))
3975           (gnus-handle-ephemeral-exit quit-config)))
3976       (if (null (gnus-list-of-unread-articles group))
3977           (gnus-message 3 "Group %s contains no messages" group)
3978         (gnus-message 3 "Can't select group"))
3979       nil)
3980      ;; The user did a `C-g' while prompting for number of articles,
3981      ;; so we exit this group.
3982      ((eq did-select 'quit)
3983       (and (eq major-mode 'gnus-summary-mode)
3984            (not (equal (current-buffer) kill-buffer))
3985            (kill-buffer (current-buffer)))
3986       (when kill-buffer
3987         (gnus-kill-or-deaden-summary kill-buffer))
3988       (if (not quit-config)
3989           (progn
3990             (set-buffer gnus-group-buffer)
3991             (gnus-group-jump-to-group group)
3992             (gnus-configure-windows 'group 'force))
3993         (gnus-handle-ephemeral-exit quit-config))
3994       ;; Finally signal the quit.
3995       (signal 'quit nil))
3996      ;; The group was successfully selected.
3997      (t
3998       (gnus-set-global-variables)
3999       ;; Save the active value in effect when the group was entered.
4000       (setq gnus-newsgroup-active
4001             (gnus-copy-sequence
4002              (gnus-active gnus-newsgroup-name)))
4003       (setq gnus-newsgroup-highest (cdr gnus-newsgroup-active))
4004       ;; You can change the summary buffer in some way with this hook.
4005       (gnus-run-hooks 'gnus-select-group-hook)
4006       (when (memq 'summary (gnus-update-format-specifications
4007                             nil 'summary 'summary-mode 'summary-dummy))
4008         ;; The format specification for the summary line was updated,
4009         ;; so we need to update the mark positions as well.
4010         (gnus-update-summary-mark-positions))
4011       ;; Do score processing.
4012       (when gnus-use-scoring
4013         (gnus-possibly-score-headers))
4014       ;; Check whether to fill in the gaps in the threads.
4015       (when gnus-build-sparse-threads
4016         (gnus-build-sparse-threads))
4017       ;; Find the initial limit.
4018       (if show-all
4019           (let ((gnus-newsgroup-dormant nil))
4020             (gnus-summary-initial-limit show-all))
4021         (gnus-summary-initial-limit show-all))
4022       ;; Generate the summary buffer.
4023       (unless no-display
4024         (gnus-summary-prepare))
4025       (when gnus-use-trees
4026         (gnus-tree-open group)
4027         (setq gnus-summary-highlight-line-function
4028               'gnus-tree-highlight-article))
4029       ;; If the summary buffer is empty, but there are some low-scored
4030       ;; articles or some excluded dormants, we include these in the
4031       ;; buffer.
4032       (when (and (zerop (buffer-size))
4033                  (not no-display))
4034         (cond (gnus-newsgroup-dormant
4035                (gnus-summary-limit-include-dormant))
4036               ((and gnus-newsgroup-scored show-all)
4037                (gnus-summary-limit-include-expunged t))))
4038       ;; Function `gnus-apply-kill-file' must be called in this hook.
4039       (gnus-run-hooks 'gnus-apply-kill-hook)
4040       (if (and (zerop (buffer-size))
4041                (not no-display))
4042           (progn
4043             ;; This newsgroup is empty.
4044             (gnus-summary-catchup-and-exit nil t)
4045             (gnus-message 6 "No unread news")
4046             (when kill-buffer
4047               (gnus-kill-or-deaden-summary kill-buffer))
4048             ;; Return nil from this function.
4049             nil)
4050         ;; Hide conversation thread subtrees.  We cannot do this in
4051         ;; gnus-summary-prepare-hook since kill processing may not
4052         ;; work with hidden articles.
4053         (gnus-summary-maybe-hide-threads)
4054         (gnus-configure-windows 'summary)
4055         (when kill-buffer
4056           (gnus-kill-or-deaden-summary kill-buffer))
4057         (gnus-summary-auto-select-subject)
4058         ;; Show first unread article if requested.
4059         (if (and (not no-article)
4060                  (not no-display)
4061                  gnus-newsgroup-unreads
4062                  gnus-auto-select-first)
4063             (progn
4064               (let ((art (gnus-summary-article-number)))
4065                 (when (and art
4066                            gnus-plugged
4067                            (not (memq art gnus-newsgroup-undownloaded))
4068                            (not (memq art gnus-newsgroup-downloadable)))
4069                   (gnus-summary-goto-article art))))
4070           ;; Don't select any articles.
4071           (gnus-summary-position-point)
4072           (gnus-configure-windows 'summary 'force)
4073           (gnus-set-mode-line 'summary))
4074         (when (and gnus-auto-center-group
4075                    (get-buffer-window gnus-group-buffer t))
4076           ;; Gotta use windows, because recenter does weird stuff if
4077           ;; the current buffer ain't the displayed window.
4078           (let ((owin (selected-window)))
4079             (select-window (get-buffer-window gnus-group-buffer t))
4080             (when (gnus-group-goto-group group)
4081               (recenter))
4082             (select-window owin)))
4083         ;; Mark this buffer as "prepared".
4084         (setq gnus-newsgroup-prepared t)
4085         (gnus-run-hooks 'gnus-summary-prepared-hook)
4086         (unless (gnus-ephemeral-group-p group)
4087           (gnus-group-update-group group nil t))
4088         t)))))
4089
4090 (defun gnus-summary-auto-select-subject ()
4091   "Select the subject line on initial group entry."
4092   (goto-char (point-min))
4093   (cond
4094    ((eq gnus-auto-select-subject 'best)
4095     (gnus-summary-best-unread-subject))
4096    ((eq gnus-auto-select-subject 'unread)
4097     (gnus-summary-first-unread-subject))
4098    ((eq gnus-auto-select-subject 'unseen)
4099     (gnus-summary-first-unseen-subject))
4100    ((eq gnus-auto-select-subject 'unseen-or-unread)
4101     (gnus-summary-first-unseen-or-unread-subject))
4102    ((eq gnus-auto-select-subject 'first)
4103     ;; Do nothing.
4104     )
4105    ((functionp gnus-auto-select-subject)
4106     (funcall gnus-auto-select-subject))))
4107
4108 (defun gnus-summary-prepare ()
4109   "Generate the summary buffer."
4110   (interactive)
4111   (let ((inhibit-read-only t))
4112     (erase-buffer)
4113     (setq gnus-newsgroup-data nil
4114           gnus-newsgroup-data-reverse nil)
4115     (gnus-run-hooks 'gnus-summary-generate-hook)
4116     ;; Generate the buffer, either with threads or without.
4117     (when gnus-newsgroup-headers
4118       (gnus-summary-prepare-threads
4119        (if gnus-show-threads
4120            (gnus-sort-gathered-threads
4121             (funcall gnus-summary-thread-gathering-function
4122                      (gnus-sort-threads
4123                       (gnus-cut-threads (gnus-make-threads)))))
4124          ;; Unthreaded display.
4125          (gnus-sort-articles gnus-newsgroup-headers))))
4126     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
4127     ;; Call hooks for modifying summary buffer.
4128     (goto-char (point-min))
4129     (gnus-run-hooks 'gnus-summary-prepare-hook)))
4130
4131 (defsubst gnus-general-simplify-subject (subject)
4132   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4133   (setq subject
4134         (cond
4135          ;; Truncate the subject.
4136          (gnus-simplify-subject-functions
4137           (gnus-map-function gnus-simplify-subject-functions subject))
4138          ((numberp gnus-summary-gather-subject-limit)
4139           (setq subject (gnus-simplify-subject-re subject))
4140           (if (> (length subject) gnus-summary-gather-subject-limit)
4141               (substring subject 0 gnus-summary-gather-subject-limit)
4142             subject))
4143          ;; Fuzzily simplify it.
4144          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4145           (gnus-simplify-subject-fuzzy subject))
4146          ;; Just remove the leading "Re:".
4147          (t
4148           (gnus-simplify-subject-re subject))))
4149
4150   (if (and gnus-summary-gather-exclude-subject
4151            (string-match gnus-summary-gather-exclude-subject subject))
4152       nil                         ; This article shouldn't be gathered
4153     subject))
4154
4155 (defun gnus-summary-simplify-subject-query ()
4156   "Query where the respool algorithm would put this article."
4157   (interactive)
4158   (gnus-summary-select-article)
4159   (message "%s" (gnus-general-simplify-subject (gnus-summary-article-subject))))
4160
4161 (defun gnus-gather-threads-by-subject (threads)
4162   "Gather threads by looking at Subject headers."
4163   (if (not gnus-summary-make-false-root)
4164       threads
4165     (let ((hashtb (gnus-make-hashtable 1024))
4166           (prev threads)
4167           (result threads)
4168           subject hthread whole-subject)
4169       (while threads
4170         (setq subject (gnus-general-simplify-subject
4171                        (setq whole-subject (mail-header-subject
4172                                             (caar threads)))))
4173         (when subject
4174           (if (setq hthread (gnus-gethash subject hashtb))
4175               (progn
4176                 ;; We enter a dummy root into the thread, if we
4177                 ;; haven't done that already.
4178                 (unless (stringp (caar hthread))
4179                   (setcar hthread (list whole-subject (car hthread))))
4180                 ;; We add this new gathered thread to this gathered
4181                 ;; thread.
4182                 (setcdr (car hthread)
4183                         (nconc (cdar hthread) (list (car threads))))
4184                 ;; Remove it from the list of threads.
4185                 (setcdr prev (cdr threads))
4186                 (setq threads prev))
4187             ;; Enter this thread into the hash table.
4188             (gnus-sethash subject
4189                           (if gnus-summary-make-false-root-always
4190                               (progn
4191                                 ;; If you want a dummy root above all
4192                                 ;; threads...
4193                                 (setcar threads (list whole-subject
4194                                                       (car threads)))
4195                                 threads)
4196                             threads)
4197                           hashtb)))
4198         (setq prev threads)
4199         (setq threads (cdr threads)))
4200       result)))
4201
4202 (defun gnus-gather-threads-by-references (threads)
4203   "Gather threads by looking at References headers."
4204   (let ((idhashtb (gnus-make-hashtable 1024))
4205         (thhashtb (gnus-make-hashtable 1024))
4206         (prev threads)
4207         (result threads)
4208         ids references id gthread gid entered ref)
4209     (while threads
4210       (when (setq references (mail-header-references (caar threads)))
4211         (setq id (mail-header-id (caar threads))
4212               ids (inline (gnus-split-references references))
4213               entered nil)
4214         (while (setq ref (pop ids))
4215           (setq ids (delete ref ids))
4216           (if (not (setq gid (gnus-gethash ref idhashtb)))
4217               (progn
4218                 (gnus-sethash ref id idhashtb)
4219                 (gnus-sethash id threads thhashtb))
4220             (setq gthread (gnus-gethash gid thhashtb))
4221             (unless entered
4222               ;; We enter a dummy root into the thread, if we
4223               ;; haven't done that already.
4224               (unless (stringp (caar gthread))
4225                 (setcar gthread (list (mail-header-subject (caar gthread))
4226                                       (car gthread))))
4227               ;; We add this new gathered thread to this gathered
4228               ;; thread.
4229               (setcdr (car gthread)
4230                       (nconc (cdar gthread) (list (car threads)))))
4231             ;; Add it into the thread hash table.
4232             (gnus-sethash id gthread thhashtb)
4233             (setq entered t)
4234             ;; Remove it from the list of threads.
4235             (setcdr prev (cdr threads))
4236             (setq threads prev))))
4237       (setq prev threads)
4238       (setq threads (cdr threads)))
4239     result))
4240
4241 (defun gnus-sort-gathered-threads (threads)
4242   "Sort subthreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4243   (let ((result threads))
4244     (while threads
4245       (when (stringp (caar threads))
4246         (setcdr (car threads)
4247                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4248       (setq threads (cdr threads)))
4249     result))
4250
4251 (defun gnus-thread-loop-p (root thread)
4252   "Say whether ROOT is in THREAD."
4253   (let ((stack (list thread))
4254         (infloop 0)
4255         th)
4256     (while (setq thread (pop stack))
4257       (setq th (cdr thread))
4258       (while (and th
4259                   (not (eq (caar th) root)))
4260         (pop th))
4261       (if th
4262           ;; We have found a loop.
4263           (let (ref-dep)
4264             (setcdr thread (delq (car th) (cdr thread)))
4265             (if (boundp (setq ref-dep (intern "none"
4266                                               gnus-newsgroup-dependencies)))
4267                 (setcdr (symbol-value ref-dep)
4268                         (nconc (cdr (symbol-value ref-dep))
4269                                (list (car th))))
4270               (set ref-dep (list nil (car th))))
4271             (setq infloop 1
4272                   stack nil))
4273         ;; Push all the subthreads onto the stack.
4274         (push (cdr thread) stack)))
4275     infloop))
4276
4277 (defun gnus-make-threads ()
4278   "Go through the dependency hashtb and find the roots.  Return all threads."
4279   (let (threads)
4280     (while (catch 'infloop
4281              (mapatoms
4282               (lambda (refs)
4283                 ;; Deal with self-referencing References loops.
4284                 (when (and (car (symbol-value refs))
4285                            (not (zerop
4286                                  (apply
4287                                   '+
4288                                   (mapcar
4289                                    (lambda (thread)
4290                                      (gnus-thread-loop-p
4291                                       (car (symbol-value refs)) thread))
4292                                    (cdr (symbol-value refs)))))))
4293                   (setq threads nil)
4294                   (throw 'infloop t))
4295                 (unless (car (symbol-value refs))
4296                   ;; These threads do not refer back to any other
4297                   ;; articles, so they're roots.
4298                   (setq threads (append (cdr (symbol-value refs)) threads))))
4299               gnus-newsgroup-dependencies)))
4300     threads))
4301
4302 ;; Build the thread tree.
4303 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4304   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4305
4306 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4307 if it was already present.
4308
4309 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4310 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4311 Message-IDs will be renamed to a unique Message-ID before being
4312 entered.
4313
4314 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4315   (let* ((id (mail-header-id header))
4316          (id-dep (and id (intern id dependencies)))
4317          parent-id ref ref-dep ref-header replaced)
4318     ;; Enter this `header' in the `dependencies' table.
4319     (cond
4320      ((not id-dep)
4321       (setq header nil))
4322      ;; The first two cases do the normal part: enter a new `header'
4323      ;; in the `dependencies' table.
4324      ((not (boundp id-dep))
4325       (set id-dep (list header)))
4326      ((null (car (symbol-value id-dep)))
4327       (setcar (symbol-value id-dep) header))
4328
4329      ;; From here the `header' was already present in the
4330      ;; `dependencies' table.
4331      (force-new
4332       ;; Overrides an existing entry;
4333       ;; just set the header part of the entry.
4334       (setcar (symbol-value id-dep) header)
4335       (setq replaced t))
4336
4337      ;; Renames the existing `header' to a unique Message-ID.
4338      ((not gnus-summary-ignore-duplicates)
4339       ;; An article with this Message-ID has already been seen.
4340       ;; We rename the Message-ID.
4341       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4342            (list header))
4343       (mail-header-set-id header id))
4344
4345      ;; The last case ignores an existing entry, except it adds any
4346      ;; additional Xrefs (in case the two articles came from different
4347      ;; servers.
4348      ;; Also sets `header' to `nil' meaning that the `dependencies'
4349      ;; table was *not* modified.
4350      (t
4351       (mail-header-set-xref
4352        (car (symbol-value id-dep))
4353        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4354                    "")
4355                (or (mail-header-xref header) "")))
4356       (setq header nil)))
4357
4358     (when (and header (not replaced))
4359       ;; First check that we are not creating a References loop.
4360       (setq parent-id (gnus-parent-id (mail-header-references header)))
4361       (setq ref parent-id)
4362       (while (and ref
4363                   (setq ref-dep (intern-soft ref dependencies))
4364                   (boundp ref-dep)
4365                   (setq ref-header (car (symbol-value ref-dep))))
4366         (if (string= id ref)
4367             ;; Yuk!  This is a reference loop.  Make the article be a
4368             ;; root article.
4369             (progn
4370               (mail-header-set-references (car (symbol-value id-dep)) "none")
4371               (setq ref nil)
4372               (setq parent-id nil))
4373           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4374       (setq ref-dep (intern (or parent-id "none") dependencies))
4375       (if (boundp ref-dep)
4376           (setcdr (symbol-value ref-dep)
4377                   (nconc (cdr (symbol-value ref-dep))
4378                          (list (symbol-value id-dep))))
4379         (set ref-dep (list nil (symbol-value id-dep)))))
4380     header))
4381
4382 (defun gnus-extract-message-id-from-in-reply-to (string)
4383   (if (string-match "<[^>]+>" string)
4384       (substring string (match-beginning 0) (match-end 0))
4385     nil))
4386
4387 (defun gnus-build-sparse-threads ()
4388   (let ((headers gnus-newsgroup-headers)
4389         (mail-parse-charset gnus-newsgroup-charset)
4390         (gnus-summary-ignore-duplicates t)
4391         header references generation relations
4392         subject child end new-child date)
4393     ;; First we create an alist of generations/relations, where
4394     ;; generations is how much we trust the relation, and the relation
4395     ;; is parent/child.
4396     (gnus-message 7 "Making sparse threads...")
4397     (save-excursion
4398       (nnheader-set-temp-buffer " *gnus sparse threads*")
4399       (while (setq header (pop headers))
4400         (when (and (setq references (mail-header-references header))
4401                    (not (string= references "")))
4402           (insert references)
4403           (setq child (mail-header-id header)
4404                 subject (mail-header-subject header)
4405                 date (mail-header-date header)
4406                 generation 0)
4407           (while (search-backward ">" nil t)
4408             (setq end (1+ (point)))
4409             (when (search-backward "<" nil t)
4410               (setq new-child (buffer-substring (point) end))
4411               (push (list (incf generation)
4412                           child (setq child new-child)
4413                           subject date)
4414                     relations)))
4415           (when child
4416             (push (list (1+ generation) child nil subject) relations))
4417           (erase-buffer)))
4418       (kill-buffer (current-buffer)))
4419     ;; Sort over trustworthiness.
4420     (dolist (relation (sort relations 'car-less-than-car))
4421       (when (gnus-dependencies-add-header
4422              (make-full-mail-header
4423               gnus-reffed-article-number
4424               (nth 3 relation) "" (or (nth 4 relation) "")
4425               (nth 1 relation)
4426               (or (nth 2 relation) "") 0 0 "")
4427              gnus-newsgroup-dependencies nil)
4428         (push gnus-reffed-article-number gnus-newsgroup-limit)
4429         (push gnus-reffed-article-number gnus-newsgroup-sparse)
4430         (push (cons gnus-reffed-article-number gnus-sparse-mark)
4431               gnus-newsgroup-reads)
4432         (decf gnus-reffed-article-number)))
4433     (gnus-message 7 "Making sparse threads...done")))
4434
4435 (defun gnus-build-old-threads ()
4436   ;; Look at all the articles that refer back to old articles, and
4437   ;; fetch the headers for the articles that aren't there.  This will
4438   ;; build complete threads - if the roots haven't been expired by the
4439   ;; server, that is.
4440   (let ((mail-parse-charset gnus-newsgroup-charset)
4441         id heads)
4442     (mapatoms
4443      (lambda (refs)
4444        (when (not (car (symbol-value refs)))
4445          (setq heads (cdr (symbol-value refs)))
4446          (while heads
4447            (if (memq (mail-header-number (caar heads))
4448                      gnus-newsgroup-dormant)
4449                (setq heads (cdr heads))
4450              (setq id (symbol-name refs))
4451              (while (and (setq id (gnus-build-get-header id))
4452                          (not (car (gnus-id-to-thread id)))))
4453              (setq heads nil)))))
4454      gnus-newsgroup-dependencies)))
4455
4456 (defsubst gnus-remove-odd-characters (string)
4457   "Translate STRING into something that doesn't contain weird characters."
4458   (mm-subst-char-in-string
4459    ?\r ?\-
4460    (mm-subst-char-in-string ?\n ?\- string t) t))
4461
4462 ;; This function has to be called with point after the article number
4463 ;; on the beginning of the line.
4464 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4465   (let ((eol (point-at-eol))
4466         (buffer (current-buffer))
4467         header references in-reply-to)
4468
4469     ;; overview: [num subject from date id refs chars lines misc]
4470     (unwind-protect
4471         (let (x)
4472           (narrow-to-region (point) eol)
4473           (unless (eobp)
4474             (forward-char))
4475
4476           (setq header
4477                 (make-full-mail-header
4478                  number                 ; number
4479                  (condition-case ()     ; subject
4480                      (gnus-remove-odd-characters
4481                       (funcall gnus-decode-encoded-word-function
4482                                (setq x (nnheader-nov-field))))
4483                    (error x))
4484                  (condition-case ()     ; from
4485                      (gnus-remove-odd-characters
4486                       (funcall gnus-decode-encoded-address-function
4487                                (setq x (nnheader-nov-field))))
4488                    (error x))
4489                  (nnheader-nov-field)   ; date
4490                  (nnheader-nov-read-message-id number)  ; id
4491                  (setq references (nnheader-nov-field)) ; refs
4492                  (nnheader-nov-read-integer) ; chars
4493                  (nnheader-nov-read-integer) ; lines
4494                  (unless (eobp)
4495                    (if (looking-at "Xref: ")
4496                        (goto-char (match-end 0)))
4497                    (nnheader-nov-field)) ; Xref
4498                  (nnheader-nov-parse-extra)))) ; extra
4499
4500       (widen))
4501
4502     (when (and (string= references "")
4503                (setq in-reply-to (mail-header-extra header))
4504                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4505       (mail-header-set-references
4506        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4507
4508     (when gnus-alter-header-function
4509       (funcall gnus-alter-header-function header))
4510     (gnus-dependencies-add-header header dependencies force-new)))
4511
4512 (defun gnus-build-get-header (id)
4513   "Look through the buffer of NOV lines and find the header to ID.
4514 Enter this line into the dependencies hash table, and return
4515 the id of the parent article (if any)."
4516   (let ((deps gnus-newsgroup-dependencies)
4517         found header)
4518     (prog1
4519         (with-current-buffer nntp-server-buffer
4520           (let ((case-fold-search nil))
4521             (goto-char (point-min))
4522             (while (and (not found)
4523                         (search-forward id nil t))
4524               (beginning-of-line)
4525               (setq found (looking-at
4526                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4527                                    (regexp-quote id))))
4528               (or found (beginning-of-line 2)))
4529             (when found
4530               (beginning-of-line)
4531               (and
4532                (setq header (gnus-nov-parse-line
4533                              (read (current-buffer)) deps))
4534                (gnus-parent-id (mail-header-references header))))))
4535       (when header
4536         (let ((number (mail-header-number header)))
4537           (push number gnus-newsgroup-limit)
4538           (push header gnus-newsgroup-headers)
4539           (if (memq number gnus-newsgroup-unselected)
4540               (progn
4541                 (setq gnus-newsgroup-unreads
4542                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4543                                                number))
4544                 (setq gnus-newsgroup-unselected
4545                       (delq number gnus-newsgroup-unselected)))
4546             (push number gnus-newsgroup-ancient)))))))
4547
4548 (defun gnus-build-all-threads ()
4549   "Read all the headers."
4550   (let ((gnus-summary-ignore-duplicates t)
4551         (mail-parse-charset gnus-newsgroup-charset)
4552         (dependencies gnus-newsgroup-dependencies)
4553         header article)
4554     (with-current-buffer nntp-server-buffer
4555       (let ((case-fold-search nil))
4556         (goto-char (point-min))
4557         (while (not (eobp))
4558           (ignore-errors
4559             (setq article (read (current-buffer))
4560                   header (gnus-nov-parse-line article dependencies t)))
4561           (when header
4562             (with-current-buffer gnus-summary-buffer
4563               (push header gnus-newsgroup-headers)
4564               (if (memq (setq article (mail-header-number header))
4565                         gnus-newsgroup-unselected)
4566                   (progn
4567                     (setq gnus-newsgroup-unreads
4568                           (gnus-add-to-sorted-list
4569                            gnus-newsgroup-unreads article))
4570                     (setq gnus-newsgroup-unselected
4571                           (delq article gnus-newsgroup-unselected)))
4572                 (push article gnus-newsgroup-ancient)))
4573             (forward-line 1)))))))
4574
4575 (defun gnus-summary-update-article-line (article header)
4576   "Update the line for ARTICLE using HEADER."
4577   (let* ((id (mail-header-id header))
4578          (thread (gnus-id-to-thread id)))
4579     (unless thread
4580       (error "Article in no thread"))
4581     ;; Update the thread.
4582     (setcar thread header)
4583     (gnus-summary-goto-subject article)
4584     (let* ((datal (gnus-data-find-list article))
4585            (data (car datal))
4586            (inhibit-read-only t)
4587            (level (gnus-summary-thread-level)))
4588       (gnus-delete-line)
4589       (let ((inserted (- (point)
4590                          (progn
4591                            (gnus-summary-insert-line
4592                             header level nil
4593                             (memq article gnus-newsgroup-undownloaded)
4594                             (gnus-article-mark article)
4595                             (memq article gnus-newsgroup-replied)
4596                             (memq article gnus-newsgroup-expirable)
4597                             ;; Only insert the Subject string when it's different
4598                             ;; from the previous Subject string.
4599                             (if (and
4600                                  gnus-show-threads
4601                                  (gnus-subject-equal
4602                                   (condition-case ()
4603                                       (mail-header-subject
4604                                        (gnus-data-header
4605                                         (cadr
4606                                          (gnus-data-find-list
4607                                           article
4608                                           (gnus-data-list t)))))
4609                                     ;; Error on the side of excessive subjects.
4610                                     (error ""))
4611                                   (mail-header-subject header)))
4612                                 ""
4613                               (mail-header-subject header))
4614                             nil (cdr (assq article gnus-newsgroup-scored))
4615                             (memq article gnus-newsgroup-processable))
4616                            (point)))))
4617         (when (cdr datal)
4618           (gnus-data-update-list
4619            (cdr datal)
4620            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4621
4622 (defun gnus-summary-update-article (article &optional iheader)
4623   "Update ARTICLE in the summary buffer."
4624   (set-buffer gnus-summary-buffer)
4625   (let* ((header (gnus-summary-article-header article))
4626          (id (mail-header-id header))
4627          (data (gnus-data-find article))
4628          (thread (gnus-id-to-thread id))
4629          (references (mail-header-references header))
4630          (parent
4631           (gnus-id-to-thread
4632            (or (gnus-parent-id
4633                 (when (and references
4634                            (not (equal "" references)))
4635                   references))
4636                "none")))
4637          (inhibit-read-only t)
4638          (old (car thread)))
4639     (when thread
4640       (unless iheader
4641         (setcar thread nil)
4642         (when parent
4643           (delq thread parent)))
4644       (if (gnus-summary-insert-subject id header)
4645           ;; Set the (possibly) new article number in the data structure.
4646           (gnus-data-set-number data (gnus-id-to-article id))
4647         (setcar thread old)
4648         nil))))
4649
4650 (defun gnus-rebuild-thread (id &optional line)
4651   "Rebuild the thread containing ID.
4652 If LINE, insert the rebuilt thread starting on line LINE."
4653   (let ((inhibit-read-only t)
4654         old-pos current thread data)
4655     (if (not gnus-show-threads)
4656         (setq thread (list (car (gnus-id-to-thread id))))
4657       ;; Get the thread this article is part of.
4658       (setq thread (gnus-remove-thread id)))
4659     (setq old-pos (point-at-bol))
4660     (setq current (save-excursion
4661                     (and (re-search-backward "[\r\n]" nil t)
4662                          (gnus-summary-article-number))))
4663     ;; If this is a gathered thread, we have to go some re-gathering.
4664     (when (stringp (car thread))
4665       (let ((subject (car thread))
4666             roots thr)
4667         (setq thread (cdr thread))
4668         (while thread
4669           (unless (memq (setq thr (gnus-id-to-thread
4670                                    (gnus-root-id
4671                                     (mail-header-id (caar thread)))))
4672                         roots)
4673             (push thr roots))
4674           (setq thread (cdr thread)))
4675         ;; We now have all (unique) roots.
4676         (if (= (length roots) 1)
4677             ;; All the loose roots are now one solid root.
4678             (setq thread (car roots))
4679           (setq thread (cons subject (gnus-sort-threads roots))))))
4680     (let (threads)
4681       ;; We then insert this thread into the summary buffer.
4682       (when line
4683         (goto-char (point-min))
4684         (forward-line (1- line)))
4685       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4686         (if gnus-show-threads
4687             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4688           (gnus-summary-prepare-unthreaded thread))
4689         (setq data (nreverse gnus-newsgroup-data))
4690         (setq threads gnus-newsgroup-threads))
4691       ;; We splice the new data into the data structure.
4692       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4693       ;;!!! then we want to insert at the beginning of the buffer.
4694       ;;!!! That happens to be true with Gnus now, but that may
4695       ;;!!! change in the future.  Perhaps.
4696       (gnus-data-enter-list
4697        (if line nil current) data (- (point) old-pos))
4698       (setq gnus-newsgroup-threads
4699             (nconc threads gnus-newsgroup-threads))
4700       (gnus-data-compute-positions))))
4701
4702 (defun gnus-number-to-header (number)
4703   "Return the header for article NUMBER."
4704   (let ((headers gnus-newsgroup-headers))
4705     (while (and headers
4706                 (not (= number (mail-header-number (car headers)))))
4707       (pop headers))
4708     (when headers
4709       (car headers))))
4710
4711 (defun gnus-parent-headers (in-headers &optional generation)
4712   "Return the headers of the GENERATIONth parent of HEADERS."
4713   (unless generation
4714     (setq generation 1))
4715   (let ((parent t)
4716         (headers in-headers)
4717         references)
4718     (while (and parent
4719                 (not (zerop generation))
4720                 (setq references (mail-header-references headers)))
4721       (setq headers (if (and references
4722                              (setq parent (gnus-parent-id references)))
4723                         (car (gnus-id-to-thread parent))
4724                       nil))
4725       (decf generation))
4726     (and (not (eq headers in-headers))
4727          headers)))
4728
4729 (defun gnus-id-to-thread (id)
4730   "Return the (sub-)thread where ID appears."
4731   (gnus-gethash id gnus-newsgroup-dependencies))
4732
4733 (defun gnus-id-to-article (id)
4734   "Return the article number of ID."
4735   (let ((thread (gnus-id-to-thread id)))
4736     (when (and thread
4737                (car thread))
4738       (mail-header-number (car thread)))))
4739
4740 (defun gnus-id-to-header (id)
4741   "Return the article headers of ID."
4742   (car (gnus-id-to-thread id)))
4743
4744 (defun gnus-article-displayed-root-p (article)
4745   "Say whether ARTICLE is a root(ish) article."
4746   (let ((level (gnus-summary-thread-level article))
4747         (refs (mail-header-references  (gnus-summary-article-header article)))
4748         particle)
4749     (cond
4750      ((null level) nil)
4751      ((zerop level) t)
4752      ((null refs) t)
4753      ((null (gnus-parent-id refs)) t)
4754      ((and (= 1 level)
4755            (null (setq particle (gnus-id-to-article
4756                                  (gnus-parent-id refs))))
4757            (null (gnus-summary-thread-level particle)))))))
4758
4759 (defun gnus-root-id (id)
4760   "Return the id of the root of the thread where ID appears."
4761   (let (last-id prev)
4762     (while (and id (setq prev (car (gnus-id-to-thread id))))
4763       (setq last-id id
4764             id (gnus-parent-id (mail-header-references prev))))
4765     last-id))
4766
4767 (defun gnus-articles-in-thread (thread)
4768   "Return the list of articles in THREAD."
4769   (cons (mail-header-number (car thread))
4770         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4771
4772 (defun gnus-remove-thread (id &optional dont-remove)
4773   "Remove the thread that has ID in it."
4774   (let (headers thread last-id)
4775     ;; First go up in this thread until we find the root.
4776     (setq last-id (gnus-root-id id)
4777           headers (message-flatten-list (gnus-id-to-thread last-id)))
4778     ;; We have now found the real root of this thread.  It might have
4779     ;; been gathered into some loose thread, so we have to search
4780     ;; through the threads to find the thread we wanted.
4781     (let ((threads gnus-newsgroup-threads)
4782           sub)
4783       (while threads
4784         (setq sub (car threads))
4785         (if (stringp (car sub))
4786             ;; This is a gathered thread, so we look at the roots
4787             ;; below it to find whether this article is in this
4788             ;; gathered root.
4789             (progn
4790               (setq sub (cdr sub))
4791               (while sub
4792                 (when (member (caar sub) headers)
4793                   (setq thread (car threads)
4794                         threads nil
4795                         sub nil))
4796                 (setq sub (cdr sub))))
4797           ;; It's an ordinary thread, so we check it.
4798           (when (eq (car sub) (car headers))
4799             (setq thread sub
4800                   threads nil)))
4801         (setq threads (cdr threads)))
4802       ;; If this article is in no thread, then it's a root.
4803       (if thread
4804           (unless dont-remove
4805             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4806         (setq thread (gnus-id-to-thread last-id)))
4807       (when thread
4808         (prog1
4809             thread                      ; We return this thread.
4810           (unless dont-remove
4811             (if (stringp (car thread))
4812                 (progn
4813                   ;; If we use dummy roots, then we have to remove the
4814                   ;; dummy root as well.
4815                   (when (eq gnus-summary-make-false-root 'dummy)
4816                     ;; We go to the dummy root by going to
4817                     ;; the first sub-"thread", and then one line up.
4818                     (gnus-summary-goto-article
4819                      (mail-header-number (caadr thread)))
4820                     (forward-line -1)
4821                     (gnus-delete-line)
4822                     (gnus-data-compute-positions))
4823                   (setq thread (cdr thread))
4824                   (while thread
4825                     (gnus-remove-thread-1 (car thread))
4826                     (setq thread (cdr thread))))
4827               (gnus-remove-thread-1 thread))))))))
4828
4829 (defun gnus-remove-thread-1 (thread)
4830   "Remove the thread THREAD recursively."
4831   (let ((number (mail-header-number (pop thread)))
4832         d)
4833     (setq thread (reverse thread))
4834     (while thread
4835       (gnus-remove-thread-1 (pop thread)))
4836     (when (setq d (gnus-data-find number))
4837       (goto-char (gnus-data-pos d))
4838       (gnus-summary-show-thread)
4839       (gnus-data-remove
4840        number
4841        (- (point-at-bol)
4842           (prog1
4843               (1+ (point-at-eol))
4844             (gnus-delete-line)))))))
4845
4846 (defun gnus-sort-threads-recursive (threads func)
4847   (sort (mapcar (lambda (thread)
4848                   (cons (car thread)
4849                         (and (cdr thread)
4850                              (gnus-sort-threads-recursive (cdr thread) func))))
4851                 threads) func))
4852
4853 (defun gnus-sort-threads-loop (threads func)
4854   (let* ((superthread (cons nil threads))
4855          (stack (list (cons superthread threads)))
4856          remaining-threads thread)
4857     (while stack
4858       (setq remaining-threads (cdr (car stack)))
4859       (if remaining-threads
4860           (progn (setq thread (car remaining-threads))
4861                  (setcdr (car stack) (cdr remaining-threads))
4862                  (if (cdr thread)
4863                      (push (cons thread (cdr thread)) stack)))
4864         (setq thread (caar stack))
4865         (setcdr thread (sort (cdr thread) func))
4866         (pop stack)))
4867     (cdr superthread)))
4868
4869 (defun gnus-sort-threads (threads)
4870   "Sort THREADS."
4871   (if (not gnus-thread-sort-functions)
4872       threads
4873     (gnus-message 8 "Sorting threads...")
4874     (prog1
4875         (condition-case nil
4876             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4877               (gnus-sort-threads-recursive
4878                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4879           ;; Even after binding max-lisp-eval-depth, the recursive
4880           ;; sorter might fail for very long threads.  In that case,
4881           ;; try using a (less well-tested) non-recursive sorter.
4882           (error (gnus-message 9 "Sorting threads with loop...")
4883                  (gnus-sort-threads-loop
4884                   threads (gnus-make-sort-function
4885                            gnus-thread-sort-functions))))
4886       (gnus-message 8 "Sorting threads...done"))))
4887
4888 (defun gnus-sort-articles (articles)
4889   "Sort ARTICLES."
4890   (when gnus-article-sort-functions
4891     (gnus-message 7 "Sorting articles...")
4892     (prog1
4893         (setq gnus-newsgroup-headers
4894               (sort articles (gnus-make-sort-function
4895                               gnus-article-sort-functions)))
4896       (gnus-message 7 "Sorting articles...done"))))
4897
4898 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4899 (defmacro gnus-thread-header (thread)
4900   "Return header of first article in THREAD.
4901 Note that THREAD must never, ever be anything else than a variable -
4902 using some other form will lead to serious barfage."
4903   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4904   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4905   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4906         (vector thread) 2))
4907
4908 (defsubst gnus-article-sort-by-number (h1 h2)
4909   "Sort articles by article number."
4910   (< (mail-header-number h1)
4911      (mail-header-number h2)))
4912
4913 (defun gnus-thread-sort-by-number (h1 h2)
4914   "Sort threads by root article number."
4915   (gnus-article-sort-by-number
4916    (gnus-thread-header h1) (gnus-thread-header h2)))
4917
4918 (defsubst gnus-article-sort-by-random (h1 h2)
4919   "Sort articles randomly."
4920   (zerop (random 2)))
4921
4922 (defun gnus-thread-sort-by-random (h1 h2)
4923   "Sort threads randomly."
4924   (gnus-article-sort-by-random
4925    (gnus-thread-header h1) (gnus-thread-header h2)))
4926
4927 (defsubst gnus-article-sort-by-lines (h1 h2)
4928   "Sort articles by article Lines header."
4929   (< (mail-header-lines h1)
4930      (mail-header-lines h2)))
4931
4932 (defun gnus-thread-sort-by-lines (h1 h2)
4933   "Sort threads by root article Lines header."
4934   (gnus-article-sort-by-lines
4935    (gnus-thread-header h1) (gnus-thread-header h2)))
4936
4937 (defsubst gnus-article-sort-by-chars (h1 h2)
4938   "Sort articles by octet length."
4939   (< (mail-header-chars h1)
4940      (mail-header-chars h2)))
4941
4942 (defun gnus-thread-sort-by-chars (h1 h2)
4943   "Sort threads by root article octet length."
4944   (gnus-article-sort-by-chars
4945    (gnus-thread-header h1) (gnus-thread-header h2)))
4946
4947 (defsubst gnus-article-sort-by-author (h1 h2)
4948   "Sort articles by root author."
4949   (gnus-string<
4950    (let ((extract (funcall
4951                    gnus-extract-address-components
4952                    (mail-header-from h1))))
4953      (or (car extract) (cadr extract) ""))
4954    (let ((extract (funcall
4955                    gnus-extract-address-components
4956                    (mail-header-from h2))))
4957      (or (car extract) (cadr extract) ""))))
4958
4959 (defun gnus-thread-sort-by-author (h1 h2)
4960   "Sort threads by root author."
4961   (gnus-article-sort-by-author
4962    (gnus-thread-header h1)  (gnus-thread-header h2)))
4963
4964 (defsubst gnus-article-sort-by-recipient (h1 h2)
4965   "Sort articles by recipient."
4966   (gnus-string<
4967    (let ((extract (funcall
4968                    gnus-extract-address-components
4969                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4970      (or (car extract) (cadr extract)))
4971    (let ((extract (funcall
4972                    gnus-extract-address-components
4973                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4974      (or (car extract) (cadr extract)))))
4975
4976 (defun gnus-thread-sort-by-recipient (h1 h2)
4977   "Sort threads by root recipient."
4978   (gnus-article-sort-by-recipient
4979    (gnus-thread-header h1) (gnus-thread-header h2)))
4980
4981 (defsubst gnus-article-sort-by-subject (h1 h2)
4982   "Sort articles by root subject."
4983   (gnus-string<
4984    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4985    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4986
4987 (defun gnus-thread-sort-by-subject (h1 h2)
4988   "Sort threads by root subject."
4989   (gnus-article-sort-by-subject
4990    (gnus-thread-header h1) (gnus-thread-header h2)))
4991
4992 (defsubst gnus-article-sort-by-date (h1 h2)
4993   "Sort articles by root article date."
4994   (time-less-p
4995    (gnus-date-get-time (mail-header-date h1))
4996    (gnus-date-get-time (mail-header-date h2))))
4997
4998 (defun gnus-thread-sort-by-date (h1 h2)
4999   "Sort threads by root article date."
5000   (gnus-article-sort-by-date
5001    (gnus-thread-header h1) (gnus-thread-header h2)))
5002
5003 (defsubst gnus-article-sort-by-score (h1 h2)
5004   "Sort articles by root article score.
5005 Unscored articles will be counted as having a score of zero."
5006   (> (or (cdr (assq (mail-header-number h1)
5007                     gnus-newsgroup-scored))
5008          gnus-summary-default-score 0)
5009      (or (cdr (assq (mail-header-number h2)
5010                     gnus-newsgroup-scored))
5011          gnus-summary-default-score 0)))
5012
5013 (defun gnus-thread-sort-by-score (h1 h2)
5014   "Sort threads by root article score."
5015   (gnus-article-sort-by-score
5016    (gnus-thread-header h1) (gnus-thread-header h2)))
5017
5018 (defun gnus-thread-sort-by-total-score (h1 h2)
5019   "Sort threads by the sum of all scores in the thread.
5020 Unscored articles will be counted as having a score of zero."
5021   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
5022
5023 (defun gnus-thread-total-score (thread)
5024   ;; This function find the total score of THREAD.
5025   (cond
5026    ((null thread)
5027     0)
5028    ((consp thread)
5029     (if (stringp (car thread))
5030         (apply gnus-thread-score-function 0
5031                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
5032       (gnus-thread-total-score-1 thread)))
5033    (t
5034     (gnus-thread-total-score-1 (list thread)))))
5035
5036 (defun gnus-article-sort-by-most-recent-number (h1 h2)
5037   "Sort articles by number."
5038   (gnus-article-sort-by-number h1 h2))
5039
5040 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
5041   "Sort threads such that the thread with the most recently arrived article comes first."
5042   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
5043
5044 (defun gnus-thread-highest-number (thread)
5045   "Return the highest article number in THREAD."
5046   (apply 'max (mapcar (lambda (header)
5047                         (mail-header-number header))
5048                       (message-flatten-list thread))))
5049
5050 (defun gnus-article-sort-by-most-recent-date (h1 h2)
5051   "Sort articles by number."
5052   (gnus-article-sort-by-date h1 h2))
5053
5054 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
5055   "Sort threads such that the thread with the most recently dated article comes first."
5056   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
5057
5058 ; Since this is called not only to sort the top-level threads, but
5059 ; also in recursive sorts to order the articles within a thread, each
5060 ; article will be processed many times.  Thus it speeds things up
5061 ; quite a bit to use gnus-date-get-time, which caches the time value.
5062 (defun gnus-thread-latest-date (thread)
5063   "Return the highest article date in THREAD."
5064   (apply 'max
5065          (mapcar (lambda (header) (gnus-float-time
5066                                    (gnus-date-get-time
5067                                     (mail-header-date header))))
5068                  (message-flatten-list thread))))
5069
5070 (defun gnus-thread-total-score-1 (root)
5071   ;; This function find the total score of the thread below ROOT.
5072   (setq root (car root))
5073   (apply gnus-thread-score-function
5074          (or (append
5075               (mapcar 'gnus-thread-total-score
5076                       (cdr (gnus-id-to-thread (mail-header-id root))))
5077               (when (> (mail-header-number root) 0)
5078                 (list (or (cdr (assq (mail-header-number root)
5079                                      gnus-newsgroup-scored))
5080                           gnus-summary-default-score 0))))
5081              (list gnus-summary-default-score)
5082              '(0))))
5083
5084 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
5085 (defvar gnus-tmp-prev-subject nil)
5086 (defvar gnus-tmp-false-parent nil)
5087 (defvar gnus-tmp-root-expunged nil)
5088 (defvar gnus-tmp-dummy-line nil)
5089
5090 (defun gnus-extra-header (type &optional header)
5091   "Return the extra header of TYPE."
5092   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
5093       ""))
5094
5095 (defvar gnus-tmp-thread-tree-header-string "")
5096
5097 (defcustom gnus-sum-thread-tree-root "> "
5098   "With %B spec, used for the root of a thread.
5099 If nil, use subject instead."
5100   :version "22.1"
5101   :type '(radio (const :format "%v  " nil) string)
5102   :group 'gnus-thread)
5103
5104 (defcustom gnus-sum-thread-tree-false-root "> "
5105   "With %B spec, used for a false root of a thread.
5106 If nil, use subject instead."
5107   :version "22.1"
5108   :type '(radio (const :format "%v  " nil) string)
5109   :group 'gnus-thread)
5110
5111 (defcustom gnus-sum-thread-tree-single-indent ""
5112   "With %B spec, used for a thread with just one message.
5113 If nil, use subject instead."
5114   :version "22.1"
5115   :type '(radio (const :format "%v  " nil) string)
5116   :group 'gnus-thread)
5117
5118 (defcustom gnus-sum-thread-tree-vertical "| "
5119   "With %B spec, used for drawing a vertical line."
5120   :version "22.1"
5121   :type 'string
5122   :group 'gnus-thread)
5123
5124 (defcustom gnus-sum-thread-tree-indent "  "
5125   "With %B spec, used for indenting."
5126   :version "22.1"
5127   :type 'string
5128   :group 'gnus-thread)
5129
5130 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5131   "With %B spec, used for a leaf with brothers."
5132   :version "22.1"
5133   :type 'string
5134   :group 'gnus-thread)
5135
5136 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5137   "With %B spec, used for a leaf without brothers."
5138   :version "22.1"
5139   :type 'string
5140   :group 'gnus-thread)
5141
5142 (defcustom gnus-summary-display-while-building nil
5143   "If non-nil, show and update the summary buffer as it's being built.
5144 If the value is t, update the buffer after every line is inserted.  If
5145 the value is an integer (N), update the display every N lines."
5146   :version "22.1"
5147   :group 'gnus-thread
5148   :type '(choice (const :tag "off" nil)
5149                  number
5150                  (const :tag "frequently" t)))
5151
5152 (defun gnus-summary-prepare-threads (threads)
5153   "Prepare summary buffer from THREADS and indentation LEVEL.
5154 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5155 or a straight list of headers."
5156   (gnus-message 7 "Generating summary...")
5157
5158   (setq gnus-newsgroup-threads threads)
5159   (beginning-of-line)
5160
5161   (let ((gnus-tmp-level 0)
5162         (default-score (or gnus-summary-default-score 0))
5163         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5164         (building-line-count gnus-summary-display-while-building)
5165         (building-count (integerp gnus-summary-display-while-building))
5166         thread number subject stack state gnus-tmp-gathered beg-match
5167         new-roots gnus-tmp-new-adopts thread-end simp-subject
5168         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5169         gnus-tmp-replied gnus-tmp-subject-or-nil
5170         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5171         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5172         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5173         tree-stack)
5174
5175     (setq gnus-tmp-prev-subject nil
5176           gnus-tmp-thread-tree-header-string "")
5177
5178     (if (vectorp (car threads))
5179         ;; If this is a straight (sic) list of headers, then a
5180         ;; threaded summary display isn't required, so we just create
5181         ;; an unthreaded one.
5182         (gnus-summary-prepare-unthreaded threads)
5183
5184       ;; Do the threaded display.
5185
5186       (if gnus-summary-display-while-building
5187           (switch-to-buffer (buffer-name)))
5188       (while (or threads stack gnus-tmp-new-adopts new-roots)
5189
5190         (if (and (= gnus-tmp-level 0)
5191                  (or (not stack)
5192                      (= (caar stack) 0))
5193                  (not gnus-tmp-false-parent)
5194                  (or gnus-tmp-new-adopts new-roots))
5195             (if gnus-tmp-new-adopts
5196                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5197                       thread (list (car gnus-tmp-new-adopts))
5198                       gnus-tmp-header (caar thread)
5199                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5200               (when new-roots
5201                 (setq thread (list (car new-roots))
5202                       gnus-tmp-header (caar thread)
5203                       new-roots (cdr new-roots))))
5204
5205           (if threads
5206               ;; If there are some threads, we do them before the
5207               ;; threads on the stack.
5208               (setq thread threads
5209                     gnus-tmp-header (caar thread))
5210             ;; There were no current threads, so we pop something off
5211             ;; the stack.
5212             (setq state (car stack)
5213                   gnus-tmp-level (car state)
5214                   tree-stack (cadr state)
5215                   thread (caddr state)
5216                   stack (cdr stack)
5217                   gnus-tmp-header (caar thread))))
5218
5219         (setq gnus-tmp-false-parent nil)
5220         (setq gnus-tmp-root-expunged nil)
5221         (setq thread-end nil)
5222
5223         (if (stringp gnus-tmp-header)
5224             ;; The header is a dummy root.
5225             (cond
5226              ((eq gnus-summary-make-false-root 'adopt)
5227               ;; We let the first article adopt the rest.
5228               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5229                                                (cddar thread)))
5230               (setq gnus-tmp-gathered
5231                     (nconc (mapcar
5232                             (lambda (h) (mail-header-number (car h)))
5233                             (cddar thread))
5234                            gnus-tmp-gathered))
5235               (setq thread (cons (list (caar thread)
5236                                        (cadar thread))
5237                                  (cdr thread)))
5238               (setq gnus-tmp-level -1
5239                     gnus-tmp-false-parent t))
5240              ((eq gnus-summary-make-false-root 'empty)
5241               ;; We print adopted articles with empty subject fields.
5242               (setq gnus-tmp-gathered
5243                     (nconc (mapcar
5244                             (lambda (h) (mail-header-number (car h)))
5245                             (cddar thread))
5246                            gnus-tmp-gathered))
5247               (setq gnus-tmp-level -1))
5248              ((eq gnus-summary-make-false-root 'dummy)
5249               ;; We remember that we probably want to output a dummy
5250               ;; root.
5251               (setq gnus-tmp-dummy-line gnus-tmp-header)
5252               (setq gnus-tmp-prev-subject gnus-tmp-header))
5253              (t
5254               ;; We do not make a root for the gathered
5255               ;; sub-threads at all.
5256               (setq gnus-tmp-level -1)))
5257
5258           (setq number (mail-header-number gnus-tmp-header)
5259                 subject (mail-header-subject gnus-tmp-header)
5260                 simp-subject (gnus-simplify-subject-fully subject))
5261
5262           (cond
5263            ;; If the thread has changed subject, we might want to make
5264            ;; this subthread into a root.
5265            ((and (null gnus-thread-ignore-subject)
5266                  (not (zerop gnus-tmp-level))
5267                  gnus-tmp-prev-subject
5268                  (not (string= gnus-tmp-prev-subject simp-subject)))
5269             (setq new-roots (nconc new-roots (list (car thread)))
5270                   thread-end t
5271                   gnus-tmp-header nil))
5272            ;; If the article lies outside the current limit,
5273            ;; then we do not display it.
5274            ((not (memq number gnus-newsgroup-limit))
5275             (setq gnus-tmp-gathered
5276                   (nconc (mapcar
5277                           (lambda (h) (mail-header-number (car h)))
5278                           (cdar thread))
5279                          gnus-tmp-gathered))
5280             (setq gnus-tmp-new-adopts (if (cdar thread)
5281                                           (append gnus-tmp-new-adopts
5282                                                   (cdar thread))
5283                                         gnus-tmp-new-adopts)
5284                   thread-end t
5285                   gnus-tmp-header nil)
5286             (when (zerop gnus-tmp-level)
5287               (setq gnus-tmp-root-expunged t)))
5288            ;; Perhaps this article is to be marked as read?
5289            ((and gnus-summary-mark-below
5290                  (< (or (cdr (assq number gnus-newsgroup-scored))
5291                         default-score)
5292                     gnus-summary-mark-below)
5293                  ;; Don't touch sparse articles.
5294                  (not (gnus-summary-article-sparse-p number))
5295                  (not (gnus-summary-article-ancient-p number)))
5296             (setq gnus-newsgroup-unreads
5297                   (delq number gnus-newsgroup-unreads))
5298             (if gnus-newsgroup-auto-expire
5299                 (setq gnus-newsgroup-expirable
5300                       (gnus-add-to-sorted-list
5301                        gnus-newsgroup-expirable number))
5302               (push (cons number gnus-low-score-mark)
5303                     gnus-newsgroup-reads))))
5304
5305           (when gnus-tmp-header
5306             ;; We may have an old dummy line to output before this
5307             ;; article.
5308             (when (and gnus-tmp-dummy-line
5309                        (gnus-subject-equal
5310                         gnus-tmp-dummy-line
5311                         (mail-header-subject gnus-tmp-header)))
5312               (gnus-summary-insert-dummy-line
5313                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5314               (setq gnus-tmp-dummy-line nil))
5315
5316             ;; Compute the mark.
5317             (setq gnus-tmp-unread (gnus-article-mark number))
5318
5319             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5320                                   gnus-tmp-header gnus-tmp-level)
5321                   gnus-newsgroup-data)
5322
5323             ;; Actually insert the line.
5324             (setq
5325              gnus-tmp-subject-or-nil
5326              (cond
5327               ((and gnus-thread-ignore-subject
5328                     gnus-tmp-prev-subject
5329                     (not (string= gnus-tmp-prev-subject simp-subject)))
5330                subject)
5331               ((zerop gnus-tmp-level)
5332                (if (and (eq gnus-summary-make-false-root 'empty)
5333                         (memq number gnus-tmp-gathered)
5334                         gnus-tmp-prev-subject
5335                         (string= gnus-tmp-prev-subject simp-subject))
5336                    gnus-summary-same-subject
5337                  subject))
5338               (t gnus-summary-same-subject)))
5339             (if (and (eq gnus-summary-make-false-root 'adopt)
5340                      (= gnus-tmp-level 1)
5341                      (memq number gnus-tmp-gathered))
5342                 (setq gnus-tmp-opening-bracket ?\<
5343                       gnus-tmp-closing-bracket ?\>)
5344               (setq gnus-tmp-opening-bracket ?\[
5345                     gnus-tmp-closing-bracket ?\]))
5346             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5347                 (gnus-make-thread-indent-array
5348                  (max (* 2 (length gnus-thread-indent-array))
5349                       gnus-tmp-level)))
5350             (setq
5351              gnus-tmp-indentation
5352              (aref gnus-thread-indent-array gnus-tmp-level)
5353              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5354              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5355                                 gnus-summary-default-score 0)
5356              gnus-tmp-score-char
5357              (if (or (null gnus-summary-default-score)
5358                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5359                          gnus-summary-zcore-fuzz))
5360                  ?                      ;Whitespace
5361                (if (< gnus-tmp-score gnus-summary-default-score)
5362                    gnus-score-below-mark gnus-score-over-mark))
5363              gnus-tmp-replied
5364              (cond ((memq number gnus-newsgroup-processable)
5365                     gnus-process-mark)
5366                    ((memq number gnus-newsgroup-cached)
5367                     gnus-cached-mark)
5368                    ((memq number gnus-newsgroup-replied)
5369                     gnus-replied-mark)
5370                    ((memq number gnus-newsgroup-forwarded)
5371                     gnus-forwarded-mark)
5372                    ((memq number gnus-newsgroup-saved)
5373                     gnus-saved-mark)
5374                    ((memq number gnus-newsgroup-unseen)
5375                     gnus-unseen-mark)
5376                    (t gnus-no-mark))
5377              gnus-tmp-downloaded
5378              (cond ((memq number gnus-newsgroup-undownloaded)
5379                     gnus-undownloaded-mark)
5380                    (gnus-newsgroup-agentized
5381                     gnus-downloaded-mark)
5382                    (t
5383                     gnus-no-mark))
5384              gnus-tmp-from (mail-header-from gnus-tmp-header)
5385              gnus-tmp-name
5386              (cond
5387               ((string-match "<[^>]+> *$" gnus-tmp-from)
5388                (setq beg-match (match-beginning 0))
5389                (or (and (string-match "^\".+\"" gnus-tmp-from)
5390                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5391                    (substring gnus-tmp-from 0 beg-match)))
5392               ((string-match "(.+)" gnus-tmp-from)
5393                (substring gnus-tmp-from
5394                           (1+ (match-beginning 0)) (1- (match-end 0))))
5395               (t gnus-tmp-from))
5396
5397              ;; Do the %B string
5398              gnus-tmp-thread-tree-header-string
5399              (cond
5400               ((not gnus-show-threads) "")
5401               ((zerop gnus-tmp-level)
5402                (cond ((cdar thread)
5403                       (or gnus-sum-thread-tree-root subject))
5404                      (gnus-tmp-new-adopts
5405                       (or gnus-sum-thread-tree-false-root subject))
5406                      (t
5407                       (or gnus-sum-thread-tree-single-indent subject))))
5408               (t
5409                (concat (apply 'concat
5410                               (mapcar (lambda (item)
5411                                         (if (= item 1)
5412                                             gnus-sum-thread-tree-vertical
5413                                           gnus-sum-thread-tree-indent))
5414                                       (cdr (reverse tree-stack))))
5415                        (if (nth 1 thread)
5416                            gnus-sum-thread-tree-leaf-with-other
5417                          gnus-sum-thread-tree-single-leaf)))))
5418             (when (string= gnus-tmp-name "")
5419               (setq gnus-tmp-name gnus-tmp-from))
5420             (unless (numberp gnus-tmp-lines)
5421               (setq gnus-tmp-lines -1))
5422             (if (= gnus-tmp-lines -1)
5423                 (setq gnus-tmp-lines "?")
5424               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5425             (gnus-put-text-property
5426              (point)
5427              (progn (eval gnus-summary-line-format-spec) (point))
5428              'gnus-number number)
5429             (when gnus-visual-p
5430               (forward-line -1)
5431               (gnus-summary-highlight-line)
5432               (when gnus-summary-update-hook
5433                 (gnus-run-hooks 'gnus-summary-update-hook))
5434               (forward-line 1))
5435
5436             (setq gnus-tmp-prev-subject simp-subject)))
5437
5438         (when (nth 1 thread)
5439           (push (list (max 0 gnus-tmp-level)
5440                       (copy-sequence tree-stack)
5441                       (nthcdr 1 thread))
5442                 stack))
5443         (push (if (nth 1 thread) 1 0) tree-stack)
5444         (incf gnus-tmp-level)
5445         (setq threads (if thread-end nil (cdar thread)))
5446         (if gnus-summary-display-while-building
5447             (if building-count
5448                 (progn
5449                   ;; use a set frequency
5450                   (setq building-line-count (1- building-line-count))
5451                   (when (= building-line-count 0)
5452                     (sit-for 0)
5453                     (setq building-line-count
5454                           gnus-summary-display-while-building)))
5455               ;; always
5456               (sit-for 0)))
5457         (unless threads
5458           (setq gnus-tmp-level 0)))))
5459   (gnus-message 7 "Generating summary...done"))
5460
5461 (defun gnus-summary-prepare-unthreaded (headers)
5462   "Generate an unthreaded summary buffer based on HEADERS."
5463   (let (header number mark)
5464
5465     (beginning-of-line)
5466
5467     (while headers
5468       ;; We may have to root out some bad articles...
5469       (when (memq (setq number (mail-header-number
5470                                 (setq header (pop headers))))
5471                   gnus-newsgroup-limit)
5472         ;; Mark article as read when it has a low score.
5473         (when (and gnus-summary-mark-below
5474                    (< (or (cdr (assq number gnus-newsgroup-scored))
5475                           gnus-summary-default-score 0)
5476                       gnus-summary-mark-below)
5477                    (not (gnus-summary-article-ancient-p number)))
5478           (setq gnus-newsgroup-unreads
5479                 (delq number gnus-newsgroup-unreads))
5480           (if gnus-newsgroup-auto-expire
5481               (push number gnus-newsgroup-expirable)
5482             (push (cons number gnus-low-score-mark)
5483                   gnus-newsgroup-reads)))
5484
5485         (setq mark (gnus-article-mark number))
5486         (push (gnus-data-make number mark (1+ (point)) header 0)
5487               gnus-newsgroup-data)
5488         (gnus-summary-insert-line
5489          header 0 number
5490          (memq number gnus-newsgroup-undownloaded)
5491          mark (memq number gnus-newsgroup-replied)
5492          (memq number gnus-newsgroup-expirable)
5493          (mail-header-subject header) nil
5494          (cdr (assq number gnus-newsgroup-scored))
5495          (memq number gnus-newsgroup-processable))))))
5496
5497 (defun gnus-group-get-list-identifiers (group)
5498   "Get list identifier regexp for GROUP."
5499   (or (gnus-parameter-list-identifier group)
5500       (if (consp gnus-list-identifiers)
5501           (mapconcat 'identity gnus-list-identifiers " *\\|")
5502         gnus-list-identifiers)))
5503
5504 (defun gnus-summary-remove-list-identifiers ()
5505   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5506   (let ((regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
5507         changed subject)
5508     (when regexp
5509       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5510       (dolist (header gnus-newsgroup-headers)
5511         (setq subject (mail-header-subject header)
5512               changed nil)
5513         (while (string-match regexp subject)
5514           (setq subject
5515                 (concat (substring subject 0 (match-beginning 1))
5516                         (substring subject (match-end 0)))
5517                 changed t))
5518         (when changed
5519           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5520             (setq subject
5521                   (concat (substring subject 0 (match-beginning 1))
5522                           (substring subject (match-end 1)))))
5523           (mail-header-set-subject header subject))))))
5524
5525 (defun gnus-fetch-headers (articles &optional limit force-new dependencies)
5526   "Fetch headers of ARTICLES."
5527   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5528     (gnus-message 7 "Fetching headers for %s..." name)
5529     (prog1
5530         (if (eq 'nov
5531                 (setq gnus-headers-retrieved-by
5532                       (gnus-retrieve-headers
5533                        articles gnus-newsgroup-name
5534                        (or limit
5535                            ;; We might want to fetch old headers, but
5536                            ;; not if there is only 1 article.
5537                            (and (or (and
5538                                      (not (eq gnus-fetch-old-headers 'some))
5539                                      (not (numberp gnus-fetch-old-headers)))
5540                                     (> (length articles) 1))
5541                                 gnus-fetch-old-headers)))))
5542             (gnus-get-newsgroup-headers-xover
5543              articles force-new dependencies gnus-newsgroup-name t)
5544           (gnus-get-newsgroup-headers dependencies force-new))
5545       (gnus-message 7 "Fetching headers for %s...done" name))))
5546
5547 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5548   "Select newsgroup GROUP.
5549 If READ-ALL is non-nil, all articles in the group are selected.
5550 If SELECT-ARTICLES, only select those articles from GROUP."
5551   (let* ((entry (gnus-group-entry group))
5552          ;;!!! Dirty hack; should be removed.
5553          (gnus-summary-ignore-duplicates
5554           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5555               t
5556             gnus-summary-ignore-duplicates))
5557          (info (nth 2 entry))
5558          charset articles fetched-articles cached)
5559
5560     (unless (gnus-check-server
5561              (set (make-local-variable 'gnus-current-select-method)
5562                   (gnus-find-method-for-group group)))
5563       (error "Couldn't open server"))
5564     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5565
5566     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5567         (gnus-activate-group group)     ; Or we can activate it...
5568         (progn                          ; Or we bug out.
5569           (when (equal major-mode 'gnus-summary-mode)
5570             (gnus-kill-buffer (current-buffer)))
5571           (error
5572            "Couldn't activate group %s: %s"
5573            (mm-decode-coding-string group charset)
5574            (mm-decode-coding-string (gnus-status-message group) charset))))
5575
5576     (unless (gnus-request-group group t)
5577       (when (equal major-mode 'gnus-summary-mode)
5578         (gnus-kill-buffer (current-buffer)))
5579       (error "Couldn't request group %s: %s"
5580              (mm-decode-coding-string group charset)
5581              (mm-decode-coding-string (gnus-status-message group) charset)))
5582
5583     (when (and gnus-agent
5584                (gnus-active group))
5585       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5586
5587       (setq gnus-summary-use-undownloaded-faces
5588             (gnus-agent-find-parameter
5589              group
5590              'agent-enable-undownloaded-faces)))
5591
5592     (setq gnus-newsgroup-name group
5593           gnus-newsgroup-unselected nil
5594           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5595
5596     (let ((display (gnus-group-find-parameter group 'display)))
5597       (setq gnus-newsgroup-display
5598             (cond
5599              ((not (zerop (or (car-safe read-all) 0)))
5600               ;; The user entered the group with C-u SPC/RET, let's show
5601               ;; all articles.
5602               'gnus-not-ignore)
5603              ((eq display 'all)
5604               'gnus-not-ignore)
5605              ((arrayp display)
5606               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5607              ((numberp display)
5608               ;; The following is probably the "correct" solution, but
5609               ;; it makes Gnus fetch all headers and then limit the
5610               ;; articles (which is slow), so instead we hack the
5611               ;; select-articles parameter instead. -- Simon Josefsson
5612               ;; <jas@kth.se>
5613               ;;
5614               ;; (gnus-byte-compile
5615               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5616               ;;                         display)))))
5617               (setq select-articles
5618                     (gnus-uncompress-range
5619                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5620                              (if (> tmp 0)
5621                                  tmp
5622                                1))
5623                            (cdr (gnus-active group)))))
5624               nil)
5625              (t
5626               nil))))
5627
5628     (gnus-summary-setup-default-charset)
5629
5630     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5631     (when (gnus-virtual-group-p group)
5632       (setq cached gnus-newsgroup-cached))
5633
5634     (setq gnus-newsgroup-unreads
5635           (gnus-sorted-ndifference
5636            (gnus-sorted-ndifference gnus-newsgroup-unreads
5637                                     gnus-newsgroup-marked)
5638            gnus-newsgroup-dormant))
5639
5640     (setq gnus-newsgroup-processable nil)
5641
5642     (gnus-update-read-articles group gnus-newsgroup-unreads t)
5643
5644     ;; Adjust and set lists of article marks.
5645     (when info
5646       (gnus-adjust-marked-articles info))
5647     (if (setq articles select-articles)
5648         (setq gnus-newsgroup-unselected
5649               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5650       (setq articles (gnus-articles-to-read group read-all)))
5651
5652     (cond
5653      ((null articles)
5654       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5655       'quit)
5656      ((eq articles 0) nil)
5657      (t
5658       ;; Init the dependencies hash table.
5659       (setq gnus-newsgroup-dependencies
5660             (gnus-make-hashtable (length articles)))
5661       (if (gnus-buffer-live-p gnus-group-buffer)
5662           (gnus-set-global-variables)
5663         (set-default 'gnus-newsgroup-name gnus-newsgroup-name))
5664       ;; Retrieve the headers and read them in.
5665
5666       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5667
5668       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5669       (when cached
5670         (setq gnus-newsgroup-cached cached))
5671
5672       ;; Suppress duplicates?
5673       (when gnus-suppress-duplicates
5674         (gnus-dup-suppress-articles))
5675
5676       ;; Set the initial limit.
5677       (setq gnus-newsgroup-limit (copy-sequence articles))
5678       ;; Remove canceled articles from the list of unread articles.
5679       (setq fetched-articles
5680             (mapcar (lambda (headers) (mail-header-number headers))
5681                     gnus-newsgroup-headers))
5682       (setq gnus-newsgroup-articles fetched-articles)
5683       (setq gnus-newsgroup-unreads
5684             (gnus-sorted-nintersection
5685              gnus-newsgroup-unreads fetched-articles))
5686       (gnus-compute-unseen-list)
5687
5688       ;; Removed marked articles that do not exist.
5689       (gnus-update-missing-marks
5690        (gnus-sorted-difference articles fetched-articles))
5691       ;; We might want to build some more threads first.
5692       (when (and gnus-fetch-old-headers
5693                  (eq gnus-headers-retrieved-by 'nov))
5694         (if (eq gnus-fetch-old-headers 'invisible)
5695             (gnus-build-all-threads)
5696           (gnus-build-old-threads)))
5697       ;; Let the Gnus agent mark articles as read.
5698       (when gnus-agent
5699         (gnus-agent-get-undownloaded-list))
5700       ;; Remove list identifiers from subject
5701       (gnus-summary-remove-list-identifiers)
5702       ;; Check whether auto-expire is to be done in this group.
5703       (setq gnus-newsgroup-auto-expire
5704             (and (gnus-group-auto-expirable-p group)
5705                  (not (gnus-group-read-only-p group))))
5706       ;; Set up the article buffer now, if necessary.
5707       (unless (and gnus-single-article-buffer
5708                    (equal gnus-article-buffer "*Article*"))
5709         (gnus-article-setup-buffer))
5710       ;; First and last article in this newsgroup.
5711       (when gnus-newsgroup-headers
5712         (setq gnus-newsgroup-begin
5713               (mail-header-number (car gnus-newsgroup-headers))
5714               gnus-newsgroup-end
5715               (mail-header-number
5716                (gnus-last-element gnus-newsgroup-headers))))
5717       ;; GROUP is successfully selected.
5718       (or gnus-newsgroup-headers t)))))
5719
5720 (defun gnus-compute-unseen-list ()
5721   ;; The `seen' marks are treated specially.
5722   (if (not gnus-newsgroup-seen)
5723       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5724     (setq gnus-newsgroup-unseen
5725           (gnus-inverse-list-range-intersection
5726            gnus-newsgroup-articles gnus-newsgroup-seen))))
5727
5728 (declare-function gnus-get-predicate "gnus-agent" (predicate))
5729
5730 (defun gnus-summary-display-make-predicate (display)
5731   (require 'gnus-agent)
5732   (when (= (length display) 1)
5733     (setq display (car display)))
5734   (unless gnus-summary-display-cache
5735     (dolist (elem (append '((unread . unread)
5736                             (read . read)
5737                             (unseen . unseen))
5738                           gnus-article-mark-lists))
5739       (push (cons (cdr elem)
5740                   (gnus-byte-compile    ;Why bother?
5741                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5742             gnus-summary-display-cache)))
5743   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5744         (gnus-category-predicate-cache gnus-summary-display-cache))
5745     (gnus-get-predicate display)))
5746
5747 ;; Uses the dynamically bound `gnus-number' variable.
5748 (defvar gnus-number)
5749 (defun gnus-article-marked-p (type &optional article)
5750   (let ((article (or article gnus-number)))
5751     (cond
5752      ((eq type 'tick)
5753       (memq article gnus-newsgroup-marked))
5754      ((eq type 'spam)
5755       (memq article gnus-newsgroup-spam-marked))
5756      ((eq type 'unsend)
5757       (memq article gnus-newsgroup-unsendable))
5758      ((eq type 'undownload)
5759       (memq article gnus-newsgroup-undownloaded))
5760      ((eq type 'download)
5761       (memq article gnus-newsgroup-downloadable))
5762      ((eq type 'unread)
5763       (memq article gnus-newsgroup-unreads))
5764      ((eq type 'read)
5765       (memq article gnus-newsgroup-reads))
5766      ((eq type 'dormant)
5767       (memq article gnus-newsgroup-dormant) )
5768      ((eq type 'expire)
5769       (memq article gnus-newsgroup-expirable))
5770      ((eq type 'reply)
5771       (memq article gnus-newsgroup-replied))
5772      ((eq type 'killed)
5773       (memq article gnus-newsgroup-killed))
5774      ((eq type 'bookmark)
5775       (assq article gnus-newsgroup-bookmarks))
5776      ((eq type 'score)
5777       (assq article gnus-newsgroup-scored))
5778      ((eq type 'save)
5779       (memq article gnus-newsgroup-saved))
5780      ((eq type 'cache)
5781       (memq article gnus-newsgroup-cached))
5782      ((eq type 'forward)
5783       (memq article gnus-newsgroup-forwarded))
5784      ((eq type 'seen)
5785       (not (memq article gnus-newsgroup-unseen)))
5786      (t t))))
5787
5788 (defun gnus-articles-to-read (group &optional read-all)
5789   "Find out what articles the user wants to read."
5790   (let* ((only-read-p t)
5791          (articles
5792           (gnus-list-range-difference
5793           ;; Select all articles if `read-all' is non-nil, or if there
5794           ;; are no unread articles.
5795           (if (or read-all
5796                   (and (zerop (length gnus-newsgroup-marked))
5797                        (zerop (length gnus-newsgroup-unreads)))
5798                   ;; Fetch all if the predicate is non-nil.
5799                   gnus-newsgroup-display)
5800               ;; We want to select the headers for all the articles in
5801               ;; the group, so we select either all the active
5802               ;; articles in the group, or (if that's nil), the
5803               ;; articles in the cache.
5804               (or
5805                (if gnus-newsgroup-maximum-articles
5806                    (let ((active (gnus-active group)))
5807                      (gnus-uncompress-range
5808                       (cons (max (car active)
5809                                  (- (cdr active)
5810                                     gnus-newsgroup-maximum-articles
5811                                     -1))
5812                             (cdr active))))
5813                  (gnus-uncompress-range (gnus-active group)))
5814                (gnus-cache-articles-in-group group))
5815             ;; Select only the "normal" subset of articles.
5816             (setq only-read-p nil)
5817             (gnus-sorted-nunion
5818              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5819              gnus-newsgroup-unreads))
5820           (cdr (assq 'unexist (gnus-info-marks (gnus-get-info group))))))
5821          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5822          (scored (length scored-list))
5823          (number (length articles))
5824          (marked (+ (length gnus-newsgroup-marked)
5825                     (length gnus-newsgroup-dormant)))
5826          (select
5827           (cond
5828            ((numberp read-all)
5829             read-all)
5830            ((numberp gnus-newsgroup-display)
5831             gnus-newsgroup-display)
5832            (t
5833             (condition-case ()
5834                 (cond
5835                  ((and (or (<= scored marked) (= scored number))
5836                        (numberp gnus-large-newsgroup)
5837                        (> number gnus-large-newsgroup))
5838                   (let* ((cursor-in-echo-area nil)
5839                          (initial (gnus-parameter-large-newsgroup-initial
5840                                    gnus-newsgroup-name))
5841                          (default (if only-read-p
5842                                       (or initial gnus-large-newsgroup)
5843                                     number))
5844                          (input
5845                           (read-string
5846                            (if only-read-p
5847                                (format
5848                                 "How many articles from %s (available %d, default %d): "
5849                                 (gnus-group-decoded-name
5850                                  (gnus-group-real-name gnus-newsgroup-name))
5851                                 number default)
5852                              (format
5853                               "How many articles from %s (%d default): "
5854                               (gnus-group-decoded-name
5855                                (gnus-group-real-name gnus-newsgroup-name))
5856                               default))
5857                            nil
5858                            nil
5859                            (number-to-string default))))
5860                     (if (string-match "^[ \t]*$" input) number input)))
5861                  ((and (> scored marked) (< scored number)
5862                        (> (- scored number) 20))
5863                   (let ((input
5864                          (read-string
5865                           (format "%s %s (%d scored, %d total): "
5866                                   "How many articles from"
5867                                   (gnus-group-decoded-name
5868                                    (gnus-group-real-name gnus-newsgroup-name))
5869                                   scored number))))
5870                     (if (string-match "^[ \t]*$" input)
5871                         number input)))
5872                  (t number))
5873               (quit
5874                (message "Quit getting the articles to read")
5875                nil))))))
5876     (setq select (if (stringp select) (string-to-number select) select))
5877     (if (or (null select) (zerop select))
5878         select
5879       (if (and (not (zerop scored)) (<= (abs select) scored))
5880           (progn
5881             (setq articles (sort scored-list '<))
5882             (setq number (length articles)))
5883         (setq articles (copy-sequence articles)))
5884
5885       (when (< (abs select) number)
5886         (if (< select 0)
5887             ;; Select the N oldest articles.
5888             (setcdr (nthcdr (1- (abs select)) articles) nil)
5889           ;; Select the N most recent articles.
5890           (setq articles (nthcdr (- number select) articles))))
5891       (setq gnus-newsgroup-unselected
5892             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5893       (when gnus-alter-articles-to-read-function
5894         (setq articles
5895               (sort
5896                (funcall gnus-alter-articles-to-read-function
5897                         gnus-newsgroup-name articles)
5898                '<)))
5899       articles)))
5900
5901 (defun gnus-killed-articles (killed articles)
5902   (let (out)
5903     (while articles
5904       (when (inline (gnus-member-of-range (car articles) killed))
5905         (push (car articles) out))
5906       (setq articles (cdr articles)))
5907     out))
5908
5909 (defun gnus-article-mark-to-type (mark)
5910   "Return the type of MARK."
5911   (or (cadr (assq mark gnus-article-special-mark-lists))
5912       'list))
5913
5914 (defun gnus-article-unpropagatable-p (mark)
5915   "Return whether MARK should be propagated to back end."
5916   (memq mark gnus-article-unpropagated-mark-lists))
5917
5918 (defun gnus-adjust-marked-articles (info)
5919   "Set all article lists and remove all marks that are no longer valid."
5920   (let* ((marked-lists (gnus-info-marks info))
5921          (active (gnus-active (gnus-info-group info)))
5922          (min (car active))
5923          (max (cdr active))
5924          (types gnus-article-mark-lists)
5925          marks var articles article mark mark-type
5926          bgn end)
5927     ;; Hack to avoid adjusting marks for imap.
5928     (when (eq (car (gnus-find-method-for-group (gnus-info-group info)))
5929               'nnimap)
5930       (setq min 1))
5931
5932     (dolist (marks marked-lists)
5933       (setq mark (car marks)
5934             mark-type (gnus-article-mark-to-type mark)
5935             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5936       ;; We set the variable according to the type of the marks list,
5937       ;; and then adjust the marks to a subset of the active articles.
5938       (cond
5939        ;; Adjust "simple" lists - compressed yet unsorted
5940        ((eq mark-type 'list)
5941         ;; Simultaneously uncompress and clip to active range
5942         ;; See gnus-uncompress-range for a description of possible marks
5943         (let (l lh)
5944           (if (not (cadr marks))
5945               (set var nil)
5946             (setq articles (if (numberp (cddr marks))
5947                                (list (cdr marks))
5948                              (cdr marks))
5949                   lh (cons nil nil)
5950                   l lh)
5951
5952             (while (setq article (pop articles))
5953               (cond ((consp article)
5954                      (setq bgn (max (car article) min)
5955                            end (min (cdr article) max))
5956                      (while (<= bgn end)
5957                        (setq l (setcdr l (cons bgn nil))
5958                              bgn (1+ bgn))))
5959                     ((and (<= min article)
5960                           (>= max article))
5961                      (setq l (setcdr l (cons article nil))))))
5962             (set var (cdr lh)))))
5963        ;; Adjust assocs.
5964        ((eq mark-type 'tuple)
5965         (set var (setq articles (cdr marks)))
5966         (when (not (listp (cdr (symbol-value var))))
5967           (set var (list (symbol-value var))))
5968         (when (not (listp (cdr articles)))
5969           (setq articles (list articles)))
5970         (while articles
5971           (when (or (not (consp (setq article (pop articles))))
5972                     (< (car article) min)
5973                     (> (car article) max))
5974             (set var (delq article (symbol-value var))))))
5975        ;; Adjust ranges (sloppily).
5976        ((eq mark-type 'range)
5977         (cond
5978          ((eq mark 'seen)
5979           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5980           ;; It should be (seen (NUM1 . NUM2)).
5981           (when (numberp (cddr marks))
5982             (setcdr marks (list (cdr marks))))
5983           (setq articles (cdr marks))
5984           (while (and articles
5985                       (or (and (consp (car articles))
5986                                (> min (cdar articles)))
5987                           (and (numberp (car articles))
5988                                (> min (car articles)))))
5989             (pop articles))
5990           (set var articles))
5991          ((eq mark 'unexist)
5992           (set var (cdr marks)))))))))
5993
5994 (defun gnus-update-missing-marks (missing)
5995   "Go through the list of MISSING articles and remove them from the mark lists."
5996   (when missing
5997     (let (var m)
5998       ;; Go through all types.
5999       (dolist (elem gnus-article-mark-lists)
6000         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
6001           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
6002           (when (symbol-value var)
6003             ;; This list has articles.  So we delete all missing
6004             ;; articles from it.
6005             (setq m missing)
6006             (while m
6007               (set var (delq (pop m) (symbol-value var))))))))))
6008
6009 (defun gnus-update-marks ()
6010   "Enter the various lists of marked articles into the newsgroup info list."
6011   (let ((types gnus-article-mark-lists)
6012         (info (gnus-get-info gnus-newsgroup-name))
6013         type list newmarked symbol delta-marks)
6014     (when info
6015       ;; Add all marks lists to the list of marks lists.
6016       (while (setq type (pop types))
6017         (setq list (symbol-value
6018                     (setq symbol
6019                           (intern (format "gnus-newsgroup-%s" (car type))))))
6020
6021         (when list
6022           ;; Get rid of the entries of the articles that have the
6023           ;; default score.
6024           (when (and (eq (cdr type) 'score)
6025                      gnus-save-score
6026                      list)
6027             (let* ((arts list)
6028                    (prev (cons nil list))
6029                    (all prev))
6030               (while arts
6031                 (if (or (not (consp (car arts)))
6032                         (= (cdar arts) gnus-summary-default-score))
6033                     (setcdr prev (cdr arts))
6034                   (setq prev arts))
6035                 (setq arts (cdr arts)))
6036               (setq list (cdr all)))))
6037
6038         (when (eq (cdr type) 'seen)
6039           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
6040
6041         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
6042           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
6043
6044         (when (and (gnus-check-backend-function
6045                     'request-set-mark gnus-newsgroup-name)
6046                    (not (gnus-article-unpropagatable-p (cdr type))))
6047           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
6048                  ;; Don't do anything about marks for articles we
6049                  ;; didn't actually get any headers for.
6050                  (del
6051                   (gnus-list-range-intersection
6052                    gnus-newsgroup-articles
6053                    (gnus-remove-from-range (gnus-copy-sequence old) list)))
6054                  (add
6055                   (gnus-list-range-intersection
6056                    gnus-newsgroup-articles
6057                    (gnus-remove-from-range
6058                     (gnus-copy-sequence list) old))))
6059             (when add
6060               (push (list add 'add (list (cdr type))) delta-marks))
6061             (when del
6062               ;; Don't delete marks from outside the active range.
6063               ;; This shouldn't happen, but is a sanity check.
6064               (setq del (gnus-sorted-range-intersection
6065                          (gnus-active gnus-newsgroup-name) del))
6066               (push (list del 'del (list (cdr type))) delta-marks))))
6067
6068         (when list
6069           (push (cons (cdr type) list) newmarked)))
6070
6071       (when delta-marks
6072         (unless (gnus-check-group gnus-newsgroup-name)
6073           (error "Can't open server for %s" gnus-newsgroup-name))
6074         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
6075
6076       ;; Enter these new marks into the info of the group.
6077       (if (nthcdr 3 info)
6078           (setcar (nthcdr 3 info) newmarked)
6079         ;; Add the marks lists to the end of the info.
6080         (when newmarked
6081           (setcdr (nthcdr 2 info) (list newmarked))))
6082
6083       ;; Cut off the end of the info if there's nothing else there.
6084       (let ((i 5))
6085         (while (and (> i 2)
6086                     (not (nth i info)))
6087           (when (nthcdr (decf i) info)
6088             (setcdr (nthcdr i info) nil)))))))
6089
6090 (defun gnus-set-mode-line (where)
6091   "Set the mode line of the article or summary buffers.
6092 If WHERE is `summary', the summary mode line format will be used."
6093   ;; Is this mode line one we keep updated?
6094   (when (and (memq where gnus-updated-mode-lines)
6095              (symbol-value
6096               (intern (format "gnus-%s-mode-line-format-spec" where))))
6097     (let (mode-string)
6098       ;; We evaluate this in the summary buffer since these
6099       ;; variables are buffer-local to that buffer.
6100       (with-current-buffer gnus-summary-buffer
6101         ;; We bind all these variables that are used in the `eval' form
6102         ;; below.
6103         (let* ((mformat (symbol-value
6104                          (intern
6105                           (format "gnus-%s-mode-line-format-spec" where))))
6106                (gnus-tmp-group-name (gnus-mode-string-quote
6107                                      (gnus-group-decoded-name
6108                                       gnus-newsgroup-name)))
6109                (gnus-tmp-article-number (or gnus-current-article 0))
6110                (gnus-tmp-unread gnus-newsgroup-unreads)
6111                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
6112                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
6113                (gnus-tmp-unread-and-unselected
6114                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
6115                             (zerop gnus-tmp-unselected))
6116                        "")
6117                       ((zerop gnus-tmp-unselected)
6118                        (format "{%d more}" gnus-tmp-unread-and-unticked))
6119                       (t (format "{%d(+%d) more}"
6120                                  gnus-tmp-unread-and-unticked
6121                                  gnus-tmp-unselected))))
6122                (gnus-tmp-subject
6123                 (if (and gnus-current-headers
6124                          (vectorp gnus-current-headers))
6125                     (gnus-mode-string-quote
6126                      (mail-header-subject gnus-current-headers))
6127                   ""))
6128                bufname-length max-len
6129                gnus-tmp-header) ;; passed as argument to any user-format-funcs
6130           (setq mode-string (eval mformat))
6131           (setq bufname-length (if (string-match "%b" mode-string)
6132                                    (- (length
6133                                        (buffer-name
6134                                         (if (eq where 'summary)
6135                                             nil
6136                                           (get-buffer gnus-article-buffer))))
6137                                       2)
6138                                  0))
6139           (setq max-len (max 4 (if gnus-mode-non-string-length
6140                                    (- (window-width)
6141                                       gnus-mode-non-string-length
6142                                       bufname-length)
6143                                  (length mode-string))))
6144           ;; We might have to chop a bit of the string off...
6145           (when (> (length mode-string) max-len)
6146             (setq mode-string
6147                   (concat (truncate-string-to-width mode-string (- max-len 3))
6148                           "...")))))
6149       ;; Update the mode line.
6150       (setq mode-line-buffer-identification
6151             (gnus-mode-line-buffer-identification (list mode-string)))
6152       (set-buffer-modified-p t))))
6153
6154 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
6155   "Go through the HEADERS list and add all Xrefs to a hash table.
6156 The resulting hash table is returned, or nil if no Xrefs were found."
6157   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
6158          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
6159          (xref-hashtb (gnus-make-hashtable))
6160          start group entry number xrefs header)
6161     (while headers
6162       (setq header (pop headers))
6163       (when (and (setq xrefs (mail-header-xref header))
6164                  (not (memq (setq number (mail-header-number header))
6165                             unreads)))
6166         (setq start 0)
6167         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6168           (setq start (match-end 0))
6169           (setq group (if prefix
6170                           (concat prefix (substring xrefs (match-beginning 1)
6171                                                     (match-end 1)))
6172                         (substring xrefs (match-beginning 1) (match-end 1))))
6173           (setq number
6174                 (string-to-number (substring xrefs (match-beginning 2)
6175                                           (match-end 2))))
6176           (if (setq entry (gnus-gethash group xref-hashtb))
6177               (setcdr entry (cons number (cdr entry)))
6178             (gnus-sethash group (cons number nil) xref-hashtb)))))
6179     (and start xref-hashtb)))
6180
6181 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6182   "Look through all the headers and mark the Xrefs as read."
6183   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6184         name info xref-hashtb idlist method nth4)
6185     (with-current-buffer gnus-group-buffer
6186       (when (setq xref-hashtb
6187                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6188         (mapatoms
6189          (lambda (group)
6190            (unless (string= from-newsgroup (setq name (symbol-name group)))
6191              (setq idlist (symbol-value group))
6192              ;; Dead groups are not updated.
6193              (and (prog1
6194                       (setq info (gnus-get-info name))
6195                     (when (stringp (setq nth4 (gnus-info-method info)))
6196                       (setq nth4 (gnus-server-to-method nth4))))
6197                   ;; Only do the xrefs if the group has the same
6198                   ;; select method as the group we have just read.
6199                   (or (gnus-methods-equal-p
6200                        nth4 (gnus-find-method-for-group from-newsgroup))
6201                       virtual
6202                       (equal nth4 (setq method (gnus-find-method-for-group
6203                                                 from-newsgroup)))
6204                       (and (equal (car nth4) (car method))
6205                            (equal (nth 1 nth4) (nth 1 method))))
6206                   gnus-use-cross-reference
6207                   (or (not (eq gnus-use-cross-reference t))
6208                       virtual
6209                       ;; Only do cross-references on subscribed
6210                       ;; groups, if that is what is wanted.
6211                       (<= (gnus-info-level info) gnus-level-subscribed))
6212                   (gnus-group-make-articles-read name idlist))))
6213          xref-hashtb)))))
6214
6215 (defun gnus-compute-read-articles (group articles)
6216   (let* ((entry (gnus-group-entry group))
6217          (info (nth 2 entry))
6218          (active (gnus-active group))
6219          ninfo)
6220     (when entry
6221       ;; First peel off all invalid article numbers.
6222       (when active
6223         (let ((ids articles)
6224               id first)
6225           (while (setq id (pop ids))
6226             (when (and first (> id (cdr active)))
6227               ;; We'll end up in this situation in one particular
6228               ;; obscure situation.  If you re-scan a group and get
6229               ;; a new article that is cross-posted to a different
6230               ;; group that has not been re-scanned, you might get
6231               ;; crossposted article that has a higher number than
6232               ;; Gnus believes possible.  So we re-activate this
6233               ;; group as well.  This might mean doing the
6234               ;; crossposting thingy will *increase* the number
6235               ;; of articles in some groups.  Tsk, tsk.
6236               (setq active (or (gnus-activate-group group) active)))
6237             (when (or (> id (cdr active))
6238                       (< id (car active)))
6239               (setq articles (delq id articles))))))
6240       ;; If the read list is nil, we init it.
6241       (if (and active
6242                (null (gnus-info-read info))
6243                (> (car active) 1))
6244           (setq ninfo (cons 1 (1- (car active))))
6245         (setq ninfo (gnus-info-read info)))
6246       ;; Then we add the read articles to the range.
6247       (gnus-add-to-range
6248        ninfo (setq articles (sort articles '<))))))
6249
6250 (defun gnus-group-make-articles-read (group articles)
6251   "Update the info of GROUP to say that ARTICLES are read."
6252   (let* ((num 0)
6253          (entry (gnus-group-entry group))
6254          (info (nth 2 entry))
6255          (active (gnus-active group))
6256          (set-marks
6257           (gnus-method-option-p
6258            (gnus-find-method-for-group group)
6259            'server-marks))
6260          range)
6261     (if (not entry)
6262         ;; Group that Gnus doesn't know exists, but still allow the
6263         ;; backend to set marks.
6264         (when set-marks
6265           (gnus-request-set-mark
6266            group (list (list (gnus-compress-sequence (sort articles #'<))
6267                              'add '(read)))))
6268       ;; Normal, subscribed groups.
6269       (setq range (gnus-compute-read-articles group articles))
6270       (with-current-buffer gnus-group-buffer
6271         (gnus-undo-register
6272           `(progn
6273              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6274              (gnus-info-set-read ',info ',(gnus-info-read info))
6275              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6276              (when ,set-marks
6277                (gnus-request-set-mark
6278                 ,group (list (list ',range 'del '(read)))))
6279              (gnus-group-update-group ,group t))))
6280       ;; Add the read articles to the range.
6281       (gnus-info-set-read info range)
6282       (when set-marks
6283         (gnus-request-set-mark group (list (list range 'add '(read)))))
6284       ;; Then we have to re-compute how many unread
6285       ;; articles there are in this group.
6286       (when active
6287         (cond
6288          ((not range)
6289           (setq num (- (1+ (cdr active)) (car active))))
6290          ((not (listp (cdr range)))
6291           (setq num (- (cdr active) (- (1+ (cdr range))
6292                                        (car range)))))
6293          (t
6294           (while range
6295             (if (numberp (car range))
6296                 (setq num (1+ num))
6297               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6298             (setq range (cdr range)))
6299           (setq num (- (cdr active) num))))
6300         ;; Update the number of unread articles.
6301         (setcar entry num)
6302         ;; Update the group buffer.
6303         (unless (gnus-ephemeral-group-p group)
6304           (gnus-group-update-group group t))))))
6305
6306 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6307   (let ((cur nntp-server-buffer)
6308         (dependencies
6309          (or dependencies
6310              (with-current-buffer gnus-summary-buffer
6311                gnus-newsgroup-dependencies)))
6312         headers id end ref number
6313         (mail-parse-charset gnus-newsgroup-charset)
6314         (mail-parse-ignored-charsets
6315          (save-current-buffer (condition-case nil
6316                                   (set-buffer gnus-summary-buffer)
6317                                 (error))
6318                               gnus-newsgroup-ignored-charsets)))
6319     (with-current-buffer nntp-server-buffer
6320       ;; Translate all TAB characters into SPACE characters.
6321       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6322       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6323       (ietf-drums-unfold-fws)
6324       (gnus-run-hooks 'gnus-parse-headers-hook)
6325       (let ((case-fold-search t)
6326             in-reply-to header p lines chars)
6327         (goto-char (point-min))
6328         ;; Search to the beginning of the next header.  Error messages
6329         ;; do not begin with 2 or 3.
6330         (while (re-search-forward "^[23][0-9]+ " nil t)
6331           (setq id nil
6332                 ref nil)
6333           ;; This implementation of this function, with nine
6334           ;; search-forwards instead of the one re-search-forward and
6335           ;; a case (which basically was the old function) is actually
6336           ;; about twice as fast, even though it looks messier.  You
6337           ;; can't have everything, I guess.  Speed and elegance
6338           ;; doesn't always go hand in hand.
6339           (setq
6340            header
6341            (vector
6342             ;; Number.
6343             (prog1
6344                 (setq number (read cur))
6345               (end-of-line)
6346               (setq p (point))
6347               (narrow-to-region (point)
6348                                 (or (and (search-forward "\n.\n" nil t)
6349                                          (- (point) 2))
6350                                     (point))))
6351             ;; Subject.
6352             (progn
6353               (goto-char p)
6354               (if (search-forward "\nsubject:" nil t)
6355                   (funcall gnus-decode-encoded-word-function
6356                            (nnheader-header-value))
6357                 "(none)"))
6358             ;; From.
6359             (progn
6360               (goto-char p)
6361               (if (search-forward "\nfrom:" nil t)
6362                   (funcall gnus-decode-encoded-address-function
6363                            (nnheader-header-value))
6364                 "(nobody)"))
6365             ;; Date.
6366             (progn
6367               (goto-char p)
6368               (if (search-forward "\ndate:" nil t)
6369                   (nnheader-header-value) ""))
6370             ;; Message-ID.
6371             (progn
6372               (goto-char p)
6373               (setq id (if (re-search-forward
6374                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6375                            ;; We do it this way to make sure the Message-ID
6376                            ;; is (somewhat) syntactically valid.
6377                            (buffer-substring (match-beginning 1)
6378                                              (match-end 1))
6379                          ;; If there was no message-id, we just fake one
6380                          ;; to make subsequent routines simpler.
6381                          (nnheader-generate-fake-message-id number))))
6382             ;; References.
6383             (progn
6384               (goto-char p)
6385               (if (search-forward "\nreferences:" nil t)
6386                   (progn
6387                     (setq end (point))
6388                     (prog1
6389                         (nnheader-header-value)
6390                       (setq ref
6391                             (buffer-substring
6392                              (progn
6393                                (end-of-line)
6394                                (search-backward ">" end t)
6395                                (1+ (point)))
6396                              (progn
6397                                (search-backward "<" end t)
6398                                (point))))))
6399                 ;; Get the references from the in-reply-to header if there
6400                 ;; were no references and the in-reply-to header looks
6401                 ;; promising.
6402                 (if (and (search-forward "\nin-reply-to:" nil t)
6403                          (setq in-reply-to (nnheader-header-value))
6404                          (string-match "<[^>]+>" in-reply-to))
6405                     (let (ref2)
6406                       (setq ref (substring in-reply-to (match-beginning 0)
6407                                            (match-end 0)))
6408                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6409                         (setq ref2 (substring in-reply-to (match-beginning 0)
6410                                               (match-end 0)))
6411                         (when (> (length ref2) (length ref))
6412                           (setq ref ref2)))
6413                       ref)
6414                   (setq ref nil))))
6415             ;; Chars.
6416             (progn
6417               (goto-char p)
6418               (if (search-forward "\nchars: " nil t)
6419                   (if (numberp (setq chars (ignore-errors (read cur))))
6420                       chars -1)
6421                 -1))
6422             ;; Lines.
6423             (progn
6424               (goto-char p)
6425               (if (search-forward "\nlines: " nil t)
6426                   (if (numberp (setq lines (ignore-errors (read cur))))
6427                       lines -1)
6428                 -1))
6429             ;; Xref.
6430             (progn
6431               (goto-char p)
6432               (and (search-forward "\nxref:" nil t)
6433                    (nnheader-header-value)))
6434             ;; Extra.
6435             (when gnus-extra-headers
6436               (let ((extra gnus-extra-headers)
6437                     out)
6438                 (while extra
6439                   (goto-char p)
6440                   (when (search-forward
6441                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6442                     (push (cons (car extra) (nnheader-header-value))
6443                           out))
6444                   (pop extra))
6445                 out))))
6446           (when (equal id ref)
6447             (setq ref nil))
6448
6449           (when gnus-alter-header-function
6450             (funcall gnus-alter-header-function header)
6451             (setq id (mail-header-id header)
6452                   ref (gnus-parent-id (mail-header-references header))))
6453
6454           (when (setq header
6455                       (gnus-dependencies-add-header
6456                        header dependencies force-new))
6457             (push header headers))
6458           (goto-char (point-max))
6459           (widen))
6460         (nreverse headers)))))
6461
6462 ;; Goes through the xover lines and returns a list of vectors
6463 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6464                                                   force-new dependencies
6465                                                   group also-fetch-heads)
6466   "Parse the news overview data in the server buffer.
6467 Return a list of headers that match SEQUENCE (see
6468 `nntp-retrieve-headers')."
6469   ;; Get the Xref when the users reads the articles since most/some
6470   ;; NNTP servers do not include Xrefs when using XOVER.
6471   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6472   (let ((mail-parse-charset gnus-newsgroup-charset)
6473         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6474         (cur nntp-server-buffer)
6475         (dependencies (or dependencies gnus-newsgroup-dependencies))
6476         (allp (cond
6477                ((eq gnus-read-all-available-headers t)
6478                 t)
6479                ((and (stringp gnus-read-all-available-headers)
6480                      group)
6481                 (string-match gnus-read-all-available-headers group))
6482                (t
6483                 nil)))
6484         number headers header)
6485     (with-current-buffer nntp-server-buffer
6486       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6487       ;; Allow the user to mangle the headers before parsing them.
6488       (gnus-run-hooks 'gnus-parse-headers-hook)
6489       (goto-char (point-min))
6490       (gnus-parse-without-error
6491         (while (and (or sequence allp)
6492                     (not (eobp)))
6493           (setq number (read cur))
6494           (when (not allp)
6495             (while (and sequence
6496                         (< (car sequence) number))
6497               (setq sequence (cdr sequence))))
6498           (when (and (or allp
6499                          (and sequence
6500                               (eq number (car sequence))))
6501                      (progn
6502                        (setq sequence (cdr sequence))
6503                        (setq header (inline
6504                                       (gnus-nov-parse-line
6505                                        number dependencies force-new)))))
6506             (push header headers))
6507           (forward-line 1)))
6508       ;; A common bug in inn is that if you have posted an article and
6509       ;; then retrieves the active file, it will answer correctly --
6510       ;; the new article is included.  However, a NOV entry for the
6511       ;; article may not have been generated yet, so this may fail.
6512       ;; We work around this problem by retrieving the last few
6513       ;; headers using HEAD.
6514       (if (or (not also-fetch-heads)
6515               (not sequence))
6516           ;; We (probably) got all the headers.
6517           (nreverse headers)
6518         (let ((gnus-nov-is-evil t))
6519           (nconc
6520            (nreverse headers)
6521            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6522              (gnus-get-newsgroup-headers))))))))
6523
6524 (defun gnus-article-get-xrefs ()
6525   "Fill in the Xref value in `gnus-current-headers', if necessary.
6526 This is meant to be called in `gnus-article-internal-prepare-hook'."
6527   (let ((headers (with-current-buffer gnus-summary-buffer
6528                    gnus-current-headers)))
6529     (or (not gnus-use-cross-reference)
6530         (not headers)
6531         (and (mail-header-xref headers)
6532              (not (string= (mail-header-xref headers) "")))
6533         (let ((case-fold-search t)
6534               xref)
6535           (save-restriction
6536             (nnheader-narrow-to-headers)
6537             (goto-char (point-min))
6538             (when (or (and (not (eobp))
6539                            (eq (downcase (char-after)) ?x)
6540                            (looking-at "Xref:"))
6541                       (search-forward "\nXref:" nil t))
6542               (goto-char (1+ (match-end 0)))
6543               (setq xref (buffer-substring (point) (point-at-eol)))
6544               (mail-header-set-xref headers xref)))))))
6545
6546 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6547   "Find article ID and insert the summary line for that article.
6548 OLD-HEADER can either be a header or a line number to insert
6549 the subject line on.
6550 If USE-OLD-HEADER is non-nil, then OLD-HEADER should be a header,
6551 and OLD-HEADER will be used when the summary line is inserted,
6552 too, instead of trying to fetch new headers."
6553   (let* ((line (and (numberp old-header) old-header))
6554          (old-header (and (vectorp old-header) old-header))
6555          (header (cond ((and old-header use-old-header)
6556                         old-header)
6557                        ((and (numberp id)
6558                              (gnus-number-to-header id))
6559                         (gnus-number-to-header id))
6560                        (t
6561                         (gnus-read-header id))))
6562          (number (and (numberp id) id))
6563          d)
6564     (when header
6565       ;; Rebuild the thread that this article is part of and go to the
6566       ;; article we have fetched.
6567       (when (and (not gnus-show-threads)
6568                  old-header)
6569         (when (and number
6570                    (setq d (gnus-data-find (mail-header-number old-header))))
6571           (goto-char (gnus-data-pos d))
6572           (gnus-data-remove
6573            number
6574            (- (point-at-bol)
6575               (prog1
6576                   (1+ (point-at-eol))
6577                 (gnus-delete-line))))))
6578       ;; Remove list identifiers from subject.
6579       (let ((gnus-newsgroup-headers (list header)))
6580         (gnus-summary-remove-list-identifiers))
6581       (when old-header
6582         (mail-header-set-number header (mail-header-number old-header)))
6583       (setq gnus-newsgroup-sparse
6584             (delq (setq number (mail-header-number header))
6585                   gnus-newsgroup-sparse))
6586       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6587       (push number gnus-newsgroup-limit)
6588       (gnus-rebuild-thread (mail-header-id header) line)
6589       (gnus-summary-goto-subject number nil t))
6590     (when (and (numberp number)
6591                (> number 0))
6592       ;; We have to update the boundaries even if we can't fetch the
6593       ;; article if ID is a number -- so that the next `P' or `N'
6594       ;; command will fetch the previous (or next) article even
6595       ;; if the one we tried to fetch this time has been canceled.
6596       (unless (and gnus-newsgroup-end (< number gnus-newsgroup-end))
6597         (setq gnus-newsgroup-end number))
6598       (unless (and gnus-newsgroup-begin (> number gnus-newsgroup-begin))
6599         (setq gnus-newsgroup-begin number))
6600       (setq gnus-newsgroup-unselected
6601             (delq number gnus-newsgroup-unselected)))
6602     ;; Report back a success?
6603     (and header (mail-header-number header))))
6604
6605 ;;; Process/prefix in the summary buffer
6606
6607 (defun gnus-summary-work-articles (n)
6608   "Return a list of articles to be worked upon.
6609 The prefix argument, the list of process marked articles, and the
6610 current article will be taken into consideration."
6611   (with-current-buffer gnus-summary-buffer
6612     (cond
6613      (n
6614       ;; A numerical prefix has been given.
6615       (setq n (prefix-numeric-value n))
6616       (let ((backward (< n 0))
6617             (n (abs (prefix-numeric-value n)))
6618             articles article)
6619         (save-excursion
6620           (while
6621               (and (> n 0)
6622                    (push (setq article (gnus-summary-article-number))
6623                          articles)
6624                    (if backward
6625                        (gnus-summary-find-prev nil article)
6626                      (gnus-summary-find-next nil article)))
6627             (decf n)))
6628         (nreverse articles)))
6629      ((and (gnus-region-active-p) (mark))
6630       (message "region active")
6631       ;; Work on the region between point and mark.
6632       (let ((max (max (point) (mark)))
6633             articles article)
6634         (save-excursion
6635           (goto-char (min (point) (mark)))
6636           (while
6637               (and
6638                (push (setq article (gnus-summary-article-number)) articles)
6639                (gnus-summary-find-next nil article)
6640                (< (point) max)))
6641           (nreverse articles))))
6642      (gnus-newsgroup-processable
6643       ;; There are process-marked articles present.
6644       ;; Save current state.
6645       (gnus-summary-save-process-mark)
6646       ;; Return the list.
6647       (reverse gnus-newsgroup-processable))
6648      (t
6649       ;; Just return the current article.
6650       (list (gnus-summary-article-number))))))
6651
6652 (defmacro gnus-summary-iterate (arg &rest forms)
6653   "Iterate over the process/prefixed articles and do FORMS.
6654 ARG is the interactive prefix given to the command.  FORMS will be
6655 executed with point over the summary line of the articles."
6656   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6657     `(let ((,articles (gnus-summary-work-articles ,arg)))
6658        (while ,articles
6659          (gnus-summary-goto-subject (car ,articles))
6660          ,@forms
6661          (pop ,articles)))))
6662
6663 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6664 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6665
6666 (defun gnus-summary-save-process-mark ()
6667   "Push the current set of process marked articles on the stack."
6668   (interactive)
6669   (push (copy-sequence gnus-newsgroup-processable)
6670         gnus-newsgroup-process-stack))
6671
6672 (defun gnus-summary-kill-process-mark ()
6673   "Push the current set of process marked articles on the stack and unmark."
6674   (interactive)
6675   (gnus-summary-save-process-mark)
6676   (gnus-summary-unmark-all-processable))
6677
6678 (defun gnus-summary-yank-process-mark ()
6679   "Pop the last process mark state off the stack and restore it."
6680   (interactive)
6681   (unless gnus-newsgroup-process-stack
6682     (error "Empty mark stack"))
6683   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6684
6685 (defun gnus-summary-process-mark-set (set)
6686   "Make SET into the current process marked articles."
6687   (gnus-summary-unmark-all-processable)
6688   (mapc 'gnus-summary-set-process-mark set))
6689
6690 ;;; Searching and stuff
6691
6692 (defun gnus-summary-search-group (&optional backward use-level)
6693   "Search for next unread newsgroup.
6694 If optional argument BACKWARD is non-nil, search backward instead."
6695   (with-current-buffer gnus-group-buffer
6696     (when (gnus-group-search-forward
6697            backward nil (if use-level (gnus-group-group-level) nil))
6698       (gnus-group-group-name))))
6699
6700 (defun gnus-summary-best-group (&optional exclude-group)
6701   "Find the name of the best unread group.
6702 If EXCLUDE-GROUP, do not go to this group."
6703   (with-current-buffer gnus-group-buffer
6704     (save-excursion
6705       (gnus-group-best-unread-group exclude-group))))
6706
6707 (defun gnus-summary-find-next (&optional unread article backward)
6708   (if backward
6709       (gnus-summary-find-prev unread article)
6710     (let* ((dummy (gnus-summary-article-intangible-p))
6711            (article (or article (gnus-summary-article-number)))
6712            (data (gnus-data-find-list article))
6713            result)
6714       (when (and (not dummy)
6715                  (or (not gnus-summary-check-current)
6716                      (not unread)
6717                      (not (gnus-data-unread-p (car data)))))
6718         (setq data (cdr data)))
6719       (when (setq result
6720                   (if unread
6721                       (progn
6722                         (while data
6723                           (unless (memq (gnus-data-number (car data))
6724                                         (cond
6725                                          ((eq gnus-auto-goto-ignores
6726                                               'always-undownloaded)
6727                                           gnus-newsgroup-undownloaded)
6728                                          (gnus-plugged
6729                                           nil)
6730                                          ((eq gnus-auto-goto-ignores
6731                                               'unfetched)
6732                                           gnus-newsgroup-unfetched)
6733                                          ((eq gnus-auto-goto-ignores
6734                                               'undownloaded)
6735                                           gnus-newsgroup-undownloaded)))
6736                             (when (gnus-data-unread-p (car data))
6737                               (setq result (car data)
6738                                     data nil)))
6739                           (setq data (cdr data)))
6740                         result)
6741                     (car data)))
6742         (goto-char (gnus-data-pos result))
6743         (gnus-data-number result)))))
6744
6745 (defun gnus-summary-find-prev (&optional unread article)
6746   (let* ((eobp (eobp))
6747          (article (or article (gnus-summary-article-number)))
6748          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6749          result)
6750     (when (and (not eobp)
6751                (or (not gnus-summary-check-current)
6752                    (not unread)
6753                    (not (gnus-data-unread-p (car data)))))
6754       (setq data (cdr data)))
6755     (when (setq result
6756                 (if unread
6757                     (progn
6758                       (while data
6759                         (unless (memq (gnus-data-number (car data))
6760                                       (cond
6761                                        ((eq gnus-auto-goto-ignores
6762                                             'always-undownloaded)
6763                                         gnus-newsgroup-undownloaded)
6764                                        (gnus-plugged
6765                                         nil)
6766                                        ((eq gnus-auto-goto-ignores
6767                                             'unfetched)
6768                                         gnus-newsgroup-unfetched)
6769                                        ((eq gnus-auto-goto-ignores
6770                                             'undownloaded)
6771                                         gnus-newsgroup-undownloaded)))
6772                           (when (gnus-data-unread-p (car data))
6773                             (setq result (car data)
6774                                   data nil)))
6775                         (setq data (cdr data)))
6776                       result)
6777                   (car data)))
6778       (goto-char (gnus-data-pos result))
6779       (gnus-data-number result))))
6780
6781 (defun gnus-summary-find-subject (subject &optional unread backward article)
6782   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6783          (article (or article (gnus-summary-article-number)))
6784          (articles (gnus-data-list backward))
6785          (arts (gnus-data-find-list article articles))
6786          result)
6787     (when (or (not gnus-summary-check-current)
6788               (not unread)
6789               (not (gnus-data-unread-p (car arts))))
6790       (setq arts (cdr arts)))
6791     (while arts
6792       (and (or (not unread)
6793                (gnus-data-unread-p (car arts)))
6794            (vectorp (gnus-data-header (car arts)))
6795            (gnus-subject-equal
6796             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6797            (setq result (car arts)
6798                  arts nil))
6799       (setq arts (cdr arts)))
6800     (and result
6801          (goto-char (gnus-data-pos result))
6802          (gnus-data-number result))))
6803
6804 (defun gnus-summary-search-forward (&optional unread subject backward)
6805   "Search forward for an article.
6806 If UNREAD, look for unread articles.  If SUBJECT, look for
6807 articles with that subject.  If BACKWARD, search backward instead."
6808   (cond (subject (gnus-summary-find-subject subject unread backward))
6809         (backward (gnus-summary-find-prev unread))
6810         (t (gnus-summary-find-next unread))))
6811
6812 (defun gnus-recenter (&optional n)
6813   "Center point in window and redisplay frame.
6814 Also do horizontal recentering."
6815   (interactive "P")
6816   (when (and gnus-auto-center-summary
6817              (not (eq gnus-auto-center-summary 'vertical)))
6818     (gnus-horizontal-recenter))
6819   (if (fboundp 'recenter-top-bottom)
6820       (recenter-top-bottom n)
6821     (recenter n)))
6822
6823 (put 'gnus-recenter 'isearch-scroll t)
6824
6825 (defun gnus-forward-line-ignore-invisible (n)
6826   "Move N lines forward (backward if N is negative).
6827 Like forward-line, but skip over (and don't count) invisible lines."
6828   (let (done)
6829     (while (and (> n 0) (not done))
6830       ;; If the following character is currently invisible,
6831       ;; skip all characters with that same `invisible' property value.
6832       (while (gnus-invisible-p (point))
6833         (goto-char (gnus-next-char-property-change (point))))
6834       (forward-line 1)
6835       (if (eobp)
6836           (setq done t)
6837         (setq n (1- n))))
6838     (while (and (< n 0) (not done))
6839       (forward-line -1)
6840       (if (bobp) (setq done t)
6841         (setq n (1+ n))
6842         (while (and (not (bobp)) (gnus-invisible-p (1- (point))))
6843           (goto-char (gnus-previous-char-property-change (point))))))))
6844
6845 (defun gnus-summary-recenter ()
6846   "Center point in the summary window.
6847 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6848 displayed, no centering will be performed."
6849   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6850   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6851   (interactive)
6852   ;; The user has to want it.
6853   (when gnus-auto-center-summary
6854     (let* ((top (cond ((< (window-height) 4) 0)
6855                       ((< (window-height) 7) 1)
6856                       (t (if (numberp gnus-auto-center-summary)
6857                              gnus-auto-center-summary
6858                            (/ (1- (window-height)) 2)))))
6859            (height (1- (window-height)))
6860            (bottom (save-excursion
6861                      (goto-char (point-max))
6862                      (gnus-forward-line-ignore-invisible (- height))
6863                      (point)))
6864            (window (get-buffer-window (current-buffer))))
6865       (when (get-buffer-window gnus-article-buffer)
6866         ;; Only do recentering when the article buffer is displayed,
6867         ;; Set the window start to either `bottom', which is the biggest
6868         ;; possible valid number, or the second line from the top,
6869         ;; whichever is the least.
6870         (let ((top-pos (save-excursion
6871                          (gnus-forward-line-ignore-invisible (- top))
6872                          (point))))
6873           (if (> bottom top-pos)
6874               ;; Keep the second line from the top visible
6875               (set-window-start window top-pos)
6876             ;; Try to keep the bottom line visible; if it's partially
6877             ;; obscured, either scroll one more line to make it fully
6878             ;; visible, or revert to using TOP-POS.
6879             (save-excursion
6880               (goto-char (point-max))
6881               (gnus-forward-line-ignore-invisible -1)
6882               (let ((last-line-start (point)))
6883                 (goto-char bottom)
6884                 (set-window-start window (point) t)
6885                 (when (not (pos-visible-in-window-p last-line-start window))
6886                   (gnus-forward-line-ignore-invisible 1)
6887                   (set-window-start window (min (point) top-pos) t)))))))
6888       ;; Do horizontal recentering while we're at it.
6889       (when (and (get-buffer-window (current-buffer) t)
6890                  (not (eq gnus-auto-center-summary 'vertical)))
6891         (let ((selected (selected-window)))
6892           (select-window (get-buffer-window (current-buffer) t))
6893           (gnus-summary-position-point)
6894           (gnus-horizontal-recenter)
6895           (select-window selected))))))
6896
6897 (defun gnus-summary-jump-to-group (newsgroup)
6898   "Move point to NEWSGROUP in group mode buffer."
6899   ;; Keep update point of group mode buffer if visible.
6900   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6901       (save-window-excursion
6902         ;; Take care of tree window mode.
6903         (when (get-buffer-window gnus-group-buffer)
6904           (pop-to-buffer gnus-group-buffer))
6905         (gnus-group-jump-to-group newsgroup))
6906     (save-excursion
6907       ;; Take care of tree window mode.
6908       (if (get-buffer-window gnus-group-buffer 0)
6909           (pop-to-buffer gnus-group-buffer)
6910         (set-buffer gnus-group-buffer))
6911       (gnus-group-jump-to-group newsgroup))))
6912
6913 ;; This function returns a list of article numbers based on the
6914 ;; difference between the ranges of read articles in this group and
6915 ;; the range of active articles.
6916 (defun gnus-list-of-unread-articles (group)
6917   (let* ((read (gnus-info-read (gnus-get-info group)))
6918          (active (or (gnus-active group) (gnus-activate-group group)))
6919          (last (or (cdr active)
6920                    (error "Group %s couldn't be activated " group)))
6921          (bottom (if gnus-newsgroup-maximum-articles
6922                      (max (car active)
6923                           (- last gnus-newsgroup-maximum-articles -1))
6924                    (car active)))
6925          first nlast unread)
6926     ;; If none are read, then all are unread.
6927     (if (not read)
6928         (setq first bottom)
6929       ;; If the range of read articles is a single range, then the
6930       ;; first unread article is the article after the last read
6931       ;; article.  Sounds logical, doesn't it?
6932       (if (and (not (listp (cdr read)))
6933                (or (< (car read) bottom)
6934                    (progn (setq read (list read))
6935                           nil)))
6936           (setq first (max bottom (1+ (cdr read))))
6937         ;; `read' is a list of ranges.
6938         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6939                                   (caar read)))
6940                   1)
6941           (setq first bottom))
6942         (while read
6943           (when first
6944             (while (< first nlast)
6945               (setq unread (cons first unread)
6946                     first (1+ first))))
6947           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6948           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6949           (setq read (cdr read)))))
6950     ;; And add the last unread articles.
6951     (while (<= first last)
6952       (setq unread (cons first unread)
6953             first (1+ first)))
6954     ;; Return the list of unread articles.
6955     (delq 0 (nreverse unread))))
6956
6957 (defun gnus-list-of-read-articles (group)
6958   "Return a list of unread, unticked and non-dormant articles."
6959   (let* ((info (gnus-get-info group))
6960          (marked (gnus-info-marks info))
6961          (active (gnus-active group)))
6962     (and info active
6963          (gnus-list-range-difference
6964           (gnus-list-range-difference
6965            (gnus-sorted-complement
6966             (gnus-uncompress-range
6967              (if gnus-newsgroup-maximum-articles
6968                  (cons (max (car active)
6969                             (- (cdr active)
6970                                gnus-newsgroup-maximum-articles
6971                                -1))
6972                        (cdr active))
6973                active))
6974             (gnus-list-of-unread-articles group))
6975            (cdr (assq 'dormant marked)))
6976           (cdr (assq 'tick marked))))))
6977
6978 ;; This function returns a sequence of article numbers based on the
6979 ;; difference between the ranges of read articles in this group and
6980 ;; the range of active articles.
6981 (defun gnus-sequence-of-unread-articles (group)
6982   (let* ((read (gnus-info-read (gnus-get-info group)))
6983          (active (or (gnus-active group) (gnus-activate-group group)))
6984          (last (cdr active))
6985          (bottom (if gnus-newsgroup-maximum-articles
6986                      (max (car active)
6987                           (- last gnus-newsgroup-maximum-articles -1))
6988                    (car active)))
6989          first nlast unread)
6990     ;; If none are read, then all are unread.
6991     (if (not read)
6992         (setq first bottom)
6993       ;; If the range of read articles is a single range, then the
6994       ;; first unread article is the article after the last read
6995       ;; article.  Sounds logical, doesn't it?
6996       (if (and (not (listp (cdr read)))
6997                (or (< (car read) bottom)
6998                    (progn (setq read (list read))
6999                           nil)))
7000           (setq first (max bottom (1+ (cdr read))))
7001         ;; `read' is a list of ranges.
7002         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
7003                                   (caar read)))
7004                   1)
7005           (setq first bottom))
7006         (while read
7007           (when first
7008             (push (cons first nlast) unread))
7009           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
7010           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
7011           (setq read (cdr read)))))
7012     ;; And add the last unread articles.
7013     (cond ((not (and first last))
7014            nil)
7015           ((< first last)
7016            (push (cons first last) unread))
7017           ((= first last)
7018            (push first unread)))
7019     ;; Return the sequence of unread articles.
7020     (delq 0 (nreverse unread))))
7021
7022 ;; Various summary commands
7023
7024 (defun gnus-summary-select-article-buffer ()
7025   "Reconfigure windows to show the article buffer.
7026 If `gnus-widen-article-window' is set, show only the article
7027 buffer."
7028   (interactive)
7029   (if (not (gnus-buffer-live-p gnus-article-buffer))
7030       (error "There is no article buffer for this summary buffer")
7031     (unless (get-buffer-window gnus-article-buffer)
7032       (gnus-summary-show-article))
7033     (gnus-configure-windows
7034      (if gnus-widen-article-window
7035          'only-article
7036        'article)
7037      t)
7038     (select-window (get-buffer-window gnus-article-buffer))))
7039
7040 (defun gnus-summary-universal-argument (arg)
7041   "Perform any operation on all articles that are process/prefixed."
7042   (interactive "P")
7043   (let ((articles (gnus-summary-work-articles arg))
7044         func article)
7045     (if (eq
7046          (setq
7047           func
7048           (key-binding
7049            (read-key-sequence
7050             (substitute-command-keys
7051              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
7052          'undefined)
7053         (gnus-error 1 "Undefined key")
7054       (save-excursion
7055         (while articles
7056           (gnus-summary-goto-subject (setq article (pop articles)))
7057           (let (gnus-newsgroup-processable)
7058             (command-execute func))
7059           (gnus-summary-remove-process-mark article)))))
7060   (gnus-summary-position-point))
7061
7062 (defun gnus-summary-toggle-truncation (&optional arg)
7063   "Toggle truncation of summary lines.
7064 With ARG, turn line truncation on if ARG is positive."
7065   (interactive "P")
7066   (setq truncate-lines
7067         (if (null arg) (not truncate-lines)
7068           (> (prefix-numeric-value arg) 0)))
7069   (redraw-display))
7070
7071 (defun gnus-summary-find-for-reselect ()
7072   "Return the number of an article to stay on across a reselect.
7073 The current article is considered, then following articles, then previous
7074 articles.  An article is sought which is not canceled and isn't a temporary
7075 insertion from another group.  If there's no such then return a dummy 0."
7076   (let (found)
7077     (dolist (rev '(nil t))
7078       (unless found      ; don't demand the reverse list if we don't need it
7079         (let ((data (gnus-data-find-list
7080                      (gnus-summary-article-number) (gnus-data-list rev))))
7081           (while (and data (not found))
7082             (if (and (< 0 (gnus-data-number (car data)))
7083                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
7084                 (setq found (gnus-data-number (car data))))
7085             (setq data (cdr data))))))
7086     (or found 0)))
7087
7088 (defun gnus-summary-reselect-current-group (&optional all rescan)
7089   "Exit and then reselect the current newsgroup.
7090 The prefix argument ALL means to select all articles."
7091   (interactive "P")
7092   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
7093     (error "Ephemeral groups can't be reselected"))
7094   (let ((current-subject (gnus-summary-find-for-reselect))
7095         (group gnus-newsgroup-name))
7096     (setq gnus-newsgroup-begin nil)
7097     (gnus-summary-exit nil 'leave-hidden)
7098     ;; We have to adjust the point of group mode buffer because
7099     ;; point was moved to the next unread newsgroup by exiting.
7100     (gnus-summary-jump-to-group group)
7101     (when rescan
7102       (save-excursion
7103         (gnus-group-get-new-news-this-group 1)))
7104     (gnus-group-read-group all t)
7105     (gnus-summary-goto-subject current-subject nil t)))
7106
7107 (defun gnus-summary-rescan-group (&optional all)
7108   "Exit the newsgroup, ask for new articles, and select the newsgroup."
7109   (interactive "P")
7110   (let ((config gnus-current-window-configuration))
7111     (gnus-summary-reselect-current-group all t)
7112     (gnus-configure-windows config)
7113     (when (eq config 'article)
7114       (gnus-summary-select-article))))
7115
7116 (defun gnus-summary-update-info (&optional non-destructive)
7117   (save-excursion
7118     (let ((group gnus-newsgroup-name))
7119       (when group
7120         (when gnus-newsgroup-kill-headers
7121           (setq gnus-newsgroup-killed
7122                 (gnus-compress-sequence
7123                  (gnus-sorted-union
7124                   (gnus-list-range-intersection
7125                    gnus-newsgroup-unselected gnus-newsgroup-killed)
7126                   gnus-newsgroup-unreads)
7127                  t)))
7128         (unless (listp (cdr gnus-newsgroup-killed))
7129           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
7130         (let ((headers gnus-newsgroup-headers)
7131               (ephemeral-p (gnus-ephemeral-group-p group))
7132               info)
7133           (unless ephemeral-p
7134             (setq info (copy-sequence (gnus-get-info group))
7135                   info (delq (gnus-info-params info) info)))
7136           ;; Set the new ranges of read articles.
7137           (with-current-buffer gnus-group-buffer
7138             (gnus-undo-force-boundary))
7139           (gnus-update-read-articles
7140            group (gnus-sorted-union
7141                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
7142           ;; Set the current article marks.
7143           (let ((gnus-newsgroup-scored
7144                  (if (and (not gnus-save-score)
7145                           (not non-destructive))
7146                      nil
7147                    gnus-newsgroup-scored)))
7148             (save-excursion
7149               (gnus-update-marks)))
7150           ;; Do the cross-ref thing.
7151           (when gnus-use-cross-reference
7152             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
7153           ;; Do not switch windows but change the buffer to work.
7154           (set-buffer gnus-group-buffer)
7155           (unless ephemeral-p
7156             (gnus-group-update-group
7157              group nil
7158              (equal info
7159                     (setq info (copy-sequence (gnus-get-info group))
7160                           info (delq (gnus-info-params info) info))))))))))
7161
7162 (defun gnus-summary-save-newsrc (&optional force)
7163   "Save the current number of read/marked articles in the dribble buffer.
7164 The dribble buffer will then be saved.
7165 If FORCE (the prefix), also save the .newsrc file(s)."
7166   (interactive "P")
7167   (gnus-summary-update-info t)
7168   (if force
7169       (gnus-save-newsrc-file)
7170     (gnus-dribble-save)))
7171
7172 (declare-function gnus-cache-write-active "gnus-cache" (&optional force))
7173
7174 (defun gnus-summary-exit (&optional temporary leave-hidden)
7175   "Exit reading current newsgroup, and then return to group selection mode.
7176 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
7177   (interactive)
7178   (gnus-set-global-variables)
7179   (when (gnus-buffer-live-p gnus-article-buffer)
7180     (with-current-buffer gnus-article-buffer
7181       (mm-destroy-parts gnus-article-mime-handles)
7182       ;; Set it to nil for safety reason.
7183       (setq gnus-article-mime-handle-alist nil)
7184       (setq gnus-article-mime-handles nil)))
7185   (gnus-kill-save-kill-buffer)
7186   (gnus-async-halt-prefetch)
7187   (let* ((group gnus-newsgroup-name)
7188          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
7189          (gnus-group-is-exiting-p t)
7190          (article-buffer gnus-article-buffer)
7191          (original-article-buffer gnus-original-article-buffer)
7192          (mode major-mode)
7193          (group-point nil)
7194          (buf (current-buffer))
7195          ;; `gnus-single-article-buffer' is nil buffer-locally in
7196          ;; ephemeral group of which summary buffer will be killed,
7197          ;; but the global value may be non-nil.
7198          (single-article-buffer gnus-single-article-buffer))
7199     (unless quit-config
7200       ;; Do adaptive scoring, and possibly save score files.
7201       (when gnus-newsgroup-adaptive
7202         (gnus-score-adaptive))
7203       (when gnus-use-scoring
7204         (gnus-score-save)))
7205     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
7206     (when gnus-use-cache
7207       (gnus-cache-possibly-remove-articles)
7208       (gnus-cache-save-buffers))
7209     (gnus-async-prefetch-remove-group group)
7210     (when gnus-suppress-duplicates
7211       (gnus-dup-enter-articles))
7212     (when gnus-use-trees
7213       (gnus-tree-close group))
7214     (when gnus-use-cache
7215       (gnus-cache-write-active))
7216     ;; Remove entries for this group.
7217     (nnmail-purge-split-history (gnus-group-real-name group))
7218     ;; Make all changes in this group permanent.
7219     (unless quit-config
7220       (gnus-run-hooks 'gnus-exit-group-hook)
7221       (gnus-summary-update-info))
7222     (gnus-close-group group)
7223     ;; Make sure where we were, and go to next newsgroup.
7224     (when (buffer-live-p (get-buffer gnus-group-buffer))
7225       (set-buffer gnus-group-buffer))
7226     (unless quit-config
7227       (gnus-group-jump-to-group group))
7228     (gnus-run-hooks 'gnus-summary-exit-hook)
7229     (unless (or quit-config
7230                 (not gnus-summary-next-group-on-exit)
7231                 ;; If this group has disappeared from the summary
7232                 ;; buffer, don't skip forwards.
7233                 (not (string= group (gnus-group-group-name))))
7234       (gnus-group-next-unread-group 1))
7235     (setq group-point (point))
7236     (if temporary
7237         nil                             ;Nothing to do.
7238       (set-buffer buf)
7239       (if (not gnus-kill-summary-on-exit)
7240           (progn
7241             (gnus-deaden-summary)
7242             (setq mode nil))
7243         (when (get-buffer gnus-article-buffer)
7244           (bury-buffer gnus-article-buffer))
7245         ;; Return to group mode buffer.
7246         (when (eq mode 'gnus-summary-mode)
7247           (gnus-kill-buffer buf)))
7248
7249       (setq gnus-current-select-method gnus-select-method)
7250       (when (gnus-buffer-live-p gnus-group-buffer)
7251         (set-buffer gnus-group-buffer))
7252       (if quit-config
7253           (gnus-handle-ephemeral-exit quit-config)
7254         (goto-char group-point)
7255         ;; If gnus-group-buffer is already displayed, make sure we also move
7256         ;; the cursor in the window that displays it.
7257         (let ((win (get-buffer-window (current-buffer) 0)))
7258           (if win (set-window-point win (point))))
7259         (unless leave-hidden
7260           (gnus-configure-windows 'group 'force)))
7261
7262       ;; If we have several article buffers, we kill them at exit.
7263       (unless single-article-buffer
7264         (when (gnus-buffer-live-p article-buffer)
7265           (with-current-buffer article-buffer
7266             ;; Don't kill sticky article buffers
7267             (unless (eq major-mode 'gnus-sticky-article-mode)
7268               (gnus-kill-buffer article-buffer)
7269               (setq gnus-article-current nil))))
7270         (gnus-kill-buffer original-article-buffer))
7271
7272       ;; Clear the current group name.
7273       (unless quit-config
7274         (setq gnus-newsgroup-name nil)))))
7275
7276 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7277 (defun gnus-summary-exit-no-update (&optional no-questions)
7278   "Quit reading current newsgroup without updating read article info."
7279   (interactive)
7280   (let* ((group gnus-newsgroup-name)
7281          (gnus-group-is-exiting-p t)
7282          (gnus-group-is-exiting-without-update-p t)
7283          (quit-config (gnus-group-quit-config group)))
7284     (when (or no-questions
7285               gnus-expert-user
7286               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7287       (gnus-async-halt-prefetch)
7288       (run-hooks 'gnus-summary-prepare-exit-hook)
7289       (when (gnus-buffer-live-p gnus-article-buffer)
7290         (with-current-buffer gnus-article-buffer
7291           (gnus-article-stop-animations)
7292           (gnus-stop-downloads)
7293           (mm-destroy-parts gnus-article-mime-handles)
7294           ;; Set it to nil for safety reason.
7295           (setq gnus-article-mime-handle-alist nil)
7296           (setq gnus-article-mime-handles nil)))
7297       ;; If we have several article buffers, we kill them at exit.
7298       (unless gnus-single-article-buffer
7299         (gnus-kill-buffer gnus-article-buffer)
7300         (gnus-kill-buffer gnus-original-article-buffer)
7301         (setq gnus-article-current nil))
7302       ;; Return to the group buffer.
7303       (if (not gnus-kill-summary-on-exit)
7304           (progn
7305             (gnus-deaden-summary)
7306             (gnus-configure-windows 'group 'force))
7307         (gnus-configure-windows 'group 'force)
7308         (gnus-close-group group)
7309         (gnus-kill-buffer gnus-summary-buffer))
7310       (unless gnus-single-article-buffer
7311         (setq gnus-article-current nil))
7312       (when gnus-use-trees
7313         (gnus-tree-close group))
7314       (gnus-async-prefetch-remove-group group)
7315       (when (get-buffer gnus-article-buffer)
7316         (bury-buffer gnus-article-buffer))
7317       ;; Clear the current group name.
7318       (setq gnus-newsgroup-name nil)
7319       (unless (gnus-ephemeral-group-p group)
7320         (gnus-group-update-group group nil t))
7321       (when (equal (gnus-group-group-name) group)
7322         (gnus-group-next-unread-group 1))
7323       (when quit-config
7324         (gnus-handle-ephemeral-exit quit-config)))))
7325
7326 (defun gnus-handle-ephemeral-exit (quit-config)
7327   "Handle movement when leaving an ephemeral group.
7328 The state which existed when entering the ephemeral is reset."
7329   (if (not (buffer-live-p (car quit-config)))
7330       (when (gnus-buffer-live-p gnus-group-buffer)
7331         (gnus-configure-windows 'group 'force))
7332     (set-buffer (car quit-config))
7333     (unless (eq (cdr quit-config) 'group)
7334       (setq gnus-current-select-method
7335             (gnus-find-method-for-group gnus-newsgroup-name)))
7336     (cond ((eq major-mode 'gnus-summary-mode)
7337            (gnus-set-global-variables))
7338           ((eq major-mode 'gnus-article-mode)
7339            (save-current-buffer
7340              ;; The `gnus-summary-buffer' variable may point
7341              ;; to the old summary buffer when using a single
7342              ;; article buffer.
7343              (unless (gnus-buffer-live-p gnus-summary-buffer)
7344                (set-buffer gnus-group-buffer))
7345              (set-buffer gnus-summary-buffer)
7346              (gnus-set-global-variables))))
7347     (if (or (eq (cdr quit-config) 'article)
7348             (eq (cdr quit-config) 'pick))
7349         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7350             (gnus-configure-windows 'pick 'force)
7351           (gnus-configure-windows (cdr quit-config) 'force))
7352       (gnus-configure-windows (cdr quit-config) 'force))
7353     (when (eq major-mode 'gnus-summary-mode)
7354       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7355                                                      next-unread-noselect))
7356           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7357                                   'next-noselect)
7358                               (gnus-summary-next-subject 1 nil t))
7359                              ((eq gnus-auto-select-on-ephemeral-exit
7360                                   'next-unread-noselect)
7361                               (gnus-summary-next-subject 1 t t))))
7362             ;; Hide the article buffer which displays the article different
7363             ;; from the one that the cursor points to in the summary buffer.
7364             (gnus-configure-windows 'summary 'force))
7365         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7366                (gnus-summary-next-subject 1))
7367               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7368                (gnus-summary-next-subject 1 t))))
7369       (gnus-summary-recenter)
7370       (gnus-summary-position-point))))
7371
7372 ;;; Dead summaries.
7373
7374 (defvar gnus-dead-summary-mode-map
7375   (let ((map (make-keymap)))
7376     (suppress-keymap map)
7377     (substitute-key-definition 'undefined 'gnus-summary-wake-up-the-dead map)
7378     (dolist (key '("\C-d" "\r" "\177" [delete]))
7379       (define-key map key 'gnus-summary-wake-up-the-dead))
7380     (dolist (key '("q" "Q"))
7381       (define-key map key 'bury-buffer))
7382     map))
7383
7384 (define-minor-mode gnus-dead-summary-mode
7385   "Minor mode for Gnus summary buffers."
7386   :lighter " Dead" :keymap gnus-dead-summary-mode-map
7387   (unless (derived-mode-p 'gnus-summary-mode)
7388     (setq gnus-dead-summary-mode nil)))
7389
7390 (defun gnus-deaden-summary ()
7391   "Make the current summary buffer into a dead summary buffer."
7392   ;; Kill any previous dead summary buffer.
7393   (when (and gnus-dead-summary
7394              (buffer-name gnus-dead-summary))
7395     (with-current-buffer gnus-dead-summary
7396       (when gnus-dead-summary-mode
7397         (kill-buffer (current-buffer)))))
7398   ;; Make this the current dead summary.
7399   (setq gnus-dead-summary (current-buffer))
7400   (gnus-dead-summary-mode 1)
7401   (let ((name (buffer-name)))
7402     (when (string-match "Summary" name)
7403       (rename-buffer
7404        (concat (substring name 0 (match-beginning 0)) "Dead "
7405                (substring name (match-beginning 0)))
7406        t)
7407       (bury-buffer))))
7408
7409 (defun gnus-kill-or-deaden-summary (buffer)
7410   "Kill or deaden the summary BUFFER."
7411   (save-excursion
7412     (when (and (buffer-name buffer)
7413                (not gnus-single-article-buffer))
7414       (with-current-buffer buffer
7415         (gnus-kill-buffer gnus-article-buffer)
7416         (gnus-kill-buffer gnus-original-article-buffer)))
7417     (cond
7418      ;; Kill the buffer.
7419      (gnus-kill-summary-on-exit
7420       (when (and gnus-use-trees
7421                  (gnus-buffer-exists-p buffer))
7422         (with-current-buffer buffer
7423           (gnus-tree-close gnus-newsgroup-name)))
7424       (gnus-kill-buffer buffer))
7425      ;; Deaden the buffer.
7426      ((gnus-buffer-exists-p buffer)
7427       (with-current-buffer buffer
7428         (gnus-deaden-summary))))))
7429
7430 (defun gnus-summary-wake-up-the-dead (&rest args)
7431   "Wake up the dead summary buffer."
7432   (interactive)
7433   (gnus-dead-summary-mode -1)
7434   (let ((name (buffer-name)))
7435     (when (string-match "Dead " name)
7436       (rename-buffer
7437        (concat (substring name 0 (match-beginning 0))
7438                (substring name (match-end 0)))
7439        t)))
7440   (gnus-message 3 "This dead summary is now alive again"))
7441
7442 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7443 (defun gnus-summary-describe-group (&optional force)
7444   "Describe the current newsgroup."
7445   (interactive "P")
7446   (gnus-group-describe-group force gnus-newsgroup-name))
7447
7448 (defun gnus-summary-describe-briefly ()
7449   "Describe summary mode commands briefly."
7450   (interactive)
7451   (gnus-message 6 "%s" (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")))
7452
7453 ;; Walking around group mode buffer from summary mode.
7454
7455 (defun gnus-summary-next-group (&optional no-article target-group backward)
7456   "Exit current newsgroup and then select next unread newsgroup.
7457 If prefix argument NO-ARTICLE is non-nil, no article is selected
7458 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7459 previous group instead."
7460   (interactive "P")
7461   ;; Stop pre-fetching.
7462   (gnus-async-halt-prefetch)
7463   (let ((current-group gnus-newsgroup-name)
7464         (current-buffer (current-buffer))
7465         entered)
7466     ;; First we semi-exit this group to update Xrefs and all variables.
7467     ;; We can't do a real exit, because the window conf must remain
7468     ;; the same in case the user is prompted for info, and we don't
7469     ;; want the window conf to change before that...
7470     (gnus-summary-exit t)
7471     (while (not entered)
7472       ;; Then we find what group we are supposed to enter.
7473       (set-buffer gnus-group-buffer)
7474       (gnus-group-jump-to-group current-group)
7475       (setq target-group
7476             (or target-group
7477                 (if (eq gnus-keep-same-level 'best)
7478                     (gnus-summary-best-group gnus-newsgroup-name)
7479                   (gnus-summary-search-group backward gnus-keep-same-level))))
7480       (if (not target-group)
7481           ;; There are no further groups, so we return to the group
7482           ;; buffer.
7483           (progn
7484             (gnus-message 5 "Returning to the group buffer")
7485             (setq entered t)
7486             (when (gnus-buffer-live-p current-buffer)
7487               (set-buffer current-buffer)
7488               (gnus-summary-exit))
7489             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7490         ;; We try to enter the target group.
7491         (gnus-group-jump-to-group target-group)
7492         (let ((unreads (gnus-group-group-unread)))
7493           (if (and (or (eq t unreads)
7494                        (and unreads (not (zerop unreads))))
7495                    (gnus-summary-read-group
7496                     target-group nil no-article
7497                     (and (buffer-name current-buffer) current-buffer)
7498                     nil backward))
7499               (setq entered t)
7500             (setq current-group target-group
7501                   target-group nil)))))))
7502
7503 (defun gnus-summary-prev-group (&optional no-article)
7504   "Exit current newsgroup and then select previous unread newsgroup.
7505 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7506   (interactive "P")
7507   (gnus-summary-next-group no-article nil t))
7508
7509 ;; Walking around summary lines.
7510
7511 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7512   "Go to the first subject satisfying any non-nil constraint.
7513 If UNREAD is non-nil, the article should be unread.
7514 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7515 If UNSEEN is non-nil, the article should be unseen as well as unread.
7516 Returns the article selected or nil if there are no matching articles."
7517   (interactive "P")
7518   (cond
7519    ;; Empty summary.
7520    ((null gnus-newsgroup-data)
7521     (gnus-message 3 "No articles in the group")
7522     nil)
7523    ;; Pick the first article.
7524    ((not (or unread undownloaded unseen))
7525     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7526     (gnus-data-number (car gnus-newsgroup-data)))
7527    ;; Find the first unread article.
7528    (t
7529     (let ((data gnus-newsgroup-data))
7530       (while (and data
7531                   (let ((num (gnus-data-number (car data))))
7532                     (or (memq num gnus-newsgroup-unfetched)
7533                         (not (or (and unread
7534                                       (memq num gnus-newsgroup-unreads))
7535                                  (and undownloaded
7536                                       (memq num gnus-newsgroup-undownloaded))
7537                                  (and unseen
7538                                       (memq num gnus-newsgroup-unseen)
7539                                       (memq num gnus-newsgroup-unreads)))))))
7540         (setq data (cdr data)))
7541       (prog1
7542           (if data
7543               (progn
7544                 (goto-char (gnus-data-pos (car data)))
7545                 (gnus-data-number (car data)))
7546             (gnus-message 3 "No more%s articles"
7547                           (let* ((r (when unread " unread"))
7548                                  (d (when undownloaded " undownloaded"))
7549                                  (s (when unseen " unseen"))
7550                                  (l (delq nil (list r d s))))
7551                             (cond ((= 3 (length l))
7552                                    (concat r "," d ", or" s))
7553                                   ((= 2 (length l))
7554                                    (concat (car l) ", or" (cadr l)))
7555                                   ((= 1 (length l))
7556                                    (car l))
7557                                   (t
7558                                    ""))))
7559             nil
7560             )
7561         (gnus-summary-position-point))))))
7562
7563 (defun gnus-summary-next-subject (n &optional unread dont-display)
7564   "Go to next N'th summary line.
7565 If N is negative, go to the previous N'th subject line.
7566 If UNREAD is non-nil, only unread articles are selected.
7567 The difference between N and the actual number of steps taken is
7568 returned."
7569   (interactive "p")
7570   (let ((backward (< n 0))
7571         (n (abs n)))
7572     (while (and (> n 0)
7573                 (if backward
7574                     (gnus-summary-find-prev unread)
7575                   (gnus-summary-find-next unread)))
7576       (unless (zerop (setq n (1- n)))
7577         (gnus-summary-show-thread)))
7578     (when (/= 0 n)
7579       (gnus-message 7 "No more%s articles"
7580                     (if unread " unread" "")))
7581     (unless dont-display
7582       (gnus-summary-recenter)
7583       (gnus-summary-position-point))
7584     n))
7585
7586 (defun gnus-summary-next-unread-subject (n)
7587   "Go to next N'th unread summary line."
7588   (interactive "p")
7589   (gnus-summary-next-subject n t))
7590
7591 (defun gnus-summary-prev-subject (n &optional unread)
7592   "Go to previous N'th summary line.
7593 If optional argument UNREAD is non-nil, only unread article is selected."
7594   (interactive "p")
7595   (gnus-summary-next-subject (- n) unread))
7596
7597 (defun gnus-summary-prev-unread-subject (n)
7598   "Go to previous N'th unread summary line."
7599   (interactive "p")
7600   (gnus-summary-next-subject (- n) t))
7601
7602 (defun gnus-summary-goto-subjects (articles)
7603   "Insert the subject header for ARTICLES in the current buffer."
7604   (save-excursion
7605     (dolist (article articles)
7606       (gnus-summary-goto-subject article t)))
7607   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7608   (gnus-summary-position-point))
7609
7610 (defun gnus-summary-goto-subject (article &optional force silent)
7611   "Go to the subject line of ARTICLE.
7612 If FORCE, also allow jumping to articles not currently shown."
7613   (interactive "nArticle number: ")
7614   (unless (numberp article)
7615     (error "Article %s is not a number" article))
7616   (let ((b (point))
7617         (data (gnus-data-find article)))
7618     ;; We read in the article if we have to.
7619     (and (not data)
7620          force
7621          (gnus-summary-insert-subject
7622           article
7623           (if (or (numberp force) (vectorp force)) force)
7624           t)
7625          (setq data (gnus-data-find article)))
7626     (goto-char b)
7627     (if (not data)
7628         (progn
7629           (unless silent
7630             (gnus-message 3 "Can't find article %d" article))
7631           nil)
7632       (let ((pt (gnus-data-pos data)))
7633         (goto-char pt)
7634         (gnus-summary-set-article-display-arrow pt))
7635       (gnus-summary-position-point)
7636       article)))
7637
7638 ;; Walking around summary lines with displaying articles.
7639
7640 (defun gnus-summary-expand-window (&optional arg)
7641   "Make the summary buffer take up the entire Emacs frame.
7642 Given a prefix, will force an `article' buffer configuration."
7643   (interactive "P")
7644   (if arg
7645       (gnus-configure-windows 'article 'force)
7646     (gnus-configure-windows 'summary 'force)))
7647
7648 (defun gnus-summary-display-article (article &optional all-header)
7649   "Display ARTICLE in article buffer."
7650   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7651                (with-current-buffer gnus-article-buffer
7652                  (eq major-mode 'gnus-article-mode)))
7653     (gnus-article-setup-buffer))
7654   (gnus-set-global-variables)
7655   (with-current-buffer gnus-article-buffer
7656     (setq gnus-article-charset gnus-newsgroup-charset)
7657     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7658     (mm-enable-multibyte))
7659   (if (null article)
7660       nil
7661     (prog1
7662         (if gnus-summary-display-article-function
7663             (funcall gnus-summary-display-article-function article all-header)
7664           (gnus-article-prepare article all-header))
7665       (gnus-run-hooks 'gnus-select-article-hook)
7666       (when (and gnus-current-article
7667                  (not (zerop gnus-current-article)))
7668         (gnus-summary-goto-subject gnus-current-article))
7669       (gnus-summary-recenter)
7670       (when (and gnus-use-trees gnus-show-threads)
7671         (gnus-possibly-generate-tree article)
7672         (gnus-highlight-selected-tree article))
7673       ;; Successfully display article.
7674       (gnus-article-set-window-start
7675        (cdr (assq article gnus-newsgroup-bookmarks))))))
7676
7677 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7678   "Select the current article.
7679 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7680 non-nil, the article will be re-fetched even if it already present in
7681 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7682 be displayed."
7683   ;; Make sure we are in the summary buffer to work around bbdb bug.
7684   (unless (eq major-mode 'gnus-summary-mode)
7685     (set-buffer gnus-summary-buffer))
7686   (let ((article (or article (gnus-summary-article-number)))
7687         (all-headers (not (not all-headers))) ;Must be t or nil.
7688         gnus-summary-display-article-function)
7689     (and (not pseudo)
7690          (gnus-summary-article-pseudo-p article)
7691          (error "This is a pseudo-article"))
7692     (with-current-buffer gnus-summary-buffer
7693       (if (or (and gnus-single-article-buffer
7694                    (or (null gnus-current-article)
7695                        (null gnus-article-current)
7696                        (null (get-buffer gnus-article-buffer))
7697                        (not (eq article (cdr gnus-article-current)))
7698                        (not (equal (car gnus-article-current)
7699                                    gnus-newsgroup-name))
7700                        (not (get-buffer gnus-original-article-buffer))))
7701               (and (not gnus-single-article-buffer)
7702                    (or (null gnus-current-article)
7703                        (not (get-buffer gnus-original-article-buffer))
7704                        (not (eq gnus-current-article article))))
7705               force)
7706           ;; The requested article is different from the current article.
7707           (progn
7708             (gnus-summary-display-article article all-headers)
7709             (when (gnus-buffer-live-p gnus-article-buffer)
7710               (with-current-buffer gnus-article-buffer
7711                 (if (not gnus-article-decoded-p) ;; a local variable
7712                     (mm-disable-multibyte))))
7713             (gnus-article-set-window-start
7714              (cdr (assq article gnus-newsgroup-bookmarks)))
7715             article)
7716         'old))))
7717
7718 (defun gnus-summary-force-verify-and-decrypt ()
7719   "Display buttons for signed/encrypted parts and verify/decrypt them."
7720   (interactive)
7721   (let ((mm-verify-option 'known)
7722         (mm-decrypt-option 'known)
7723         (gnus-article-emulate-mime t)
7724         (gnus-buttonized-mime-types (append (list "multipart/signed"
7725                                                   "multipart/encrypted")
7726                                             gnus-buttonized-mime-types)))
7727     (gnus-summary-select-article nil 'force)))
7728
7729 (defun gnus-summary-next-article (&optional unread subject backward push)
7730   "Select the next article.
7731 If UNREAD, only unread articles are selected.
7732 If SUBJECT, only articles with SUBJECT are selected.
7733 If BACKWARD, the previous article is selected instead of the next."
7734   (interactive "P")
7735   ;; Make sure we are in the summary buffer.
7736   (unless (eq major-mode 'gnus-summary-mode)
7737     (set-buffer gnus-summary-buffer))
7738   (cond
7739    ;; Is there such an article?
7740    ((and (gnus-summary-search-forward unread subject backward)
7741          (or (gnus-summary-display-article (gnus-summary-article-number))
7742              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7743     (gnus-summary-position-point))
7744    ;; If not, we try the first unread, if that is wanted.
7745    ((and subject
7746          gnus-auto-select-same
7747          (gnus-summary-first-unread-article))
7748     (gnus-summary-position-point)
7749     (gnus-message 6 "Wrapped"))
7750    ;; Try to get next/previous article not displayed in this group.
7751    ((and gnus-auto-extend-newsgroup
7752          (not unread) (not subject))
7753     (gnus-summary-goto-article
7754      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7755      nil (count-lines (point-min) (point))))
7756    ;; Go to next/previous group.
7757    (t
7758     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7759       (gnus-summary-jump-to-group gnus-newsgroup-name))
7760     (let ((cmd (if (featurep 'xemacs)
7761                    last-command-char
7762                  last-command-event))
7763           (point
7764            (with-current-buffer gnus-group-buffer
7765              (point)))
7766           (current-summary (current-buffer))
7767           (group
7768            (if (eq gnus-keep-same-level 'best)
7769                (gnus-summary-best-group gnus-newsgroup-name)
7770              (gnus-summary-search-group backward gnus-keep-same-level))))
7771       ;; Select next unread newsgroup automagically.
7772       (cond
7773        ((or (not gnus-auto-select-next)
7774             (not cmd))
7775         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7776        ((or (eq gnus-auto-select-next 'quietly)
7777             (and (eq gnus-auto-select-next 'slightly-quietly)
7778                  push)
7779             (and (eq gnus-auto-select-next 'almost-quietly)
7780                  (gnus-summary-last-article-p)))
7781         ;; Select quietly.
7782         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7783             (gnus-summary-exit)
7784           (gnus-message 7 "No more%s articles (%s)..."
7785                         (if unread " unread" "")
7786                         (if group (concat "selecting " group)
7787                           "exiting"))
7788           (gnus-summary-next-group nil group backward)))
7789        (t
7790         (when (gnus-key-press-event-p last-input-event)
7791           ;; Somehow or other, we may now have selected a different
7792           ;; window.  Make point go back to the summary buffer.
7793           (when (eq current-summary (current-buffer))
7794             ;; FIXME: This burps when get-buffer-window returns nil.
7795             (select-window (get-buffer-window current-summary 0)))
7796           (gnus-summary-walk-group-buffer
7797            gnus-newsgroup-name cmd unread backward point))))))))
7798
7799 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7800   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7801                       (?\C-p (gnus-group-prev-unread-group 1))))
7802         (cursor-in-echo-area t)
7803         keve key group ended prompt)
7804     (with-current-buffer gnus-group-buffer
7805       (goto-char start)
7806       (setq group
7807             (if (eq gnus-keep-same-level 'best)
7808                 (gnus-summary-best-group gnus-newsgroup-name)
7809               (gnus-summary-search-group backward gnus-keep-same-level))))
7810     (while (not ended)
7811       (setq prompt
7812             (format
7813              "No more%s articles%s " (if unread " unread" "")
7814              (if (and group
7815                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7816                  (format " (Type %s for %s [%s])"
7817                          (single-key-description cmd)
7818                          (gnus-group-decoded-name group)
7819                          (gnus-group-unread group))
7820                (format " (Type %s to exit %s)"
7821                        (single-key-description cmd)
7822                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7823       ;; Confirm auto selection.
7824       (setq key (car (setq keve (gnus-read-event-char prompt)))
7825             ended t)
7826       (cond
7827        ((assq key keystrokes)
7828         (let ((obuf (current-buffer)))
7829           (switch-to-buffer gnus-group-buffer)
7830           (when group
7831             (gnus-group-jump-to-group group))
7832           (eval (cadr (assq key keystrokes)))
7833           (setq group (gnus-group-group-name))
7834           (switch-to-buffer obuf))
7835         (setq ended nil))
7836        ((equal key cmd)
7837         (if (or (not group)
7838                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7839             (gnus-summary-exit)
7840           (gnus-summary-next-group nil group backward)))
7841        (t
7842         (push (cdr keve) unread-command-events))))))
7843
7844 (defun gnus-summary-next-unread-article ()
7845   "Select unread article after current one."
7846   (interactive)
7847   (gnus-summary-next-article
7848    (or (not (eq gnus-summary-goto-unread 'never))
7849        (gnus-summary-last-article-p (gnus-summary-article-number)))
7850    (and gnus-auto-select-same
7851         (gnus-summary-article-subject))))
7852
7853 (defun gnus-summary-prev-article (&optional unread subject)
7854   "Select the article before the current one.
7855 If UNREAD is non-nil, only unread articles are selected."
7856   (interactive "P")
7857   (gnus-summary-next-article unread subject t))
7858
7859 (defun gnus-summary-prev-unread-article ()
7860   "Select unread article before current one."
7861   (interactive)
7862   (gnus-summary-prev-article
7863    (or (not (eq gnus-summary-goto-unread 'never))
7864        (gnus-summary-first-article-p (gnus-summary-article-number)))
7865    (and gnus-auto-select-same
7866         (gnus-summary-article-subject))))
7867
7868 (defun gnus-summary-next-page (&optional lines circular stop)
7869   "Show next page of the selected article.
7870 If at the end of the current article, select the next article.
7871 LINES says how many lines should be scrolled up.
7872
7873 If CIRCULAR is non-nil, go to the start of the article instead of
7874 selecting the next article when reaching the end of the current
7875 article.
7876
7877 If STOP is non-nil, just stop when reaching the end of the message.
7878
7879 Also see the variable `gnus-article-skip-boring'."
7880   (interactive "P")
7881   (gnus-set-global-variables)
7882   (let ((article (gnus-summary-article-number))
7883         (article-window (get-buffer-window gnus-article-buffer t))
7884         endp)
7885     ;; If the buffer is empty, we have no article.
7886     (unless article
7887       (error "No article to select"))
7888     (gnus-configure-windows 'article)
7889     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7890         (if (and (eq gnus-summary-goto-unread 'never)
7891                  (not (gnus-summary-last-article-p article)))
7892             (gnus-summary-next-article)
7893           (gnus-summary-next-unread-article))
7894       (if (or (null gnus-current-article)
7895               (null gnus-article-current)
7896               (/= article (cdr gnus-article-current))
7897               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7898           ;; Selected subject is different from current article's.
7899           (gnus-summary-display-article article)
7900         (when article-window
7901           (gnus-eval-in-buffer-window gnus-article-buffer
7902             (setq endp (or (gnus-article-next-page lines)
7903                            (gnus-article-only-boring-p))))
7904           (when endp
7905             (cond ((or stop gnus-summary-stop-at-end-of-message)
7906                    (gnus-message 3 "End of message"))
7907                   (circular
7908                    (gnus-summary-beginning-of-article))
7909                   (lines
7910                    (gnus-message 3 "End of message"))
7911                   ((null lines)
7912                    (if (and (eq gnus-summary-goto-unread 'never)
7913                             (not (gnus-summary-last-article-p article)))
7914                        (gnus-summary-next-article)
7915                      (gnus-summary-next-unread-article))))))))
7916     (gnus-summary-recenter)
7917     (gnus-summary-position-point)))
7918
7919 (defun gnus-summary-prev-page (&optional lines move)
7920   "Show previous page of selected article.
7921 Argument LINES specifies lines to be scrolled down.
7922 If MOVE, move to the previous unread article if point is at
7923 the beginning of the buffer."
7924   (interactive "P")
7925   (let ((article (gnus-summary-article-number))
7926         (article-window (get-buffer-window gnus-article-buffer t))
7927         endp)
7928     (gnus-configure-windows 'article)
7929     (if (or (null gnus-current-article)
7930             (null gnus-article-current)
7931             (/= article (cdr gnus-article-current))
7932             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7933         ;; Selected subject is different from current article's.
7934         (gnus-summary-display-article article)
7935       (gnus-summary-recenter)
7936       (when article-window
7937         (gnus-eval-in-buffer-window gnus-article-buffer
7938           (setq endp (gnus-article-prev-page lines)))
7939         (when (and move endp)
7940           (cond (lines
7941                  (gnus-message 3 "Beginning of message"))
7942                 ((null lines)
7943                  (if (and (eq gnus-summary-goto-unread 'never)
7944                           (not (gnus-summary-first-article-p article)))
7945                      (gnus-summary-prev-article)
7946                    (gnus-summary-prev-unread-article))))))))
7947   (gnus-summary-position-point))
7948
7949 (defun gnus-summary-prev-page-or-article (&optional lines)
7950   "Show previous page of selected article.
7951 Argument LINES specifies lines to be scrolled down.
7952 If at the beginning of the article, go to the next article."
7953   (interactive "P")
7954   (gnus-summary-prev-page lines t))
7955
7956 (defun gnus-summary-scroll-up (lines)
7957   "Scroll up (or down) one line current article.
7958 Argument LINES specifies lines to be scrolled up (or down if negative).
7959 If no article is selected, then the current article will be selected first."
7960   (interactive "p")
7961   (gnus-configure-windows 'article)
7962   (gnus-summary-show-thread)
7963   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7964     (gnus-eval-in-buffer-window gnus-article-buffer
7965       (cond ((> lines 0)
7966              (when (gnus-article-next-page lines)
7967                (gnus-message 3 "End of message")))
7968             ((< lines 0)
7969              (gnus-article-prev-page (- lines))))))
7970   (gnus-summary-recenter)
7971   (gnus-summary-position-point))
7972
7973 (defun gnus-summary-scroll-down (lines)
7974   "Scroll down (or up) one line current article.
7975 Argument LINES specifies lines to be scrolled down (or up if negative).
7976 If no article is selected, then the current article will be selected first."
7977   (interactive "p")
7978   (gnus-summary-scroll-up (- lines)))
7979
7980 (defun gnus-summary-next-same-subject ()
7981   "Select next article which has the same subject as current one."
7982   (interactive)
7983   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7984
7985 (defun gnus-summary-prev-same-subject ()
7986   "Select previous article which has the same subject as current one."
7987   (interactive)
7988   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7989
7990 (defun gnus-summary-next-unread-same-subject ()
7991   "Select next unread article which has the same subject as current one."
7992   (interactive)
7993   (gnus-summary-next-article t (gnus-summary-article-subject)))
7994
7995 (defun gnus-summary-prev-unread-same-subject ()
7996   "Select previous unread article which has the same subject as current one."
7997   (interactive)
7998   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7999
8000 (defun gnus-summary-first-unread-article ()
8001   "Select the first unread article.
8002 Return nil if there are no unread articles."
8003   (interactive)
8004   (prog1
8005       (when (gnus-summary-first-subject t)
8006         (gnus-summary-show-thread)
8007         (gnus-summary-first-subject t)
8008         (gnus-summary-display-article (gnus-summary-article-number)))
8009     (gnus-summary-position-point)))
8010
8011 (defun gnus-summary-first-unread-subject ()
8012   "Place the point on the subject line of the first unread article.
8013 Return nil if there are no unread articles."
8014   (interactive)
8015   (prog1
8016       (when (gnus-summary-first-subject t)
8017         (gnus-summary-show-thread)
8018         (gnus-summary-first-subject t))
8019     (gnus-summary-position-point)))
8020
8021 (defun gnus-summary-first-unseen-subject ()
8022   "Place the point on the subject line of the first unseen article.
8023 Return nil if there are no unseen articles."
8024   (interactive)
8025   (prog1
8026       (when (gnus-summary-first-subject nil nil t)
8027         (gnus-summary-show-thread)
8028         (gnus-summary-first-subject nil nil t))
8029     (gnus-summary-position-point)))
8030
8031 (defun gnus-summary-first-unseen-or-unread-subject ()
8032   "Place the point on the subject line of the first unseen and unread article.
8033 If all article have been seen, on the subject line of the first unread
8034 article."
8035   (interactive)
8036   (prog1
8037       (unless (when (gnus-summary-first-subject nil nil t)
8038                 (gnus-summary-show-thread)
8039                 (gnus-summary-first-subject nil nil t))
8040         (when (gnus-summary-first-subject t)
8041           (gnus-summary-show-thread)
8042           (gnus-summary-first-subject t)))
8043     (gnus-summary-position-point)))
8044
8045 (defun gnus-summary-first-article ()
8046   "Select the first article.
8047 Return nil if there are no articles."
8048   (interactive)
8049   (prog1
8050       (when (gnus-summary-first-subject)
8051         (gnus-summary-show-thread)
8052         (gnus-summary-first-subject)
8053         (gnus-summary-display-article (gnus-summary-article-number)))
8054     (gnus-summary-position-point)))
8055
8056 (defun gnus-summary-best-unread-article (&optional arg)
8057   "Select the unread article with the highest score.
8058 If given a prefix argument, select the next unread article that has a
8059 score higher than the default score."
8060   (interactive "P")
8061   (let ((article (if arg
8062                      (gnus-summary-better-unread-subject)
8063                    (gnus-summary-best-unread-subject))))
8064     (if article
8065         (gnus-summary-goto-article article)
8066       (error "No unread articles"))))
8067
8068 (defun gnus-summary-best-unread-subject ()
8069   "Select the unread subject with the highest score."
8070   (interactive)
8071   (let ((best -1000000)
8072         (data gnus-newsgroup-data)
8073         article score)
8074     (while data
8075       (and (gnus-data-unread-p (car data))
8076            (> (setq score
8077                     (gnus-summary-article-score (gnus-data-number (car data))))
8078               best)
8079            (setq best score
8080                  article (gnus-data-number (car data))))
8081       (setq data (cdr data)))
8082     (when article
8083       (gnus-summary-goto-subject article))
8084     (gnus-summary-position-point)
8085     article))
8086
8087 (defun gnus-summary-better-unread-subject ()
8088   "Select the first unread subject that has a score over the default score."
8089   (interactive)
8090   (let ((data gnus-newsgroup-data)
8091         article score)
8092     (while (and (setq article (gnus-data-number (car data)))
8093                 (or (gnus-data-read-p (car data))
8094                     (not (> (gnus-summary-article-score article)
8095                             gnus-summary-default-score))))
8096       (setq data (cdr data)))
8097     (when article
8098       (gnus-summary-goto-subject article))
8099     (gnus-summary-position-point)
8100     article))
8101
8102 (defun gnus-summary-last-subject ()
8103   "Go to the last displayed subject line in the group."
8104   (let ((article (gnus-data-number (car (gnus-data-list t)))))
8105     (when article
8106       (gnus-summary-goto-subject article))))
8107
8108 (defun gnus-summary-goto-article (article &optional all-headers force)
8109   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
8110 If ALL-HEADERS is non-nil, no header lines are hidden.
8111 If FORCE, go to the article even if it isn't displayed.  If FORCE
8112 is a number, it is the line the article is to be displayed on."
8113   (interactive
8114    (list
8115     (gnus-completing-read
8116      "Article number or Message-ID"
8117      (mapcar 'int-to-string gnus-newsgroup-limit))
8118     current-prefix-arg
8119     t))
8120   (prog1
8121       (if (and (stringp article)
8122                (string-match "@\\|%40" article))
8123           (gnus-summary-refer-article article)
8124         (when (stringp article)
8125           (setq article (string-to-number article)))
8126         (if (gnus-summary-goto-subject article force)
8127             (gnus-summary-display-article article all-headers)
8128           (gnus-message 4 "Couldn't go to article %s" article) nil))
8129     (gnus-summary-position-point)))
8130
8131 (defun gnus-summary-goto-last-article ()
8132   "Go to the previously read article."
8133   (interactive)
8134   (prog1
8135       (when gnus-last-article
8136         (gnus-summary-goto-article gnus-last-article nil t))
8137     (gnus-summary-position-point)))
8138
8139 (defun gnus-summary-pop-article (number)
8140   "Pop one article off the history and go to the previous.
8141 NUMBER articles will be popped off."
8142   (interactive "p")
8143   (let (to)
8144     (setq gnus-newsgroup-history
8145           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
8146     (if to
8147         (gnus-summary-goto-article (car to) nil t)
8148       (error "Article history empty")))
8149   (gnus-summary-position-point))
8150
8151 ;; Summary commands and functions for limiting the summary buffer.
8152
8153 (defun gnus-summary-limit-to-articles (n)
8154   "Limit the summary buffer to the next N articles.
8155 If not given a prefix, use the process marked articles instead."
8156   (interactive "P")
8157   (prog1
8158       (let ((articles (gnus-summary-work-articles n)))
8159         (setq gnus-newsgroup-processable nil)
8160         (gnus-summary-limit articles))
8161     (gnus-summary-position-point)))
8162
8163 (defun gnus-summary-pop-limit (&optional total)
8164   "Restore the previous limit.
8165 If given a prefix, remove all limits."
8166   (interactive "P")
8167   (when total
8168     (setq gnus-newsgroup-limits
8169           (list (mapcar (lambda (h) (mail-header-number h))
8170                         gnus-newsgroup-headers))))
8171   (unless gnus-newsgroup-limits
8172     (error "No limit to pop"))
8173   (prog1
8174       (gnus-summary-limit nil 'pop)
8175     (gnus-summary-position-point)))
8176
8177 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
8178   "Limit the summary buffer to articles that have subjects that match a regexp.
8179 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
8180   (interactive
8181    (list (read-string (if current-prefix-arg
8182                           "Exclude subject (regexp): "
8183                         "Limit to subject (regexp): "))
8184          nil current-prefix-arg))
8185   (unless header
8186     (setq header "subject"))
8187   (when (not (equal "" subject))
8188     (prog1
8189         (let ((articles (gnus-summary-find-matching
8190                          (or header "subject") subject 'all nil nil
8191                          not-matching)))
8192           (unless articles
8193             (error "Found no matches for \"%s\"" subject))
8194           (gnus-summary-limit articles))
8195       (gnus-summary-position-point))))
8196
8197 (defun gnus-summary-limit-to-author (from &optional not-matching)
8198   "Limit the summary buffer to articles that have authors that match a regexp.
8199 If NOT-MATCHING, excluding articles that have authors that match a regexp."
8200   (interactive
8201    (list (let* ((header (gnus-summary-article-header))
8202                 (default (and header (car (mail-header-parse-address
8203                                            (mail-header-from header))))))
8204            (read-string (concat (if current-prefix-arg
8205                                     "Exclude author (regexp"
8206                                   "Limit to author (regexp")
8207                                 (if default
8208                                     (concat ", default \"" default "\"): ")
8209                                   "): "))
8210                         nil nil
8211                         default))
8212          current-prefix-arg))
8213   (gnus-summary-limit-to-subject from "from" not-matching))
8214
8215 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8216   "Limit the summary buffer to articles with the given RECIPIENT.
8217
8218 If NOT-MATCHING, exclude RECIPIENT.
8219
8220 To and Cc headers are checked.  You need to include them in
8221 `nnmail-extra-headers'."
8222   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8223   (interactive
8224    (list (read-string (format "%s recipient (regexp): "
8225                               (if current-prefix-arg "Exclude" "Limit to")))
8226          current-prefix-arg))
8227   (when (not (equal "" recipient))
8228     (prog1 (let* ((to
8229                    (if (memq 'To nnmail-extra-headers)
8230                        (gnus-summary-find-matching
8231                         (cons 'extra 'To) recipient 'all nil nil
8232                         not-matching)
8233                      (gnus-message
8234                       1 "`To' isn't present in `nnmail-extra-headers'")
8235                      (sit-for 1)
8236                      nil))
8237                   (cc
8238                    (if (memq 'Cc nnmail-extra-headers)
8239                        (gnus-summary-find-matching
8240                         (cons 'extra 'Cc) recipient 'all nil nil
8241                         not-matching)
8242                      (gnus-message
8243                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8244                      (sit-for 1)
8245                      nil))
8246                   (articles
8247                    (if not-matching
8248                        ;; We need the numbers that are in both lists:
8249                        (mapcar (lambda (a)
8250                                  (and (memq a to) a))
8251                                cc)
8252                      (nconc to cc))))
8253              (unless articles
8254                (error "Found no matches for \"%s\"" recipient))
8255              (gnus-summary-limit articles))
8256       (gnus-summary-position-point))))
8257
8258 (defun gnus-summary-limit-to-address (address &optional not-matching)
8259   "Limit the summary buffer to articles with the given ADDRESS.
8260
8261 If NOT-MATCHING, exclude ADDRESS.
8262
8263 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8264 in `nnmail-extra-headers'."
8265   (interactive
8266    (list (read-string (format "%s address (regexp): "
8267                               (if current-prefix-arg "Exclude" "Limit to")))
8268          current-prefix-arg))
8269   (when (not (equal "" address))
8270     (prog1 (let* ((to
8271                    (if (memq 'To nnmail-extra-headers)
8272                        (gnus-summary-find-matching
8273                         (cons 'extra 'To) address 'all nil nil
8274                         not-matching)
8275                      (gnus-message
8276                       1 "`To' isn't present in `nnmail-extra-headers'")
8277                      (sit-for 1)
8278                      t))
8279                   (cc
8280                    (if (memq 'Cc nnmail-extra-headers)
8281                        (gnus-summary-find-matching
8282                         (cons 'extra 'Cc) address 'all nil nil
8283                         not-matching)
8284                      (gnus-message
8285                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8286                      (sit-for 1)
8287                      t))
8288                   (from
8289                    (gnus-summary-find-matching "from" address
8290                                                'all nil nil not-matching))
8291                   (articles
8292                    (if not-matching
8293                        ;; We need the numbers that are in all lists:
8294                        (if (eq cc t)
8295                            (if (eq to t)
8296                                from
8297                              (mapcar (lambda (a) (car (memq a from))) to))
8298                          (if (eq to t)
8299                              (mapcar (lambda (a) (car (memq a from))) cc)
8300                            (mapcar (lambda (a) (car (memq a from)))
8301                                    (mapcar (lambda (a) (car (memq a to)))
8302                                            cc))))
8303                      (nconc (if (eq to t) nil to)
8304                             (if (eq cc t) nil cc)
8305                             from))))
8306              (unless articles
8307                (error "Found no matches for \"%s\"" address))
8308              (gnus-summary-limit articles))
8309       (gnus-summary-position-point))))
8310
8311 (defun gnus-summary-limit-strange-charsets-predicate (header)
8312   (when (fboundp 'char-charset)
8313     (let ((string (concat (mail-header-subject header)
8314                           (mail-header-from header)))
8315           charset found)
8316       (dotimes (i (1- (length string)))
8317         (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8318         (when (string-match "unicode\\|big\\|japanese" charset)
8319           (setq found t)))
8320       found)))
8321
8322 (defun gnus-summary-limit-to-predicate (predicate)
8323   "Limit to articles where PREDICATE returns non-nil.
8324 PREDICATE will be called with the header structures of the
8325 articles."
8326   (let ((articles nil)
8327         (case-fold-search t))
8328     (dolist (header gnus-newsgroup-headers)
8329       (when (funcall predicate header)
8330         (push (mail-header-number header) articles)))
8331     (gnus-summary-limit (nreverse articles))))
8332
8333 (defun gnus-summary-limit-to-age (age &optional younger-p)
8334   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8335 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8336 articles that are younger than AGE days."
8337   (interactive
8338    (let ((younger current-prefix-arg)
8339          (days-got nil)
8340          days)
8341      (while (not days-got)
8342        (setq days (if younger
8343                       (read-string "Limit to articles younger than (in days, older when negative): ")
8344                     (read-string
8345                      "Limit to articles older than (in days, younger when negative): ")))
8346        (when (> (length days) 0)
8347          (setq days (read days)))
8348        (if (numberp days)
8349            (progn
8350              (setq days-got t)
8351              (when (< days 0)
8352                (setq younger (not younger))
8353                (setq days (* days -1))))
8354          (message "Please enter a number.")
8355          (sleep-for 1)))
8356      (list days younger)))
8357   (prog1
8358       (let ((data gnus-newsgroup-data)
8359             (cutoff (days-to-time age))
8360             articles d date is-younger)
8361         (while (setq d (pop data))
8362           (when (and (vectorp (gnus-data-header d))
8363                      (setq date (mail-header-date (gnus-data-header d))))
8364             (setq is-younger (time-less-p
8365                               (time-since (gnus-date-get-time date))
8366                               cutoff))
8367             (when (if younger-p
8368                       is-younger
8369                     (not is-younger))
8370               (push (gnus-data-number d) articles))))
8371         (gnus-summary-limit (nreverse articles)))
8372     (gnus-summary-position-point)))
8373
8374 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8375   "Limit the summary buffer to articles that match an 'extra' header."
8376   (interactive
8377    (let ((header
8378           (intern
8379            (gnus-completing-read
8380             (if current-prefix-arg
8381                 "Exclude extra header"
8382               "Limit extra header")
8383             (mapcar 'symbol-name gnus-extra-headers)
8384             t nil nil
8385             (symbol-name (car gnus-extra-headers))))))
8386      (list header
8387            (read-string (format "%s header %s (regexp): "
8388                                 (if current-prefix-arg "Exclude" "Limit to")
8389                                 header))
8390            current-prefix-arg)))
8391   (when (not (equal "" regexp))
8392     (prog1
8393         (let ((articles (gnus-summary-find-matching
8394                          (cons 'extra header) regexp 'all nil nil
8395                          not-matching)))
8396           (unless articles
8397             (error "Found no matches for \"%s\"" regexp))
8398           (gnus-summary-limit articles))
8399       (gnus-summary-position-point))))
8400
8401 (defun gnus-summary-limit-to-display-predicate ()
8402   "Limit the summary buffer to the predicated in the `display' group parameter."
8403   (interactive)
8404   (unless gnus-newsgroup-display
8405     (error "There is no `display' group parameter"))
8406   (let (articles)
8407     (dolist (gnus-number gnus-newsgroup-articles)
8408       (when (funcall gnus-newsgroup-display)
8409         (push gnus-number articles)))
8410     (gnus-summary-limit articles))
8411   (gnus-summary-position-point))
8412
8413 (defun gnus-summary-limit-to-unread (&optional all)
8414   "Limit the summary buffer to articles that are not marked as read.
8415 If ALL is non-nil, limit strictly to unread articles."
8416   (interactive "P")
8417   (if all
8418       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8419     (gnus-summary-limit-to-marks
8420      ;; Concat all the marks that say that an article is read and have
8421      ;; those removed.
8422      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8423            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8424            gnus-low-score-mark gnus-expirable-mark
8425            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8426            gnus-duplicate-mark)
8427      'reverse)))
8428
8429 (defun gnus-summary-limit-to-headers (match &optional reverse)
8430   "Limit the summary buffer to articles that have headers that match MATCH.
8431 If REVERSE (the prefix), limit to articles that don't match."
8432   (interactive "sMatch headers (regexp): \nP")
8433   (gnus-summary-limit-to-bodies match reverse t))
8434
8435 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8436   "Limit the summary buffer to articles that have bodies that match MATCH.
8437 If REVERSE (the prefix), limit to articles that don't match."
8438   (interactive "sMatch body (regexp): \nP")
8439   (let ((articles nil)
8440         (gnus-select-article-hook nil)  ;Disable hook.
8441         (gnus-article-prepare-hook nil)
8442         (gnus-use-article-prefetch nil)
8443         (gnus-keep-backlog nil)
8444         (gnus-break-pages nil)
8445         (gnus-summary-display-arrow nil)
8446         (gnus-updated-mode-lines nil)
8447         (gnus-auto-center-summary nil)
8448         (gnus-display-mime-function nil))
8449     (dolist (data gnus-newsgroup-data)
8450       (let (gnus-mark-article-hook)
8451         (gnus-summary-select-article t t nil (gnus-data-number data)))
8452       (with-current-buffer gnus-article-buffer
8453         (article-goto-body)
8454         (let* ((case-fold-search t)
8455                (found (if headersp
8456                           (re-search-backward match nil t)
8457                         (re-search-forward match nil t))))
8458           (when (or (and found
8459                          (not reverse))
8460                     (and (not found)
8461                          reverse))
8462             (push (gnus-data-number data) articles)))))
8463     (if (not articles)
8464         (message "No messages matched")
8465       (gnus-summary-limit articles)))
8466   (gnus-summary-position-point))
8467
8468 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8469   "Limit the summary buffer to articles that aren't part on any thread.
8470 If THREADSP (the prefix), limit to articles that are in threads."
8471   (interactive "P")
8472   (let ((articles nil)
8473         thread-articles
8474         threads)
8475     (dolist (thread gnus-newsgroup-threads)
8476       (if (stringp (car thread))
8477           (dolist (thread (cdr thread))
8478             (push thread threads))
8479         (push thread threads)))
8480     (dolist (thread threads)
8481       (setq thread-articles (gnus-articles-in-thread thread))
8482       (when (or (and threadsp
8483                      (> (length thread-articles) 1))
8484                 (and (not threadsp)
8485                      (= (length thread-articles) 1)))
8486         (setq articles (nconc thread-articles articles))))
8487     (if (not articles)
8488         (message "No messages matched")
8489       (gnus-summary-limit articles))
8490     (gnus-summary-position-point)))
8491
8492 (defun gnus-summary-limit-to-replied (&optional unreplied)
8493   "Limit the summary buffer to replied articles.
8494 If UNREPLIED (the prefix), limit to unreplied articles."
8495   (interactive "P")
8496   (if unreplied
8497       (gnus-summary-limit
8498        (gnus-set-difference gnus-newsgroup-articles
8499         gnus-newsgroup-replied))
8500     (gnus-summary-limit gnus-newsgroup-replied))
8501   (gnus-summary-position-point))
8502
8503 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8504   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8505 If REVERSE, limit the summary buffer to articles that are marked
8506 with MARKS.  MARKS can either be a string of marks or a list of marks.
8507 Returns how many articles were removed."
8508   (interactive "sMarks: ")
8509   (gnus-summary-limit-to-marks marks t))
8510
8511 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8512   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8513 If REVERSE (the prefix), limit the summary buffer to articles that are
8514 not marked with MARKS.  MARKS can either be a string of marks or a
8515 list of marks.
8516 Returns how many articles were removed."
8517   (interactive "sMarks: \nP")
8518   (prog1
8519       (let ((data gnus-newsgroup-data)
8520             (marks (if (listp marks) marks
8521                      (append marks nil))) ; Transform to list.
8522             articles)
8523         (while data
8524           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8525                   (memq (gnus-data-mark (car data)) marks))
8526             (push (gnus-data-number (car data)) articles))
8527           (setq data (cdr data)))
8528         (gnus-summary-limit articles))
8529     (gnus-summary-position-point)))
8530
8531 (defun gnus-summary-limit-to-score (score)
8532   "Limit to articles with score at or above SCORE."
8533   (interactive "NLimit to articles with score of at least: ")
8534   (let ((data gnus-newsgroup-data)
8535         articles)
8536     (while data
8537       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8538                 score)
8539         (push (gnus-data-number (car data)) articles))
8540       (setq data (cdr data)))
8541     (prog1
8542         (gnus-summary-limit articles)
8543       (gnus-summary-position-point))))
8544
8545 (defun gnus-summary-limit-to-unseen ()
8546   "Limit to unseen articles."
8547   (interactive)
8548   (prog1
8549       (gnus-summary-limit gnus-newsgroup-unseen)
8550     (gnus-summary-position-point)))
8551
8552 (defun gnus-summary-limit-include-thread (id)
8553   "Display all the hidden articles that is in the thread with ID in it.
8554 When called interactively, ID is the Message-ID of the current
8555 article."
8556   (interactive (list (mail-header-id (gnus-summary-article-header))))
8557   (let ((articles (gnus-articles-in-thread
8558                    (gnus-id-to-thread (gnus-root-id id))))
8559         ;;we REALLY want the whole thread---this prevents cut-threads
8560         ;;from removing the thread we want to include.
8561         (gnus-fetch-old-headers nil)
8562         (gnus-build-sparse-threads nil))
8563     (prog1
8564         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8565       (gnus-summary-limit-include-matching-articles
8566        "subject"
8567        (regexp-quote (gnus-simplify-subject-re
8568                       (mail-header-subject (gnus-id-to-header id)))))
8569       (gnus-summary-position-point))))
8570
8571 (defun gnus-summary-limit-include-matching-articles (header regexp)
8572   "Display all the hidden articles that have HEADERs that match REGEXP."
8573   (interactive (list (read-string "Match on header: ")
8574                      (read-string "Regexp: ")))
8575   (let ((articles (gnus-find-matching-articles header regexp)))
8576     (prog1
8577         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8578       (gnus-summary-position-point))))
8579
8580 (defun gnus-summary-insert-dormant-articles ()
8581   "Insert all the dormant articles for this group into the current buffer."
8582   (interactive)
8583   (let ((gnus-verbose (max 6 gnus-verbose)))
8584     (if (not gnus-newsgroup-dormant)
8585         (gnus-message 3 "No dormant articles for this group")
8586       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8587
8588 (defun gnus-summary-insert-ticked-articles ()
8589   "Insert ticked articles for this group into the current buffer."
8590   (interactive)
8591   (let ((gnus-verbose (max 6 gnus-verbose)))
8592     (if (not gnus-newsgroup-marked)
8593         (gnus-message 3 "No ticked articles for this group")
8594       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8595
8596 (defun gnus-summary-limit-include-dormant ()
8597   "Display all the hidden articles that are marked as dormant.
8598 Note that this command only works on a subset of the articles currently
8599 fetched for this group."
8600   (interactive)
8601   (unless gnus-newsgroup-dormant
8602     (error "There are no dormant articles in this group"))
8603   (prog1
8604       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8605     (gnus-summary-position-point)))
8606
8607 (defun gnus-summary-include-articles (articles)
8608   "Fetch the headers for ARTICLES and then display the summary lines."
8609   (let ((gnus-inhibit-demon t)
8610         (gnus-agent nil)
8611         (gnus-read-all-available-headers t))
8612     (setq gnus-newsgroup-headers
8613           (gnus-merge
8614            'list gnus-newsgroup-headers
8615            (gnus-fetch-headers articles nil t)
8616            'gnus-article-sort-by-number))
8617     (setq gnus-newsgroup-articles
8618           (gnus-sorted-nunion gnus-newsgroup-articles articles))
8619     (gnus-summary-limit (append articles gnus-newsgroup-limit))))
8620
8621 (defun gnus-summary-limit-exclude-dormant ()
8622   "Hide all dormant articles."
8623   (interactive)
8624   (prog1
8625       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8626     (gnus-summary-position-point)))
8627
8628 (defun gnus-summary-limit-exclude-childless-dormant ()
8629   "Hide all dormant articles that have no children."
8630   (interactive)
8631   (let ((data (gnus-data-list t))
8632         articles d children)
8633     ;; Find all articles that are either not dormant or have
8634     ;; children.
8635     (while (setq d (pop data))
8636       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8637                 (and (setq children
8638                            (gnus-article-children (gnus-data-number d)))
8639                      (let (found)
8640                        (while children
8641                          (when (memq (car children) articles)
8642                            (setq children nil
8643                                  found t))
8644                          (pop children))
8645                        found)))
8646         (push (gnus-data-number d) articles)))
8647     ;; Do the limiting.
8648     (prog1
8649         (gnus-summary-limit articles)
8650       (gnus-summary-position-point))))
8651
8652 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8653   "Mark all unread excluded articles as read.
8654 If ALL, mark even excluded ticked and dormants as read."
8655   (interactive "P")
8656   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8657   (let ((articles (gnus-sorted-ndifference
8658                    (sort
8659                     (mapcar (lambda (h) (mail-header-number h))
8660                             gnus-newsgroup-headers)
8661                     '<)
8662                    gnus-newsgroup-limit))
8663         article)
8664     (setq gnus-newsgroup-unreads
8665           (gnus-sorted-intersection gnus-newsgroup-unreads
8666                                     gnus-newsgroup-limit))
8667     (if all
8668         (setq gnus-newsgroup-dormant nil
8669               gnus-newsgroup-marked nil
8670               gnus-newsgroup-reads
8671               (nconc
8672                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8673                gnus-newsgroup-reads))
8674       (while (setq article (pop articles))
8675         (unless (or (memq article gnus-newsgroup-dormant)
8676                     (memq article gnus-newsgroup-marked))
8677           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8678
8679 (defun gnus-summary-limit (articles &optional pop)
8680   (if pop
8681       ;; We pop the previous limit off the stack and use that.
8682       (setq articles (car gnus-newsgroup-limits)
8683             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8684     ;; We use the new limit, so we push the old limit on the stack.
8685     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8686   ;; Set the limit.
8687   (setq gnus-newsgroup-limit articles)
8688   (let ((total (length gnus-newsgroup-data))
8689         (data (gnus-data-find-list (gnus-summary-article-number)))
8690         (gnus-summary-mark-below nil)   ; Inhibit this.
8691         found)
8692     ;; This will do all the work of generating the new summary buffer
8693     ;; according to the new limit.
8694     (gnus-summary-prepare)
8695     ;; Hide any threads, possibly.
8696     (gnus-summary-maybe-hide-threads)
8697     ;; Try to return to the article you were at, or one in the
8698     ;; neighborhood.
8699     (when data
8700       ;; We try to find some article after the current one.
8701       (while data
8702         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8703           (setq data nil
8704                 found t))
8705         (setq data (cdr data))))
8706     (unless found
8707       ;; If there is no data, that means that we were after the last
8708       ;; article.  The same goes when we can't find any articles
8709       ;; after the current one.
8710       (goto-char (point-max))
8711       (gnus-summary-find-prev))
8712     (gnus-set-mode-line 'summary)
8713     ;; We return how many articles were removed from the summary
8714     ;; buffer as a result of the new limit.
8715     (- total (length gnus-newsgroup-data))))
8716
8717 (defsubst gnus-invisible-cut-children (threads)
8718   (let ((num 0))
8719     (while threads
8720       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8721         (incf num))
8722       (pop threads))
8723     (< num 2)))
8724
8725 (defsubst gnus-cut-thread (thread)
8726   "Go forwards in the thread until we find an article that we want to display."
8727   (when (or (eq gnus-fetch-old-headers 'some)
8728             (eq gnus-fetch-old-headers 'invisible)
8729             (numberp gnus-fetch-old-headers)
8730             (eq gnus-build-sparse-threads 'some)
8731             (eq gnus-build-sparse-threads 'more))
8732     ;; Deal with old-fetched headers and sparse threads.
8733     (while (and
8734             thread
8735             (or
8736              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8737              (gnus-summary-article-ancient-p
8738               (mail-header-number (car thread))))
8739             (if (or (<= (length (cdr thread)) 1)
8740                     (eq gnus-fetch-old-headers 'invisible))
8741                 (setq gnus-newsgroup-limit
8742                       (delq (mail-header-number (car thread))
8743                             gnus-newsgroup-limit)
8744                       thread (cadr thread))
8745               (when (gnus-invisible-cut-children (cdr thread))
8746                 (let ((th (cdr thread)))
8747                   (while th
8748                     (if (memq (mail-header-number (caar th))
8749                               gnus-newsgroup-limit)
8750                         (setq thread (car th)
8751                               th nil)
8752                       (setq th (cdr th))))))))))
8753   thread)
8754
8755 (defun gnus-cut-threads (threads)
8756   "Cut off all uninteresting articles from the beginning of THREADS."
8757   (when (or (eq gnus-fetch-old-headers 'some)
8758             (eq gnus-fetch-old-headers 'invisible)
8759             (numberp gnus-fetch-old-headers)
8760             (eq gnus-build-sparse-threads 'some)
8761             (eq gnus-build-sparse-threads 'more))
8762     (let ((th threads))
8763       (while th
8764         (setcar th (gnus-cut-thread (car th)))
8765         (setq th (cdr th)))))
8766   ;; Remove nixed out threads.
8767   (delq nil threads))
8768
8769 (defun gnus-summary-initial-limit (&optional show-if-empty)
8770   "Figure out what the initial limit is supposed to be on group entry.
8771 This entails weeding out unwanted dormants, low-scored articles,
8772 fetch-old-headers verbiage, and so on."
8773   ;; Most groups have nothing to remove.
8774   (unless (or gnus-inhibit-limiting
8775               (and (null gnus-newsgroup-dormant)
8776                    (eq gnus-newsgroup-display 'gnus-not-ignore)
8777                    (not (eq gnus-fetch-old-headers 'some))
8778                    (not (numberp gnus-fetch-old-headers))
8779                    (not (eq gnus-fetch-old-headers 'invisible))
8780                    (null gnus-summary-expunge-below)
8781                    (not (eq gnus-build-sparse-threads 'some))
8782                    (not (eq gnus-build-sparse-threads 'more))
8783                    (null gnus-thread-expunge-below)))
8784     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8785     (setq gnus-newsgroup-limit nil)
8786     (mapatoms
8787      (lambda (node)
8788        (unless (car (symbol-value node))
8789          ;; These threads have no parents -- they are roots.
8790          (let ((nodes (cdr (symbol-value node)))
8791                thread)
8792            (while nodes
8793              (if (and gnus-thread-expunge-below
8794                       (< (gnus-thread-total-score (car nodes))
8795                          gnus-thread-expunge-below))
8796                  (gnus-expunge-thread (pop nodes))
8797                (setq thread (pop nodes))
8798                (gnus-summary-limit-children thread))))))
8799      gnus-newsgroup-dependencies)
8800     ;; If this limitation resulted in an empty group, we might
8801     ;; pop the previous limit and use it instead.
8802     (when (and (not gnus-newsgroup-limit)
8803                show-if-empty)
8804       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8805     gnus-newsgroup-limit))
8806
8807 (defun gnus-summary-limit-children (thread)
8808   "Return 1 if this subthread is visible and 0 if it is not."
8809   ;; First we get the number of visible children to this thread.  This
8810   ;; is done by recursing down the thread using this function, so this
8811   ;; will really go down to a leaf article first, before slowly
8812   ;; working its way up towards the root.
8813   (when thread
8814     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8815            (children
8816            (if (cdr thread)
8817                (apply '+ (mapcar 'gnus-summary-limit-children
8818                                  (cdr thread)))
8819              0))
8820            (number (mail-header-number (car thread)))
8821            score)
8822       (if (and
8823            (not (memq number gnus-newsgroup-marked))
8824            (or
8825             ;; If this article is dormant and has absolutely no visible
8826             ;; children, then this article isn't visible.
8827             (and (memq number gnus-newsgroup-dormant)
8828                  (zerop children))
8829             ;; If this is "fetch-old-headered" and there is no
8830             ;; visible children, then we don't want this article.
8831             (and (or (eq gnus-fetch-old-headers 'some)
8832                      (numberp gnus-fetch-old-headers))
8833                  (gnus-summary-article-ancient-p number)
8834                  (zerop children))
8835             ;; If this is "fetch-old-headered" and `invisible', then
8836             ;; we don't want this article.
8837             (and (eq gnus-fetch-old-headers 'invisible)
8838                  (gnus-summary-article-ancient-p number))
8839             ;; If this is a sparsely inserted article with no children,
8840             ;; we don't want it.
8841             (and (eq gnus-build-sparse-threads 'some)
8842                  (gnus-summary-article-sparse-p number)
8843                  (zerop children))
8844             ;; If we use expunging, and this article is really
8845             ;; low-scored, then we don't want this article.
8846             (when (and gnus-summary-expunge-below
8847                        (< (setq score
8848                                 (or (cdr (assq number gnus-newsgroup-scored))
8849                                     gnus-summary-default-score))
8850                           gnus-summary-expunge-below))
8851               ;; We increase the expunge-tally here, but that has
8852               ;; nothing to do with the limits, really.
8853               (incf gnus-newsgroup-expunged-tally)
8854               ;; We also mark as read here, if that's wanted.
8855               (when (and gnus-summary-mark-below
8856                          (< score gnus-summary-mark-below))
8857                 (setq gnus-newsgroup-unreads
8858                       (delq number gnus-newsgroup-unreads))
8859                 (if gnus-newsgroup-auto-expire
8860                     (push number gnus-newsgroup-expirable)
8861                   (push (cons number gnus-low-score-mark)
8862                         gnus-newsgroup-reads)))
8863               t)
8864             ;; Do the `display' group parameter.
8865             (and gnus-newsgroup-display
8866                  (let ((gnus-number number))
8867                    (not (funcall gnus-newsgroup-display))))))
8868           ;; Nope, invisible article.
8869           0
8870         ;; Ok, this article is to be visible, so we add it to the limit
8871         ;; and return 1.
8872         (push number gnus-newsgroup-limit)
8873         1))))
8874
8875 (defun gnus-expunge-thread (thread)
8876   "Mark all articles in THREAD as read."
8877   (let* ((number (mail-header-number (car thread))))
8878     (incf gnus-newsgroup-expunged-tally)
8879     ;; We also mark as read here, if that's wanted.
8880     (setq gnus-newsgroup-unreads
8881           (delq number gnus-newsgroup-unreads))
8882     (if gnus-newsgroup-auto-expire
8883         (push number gnus-newsgroup-expirable)
8884       (push (cons number gnus-low-score-mark)
8885             gnus-newsgroup-reads)))
8886   ;; Go recursively through all subthreads.
8887   (mapcar 'gnus-expunge-thread (cdr thread)))
8888
8889 ;; Summary article oriented commands
8890
8891 (defun gnus-summary-refer-parent-article (n)
8892   "Refer parent article N times.
8893 If N is negative, go to ancestor -N instead.
8894 The difference between N and the number of articles fetched is returned."
8895   (interactive "p")
8896   (let ((skip 1)
8897         error header ref)
8898     (when (not (natnump n))
8899       (setq skip (abs n)
8900             n 1))
8901     (while (and (> n 0)
8902                 (not error))
8903       (setq header (gnus-summary-article-header))
8904       (if (and (eq (mail-header-number header)
8905                    (cdr gnus-article-current))
8906                (equal gnus-newsgroup-name
8907                       (car gnus-article-current)))
8908           ;; If we try to find the parent of the currently
8909           ;; displayed article, then we take a look at the actual
8910           ;; References header, since this is slightly more
8911           ;; reliable than the References field we got from the
8912           ;; server.
8913           (with-current-buffer gnus-original-article-buffer
8914             (nnheader-narrow-to-headers)
8915             (unless (setq ref (message-fetch-field "references"))
8916               (when (setq ref (message-fetch-field "in-reply-to"))
8917                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8918             (widen))
8919         (setq ref
8920               ;; It's not the current article, so we take a bet on
8921               ;; the value we got from the server.
8922               (mail-header-references header)))
8923       (if (and ref
8924                (not (equal ref "")))
8925           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8926             (gnus-message 1 "Couldn't find parent"))
8927         (gnus-message 1 "No references in article %d"
8928                       (gnus-summary-article-number))
8929         (setq error t))
8930       (decf n))
8931     (gnus-summary-position-point)
8932     n))
8933
8934 (defun gnus-summary-refer-references ()
8935   "Fetch all articles mentioned in the References header.
8936 Return the number of articles fetched."
8937   (interactive)
8938   (let ((ref (mail-header-references (gnus-summary-article-header)))
8939         (current (gnus-summary-article-number))
8940         (n 0))
8941     (if (or (not ref)
8942             (equal ref ""))
8943         (error "No References in the current article")
8944       ;; For each Message-ID in the References header...
8945       (while (string-match "<[^>]*>" ref)
8946         (incf n)
8947         ;; ... fetch that article.
8948         (gnus-summary-refer-article
8949          (prog1 (match-string 0 ref)
8950            (setq ref (substring ref (match-end 0))))))
8951       (gnus-summary-goto-subject current)
8952       (gnus-summary-position-point)
8953       n)))
8954
8955 (defun gnus-delete-duplicate-headers (headers)
8956   ;; First remove leading duplicates.
8957   (while (and (> (length headers) 1)
8958               (= (mail-header-number (car headers))
8959                  (mail-header-number (cadr headers))))
8960     (pop headers))
8961   ;; Then the rest.
8962   (let ((result headers))
8963     (while (> (length headers) 1)
8964       (if (= (mail-header-number (car headers))
8965              (mail-header-number (cadr headers)))
8966           (setcdr headers (cddr headers))
8967         (pop headers)))
8968     result))
8969
8970 (defun gnus-summary-refer-thread (&optional limit)
8971   "Fetch all articles in the current thread. For backends that
8972 know how to search for threads (currently only 'nnimap) a
8973 non-numeric prefix arg will use nnir to search the entire
8974 server; without a prefix arg only the current group is
8975 searched. If the variable `gnus-refer-thread-use-nnir' is
8976 non-nil the prefix arg has the reverse meaning. If no
8977 backend-specific 'request-thread function is available fetch
8978 LIMIT (the numerical prefix) old headers. If LIMIT is
8979 non-numeric or nil fetch the number specified by the
8980 `gnus-refer-thread-limit' variable."
8981   (interactive "P")
8982   (gnus-warp-to-article)
8983   (let* ((header (gnus-summary-article-header))
8984          (id (mail-header-id header))
8985          (gnus-inhibit-demon t)
8986          (gnus-summary-ignore-duplicates t)
8987          (gnus-read-all-available-headers t)
8988          (gnus-refer-thread-use-nnir
8989           (if (and (not (null limit)) (listp limit))
8990               (not gnus-refer-thread-use-nnir) gnus-refer-thread-use-nnir))
8991          (new-headers
8992           (if (gnus-check-backend-function
8993                'request-thread gnus-newsgroup-name)
8994               (gnus-request-thread header gnus-newsgroup-name)
8995             (let* ((limit (if (numberp limit) (prefix-numeric-value limit)
8996                             gnus-refer-thread-limit))
8997                    (last (if (numberp limit)
8998                              (min (+ (mail-header-number header)
8999                                      limit)
9000                                   gnus-newsgroup-highest)
9001                            gnus-newsgroup-highest))
9002                    (subject (gnus-simplify-subject
9003                              (mail-header-subject header)))
9004                    (refs (split-string (or (mail-header-references header)
9005                                            "")))
9006                    (gnus-parse-headers-hook
9007                     `(lambda () (goto-char (point-min))
9008                       (keep-lines
9009                        (regexp-opt ',(append refs (list id subject)))))))
9010               (gnus-fetch-headers (list last) (if (numberp limit)
9011                                                   (* 2 limit) limit) t))))
9012          article-ids)
9013     (when (listp new-headers)
9014       (dolist (header new-headers)
9015         (push (mail-header-number header) article-ids)
9016         (when (member (mail-header-number header) gnus-newsgroup-unselected)
9017           (push (mail-header-number header) gnus-newsgroup-unreads)
9018           (setq gnus-newsgroup-unselected
9019                 (delete (mail-header-number header)
9020                         gnus-newsgroup-unselected))))
9021       (setq gnus-newsgroup-headers
9022             (gnus-delete-duplicate-headers
9023              (gnus-merge
9024               'list gnus-newsgroup-headers new-headers
9025               'gnus-article-sort-by-number)))
9026       (setq gnus-newsgroup-articles
9027             (gnus-sorted-nunion gnus-newsgroup-articles (nreverse article-ids)))
9028       (gnus-summary-limit-include-thread id)))
9029   (gnus-summary-show-thread))
9030
9031 (defun gnus-summary-refer-article (message-id)
9032   "Fetch an article specified by MESSAGE-ID."
9033   (interactive "sMessage-ID: ")
9034   (gnus-warp-to-article)
9035   (when (and (stringp message-id)
9036              (not (zerop (length message-id))))
9037     (setq message-id (gnus-replace-in-string message-id " " ""))
9038     ;; Construct the correct Message-ID if necessary.
9039     ;; Suggested by tale@pawl.rpi.edu.
9040     (unless (string-match "^<" message-id)
9041       (setq message-id (concat "<" message-id)))
9042     (unless (string-match ">$" message-id)
9043       (setq message-id (concat message-id ">")))
9044     ;; People often post MIDs from URLs, so unhex it:
9045     (unless (string-match "@" message-id)
9046       (setq message-id (gnus-url-unhex-string message-id)))
9047     (let* ((header (gnus-id-to-header message-id))
9048            (sparse (and header
9049                         (gnus-summary-article-sparse-p
9050                          (mail-header-number header))
9051                         (memq (mail-header-number header)
9052                               gnus-newsgroup-limit)))
9053            number)
9054       (cond
9055        ;; If the article is present in the buffer we just go to it.
9056        ((and header
9057              (or (not (gnus-summary-article-sparse-p
9058                        (mail-header-number header)))
9059                  sparse))
9060         (prog1
9061             (gnus-summary-goto-article
9062              (mail-header-number header) nil t)
9063           (when sparse
9064             (gnus-summary-update-article (mail-header-number header)))))
9065        (t
9066         ;; We fetch the article.
9067         (catch 'found
9068           (dolist (gnus-override-method (gnus-refer-article-methods))
9069             (when (and (gnus-check-server gnus-override-method)
9070                        ;; Fetch the header,
9071                        (setq number (gnus-summary-insert-subject message-id)))
9072               ;; and display the article.
9073               (gnus-summary-select-article nil nil nil number)
9074               (throw 'found t)))
9075           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
9076
9077 (defun gnus-refer-article-methods ()
9078   "Return a list of referable methods."
9079   (cond
9080    ;; No method, so we default to current and native.
9081    ((null gnus-refer-article-method)
9082     (list gnus-current-select-method gnus-select-method))
9083    ;; Current.
9084    ((eq 'current gnus-refer-article-method)
9085     (list gnus-current-select-method))
9086    ;; List of select methods.
9087    ((not (and (symbolp (car gnus-refer-article-method))
9088               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
9089     (let (out)
9090       (dolist (method gnus-refer-article-method)
9091         (push (if (eq 'current method)
9092                   gnus-current-select-method
9093                 (if (eq 'nnir (car method))
9094                     (list
9095                      'nnir
9096                      (or (cadr method)
9097                          (gnus-method-to-server gnus-current-select-method)))
9098                   method))
9099               out))
9100       (nreverse out)))
9101    ;; One single select method.
9102    (t
9103     (list gnus-refer-article-method))))
9104
9105 (defun gnus-summary-edit-parameters ()
9106   "Edit the group parameters of the current group."
9107   (interactive)
9108   (gnus-group-edit-group gnus-newsgroup-name 'params))
9109
9110 (defun gnus-summary-customize-parameters ()
9111   "Customize the group parameters of the current group."
9112   (interactive)
9113   (gnus-group-customize gnus-newsgroup-name))
9114
9115 (defun gnus-summary-enter-digest-group (&optional force)
9116   "Enter an nndoc group based on the current article.
9117 If FORCE, force a digest interpretation.  If not, try to guess
9118 what the document format is.
9119
9120 To control what happens when you exit the group, see the
9121 `gnus-auto-select-on-ephemeral-exit' variable."
9122   (interactive "P")
9123   (let ((conf gnus-current-window-configuration))
9124     (save-window-excursion
9125       (save-excursion
9126         (let (gnus-article-prepare-hook
9127               gnus-display-mime-function
9128               gnus-break-pages)
9129           (gnus-summary-select-article))))
9130     (setq gnus-current-window-configuration conf)
9131     (let* ((name (format "%s-%d"
9132                          (gnus-group-prefixed-name
9133                           gnus-newsgroup-name (list 'nndoc ""))
9134                          (with-current-buffer gnus-summary-buffer
9135                            gnus-current-article)))
9136            (ogroup gnus-newsgroup-name)
9137            (params (append (gnus-info-params (gnus-get-info ogroup))
9138                            (list (cons 'to-group ogroup))
9139                            (list (cons 'parent-group ogroup))
9140                            (list (cons 'save-article-group ogroup))))
9141            (case-fold-search t)
9142            (buf (current-buffer))
9143            dig to-address charset)
9144       (with-current-buffer gnus-original-article-buffer
9145         ;; Have the digest group inherit the main mail address of
9146         ;; the parent article.
9147         (when (setq to-address (or (gnus-fetch-field "reply-to")
9148                                    (gnus-fetch-field "from")))
9149           (setq params
9150                 (append
9151                  (list (cons 'to-address
9152                              (funcall gnus-decode-encoded-address-function
9153                                       to-address))))))
9154         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
9155         (insert-buffer-substring gnus-original-article-buffer)
9156         (narrow-to-region
9157          (goto-char (point-min))
9158          (or (search-forward "\n\n" nil t) (point)))
9159         ;; Remove lines that may lead nndoc to misinterpret the
9160         ;; document type.
9161         (goto-char (point-min))
9162         (delete-matching-lines "^Path:\\|^From ")
9163         ;; Parse charset, and decode content transfer encoding.
9164         (setq charset (mail-content-type-get
9165                        (mail-header-parse-content-type
9166                         (or (gnus-fetch-field "content-type") ""))
9167                        'charset))
9168         (let ((encoding (gnus-fetch-field "content-transfer-encoding")))
9169           (when encoding
9170             (message-remove-header "content-transfer-encoding")
9171             (goto-char (point-max))
9172             (widen)
9173             (narrow-to-region (point) (point-max))
9174             (mm-decode-content-transfer-encoding
9175              (intern (downcase (mail-header-strip encoding))))))
9176         (widen))
9177       (unwind-protect
9178           (if (let ((gnus-newsgroup-ephemeral-charset
9179                      (if charset
9180                          (intern (downcase (gnus-strip-whitespace charset)))
9181                        gnus-newsgroup-charset))
9182                     (gnus-newsgroup-ephemeral-ignored-charsets
9183                      gnus-newsgroup-ignored-charsets))
9184                 (gnus-group-read-ephemeral-group
9185                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
9186                               (nndoc-article-type
9187                                ,(if force 'mbox 'guess)))
9188                  t nil nil nil
9189                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
9190                                                         "ADAPT")))))
9191               ;; Make all postings to this group go to the parent group.
9192               (nconc (gnus-info-params (gnus-get-info name))
9193                      params)
9194             ;; Couldn't select this doc group.
9195             (switch-to-buffer buf)
9196             (gnus-set-global-variables)
9197             (gnus-configure-windows 'summary)
9198             (gnus-message 3 "Article couldn't be entered?"))
9199         (kill-buffer dig)))))
9200
9201 (defun gnus-summary-read-document (n)
9202   "Open a new group based on the current article(s).
9203 This will allow you to read digests and other similar
9204 documents as newsgroups.
9205 Obeys the standard process/prefix convention."
9206   (interactive "P")
9207   (let* ((ogroup gnus-newsgroup-name)
9208          (params (append (gnus-info-params (gnus-get-info ogroup))
9209                          (list (cons 'to-group ogroup))))
9210          group egroup groups vgroup)
9211     (dolist (article (gnus-summary-work-articles n))
9212       (setq group (format "%s-%d" gnus-newsgroup-name article))
9213       (gnus-summary-remove-process-mark article)
9214       (when (gnus-summary-display-article article)
9215         (save-excursion ;;What for?
9216           (with-temp-buffer
9217             (insert-buffer-substring gnus-original-article-buffer)
9218             ;; Remove some headers that may lead nndoc to make
9219             ;; the wrong guess.
9220             (message-narrow-to-head)
9221             (goto-char (point-min))
9222             (delete-matching-lines "^Path:\\|^From ")
9223             (widen)
9224             (if (setq egroup
9225                       (gnus-group-read-ephemeral-group
9226                        group `(nndoc ,group (nndoc-address ,(current-buffer))
9227                                      (nndoc-article-type guess))
9228                        t nil t))
9229                 (progn
9230                   ;; Make all postings to this group go to the parent group.
9231                   (nconc (gnus-info-params (gnus-get-info egroup))
9232                          params)
9233                   (push egroup groups))
9234               ;; Couldn't select this doc group.
9235               (gnus-error 3 "Article couldn't be entered"))))))
9236     ;; Now we have selected all the documents.
9237     (cond
9238      ((not groups)
9239       (error "None of the articles could be interpreted as documents"))
9240      ((gnus-group-read-ephemeral-group
9241        (setq vgroup (format
9242                      "nnvirtual:%s-%s" gnus-newsgroup-name
9243                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
9244        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
9245        t
9246        (cons (current-buffer) 'summary)))
9247      (t
9248       (error "Couldn't select virtual nndoc group")))))
9249
9250 (defun gnus-summary-widget-forward (arg)
9251   "Move point to the next field or button in the article.
9252 With optional ARG, move across that many fields."
9253   (interactive "p")
9254   (gnus-summary-select-article)
9255   (gnus-configure-windows 'article)
9256   (select-window (gnus-get-buffer-window gnus-article-buffer))
9257   (widget-forward arg))
9258
9259 (defun gnus-summary-widget-backward (arg)
9260   "Move point to the previous field or button in the article.
9261 With optional ARG, move across that many fields."
9262   (interactive "p")
9263   (gnus-summary-select-article)
9264   (gnus-configure-windows 'article)
9265   (select-window (gnus-get-buffer-window gnus-article-buffer))
9266   (unless (widget-at (point))
9267     (goto-char (point-max)))
9268   (widget-backward arg))
9269
9270 (defun gnus-summary-isearch-article (&optional regexp-p)
9271   "Do incremental search forward on the current article.
9272 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
9273   (interactive "P")
9274   (gnus-summary-select-article)
9275   (gnus-configure-windows 'article)
9276   (gnus-eval-in-buffer-window gnus-article-buffer
9277     (save-restriction
9278       (widen)
9279       (isearch-forward regexp-p))))
9280
9281 (defun gnus-summary-repeat-search-article-forward ()
9282   "Repeat the previous search forwards."
9283   (interactive)
9284   (unless gnus-last-search-regexp
9285     (error "No previous search"))
9286   (gnus-summary-search-article-forward gnus-last-search-regexp))
9287
9288 (defun gnus-summary-repeat-search-article-backward ()
9289   "Repeat the previous search backwards."
9290   (interactive)
9291   (unless gnus-last-search-regexp
9292     (error "No previous search"))
9293   (gnus-summary-search-article-forward gnus-last-search-regexp t))
9294
9295 (defun gnus-summary-search-article-forward (regexp &optional backward)
9296   "Search for an article containing REGEXP forward.
9297 If BACKWARD, search backward instead."
9298   (interactive
9299    (list (read-string
9300           (format "Search article %s (regexp%s): "
9301                   (if current-prefix-arg "backward" "forward")
9302                   (if gnus-last-search-regexp
9303                       (concat ", default " gnus-last-search-regexp)
9304                     "")))
9305          current-prefix-arg))
9306   (if (string-equal regexp "")
9307       (setq regexp (or gnus-last-search-regexp ""))
9308     (setq gnus-last-search-regexp regexp)
9309     (setq gnus-article-before-search gnus-current-article))
9310   ;; Intentionally set gnus-last-article.
9311   (setq gnus-last-article gnus-article-before-search)
9312   (let ((gnus-last-article gnus-last-article))
9313     (if (gnus-summary-search-article regexp backward)
9314         (gnus-summary-show-thread)
9315       (signal 'search-failed (list regexp)))))
9316
9317 (defun gnus-summary-search-article-backward (regexp)
9318   "Search for an article containing REGEXP backward."
9319   (interactive
9320    (list (read-string
9321           (format "Search article backward (regexp%s): "
9322                   (if gnus-last-search-regexp
9323                       (concat ", default " gnus-last-search-regexp)
9324                     "")))))
9325   (gnus-summary-search-article-forward regexp 'backward))
9326
9327 (defun gnus-summary-search-article (regexp &optional backward)
9328   "Search for an article containing REGEXP.
9329 Optional argument BACKWARD means do search for backward.
9330 `gnus-select-article-hook' is not called during the search."
9331   ;; We have to require this here to make sure that the following
9332   ;; dynamic binding isn't shadowed by autoloading.
9333   (require 'gnus-async)
9334   (require 'gnus-art)
9335   (let ((gnus-select-article-hook nil)  ;Disable hook.
9336         (gnus-article-prepare-hook nil)
9337         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9338         (gnus-use-article-prefetch nil)
9339         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9340         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9341         (gnus-visual nil)
9342         (gnus-keep-backlog nil)
9343         (gnus-break-pages nil)
9344         (gnus-summary-display-arrow nil)
9345         (gnus-updated-mode-lines nil)
9346         (gnus-auto-center-summary nil)
9347         (sum (current-buffer))
9348         (gnus-display-mime-function nil)
9349         (found nil)
9350         point)
9351     (gnus-save-hidden-threads
9352       (gnus-summary-select-article)
9353       (set-buffer gnus-article-buffer)
9354       (goto-char (window-point (get-buffer-window (current-buffer))))
9355       (when backward
9356         (forward-line -1))
9357       (while (not found)
9358         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9359         (if (if backward
9360                 (re-search-backward regexp nil t)
9361               (re-search-forward regexp nil t))
9362             ;; We found the regexp.
9363             (progn
9364               (setq found 'found)
9365               (beginning-of-line)
9366               (set-window-start
9367                (get-buffer-window (current-buffer))
9368                (point))
9369               (forward-line 1)
9370               (set-window-point
9371                (get-buffer-window (current-buffer))
9372                (point))
9373               (set-buffer sum)
9374               (setq point (point)))
9375           ;; We didn't find it, so we go to the next article.
9376           (set-buffer sum)
9377           (setq found 'not)
9378           (while (eq found 'not)
9379             (if (not (if backward (gnus-summary-find-prev)
9380                        (gnus-summary-find-next)))
9381                 ;; No more articles.
9382                 (setq found t)
9383               ;; Select the next article and adjust point.
9384               (unless (gnus-summary-article-sparse-p
9385                        (gnus-summary-article-number))
9386                 (setq found nil)
9387                 (gnus-summary-select-article)
9388                 (set-buffer gnus-article-buffer)
9389                 (widen)
9390                 (goto-char (if backward (point-max) (point-min))))))))
9391       (gnus-message 7 ""))
9392     ;; Return whether we found the regexp.
9393     (when (eq found 'found)
9394       (goto-char point)
9395       (gnus-summary-show-thread)
9396       (gnus-summary-goto-subject gnus-current-article)
9397       (gnus-summary-position-point)
9398       t)))
9399
9400 (defun gnus-find-matching-articles (header regexp)
9401   "Return a list of all articles that match REGEXP on HEADER.
9402 This search includes all articles in the current group that Gnus has
9403 fetched headers for, whether they are displayed or not."
9404   (let ((articles nil)
9405         ;; Can't eta-reduce because it's a macro.
9406         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9407         (case-fold-search t))
9408     (dolist (header gnus-newsgroup-headers)
9409       (when (string-match regexp (funcall func header))
9410         (push (mail-header-number header) articles)))
9411     (nreverse articles)))
9412
9413 (defun gnus-summary-find-matching (header regexp &optional backward unread
9414                                           not-case-fold not-matching)
9415   "Return a list of all articles that match REGEXP on HEADER.
9416 The search stars on the current article and goes forwards unless
9417 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9418 If UNREAD is non-nil, only unread articles will
9419 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9420 in the comparisons. If NOT-MATCHING, return a list of all articles that
9421 not match REGEXP on HEADER."
9422   (let ((case-fold-search (not not-case-fold))
9423         articles d func)
9424     (if (consp header)
9425         (if (eq (car header) 'extra)
9426             (setq func
9427                   `(lambda (h)
9428                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9429                          "")))
9430           (error "%s is an invalid header" header))
9431       (unless (fboundp (intern (concat "mail-header-" header)))
9432         (error "%s is not a valid header" header))
9433       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9434     (dolist (d (if (eq backward 'all)
9435                    gnus-newsgroup-data
9436                  (gnus-data-find-list
9437                   (gnus-summary-article-number)
9438                   (gnus-data-list backward))))
9439       (when (and (or (not unread)       ; We want all articles...
9440                      (gnus-data-unread-p d)) ; Or just unreads.
9441                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9442                  (if not-matching
9443                      (not (string-match
9444                            regexp
9445                            (funcall func (gnus-data-header d))))
9446                    (string-match regexp
9447                                  (funcall func (gnus-data-header d)))))
9448         (push (gnus-data-number d) articles))) ; Success!
9449     (nreverse articles)))
9450
9451 (defun gnus-summary-execute-command (header regexp command &optional backward)
9452   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9453 If HEADER is an empty string (or nil), the match is done on the entire
9454 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9455   (interactive
9456    (list (let ((completion-ignore-case t))
9457            (gnus-completing-read
9458             "Header name"
9459             (mapcar 'symbol-name
9460                     (append
9461                      '(Number Subject From Lines Date
9462                        Message-ID Xref References Body)
9463                      gnus-extra-headers))
9464             'require-match))
9465          (read-string "Regexp: ")
9466          (read-key-sequence "Command: ")
9467          current-prefix-arg))
9468   (when (equal header "Body")
9469     (setq header ""))
9470   ;; Hidden thread subtrees must be searched as well.
9471   (gnus-summary-show-all-threads)
9472   ;; We don't want to change current point nor window configuration.
9473   (save-excursion
9474     (save-window-excursion
9475       (let (gnus-visual
9476             gnus-treat-strip-trailing-blank-lines
9477             gnus-treat-strip-leading-blank-lines
9478             gnus-treat-strip-multiple-blank-lines
9479             gnus-treat-hide-boring-headers
9480             gnus-treat-fold-newsgroups
9481             gnus-article-prepare-hook)
9482         (gnus-message 6 "Executing %s..." (key-description command))
9483         ;; We'd like to execute COMMAND interactively so as to give arguments.
9484         (gnus-execute header regexp
9485                       `(call-interactively ',(key-binding command))
9486                       backward)
9487         (gnus-message 6 "Executing %s...done" (key-description command))))))
9488
9489 (defun gnus-summary-beginning-of-article ()
9490   "Scroll the article back to the beginning."
9491   (interactive)
9492   (gnus-summary-select-article)
9493   (gnus-configure-windows 'article)
9494   (gnus-eval-in-buffer-window gnus-article-buffer
9495     (widen)
9496     (goto-char (point-min))
9497     (when gnus-break-pages
9498       (gnus-narrow-to-page))))
9499
9500 (defun gnus-summary-end-of-article ()
9501   "Scroll to the end of the article."
9502   (interactive)
9503   (gnus-summary-select-article)
9504   (gnus-configure-windows 'article)
9505   (gnus-eval-in-buffer-window gnus-article-buffer
9506     (widen)
9507     (goto-char (point-max))
9508     (recenter -3)
9509     (when gnus-break-pages
9510       (gnus-narrow-to-page))))
9511
9512 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9513   "Truncate to LEN and quote all \"(\"'s in STRING."
9514   (gnus-replace-in-string (if (and len (> (length string) len))
9515                               (substring string 0 len)
9516                             string)
9517                           "[()]" "\\\\\\&"))
9518
9519 (defun gnus-summary-print-article (&optional filename n)
9520   "Generate and print a PostScript image of the process-marked (mail) articles.
9521
9522 If used interactively, print the current article if none are
9523 process-marked.  With prefix arg, prompt the user for the name of the
9524 file to save in.
9525
9526 When used from Lisp, accept two optional args FILENAME and N.  N means
9527 to print the next N articles.  If N is negative, print the N previous
9528 articles.  If N is nil and articles have been marked with the process
9529 mark, print these instead.
9530
9531 If the optional first argument FILENAME is nil, send the image to the
9532 printer.  If FILENAME is a string, save the PostScript image in a file with
9533 that name.  If FILENAME is a number, prompt the user for the name of the file
9534 to save in."
9535   (interactive (list (ps-print-preprint current-prefix-arg)))
9536   (dolist (article (gnus-summary-work-articles n))
9537     (gnus-summary-select-article nil nil 'pseudo article)
9538     (gnus-eval-in-buffer-window gnus-article-buffer
9539       (gnus-print-buffer))
9540     (gnus-summary-remove-process-mark article))
9541   (ps-despool filename))
9542
9543 (defun gnus-print-buffer ()
9544   (let ((ps-left-header
9545          (list
9546           (concat "("
9547                   (gnus-summary-print-truncate-and-quote
9548                    (mail-header-subject gnus-current-headers)
9549                    66) ")")
9550           (concat "("
9551                   (gnus-summary-print-truncate-and-quote
9552                    (mail-header-from gnus-current-headers)
9553                    45) ")")))
9554         (ps-right-header
9555          (list
9556           "/pagenumberstring load"
9557           (concat "("
9558                   (mail-header-date gnus-current-headers) ")"))))
9559     (gnus-run-hooks 'gnus-ps-print-hook)
9560     (save-excursion
9561       (if ps-print-color-p
9562           (ps-spool-buffer-with-faces)
9563         (ps-spool-buffer)))))
9564
9565 (defun gnus-summary-show-complete-article ()
9566   "Show a complete version of the current article.
9567 This is only useful if you're looking at a partial version of the
9568 article currently."
9569   (interactive)
9570   (let ((gnus-keep-backlog nil)
9571         (gnus-use-cache nil)
9572         (gnus-agent nil)
9573         (variable (intern
9574                    (format "%s-fetch-partial-articles"
9575                            (car (gnus-find-method-for-group
9576                                  gnus-newsgroup-name)))
9577                    obarray))
9578         old-val)
9579     (unwind-protect
9580         (progn
9581           (setq old-val (symbol-value variable))
9582           (set variable nil)
9583           (gnus-flush-original-article-buffer)
9584           (gnus-summary-show-article))
9585       (set variable old-val))))
9586
9587 (defun gnus-summary-show-article (&optional arg)
9588   "Force redisplaying of the current article.
9589 If ARG (the prefix) is a number, show the article with the charset
9590 defined in `gnus-summary-show-article-charset-alist', or the charset
9591 input.
9592 If ARG (the prefix) is non-nil and not a number, show the article,
9593 but without running any of the article treatment functions
9594 article.  Normally, the keystroke is `C-u g'.  When using `C-u
9595 C-u g', show the raw article."
9596   (interactive "P")
9597   (cond
9598    ((numberp arg)
9599     (gnus-summary-show-article t)
9600     (let ((gnus-newsgroup-charset
9601            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9602                (mm-read-coding-system
9603                 "View as charset: " ;; actually it is coding system.
9604                 (with-current-buffer gnus-article-buffer
9605                   (mm-detect-coding-region (point) (point-max))))))
9606           (gnus-newsgroup-ignored-charsets 'gnus-all))
9607       (gnus-summary-select-article nil 'force)
9608       (let ((deps gnus-newsgroup-dependencies)
9609             head header lines)
9610         (with-current-buffer gnus-original-article-buffer
9611           (save-restriction
9612             (message-narrow-to-head)
9613             (setq head (buffer-string))
9614             (goto-char (point-min))
9615             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9616               (goto-char (point-max))
9617               (widen)
9618               (setq lines (1- (count-lines (point) (point-max))))))
9619           (with-temp-buffer
9620             (insert (format "211 %d Article retrieved.\n"
9621                             (cdr gnus-article-current)))
9622             (insert head)
9623             (if lines (insert (format "Lines: %d\n" lines)))
9624             (insert ".\n")
9625             (let ((nntp-server-buffer (current-buffer)))
9626               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9627         (gnus-data-set-header
9628          (gnus-data-find (cdr gnus-article-current))
9629          header)
9630         (gnus-summary-update-article-line
9631          (cdr gnus-article-current) header)
9632         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9633           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9634    ((not arg)
9635     ;; Select the article the normal way.
9636     (if (eq mm-text-html-renderer 'shr)
9637         (progn
9638           (require 'shr)
9639           (let ((shr-ignore-cache t))
9640             (gnus-summary-select-article nil 'force)))
9641       (gnus-summary-select-article nil 'force)))
9642    ((equal arg '(16))
9643     ;; C-u C-u g
9644     (let ((gnus-inhibit-article-treatments t))
9645       (gnus-summary-select-article nil 'force)))
9646    (t
9647     ;; We have to require this here to make sure that the following
9648     ;; dynamic binding isn't shadowed by autoloading.
9649     (require 'gnus-async)
9650     (require 'gnus-art)
9651     ;; Bind the article treatment functions to nil.
9652     (let ((gnus-have-all-headers t)
9653           gnus-article-prepare-hook
9654           gnus-article-decode-hook
9655           gnus-display-mime-function
9656           gnus-break-pages)
9657       ;; Destroy any MIME parts.
9658       (when (gnus-buffer-live-p gnus-article-buffer)
9659         (with-current-buffer gnus-article-buffer
9660           (gnus-article-stop-animations)
9661           (gnus-stop-downloads)
9662           (mm-destroy-parts gnus-article-mime-handles)
9663           ;; Set it to nil for safety reason.
9664           (setq gnus-article-mime-handle-alist nil)
9665           (setq gnus-article-mime-handles nil)))
9666       (gnus-summary-select-article nil 'force))))
9667   (gnus-summary-goto-subject gnus-current-article)
9668   (gnus-summary-position-point))
9669
9670 (defun gnus-summary-show-raw-article ()
9671   "Show the raw article without any article massaging functions being run."
9672   (interactive)
9673   (gnus-summary-show-article t))
9674
9675 (defun gnus-summary-verbose-headers (&optional arg)
9676   "Toggle permanent full header display.
9677 If ARG is a positive number, turn header display on.
9678 If ARG is a negative number, turn header display off."
9679   (interactive "P")
9680   (setq gnus-show-all-headers
9681         (cond ((or (not (numberp arg))
9682                    (zerop arg))
9683                (not gnus-show-all-headers))
9684               ((natnump arg)
9685                t)))
9686   (gnus-summary-show-article))
9687
9688 (defun gnus-summary-toggle-header (&optional arg)
9689   "Show the headers if they are hidden, or hide them if they are shown.
9690 If ARG is a positive number, show the entire header.
9691 If ARG is a negative number, hide the unwanted header lines."
9692   (interactive "P")
9693   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9694                      (get-buffer-window gnus-article-buffer t))))
9695     (with-current-buffer gnus-article-buffer
9696       (widen)
9697       (article-narrow-to-head)
9698       (let* ((inhibit-read-only t)
9699              (inhibit-point-motion-hooks t)
9700              (hidden (if (numberp arg)
9701                          (>= arg 0)
9702                        (or (not (looking-at "[^ \t\n]+:"))
9703                            (gnus-article-hidden-text-p 'headers))))
9704              s e)
9705         (delete-region (point-min) (point-max))
9706         (with-current-buffer gnus-original-article-buffer
9707           (goto-char (setq s (point-min)))
9708           (setq e (if (search-forward "\n\n" nil t)
9709                       (1- (point))
9710                     (point-max))))
9711         (insert-buffer-substring gnus-original-article-buffer s e)
9712         (run-hooks 'gnus-article-decode-hook)
9713         (if hidden
9714             (let ((gnus-treat-hide-headers nil)
9715                   (gnus-treat-hide-boring-headers nil))
9716               (gnus-delete-wash-type 'headers)
9717               (gnus-treat-article 'head))
9718           (gnus-treat-article 'head))
9719         (widen)
9720         (if window
9721             (set-window-start window (goto-char (point-min))))
9722         (if gnus-break-pages
9723             (gnus-narrow-to-page)
9724           (when (gnus-visual-p 'page-marker)
9725             (let ((inhibit-read-only t))
9726               (gnus-remove-text-with-property 'gnus-prev)
9727               (gnus-remove-text-with-property 'gnus-next))))
9728         (gnus-set-mode-line 'article)))))
9729
9730 (defun gnus-summary-show-all-headers ()
9731   "Make all header lines visible."
9732   (interactive)
9733   (gnus-summary-toggle-header 1))
9734
9735 (defun gnus-summary-caesar-message (&optional arg)
9736   "Caesar rotate the current article by 13.
9737 With a non-numerical prefix, also rotate headers.  A numerical
9738 prefix specifies how many places to rotate each letter forward."
9739   (interactive "P")
9740   (gnus-summary-select-article)
9741   (let ((mail-header-separator ""))
9742     (gnus-eval-in-buffer-window gnus-article-buffer
9743       (save-restriction
9744         (widen)
9745         (let ((start (window-start))
9746               (inhibit-read-only t))
9747           (if (equal arg '(4))
9748               (message-caesar-buffer-body nil t)
9749             (message-caesar-buffer-body arg))
9750           (set-window-start (get-buffer-window (current-buffer)) start)))))
9751   ;; Create buttons and stuff...
9752   (gnus-treat-article nil))
9753
9754 (declare-function idna-to-unicode "ext:idna" (str))
9755
9756 (defun gnus-summary-idna-message (&optional arg)
9757   "Decode IDNA encoded domain names in the current articles.
9758 IDNA encoded domain names looks like `xn--bar'.  If a string
9759 remain unencoded after running this function, it is likely an
9760 invalid IDNA string (`xn--bar' is invalid).
9761
9762 You must have GNU Libidn (URL `http://www.gnu.org/software/libidn/')
9763 installed for this command to work."
9764   (interactive "P")
9765   (if (not (and (condition-case nil (require 'idna)
9766                   (file-error))
9767                 (mm-coding-system-p 'utf-8)
9768                 (executable-find (symbol-value 'idna-program))))
9769       (gnus-message
9770        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9771     (gnus-summary-select-article)
9772     (let ((mail-header-separator ""))
9773       (gnus-eval-in-buffer-window gnus-article-buffer
9774         (save-restriction
9775           (widen)
9776           (let ((start (window-start))
9777                 buffer-read-only)
9778             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9779               (replace-match (idna-to-unicode (match-string 1))))
9780             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9781
9782 (defun gnus-summary-morse-message (&optional arg)
9783   "Morse decode the current article."
9784   (interactive "P")
9785   (gnus-summary-select-article)
9786   (let ((mail-header-separator ""))
9787     (gnus-eval-in-buffer-window gnus-article-buffer
9788       (save-excursion
9789         (save-restriction
9790           (widen)
9791           (let ((pos (window-start))
9792                 (inhibit-read-only t))
9793             (goto-char (point-min))
9794             (when (message-goto-body)
9795               (gnus-narrow-to-body))
9796             (goto-char (point-min))
9797             (while (search-forward "·" (point-max) t)
9798               (replace-match "."))
9799             (unmorse-region (point-min) (point-max))
9800             (widen)
9801             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9802
9803 (defun gnus-summary-stop-page-breaking ()
9804   "Stop page breaking in the current article."
9805   (interactive)
9806   (gnus-summary-select-article)
9807   (gnus-eval-in-buffer-window gnus-article-buffer
9808     (widen)
9809     (when (gnus-visual-p 'page-marker)
9810       (let ((inhibit-read-only t))
9811         (gnus-remove-text-with-property 'gnus-prev)
9812         (gnus-remove-text-with-property 'gnus-next))
9813       (setq gnus-page-broken nil))))
9814
9815 (defun gnus-summary-move-article (&optional n to-newsgroup
9816                                             select-method action)
9817   "Move the current article to a different newsgroup.
9818 If N is a positive number, move the N next articles.
9819 If N is a negative number, move the N previous articles.
9820 If N is nil and any articles have been marked with the process mark,
9821 move those articles instead.
9822 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9823 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9824 re-spool using this method.
9825
9826 When called interactively with TO-NEWSGROUP being nil, the value of
9827 the variable `gnus-move-split-methods' is used for finding a default
9828 for the target newsgroup.
9829
9830 For this function to work, both the current newsgroup and the
9831 newsgroup that you want to move to have to support the `request-move'
9832 and `request-accept' functions.
9833
9834 ACTION can be either `move' (the default), `crosspost' or `copy'."
9835   (interactive "P")
9836   (unless action
9837     (setq action 'move))
9838   ;; Check whether the source group supports the required functions.
9839   (cond ((and (eq action 'move)
9840               (not (gnus-check-backend-function
9841                     'request-move-article gnus-newsgroup-name)))
9842          (error "The current group does not support article moving"))
9843         ((and (eq action 'crosspost)
9844               (not (gnus-check-backend-function
9845                     'request-replace-article gnus-newsgroup-name)))
9846          (error "The current group does not support article editing")))
9847   (let ((articles (gnus-summary-work-articles n))
9848         (prefix (if (gnus-check-backend-function
9849                      'request-move-article gnus-newsgroup-name)
9850                     (funcall gnus-move-group-prefix-function
9851                              gnus-newsgroup-name)
9852                   ""))
9853         (names '((move "Move" "Moving")
9854                  (copy "Copy" "Copying")
9855                  (crosspost "Crosspost" "Crossposting")))
9856         (copy-buf (save-excursion
9857                     (nnheader-set-temp-buffer " *copy article*")))
9858         art-group to-method new-xref article to-groups
9859         articles-to-update-marks encoded)
9860     (unless (assq action names)
9861       (error "Unknown action %s" action))
9862     ;; Read the newsgroup name.
9863     (when (and (not to-newsgroup)
9864                (not select-method))
9865       (if (and gnus-move-split-methods
9866                (not
9867                 (and (memq gnus-current-article articles)
9868                      (gnus-buffer-live-p gnus-original-article-buffer))))
9869           ;; When `gnus-move-split-methods' is non-nil, we have to
9870           ;; select an article to give `gnus-read-move-group-name' an
9871           ;; opportunity to suggest an appropriate default.  However,
9872           ;; we needn't render or mark the article.
9873           (let ((gnus-display-mime-function nil)
9874                 (gnus-article-prepare-hook nil)
9875                 (gnus-mark-article-hook nil))
9876             (gnus-summary-select-article nil nil nil (car articles))))
9877       (setq to-newsgroup (gnus-read-move-group-name
9878                           (cadr (assq action names))
9879                           (symbol-value
9880                            (intern (format "gnus-current-%s-group" action)))
9881                           articles prefix)
9882             encoded to-newsgroup
9883             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9884       (set (intern (format "gnus-current-%s-group" action))
9885            (mm-decode-coding-string
9886             to-newsgroup
9887             (gnus-group-name-charset to-method to-newsgroup))))
9888     (unless to-method
9889       (setq to-method (or select-method
9890                           (gnus-server-to-method
9891                            (gnus-group-method to-newsgroup)))))
9892     (setq to-newsgroup
9893           (or encoded
9894               (and to-newsgroup
9895                    (mm-encode-coding-string
9896                     to-newsgroup
9897                     (gnus-group-name-charset to-method to-newsgroup)))))
9898     ;; Check the method we are to move this article to...
9899     (unless (gnus-check-backend-function
9900              'request-accept-article (car to-method))
9901       (error "%s does not support article copying" (car to-method)))
9902     (unless (gnus-check-server to-method)
9903       (error "Can't open server %s" (car to-method)))
9904     (gnus-message 6 "%s to %s: %s..."
9905                   (caddr (assq action names))
9906                   (or (car select-method)
9907                       (gnus-group-decoded-name to-newsgroup))
9908                   articles)
9909     (while articles
9910       (setq article (pop articles))
9911       ;; Set any marks that may have changed in the summary buffer.
9912       (when gnus-preserve-marks
9913         (gnus-summary-push-marks-to-backend article))
9914       (setq
9915        art-group
9916        (cond
9917         ;; Move the article.
9918         ((eq action 'move)
9919          ;; Remove this article from future suppression.
9920          (gnus-dup-unsuppress-article article)
9921          (let* ((from-method (gnus-find-method-for-group
9922                               gnus-newsgroup-name))
9923                 (to-method (or select-method
9924                                (gnus-find-method-for-group to-newsgroup)))
9925                 (move-is-internal (gnus-server-equal from-method to-method)))
9926            (gnus-request-move-article
9927             article                     ; Article to move
9928             gnus-newsgroup-name         ; From newsgroup
9929             (nth 1 (gnus-find-method-for-group
9930                     gnus-newsgroup-name)) ; Server
9931             (list 'gnus-request-accept-article
9932                   to-newsgroup (list 'quote select-method)
9933                   (not articles) t)     ; Accept form
9934             (not articles)              ; Only save nov last time
9935             (and move-is-internal
9936                  to-newsgroup           ; Not respooling
9937                                         ; Is this move internal?
9938                  (gnus-group-real-name to-newsgroup)))))
9939         ;; Copy the article.
9940         ((eq action 'copy)
9941          (with-current-buffer copy-buf
9942            (when (gnus-request-article-this-buffer article
9943                                                    gnus-newsgroup-name)
9944              (save-restriction
9945                (nnheader-narrow-to-headers)
9946                (dolist (hdr gnus-copy-article-ignored-headers)
9947                  (message-remove-header hdr t)))
9948              (gnus-request-accept-article
9949               to-newsgroup select-method (not articles) t))))
9950         ;; Crosspost the article.
9951         ((eq action 'crosspost)
9952          (let ((xref (message-tokenize-header
9953                       (mail-header-xref (gnus-summary-article-header
9954                                          article))
9955                       " ")))
9956            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9957                                   ":" (number-to-string article)))
9958            (unless xref
9959              (setq xref (list (system-name))))
9960            (setq new-xref
9961                  (concat
9962                   (mapconcat 'identity
9963                              (delete "Xref:" (delete new-xref xref))
9964                              " ")
9965                   " " new-xref))
9966            (with-current-buffer copy-buf
9967              ;; First put the article in the destination group.
9968              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9969              (when (consp (setq art-group
9970                                 (gnus-request-accept-article
9971                                  to-newsgroup select-method (not articles)
9972                                  t)))
9973                (setq new-xref (concat new-xref " " (car art-group)
9974                                       ":"
9975                                       (number-to-string (cdr art-group))))
9976                ;; Now we have the new Xrefs header, so we insert
9977                ;; it and replace the new article.
9978                (nnheader-replace-header "Xref" new-xref)
9979                (gnus-request-replace-article
9980                 (cdr art-group) to-newsgroup (current-buffer) t)
9981                art-group))))))
9982       (cond
9983        ((not art-group)
9984         (gnus-message 1 "Couldn't %s article %s: %s"
9985                       (cadr (assq action names)) article
9986                       (nnheader-get-report (car to-method))))
9987        ((eq art-group 'junk)
9988         (when (eq action 'move)
9989           (gnus-summary-mark-article article gnus-canceled-mark)
9990           (gnus-message 4 "Deleted article %s" article)
9991           ;; run the delete hook
9992           (run-hook-with-args 'gnus-summary-article-delete-hook
9993                               action
9994                               (gnus-data-header
9995                                (assoc article (gnus-data-list nil)))
9996                               gnus-newsgroup-name nil
9997                               select-method)))
9998        (t
9999         (let* ((pto-group (gnus-group-prefixed-name
10000                            (car art-group) to-method))
10001                (info (gnus-get-info pto-group))
10002                (to-group (gnus-info-group info))
10003                to-marks)
10004           ;; Update the group that has been moved to.
10005           (when (and info
10006                      (memq action '(move copy)))
10007             (unless (member to-group to-groups)
10008               (push to-group to-groups))
10009
10010             (when (and (not (memq article gnus-newsgroup-unreads))
10011                        (cdr art-group))
10012               (push 'read to-marks)
10013               (gnus-info-set-read
10014                info (gnus-add-to-range (gnus-info-read info)
10015                                        (list (cdr art-group)))))
10016
10017             ;; See whether the article is to be put in the cache.
10018             (let* ((expirable (gnus-group-auto-expirable-p to-group))
10019                    (marks (if expirable
10020                               gnus-article-mark-lists
10021                             (delete '(expirable . expire)
10022                                     (copy-sequence
10023                                      gnus-article-mark-lists))))
10024                    (to-article (cdr art-group)))
10025
10026               ;; Enter the article into the cache in the new group,
10027               ;; if that is required.
10028               (when (and to-article
10029                          gnus-use-cache)
10030                 (gnus-cache-possibly-enter-article
10031                  to-group to-article
10032                  (memq article gnus-newsgroup-marked)
10033                  (memq article gnus-newsgroup-dormant)
10034                  (memq article gnus-newsgroup-unreads)))
10035
10036               (when (and gnus-preserve-marks
10037                          to-article)
10038                 ;; Copy any marks over to the new group.
10039                 (when (and (equal to-group gnus-newsgroup-name)
10040                            (not (memq article gnus-newsgroup-unreads)))
10041                   ;; Mark this article as read in this group.
10042                   (push (cons to-article gnus-read-mark)
10043                         gnus-newsgroup-reads)
10044                   ;; Increase the active status of this group.
10045                   (setcdr (gnus-active to-group) to-article)
10046                   (setcdr gnus-newsgroup-active to-article))
10047
10048                 (while marks
10049                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
10050                     (when (memq article (symbol-value
10051                                          (intern (format "gnus-newsgroup-%s"
10052                                                          (caar marks)))))
10053                       (push (cdar marks) to-marks)
10054                       ;; If the other group is the same as this group,
10055                       ;; then we have to add the mark to the list.
10056                       (when (equal to-group gnus-newsgroup-name)
10057                         (set (intern (format "gnus-newsgroup-%s"
10058                                              (caar marks)))
10059                              (cons to-article
10060                                    (symbol-value
10061                                     (intern (format "gnus-newsgroup-%s"
10062                                                     (caar marks)))))))
10063                       ;; Copy the marks to other group.
10064                       (gnus-add-marked-articles
10065                        to-group (cdar marks) (list to-article) info)))
10066                   (setq marks (cdr marks)))
10067
10068                 (when (and expirable
10069                            gnus-mark-copied-or-moved-articles-as-expirable
10070                            (not (memq 'expire to-marks)))
10071                   ;; Mark this article as expirable.
10072                   (push 'expire to-marks)
10073                   (when (equal to-group gnus-newsgroup-name)
10074                     (push to-article gnus-newsgroup-expirable))
10075                   ;; Copy the expirable mark to other group.
10076                   (gnus-add-marked-articles
10077                    to-group 'expire (list to-article) info))
10078
10079                 (when (and to-marks
10080                            (gnus-method-option-p
10081                             (gnus-find-method-for-group to-group)
10082                             'server-marks))
10083                   (gnus-request-set-mark
10084                    to-group (list (list (list to-article) 'add to-marks)))))
10085
10086               (gnus-dribble-enter
10087                (concat "(gnus-group-set-info '"
10088                        (gnus-prin1-to-string (gnus-get-info to-group))
10089                        ")")
10090                (concat "^(gnus-group-set-info '(\""
10091                        (regexp-quote to-group) "\""))))
10092
10093           ;; Update the Xref header in this article to point to
10094           ;; the new crossposted article we have just created.
10095           (when (eq action 'crosspost)
10096             (with-current-buffer copy-buf
10097               (gnus-request-article-this-buffer article gnus-newsgroup-name)
10098               (nnheader-replace-header "Xref" new-xref)
10099               (gnus-request-replace-article
10100                article gnus-newsgroup-name (current-buffer) t)))
10101
10102           ;; run the move/copy/crosspost/respool hook
10103           (run-hook-with-args 'gnus-summary-article-move-hook
10104                               action
10105                               (gnus-data-header
10106                                (assoc article (gnus-data-list nil)))
10107                               gnus-newsgroup-name
10108                               to-newsgroup
10109                               select-method))
10110
10111         ;;;!!!Why is this necessary?
10112         (set-buffer gnus-summary-buffer)
10113
10114         (when (eq action 'move)
10115           (save-excursion
10116             (gnus-summary-goto-subject article)
10117             (gnus-summary-mark-article article gnus-canceled-mark)))))
10118       (push article articles-to-update-marks))
10119
10120     (save-excursion
10121       (apply 'gnus-summary-remove-process-mark articles-to-update-marks))
10122     ;; Re-activate all groups that have been moved to.
10123     (with-current-buffer gnus-group-buffer
10124       (let ((gnus-group-marked to-groups))
10125         (gnus-group-get-new-news-this-group nil t)))
10126
10127     (gnus-kill-buffer copy-buf)
10128     (gnus-summary-position-point)
10129     (gnus-set-mode-line 'summary)))
10130
10131 (defun gnus-summary-push-marks-to-backend (article)
10132   (let ((set nil)
10133         (del nil)
10134         (marks gnus-article-mark-lists))
10135     (unless (memq article gnus-newsgroup-unreads)
10136       (push 'read set))
10137     (while marks
10138       (if (and (eq (gnus-article-mark-to-type (cdar marks)) 'list)
10139                (memq article (symbol-value
10140                               (intern (format "gnus-newsgroup-%s"
10141                                               (caar marks))))))
10142           (push (cdar marks) set)
10143         (push (cdar marks) del))
10144       (pop marks))
10145     (gnus-request-set-mark gnus-newsgroup-name `(((,article) set ,set)
10146                                                  ((,article) del ,del)))))
10147
10148 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
10149   "Copy the current article to some other group.
10150 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
10151 When called interactively, if TO-NEWSGROUP is nil, use the value of
10152 the variable `gnus-move-split-methods' for finding a default target
10153 newsgroup.
10154 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
10155 re-spool using this method."
10156   (interactive "P")
10157   (gnus-summary-move-article n to-newsgroup select-method 'copy))
10158
10159 (defun gnus-summary-crosspost-article (&optional n)
10160   "Crosspost the current article to some other group."
10161   (interactive "P")
10162   (gnus-summary-move-article n nil nil 'crosspost))
10163
10164 (defcustom gnus-summary-respool-default-method nil
10165   "Default method type for respooling an article.
10166 If nil, use to the current newsgroup method."
10167   :type 'symbol
10168   :group 'gnus-summary-mail)
10169
10170 (defun gnus-summary-respool-article (&optional n method)
10171   "Respool the current article.
10172 The article will be squeezed through the mail spooling process again,
10173 which means that it will be put in some mail newsgroup or other
10174 depending on `nnmail-split-methods'.
10175 If N is a positive number, respool the N next articles.
10176 If N is a negative number, respool the N previous articles.
10177 If N is nil and any articles have been marked with the process mark,
10178 respool those articles instead.
10179
10180 Respooling can be done both from mail groups and \"real\" newsgroups.
10181 In the former case, the articles in question will be moved from the
10182 current group into whatever groups they are destined to.  In the
10183 latter case, they will be copied into the relevant groups."
10184   (interactive
10185    (list current-prefix-arg
10186          (let* ((methods (mapcar #'car (gnus-methods-using 'respool)))
10187                 (methname
10188                  (symbol-name (or gnus-summary-respool-default-method
10189                                   (car (gnus-find-method-for-group
10190                                         gnus-newsgroup-name)))))
10191                 (method
10192                  (gnus-completing-read
10193                   "Backend to use when respooling"
10194                   methods t nil 'gnus-mail-method-history methname))
10195                 ms)
10196            (cond
10197             ((zerop (length (setq ms (gnus-servers-using-backend
10198                                       (intern method)))))
10199              (list (intern method) ""))
10200             ((= 1 (length ms))
10201              (car ms))
10202             (t
10203              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
10204                (cdr (assoc (gnus-completing-read "Server name" ms-alist t)
10205                            ms-alist))))))))
10206   (unless method
10207     (error "No method given for respooling"))
10208   (if (assoc (symbol-name
10209               (car (gnus-find-method-for-group gnus-newsgroup-name)))
10210              (gnus-methods-using 'respool))
10211       (gnus-summary-move-article n nil method)
10212     (gnus-summary-copy-article n nil method)))
10213
10214 (defun gnus-summary-import-article (file &optional edit)
10215   "Import an arbitrary file into a mail newsgroup."
10216   (interactive "fImport file: \nP")
10217   (let ((group gnus-newsgroup-name)
10218         (now (current-time))
10219         atts lines group-art)
10220     (unless (gnus-check-backend-function 'request-accept-article group)
10221       (error "%s does not support article importing" group))
10222     (or (file-readable-p file)
10223         (not (file-regular-p file))
10224         (error "Can't read %s" file))
10225     (with-current-buffer (gnus-get-buffer-create " *import file*")
10226       (erase-buffer)
10227       (nnheader-insert-file-contents file)
10228       (goto-char (point-min))
10229       (if (nnheader-article-p)
10230           (save-restriction
10231             (goto-char (point-min))
10232             (search-forward "\n\n" nil t)
10233             (narrow-to-region (point-min) (1- (point)))
10234             (goto-char (point-min))
10235             (unless (re-search-forward "^date:" nil t)
10236               (goto-char (point-max))
10237               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
10238        ;; This doesn't look like an article, so we fudge some headers.
10239         (setq atts (file-attributes file)
10240               lines (count-lines (point-min) (point-max)))
10241         (insert "From: " (read-string "From: ") "\n"
10242                 "Subject: " (read-string "Subject: ") "\n"
10243                 "Date: " (message-make-date (nth 5 atts)) "\n"
10244                 "Message-ID: " (message-make-message-id) "\n"
10245                 "Lines: " (int-to-string lines) "\n"
10246                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
10247       (setq group-art (gnus-request-accept-article group nil t))
10248       (kill-buffer (current-buffer)))
10249     (setq gnus-newsgroup-active (gnus-activate-group group))
10250     (forward-line 1)
10251     (gnus-summary-goto-article (cdr group-art) nil t)
10252     (when edit
10253       (gnus-summary-edit-article))))
10254
10255 (defun gnus-summary-create-article ()
10256   "Create an article in a mail newsgroup."
10257   (interactive)
10258   (let ((group gnus-newsgroup-name)
10259         (now (current-time))
10260         group-art)
10261     (unless (gnus-check-backend-function 'request-accept-article group)
10262       (error "%s does not support article importing" group))
10263     (with-current-buffer (gnus-get-buffer-create " *import file*")
10264       (erase-buffer)
10265       (goto-char (point-min))
10266       ;; This doesn't look like an article, so we fudge some headers.
10267       (insert "From: " (read-string "From: ") "\n"
10268               "Subject: " (read-string "Subject: ") "\n"
10269               "Date: " (message-make-date now) "\n"
10270               "Message-ID: " (message-make-message-id) "\n")
10271       (setq group-art (gnus-request-accept-article group nil t))
10272       (kill-buffer (current-buffer)))
10273     (setq gnus-newsgroup-active (gnus-activate-group group))
10274     (forward-line 1)
10275     (gnus-summary-goto-article (cdr group-art) nil t)
10276     (gnus-summary-edit-article)))
10277
10278 (defun gnus-summary-article-posted-p ()
10279   "Say whether the current (mail) article is available from news as well.
10280 This will be the case if the article has both been mailed and posted."
10281   (interactive)
10282   (let ((id (mail-header-references (gnus-summary-article-header)))
10283         (gnus-override-method (car (gnus-refer-article-methods))))
10284     (if (gnus-request-head id "")
10285         (gnus-message 2 "The current message was found on %s"
10286                       gnus-override-method)
10287       (gnus-message 2 "The current message couldn't be found on %s"
10288                     gnus-override-method)
10289       nil)))
10290
10291 (defun gnus-summary-expire-articles (&optional now)
10292   "Expire all articles that are marked as expirable in the current group."
10293   (interactive)
10294   (when (and (not gnus-group-is-exiting-without-update-p)
10295              (gnus-check-backend-function
10296               'request-expire-articles gnus-newsgroup-name))
10297     ;; This backend supports expiry.
10298     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
10299            (expirable
10300             (gnus-list-range-difference
10301              (if total
10302                  (progn
10303                    ;; We need to update the info for
10304                    ;; this group for `gnus-list-of-read-articles'
10305                    ;; to give us the right answer.
10306                    (gnus-run-hooks 'gnus-exit-group-hook)
10307                    (gnus-summary-update-info)
10308                    (gnus-list-of-read-articles gnus-newsgroup-name))
10309                (setq gnus-newsgroup-expirable
10310                      (sort gnus-newsgroup-expirable '<)))
10311              gnus-newsgroup-unexist))
10312            (expiry-wait (if now 'immediate
10313                           (gnus-group-find-parameter
10314                            gnus-newsgroup-name 'expiry-wait)))
10315            (nnmail-expiry-target
10316             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
10317                 nnmail-expiry-target))
10318            es)
10319       (when expirable
10320         ;; There are expirable articles in this group, so we run them
10321         ;; through the expiry process.
10322         (gnus-message 6 "Expiring articles...")
10323         (when (gnus-check-group gnus-newsgroup-name)
10324           ;; The list of articles that weren't expired is returned.
10325           (save-excursion
10326             (if expiry-wait
10327                 (let ((nnmail-expiry-wait-function nil)
10328                       (nnmail-expiry-wait expiry-wait))
10329                   (setq es (gnus-request-expire-articles
10330                             expirable gnus-newsgroup-name)))
10331               (setq es (gnus-request-expire-articles
10332                         expirable gnus-newsgroup-name)))
10333             (unless total
10334               (setq gnus-newsgroup-expirable es))
10335             ;; We go through the old list of expirable, and mark all
10336             ;; really expired articles as nonexistent.
10337             (unless (eq es expirable) ;If nothing was expired, we don't mark.
10338               (let ((gnus-use-cache nil))
10339                 (dolist (article expirable)
10340                   (when (and (not (memq article es))
10341                              (gnus-data-find article))
10342                     (gnus-summary-mark-article article gnus-canceled-mark)
10343                     (run-hook-with-args 'gnus-summary-article-expire-hook
10344                                         'delete
10345                                         (gnus-data-header
10346                                          (assoc article (gnus-data-list nil)))
10347                                         gnus-newsgroup-name
10348                                         nil
10349                                         nil)))))))
10350         (gnus-message 6 "Expiring articles...done")))))
10351
10352 (defun gnus-summary-expire-articles-now ()
10353   "Expunge all expirable articles in the current group.
10354 This means that *all* articles that are marked as expirable will be
10355 deleted forever, right now."
10356   (interactive)
10357   (or gnus-expert-user
10358       (gnus-yes-or-no-p
10359        "Are you really, really sure you want to delete all expirable messages? ")
10360       (error "Phew!"))
10361   (gnus-summary-expire-articles t))
10362
10363 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10364 (defun gnus-summary-delete-article (&optional n)
10365   "Delete the N next (mail) articles.
10366 This command actually deletes articles.  This is not a marking
10367 command.  The article will disappear forever from your life, never to
10368 return.
10369
10370 If N is negative, delete backwards.
10371 If N is nil and articles have been marked with the process mark,
10372 delete these instead.
10373
10374 If `gnus-novice-user' is non-nil you will be asked for
10375 confirmation before the articles are deleted."
10376   (interactive "P")
10377   (unless (gnus-check-backend-function 'request-expire-articles
10378                                        gnus-newsgroup-name)
10379     (error "The current newsgroup does not support article deletion"))
10380   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10381     (error "Couldn't open server"))
10382   ;; Compute the list of articles to delete.
10383   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10384         (nnmail-expiry-target 'delete)
10385         not-deleted)
10386     (if (and gnus-novice-user
10387              (not (gnus-yes-or-no-p
10388                    (format "Do you really want to delete %s forever? "
10389                            (if (> (length articles) 1)
10390                                (format "these %s articles" (length articles))
10391                              "this article")))))
10392         ()
10393       ;; Delete the articles.
10394       (setq not-deleted (gnus-request-expire-articles
10395                          articles gnus-newsgroup-name 'force))
10396       (save-excursion
10397         (while articles
10398           (gnus-summary-remove-process-mark (car articles))
10399           ;; The backend might not have been able to delete the article
10400           ;; after all.
10401           (unless (memq (car articles) not-deleted)
10402             (gnus-summary-mark-article (car articles) gnus-canceled-mark)
10403             (let* ((article (car articles))
10404                    (ghead  (gnus-data-header
10405                             (assoc article (gnus-data-list nil)))))
10406               (run-hook-with-args 'gnus-summary-article-delete-hook
10407                                   'delete ghead gnus-newsgroup-name nil
10408                                   nil)))
10409           (setq articles (cdr articles))))
10410       (when not-deleted
10411         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10412     (gnus-summary-position-point)
10413     (gnus-set-mode-line 'summary)
10414     not-deleted))
10415
10416 (defun gnus-summary-edit-article (&optional arg)
10417   "Edit the current article.
10418 This will have permanent effect only in mail groups.
10419 If ARG is nil, edit the decoded articles.
10420 If ARG is 1, edit the raw articles.
10421 If ARG is 2, edit the raw articles even in read-only groups.
10422 If ARG is 3, edit the articles with the current handles.
10423 Otherwise, allow editing of articles even in read-only
10424 groups."
10425   (interactive "P")
10426   (let (force raw current-handles)
10427     (cond
10428      ((null arg))
10429      ((eq arg 1)
10430       (setq raw t))
10431      ((eq arg 2)
10432       (setq raw t
10433             force t))
10434      ((eq arg 3)
10435       (setq current-handles
10436             (and (gnus-buffer-live-p gnus-article-buffer)
10437                  (with-current-buffer gnus-article-buffer
10438                    (prog1
10439                        gnus-article-mime-handles
10440                      (setq gnus-article-mime-handles nil))))))
10441      (t
10442       (setq force t)))
10443     (when (and raw (not force)
10444                (member gnus-newsgroup-name '("nndraft:delayed"
10445                                              "nndraft:drafts"
10446                                              "nndraft:queue")))
10447       (error "Can't edit the raw article in group %s"
10448              gnus-newsgroup-name))
10449     (with-current-buffer gnus-summary-buffer
10450       (let ((mail-parse-charset gnus-newsgroup-charset)
10451             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10452         (gnus-set-global-variables)
10453         (when (and (not force)
10454                    (gnus-group-read-only-p))
10455           (error "The current newsgroup does not support article editing"))
10456         (gnus-summary-show-article t)
10457         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10458           (with-current-buffer gnus-article-buffer
10459             (mm-enable-multibyte)))
10460         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10461             (setq raw t))
10462         (gnus-article-edit-article
10463          (if raw 'ignore
10464            `(lambda ()
10465               (let ((mbl mml-buffer-list))
10466                 (setq mml-buffer-list nil)
10467                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10468                   (mime-to-mml ,'current-handles))
10469                 (let ((mbl1 mml-buffer-list))
10470                   (setq mml-buffer-list mbl)
10471                   (set (make-local-variable 'mml-buffer-list) mbl1))
10472                 (gnus-make-local-hook 'kill-buffer-hook)
10473                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10474          `(lambda (no-highlight)
10475             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10476                   (message-options message-options)
10477                   (message-options-set-recipient)
10478                   (mail-parse-ignored-charsets
10479                    ',gnus-newsgroup-ignored-charsets)
10480                   (rfc2047-header-encoding-alist
10481                    ',(let ((charset (gnus-group-name-charset
10482                                      (gnus-find-method-for-group
10483                                       gnus-newsgroup-name)
10484                                      gnus-newsgroup-name)))
10485                        (append (list (cons "Newsgroups" charset)
10486                                      (cons "Followup-To" charset)
10487                                      (cons "Xref" charset))
10488                                rfc2047-header-encoding-alist))))
10489               ,(if (not raw) '(progn
10490                                 (mml-to-mime)
10491                                 (mml-destroy-buffers)
10492                                 (remove-hook 'kill-buffer-hook
10493                                              'mml-destroy-buffers t)
10494                                 (kill-local-variable 'mml-buffer-list)))
10495               (gnus-summary-edit-article-done
10496                ,(or (mail-header-references gnus-current-headers) "")
10497                ,(gnus-group-read-only-p)
10498                ,gnus-summary-buffer no-highlight))))))))
10499
10500 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10501
10502 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10503                                                  no-highlight)
10504   "Make edits to the current article permanent."
10505   (interactive)
10506   (save-excursion
10507     ;; The buffer restriction contains the entire article if it exists.
10508     (when (article-goto-body)
10509       (let ((lines (count-lines (point) (point-max)))
10510             (length (- (point-max) (point)))
10511             (case-fold-search t)
10512             (body (copy-marker (point))))
10513         (goto-char (point-min))
10514         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10515           (delete-region (match-beginning 1) (match-end 1))
10516           (insert (number-to-string length)))
10517         (goto-char (point-min))
10518         (when (re-search-forward
10519                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10520           (delete-region (match-beginning 1) (match-end 1))
10521           (insert (number-to-string length)))
10522         (goto-char (point-min))
10523         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10524           (delete-region (match-beginning 1) (match-end 1))
10525           (insert (number-to-string lines))))))
10526   ;; Replace the article.
10527   (let ((buf (current-buffer))
10528         (article (cdr gnus-article-current))
10529         replace-result)
10530     (with-temp-buffer
10531       (insert-buffer-substring buf)
10532       (if (and (not read-only)
10533                (not (setq replace-result
10534                           (gnus-request-replace-article
10535                            article (car gnus-article-current)
10536                            (current-buffer) t))))
10537           (error "Couldn't replace article")
10538         ;; If we got a number back, then that's the new article number
10539         ;; for this article.  Otherwise, the article number didn't change.
10540         (when (numberp replace-result)
10541           (with-current-buffer gnus-summary-buffer
10542             (setq gnus-newsgroup-limit (delq article gnus-newsgroup-limit))
10543             (gnus-summary-limit gnus-newsgroup-limit)
10544             (setq article replace-result)
10545             (gnus-summary-goto-subject article t)))
10546         ;; Update the summary buffer.
10547         (if (and references
10548                  (equal (message-tokenize-header references " ")
10549                         (message-tokenize-header
10550                          (or (message-fetch-field "references") "") " ")))
10551             ;; We only have to update this line.
10552             (save-excursion
10553               (save-restriction
10554                 (message-narrow-to-head)
10555                 (let ((head (buffer-substring-no-properties
10556                              (point-min) (point-max)))
10557                       header)
10558                   (with-temp-buffer
10559                     (insert (format "211 %d Article retrieved.\n" article))
10560                     (insert head)
10561                     (insert ".\n")
10562                     (let ((nntp-server-buffer (current-buffer)))
10563                       (setq header (car (gnus-get-newsgroup-headers nil t))))
10564                     (with-current-buffer gnus-summary-buffer
10565                       (gnus-data-set-header (gnus-data-find article) header)
10566                       (gnus-summary-update-article-line article header)
10567                       (if (gnus-summary-goto-subject article nil t)
10568                           (gnus-summary-update-secondary-mark article)))))))
10569           ;; Update threads.
10570           (set-buffer (or buffer gnus-summary-buffer))
10571           (gnus-summary-update-article article)
10572           (if (gnus-summary-goto-subject article nil t)
10573               (gnus-summary-update-secondary-mark article)))
10574         ;; Prettify the article buffer again.
10575         (unless no-highlight
10576           (with-current-buffer gnus-article-buffer
10577             ;;!!! Fix this -- article should be rehighlighted.
10578             ;;(gnus-run-hooks 'gnus-article-display-hook)
10579             (set-buffer gnus-original-article-buffer)
10580             (gnus-request-article
10581              article (car gnus-article-current) (current-buffer))))
10582         ;; Prettify the summary buffer line.
10583         (when (gnus-visual-p 'summary-highlight 'highlight)
10584           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10585
10586 (defun gnus-summary-edit-wash (key)
10587   "Perform editing command KEY in the article buffer."
10588   (interactive
10589    (list
10590     (progn
10591       (message "%s" (concat (this-command-keys) "- "))
10592       (read-char))))
10593   (message "")
10594   (gnus-summary-edit-article)
10595   (execute-kbd-macro (concat (this-command-keys) key))
10596   (gnus-article-edit-done))
10597
10598 ;;; Respooling
10599
10600 (defun gnus-summary-respool-query (&optional silent trace)
10601   "Query where the respool algorithm would put this article."
10602   (interactive)
10603   (let (gnus-mark-article-hook)
10604     (gnus-summary-select-article)
10605     (with-current-buffer gnus-original-article-buffer
10606       (let ((groups (nnmail-article-group 'identity trace)))
10607         (unless silent
10608           (if groups
10609               (message "This message would go to %s"
10610                        (mapconcat 'car groups ", "))
10611             (message "This message would go to no groups"))
10612           groups)))))
10613
10614 (defun gnus-summary-respool-trace ()
10615   "Trace where the respool algorithm would put this article.
10616 Display a buffer showing all fancy splitting patterns which matched."
10617   (interactive)
10618   (gnus-summary-respool-query nil t))
10619
10620 ;; Summary marking commands.
10621
10622 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10623   "Mark articles which has the same subject as read, and then select the next.
10624 If UNMARK is positive, remove any kind of mark.
10625 If UNMARK is negative, tick articles."
10626   (interactive "P")
10627   (when unmark
10628     (setq unmark (prefix-numeric-value unmark)))
10629   (let ((count
10630          (gnus-summary-mark-same-subject
10631           (gnus-summary-article-subject) unmark)))
10632     ;; Select next unread article.  If auto-select-same mode, should
10633     ;; select the first unread article.
10634     (gnus-summary-next-article t (and gnus-auto-select-same
10635                                       (gnus-summary-article-subject)))
10636     (gnus-message 7 "%d article%s marked as %s"
10637                   count (if (= count 1) " is" "s are")
10638                   (if unmark "unread" "read"))))
10639
10640 (defun gnus-summary-kill-same-subject (&optional unmark)
10641   "Mark articles which has the same subject as read.
10642 If UNMARK is positive, remove any kind of mark.
10643 If UNMARK is negative, tick articles."
10644   (interactive "P")
10645   (when unmark
10646     (setq unmark (prefix-numeric-value unmark)))
10647   (let ((count
10648          (gnus-summary-mark-same-subject
10649           (gnus-summary-article-subject) unmark)))
10650     ;; If marked as read, go to next unread subject.
10651     (when (null unmark)
10652       ;; Go to next unread subject.
10653       (gnus-summary-next-subject 1 t))
10654     (gnus-message 7 "%d articles are marked as %s"
10655                   count (if unmark "unread" "read"))))
10656
10657 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10658   "Mark articles with same SUBJECT as read, and return marked number.
10659 If optional argument UNMARK is positive, remove any kinds of marks.
10660 If optional argument UNMARK is negative, mark articles as unread instead."
10661   (let ((count 1))
10662     (save-excursion
10663       (cond
10664        ((null unmark)                   ; Mark as read.
10665         (while (and
10666                 (progn
10667                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10668                   (gnus-summary-show-thread) t)
10669                 (gnus-summary-find-subject subject))
10670           (setq count (1+ count))))
10671        ((> unmark 0)                    ; Tick.
10672         (while (and
10673                 (progn
10674                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10675                   (gnus-summary-show-thread) t)
10676                 (gnus-summary-find-subject subject))
10677           (setq count (1+ count))))
10678        (t                               ; Mark as unread.
10679         (while (and
10680                 (progn
10681                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10682                   (gnus-summary-show-thread) t)
10683                 (gnus-summary-find-subject subject))
10684           (setq count (1+ count)))))
10685       (gnus-set-mode-line 'summary)
10686       ;; Return the number of marked articles.
10687       count)))
10688
10689 (defun gnus-summary-mark-as-processable (n &optional unmark)
10690   "Set the process mark on the next N articles.
10691 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10692 the process mark instead.  The difference between N and the actual
10693 number of articles marked is returned."
10694   (interactive "P")
10695   (if (and (null n) (gnus-region-active-p))
10696       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10697     (setq n (prefix-numeric-value n))
10698     (let ((backward (< n 0))
10699           (n (abs n)))
10700       (while (and
10701               (> n 0)
10702               (if unmark
10703                   (gnus-summary-remove-process-mark
10704                    (gnus-summary-article-number))
10705                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10706               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10707         (setq n (1- n)))
10708       (when (/= 0 n)
10709         (gnus-message 7 "No more articles"))
10710       (gnus-summary-recenter)
10711       (gnus-summary-position-point)
10712       n)))
10713
10714 (defun gnus-summary-unmark-as-processable (n)
10715   "Remove the process mark from the next N articles.
10716 If N is negative, unmark backward instead.  The difference between N and
10717 the actual number of articles unmarked is returned."
10718   (interactive "P")
10719   (gnus-summary-mark-as-processable n t))
10720
10721 (defun gnus-summary-unmark-all-processable ()
10722   "Remove the process mark from all articles."
10723   (interactive)
10724   (save-excursion
10725     (while gnus-newsgroup-processable
10726       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10727   (gnus-summary-position-point))
10728
10729 (defun gnus-summary-add-mark (article type)
10730   "Mark ARTICLE with a mark of TYPE."
10731   (let ((vtype (car (assq type gnus-article-mark-lists)))
10732         var)
10733     (if (not vtype)
10734         (error "No such mark type: %s" type)
10735       (setq var (intern (format "gnus-newsgroup-%s" type)))
10736       (set var (cons article (symbol-value var)))
10737       (if (memq type '(processable cached replied forwarded recent saved))
10738           (gnus-summary-update-secondary-mark article)
10739         ;;; !!! This is bogus.  We should find out what primary
10740         ;;; !!! mark we want to set.
10741         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10742
10743 (defun gnus-summary-mark-as-expirable (n)
10744   "Mark N articles forward as expirable.
10745 If N is negative, mark backward instead.  The difference between N and
10746 the actual number of articles marked is returned."
10747   (interactive "p")
10748   (gnus-summary-mark-forward n gnus-expirable-mark))
10749
10750 (defun gnus-summary-mark-as-spam (n)
10751   "Mark N articles forward as spam.
10752 If N is negative, mark backward instead.  The difference between N and
10753 the actual number of articles marked is returned."
10754   (interactive "p")
10755   (gnus-summary-mark-forward n gnus-spam-mark))
10756
10757 (defun gnus-summary-mark-article-as-replied (article)
10758   "Mark ARTICLE as replied to and update the summary line.
10759 ARTICLE can also be a list of articles."
10760   (interactive (list (gnus-summary-article-number)))
10761   (let ((articles (if (listp article) article (list article))))
10762     (dolist (article articles)
10763       (unless (numberp article)
10764         (error "%s is not a number" article))
10765       (push article gnus-newsgroup-replied)
10766       (let ((inhibit-read-only t))
10767         (when (gnus-summary-goto-subject article nil t)
10768           (gnus-summary-update-secondary-mark article))))))
10769
10770 (defun gnus-summary-mark-article-as-forwarded (article)
10771   "Mark ARTICLE as forwarded and update the summary line.
10772 ARTICLE can also be a list of articles."
10773   (let ((articles (if (listp article) article (list article))))
10774     (dolist (article articles)
10775       (push article gnus-newsgroup-forwarded)
10776       (let ((inhibit-read-only t))
10777         (when (gnus-summary-goto-subject article nil t)
10778           (gnus-summary-update-secondary-mark article))))))
10779
10780 (defun gnus-summary-set-bookmark (article)
10781   "Set a bookmark in current article."
10782   (interactive (list (gnus-summary-article-number)))
10783   (when (or (not (get-buffer gnus-article-buffer))
10784             (not gnus-current-article)
10785             (not gnus-article-current)
10786             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10787     (error "No current article selected"))
10788   ;; Remove old bookmark, if one exists.
10789   (gnus-alist-pull article gnus-newsgroup-bookmarks)
10790   ;; Set the new bookmark, which is on the form
10791   ;; (article-number . line-number-in-body).
10792   (push
10793    (cons article
10794          (with-current-buffer gnus-article-buffer
10795            (count-lines
10796             (min (point)
10797                  (save-excursion
10798                    (article-goto-body)
10799                    (point)))
10800             (point))))
10801    gnus-newsgroup-bookmarks)
10802   (gnus-message 6 "A bookmark has been added to the current article."))
10803
10804 (defun gnus-summary-remove-bookmark (article)
10805   "Remove the bookmark from the current article."
10806   (interactive (list (gnus-summary-article-number)))
10807   ;; Remove old bookmark, if one exists.
10808   (if (not (assq article gnus-newsgroup-bookmarks))
10809       (gnus-message 6 "No bookmark in current article.")
10810     (gnus-alist-pull article gnus-newsgroup-bookmarks)
10811     (gnus-message 6 "Removed bookmark.")))
10812
10813 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10814 (defun gnus-summary-mark-as-dormant (n)
10815   "Mark N articles forward as dormant.
10816 If N is negative, mark backward instead.  The difference between N and
10817 the actual number of articles marked is returned."
10818   (interactive "p")
10819   (gnus-summary-mark-forward n gnus-dormant-mark))
10820
10821 (defun gnus-summary-set-process-mark (article)
10822   "Set the process mark on ARTICLE and update the summary line."
10823   (setq gnus-newsgroup-processable
10824         (cons article
10825               (delq article gnus-newsgroup-processable)))
10826   (when (gnus-summary-goto-subject article)
10827     (gnus-summary-show-thread)
10828     (gnus-summary-goto-subject article)
10829     (gnus-summary-update-secondary-mark article)))
10830
10831 (defun gnus-summary-remove-process-mark (&rest articles)
10832   "Remove the process mark from ARTICLES and update the summary line."
10833   (dolist (article articles)
10834     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10835     (when (gnus-summary-goto-subject article)
10836       (gnus-summary-show-thread)
10837       (gnus-summary-goto-subject article)
10838       (gnus-summary-update-secondary-mark article)))
10839   t)
10840
10841 (defun gnus-summary-set-saved-mark (article)
10842   "Set the process mark on ARTICLE and update the summary line."
10843   (push article gnus-newsgroup-saved)
10844   (when (gnus-summary-goto-subject article)
10845     (gnus-summary-update-secondary-mark article)))
10846
10847 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10848   "Mark N articles as read forwards.
10849 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10850 The difference between N and the actual number of articles marked is
10851 returned.
10852 If NO-EXPIRE, auto-expiry will be inhibited."
10853   (interactive "p")
10854   (gnus-summary-show-thread)
10855   (let ((backward (< n 0))
10856         (gnus-summary-goto-unread
10857          (and gnus-summary-goto-unread
10858               (not (eq gnus-summary-goto-unread 'never))
10859               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10860                                     gnus-ticked-mark gnus-dormant-mark)))))
10861         (n (abs n))
10862         (mark (or mark gnus-del-mark)))
10863     (while (and (> n 0)
10864                 (gnus-summary-mark-article nil mark no-expire)
10865                 (zerop (gnus-summary-next-subject
10866                         (if backward -1 1)
10867                         (and gnus-summary-goto-unread
10868                              (not (eq gnus-summary-goto-unread 'never)))
10869                         t)))
10870       (setq n (1- n)))
10871     (when (/= 0 n)
10872       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10873     (gnus-summary-recenter)
10874     (gnus-summary-position-point)
10875     (gnus-set-mode-line 'summary)
10876     n))
10877
10878 (defun gnus-summary-mark-article-as-read (mark)
10879   "Mark the current article quickly as read with MARK."
10880   (let ((article (gnus-summary-article-number)))
10881     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10882     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10883     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10884     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10885     (push (cons article mark) gnus-newsgroup-reads)
10886     ;; Possibly remove from cache, if that is used.
10887     (when gnus-use-cache
10888       (gnus-cache-enter-remove-article article))
10889     ;; Allow the backend to change the mark.
10890     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10891     ;; Check for auto-expiry.
10892     (when (and gnus-newsgroup-auto-expire
10893                (memq mark gnus-auto-expirable-marks))
10894       (setq mark gnus-expirable-mark)
10895       ;; Let the backend know about the mark change.
10896       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10897       (push article gnus-newsgroup-expirable))
10898     ;; Set the mark in the buffer.
10899     (gnus-summary-update-mark mark 'unread)
10900     t))
10901
10902 (defun gnus-summary-mark-article-as-unread (mark)
10903   "Mark the current article quickly as unread with MARK."
10904   (let* ((article (gnus-summary-article-number))
10905          (old-mark (gnus-summary-article-mark article)))
10906     ;; Allow the backend to change the mark.
10907     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10908     (if (eq mark old-mark)
10909         t
10910       (if (<= article 0)
10911           (progn
10912             (gnus-error 1 "Can't mark negative article numbers")
10913             nil)
10914         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10915         (setq gnus-newsgroup-spam-marked
10916               (delq article gnus-newsgroup-spam-marked))
10917         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10918         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10919         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10920         (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10921         (cond ((= mark gnus-ticked-mark)
10922                (setq gnus-newsgroup-marked
10923                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10924                                               article)))
10925               ((= mark gnus-spam-mark)
10926                (setq gnus-newsgroup-spam-marked
10927                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10928                                               article)))
10929               ((= mark gnus-dormant-mark)
10930                (setq gnus-newsgroup-dormant
10931                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10932                                               article)))
10933               (t
10934                (setq gnus-newsgroup-unreads
10935                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10936                                               article))))
10937         (gnus-alist-pull article gnus-newsgroup-reads)
10938
10939         ;; See whether the article is to be put in the cache.
10940         (and gnus-use-cache
10941              (vectorp (gnus-summary-article-header article))
10942              (save-excursion
10943                (gnus-cache-possibly-enter-article
10944                 gnus-newsgroup-name article
10945                 (= mark gnus-ticked-mark)
10946                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10947
10948         ;; Fix the mark.
10949         (gnus-summary-update-mark mark 'unread)
10950         t))))
10951
10952 (defun gnus-summary-mark-article (&optional article mark no-expire)
10953   "Mark ARTICLE with MARK.  MARK can be any character.
10954 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10955 `??' (dormant) and `?E' (expirable).
10956 If MARK is nil, then the default character `?r' is used.
10957 If ARTICLE is nil, then the article on the current line will be
10958 marked.
10959 If NO-EXPIRE, auto-expiry will be inhibited."
10960   ;; The mark might be a string.
10961   (when (stringp mark)
10962     (setq mark (aref mark 0)))
10963   ;; If no mark is given, then we check auto-expiring.
10964   (when (null mark)
10965     (setq mark gnus-del-mark))
10966   (when (and (not no-expire)
10967              gnus-newsgroup-auto-expire
10968              (memq mark gnus-auto-expirable-marks))
10969     (setq mark gnus-expirable-mark))
10970   (let ((article (or article (gnus-summary-article-number)))
10971         (old-mark (gnus-summary-article-mark article)))
10972     ;; Allow the backend to change the mark.
10973     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10974     (if (eq mark old-mark)
10975         t
10976       (unless article
10977         (error "No article on current line"))
10978       (if (not (if (or (= mark gnus-unread-mark)
10979                        (= mark gnus-ticked-mark)
10980                        (= mark gnus-spam-mark)
10981                        (= mark gnus-dormant-mark))
10982                    (gnus-mark-article-as-unread article mark)
10983                  (gnus-mark-article-as-read article mark)))
10984           t
10985         ;; See whether the article is to be put in the cache.
10986         (and gnus-use-cache
10987              (not (= mark gnus-canceled-mark))
10988              (vectorp (gnus-summary-article-header article))
10989              (save-excursion
10990                (gnus-cache-possibly-enter-article
10991                 gnus-newsgroup-name article
10992                 (= mark gnus-ticked-mark)
10993                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10994
10995         (when (gnus-summary-goto-subject article nil t)
10996           (let ((inhibit-read-only t))
10997             (gnus-summary-show-thread)
10998             ;; Fix the mark.
10999             (gnus-summary-update-mark mark 'unread)
11000             t))))))
11001
11002 (defun gnus-summary-update-secondary-mark (article)
11003   "Update the secondary (read, process, cache) mark."
11004   (gnus-summary-update-mark
11005    (cond ((memq article gnus-newsgroup-processable)
11006           gnus-process-mark)
11007          ((memq article gnus-newsgroup-cached)
11008           gnus-cached-mark)
11009          ((memq article gnus-newsgroup-replied)
11010           gnus-replied-mark)
11011          ((memq article gnus-newsgroup-forwarded)
11012           gnus-forwarded-mark)
11013          ((memq article gnus-newsgroup-saved)
11014           gnus-saved-mark)
11015          ((memq article gnus-newsgroup-unseen)
11016           gnus-unseen-mark)
11017          (t gnus-no-mark))
11018    'replied)
11019   (when (gnus-visual-p 'summary-highlight 'highlight)
11020     (gnus-summary-highlight-line)
11021     (gnus-run-hooks 'gnus-summary-update-hook))
11022   t)
11023
11024 (defun gnus-summary-update-download-mark (article)
11025   "Update the download mark."
11026   (gnus-summary-update-mark
11027    (cond ((memq article gnus-newsgroup-undownloaded)
11028           gnus-undownloaded-mark)
11029          (gnus-newsgroup-agentized
11030           gnus-downloaded-mark)
11031          (t
11032           gnus-no-mark))
11033    'download)
11034   (gnus-summary-update-line t)
11035   t)
11036
11037 (defun gnus-summary-update-mark (mark type)
11038   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
11039         (inhibit-read-only t))
11040     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
11041     (when forward
11042       (when (looking-at "\r")
11043         (incf forward))
11044       (when (<= (+ forward (point)) (point-max))
11045         ;; Go to the right position on the line.
11046         (goto-char (+ forward (point)))
11047         ;; Replace the old mark with the new mark.
11048         (let ((to-insert
11049                (mm-subst-char-in-string
11050                 (char-after) mark
11051                 (buffer-substring (point) (1+ (point))))))
11052           (delete-region (point) (1+ (point)))
11053           (insert to-insert))
11054         ;; Optionally update the marks by some user rule.
11055         (when (eq type 'unread)
11056           (gnus-data-set-mark
11057            (gnus-data-find (gnus-summary-article-number)) mark)
11058           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
11059
11060 (defun gnus-mark-article-as-read (article &optional mark)
11061   "Enter ARTICLE in the pertinent lists and remove it from others."
11062   ;; Make the article expirable.
11063   (let ((mark (or mark gnus-del-mark)))
11064     (setq gnus-newsgroup-expirable
11065           (if (= mark gnus-expirable-mark)
11066               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
11067             (delq article gnus-newsgroup-expirable)))
11068     ;; Remove from unread and marked lists.
11069     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
11070     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
11071     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
11072     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
11073     (push (cons article mark) gnus-newsgroup-reads)
11074     ;; Possibly remove from cache, if that is used.
11075     (when gnus-use-cache
11076       (gnus-cache-enter-remove-article article))
11077     t))
11078
11079 (defun gnus-mark-article-as-unread (article &optional mark)
11080   "Enter ARTICLE in the pertinent lists and remove it from others."
11081   (let ((mark (or mark gnus-ticked-mark)))
11082     (if (<= article 0)
11083         (progn
11084           (gnus-error 1 "Can't mark negative article numbers")
11085           nil)
11086       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
11087             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
11088             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
11089             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
11090             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
11091
11092       ;; Unsuppress duplicates?
11093       (when gnus-suppress-duplicates
11094         (gnus-dup-unsuppress-article article))
11095
11096       (cond ((= mark gnus-ticked-mark)
11097              (setq gnus-newsgroup-marked
11098                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
11099             ((= mark gnus-spam-mark)
11100              (setq gnus-newsgroup-spam-marked
11101                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
11102                                             article)))
11103             ((= mark gnus-dormant-mark)
11104              (setq gnus-newsgroup-dormant
11105                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
11106             (t
11107              (setq gnus-newsgroup-unreads
11108                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
11109       (gnus-alist-pull article gnus-newsgroup-reads)
11110       t)))
11111
11112 (defun gnus-summary-tick-article-forward (n)
11113   "Tick N articles forwards.
11114 If N is negative, tick backwards instead.
11115 The difference between N and the number of articles ticked is returned."
11116   (interactive "p")
11117   (gnus-summary-mark-forward n gnus-ticked-mark))
11118
11119 (defun gnus-summary-tick-article-backward (n)
11120   "Tick N articles backwards.
11121 The difference between N and the number of articles ticked is returned."
11122   (interactive "p")
11123   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
11124
11125 (defun gnus-summary-tick-article (&optional article clear-mark)
11126   "Mark current article as unread.
11127 Optional 1st argument ARTICLE specifies article number to be marked as unread.
11128 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
11129   (interactive)
11130   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
11131                                        gnus-ticked-mark)))
11132
11133 (defun gnus-summary-mark-as-read-forward (n)
11134   "Mark N articles as read forwards.
11135 If N is negative, mark backwards instead.
11136 The difference between N and the actual number of articles marked is
11137 returned."
11138   (interactive "p")
11139   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
11140
11141 (defun gnus-summary-mark-as-read-backward (n)
11142   "Mark the N articles as read backwards.
11143 The difference between N and the actual number of articles marked is
11144 returned."
11145   (interactive "p")
11146   (gnus-summary-mark-forward
11147    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
11148
11149 (defun gnus-summary-mark-as-read (&optional article mark)
11150   "Mark current article as read.
11151 ARTICLE specifies the article to be marked as read.
11152 MARK specifies a string to be inserted at the beginning of the line."
11153   (gnus-summary-mark-article article mark))
11154
11155 (defun gnus-summary-clear-mark-forward (n)
11156   "Clear marks from N articles forward.
11157 If N is negative, clear backward instead.
11158 The difference between N and the number of marks cleared is returned."
11159   (interactive "p")
11160   (gnus-summary-mark-forward n gnus-unread-mark))
11161
11162 (defun gnus-summary-clear-mark-backward (n)
11163   "Clear marks from N articles backward.
11164 The difference between N and the number of marks cleared is returned."
11165   (interactive "p")
11166   (gnus-summary-mark-forward (- n) gnus-unread-mark))
11167
11168 (defun gnus-summary-mark-unread-as-read ()
11169   "Intended to be used by `gnus-mark-article-hook'."
11170   (when (memq gnus-current-article gnus-newsgroup-unreads)
11171     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
11172
11173 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
11174   "Intended to be used by `gnus-mark-article-hook'."
11175   (let ((mark (gnus-summary-article-mark)))
11176     (when (or (gnus-unread-mark-p mark)
11177               (gnus-read-mark-p mark))
11178       (gnus-summary-mark-article gnus-current-article
11179                                  (or new-mark gnus-read-mark)))))
11180
11181 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
11182   "Intended to be used by `gnus-mark-article-hook'."
11183   (let ((mark (gnus-summary-article-mark)))
11184     (when (or (gnus-unread-mark-p mark)
11185               (gnus-read-mark-p mark))
11186       (gnus-summary-mark-article (gnus-summary-article-number)
11187                                  (or new-mark gnus-read-mark)))))
11188
11189 (defun gnus-summary-mark-unread-as-ticked ()
11190   "Intended to be used by `gnus-mark-article-hook'."
11191   (when (memq gnus-current-article gnus-newsgroup-unreads)
11192     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
11193
11194 (defun gnus-summary-mark-region-as-read (point mark all)
11195   "Mark all unread articles between point and mark as read.
11196 If given a prefix, mark all articles between point and mark as read,
11197 even ticked and dormant ones."
11198   (interactive "r\nP")
11199   (save-excursion
11200     (let (article)
11201       (goto-char point)
11202       (beginning-of-line)
11203       (while (and
11204               (< (point) mark)
11205               (progn
11206                 (when (or all
11207                           (memq (setq article (gnus-summary-article-number))
11208                                 gnus-newsgroup-unreads))
11209                   (gnus-summary-mark-article article gnus-del-mark))
11210                 t)
11211               (gnus-summary-find-next))))))
11212
11213 (defun gnus-summary-mark-below (score mark)
11214   "Mark articles with score less than SCORE with MARK."
11215   (interactive "P\ncMark: ")
11216   (setq score (if score
11217                   (prefix-numeric-value score)
11218                 (or gnus-summary-default-score 0)))
11219   (with-current-buffer gnus-summary-buffer
11220     (goto-char (point-min))
11221     (while
11222         (progn
11223           (and (< (gnus-summary-article-score) score)
11224                (gnus-summary-mark-article nil mark))
11225           (gnus-summary-find-next)))))
11226
11227 (defun gnus-summary-kill-below (&optional score)
11228   "Mark articles with score below SCORE as read."
11229   (interactive "P")
11230   (gnus-summary-mark-below score gnus-killed-mark))
11231
11232 (defun gnus-summary-clear-above (&optional score)
11233   "Clear all marks from articles with score above SCORE."
11234   (interactive "P")
11235   (gnus-summary-mark-above score gnus-unread-mark))
11236
11237 (defun gnus-summary-tick-above (&optional score)
11238   "Tick all articles with score above SCORE."
11239   (interactive "P")
11240   (gnus-summary-mark-above score gnus-ticked-mark))
11241
11242 (defun gnus-summary-mark-above (score mark)
11243   "Mark articles with score over SCORE with MARK."
11244   (interactive "P\ncMark: ")
11245   (setq score (if score
11246                   (prefix-numeric-value score)
11247                 (or gnus-summary-default-score 0)))
11248   (with-current-buffer gnus-summary-buffer
11249     (goto-char (point-min))
11250     (while (and (progn
11251                   (when (> (gnus-summary-article-score) score)
11252                     (gnus-summary-mark-article nil mark))
11253                   t)
11254                 (gnus-summary-find-next)))))
11255
11256 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
11257 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
11258 (defun gnus-summary-limit-include-expunged (&optional no-error)
11259   "Display all the hidden articles that were expunged for low scores."
11260   (interactive)
11261   (let ((inhibit-read-only t))
11262     (let ((scored gnus-newsgroup-scored)
11263           headers h)
11264       (while scored
11265         (unless (gnus-summary-article-header (caar scored))
11266           (and (setq h (gnus-number-to-header (caar scored)))
11267                (< (cdar scored) gnus-summary-expunge-below)
11268                (push h headers)))
11269         (setq scored (cdr scored)))
11270       (if (not headers)
11271           (when (not no-error)
11272             (error "No expunged articles hidden"))
11273         (goto-char (point-min))
11274         (push gnus-newsgroup-limit gnus-newsgroup-limits)
11275         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
11276         (dolist (x headers)
11277           (push (mail-header-number x) gnus-newsgroup-limit))
11278         (gnus-summary-prepare-unthreaded (nreverse headers))
11279         (goto-char (point-min))
11280         (gnus-summary-position-point)
11281         t))))
11282
11283 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
11284   "Mark all unread articles in this newsgroup as read.
11285 If prefix argument ALL is non-nil, ticked and dormant articles will
11286 also be marked as read.
11287 If QUIETLY is non-nil, no questions will be asked.
11288
11289 If TO-HERE is non-nil, it should be a point in the buffer.  All
11290 articles before (after, if REVERSE is set) this point will be marked
11291 as read.
11292
11293 Note that this function will only catch up the unread article
11294 in the current summary buffer limitation.
11295
11296 The number of articles marked as read is returned."
11297   (interactive "P")
11298   (prog1
11299       (save-excursion
11300         (when (or quietly
11301                   (not gnus-interactive-catchup) ;Without confirmation?
11302                   gnus-expert-user
11303                   (gnus-y-or-n-p
11304                    (if all
11305                        "Mark absolutely all articles as read? "
11306                      "Mark all unread articles as read? ")))
11307           (if (and not-mark
11308                    (not gnus-newsgroup-adaptive)
11309                    (not gnus-newsgroup-auto-expire)
11310                    (not gnus-suppress-duplicates)
11311                    (or (not gnus-use-cache)
11312                        (eq gnus-use-cache 'passive)))
11313               (progn
11314                 (when all
11315                   (setq gnus-newsgroup-marked nil
11316                         gnus-newsgroup-spam-marked nil
11317                         gnus-newsgroup-dormant nil))
11318                 (setq gnus-newsgroup-unreads
11319                       (gnus-sorted-nunion
11320                        (gnus-sorted-intersection gnus-newsgroup-unreads
11321                                                  gnus-newsgroup-downloadable)
11322                        (gnus-sorted-difference gnus-newsgroup-unfetched
11323                                                gnus-newsgroup-cached))))
11324             ;; We actually mark all articles as canceled, which we
11325             ;; have to do when using auto-expiry or adaptive scoring.
11326             (gnus-summary-show-all-threads)
11327             (if (and to-here reverse)
11328                 (progn
11329                   (goto-char to-here)
11330                   (gnus-summary-mark-current-read-and-unread-as-read
11331                    gnus-catchup-mark)
11332                   (while (gnus-summary-find-next (not all))
11333                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
11334               (when (gnus-summary-first-subject (not all))
11335                 (while (and
11336                         (if to-here (< (point) to-here) t)
11337                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
11338                         (gnus-summary-find-next (not all))))))
11339             (gnus-set-mode-line 'summary))
11340           t))
11341     (gnus-summary-position-point)))
11342
11343 (defun gnus-summary-catchup-to-here (&optional all)
11344   "Mark all unticked articles before the current one as read.
11345 If ALL is non-nil, also mark ticked and dormant articles as read."
11346   (interactive "P")
11347   (save-excursion
11348     (gnus-save-hidden-threads
11349       (let ((beg (point)))
11350         ;; We check that there are unread articles.
11351         (when (or all (gnus-summary-find-prev))
11352           (gnus-summary-catchup all t beg)))))
11353   (gnus-summary-position-point))
11354
11355 (defun gnus-summary-catchup-from-here (&optional all)
11356   "Mark all unticked articles after (and including) the current one as read.
11357 If ALL is non-nil, also mark ticked and dormant articles as read."
11358   (interactive "P")
11359   (save-excursion
11360     (gnus-save-hidden-threads
11361       (let ((beg (point)))
11362         ;; We check that there are unread articles.
11363         (when (or all (gnus-summary-find-next))
11364           (gnus-summary-catchup all t beg nil t)))))
11365   (gnus-summary-position-point))
11366
11367 (defun gnus-summary-catchup-all (&optional quietly)
11368   "Mark all articles in this newsgroup as read.
11369 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11370 instead, which marks only unread articles as read."
11371   (interactive "P")
11372   (gnus-summary-catchup t quietly))
11373
11374 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11375   "Mark all unread articles in this group as read, then exit.
11376 If prefix argument ALL is non-nil, all articles are marked as read.
11377 If QUIETLY is non-nil, no questions will be asked."
11378   (interactive "P")
11379   (when (gnus-summary-catchup all quietly nil 'fast)
11380     ;; Select next newsgroup or exit.
11381     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11382              (eq gnus-auto-select-next 'quietly))
11383         (gnus-summary-next-group nil)
11384       (gnus-summary-exit))))
11385
11386 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11387   "Mark all articles in this newsgroup as read, and then exit.
11388 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11389 instead, which marks only unread articles as read."
11390   (interactive "P")
11391   (gnus-summary-catchup-and-exit t quietly))
11392
11393 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11394   "Mark all articles in this group as read and select the next group.
11395 If given a prefix, mark all articles, unread as well as ticked, as
11396 read."
11397   (interactive "P")
11398   (save-excursion
11399     (gnus-summary-catchup all))
11400   (gnus-summary-next-group))
11401
11402 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11403   "Mark all articles in this group as read and select the previous group.
11404 If given a prefix, mark all articles, unread as well as ticked, as
11405 read."
11406   (interactive "P")
11407   (save-excursion
11408     (gnus-summary-catchup all))
11409   (gnus-summary-next-group nil nil t))
11410
11411 ;;;
11412 ;;; with article
11413 ;;;
11414
11415 (defmacro gnus-with-article (article &rest forms)
11416   "Select ARTICLE and perform FORMS in the original article buffer.
11417 Then replace the article with the result."
11418   `(progn
11419      ;; We don't want the article to be marked as read.
11420      (let (gnus-mark-article-hook)
11421        (gnus-summary-select-article t t nil ,article))
11422      (set-buffer gnus-original-article-buffer)
11423      ,@forms
11424      (if (not (gnus-check-backend-function
11425                'request-replace-article (car gnus-article-current)))
11426          (gnus-message 5 "Read-only group; not replacing")
11427        (unless (gnus-request-replace-article
11428                 ,article (car gnus-article-current)
11429                 (current-buffer) t)
11430          (error "Couldn't replace article")))
11431      ;; The cache and backlog have to be flushed somewhat.
11432      (when gnus-keep-backlog
11433        (gnus-backlog-remove-article
11434         (car gnus-article-current) (cdr gnus-article-current)))
11435      (when gnus-use-cache
11436        (gnus-cache-update-article
11437         (car gnus-article-current) (cdr gnus-article-current)))))
11438
11439 (put 'gnus-with-article 'lisp-indent-function 1)
11440 (put 'gnus-with-article 'edebug-form-spec '(form body))
11441
11442 ;; Thread-based commands.
11443
11444 (defun gnus-summary-articles-in-thread (&optional article)
11445   "Return a list of all articles in the current thread.
11446 If ARTICLE is non-nil, return all articles in the thread that starts
11447 with that article."
11448   (let* ((article (or article (gnus-summary-article-number)))
11449          (data (gnus-data-find-list article))
11450          (top-level (gnus-data-level (car data)))
11451          (top-subject
11452           (cond ((null gnus-thread-operation-ignore-subject)
11453                  (gnus-simplify-subject-re
11454                   (mail-header-subject (gnus-data-header (car data)))))
11455                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11456                  (gnus-simplify-subject-fuzzy
11457                   (mail-header-subject (gnus-data-header (car data)))))
11458                 (t nil)))
11459          (end-point (save-excursion
11460                       (goto-char (gnus-data-pos (car data)))
11461                       (if (gnus-summary-go-to-next-thread)
11462                           (point) (point-max))))
11463          articles)
11464     (while (and data
11465                 (< (gnus-data-pos (car data)) end-point))
11466       (when (or (not top-subject)
11467                 (string= top-subject
11468                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11469                              (gnus-simplify-subject-fuzzy
11470                               (mail-header-subject
11471                                (gnus-data-header (car data))))
11472                            (gnus-simplify-subject-re
11473                             (mail-header-subject
11474                              (gnus-data-header (car data)))))))
11475         (push (gnus-data-number (car data)) articles))
11476       (unless (and (setq data (cdr data))
11477                    (> (gnus-data-level (car data)) top-level))
11478         (setq data nil)))
11479     ;; Return the list of articles.
11480     (nreverse articles)))
11481
11482 (defun gnus-summary-rethread-current ()
11483   "Rethread the thread the current article is part of."
11484   (interactive)
11485   (let* ((gnus-show-threads t)
11486          (article (gnus-summary-article-number))
11487          (id (mail-header-id (gnus-summary-article-header)))
11488          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11489     (unless id
11490       (error "No article on the current line"))
11491     (gnus-rebuild-thread id)
11492     (gnus-summary-goto-subject article)))
11493
11494 (defun gnus-summary-reparent-thread ()
11495   "Make the current article child of the marked (or previous) article.
11496
11497 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11498 is non-nil or the Subject: of both articles are the same."
11499   (interactive)
11500   (unless (not (gnus-group-read-only-p))
11501     (error "The current newsgroup does not support article editing"))
11502   (unless (<= (length gnus-newsgroup-processable) 1)
11503     (error "No more than one article may be marked"))
11504   (let ((child (gnus-summary-article-number))
11505         ;; First grab the marked article, otherwise one line up.
11506         (parent (if (not (null gnus-newsgroup-processable))
11507                     (car gnus-newsgroup-processable)
11508                   (save-excursion
11509                     (if (eq (forward-line -1) 0)
11510                         (gnus-summary-article-number)
11511                       (error "Beginning of summary buffer"))))))
11512     (gnus-summary-reparent-children parent (list child))))
11513
11514 (defun gnus-summary-reparent-children (parent children)
11515   "Make PARENT the parent of CHILDREN.
11516 When called interactively, PARENT is the current article and CHILDREN
11517 are the process-marked articles."
11518   (interactive
11519    (list (gnus-summary-article-number)
11520          (gnus-summary-work-articles nil)))
11521   (dolist (child children)
11522     (save-window-excursion
11523       (let ((gnus-article-buffer " *reparent*"))
11524         (unless (not (eq parent child))
11525           (error "An article may not be self-referential"))
11526         (let ((message-id (mail-header-id
11527                            (gnus-summary-article-header parent))))
11528           (unless (and message-id (not (equal message-id "")))
11529             (error "No message-id in desired parent"))
11530           (gnus-with-article child
11531             (save-restriction
11532               (goto-char (point-min))
11533               (message-narrow-to-head)
11534               (if (re-search-forward "^References: " nil t)
11535                   (progn
11536                     (re-search-forward "^[^ \t]" nil t)
11537                     (forward-line -1)
11538                     (end-of-line)
11539                     (insert " " message-id))
11540                 (insert "References: " message-id "\n"))))
11541           (set-buffer gnus-summary-buffer)
11542           (gnus-summary-unmark-all-processable)
11543           (gnus-summary-update-article child)
11544           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11545             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11546           (gnus-summary-rethread-current)
11547           (gnus-message 3 "Article %d is now the child of article %d"
11548                         child parent))))))
11549
11550 (defun gnus-summary-toggle-threads (&optional arg)
11551   "Toggle showing conversation threads.
11552 If ARG is positive number, turn showing conversation threads on."
11553   (interactive "P")
11554   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11555     (setq gnus-show-threads
11556           (if (null arg) (not gnus-show-threads)
11557             (> (prefix-numeric-value arg) 0)))
11558     (gnus-summary-prepare)
11559     (gnus-summary-goto-subject current)
11560     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11561     (gnus-summary-position-point)))
11562
11563 (eval-and-compile
11564   (if (fboundp 'remove-overlays)
11565       (defalias 'gnus-remove-overlays 'remove-overlays)
11566     (defun gnus-remove-overlays (beg end name val)
11567       "Clear BEG and END of overlays whose property NAME has value VAL.
11568 For compatibility with XEmacs."
11569       (dolist (ov (gnus-overlays-in beg end))
11570         (when (eq (gnus-overlay-get ov name) val)
11571           (gnus-delete-overlay ov))))))
11572
11573 (defun gnus-summary-show-all-threads ()
11574   "Show all threads."
11575   (interactive)
11576   (gnus-remove-overlays (point-min) (point-max) 'invisible 'gnus-sum)
11577   (gnus-summary-position-point))
11578
11579 (defsubst gnus-summary--inv (p)
11580   (and (eq (get-char-property p 'invisible) 'gnus-sum) p))
11581
11582 (defun gnus-summary-show-thread ()
11583   "Show thread subtrees.
11584 Returns nil if no thread was there to be shown."
11585   (interactive)
11586   (let* ((orig (point))
11587          (end (point-at-eol))
11588          (end (or (gnus-summary--inv end) (gnus-summary--inv (1- end))))
11589          ;; Leave point at bol
11590          (beg (progn (beginning-of-line) (if (bobp) (point) (1- (point)))))
11591          (eoi (when end
11592                 (if (fboundp 'next-single-char-property-change)
11593                     ;; Note: XEmacs version of n-s-c-p-c may return nil
11594                     (or (next-single-char-property-change end 'invisible)
11595                         (point-max))
11596                   (while (progn
11597                            (end-of-line 2)
11598                            (and (not (eobp))
11599                                 (eq (get-char-property (point) 'invisible)
11600                                     'gnus-sum))))
11601                   (point)))))
11602     (when eoi
11603       (gnus-remove-overlays beg eoi 'invisible 'gnus-sum)
11604       (goto-char orig)
11605       (gnus-summary-position-point)
11606       eoi)))
11607
11608 (defun gnus-summary-maybe-hide-threads ()
11609   "If requested, hide the threads that should be hidden."
11610   (when (and gnus-show-threads
11611              gnus-thread-hide-subtree)
11612     (gnus-summary-hide-all-threads
11613      (if (or (consp gnus-thread-hide-subtree)
11614              (functionp gnus-thread-hide-subtree))
11615          (gnus-make-predicate gnus-thread-hide-subtree)
11616        nil))))
11617
11618 ;;; Hiding predicates.
11619
11620 (defun gnus-article-unread-p (header)
11621   (memq (mail-header-number header) gnus-newsgroup-unreads))
11622
11623 (defun gnus-article-unseen-p (header)
11624   (memq (mail-header-number header) gnus-newsgroup-unseen))
11625
11626 (defun gnus-map-articles (predicate articles)
11627   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11628   (apply 'gnus-or (mapcar predicate
11629                           (mapcar (lambda (number)
11630                                     (gnus-summary-article-header number))
11631                                   articles))))
11632
11633 (defun gnus-summary-hide-all-threads (&optional predicate)
11634   "Hide all thread subtrees.
11635 If PREDICATE is supplied, threads that satisfy this predicate
11636 will not be hidden."
11637   (interactive)
11638   (save-excursion
11639     (goto-char (point-min))
11640     (let ((end nil)
11641           (count 0))
11642       (while (not end)
11643         (incf count)
11644         (when (zerop (mod count 1000))
11645           (message "Hiding all threads... %d" count))
11646         (when (or (not predicate)
11647                   (gnus-map-articles
11648                    predicate (gnus-summary-article-children)))
11649             (gnus-summary-hide-thread))
11650         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11651   (gnus-summary-position-point))
11652
11653 (defun gnus-summary-hide-thread ()
11654   "Hide thread subtrees.
11655 If PREDICATE is supplied, threads that satisfy this predicate
11656 will not be hidden.
11657 Returns nil if no threads were there to be hidden."
11658   (interactive)
11659   (beginning-of-line)
11660   (let ((start (point))
11661         (starteol (line-end-position))
11662         (article (gnus-summary-article-number)))
11663     ;; Go forward until either the buffer ends or the subthread ends.
11664     (when (and (not (eobp))
11665                (or (zerop (gnus-summary-next-thread 1 t))
11666                    (goto-char (point-max))))
11667       (if (and (> (point) start)
11668                ;; FIXME: this should actually search for a non-invisible \n.
11669                (search-backward "\n" start t))
11670           (progn
11671             (when (> (point) starteol)
11672               (gnus-remove-overlays starteol (point) 'invisible 'gnus-sum)
11673               (let ((ol (gnus-make-overlay starteol (point) nil t nil)))
11674                 (gnus-overlay-put ol 'invisible 'gnus-sum)
11675                 (gnus-overlay-put ol 'evaporate t)))
11676             (gnus-summary-goto-subject article)
11677             (when (> start (point))
11678               (message "Hiding the thread moved us backwards, aborting!")
11679               (goto-char (point-max))))
11680         (goto-char start)
11681         nil))))
11682
11683 (defun gnus-summary-go-to-next-thread (&optional previous)
11684   "Go to the same level (or less) next thread.
11685 If PREVIOUS is non-nil, go to previous thread instead.
11686 Return the article number moved to, or nil if moving was impossible."
11687   (let ((level (gnus-summary-thread-level))
11688         (way (if previous -1 1))
11689         (beg (point)))
11690     (forward-line way)
11691     (while (and (not (eobp))
11692                 (< level (gnus-summary-thread-level)))
11693       (forward-line way))
11694     (if (eobp)
11695         (progn
11696           (goto-char beg)
11697           nil)
11698       (setq beg (point))
11699       (prog1
11700           (gnus-summary-article-number)
11701         (goto-char beg)))))
11702
11703 (defun gnus-summary-next-thread (n &optional silent)
11704   "Go to the same level next N'th thread.
11705 If N is negative, search backward instead.
11706 Returns the difference between N and the number of skips actually
11707 done.
11708
11709 If SILENT, don't output messages."
11710   (interactive "p")
11711   (let ((backward (< n 0))
11712         (n (abs n)))
11713     (while (and (> n 0)
11714                 (gnus-summary-go-to-next-thread backward))
11715       (decf n))
11716     (unless silent
11717       (gnus-summary-position-point))
11718     (when (and (not silent) (/= 0 n))
11719       (gnus-message 7 "No more threads"))
11720     n))
11721
11722 (defun gnus-summary-prev-thread (n)
11723   "Go to the same level previous N'th thread.
11724 Returns the difference between N and the number of skips actually
11725 done."
11726   (interactive "p")
11727   (gnus-summary-next-thread (- n)))
11728
11729 (defun gnus-summary-go-down-thread ()
11730   "Go down one level in the current thread."
11731   (let ((children (gnus-summary-article-children)))
11732     (when children
11733       (gnus-summary-goto-subject (car children)))))
11734
11735 (defun gnus-summary-go-up-thread ()
11736   "Go up one level in the current thread."
11737   (let ((parent (gnus-summary-article-parent)))
11738     (when parent
11739       (gnus-summary-goto-subject parent))))
11740
11741 (defun gnus-summary-down-thread (n)
11742   "Go down thread N steps.
11743 If N is negative, go up instead.
11744 Returns the difference between N and how many steps down that were
11745 taken."
11746   (interactive "p")
11747   (let ((up (< n 0))
11748         (n (abs n)))
11749     (while (and (> n 0)
11750                 (if up (gnus-summary-go-up-thread)
11751                   (gnus-summary-go-down-thread)))
11752       (setq n (1- n)))
11753     (gnus-summary-position-point)
11754     (when (/= 0 n)
11755       (gnus-message 7 "Can't go further"))
11756     n))
11757
11758 (defun gnus-summary-up-thread (n)
11759   "Go up thread N steps.
11760 If N is negative, go down instead.
11761 Returns the difference between N and how many steps down that were
11762 taken."
11763   (interactive "p")
11764   (gnus-summary-down-thread (- n)))
11765
11766 (defun gnus-summary-top-thread ()
11767   "Go to the top of the thread."
11768   (interactive)
11769   (while (gnus-summary-go-up-thread))
11770   (gnus-summary-article-number))
11771
11772 (defun gnus-summary-expire-thread ()
11773   "Mark articles under current thread as expired."
11774   (interactive)
11775   (gnus-summary-kill-thread 0))
11776
11777 (defun gnus-summary-kill-thread (&optional unmark)
11778   "Mark articles under current thread as read.
11779 If the prefix argument is positive, remove any kinds of marks.
11780 If the prefix argument is zero, mark thread as expired.
11781 If the prefix argument is negative, tick articles instead."
11782   (interactive "P")
11783   (when unmark
11784     (setq unmark (prefix-numeric-value unmark)))
11785   (let ((articles (gnus-summary-articles-in-thread))
11786         (hide (or (null unmark) (= unmark 0))))
11787     (save-excursion
11788       ;; Expand the thread.
11789       (gnus-summary-show-thread)
11790       ;; Mark all the articles.
11791       (while articles
11792         (gnus-summary-goto-subject (car articles))
11793         (cond ((null unmark)
11794                (gnus-summary-mark-article-as-read gnus-killed-mark))
11795               ((> unmark 0)
11796                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11797               ((= unmark 0)
11798                (gnus-summary-mark-article nil gnus-expirable-mark))
11799               (t
11800                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11801         (setq articles (cdr articles))))
11802     ;; Hide killed subtrees when hide is true.
11803     (and hide
11804          gnus-thread-hide-killed
11805          (gnus-summary-hide-thread))
11806     ;; If hide is t, go to next unread subject.
11807     (when hide
11808       ;; Go to next unread subject.
11809       (gnus-summary-next-subject 1 t)))
11810   (gnus-set-mode-line 'summary))
11811
11812 ;; Summary sorting commands
11813
11814 (defun gnus-summary-sort-by-number (&optional reverse)
11815   "Sort the summary buffer by article number.
11816 Argument REVERSE means reverse order."
11817   (interactive "P")
11818   (gnus-summary-sort 'number reverse))
11819
11820 (defun gnus-summary-sort-by-most-recent-number (&optional reverse)
11821   "Sort the summary buffer by most recent article number.
11822 Argument REVERSE means reverse order."
11823   (interactive "P")
11824   (gnus-summary-sort 'most-recent-number reverse))
11825
11826 (defun gnus-summary-sort-by-random (&optional reverse)
11827   "Randomize the order in the summary buffer.
11828 Argument REVERSE means to randomize in reverse order."
11829   (interactive "P")
11830   (gnus-summary-sort 'random reverse))
11831
11832 (defun gnus-summary-sort-by-author (&optional reverse)
11833   "Sort the summary buffer by author name alphabetically.
11834 If `case-fold-search' is non-nil, case of letters is ignored.
11835 Argument REVERSE means reverse order."
11836   (interactive "P")
11837   (gnus-summary-sort 'author reverse))
11838
11839 (defun gnus-summary-sort-by-recipient (&optional reverse)
11840   "Sort the summary buffer by recipient name alphabetically.
11841 If `case-fold-search' is non-nil, case of letters is ignored.
11842 Argument REVERSE means reverse order."
11843   (interactive "P")
11844   (gnus-summary-sort 'recipient reverse))
11845
11846 (defun gnus-summary-sort-by-subject (&optional reverse)
11847   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11848 If `case-fold-search' is non-nil, case of letters is ignored.
11849 Argument REVERSE means reverse order."
11850   (interactive "P")
11851   (gnus-summary-sort 'subject reverse))
11852
11853 (defun gnus-summary-sort-by-date (&optional reverse)
11854   "Sort the summary buffer by date.
11855 Argument REVERSE means reverse order."
11856   (interactive "P")
11857   (gnus-summary-sort 'date reverse))
11858
11859 (defun gnus-summary-sort-by-most-recent-date (&optional reverse)
11860   "Sort the summary buffer by most recent date.
11861 Argument REVERSE means reverse order."
11862   (interactive "P")
11863   (gnus-summary-sort 'most-recent-date reverse))
11864
11865 (defun gnus-summary-sort-by-score (&optional reverse)
11866   "Sort the summary buffer by score.
11867 Argument REVERSE means reverse order."
11868   (interactive "P")
11869   (gnus-summary-sort 'score reverse))
11870
11871 (defun gnus-summary-sort-by-lines (&optional reverse)
11872   "Sort the summary buffer by the number of lines.
11873 Argument REVERSE means reverse order."
11874   (interactive "P")
11875   (gnus-summary-sort 'lines reverse))
11876
11877 (defun gnus-summary-sort-by-chars (&optional reverse)
11878   "Sort the summary buffer by article length.
11879 Argument REVERSE means reverse order."
11880   (interactive "P")
11881   (gnus-summary-sort 'chars reverse))
11882
11883 (defun gnus-summary-sort-by-original (&optional reverse)
11884   "Sort the summary buffer using the default sorting method.
11885 Argument REVERSE means reverse order."
11886   (interactive "P")
11887   (let* ((inhibit-read-only t)
11888          (gnus-summary-prepare-hook nil))
11889     ;; We do the sorting by regenerating the threads.
11890     (gnus-summary-prepare)
11891     ;; Hide subthreads if needed.
11892     (gnus-summary-maybe-hide-threads)))
11893
11894 (defun gnus-summary-sort (predicate reverse)
11895   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11896   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11897          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11898          (gnus-thread-sort-functions
11899           (if (not reverse)
11900               thread
11901             `(lambda (t1 t2)
11902                (,thread t2 t1))))
11903          (gnus-sort-gathered-threads-function
11904           gnus-thread-sort-functions)
11905          (gnus-article-sort-functions
11906           (if (not reverse)
11907               article
11908             `(lambda (t1 t2)
11909                (,article t2 t1))))
11910          (inhibit-read-only t)
11911          (gnus-summary-prepare-hook nil))
11912     ;; We do the sorting by regenerating the threads.
11913     (gnus-summary-prepare)
11914     ;; Hide subthreads if needed.
11915     (gnus-summary-maybe-hide-threads)))
11916
11917 ;; Summary saving commands.
11918
11919 (defun gnus-summary-save-article (&optional n not-saved)
11920   "Save the current article using the default saver function.
11921 If N is a positive number, save the N next articles.
11922 If N is a negative number, save the N previous articles.
11923 If N is nil and any articles have been marked with the process mark,
11924 save those articles instead.
11925 The variable `gnus-default-article-saver' specifies the saver function.
11926
11927 If the optional second argument NOT-SAVED is non-nil, articles saved
11928 will not be marked as saved."
11929   (interactive "P")
11930   (require 'gnus-art)
11931   (let* ((articles (gnus-summary-work-articles n))
11932          (save-buffer (save-excursion
11933                         (nnheader-set-temp-buffer " *Gnus Save*")))
11934          (num (length articles))
11935          ;; Whether to save decoded articles or raw articles.
11936          (decode (when gnus-article-save-coding-system
11937                    (get gnus-default-article-saver :decode)))
11938          ;; When saving many articles in a single file, use the other
11939          ;; function to save articles other than the first one.
11940          (saver2 (get gnus-default-article-saver :function))
11941          (gnus-prompt-before-saving (if saver2
11942                                         t
11943                                       gnus-prompt-before-saving))
11944          (gnus-default-article-saver gnus-default-article-saver)
11945          header file)
11946     (dolist (article articles)
11947       (setq header (gnus-summary-article-header article))
11948       (if (not (vectorp header))
11949           ;; This is a pseudo-article.
11950           (if (assq 'name header)
11951               (gnus-copy-file (cdr (assq 'name header)))
11952             (gnus-message 1 "Article %d is unsavable" article))
11953         ;; This is a real article.
11954         (save-window-excursion
11955           (gnus-summary-select-article decode decode nil article)
11956           (gnus-summary-goto-subject article))
11957         (with-current-buffer save-buffer
11958           (erase-buffer)
11959           (insert-buffer-substring (if decode
11960                                        gnus-article-buffer
11961                                      gnus-original-article-buffer)))
11962         (setq file (gnus-article-save save-buffer file num))
11963         (gnus-summary-remove-process-mark article)
11964         (unless not-saved
11965           (gnus-summary-set-saved-mark article)))
11966       (when saver2
11967         (setq gnus-default-article-saver saver2
11968               saver2 nil)))
11969     (gnus-kill-buffer save-buffer)
11970     (gnus-summary-position-point)
11971     (gnus-set-mode-line 'summary)
11972     n))
11973
11974 (defun gnus-summary-pipe-output (&optional n sym)
11975   "Pipe the current article to a subprocess.
11976 If N is a positive number, pipe the N next articles.
11977 If N is a negative number, pipe the N previous articles.
11978 If N is nil and any articles have been marked with the process mark,
11979 pipe those articles instead.
11980 The default command to which articles are piped is specified by the
11981 variable `gnus-summary-pipe-output-default-command'; if it is nil, you
11982 will be prompted for the command.
11983
11984 The properties `:decode' and `:headers' that are put to the function
11985 symbol `gnus-summary-save-in-pipe' control whether this function
11986 decodes articles and what headers to keep (see the doc string for the
11987 `gnus-default-article-saver' variable).  If SYM (the symbolic prefix)
11988 is neither omitted nor the symbol `r', force including all headers
11989 regardless of the `:headers' property.  If it is the symbol `r',
11990 articles that are not decoded and include all headers will be piped
11991 no matter what the properties `:decode' and `:headers' are."
11992   (interactive (gnus-interactive "P\ny"))
11993   (require 'gnus-art)
11994   (let* ((articles (gnus-summary-work-articles n))
11995          (result-buffer "*Shell Command Output*")
11996          (all-headers (not (memq sym '(nil r))))
11997          (gnus-save-all-headers (or all-headers gnus-save-all-headers))
11998          (raw (eq sym 'r))
11999          (headers (get 'gnus-summary-save-in-pipe :headers))
12000          command result)
12001     (unless (numberp (car articles))
12002       (error "No article to pipe"))
12003     (setq command (gnus-read-shell-command
12004                    (concat "Shell command on "
12005                            (if (cdr articles)
12006                                (format "these %d articles" (length articles))
12007                              "this article")
12008                            ": ")
12009                    gnus-summary-pipe-output-default-command))
12010     (when (string-equal command "")
12011       (error "A command is required"))
12012     (when all-headers
12013       (put 'gnus-summary-save-in-pipe :headers nil))
12014     (unwind-protect
12015         (while articles
12016           (gnus-summary-goto-subject (pop articles))
12017           (save-window-excursion (gnus-summary-save-in-pipe command raw))
12018           (when (and (get-buffer result-buffer)
12019                      (not (zerop (buffer-size (get-buffer result-buffer)))))
12020             (setq result (concat result (with-current-buffer result-buffer
12021                                           (buffer-string))))))
12022       (put 'gnus-summary-save-in-pipe :headers headers))
12023     (unless (zerop (length result))
12024       (if (with-current-buffer (get-buffer-create result-buffer)
12025             (erase-buffer)
12026             (insert result)
12027             (prog1
12028                 (and (= (count-lines (point-min) (point)) 1)
12029                      (progn
12030                        (end-of-line 0)
12031                        (<= (current-column)
12032                            (window-width (minibuffer-window)))))
12033               (goto-char (point-min))))
12034           (message "%s" (substring result 0 -1))
12035         (message nil)
12036         (gnus-configure-windows 'pipe)))))
12037
12038 (defun gnus-summary-save-article-mail (&optional arg)
12039   "Append the current article to a Unix mail box file.
12040 If N is a positive number, save the N next articles.
12041 If N is a negative number, save the N previous articles.
12042 If N is nil and any articles have been marked with the process mark,
12043 save those articles instead."
12044   (interactive "P")
12045   (require 'gnus-art)
12046   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
12047     (gnus-summary-save-article arg)))
12048
12049 (defun gnus-summary-save-article-rmail (&optional arg)
12050   "Append the current article to an rmail file.
12051 If N is a positive number, save the N next articles.
12052 If N is a negative number, save the N previous articles.
12053 If N is nil and any articles have been marked with the process mark,
12054 save those articles instead."
12055   (interactive "P")
12056   (require 'gnus-art)
12057   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
12058     (gnus-summary-save-article arg)))
12059
12060 (defun gnus-summary-save-article-file (&optional arg)
12061   "Append the current article to a file.
12062 If N is a positive number, save the N next articles.
12063 If N is a negative number, save the N previous articles.
12064 If N is nil and any articles have been marked with the process mark,
12065 save those articles instead."
12066   (interactive "P")
12067   (require 'gnus-art)
12068   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
12069     (gnus-summary-save-article arg)))
12070
12071 (defun gnus-summary-write-article-file (&optional arg)
12072   "Write the current article to a file, deleting the previous file.
12073 If N is a positive number, save the N next articles.
12074 If N is a negative number, save the N previous articles.
12075 If N is nil and any articles have been marked with the process mark,
12076 save those articles instead."
12077   (interactive "P")
12078   (require 'gnus-art)
12079   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
12080     (gnus-summary-save-article arg)))
12081
12082 (defun gnus-summary-save-article-body-file (&optional arg)
12083   "Append the current article body to a file.
12084 If N is a positive number, save the N next articles.
12085 If N is a negative number, save the N previous articles.
12086 If N is nil and any articles have been marked with the process mark,
12087 save those articles instead."
12088   (interactive "P")
12089   (require 'gnus-art)
12090   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
12091     (gnus-summary-save-article arg)))
12092
12093 (defun gnus-summary-write-article-body-file (&optional arg)
12094   "Write the current article body to a file, deleting the previous file.
12095 If N is a positive number, save the N next articles.
12096 If N is a negative number, save the N previous articles.
12097 If N is nil and any articles have been marked with the process mark,
12098 save those articles instead."
12099   (interactive "P")
12100   (require 'gnus-art)
12101   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
12102     (gnus-summary-save-article arg)))
12103
12104 (defun gnus-summary-muttprint (&optional arg)
12105   "Print the current article using Muttprint.
12106 If N is a positive number, save the N next articles.
12107 If N is a negative number, save the N previous articles.
12108 If N is nil and any articles have been marked with the process mark,
12109 save those articles instead."
12110   (interactive "P")
12111   (require 'gnus-art)
12112   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
12113     (gnus-summary-save-article arg t)))
12114
12115 (defun gnus-summary-pipe-message (program)
12116   "Pipe the current article through PROGRAM."
12117   (interactive "sProgram: ")
12118   (gnus-summary-select-article)
12119   (let ((mail-header-separator ""))
12120     (gnus-eval-in-buffer-window gnus-article-buffer
12121       (save-restriction
12122         (widen)
12123         (let ((start (window-start))
12124               (inhibit-read-only t))
12125           (message-pipe-buffer-body program)
12126           (set-window-start (get-buffer-window (current-buffer)) start))))))
12127
12128 (defun gnus-get-split-value (methods)
12129   "Return a value based on the split METHODS."
12130   (let (split-name method result match)
12131     (when methods
12132       (with-current-buffer gnus-original-article-buffer
12133         (save-restriction
12134           (nnheader-narrow-to-headers)
12135           (while (and methods (not split-name))
12136             (goto-char (point-min))
12137             (setq method (pop methods))
12138             (setq match (car method))
12139             (when (cond
12140                    ((stringp match)
12141                     ;; Regular expression.
12142                     (ignore-errors
12143                       (re-search-forward match nil t)))
12144                    ((functionp match)
12145                     ;; Function.
12146                     (save-restriction
12147                       (widen)
12148                       (setq result (funcall match gnus-newsgroup-name))))
12149                    ((consp match)
12150                     ;; Form.
12151                     (save-restriction
12152                       (widen)
12153                       (setq result (eval match)))))
12154               (setq split-name (cdr method))
12155               (cond ((stringp result)
12156                      (push (expand-file-name
12157                             result gnus-article-save-directory)
12158                            split-name))
12159                     ((consp result)
12160                      (setq split-name (append result split-name)))))))))
12161     (nreverse split-name)))
12162
12163 (defun gnus-valid-move-group-p (group)
12164   (and (symbolp group)
12165        (boundp group)
12166        (symbol-name group)
12167        (symbol-value group)
12168        (gnus-get-function (gnus-find-method-for-group
12169                            (symbol-name group)) 'request-accept-article t)))
12170
12171 (defun gnus-read-move-group-name (prompt default articles prefix)
12172   "Read a group name."
12173   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
12174          (minibuffer-confirm-incomplete nil) ; XEmacs
12175          (prom
12176           (format "%s %s to"
12177                   prompt
12178                   (if (> (length articles) 1)
12179                       (format "these %d articles" (length articles))
12180                     "this article")))
12181          (to-newsgroup
12182           (cond
12183            ((null split-name)
12184             (gnus-group-completing-read
12185              prom
12186              (gnus-remove-if-not 'gnus-valid-move-group-p gnus-active-hashtb t)
12187              nil prefix nil default))
12188            ((= 1 (length split-name))
12189             (gnus-group-completing-read
12190              prom
12191              (gnus-remove-if-not 'gnus-valid-move-group-p gnus-active-hashtb t)
12192              nil prefix 'gnus-group-history (car split-name)))
12193            (t
12194             (gnus-completing-read
12195              prom (nreverse split-name) nil nil 'gnus-group-history))))
12196          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
12197          encoded)
12198     (when to-newsgroup
12199       (if (or (string= to-newsgroup "")
12200               (string= to-newsgroup prefix))
12201           (setq to-newsgroup default))
12202       (unless to-newsgroup
12203         (error "No group name entered"))
12204       (setq encoded (mm-encode-coding-string
12205                      to-newsgroup
12206                      (gnus-group-name-charset to-method to-newsgroup)))
12207       (or (gnus-active encoded)
12208           (gnus-activate-group encoded nil nil to-method)
12209           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
12210                                      to-newsgroup))
12211               (or (and (gnus-request-create-group encoded to-method)
12212                        (gnus-activate-group encoded nil nil to-method)
12213                        (gnus-subscribe-group encoded))
12214                   (error "Couldn't create group %s" to-newsgroup)))
12215           (error "No such group: %s" to-newsgroup))
12216       encoded)))
12217
12218 (defvar gnus-summary-save-parts-counter)
12219 (declare-function mm-uu-dissect "mm-uu" (&optional noheader mime-type))
12220
12221 (defun gnus-summary-save-parts (type dir n &optional reverse)
12222   "Save parts matching TYPE to DIR.
12223 If REVERSE, save parts that do not match TYPE."
12224   (interactive
12225    (list (read-string "Save parts of type: "
12226                       (or (car gnus-summary-save-parts-type-history)
12227                           gnus-summary-save-parts-default-mime)
12228                       'gnus-summary-save-parts-type-history)
12229          (setq gnus-summary-save-parts-last-directory
12230                (read-directory-name "Save to directory: "
12231                                     gnus-summary-save-parts-last-directory
12232                                     nil t))
12233          current-prefix-arg))
12234   (gnus-summary-iterate n
12235     (let ((gnus-display-mime-function nil)
12236           gnus-article-prepare-hook
12237           gnus-article-decode-hook
12238           gnus-display-mime-function
12239           gnus-break-pages
12240           (gnus-inhibit-treatment t))
12241       (gnus-summary-select-article))
12242     (with-current-buffer gnus-article-buffer
12243       (let ((handles (or gnus-article-mime-handles
12244                          (mm-dissect-buffer nil gnus-article-loose-mime)
12245                          (and gnus-article-emulate-mime
12246                               (mm-uu-dissect))))
12247             (gnus-summary-save-parts-counter 1))
12248         (when handles
12249           (gnus-summary-save-parts-1 type dir handles reverse)
12250           (unless gnus-article-mime-handles ;; Don't destroy this case.
12251             (mm-destroy-parts handles)))))))
12252
12253 (defun gnus-summary-save-parts-1 (type dir handle reverse)
12254   (if (stringp (car handle))
12255       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
12256               (cdr handle))
12257     (when (if reverse
12258               (not (string-match type (mm-handle-media-type handle)))
12259             (string-match type (mm-handle-media-type handle)))
12260       (let ((file (expand-file-name
12261                    (gnus-map-function
12262                     mm-file-name-rewrite-functions
12263                     (file-name-nondirectory
12264                      (or
12265                       (mm-handle-filename handle)
12266                       (format "%s.%d.%d" gnus-newsgroup-name
12267                               (cdr gnus-article-current)
12268                               gnus-summary-save-parts-counter))))
12269                    dir)))
12270         (incf gnus-summary-save-parts-counter)
12271         (unless (file-exists-p file)
12272           (mm-save-part-to-file handle file))))))
12273
12274 ;; Summary extract commands
12275
12276 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
12277   (let ((inhibit-read-only t)
12278         (article (gnus-summary-article-number))
12279         after-article b e)
12280     (unless (gnus-summary-goto-subject article)
12281       (error "No such article: %d" article))
12282     (gnus-summary-position-point)
12283     ;; If all commands are to be bunched up on one line, we collect
12284     ;; them here.
12285     (unless gnus-view-pseudos-separately
12286       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
12287             files action)
12288         (while ps
12289           (setq action (cdr (assq 'action (car ps))))
12290           (setq files (list (cdr (assq 'name (car ps)))))
12291           (while (and ps (cdr ps)
12292                       (string= (or action "1")
12293                                (or (cdr (assq 'action (cadr ps))) "2")))
12294             (push (cdr (assq 'name (cadr ps))) files)
12295             (setcdr ps (cddr ps)))
12296           (when files
12297             (when (not (string-match "%s" action))
12298               (push " " files))
12299             (push " " files)
12300             (when (assq 'execute (car ps))
12301               (setcdr (assq 'execute (car ps))
12302                       (funcall (if (string-match "%s" action)
12303                                    'format 'concat)
12304                                action
12305                                (mapconcat
12306                                 (lambda (f)
12307                                   (if (equal f " ")
12308                                       f
12309                                     (shell-quote-argument f)))
12310                                 files " ")))))
12311           (setq ps (cdr ps)))))
12312     (if (and gnus-view-pseudos (not not-view))
12313         (while pslist
12314           (when (assq 'execute (car pslist))
12315             (gnus-execute-command (cdr (assq 'execute (car pslist)))
12316                                   (eq gnus-view-pseudos 'not-confirm)))
12317           (setq pslist (cdr pslist)))
12318       (save-excursion
12319         (while pslist
12320           (setq after-article (or (cdr (assq 'article (car pslist)))
12321                                   (gnus-summary-article-number)))
12322           (gnus-summary-goto-subject after-article)
12323           (forward-line 1)
12324           (setq b (point))
12325           (insert "    " (file-name-nondirectory
12326                           (cdr (assq 'name (car pslist))))
12327                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
12328           (setq e (point))
12329           (forward-line -1)             ; back to `b'
12330           (gnus-add-text-properties
12331            b (1- e) (list 'gnus-number gnus-reffed-article-number
12332                           gnus-mouse-face-prop gnus-mouse-face))
12333           (gnus-data-enter
12334            after-article gnus-reffed-article-number
12335            gnus-unread-mark b (car pslist) 0 (- e b))
12336           (setq gnus-newsgroup-unreads
12337                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
12338                                          gnus-reffed-article-number))
12339           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
12340           (setq pslist (cdr pslist)))))))
12341
12342 (defun gnus-pseudos< (p1 p2)
12343   (let ((c1 (cdr (assq 'action p1)))
12344         (c2 (cdr (assq 'action p2))))
12345     (and c1 c2 (string< c1 c2))))
12346
12347 (defun gnus-request-pseudo-article (props)
12348   (cond ((assq 'execute props)
12349          (gnus-execute-command (cdr (assq 'execute props)))))
12350   (let ((gnus-current-article (gnus-summary-article-number)))
12351     (gnus-run-hooks 'gnus-mark-article-hook)))
12352
12353 (defun gnus-execute-command (command &optional automatic)
12354   (save-excursion
12355     (gnus-article-setup-buffer)
12356     (set-buffer gnus-article-buffer)
12357     (setq buffer-read-only nil)
12358     (let ((command (if automatic command
12359                      (read-string "Command: " (cons command 0)))))
12360       (erase-buffer)
12361       (insert "$ " command "\n\n")
12362       (if gnus-view-pseudo-asynchronously
12363           (start-process "gnus-execute" (current-buffer) shell-file-name
12364                          shell-command-switch command)
12365         (call-process shell-file-name nil t nil
12366                       shell-command-switch command)))))
12367
12368 ;; Summary kill commands.
12369
12370 (defun gnus-summary-edit-global-kill (article)
12371   "Edit the \"global\" kill file."
12372   (interactive (list (gnus-summary-article-number)))
12373   (gnus-group-edit-global-kill article))
12374
12375 (defun gnus-summary-edit-local-kill ()
12376   "Edit a local kill file applied to the current newsgroup."
12377   (interactive)
12378   (setq gnus-current-headers (gnus-summary-article-header))
12379   (gnus-group-edit-local-kill
12380    (gnus-summary-article-number) gnus-newsgroup-name))
12381
12382 ;;; Header reading.
12383
12384 (defun gnus-read-header (id &optional header)
12385   "Read the headers of article ID and enter them into the Gnus system."
12386   (let ((group gnus-newsgroup-name)
12387         (gnus-override-method
12388          (or
12389           gnus-override-method
12390           (and (gnus-news-group-p gnus-newsgroup-name)
12391                (car (gnus-refer-article-methods)))))
12392         where)
12393     ;; First we check to see whether the header in question is already
12394     ;; fetched.
12395     (if (stringp id)
12396         ;; This is a Message-ID.
12397         (setq header (or header (gnus-id-to-header id)))
12398       ;; This is an article number.
12399       (setq header (or header (gnus-summary-article-header id))))
12400     (if (and header
12401              (not (gnus-summary-article-sparse-p (mail-header-number header))))
12402         ;; We have found the header.
12403         header
12404       ;; We have to really fetch the header to this article.
12405       (with-current-buffer nntp-server-buffer
12406         (when (setq where (gnus-request-head id group))
12407           (nnheader-fold-continuation-lines)
12408           (goto-char (point-max))
12409           (insert ".\n")
12410           (goto-char (point-min))
12411           (insert "211 ")
12412           (princ (cond
12413                   ((numberp id) id)
12414                   ((cdr where) (cdr where))
12415                   (header (mail-header-number header))
12416                   (t gnus-reffed-article-number))
12417                  (current-buffer))
12418           (insert " Article retrieved.\n"))
12419         (if (or (not where)
12420                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
12421             ()                          ; Malformed head.
12422           (unless (gnus-summary-article-sparse-p (mail-header-number header))
12423             (when (and (bound-and-true-p gnus-registry-enabled)
12424                        (not (gnus-ephemeral-group-p (car where))))
12425               (gnus-registry-handle-action
12426                (mail-header-id header) nil
12427                (gnus-group-prefixed-name (car where) gnus-override-method)
12428                (mail-header-subject header)
12429                (mail-header-from header)))
12430             (when (and (stringp id)
12431                        (or
12432                         (not (string= (gnus-group-real-name group)
12433                                       (car where)))
12434                         (not (gnus-server-equal gnus-override-method
12435                                                 (gnus-group-method group)))))
12436               ;; If we fetched by Message-ID and the article came from
12437               ;; a different group (or server), we fudge some bogus
12438               ;; article numbers for this article.
12439               (mail-header-set-number header gnus-reffed-article-number))
12440             (with-current-buffer gnus-summary-buffer
12441               (decf gnus-reffed-article-number)
12442               (gnus-remove-header (mail-header-number header))
12443               (push header gnus-newsgroup-headers)
12444               (setq gnus-current-headers header)
12445               (push (mail-header-number header) gnus-newsgroup-limit)))
12446           header)))))
12447
12448 (defun gnus-remove-header (number)
12449   "Remove header NUMBER from `gnus-newsgroup-headers'."
12450   (if (and gnus-newsgroup-headers
12451            (= number (mail-header-number (car gnus-newsgroup-headers))))
12452       (pop gnus-newsgroup-headers)
12453     (let ((headers gnus-newsgroup-headers))
12454       (while (and (cdr headers)
12455                   (not (= number (mail-header-number (cadr headers)))))
12456         (pop headers))
12457       (when (cdr headers)
12458         (setcdr headers (cddr headers))))))
12459
12460 ;;;
12461 ;;; summary highlights
12462 ;;;
12463
12464 (defun gnus-highlight-selected-summary ()
12465   "Highlight selected article in summary buffer."
12466   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12467   (when gnus-summary-selected-face
12468     (save-excursion
12469       (let* ((beg (point-at-bol))
12470              (end (point-at-eol))
12471              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12472              (from (if (get-text-property beg gnus-mouse-face-prop)
12473                        beg
12474                      (or (next-single-property-change
12475                           beg gnus-mouse-face-prop nil end)
12476                          beg)))
12477              (to
12478               (if (= from end)
12479                   (- from 2)
12480                 (or (next-single-property-change
12481                      from gnus-mouse-face-prop nil end)
12482                     end))))
12483         ;; If no mouse-face prop on line we will have to = from = end,
12484         ;; so we highlight the entire line instead.
12485         (when (= (+ to 2) from)
12486           (setq from beg)
12487           (setq to end))
12488         (if gnus-newsgroup-selected-overlay
12489             ;; Move old overlay.
12490             (gnus-move-overlay
12491              gnus-newsgroup-selected-overlay from to (current-buffer))
12492           ;; Create new overlay.
12493           (gnus-overlay-put
12494            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12495            'face gnus-summary-selected-face))))))
12496
12497 (defvar gnus-summary-highlight-line-cached nil)
12498 (defvar gnus-summary-highlight-line-trigger nil)
12499
12500 (defun gnus-summary-highlight-line-0 ()
12501   (if (and (eq gnus-summary-highlight-line-trigger
12502                gnus-summary-highlight)
12503            gnus-summary-highlight-line-cached)
12504       gnus-summary-highlight-line-cached
12505     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12506           gnus-summary-highlight-line-cached
12507           (let* ((cond (list 'cond))
12508                  (c cond)
12509                  (list gnus-summary-highlight))
12510             (while list
12511               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12512                               nil))
12513               (setq c (cdr c)
12514                     list (cdr list)))
12515             (gnus-byte-compile (list 'lambda nil cond))))))
12516
12517 (defun gnus-summary-highlight-line ()
12518   "Highlight current line according to `gnus-summary-highlight'."
12519   (let* ((beg (point-at-bol))
12520          (article (or (gnus-summary-article-number) gnus-current-article))
12521          (score (or (cdr (assq article
12522                                gnus-newsgroup-scored))
12523                     gnus-summary-default-score 0))
12524          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12525          (inhibit-read-only t)
12526          (default gnus-summary-default-score)
12527          (default-high gnus-summary-default-high-score)
12528          (default-low gnus-summary-default-low-score)
12529          (uncached (and gnus-summary-use-undownloaded-faces
12530                         (memq article gnus-newsgroup-undownloaded)
12531                         (not (memq article gnus-newsgroup-cached)))))
12532     (let ((face (funcall (gnus-summary-highlight-line-0))))
12533       (unless (eq face (gnus-get-text-property-excluding-characters-with-faces beg 'face))
12534         (gnus-put-text-property-excluding-characters-with-faces
12535          beg (point-at-eol) 'face
12536          (setq face (if (boundp face) (symbol-value face) face)))
12537         (when gnus-summary-highlight-line-function
12538           (funcall gnus-summary-highlight-line-function article face))))))
12539
12540 (defun gnus-update-read-articles (group unread &optional compute)
12541   "Update the list of read articles in GROUP.
12542 UNREAD is a sorted list."
12543   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12544         (info (gnus-get-info group))
12545         (prev 1)
12546         read)
12547     (if (or (not info) (not active))
12548         ;; There is no info on this group if it was, in fact,
12549         ;; killed.  Gnus stores no information on killed groups, so
12550         ;; there's nothing to be done.
12551         ;; One could store the information somewhere temporarily,
12552         ;; perhaps...  Hmmm...
12553         ()
12554       ;; Remove any negative articles numbers.
12555       (while (and unread (< (car unread) 0))
12556         (setq unread (cdr unread)))
12557       ;; Remove any expired article numbers
12558       (while (and unread (< (car unread) (car active)))
12559         (setq unread (cdr unread)))
12560       ;; Compute the ranges of read articles by looking at the list of
12561       ;; unread articles.
12562       (while unread
12563         (when (/= (car unread) prev)
12564           (push (if (= prev (1- (car unread))) prev
12565                   (cons prev (1- (car unread))))
12566                 read))
12567         (setq prev (1+ (car unread)))
12568         (setq unread (cdr unread)))
12569       (when (<= prev (cdr active))
12570         (push (cons prev (cdr active)) read))
12571       (setq read (if (> (length read) 1) (nreverse read) read))
12572       (if compute
12573           read
12574         (save-excursion
12575           (let (setmarkundo)
12576             ;; Propagate the read marks to the backend.
12577             (when (and (gnus-method-option-p
12578                         (gnus-find-method-for-group group)
12579                         'server-marks)
12580                        (gnus-check-backend-function 'request-set-mark group))
12581               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12582                     (add (gnus-remove-from-range read (gnus-info-read info))))
12583                 (when (or add del)
12584                   (unless (gnus-check-group group)
12585                     (error "Can't open server for %s" group))
12586                   (gnus-request-set-mark
12587                    group (delq nil (list (if add (list add 'add '(read)))
12588                                          (if del (list del 'del '(read))))))
12589                   (setq setmarkundo
12590                         `(gnus-request-set-mark
12591                           ,group
12592                           ',(delq nil (list
12593                                        (if del (list del 'add '(read)))
12594                                        (if add (list add 'del '(read))))))))))
12595             (set-buffer gnus-group-buffer)
12596             (gnus-undo-register
12597               `(progn
12598                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12599                  (gnus-info-set-read ',info ',(gnus-info-read info))
12600                  (gnus-get-unread-articles-in-group ',info
12601                                                     (gnus-active ,group))
12602                  (gnus-group-update-group ,group t)
12603                  ,setmarkundo))))
12604         ;; Enter this list into the group info.
12605         (gnus-info-set-read info read)
12606         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12607         (gnus-get-unread-articles-in-group info (gnus-active group))
12608         t))))
12609
12610 (defun gnus-offer-save-summaries ()
12611   "Offer to save all active summary buffers."
12612   (let (buffers)
12613     ;; Go through all buffers and find all summaries.
12614     (dolist (buffer (buffer-list))
12615       (when (and (setq buffer (buffer-name buffer))
12616                  (string-match "Summary" buffer)
12617                  (with-current-buffer buffer
12618                    ;; We check that this is, indeed, a summary buffer.
12619                    (and (eq major-mode 'gnus-summary-mode)
12620                         ;; Also make sure this isn't bogus.
12621                         gnus-newsgroup-prepared
12622                         ;; Also make sure that this isn't a
12623                         ;; dead summary buffer.
12624                         (not gnus-dead-summary-mode))))
12625         (push buffer buffers)))
12626     ;; Go through all these summary buffers and offer to save them.
12627     (when buffers
12628       (save-excursion
12629         (if (eq gnus-interactive-exit 'quiet)
12630             (dolist (buffer buffers)
12631               (switch-to-buffer buffer)
12632               (gnus-summary-exit))
12633           (map-y-or-n-p
12634            "Update summary buffer %s? "
12635            (lambda (buf)
12636              (switch-to-buffer buf)
12637              (gnus-summary-exit))
12638            buffers))))))
12639
12640 (defun gnus-summary-setup-default-charset ()
12641   "Setup newsgroup default charset."
12642   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12643       (setq gnus-newsgroup-charset nil)
12644     (let* ((ignored-charsets
12645             (or gnus-newsgroup-ephemeral-ignored-charsets
12646                 (append
12647                  (and gnus-newsgroup-name
12648                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12649                  gnus-newsgroup-ignored-charsets))))
12650       (setq gnus-newsgroup-charset
12651             (or gnus-newsgroup-ephemeral-charset
12652                 (and gnus-newsgroup-name
12653                      (gnus-parameter-charset gnus-newsgroup-name))
12654                 gnus-default-charset))
12655       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12656            ignored-charsets))))
12657
12658 ;;;
12659 ;;; Mime Commands
12660 ;;;
12661
12662 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12663   "Display the current article buffer fully MIME-buttonized.
12664 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12665 treated as multipart/mixed."
12666   (interactive "P")
12667   (require 'gnus-art)
12668   (let ((gnus-unbuttonized-mime-types nil)
12669         (gnus-mime-display-multipart-as-mixed show-all-parts))
12670     (gnus-summary-show-article)))
12671
12672 (defun gnus-summary-repair-multipart (article)
12673   "Add a Content-Type header to a multipart article without one."
12674   (interactive (list (gnus-summary-article-number)))
12675   (gnus-with-article article
12676     (message-narrow-to-head)
12677     (message-remove-header "Mime-Version")
12678     (goto-char (point-max))
12679     (insert "Mime-Version: 1.0\n")
12680     (widen)
12681     (when (search-forward "\n--" nil t)
12682       (let ((separator (buffer-substring (point) (point-at-eol))))
12683         (message-narrow-to-head)
12684         (message-remove-header "Content-Type")
12685         (goto-char (point-max))
12686         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12687                         separator))
12688         (widen))))
12689   (let (gnus-mark-article-hook)
12690     (gnus-summary-select-article t t nil article)))
12691
12692 (defun gnus-summary-toggle-display-buttonized ()
12693   "Toggle the buttonizing of the article buffer."
12694   (interactive)
12695   (require 'gnus-art)
12696   (if (setq gnus-inhibit-mime-unbuttonizing
12697             (not gnus-inhibit-mime-unbuttonizing))
12698       (let ((gnus-unbuttonized-mime-types nil))
12699         (gnus-summary-show-article))
12700     (gnus-summary-show-article)))
12701
12702 ;;;
12703 ;;; Generic summary marking commands
12704 ;;;
12705
12706 (defvar gnus-summary-marking-alist
12707   '((read gnus-del-mark "d")
12708     (unread gnus-unread-mark "u")
12709     (ticked gnus-ticked-mark "!")
12710     (dormant gnus-dormant-mark "?")
12711     (expirable gnus-expirable-mark "e"))
12712   "An alist of names/marks/keystrokes.")
12713
12714 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12715 (defvar gnus-summary-mark-map)
12716
12717 (defun gnus-summary-make-all-marking-commands ()
12718   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12719   (dolist (elem gnus-summary-marking-alist)
12720     (apply 'gnus-summary-make-marking-command elem)))
12721
12722 (defun gnus-summary-make-marking-command (name mark keystroke)
12723   (let ((map (make-sparse-keymap)))
12724     (define-key gnus-summary-generic-mark-map keystroke map)
12725     (dolist (lway `((next "next" next nil "n")
12726                     (next-unread "next unread" next t "N")
12727                     (prev "previous" prev nil "p")
12728                     (prev-unread "previous unread" prev t "P")
12729                     (nomove "" nil nil ,keystroke)))
12730       (let ((func (gnus-summary-make-marking-command-1
12731                    mark (car lway) lway name)))
12732         (setq func (eval func))
12733         (define-key map (nth 4 lway) func)))))
12734
12735 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12736   `(defun ,(intern
12737             (format "gnus-summary-put-mark-as-%s%s"
12738                     name (if (eq way 'nomove)
12739                              ""
12740                            (concat "-" (symbol-name way)))))
12741      (n)
12742      ,(format
12743        "Mark the current article as %s%s.
12744 If N, the prefix, then repeat N times.
12745 If N is negative, move in reverse order.
12746 The difference between N and the actual number of articles marked is
12747 returned."
12748        name (cadr lway))
12749      (interactive "p")
12750      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12751
12752 (defun gnus-summary-generic-mark (n mark move unread)
12753   "Mark N articles with MARK."
12754   (unless (eq major-mode 'gnus-summary-mode)
12755     (error "This command can only be used in the summary buffer"))
12756   (gnus-summary-show-thread)
12757   (let ((nummove
12758          (cond
12759           ((eq move 'next) 1)
12760           ((eq move 'prev) -1)
12761           (t 0))))
12762     (if (zerop nummove)
12763         (setq n 1)
12764       (when (< n 0)
12765         (setq n (abs n)
12766               nummove (* -1 nummove))))
12767     (while (and (> n 0)
12768                 (gnus-summary-mark-article nil mark)
12769                 (zerop (gnus-summary-next-subject nummove unread t)))
12770       (setq n (1- n)))
12771     (when (/= 0 n)
12772       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12773     (gnus-summary-recenter)
12774     (gnus-summary-position-point)
12775     (gnus-set-mode-line 'summary)
12776     n))
12777
12778 (defun gnus-summary-insert-articles (articles)
12779   (when (setq articles
12780               (gnus-sorted-difference articles
12781                                       (mapcar (lambda (h)
12782                                                 (mail-header-number h))
12783                                               gnus-newsgroup-headers)))
12784     (setq gnus-newsgroup-headers
12785           (gnus-merge 'list
12786                       gnus-newsgroup-headers
12787                       (gnus-fetch-headers articles)
12788                       'gnus-article-sort-by-number))
12789     (setq gnus-newsgroup-articles
12790           (gnus-sorted-nunion gnus-newsgroup-articles articles))
12791     ;; Suppress duplicates?
12792     (when gnus-suppress-duplicates
12793       (gnus-dup-suppress-articles))
12794
12795     (if (and gnus-fetch-old-headers
12796              (eq gnus-headers-retrieved-by 'nov))
12797         ;; We might want to build some more threads first.
12798         (if (eq gnus-fetch-old-headers 'invisible)
12799             (gnus-build-all-threads)
12800           (gnus-build-old-threads))
12801       ;; Mark the inserted articles that are unread as unread.
12802       (setq gnus-newsgroup-unreads
12803             (gnus-sorted-nunion
12804              gnus-newsgroup-unreads
12805              (gnus-sorted-nintersection
12806               (gnus-list-of-unread-articles gnus-newsgroup-name)
12807               articles)))
12808       ;; Mark the inserted articles as selected so that the information
12809       ;; of the marks having been changed by a user may be updated when
12810       ;; exiting this group.  See `gnus-summary-update-info'.
12811       (dolist (art articles)
12812         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12813     ;; Let the Gnus agent mark articles as read.
12814     (when gnus-agent
12815       (gnus-agent-get-undownloaded-list))
12816     ;; Remove list identifiers from subject
12817     (gnus-summary-remove-list-identifiers)
12818     ;; First and last article in this newsgroup.
12819     (when gnus-newsgroup-headers
12820       (setq gnus-newsgroup-begin
12821             (mail-header-number (car gnus-newsgroup-headers))
12822             gnus-newsgroup-end
12823             (mail-header-number
12824              (gnus-last-element gnus-newsgroup-headers))))
12825     (when gnus-use-scoring
12826       (gnus-possibly-score-headers))))
12827
12828 (defun gnus-summary-insert-old-articles (&optional all)
12829   "Insert all old articles in this group.
12830 If ALL is non-nil, already read articles become readable.
12831 If ALL is a number, fetch this number of articles."
12832   (interactive "P")
12833   (prog1
12834       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12835             older len)
12836         (setq older
12837               ;; Some nntp servers lie about their active range.  When
12838               ;; this happens, the active range can be in the millions.
12839               ;; Use a compressed range to avoid creating a huge list.
12840               (gnus-range-difference
12841                (gnus-range-difference (list gnus-newsgroup-active) old)
12842                gnus-newsgroup-unexist))
12843         (setq len (gnus-range-length older))
12844         (cond
12845          ((null older) nil)
12846          ((numberp all)
12847           (if (< all len)
12848               (let ((older-range (nreverse older)))
12849                 (setq older nil)
12850
12851                 (while (> all 0)
12852                   (let* ((r (pop older-range))
12853                          (min (if (numberp r) r (car r)))
12854                          (max (if (numberp r) r (cdr r))))
12855                     (while (and (<= min max)
12856                                 (> all 0))
12857                       (push max older)
12858                       (setq all (1- all)
12859                             max (1- max))))))
12860             (setq older (gnus-uncompress-range older))))
12861          (all
12862           (setq older (gnus-uncompress-range older)))
12863          (t
12864           (when (and (numberp gnus-large-newsgroup)
12865                    (> len gnus-large-newsgroup))
12866               (let* ((cursor-in-echo-area nil)
12867                      (initial (gnus-parameter-large-newsgroup-initial
12868                                gnus-newsgroup-name))
12869                      (input
12870                       (read-string
12871                        (format
12872                         "How many articles from %s (%s %d): "
12873                         (gnus-group-decoded-name gnus-newsgroup-name)
12874                         (if initial "max" "default")
12875                         len)
12876                        nil nil
12877                        (and initial
12878                             (number-to-string initial)))))
12879                 (unless (string-match "^[ \t]*$" input)
12880                   (setq all (string-to-number input))
12881                   (if (< all len)
12882                       (let ((older-range (nreverse older)))
12883                         (setq older nil)
12884
12885                         (while (> all 0)
12886                           (let* ((r (pop older-range))
12887                                  (min (if (numberp r) r (car r)))
12888                                  (max (if (numberp r) r (cdr r))))
12889                             (while (and (<= min max)
12890                                         (> all 0))
12891                               (push max older)
12892                               (setq all (1- all)
12893                                     max (1- max))))))))))
12894           (setq older (gnus-uncompress-range older))))
12895         (if (not older)
12896             (message "No old news.")
12897           (gnus-summary-insert-articles older)
12898           (gnus-summary-limit (gnus-sorted-nunion old older))))
12899     (gnus-summary-position-point)))
12900
12901 (defun gnus-summary-insert-new-articles ()
12902   "Insert all new articles in this group."
12903   (interactive)
12904   (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12905         (old-high gnus-newsgroup-highest)
12906         (nnmail-fetched-sources (list t))
12907         (new-active (gnus-activate-group gnus-newsgroup-name 'scan))
12908         i new)
12909     (unless new-active
12910       (error "Couldn't fetch new data"))
12911     (setq gnus-newsgroup-active (gnus-copy-sequence new-active))
12912     (setq i (cdr gnus-newsgroup-active)
12913           gnus-newsgroup-highest i)
12914     (while (> i old-high)
12915       (push i new)
12916       (decf i))
12917     (if (not new)
12918         (message "No gnus is bad news")
12919       (gnus-summary-insert-articles new)
12920       (setq gnus-newsgroup-unreads
12921             (gnus-sorted-nunion gnus-newsgroup-unreads new))
12922       (gnus-summary-limit (gnus-sorted-nunion old new))))
12923   (gnus-summary-position-point))
12924
12925 ;;; Bookmark support for Gnus.
12926 (declare-function bookmark-make-record-default
12927                   "bookmark" (&optional no-file no-context posn))
12928 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
12929 (declare-function bookmark-default-handler "bookmark" (bmk))
12930 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
12931 (defvar bookmark-yank-point)
12932 (defvar bookmark-current-buffer)
12933
12934 (defun gnus-summary-bookmark-make-record ()
12935   "Make a bookmark entry for a Gnus summary buffer."
12936   (let (pos buf)
12937     (unless (and (derived-mode-p 'gnus-summary-mode) gnus-article-current)
12938       (save-restriction              ; FIXME is it necessary to widen?
12939         (widen) (setq pos (point))) ; Set position in gnus-article buffer.
12940       (setq buf "art") ; We are recording bookmark from article buffer.
12941       (setq bookmark-yank-point (point))
12942       (setq bookmark-current-buffer (current-buffer))
12943       (gnus-article-show-summary))      ; Go back in summary buffer.
12944     ;; We are now recording bookmark from summary buffer.
12945     (unless buf (setq buf "sum"))
12946     (let* ((subject (elt (gnus-summary-article-header) 1))
12947            (grp     (car gnus-article-current))
12948            (art     (cdr gnus-article-current))
12949            (head    (gnus-summary-article-header art))
12950            (id      (mail-header-id head)))
12951       `(,subject
12952         ,@(condition-case nil
12953               (bookmark-make-record-default 'no-file 'no-context pos)
12954             (wrong-number-of-arguments
12955              (bookmark-make-record-default 'point-only)))
12956         (location . ,(format "Gnus-%s %s:%d:%s" buf grp art id))
12957         (group . ,grp) (article . ,art)
12958         (message-id . ,id) (handler . gnus-summary-bookmark-jump)))))
12959
12960 ;;;###autoload
12961 (defun gnus-summary-bookmark-jump (bookmark)
12962   "Handler function for record returned by `gnus-summary-bookmark-make-record'.
12963 BOOKMARK is a bookmark name or a bookmark record."
12964   (let ((group    (bookmark-prop-get bookmark 'group))
12965         (article  (bookmark-prop-get bookmark 'article))
12966         (id       (bookmark-prop-get bookmark 'message-id))
12967         (buf      (car (split-string (bookmark-prop-get bookmark 'location)))))
12968     (gnus-fetch-group group (list article))
12969     (gnus-summary-insert-cached-articles)
12970     (gnus-summary-goto-article id nil 'force)
12971     ;; FIXME we have to wait article buffer is ready (only large buffer)
12972     ;; Is there a better solution to know that?
12973     ;; If we don't wait `bookmark-default-handler' will have no chance
12974     ;; to set position. However there is no error, just wrong pos.
12975     (sit-for 1)
12976     (when (string= buf "Gnus-art")
12977       (other-window 1))
12978     (bookmark-default-handler
12979      `(""
12980        (buffer . ,(current-buffer))
12981        . ,(bookmark-get-bookmark-record bookmark)))))
12982
12983 (gnus-summary-make-all-marking-commands)
12984
12985 (gnus-ems-redefine)
12986
12987 (provide 'gnus-sum)
12988
12989 (run-hooks 'gnus-sum-load-hook)
12990
12991 ;; Local Variables:
12992 ;; coding: iso-8859-1
12993 ;; End:
12994
12995 ;;; gnus-sum.el ends here