Compile with imagemagick support by default.
[bpt/emacs.git] / lisp / gnus / gnus-sum.el
CommitLineData
eec82323 1;;; gnus-sum.el --- summary mode commands for Gnus
e84b4b86
TTN
2
3;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
114f9c96 4;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
eec82323 5
6748645f 6;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
7;; Keywords: news
8
9;; This file is part of GNU Emacs.
10
5e809f55 11;; GNU Emacs is free software: you can redistribute it and/or modify
eec82323 12;; it under the terms of the GNU General Public License as published by
5e809f55
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
eec82323
LMI
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
01ccbb85 18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eec82323
LMI
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
5e809f55 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
eec82323
LMI
23
24;;; Commentary:
25
26;;; Code:
27
d09ae6ca
GM
28;; For Emacs < 22.2.
29(eval-and-compile
30 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
23f87bed 31(eval-when-compile
9efa445f 32 (require 'cl))
d029b5d2
KY
33(eval-when-compile
34 (when (featurep 'xemacs)
35 (require 'easy-mmode))) ; for `define-minor-mode'
9efa445f
DN
36
37(defvar tool-bar-mode)
38(defvar gnus-tmp-header)
5ab7173c 39
eec82323
LMI
40(require 'gnus)
41(require 'gnus-group)
42(require 'gnus-spec)
43(require 'gnus-range)
44(require 'gnus-int)
45(require 'gnus-undo)
6748645f 46(require 'gnus-util)
18c06a99 47(require 'gmm-utils)
16409b0b 48(require 'mm-decode)
08c9a385 49(require 'nnoo)
23f87bed 50
6748645f 51(autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
d4dfaa19 52(autoload 'gnus-cache-write-active "gnus-cache")
23f87bed
MB
53(autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
54(autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
531e5812 55(autoload 'gnus-pick-line-number "gnus-salt" nil t)
08c9a385 56(autoload 'mm-uu-dissect "mm-uu")
23f87bed
MB
57(autoload 'gnus-article-outlook-deuglify-article "deuglify"
58 "Deuglify broken Outlook (Express) articles and redisplay."
59 t)
60(autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
61(autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
62(autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
eec82323
LMI
63
64(defcustom gnus-kill-summary-on-exit t
65 "*If non-nil, kill the summary buffer when you exit from it.
66If nil, the summary will become a \"*Dead Summary*\" buffer, and
67it will be killed sometime later."
68 :group 'gnus-summary-exit
69 :type 'boolean)
70
01c52d31
MB
71(defcustom gnus-summary-next-group-on-exit t
72 "If non-nil, go to the next unread newsgroup on summary exit.
73See `gnus-group-goto-unread'."
74 :link '(custom-manual "(gnus)Group Maneuvering")
75 :group 'gnus-summary-exit
330f707b 76 :version "23.1" ;; No Gnus
01c52d31
MB
77 :type 'boolean)
78
b1992461
KY
79(defcustom gnus-summary-stop-at-end-of-message nil
80 "If non-nil, don't select the next message when using `SPC'."
81 :link '(custom-manual "(gnus)Group Maneuvering")
82 :group 'gnus-summary-maneuvering
1a10d421 83 :version "24.1"
b1992461
KY
84 :type 'boolean)
85
eec82323
LMI
86(defcustom gnus-fetch-old-headers nil
87 "*Non-nil means that Gnus will try to build threads by grabbing old headers.
01c52d31
MB
88If an unread article in the group refers to an older, already
89read (or just marked as read) article, the old article will not
90normally be displayed in the Summary buffer. If this variable is
91t, Gnus will attempt to grab the headers to the old articles, and
92thereby build complete threads. If it has the value `some', all
93old headers will be fetched but only enough headers to connect
94otherwise loose threads will be displayed. This variable can
95also be a number. In that case, no more than that number of old
96headers will be fetched. If it has the value `invisible', all
6748645f 97old headers will be fetched, but none will be displayed.
eec82323 98
01c52d31
MB
99The server has to support NOV for any of this to work.
100
101This feature can seriously impact performance it ignores all
f394fa25
MB
102locally cached header entries. Setting it to t for groups for a
103server that doesn't expire articles (such as news.gmane.org),
104leads to very slow summary generation."
eec82323
LMI
105 :group 'gnus-thread
106 :type '(choice (const :tag "off" nil)
1232b9cb 107 (const :tag "on" t)
eec82323 108 (const some)
1232b9cb 109 (const invisible)
eec82323
LMI
110 number
111 (sexp :menu-tag "other" t)))
112
01c52d31 113(defcustom gnus-refer-thread-limit 500
6748645f
LMI
114 "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
115If t, fetch all the available old headers."
116 :group 'gnus-thread
117 :type '(choice number
118 (sexp :menu-tag "other" t)))
119
eec82323
LMI
120(defcustom gnus-summary-make-false-root 'adopt
121 "*nil means that Gnus won't gather loose threads.
122If the root of a thread has expired or been read in a previous
123session, the information necessary to build a complete thread has been
124lost. Instead of having many small sub-threads from this original thread
125scattered all over the summary buffer, Gnus can gather them.
126
127If non-nil, Gnus will try to gather all loose sub-threads from an
128original thread into one large thread.
129
130If this variable is non-nil, it should be one of `none', `adopt',
131`dummy' or `empty'.
132
133If this variable is `none', Gnus will not make a false root, but just
134present the sub-threads after another.
135If this variable is `dummy', Gnus will create a dummy root that will
136have all the sub-threads as children.
137If this variable is `adopt', Gnus will make one of the \"children\"
138the parent and mark all the step-children as such.
139If this variable is `empty', the \"children\" are printed with empty
01ccbb85 140subject fields. (Or rather, they will be printed with a string
eec82323
LMI
141given by the `gnus-summary-same-subject' variable.)"
142 :group 'gnus-thread
143 :type '(choice (const :tag "off" nil)
144 (const none)
145 (const dummy)
146 (const adopt)
147 (const empty)))
148
23f87bed
MB
149(defcustom gnus-summary-make-false-root-always nil
150 "Always make a false dummy root."
bf247b6e 151 :version "22.1"
23f87bed
MB
152 :group 'gnus-thread
153 :type 'boolean)
154
eec82323
LMI
155(defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
156 "*A regexp to match subjects to be excluded from loose thread gathering.
157As loose thread gathering is done on subjects only, that means that
158there can be many false gatherings performed. By rooting out certain
159common subjects, gathering might become saner."
160 :group 'gnus-thread
161 :type 'regexp)
162
163(defcustom gnus-summary-gather-subject-limit nil
164 "*Maximum length of subject comparisons when gathering loose threads.
165Use nil to compare full subjects. Setting this variable to a low
166number will help gather threads that have been corrupted by
167newsreaders chopping off subject lines, but it might also mean that
168unrelated articles that have subject that happen to begin with the
169same few characters will be incorrectly gathered.
170
171If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
172comparing subjects."
173 :group 'gnus-thread
174 :type '(choice (const :tag "off" nil)
175 (const fuzzy)
176 (sexp :menu-tag "on" t)))
177
6748645f
LMI
178(defcustom gnus-simplify-subject-functions nil
179 "List of functions taking a string argument that simplify subjects.
180The functions are applied recursively.
181
23f87bed
MB
182Useful functions to put in this list include:
183`gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
184`gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
6748645f
LMI
185 :group 'gnus-thread
186 :type '(repeat function))
187
eec82323 188(defcustom gnus-simplify-ignored-prefixes nil
23f87bed 189 "*Remove matches for this regexp from subject lines when simplifying fuzzily."
eec82323
LMI
190 :group 'gnus-thread
191 :type '(choice (const :tag "off" nil)
192 regexp))
193
194(defcustom gnus-build-sparse-threads nil
195 "*If non-nil, fill in the gaps in threads.
196If `some', only fill in the gaps that are needed to tie loose threads
197together. If `more', fill in all leaf nodes that Gnus can find. If
198non-nil and non-`some', fill in all gaps that Gnus manages to guess."
199 :group 'gnus-thread
200 :type '(choice (const :tag "off" nil)
201 (const some)
202 (const more)
203 (sexp :menu-tag "all" t)))
204
205(defcustom gnus-summary-thread-gathering-function
206 'gnus-gather-threads-by-subject
6748645f 207 "*Function used for gathering loose threads.
eec82323
LMI
208There are two pre-defined functions: `gnus-gather-threads-by-subject',
209which only takes Subjects into consideration; and
210`gnus-gather-threads-by-references', which compared the References
211headers of the articles to find matches."
212 :group 'gnus-thread
22115a9e
RS
213 :type '(radio (function-item gnus-gather-threads-by-subject)
214 (function-item gnus-gather-threads-by-references)
215 (function :tag "other")))
eec82323 216
eec82323
LMI
217(defcustom gnus-summary-same-subject ""
218 "*String indicating that the current article has the same subject as the previous.
219This variable will only be used if the value of
220`gnus-summary-make-false-root' is `empty'."
221 :group 'gnus-summary-format
222 :type 'string)
223
1d297c49 224(defcustom gnus-summary-goto-unread nil
16409b0b
GM
225 "*If t, many commands will go to the next unread article.
226This applies to marking commands as well as other commands that
227\"naturally\" select the next article, like, for instance, `SPC' at
228the end of an article.
229
230If nil, the marking commands do NOT go to the next unread article
2642ac8f 231\(they go to the next article instead). If `never', commands that
16409b0b
GM
232usually go to the next unread article, will go to the next article,
233whether it is read or not."
1d297c49 234 :version "24.1"
eec82323
LMI
235 :group 'gnus-summary-marks
236 :link '(custom-manual "(gnus)Setting Marks")
237 :type '(choice (const :tag "off" nil)
238 (const never)
239 (sexp :menu-tag "on" t)))
240
241(defcustom gnus-summary-default-score 0
242 "*Default article score level.
243All scores generated by the score files will be added to this score.
244If this variable is nil, scoring will be disabled."
245 :group 'gnus-score-default
246 :type '(choice (const :tag "disable")
247 integer))
248
23f87bed
MB
249(defcustom gnus-summary-default-high-score 0
250 "*Default threshold for a high scored article.
251An article will be highlighted as high scored if its score is greater
252than this score."
bf247b6e 253 :version "22.1"
23f87bed
MB
254 :group 'gnus-score-default
255 :type 'integer)
256
257(defcustom gnus-summary-default-low-score 0
258 "*Default threshold for a low scored article.
259An article will be highlighted as low scored if its score is smaller
260than this score."
bf247b6e 261 :version "22.1"
23f87bed
MB
262 :group 'gnus-score-default
263 :type 'integer)
264
eec82323
LMI
265(defcustom gnus-summary-zcore-fuzz 0
266 "*Fuzziness factor for the zcore in the summary buffer.
267Articles with scores closer than this to `gnus-summary-default-score'
268will not be marked."
269 :group 'gnus-summary-format
270 :type 'integer)
271
272(defcustom gnus-simplify-subject-fuzzy-regexp nil
273 "*Strings to be removed when doing fuzzy matches.
274This can either be a regular expression or list of regular expressions
275that will be removed from subject strings if fuzzy subject
276simplification is selected."
277 :group 'gnus-thread
278 :type '(repeat regexp))
279
280(defcustom gnus-show-threads t
281 "*If non-nil, display threads in summary mode."
282 :group 'gnus-thread
283 :type 'boolean)
284
285(defcustom gnus-thread-hide-subtree nil
286 "*If non-nil, hide all threads initially.
23f87bed 287This can be a predicate specifier which says which threads to hide.
eec82323 288If threads are hidden, you have to run the command
4a2358e9 289`gnus-summary-show-thread' by hand or select an article."
eec82323 290 :group 'gnus-thread
23f87bed
MB
291 :type '(radio (sexp :format "Non-nil\n"
292 :match (lambda (widget value)
293 (not (or (consp value) (functionp value))))
294 :value t)
295 (const nil)
ad136a7c 296 (sexp :tag "Predicate specifier")))
eec82323
LMI
297
298(defcustom gnus-thread-hide-killed t
299 "*If non-nil, hide killed threads automatically."
300 :group 'gnus-thread
301 :type 'boolean)
302
6748645f
LMI
303(defcustom gnus-thread-ignore-subject t
304 "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
305If nil, articles that have different subjects from their parents will
306start separate threads."
eec82323
LMI
307 :group 'gnus-thread
308 :type 'boolean)
309
310(defcustom gnus-thread-operation-ignore-subject t
311 "*If non-nil, subjects will be ignored when doing thread commands.
312This affects commands like `gnus-summary-kill-thread' and
313`gnus-summary-lower-thread'.
314
315If this variable is nil, articles in the same thread with different
316subjects will not be included in the operation in question. If this
317variable is `fuzzy', only articles that have subjects that are fuzzily
318equal will be included."
319 :group 'gnus-thread
320 :type '(choice (const :tag "off" nil)
321 (const fuzzy)
322 (sexp :tag "on" t)))
323
324(defcustom gnus-thread-indent-level 4
325 "*Number that says how much each sub-thread should be indented."
326 :group 'gnus-thread
327 :type 'integer)
328
329(defcustom gnus-auto-extend-newsgroup t
330 "*If non-nil, extend newsgroup forward and backward when requested."
331 :group 'gnus-summary-choose
332 :type 'boolean)
333
334(defcustom gnus-auto-select-first t
651408cb
MB
335 "If non-nil, select an article on group entry.
336An article is selected automatically when entering a group
337e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
338`gnus-summary-catchup-and-goto-next-group'.
339
340Which article is selected is controlled by the variable
341`gnus-auto-select-subject'.
23f87bed
MB
342
343If you want to prevent automatic selection of articles in some
344newsgroups, set the variable to nil in `gnus-select-group-hook'."
651408cb
MB
345 ;; Commands include...
346 ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
347 ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
348 ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
eec82323
LMI
349 :group 'gnus-group-select
350 :type '(choice (const :tag "none" nil)
23f87bed
MB
351 (sexp :menu-tag "first" t)))
352
a1347097 353(defcustom gnus-auto-select-subject 'unseen-or-unread
23f87bed
MB
354 "*Says what subject to place under point when entering a group.
355
356This variable can either be the symbols `first' (place point on the
357first subject), `unread' (place point on the subject line of the first
358unread article), `best' (place point on the subject line of the
359higest-scored article), `unseen' (place point on the subject line of
99b5aab7 360the first unseen article), `unseen-or-unread' (place point on the subject
23f87bed
MB
361line of the first unseen article or, if all article have been seen, on the
362subject line of the first unread article), or a function to be called to
363place point on some subject line."
a1347097 364 :version "24.1"
23f87bed
MB
365 :group 'gnus-group-select
366 :type '(choice (const best)
367 (const unread)
368 (const first)
369 (const unseen)
370 (const unseen-or-unread)))
eec82323
LMI
371
372(defcustom gnus-auto-select-next t
373 "*If non-nil, offer to go to the next group from the end of the previous.
374If the value is t and the next newsgroup is empty, Gnus will exit
23f87bed
MB
375summary mode and go back to group mode. If the value is neither nil
376nor t, Gnus will select the following unread newsgroup. In
eec82323
LMI
377particular, if the value is the symbol `quietly', the next unread
378newsgroup will be selected without any confirmation, and if it is
379`almost-quietly', the next group will be selected without any
380confirmation if you are located on the last article in the group.
23f87bed 381Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
eec82323
LMI
382will go to the next group without confirmation."
383 :group 'gnus-summary-maneuvering
384 :type '(choice (const :tag "off" nil)
385 (const quietly)
386 (const almost-quietly)
387 (const slightly-quietly)
388 (sexp :menu-tag "on" t)))
389
390(defcustom gnus-auto-select-same nil
6748645f
LMI
391 "*If non-nil, select the next article with the same subject.
392If there are no more articles with the same subject, go to
393the first unread article."
eec82323
LMI
394 :group 'gnus-summary-maneuvering
395 :type 'boolean)
396
01c52d31
MB
397(defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
398 "What article should be selected after exiting an ephemeral group.
399Valid values include:
400
401`next'
402 Select the next article.
403`next-unread'
404 Select the next unread article.
405`next-noselect'
406 Move the cursor to the next article. This is the default.
407`next-unread-noselect'
408 Move the cursor to the next unread article.
409
410If it has any other value or there is no next (unread) article, the
411article selected before entering to the ephemeral group will appear."
330f707b 412 :version "23.1" ;; No Gnus
01c52d31
MB
413 :group 'gnus-summary-maneuvering
414 :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
415 (const next) (const next-unread)
416 (const next-noselect) (const next-unread-noselect)
417 (sexp :tag "other" :value nil)))
418
23f87bed
MB
419(defcustom gnus-auto-goto-ignores 'unfetched
420 "*Says how to handle unfetched articles when maneuvering.
421
422This variable can either be the symbols nil (maneuver to any
423article), `undownloaded' (maneuvering while unplugged ignores articles
424that have not been fetched), `always-undownloaded' (maneuvering always
425ignores articles that have not been fetched), `unfetched' (maneuvering
426ignores articles whose headers have not been fetched).
427
428NOTE: The list of unfetched articles will always be nil when plugged
429and, when unplugged, a subset of the undownloaded article list."
bf247b6e 430 :version "22.1"
23f87bed
MB
431 :group 'gnus-summary-maneuvering
432 :type '(choice (const :tag "None" nil)
433 (const :tag "Undownloaded when unplugged" undownloaded)
434 (const :tag "Undownloaded" always-undownloaded)
435 (const :tag "Unfetched" unfetched)))
436
eec82323
LMI
437(defcustom gnus-summary-check-current nil
438 "*If non-nil, consider the current article when moving.
439The \"unread\" movement commands will stay on the same line if the
440current article is unread."
441 :group 'gnus-summary-maneuvering
442 :type 'boolean)
443
01c52d31 444(defcustom gnus-auto-center-summary 2
eec82323
LMI
445 "*If non-nil, always center the current summary buffer.
446In particular, if `vertical' do only vertical recentering. If non-nil
447and non-`vertical', do both horizontal and vertical recentering."
448 :group 'gnus-summary-maneuvering
449 :type '(choice (const :tag "none" nil)
450 (const vertical)
16409b0b 451 (integer :tag "height")
eec82323
LMI
452 (sexp :menu-tag "both" t)))
453
2d04f304
G
454(defcustom gnus-auto-center-group t
455 "If non-nil, always center the group buffer."
456 :group 'gnus-summary-maneuvering
457 :type 'boolean)
23f87bed 458
eec82323
LMI
459(defcustom gnus-show-all-headers nil
460 "*If non-nil, don't hide any headers."
461 :group 'gnus-article-hiding
462 :group 'gnus-article-headers
463 :type 'boolean)
464
465(defcustom gnus-summary-ignore-duplicates nil
466 "*If non-nil, ignore articles with identical Message-ID headers."
467 :group 'gnus-summary
468 :type 'boolean)
6748645f 469
1d297c49 470(defcustom gnus-single-article-buffer nil
eec82323
LMI
471 "*If non-nil, display all articles in the same buffer.
472If nil, each group will get its own article buffer."
1d297c49 473 :version "24.1"
eec82323
LMI
474 :group 'gnus-article-various
475 :type 'boolean)
476
477(defcustom gnus-break-pages t
478 "*If non-nil, do page breaking on articles.
479The page delimiter is specified by the `gnus-page-delimiter'
480variable."
481 :group 'gnus-article-various
482 :type 'boolean)
483
eec82323
LMI
484(defcustom gnus-move-split-methods nil
485 "*Variable used to suggest where articles are to be moved to.
23f87bed
MB
486It uses the same syntax as the `gnus-split-methods' variable.
487However, whereas `gnus-split-methods' specifies file names as targets,
488this variable specifies group names."
eec82323 489 :group 'gnus-summary-mail
6748645f
LMI
490 :type '(repeat (choice (list :value (fun) function)
491 (cons :value ("" "") regexp (repeat string))
492 (sexp :value nil))))
eec82323 493
01c52d31
MB
494(defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
495 "Function used to compute default prefix for article move/copy/etc prompts.
496The function should take one argument, a group name, and return a
497string with the suggested prefix."
498 :group 'gnus-summary-mail
499 :type 'function)
500
e62e7654
MB
501;; FIXME: Although the custom type is `character' for the following variables,
502;; using multibyte characters (Latin-1, UTF-8) doesn't work. -- rs
503
23f87bed 504(defcustom gnus-unread-mark ? ;Whitespace
eec82323
LMI
505 "*Mark used for unread articles."
506 :group 'gnus-summary-marks
507 :type 'character)
508
509(defcustom gnus-ticked-mark ?!
510 "*Mark used for ticked articles."
511 :group 'gnus-summary-marks
512 :type 'character)
513
514(defcustom gnus-dormant-mark ??
515 "*Mark used for dormant articles."
516 :group 'gnus-summary-marks
517 :type 'character)
518
519(defcustom gnus-del-mark ?r
520 "*Mark used for del'd articles."
521 :group 'gnus-summary-marks
522 :type 'character)
523
524(defcustom gnus-read-mark ?R
525 "*Mark used for read articles."
526 :group 'gnus-summary-marks
527 :type 'character)
528
529(defcustom gnus-expirable-mark ?E
530 "*Mark used for expirable articles."
531 :group 'gnus-summary-marks
532 :type 'character)
533
534(defcustom gnus-killed-mark ?K
535 "*Mark used for killed articles."
536 :group 'gnus-summary-marks
537 :type 'character)
538
23f87bed
MB
539(defcustom gnus-spam-mark ?$
540 "*Mark used for spam articles."
bf247b6e 541 :version "22.1"
23f87bed
MB
542 :group 'gnus-summary-marks
543 :type 'character)
544
eec82323
LMI
545(defcustom gnus-kill-file-mark ?X
546 "*Mark used for articles killed by kill files."
547 :group 'gnus-summary-marks
548 :type 'character)
549
550(defcustom gnus-low-score-mark ?Y
551 "*Mark used for articles with a low score."
552 :group 'gnus-summary-marks
553 :type 'character)
554
555(defcustom gnus-catchup-mark ?C
556 "*Mark used for articles that are caught up."
557 :group 'gnus-summary-marks
558 :type 'character)
559
560(defcustom gnus-replied-mark ?A
561 "*Mark used for articles that have been replied to."
562 :group 'gnus-summary-marks
563 :type 'character)
564
23f87bed
MB
565(defcustom gnus-forwarded-mark ?F
566 "*Mark used for articles that have been forwarded."
bf247b6e 567 :version "22.1"
23f87bed
MB
568 :group 'gnus-summary-marks
569 :type 'character)
570
571(defcustom gnus-recent-mark ?N
572 "*Mark used for articles that are recent."
bf247b6e 573 :version "22.1"
23f87bed
MB
574 :group 'gnus-summary-marks
575 :type 'character)
576
eec82323
LMI
577(defcustom gnus-cached-mark ?*
578 "*Mark used for articles that are in the cache."
579 :group 'gnus-summary-marks
580 :type 'character)
581
582(defcustom gnus-saved-mark ?S
23f87bed
MB
583 "*Mark used for articles that have been saved."
584 :group 'gnus-summary-marks
585 :type 'character)
586
587(defcustom gnus-unseen-mark ?.
588 "*Mark used for articles that haven't been seen."
bf247b6e 589 :version "22.1"
23f87bed
MB
590 :group 'gnus-summary-marks
591 :type 'character)
592
593(defcustom gnus-no-mark ? ;Whitespace
594 "*Mark used for articles that have no other secondary mark."
bf247b6e 595 :version "22.1"
eec82323
LMI
596 :group 'gnus-summary-marks
597 :type 'character)
598
599(defcustom gnus-ancient-mark ?O
600 "*Mark used for ancient articles."
601 :group 'gnus-summary-marks
602 :type 'character)
603
604(defcustom gnus-sparse-mark ?Q
605 "*Mark used for sparsely reffed articles."
606 :group 'gnus-summary-marks
607 :type 'character)
608
609(defcustom gnus-canceled-mark ?G
610 "*Mark used for canceled articles."
611 :group 'gnus-summary-marks
612 :type 'character)
613
614(defcustom gnus-duplicate-mark ?M
615 "*Mark used for duplicate articles."
616 :group 'gnus-summary-marks
617 :type 'character)
618
23f87bed 619(defcustom gnus-undownloaded-mark ?-
6748645f 620 "*Mark used for articles that weren't downloaded."
bf247b6e 621 :version "22.1"
6748645f
LMI
622 :group 'gnus-summary-marks
623 :type 'character)
624
23f87bed
MB
625(defcustom gnus-downloaded-mark ?+
626 "*Mark used for articles that were downloaded."
627 :group 'gnus-summary-marks
628 :type 'character)
629
6748645f
LMI
630(defcustom gnus-downloadable-mark ?%
631 "*Mark used for articles that are to be downloaded."
632 :group 'gnus-summary-marks
633 :type 'character)
634
635(defcustom gnus-unsendable-mark ?=
636 "*Mark used for articles that won't be sent."
637 :group 'gnus-summary-marks
638 :type 'character)
639
eec82323
LMI
640(defcustom gnus-score-over-mark ?+
641 "*Score mark used for articles with high scores."
642 :group 'gnus-summary-marks
643 :type 'character)
644
645(defcustom gnus-score-below-mark ?-
646 "*Score mark used for articles with low scores."
647 :group 'gnus-summary-marks
648 :type 'character)
649
23f87bed 650(defcustom gnus-empty-thread-mark ? ;Whitespace
eec82323
LMI
651 "*There is no thread under the article."
652 :group 'gnus-summary-marks
653 :type 'character)
654
655(defcustom gnus-not-empty-thread-mark ?=
656 "*There is a thread under the article."
657 :group 'gnus-summary-marks
658 :type 'character)
659
660(defcustom gnus-view-pseudo-asynchronously nil
661 "*If non-nil, Gnus will view pseudo-articles asynchronously."
662 :group 'gnus-extract-view
663 :type 'boolean)
664
16409b0b
GM
665(defcustom gnus-auto-expirable-marks
666 (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
667 gnus-low-score-mark gnus-ancient-mark gnus-read-mark
c4d82de8 668 gnus-duplicate-mark)
16409b0b 669 "*The list of marks converted into expiration if a group is auto-expirable."
b0e30310 670 :version "24.1"
16409b0b
GM
671 :group 'gnus-summary
672 :type '(repeat character))
673
674(defcustom gnus-inhibit-user-auto-expire t
675 "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
58e39d05 676 :version "21.1"
16409b0b
GM
677 :group 'gnus-summary
678 :type 'boolean)
679
b0b63450
MB
680(defcustom gnus-mark-copied-or-moved-articles-as-expirable nil
681 "If non-nil, mark articles copied or moved to auto-expire group as expirable.
682If nil, the expirable marks will be unchanged except that the marks
683will be removed when copying or moving articles to a group that has
684not turned auto-expire on. If non-nil, articles that have been read
685will be marked as expirable when being copied or moved to a group in
686which auto-expire is turned on."
687 :version "23.2"
688 :type 'boolean
689 :group 'gnus-summary-marks)
690
eec82323
LMI
691(defcustom gnus-view-pseudos nil
692 "*If `automatic', pseudo-articles will be viewed automatically.
693If `not-confirm', pseudos will be viewed automatically, and the user
694will not be asked to confirm the command."
695 :group 'gnus-extract-view
696 :type '(choice (const :tag "off" nil)
697 (const automatic)
698 (const not-confirm)))
699
700(defcustom gnus-view-pseudos-separately t
701 "*If non-nil, one pseudo-article will be created for each file to be viewed.
702If nil, all files that use the same viewing command will be given as a
703list of parameters to that command."
704 :group 'gnus-extract-view
705 :type 'boolean)
706
707(defcustom gnus-insert-pseudo-articles t
708 "*If non-nil, insert pseudo-articles when decoding articles."
709 :group 'gnus-extract-view
710 :type 'boolean)
711
712(defcustom gnus-summary-dummy-line-format
23f87bed 713 " %(: :%) %S\n"
eec82323
LMI
714 "*The format specification for the dummy roots in the summary buffer.
715It works along the same lines as a normal formatting string,
716with some simple extensions.
717
23f87bed
MB
718%S The subject
719
720General format specifiers can also be used.
721See `(gnus)Formatting Variables'."
722 :link '(custom-manual "(gnus)Formatting Variables")
eec82323
LMI
723 :group 'gnus-threading
724 :type 'string)
725
16409b0b 726(defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
eec82323
LMI
727 "*The format specification for the summary mode line.
728It works along the same lines as a normal formatting string,
729with some simple extensions:
730
731%G Group name
732%p Unprefixed group name
733%A Current article number
6748645f 734%z Current article score
eec82323
LMI
735%V Gnus version
736%U Number of unread articles in the group
737%e Number of unselected articles in the group
738%Z A string with unread/unselected article counts
739%g Shortish group name
740%S Subject of the current article
741%u User-defined spec
742%s Current score file name
743%d Number of dormant articles
744%r Number of articles that have been marked as read in this session
745%E Number of articles expunged by the score files"
746 :group 'gnus-summary-format
747 :type 'string)
748
16409b0b
GM
749(defcustom gnus-list-identifiers nil
750 "Regexp that matches list identifiers to be removed from subject.
751This can also be a list of regexps."
58e39d05 752 :version "21.1"
16409b0b
GM
753 :group 'gnus-summary-format
754 :group 'gnus-article-hiding
755 :type '(choice (const :tag "none" nil)
756 (regexp :value ".*")
757 (repeat :value (".*") regexp)))
758
eec82323
LMI
759(defcustom gnus-summary-mark-below 0
760 "*Mark all articles with a score below this variable as read.
761This variable is local to each summary buffer and usually set by the
762score file."
763 :group 'gnus-score-default
764 :type 'integer)
765
01c52d31
MB
766(defun gnus-widget-reversible-match (widget value)
767 "Ignoring WIDGET, convert VALUE to internal form.
768VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
769 ;; (debug value)
770 (or (symbolp value)
771 (and (listp value)
772 (eq (length value) 2)
773 (eq (nth 0 value) 'not)
774 (symbolp (nth 1 value)))))
775
776(defun gnus-widget-reversible-to-internal (widget value)
777 "Ignoring WIDGET, convert VALUE to internal form.
778VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
779FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
780 ;; (debug value)
781 (if (atom value)
782 (list value nil)
783 (list (nth 1 value) t)))
784
785(defun gnus-widget-reversible-to-external (widget value)
786 "Ignoring WIDGET, convert VALUE to external form.
787VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
788\(FOO nil) is converted to FOO and (FOO t) is converted to (not FOO)."
789 ;; (debug value)
790 (if (nth 1 value)
791 (list 'not (nth 0 value))
792 (nth 0 value)))
793
794(define-widget 'gnus-widget-reversible 'group
795 "A `group' that convert values."
796 :match 'gnus-widget-reversible-match
797 :value-to-internal 'gnus-widget-reversible-to-internal
798 :value-to-external 'gnus-widget-reversible-to-external)
799
eec82323
LMI
800(defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
801 "*List of functions used for sorting articles in the summary buffer.
23f87bed
MB
802
803Each function takes two articles and returns non-nil if the first
804article should be sorted before the other. If you use more than one
805function, the primary sort function should be the last. You should
806probably always include `gnus-article-sort-by-number' in the list of
807sorting functions -- preferably first. Also note that sorting by date
808is often much slower than sorting by number, and the sorting order is
809very similar. (Sorting by date means sorting by the time the message
810was sent, sorting by number means sorting by arrival time.)
811
01c52d31
MB
812Each item can also be a list `(not F)' where F is a function;
813this reverses the sort order.
814
23f87bed
MB
815Ready-made functions include `gnus-article-sort-by-number',
816`gnus-article-sort-by-author', `gnus-article-sort-by-subject',
817`gnus-article-sort-by-date', `gnus-article-sort-by-random'
818and `gnus-article-sort-by-score'.
819
820When threading is turned on, the variable `gnus-thread-sort-functions'
821controls how articles are sorted."
eec82323 822 :group 'gnus-summary-sort
01c52d31
MB
823 :type '(repeat (gnus-widget-reversible
824 (choice (function-item gnus-article-sort-by-number)
825 (function-item gnus-article-sort-by-author)
826 (function-item gnus-article-sort-by-subject)
827 (function-item gnus-article-sort-by-date)
828 (function-item gnus-article-sort-by-score)
829 (function-item gnus-article-sort-by-random)
830 (function :tag "other"))
831 (boolean :tag "Reverse order"))))
832
eec82323
LMI
833
834(defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
835 "*List of functions used for sorting threads in the summary buffer.
836By default, threads are sorted by article number.
837
23f87bed
MB
838Each function takes two threads and returns non-nil if the first
839thread should be sorted before the other. If you use more than one
840function, the primary sort function should be the last. You should
841probably always include `gnus-thread-sort-by-number' in the list of
842sorting functions -- preferably first. Also note that sorting by date
843is often much slower than sorting by number, and the sorting order is
844very similar. (Sorting by date means sorting by the time the message
845was sent, sorting by number means sorting by arrival time.)
eec82323 846
01c52d31
MB
847Each list item can also be a list `(not F)' where F is a
848function; this specifies reversed sort order.
849
eec82323 850Ready-made functions include `gnus-thread-sort-by-number',
01c52d31
MB
851`gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
852`gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
853`gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
854`gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
855and `gnus-thread-sort-by-total-score' (see
856`gnus-thread-score-function').
23f87bed
MB
857
858When threading is turned off, the variable
859`gnus-article-sort-functions' controls how articles are sorted."
eec82323 860 :group 'gnus-summary-sort
01c52d31
MB
861 :type '(repeat
862 (gnus-widget-reversible
863 (choice (function-item gnus-thread-sort-by-number)
864 (function-item gnus-thread-sort-by-author)
865 (function-item gnus-thread-sort-by-recipient)
866 (function-item gnus-thread-sort-by-subject)
867 (function-item gnus-thread-sort-by-date)
868 (function-item gnus-thread-sort-by-score)
869 (function-item gnus-thread-sort-by-most-recent-number)
870 (function-item gnus-thread-sort-by-most-recent-date)
871 (function-item gnus-thread-sort-by-random)
872 (function-item gnus-thread-sort-by-total-score)
873 (function :tag "other"))
874 (boolean :tag "Reverse order"))))
eec82323
LMI
875
876(defcustom gnus-thread-score-function '+
877 "*Function used for calculating the total score of a thread.
878
879The function is called with the scores of the article and each
880subthread and should then return the score of the thread.
881
882Some functions you can use are `+', `max', or `min'."
883 :group 'gnus-summary-sort
884 :type 'function)
885
886(defcustom gnus-summary-expunge-below nil
6748645f
LMI
887 "All articles that have a score less than this variable will be expunged.
888This variable is local to the summary buffers."
eec82323
LMI
889 :group 'gnus-score-default
890 :type '(choice (const :tag "off" nil)
891 integer))
892
893(defcustom gnus-thread-expunge-below nil
894 "All threads that have a total score less than this variable will be expunged.
895See `gnus-thread-score-function' for en explanation of what a
6748645f
LMI
896\"thread score\" is.
897
898This variable is local to the summary buffers."
16409b0b 899 :group 'gnus-threading
eec82323
LMI
900 :group 'gnus-score-default
901 :type '(choice (const :tag "off" nil)
902 integer))
903
904(defcustom gnus-summary-mode-hook nil
905 "*A hook for Gnus summary mode.
906This hook is run before any variables are set in the summary buffer."
23f87bed 907 :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
eec82323
LMI
908 :group 'gnus-summary-various
909 :type 'hook)
910
23f87bed
MB
911;; Extracted from gnus-xmas-redefine in order to preserve user settings
912(when (featurep 'xemacs)
913 (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
914 (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
915 (add-hook 'gnus-summary-mode-hook
916 'gnus-xmas-switch-horizontal-scrollbar-off))
917
eec82323
LMI
918(defcustom gnus-summary-menu-hook nil
919 "*Hook run after the creation of the summary mode menu."
920 :group 'gnus-summary-visual
921 :type 'hook)
922
923(defcustom gnus-summary-exit-hook nil
924 "*A hook called on exit from the summary buffer.
925It will be called with point in the group buffer."
926 :group 'gnus-summary-exit
927 :type 'hook)
928
929(defcustom gnus-summary-prepare-hook nil
930 "*A hook called after the summary buffer has been generated.
931If you want to modify the summary buffer, you can use this hook."
932 :group 'gnus-summary-various
933 :type 'hook)
934
6748645f
LMI
935(defcustom gnus-summary-prepared-hook nil
936 "*A hook called as the last thing after the summary buffer has been generated."
937 :group 'gnus-summary-various
938 :type 'hook)
939
eec82323
LMI
940(defcustom gnus-summary-generate-hook nil
941 "*A hook run just before generating the summary buffer.
942This hook is commonly used to customize threading variables and the
943like."
944 :group 'gnus-summary-various
945 :type 'hook)
946
947(defcustom gnus-select-group-hook nil
948 "*A hook called when a newsgroup is selected.
949
950If you'd like to simplify subjects like the
951`gnus-summary-next-same-subject' command does, you can use the
952following hook:
953
23f87bed
MB
954 (add-hook gnus-select-group-hook
955 (lambda ()
956 (mapcar (lambda (header)
957 (mail-header-set-subject
958 header
959 (gnus-simplify-subject
960 (mail-header-subject header) 're-only)))
961 gnus-newsgroup-headers)))"
eec82323
LMI
962 :group 'gnus-group-select
963 :type 'hook)
964
965(defcustom gnus-select-article-hook nil
966 "*A hook called when an article is selected."
967 :group 'gnus-summary-choose
23f87bed 968 :options '(gnus-agent-fetch-selected-article)
eec82323
LMI
969 :type 'hook)
970
971(defcustom gnus-visual-mark-article-hook
972 (list 'gnus-highlight-selected-summary)
973 "*Hook run after selecting an article in the summary buffer.
974It is meant to be used for highlighting the article in some way. It
975is not run if `gnus-visual' is nil."
976 :group 'gnus-summary-visual
977 :type 'hook)
978
16409b0b 979(defcustom gnus-parse-headers-hook nil
eec82323
LMI
980 "*A hook called before parsing the headers."
981 :group 'gnus-various
982 :type 'hook)
983
984(defcustom gnus-exit-group-hook nil
16409b0b
GM
985 "*A hook called when exiting summary mode.
986This hook is not called from the non-updating exit commands like `Q'."
eec82323
LMI
987 :group 'gnus-various
988 :type 'hook)
989
a9ec34f4 990(defcustom gnus-summary-update-hook nil
eec82323
LMI
991 "*A hook called when a summary line is changed.
992The hook will not be called if `gnus-visual' is nil.
993
994The default function `gnus-summary-highlight-line' will
995highlight the line according to the `gnus-summary-highlight'
996variable."
997 :group 'gnus-summary-visual
998 :type 'hook)
999
1000(defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
1001 "*A hook called when an article is selected for the first time.
1002The hook is intended to mark an article as read (or unread)
1003automatically when it is selected."
1004 :group 'gnus-summary-choose
1005 :type 'hook)
1006
1007(defcustom gnus-group-no-more-groups-hook nil
1008 "*A hook run when returning to group mode having no more (unread) groups."
1009 :group 'gnus-group-select
1010 :type 'hook)
1011
1012(defcustom gnus-ps-print-hook nil
1013 "*A hook run before ps-printing something from Gnus."
1014 :group 'gnus-summary
1015 :type 'hook)
1016
23f87bed
MB
1017(defcustom gnus-summary-article-move-hook nil
1018 "*A hook called after an article is moved, copied, respooled, or crossposted."
bf247b6e 1019 :version "22.1"
23f87bed
MB
1020 :group 'gnus-summary
1021 :type 'hook)
1022
1023(defcustom gnus-summary-article-delete-hook nil
1024 "*A hook called after an article is deleted."
bf247b6e 1025 :version "22.1"
23f87bed
MB
1026 :group 'gnus-summary
1027 :type 'hook)
1028
1029(defcustom gnus-summary-article-expire-hook nil
1030 "*A hook called after an article is expired."
bf247b6e 1031 :version "22.1"
23f87bed
MB
1032 :group 'gnus-summary
1033 :type 'hook)
1034
1035(defcustom gnus-summary-display-arrow
1036 (and (fboundp 'display-graphic-p)
1037 (display-graphic-p))
1038 "*If non-nil, display an arrow highlighting the current article."
bf247b6e 1039 :version "22.1"
23f87bed
MB
1040 :group 'gnus-summary
1041 :type 'boolean)
1042
0f49874b 1043(defcustom gnus-summary-selected-face 'gnus-summary-selected
eec82323
LMI
1044 "Face used for highlighting the current article in the summary buffer."
1045 :group 'gnus-summary-visual
1046 :type 'face)
1047
23f87bed
MB
1048(defvar gnus-tmp-downloaded nil)
1049
eec82323 1050(defcustom gnus-summary-highlight
23f87bed 1051 '(((eq mark gnus-canceled-mark)
0f49874b 1052 . gnus-summary-cancelled)
23f87bed 1053 ((and uncached (> score default-high))
0f49874b 1054 . gnus-summary-high-undownloaded)
23f87bed 1055 ((and uncached (< score default-low))
0f49874b 1056 . gnus-summary-low-undownloaded)
23f87bed 1057 (uncached
0f49874b 1058 . gnus-summary-normal-undownloaded)
23f87bed
MB
1059 ((and (> score default-high)
1060 (or (eq mark gnus-dormant-mark)
1061 (eq mark gnus-ticked-mark)))
0f49874b 1062 . gnus-summary-high-ticked)
23f87bed
MB
1063 ((and (< score default-low)
1064 (or (eq mark gnus-dormant-mark)
1065 (eq mark gnus-ticked-mark)))
0f49874b 1066 . gnus-summary-low-ticked)
23f87bed
MB
1067 ((or (eq mark gnus-dormant-mark)
1068 (eq mark gnus-ticked-mark))
0f49874b 1069 . gnus-summary-normal-ticked)
23f87bed 1070 ((and (> score default-high) (eq mark gnus-ancient-mark))
0f49874b 1071 . gnus-summary-high-ancient)
23f87bed 1072 ((and (< score default-low) (eq mark gnus-ancient-mark))
0f49874b 1073 . gnus-summary-low-ancient)
23f87bed 1074 ((eq mark gnus-ancient-mark)
0f49874b 1075 . gnus-summary-normal-ancient)
23f87bed 1076 ((and (> score default-high) (eq mark gnus-unread-mark))
0f49874b 1077 . gnus-summary-high-unread)
23f87bed 1078 ((and (< score default-low) (eq mark gnus-unread-mark))
0f49874b 1079 . gnus-summary-low-unread)
23f87bed 1080 ((eq mark gnus-unread-mark)
0f49874b 1081 . gnus-summary-normal-unread)
23f87bed 1082 ((> score default-high)
0f49874b 1083 . gnus-summary-high-read)
23f87bed 1084 ((< score default-low)
0f49874b 1085 . gnus-summary-low-read)
eec82323 1086 (t
0f49874b 1087 . gnus-summary-normal-read))
6748645f 1088 "*Controls the highlighting of summary buffer lines.
eec82323 1089
107cf8ec 1090A list of (FORM . FACE) pairs. When deciding how a particular
23f87bed
MB
1091summary line should be displayed, each form is evaluated. The content
1092of the face field after the first true form is used. You can change
1093how those summary lines are displayed, by editing the face field.
eec82323
LMI
1094
1095You can use the following variables in the FORM field.
1096
107cf8ec 1097score: The article's score.
23f87bed
MB
1098default: The default article score.
1099default-high: The default score for high scored articles.
1100default-low: The default score for low scored articles.
1101below: The score below which articles are automatically marked as read.
1102mark: The article's mark.
1103uncached: Non-nil if the article is uncached."
eec82323
LMI
1104 :group 'gnus-summary-visual
1105 :type '(repeat (cons (sexp :tag "Form" nil)
1106 face)))
c12ecb0a 1107(put 'gnus-summary-highlight 'risky-local-variable t)
eec82323 1108
6748645f
LMI
1109(defcustom gnus-alter-header-function nil
1110 "Function called to allow alteration of article header structures.
1111The function is called with one parameter, the article header vector,
0ab0f2d3
SZ
1112which it may alter in any way."
1113 :type '(choice (const :tag "None" nil)
1114 function)
1115 :group 'gnus-summary)
eec82323 1116
16409b0b 1117(defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
343d6628
MB
1118 "Function used to decode a string with encoded words.")
1119
1120(defvar gnus-decode-encoded-address-function
1121 'mail-decode-encoded-address-string
1122 "Function used to decode addresses with encoded words.")
16409b0b 1123
23f87bed 1124(defcustom gnus-extra-headers '(To Newsgroups)
16409b0b 1125 "*Extra headers to parse."
58e39d05 1126 :version "21.1"
16409b0b
GM
1127 :group 'gnus-summary
1128 :type '(repeat symbol))
1129
1130(defcustom gnus-ignored-from-addresses
343d6628 1131 (and user-mail-address
7cd9f860
CY
1132 (not (string= user-mail-address ""))
1133 (regexp-quote user-mail-address))
01c52d31
MB
1134 "*From headers that may be suppressed in favor of To headers.
1135This can be a regexp or a list of regexps."
58e39d05 1136 :version "21.1"
16409b0b 1137 :group 'gnus-summary
01c52d31
MB
1138 :type '(choice regexp
1139 (repeat :tag "Regexp List" regexp)))
1140
1141(defsubst gnus-ignored-from-addresses ()
1142 (gmm-regexp-concat gnus-ignored-from-addresses))
1143
1144(defcustom gnus-summary-to-prefix "-> "
1145 "*String prefixed to the To field in the summary line when
1146using `gnus-ignored-from-addresses'."
1147 :version "22.1"
1148 :group 'gnus-summary
1149 :type 'string)
1150
1151(defcustom gnus-summary-newsgroup-prefix "=> "
1152 "*String prefixed to the Newsgroup field in the summary
1153line when using `gnus-ignored-from-addresses'."
1154 :version "22.1"
1155 :group 'gnus-summary
1156 :type 'string)
16409b0b 1157
16409b0b
GM
1158(defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1159 "List of charsets that should be ignored.
1160When these charsets are used in the \"charset\" parameter, the
1161default charset will be used instead."
58e39d05 1162 :version "21.1"
16409b0b
GM
1163 :type '(repeat symbol)
1164 :group 'gnus-charset)
1165
4b70e299
MB
1166(defcustom gnus-newsgroup-maximum-articles nil
1167 "The maximum number of articles a newsgroup.
1168If this is a number, old articles in a newsgroup exceeding this number
1169are silently ignored. If it is nil, no article is ignored. Note that
1170setting this variable to a number might prevent you from reading very
1171old articles."
1172 :group 'gnus-group-select
1173 :version "22.2"
1174 :type '(choice (const :tag "No limit" nil)
1175 integer))
1176
23f87bed
MB
1177(gnus-define-group-parameter
1178 ignored-charsets
1179 :type list
1180 :function-document
1181 "Return the ignored charsets of GROUP."
1182 :variable gnus-group-ignored-charsets-alist
1183 :variable-default
1184 '(("alt\\.chinese\\.text" iso-8859-1))
1185 :variable-document
1186 "Alist of regexps (to match group names) and charsets that should be ignored.
16409b0b
GM
1187When these charsets are used in the \"charset\" parameter, the
1188default charset will be used instead."
23f87bed
MB
1189 :variable-group gnus-charset
1190 :variable-type '(repeat (cons (regexp :tag "Group")
1191 (repeat symbol)))
1192 :parameter-type '(choice :tag "Ignored charsets"
1193 :value nil
1194 (repeat (symbol)))
1195 :parameter-document "\
1196List of charsets that should be ignored.
1197
1198When these charsets are used in the \"charset\" parameter, the
1199default charset will be used instead.")
16409b0b
GM
1200
1201(defcustom gnus-group-highlight-words-alist nil
1202 "Alist of group regexps and highlight regexps.
1203This variable uses the same syntax as `gnus-emphasis-alist'."
58e39d05 1204 :version "21.1"
16409b0b
GM
1205 :type '(repeat (cons (regexp :tag "Group")
1206 (repeat (list (regexp :tag "Highlight regexp")
1207 (number :tag "Group for entire word" 0)
1208 (number :tag "Group for displayed part" 0)
1209 (symbol :tag "Face"
1210 gnus-emphasis-highlight-words)))))
1211 :group 'gnus-summary-visual)
1212
1213(defcustom gnus-summary-show-article-charset-alist
1214 nil
1215 "Alist of number and charset.
1216The article will be shown with the charset corresponding to the
1217numbered argument.
1218For example: ((1 . cn-gb-2312) (2 . big5))."
58e39d05 1219 :version "21.1"
16409b0b
GM
1220 :type '(repeat (cons (number :tag "Argument" 1)
1221 (symbol :tag "Charset")))
1222 :group 'gnus-charset)
1223
1224(defcustom gnus-preserve-marks t
1225 "Whether marks are preserved when moving, copying and respooling messages."
58e39d05 1226 :version "21.1"
16409b0b
GM
1227 :type 'boolean
1228 :group 'gnus-summary-marks)
1229
3a23a519
MB
1230(defcustom gnus-propagate-marks t
1231 "If non-nil, do not propagate marks to the backends."
f8a29505 1232 :version "23.1" ;; No Gnus
3a23a519
MB
1233 :type 'boolean
1234 :group 'gnus-summary-marks)
1235
16409b0b
GM
1236(defcustom gnus-alter-articles-to-read-function nil
1237 "Function to be called to alter the list of articles to be selected."
8fc7a9a1 1238 :type '(choice (const nil) function)
16409b0b
GM
1239 :group 'gnus-summary)
1240
1241(defcustom gnus-orphan-score nil
1242 "*All orphans get this score added. Set in the score file."
1243 :group 'gnus-score-default
1244 :type '(choice (const nil)
1245 integer))
1246
8b93df01 1247(defcustom gnus-summary-save-parts-default-mime "image/.*"
23f87bed
MB
1248 "*A regexp to match MIME parts when saving multiple parts of a
1249message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1250This regexp will be used by default when prompting the user for which
1251type of files to save."
8b93df01
DL
1252 :group 'gnus-summary
1253 :type 'regexp)
1254
23f87bed
MB
1255(defcustom gnus-read-all-available-headers nil
1256 "Whether Gnus should parse all headers made available to it.
1257This is mostly relevant for slow back ends where the user may
1258wish to widen the summary buffer to include all headers
c4d82de8 1259that were fetched."
bf247b6e 1260 :version "22.1"
23f87bed
MB
1261 :group 'gnus-summary
1262 :type '(choice boolean regexp))
1263
89167438
MB
1264(defcustom gnus-summary-pipe-output-default-command nil
1265 "Command (and optional arguments) used to pipe article to subprocess.
1266This will be used as the default command if it is non-nil. The value
1267will be updated if you modify it when executing the command
1268`gnus-summary-pipe-output' or the function `gnus-summary-save-in-pipe'."
1269 :version "23.1" ;; No Gnus
1270 :group 'gnus-summary
1271 :type '(radio (const :tag "None" nil) (string :tag "Command")))
1272
23f87bed 1273(defcustom gnus-summary-muttprint-program "muttprint"
89167438
MB
1274 "Command (and optional arguments) used to run Muttprint.
1275The value will be updated if you modify it when executing the command
1276`gnus-summary-muttprint'."
bf247b6e 1277 :version "22.1"
23f87bed
MB
1278 :group 'gnus-summary
1279 :type 'string)
1280
01c52d31 1281(defcustom gnus-article-loose-mime t
23f87bed
MB
1282 "If non-nil, don't require MIME-Version header.
1283Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
a08b59c9 1284supply the MIME-Version header or deliberately strip it from the mail.
01c52d31
MB
1285If non-nil (the default), Gnus will treat some articles as MIME
1286even if the MIME-Version header is missing."
bf247b6e 1287 :version "22.1"
23f87bed
MB
1288 :type 'boolean
1289 :group 'gnus-article-mime)
1290
1291(defcustom gnus-article-emulate-mime t
1292 "If non-nil, use MIME emulation for uuencode and the like.
1293This means that Gnus will search message bodies for text that look
1294like uuencoded bits, yEncoded bits, and so on, and present that using
1295the normal Gnus MIME machinery."
bf247b6e 1296 :version "22.1"
23f87bed
MB
1297 :type 'boolean
1298 :group 'gnus-article-mime)
8b93df01 1299
eec82323
LMI
1300;;; Internal variables
1301
23f87bed 1302(defvar gnus-summary-display-cache nil)
16409b0b
GM
1303(defvar gnus-article-mime-handles nil)
1304(defvar gnus-article-decoded-p nil)
23f87bed
MB
1305(defvar gnus-article-charset nil)
1306(defvar gnus-article-ignored-charsets nil)
eec82323
LMI
1307(defvar gnus-scores-exclude-files nil)
1308(defvar gnus-page-broken nil)
1309
1310(defvar gnus-original-article nil)
1311(defvar gnus-article-internal-prepare-hook nil)
1312(defvar gnus-newsgroup-process-stack nil)
1313
1314(defvar gnus-thread-indent-array nil)
1315(defvar gnus-thread-indent-array-level gnus-thread-indent-level)
16409b0b
GM
1316(defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1317 "Function called to sort the articles within a thread after it has been gathered together.")
eec82323 1318
8b93df01 1319(defvar gnus-summary-save-parts-type-history nil)
23f87bed 1320(defvar gnus-summary-save-parts-last-directory mm-default-directory)
8b93df01 1321
eec82323
LMI
1322;; Avoid highlighting in kill files.
1323(defvar gnus-summary-inhibit-highlight nil)
1324(defvar gnus-newsgroup-selected-overlay nil)
1325(defvar gnus-inhibit-limiting nil)
1326(defvar gnus-newsgroup-adaptive-score-file nil)
1327(defvar gnus-current-score-file nil)
1328(defvar gnus-current-move-group nil)
1329(defvar gnus-current-copy-group nil)
1330(defvar gnus-current-crosspost-group nil)
23f87bed 1331(defvar gnus-newsgroup-display nil)
eec82323
LMI
1332
1333(defvar gnus-newsgroup-dependencies nil)
1334(defvar gnus-newsgroup-adaptive nil)
1335(defvar gnus-summary-display-article-function nil)
1336(defvar gnus-summary-highlight-line-function nil
1337 "Function called after highlighting a summary line.")
1338
1339(defvar gnus-summary-line-format-alist
1340 `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1341 (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1342 (?s gnus-tmp-subject-or-nil ?s)
1343 (?n gnus-tmp-name ?s)
1344 (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1345 ?s)
1346 (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1347 gnus-tmp-from) ?s)
1348 (?F gnus-tmp-from ?s)
1349 (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1350 (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1351 (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
6748645f 1352 (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
eec82323
LMI
1353 (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1354 (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1355 (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
23f87bed
MB
1356 (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1357 (?L gnus-tmp-lines ?s)
1358 (?O gnus-tmp-downloaded ?c)
eec82323
LMI
1359 (?I gnus-tmp-indentation ?s)
1360 (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1361 (?R gnus-tmp-replied ?c)
1362 (?\[ gnus-tmp-opening-bracket ?c)
1363 (?\] gnus-tmp-closing-bracket ?c)
1364 (?\> (make-string gnus-tmp-level ? ) ?s)
1365 (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1366 (?i gnus-tmp-score ?d)
1367 (?z gnus-tmp-score-char ?c)
eec82323
LMI
1368 (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1369 (?U gnus-tmp-unread ?c)
23f87bed
MB
1370 (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1371 ?s)
eec82323
LMI
1372 (?t (gnus-summary-number-of-articles-in-thread
1373 (and (boundp 'thread) (car thread)) gnus-tmp-level)
1374 ?d)
1375 (?e (gnus-summary-number-of-articles-in-thread
1376 (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1377 ?c)
1378 (?u gnus-tmp-user-defined ?s)
23f87bed
MB
1379 (?P (gnus-pick-line-number) ?d)
1380 (?B gnus-tmp-thread-tree-header-string ?s)
1381 (user-date (gnus-user-date
1382 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
16409b0b
GM
1383 "An alist of format specifications that can appear in summary lines.
1384These are paired with what variables they correspond with, along with
1385the type of the variable (string, integer, character, etc).")
eec82323
LMI
1386
1387(defvar gnus-summary-dummy-line-format-alist
1388 `((?S gnus-tmp-subject ?s)
1389 (?N gnus-tmp-number ?d)
1390 (?u gnus-tmp-user-defined ?s)))
1391
1392(defvar gnus-summary-mode-line-format-alist
1393 `((?G gnus-tmp-group-name ?s)
1394 (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1395 (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1396 (?A gnus-tmp-article-number ?d)
1397 (?Z gnus-tmp-unread-and-unselected ?s)
1398 (?V gnus-version ?s)
1399 (?U gnus-tmp-unread-and-unticked ?d)
1400 (?S gnus-tmp-subject ?s)
1401 (?e gnus-tmp-unselected ?d)
1402 (?u gnus-tmp-user-defined ?s)
1403 (?d (length gnus-newsgroup-dormant) ?d)
1404 (?t (length gnus-newsgroup-marked) ?d)
23f87bed 1405 (?h (length gnus-newsgroup-spam-marked) ?d)
eec82323 1406 (?r (length gnus-newsgroup-reads) ?d)
6748645f 1407 (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
eec82323
LMI
1408 (?E gnus-newsgroup-expunged-tally ?d)
1409 (?s (gnus-current-score-file-nondirectory) ?s)))
1410
c1717fbd
GM
1411;; This is here rather than in gnus-art for compilation reasons.
1412(defvar gnus-article-mode-line-format-alist
1413 (nconc '((?w (gnus-article-wash-status) ?s)
1414 (?m (gnus-article-mime-part-status) ?s))
1415 gnus-summary-mode-line-format-alist))
1416
eec82323
LMI
1417(defvar gnus-last-search-regexp nil
1418 "Default regexp for article search command.")
1419
1420(defvar gnus-last-shell-command nil
1421 "Default shell command on article.")
1422
23f87bed
MB
1423(defvar gnus-newsgroup-agentized nil
1424 "Locally bound in each summary buffer to indicate whether the server has been agentized.")
eec82323
LMI
1425(defvar gnus-newsgroup-begin nil)
1426(defvar gnus-newsgroup-end nil)
1427(defvar gnus-newsgroup-last-rmail nil)
1428(defvar gnus-newsgroup-last-mail nil)
1429(defvar gnus-newsgroup-last-folder nil)
1430(defvar gnus-newsgroup-last-file nil)
26c9afc3 1431(defvar gnus-newsgroup-last-directory nil)
eec82323
LMI
1432(defvar gnus-newsgroup-auto-expire nil)
1433(defvar gnus-newsgroup-active nil)
1434
1435(defvar gnus-newsgroup-data nil)
1436(defvar gnus-newsgroup-data-reverse nil)
1437(defvar gnus-newsgroup-limit nil)
1438(defvar gnus-newsgroup-limits nil)
23f87bed 1439(defvar gnus-summary-use-undownloaded-faces nil)
eec82323
LMI
1440
1441(defvar gnus-newsgroup-unreads nil
23f87bed 1442 "Sorted list of unread articles in the current newsgroup.")
eec82323
LMI
1443
1444(defvar gnus-newsgroup-unselected nil
23f87bed 1445 "Sorted list of unselected unread articles in the current newsgroup.")
eec82323
LMI
1446
1447(defvar gnus-newsgroup-reads nil
1448 "Alist of read articles and article marks in the current newsgroup.")
1449
1450(defvar gnus-newsgroup-expunged-tally nil)
1451
1452(defvar gnus-newsgroup-marked nil
23f87bed
MB
1453 "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1454
1455(defvar gnus-newsgroup-spam-marked nil
1456 "List of ranges of articles that have been marked as spam.")
eec82323
LMI
1457
1458(defvar gnus-newsgroup-killed nil
1459 "List of ranges of articles that have been through the scoring process.")
1460
1461(defvar gnus-newsgroup-cached nil
23f87bed 1462 "Sorted list of articles that come from the article cache.")
eec82323
LMI
1463
1464(defvar gnus-newsgroup-saved nil
1465 "List of articles that have been saved.")
1466
1467(defvar gnus-newsgroup-kill-headers nil)
1468
1469(defvar gnus-newsgroup-replied nil
1470 "List of articles that have been replied to in the current newsgroup.")
1471
23f87bed
MB
1472(defvar gnus-newsgroup-forwarded nil
1473 "List of articles that have been forwarded in the current newsgroup.")
1474
1475(defvar gnus-newsgroup-recent nil
1476 "List of articles that have are recent in the current newsgroup.")
1477
eec82323 1478(defvar gnus-newsgroup-expirable nil
23f87bed 1479 "Sorted list of articles in the current newsgroup that can be expired.")
eec82323
LMI
1480
1481(defvar gnus-newsgroup-processable nil
1482 "List of articles in the current newsgroup that can be processed.")
1483
6748645f 1484(defvar gnus-newsgroup-downloadable nil
23f87bed
MB
1485 "Sorted list of articles in the current newsgroup that can be processed.")
1486
1487(defvar gnus-newsgroup-unfetched nil
1488 "Sorted list of articles in the current newsgroup whose headers have
1489not been fetched into the agent.
1490
1491This list will always be a subset of gnus-newsgroup-undownloaded.")
6748645f
LMI
1492
1493(defvar gnus-newsgroup-undownloaded nil
23f87bed 1494 "List of articles in the current newsgroup that haven't been downloaded.")
6748645f
LMI
1495
1496(defvar gnus-newsgroup-unsendable nil
1497 "List of articles in the current newsgroup that won't be sent.")
1498
eec82323
LMI
1499(defvar gnus-newsgroup-bookmarks nil
1500 "List of articles in the current newsgroup that have bookmarks.")
1501
1502(defvar gnus-newsgroup-dormant nil
23f87bed
MB
1503 "Sorted list of dormant articles in the current newsgroup.")
1504
1505(defvar gnus-newsgroup-unseen nil
1506 "List of unseen articles in the current newsgroup.")
1507
1508(defvar gnus-newsgroup-seen nil
1509 "Range of seen articles in the current newsgroup.")
1510
1511(defvar gnus-newsgroup-articles nil
1512 "List of articles in the current newsgroup.")
eec82323
LMI
1513
1514(defvar gnus-newsgroup-scored nil
1515 "List of scored articles in the current newsgroup.")
1516
1517(defvar gnus-newsgroup-headers nil
1518 "List of article headers in the current newsgroup.")
1519
1520(defvar gnus-newsgroup-threads nil)
1521
1522(defvar gnus-newsgroup-prepared nil
1523 "Whether the current group has been prepared properly.")
1524
1525(defvar gnus-newsgroup-ancient nil
1526 "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1527
1528(defvar gnus-newsgroup-sparse nil)
1529
1530(defvar gnus-current-article nil)
1531(defvar gnus-article-current nil)
1532(defvar gnus-current-headers nil)
1533(defvar gnus-have-all-headers nil)
1534(defvar gnus-last-article nil)
1535(defvar gnus-newsgroup-history nil)
16409b0b
GM
1536(defvar gnus-newsgroup-charset nil)
1537(defvar gnus-newsgroup-ephemeral-charset nil)
1538(defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
eec82323 1539
23f87bed
MB
1540(defvar gnus-article-before-search nil)
1541
1542(defvar gnus-summary-local-variables
eec82323 1543 '(gnus-newsgroup-name
b1ae92ba
G
1544
1545 ;; Marks lists
1546 gnus-newsgroup-unreads
1547 gnus-newsgroup-unselected
1548 gnus-newsgroup-marked
1549 gnus-newsgroup-spam-marked
1550 gnus-newsgroup-reads
1551 gnus-newsgroup-saved
1552 gnus-newsgroup-replied
1553 gnus-newsgroup-forwarded
1554 gnus-newsgroup-recent
1555 gnus-newsgroup-expirable
1556 gnus-newsgroup-killed
1557 gnus-newsgroup-unseen
1558 gnus-newsgroup-seen
1559 gnus-newsgroup-cached
1560 gnus-newsgroup-downloadable
1561 gnus-newsgroup-undownloaded
1562 gnus-newsgroup-unsendable
1563
eec82323
LMI
1564 gnus-newsgroup-begin gnus-newsgroup-end
1565 gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1566 gnus-newsgroup-last-folder gnus-newsgroup-last-file
26c9afc3 1567 gnus-newsgroup-last-directory
b1ae92ba
G
1568 gnus-newsgroup-auto-expire
1569 gnus-newsgroup-processable
23f87bed 1570 gnus-newsgroup-unfetched
b1ae92ba 1571 gnus-newsgroup-articles
eec82323
LMI
1572 gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1573 gnus-newsgroup-headers gnus-newsgroup-threads
1574 gnus-newsgroup-prepared gnus-summary-highlight-line-function
1575 gnus-current-article gnus-current-headers gnus-have-all-headers
1576 gnus-last-article gnus-article-internal-prepare-hook
1577 gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1578 gnus-newsgroup-scored gnus-newsgroup-kill-headers
1579 gnus-thread-expunge-below
16409b0b
GM
1580 gnus-score-alist gnus-current-score-file
1581 (gnus-summary-expunge-below . global)
eec82323 1582 (gnus-summary-mark-below . global)
16409b0b 1583 (gnus-orphan-score . global)
eec82323
LMI
1584 gnus-newsgroup-active gnus-scores-exclude-files
1585 gnus-newsgroup-history gnus-newsgroup-ancient
1586 gnus-newsgroup-sparse gnus-newsgroup-process-stack
1587 (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1588 gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1589 (gnus-newsgroup-expunged-tally . 0)
b1ae92ba 1590 gnus-cache-removable-articles
eec82323 1591 gnus-newsgroup-data gnus-newsgroup-data-reverse
16409b0b 1592 gnus-newsgroup-limit gnus-newsgroup-limits
23f87bed
MB
1593 gnus-newsgroup-charset gnus-newsgroup-display
1594 gnus-summary-use-undownloaded-faces)
eec82323
LMI
1595 "Variables that are buffer-local to the summary buffers.")
1596
23f87bed
MB
1597(defvar gnus-newsgroup-variables nil
1598 "A list of variables that have separate values in different newsgroups.
1599A list of newsgroup (summary buffer) local variables, or cons of
1600variables and their default expressions to be evalled (when the default
1601values are not nil), that should be made global while the summary buffer
1602is active.
1603
1604Note: The default expressions will be evaluated (using function `eval')
1605before assignment to the local variable rather than just assigned to it.
1606If the default expression is the symbol `global', that symbol will not
1607be evaluated but the global value of the local variable will be used
1608instead.
1609
1610These variables can be used to set variables in the group parameters
1611while still allowing them to affect operations done in other buffers.
1612For example:
1613
1614\(setq gnus-newsgroup-variables
1615 '(message-use-followup-to
1616 (gnus-visible-headers .
1617 \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1618")
1619
23f87bed
MB
1620(eval-when-compile
1621 ;; Bind features so that require will believe that gnus-sum has
1622 ;; already been loaded (avoids infinite recursion)
1623 (let ((features (cons 'gnus-sum features)))
23f87bed 1624 (require 'gnus-art)))
eec82323 1625
16409b0b
GM
1626;; MIME stuff.
1627
1628(defvar gnus-decode-encoded-word-methods
1629 '(mail-decode-encoded-word-string)
1630 "List of methods used to decode encoded words.
1631
23f87bed
MB
1632This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
1633is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
1634\(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
16409b0b
GM
1635whose names match REGEXP.
1636
1637For example:
23f87bed 1638\((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
16409b0b
GM
1639 mail-decode-encoded-word-string
1640 (\"chinese\" . rfc1843-decode-string))")
1641
1642(defvar gnus-decode-encoded-word-methods-cache nil)
1643
1644(defun gnus-multi-decode-encoded-word-string (string)
1645 "Apply the functions from `gnus-encoded-word-methods' that match."
1646 (unless (and gnus-decode-encoded-word-methods-cache
1647 (eq gnus-newsgroup-name
1648 (car gnus-decode-encoded-word-methods-cache)))
1649 (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
01c52d31
MB
1650 (dolist (method gnus-decode-encoded-word-methods)
1651 (if (symbolp method)
1652 (nconc gnus-decode-encoded-word-methods-cache (list method))
1653 (if (and gnus-newsgroup-name
1654 (string-match (car method) gnus-newsgroup-name))
1655 (nconc gnus-decode-encoded-word-methods-cache
1656 (list (cdr method)))))))
1657 (dolist (method (cdr gnus-decode-encoded-word-methods-cache) string)
1658 (setq string (funcall method string))))
16409b0b 1659
eec82323
LMI
1660;; Subject simplification.
1661
6748645f 1662(defun gnus-simplify-whitespace (str)
16409b0b 1663 "Remove excessive whitespace from STR."
23f87bed
MB
1664 ;; Multiple spaces.
1665 (while (string-match "[ \t][ \t]+" str)
1666 (setq str (concat (substring str 0 (match-beginning 0))
1667 " "
1668 (substring str (match-end 0)))))
1669 ;; Leading spaces.
1670 (when (string-match "^[ \t]+" str)
1671 (setq str (substring str (match-end 0))))
1672 ;; Trailing spaces.
1673 (when (string-match "[ \t]+$" str)
1674 (setq str (substring str 0 (match-beginning 0))))
1675 str)
1676
1677(defun gnus-simplify-all-whitespace (str)
1678 "Remove all whitespace from STR."
1679 (while (string-match "[ \t\n]+" str)
1680 (setq str (replace-match "" nil nil str)))
1681 str)
6748645f 1682
eec82323
LMI
1683(defsubst gnus-simplify-subject-re (subject)
1684 "Remove \"Re:\" from subject lines."
23f87bed 1685 (if (string-match message-subject-re-regexp subject)
eec82323
LMI
1686 (substring subject (match-end 0))
1687 subject))
1688
1689(defun gnus-simplify-subject (subject &optional re-only)
1690 "Remove `Re:' and words in parentheses.
1691If RE-ONLY is non-nil, strip leading `Re:'s only."
1692 (let ((case-fold-search t)) ;Ignore case.
1693 ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1694 (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1695 (setq subject (substring subject (match-end 0))))
1696 ;; Remove uninteresting prefixes.
1697 (when (and (not re-only)
1698 gnus-simplify-ignored-prefixes
1699 (string-match gnus-simplify-ignored-prefixes subject))
1700 (setq subject (substring subject (match-end 0))))
1701 ;; Remove words in parentheses from end.
1702 (unless re-only
1703 (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1704 (setq subject (substring subject 0 (match-beginning 0)))))
1705 ;; Return subject string.
1706 subject))
1707
1708;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1709;; all whitespace.
1710(defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1711 (goto-char (point-min))
1712 (while (re-search-forward regexp nil t)
16409b0b 1713 (replace-match (or newtext ""))))
eec82323
LMI
1714
1715(defun gnus-simplify-buffer-fuzzy ()
1716 "Simplify string in the buffer fuzzily.
1717The string in the accessible portion of the current buffer is simplified.
1718It is assumed to be a single-line subject.
1719Whitespace is generally cleaned up, and miscellaneous leading/trailing
1720matter is removed. Additional things can be deleted by setting
16409b0b 1721`gnus-simplify-subject-fuzzy-regexp'."
eec82323
LMI
1722 (let ((case-fold-search t)
1723 (modified-tick))
1724 (gnus-simplify-buffer-fuzzy-step "\t" " ")
1725
1726 (while (not (eq modified-tick (buffer-modified-tick)))
1727 (setq modified-tick (buffer-modified-tick))
1728 (cond
1729 ((listp gnus-simplify-subject-fuzzy-regexp)
01c52d31
MB
1730 (mapc 'gnus-simplify-buffer-fuzzy-step
1731 gnus-simplify-subject-fuzzy-regexp))
eec82323
LMI
1732 (gnus-simplify-subject-fuzzy-regexp
1733 (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1734 (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1735 (gnus-simplify-buffer-fuzzy-step
1736 "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1737 (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1738
1739 (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1740 (gnus-simplify-buffer-fuzzy-step " +" " ")
1741 (gnus-simplify-buffer-fuzzy-step " $")
1742 (gnus-simplify-buffer-fuzzy-step "^ +")))
1743
1744(defun gnus-simplify-subject-fuzzy (subject)
1745 "Simplify a subject string fuzzily.
6748645f 1746See `gnus-simplify-buffer-fuzzy' for details."
eec82323
LMI
1747 (save-excursion
1748 (gnus-set-work-buffer)
1749 (let ((case-fold-search t))
6748645f
LMI
1750 ;; Remove uninteresting prefixes.
1751 (when (and gnus-simplify-ignored-prefixes
1752 (string-match gnus-simplify-ignored-prefixes subject))
1753 (setq subject (substring subject (match-end 0))))
eec82323
LMI
1754 (insert subject)
1755 (inline (gnus-simplify-buffer-fuzzy))
1756 (buffer-string))))
1757
1758(defsubst gnus-simplify-subject-fully (subject)
23f87bed 1759 "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
eec82323 1760 (cond
6748645f
LMI
1761 (gnus-simplify-subject-functions
1762 (gnus-map-function gnus-simplify-subject-functions subject))
eec82323
LMI
1763 ((null gnus-summary-gather-subject-limit)
1764 (gnus-simplify-subject-re subject))
1765 ((eq gnus-summary-gather-subject-limit 'fuzzy)
1766 (gnus-simplify-subject-fuzzy subject))
1767 ((numberp gnus-summary-gather-subject-limit)
01c52d31
MB
1768 (truncate-string-to-width (gnus-simplify-subject-re subject)
1769 gnus-summary-gather-subject-limit))
eec82323
LMI
1770 (t
1771 subject)))
1772
1773(defsubst gnus-subject-equal (s1 s2 &optional simple-first)
6748645f 1774 "Check whether two subjects are equal.
23f87bed 1775If optional argument SIMPLE-FIRST is t, first argument is already
6748645f 1776simplified."
eec82323
LMI
1777 (cond
1778 ((null simple-first)
1779 (equal (gnus-simplify-subject-fully s1)
1780 (gnus-simplify-subject-fully s2)))
1781 (t
1782 (equal s1
1783 (gnus-simplify-subject-fully s2)))))
1784
1785(defun gnus-summary-bubble-group ()
1786 "Increase the score of the current group.
1787This is a handy function to add to `gnus-summary-exit-hook' to
1788increase the score of each group you read."
1789 (gnus-group-add-score gnus-newsgroup-name))
1790
1791\f
1792;;;
1793;;; Gnus summary mode
1794;;;
1795
1796(put 'gnus-summary-mode 'mode-class 'special)
1797
1653df0f
SZ
1798(defvar gnus-article-commands-menu)
1799
23f87bed
MB
1800;; Non-orthogonal keys
1801
1802(gnus-define-keys gnus-summary-mode-map
1803 " " gnus-summary-next-page
1804 "\177" gnus-summary-prev-page
1805 [delete] gnus-summary-prev-page
1806 [backspace] gnus-summary-prev-page
1807 "\r" gnus-summary-scroll-up
1808 "\M-\r" gnus-summary-scroll-down
1809 "n" gnus-summary-next-unread-article
1810 "p" gnus-summary-prev-unread-article
1811 "N" gnus-summary-next-article
1812 "P" gnus-summary-prev-article
1813 "\M-\C-n" gnus-summary-next-same-subject
1814 "\M-\C-p" gnus-summary-prev-same-subject
1815 "\M-n" gnus-summary-next-unread-subject
1816 "\M-p" gnus-summary-prev-unread-subject
1817 "." gnus-summary-first-unread-article
1818 "," gnus-summary-best-unread-article
1819 "\M-s" gnus-summary-search-article-forward
1820 "\M-r" gnus-summary-search-article-backward
01c52d31
MB
1821 "\M-S" gnus-summary-repeat-search-article-forward
1822 "\M-R" gnus-summary-repeat-search-article-backward
23f87bed
MB
1823 "<" gnus-summary-beginning-of-article
1824 ">" gnus-summary-end-of-article
1825 "j" gnus-summary-goto-article
1826 "^" gnus-summary-refer-parent-article
1827 "\M-^" gnus-summary-refer-article
1828 "u" gnus-summary-tick-article-forward
1829 "!" gnus-summary-tick-article-forward
1830 "U" gnus-summary-tick-article-backward
1831 "d" gnus-summary-mark-as-read-forward
1832 "D" gnus-summary-mark-as-read-backward
1833 "E" gnus-summary-mark-as-expirable
1834 "\M-u" gnus-summary-clear-mark-forward
1835 "\M-U" gnus-summary-clear-mark-backward
1836 "k" gnus-summary-kill-same-subject-and-select
1837 "\C-k" gnus-summary-kill-same-subject
1838 "\M-\C-k" gnus-summary-kill-thread
1839 "\M-\C-l" gnus-summary-lower-thread
1840 "e" gnus-summary-edit-article
1841 "#" gnus-summary-mark-as-processable
1842 "\M-#" gnus-summary-unmark-as-processable
1843 "\M-\C-t" gnus-summary-toggle-threads
1844 "\M-\C-s" gnus-summary-show-thread
1845 "\M-\C-h" gnus-summary-hide-thread
1846 "\M-\C-f" gnus-summary-next-thread
1847 "\M-\C-b" gnus-summary-prev-thread
1848 [(meta down)] gnus-summary-next-thread
1849 [(meta up)] gnus-summary-prev-thread
1850 "\M-\C-u" gnus-summary-up-thread
1851 "\M-\C-d" gnus-summary-down-thread
1852 "&" gnus-summary-execute-command
1853 "c" gnus-summary-catchup-and-exit
1854 "\C-w" gnus-summary-mark-region-as-read
1855 "\C-t" gnus-summary-toggle-truncation
1856 "?" gnus-summary-mark-as-dormant
1857 "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1858 "\C-c\C-s\C-n" gnus-summary-sort-by-number
6ecfe5c2 1859 "\C-c\C-s\C-m\C-n" gnus-summary-sort-by-most-recent-number
23f87bed
MB
1860 "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1861 "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1862 "\C-c\C-s\C-a" gnus-summary-sort-by-author
01c52d31 1863 "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
23f87bed
MB
1864 "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1865 "\C-c\C-s\C-d" gnus-summary-sort-by-date
6ecfe5c2 1866 "\C-c\C-s\C-m\C-d" gnus-summary-sort-by-most-recent-date
23f87bed
MB
1867 "\C-c\C-s\C-i" gnus-summary-sort-by-score
1868 "\C-c\C-s\C-o" gnus-summary-sort-by-original
1869 "\C-c\C-s\C-r" gnus-summary-sort-by-random
1870 "=" gnus-summary-expand-window
1871 "\C-x\C-s" gnus-summary-reselect-current-group
1872 "\M-g" gnus-summary-rescan-group
23f87bed
MB
1873 "\C-c\C-r" gnus-summary-caesar-message
1874 "f" gnus-summary-followup
1875 "F" gnus-summary-followup-with-original
1876 "C" gnus-summary-cancel-article
1877 "r" gnus-summary-reply
1878 "R" gnus-summary-reply-with-original
1879 "\C-c\C-f" gnus-summary-mail-forward
1880 "o" gnus-summary-save-article
1881 "\C-o" gnus-summary-save-article-mail
1882 "|" gnus-summary-pipe-output
1883 "\M-k" gnus-summary-edit-local-kill
1884 "\M-K" gnus-summary-edit-global-kill
1885 ;; "V" gnus-version
1886 "\C-c\C-d" gnus-summary-describe-group
1887 "q" gnus-summary-exit
1888 "Q" gnus-summary-exit-no-update
1889 "\C-c\C-i" gnus-info-find-node
1890 gnus-mouse-2 gnus-mouse-pick-article
132cf96d 1891 [follow-link] mouse-face
23f87bed
MB
1892 "m" gnus-summary-mail-other-window
1893 "a" gnus-summary-post-news
23f87bed
MB
1894 "x" gnus-summary-limit-to-unread
1895 "s" gnus-summary-isearch-article
1896 "t" gnus-summary-toggle-header
1897 "g" gnus-summary-show-article
1898 "l" gnus-summary-goto-last-article
1899 "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1900 "\C-d" gnus-summary-enter-digest-group
1901 "\M-\C-d" gnus-summary-read-document
1902 "\M-\C-e" gnus-summary-edit-parameters
1903 "\M-\C-a" gnus-summary-customize-parameters
1904 "\C-c\C-b" gnus-bug
1905 "*" gnus-cache-enter-article
1906 "\M-*" gnus-cache-remove-article
1907 "\M-&" gnus-summary-universal-argument
1908 "\C-l" gnus-recenter
1909 "I" gnus-summary-increase-score
1910 "L" gnus-summary-lower-score
1911 "\M-i" gnus-symbolic-argument
1912 "h" gnus-summary-select-article-buffer
1913
1914 "b" gnus-article-view-part
1915 "\M-t" gnus-summary-toggle-display-buttonized
1916
1917 "V" gnus-summary-score-map
1918 "X" gnus-uu-extract-map
1919 "S" gnus-summary-send-map)
1920
1921;; Sort of orthogonal keymap
1922(gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1923 "t" gnus-summary-tick-article-forward
1924 "!" gnus-summary-tick-article-forward
1925 "d" gnus-summary-mark-as-read-forward
1926 "r" gnus-summary-mark-as-read-forward
1927 "c" gnus-summary-clear-mark-forward
1928 " " gnus-summary-clear-mark-forward
1929 "e" gnus-summary-mark-as-expirable
1930 "x" gnus-summary-mark-as-expirable
1931 "?" gnus-summary-mark-as-dormant
1932 "b" gnus-summary-set-bookmark
1933 "B" gnus-summary-remove-bookmark
1934 "#" gnus-summary-mark-as-processable
1935 "\M-#" gnus-summary-unmark-as-processable
1936 "S" gnus-summary-limit-include-expunged
1937 "C" gnus-summary-catchup
1938 "H" gnus-summary-catchup-to-here
1939 "h" gnus-summary-catchup-from-here
1940 "\C-c" gnus-summary-catchup-all
1941 "k" gnus-summary-kill-same-subject-and-select
1942 "K" gnus-summary-kill-same-subject
1943 "P" gnus-uu-mark-map)
1944
1945(gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1946 "c" gnus-summary-clear-above
1947 "u" gnus-summary-tick-above
1948 "m" gnus-summary-mark-above
1949 "k" gnus-summary-kill-below)
1950
1951(gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1952 "/" gnus-summary-limit-to-subject
1953 "n" gnus-summary-limit-to-articles
01c52d31
MB
1954 "b" gnus-summary-limit-to-bodies
1955 "h" gnus-summary-limit-to-headers
23f87bed
MB
1956 "w" gnus-summary-pop-limit
1957 "s" gnus-summary-limit-to-subject
1958 "a" gnus-summary-limit-to-author
1959 "u" gnus-summary-limit-to-unread
1960 "m" gnus-summary-limit-to-marks
1961 "M" gnus-summary-limit-exclude-marks
1962 "v" gnus-summary-limit-to-score
1963 "*" gnus-summary-limit-include-cached
1964 "D" gnus-summary-limit-include-dormant
1965 "T" gnus-summary-limit-include-thread
1966 "d" gnus-summary-limit-exclude-dormant
1967 "t" gnus-summary-limit-to-age
1968 "." gnus-summary-limit-to-unseen
1969 "x" gnus-summary-limit-to-extra
1970 "p" gnus-summary-limit-to-display-predicate
1971 "E" gnus-summary-limit-include-expunged
1972 "c" gnus-summary-limit-exclude-childless-dormant
1973 "C" gnus-summary-limit-mark-excluded-as-read
1974 "o" gnus-summary-insert-old-articles
01c52d31
MB
1975 "N" gnus-summary-insert-new-articles
1976 "S" gnus-summary-limit-to-singletons
1977 "r" gnus-summary-limit-to-replied
1978 "R" gnus-summary-limit-to-recipient
1979 "A" gnus-summary-limit-to-address)
23f87bed
MB
1980
1981(gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1982 "n" gnus-summary-next-unread-article
1983 "p" gnus-summary-prev-unread-article
1984 "N" gnus-summary-next-article
1985 "P" gnus-summary-prev-article
1986 "\C-n" gnus-summary-next-same-subject
1987 "\C-p" gnus-summary-prev-same-subject
1988 "\M-n" gnus-summary-next-unread-subject
1989 "\M-p" gnus-summary-prev-unread-subject
1990 "f" gnus-summary-first-unread-article
1991 "b" gnus-summary-best-unread-article
1992 "j" gnus-summary-goto-article
1993 "g" gnus-summary-goto-subject
1994 "l" gnus-summary-goto-last-article
1995 "o" gnus-summary-pop-article)
1996
1997(gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1998 "k" gnus-summary-kill-thread
01c52d31 1999 "E" gnus-summary-expire-thread
23f87bed
MB
2000 "l" gnus-summary-lower-thread
2001 "i" gnus-summary-raise-thread
2002 "T" gnus-summary-toggle-threads
2003 "t" gnus-summary-rethread-current
2004 "^" gnus-summary-reparent-thread
01c52d31 2005 "\M-^" gnus-summary-reparent-children
23f87bed
MB
2006 "s" gnus-summary-show-thread
2007 "S" gnus-summary-show-all-threads
2008 "h" gnus-summary-hide-thread
2009 "H" gnus-summary-hide-all-threads
2010 "n" gnus-summary-next-thread
2011 "p" gnus-summary-prev-thread
2012 "u" gnus-summary-up-thread
2013 "o" gnus-summary-top-thread
2014 "d" gnus-summary-down-thread
2015 "#" gnus-uu-mark-thread
2016 "\M-#" gnus-uu-unmark-thread)
2017
2018(gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
2019 "g" gnus-summary-prepare
2020 "c" gnus-summary-insert-cached-articles
01c52d31
MB
2021 "d" gnus-summary-insert-dormant-articles
2022 "t" gnus-summary-insert-ticked-articles)
23f87bed
MB
2023
2024(gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
2025 "c" gnus-summary-catchup-and-exit
2026 "C" gnus-summary-catchup-all-and-exit
2027 "E" gnus-summary-exit-no-update
2028 "Q" gnus-summary-exit
2029 "Z" gnus-summary-exit
2030 "n" gnus-summary-catchup-and-goto-next-group
01c52d31 2031 "p" gnus-summary-catchup-and-goto-prev-group
23f87bed
MB
2032 "R" gnus-summary-reselect-current-group
2033 "G" gnus-summary-rescan-group
2034 "N" gnus-summary-next-group
2035 "s" gnus-summary-save-newsrc
2036 "P" gnus-summary-prev-group)
2037
2038(gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
2039 " " gnus-summary-next-page
2040 "n" gnus-summary-next-page
2041 "\177" gnus-summary-prev-page
2042 [delete] gnus-summary-prev-page
2043 "p" gnus-summary-prev-page
2044 "\r" gnus-summary-scroll-up
2045 "\M-\r" gnus-summary-scroll-down
2046 "<" gnus-summary-beginning-of-article
2047 ">" gnus-summary-end-of-article
2048 "b" gnus-summary-beginning-of-article
2049 "e" gnus-summary-end-of-article
2050 "^" gnus-summary-refer-parent-article
2051 "r" gnus-summary-refer-parent-article
8ccbef23 2052 "C" gnus-summary-show-complete-article
23f87bed
MB
2053 "D" gnus-summary-enter-digest-group
2054 "R" gnus-summary-refer-references
2055 "T" gnus-summary-refer-thread
2056 "g" gnus-summary-show-article
2057 "s" gnus-summary-isearch-article
2058 "P" gnus-summary-print-article
01c52d31 2059 "S" gnus-sticky-article
23f87bed
MB
2060 "M" gnus-mailing-list-insinuate
2061 "t" gnus-article-babel)
2062
2063(gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2064 "b" gnus-article-add-buttons
2065 "B" gnus-article-add-buttons-to-head
2066 "o" gnus-article-treat-overstrike
2067 "e" gnus-article-emphasize
2068 "w" gnus-article-fill-cited-article
2069 "Q" gnus-article-fill-long-lines
01c52d31 2070 "L" gnus-article-toggle-truncate-lines
23f87bed
MB
2071 "C" gnus-article-capitalize-sentences
2072 "c" gnus-article-remove-cr
2073 "q" gnus-article-de-quoted-unreadable
2074 "6" gnus-article-de-base64-unreadable
2075 "Z" gnus-article-decode-HZ
01c52d31 2076 "A" gnus-article-treat-ansi-sequences
23f87bed
MB
2077 "h" gnus-article-wash-html
2078 "u" gnus-article-unsplit-urls
2079 "s" gnus-summary-force-verify-and-decrypt
2080 "f" gnus-article-display-x-face
2081 "l" gnus-summary-stop-page-breaking
2082 "r" gnus-summary-caesar-message
2083 "m" gnus-summary-morse-message
2084 "t" gnus-summary-toggle-header
2085 "g" gnus-treat-smiley
2086 "v" gnus-summary-verbose-headers
2087 "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2088 "p" gnus-article-verify-x-pgp-sig
01c52d31
MB
2089 "d" gnus-article-treat-dumbquotes
2090 "i" gnus-summary-idna-message)
23f87bed
MB
2091
2092(gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2093 ;; mnemonic: deuglif*Y*
2094 "u" gnus-article-outlook-unwrap-lines
2095 "a" gnus-article-outlook-repair-attribution
2096 "c" gnus-article-outlook-rearrange-citation
2097 "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2098
2099(gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2100 "a" gnus-article-hide
2101 "h" gnus-article-hide-headers
2102 "b" gnus-article-hide-boring-headers
2103 "s" gnus-article-hide-signature
2104 "c" gnus-article-hide-citation
2105 "C" gnus-article-hide-citation-in-followups
2106 "l" gnus-article-hide-list-identifiers
2107 "B" gnus-article-strip-banner
2108 "P" gnus-article-hide-pem
2109 "\C-c" gnus-article-hide-citation-maybe)
2110
2111(gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2112 "a" gnus-article-highlight
2113 "h" gnus-article-highlight-headers
2114 "c" gnus-article-highlight-citation
2115 "s" gnus-article-highlight-signature)
2116
2117(gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2118 "f" gnus-article-treat-fold-headers
2119 "u" gnus-article-treat-unfold-headers
2120 "n" gnus-article-treat-fold-newsgroups)
2121
2122(gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2123 "x" gnus-article-display-x-face
2124 "d" gnus-article-display-face
2125 "s" gnus-treat-smiley
2126 "D" gnus-article-remove-images
25f28806 2127 "W" gnus-html-show-images
23f87bed
MB
2128 "f" gnus-treat-from-picon
2129 "m" gnus-treat-mail-picon
61b1af82
G
2130 "n" gnus-treat-newsgroups-picon
2131 "g" gnus-treat-from-gravatar
2132 "h" gnus-treat-mail-gravatar)
23f87bed
MB
2133
2134(gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2135 "w" gnus-article-decode-mime-words
2136 "c" gnus-article-decode-charset
2137 "v" gnus-mime-view-all-parts
2138 "b" gnus-article-view-part)
2139
2140(gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2141 "z" gnus-article-date-ut
2142 "u" gnus-article-date-ut
2143 "l" gnus-article-date-local
2144 "p" gnus-article-date-english
2145 "e" gnus-article-date-lapsed
2146 "o" gnus-article-date-original
2147 "i" gnus-article-date-iso8601
2148 "s" gnus-article-date-user)
2149
2150(gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2151 "t" gnus-article-remove-trailing-blank-lines
2152 "l" gnus-article-strip-leading-blank-lines
2153 "m" gnus-article-strip-multiple-blank-lines
2154 "a" gnus-article-strip-blank-lines
2155 "A" gnus-article-strip-all-blank-lines
2156 "s" gnus-article-strip-leading-space
2157 "e" gnus-article-strip-trailing-space
2158 "w" gnus-article-remove-leading-whitespace)
2159
2160(gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2161 "v" gnus-version
23f87bed
MB
2162 "d" gnus-summary-describe-group
2163 "h" gnus-summary-describe-briefly
2164 "i" gnus-info-find-node
23f87bed
MB
2165 "C" gnus-group-fetch-control)
2166
2167(gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2168 "e" gnus-summary-expire-articles
2169 "\M-\C-e" gnus-summary-expire-articles-now
2170 "\177" gnus-summary-delete-article
2171 [delete] gnus-summary-delete-article
2172 [backspace] gnus-summary-delete-article
2173 "m" gnus-summary-move-article
2174 "r" gnus-summary-respool-article
2175 "w" gnus-summary-edit-article
2176 "c" gnus-summary-copy-article
2177 "B" gnus-summary-crosspost-article
2178 "q" gnus-summary-respool-query
2179 "t" gnus-summary-respool-trace
2180 "i" gnus-summary-import-article
2181 "I" gnus-summary-create-article
2182 "p" gnus-summary-article-posted-p)
2183
2184(gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2185 "o" gnus-summary-save-article
2186 "m" gnus-summary-save-article-mail
2187 "F" gnus-summary-write-article-file
2188 "r" gnus-summary-save-article-rmail
2189 "f" gnus-summary-save-article-file
2190 "b" gnus-summary-save-article-body-file
26c9afc3 2191 "B" gnus-summary-write-article-body-file
23f87bed
MB
2192 "h" gnus-summary-save-article-folder
2193 "v" gnus-summary-save-article-vm
2194 "p" gnus-summary-pipe-output
c4d82de8 2195 "P" gnus-summary-muttprint)
23f87bed
MB
2196
2197(gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2198 "b" gnus-summary-display-buttonized
2199 "m" gnus-summary-repair-multipart
2200 "v" gnus-article-view-part
2201 "o" gnus-article-save-part
01c52d31
MB
2202 "O" gnus-article-save-part-and-strip
2203 "r" gnus-article-replace-part
2204 "d" gnus-article-delete-part
2205 "t" gnus-article-view-part-as-type
2206 "j" gnus-article-jump-to-part
23f87bed
MB
2207 "c" gnus-article-copy-part
2208 "C" gnus-article-view-part-as-charset
2209 "e" gnus-article-view-part-externally
01c52d31 2210 "H" gnus-article-browse-html-article
23f87bed
MB
2211 "E" gnus-article-encrypt-body
2212 "i" gnus-article-inline-part
2213 "|" gnus-article-pipe-part)
2214
2215(gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2216 "p" gnus-summary-mark-as-processable
2217 "u" gnus-summary-unmark-as-processable
2218 "U" gnus-summary-unmark-all-processable
2219 "v" gnus-uu-mark-over
2220 "s" gnus-uu-mark-series
2221 "r" gnus-uu-mark-region
2222 "g" gnus-uu-unmark-region
2223 "R" gnus-uu-mark-by-regexp
2224 "G" gnus-uu-unmark-by-regexp
2225 "t" gnus-uu-mark-thread
2226 "T" gnus-uu-unmark-thread
2227 "a" gnus-uu-mark-all
2228 "b" gnus-uu-mark-buffer
2229 "S" gnus-uu-mark-sparse
2230 "k" gnus-summary-kill-process-mark
2231 "y" gnus-summary-yank-process-mark
2232 "w" gnus-summary-save-process-mark
2233 "i" gnus-uu-invert-processable)
2234
2235(gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2236 ;;"x" gnus-uu-extract-any
2237 "m" gnus-summary-save-parts
2238 "u" gnus-uu-decode-uu
2239 "U" gnus-uu-decode-uu-and-save
2240 "s" gnus-uu-decode-unshar
2241 "S" gnus-uu-decode-unshar-and-save
2242 "o" gnus-uu-decode-save
2243 "O" gnus-uu-decode-save
2244 "b" gnus-uu-decode-binhex
2245 "B" gnus-uu-decode-binhex
b890d447 2246 "Y" gnus-uu-decode-yenc
23f87bed
MB
2247 "p" gnus-uu-decode-postscript
2248 "P" gnus-uu-decode-postscript-and-save)
2249
2250(gnus-define-keys
2251 (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2252 "u" gnus-uu-decode-uu-view
2253 "U" gnus-uu-decode-uu-and-save-view
2254 "s" gnus-uu-decode-unshar-view
2255 "S" gnus-uu-decode-unshar-and-save-view
2256 "o" gnus-uu-decode-save-view
2257 "O" gnus-uu-decode-save-view
2258 "b" gnus-uu-decode-binhex-view
2259 "B" gnus-uu-decode-binhex-view
2260 "p" gnus-uu-decode-postscript-view
2261 "P" gnus-uu-decode-postscript-and-save-view)
2262
2263(defvar gnus-article-post-menu nil)
2264
2265(defconst gnus-summary-menu-maxlen 20)
2266
2267(defun gnus-summary-menu-split (menu)
2268 ;; If we have lots of elements, divide them into groups of 20
2269 ;; and make a pane (or submenu) for each one.
2270 (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2271 (let ((menu menu) sublists next
2272 (i 1))
2273 (while menu
2274 ;; Pull off the next gnus-summary-menu-maxlen elements
2275 ;; and make them the next element of sublist.
2276 (setq next (nthcdr gnus-summary-menu-maxlen menu))
2277 (if next
2278 (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2279 nil))
2280 (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2281 (aref (car (last menu)) 0)) menu)
2282 sublists))
2283 (setq i (1+ i))
2284 (setq menu next))
2285 (nreverse sublists))
2286 ;; Few elements--put them all in one pane.
2287 menu))
eec82323
LMI
2288
2289(defun gnus-summary-make-menu-bar ()
2290 (gnus-turn-off-edit-menu 'summary)
2291
2292 (unless (boundp 'gnus-summary-misc-menu)
2293
2294 (easy-menu-define
23f87bed
MB
2295 gnus-summary-kill-menu gnus-summary-mode-map ""
2296 (cons
2297 "Score"
2298 (nconc
2299 (list
2300 ["Customize" gnus-score-customize t])
2301 (gnus-make-score-map 'increase)
2302 (gnus-make-score-map 'lower)
2303 '(("Mark"
2304 ["Kill below" gnus-summary-kill-below t]
2305 ["Mark above" gnus-summary-mark-above t]
2306 ["Tick above" gnus-summary-tick-above t]
2307 ["Clear above" gnus-summary-clear-above t])
2308 ["Current score" gnus-summary-current-score t]
2309 ["Set score" gnus-summary-set-score t]
2310 ["Switch current score file..." gnus-score-change-score-file t]
2311 ["Set mark below..." gnus-score-set-mark-below t]
2312 ["Set expunge below..." gnus-score-set-expunge-below t]
2313 ["Edit current score file" gnus-score-edit-current-scores t]
59429511 2314 ["Edit score file..." gnus-score-edit-file t]
23f87bed
MB
2315 ["Trace score" gnus-score-find-trace t]
2316 ["Find words" gnus-score-find-favourite-words t]
2317 ["Rescore buffer" gnus-summary-rescore t]
2318 ["Increase score..." gnus-summary-increase-score t]
2319 ["Lower score..." gnus-summary-lower-score t]))))
2320
2321 ;; Define both the Article menu in the summary buffer and the
2322 ;; equivalent Commands menu in the article buffer here for
2323 ;; consistency.
6748645f 2324 (let ((innards
23f87bed
MB
2325 `(("Hide"
2326 ["All" gnus-article-hide t]
2327 ["Headers" gnus-article-hide-headers t]
2328 ["Signature" gnus-article-hide-signature t]
2329 ["Citation" gnus-article-hide-citation t]
16409b0b 2330 ["List identifiers" gnus-article-hide-list-identifiers t]
16409b0b 2331 ["Banner" gnus-article-strip-banner t]
23f87bed
MB
2332 ["Boring headers" gnus-article-hide-boring-headers t])
2333 ("Highlight"
2334 ["All" gnus-article-highlight t]
2335 ["Headers" gnus-article-highlight-headers t]
2336 ["Signature" gnus-article-highlight-signature t]
2337 ["Citation" gnus-article-highlight-citation t])
16409b0b
GM
2338 ("MIME"
2339 ["Words" gnus-article-decode-mime-words t]
2340 ["Charset" gnus-article-decode-charset t]
2341 ["QP" gnus-article-de-quoted-unreadable t]
2342 ["Base64" gnus-article-de-base64-unreadable t]
23f87bed
MB
2343 ["View MIME buttons" gnus-summary-display-buttonized t]
2344 ["View all" gnus-mime-view-all-parts t]
2345 ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2346 ["Encrypt body" gnus-article-encrypt-body
2347 :active (not (gnus-group-read-only-p))
2348 ,@(if (featurep 'xemacs) nil
2349 '(:help "Encrypt the message body on disk"))]
2350 ["Extract all parts..." gnus-summary-save-parts t]
2351 ("Multipart"
2352 ["Repair multipart" gnus-summary-repair-multipart t]
2353 ["Pipe part..." gnus-article-pipe-part t]
2354 ["Inline part" gnus-article-inline-part t]
01c52d31 2355 ["View part as type..." gnus-article-view-part-as-type t]
23f87bed
MB
2356 ["Encrypt body" gnus-article-encrypt-body
2357 :active (not (gnus-group-read-only-p))
2358 ,@(if (featurep 'xemacs) nil
2359 '(:help "Encrypt the message body on disk"))]
2360 ["View part externally" gnus-article-view-part-externally t]
01c52d31 2361 ["View HTML parts in browser" gnus-article-browse-html-article t]
23f87bed
MB
2362 ["View part with charset..." gnus-article-view-part-as-charset t]
2363 ["Copy part" gnus-article-copy-part t]
2364 ["Save part..." gnus-article-save-part t]
2365 ["View part" gnus-article-view-part t]))
2366 ("Date"
2367 ["Local" gnus-article-date-local t]
2368 ["ISO8601" gnus-article-date-iso8601 t]
2369 ["UT" gnus-article-date-ut t]
2370 ["Original" gnus-article-date-original t]
2371 ["Lapsed" gnus-article-date-lapsed t]
2372 ["User-defined" gnus-article-date-user t])
2373 ("Display"
2374 ["Remove images" gnus-article-remove-images t]
2375 ["Toggle smiley" gnus-treat-smiley t]
2376 ["Show X-Face" gnus-article-display-x-face t]
2377 ["Show picons in From" gnus-treat-from-picon t]
2378 ["Show picons in mail headers" gnus-treat-mail-picon t]
2379 ["Show picons in news headers" gnus-treat-newsgroups-picon t]
61b1af82
G
2380 ["Show Gravatars in From" gnus-treat-from-gravatar t]
2381 ["Show Gravatars in mail headers" gnus-treat-mail-gravatar t]
23f87bed
MB
2382 ("View as different encoding"
2383 ,@(gnus-summary-menu-split
2384 (mapcar
2385 (lambda (cs)
2386 ;; Since easymenu under Emacs doesn't allow
2387 ;; lambda forms for menu commands, we should
2388 ;; provide intern'ed function symbols.
2389 (let ((command (intern (format "\
2390gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2391 (fset command
2392 `(lambda ()
2393 (interactive)
2394 (let ((gnus-summary-show-article-charset-alist
2395 '((1 . ,cs))))
2396 (gnus-summary-show-article 1))))
2397 `[,(symbol-name cs) ,command t]))
2398 (sort (if (fboundp 'coding-system-list)
2399 (coding-system-list)
2400 (mapcar 'car mm-mime-mule-charset-alist))
2401 'string<)))))
2402 ("Washing"
2403 ("Remove Blanks"
2404 ["Leading" gnus-article-strip-leading-blank-lines t]
2405 ["Multiple" gnus-article-strip-multiple-blank-lines t]
2406 ["Trailing" gnus-article-remove-trailing-blank-lines t]
2407 ["All of the above" gnus-article-strip-blank-lines t]
2408 ["All" gnus-article-strip-all-blank-lines t]
2409 ["Leading space" gnus-article-strip-leading-space t]
2410 ["Trailing space" gnus-article-strip-trailing-space t]
2411 ["Leading space in headers"
2412 gnus-article-remove-leading-whitespace t])
2413 ["Overstrike" gnus-article-treat-overstrike t]
2414 ["Dumb quotes" gnus-article-treat-dumbquotes t]
2415 ["Emphasis" gnus-article-emphasize t]
2416 ["Word wrap" gnus-article-fill-cited-article t]
16409b0b 2417 ["Fill long lines" gnus-article-fill-long-lines t]
01c52d31 2418 ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
16409b0b 2419 ["Capitalize sentences" gnus-article-capitalize-sentences t]
23f87bed
MB
2420 ["Remove CR" gnus-article-remove-cr t]
2421 ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2422 ["Base64" gnus-article-de-base64-unreadable t]
2423 ["Rot 13" gnus-summary-caesar-message
2424 ,@(if (featurep 'xemacs) '(t)
2425 '(:help "\"Caesar rotate\" article by 13"))]
01c52d31 2426 ["De-IDNA" gnus-summary-idna-message t]
23f87bed
MB
2427 ["Morse decode" gnus-summary-morse-message t]
2428 ["Unix pipe..." gnus-summary-pipe-message t]
2429 ["Add buttons" gnus-article-add-buttons t]
2430 ["Add buttons to head" gnus-article-add-buttons-to-head t]
2431 ["Stop page breaking" gnus-summary-stop-page-breaking t]
2432 ["Verbose header" gnus-summary-verbose-headers t]
2433 ["Toggle header" gnus-summary-toggle-header t]
2434 ["Unfold headers" gnus-article-treat-unfold-headers t]
2435 ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
16409b0b 2436 ["Html" gnus-article-wash-html t]
23f87bed
MB
2437 ["Unsplit URLs" gnus-article-unsplit-urls t]
2438 ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2439 ["Decode HZ" gnus-article-decode-HZ t]
01c52d31 2440 ["ANSI sequences" gnus-article-treat-ansi-sequences t]
23f87bed
MB
2441 ("(Outlook) Deuglify"
2442 ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2443 ["Repair attribution" gnus-article-outlook-repair-attribution t]
2444 ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2445 ["Full (Outlook) deuglify"
2446 gnus-article-outlook-deuglify-article t])
2447 )
2448 ("Output"
2449 ["Save in default format..." gnus-summary-save-article
2450 ,@(if (featurep 'xemacs) '(t)
2451 '(:help "Save article using default method"))]
2452 ["Save in file..." gnus-summary-save-article-file
2453 ,@(if (featurep 'xemacs) '(t)
2454 '(:help "Save article in file"))]
2455 ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2456 ["Save in MH folder..." gnus-summary-save-article-folder t]
2457 ["Save in VM folder..." gnus-summary-save-article-vm t]
2458 ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2459 ["Save body in file..." gnus-summary-save-article-body-file t]
2460 ["Pipe through a filter..." gnus-summary-pipe-output t]
23f87bed 2461 ["Print with Muttprint..." gnus-summary-muttprint t]
531e5812
MB
2462 ["Print" gnus-summary-print-article
2463 ,@(if (featurep 'xemacs) '(t)
2464 '(:help "Generate and print a PostScript image"))])
2465 ("Copy, move,... (Backend)"
707f2b38 2466 ,@(if (featurep 'xemacs) nil
531e5812 2467 '(:help "Copying, moving, expiring articles..."))
23f87bed
MB
2468 ["Respool article..." gnus-summary-respool-article t]
2469 ["Move article..." gnus-summary-move-article
2470 (gnus-check-backend-function
2471 'request-move-article gnus-newsgroup-name)]
2472 ["Copy article..." gnus-summary-copy-article t]
2473 ["Crosspost article..." gnus-summary-crosspost-article
2474 (gnus-check-backend-function
2475 'request-replace-article gnus-newsgroup-name)]
2476 ["Import file..." gnus-summary-import-article
2477 (gnus-check-backend-function
2478 'request-accept-article gnus-newsgroup-name)]
2479 ["Create article..." gnus-summary-create-article
2480 (gnus-check-backend-function
2481 'request-accept-article gnus-newsgroup-name)]
2482 ["Check if posted" gnus-summary-article-posted-p t]
2483 ["Edit article" gnus-summary-edit-article
2484 (not (gnus-group-read-only-p))]
2485 ["Delete article" gnus-summary-delete-article
2486 (gnus-check-backend-function
2487 'request-expire-articles gnus-newsgroup-name)]
2488 ["Query respool" gnus-summary-respool-query t]
6748645f 2489 ["Trace respool" gnus-summary-respool-trace t]
23f87bed
MB
2490 ["Delete expirable articles" gnus-summary-expire-articles-now
2491 (gnus-check-backend-function
2492 'request-expire-articles gnus-newsgroup-name)])
2493 ("Extract"
2494 ["Uudecode" gnus-uu-decode-uu
2495 ,@(if (featurep 'xemacs) '(t)
2496 '(:help "Decode uuencoded article(s)"))]
2497 ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2498 ["Unshar" gnus-uu-decode-unshar t]
2499 ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2500 ["Save" gnus-uu-decode-save t]
2501 ["Binhex" gnus-uu-decode-binhex t]
2502 ["Postscript" gnus-uu-decode-postscript t]
2503 ["All MIME parts" gnus-summary-save-parts t])
2504 ("Cache"
2505 ["Enter article" gnus-cache-enter-article t]
2506 ["Remove article" gnus-cache-remove-article t])
16409b0b 2507 ["Translate" gnus-article-babel t]
23f87bed 2508 ["Select article buffer" gnus-summary-select-article-buffer t]
01c52d31 2509 ["Make article buffer sticky" gnus-sticky-article t]
23f87bed
MB
2510 ["Enter digest buffer" gnus-summary-enter-digest-group t]
2511 ["Isearch article..." gnus-summary-isearch-article t]
2512 ["Beginning of the article" gnus-summary-beginning-of-article t]
2513 ["End of the article" gnus-summary-end-of-article t]
2514 ["Fetch parent of article" gnus-summary-refer-parent-article t]
2515 ["Fetch referenced articles" gnus-summary-refer-references t]
2516 ["Fetch current thread" gnus-summary-refer-thread t]
2517 ["Fetch article with id..." gnus-summary-refer-article t]
2518 ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2519 ["Redisplay" gnus-summary-show-article t]
2520 ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
6748645f 2521 (easy-menu-define
23f87bed
MB
2522 gnus-summary-article-menu gnus-summary-mode-map ""
2523 (cons "Article" innards))
6748645f 2524
1653df0f
SZ
2525 (if (not (keymapp gnus-summary-article-menu))
2526 (easy-menu-define
2527 gnus-article-commands-menu gnus-article-mode-map ""
2528 (cons "Commands" innards))
2529 ;; in Emacs, don't share menu.
a1506d29 2530 (setq gnus-article-commands-menu
1653df0f
SZ
2531 (copy-keymap gnus-summary-article-menu))
2532 (define-key gnus-article-mode-map [menu-bar commands]
2533 (cons "Commands" gnus-article-commands-menu))))
eec82323
LMI
2534
2535 (easy-menu-define
23f87bed
MB
2536 gnus-summary-thread-menu gnus-summary-mode-map ""
2537 '("Threads"
2538 ["Find all messages in thread" gnus-summary-refer-thread t]
2539 ["Toggle threading" gnus-summary-toggle-threads t]
2540 ["Hide threads" gnus-summary-hide-all-threads t]
2541 ["Show threads" gnus-summary-show-all-threads t]
2542 ["Hide thread" gnus-summary-hide-thread t]
2543 ["Show thread" gnus-summary-show-thread t]
2544 ["Go to next thread" gnus-summary-next-thread t]
2545 ["Go to previous thread" gnus-summary-prev-thread t]
2546 ["Go down thread" gnus-summary-down-thread t]
2547 ["Go up thread" gnus-summary-up-thread t]
2548 ["Top of thread" gnus-summary-top-thread t]
2549 ["Mark thread as read" gnus-summary-kill-thread t]
01c52d31 2550 ["Mark thread as expired" gnus-summary-expire-thread t]
23f87bed
MB
2551 ["Lower thread score" gnus-summary-lower-thread t]
2552 ["Raise thread score" gnus-summary-raise-thread t]
2553 ["Rethread current" gnus-summary-rethread-current t]))
eec82323
LMI
2554
2555 (easy-menu-define
23f87bed
MB
2556 gnus-summary-post-menu gnus-summary-mode-map ""
2557 `("Post"
2558 ["Send a message (mail or news)" gnus-summary-post-news
2559 ,@(if (featurep 'xemacs) '(t)
531e5812 2560 '(:help "Compose a new message (mail or news)"))]
23f87bed
MB
2561 ["Followup" gnus-summary-followup
2562 ,@(if (featurep 'xemacs) '(t)
2563 '(:help "Post followup to this article"))]
2564 ["Followup and yank" gnus-summary-followup-with-original
2565 ,@(if (featurep 'xemacs) '(t)
2566 '(:help "Post followup to this article, quoting its contents"))]
2567 ["Supersede article" gnus-summary-supersede-article t]
2568 ["Cancel article" gnus-summary-cancel-article
2569 ,@(if (featurep 'xemacs) '(t)
2570 '(:help "Cancel an article you posted"))]
2571 ["Reply" gnus-summary-reply t]
2572 ["Reply and yank" gnus-summary-reply-with-original t]
2573 ["Wide reply" gnus-summary-wide-reply t]
2574 ["Wide reply and yank" gnus-summary-wide-reply-with-original
2575 ,@(if (featurep 'xemacs) '(t)
2576 '(:help "Mail a reply, quoting this article"))]
2577 ["Very wide reply" gnus-summary-very-wide-reply t]
2578 ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2579 ,@(if (featurep 'xemacs) '(t)
2580 '(:help "Mail a very wide reply, quoting this article"))]
2581 ["Mail forward" gnus-summary-mail-forward t]
2582 ["Post forward" gnus-summary-post-forward t]
2583 ["Digest and mail" gnus-uu-digest-mail-forward t]
2584 ["Digest and post" gnus-uu-digest-post-forward t]
2585 ["Resend message" gnus-summary-resend-message t]
2586 ["Resend message edit" gnus-summary-resend-message-edit t]
2587 ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2588 ["Send a mail" gnus-summary-mail-other-window t]
2589 ["Create a local message" gnus-summary-news-other-window t]
2590 ["Uuencode and post" gnus-uu-post-news
2591 ,@(if (featurep 'xemacs) '(t)
2592 '(:help "Post a uuencoded article"))]
2593 ["Followup via news" gnus-summary-followup-to-mail t]
2594 ["Followup via news and yank"
2595 gnus-summary-followup-to-mail-with-original t]
9b3ebcb6
MB
2596 ["Strip signature on reply"
2597 (lambda ()
2598 (interactive)
2599 (if (not (memq message-cite-function
2600 '(message-cite-original-without-signature
2601 message-cite-original)))
2602 ;; Stupid workaround for XEmacs not honoring :visible.
2603 (message "Can't toggle this value of `message-cite-function'")
2604 (setq message-cite-function
2605 (if (eq message-cite-function
2606 'message-cite-original-without-signature)
2607 'message-cite-original
2608 'message-cite-original-without-signature))))
2609 ;; XEmacs barfs on :visible.
2610 ,@(if (featurep 'xemacs) nil
2611 '(:visible (memq message-cite-function
2612 '(message-cite-original-without-signature
2613 message-cite-original))))
2614 :style toggle
2615 :selected (eq message-cite-function
2616 'message-cite-original-without-signature)
2617 ,@(if (featurep 'xemacs) nil
2618 '(:help "Strip signature from cited article when replying."))]
23f87bed
MB
2619 ;;("Draft"
2620 ;;["Send" gnus-summary-send-draft t]
2621 ;;["Send bounced" gnus-resend-bounced-mail t])
2622 ))
2623
2624 (cond
2625 ((not (keymapp gnus-summary-post-menu))
2626 (setq gnus-article-post-menu gnus-summary-post-menu))
2627 ((not gnus-article-post-menu)
2628 ;; Don't share post menu.
2629 (setq gnus-article-post-menu
2630 (copy-keymap gnus-summary-post-menu))))
2631 (define-key gnus-article-mode-map [menu-bar post]
2632 (cons "Post" gnus-article-post-menu))
eec82323
LMI
2633
2634 (easy-menu-define
23f87bed
MB
2635 gnus-summary-misc-menu gnus-summary-mode-map ""
2636 `("Gnus"
2637 ("Mark Read"
2638 ["Mark as read" gnus-summary-mark-as-read-forward t]
2639 ["Mark same subject and select"
2640 gnus-summary-kill-same-subject-and-select t]
2641 ["Mark same subject" gnus-summary-kill-same-subject t]
2642 ["Catchup" gnus-summary-catchup
2643 ,@(if (featurep 'xemacs) '(t)
2644 '(:help "Mark unread articles in this group as read"))]
2645 ["Catchup all" gnus-summary-catchup-all t]
2646 ["Catchup to here" gnus-summary-catchup-to-here t]
2647 ["Catchup from here" gnus-summary-catchup-from-here t]
2648 ["Catchup region" gnus-summary-mark-region-as-read
2649 (gnus-mark-active-p)]
2650 ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2651 ("Mark Various"
2652 ["Tick" gnus-summary-tick-article-forward t]
2653 ["Mark as dormant" gnus-summary-mark-as-dormant t]
2654 ["Remove marks" gnus-summary-clear-mark-forward t]
2655 ["Set expirable mark" gnus-summary-mark-as-expirable t]
2656 ["Set bookmark" gnus-summary-set-bookmark t]
2657 ["Remove bookmark" gnus-summary-remove-bookmark t])
2658 ("Limit to"
2659 ["Marks..." gnus-summary-limit-to-marks t]
2660 ["Subject..." gnus-summary-limit-to-subject t]
2661 ["Author..." gnus-summary-limit-to-author t]
01c52d31
MB
2662 ["Recipient..." gnus-summary-limit-to-recipient t]
2663 ["Address..." gnus-summary-limit-to-address t]
23f87bed
MB
2664 ["Age..." gnus-summary-limit-to-age t]
2665 ["Extra..." gnus-summary-limit-to-extra t]
2666 ["Score..." gnus-summary-limit-to-score t]
2667 ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2668 ["Unread" gnus-summary-limit-to-unread t]
2669 ["Unseen" gnus-summary-limit-to-unseen t]
01c52d31
MB
2670 ["Singletons" gnus-summary-limit-to-singletons t]
2671 ["Replied" gnus-summary-limit-to-replied t]
23f87bed 2672 ["Non-dormant" gnus-summary-limit-exclude-dormant t]
996aa8c1 2673 ["Next or process marked articles" gnus-summary-limit-to-articles t]
23f87bed
MB
2674 ["Pop limit" gnus-summary-pop-limit t]
2675 ["Show dormant" gnus-summary-limit-include-dormant t]
2676 ["Hide childless dormant"
2677 gnus-summary-limit-exclude-childless-dormant t]
2678 ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2679 ["Hide marked" gnus-summary-limit-exclude-marks t]
2680 ["Show expunged" gnus-summary-limit-include-expunged t])
2681 ("Process Mark"
2682 ["Set mark" gnus-summary-mark-as-processable t]
2683 ["Remove mark" gnus-summary-unmark-as-processable t]
2684 ["Remove all marks" gnus-summary-unmark-all-processable t]
01c52d31 2685 ["Invert marks" gnus-uu-invert-processable t]
23f87bed
MB
2686 ["Mark above" gnus-uu-mark-over t]
2687 ["Mark series" gnus-uu-mark-series t]
2688 ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2689 ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2690 ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2691 ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2692 ["Mark all" gnus-uu-mark-all t]
2693 ["Mark buffer" gnus-uu-mark-buffer t]
2694 ["Mark sparse" gnus-uu-mark-sparse t]
2695 ["Mark thread" gnus-uu-mark-thread t]
2696 ["Unmark thread" gnus-uu-unmark-thread t]
2697 ("Process Mark Sets"
2698 ["Kill" gnus-summary-kill-process-mark t]
2699 ["Yank" gnus-summary-yank-process-mark
2700 gnus-newsgroup-process-stack]
2701 ["Save" gnus-summary-save-process-mark t]
2702 ["Run command on marked..." gnus-summary-universal-argument t]))
ec7995fa 2703 ("Registry Marks")
23f87bed
MB
2704 ("Scroll article"
2705 ["Page forward" gnus-summary-next-page
2706 ,@(if (featurep 'xemacs) '(t)
2707 '(:help "Show next page of article"))]
2708 ["Page backward" gnus-summary-prev-page
2709 ,@(if (featurep 'xemacs) '(t)
2710 '(:help "Show previous page of article"))]
2711 ["Line forward" gnus-summary-scroll-up t])
2712 ("Move"
2713 ["Next unread article" gnus-summary-next-unread-article t]
2714 ["Previous unread article" gnus-summary-prev-unread-article t]
2715 ["Next article" gnus-summary-next-article t]
2716 ["Previous article" gnus-summary-prev-article t]
2717 ["Next unread subject" gnus-summary-next-unread-subject t]
2718 ["Previous unread subject" gnus-summary-prev-unread-subject t]
2719 ["Next article same subject" gnus-summary-next-same-subject t]
2720 ["Previous article same subject" gnus-summary-prev-same-subject t]
2721 ["First unread article" gnus-summary-first-unread-article t]
2722 ["Best unread article" gnus-summary-best-unread-article t]
2723 ["Go to subject number..." gnus-summary-goto-subject t]
2724 ["Go to article number..." gnus-summary-goto-article t]
2725 ["Go to the last article" gnus-summary-goto-last-article t]
2726 ["Pop article off history" gnus-summary-pop-article t])
2727 ("Sort"
2728 ["Sort by number" gnus-summary-sort-by-number t]
6ecfe5c2 2729 ["Sort by most recent number" gnus-summary-sort-by-most-recent-number t]
23f87bed 2730 ["Sort by author" gnus-summary-sort-by-author t]
01c52d31 2731 ["Sort by recipient" gnus-summary-sort-by-recipient t]
23f87bed
MB
2732 ["Sort by subject" gnus-summary-sort-by-subject t]
2733 ["Sort by date" gnus-summary-sort-by-date t]
6ecfe5c2 2734 ["Sort by most recent date" gnus-summary-sort-by-most-recent-date t]
23f87bed
MB
2735 ["Sort by score" gnus-summary-sort-by-score t]
2736 ["Sort by lines" gnus-summary-sort-by-lines t]
2737 ["Sort by characters" gnus-summary-sort-by-chars t]
2738 ["Randomize" gnus-summary-sort-by-random t]
2739 ["Original sort" gnus-summary-sort-by-original t])
2740 ("Help"
23f87bed 2741 ["Describe group" gnus-summary-describe-group t]
23f87bed
MB
2742 ["Fetch control message" gnus-group-fetch-control
2743 ,@(if (featurep 'xemacs) nil
2744 '(:help "Display the archived control message for the current group"))]
2745 ["Read manual" gnus-info-find-node t])
2746 ("Modes"
2747 ["Pick and read" gnus-pick-mode t]
2748 ["Binary" gnus-binary-mode t])
2749 ("Regeneration"
2750 ["Regenerate" gnus-summary-prepare t]
2751 ["Insert cached articles" gnus-summary-insert-cached-articles t]
2752 ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
01c52d31 2753 ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
23f87bed
MB
2754 ["Toggle threading" gnus-summary-toggle-threads t])
2755 ["See old articles" gnus-summary-insert-old-articles t]
2756 ["See new articles" gnus-summary-insert-new-articles t]
2757 ["Filter articles..." gnus-summary-execute-command t]
2758 ["Run command on articles..." gnus-summary-universal-argument t]
2759 ["Search articles forward..." gnus-summary-search-article-forward t]
2760 ["Search articles backward..." gnus-summary-search-article-backward t]
2761 ["Toggle line truncation" gnus-summary-toggle-truncation t]
2762 ["Expand window" gnus-summary-expand-window t]
2763 ["Expire expirable articles" gnus-summary-expire-articles
2764 (gnus-check-backend-function
2765 'request-expire-articles gnus-newsgroup-name)]
2766 ["Edit local kill file" gnus-summary-edit-local-kill t]
2767 ["Edit main kill file" gnus-summary-edit-global-kill t]
2768 ["Edit group parameters" gnus-summary-edit-parameters t]
2769 ["Customize group parameters" gnus-summary-customize-parameters t]
2770 ["Send a bug report" gnus-bug t]
2771 ("Exit"
2772 ["Catchup and exit" gnus-summary-catchup-and-exit
2773 ,@(if (featurep 'xemacs) '(t)
2774 '(:help "Mark unread articles in this group as read, then exit"))]
2775 ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2776 ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
01c52d31 2777 ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
23f87bed
MB
2778 ["Exit group" gnus-summary-exit
2779 ,@(if (featurep 'xemacs) '(t)
2780 '(:help "Exit current group, return to group selection mode"))]
2781 ["Exit group without updating" gnus-summary-exit-no-update t]
2782 ["Exit and goto next group" gnus-summary-next-group t]
2783 ["Exit and goto prev group" gnus-summary-prev-group t]
2784 ["Reselect group" gnus-summary-reselect-current-group t]
2785 ["Rescan group" gnus-summary-rescan-group t]
2786 ["Update dribble" gnus-summary-save-newsrc t])))
eec82323 2787
6748645f 2788 (gnus-run-hooks 'gnus-summary-menu-hook)))
eec82323 2789
60bd5589
DL
2790(defvar gnus-summary-tool-bar-map nil)
2791
18c06a99
RS
2792;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2793;; affect _new_ message buffers. We might add a function that walks thru all
2794;; summary-mode buffers and force the update.
2795(defun gnus-summary-tool-bar-update (&optional symbol value)
2796 "Update summary mode toolbar.
2797Setter function for custom variables."
2798 (setq-default gnus-summary-tool-bar-map nil)
2799 (when symbol
2800 ;; When used as ":set" function:
2801 (set-default symbol value))
2802 (when (gnus-buffer-live-p gnus-summary-buffer)
2803 (with-current-buffer gnus-summary-buffer
2804 (gnus-summary-make-tool-bar))))
2805
2806(defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2807 'gnus-summary-tool-bar-gnome
2808 'gnus-summary-tool-bar-retro)
2809 "Specifies the Gnus summary tool bar.
2810
2811It can be either a list or a symbol refering to a list. See
2812`gmm-tool-bar-from-list' for the format of the list. The
2813default key map is `gnus-summary-mode-map'.
2814
2815Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2816`gnus-summary-tool-bar-retro'."
2817 :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2818 (const :tag "Retro look" gnus-summary-tool-bar-retro)
2819 (repeat :tag "User defined list" gmm-tool-bar-item)
2820 (symbol))
330f707b 2821 :version "23.1" ;; No Gnus
18c06a99
RS
2822 :initialize 'custom-initialize-default
2823 :set 'gnus-summary-tool-bar-update
2824 :group 'gnus-summary)
2825
2826(defcustom gnus-summary-tool-bar-gnome
2827 '((gnus-summary-post-news "mail/compose" nil)
2828 (gnus-summary-insert-new-articles "mail/inbox" nil
2829 :visible (or (not gnus-agent)
2830 gnus-plugged))
2831 (gnus-summary-reply-with-original "mail/reply")
2832 (gnus-summary-reply "mail/reply" nil :visible nil)
2833 (gnus-summary-followup-with-original "mail/reply-all")
2834 (gnus-summary-followup "mail/reply-all" nil :visible nil)
2835 (gnus-summary-mail-forward "mail/forward")
2836 (gnus-summary-save-article "mail/save")
2837 (gnus-summary-search-article-forward "search" nil :visible nil)
2838 (gnus-summary-print-article "print")
2839 (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2840 ;; Some new commands that may need more suitable icons:
2841 (gnus-summary-save-newsrc "save" nil :visible nil)
2842 ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2843 (gnus-summary-prev-article "left-arrow")
2844 (gnus-summary-next-article "right-arrow")
2845 (gnus-summary-next-page "next-page")
2846 ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2847 ;;
2848 ;; Maybe some sort-by-... could be added:
2849 ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2850 ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2851 (gnus-summary-mark-as-expirable
2852 "delete" nil
2853 :visible (gnus-check-backend-function 'request-expire-articles
2854 gnus-newsgroup-name))
2855 (gnus-summary-mark-as-spam
2856 "mail/spam" t
2857 :visible (and (fboundp 'spam-group-ham-contents-p)
2858 (spam-group-ham-contents-p gnus-newsgroup-name))
2859 :help "Mark as spam")
2860 (gnus-summary-mark-as-read-forward
2861 "mail/not-spam" nil
2862 :visible (and (fboundp 'spam-group-spam-contents-p)
2863 (spam-group-spam-contents-p gnus-newsgroup-name)))
2864 ;;
2865 (gnus-summary-exit "exit")
2866 (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2867 (gnus-info-find-node "help"))
2868 "List of functions for the summary tool bar (GNOME style).
2869
2870See `gmm-tool-bar-from-list' for the format of the list."
2871 :type '(repeat gmm-tool-bar-item)
330f707b 2872 :version "23.1" ;; No Gnus
18c06a99
RS
2873 :initialize 'custom-initialize-default
2874 :set 'gnus-summary-tool-bar-update
2875 :group 'gnus-summary)
2876
2877(defcustom gnus-summary-tool-bar-retro
2878 '((gnus-summary-prev-unread-article "gnus/prev-ur")
2879 (gnus-summary-next-unread-article "gnus/next-ur")
2880 (gnus-summary-post-news "gnus/post")
2881 (gnus-summary-followup-with-original "gnus/fuwo")
2882 (gnus-summary-followup "gnus/followup")
2883 (gnus-summary-reply-with-original "gnus/reply-wo")
2884 (gnus-summary-reply "gnus/reply")
2885 (gnus-summary-caesar-message "gnus/rot13")
2886 (gnus-uu-decode-uu "gnus/uu-decode")
2887 (gnus-summary-save-article-file "gnus/save-aif")
2888 (gnus-summary-save-article "gnus/save-art")
2889 (gnus-uu-post-news "gnus/uu-post")
2890 (gnus-summary-catchup "gnus/catchup")
2891 (gnus-summary-catchup-and-exit "gnus/cu-exit")
2892 (gnus-summary-exit "gnus/exit-summ")
2893 ;; Some new command that may need more suitable icons:
2894 (gnus-summary-print-article "gnus/print" nil :visible nil)
2895 (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2896 (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2897 ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2898 (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2899 ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2900 ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2901 ;;
2902 (gnus-info-find-node "gnus/help" nil :visible nil))
2903 "List of functions for the summary tool bar (retro look).
2904
2905See `gmm-tool-bar-from-list' for the format of the list."
2906 :type '(repeat gmm-tool-bar-item)
330f707b 2907 :version "23.1" ;; No Gnus
18c06a99
RS
2908 :initialize 'custom-initialize-default
2909 :set 'gnus-summary-tool-bar-update
2910 :group 'gnus-summary)
2911
2912(defcustom gnus-summary-tool-bar-zap-list t
2913 "List of icon items from the global tool bar.
2914These items are not displayed in the Gnus summary mode tool bar.
2915
2916See `gmm-tool-bar-from-list' for the format of the list."
2917 :type 'gmm-tool-bar-zap-list
330f707b 2918 :version "23.1" ;; No Gnus
18c06a99
RS
2919 :initialize 'custom-initialize-default
2920 :set 'gnus-summary-tool-bar-update
2921 :group 'gnus-summary)
2922
2923(defvar image-load-path)
f654fa04 2924(defvar tool-bar-map)
18c06a99
RS
2925
2926(defun gnus-summary-make-tool-bar (&optional force)
2927 "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2928When FORCE, rebuild the tool bar."
2929 (when (and (not (featurep 'xemacs))
2930 (boundp 'tool-bar-mode)
2931 tool-bar-mode
2932 (or (not gnus-summary-tool-bar-map) force))
2933 (let* ((load-path
2934 (gmm-image-load-path-for-library "gnus"
2935 "mail/save.xpm"
2936 nil t))
2937 (image-load-path (cons (car load-path)
2938 (when (boundp 'image-load-path)
2939 image-load-path)))
2940 (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2941 gnus-summary-tool-bar-zap-list
2942 'gnus-summary-mode-map)))
2943 (when map
2944 ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2945 ;; uses it's value.
2946 (setq gnus-summary-tool-bar-map map))))
2947 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
60bd5589 2948
eec82323
LMI
2949(defun gnus-score-set-default (var value)
2950 "A version of set that updates the GNU Emacs menu-bar."
2951 (set var value)
2952 ;; It is the message that forces the active status to be updated.
2953 (message ""))
2954
2955(defun gnus-make-score-map (type)
2956 "Make a summary score map of type TYPE."
2957 (if t
2958 nil
2959 (let ((headers '(("author" "from" string)
2960 ("subject" "subject" string)
2961 ("article body" "body" string)
2962 ("article head" "head" string)
2963 ("xref" "xref" string)
16409b0b 2964 ("extra header" "extra" string)
eec82323
LMI
2965 ("lines" "lines" number)
2966 ("followups to author" "followup" string)))
2967 (types '((number ("less than" <)
2968 ("greater than" >)
2969 ("equal" =))
2970 (string ("substring" s)
2971 ("exact string" e)
2972 ("fuzzy string" f)
2973 ("regexp" r))))
2974 (perms '(("temporary" (current-time-string))
2975 ("permanent" nil)
2976 ("immediate" now)))
2977 header)
2978 (list
2979 (apply
2980 'nconc
2981 (list
2982 (if (eq type 'lower)
2983 "Lower score"
2984 "Increase score"))
2985 (let (outh)
2986 (while headers
2987 (setq header (car headers))
2988 (setq outh
2989 (cons
2990 (apply
2991 'nconc
2992 (list (car header))
2993 (let ((ts (cdr (assoc (nth 2 header) types)))
2994 outt)
2995 (while ts
2996 (setq outt
2997 (cons
2998 (apply
2999 'nconc
3000 (list (caar ts))
3001 (let ((ps perms)
3002 outp)
3003 (while ps
3004 (setq outp
3005 (cons
3006 (vector
3007 (caar ps)
3008 (list
3009 'gnus-summary-score-entry
3010 (nth 1 header)
3011 (if (or (string= (nth 1 header)
3012 "head")
3013 (string= (nth 1 header)
3014 "body"))
3015 ""
3016 (list 'gnus-summary-header
3017 (nth 1 header)))
3018 (list 'quote (nth 1 (car ts)))
16409b0b
GM
3019 (list 'gnus-score-delta-default
3020 nil)
eec82323
LMI
3021 (nth 1 (car ps))
3022 t)
3023 t)
3024 outp))
3025 (setq ps (cdr ps)))
3026 (list (nreverse outp))))
3027 outt))
3028 (setq ts (cdr ts)))
3029 (list (nreverse outt))))
3030 outh))
3031 (setq headers (cdr headers)))
3032 (list (nreverse outh))))))))
3033
704f1663
GM
3034
3035(declare-function turn-on-gnus-mailing-list-mode "gnus-ml" ())
398a825b 3036(defvar bookmark-make-record-function)
eec82323
LMI
3037\f
3038
3039(defun gnus-summary-mode (&optional group)
3040 "Major mode for reading articles.
3041
3042All normal editing commands are switched off.
3043\\<gnus-summary-mode-map>
3044Each line in this buffer represents one article. To read an
3045article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
3046and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
3047respectively.
3048
3049You can also post articles and send mail from this buffer. To
23f87bed 3050follow up an article, type `\\[gnus-summary-followup]'. To mail a reply to the author
eec82323
LMI
3051of an article, type `\\[gnus-summary-reply]'.
3052
3053There are approx. one gazillion commands you can execute in this
3054buffer; read the info pages for more information (`\\[gnus-info-find-node]').
3055
3056The following commands are available:
3057
3058\\{gnus-summary-mode-map}"
3059 (interactive)
eec82323 3060 (kill-all-local-variables)
01c52d31
MB
3061 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
3062 (gnus-summary-make-local-variables))
3063 (gnus-summary-make-local-variables)
3064 (setq gnus-newsgroup-name group)
60bd5589
DL
3065 (when (gnus-visual-p 'summary-menu 'menu)
3066 (gnus-summary-make-menu-bar)
3067 (gnus-summary-make-tool-bar))
eec82323
LMI
3068 (gnus-make-thread-indent-array)
3069 (gnus-simplify-mode-line)
3070 (setq major-mode 'gnus-summary-mode)
3071 (setq mode-name "Summary")
eec82323 3072 (use-local-map gnus-summary-mode-map)
16409b0b 3073 (buffer-disable-undo)
01c52d31
MB
3074 (setq buffer-read-only t ;Disable modification
3075 show-trailing-whitespace nil)
eec82323 3076 (setq truncate-lines t)
9bfd9a76 3077 (add-to-invisibility-spec '(gnus-sum . t))
eec82323
LMI
3078 (gnus-summary-set-display-table)
3079 (gnus-set-default-directory)
eec82323
LMI
3080 (make-local-variable 'gnus-summary-line-format)
3081 (make-local-variable 'gnus-summary-line-format-spec)
6748645f
LMI
3082 (make-local-variable 'gnus-summary-dummy-line-format)
3083 (make-local-variable 'gnus-summary-dummy-line-format-spec)
eec82323 3084 (make-local-variable 'gnus-summary-mark-positions)
23f87bed 3085 (gnus-make-local-hook 'pre-command-hook)
6748645f 3086 (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
cfcd5c91 3087 (gnus-run-mode-hooks 'gnus-summary-mode-hook)
23f87bed 3088 (turn-on-gnus-mailing-list-mode)
87545352 3089 (mm-enable-multibyte)
45be326a
TV
3090 (set (make-local-variable 'bookmark-make-record-function)
3091 'gnus-summary-bookmark-make-record)
eec82323
LMI
3092 (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3093 (gnus-update-summary-mark-positions))
3094
3095(defun gnus-summary-make-local-variables ()
3096 "Make all the local summary buffer variables."
16409b0b
GM
3097 (let (global)
3098 (dolist (local gnus-summary-local-variables)
eec82323
LMI
3099 (if (consp local)
3100 (progn
3101 (if (eq (cdr local) 'global)
3102 ;; Copy the global value of the variable.
3103 (setq global (symbol-value (car local)))
3104 ;; Use the value from the list.
3105 (setq global (eval (cdr local))))
16409b0b 3106 (set (make-local-variable (car local)) global))
eec82323 3107 ;; Simple nil-valued local variable.
16409b0b 3108 (set (make-local-variable local) nil)))))
eec82323
LMI
3109
3110(defun gnus-summary-clear-local-variables ()
3111 (let ((locals gnus-summary-local-variables))
3112 (while locals
3113 (if (consp (car locals))
01c52d31 3114 (and (symbolp (caar locals))
eec82323 3115 (set (caar locals) nil))
01c52d31 3116 (and (symbolp (car locals))
eec82323
LMI
3117 (set (car locals) nil)))
3118 (setq locals (cdr locals)))))
3119
3120;; Summary data functions.
3121
3122(defmacro gnus-data-number (data)
3123 `(car ,data))
3124
3125(defmacro gnus-data-set-number (data number)
3126 `(setcar ,data ,number))
3127
3128(defmacro gnus-data-mark (data)
3129 `(nth 1 ,data))
3130
3131(defmacro gnus-data-set-mark (data mark)
3132 `(setcar (nthcdr 1 ,data) ,mark))
3133
3134(defmacro gnus-data-pos (data)
3135 `(nth 2 ,data))
3136
3137(defmacro gnus-data-set-pos (data pos)
3138 `(setcar (nthcdr 2 ,data) ,pos))
3139
3140(defmacro gnus-data-header (data)
3141 `(nth 3 ,data))
3142
3143(defmacro gnus-data-set-header (data header)
3144 `(setf (nth 3 ,data) ,header))
3145
3146(defmacro gnus-data-level (data)
3147 `(nth 4 ,data))
3148
3149(defmacro gnus-data-unread-p (data)
3150 `(= (nth 1 ,data) gnus-unread-mark))
3151
3152(defmacro gnus-data-read-p (data)
3153 `(/= (nth 1 ,data) gnus-unread-mark))
3154
3155(defmacro gnus-data-pseudo-p (data)
3156 `(consp (nth 3 ,data)))
3157
3158(defmacro gnus-data-find (number)
3159 `(assq ,number gnus-newsgroup-data))
3160
3161(defmacro gnus-data-find-list (number &optional data)
3162 `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3163 (memq (assq ,number bdata)
3164 bdata)))
3165
3166(defmacro gnus-data-make (number mark pos header level)
3167 `(list ,number ,mark ,pos ,header ,level))
3168
3169(defun gnus-data-enter (after-article number mark pos header level offset)
3170 (let ((data (gnus-data-find-list after-article)))
3171 (unless data
3172 (error "No such article: %d" after-article))
3173 (setcdr data (cons (gnus-data-make number mark pos header level)
3174 (cdr data)))
3175 (setq gnus-newsgroup-data-reverse nil)
3176 (gnus-data-update-list (cddr data) offset)))
3177
3178(defun gnus-data-enter-list (after-article list &optional offset)
3179 (when list
3180 (let ((data (and after-article (gnus-data-find-list after-article)))
3181 (ilist list))
6748645f
LMI
3182 (if (not (or data
3183 after-article))
3184 (let ((odata gnus-newsgroup-data))
3185 (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
eec82323 3186 (when offset
6748645f 3187 (gnus-data-update-list odata offset)))
01c52d31 3188 ;; Find the last element in the list to be spliced into the main
6748645f 3189 ;; list.
01c52d31 3190 (setq list (last list))
6748645f
LMI
3191 (if (not data)
3192 (progn
3193 (setcdr list gnus-newsgroup-data)
3194 (setq gnus-newsgroup-data ilist)
3195 (when offset
3196 (gnus-data-update-list (cdr list) offset)))
3197 (setcdr list (cdr data))
3198 (setcdr data ilist)
3199 (when offset
3200 (gnus-data-update-list (cdr list) offset))))
eec82323
LMI
3201 (setq gnus-newsgroup-data-reverse nil))))
3202
3203(defun gnus-data-remove (article &optional offset)
3204 (let ((data gnus-newsgroup-data))
3205 (if (= (gnus-data-number (car data)) article)
3206 (progn
3207 (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3208 gnus-newsgroup-data-reverse nil)
3209 (when offset
3210 (gnus-data-update-list gnus-newsgroup-data offset)))
3211 (while (cdr data)
3212 (when (= (gnus-data-number (cadr data)) article)
3213 (setcdr data (cddr data))
3214 (when offset
3215 (gnus-data-update-list (cdr data) offset))
3216 (setq data nil
3217 gnus-newsgroup-data-reverse nil))
3218 (setq data (cdr data))))))
3219
3220(defmacro gnus-data-list (backward)
3221 `(if ,backward
3222 (or gnus-newsgroup-data-reverse
3223 (setq gnus-newsgroup-data-reverse
3224 (reverse gnus-newsgroup-data)))
3225 gnus-newsgroup-data))
3226
3227(defun gnus-data-update-list (data offset)
3228 "Add OFFSET to the POS of all data entries in DATA."
6748645f 3229 (setq gnus-newsgroup-data-reverse nil)
eec82323
LMI
3230 (while data
3231 (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3232 (setq data (cdr data))))
3233
eec82323
LMI
3234(defun gnus-summary-article-pseudo-p (article)
3235 "Say whether this article is a pseudo article or not."
3236 (not (vectorp (gnus-data-header (gnus-data-find article)))))
3237
3238(defmacro gnus-summary-article-sparse-p (article)
3239 "Say whether this article is a sparse article or not."
a8151ef7 3240 `(memq ,article gnus-newsgroup-sparse))
eec82323
LMI
3241
3242(defmacro gnus-summary-article-ancient-p (article)
3243 "Say whether this article is a sparse article or not."
3244 `(memq ,article gnus-newsgroup-ancient))
3245
3246(defun gnus-article-parent-p (number)
3247 "Say whether this article is a parent or not."
3248 (let ((data (gnus-data-find-list number)))
23f87bed 3249 (and (cdr data) ; There has to be an article after...
eec82323
LMI
3250 (< (gnus-data-level (car data)) ; And it has to have a higher level.
3251 (gnus-data-level (nth 1 data))))))
3252
3253(defun gnus-article-children (number)
3254 "Return a list of all children to NUMBER."
3255 (let* ((data (gnus-data-find-list number))
3256 (level (gnus-data-level (car data)))
3257 children)
3258 (setq data (cdr data))
3259 (while (and data
3260 (= (gnus-data-level (car data)) (1+ level)))
3261 (push (gnus-data-number (car data)) children)
3262 (setq data (cdr data)))
3263 children))
3264
3265(defmacro gnus-summary-skip-intangible ()
3266 "If the current article is intangible, then jump to a different article."
3267 '(let ((to (get-text-property (point) 'gnus-intangible)))
3268 (and to (gnus-summary-goto-subject to))))
3269
3270(defmacro gnus-summary-article-intangible-p ()
3271 "Say whether this article is intangible or not."
3272 '(get-text-property (point) 'gnus-intangible))
3273
3274(defun gnus-article-read-p (article)
3275 "Say whether ARTICLE is read or not."
3276 (not (or (memq article gnus-newsgroup-marked)
23f87bed 3277 (memq article gnus-newsgroup-spam-marked)
eec82323
LMI
3278 (memq article gnus-newsgroup-unreads)
3279 (memq article gnus-newsgroup-unselected)
3280 (memq article gnus-newsgroup-dormant))))
3281
3282;; Some summary mode macros.
3283
3284(defmacro gnus-summary-article-number ()
3285 "The article number of the article on the current line.
8f688cb0 3286If there isn't an article number here, then we return the current
eec82323
LMI
3287article number."
3288 '(progn
3289 (gnus-summary-skip-intangible)
3290 (or (get-text-property (point) 'gnus-number)
3291 (gnus-summary-last-subject))))
3292
3293(defmacro gnus-summary-article-header (&optional number)
6748645f 3294 "Return the header of article NUMBER."
eec82323
LMI
3295 `(gnus-data-header (gnus-data-find
3296 ,(or number '(gnus-summary-article-number)))))
3297
3298(defmacro gnus-summary-thread-level (&optional number)
6748645f 3299 "Return the level of thread that starts with article NUMBER."
eec82323
LMI
3300 `(if (and (eq gnus-summary-make-false-root 'dummy)
3301 (get-text-property (point) 'gnus-intangible))
3302 0
3303 (gnus-data-level (gnus-data-find
3304 ,(or number '(gnus-summary-article-number))))))
3305
3306(defmacro gnus-summary-article-mark (&optional number)
6748645f 3307 "Return the mark of article NUMBER."
eec82323
LMI
3308 `(gnus-data-mark (gnus-data-find
3309 ,(or number '(gnus-summary-article-number)))))
3310
3311(defmacro gnus-summary-article-pos (&optional number)
6748645f 3312 "Return the position of the line of article NUMBER."
eec82323
LMI
3313 `(gnus-data-pos (gnus-data-find
3314 ,(or number '(gnus-summary-article-number)))))
3315
3316(defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3317(defmacro gnus-summary-article-subject (&optional number)
3318 "Return current subject string or nil if nothing."
3319 `(let ((headers
3320 ,(if number
3321 `(gnus-data-header (assq ,number gnus-newsgroup-data))
3322 '(gnus-data-header (assq (gnus-summary-article-number)
3323 gnus-newsgroup-data)))))
3324 (and headers
3325 (vectorp headers)
3326 (mail-header-subject headers))))
3327
3328(defmacro gnus-summary-article-score (&optional number)
3329 "Return current article score."
3330 `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3331 gnus-newsgroup-scored))
3332 gnus-summary-default-score 0))
3333
3334(defun gnus-summary-article-children (&optional number)
6748645f 3335 "Return a list of article numbers that are children of article NUMBER."
eec82323
LMI
3336 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3337 (level (gnus-data-level (car data)))
3338 l children)
3339 (while (and (setq data (cdr data))
3340 (> (setq l (gnus-data-level (car data))) level))
3341 (and (= (1+ level) l)
3342 (push (gnus-data-number (car data))
3343 children)))
3344 (nreverse children)))
3345
3346(defun gnus-summary-article-parent (&optional number)
6748645f 3347 "Return the article number of the parent of article NUMBER."
eec82323
LMI
3348 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3349 (gnus-data-list t)))
3350 (level (gnus-data-level (car data))))
3351 (if (zerop level)
3352 () ; This is a root.
3353 ;; We search until we find an article with a level less than
3354 ;; this one. That function has to be the parent.
3355 (while (and (setq data (cdr data))
3356 (not (< (gnus-data-level (car data)) level))))
3357 (and data (gnus-data-number (car data))))))
3358
3359(defun gnus-unread-mark-p (mark)
3360 "Say whether MARK is the unread mark."
3361 (= mark gnus-unread-mark))
3362
3363(defun gnus-read-mark-p (mark)
3364 "Say whether MARK is one of the marks that mark as read.
3365This is all marks except unread, ticked, dormant, and expirable."
3366 (not (or (= mark gnus-unread-mark)
3367 (= mark gnus-ticked-mark)
23f87bed 3368 (= mark gnus-spam-mark)
eec82323
LMI
3369 (= mark gnus-dormant-mark)
3370 (= mark gnus-expirable-mark))))
3371
3372(defmacro gnus-article-mark (number)
6748645f
LMI
3373 "Return the MARK of article NUMBER.
3374This macro should only be used when computing the mark the \"first\"
3375time; i.e., when generating the summary lines. After that,
3376`gnus-summary-article-mark' should be used to examine the
3377marks of articles."
eec82323 3378 `(cond
6748645f 3379 ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
6748645f 3380 ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
eec82323
LMI
3381 ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3382 ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
23f87bed 3383 ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
eec82323
LMI
3384 ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3385 ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3386 (t (or (cdr (assq ,number gnus-newsgroup-reads))
3387 gnus-ancient-mark))))
3388
3389;; Saving hidden threads.
3390
eec82323
LMI
3391(defmacro gnus-save-hidden-threads (&rest forms)
3392 "Save hidden threads, eval FORMS, and restore the hidden threads."
3393 (let ((config (make-symbol "config")))
3394 `(let ((,config (gnus-hidden-threads-configuration)))
3395 (unwind-protect
3396 (save-excursion
3397 ,@forms)
3398 (gnus-restore-hidden-threads-configuration ,config)))))
23f87bed
MB
3399(put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3400(put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
eec82323 3401
107ecebb
AS
3402(defun gnus-data-compute-positions ()
3403 "Compute the positions of all articles."
3404 (setq gnus-newsgroup-data-reverse nil)
3405 (let ((data gnus-newsgroup-data))
3406 (save-excursion
3407 (gnus-save-hidden-threads
3408 (gnus-summary-show-all-threads)
3409 (goto-char (point-min))
3410 (while data
3411 (while (get-text-property (point) 'gnus-intangible)
3412 (forward-line 1))
3413 (gnus-data-set-pos (car data) (+ (point) 3))
3414 (setq data (cdr data))
3415 (forward-line 1))))))
3416
16409b0b
GM
3417(defun gnus-hidden-threads-configuration ()
3418 "Return the current hidden threads configuration."
3419 (save-excursion
3420 (let (config)
3421 (goto-char (point-min))
62a83cc8
KY
3422 (while (not (eobp))
3423 (when (eq (get-char-property (point-at-eol) 'invisible) 'gnus-sum)
3424 (push (save-excursion (forward-line 0) (point)) config))
3425 (forward-line 1))
16409b0b
GM
3426 config)))
3427
3428(defun gnus-restore-hidden-threads-configuration (config)
3429 "Restore hidden threads configuration from CONFIG."
3430 (save-excursion
c7a91ce1 3431 (let (point (inhibit-read-only t))
16409b0b 3432 (while (setq point (pop config))
62a83cc8
KY
3433 (goto-char point)
3434 (gnus-summary-hide-thread)))))
16409b0b 3435
eec82323
LMI
3436;; Various summary mode internalish functions.
3437
3438(defun gnus-mouse-pick-article (e)
3439 (interactive "e")
3440 (mouse-set-point e)
3441 (gnus-summary-next-page nil t))
3442
3443(defun gnus-summary-set-display-table ()
16409b0b
GM
3444 "Change the display table.
3445Odd characters have a tendency to mess
3446up nicely formatted displays - we make all possible glyphs
3447display only a single character."
eec82323
LMI
3448
3449 ;; We start from the standard display table, if any.
3450 (let ((table (or (copy-sequence standard-display-table)
3451 (make-display-table)))
3452 (i 32))
3453 ;; Nix out all the control chars...
3454 (while (>= (setq i (1- i)) 0)
2b968687 3455 (gnus-put-display-table i [??] table))
23f87bed 3456 ;; ... but not newline and cr, of course. (cr is necessary for the
eec82323 3457 ;; selective display).
2b968687
MB
3458 (gnus-put-display-table ?\n nil table)
3459 (gnus-put-display-table ?\r nil table)
6748645f 3460 ;; We keep TAB as well.
2b968687 3461 (gnus-put-display-table ?\t nil table)
719120ef 3462 ;; We nix out any glyphs 127 through 255, or 127 through 159 in
fe62aacc 3463 ;; Emacs 23 (unicode), that are not set already.
719120ef
MB
3464 (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3465 160
3466 256)))
eec82323
LMI
3467 (while (>= (setq i (1- i)) 127)
3468 ;; Only modify if the entry is nil.
2b968687
MB
3469 (unless (gnus-get-display-table i table)
3470 (gnus-put-display-table i [??] table))))
eec82323
LMI
3471 (setq buffer-display-table table)))
3472
23f87bed
MB
3473(defun gnus-summary-set-article-display-arrow (pos)
3474 "Update the overlay arrow to point to line at position POS."
e3e955fe
MB
3475 (when gnus-summary-display-arrow
3476 (make-local-variable 'overlay-arrow-position)
3477 (make-local-variable 'overlay-arrow-string)
23f87bed
MB
3478 (save-excursion
3479 (goto-char pos)
3480 (beginning-of-line)
3481 (unless overlay-arrow-position
3482 (setq overlay-arrow-position (make-marker)))
3483 (setq overlay-arrow-string "=>"
3484 overlay-arrow-position (set-marker overlay-arrow-position
3485 (point)
3486 (current-buffer))))))
3487
eec82323
LMI
3488(defun gnus-summary-setup-buffer (group)
3489 "Initialize summary buffer."
23f87bed
MB
3490 (let ((buffer (gnus-summary-buffer-name group))
3491 (dead-name (concat "*Dead Summary "
3492 (gnus-group-decoded-name group) "*")))
3493 ;; If a dead summary buffer exists, we kill it.
3494 (when (gnus-buffer-live-p dead-name)
3495 (gnus-kill-buffer dead-name))
eec82323
LMI
3496 (if (get-buffer buffer)
3497 (progn
3498 (set-buffer buffer)
3499 (setq gnus-summary-buffer (current-buffer))
3500 (not gnus-newsgroup-prepared))
3501 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
6748645f 3502 (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
eec82323
LMI
3503 (gnus-summary-mode group)
3504 (when gnus-carpal
3505 (gnus-carpal-setup-buffer 'summary))
01c52d31
MB
3506 (when (gnus-group-quit-config group)
3507 (set (make-local-variable 'gnus-single-article-buffer) nil))
3508 (make-local-variable 'gnus-article-buffer)
3509 (make-local-variable 'gnus-article-current)
3510 (make-local-variable 'gnus-original-article-buffer)
eec82323 3511 (setq gnus-newsgroup-name group)
23f87bed
MB
3512 ;; Set any local variables in the group parameters.
3513 (gnus-summary-set-local-parameters gnus-newsgroup-name)
eec82323
LMI
3514 t)))
3515
3516(defun gnus-set-global-variables ()
16409b0b
GM
3517 "Set the global equivalents of the buffer-local variables.
3518They are set to the latest values they had. These reflect the summary
3519buffer that was in action when the last article was fetched."
eec82323
LMI
3520 (when (eq major-mode 'gnus-summary-mode)
3521 (setq gnus-summary-buffer (current-buffer))
3522 (let ((name gnus-newsgroup-name)
3523 (marked gnus-newsgroup-marked)
23f87bed 3524 (spam gnus-newsgroup-spam-marked)
eec82323
LMI
3525 (unread gnus-newsgroup-unreads)
3526 (headers gnus-current-headers)
3527 (data gnus-newsgroup-data)
3528 (summary gnus-summary-buffer)
3529 (article-buffer gnus-article-buffer)
3530 (original gnus-original-article-buffer)
3531 (gac gnus-article-current)
3532 (reffed gnus-reffed-article-number)
16409b0b 3533 (score-file gnus-current-score-file)
23f87bed
MB
3534 (default-charset gnus-newsgroup-charset)
3535 vlist)
3536 (let ((locals gnus-newsgroup-variables))
3537 (while locals
3538 (if (consp (car locals))
3539 (push (eval (caar locals)) vlist)
3540 (push (eval (car locals)) vlist))
3541 (setq locals (cdr locals)))
3542 (setq vlist (nreverse vlist)))
01c52d31 3543 (with-current-buffer gnus-group-buffer
6748645f
LMI
3544 (setq gnus-newsgroup-name name
3545 gnus-newsgroup-marked marked
23f87bed 3546 gnus-newsgroup-spam-marked spam
6748645f
LMI
3547 gnus-newsgroup-unreads unread
3548 gnus-current-headers headers
3549 gnus-newsgroup-data data
3550 gnus-article-current gac
3551 gnus-summary-buffer summary
3552 gnus-article-buffer article-buffer
3553 gnus-original-article-buffer original
3554 gnus-reffed-article-number reffed
16409b0b
GM
3555 gnus-current-score-file score-file
3556 gnus-newsgroup-charset default-charset)
23f87bed
MB
3557 (let ((locals gnus-newsgroup-variables))
3558 (while locals
3559 (if (consp (car locals))
3560 (set (caar locals) (pop vlist))
3561 (set (car locals) (pop vlist)))
3562 (setq locals (cdr locals))))
eec82323
LMI
3563 ;; The article buffer also has local variables.
3564 (when (gnus-buffer-live-p gnus-article-buffer)
3565 (set-buffer gnus-article-buffer)
3566 (setq gnus-summary-buffer summary))))))
3567
3568(defun gnus-summary-article-unread-p (article)
3569 "Say whether ARTICLE is unread or not."
3570 (memq article gnus-newsgroup-unreads))
3571
3572(defun gnus-summary-first-article-p (&optional article)
3573 "Return whether ARTICLE is the first article in the buffer."
3574 (if (not (setq article (or article (gnus-summary-article-number))))
3575 nil
3576 (eq article (caar gnus-newsgroup-data))))
3577
3578(defun gnus-summary-last-article-p (&optional article)
3579 "Return whether ARTICLE is the last article in the buffer."
3580 (if (not (setq article (or article (gnus-summary-article-number))))
16409b0b
GM
3581 ;; All non-existent numbers are the last article. :-)
3582 t
eec82323
LMI
3583 (not (cdr (gnus-data-find-list article)))))
3584
4921bbdd
CY
3585(defun gnus-make-thread-indent-array (&optional n)
3586 (when (or n
3587 (progn (setq n 200) nil)
3588 (null gnus-thread-indent-array)
3589 (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3590 (setq gnus-thread-indent-array (make-vector (1+ n) "")
3591 gnus-thread-indent-array-level gnus-thread-indent-level)
3592 (while (>= n 0)
3593 (aset gnus-thread-indent-array n
6a30c01d 3594 (make-string (* n gnus-thread-indent-level) ? ))
4921bbdd 3595 (setq n (1- n)))))
eec82323
LMI
3596
3597(defun gnus-update-summary-mark-positions ()
3598 "Compute where the summary marks are to go."
3599 (save-excursion
6748645f 3600 (when (gnus-buffer-exists-p gnus-summary-buffer)
eec82323 3601 (set-buffer gnus-summary-buffer))
5153a47a
MB
3602 (let ((spec gnus-summary-line-format-spec)
3603 pos)
eec82323
LMI
3604 (save-excursion
3605 (gnus-set-work-buffer)
5153a47a
MB
3606 (let ((gnus-tmp-unread ?Z)
3607 (gnus-replied-mark ?Z)
3608 (gnus-score-below-mark ?Z)
3609 (gnus-score-over-mark ?Z)
3610 (gnus-undownloaded-mark ?Z)
3611 (gnus-summary-line-format-spec spec)
54506618 3612 (gnus-newsgroup-downloadable '(0))
5153a47a
MB
3613 (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3614 case-fold-search ignores)
3615 ;; Here, all marks are bound to Z.
3616 (gnus-summary-insert-line header
3617 0 nil t gnus-tmp-unread t nil "" nil 1)
3618 (goto-char (point-min))
3619 ;; Memorize the positions of the same characters as dummy marks.
3620 (while (re-search-forward "[A-D]" nil t)
3621 (push (point) ignores))
54506618 3622 (erase-buffer)
5153a47a
MB
3623 ;; We use A-D as dummy marks in order to know column positions
3624 ;; where marks should be inserted.
3625 (setq gnus-tmp-unread ?A
3626 gnus-replied-mark ?B
3627 gnus-score-below-mark ?C
3628 gnus-score-over-mark ?C
3629 gnus-undownloaded-mark ?D)
3630 (gnus-summary-insert-line header
3631 0 nil t gnus-tmp-unread t nil "" nil 1)
3632 ;; Ignore characters which aren't dummy marks.
3633 (dolist (p ignores)
3634 (delete-region (goto-char (1- p)) p)
3635 (insert ?Z))
eec82323 3636 (goto-char (point-min))
7c3bb5a5 3637 (setq pos (list (cons 'unread
5153a47a 3638 (and (search-forward "A" nil t)
7c3bb5a5 3639 (- (point) (point-min) 1)))))
eec82323 3640 (goto-char (point-min))
5153a47a 3641 (push (cons 'replied (and (search-forward "B" nil t)
667e0ba6 3642 (- (point) (point-min) 1)))
eec82323
LMI
3643 pos)
3644 (goto-char (point-min))
5153a47a 3645 (push (cons 'score (and (search-forward "C" nil t)
667e0ba6 3646 (- (point) (point-min) 1)))
6748645f
LMI
3647 pos)
3648 (goto-char (point-min))
5153a47a 3649 (push (cons 'download (and (search-forward "D" nil t)
7c3bb5a5 3650 (- (point) (point-min) 1)))
eec82323
LMI
3651 pos)))
3652 (setq gnus-summary-mark-positions pos))))
3653
3654(defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3655 "Insert a dummy root in the summary buffer."
3656 (beginning-of-line)
3657 (gnus-add-text-properties
3658 (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3659 (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3660
23f87bed
MB
3661(defun gnus-summary-extract-address-component (from)
3662 (or (car (funcall gnus-extract-address-components from))
3663 from))
3664
3665(defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3666 (let ((mail-parse-charset gnus-newsgroup-charset)
01c52d31 3667 (ignored-from-addresses (gnus-ignored-from-addresses))
23f87bed
MB
3668 ; Is it really necessary to do this next part for each summary line?
3669 ; Luckily, doesn't seem to slow things down much.
16409b0b 3670 (mail-parse-ignored-charsets
01c52d31
MB
3671 (with-current-buffer gnus-summary-buffer
3672 gnus-newsgroup-ignored-charsets)))
23f87bed 3673 (or
01c52d31
MB
3674 (and ignored-from-addresses
3675 (string-match ignored-from-addresses gnus-tmp-from)
23f87bed
MB
3676 (let ((extra-headers (mail-header-extra header))
3677 to
3678 newsgroups)
3679 (cond
3680 ((setq to (cdr (assq 'To extra-headers)))
01c52d31 3681 (concat gnus-summary-to-prefix
23f87bed
MB
3682 (inline
3683 (gnus-summary-extract-address-component
343d6628 3684 (funcall gnus-decode-encoded-address-function to)))))
01c52d31
MB
3685 ((setq newsgroups
3686 (or
3687 (cdr (assq 'Newsgroups extra-headers))
3688 (and
3689 (memq 'Newsgroups gnus-extra-headers)
3690 (eq (car (gnus-find-method-for-group
3691 gnus-newsgroup-name)) 'nntp)
3692 (gnus-group-real-name gnus-newsgroup-name))))
3693 (concat gnus-summary-newsgroup-prefix newsgroups)))))
23f87bed 3694 (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
16409b0b 3695
eec82323
LMI
3696(defun gnus-summary-insert-line (gnus-tmp-header
3697 gnus-tmp-level gnus-tmp-current
23f87bed 3698 undownloaded gnus-tmp-unread gnus-tmp-replied
eec82323
LMI
3699 gnus-tmp-expirable gnus-tmp-subject-or-nil
3700 &optional gnus-tmp-dummy gnus-tmp-score
3701 gnus-tmp-process)
4921bbdd
CY
3702 (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3703 (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3704 gnus-tmp-level)))
eec82323
LMI
3705 (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3706 (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3707 (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3708 (gnus-tmp-score-char
3709 (if (or (null gnus-summary-default-score)
3710 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3711 gnus-summary-zcore-fuzz))
23f87bed 3712 ? ;Whitespace
eec82323
LMI
3713 (if (< gnus-tmp-score gnus-summary-default-score)
3714 gnus-score-below-mark gnus-score-over-mark)))
23f87bed 3715 (gnus-tmp-number (mail-header-number gnus-tmp-header))
eec82323
LMI
3716 (gnus-tmp-replied
3717 (cond (gnus-tmp-process gnus-process-mark)
3718 ((memq gnus-tmp-current gnus-newsgroup-cached)
3719 gnus-cached-mark)
3720 (gnus-tmp-replied gnus-replied-mark)
23f87bed
MB
3721 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3722 gnus-forwarded-mark)
eec82323
LMI
3723 ((memq gnus-tmp-current gnus-newsgroup-saved)
3724 gnus-saved-mark)
23f87bed
MB
3725 ((memq gnus-tmp-number gnus-newsgroup-recent)
3726 gnus-recent-mark)
3727 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3728 gnus-unseen-mark)
3729 (t gnus-no-mark)))
3730 (gnus-tmp-downloaded
3731 (cond (undownloaded
3732 gnus-undownloaded-mark)
3733 (gnus-newsgroup-agentized
3734 gnus-downloaded-mark)
3735 (t
3736 gnus-no-mark)))
eec82323
LMI
3737 (gnus-tmp-from (mail-header-from gnus-tmp-header))
3738 (gnus-tmp-name
3739 (cond
3740 ((string-match "<[^>]+> *$" gnus-tmp-from)
3741 (let ((beg (match-beginning 0)))
23f87bed
MB
3742 (or (and (string-match "^\".+\"" gnus-tmp-from)
3743 (substring gnus-tmp-from 1 (1- (match-end 0))))
eec82323
LMI
3744 (substring gnus-tmp-from 0 beg))))
3745 ((string-match "(.+)" gnus-tmp-from)
3746 (substring gnus-tmp-from
3747 (1+ (match-beginning 0)) (1- (match-end 0))))
3748 (t gnus-tmp-from)))
3749 (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
eec82323
LMI
3750 (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3751 (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
c7a91ce1 3752 (inhibit-read-only t))
eec82323
LMI
3753 (when (string= gnus-tmp-name "")
3754 (setq gnus-tmp-name gnus-tmp-from))
3755 (unless (numberp gnus-tmp-lines)
23f87bed
MB
3756 (setq gnus-tmp-lines -1))
3757 (if (= gnus-tmp-lines -1)
3758 (setq gnus-tmp-lines "?")
3759 (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
64763fe3
MB
3760 (condition-case ()
3761 (gnus-put-text-property
3762 (point)
3763 (progn (eval gnus-summary-line-format-spec) (point))
3764 'gnus-number gnus-tmp-number)
3765 (error (gnus-message 5 "Error updating the summary line")))
eec82323
LMI
3766 (when (gnus-visual-p 'summary-highlight 'highlight)
3767 (forward-line -1)
a9ec34f4 3768 (gnus-summary-highlight-line)
6748645f 3769 (gnus-run-hooks 'gnus-summary-update-hook)
eec82323
LMI
3770 (forward-line 1))))
3771
3772(defun gnus-summary-update-line (&optional dont-update)
16409b0b 3773 "Update summary line after change."
eec82323
LMI
3774 (when (and gnus-summary-default-score
3775 (not gnus-summary-inhibit-highlight))
3776 (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3777 (article (gnus-summary-article-number))
3778 (score (gnus-summary-article-score article)))
3779 (unless dont-update
3780 (if (and gnus-summary-mark-below
3781 (< (gnus-summary-article-score)
3782 gnus-summary-mark-below))
3783 ;; This article has a low score, so we mark it as read.
3784 (when (memq article gnus-newsgroup-unreads)
3785 (gnus-summary-mark-article-as-read gnus-low-score-mark))
3786 (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3787 ;; This article was previously marked as read on account
3788 ;; of a low score, but now it has risen, so we mark it as
3789 ;; unread.
3790 (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3791 (gnus-summary-update-mark
3792 (if (or (null gnus-summary-default-score)
3793 (<= (abs (- score gnus-summary-default-score))
3794 gnus-summary-zcore-fuzz))
23f87bed 3795 ? ;Whitespace
eec82323
LMI
3796 (if (< score gnus-summary-default-score)
3797 gnus-score-below-mark gnus-score-over-mark))
3798 'score))
3799 ;; Do visual highlighting.
3800 (when (gnus-visual-p 'summary-highlight 'highlight)
a9ec34f4 3801 (gnus-summary-highlight-line)
6748645f 3802 (gnus-run-hooks 'gnus-summary-update-hook)))))
eec82323
LMI
3803
3804(defvar gnus-tmp-new-adopts nil)
3805
3806(defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3807 "Return the number of articles in THREAD.
3808This may be 0 in some cases -- if none of the articles in
3809the thread are to be displayed."
3810 (let* ((number
23f87bed 3811 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
eec82323
LMI
3812 (cond
3813 ((not (listp thread))
3814 1)
3815 ((and (consp thread) (cdr thread))
3816 (apply
3817 '+ 1 (mapcar
3818 'gnus-summary-number-of-articles-in-thread (cdr thread))))
3819 ((null thread)
3820 1)
3821 ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3822 1)
3823 (t 0))))
3824 (when (and level (zerop level) gnus-tmp-new-adopts)
3825 (incf number
3826 (apply '+ (mapcar
3827 'gnus-summary-number-of-articles-in-thread
3828 gnus-tmp-new-adopts))))
3829 (if char
3830 (if (> number 1) gnus-not-empty-thread-mark
3831 gnus-empty-thread-mark)
3832 number)))
3833
23f87bed
MB
3834(defsubst gnus-summary-line-message-size (head)
3835 "Return pretty-printed version of message size.
3836This function is intended to be used in
3837`gnus-summary-line-format-alist'."
3838 (let ((c (or (mail-header-chars head) -1)))
3839 (cond ((< c 0) "n/a") ; chars not available
3840 ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3841 ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3842 ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3843 (t (format "%dM" (/ c (* 1024.0 1024)))))))
3844
3845
eec82323
LMI
3846(defun gnus-summary-set-local-parameters (group)
3847 "Go through the local params of GROUP and set all variable specs in that list."
01c52d31
MB
3848 (let ((vars '(quit-config))) ; Ignore quit-config.
3849 (dolist (elem (gnus-group-find-parameter group))
eec82323
LMI
3850 (and (consp elem) ; Has to be a cons.
3851 (consp (cdr elem)) ; The cdr has to be a list.
3852 (symbolp (car elem)) ; Has to be a symbol in there.
23f87bed 3853 (not (memq (car elem) vars))
e3e955fe 3854 (ignore-errors
23f87bed 3855 (push (car elem) vars)
e3e955fe
MB
3856 ;; Variables like `gnus-show-threads' that are globally
3857 ;; bound, if used as group parameters, need to get to be
3858 ;; buffer-local, whereas just parameters like `gcc-self',
3859 ;; `timestamp', etc. should not be bound as variables.
3860 (if (boundp (car elem))
3861 (set (make-local-variable (car elem)) (eval (nth 1 elem)))
3862 (eval (nth 1 elem))))))))
eec82323
LMI
3863
3864(defun gnus-summary-read-group (group &optional show-all no-article
6748645f
LMI
3865 kill-buffer no-display backward
3866 select-articles)
eec82323
LMI
3867 "Start reading news in newsgroup GROUP.
3868If SHOW-ALL is non-nil, already read articles are also listed.
3869If NO-ARTICLE is non-nil, no article is selected initially.
3870If NO-DISPLAY, don't generate a summary buffer."
3871 (let (result)
3872 (while (and group
3873 (null (setq result
3874 (let ((gnus-auto-select-next nil))
6748645f
LMI
3875 (or (gnus-summary-read-group-1
3876 group show-all no-article
3877 kill-buffer no-display
3878 select-articles)
3879 (setq show-all nil
16409b0b 3880 select-articles nil)))))
eec82323
LMI
3881 (eq gnus-auto-select-next 'quietly))
3882 (set-buffer gnus-group-buffer)
6748645f
LMI
3883 ;; The entry function called above goes to the next
3884 ;; group automatically, so we go two groups back
3885 ;; if we are searching for the previous group.
3886 (when backward
3887 (gnus-group-prev-unread-group 2))
eec82323
LMI
3888 (if (not (equal group (gnus-group-group-name)))
3889 (setq group (gnus-group-group-name))
3890 (setq group nil)))
3891 result))
3892
3893(defun gnus-summary-read-group-1 (group show-all no-article
6748645f
LMI
3894 kill-buffer no-display
3895 &optional select-articles)
eec82323 3896 ;; Killed foreign groups can't be entered.
23f87bed
MB
3897 ;; (when (and (not (gnus-group-native-p group))
3898 ;; (not (gnus-gethash group gnus-newsrc-hashtb)))
3899 ;; (error "Dead non-native groups can't be entered"))
3900 (gnus-message 5 "Retrieving newsgroup: %s..."
3901 (gnus-group-decoded-name group))
eec82323
LMI
3902 (let* ((new-group (gnus-summary-setup-buffer group))
3903 (quit-config (gnus-group-quit-config group))
6748645f
LMI
3904 (did-select (and new-group (gnus-select-newsgroup
3905 group show-all select-articles))))
eec82323
LMI
3906 (cond
3907 ;; This summary buffer exists already, so we just select it.
3908 ((not new-group)
3909 (gnus-set-global-variables)
3910 (when kill-buffer
3911 (gnus-kill-or-deaden-summary kill-buffer))
3912 (gnus-configure-windows 'summary 'force)
3913 (gnus-set-mode-line 'summary)
3914 (gnus-summary-position-point)
3915 (message "")
3916 t)
3917 ;; We couldn't select this group.
3918 ((null did-select)
3919 (when (and (eq major-mode 'gnus-summary-mode)
3920 (not (equal (current-buffer) kill-buffer)))
3921 (kill-buffer (current-buffer))
3922 (if (not quit-config)
3923 (progn
6748645f
LMI
3924 ;; Update the info -- marks might need to be removed,
3925 ;; for instance.
3926 (gnus-summary-update-info)
eec82323
LMI
3927 (set-buffer gnus-group-buffer)
3928 (gnus-group-jump-to-group group)
3929 (gnus-group-next-unread-group 1))
3930 (gnus-handle-ephemeral-exit quit-config)))
23f87bed
MB
3931 (let ((grpinfo (gnus-get-info group)))
3932 (if (null (gnus-info-read grpinfo))
3933 (gnus-message 3 "Group %s contains no messages"
3934 (gnus-group-decoded-name group))
3935 (gnus-message 3 "Can't select group")))
eec82323
LMI
3936 nil)
3937 ;; The user did a `C-g' while prompting for number of articles,
3938 ;; so we exit this group.
3939 ((eq did-select 'quit)
3940 (and (eq major-mode 'gnus-summary-mode)
3941 (not (equal (current-buffer) kill-buffer))
3942 (kill-buffer (current-buffer)))
3943 (when kill-buffer
3944 (gnus-kill-or-deaden-summary kill-buffer))
3945 (if (not quit-config)
3946 (progn
3947 (set-buffer gnus-group-buffer)
3948 (gnus-group-jump-to-group group)
eec82323
LMI
3949 (gnus-configure-windows 'group 'force))
3950 (gnus-handle-ephemeral-exit quit-config))
3951 ;; Finally signal the quit.
3952 (signal 'quit nil))
3953 ;; The group was successfully selected.
3954 (t
3955 (gnus-set-global-variables)
3956 ;; Save the active value in effect when the group was entered.
3957 (setq gnus-newsgroup-active
3958 (gnus-copy-sequence
3959 (gnus-active gnus-newsgroup-name)))
3960 ;; You can change the summary buffer in some way with this hook.
6748645f 3961 (gnus-run-hooks 'gnus-select-group-hook)
5153a47a
MB
3962 (when (memq 'summary (gnus-update-format-specifications
3963 nil 'summary 'summary-mode 'summary-dummy))
3964 ;; The format specification for the summary line was updated,
3965 ;; so we need to update the mark positions as well.
3966 (gnus-update-summary-mark-positions))
eec82323
LMI
3967 ;; Do score processing.
3968 (when gnus-use-scoring
3969 (gnus-possibly-score-headers))
3970 ;; Check whether to fill in the gaps in the threads.
3971 (when gnus-build-sparse-threads
3972 (gnus-build-sparse-threads))
3973 ;; Find the initial limit.
26c9afc3
MB
3974 (if show-all
3975 (let ((gnus-newsgroup-dormant nil))
eec82323 3976 (gnus-summary-initial-limit show-all))
26c9afc3 3977 (gnus-summary-initial-limit show-all))
eec82323
LMI
3978 ;; Generate the summary buffer.
3979 (unless no-display
3980 (gnus-summary-prepare))
3981 (when gnus-use-trees
3982 (gnus-tree-open group)
3983 (setq gnus-summary-highlight-line-function
3984 'gnus-tree-highlight-article))
3985 ;; If the summary buffer is empty, but there are some low-scored
3986 ;; articles or some excluded dormants, we include these in the
3987 ;; buffer.
3988 (when (and (zerop (buffer-size))
3989 (not no-display))
3990 (cond (gnus-newsgroup-dormant
3991 (gnus-summary-limit-include-dormant))
3992 ((and gnus-newsgroup-scored show-all)
3993 (gnus-summary-limit-include-expunged t))))
3994 ;; Function `gnus-apply-kill-file' must be called in this hook.
6748645f 3995 (gnus-run-hooks 'gnus-apply-kill-hook)
eec82323
LMI
3996 (if (and (zerop (buffer-size))
3997 (not no-display))
3998 (progn
3999 ;; This newsgroup is empty.
4000 (gnus-summary-catchup-and-exit nil t)
4001 (gnus-message 6 "No unread news")
4002 (when kill-buffer
4003 (gnus-kill-or-deaden-summary kill-buffer))
4004 ;; Return nil from this function.
4005 nil)
4006 ;; Hide conversation thread subtrees. We cannot do this in
4007 ;; gnus-summary-prepare-hook since kill processing may not
4008 ;; work with hidden articles.
23f87bed 4009 (gnus-summary-maybe-hide-threads)
6748645f
LMI
4010 (when kill-buffer
4011 (gnus-kill-or-deaden-summary kill-buffer))
23f87bed 4012 (gnus-summary-auto-select-subject)
eec82323
LMI
4013 ;; Show first unread article if requested.
4014 (if (and (not no-article)
4015 (not no-display)
4016 gnus-newsgroup-unreads
4017 gnus-auto-select-first)
16409b0b
GM
4018 (progn
4019 (gnus-configure-windows 'summary)
23f87bed
MB
4020 (let ((art (gnus-summary-article-number)))
4021 (unless (and (not gnus-plugged)
4022 (or (memq art gnus-newsgroup-undownloaded)
4023 (memq art gnus-newsgroup-downloadable)))
4024 (gnus-summary-goto-article art))))
4025 ;; Don't select any articles.
eec82323 4026 (gnus-summary-position-point)
6748645f
LMI
4027 (gnus-configure-windows 'summary 'force)
4028 (gnus-set-mode-line 'summary))
23f87bed
MB
4029 (when (and gnus-auto-center-group
4030 (get-buffer-window gnus-group-buffer t))
eec82323
LMI
4031 ;; Gotta use windows, because recenter does weird stuff if
4032 ;; the current buffer ain't the displayed window.
4033 (let ((owin (selected-window)))
4034 (select-window (get-buffer-window gnus-group-buffer t))
4035 (when (gnus-group-goto-group group)
4036 (recenter))
4037 (select-window owin)))
4038 ;; Mark this buffer as "prepared".
4039 (setq gnus-newsgroup-prepared t)
6748645f 4040 (gnus-run-hooks 'gnus-summary-prepared-hook)
23f87bed
MB
4041 (unless (gnus-ephemeral-group-p group)
4042 (gnus-group-update-group group))
eec82323
LMI
4043 t)))))
4044
23f87bed
MB
4045(defun gnus-summary-auto-select-subject ()
4046 "Select the subject line on initial group entry."
4047 (goto-char (point-min))
4048 (cond
4049 ((eq gnus-auto-select-subject 'best)
4050 (gnus-summary-best-unread-subject))
4051 ((eq gnus-auto-select-subject 'unread)
4052 (gnus-summary-first-unread-subject))
4053 ((eq gnus-auto-select-subject 'unseen)
4054 (gnus-summary-first-unseen-subject))
4055 ((eq gnus-auto-select-subject 'unseen-or-unread)
4056 (gnus-summary-first-unseen-or-unread-subject))
4057 ((eq gnus-auto-select-subject 'first)
4058 ;; Do nothing.
4059 )
4060 ((functionp gnus-auto-select-subject)
4061 (funcall gnus-auto-select-subject))))
4062
eec82323
LMI
4063(defun gnus-summary-prepare ()
4064 "Generate the summary buffer."
4065 (interactive)
c7a91ce1 4066 (let ((inhibit-read-only t))
eec82323
LMI
4067 (erase-buffer)
4068 (setq gnus-newsgroup-data nil
4069 gnus-newsgroup-data-reverse nil)
6748645f 4070 (gnus-run-hooks 'gnus-summary-generate-hook)
eec82323
LMI
4071 ;; Generate the buffer, either with threads or without.
4072 (when gnus-newsgroup-headers
4073 (gnus-summary-prepare-threads
4074 (if gnus-show-threads
4075 (gnus-sort-gathered-threads
4076 (funcall gnus-summary-thread-gathering-function
4077 (gnus-sort-threads
4078 (gnus-cut-threads (gnus-make-threads)))))
4079 ;; Unthreaded display.
4080 (gnus-sort-articles gnus-newsgroup-headers))))
4081 (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
4082 ;; Call hooks for modifying summary buffer.
4083 (goto-char (point-min))
6748645f 4084 (gnus-run-hooks 'gnus-summary-prepare-hook)))
eec82323
LMI
4085
4086(defsubst gnus-general-simplify-subject (subject)
23f87bed 4087 "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
eec82323
LMI
4088 (setq subject
4089 (cond
4090 ;; Truncate the subject.
6748645f
LMI
4091 (gnus-simplify-subject-functions
4092 (gnus-map-function gnus-simplify-subject-functions subject))
eec82323
LMI
4093 ((numberp gnus-summary-gather-subject-limit)
4094 (setq subject (gnus-simplify-subject-re subject))
4095 (if (> (length subject) gnus-summary-gather-subject-limit)
4096 (substring subject 0 gnus-summary-gather-subject-limit)
4097 subject))
4098 ;; Fuzzily simplify it.
4099 ((eq 'fuzzy gnus-summary-gather-subject-limit)
4100 (gnus-simplify-subject-fuzzy subject))
4101 ;; Just remove the leading "Re:".
4102 (t
4103 (gnus-simplify-subject-re subject))))
4104
4105 (if (and gnus-summary-gather-exclude-subject
4106 (string-match gnus-summary-gather-exclude-subject subject))
23f87bed 4107 nil ; This article shouldn't be gathered
eec82323
LMI
4108 subject))
4109
4110(defun gnus-summary-simplify-subject-query ()
4111 "Query where the respool algorithm would put this article."
4112 (interactive)
eec82323 4113 (gnus-summary-select-article)
274f1353 4114 (message "%s" (gnus-general-simplify-subject (gnus-summary-article-subject))))
eec82323
LMI
4115
4116(defun gnus-gather-threads-by-subject (threads)
4117 "Gather threads by looking at Subject headers."
4118 (if (not gnus-summary-make-false-root)
4119 threads
4120 (let ((hashtb (gnus-make-hashtable 1024))
4121 (prev threads)
4122 (result threads)
4123 subject hthread whole-subject)
4124 (while threads
4125 (setq subject (gnus-general-simplify-subject
4126 (setq whole-subject (mail-header-subject
4127 (caar threads)))))
4128 (when subject
4129 (if (setq hthread (gnus-gethash subject hashtb))
4130 (progn
4131 ;; We enter a dummy root into the thread, if we
4132 ;; haven't done that already.
4133 (unless (stringp (caar hthread))
4134 (setcar hthread (list whole-subject (car hthread))))
4135 ;; We add this new gathered thread to this gathered
4136 ;; thread.
4137 (setcdr (car hthread)
4138 (nconc (cdar hthread) (list (car threads))))
4139 ;; Remove it from the list of threads.
4140 (setcdr prev (cdr threads))
4141 (setq threads prev))
4142 ;; Enter this thread into the hash table.
23f87bed
MB
4143 (gnus-sethash subject
4144 (if gnus-summary-make-false-root-always
4145 (progn
4146 ;; If you want a dummy root above all
4147 ;; threads...
4148 (setcar threads (list whole-subject
4149 (car threads)))
4150 threads)
4151 threads)
4152 hashtb)))
eec82323
LMI
4153 (setq prev threads)
4154 (setq threads (cdr threads)))
4155 result)))
4156
4157(defun gnus-gather-threads-by-references (threads)
4158 "Gather threads by looking at References headers."
4159 (let ((idhashtb (gnus-make-hashtable 1024))
4160 (thhashtb (gnus-make-hashtable 1024))
4161 (prev threads)
4162 (result threads)
4163 ids references id gthread gid entered ref)
4164 (while threads
4165 (when (setq references (mail-header-references (caar threads)))
4166 (setq id (mail-header-id (caar threads))
23f87bed 4167 ids (inline (gnus-split-references references))
eec82323
LMI
4168 entered nil)
4169 (while (setq ref (pop ids))
4170 (setq ids (delete ref ids))
4171 (if (not (setq gid (gnus-gethash ref idhashtb)))
4172 (progn
4173 (gnus-sethash ref id idhashtb)
4174 (gnus-sethash id threads thhashtb))
4175 (setq gthread (gnus-gethash gid thhashtb))
4176 (unless entered
4177 ;; We enter a dummy root into the thread, if we
4178 ;; haven't done that already.
4179 (unless (stringp (caar gthread))
4180 (setcar gthread (list (mail-header-subject (caar gthread))
4181 (car gthread))))
4182 ;; We add this new gathered thread to this gathered
4183 ;; thread.
4184 (setcdr (car gthread)
4185 (nconc (cdar gthread) (list (car threads)))))
4186 ;; Add it into the thread hash table.
4187 (gnus-sethash id gthread thhashtb)
4188 (setq entered t)
4189 ;; Remove it from the list of threads.
4190 (setcdr prev (cdr threads))
4191 (setq threads prev))))
4192 (setq prev threads)
4193 (setq threads (cdr threads)))
4194 result))
4195
4196(defun gnus-sort-gathered-threads (threads)
16409b0b 4197 "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
eec82323
LMI
4198 (let ((result threads))
4199 (while threads
4200 (when (stringp (caar threads))
4201 (setcdr (car threads)
16409b0b 4202 (sort (cdar threads) gnus-sort-gathered-threads-function)))
eec82323
LMI
4203 (setq threads (cdr threads)))
4204 result))
4205
4206(defun gnus-thread-loop-p (root thread)
4207 "Say whether ROOT is in THREAD."
4208 (let ((stack (list thread))
4209 (infloop 0)
4210 th)
4211 (while (setq thread (pop stack))
4212 (setq th (cdr thread))
4213 (while (and th
4214 (not (eq (caar th) root)))
4215 (pop th))
4216 (if th
4217 ;; We have found a loop.
4218 (let (ref-dep)
4219 (setcdr thread (delq (car th) (cdr thread)))
4220 (if (boundp (setq ref-dep (intern "none"
4221 gnus-newsgroup-dependencies)))
4222 (setcdr (symbol-value ref-dep)
4223 (nconc (cdr (symbol-value ref-dep))
4224 (list (car th))))
4225 (set ref-dep (list nil (car th))))
4226 (setq infloop 1
4227 stack nil))
4228 ;; Push all the subthreads onto the stack.
4229 (push (cdr thread) stack)))
4230 infloop))
4231
4232(defun gnus-make-threads ()
01ccbb85 4233 "Go through the dependency hashtb and find the roots. Return all threads."
eec82323
LMI
4234 (let (threads)
4235 (while (catch 'infloop
4236 (mapatoms
4237 (lambda (refs)
4238 ;; Deal with self-referencing References loops.
4239 (when (and (car (symbol-value refs))
4240 (not (zerop
4241 (apply
4242 '+
4243 (mapcar
4244 (lambda (thread)
4245 (gnus-thread-loop-p
4246 (car (symbol-value refs)) thread))
4247 (cdr (symbol-value refs)))))))
4248 (setq threads nil)
4249 (throw 'infloop t))
4250 (unless (car (symbol-value refs))
23f87bed
MB
4251 ;; These threads do not refer back to any other
4252 ;; articles, so they're roots.
eec82323
LMI
4253 (setq threads (append (cdr (symbol-value refs)) threads))))
4254 gnus-newsgroup-dependencies)))
4255 threads))
4256
6748645f 4257;; Build the thread tree.
16409b0b 4258(defsubst gnus-dependencies-add-header (header dependencies force-new)
6748645f
LMI
4259 "Enter HEADER into the DEPENDENCIES table if it is not already there.
4260
4261If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4262if it was already present.
4263
4264If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4265will not be entered in the DEPENDENCIES table. Otherwise duplicate
23f87bed
MB
4266Message-IDs will be renamed to a unique Message-ID before being
4267entered.
6748645f
LMI
4268
4269Returns HEADER if it was entered in the DEPENDENCIES. Returns nil otherwise."
4270 (let* ((id (mail-header-id header))
4271 (id-dep (and id (intern id dependencies)))
23f87bed 4272 parent-id ref ref-dep ref-header replaced)
6748645f
LMI
4273 ;; Enter this `header' in the `dependencies' table.
4274 (cond
4275 ((not id-dep)
4276 (setq header nil))
4277 ;; The first two cases do the normal part: enter a new `header'
4278 ;; in the `dependencies' table.
4279 ((not (boundp id-dep))
4280 (set id-dep (list header)))
4281 ((null (car (symbol-value id-dep)))
4282 (setcar (symbol-value id-dep) header))
4283
4284 ;; From here the `header' was already present in the
4285 ;; `dependencies' table.
4286 (force-new
4287 ;; Overrides an existing entry;
4288 ;; just set the header part of the entry.
23f87bed
MB
4289 (setcar (symbol-value id-dep) header)
4290 (setq replaced t))
6748645f
LMI
4291
4292 ;; Renames the existing `header' to a unique Message-ID.
4293 ((not gnus-summary-ignore-duplicates)
4294 ;; An article with this Message-ID has already been seen.
4295 ;; We rename the Message-ID.
4296 (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4297 (list header))
4298 (mail-header-set-id header id))
4299
4300 ;; The last case ignores an existing entry, except it adds any
4301 ;; additional Xrefs (in case the two articles came from different
4302 ;; servers.
4303 ;; Also sets `header' to `nil' meaning that the `dependencies'
4304 ;; table was *not* modified.
4305 (t
4306 (mail-header-set-xref
4307 (car (symbol-value id-dep))
4308 (concat (or (mail-header-xref (car (symbol-value id-dep)))
4309 "")
4310 (or (mail-header-xref header) "")))
4311 (setq header nil)))
4312
23f87bed
MB
4313 (when (and header (not replaced))
4314 ;; First check that we are not creating a References loop.
4315 (setq parent-id (gnus-parent-id (mail-header-references header)))
4316 (setq ref parent-id)
6748645f
LMI
4317 (while (and ref
4318 (setq ref-dep (intern-soft ref dependencies))
4319 (boundp ref-dep)
4320 (setq ref-header (car (symbol-value ref-dep))))
4321 (if (string= id ref)
4322 ;; Yuk! This is a reference loop. Make the article be a
4323 ;; root article.
4324 (progn
4325 (mail-header-set-references (car (symbol-value id-dep)) "none")
23f87bed
MB
4326 (setq ref nil)
4327 (setq parent-id nil))
6748645f 4328 (setq ref (gnus-parent-id (mail-header-references ref-header)))))
23f87bed 4329 (setq ref-dep (intern (or parent-id "none") dependencies))
6748645f
LMI
4330 (if (boundp ref-dep)
4331 (setcdr (symbol-value ref-dep)
4332 (nconc (cdr (symbol-value ref-dep))
4333 (list (symbol-value id-dep))))
4334 (set ref-dep (list nil (symbol-value id-dep)))))
4335 header))
4336
23f87bed
MB
4337(defun gnus-extract-message-id-from-in-reply-to (string)
4338 (if (string-match "<[^>]+>" string)
4339 (substring string (match-beginning 0) (match-end 0))
4340 nil))
4341
eec82323
LMI
4342(defun gnus-build-sparse-threads ()
4343 (let ((headers gnus-newsgroup-headers)
16409b0b 4344 (mail-parse-charset gnus-newsgroup-charset)
6748645f 4345 (gnus-summary-ignore-duplicates t)
eec82323 4346 header references generation relations
6748645f 4347 subject child end new-child date)
eec82323
LMI
4348 ;; First we create an alist of generations/relations, where
4349 ;; generations is how much we trust the relation, and the relation
4350 ;; is parent/child.
4351 (gnus-message 7 "Making sparse threads...")
4352 (save-excursion
4353 (nnheader-set-temp-buffer " *gnus sparse threads*")
4354 (while (setq header (pop headers))
4355 (when (and (setq references (mail-header-references header))
4356 (not (string= references "")))
4357 (insert references)
4358 (setq child (mail-header-id header)
6748645f
LMI
4359 subject (mail-header-subject header)
4360 date (mail-header-date header)
4361 generation 0)
eec82323
LMI
4362 (while (search-backward ">" nil t)
4363 (setq end (1+ (point)))
4364 (when (search-backward "<" nil t)
6748645f 4365 (setq new-child (buffer-substring (point) end))
eec82323 4366 (push (list (incf generation)
6748645f
LMI
4367 child (setq child new-child)
4368 subject date)
eec82323 4369 relations)))
6748645f
LMI
4370 (when child
4371 (push (list (1+ generation) child nil subject) relations))
eec82323
LMI
4372 (erase-buffer)))
4373 (kill-buffer (current-buffer)))
4374 ;; Sort over trustworthiness.
01c52d31
MB
4375 (dolist (relation (sort relations 'car-less-than-car))
4376 (when (gnus-dependencies-add-header
4377 (make-full-mail-header
4378 gnus-reffed-article-number
4379 (nth 3 relation) "" (or (nth 4 relation) "")
4380 (nth 1 relation)
4381 (or (nth 2 relation) "") 0 0 "")
4382 gnus-newsgroup-dependencies nil)
4383 (push gnus-reffed-article-number gnus-newsgroup-limit)
4384 (push gnus-reffed-article-number gnus-newsgroup-sparse)
4385 (push (cons gnus-reffed-article-number gnus-sparse-mark)
4386 gnus-newsgroup-reads)
4387 (decf gnus-reffed-article-number)))
eec82323
LMI
4388 (gnus-message 7 "Making sparse threads...done")))
4389
4390(defun gnus-build-old-threads ()
4391 ;; Look at all the articles that refer back to old articles, and
4392 ;; fetch the headers for the articles that aren't there. This will
4393 ;; build complete threads - if the roots haven't been expired by the
4394 ;; server, that is.
16409b0b
GM
4395 (let ((mail-parse-charset gnus-newsgroup-charset)
4396 id heads)
eec82323
LMI
4397 (mapatoms
4398 (lambda (refs)
4399 (when (not (car (symbol-value refs)))
4400 (setq heads (cdr (symbol-value refs)))
4401 (while heads
4402 (if (memq (mail-header-number (caar heads))
4403 gnus-newsgroup-dormant)
4404 (setq heads (cdr heads))
4405 (setq id (symbol-name refs))
4406 (while (and (setq id (gnus-build-get-header id))
6748645f 4407 (not (car (gnus-id-to-thread id)))))
eec82323
LMI
4408 (setq heads nil)))))
4409 gnus-newsgroup-dependencies)))
4410
23f87bed
MB
4411(defsubst gnus-remove-odd-characters (string)
4412 "Translate STRING into something that doesn't contain weird characters."
4413 (mm-subst-char-in-string
4414 ?\r ?\-
01c52d31 4415 (mm-subst-char-in-string ?\n ?\- string t) t))
23f87bed 4416
6748645f
LMI
4417;; This function has to be called with point after the article number
4418;; on the beginning of the line.
4419(defsubst gnus-nov-parse-line (number dependencies &optional force-new)
01c52d31 4420 (let ((eol (point-at-eol))
6748645f 4421 (buffer (current-buffer))
23f87bed 4422 header references in-reply-to)
6748645f
LMI
4423
4424 ;; overview: [num subject from date id refs chars lines misc]
4425 (unwind-protect
23f87bed 4426 (let (x)
6748645f
LMI
4427 (narrow-to-region (point) eol)
4428 (unless (eobp)
4429 (forward-char))
4430
4431 (setq header
4432 (make-full-mail-header
4433 number ; number
23f87bed
MB
4434 (condition-case () ; subject
4435 (gnus-remove-odd-characters
4436 (funcall gnus-decode-encoded-word-function
4437 (setq x (nnheader-nov-field))))
4438 (error x))
4439 (condition-case () ; from
4440 (gnus-remove-odd-characters
343d6628 4441 (funcall gnus-decode-encoded-address-function
23f87bed
MB
4442 (setq x (nnheader-nov-field))))
4443 (error x))
16409b0b 4444 (nnheader-nov-field) ; date
01c52d31 4445 (nnheader-nov-read-message-id number) ; id
23f87bed 4446 (setq references (nnheader-nov-field)) ; refs
16409b0b
GM
4447 (nnheader-nov-read-integer) ; chars
4448 (nnheader-nov-read-integer) ; lines
4449 (unless (eobp)
8b93df01
DL
4450 (if (looking-at "Xref: ")
4451 (goto-char (match-end 0)))
4452 (nnheader-nov-field)) ; Xref
16409b0b 4453 (nnheader-nov-parse-extra)))) ; extra
6748645f
LMI
4454
4455 (widen))
4456
23f87bed
MB
4457 (when (and (string= references "")
4458 (setq in-reply-to (mail-header-extra header))
4459 (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4460 (mail-header-set-references
4461 header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4462
6748645f
LMI
4463 (when gnus-alter-header-function
4464 (funcall gnus-alter-header-function header))
4465 (gnus-dependencies-add-header header dependencies force-new)))
4466
eec82323 4467(defun gnus-build-get-header (id)
16409b0b
GM
4468 "Look through the buffer of NOV lines and find the header to ID.
4469Enter this line into the dependencies hash table, and return
4470the id of the parent article (if any)."
eec82323
LMI
4471 (let ((deps gnus-newsgroup-dependencies)
4472 found header)
4473 (prog1
c7a91ce1 4474 (with-current-buffer nntp-server-buffer
eec82323
LMI
4475 (let ((case-fold-search nil))
4476 (goto-char (point-min))
4477 (while (and (not found)
4478 (search-forward id nil t))
4479 (beginning-of-line)
4480 (setq found (looking-at
4481 (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4482 (regexp-quote id))))
4483 (or found (beginning-of-line 2)))
4484 (when found
4485 (beginning-of-line)
4486 (and
4487 (setq header (gnus-nov-parse-line
4488 (read (current-buffer)) deps))
4489 (gnus-parent-id (mail-header-references header))))))
4490 (when header
4491 (let ((number (mail-header-number header)))
4492 (push number gnus-newsgroup-limit)
4493 (push header gnus-newsgroup-headers)
4494 (if (memq number gnus-newsgroup-unselected)
4495 (progn
23f87bed
MB
4496 (setq gnus-newsgroup-unreads
4497 (gnus-add-to-sorted-list gnus-newsgroup-unreads
4498 number))
eec82323
LMI
4499 (setq gnus-newsgroup-unselected
4500 (delq number gnus-newsgroup-unselected)))
4501 (push number gnus-newsgroup-ancient)))))))
4502
6748645f
LMI
4503(defun gnus-build-all-threads ()
4504 "Read all the headers."
4505 (let ((gnus-summary-ignore-duplicates t)
16409b0b 4506 (mail-parse-charset gnus-newsgroup-charset)
6748645f
LMI
4507 (dependencies gnus-newsgroup-dependencies)
4508 header article)
c7a91ce1 4509 (with-current-buffer nntp-server-buffer
6748645f
LMI
4510 (let ((case-fold-search nil))
4511 (goto-char (point-min))
4512 (while (not (eobp))
4513 (ignore-errors
4514 (setq article (read (current-buffer))
16409b0b 4515 header (gnus-nov-parse-line article dependencies)))
6748645f 4516 (when header
01c52d31 4517 (with-current-buffer gnus-summary-buffer
6748645f
LMI
4518 (push header gnus-newsgroup-headers)
4519 (if (memq (setq article (mail-header-number header))
4520 gnus-newsgroup-unselected)
4521 (progn
23f87bed
MB
4522 (setq gnus-newsgroup-unreads
4523 (gnus-add-to-sorted-list
4524 gnus-newsgroup-unreads article))
6748645f
LMI
4525 (setq gnus-newsgroup-unselected
4526 (delq article gnus-newsgroup-unselected)))
4527 (push article gnus-newsgroup-ancient)))
4528 (forward-line 1)))))))
4529
eec82323 4530(defun gnus-summary-update-article-line (article header)
23f87bed 4531 "Update the line for ARTICLE using HEADER."
eec82323
LMI
4532 (let* ((id (mail-header-id header))
4533 (thread (gnus-id-to-thread id)))
4534 (unless thread
4535 (error "Article in no thread"))
4536 ;; Update the thread.
4537 (setcar thread header)
4538 (gnus-summary-goto-subject article)
4539 (let* ((datal (gnus-data-find-list article))
4540 (data (car datal))
c7a91ce1 4541 (inhibit-read-only t)
eec82323
LMI
4542 (level (gnus-summary-thread-level)))
4543 (gnus-delete-line)
23f87bed
MB
4544 (let ((inserted (- (point)
4545 (progn
4546 (gnus-summary-insert-line
4547 header level nil
4548 (memq article gnus-newsgroup-undownloaded)
4549 (gnus-article-mark article)
4550 (memq article gnus-newsgroup-replied)
4551 (memq article gnus-newsgroup-expirable)
4552 ;; Only insert the Subject string when it's different
4553 ;; from the previous Subject string.
4554 (if (and
4555 gnus-show-threads
4556 (gnus-subject-equal
4557 (condition-case ()
4558 (mail-header-subject
4559 (gnus-data-header
4560 (cadr
4561 (gnus-data-find-list
4562 article
4563 (gnus-data-list t)))))
4564 ;; Error on the side of excessive subjects.
4565 (error ""))
4566 (mail-header-subject header)))
4567 ""
4568 (mail-header-subject header))
4569 nil (cdr (assq article gnus-newsgroup-scored))
4570 (memq article gnus-newsgroup-processable))
4571 (point)))))
4572 (when (cdr datal)
4573 (gnus-data-update-list
4574 (cdr datal)
4575 (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
eec82323
LMI
4576
4577(defun gnus-summary-update-article (article &optional iheader)
4578 "Update ARTICLE in the summary buffer."
4579 (set-buffer gnus-summary-buffer)
6748645f 4580 (let* ((header (gnus-summary-article-header article))
eec82323
LMI
4581 (id (mail-header-id header))
4582 (data (gnus-data-find article))
4583 (thread (gnus-id-to-thread id))
4584 (references (mail-header-references header))
4585 (parent
4586 (gnus-id-to-thread
4587 (or (gnus-parent-id
4588 (when (and references
4589 (not (equal "" references)))
4590 references))
4591 "none")))
c7a91ce1 4592 (inhibit-read-only t)
6748645f 4593 (old (car thread)))
eec82323 4594 (when thread
eec82323 4595 (unless iheader
6748645f
LMI
4596 (setcar thread nil)
4597 (when parent
4598 (delq thread parent)))
4599 (if (gnus-summary-insert-subject id header)
eec82323
LMI
4600 ;; Set the (possibly) new article number in the data structure.
4601 (gnus-data-set-number data (gnus-id-to-article id))
4602 (setcar thread old)
4603 nil))))
4604
6748645f
LMI
4605(defun gnus-rebuild-thread (id &optional line)
4606 "Rebuild the thread containing ID.
4607If LINE, insert the rebuilt thread starting on line LINE."
c7a91ce1 4608 (let ((inhibit-read-only t)
eec82323
LMI
4609 old-pos current thread data)
4610 (if (not gnus-show-threads)
4611 (setq thread (list (car (gnus-id-to-thread id))))
4612 ;; Get the thread this article is part of.
4613 (setq thread (gnus-remove-thread id)))
01c52d31 4614 (setq old-pos (point-at-bol))
eec82323 4615 (setq current (save-excursion
94384150 4616 (and (re-search-backward "[\r\n]" nil t)
eec82323
LMI
4617 (gnus-summary-article-number))))
4618 ;; If this is a gathered thread, we have to go some re-gathering.
4619 (when (stringp (car thread))
4620 (let ((subject (car thread))
4621 roots thr)
4622 (setq thread (cdr thread))
4623 (while thread
4624 (unless (memq (setq thr (gnus-id-to-thread
4625 (gnus-root-id
4626 (mail-header-id (caar thread)))))
4627 roots)
4628 (push thr roots))
4629 (setq thread (cdr thread)))
4630 ;; We now have all (unique) roots.
4631 (if (= (length roots) 1)
4632 ;; All the loose roots are now one solid root.
4633 (setq thread (car roots))
4634 (setq thread (cons subject (gnus-sort-threads roots))))))
4635 (let (threads)
4636 ;; We then insert this thread into the summary buffer.
6748645f
LMI
4637 (when line
4638 (goto-char (point-min))
4639 (forward-line (1- line)))
eec82323
LMI
4640 (let (gnus-newsgroup-data gnus-newsgroup-threads)
4641 (if gnus-show-threads
4642 (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4643 (gnus-summary-prepare-unthreaded thread))
4644 (setq data (nreverse gnus-newsgroup-data))
4645 (setq threads gnus-newsgroup-threads))
4646 ;; We splice the new data into the data structure.
6748645f
LMI
4647 ;;!!! This is kinda bogus. We assume that in LINE is non-nil,
4648 ;;!!! then we want to insert at the beginning of the buffer.
4649 ;;!!! That happens to be true with Gnus now, but that may
4650 ;;!!! change in the future. Perhaps.
4651 (gnus-data-enter-list
4652 (if line nil current) data (- (point) old-pos))
4653 (setq gnus-newsgroup-threads
4654 (nconc threads gnus-newsgroup-threads))
4655 (gnus-data-compute-positions))))
eec82323
LMI
4656
4657(defun gnus-number-to-header (number)
4658 "Return the header for article NUMBER."
4659 (let ((headers gnus-newsgroup-headers))
4660 (while (and headers
4661 (not (= number (mail-header-number (car headers)))))
4662 (pop headers))
4663 (when headers
4664 (car headers))))
4665
6748645f 4666(defun gnus-parent-headers (in-headers &optional generation)
eec82323
LMI
4667 "Return the headers of the GENERATIONeth parent of HEADERS."
4668 (unless generation
4669 (setq generation 1))
a8151ef7 4670 (let ((parent t)
6748645f 4671 (headers in-headers)
a8151ef7 4672 references)
6748645f
LMI
4673 (while (and parent
4674 (not (zerop generation))
4675 (setq references (mail-header-references headers)))
4676 (setq headers (if (and references
4677 (setq parent (gnus-parent-id references)))
4678 (car (gnus-id-to-thread parent))
4679 nil))
4680 (decf generation))
4681 (and (not (eq headers in-headers))
4682 headers)))
eec82323
LMI
4683
4684(defun gnus-id-to-thread (id)
4685 "Return the (sub-)thread where ID appears."
4686 (gnus-gethash id gnus-newsgroup-dependencies))
4687
4688(defun gnus-id-to-article (id)
4689 "Return the article number of ID."
4690 (let ((thread (gnus-id-to-thread id)))
4691 (when (and thread
4692 (car thread))
4693 (mail-header-number (car thread)))))
4694
4695(defun gnus-id-to-header (id)
4696 "Return the article headers of ID."
4697 (car (gnus-id-to-thread id)))
4698
4699(defun gnus-article-displayed-root-p (article)
4700 "Say whether ARTICLE is a root(ish) article."
4701 (let ((level (gnus-summary-thread-level article))
4702 (refs (mail-header-references (gnus-summary-article-header article)))
4703 particle)
4704 (cond
4705 ((null level) nil)
4706 ((zerop level) t)
4707 ((null refs) t)
4708 ((null (gnus-parent-id refs)) t)
4709 ((and (= 1 level)
4710 (null (setq particle (gnus-id-to-article
4711 (gnus-parent-id refs))))
4712 (null (gnus-summary-thread-level particle)))))))
4713
4714(defun gnus-root-id (id)
4715 "Return the id of the root of the thread where ID appears."
4716 (let (last-id prev)
6748645f 4717 (while (and id (setq prev (car (gnus-id-to-thread id))))
eec82323
LMI
4718 (setq last-id id
4719 id (gnus-parent-id (mail-header-references prev))))
4720 last-id))
4721
6748645f
LMI
4722(defun gnus-articles-in-thread (thread)
4723 "Return the list of articles in THREAD."
4724 (cons (mail-header-number (car thread))
4725 (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4726
eec82323
LMI
4727(defun gnus-remove-thread (id &optional dont-remove)
4728 "Remove the thread that has ID in it."
6748645f 4729 (let (headers thread last-id)
eec82323 4730 ;; First go up in this thread until we find the root.
6748645f
LMI
4731 (setq last-id (gnus-root-id id)
4732 headers (message-flatten-list (gnus-id-to-thread last-id)))
01ccbb85 4733 ;; We have now found the real root of this thread. It might have
eec82323
LMI
4734 ;; been gathered into some loose thread, so we have to search
4735 ;; through the threads to find the thread we wanted.
4736 (let ((threads gnus-newsgroup-threads)
4737 sub)
4738 (while threads
4739 (setq sub (car threads))
4740 (if (stringp (car sub))
4741 ;; This is a gathered thread, so we look at the roots
4742 ;; below it to find whether this article is in this
4743 ;; gathered root.
4744 (progn
4745 (setq sub (cdr sub))
4746 (while sub
4747 (when (member (caar sub) headers)
4748 (setq thread (car threads)
4749 threads nil
4750 sub nil))
4751 (setq sub (cdr sub))))
4752 ;; It's an ordinary thread, so we check it.
4753 (when (eq (car sub) (car headers))
4754 (setq thread sub
4755 threads nil)))
4756 (setq threads (cdr threads)))
4757 ;; If this article is in no thread, then it's a root.
4758 (if thread
4759 (unless dont-remove
4760 (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
6748645f 4761 (setq thread (gnus-id-to-thread last-id)))
eec82323
LMI
4762 (when thread
4763 (prog1
4764 thread ; We return this thread.
4765 (unless dont-remove
4766 (if (stringp (car thread))
4767 (progn
4768 ;; If we use dummy roots, then we have to remove the
4769 ;; dummy root as well.
4770 (when (eq gnus-summary-make-false-root 'dummy)
6748645f
LMI
4771 ;; We go to the dummy root by going to
4772 ;; the first sub-"thread", and then one line up.
4773 (gnus-summary-goto-article
4774 (mail-header-number (caadr thread)))
4775 (forward-line -1)
eec82323
LMI
4776 (gnus-delete-line)
4777 (gnus-data-compute-positions))
4778 (setq thread (cdr thread))
4779 (while thread
4780 (gnus-remove-thread-1 (car thread))
4781 (setq thread (cdr thread))))
4782 (gnus-remove-thread-1 thread))))))))
4783
4784(defun gnus-remove-thread-1 (thread)
4785 "Remove the thread THREAD recursively."
4786 (let ((number (mail-header-number (pop thread)))
4787 d)
4788 (setq thread (reverse thread))
4789 (while thread
4790 (gnus-remove-thread-1 (pop thread)))
4791 (when (setq d (gnus-data-find number))
4792 (goto-char (gnus-data-pos d))
16409b0b 4793 (gnus-summary-show-thread)
eec82323
LMI
4794 (gnus-data-remove
4795 number
01c52d31 4796 (- (point-at-bol)
eec82323 4797 (prog1
01c52d31 4798 (1+ (point-at-eol))
eec82323
LMI
4799 (gnus-delete-line)))))))
4800
4921bbdd 4801(defun gnus-sort-threads-recursive (threads func)
16409b0b
GM
4802 (sort (mapcar (lambda (thread)
4803 (cons (car thread)
4804 (and (cdr thread)
4921bbdd 4805 (gnus-sort-threads-recursive (cdr thread) func))))
16409b0b
GM
4806 threads) func))
4807
4921bbdd
CY
4808(defun gnus-sort-threads-loop (threads func)
4809 (let* ((superthread (cons nil threads))
4810 (stack (list (cons superthread threads)))
4811 remaining-threads thread)
4812 (while stack
4813 (setq remaining-threads (cdr (car stack)))
4814 (if remaining-threads
4815 (progn (setq thread (car remaining-threads))
4816 (setcdr (car stack) (cdr remaining-threads))
4817 (if (cdr thread)
4818 (push (cons thread (cdr thread)) stack)))
4819 (setq thread (caar stack))
4820 (setcdr thread (sort (cdr thread) func))
4821 (pop stack)))
4822 (cdr superthread)))
4823
eec82323
LMI
4824(defun gnus-sort-threads (threads)
4825 "Sort THREADS."
4826 (if (not gnus-thread-sort-functions)
4827 threads
6748645f 4828 (gnus-message 8 "Sorting threads...")
4921bbdd
CY
4829 (prog1
4830 (condition-case nil
4831 (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4832 (gnus-sort-threads-recursive
4833 threads (gnus-make-sort-function gnus-thread-sort-functions)))
4834 ;; Even after binding max-lisp-eval-depth, the recursive
4835 ;; sorter might fail for very long threads. In that case,
4836 ;; try using a (less well-tested) non-recursive sorter.
3d6e7a43
KY
4837 (error (gnus-message 9 "Sorting threads with loop...")
4838 (gnus-sort-threads-loop
4921bbdd
CY
4839 threads (gnus-make-sort-function
4840 gnus-thread-sort-functions))))
4841 (gnus-message 8 "Sorting threads...done"))))
eec82323
LMI
4842
4843(defun gnus-sort-articles (articles)
4844 "Sort ARTICLES."
4845 (when gnus-article-sort-functions
4846 (gnus-message 7 "Sorting articles...")
4847 (prog1
4848 (setq gnus-newsgroup-headers
4849 (sort articles (gnus-make-sort-function
4850 gnus-article-sort-functions)))
4851 (gnus-message 7 "Sorting articles...done"))))
4852
4853;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4854(defmacro gnus-thread-header (thread)
16409b0b
GM
4855 "Return header of first article in THREAD.
4856Note that THREAD must never, ever be anything else than a variable -
4857using some other form will lead to serious barfage."
eec82323
LMI
4858 (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4859 ;; (8% speedup to gnus-summary-prepare, just for fun :-)
16409b0b 4860 (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
eec82323
LMI
4861 (vector thread) 2))
4862
4863(defsubst gnus-article-sort-by-number (h1 h2)
4864 "Sort articles by article number."
4865 (< (mail-header-number h1)
4866 (mail-header-number h2)))
4867
4868(defun gnus-thread-sort-by-number (h1 h2)
4869 "Sort threads by root article number."
4870 (gnus-article-sort-by-number
4871 (gnus-thread-header h1) (gnus-thread-header h2)))
4872
23f87bed 4873(defsubst gnus-article-sort-by-random (h1 h2)
0b6799c3 4874 "Sort articles randomly."
23f87bed
MB
4875 (zerop (random 2)))
4876
4877(defun gnus-thread-sort-by-random (h1 h2)
0b6799c3 4878 "Sort threads randomly."
23f87bed
MB
4879 (gnus-article-sort-by-random
4880 (gnus-thread-header h1) (gnus-thread-header h2)))
4881
eec82323
LMI
4882(defsubst gnus-article-sort-by-lines (h1 h2)
4883 "Sort articles by article Lines header."
4884 (< (mail-header-lines h1)
4885 (mail-header-lines h2)))
4886
4887(defun gnus-thread-sort-by-lines (h1 h2)
4888 "Sort threads by root article Lines header."
4889 (gnus-article-sort-by-lines
4890 (gnus-thread-header h1) (gnus-thread-header h2)))
4891
16409b0b
GM
4892(defsubst gnus-article-sort-by-chars (h1 h2)
4893 "Sort articles by octet length."
4894 (< (mail-header-chars h1)
4895 (mail-header-chars h2)))
4896
4897(defun gnus-thread-sort-by-chars (h1 h2)
4898 "Sort threads by root article octet length."
4899 (gnus-article-sort-by-chars
4900 (gnus-thread-header h1) (gnus-thread-header h2)))
4901
eec82323
LMI
4902(defsubst gnus-article-sort-by-author (h1 h2)
4903 "Sort articles by root author."
b4fde39f 4904 (gnus-string<
eec82323
LMI
4905 (let ((extract (funcall
4906 gnus-extract-address-components
4907 (mail-header-from h1))))
4908 (or (car extract) (cadr extract) ""))
4909 (let ((extract (funcall
4910 gnus-extract-address-components
4911 (mail-header-from h2))))
4912 (or (car extract) (cadr extract) ""))))
4913
4914(defun gnus-thread-sort-by-author (h1 h2)
4915 "Sort threads by root author."
4916 (gnus-article-sort-by-author
4917 (gnus-thread-header h1) (gnus-thread-header h2)))
4918
01c52d31
MB
4919(defsubst gnus-article-sort-by-recipient (h1 h2)
4920 "Sort articles by recipient."
4921 (gnus-string<
4922 (let ((extract (funcall
4923 gnus-extract-address-components
4924 (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4925 (or (car extract) (cadr extract)))
4926 (let ((extract (funcall
4927 gnus-extract-address-components
4928 (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4929 (or (car extract) (cadr extract)))))
4930
4931(defun gnus-thread-sort-by-recipient (h1 h2)
4932 "Sort threads by root recipient."
4933 (gnus-article-sort-by-recipient
4934 (gnus-thread-header h1) (gnus-thread-header h2)))
4935
eec82323
LMI
4936(defsubst gnus-article-sort-by-subject (h1 h2)
4937 "Sort articles by root subject."
b4fde39f 4938 (gnus-string<
eec82323
LMI
4939 (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4940 (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4941
4942(defun gnus-thread-sort-by-subject (h1 h2)
4943 "Sort threads by root subject."
4944 (gnus-article-sort-by-subject
4945 (gnus-thread-header h1) (gnus-thread-header h2)))
4946
4947(defsubst gnus-article-sort-by-date (h1 h2)
4948 "Sort articles by root article date."
16409b0b 4949 (time-less-p
eec82323
LMI
4950 (gnus-date-get-time (mail-header-date h1))
4951 (gnus-date-get-time (mail-header-date h2))))
4952
4953(defun gnus-thread-sort-by-date (h1 h2)
4954 "Sort threads by root article date."
4955 (gnus-article-sort-by-date
4956 (gnus-thread-header h1) (gnus-thread-header h2)))
4957
4958(defsubst gnus-article-sort-by-score (h1 h2)
4959 "Sort articles by root article score.
4960Unscored articles will be counted as having a score of zero."
4961 (> (or (cdr (assq (mail-header-number h1)
4962 gnus-newsgroup-scored))
4963 gnus-summary-default-score 0)
4964 (or (cdr (assq (mail-header-number h2)
4965 gnus-newsgroup-scored))
4966 gnus-summary-default-score 0)))
4967
4968(defun gnus-thread-sort-by-score (h1 h2)
4969 "Sort threads by root article score."
4970 (gnus-article-sort-by-score
4971 (gnus-thread-header h1) (gnus-thread-header h2)))
4972
4973(defun gnus-thread-sort-by-total-score (h1 h2)
4974 "Sort threads by the sum of all scores in the thread.
4975Unscored articles will be counted as having a score of zero."
4976 (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4977
4978(defun gnus-thread-total-score (thread)
16409b0b 4979 ;; This function find the total score of THREAD.
23f87bed
MB
4980 (cond
4981 ((null thread)
4982 0)
4983 ((consp thread)
4984 (if (stringp (car thread))
4985 (apply gnus-thread-score-function 0
4986 (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4987 (gnus-thread-total-score-1 thread)))
4988 (t
4989 (gnus-thread-total-score-1 (list thread)))))
4990
4991(defun gnus-thread-sort-by-most-recent-number (h1 h2)
4992 "Sort threads such that the thread with the most recently arrived article comes first."
4993 (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4994
4995(defun gnus-thread-highest-number (thread)
4996 "Return the highest article number in THREAD."
4997 (apply 'max (mapcar (lambda (header)
4998 (mail-header-number header))
4999 (message-flatten-list thread))))
5000
5001(defun gnus-thread-sort-by-most-recent-date (h1 h2)
5002 "Sort threads such that the thread with the most recently dated article comes first."
5003 (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
5004
3d6e7a43
KY
5005; Since this is called not only to sort the top-level threads, but
5006; also in recursive sorts to order the articles within a thread, each
5007; article will be processed many times. Thus it speeds things up
5008; quite a bit to use gnus-date-get-time, which caches the time value.
23f87bed
MB
5009(defun gnus-thread-latest-date (thread)
5010 "Return the highest article date in THREAD."
3d6e7a43
KY
5011 (apply 'max
5012 (mapcar (lambda (header) (gnus-float-time
5013 (gnus-date-get-time
5014 (mail-header-date header))))
5015 (message-flatten-list thread))))
eec82323
LMI
5016
5017(defun gnus-thread-total-score-1 (root)
5018 ;; This function find the total score of the thread below ROOT.
5019 (setq root (car root))
5020 (apply gnus-thread-score-function
5021 (or (append
5022 (mapcar 'gnus-thread-total-score
6748645f 5023 (cdr (gnus-id-to-thread (mail-header-id root))))
eec82323
LMI
5024 (when (> (mail-header-number root) 0)
5025 (list (or (cdr (assq (mail-header-number root)
5026 gnus-newsgroup-scored))
5027 gnus-summary-default-score 0))))
5028 (list gnus-summary-default-score)
5029 '(0))))
5030
5031;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
5032(defvar gnus-tmp-prev-subject nil)
5033(defvar gnus-tmp-false-parent nil)
5034(defvar gnus-tmp-root-expunged nil)
5035(defvar gnus-tmp-dummy-line nil)
5036
16409b0b
GM
5037(defun gnus-extra-header (type &optional header)
5038 "Return the extra header of TYPE."
5039 (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
5040 ""))
5041
23f87bed
MB
5042(defvar gnus-tmp-thread-tree-header-string "")
5043
5044(defcustom gnus-sum-thread-tree-root "> "
5045 "With %B spec, used for the root of a thread.
5046If nil, use subject instead."
bf247b6e 5047 :version "22.1"
ad136a7c 5048 :type '(radio (const :format "%v " nil) string)
23f87bed 5049 :group 'gnus-thread)
01c52d31 5050
23f87bed
MB
5051(defcustom gnus-sum-thread-tree-false-root "> "
5052 "With %B spec, used for a false root of a thread.
5053If nil, use subject instead."
bf247b6e 5054 :version "22.1"
ad136a7c 5055 :type '(radio (const :format "%v " nil) string)
23f87bed 5056 :group 'gnus-thread)
01c52d31 5057
23f87bed
MB
5058(defcustom gnus-sum-thread-tree-single-indent ""
5059 "With %B spec, used for a thread with just one message.
5060If nil, use subject instead."
bf247b6e 5061 :version "22.1"
ad136a7c 5062 :type '(radio (const :format "%v " nil) string)
23f87bed 5063 :group 'gnus-thread)
01c52d31 5064
23f87bed
MB
5065(defcustom gnus-sum-thread-tree-vertical "| "
5066 "With %B spec, used for drawing a vertical line."
bf247b6e 5067 :version "22.1"
23f87bed
MB
5068 :type 'string
5069 :group 'gnus-thread)
01c52d31 5070
23f87bed
MB
5071(defcustom gnus-sum-thread-tree-indent " "
5072 "With %B spec, used for indenting."
bf247b6e 5073 :version "22.1"
23f87bed
MB
5074 :type 'string
5075 :group 'gnus-thread)
01c52d31 5076
23f87bed
MB
5077(defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5078 "With %B spec, used for a leaf with brothers."
bf247b6e 5079 :version "22.1"
23f87bed
MB
5080 :type 'string
5081 :group 'gnus-thread)
01c52d31 5082
23f87bed
MB
5083(defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5084 "With %B spec, used for a leaf without brothers."
bf247b6e 5085 :version "22.1"
23f87bed
MB
5086 :type 'string
5087 :group 'gnus-thread)
5088
1fc34624
GM
5089(defcustom gnus-summary-display-while-building nil
5090 "If non-nil, show and update the summary buffer as it's being built.
5091If the value is t, update the buffer after every line is inserted. If
5092the value is an integer (N), update the display every N lines."
5093 :version "22.1"
5094 :group 'gnus-thread
5095 :type '(choice (const :tag "off" nil)
5096 number
5097 (const :tag "frequently" t)))
5098
eec82323
LMI
5099(defun gnus-summary-prepare-threads (threads)
5100 "Prepare summary buffer from THREADS and indentation LEVEL.
5101THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5102or a straight list of headers."
5103 (gnus-message 7 "Generating summary...")
5104
5105 (setq gnus-newsgroup-threads threads)
5106 (beginning-of-line)
5107
5108 (let ((gnus-tmp-level 0)
5109 (default-score (or gnus-summary-default-score 0))
5110 (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
23f87bed
MB
5111 (building-line-count gnus-summary-display-while-building)
5112 (building-count (integerp gnus-summary-display-while-building))
eec82323 5113 thread number subject stack state gnus-tmp-gathered beg-match
23f87bed
MB
5114 new-roots gnus-tmp-new-adopts thread-end simp-subject
5115 gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
eec82323
LMI
5116 gnus-tmp-replied gnus-tmp-subject-or-nil
5117 gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5118 gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
23f87bed
MB
5119 gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5120 tree-stack)
eec82323 5121
23f87bed
MB
5122 (setq gnus-tmp-prev-subject nil
5123 gnus-tmp-thread-tree-header-string "")
eec82323
LMI
5124
5125 (if (vectorp (car threads))
5126 ;; If this is a straight (sic) list of headers, then a
5127 ;; threaded summary display isn't required, so we just create
5128 ;; an unthreaded one.
5129 (gnus-summary-prepare-unthreaded threads)
5130
5131 ;; Do the threaded display.
5132
23f87bed
MB
5133 (if gnus-summary-display-while-building
5134 (switch-to-buffer (buffer-name)))
eec82323
LMI
5135 (while (or threads stack gnus-tmp-new-adopts new-roots)
5136
5137 (if (and (= gnus-tmp-level 0)
eec82323
LMI
5138 (or (not stack)
5139 (= (caar stack) 0))
5140 (not gnus-tmp-false-parent)
5141 (or gnus-tmp-new-adopts new-roots))
5142 (if gnus-tmp-new-adopts
5143 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5144 thread (list (car gnus-tmp-new-adopts))
5145 gnus-tmp-header (caar thread)
5146 gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5147 (when new-roots
5148 (setq thread (list (car new-roots))
5149 gnus-tmp-header (caar thread)
5150 new-roots (cdr new-roots))))
5151
5152 (if threads
5153 ;; If there are some threads, we do them before the
5154 ;; threads on the stack.
5155 (setq thread threads
5156 gnus-tmp-header (caar thread))
5157 ;; There were no current threads, so we pop something off
5158 ;; the stack.
5159 (setq state (car stack)
5160 gnus-tmp-level (car state)
23f87bed
MB
5161 tree-stack (cadr state)
5162 thread (caddr state)
eec82323
LMI
5163 stack (cdr stack)
5164 gnus-tmp-header (caar thread))))
5165
5166 (setq gnus-tmp-false-parent nil)
5167 (setq gnus-tmp-root-expunged nil)
5168 (setq thread-end nil)
5169
5170 (if (stringp gnus-tmp-header)
5171 ;; The header is a dummy root.
5172 (cond
5173 ((eq gnus-summary-make-false-root 'adopt)
5174 ;; We let the first article adopt the rest.
5175 (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5176 (cddar thread)))
5177 (setq gnus-tmp-gathered
5178 (nconc (mapcar
5179 (lambda (h) (mail-header-number (car h)))
5180 (cddar thread))
5181 gnus-tmp-gathered))
5182 (setq thread (cons (list (caar thread)
5183 (cadar thread))
5184 (cdr thread)))
5185 (setq gnus-tmp-level -1
5186 gnus-tmp-false-parent t))
5187 ((eq gnus-summary-make-false-root 'empty)
5188 ;; We print adopted articles with empty subject fields.
5189 (setq gnus-tmp-gathered
5190 (nconc (mapcar
5191 (lambda (h) (mail-header-number (car h)))
5192 (cddar thread))
5193 gnus-tmp-gathered))
5194 (setq gnus-tmp-level -1))
5195 ((eq gnus-summary-make-false-root 'dummy)
5196 ;; We remember that we probably want to output a dummy
5197 ;; root.
5198 (setq gnus-tmp-dummy-line gnus-tmp-header)
5199 (setq gnus-tmp-prev-subject gnus-tmp-header))
5200 (t
5201 ;; We do not make a root for the gathered
5202 ;; sub-threads at all.
5203 (setq gnus-tmp-level -1)))
5204
5205 (setq number (mail-header-number gnus-tmp-header)
23f87bed
MB
5206 subject (mail-header-subject gnus-tmp-header)
5207 simp-subject (gnus-simplify-subject-fully subject))
eec82323
LMI
5208
5209 (cond
5210 ;; If the thread has changed subject, we might want to make
5211 ;; this subthread into a root.
5212 ((and (null gnus-thread-ignore-subject)
5213 (not (zerop gnus-tmp-level))
5214 gnus-tmp-prev-subject
23f87bed 5215 (not (string= gnus-tmp-prev-subject simp-subject)))
eec82323
LMI
5216 (setq new-roots (nconc new-roots (list (car thread)))
5217 thread-end t
5218 gnus-tmp-header nil))
5219 ;; If the article lies outside the current limit,
5220 ;; then we do not display it.
5221 ((not (memq number gnus-newsgroup-limit))
5222 (setq gnus-tmp-gathered
5223 (nconc (mapcar
5224 (lambda (h) (mail-header-number (car h)))
5225 (cdar thread))
5226 gnus-tmp-gathered))
5227 (setq gnus-tmp-new-adopts (if (cdar thread)
5228 (append gnus-tmp-new-adopts
5229 (cdar thread))
5230 gnus-tmp-new-adopts)
5231 thread-end t
5232 gnus-tmp-header nil)
5233 (when (zerop gnus-tmp-level)
5234 (setq gnus-tmp-root-expunged t)))
5235 ;; Perhaps this article is to be marked as read?
5236 ((and gnus-summary-mark-below
5237 (< (or (cdr (assq number gnus-newsgroup-scored))
5238 default-score)
5239 gnus-summary-mark-below)
5240 ;; Don't touch sparse articles.
5241 (not (gnus-summary-article-sparse-p number))
5242 (not (gnus-summary-article-ancient-p number)))
5243 (setq gnus-newsgroup-unreads
5244 (delq number gnus-newsgroup-unreads))
5245 (if gnus-newsgroup-auto-expire
23f87bed
MB
5246 (setq gnus-newsgroup-expirable
5247 (gnus-add-to-sorted-list
5248 gnus-newsgroup-expirable number))
eec82323
LMI
5249 (push (cons number gnus-low-score-mark)
5250 gnus-newsgroup-reads))))
5251
5252 (when gnus-tmp-header
5253 ;; We may have an old dummy line to output before this
5254 ;; article.
6748645f
LMI
5255 (when (and gnus-tmp-dummy-line
5256 (gnus-subject-equal
5257 gnus-tmp-dummy-line
5258 (mail-header-subject gnus-tmp-header)))
eec82323
LMI
5259 (gnus-summary-insert-dummy-line
5260 gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5261 (setq gnus-tmp-dummy-line nil))
5262
5263 ;; Compute the mark.
5264 (setq gnus-tmp-unread (gnus-article-mark number))
5265
5266 (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5267 gnus-tmp-header gnus-tmp-level)
5268 gnus-newsgroup-data)
5269
5270 ;; Actually insert the line.
5271 (setq
5272 gnus-tmp-subject-or-nil
5273 (cond
5274 ((and gnus-thread-ignore-subject
5275 gnus-tmp-prev-subject
23f87bed 5276 (not (string= gnus-tmp-prev-subject simp-subject)))
eec82323
LMI
5277 subject)
5278 ((zerop gnus-tmp-level)
5279 (if (and (eq gnus-summary-make-false-root 'empty)
5280 (memq number gnus-tmp-gathered)
5281 gnus-tmp-prev-subject
23f87bed 5282 (string= gnus-tmp-prev-subject simp-subject))
eec82323
LMI
5283 gnus-summary-same-subject
5284 subject))
5285 (t gnus-summary-same-subject)))
5286 (if (and (eq gnus-summary-make-false-root 'adopt)
5287 (= gnus-tmp-level 1)
5288 (memq number gnus-tmp-gathered))
5289 (setq gnus-tmp-opening-bracket ?\<
5290 gnus-tmp-closing-bracket ?\>)
5291 (setq gnus-tmp-opening-bracket ?\[
5292 gnus-tmp-closing-bracket ?\]))
4921bbdd
CY
5293 (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5294 (gnus-make-thread-indent-array
5295 (max (* 2 (length gnus-thread-indent-array))
5296 gnus-tmp-level)))
eec82323
LMI
5297 (setq
5298 gnus-tmp-indentation
5299 (aref gnus-thread-indent-array gnus-tmp-level)
5300 gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5301 gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5302 gnus-summary-default-score 0)
5303 gnus-tmp-score-char
5304 (if (or (null gnus-summary-default-score)
5305 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5306 gnus-summary-zcore-fuzz))
23f87bed 5307 ? ;Whitespace
eec82323
LMI
5308 (if (< gnus-tmp-score gnus-summary-default-score)
5309 gnus-score-below-mark gnus-score-over-mark))
5310 gnus-tmp-replied
5311 (cond ((memq number gnus-newsgroup-processable)
5312 gnus-process-mark)
5313 ((memq number gnus-newsgroup-cached)
5314 gnus-cached-mark)
5315 ((memq number gnus-newsgroup-replied)
5316 gnus-replied-mark)
23f87bed
MB
5317 ((memq number gnus-newsgroup-forwarded)
5318 gnus-forwarded-mark)
eec82323
LMI
5319 ((memq number gnus-newsgroup-saved)
5320 gnus-saved-mark)
23f87bed
MB
5321 ((memq number gnus-newsgroup-recent)
5322 gnus-recent-mark)
5323 ((memq number gnus-newsgroup-unseen)
5324 gnus-unseen-mark)
5325 (t gnus-no-mark))
5326 gnus-tmp-downloaded
5327 (cond ((memq number gnus-newsgroup-undownloaded)
5328 gnus-undownloaded-mark)
5329 (gnus-newsgroup-agentized
5330 gnus-downloaded-mark)
5331 (t
5332 gnus-no-mark))
eec82323
LMI
5333 gnus-tmp-from (mail-header-from gnus-tmp-header)
5334 gnus-tmp-name
5335 (cond
5336 ((string-match "<[^>]+> *$" gnus-tmp-from)
5337 (setq beg-match (match-beginning 0))
23f87bed
MB
5338 (or (and (string-match "^\".+\"" gnus-tmp-from)
5339 (substring gnus-tmp-from 1 (1- (match-end 0))))
eec82323
LMI
5340 (substring gnus-tmp-from 0 beg-match)))
5341 ((string-match "(.+)" gnus-tmp-from)
5342 (substring gnus-tmp-from
5343 (1+ (match-beginning 0)) (1- (match-end 0))))
23f87bed
MB
5344 (t gnus-tmp-from))
5345
5346 ;; Do the %B string
5347 gnus-tmp-thread-tree-header-string
5348 (cond
5349 ((not gnus-show-threads) "")
5350 ((zerop gnus-tmp-level)
5351 (cond ((cdar thread)
5352 (or gnus-sum-thread-tree-root subject))
5353 (gnus-tmp-new-adopts
5354 (or gnus-sum-thread-tree-false-root subject))
5355 (t
5356 (or gnus-sum-thread-tree-single-indent subject))))
5357 (t
5358 (concat (apply 'concat
5359 (mapcar (lambda (item)
5360 (if (= item 1)
5361 gnus-sum-thread-tree-vertical
5362 gnus-sum-thread-tree-indent))
5363 (cdr (reverse tree-stack))))
5364 (if (nth 1 thread)
5365 gnus-sum-thread-tree-leaf-with-other
5366 gnus-sum-thread-tree-single-leaf)))))
eec82323
LMI
5367 (when (string= gnus-tmp-name "")
5368 (setq gnus-tmp-name gnus-tmp-from))
5369 (unless (numberp gnus-tmp-lines)
23f87bed
MB
5370 (setq gnus-tmp-lines -1))
5371 (if (= gnus-tmp-lines -1)
5372 (setq gnus-tmp-lines "?")
5373 (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
61b1af82
G
5374 (gnus-put-text-property
5375 (point)
5376 (progn (eval gnus-summary-line-format-spec) (point))
5377 'gnus-number number)
5378 (when gnus-visual-p
5379 (forward-line -1)
5380 (gnus-summary-highlight-line)
5381 (when gnus-summary-update-hook
5382 (gnus-run-hooks 'gnus-summary-update-hook))
5383 (forward-line 1))
5384
5385 (setq gnus-tmp-prev-subject simp-subject)))
eec82323
LMI
5386
5387 (when (nth 1 thread)
23f87bed
MB
5388 (push (list (max 0 gnus-tmp-level)
5389 (copy-sequence tree-stack)
5390 (nthcdr 1 thread))
5391 stack))
5392 (push (if (nth 1 thread) 1 0) tree-stack)
eec82323
LMI
5393 (incf gnus-tmp-level)
5394 (setq threads (if thread-end nil (cdar thread)))
23f87bed
MB
5395 (if gnus-summary-display-while-building
5396 (if building-count
5397 (progn
5398 ;; use a set frequency
5399 (setq building-line-count (1- building-line-count))
5400 (when (= building-line-count 0)
5401 (sit-for 0)
5402 (setq building-line-count
5403 gnus-summary-display-while-building)))
5404 ;; always
5405 (sit-for 0)))
eec82323
LMI
5406 (unless threads
5407 (setq gnus-tmp-level 0)))))
5408 (gnus-message 7 "Generating summary...done"))
5409
5410(defun gnus-summary-prepare-unthreaded (headers)
5411 "Generate an unthreaded summary buffer based on HEADERS."
5412 (let (header number mark)
5413
5414 (beginning-of-line)
5415
5416 (while headers
5417 ;; We may have to root out some bad articles...
5418 (when (memq (setq number (mail-header-number
5419 (setq header (pop headers))))
5420 gnus-newsgroup-limit)
5421 ;; Mark article as read when it has a low score.
5422 (when (and gnus-summary-mark-below
5423 (< (or (cdr (assq number gnus-newsgroup-scored))
5424 gnus-summary-default-score 0)
5425 gnus-summary-mark-below)
5426 (not (gnus-summary-article-ancient-p number)))
5427 (setq gnus-newsgroup-unreads
5428 (delq number gnus-newsgroup-unreads))
5429 (if gnus-newsgroup-auto-expire
5430 (push number gnus-newsgroup-expirable)
5431 (push (cons number gnus-low-score-mark)
5432 gnus-newsgroup-reads)))
5433
5434 (setq mark (gnus-article-mark number))
5435 (push (gnus-data-make number mark (1+ (point)) header 0)
5436 gnus-newsgroup-data)
5437 (gnus-summary-insert-line
5438 header 0 number
23f87bed 5439 (memq number gnus-newsgroup-undownloaded)
eec82323
LMI
5440 mark (memq number gnus-newsgroup-replied)
5441 (memq number gnus-newsgroup-expirable)
5442 (mail-header-subject header) nil
5443 (cdr (assq number gnus-newsgroup-scored))
5444 (memq number gnus-newsgroup-processable))))))
5445
16409b0b
GM
5446(defun gnus-summary-remove-list-identifiers ()
5447 "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
23f87bed
MB
5448 (let ((regexp (if (consp gnus-list-identifiers)
5449 (mapconcat 'identity gnus-list-identifiers " *\\|")
5450 gnus-list-identifiers))
5451 changed subject)
5452 (when regexp
01c52d31 5453 (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
23f87bed
MB
5454 (dolist (header gnus-newsgroup-headers)
5455 (setq subject (mail-header-subject header)
5456 changed nil)
01c52d31 5457 (while (string-match regexp subject)
23f87bed 5458 (setq subject
01c52d31 5459 (concat (substring subject 0 (match-beginning 1))
23f87bed
MB
5460 (substring subject (match-end 0)))
5461 changed t))
23f87bed 5462 (when changed
01c52d31
MB
5463 (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5464 (setq subject
5465 (concat (substring subject 0 (match-beginning 1))
5466 (substring subject (match-end 1)))))
23f87bed
MB
5467 (mail-header-set-subject header subject))))))
5468
5469(defun gnus-fetch-headers (articles)
5470 "Fetch headers of ARTICLES."
5471 (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5472 (gnus-message 5 "Fetching headers for %s..." name)
5473 (prog1
5474 (if (eq 'nov
5475 (setq gnus-headers-retrieved-by
5476 (gnus-retrieve-headers
5477 articles gnus-newsgroup-name
5478 ;; We might want to fetch old headers, but
5479 ;; not if there is only 1 article.
5480 (and (or (and
5481 (not (eq gnus-fetch-old-headers 'some))
5482 (not (numberp gnus-fetch-old-headers)))
5483 (> (length articles) 1))
5484 gnus-fetch-old-headers))))
5485 (gnus-get-newsgroup-headers-xover
5486 articles nil nil gnus-newsgroup-name t)
5487 (gnus-get-newsgroup-headers))
5488 (gnus-message 5 "Fetching headers for %s...done" name))))
16409b0b 5489
6748645f 5490(defun gnus-select-newsgroup (group &optional read-all select-articles)
eec82323 5491 "Select newsgroup GROUP.
6748645f
LMI
5492If READ-ALL is non-nil, all articles in the group are selected.
5493If SELECT-ARTICLES, only select those articles from GROUP."
01c52d31 5494 (let* ((entry (gnus-group-entry group))
eec82323
LMI
5495 ;;!!! Dirty hack; should be removed.
5496 (gnus-summary-ignore-duplicates
23f87bed 5497 (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
eec82323
LMI
5498 t
5499 gnus-summary-ignore-duplicates))
5500 (info (nth 2 entry))
01c52d31 5501 charset articles fetched-articles cached)
eec82323
LMI
5502
5503 (unless (gnus-check-server
475e0e0c
GM
5504 (set (make-local-variable 'gnus-current-select-method)
5505 (gnus-find-method-for-group group)))
eec82323 5506 (error "Couldn't open server"))
01c52d31 5507 (setq charset (gnus-group-name-charset gnus-current-select-method group))
eec82323
LMI
5508
5509 (or (and entry (not (eq (car entry) t))) ; Either it's active...
5510 (gnus-activate-group group) ; Or we can activate it...
5511 (progn ; Or we bug out.
5512 (when (equal major-mode 'gnus-summary-mode)
23f87bed 5513 (gnus-kill-buffer (current-buffer)))
01c52d31
MB
5514 (error
5515 "Couldn't activate group %s: %s"
5516 (mm-decode-coding-string group charset)
5517 (mm-decode-coding-string (gnus-status-message group) charset))))
eec82323
LMI
5518
5519 (unless (gnus-request-group group t)
20a673b2
KY
5520 (when (equal major-mode 'gnus-summary-mode)
5521 (gnus-kill-buffer (current-buffer)))
5522 (error "Couldn't request group %s: %s"
5523 (mm-decode-coding-string group charset)
5524 (mm-decode-coding-string (gnus-status-message group) charset)))
eec82323 5525
23f87bed 5526 (when gnus-agent
54506618 5527 (gnus-agent-possibly-alter-active group (gnus-active group) info)
132cf96d 5528
23f87bed
MB
5529 (setq gnus-summary-use-undownloaded-faces
5530 (gnus-agent-find-parameter
5531 group
5532 'agent-enable-undownloaded-faces)))
5533
5534 (setq gnus-newsgroup-name group
5535 gnus-newsgroup-unselected nil
5536 gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5537
5538 (let ((display (gnus-group-find-parameter group 'display)))
5539 (setq gnus-newsgroup-display
5540 (cond
5541 ((not (zerop (or (car-safe read-all) 0)))
5542 ;; The user entered the group with C-u SPC/RET, let's show
5543 ;; all articles.
5544 'gnus-not-ignore)
5545 ((eq display 'all)
5546 'gnus-not-ignore)
5547 ((arrayp display)
5548 (gnus-summary-display-make-predicate (mapcar 'identity display)))
5549 ((numberp display)
5550 ;; The following is probably the "correct" solution, but
5551 ;; it makes Gnus fetch all headers and then limit the
5552 ;; articles (which is slow), so instead we hack the
5553 ;; select-articles parameter instead. -- Simon Josefsson
5554 ;; <jas@kth.se>
5555 ;;
5556 ;; (gnus-byte-compile
5557 ;; `(lambda () (> number ,(- (cdr (gnus-active group))
5558 ;; display)))))
5559 (setq select-articles
5560 (gnus-uncompress-range
5561 (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5562 (if (> tmp 0)
5563 tmp
5564 1))
5565 (cdr (gnus-active group)))))
5566 nil)
5567 (t
5568 nil))))
eec82323 5569
23f87bed 5570 (gnus-summary-setup-default-charset)
eec82323
LMI
5571
5572 ;; Kludge to avoid having cached articles nixed out in virtual groups.
5573 (when (gnus-virtual-group-p group)
5574 (setq cached gnus-newsgroup-cached))
5575
5576 (setq gnus-newsgroup-unreads
23f87bed
MB
5577 (gnus-sorted-ndifference
5578 (gnus-sorted-ndifference gnus-newsgroup-unreads
5579 gnus-newsgroup-marked)
eec82323
LMI
5580 gnus-newsgroup-dormant))
5581
5582 (setq gnus-newsgroup-processable nil)
5583
5584 (gnus-update-read-articles group gnus-newsgroup-unreads)
eec82323 5585
23f87bed
MB
5586 ;; Adjust and set lists of article marks.
5587 (when info
5588 (gnus-adjust-marked-articles info))
6748645f
LMI
5589 (if (setq articles select-articles)
5590 (setq gnus-newsgroup-unselected
23f87bed 5591 (gnus-sorted-difference gnus-newsgroup-unreads articles))
6748645f 5592 (setq articles (gnus-articles-to-read group read-all)))
eec82323
LMI
5593
5594 (cond
5595 ((null articles)
5596 ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5597 'quit)
5598 ((eq articles 0) nil)
5599 (t
5600 ;; Init the dependencies hash table.
5601 (setq gnus-newsgroup-dependencies
5602 (gnus-make-hashtable (length articles)))
16409b0b 5603 (gnus-set-global-variables)
eec82323 5604 ;; Retrieve the headers and read them in.
23f87bed
MB
5605
5606 (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
eec82323
LMI
5607
5608 ;; Kludge to avoid having cached articles nixed out in virtual groups.
5609 (when cached
5610 (setq gnus-newsgroup-cached cached))
5611
5612 ;; Suppress duplicates?
5613 (when gnus-suppress-duplicates
5614 (gnus-dup-suppress-articles))
5615
5616 ;; Set the initial limit.
5617 (setq gnus-newsgroup-limit (copy-sequence articles))
5618 ;; Remove canceled articles from the list of unread articles.
23f87bed
MB
5619 (setq fetched-articles
5620 (mapcar (lambda (headers) (mail-header-number headers))
5621 gnus-newsgroup-headers))
5622 (setq gnus-newsgroup-articles fetched-articles)
eec82323 5623 (setq gnus-newsgroup-unreads
23f87bed
MB
5624 (gnus-sorted-nintersection
5625 gnus-newsgroup-unreads fetched-articles))
5626 (gnus-compute-unseen-list)
5627
eec82323
LMI
5628 ;; Removed marked articles that do not exist.
5629 (gnus-update-missing-marks
23f87bed 5630 (gnus-sorted-difference articles fetched-articles))
eec82323 5631 ;; We might want to build some more threads first.
6748645f
LMI
5632 (when (and gnus-fetch-old-headers
5633 (eq gnus-headers-retrieved-by 'nov))
5634 (if (eq gnus-fetch-old-headers 'invisible)
5635 (gnus-build-all-threads)
5636 (gnus-build-old-threads)))
5637 ;; Let the Gnus agent mark articles as read.
5638 (when gnus-agent
5639 (gnus-agent-get-undownloaded-list))
16409b0b
GM
5640 ;; Remove list identifiers from subject
5641 (when gnus-list-identifiers
5642 (gnus-summary-remove-list-identifiers))
eec82323
LMI
5643 ;; Check whether auto-expire is to be done in this group.
5644 (setq gnus-newsgroup-auto-expire
5645 (gnus-group-auto-expirable-p group))
5646 ;; Set up the article buffer now, if necessary.
01c52d31
MB
5647 (unless (and gnus-single-article-buffer
5648 (equal gnus-article-buffer "*Article*"))
eec82323
LMI
5649 (gnus-article-setup-buffer))
5650 ;; First and last article in this newsgroup.
5651 (when gnus-newsgroup-headers
5652 (setq gnus-newsgroup-begin
5653 (mail-header-number (car gnus-newsgroup-headers))
5654 gnus-newsgroup-end
5655 (mail-header-number
5656 (gnus-last-element gnus-newsgroup-headers))))
5657 ;; GROUP is successfully selected.
5658 (or gnus-newsgroup-headers t)))))
5659
23f87bed
MB
5660(defun gnus-compute-unseen-list ()
5661 ;; The `seen' marks are treated specially.
5662 (if (not gnus-newsgroup-seen)
5663 (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5664 (setq gnus-newsgroup-unseen
5665 (gnus-inverse-list-range-intersection
5666 gnus-newsgroup-articles gnus-newsgroup-seen))))
5667
d09ae6ca
GM
5668(declare-function gnus-get-predicate "gnus-agent" (predicate))
5669
23f87bed
MB
5670(defun gnus-summary-display-make-predicate (display)
5671 (require 'gnus-agent)
5672 (when (= (length display) 1)
5673 (setq display (car display)))
5674 (unless gnus-summary-display-cache
5675 (dolist (elem (append '((unread . unread)
5676 (read . read)
5677 (unseen . unseen))
5678 gnus-article-mark-lists))
5679 (push (cons (cdr elem)
5680 (gnus-byte-compile
5681 `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5682 gnus-summary-display-cache)))
5683 (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5684 (gnus-category-predicate-cache gnus-summary-display-cache))
5685 (gnus-get-predicate display)))
5686
5687;; Uses the dynamically bound `number' variable.
9efa445f 5688(defvar number)
23f87bed
MB
5689(defun gnus-article-marked-p (type &optional article)
5690 (let ((article (or article number)))
5691 (cond
5692 ((eq type 'tick)
5693 (memq article gnus-newsgroup-marked))
5694 ((eq type 'spam)
5695 (memq article gnus-newsgroup-spam-marked))
5696 ((eq type 'unsend)
5697 (memq article gnus-newsgroup-unsendable))
5698 ((eq type 'undownload)
5699 (memq article gnus-newsgroup-undownloaded))
5700 ((eq type 'download)
5701 (memq article gnus-newsgroup-downloadable))
5702 ((eq type 'unread)
5703 (memq article gnus-newsgroup-unreads))
5704 ((eq type 'read)
5705 (memq article gnus-newsgroup-reads))
5706 ((eq type 'dormant)
5707 (memq article gnus-newsgroup-dormant) )
5708 ((eq type 'expire)
5709 (memq article gnus-newsgroup-expirable))
5710 ((eq type 'reply)
5711 (memq article gnus-newsgroup-replied))
5712 ((eq type 'killed)
5713 (memq article gnus-newsgroup-killed))
5714 ((eq type 'bookmark)
5715 (assq article gnus-newsgroup-bookmarks))
5716 ((eq type 'score)
5717 (assq article gnus-newsgroup-scored))
5718 ((eq type 'save)
5719 (memq article gnus-newsgroup-saved))
5720 ((eq type 'cache)
5721 (memq article gnus-newsgroup-cached))
5722 ((eq type 'forward)
5723 (memq article gnus-newsgroup-forwarded))
5724 ((eq type 'seen)
5725 (not (memq article gnus-newsgroup-unseen)))
5726 ((eq type 'recent)
5727 (memq article gnus-newsgroup-recent))
5728 (t t))))
5729
eec82323 5730(defun gnus-articles-to-read (group &optional read-all)
16409b0b 5731 "Find out what articles the user wants to read."
26c9afc3 5732 (let* ((articles
eec82323
LMI
5733 ;; Select all articles if `read-all' is non-nil, or if there
5734 ;; are no unread articles.
5735 (if (or read-all
5736 (and (zerop (length gnus-newsgroup-marked))
5737 (zerop (length gnus-newsgroup-unreads)))
23f87bed
MB
5738 ;; Fetch all if the predicate is non-nil.
5739 gnus-newsgroup-display)
5740 ;; We want to select the headers for all the articles in
5741 ;; the group, so we select either all the active
5742 ;; articles in the group, or (if that's nil), the
5743 ;; articles in the cache.
16409b0b 5744 (or
4b70e299 5745 (if gnus-newsgroup-maximum-articles
11abff8e
MB
5746 (let ((active (gnus-active group)))
5747 (gnus-uncompress-range
5748 (cons (max (car active)
4b70e299
MB
5749 (- (cdr active)
5750 gnus-newsgroup-maximum-articles
5751 -1))
11abff8e
MB
5752 (cdr active))))
5753 (gnus-uncompress-range (gnus-active group)))
16409b0b 5754 (gnus-cache-articles-in-group group))
23f87bed
MB
5755 ;; Select only the "normal" subset of articles.
5756 (gnus-sorted-nunion
5757 (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5758 gnus-newsgroup-unreads)))
eec82323
LMI
5759 (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5760 (scored (length scored-list))
5761 (number (length articles))
5762 (marked (+ (length gnus-newsgroup-marked)
5763 (length gnus-newsgroup-dormant)))
5764 (select
5765 (cond
5766 ((numberp read-all)
5767 read-all)
23f87bed
MB
5768 ((numberp gnus-newsgroup-display)
5769 gnus-newsgroup-display)
eec82323
LMI
5770 (t
5771 (condition-case ()
5772 (cond
5773 ((and (or (<= scored marked) (= scored number))
5774 (numberp gnus-large-newsgroup)
5775 (> number gnus-large-newsgroup))
23f87bed
MB
5776 (let* ((cursor-in-echo-area nil)
5777 (initial (gnus-parameter-large-newsgroup-initial
5778 gnus-newsgroup-name))
5779 (input
5780 (read-string
5781 (format
5782 "How many articles from %s (%s %d): "
01c52d31 5783 (gnus-group-decoded-name gnus-newsgroup-name)
23f87bed
MB
5784 (if initial "max" "default")
5785 number)
5786 (if initial
5787 (cons (number-to-string initial)
5788 0)))))
eec82323
LMI
5789 (if (string-match "^[ \t]*$" input) number input)))
5790 ((and (> scored marked) (< scored number)
5791 (> (- scored number) 20))
5792 (let ((input
5793 (read-string
5794 (format "%s %s (%d scored, %d total): "
5795 "How many articles from"
23f87bed
MB
5796 (gnus-group-decoded-name group)
5797 scored number))))
eec82323
LMI
5798 (if (string-match "^[ \t]*$" input)
5799 number input)))
5800 (t number))
d4dfaa19
DL
5801 (quit
5802 (message "Quit getting the articles to read")
5803 nil))))))
eec82323
LMI
5804 (setq select (if (stringp select) (string-to-number select) select))
5805 (if (or (null select) (zerop select))
5806 select
5807 (if (and (not (zerop scored)) (<= (abs select) scored))
5808 (progn
5809 (setq articles (sort scored-list '<))
5810 (setq number (length articles)))
5811 (setq articles (copy-sequence articles)))
5812
5813 (when (< (abs select) number)
5814 (if (< select 0)
5815 ;; Select the N oldest articles.
5816 (setcdr (nthcdr (1- (abs select)) articles) nil)
5817 ;; Select the N most recent articles.
5818 (setq articles (nthcdr (- number select) articles))))
5819 (setq gnus-newsgroup-unselected
23f87bed 5820 (gnus-sorted-difference gnus-newsgroup-unreads articles))
16409b0b 5821 (when gnus-alter-articles-to-read-function
23f87bed 5822 (setq articles
a1506d29 5823 (sort
16409b0b 5824 (funcall gnus-alter-articles-to-read-function
23f87bed 5825 gnus-newsgroup-name articles)
16409b0b 5826 '<)))
eec82323
LMI
5827 articles)))
5828
5829(defun gnus-killed-articles (killed articles)
5830 (let (out)
5831 (while articles
5832 (when (inline (gnus-member-of-range (car articles) killed))
5833 (push (car articles) out))
5834 (setq articles (cdr articles)))
5835 out))
5836
5837(defun gnus-uncompress-marks (marks)
5838 "Uncompress the mark ranges in MARKS."
5839 (let ((uncompressed '(score bookmark))
5840 out)
5841 (while marks
5842 (if (memq (caar marks) uncompressed)
5843 (push (car marks) out)
5844 (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5845 (setq marks (cdr marks)))
5846 out))
5847
23f87bed
MB
5848(defun gnus-article-mark-to-type (mark)
5849 "Return the type of MARK."
5850 (or (cadr (assq mark gnus-article-special-mark-lists))
5851 'list))
5852
5853(defun gnus-article-unpropagatable-p (mark)
5854 "Return whether MARK should be propagated to back end."
5855 (memq mark gnus-article-unpropagated-mark-lists))
5856
eec82323 5857(defun gnus-adjust-marked-articles (info)
16409b0b 5858 "Set all article lists and remove all marks that are no longer valid."
eec82323
LMI
5859 (let* ((marked-lists (gnus-info-marks info))
5860 (active (gnus-active (gnus-info-group info)))
5861 (min (car active))
5862 (max (cdr active))
5863 (types gnus-article-mark-lists)
54506618
MB
5864 marks var articles article mark mark-type
5865 bgn end)
0617bb00
LMI
5866 ;; Hack to avoid adjusting marks for imap.
5867 (when (eq (car (gnus-find-method-for-group (gnus-info-group info)))
5868 'nnimap)
5869 (setq min 1))
eec82323 5870
23f87bed
MB
5871 (dolist (marks marked-lists)
5872 (setq mark (car marks)
5873 mark-type (gnus-article-mark-to-type mark)
5874 var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
eec82323 5875
23f87bed
MB
5876 ;; We set the variable according to the type of the marks list,
5877 ;; and then adjust the marks to a subset of the active articles.
eec82323 5878 (cond
54506618 5879 ;; Adjust "simple" lists - compressed yet unsorted
23f87bed 5880 ((eq mark-type 'list)
54506618
MB
5881 ;; Simultaneously uncompress and clip to active range
5882 ;; See gnus-uncompress-range for a description of possible marks
5883 (let (l lh)
5884 (if (not (cadr marks))
5885 (set var nil)
5886 (setq articles (if (numberp (cddr marks))
5887 (list (cdr marks))
5888 (cdr marks))
5889 lh (cons nil nil)
5890 l lh)
5891
5892 (while (setq article (pop articles))
5893 (cond ((consp article)
5894 (setq bgn (max (car article) min)
5895 end (min (cdr article) max))
5896 (while (<= bgn end)
5897 (setq l (setcdr l (cons bgn nil))
5898 bgn (1+ bgn))))
5899 ((and (<= min article)
5900 (>= max article))
5901 (setq l (setcdr l (cons article nil))))))
5902 (set var (cdr lh)))))
eec82323 5903 ;; Adjust assocs.
23f87bed
MB
5904 ((eq mark-type 'tuple)
5905 (set var (setq articles (cdr marks)))
a8151ef7
LMI
5906 (when (not (listp (cdr (symbol-value var))))
5907 (set var (list (symbol-value var))))
5908 (when (not (listp (cdr articles)))
5909 (setq articles (list articles)))
eec82323
LMI
5910 (while articles
5911 (when (or (not (consp (setq article (pop articles))))
5912 (< (car article) min)
5913 (> (car article) max))
23f87bed
MB
5914 (set var (delq article (symbol-value var))))))
5915 ;; Adjust ranges (sloppily).
5916 ((eq mark-type 'range)
5917 (cond
5918 ((eq mark 'seen)
5919 ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5920 ;; It should be (seen (NUM1 . NUM2)).
5921 (when (numberp (cddr marks))
5922 (setcdr marks (list (cdr marks))))
5923 (setq articles (cdr marks))
5924 (while (and articles
5925 (or (and (consp (car articles))
5926 (> min (cdar articles)))
5927 (and (numberp (car articles))
5928 (> min (car articles)))))
5929 (pop articles))
5930 (set var articles))))))))
eec82323
LMI
5931
5932(defun gnus-update-missing-marks (missing)
6748645f 5933 "Go through the list of MISSING articles and remove them from the mark lists."
eec82323 5934 (when missing
23f87bed 5935 (let (var m)
eec82323 5936 ;; Go through all types.
23f87bed
MB
5937 (dolist (elem gnus-article-mark-lists)
5938 (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5939 (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5940 (when (symbol-value var)
5941 ;; This list has articles. So we delete all missing
5942 ;; articles from it.
5943 (setq m missing)
5944 (while m
5945 (set var (delq (pop m) (symbol-value var))))))))))
eec82323
LMI
5946
5947(defun gnus-update-marks ()
5948 "Enter the various lists of marked articles into the newsgroup info list."
5949 (let ((types gnus-article-mark-lists)
5950 (info (gnus-get-info gnus-newsgroup-name))
16409b0b 5951 type list newmarked symbol delta-marks)
eec82323 5952 (when info
16409b0b 5953 ;; Add all marks lists to the list of marks lists.
eec82323 5954 (while (setq type (pop types))
16409b0b
GM
5955 (setq list (symbol-value
5956 (setq symbol
23f87bed 5957 (intern (format "gnus-newsgroup-%s" (car type))))))
eec82323 5958
16409b0b 5959 (when list
eec82323
LMI
5960 ;; Get rid of the entries of the articles that have the
5961 ;; default score.
5962 (when (and (eq (cdr type) 'score)
5963 gnus-save-score
5964 list)
5965 (let* ((arts list)
5966 (prev (cons nil list))
5967 (all prev))
5968 (while arts
5969 (if (or (not (consp (car arts)))
5970 (= (cdar arts) gnus-summary-default-score))
5971 (setcdr prev (cdr arts))
5972 (setq prev arts))
5973 (setq arts (cdr arts)))
16409b0b
GM
5974 (setq list (cdr all)))))
5975
23f87bed
MB
5976 (when (eq (cdr type) 'seen)
5977 (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5978
5979 (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
16409b0b 5980 (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
a1506d29 5981
23f87bed
MB
5982 (when (and (gnus-check-backend-function
5983 'request-set-mark gnus-newsgroup-name)
5984 (not (gnus-article-unpropagatable-p (cdr type))))
5985 (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5986 (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5987 (add (gnus-remove-from-range
5988 (gnus-copy-sequence list) old)))
5989 (when add
5990 (push (list add 'add (list (cdr type))) delta-marks))
5991 (when del
b069e5a6
G
5992 ;; Don't delete marks from outside the active range. This
5993 ;; shouldn't happen, but is a sanity check.
5994 (setq del (gnus-sorted-range-intersection
5995 (gnus-active gnus-newsgroup-name) del))
23f87bed 5996 (push (list del 'del (list (cdr type))) delta-marks))))
a1506d29 5997
16409b0b
GM
5998 (when list
5999 (push (cons (cdr type) list) newmarked)))
6000
6001 (when delta-marks
6002 (unless (gnus-check-group gnus-newsgroup-name)
6003 (error "Can't open server for %s" gnus-newsgroup-name))
6004 (gnus-request-set-mark gnus-newsgroup-name delta-marks))
a1506d29 6005
eec82323
LMI
6006 ;; Enter these new marks into the info of the group.
6007 (if (nthcdr 3 info)
6008 (setcar (nthcdr 3 info) newmarked)
6009 ;; Add the marks lists to the end of the info.
6010 (when newmarked
6011 (setcdr (nthcdr 2 info) (list newmarked))))
6012
6013 ;; Cut off the end of the info if there's nothing else there.
6014 (let ((i 5))
6015 (while (and (> i 2)
6016 (not (nth i info)))
6017 (when (nthcdr (decf i) info)
6018 (setcdr (nthcdr i info) nil)))))))
6019
6020(defun gnus-set-mode-line (where)
16409b0b 6021 "Set the mode line of the article or summary buffers.
eec82323
LMI
6022If WHERE is `summary', the summary mode line format will be used."
6023 ;; Is this mode line one we keep updated?
16409b0b
GM
6024 (when (and (memq where gnus-updated-mode-lines)
6025 (symbol-value
6026 (intern (format "gnus-%s-mode-line-format-spec" where))))
eec82323 6027 (let (mode-string)
c7a91ce1
SM
6028 ;; We evaluate this in the summary buffer since these
6029 ;; variables are buffer-local to that buffer.
6030 (with-current-buffer gnus-summary-buffer
6031 ;; We bind all these variables that are used in the `eval' form
eec82323
LMI
6032 ;; below.
6033 (let* ((mformat (symbol-value
6034 (intern
6035 (format "gnus-%s-mode-line-format-spec" where))))
b90a6149
MB
6036 (gnus-tmp-group-name (gnus-mode-string-quote
6037 (gnus-group-decoded-name
6038 gnus-newsgroup-name)))
eec82323
LMI
6039 (gnus-tmp-article-number (or gnus-current-article 0))
6040 (gnus-tmp-unread gnus-newsgroup-unreads)
6041 (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
6042 (gnus-tmp-unselected (length gnus-newsgroup-unselected))
6043 (gnus-tmp-unread-and-unselected
6044 (cond ((and (zerop gnus-tmp-unread-and-unticked)
6045 (zerop gnus-tmp-unselected))
6046 "")
6047 ((zerop gnus-tmp-unselected)
6048 (format "{%d more}" gnus-tmp-unread-and-unticked))
6049 (t (format "{%d(+%d) more}"
6050 gnus-tmp-unread-and-unticked
6051 gnus-tmp-unselected))))
6052 (gnus-tmp-subject
6053 (if (and gnus-current-headers
6054 (vectorp gnus-current-headers))
6055 (gnus-mode-string-quote
6056 (mail-header-subject gnus-current-headers))
6057 ""))
6058 bufname-length max-len
23f87bed 6059 gnus-tmp-header) ;; passed as argument to any user-format-funcs
eec82323
LMI
6060 (setq mode-string (eval mformat))
6061 (setq bufname-length (if (string-match "%b" mode-string)
6062 (- (length
6063 (buffer-name
6064 (if (eq where 'summary)
6065 nil
6066 (get-buffer gnus-article-buffer))))
6067 2)
6068 0))
6069 (setq max-len (max 4 (if gnus-mode-non-string-length
6070 (- (window-width)
6071 gnus-mode-non-string-length
6072 bufname-length)
6073 (length mode-string))))
6074 ;; We might have to chop a bit of the string off...
6075 (when (> (length mode-string) max-len)
6076 (setq mode-string
16409b0b 6077 (concat (truncate-string-to-width mode-string (- max-len 3))
29d31b55 6078 "...")))))
eec82323
LMI
6079 ;; Update the mode line.
6080 (setq mode-line-buffer-identification
6081 (gnus-mode-line-buffer-identification (list mode-string)))
6082 (set-buffer-modified-p t))))
6083
6084(defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
6085 "Go through the HEADERS list and add all Xrefs to a hash table.
6086The resulting hash table is returned, or nil if no Xrefs were found."
6087 (let* ((virtual (gnus-virtual-group-p from-newsgroup))
6088 (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
6089 (xref-hashtb (gnus-make-hashtable))
6090 start group entry number xrefs header)
6091 (while headers
6092 (setq header (pop headers))
6093 (when (and (setq xrefs (mail-header-xref header))
6094 (not (memq (setq number (mail-header-number header))
6095 unreads)))
6096 (setq start 0)
6097 (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6098 (setq start (match-end 0))
6099 (setq group (if prefix
6100 (concat prefix (substring xrefs (match-beginning 1)
6101 (match-end 1)))
6102 (substring xrefs (match-beginning 1) (match-end 1))))
6103 (setq number
e9bd5782 6104 (string-to-number (substring xrefs (match-beginning 2)
eec82323
LMI
6105 (match-end 2))))
6106 (if (setq entry (gnus-gethash group xref-hashtb))
6107 (setcdr entry (cons number (cdr entry)))
6108 (gnus-sethash group (cons number nil) xref-hashtb)))))
6109 (and start xref-hashtb)))
6110
6111(defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6112 "Look through all the headers and mark the Xrefs as read."
6113 (let ((virtual (gnus-virtual-group-p from-newsgroup))
01c52d31 6114 name info xref-hashtb idlist method nth4)
398a825b 6115 (with-current-buffer gnus-group-buffer
eec82323
LMI
6116 (when (setq xref-hashtb
6117 (gnus-create-xref-hashtb from-newsgroup headers unreads))
6118 (mapatoms
6119 (lambda (group)
6120 (unless (string= from-newsgroup (setq name (symbol-name group)))
6121 (setq idlist (symbol-value group))
6122 ;; Dead groups are not updated.
6123 (and (prog1
01c52d31 6124 (setq info (gnus-get-info name))
eec82323
LMI
6125 (when (stringp (setq nth4 (gnus-info-method info)))
6126 (setq nth4 (gnus-server-to-method nth4))))
6127 ;; Only do the xrefs if the group has the same
6128 ;; select method as the group we have just read.
6129 (or (gnus-methods-equal-p
6130 nth4 (gnus-find-method-for-group from-newsgroup))
6131 virtual
6132 (equal nth4 (setq method (gnus-find-method-for-group
6133 from-newsgroup)))
6134 (and (equal (car nth4) (car method))
6135 (equal (nth 1 nth4) (nth 1 method))))
6136 gnus-use-cross-reference
6137 (or (not (eq gnus-use-cross-reference t))
6138 virtual
6139 ;; Only do cross-references on subscribed
6140 ;; groups, if that is what is wanted.
6141 (<= (gnus-info-level info) gnus-level-subscribed))
6142 (gnus-group-make-articles-read name idlist))))
6143 xref-hashtb)))))
6144
6748645f 6145(defun gnus-compute-read-articles (group articles)
01c52d31 6146 (let* ((entry (gnus-group-entry group))
6748645f
LMI
6147 (info (nth 2 entry))
6148 (active (gnus-active group))
6149 ninfo)
6150 (when entry
16409b0b 6151 ;; First peel off all invalid article numbers.
6748645f
LMI
6152 (when active
6153 (let ((ids articles)
6154 id first)
6155 (while (setq id (pop ids))
6156 (when (and first (> id (cdr active)))
6157 ;; We'll end up in this situation in one particular
6158 ;; obscure situation. If you re-scan a group and get
6159 ;; a new article that is cross-posted to a different
6160 ;; group that has not been re-scanned, you might get
6161 ;; crossposted article that has a higher number than
6162 ;; Gnus believes possible. So we re-activate this
6163 ;; group as well. This might mean doing the
6164 ;; crossposting thingy will *increase* the number
6165 ;; of articles in some groups. Tsk, tsk.
6166 (setq active (or (gnus-activate-group group) active)))
6167 (when (or (> id (cdr active))
6168 (< id (car active)))
6169 (setq articles (delq id articles))))))
6170 ;; If the read list is nil, we init it.
6171 (if (and active
6172 (null (gnus-info-read info))
6173 (> (car active) 1))
6174 (setq ninfo (cons 1 (1- (car active))))
6175 (setq ninfo (gnus-info-read info)))
6176 ;; Then we add the read articles to the range.
6177 (gnus-add-to-range
6178 ninfo (setq articles (sort articles '<))))))
6179
eec82323
LMI
6180(defun gnus-group-make-articles-read (group articles)
6181 "Update the info of GROUP to say that ARTICLES are read."
6182 (let* ((num 0)
01c52d31 6183 (entry (gnus-group-entry group))
eec82323
LMI
6184 (info (nth 2 entry))
6185 (active (gnus-active group))
6186 range)
6748645f
LMI
6187 (when entry
6188 (setq range (gnus-compute-read-articles group articles))
01c52d31 6189 (with-current-buffer gnus-group-buffer
6748645f
LMI
6190 (gnus-undo-register
6191 `(progn
6192 (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6193 (gnus-info-set-read ',info ',(gnus-info-read info))
6194 (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
23f87bed 6195 (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6748645f
LMI
6196 (gnus-group-update-group ,group t))))
6197 ;; Add the read articles to the range.
6198 (gnus-info-set-read info range)
23f87bed 6199 (gnus-request-set-mark group (list (list range 'add '(read))))
6748645f
LMI
6200 ;; Then we have to re-compute how many unread
6201 ;; articles there are in this group.
6202 (when active
6203 (cond
6204 ((not range)
6205 (setq num (- (1+ (cdr active)) (car active))))
6206 ((not (listp (cdr range)))
6207 (setq num (- (cdr active) (- (1+ (cdr range))
6208 (car range)))))
6209 (t
6210 (while range
6211 (if (numberp (car range))
6212 (setq num (1+ num))
6213 (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6214 (setq range (cdr range)))
6215 (setq num (- (cdr active) num))))
6216 ;; Update the number of unread articles.
6217 (setcar entry num)
6218 ;; Update the group buffer.
23f87bed
MB
6219 (unless (gnus-ephemeral-group-p group)
6220 (gnus-group-update-group group t))))))
eec82323 6221
eec82323
LMI
6222(defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6223 (let ((cur nntp-server-buffer)
6224 (dependencies
6225 (or dependencies
01c52d31
MB
6226 (with-current-buffer gnus-summary-buffer
6227 gnus-newsgroup-dependencies)))
6228 headers id end ref number
16409b0b
GM
6229 (mail-parse-charset gnus-newsgroup-charset)
6230 (mail-parse-ignored-charsets
c7a91ce1
SM
6231 (save-current-buffer (condition-case nil
6232 (set-buffer gnus-summary-buffer)
6233 (error))
6234 gnus-newsgroup-ignored-charsets)))
6235 (with-current-buffer nntp-server-buffer
eec82323
LMI
6236 ;; Translate all TAB characters into SPACE characters.
6237 (subst-char-in-region (point-min) (point-max) ?\t ? t)
16409b0b 6238 (subst-char-in-region (point-min) (point-max) ?\r ? t)
23f87bed 6239 (ietf-drums-unfold-fws)
6748645f 6240 (gnus-run-hooks 'gnus-parse-headers-hook)
eec82323 6241 (let ((case-fold-search t)
6748645f 6242 in-reply-to header p lines chars)
eec82323 6243 (goto-char (point-min))
01ccbb85 6244 ;; Search to the beginning of the next header. Error messages
eec82323
LMI
6245 ;; do not begin with 2 or 3.
6246 (while (re-search-forward "^[23][0-9]+ " nil t)
6247 (setq id nil
6248 ref nil)
6249 ;; This implementation of this function, with nine
6250 ;; search-forwards instead of the one re-search-forward and
6251 ;; a case (which basically was the old function) is actually
01ccbb85 6252 ;; about twice as fast, even though it looks messier. You
eec82323
LMI
6253 ;; can't have everything, I guess. Speed and elegance
6254 ;; doesn't always go hand in hand.
6255 (setq
6256 header
6257 (vector
6258 ;; Number.
6259 (prog1
01c52d31 6260 (setq number (read cur))
eec82323
LMI
6261 (end-of-line)
6262 (setq p (point))
6263 (narrow-to-region (point)
6264 (or (and (search-forward "\n.\n" nil t)
6265 (- (point) 2))
6266 (point))))
6267 ;; Subject.
6268 (progn
6269 (goto-char p)
23f87bed 6270 (if (search-forward "\nsubject:" nil t)
16409b0b
GM
6271 (funcall gnus-decode-encoded-word-function
6272 (nnheader-header-value))
2bd3dcae 6273 "(none)"))
eec82323
LMI
6274 ;; From.
6275 (progn
6276 (goto-char p)
23f87bed 6277 (if (search-forward "\nfrom:" nil t)
343d6628 6278 (funcall gnus-decode-encoded-address-function
16409b0b 6279 (nnheader-header-value))
2bd3dcae 6280 "(nobody)"))
eec82323
LMI
6281 ;; Date.
6282 (progn
6283 (goto-char p)
23f87bed 6284 (if (search-forward "\ndate:" nil t)
eec82323
LMI
6285 (nnheader-header-value) ""))
6286 ;; Message-ID.
6287 (progn
6288 (goto-char p)
6748645f
LMI
6289 (setq id (if (re-search-forward
6290 "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6291 ;; We do it this way to make sure the Message-ID
6292 ;; is (somewhat) syntactically valid.
6293 (buffer-substring (match-beginning 1)
6294 (match-end 1))
eec82323
LMI
6295 ;; If there was no message-id, we just fake one
6296 ;; to make subsequent routines simpler.
01c52d31 6297 (nnheader-generate-fake-message-id number))))
eec82323
LMI
6298 ;; References.
6299 (progn
6300 (goto-char p)
23f87bed 6301 (if (search-forward "\nreferences:" nil t)
eec82323
LMI
6302 (progn
6303 (setq end (point))
6304 (prog1
6305 (nnheader-header-value)
6306 (setq ref
6307 (buffer-substring
6308 (progn
6309 (end-of-line)
6310 (search-backward ">" end t)
6311 (1+ (point)))
6312 (progn
6313 (search-backward "<" end t)
6314 (point))))))
6315 ;; Get the references from the in-reply-to header if there
6316 ;; were no references and the in-reply-to header looks
6317 ;; promising.
23f87bed 6318 (if (and (search-forward "\nin-reply-to:" nil t)
eec82323
LMI
6319 (setq in-reply-to (nnheader-header-value))
6320 (string-match "<[^>]+>" in-reply-to))
6748645f
LMI
6321 (let (ref2)
6322 (setq ref (substring in-reply-to (match-beginning 0)
6323 (match-end 0)))
6324 (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6325 (setq ref2 (substring in-reply-to (match-beginning 0)
6326 (match-end 0)))
6327 (when (> (length ref2) (length ref))
6328 (setq ref ref2)))
6329 ref)
eec82323
LMI
6330 (setq ref nil))))
6331 ;; Chars.
6748645f
LMI
6332 (progn
6333 (goto-char p)
6334 (if (search-forward "\nchars: " nil t)
6335 (if (numberp (setq chars (ignore-errors (read cur))))
23f87bed
MB
6336 chars -1)
6337 -1))
eec82323
LMI
6338 ;; Lines.
6339 (progn
6340 (goto-char p)
6341 (if (search-forward "\nlines: " nil t)
a8151ef7 6342 (if (numberp (setq lines (ignore-errors (read cur))))
23f87bed
MB
6343 lines -1)
6344 -1))
eec82323
LMI
6345 ;; Xref.
6346 (progn
6347 (goto-char p)
23f87bed 6348 (and (search-forward "\nxref:" nil t)
16409b0b
GM
6349 (nnheader-header-value)))
6350 ;; Extra.
6351 (when gnus-extra-headers
6352 (let ((extra gnus-extra-headers)
6353 out)
6354 (while extra
6355 (goto-char p)
6356 (when (search-forward
23f87bed 6357 (concat "\n" (symbol-name (car extra)) ":") nil t)
16409b0b
GM
6358 (push (cons (car extra) (nnheader-header-value))
6359 out))
6360 (pop extra))
6361 out))))
eec82323
LMI
6362 (when (equal id ref)
6363 (setq ref nil))
6748645f
LMI
6364
6365 (when gnus-alter-header-function
6366 (funcall gnus-alter-header-function header)
6367 (setq id (mail-header-id header)
6368 ref (gnus-parent-id (mail-header-references header))))
6369
6370 (when (setq header
6371 (gnus-dependencies-add-header
6372 header dependencies force-new))
eec82323
LMI
6373 (push header headers))
6374 (goto-char (point-max))
6375 (widen))
6376 (nreverse headers)))))
6377
eec82323
LMI
6378;; Goes through the xover lines and returns a list of vectors
6379(defun gnus-get-newsgroup-headers-xover (sequence &optional
6380 force-new dependencies
6381 group also-fetch-heads)
16409b0b
GM
6382 "Parse the news overview data in the server buffer.
6383Return a list of headers that match SEQUENCE (see
6384`nntp-retrieve-headers')."
eec82323
LMI
6385 ;; Get the Xref when the users reads the articles since most/some
6386 ;; NNTP servers do not include Xrefs when using XOVER.
6387 (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
16409b0b
GM
6388 (let ((mail-parse-charset gnus-newsgroup-charset)
6389 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6390 (cur nntp-server-buffer)
eec82323 6391 (dependencies (or dependencies gnus-newsgroup-dependencies))
23f87bed
MB
6392 (allp (cond
6393 ((eq gnus-read-all-available-headers t)
6394 t)
14e6dc54
MB
6395 ((and (stringp gnus-read-all-available-headers)
6396 group)
23f87bed
MB
6397 (string-match gnus-read-all-available-headers group))
6398 (t
6399 nil)))
eec82323 6400 number headers header)
c7a91ce1 6401 (with-current-buffer nntp-server-buffer
16409b0b 6402 (subst-char-in-region (point-min) (point-max) ?\r ? t)
eec82323 6403 ;; Allow the user to mangle the headers before parsing them.
6748645f 6404 (gnus-run-hooks 'gnus-parse-headers-hook)
eec82323 6405 (goto-char (point-min))
23f87bed
MB
6406 (gnus-parse-without-error
6407 (while (and (or sequence allp)
6408 (not (eobp)))
6409 (setq number (read cur))
6410 (when (not allp)
6411 (while (and sequence
6412 (< (car sequence) number))
6413 (setq sequence (cdr sequence))))
6414 (when (and (or allp
6415 (and sequence
6416 (eq number (car sequence))))
6417 (progn
6418 (setq sequence (cdr sequence))
6419 (setq header (inline
6420 (gnus-nov-parse-line
6421 number dependencies force-new)))))
6422 (push header headers))
6423 (forward-line 1)))
eec82323
LMI
6424 ;; A common bug in inn is that if you have posted an article and
6425 ;; then retrieves the active file, it will answer correctly --
6426 ;; the new article is included. However, a NOV entry for the
6427 ;; article may not have been generated yet, so this may fail.
6428 ;; We work around this problem by retrieving the last few
6429 ;; headers using HEAD.
6430 (if (or (not also-fetch-heads)
6431 (not sequence))
6432 ;; We (probably) got all the headers.
6433 (nreverse headers)
6434 (let ((gnus-nov-is-evil t))
6435 (nconc
6436 (nreverse headers)
23f87bed 6437 (when (eq (gnus-retrieve-headers sequence group) 'headers)
eec82323
LMI
6438 (gnus-get-newsgroup-headers))))))))
6439
6440(defun gnus-article-get-xrefs ()
6441 "Fill in the Xref value in `gnus-current-headers', if necessary.
6442This is meant to be called in `gnus-article-internal-prepare-hook'."
01c52d31
MB
6443 (let ((headers (with-current-buffer gnus-summary-buffer
6444 gnus-current-headers)))
eec82323
LMI
6445 (or (not gnus-use-cross-reference)
6446 (not headers)
6447 (and (mail-header-xref headers)
6448 (not (string= (mail-header-xref headers) "")))
6449 (let ((case-fold-search t)
6450 xref)
6451 (save-restriction
6452 (nnheader-narrow-to-headers)
6453 (goto-char (point-min))
16409b0b
GM
6454 (when (or (and (not (eobp))
6455 (eq (downcase (char-after)) ?x)
eec82323
LMI
6456 (looking-at "Xref:"))
6457 (search-forward "\nXref:" nil t))
6458 (goto-char (1+ (match-end 0)))
01c52d31 6459 (setq xref (buffer-substring (point) (point-at-eol)))
eec82323
LMI
6460 (mail-header-set-xref headers xref)))))))
6461
6462(defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6748645f
LMI
6463 "Find article ID and insert the summary line for that article.
6464OLD-HEADER can either be a header or a line number to insert
6465the subject line on."
6466 (let* ((line (and (numberp old-header) old-header))
6467 (old-header (and (vectorp old-header) old-header))
6468 (header (cond ((and old-header use-old-header)
16409b0b
GM
6469 old-header)
6470 ((and (numberp id)
6471 (gnus-number-to-header id))
6472 (gnus-number-to-header id))
6473 (t
6474 (gnus-read-header id))))
6475 (number (and (numberp id) id))
6476 d)
eec82323
LMI
6477 (when header
6478 ;; Rebuild the thread that this article is part of and go to the
6479 ;; article we have fetched.
6480 (when (and (not gnus-show-threads)
6481 old-header)
6748645f
LMI
6482 (when (and number
6483 (setq d (gnus-data-find (mail-header-number old-header))))
eec82323
LMI
6484 (goto-char (gnus-data-pos d))
6485 (gnus-data-remove
6486 number
01c52d31 6487 (- (point-at-bol)
eec82323 6488 (prog1
01c52d31 6489 (1+ (point-at-eol))
eec82323 6490 (gnus-delete-line))))))
23f87bed
MB
6491 ;; Remove list identifiers from subject.
6492 (when gnus-list-identifiers
6493 (let ((gnus-newsgroup-headers (list header)))
c3bc41c2 6494 (gnus-summary-remove-list-identifiers)))
eec82323
LMI
6495 (when old-header
6496 (mail-header-set-number header (mail-header-number old-header)))
6497 (setq gnus-newsgroup-sparse
6498 (delq (setq number (mail-header-number header))
6499 gnus-newsgroup-sparse))
6500 (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6748645f
LMI
6501 (push number gnus-newsgroup-limit)
6502 (gnus-rebuild-thread (mail-header-id header) line)
eec82323
LMI
6503 (gnus-summary-goto-subject number nil t))
6504 (when (and (numberp number)
6505 (> number 0))
6506 ;; We have to update the boundaries even if we can't fetch the
6507 ;; article if ID is a number -- so that the next `P' or `N'
6508 ;; command will fetch the previous (or next) article even
6509 ;; if the one we tried to fetch this time has been canceled.
6510 (when (> number gnus-newsgroup-end)
6511 (setq gnus-newsgroup-end number))
6512 (when (< number gnus-newsgroup-begin)
6513 (setq gnus-newsgroup-begin number))
6514 (setq gnus-newsgroup-unselected
6515 (delq number gnus-newsgroup-unselected)))
6516 ;; Report back a success?
6517 (and header (mail-header-number header))))
6518
6519;;; Process/prefix in the summary buffer
6520
6521(defun gnus-summary-work-articles (n)
6748645f
LMI
6522 "Return a list of articles to be worked upon.
6523The prefix argument, the list of process marked articles, and the
6524current article will be taken into consideration."
c7a91ce1 6525 (with-current-buffer gnus-summary-buffer
6748645f
LMI
6526 (cond
6527 (n
6528 ;; A numerical prefix has been given.
6529 (setq n (prefix-numeric-value n))
6530 (let ((backward (< n 0))
6531 (n (abs (prefix-numeric-value n)))
6532 articles article)
6533 (save-excursion
6534 (while
6535 (and (> n 0)
6536 (push (setq article (gnus-summary-article-number))
6537 articles)
6538 (if backward
6539 (gnus-summary-find-prev nil article)
6540 (gnus-summary-find-next nil article)))
6541 (decf n)))
6542 (nreverse articles)))
6543 ((and (gnus-region-active-p) (mark))
6544 (message "region active")
6545 ;; Work on the region between point and mark.
6546 (let ((max (max (point) (mark)))
6547 articles article)
6548 (save-excursion
7dafe00b 6549 (goto-char (min (point) (mark)))
6748645f
LMI
6550 (while
6551 (and
6552 (push (setq article (gnus-summary-article-number)) articles)
6553 (gnus-summary-find-next nil article)
6554 (< (point) max)))
6555 (nreverse articles))))
6556 (gnus-newsgroup-processable
6557 ;; There are process-marked articles present.
6558 ;; Save current state.
6559 (gnus-summary-save-process-mark)
6560 ;; Return the list.
6561 (reverse gnus-newsgroup-processable))
6562 (t
6563 ;; Just return the current article.
6564 (list (gnus-summary-article-number))))))
6565
6566(defmacro gnus-summary-iterate (arg &rest forms)
6567 "Iterate over the process/prefixed articles and do FORMS.
6568ARG is the interactive prefix given to the command. FORMS will be
6569executed with point over the summary line of the articles."
6570 (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6571 `(let ((,articles (gnus-summary-work-articles ,arg)))
6572 (while ,articles
6573 (gnus-summary-goto-subject (car ,articles))
16409b0b
GM
6574 ,@forms
6575 (pop ,articles)))))
6748645f
LMI
6576
6577(put 'gnus-summary-iterate 'lisp-indent-function 1)
6578(put 'gnus-summary-iterate 'edebug-form-spec '(form body))
eec82323
LMI
6579
6580(defun gnus-summary-save-process-mark ()
6581 "Push the current set of process marked articles on the stack."
6582 (interactive)
6583 (push (copy-sequence gnus-newsgroup-processable)
6584 gnus-newsgroup-process-stack))
6585
6586(defun gnus-summary-kill-process-mark ()
6587 "Push the current set of process marked articles on the stack and unmark."
6588 (interactive)
6589 (gnus-summary-save-process-mark)
6590 (gnus-summary-unmark-all-processable))
6591
6592(defun gnus-summary-yank-process-mark ()
6593 "Pop the last process mark state off the stack and restore it."
6594 (interactive)
6595 (unless gnus-newsgroup-process-stack
6596 (error "Empty mark stack"))
6597 (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6598
6599(defun gnus-summary-process-mark-set (set)
6600 "Make SET into the current process marked articles."
6601 (gnus-summary-unmark-all-processable)
01c52d31 6602 (mapc 'gnus-summary-set-process-mark set))
eec82323
LMI
6603
6604;;; Searching and stuff
6605
6606(defun gnus-summary-search-group (&optional backward use-level)
6607 "Search for next unread newsgroup.
6608If optional argument BACKWARD is non-nil, search backward instead."
c7a91ce1 6609 (with-current-buffer gnus-group-buffer
eec82323
LMI
6610 (when (gnus-group-search-forward
6611 backward nil (if use-level (gnus-group-group-level) nil))
6612 (gnus-group-group-name))))
6613
6614(defun gnus-summary-best-group (&optional exclude-group)
6615 "Find the name of the best unread group.
6616If EXCLUDE-GROUP, do not go to this group."
01c52d31 6617 (with-current-buffer gnus-group-buffer
eec82323
LMI
6618 (save-excursion
6619 (gnus-group-best-unread-group exclude-group))))
6620
23f87bed
MB
6621(defun gnus-summary-find-next (&optional unread article backward)
6622 (if backward
6623 (gnus-summary-find-prev unread article)
eec82323
LMI
6624 (let* ((dummy (gnus-summary-article-intangible-p))
6625 (article (or article (gnus-summary-article-number)))
23f87bed 6626 (data (gnus-data-find-list article))
eec82323
LMI
6627 result)
6628 (when (and (not dummy)
6629 (or (not gnus-summary-check-current)
6630 (not unread)
23f87bed
MB
6631 (not (gnus-data-unread-p (car data)))))
6632 (setq data (cdr data)))
eec82323
LMI
6633 (when (setq result
6634 (if unread
6635 (progn
23f87bed
MB
6636 (while data
6637 (unless (memq (gnus-data-number (car data))
6638 (cond
6639 ((eq gnus-auto-goto-ignores
6640 'always-undownloaded)
6641 gnus-newsgroup-undownloaded)
6642 (gnus-plugged
6643 nil)
6644 ((eq gnus-auto-goto-ignores
6645 'unfetched)
6646 gnus-newsgroup-unfetched)
6647 ((eq gnus-auto-goto-ignores
6648 'undownloaded)
6649 gnus-newsgroup-undownloaded)))
6650 (when (gnus-data-unread-p (car data))
6651 (setq result (car data)
6652 data nil)))
6653 (setq data (cdr data)))
eec82323 6654 result)
23f87bed 6655 (car data)))
eec82323
LMI
6656 (goto-char (gnus-data-pos result))
6657 (gnus-data-number result)))))
6658
6659(defun gnus-summary-find-prev (&optional unread article)
6660 (let* ((eobp (eobp))
6661 (article (or article (gnus-summary-article-number)))
23f87bed 6662 (data (gnus-data-find-list article (gnus-data-list 'rev)))
eec82323
LMI
6663 result)
6664 (when (and (not eobp)
6665 (or (not gnus-summary-check-current)
6666 (not unread)
23f87bed
MB
6667 (not (gnus-data-unread-p (car data)))))
6668 (setq data (cdr data)))
eec82323
LMI
6669 (when (setq result
6670 (if unread
6671 (progn
23f87bed
MB
6672 (while data
6673 (unless (memq (gnus-data-number (car data))
6674 (cond
6675 ((eq gnus-auto-goto-ignores
6676 'always-undownloaded)
6677 gnus-newsgroup-undownloaded)
6678 (gnus-plugged
6679 nil)
6680 ((eq gnus-auto-goto-ignores
6681 'unfetched)
6682 gnus-newsgroup-unfetched)
6683 ((eq gnus-auto-goto-ignores
6684 'undownloaded)
6685 gnus-newsgroup-undownloaded)))
6686 (when (gnus-data-unread-p (car data))
6687 (setq result (car data)
6688 data nil)))
6689 (setq data (cdr data)))
eec82323 6690 result)
23f87bed 6691 (car data)))
eec82323
LMI
6692 (goto-char (gnus-data-pos result))
6693 (gnus-data-number result))))
6694
6695(defun gnus-summary-find-subject (subject &optional unread backward article)
6696 (let* ((simp-subject (gnus-simplify-subject-fully subject))
6697 (article (or article (gnus-summary-article-number)))
6698 (articles (gnus-data-list backward))
6699 (arts (gnus-data-find-list article articles))
6700 result)
6701 (when (or (not gnus-summary-check-current)
6702 (not unread)
6703 (not (gnus-data-unread-p (car arts))))
6704 (setq arts (cdr arts)))
6705 (while arts
6706 (and (or (not unread)
6707 (gnus-data-unread-p (car arts)))
6708 (vectorp (gnus-data-header (car arts)))
6709 (gnus-subject-equal
6710 simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6711 (setq result (car arts)
6712 arts nil))
6713 (setq arts (cdr arts)))
6714 (and result
6715 (goto-char (gnus-data-pos result))
6716 (gnus-data-number result))))
6717
6718(defun gnus-summary-search-forward (&optional unread subject backward)
6719 "Search forward for an article.
6720If UNREAD, look for unread articles. If SUBJECT, look for
6721articles with that subject. If BACKWARD, search backward instead."
6722 (cond (subject (gnus-summary-find-subject subject unread backward))
6723 (backward (gnus-summary-find-prev unread))
6724 (t (gnus-summary-find-next unread))))
6725
6726(defun gnus-recenter (&optional n)
6727 "Center point in window and redisplay frame.
6728Also do horizontal recentering."
6729 (interactive "P")
6730 (when (and gnus-auto-center-summary
6731 (not (eq gnus-auto-center-summary 'vertical)))
6732 (gnus-horizontal-recenter))
5aa75bd8
JL
6733 (if (fboundp 'recenter-top-bottom)
6734 (recenter-top-bottom n)
6735 (recenter n)))
6736
6737(put 'gnus-recenter 'isearch-scroll t)
eec82323 6738
7b47345b
AS
6739(defun gnus-forward-line-ignore-invisible (n)
6740 "Move N lines forward (backward if N is negative).
6741Like forward-line, but skip over (and don't count) invisible lines."
6742 (let (done)
6743 (while (and (> n 0) (not done))
6744 ;; If the following character is currently invisible,
6745 ;; skip all characters with that same `invisible' property value.
770d9a1f
KY
6746 (while (gnus-invisible-p (point))
6747 (goto-char (gnus-next-char-property-change (point))))
7b47345b
AS
6748 (forward-line 1)
6749 (if (eobp)
6750 (setq done t)
6751 (setq n (1- n))))
6752 (while (and (< n 0) (not done))
6753 (forward-line -1)
6754 (if (bobp) (setq done t)
6755 (setq n (1+ n))
770d9a1f
KY
6756 (while (and (not (bobp)) (gnus-invisible-p (1- (point))))
6757 (goto-char (gnus-previous-char-property-change (point))))))))
6758
eec82323
LMI
6759(defun gnus-summary-recenter ()
6760 "Center point in the summary window.
6761If `gnus-auto-center-summary' is nil, or the article buffer isn't
6762displayed, no centering will be performed."
6763 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6764 ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
16409b0b 6765 (interactive)
23f87bed
MB
6766 ;; The user has to want it.
6767 (when gnus-auto-center-summary
6768 (let* ((top (cond ((< (window-height) 4) 0)
6769 ((< (window-height) 7) 1)
6770 (t (if (numberp gnus-auto-center-summary)
6771 gnus-auto-center-summary
01c52d31 6772 (/ (1- (window-height)) 2)))))
23f87bed 6773 (height (1- (window-height)))
7b47345b
AS
6774 (bottom (save-excursion
6775 (goto-char (point-max))
6776 (gnus-forward-line-ignore-invisible (- height))
6777 (point)))
23f87bed 6778 (window (get-buffer-window (current-buffer))))
eec82323
LMI
6779 (when (get-buffer-window gnus-article-buffer)
6780 ;; Only do recentering when the article buffer is displayed,
6781 ;; Set the window start to either `bottom', which is the biggest
6782 ;; possible valid number, or the second line from the top,
6783 ;; whichever is the least.
7b47345b
AS
6784 (let ((top-pos (save-excursion
6785 (gnus-forward-line-ignore-invisible (- top))
6786 (point))))
db7ebd73
MB
6787 (if (> bottom top-pos)
6788 ;; Keep the second line from the top visible
01c52d31 6789 (set-window-start window top-pos)
db7ebd73
MB
6790 ;; Try to keep the bottom line visible; if it's partially
6791 ;; obscured, either scroll one more line to make it fully
6792 ;; visible, or revert to using TOP-POS.
6793 (save-excursion
6794 (goto-char (point-max))
7b47345b 6795 (gnus-forward-line-ignore-invisible -1)
db7ebd73
MB
6796 (let ((last-line-start (point)))
6797 (goto-char bottom)
6798 (set-window-start window (point) t)
6799 (when (not (pos-visible-in-window-p last-line-start window))
7b47345b 6800 (gnus-forward-line-ignore-invisible 1)
db7ebd73 6801 (set-window-start window (min (point) top-pos) t)))))))
eec82323
LMI
6802 ;; Do horizontal recentering while we're at it.
6803 (when (and (get-buffer-window (current-buffer) t)
6804 (not (eq gnus-auto-center-summary 'vertical)))
6805 (let ((selected (selected-window)))
6806 (select-window (get-buffer-window (current-buffer) t))
6807 (gnus-summary-position-point)
6808 (gnus-horizontal-recenter)
6809 (select-window selected))))))
6810
6811(defun gnus-summary-jump-to-group (newsgroup)
6812 "Move point to NEWSGROUP in group mode buffer."
6813 ;; Keep update point of group mode buffer if visible.
6814 (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6815 (save-window-excursion
6816 ;; Take care of tree window mode.
6817 (when (get-buffer-window gnus-group-buffer)
6818 (pop-to-buffer gnus-group-buffer))
6819 (gnus-group-jump-to-group newsgroup))
6820 (save-excursion
6821 ;; Take care of tree window mode.
c7a91ce1 6822 (if (get-buffer-window gnus-group-buffer 0)
eec82323
LMI
6823 (pop-to-buffer gnus-group-buffer)
6824 (set-buffer gnus-group-buffer))
6825 (gnus-group-jump-to-group newsgroup))))
6826
6827;; This function returns a list of article numbers based on the
6828;; difference between the ranges of read articles in this group and
6829;; the range of active articles.
6830(defun gnus-list-of-unread-articles (group)
6831 (let* ((read (gnus-info-read (gnus-get-info group)))
6832 (active (or (gnus-active group) (gnus-activate-group group)))
01c52d31
MB
6833 (last (or (cdr active)
6834 (error "Group %s couldn't be activated " group)))
4b70e299
MB
6835 (bottom (if gnus-newsgroup-maximum-articles
6836 (max (car active)
6837 (- last gnus-newsgroup-maximum-articles -1))
11abff8e 6838 (car active)))
eec82323
LMI
6839 first nlast unread)
6840 ;; If none are read, then all are unread.
6841 (if (not read)
11abff8e 6842 (setq first bottom)
eec82323
LMI
6843 ;; If the range of read articles is a single range, then the
6844 ;; first unread article is the article after the last read
6845 ;; article. Sounds logical, doesn't it?
16409b0b 6846 (if (and (not (listp (cdr read)))
11abff8e 6847 (or (< (car read) bottom)
16409b0b
GM
6848 (progn (setq read (list read))
6849 nil)))
11abff8e 6850 (setq first (max bottom (1+ (cdr read))))
eec82323
LMI
6851 ;; `read' is a list of ranges.
6852 (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6853 (caar read)))
6854 1)
11abff8e 6855 (setq first bottom))
eec82323
LMI
6856 (while read
6857 (when first
6858 (while (< first nlast)
54506618
MB
6859 (setq unread (cons first unread)
6860 first (1+ first))))
eec82323
LMI
6861 (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6862 (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6863 (setq read (cdr read)))))
6864 ;; And add the last unread articles.
6865 (while (<= first last)
54506618
MB
6866 (setq unread (cons first unread)
6867 first (1+ first)))
eec82323 6868 ;; Return the list of unread articles.
6748645f 6869 (delq 0 (nreverse unread))))
eec82323
LMI
6870
6871(defun gnus-list-of-read-articles (group)
6872 "Return a list of unread, unticked and non-dormant articles."
6873 (let* ((info (gnus-get-info group))
6874 (marked (gnus-info-marks info))
6875 (active (gnus-active group)))
6876 (and info active
23f87bed
MB
6877 (gnus-list-range-difference
6878 (gnus-list-range-difference
6879 (gnus-sorted-complement
11abff8e 6880 (gnus-uncompress-range
4b70e299 6881 (if gnus-newsgroup-maximum-articles
11abff8e 6882 (cons (max (car active)
4b70e299
MB
6883 (- (cdr active)
6884 gnus-newsgroup-maximum-articles
6885 -1))
11abff8e
MB
6886 (cdr active))
6887 active))
23f87bed
MB
6888 (gnus-list-of-unread-articles group))
6889 (cdr (assq 'dormant marked)))
6890 (cdr (assq 'tick marked))))))
eec82323 6891
54506618
MB
6892;; This function returns a sequence of article numbers based on the
6893;; difference between the ranges of read articles in this group and
6894;; the range of active articles.
6895(defun gnus-sequence-of-unread-articles (group)
6896 (let* ((read (gnus-info-read (gnus-get-info group)))
6897 (active (or (gnus-active group) (gnus-activate-group group)))
6898 (last (cdr active))
4b70e299
MB
6899 (bottom (if gnus-newsgroup-maximum-articles
6900 (max (car active)
6901 (- last gnus-newsgroup-maximum-articles -1))
11abff8e 6902 (car active)))
54506618
MB
6903 first nlast unread)
6904 ;; If none are read, then all are unread.
6905 (if (not read)
11abff8e 6906 (setq first bottom)
54506618
MB
6907 ;; If the range of read articles is a single range, then the
6908 ;; first unread article is the article after the last read
6909 ;; article. Sounds logical, doesn't it?
6910 (if (and (not (listp (cdr read)))
11abff8e 6911 (or (< (car read) bottom)
54506618
MB
6912 (progn (setq read (list read))
6913 nil)))
11abff8e 6914 (setq first (max bottom (1+ (cdr read))))
54506618
MB
6915 ;; `read' is a list of ranges.
6916 (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6917 (caar read)))
6918 1)
11abff8e 6919 (setq first bottom))
54506618
MB
6920 (while read
6921 (when first
6922 (push (cons first nlast) unread))
6923 (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6924 (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6925 (setq read (cdr read)))))
6926 ;; And add the last unread articles.
ba0226dd
MB
6927 (cond ((not (and first last))
6928 nil)
6929 ((< first last)
6930 (push (cons first last) unread))
6931 ((= first last)
6932 (push first unread)))
54506618
MB
6933 ;; Return the sequence of unread articles.
6934 (delq 0 (nreverse unread))))
6935
eec82323
LMI
6936;; Various summary commands
6937
6748645f
LMI
6938(defun gnus-summary-select-article-buffer ()
6939 "Reconfigure windows to show article buffer."
6940 (interactive)
6941 (if (not (gnus-buffer-live-p gnus-article-buffer))
6942 (error "There is no article buffer for this summary buffer")
6943 (gnus-configure-windows 'article)
6944 (select-window (get-buffer-window gnus-article-buffer))))
6945
eec82323
LMI
6946(defun gnus-summary-universal-argument (arg)
6947 "Perform any operation on all articles that are process/prefixed."
6948 (interactive "P")
eec82323
LMI
6949 (let ((articles (gnus-summary-work-articles arg))
6950 func article)
6951 (if (eq
6952 (setq
6953 func
6954 (key-binding
6955 (read-key-sequence
6956 (substitute-command-keys
16409b0b 6957 "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
eec82323
LMI
6958 'undefined)
6959 (gnus-error 1 "Undefined key")
6960 (save-excursion
6961 (while articles
6962 (gnus-summary-goto-subject (setq article (pop articles)))
6963 (let (gnus-newsgroup-processable)
6964 (command-execute func))
6965 (gnus-summary-remove-process-mark article)))))
6966 (gnus-summary-position-point))
6967
6968(defun gnus-summary-toggle-truncation (&optional arg)
6969 "Toggle truncation of summary lines.
23f87bed 6970With ARG, turn line truncation on if ARG is positive."
eec82323
LMI
6971 (interactive "P")
6972 (setq truncate-lines
6973 (if (null arg) (not truncate-lines)
6974 (> (prefix-numeric-value arg) 0)))
6975 (redraw-display))
6976
23f87bed
MB
6977(defun gnus-summary-find-for-reselect ()
6978 "Return the number of an article to stay on across a reselect.
6979The current article is considered, then following articles, then previous
6980articles. An article is sought which is not cancelled and isn't a temporary
6981insertion from another group. If there's no such then return a dummy 0."
6982 (let (found)
6983 (dolist (rev '(nil t))
6984 (unless found ; don't demand the reverse list if we don't need it
6985 (let ((data (gnus-data-find-list
6986 (gnus-summary-article-number) (gnus-data-list rev))))
6987 (while (and data (not found))
6988 (if (and (< 0 (gnus-data-number (car data)))
6989 (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6990 (setq found (gnus-data-number (car data))))
6991 (setq data (cdr data))))))
6992 (or found 0)))
6993
eec82323
LMI
6994(defun gnus-summary-reselect-current-group (&optional all rescan)
6995 "Exit and then reselect the current newsgroup.
6996The prefix argument ALL means to select all articles."
6997 (interactive "P")
eec82323
LMI
6998 (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6999 (error "Ephemeral groups can't be reselected"))
23f87bed 7000 (let ((current-subject (gnus-summary-find-for-reselect))
eec82323
LMI
7001 (group gnus-newsgroup-name))
7002 (setq gnus-newsgroup-begin nil)
23f87bed 7003 (gnus-summary-exit nil 'leave-hidden)
eec82323
LMI
7004 ;; We have to adjust the point of group mode buffer because
7005 ;; point was moved to the next unread newsgroup by exiting.
7006 (gnus-summary-jump-to-group group)
7007 (when rescan
7008 (save-excursion
7009 (gnus-group-get-new-news-this-group 1)))
7010 (gnus-group-read-group all t)
7011 (gnus-summary-goto-subject current-subject nil t)))
7012
7013(defun gnus-summary-rescan-group (&optional all)
7014 "Exit the newsgroup, ask for new articles, and select the newsgroup."
7015 (interactive "P")
7016 (gnus-summary-reselect-current-group all t))
7017
7018(defun gnus-summary-update-info (&optional non-destructive)
7019 (save-excursion
7020 (let ((group gnus-newsgroup-name))
6748645f
LMI
7021 (when group
7022 (when gnus-newsgroup-kill-headers
7023 (setq gnus-newsgroup-killed
7024 (gnus-compress-sequence
23f87bed
MB
7025 (gnus-sorted-union
7026 (gnus-list-range-intersection
7027 gnus-newsgroup-unselected gnus-newsgroup-killed)
7028 gnus-newsgroup-unreads)
6748645f
LMI
7029 t)))
7030 (unless (listp (cdr gnus-newsgroup-killed))
7031 (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
7032 (let ((headers gnus-newsgroup-headers))
7033 ;; Set the new ranges of read articles.
01c52d31 7034 (with-current-buffer gnus-group-buffer
6748645f
LMI
7035 (gnus-undo-force-boundary))
7036 (gnus-update-read-articles
23f87bed
MB
7037 group (gnus-sorted-union
7038 gnus-newsgroup-unreads gnus-newsgroup-unselected))
6748645f
LMI
7039 ;; Set the current article marks.
7040 (let ((gnus-newsgroup-scored
7041 (if (and (not gnus-save-score)
7042 (not non-destructive))
7043 nil
7044 gnus-newsgroup-scored)))
7045 (save-excursion
7046 (gnus-update-marks)))
7047 ;; Do the cross-ref thing.
7048 (when gnus-use-cross-reference
7049 (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
7050 ;; Do not switch windows but change the buffer to work.
a8151ef7 7051 (set-buffer gnus-group-buffer)
6748645f
LMI
7052 (unless (gnus-ephemeral-group-p group)
7053 (gnus-group-update-group group)))))))
eec82323
LMI
7054
7055(defun gnus-summary-save-newsrc (&optional force)
7056 "Save the current number of read/marked articles in the dribble buffer.
7057The dribble buffer will then be saved.
7058If FORCE (the prefix), also save the .newsrc file(s)."
7059 (interactive "P")
7060 (gnus-summary-update-info t)
7061 (if force
7062 (gnus-save-newsrc-file)
7063 (gnus-dribble-save)))
7064
704f1663
GM
7065(declare-function gnus-cache-write-active "gnus-cache" (&optional force))
7066
23f87bed 7067(defun gnus-summary-exit (&optional temporary leave-hidden)
eec82323 7068 "Exit reading current newsgroup, and then return to group selection mode.
16409b0b 7069`gnus-exit-group-hook' is called with no arguments if that value is non-nil."
eec82323
LMI
7070 (interactive)
7071 (gnus-set-global-variables)
16409b0b 7072 (when (gnus-buffer-live-p gnus-article-buffer)
c7a91ce1 7073 (with-current-buffer gnus-article-buffer
16409b0b
GM
7074 (mm-destroy-parts gnus-article-mime-handles)
7075 ;; Set it to nil for safety reason.
7076 (setq gnus-article-mime-handle-alist nil)
7077 (setq gnus-article-mime-handles nil)))
eec82323 7078 (gnus-kill-save-kill-buffer)
6748645f 7079 (gnus-async-halt-prefetch)
eec82323
LMI
7080 (let* ((group gnus-newsgroup-name)
7081 (quit-config (gnus-group-quit-config gnus-newsgroup-name))
23f87bed 7082 (gnus-group-is-exiting-p t)
eec82323 7083 (mode major-mode)
23f87bed 7084 (group-point nil)
eec82323 7085 (buf (current-buffer)))
16409b0b
GM
7086 (unless quit-config
7087 ;; Do adaptive scoring, and possibly save score files.
7088 (when gnus-newsgroup-adaptive
7089 (gnus-score-adaptive))
7090 (when gnus-use-scoring
7091 (gnus-score-save)))
6748645f 7092 (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
eec82323
LMI
7093 ;; If we have several article buffers, we kill them at exit.
7094 (unless gnus-single-article-buffer
01c52d31
MB
7095 (when (gnus-buffer-live-p gnus-article-buffer)
7096 (with-current-buffer gnus-article-buffer
7097 ;; Don't kill sticky article buffers
7098 (unless (eq major-mode 'gnus-sticky-article-mode)
7099 (gnus-kill-buffer gnus-article-buffer)
7100 (setq gnus-article-current nil))))
7101 (gnus-kill-buffer gnus-original-article-buffer))
eec82323
LMI
7102 (when gnus-use-cache
7103 (gnus-cache-possibly-remove-articles)
7104 (gnus-cache-save-buffers))
7105 (gnus-async-prefetch-remove-group group)
7106 (when gnus-suppress-duplicates
7107 (gnus-dup-enter-articles))
7108 (when gnus-use-trees
7109 (gnus-tree-close group))
16409b0b
GM
7110 (when gnus-use-cache
7111 (gnus-cache-write-active))
6748645f
LMI
7112 ;; Remove entries for this group.
7113 (nnmail-purge-split-history (gnus-group-real-name group))
eec82323
LMI
7114 ;; Make all changes in this group permanent.
7115 (unless quit-config
6748645f 7116 (gnus-run-hooks 'gnus-exit-group-hook)
16409b0b 7117 (gnus-summary-update-info))
eec82323
LMI
7118 (gnus-close-group group)
7119 ;; Make sure where we were, and go to next newsgroup.
7120 (set-buffer gnus-group-buffer)
7121 (unless quit-config
7122 (gnus-group-jump-to-group group))
6748645f
LMI
7123 (gnus-run-hooks 'gnus-summary-exit-hook)
7124 (unless (or quit-config
01c52d31 7125 (not gnus-summary-next-group-on-exit)
6748645f
LMI
7126 ;; If this group has disappeared from the summary
7127 ;; buffer, don't skip forwards.
7128 (not (string= group (gnus-group-group-name))))
eec82323 7129 (gnus-group-next-unread-group 1))
a8151ef7 7130 (setq group-point (point))
eec82323
LMI
7131 (if temporary
7132 nil ;Nothing to do.
eec82323
LMI
7133 (set-buffer buf)
7134 (if (not gnus-kill-summary-on-exit)
23f87bed
MB
7135 (progn
7136 (gnus-deaden-summary)
7137 (setq mode nil))
eec82323
LMI
7138 ;; We set all buffer-local variables to nil. It is unclear why
7139 ;; this is needed, but if we don't, buffer-local variables are
7140 ;; not garbage-collected, it seems. This would the lead to en
7141 ;; ever-growing Emacs.
7142 (gnus-summary-clear-local-variables)
23f87bed
MB
7143 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7144 (gnus-summary-clear-local-variables))
eec82323
LMI
7145 (when (get-buffer gnus-article-buffer)
7146 (bury-buffer gnus-article-buffer))
eec82323
LMI
7147 ;; Return to group mode buffer.
7148 (when (eq mode 'gnus-summary-mode)
7149 (gnus-kill-buffer buf)))
7150 (setq gnus-current-select-method gnus-select-method)
d61c212b
SM
7151 (set-buffer gnus-group-buffer)
7152 (if quit-config
7153 (gnus-handle-ephemeral-exit quit-config)
4e90f2b9
SM
7154 (goto-char group-point)
7155 ;; If gnus-group-buffer is already displayed, make sure we also move
7156 ;; the cursor in the window that displays it.
7157 (let ((win (get-buffer-window (current-buffer) 0)))
7158 (if win (set-window-point win (point))))
d61c212b 7159 (unless leave-hidden
4e90f2b9 7160 (gnus-configure-windows 'group 'force)))
6748645f 7161 ;; Clear the current group name.
eec82323
LMI
7162 (unless quit-config
7163 (setq gnus-newsgroup-name nil)))))
7164
7165(defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7166(defun gnus-summary-exit-no-update (&optional no-questions)
7167 "Quit reading current newsgroup without updating read article info."
7168 (interactive)
eec82323 7169 (let* ((group gnus-newsgroup-name)
23f87bed
MB
7170 (gnus-group-is-exiting-p t)
7171 (gnus-group-is-exiting-without-update-p t)
eec82323
LMI
7172 (quit-config (gnus-group-quit-config group)))
7173 (when (or no-questions
7174 gnus-expert-user
7175 (gnus-y-or-n-p "Discard changes to this group and exit? "))
6748645f 7176 (gnus-async-halt-prefetch)
23f87bed 7177 (run-hooks 'gnus-summary-prepare-exit-hook)
16409b0b 7178 (when (gnus-buffer-live-p gnus-article-buffer)
c7a91ce1 7179 (with-current-buffer gnus-article-buffer
16409b0b
GM
7180 (mm-destroy-parts gnus-article-mime-handles)
7181 ;; Set it to nil for safety reason.
7182 (setq gnus-article-mime-handle-alist nil)
7183 (setq gnus-article-mime-handles nil)))
eec82323
LMI
7184 ;; If we have several article buffers, we kill them at exit.
7185 (unless gnus-single-article-buffer
7186 (gnus-kill-buffer gnus-article-buffer)
7187 (gnus-kill-buffer gnus-original-article-buffer)
7188 (setq gnus-article-current nil))
7189 (if (not gnus-kill-summary-on-exit)
7190 (gnus-deaden-summary)
7191 (gnus-close-group group)
7192 (gnus-summary-clear-local-variables)
23f87bed
MB
7193 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7194 (gnus-summary-clear-local-variables))
7195 (gnus-kill-buffer gnus-summary-buffer))
eec82323
LMI
7196 (unless gnus-single-article-buffer
7197 (setq gnus-article-current nil))
7198 (when gnus-use-trees
7199 (gnus-tree-close group))
7200 (gnus-async-prefetch-remove-group group)
7201 (when (get-buffer gnus-article-buffer)
7202 (bury-buffer gnus-article-buffer))
7203 ;; Return to the group buffer.
7204 (gnus-configure-windows 'group 'force)
7205 ;; Clear the current group name.
7206 (setq gnus-newsgroup-name nil)
23f87bed
MB
7207 (unless (gnus-ephemeral-group-p group)
7208 (gnus-group-update-group group))
eec82323
LMI
7209 (when (equal (gnus-group-group-name) group)
7210 (gnus-group-next-unread-group 1))
7211 (when quit-config
23f87bed 7212 (gnus-handle-ephemeral-exit quit-config)))))
eec82323
LMI
7213
7214(defun gnus-handle-ephemeral-exit (quit-config)
6748645f
LMI
7215 "Handle movement when leaving an ephemeral group.
7216The state which existed when entering the ephemeral is reset."
eec82323
LMI
7217 (if (not (buffer-name (car quit-config)))
7218 (gnus-configure-windows 'group 'force)
7219 (set-buffer (car quit-config))
7220 (cond ((eq major-mode 'gnus-summary-mode)
23f87bed
MB
7221 (gnus-set-global-variables))
7222 ((eq major-mode 'gnus-article-mode)
c7a91ce1 7223 (save-current-buffer
23f87bed
MB
7224 ;; The `gnus-summary-buffer' variable may point
7225 ;; to the old summary buffer when using a single
7226 ;; article buffer.
7227 (unless (gnus-buffer-live-p gnus-summary-buffer)
7228 (set-buffer gnus-group-buffer))
7229 (set-buffer gnus-summary-buffer)
7230 (gnus-set-global-variables))))
eec82323 7231 (if (or (eq (cdr quit-config) 'article)
23f87bed 7232 (eq (cdr quit-config) 'pick))
01c52d31
MB
7233 (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7234 (gnus-configure-windows 'pick 'force)
7235 (gnus-configure-windows (cdr quit-config) 'force))
eec82323
LMI
7236 (gnus-configure-windows (cdr quit-config) 'force))
7237 (when (eq major-mode 'gnus-summary-mode)
01c52d31
MB
7238 (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7239 next-unread-noselect))
7240 (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7241 'next-noselect)
7242 (gnus-summary-next-subject 1 nil t))
7243 ((eq gnus-auto-select-on-ephemeral-exit
7244 'next-unread-noselect)
7245 (gnus-summary-next-subject 1 t t))))
7246 ;; Hide the article buffer which displays the article different
7247 ;; from the one that the cursor points to in the summary buffer.
7248 (gnus-configure-windows 'summary 'force))
7249 (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7250 (gnus-summary-next-subject 1))
7251 ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7252 (gnus-summary-next-subject 1 t))))
eec82323
LMI
7253 (gnus-summary-recenter)
7254 (gnus-summary-position-point))))
7255
7256;;; Dead summaries.
7257
bbf52f1e
SM
7258(defvar gnus-dead-summary-mode-map
7259 (let ((map (make-keymap)))
7260 (suppress-keymap map)
7261 (substitute-key-definition 'undefined 'gnus-summary-wake-up-the-dead map)
7262 (dolist (key '("\C-d" "\r" "\177" [delete]))
7263 (define-key map key 'gnus-summary-wake-up-the-dead))
7264 (dolist (key '("q" "Q"))
7265 (define-key map key 'bury-buffer))
7266 map))
7267
7268(define-minor-mode gnus-dead-summary-mode
eec82323 7269 "Minor mode for Gnus summary buffers."
bbf52f1e
SM
7270 :lighter " Dead" :keymap gnus-dead-summary-mode-map
7271 (unless (derived-mode-p 'gnus-summary-mode)
7272 (setq gnus-dead-summary-mode nil)))
eec82323
LMI
7273
7274(defun gnus-deaden-summary ()
7275 "Make the current summary buffer into a dead summary buffer."
7276 ;; Kill any previous dead summary buffer.
7277 (when (and gnus-dead-summary
7278 (buffer-name gnus-dead-summary))
01c52d31 7279 (with-current-buffer gnus-dead-summary
eec82323
LMI
7280 (when gnus-dead-summary-mode
7281 (kill-buffer (current-buffer)))))
7282 ;; Make this the current dead summary.
7283 (setq gnus-dead-summary (current-buffer))
7284 (gnus-dead-summary-mode 1)
7285 (let ((name (buffer-name)))
7286 (when (string-match "Summary" name)
7287 (rename-buffer
7288 (concat (substring name 0 (match-beginning 0)) "Dead "
7289 (substring name (match-beginning 0)))
16409b0b
GM
7290 t)
7291 (bury-buffer))))
eec82323
LMI
7292
7293(defun gnus-kill-or-deaden-summary (buffer)
7294 "Kill or deaden the summary BUFFER."
6748645f
LMI
7295 (save-excursion
7296 (when (and (buffer-name buffer)
7297 (not gnus-single-article-buffer))
01c52d31 7298 (with-current-buffer buffer
6748645f
LMI
7299 (gnus-kill-buffer gnus-article-buffer)
7300 (gnus-kill-buffer gnus-original-article-buffer)))
23f87bed
MB
7301 (cond
7302 ;; Kill the buffer.
7303 (gnus-kill-summary-on-exit
7304 (when (and gnus-use-trees
7305 (gnus-buffer-exists-p buffer))
c7a91ce1 7306 (with-current-buffer buffer
23f87bed
MB
7307 (gnus-tree-close gnus-newsgroup-name)))
7308 (gnus-kill-buffer buffer))
7309 ;; Deaden the buffer.
7310 ((gnus-buffer-exists-p buffer)
c7a91ce1 7311 (with-current-buffer buffer
23f87bed 7312 (gnus-deaden-summary))))))
eec82323
LMI
7313
7314(defun gnus-summary-wake-up-the-dead (&rest args)
7315 "Wake up the dead summary buffer."
7316 (interactive)
7317 (gnus-dead-summary-mode -1)
7318 (let ((name (buffer-name)))
7319 (when (string-match "Dead " name)
7320 (rename-buffer
7321 (concat (substring name 0 (match-beginning 0))
7322 (substring name (match-end 0)))
7323 t)))
7324 (gnus-message 3 "This dead summary is now alive again"))
7325
eec82323
LMI
7326;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7327(defun gnus-summary-describe-group (&optional force)
7328 "Describe the current newsgroup."
7329 (interactive "P")
7330 (gnus-group-describe-group force gnus-newsgroup-name))
7331
7332(defun gnus-summary-describe-briefly ()
7333 "Describe summary mode commands briefly."
7334 (interactive)
bdaa75c7 7335 (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")))
eec82323
LMI
7336
7337;; Walking around group mode buffer from summary mode.
7338
7339(defun gnus-summary-next-group (&optional no-article target-group backward)
7340 "Exit current newsgroup and then select next unread newsgroup.
7341If prefix argument NO-ARTICLE is non-nil, no article is selected
23f87bed 7342initially. If TARGET-GROUP, go to this group. If BACKWARD, go to
eec82323
LMI
7343previous group instead."
7344 (interactive "P")
eec82323
LMI
7345 ;; Stop pre-fetching.
7346 (gnus-async-halt-prefetch)
7347 (let ((current-group gnus-newsgroup-name)
7348 (current-buffer (current-buffer))
7349 entered)
7350 ;; First we semi-exit this group to update Xrefs and all variables.
7351 ;; We can't do a real exit, because the window conf must remain
7352 ;; the same in case the user is prompted for info, and we don't
7353 ;; want the window conf to change before that...
7354 (gnus-summary-exit t)
7355 (while (not entered)
7356 ;; Then we find what group we are supposed to enter.
7357 (set-buffer gnus-group-buffer)
7358 (gnus-group-jump-to-group current-group)
7359 (setq target-group
7360 (or target-group
7361 (if (eq gnus-keep-same-level 'best)
7362 (gnus-summary-best-group gnus-newsgroup-name)
7363 (gnus-summary-search-group backward gnus-keep-same-level))))
7364 (if (not target-group)
7365 ;; There are no further groups, so we return to the group
7366 ;; buffer.
7367 (progn
7368 (gnus-message 5 "Returning to the group buffer")
7369 (setq entered t)
7370 (when (gnus-buffer-live-p current-buffer)
7371 (set-buffer current-buffer)
7372 (gnus-summary-exit))
6748645f 7373 (gnus-run-hooks 'gnus-group-no-more-groups-hook))
eec82323
LMI
7374 ;; We try to enter the target group.
7375 (gnus-group-jump-to-group target-group)
7376 (let ((unreads (gnus-group-group-unread)))
7377 (if (and (or (eq t unreads)
7378 (and unreads (not (zerop unreads))))
23f87bed
MB
7379 (gnus-summary-read-group
7380 target-group nil no-article
7381 (and (buffer-name current-buffer) current-buffer)
7382 nil backward))
eec82323
LMI
7383 (setq entered t)
7384 (setq current-group target-group
7385 target-group nil)))))))
7386
7387(defun gnus-summary-prev-group (&optional no-article)
7388 "Exit current newsgroup and then select previous unread newsgroup.
7389If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7390 (interactive "P")
7391 (gnus-summary-next-group no-article nil t))
7392
7393;; Walking around summary lines.
7394
23f87bed
MB
7395(defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7396 "Go to the first subject satisfying any non-nil constraint.
7397If UNREAD is non-nil, the article should be unread.
7398If UNDOWNLOADED is non-nil, the article should be undownloaded.
20a673b2 7399If UNSEEN is non-nil, the article should be unseen as well as unread.
23f87bed 7400Returns the article selected or nil if there are no matching articles."
eec82323 7401 (interactive "P")
23f87bed
MB
7402 (cond
7403 ;; Empty summary.
7404 ((null gnus-newsgroup-data)
7405 (gnus-message 3 "No articles in the group")
7406 nil)
7407 ;; Pick the first article.
7408 ((not (or unread undownloaded unseen))
7409 (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7410 (gnus-data-number (car gnus-newsgroup-data)))
7411 ;; Find the first unread article.
7412 (t
7413 (let ((data gnus-newsgroup-data))
7414 (while (and data
7415 (let ((num (gnus-data-number (car data))))
7416 (or (memq num gnus-newsgroup-unfetched)
7417 (not (or (and unread
7418 (memq num gnus-newsgroup-unreads))
7419 (and undownloaded
7420 (memq num gnus-newsgroup-undownloaded))
7421 (and unseen
20a673b2
KY
7422 (memq num gnus-newsgroup-unseen)
7423 (memq num gnus-newsgroup-unreads)))))))
23f87bed
MB
7424 (setq data (cdr data)))
7425 (prog1
7426 (if data
7427 (progn
7428 (goto-char (gnus-data-pos (car data)))
7429 (gnus-data-number (car data)))
7430 (gnus-message 3 "No more%s articles"
7431 (let* ((r (when unread " unread"))
7432 (d (when undownloaded " undownloaded"))
7433 (s (when unseen " unseen"))
7434 (l (delq nil (list r d s))))
7435 (cond ((= 3 (length l))
7436 (concat r "," d ", or" s))
7437 ((= 2 (length l))
7438 (concat (car l) ", or" (cadr l)))
7439 ((= 1 (length l))
7440 (car l))
7441 (t
7442 ""))))
7443 nil
7444 )
7445 (gnus-summary-position-point))))))
eec82323
LMI
7446
7447(defun gnus-summary-next-subject (n &optional unread dont-display)
7448 "Go to next N'th summary line.
7449If N is negative, go to the previous N'th subject line.
7450If UNREAD is non-nil, only unread articles are selected.
7451The difference between N and the actual number of steps taken is
7452returned."
7453 (interactive "p")
7454 (let ((backward (< n 0))
7455 (n (abs n)))
7456 (while (and (> n 0)
7457 (if backward
7458 (gnus-summary-find-prev unread)
7459 (gnus-summary-find-next unread)))
16409b0b
GM
7460 (unless (zerop (setq n (1- n)))
7461 (gnus-summary-show-thread)))
eec82323
LMI
7462 (when (/= 0 n)
7463 (gnus-message 7 "No more%s articles"
7464 (if unread " unread" "")))
7465 (unless dont-display
7466 (gnus-summary-recenter)
7467 (gnus-summary-position-point))
7468 n))
7469
7470(defun gnus-summary-next-unread-subject (n)
7471 "Go to next N'th unread summary line."
7472 (interactive "p")
7473 (gnus-summary-next-subject n t))
7474
7475(defun gnus-summary-prev-subject (n &optional unread)
7476 "Go to previous N'th summary line.
7477If optional argument UNREAD is non-nil, only unread article is selected."
7478 (interactive "p")
7479 (gnus-summary-next-subject (- n) unread))
7480
7481(defun gnus-summary-prev-unread-subject (n)
7482 "Go to previous N'th unread summary line."
7483 (interactive "p")
7484 (gnus-summary-next-subject (- n) t))
7485
23f87bed
MB
7486(defun gnus-summary-goto-subjects (articles)
7487 "Insert the subject header for ARTICLES in the current buffer."
7488 (save-excursion
7489 (dolist (article articles)
7490 (gnus-summary-goto-subject article t)))
7491 (gnus-summary-limit (append articles gnus-newsgroup-limit))
7492 (gnus-summary-position-point))
132cf96d 7493
eec82323 7494(defun gnus-summary-goto-subject (article &optional force silent)
d55fe5bb 7495 "Go to the subject line of ARTICLE.
eec82323
LMI
7496If FORCE, also allow jumping to articles not currently shown."
7497 (interactive "nArticle number: ")
23f87bed
MB
7498 (unless (numberp article)
7499 (error "Article %s is not a number" article))
eec82323
LMI
7500 (let ((b (point))
7501 (data (gnus-data-find article)))
7502 ;; We read in the article if we have to.
7503 (and (not data)
7504 force
6748645f
LMI
7505 (gnus-summary-insert-subject
7506 article
7507 (if (or (numberp force) (vectorp force)) force)
7508 t)
eec82323
LMI
7509 (setq data (gnus-data-find article)))
7510 (goto-char b)
7511 (if (not data)
7512 (progn
7513 (unless silent
7514 (gnus-message 3 "Can't find article %d" article))
7515 nil)
23f87bed
MB
7516 (let ((pt (gnus-data-pos data)))
7517 (goto-char pt)
7518 (gnus-summary-set-article-display-arrow pt))
6748645f 7519 (gnus-summary-position-point)
eec82323
LMI
7520 article)))
7521
7522;; Walking around summary lines with displaying articles.
7523
7524(defun gnus-summary-expand-window (&optional arg)
7525 "Make the summary buffer take up the entire Emacs frame.
7526Given a prefix, will force an `article' buffer configuration."
7527 (interactive "P")
eec82323
LMI
7528 (if arg
7529 (gnus-configure-windows 'article 'force)
7530 (gnus-configure-windows 'summary 'force)))
7531
7532(defun gnus-summary-display-article (article &optional all-header)
7533 "Display ARTICLE in article buffer."
01c52d31
MB
7534 (unless (and (gnus-buffer-live-p gnus-article-buffer)
7535 (with-current-buffer gnus-article-buffer
7536 (eq major-mode 'gnus-article-mode)))
7537 (gnus-article-setup-buffer))
eec82323 7538 (gnus-set-global-variables)
01c52d31
MB
7539 (with-current-buffer gnus-article-buffer
7540 (setq gnus-article-charset gnus-newsgroup-charset)
7541 (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7542 (mm-enable-multibyte))
eec82323
LMI
7543 (if (null article)
7544 nil
7545 (prog1
7546 (if gnus-summary-display-article-function
7547 (funcall gnus-summary-display-article-function article all-header)
7548 (gnus-article-prepare article all-header))
6748645f 7549 (gnus-run-hooks 'gnus-select-article-hook)
eec82323
LMI
7550 (when (and gnus-current-article
7551 (not (zerop gnus-current-article)))
7552 (gnus-summary-goto-subject gnus-current-article))
7553 (gnus-summary-recenter)
7554 (when (and gnus-use-trees gnus-show-threads)
7555 (gnus-possibly-generate-tree article)
7556 (gnus-highlight-selected-tree article))
7557 ;; Successfully display article.
7558 (gnus-article-set-window-start
7559 (cdr (assq article gnus-newsgroup-bookmarks))))))
7560
7561(defun gnus-summary-select-article (&optional all-headers force pseudo article)
7562 "Select the current article.
7563If ALL-HEADERS is non-nil, show all header fields. If FORCE is
7564non-nil, the article will be re-fetched even if it already present in
7565the article buffer. If PSEUDO is non-nil, pseudo-articles will also
7566be displayed."
7567 ;; Make sure we are in the summary buffer to work around bbdb bug.
7568 (unless (eq major-mode 'gnus-summary-mode)
7569 (set-buffer gnus-summary-buffer))
7570 (let ((article (or article (gnus-summary-article-number)))
f0529b5b 7571 (all-headers (not (not all-headers))) ;Must be t or nil.
16409b0b 7572 gnus-summary-display-article-function)
eec82323
LMI
7573 (and (not pseudo)
7574 (gnus-summary-article-pseudo-p article)
a8151ef7 7575 (error "This is a pseudo-article"))
c7a91ce1 7576 (with-current-buffer gnus-summary-buffer
16409b0b
GM
7577 (if (or (and gnus-single-article-buffer
7578 (or (null gnus-current-article)
7579 (null gnus-article-current)
7580 (null (get-buffer gnus-article-buffer))
7581 (not (eq article (cdr gnus-article-current)))
7582 (not (equal (car gnus-article-current)
7583 gnus-newsgroup-name))))
7584 (and (not gnus-single-article-buffer)
7585 (or (null gnus-current-article)
7586 (not (eq gnus-current-article article))))
7587 force)
7588 ;; The requested article is different from the current article.
7589 (progn
16409b0b
GM
7590 (gnus-summary-display-article article all-headers)
7591 (when (gnus-buffer-live-p gnus-article-buffer)
23f87bed 7592 (with-current-buffer gnus-article-buffer
16409b0b 7593 (if (not gnus-article-decoded-p) ;; a local variable
87545352 7594 (mm-disable-multibyte))))
16409b0b
GM
7595 (gnus-article-set-window-start
7596 (cdr (assq article gnus-newsgroup-bookmarks)))
7597 article)
16409b0b 7598 'old))))
eec82323 7599
23f87bed
MB
7600(defun gnus-summary-force-verify-and-decrypt ()
7601 "Display buttons for signed/encrypted parts and verify/decrypt them."
7602 (interactive)
7603 (let ((mm-verify-option 'known)
7604 (mm-decrypt-option 'known)
7605 (gnus-article-emulate-mime t)
7606 (gnus-buttonized-mime-types (append (list "multipart/signed"
7607 "multipart/encrypted")
7608 gnus-buttonized-mime-types)))
7609 (gnus-summary-select-article nil 'force)))
7610
eec82323
LMI
7611(defun gnus-summary-set-current-mark (&optional current-mark)
7612 "Obsolete function."
7613 nil)
7614
7615(defun gnus-summary-next-article (&optional unread subject backward push)
7616 "Select the next article.
7617If UNREAD, only unread articles are selected.
7618If SUBJECT, only articles with SUBJECT are selected.
7619If BACKWARD, the previous article is selected instead of the next."
7620 (interactive "P")
11e95b02
MB
7621 ;; Make sure we are in the summary buffer.
7622 (unless (eq major-mode 'gnus-summary-mode)
7623 (set-buffer gnus-summary-buffer))
eec82323
LMI
7624 (cond
7625 ;; Is there such an article?
7626 ((and (gnus-summary-search-forward unread subject backward)
7627 (or (gnus-summary-display-article (gnus-summary-article-number))
7628 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7629 (gnus-summary-position-point))
7630 ;; If not, we try the first unread, if that is wanted.
7631 ((and subject
7632 gnus-auto-select-same
7633 (gnus-summary-first-unread-article))
7634 (gnus-summary-position-point)
7635 (gnus-message 6 "Wrapped"))
7636 ;; Try to get next/previous article not displayed in this group.
7637 ((and gnus-auto-extend-newsgroup
7638 (not unread) (not subject))
7639 (gnus-summary-goto-article
7640 (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6748645f 7641 nil (count-lines (point-min) (point))))
eec82323
LMI
7642 ;; Go to next/previous group.
7643 (t
7644 (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7645 (gnus-summary-jump-to-group gnus-newsgroup-name))
49e787c9
GM
7646 (let ((cmd (if (featurep 'xemacs)
7647 last-command-char
7648 last-command-event))
eec82323 7649 (point
01c52d31 7650 (with-current-buffer gnus-group-buffer
eec82323
LMI
7651 (point)))
7652 (group
7653 (if (eq gnus-keep-same-level 'best)
7654 (gnus-summary-best-group gnus-newsgroup-name)
7655 (gnus-summary-search-group backward gnus-keep-same-level))))
7656 ;; For some reason, the group window gets selected. We change
7657 ;; it back.
7658 (select-window (get-buffer-window (current-buffer)))
7659 ;; Select next unread newsgroup automagically.
7660 (cond
7661 ((or (not gnus-auto-select-next)
7662 (not cmd))
7663 (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7664 ((or (eq gnus-auto-select-next 'quietly)
7665 (and (eq gnus-auto-select-next 'slightly-quietly)
7666 push)
7667 (and (eq gnus-auto-select-next 'almost-quietly)
7668 (gnus-summary-last-article-p)))
7669 ;; Select quietly.
7670 (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7671 (gnus-summary-exit)
7672 (gnus-message 7 "No more%s articles (%s)..."
7673 (if unread " unread" "")
7674 (if group (concat "selecting " group)
7675 "exiting"))
7676 (gnus-summary-next-group nil group backward)))
7677 (t
7678 (when (gnus-key-press-event-p last-input-event)
7679 (gnus-summary-walk-group-buffer
7680 gnus-newsgroup-name cmd unread backward point))))))))
7681
7682(defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7683 (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7684 (?\C-p (gnus-group-prev-unread-group 1))))
7685 (cursor-in-echo-area t)
23f87bed 7686 keve key group ended prompt)
c7a91ce1 7687 (with-current-buffer gnus-group-buffer
eec82323
LMI
7688 (goto-char start)
7689 (setq group
7690 (if (eq gnus-keep-same-level 'best)
7691 (gnus-summary-best-group gnus-newsgroup-name)
7692 (gnus-summary-search-group backward gnus-keep-same-level))))
7693 (while (not ended)
23f87bed
MB
7694 (setq prompt
7695 (format
7696 "No more%s articles%s " (if unread " unread" "")
7697 (if (and group
7698 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7699 (format " (Type %s for %s [%s])"
91472578
MB
7700 (single-key-description cmd)
7701 (gnus-group-decoded-name group)
01c52d31 7702 (gnus-group-unread group))
23f87bed
MB
7703 (format " (Type %s to exit %s)"
7704 (single-key-description cmd)
91472578 7705 (gnus-group-decoded-name gnus-newsgroup-name)))))
eec82323 7706 ;; Confirm auto selection.
23f87bed
MB
7707 (setq key (car (setq keve (gnus-read-event-char prompt)))
7708 ended t)
eec82323
LMI
7709 (cond
7710 ((assq key keystrokes)
7711 (let ((obuf (current-buffer)))
7712 (switch-to-buffer gnus-group-buffer)
7713 (when group
7714 (gnus-group-jump-to-group group))
7715 (eval (cadr (assq key keystrokes)))
7716 (setq group (gnus-group-group-name))
7717 (switch-to-buffer obuf))
7718 (setq ended nil))
7719 ((equal key cmd)
7720 (if (or (not group)
7721 (gnus-ephemeral-group-p gnus-newsgroup-name))
7722 (gnus-summary-exit)
7723 (gnus-summary-next-group nil group backward)))
7724 (t
7725 (push (cdr keve) unread-command-events))))))
7726
7727(defun gnus-summary-next-unread-article ()
7728 "Select unread article after current one."
7729 (interactive)
7730 (gnus-summary-next-article
7731 (or (not (eq gnus-summary-goto-unread 'never))
7732 (gnus-summary-last-article-p (gnus-summary-article-number)))
7733 (and gnus-auto-select-same
7734 (gnus-summary-article-subject))))
7735
7736(defun gnus-summary-prev-article (&optional unread subject)
bbbe940b 7737 "Select the article before the current one.
eec82323
LMI
7738If UNREAD is non-nil, only unread articles are selected."
7739 (interactive "P")
7740 (gnus-summary-next-article unread subject t))
7741
7742(defun gnus-summary-prev-unread-article ()
7743 "Select unread article before current one."
7744 (interactive)
7745 (gnus-summary-prev-article
7746 (or (not (eq gnus-summary-goto-unread 'never))
7747 (gnus-summary-first-article-p (gnus-summary-article-number)))
7748 (and gnus-auto-select-same
7749 (gnus-summary-article-subject))))
7750
23f87bed 7751(defun gnus-summary-next-page (&optional lines circular stop)
eec82323
LMI
7752 "Show next page of the selected article.
7753If at the end of the current article, select the next article.
7754LINES says how many lines should be scrolled up.
7755
7756If CIRCULAR is non-nil, go to the start of the article instead of
7757selecting the next article when reaching the end of the current
23f87bed
MB
7758article.
7759
7760If STOP is non-nil, just stop when reaching the end of the message.
7761
7762Also see the variable `gnus-article-skip-boring'."
eec82323
LMI
7763 (interactive "P")
7764 (setq gnus-summary-buffer (current-buffer))
7765 (gnus-set-global-variables)
7766 (let ((article (gnus-summary-article-number))
7767 (article-window (get-buffer-window gnus-article-buffer t))
7768 endp)
6748645f
LMI
7769 ;; If the buffer is empty, we have no article.
7770 (unless article
7771 (error "No article to select"))
eec82323
LMI
7772 (gnus-configure-windows 'article)
7773 (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7774 (if (and (eq gnus-summary-goto-unread 'never)
7775 (not (gnus-summary-last-article-p article)))
7776 (gnus-summary-next-article)
7777 (gnus-summary-next-unread-article))
7778 (if (or (null gnus-current-article)
7779 (null gnus-article-current)
7780 (/= article (cdr gnus-article-current))
7781 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7782 ;; Selected subject is different from current article's.
7783 (gnus-summary-display-article article)
7784 (when article-window
7785 (gnus-eval-in-buffer-window gnus-article-buffer
23f87bed
MB
7786 (setq endp (or (gnus-article-next-page lines)
7787 (gnus-article-only-boring-p))))
eec82323 7788 (when endp
b1992461 7789 (cond ((or stop gnus-summary-stop-at-end-of-message)
23f87bed
MB
7790 (gnus-message 3 "End of message"))
7791 (circular
eec82323
LMI
7792 (gnus-summary-beginning-of-article))
7793 (lines
7794 (gnus-message 3 "End of message"))
7795 ((null lines)
7796 (if (and (eq gnus-summary-goto-unread 'never)
7797 (not (gnus-summary-last-article-p article)))
7798 (gnus-summary-next-article)
7799 (gnus-summary-next-unread-article))))))))
7800 (gnus-summary-recenter)
7801 (gnus-summary-position-point)))
7802
7803(defun gnus-summary-prev-page (&optional lines move)
7804 "Show previous page of selected article.
7805Argument LINES specifies lines to be scrolled down.
7806If MOVE, move to the previous unread article if point is at
7807the beginning of the buffer."
7808 (interactive "P")
eec82323
LMI
7809 (let ((article (gnus-summary-article-number))
7810 (article-window (get-buffer-window gnus-article-buffer t))
7811 endp)
7812 (gnus-configure-windows 'article)
7813 (if (or (null gnus-current-article)
7814 (null gnus-article-current)
7815 (/= article (cdr gnus-article-current))
7816 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7817 ;; Selected subject is different from current article's.
7818 (gnus-summary-display-article article)
7819 (gnus-summary-recenter)
7820 (when article-window
7821 (gnus-eval-in-buffer-window gnus-article-buffer
7822 (setq endp (gnus-article-prev-page lines)))
7823 (when (and move endp)
7824 (cond (lines
7825 (gnus-message 3 "Beginning of message"))
7826 ((null lines)
7827 (if (and (eq gnus-summary-goto-unread 'never)
7828 (not (gnus-summary-first-article-p article)))
7829 (gnus-summary-prev-article)
7830 (gnus-summary-prev-unread-article))))))))
7831 (gnus-summary-position-point))
7832
7833(defun gnus-summary-prev-page-or-article (&optional lines)
7834 "Show previous page of selected article.
7835Argument LINES specifies lines to be scrolled down.
7836If at the beginning of the article, go to the next article."
7837 (interactive "P")
7838 (gnus-summary-prev-page lines t))
7839
7840(defun gnus-summary-scroll-up (lines)
7841 "Scroll up (or down) one line current article.
7842Argument LINES specifies lines to be scrolled up (or down if negative)."
7843 (interactive "p")
eec82323
LMI
7844 (gnus-configure-windows 'article)
7845 (gnus-summary-show-thread)
7846 (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7847 (gnus-eval-in-buffer-window gnus-article-buffer
7848 (cond ((> lines 0)
7849 (when (gnus-article-next-page lines)
7850 (gnus-message 3 "End of message")))
7851 ((< lines 0)
7852 (gnus-article-prev-page (- lines))))))
7853 (gnus-summary-recenter)
7854 (gnus-summary-position-point))
7855
6748645f
LMI
7856(defun gnus-summary-scroll-down (lines)
7857 "Scroll down (or up) one line current article.
7858Argument LINES specifies lines to be scrolled down (or up if negative)."
7859 (interactive "p")
7860 (gnus-summary-scroll-up (- lines)))
7861
eec82323
LMI
7862(defun gnus-summary-next-same-subject ()
7863 "Select next article which has the same subject as current one."
7864 (interactive)
eec82323
LMI
7865 (gnus-summary-next-article nil (gnus-summary-article-subject)))
7866
7867(defun gnus-summary-prev-same-subject ()
7868 "Select previous article which has the same subject as current one."
7869 (interactive)
eec82323
LMI
7870 (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7871
7872(defun gnus-summary-next-unread-same-subject ()
7873 "Select next unread article which has the same subject as current one."
7874 (interactive)
eec82323
LMI
7875 (gnus-summary-next-article t (gnus-summary-article-subject)))
7876
7877(defun gnus-summary-prev-unread-same-subject ()
7878 "Select previous unread article which has the same subject as current one."
7879 (interactive)
eec82323
LMI
7880 (gnus-summary-prev-article t (gnus-summary-article-subject)))
7881
7882(defun gnus-summary-first-unread-article ()
7883 "Select the first unread article.
7884Return nil if there are no unread articles."
7885 (interactive)
eec82323
LMI
7886 (prog1
7887 (when (gnus-summary-first-subject t)
7888 (gnus-summary-show-thread)
7889 (gnus-summary-first-subject t)
7890 (gnus-summary-display-article (gnus-summary-article-number)))
7891 (gnus-summary-position-point)))
7892
16409b0b
GM
7893(defun gnus-summary-first-unread-subject ()
7894 "Place the point on the subject line of the first unread article.
7895Return nil if there are no unread articles."
7896 (interactive)
7897 (prog1
7898 (when (gnus-summary-first-subject t)
7899 (gnus-summary-show-thread)
7900 (gnus-summary-first-subject t))
7901 (gnus-summary-position-point)))
7902
23f87bed
MB
7903(defun gnus-summary-first-unseen-subject ()
7904 "Place the point on the subject line of the first unseen article.
7905Return nil if there are no unseen articles."
7906 (interactive)
7907 (prog1
7908 (when (gnus-summary-first-subject nil nil t)
7909 (gnus-summary-show-thread)
7910 (gnus-summary-first-subject nil nil t))
7911 (gnus-summary-position-point)))
7912
7913(defun gnus-summary-first-unseen-or-unread-subject ()
20a673b2
KY
7914 "Place the point on the subject line of the first unseen and unread article.
7915If all article have been seen, on the subject line of the first unread
23f87bed
MB
7916article."
7917 (interactive)
7918 (prog1
7919 (unless (when (gnus-summary-first-subject nil nil t)
7920 (gnus-summary-show-thread)
7921 (gnus-summary-first-subject nil nil t))
7922 (when (gnus-summary-first-subject t)
7923 (gnus-summary-show-thread)
7924 (gnus-summary-first-subject t)))
7925 (gnus-summary-position-point)))
7926
eec82323
LMI
7927(defun gnus-summary-first-article ()
7928 "Select the first article.
7929Return nil if there are no articles."
7930 (interactive)
eec82323
LMI
7931 (prog1
7932 (when (gnus-summary-first-subject)
16409b0b
GM
7933 (gnus-summary-show-thread)
7934 (gnus-summary-first-subject)
7935 (gnus-summary-display-article (gnus-summary-article-number)))
eec82323
LMI
7936 (gnus-summary-position-point)))
7937
23f87bed
MB
7938(defun gnus-summary-best-unread-article (&optional arg)
7939 "Select the unread article with the highest score.
7940If given a prefix argument, select the next unread article that has a
7941score higher than the default score."
7942 (interactive "P")
7943 (let ((article (if arg
7944 (gnus-summary-better-unread-subject)
7945 (gnus-summary-best-unread-subject))))
7946 (if article
7947 (gnus-summary-goto-article article)
7948 (error "No unread articles"))))
7949
7950(defun gnus-summary-best-unread-subject ()
7951 "Select the unread subject with the highest score."
eec82323 7952 (interactive)
eec82323
LMI
7953 (let ((best -1000000)
7954 (data gnus-newsgroup-data)
7955 article score)
7956 (while data
7957 (and (gnus-data-unread-p (car data))
7958 (> (setq score
7959 (gnus-summary-article-score (gnus-data-number (car data))))
7960 best)
7961 (setq best score
7962 article (gnus-data-number (car data))))
7963 (setq data (cdr data)))
23f87bed
MB
7964 (when article
7965 (gnus-summary-goto-subject article))
7966 (gnus-summary-position-point)
7967 article))
7968
7969(defun gnus-summary-better-unread-subject ()
7970 "Select the first unread subject that has a score over the default score."
7971 (interactive)
7972 (let ((data gnus-newsgroup-data)
7973 article score)
7974 (while (and (setq article (gnus-data-number (car data)))
7975 (or (gnus-data-read-p (car data))
7976 (not (> (gnus-summary-article-score article)
7977 gnus-summary-default-score))))
7978 (setq data (cdr data)))
7979 (when article
7980 (gnus-summary-goto-subject article))
7981 (gnus-summary-position-point)
7982 article))
eec82323
LMI
7983
7984(defun gnus-summary-last-subject ()
7985 "Go to the last displayed subject line in the group."
7986 (let ((article (gnus-data-number (car (gnus-data-list t)))))
7987 (when article
7988 (gnus-summary-goto-subject article))))
7989
7990(defun gnus-summary-goto-article (article &optional all-headers force)
6748645f
LMI
7991 "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7992If ALL-HEADERS is non-nil, no header lines are hidden.
7993If FORCE, go to the article even if it isn't displayed. If FORCE
7994is a number, it is the line the article is to be displayed on."
eec82323
LMI
7995 (interactive
7996 (list
6748645f
LMI
7997 (completing-read
7998 "Article number or Message-ID: "
7999 (mapcar (lambda (number) (list (int-to-string number)))
8000 gnus-newsgroup-limit))
eec82323
LMI
8001 current-prefix-arg
8002 t))
8003 (prog1
6748645f 8004 (if (and (stringp article)
23f87bed 8005 (string-match "@\\|%40" article))
6748645f
LMI
8006 (gnus-summary-refer-article article)
8007 (when (stringp article)
8008 (setq article (string-to-number article)))
8009 (if (gnus-summary-goto-subject article force)
8010 (gnus-summary-display-article article all-headers)
8011 (gnus-message 4 "Couldn't go to article %s" article) nil))
eec82323
LMI
8012 (gnus-summary-position-point)))
8013
8014(defun gnus-summary-goto-last-article ()
8015 "Go to the previously read article."
8016 (interactive)
8017 (prog1
8018 (when gnus-last-article
6748645f 8019 (gnus-summary-goto-article gnus-last-article nil t))
eec82323
LMI
8020 (gnus-summary-position-point)))
8021
8022(defun gnus-summary-pop-article (number)
8023 "Pop one article off the history and go to the previous.
8024NUMBER articles will be popped off."
8025 (interactive "p")
8026 (let (to)
8027 (setq gnus-newsgroup-history
8028 (cdr (setq to (nthcdr number gnus-newsgroup-history))))
8029 (if to
6748645f 8030 (gnus-summary-goto-article (car to) nil t)
eec82323
LMI
8031 (error "Article history empty")))
8032 (gnus-summary-position-point))
8033
8034;; Summary commands and functions for limiting the summary buffer.
8035
8036(defun gnus-summary-limit-to-articles (n)
8037 "Limit the summary buffer to the next N articles.
8038If not given a prefix, use the process marked articles instead."
8039 (interactive "P")
eec82323
LMI
8040 (prog1
8041 (let ((articles (gnus-summary-work-articles n)))
8042 (setq gnus-newsgroup-processable nil)
8043 (gnus-summary-limit articles))
8044 (gnus-summary-position-point)))
8045
8046(defun gnus-summary-pop-limit (&optional total)
8047 "Restore the previous limit.
8048If given a prefix, remove all limits."
8049 (interactive "P")
eec82323
LMI
8050 (when total
8051 (setq gnus-newsgroup-limits
8052 (list (mapcar (lambda (h) (mail-header-number h))
8053 gnus-newsgroup-headers))))
8054 (unless gnus-newsgroup-limits
8055 (error "No limit to pop"))
8056 (prog1
8057 (gnus-summary-limit nil 'pop)
8058 (gnus-summary-position-point)))
8059
47b63dfa
SZ
8060(defun gnus-summary-limit-to-subject (subject &optional header not-matching)
8061 "Limit the summary buffer to articles that have subjects that match a regexp.
8062If NOT-MATCHING, excluding articles that have subjects that match a regexp."
a1506d29 8063 (interactive
47b63dfa
SZ
8064 (list (read-string (if current-prefix-arg
8065 "Exclude subject (regexp): "
a1506d29 8066 "Limit to subject (regexp): "))
47b63dfa 8067 nil current-prefix-arg))
eec82323
LMI
8068 (unless header
8069 (setq header "subject"))
8070 (when (not (equal "" subject))
8071 (prog1
8072 (let ((articles (gnus-summary-find-matching
a1506d29 8073 (or header "subject") subject 'all nil nil
47b63dfa 8074 not-matching)))
eec82323
LMI
8075 (unless articles
8076 (error "Found no matches for \"%s\"" subject))
8077 (gnus-summary-limit articles))
8078 (gnus-summary-position-point))))
8079
ef6e0ec7 8080(defun gnus-summary-limit-to-author (from &optional not-matching)
47b63dfa
SZ
8081 "Limit the summary buffer to articles that have authors that match a regexp.
8082If NOT-MATCHING, excluding articles that have authors that match a regexp."
a1506d29 8083 (interactive
47b63dfa
SZ
8084 (list (read-string (if current-prefix-arg
8085 "Exclude author (regexp): "
a1506d29 8086 "Limit to author (regexp): "))
ef6e0ec7
SZ
8087 current-prefix-arg))
8088 (gnus-summary-limit-to-subject from "from" not-matching))
eec82323 8089
01c52d31
MB
8090(defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8091 "Limit the summary buffer to articles with the given RECIPIENT.
8092
8093If NOT-MATCHING, exclude RECIPIENT.
8094
8095To and Cc headers are checked. You need to include them in
8096`nnmail-extra-headers'."
8097 ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8098 (interactive
8099 (list (read-string (format "%s recipient (regexp): "
8100 (if current-prefix-arg "Exclude" "Limit to")))
8101 current-prefix-arg))
8102 (when (not (equal "" recipient))
8103 (prog1 (let* ((to
8104 (if (memq 'To nnmail-extra-headers)
8105 (gnus-summary-find-matching
8106 (cons 'extra 'To) recipient 'all nil nil
8107 not-matching)
8108 (gnus-message
8109 1 "`To' isn't present in `nnmail-extra-headers'")
8110 (sit-for 1)
8111 nil))
8112 (cc
8113 (if (memq 'Cc nnmail-extra-headers)
8114 (gnus-summary-find-matching
8115 (cons 'extra 'Cc) recipient 'all nil nil
8116 not-matching)
8117 (gnus-message
8118 1 "`Cc' isn't present in `nnmail-extra-headers'")
8119 (sit-for 1)
8120 nil))
8121 (articles
8122 (if not-matching
8123 ;; We need the numbers that are in both lists:
8124 (mapcar (lambda (a)
8125 (and (memq a to) a))
8126 cc)
8127 (nconc to cc))))
8128 (unless articles
8129 (error "Found no matches for \"%s\"" recipient))
8130 (gnus-summary-limit articles))
8131 (gnus-summary-position-point))))
8132
8133(defun gnus-summary-limit-to-address (address &optional not-matching)
8134 "Limit the summary buffer to articles with the given ADDRESS.
8135
8136If NOT-MATCHING, exclude ADDRESS.
8137
8138To, Cc and From headers are checked. You need to include `To' and `Cc'
8139in `nnmail-extra-headers'."
8140 (interactive
8141 (list (read-string (format "%s address (regexp): "
8142 (if current-prefix-arg "Exclude" "Limit to")))
8143 current-prefix-arg))
8144 (when (not (equal "" address))
8145 (prog1 (let* ((to
8146 (if (memq 'To nnmail-extra-headers)
8147 (gnus-summary-find-matching
8148 (cons 'extra 'To) address 'all nil nil
8149 not-matching)
8150 (gnus-message
8151 1 "`To' isn't present in `nnmail-extra-headers'")
8152 (sit-for 1)
8153 t))
8154 (cc
8155 (if (memq 'Cc nnmail-extra-headers)
8156 (gnus-summary-find-matching
8157 (cons 'extra 'Cc) address 'all nil nil
8158 not-matching)
8159 (gnus-message
8160 1 "`Cc' isn't present in `nnmail-extra-headers'")
8161 (sit-for 1)
8162 t))
8163 (from
8164 (gnus-summary-find-matching "from" address
8165 'all nil nil not-matching))
8166 (articles
8167 (if not-matching
8168 ;; We need the numbers that are in all lists:
8169 (if (eq cc t)
8170 (if (eq to t)
8171 from
8172 (mapcar (lambda (a) (car (memq a from))) to))
8173 (if (eq to t)
8174 (mapcar (lambda (a) (car (memq a from))) cc)
8175 (mapcar (lambda (a) (car (memq a from)))
8176 (mapcar (lambda (a) (car (memq a to)))
8177 cc))))
8178 (nconc (if (eq to t) nil to)
8179 (if (eq cc t) nil cc)
8180 from))))
8181 (unless articles
8182 (error "Found no matches for \"%s\"" address))
8183 (gnus-summary-limit articles))
8184 (gnus-summary-position-point))))
8185
8186(defun gnus-summary-limit-strange-charsets-predicate (header)
765d4319
KY
8187 (when (fboundp 'char-charset)
8188 (let ((string (concat (mail-header-subject header)
8189 (mail-header-from header)))
8190 charset found)
8191 (dotimes (i (1- (length string)))
8192 (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8193 (when (string-match "unicode\\|big\\|japanese" charset)
8194 (setq found t)))
8195 found)))
01c52d31
MB
8196
8197(defun gnus-summary-limit-to-predicate (predicate)
8198 "Limit to articles where PREDICATE returns non-nil.
8199PREDICATE will be called with the header structures of the
8200articles."
8201 (let ((articles nil)
8202 (case-fold-search t))
8203 (dolist (header gnus-newsgroup-headers)
8204 (when (funcall predicate header)
8205 (push (mail-header-number header) articles)))
8206 (gnus-summary-limit (nreverse articles))))
8207
eec82323
LMI
8208(defun gnus-summary-limit-to-age (age &optional younger-p)
8209 "Limit the summary buffer to articles that are older than (or equal) AGE days.
8210If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8211articles that are younger than AGE days."
16409b0b
GM
8212 (interactive
8213 (let ((younger current-prefix-arg)
8214 (days-got nil)
8215 days)
8216 (while (not days-got)
8217 (setq days (if younger
23f87bed
MB
8218 (read-string "Limit to articles younger than (in days, older when negative): ")
8219 (read-string
8220 "Limit to articles older than (in days, younger when negative): ")))
16409b0b
GM
8221 (when (> (length days) 0)
8222 (setq days (read days)))
8223 (if (numberp days)
23f87bed
MB
8224 (progn
8225 (setq days-got t)
01c52d31
MB
8226 (when (< days 0)
8227 (setq younger (not younger))
8228 (setq days (* days -1))))
16409b0b
GM
8229 (message "Please enter a number.")
8230 (sleep-for 1)))
8231 (list days younger)))
eec82323
LMI
8232 (prog1
8233 (let ((data gnus-newsgroup-data)
16409b0b 8234 (cutoff (days-to-time age))
eec82323
LMI
8235 articles d date is-younger)
8236 (while (setq d (pop data))
8237 (when (and (vectorp (gnus-data-header d))
8238 (setq date (mail-header-date (gnus-data-header d))))
16409b0b 8239 (setq is-younger (time-less-p
3d6e7a43 8240 (time-since (gnus-date-get-time date))
eec82323 8241 cutoff))
6748645f
LMI
8242 (when (if younger-p
8243 is-younger
8244 (not is-younger))
eec82323
LMI
8245 (push (gnus-data-number d) articles))))
8246 (gnus-summary-limit (nreverse articles)))
8247 (gnus-summary-position-point)))
8248
47b63dfa 8249(defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
16409b0b
GM
8250 "Limit the summary buffer to articles that match an 'extra' header."
8251 (interactive
8252 (let ((header
8253 (intern
23f87bed 8254 (gnus-completing-read-with-default
16409b0b 8255 (symbol-name (car gnus-extra-headers))
47b63dfa 8256 (if current-prefix-arg
81df110a
RF
8257 "Exclude extra header"
8258 "Limit extra header")
16409b0b
GM
8259 (mapcar (lambda (x)
8260 (cons (symbol-name x) x))
8261 gnus-extra-headers)
8262 nil
8263 t))))
8264 (list header
a1506d29 8265 (read-string (format "%s header %s (regexp): "
47b63dfa
SZ
8266 (if current-prefix-arg "Exclude" "Limit to")
8267 header))
8268 current-prefix-arg)))
16409b0b
GM
8269 (when (not (equal "" regexp))
8270 (prog1
8271 (let ((articles (gnus-summary-find-matching
a1506d29 8272 (cons 'extra header) regexp 'all nil nil
47b63dfa 8273 not-matching)))
16409b0b
GM
8274 (unless articles
8275 (error "Found no matches for \"%s\"" regexp))
8276 (gnus-summary-limit articles))
8277 (gnus-summary-position-point))))
8278
23f87bed
MB
8279(defun gnus-summary-limit-to-display-predicate ()
8280 "Limit the summary buffer to the predicated in the `display' group parameter."
8281 (interactive)
8282 (unless gnus-newsgroup-display
8283 (error "There is no `display' group parameter"))
8284 (let (articles)
8285 (dolist (number gnus-newsgroup-articles)
8286 (when (funcall gnus-newsgroup-display)
8287 (push number articles)))
8288 (gnus-summary-limit articles))
8289 (gnus-summary-position-point))
8290
eec82323
LMI
8291(defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8292(make-obsolete
265ac10b 8293 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread "Emacs 20.4")
eec82323
LMI
8294
8295(defun gnus-summary-limit-to-unread (&optional all)
8296 "Limit the summary buffer to articles that are not marked as read.
8297If ALL is non-nil, limit strictly to unread articles."
8298 (interactive "P")
8299 (if all
8300 (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8301 (gnus-summary-limit-to-marks
8302 ;; Concat all the marks that say that an article is read and have
8303 ;; those removed.
8304 (list gnus-del-mark gnus-read-mark gnus-ancient-mark
23f87bed 8305 gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
eec82323
LMI
8306 gnus-low-score-mark gnus-expirable-mark
8307 gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
c4d82de8 8308 gnus-duplicate-mark)
eec82323
LMI
8309 'reverse)))
8310
01c52d31
MB
8311(defun gnus-summary-limit-to-headers (match &optional reverse)
8312 "Limit the summary buffer to articles that have headers that match MATCH.
8313If REVERSE (the prefix), limit to articles that don't match."
8314 (interactive "sMatch headers (regexp): \nP")
8315 (gnus-summary-limit-to-bodies match reverse t))
8316
8317(defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8318 "Limit the summary buffer to articles that have bodies that match MATCH.
8319If REVERSE (the prefix), limit to articles that don't match."
8320 (interactive "sMatch body (regexp): \nP")
8321 (let ((articles nil)
8322 (gnus-select-article-hook nil) ;Disable hook.
8323 (gnus-article-prepare-hook nil)
8324 (gnus-use-article-prefetch nil)
8325 (gnus-keep-backlog nil)
8326 (gnus-break-pages nil)
8327 (gnus-summary-display-arrow nil)
8328 (gnus-updated-mode-lines nil)
8329 (gnus-auto-center-summary nil)
8330 (gnus-display-mime-function nil))
8331 (dolist (data gnus-newsgroup-data)
8332 (let (gnus-mark-article-hook)
8333 (gnus-summary-select-article t t nil (gnus-data-number data)))
398a825b 8334 (with-current-buffer gnus-article-buffer
01c52d31
MB
8335 (article-goto-body)
8336 (let* ((case-fold-search t)
8337 (found (if headersp
8338 (re-search-backward match nil t)
8339 (re-search-forward match nil t))))
8340 (when (or (and found
8341 (not reverse))
8342 (and (not found)
8343 reverse))
8344 (push (gnus-data-number data) articles)))))
8345 (if (not articles)
8346 (message "No messages matched")
8347 (gnus-summary-limit articles)))
8348 (gnus-summary-position-point))
8349
8350(defun gnus-summary-limit-to-singletons (&optional threadsp)
8351 "Limit the summary buffer to articles that aren't part on any thread.
8352If THREADSP (the prefix), limit to articles that are in threads."
8353 (interactive "P")
8354 (let ((articles nil)
8355 thread-articles
8356 threads)
8357 (dolist (thread gnus-newsgroup-threads)
8358 (if (stringp (car thread))
8359 (dolist (thread (cdr thread))
8360 (push thread threads))
8361 (push thread threads)))
8362 (dolist (thread threads)
8363 (setq thread-articles (gnus-articles-in-thread thread))
8364 (when (or (and threadsp
8365 (> (length thread-articles) 1))
8366 (and (not threadsp)
8367 (= (length thread-articles) 1)))
8368 (setq articles (nconc thread-articles articles))))
8369 (if (not articles)
8370 (message "No messages matched")
8371 (gnus-summary-limit articles))
8372 (gnus-summary-position-point)))
8373
8374(defun gnus-summary-limit-to-replied (&optional unreplied)
8375 "Limit the summary buffer to replied articles.
8376If UNREPLIED (the prefix), limit to unreplied articles."
8377 (interactive "P")
8378 (if unreplied
8379 (gnus-summary-limit
8380 (gnus-set-difference gnus-newsgroup-articles
8381 gnus-newsgroup-replied))
8382 (gnus-summary-limit gnus-newsgroup-replied))
8383 (gnus-summary-position-point))
8384
eec82323
LMI
8385(defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8386(make-obsolete 'gnus-summary-delete-marked-with
265ac10b 8387 'gnus-summary-limit-exclude-marks "Emacs 20.4")
eec82323
LMI
8388
8389(defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8390 "Exclude articles that are marked with MARKS (e.g. \"DK\").
8391If REVERSE, limit the summary buffer to articles that are marked
8392with MARKS. MARKS can either be a string of marks or a list of marks.
8393Returns how many articles were removed."
8394 (interactive "sMarks: ")
8395 (gnus-summary-limit-to-marks marks t))
8396
8397(defun gnus-summary-limit-to-marks (marks &optional reverse)
8398 "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8399If REVERSE (the prefix), limit the summary buffer to articles that are
8400not marked with MARKS. MARKS can either be a string of marks or a
8401list of marks.
8402Returns how many articles were removed."
6748645f 8403 (interactive "sMarks: \nP")
eec82323
LMI
8404 (prog1
8405 (let ((data gnus-newsgroup-data)
8406 (marks (if (listp marks) marks
8407 (append marks nil))) ; Transform to list.
8408 articles)
8409 (while data
8410 (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8411 (memq (gnus-data-mark (car data)) marks))
8412 (push (gnus-data-number (car data)) articles))
8413 (setq data (cdr data)))
8414 (gnus-summary-limit articles))
8415 (gnus-summary-position-point)))
8416
23f87bed 8417(defun gnus-summary-limit-to-score (score)
eec82323 8418 "Limit to articles with score at or above SCORE."
23f87bed 8419 (interactive "NLimit to articles with score of at least: ")
eec82323
LMI
8420 (let ((data gnus-newsgroup-data)
8421 articles)
8422 (while data
8423 (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8424 score)
8425 (push (gnus-data-number (car data)) articles))
8426 (setq data (cdr data)))
8427 (prog1
8428 (gnus-summary-limit articles)
8429 (gnus-summary-position-point))))
8430
23f87bed
MB
8431(defun gnus-summary-limit-to-unseen ()
8432 "Limit to unseen articles."
8433 (interactive)
8434 (prog1
8435 (gnus-summary-limit gnus-newsgroup-unseen)
8436 (gnus-summary-position-point)))
8437
6748645f 8438(defun gnus-summary-limit-include-thread (id)
23f87bed
MB
8439 "Display all the hidden articles that is in the thread with ID in it.
8440When called interactively, ID is the Message-ID of the current
8441article."
6748645f
LMI
8442 (interactive (list (mail-header-id (gnus-summary-article-header))))
8443 (let ((articles (gnus-articles-in-thread
8444 (gnus-id-to-thread (gnus-root-id id)))))
8445 (prog1
8446 (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
23f87bed
MB
8447 (gnus-summary-limit-include-matching-articles
8448 "subject"
8449 (regexp-quote (gnus-simplify-subject-re
8450 (mail-header-subject (gnus-id-to-header id)))))
6748645f
LMI
8451 (gnus-summary-position-point))))
8452
23f87bed
MB
8453(defun gnus-summary-limit-include-matching-articles (header regexp)
8454 "Display all the hidden articles that have HEADERs that match REGEXP."
8455 (interactive (list (read-string "Match on header: ")
8456 (read-string "Regexp: ")))
8457 (let ((articles (gnus-find-matching-articles header regexp)))
8458 (prog1
8459 (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8460 (gnus-summary-position-point))))
8461
8462(defun gnus-summary-insert-dormant-articles ()
8463 "Insert all the dormant articles for this group into the current buffer."
8464 (interactive)
8465 (let ((gnus-verbose (max 6 gnus-verbose)))
8466 (if (not gnus-newsgroup-dormant)
db629244 8467 (gnus-message 3 "No dormant articles for this group")
23f87bed
MB
8468 (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8469
01c52d31
MB
8470(defun gnus-summary-insert-ticked-articles ()
8471 "Insert ticked articles for this group into the current buffer."
8472 (interactive)
8473 (let ((gnus-verbose (max 6 gnus-verbose)))
8474 (if (not gnus-newsgroup-marked)
8475 (gnus-message 3 "No ticked articles for this group")
8476 (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8477
eec82323 8478(defun gnus-summary-limit-include-dormant ()
6748645f
LMI
8479 "Display all the hidden articles that are marked as dormant.
8480Note that this command only works on a subset of the articles currently
8481fetched for this group."
eec82323 8482 (interactive)
eec82323
LMI
8483 (unless gnus-newsgroup-dormant
8484 (error "There are no dormant articles in this group"))
8485 (prog1
8486 (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8487 (gnus-summary-position-point)))
8488
8489(defun gnus-summary-limit-exclude-dormant ()
8490 "Hide all dormant articles."
8491 (interactive)
eec82323
LMI
8492 (prog1
8493 (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8494 (gnus-summary-position-point)))
8495
8496(defun gnus-summary-limit-exclude-childless-dormant ()
8497 "Hide all dormant articles that have no children."
8498 (interactive)
eec82323
LMI
8499 (let ((data (gnus-data-list t))
8500 articles d children)
8501 ;; Find all articles that are either not dormant or have
8502 ;; children.
8503 (while (setq d (pop data))
8504 (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8505 (and (setq children
8506 (gnus-article-children (gnus-data-number d)))
8507 (let (found)
8508 (while children
8509 (when (memq (car children) articles)
8510 (setq children nil
8511 found t))
8512 (pop children))
8513 found)))
8514 (push (gnus-data-number d) articles)))
8515 ;; Do the limiting.
8516 (prog1
8517 (gnus-summary-limit articles)
8518 (gnus-summary-position-point))))
8519
8520(defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8521 "Mark all unread excluded articles as read.
8522If ALL, mark even excluded ticked and dormants as read."
8523 (interactive "P")
23f87bed
MB
8524 (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8525 (let ((articles (gnus-sorted-ndifference
eec82323
LMI
8526 (sort
8527 (mapcar (lambda (h) (mail-header-number h))
8528 gnus-newsgroup-headers)
8529 '<)
23f87bed 8530 gnus-newsgroup-limit))
eec82323 8531 article)
6748645f 8532 (setq gnus-newsgroup-unreads
23f87bed
MB
8533 (gnus-sorted-intersection gnus-newsgroup-unreads
8534 gnus-newsgroup-limit))
eec82323
LMI
8535 (if all
8536 (setq gnus-newsgroup-dormant nil
8537 gnus-newsgroup-marked nil
8538 gnus-newsgroup-reads
8539 (nconc
8540 (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8541 gnus-newsgroup-reads))
8542 (while (setq article (pop articles))
8543 (unless (or (memq article gnus-newsgroup-dormant)
8544 (memq article gnus-newsgroup-marked))
8545 (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8546
8547(defun gnus-summary-limit (articles &optional pop)
8548 (if pop
8549 ;; We pop the previous limit off the stack and use that.
8550 (setq articles (car gnus-newsgroup-limits)
8551 gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8552 ;; We use the new limit, so we push the old limit on the stack.
8553 (push gnus-newsgroup-limit gnus-newsgroup-limits))
8554 ;; Set the limit.
8555 (setq gnus-newsgroup-limit articles)
8556 (let ((total (length gnus-newsgroup-data))
8557 (data (gnus-data-find-list (gnus-summary-article-number)))
8558 (gnus-summary-mark-below nil) ; Inhibit this.
8559 found)
8560 ;; This will do all the work of generating the new summary buffer
8561 ;; according to the new limit.
8562 (gnus-summary-prepare)
8563 ;; Hide any threads, possibly.
23f87bed 8564 (gnus-summary-maybe-hide-threads)
eec82323
LMI
8565 ;; Try to return to the article you were at, or one in the
8566 ;; neighborhood.
8567 (when data
8568 ;; We try to find some article after the current one.
8569 (while data
8570 (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8571 (setq data nil
8572 found t))
8573 (setq data (cdr data))))
8574 (unless found
8575 ;; If there is no data, that means that we were after the last
8576 ;; article. The same goes when we can't find any articles
8577 ;; after the current one.
8578 (goto-char (point-max))
8579 (gnus-summary-find-prev))
6748645f 8580 (gnus-set-mode-line 'summary)
eec82323
LMI
8581 ;; We return how many articles were removed from the summary
8582 ;; buffer as a result of the new limit.
8583 (- total (length gnus-newsgroup-data))))
8584
8585(defsubst gnus-invisible-cut-children (threads)
8586 (let ((num 0))
8587 (while threads
8588 (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8589 (incf num))
8590 (pop threads))
8591 (< num 2)))
8592
8593(defsubst gnus-cut-thread (thread)
8594 "Go forwards in the thread until we find an article that we want to display."
8595 (when (or (eq gnus-fetch-old-headers 'some)
6748645f 8596 (eq gnus-fetch-old-headers 'invisible)
16409b0b 8597 (numberp gnus-fetch-old-headers)
eec82323
LMI
8598 (eq gnus-build-sparse-threads 'some)
8599 (eq gnus-build-sparse-threads 'more))
8600 ;; Deal with old-fetched headers and sparse threads.
8601 (while (and
8602 thread
8603 (or
8604 (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8605 (gnus-summary-article-ancient-p
8606 (mail-header-number (car thread))))
6748645f
LMI
8607 (if (or (<= (length (cdr thread)) 1)
8608 (eq gnus-fetch-old-headers 'invisible))
8609 (setq gnus-newsgroup-limit
8610 (delq (mail-header-number (car thread))
8611 gnus-newsgroup-limit)
8612 thread (cadr thread))
8613 (when (gnus-invisible-cut-children (cdr thread))
8614 (let ((th (cdr thread)))
8615 (while th
8616 (if (memq (mail-header-number (caar th))
a8151ef7 8617 gnus-newsgroup-limit)
6748645f
LMI
8618 (setq thread (car th)
8619 th nil)
8620 (setq th (cdr th))))))))))
eec82323
LMI
8621 thread)
8622
8623(defun gnus-cut-threads (threads)
23f87bed 8624 "Cut off all uninteresting articles from the beginning of THREADS."
eec82323 8625 (when (or (eq gnus-fetch-old-headers 'some)
6748645f 8626 (eq gnus-fetch-old-headers 'invisible)
16409b0b 8627 (numberp gnus-fetch-old-headers)
eec82323
LMI
8628 (eq gnus-build-sparse-threads 'some)
8629 (eq gnus-build-sparse-threads 'more))
8630 (let ((th threads))
8631 (while th
8632 (setcar th (gnus-cut-thread (car th)))
8633 (setq th (cdr th)))))
8634 ;; Remove nixed out threads.
8635 (delq nil threads))
8636
8637(defun gnus-summary-initial-limit (&optional show-if-empty)
8638 "Figure out what the initial limit is supposed to be on group entry.
8639This entails weeding out unwanted dormants, low-scored articles,
8640fetch-old-headers verbiage, and so on."
8641 ;; Most groups have nothing to remove.
f394fa25
MB
8642 (unless (or gnus-inhibit-limiting
8643 (and (null gnus-newsgroup-dormant)
8644 (eq gnus-newsgroup-display 'gnus-not-ignore)
8645 (not (eq gnus-fetch-old-headers 'some))
8646 (not (numberp gnus-fetch-old-headers))
8647 (not (eq gnus-fetch-old-headers 'invisible))
8648 (null gnus-summary-expunge-below)
8649 (not (eq gnus-build-sparse-threads 'some))
8650 (not (eq gnus-build-sparse-threads 'more))
8ccbef23 8651 (null gnus-thread-expunge-below)))
eec82323
LMI
8652 (push gnus-newsgroup-limit gnus-newsgroup-limits)
8653 (setq gnus-newsgroup-limit nil)
8654 (mapatoms
8655 (lambda (node)
8656 (unless (car (symbol-value node))
8657 ;; These threads have no parents -- they are roots.
8658 (let ((nodes (cdr (symbol-value node)))
8659 thread)
8660 (while nodes
8661 (if (and gnus-thread-expunge-below
8662 (< (gnus-thread-total-score (car nodes))
8663 gnus-thread-expunge-below))
8664 (gnus-expunge-thread (pop nodes))
8665 (setq thread (pop nodes))
8666 (gnus-summary-limit-children thread))))))
8667 gnus-newsgroup-dependencies)
8668 ;; If this limitation resulted in an empty group, we might
8669 ;; pop the previous limit and use it instead.
8670 (when (and (not gnus-newsgroup-limit)
8671 show-if-empty)
8672 (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8673 gnus-newsgroup-limit))
8674
8675(defun gnus-summary-limit-children (thread)
8676 "Return 1 if this subthread is visible and 0 if it is not."
8677 ;; First we get the number of visible children to this thread. This
8678 ;; is done by recursing down the thread using this function, so this
8679 ;; will really go down to a leaf article first, before slowly
8680 ;; working its way up towards the root.
8681 (when thread
04b61ae9 8682 (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
23f87bed 8683 (children
eec82323
LMI
8684 (if (cdr thread)
8685 (apply '+ (mapcar 'gnus-summary-limit-children
8686 (cdr thread)))
8687 0))
8688 (number (mail-header-number (car thread)))
8689 score)
8690 (if (and
8691 (not (memq number gnus-newsgroup-marked))
8692 (or
8693 ;; If this article is dormant and has absolutely no visible
8694 ;; children, then this article isn't visible.
8695 (and (memq number gnus-newsgroup-dormant)
8696 (zerop children))
8697 ;; If this is "fetch-old-headered" and there is no
8698 ;; visible children, then we don't want this article.
16409b0b
GM
8699 (and (or (eq gnus-fetch-old-headers 'some)
8700 (numberp gnus-fetch-old-headers))
eec82323
LMI
8701 (gnus-summary-article-ancient-p number)
8702 (zerop children))
6748645f
LMI
8703 ;; If this is "fetch-old-headered" and `invisible', then
8704 ;; we don't want this article.
8705 (and (eq gnus-fetch-old-headers 'invisible)
8706 (gnus-summary-article-ancient-p number))
eec82323
LMI
8707 ;; If this is a sparsely inserted article with no children,
8708 ;; we don't want it.
8709 (and (eq gnus-build-sparse-threads 'some)
8710 (gnus-summary-article-sparse-p number)
8711 (zerop children))
8712 ;; If we use expunging, and this article is really
8713 ;; low-scored, then we don't want this article.
8714 (when (and gnus-summary-expunge-below
8715 (< (setq score
8716 (or (cdr (assq number gnus-newsgroup-scored))
8717 gnus-summary-default-score))
8718 gnus-summary-expunge-below))
8719 ;; We increase the expunge-tally here, but that has
8720 ;; nothing to do with the limits, really.
8721 (incf gnus-newsgroup-expunged-tally)
8722 ;; We also mark as read here, if that's wanted.
8723 (when (and gnus-summary-mark-below
8724 (< score gnus-summary-mark-below))
8725 (setq gnus-newsgroup-unreads
8726 (delq number gnus-newsgroup-unreads))
8727 (if gnus-newsgroup-auto-expire
8728 (push number gnus-newsgroup-expirable)
8729 (push (cons number gnus-low-score-mark)
8730 gnus-newsgroup-reads)))
8731 t)
23f87bed
MB
8732 ;; Do the `display' group parameter.
8733 (and gnus-newsgroup-display
8ccbef23 8734 (not (funcall gnus-newsgroup-display)))))
eec82323
LMI
8735 ;; Nope, invisible article.
8736 0
8737 ;; Ok, this article is to be visible, so we add it to the limit
8738 ;; and return 1.
8739 (push number gnus-newsgroup-limit)
8740 1))))
8741
8742(defun gnus-expunge-thread (thread)
8743 "Mark all articles in THREAD as read."
8744 (let* ((number (mail-header-number (car thread))))
8745 (incf gnus-newsgroup-expunged-tally)
8746 ;; We also mark as read here, if that's wanted.
8747 (setq gnus-newsgroup-unreads
8748 (delq number gnus-newsgroup-unreads))
8749 (if gnus-newsgroup-auto-expire
8750 (push number gnus-newsgroup-expirable)
8751 (push (cons number gnus-low-score-mark)
8752 gnus-newsgroup-reads)))
8753 ;; Go recursively through all subthreads.
8754 (mapcar 'gnus-expunge-thread (cdr thread)))
8755
8756;; Summary article oriented commands
8757
8758(defun gnus-summary-refer-parent-article (n)
8759 "Refer parent article N times.
8760If N is negative, go to ancestor -N instead.
8761The difference between N and the number of articles fetched is returned."
8762 (interactive "p")
eec82323
LMI
8763 (let ((skip 1)
8764 error header ref)
8765 (when (not (natnump n))
8766 (setq skip (abs n)
8767 n 1))
8768 (while (and (> n 0)
8769 (not error))
8770 (setq header (gnus-summary-article-header))
8771 (if (and (eq (mail-header-number header)
8772 (cdr gnus-article-current))
8773 (equal gnus-newsgroup-name
8774 (car gnus-article-current)))
8775 ;; If we try to find the parent of the currently
8776 ;; displayed article, then we take a look at the actual
8777 ;; References header, since this is slightly more
8778 ;; reliable than the References field we got from the
8779 ;; server.
c7a91ce1 8780 (with-current-buffer gnus-original-article-buffer
eec82323
LMI
8781 (nnheader-narrow-to-headers)
8782 (unless (setq ref (message-fetch-field "references"))
23f87bed
MB
8783 (when (setq ref (message-fetch-field "in-reply-to"))
8784 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
eec82323
LMI
8785 (widen))
8786 (setq ref
8787 ;; It's not the current article, so we take a bet on
8788 ;; the value we got from the server.
8789 (mail-header-references header)))
8790 (if (and ref
8791 (not (equal ref "")))
8792 (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8793 (gnus-message 1 "Couldn't find parent"))
8794 (gnus-message 1 "No references in article %d"
8795 (gnus-summary-article-number))
8796 (setq error t))
8797 (decf n))
8798 (gnus-summary-position-point)
8799 n))
8800
8801(defun gnus-summary-refer-references ()
8802 "Fetch all articles mentioned in the References header.
6748645f 8803Return the number of articles fetched."
eec82323 8804 (interactive)
eec82323
LMI
8805 (let ((ref (mail-header-references (gnus-summary-article-header)))
8806 (current (gnus-summary-article-number))
8807 (n 0))
8808 (if (or (not ref)
8809 (equal ref ""))
8810 (error "No References in the current article")
8811 ;; For each Message-ID in the References header...
8812 (while (string-match "<[^>]*>" ref)
8813 (incf n)
8814 ;; ... fetch that article.
8815 (gnus-summary-refer-article
8816 (prog1 (match-string 0 ref)
8817 (setq ref (substring ref (match-end 0))))))
8818 (gnus-summary-goto-subject current)
8819 (gnus-summary-position-point)
8820 n)))
8821
6748645f
LMI
8822(defun gnus-summary-refer-thread (&optional limit)
8823 "Fetch all articles in the current thread.
8824If LIMIT (the numerical prefix), fetch that many old headers instead
8825of what's specified by the `gnus-refer-thread-limit' variable."
8826 (interactive "P")
8827 (let ((id (mail-header-id (gnus-summary-article-header)))
8828 (limit (if limit (prefix-numeric-value limit)
8829 gnus-refer-thread-limit)))
6748645f
LMI
8830 (unless (eq gnus-fetch-old-headers 'invisible)
8831 (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8832 ;; Retrieve the headers and read them in.
23f87bed
MB
8833 (if (eq (if (numberp limit)
8834 (gnus-retrieve-headers
8835 (list (min
8836 (+ (mail-header-number
8837 (gnus-summary-article-header))
8838 limit)
8839 gnus-newsgroup-end))
8840 gnus-newsgroup-name (* limit 2))
8841 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8842 ;; headers.
8843 (gnus-retrieve-headers (list gnus-newsgroup-end)
8844 gnus-newsgroup-name limit))
6748645f
LMI
8845 'nov)
8846 (gnus-build-all-threads)
23f87bed 8847 (error "Can't fetch thread from back ends that don't support NOV"))
6748645f
LMI
8848 (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8849 (gnus-summary-limit-include-thread id)))
8850
16409b0b
GM
8851(defun gnus-summary-refer-article (message-id)
8852 "Fetch an article specified by MESSAGE-ID."
8853 (interactive "sMessage-ID: ")
eec82323
LMI
8854 (when (and (stringp message-id)
8855 (not (zerop (length message-id))))
23f87bed 8856 (setq message-id (gnus-replace-in-string message-id " " ""))
eec82323
LMI
8857 ;; Construct the correct Message-ID if necessary.
8858 ;; Suggested by tale@pawl.rpi.edu.
8859 (unless (string-match "^<" message-id)
8860 (setq message-id (concat "<" message-id)))
8861 (unless (string-match ">$" message-id)
8862 (setq message-id (concat message-id ">")))
23f87bed
MB
8863 ;; People often post MIDs from URLs, so unhex it:
8864 (unless (string-match "@" message-id)
8865 (setq message-id (gnus-url-unhex-string message-id)))
eec82323
LMI
8866 (let* ((header (gnus-id-to-header message-id))
8867 (sparse (and header
8868 (gnus-summary-article-sparse-p
a8151ef7
LMI
8869 (mail-header-number header))
8870 (memq (mail-header-number header)
16409b0b
GM
8871 gnus-newsgroup-limit)))
8872 number)
6748645f
LMI
8873 (cond
8874 ;; If the article is present in the buffer we just go to it.
8875 ((and header
8876 (or (not (gnus-summary-article-sparse-p
8877 (mail-header-number header)))
8878 sparse))
8879 (prog1
8880 (gnus-summary-goto-article
8881 (mail-header-number header) nil t)
8882 (when sparse
8883 (gnus-summary-update-article (mail-header-number header)))))
8884 (t
16409b0b
GM
8885 ;; We fetch the article.
8886 (catch 'found
8887 (dolist (gnus-override-method (gnus-refer-article-methods))
23f87bed
MB
8888 (when (and (gnus-check-server gnus-override-method)
8889 ;; Fetch the header,
8890 (setq number (gnus-summary-insert-subject message-id)))
8891 ;; and display the article.
eec82323 8892 (gnus-summary-select-article nil nil nil number)
16409b0b
GM
8893 (throw 'found t)))
8894 (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8895
8896(defun gnus-refer-article-methods ()
8f688cb0 8897 "Return a list of referable methods."
16409b0b
GM
8898 (cond
8899 ;; No method, so we default to current and native.
8900 ((null gnus-refer-article-method)
8901 (list gnus-current-select-method gnus-select-method))
8902 ;; Current.
8903 ((eq 'current gnus-refer-article-method)
8904 (list gnus-current-select-method))
8905 ;; List of select methods.
d4dfaa19
DL
8906 ((not (and (symbolp (car gnus-refer-article-method))
8907 (assq (car gnus-refer-article-method) nnoo-definition-alist)))
16409b0b
GM
8908 (let (out)
8909 (dolist (method gnus-refer-article-method)
8910 (push (if (eq 'current method)
8911 gnus-current-select-method
8912 method)
8913 out))
8914 (nreverse out)))
8915 ;; One single select method.
8916 (t
8917 (list gnus-refer-article-method))))
6748645f
LMI
8918
8919(defun gnus-summary-edit-parameters ()
8920 "Edit the group parameters of the current group."
8921 (interactive)
8922 (gnus-group-edit-group gnus-newsgroup-name 'params))
eec82323 8923
16409b0b
GM
8924(defun gnus-summary-customize-parameters ()
8925 "Customize the group parameters of the current group."
8926 (interactive)
8927 (gnus-group-customize gnus-newsgroup-name))
8928
eec82323
LMI
8929(defun gnus-summary-enter-digest-group (&optional force)
8930 "Enter an nndoc group based on the current article.
8931If FORCE, force a digest interpretation. If not, try
8932to guess what the document format is."
8933 (interactive "P")
eec82323 8934 (let ((conf gnus-current-window-configuration))
23f87bed
MB
8935 (save-window-excursion
8936 (save-excursion
8937 (let (gnus-article-prepare-hook
8938 gnus-display-mime-function
8939 gnus-break-pages)
8940 (gnus-summary-select-article))))
eec82323
LMI
8941 (setq gnus-current-window-configuration conf)
8942 (let* ((name (format "%s-%d"
8943 (gnus-group-prefixed-name
8944 gnus-newsgroup-name (list 'nndoc ""))
01c52d31 8945 (with-current-buffer gnus-summary-buffer
eec82323
LMI
8946 gnus-current-article)))
8947 (ogroup gnus-newsgroup-name)
8948 (params (append (gnus-info-params (gnus-get-info ogroup))
8949 (list (cons 'to-group ogroup))
23f87bed 8950 (list (cons 'parent-group ogroup))
eec82323
LMI
8951 (list (cons 'save-article-group ogroup))))
8952 (case-fold-search t)
8953 (buf (current-buffer))
16409b0b 8954 dig to-address)
c7a91ce1 8955 (with-current-buffer gnus-original-article-buffer
16409b0b
GM
8956 ;; Have the digest group inherit the main mail address of
8957 ;; the parent article.
23f87bed
MB
8958 (when (setq to-address (or (gnus-fetch-field "reply-to")
8959 (gnus-fetch-field "from")))
343d6628
MB
8960 (setq params
8961 (append
8962 (list (cons 'to-address
8963 (funcall gnus-decode-encoded-address-function
8964 to-address))))))
eec82323
LMI
8965 (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8966 (insert-buffer-substring gnus-original-article-buffer)
8967 ;; Remove lines that may lead nndoc to misinterpret the
8968 ;; document type.
8969 (narrow-to-region
8970 (goto-char (point-min))
8971 (or (search-forward "\n\n" nil t) (point)))
8972 (goto-char (point-min))
16409b0b 8973 (delete-matching-lines "^Path:\\|^From ")
eec82323
LMI
8974 (widen))
8975 (unwind-protect
23f87bed 8976 (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
16409b0b
GM
8977 (gnus-newsgroup-ephemeral-ignored-charsets
8978 gnus-newsgroup-ignored-charsets))
8979 (gnus-group-read-ephemeral-group
8980 name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8981 (nndoc-article-type
23f87bed
MB
8982 ,(if force 'mbox 'guess)))
8983 t nil nil nil
8984 `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8985 "ADAPT")))))
16409b0b 8986 ;; Make all postings to this group go to the parent group.
23f87bed
MB
8987 (nconc (gnus-info-params (gnus-get-info name))
8988 params)
8989 ;; Couldn't select this doc group.
8990 (switch-to-buffer buf)
8991 (gnus-set-global-variables)
8992 (gnus-configure-windows 'summary)
8993 (gnus-message 3 "Article couldn't be entered?"))
eec82323
LMI
8994 (kill-buffer dig)))))
8995
8996(defun gnus-summary-read-document (n)
8997 "Open a new group based on the current article(s).
8998This will allow you to read digests and other similar
8999documents as newsgroups.
9000Obeys the standard process/prefix convention."
9001 (interactive "P")
01c52d31 9002 (let* ((ogroup gnus-newsgroup-name)
eec82323
LMI
9003 (params (append (gnus-info-params (gnus-get-info ogroup))
9004 (list (cons 'to-group ogroup))))
01c52d31
MB
9005 group egroup groups vgroup)
9006 (dolist (article (gnus-summary-work-articles n))
eec82323
LMI
9007 (setq group (format "%s-%d" gnus-newsgroup-name article))
9008 (gnus-summary-remove-process-mark article)
9009 (when (gnus-summary-display-article article)
398a825b 9010 (save-excursion ;;What for?
16409b0b 9011 (with-temp-buffer
eec82323
LMI
9012 (insert-buffer-substring gnus-original-article-buffer)
9013 ;; Remove some headers that may lead nndoc to make
9014 ;; the wrong guess.
9015 (message-narrow-to-head)
9016 (goto-char (point-min))
01c52d31 9017 (delete-matching-lines "^Path:\\|^From ")
eec82323
LMI
9018 (widen)
9019 (if (setq egroup
9020 (gnus-group-read-ephemeral-group
9021 group `(nndoc ,group (nndoc-address ,(current-buffer))
9022 (nndoc-article-type guess))
9023 t nil t))
9024 (progn
c7a91ce1 9025 ;; Make all postings to this group go to the parent group.
eec82323
LMI
9026 (nconc (gnus-info-params (gnus-get-info egroup))
9027 params)
9028 (push egroup groups))
9029 ;; Couldn't select this doc group.
9030 (gnus-error 3 "Article couldn't be entered"))))))
9031 ;; Now we have selected all the documents.
9032 (cond
9033 ((not groups)
9034 (error "None of the articles could be interpreted as documents"))
9035 ((gnus-group-read-ephemeral-group
9036 (setq vgroup (format
9037 "nnvirtual:%s-%s" gnus-newsgroup-name
9038 (format-time-string "%Y%m%dT%H%M%S" (current-time))))
9039 `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
9040 t
9041 (cons (current-buffer) 'summary)))
9042 (t
9043 (error "Couldn't select virtual nndoc group")))))
9044
9045(defun gnus-summary-isearch-article (&optional regexp-p)
9046 "Do incremental search forward on the current article.
9047If REGEXP-P (the prefix) is non-nil, do regexp isearch."
9048 (interactive "P")
eec82323
LMI
9049 (gnus-summary-select-article)
9050 (gnus-configure-windows 'article)
9051 (gnus-eval-in-buffer-window gnus-article-buffer
6748645f
LMI
9052 (save-restriction
9053 (widen)
9054 (isearch-forward regexp-p))))
eec82323 9055
01c52d31
MB
9056(defun gnus-summary-repeat-search-article-forward ()
9057 "Repeat the previous search forwards."
9058 (interactive)
9059 (unless gnus-last-search-regexp
9060 (error "No previous search"))
9061 (gnus-summary-search-article-forward gnus-last-search-regexp))
9062
9063(defun gnus-summary-repeat-search-article-backward ()
9064 "Repeat the previous search backwards."
9065 (interactive)
9066 (unless gnus-last-search-regexp
9067 (error "No previous search"))
9068 (gnus-summary-search-article-forward gnus-last-search-regexp t))
9069
eec82323
LMI
9070(defun gnus-summary-search-article-forward (regexp &optional backward)
9071 "Search for an article containing REGEXP forward.
9072If BACKWARD, search backward instead."
9073 (interactive
9074 (list (read-string
9075 (format "Search article %s (regexp%s): "
9076 (if current-prefix-arg "backward" "forward")
9077 (if gnus-last-search-regexp
9078 (concat ", default " gnus-last-search-regexp)
9079 "")))
9080 current-prefix-arg))
eec82323
LMI
9081 (if (string-equal regexp "")
9082 (setq regexp (or gnus-last-search-regexp ""))
23f87bed
MB
9083 (setq gnus-last-search-regexp regexp)
9084 (setq gnus-article-before-search gnus-current-article))
9085 ;; Intentionally set gnus-last-article.
9086 (setq gnus-last-article gnus-article-before-search)
9087 (let ((gnus-last-article gnus-last-article))
9088 (if (gnus-summary-search-article regexp backward)
9089 (gnus-summary-show-thread)
abc40aab 9090 (signal 'search-failed (list regexp)))))
eec82323
LMI
9091
9092(defun gnus-summary-search-article-backward (regexp)
9093 "Search for an article containing REGEXP backward."
9094 (interactive
9095 (list (read-string
9096 (format "Search article backward (regexp%s): "
9097 (if gnus-last-search-regexp
9098 (concat ", default " gnus-last-search-regexp)
9099 "")))))
9100 (gnus-summary-search-article-forward regexp 'backward))
9101
9102(defun gnus-summary-search-article (regexp &optional backward)
9103 "Search for an article containing REGEXP.
9104Optional argument BACKWARD means do search for backward.
9105`gnus-select-article-hook' is not called during the search."
a8151ef7
LMI
9106 ;; We have to require this here to make sure that the following
9107 ;; dynamic binding isn't shadowed by autoloading.
9108 (require 'gnus-async)
16409b0b 9109 (require 'gnus-art)
eec82323 9110 (let ((gnus-select-article-hook nil) ;Disable hook.
16409b0b 9111 (gnus-article-prepare-hook nil)
eec82323
LMI
9112 (gnus-mark-article-hook nil) ;Inhibit marking as read.
9113 (gnus-use-article-prefetch nil)
9114 (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
a8151ef7 9115 (gnus-use-trees nil) ;Inhibit updating tree buffer.
23f87bed
MB
9116 (gnus-visual nil)
9117 (gnus-keep-backlog nil)
9118 (gnus-break-pages nil)
9119 (gnus-summary-display-arrow nil)
9120 (gnus-updated-mode-lines nil)
9121 (gnus-auto-center-summary nil)
eec82323 9122 (sum (current-buffer))
16409b0b 9123 (gnus-display-mime-function nil)
eec82323
LMI
9124 (found nil)
9125 point)
9126 (gnus-save-hidden-threads
9127 (gnus-summary-select-article)
9128 (set-buffer gnus-article-buffer)
16409b0b 9129 (goto-char (window-point (get-buffer-window (current-buffer))))
eec82323
LMI
9130 (when backward
9131 (forward-line -1))
9132 (while (not found)
9133 (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9134 (if (if backward
9135 (re-search-backward regexp nil t)
9136 (re-search-forward regexp nil t))
9137 ;; We found the regexp.
9138 (progn
9139 (setq found 'found)
9140 (beginning-of-line)
9141 (set-window-start
9142 (get-buffer-window (current-buffer))
9143 (point))
9144 (forward-line 1)
16409b0b
GM
9145 (set-window-point
9146 (get-buffer-window (current-buffer))
9147 (point))
eec82323
LMI
9148 (set-buffer sum)
9149 (setq point (point)))
9150 ;; We didn't find it, so we go to the next article.
9151 (set-buffer sum)
9152 (setq found 'not)
9153 (while (eq found 'not)
9154 (if (not (if backward (gnus-summary-find-prev)
9155 (gnus-summary-find-next)))
9156 ;; No more articles.
9157 (setq found t)
9158 ;; Select the next article and adjust point.
9159 (unless (gnus-summary-article-sparse-p
9160 (gnus-summary-article-number))
9161 (setq found nil)
9162 (gnus-summary-select-article)
9163 (set-buffer gnus-article-buffer)
9164 (widen)
9165 (goto-char (if backward (point-max) (point-min))))))))
9166 (gnus-message 7 ""))
9167 ;; Return whether we found the regexp.
9168 (when (eq found 'found)
9169 (goto-char point)
9170 (gnus-summary-show-thread)
9171 (gnus-summary-goto-subject gnus-current-article)
9172 (gnus-summary-position-point)
9173 t)))
9174
23f87bed
MB
9175(defun gnus-find-matching-articles (header regexp)
9176 "Return a list of all articles that match REGEXP on HEADER.
9177This search includes all articles in the current group that Gnus has
9178fetched headers for, whether they are displayed or not."
9179 (let ((articles nil)
c7a91ce1 9180 ;; Can't eta-reduce because it's a macro.
23f87bed
MB
9181 (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9182 (case-fold-search t))
9183 (dolist (header gnus-newsgroup-headers)
9184 (when (string-match regexp (funcall func header))
9185 (push (mail-header-number header) articles)))
9186 (nreverse articles)))
9187
eec82323 9188(defun gnus-summary-find-matching (header regexp &optional backward unread
47b63dfa 9189 not-case-fold not-matching)
eec82323
LMI
9190 "Return a list of all articles that match REGEXP on HEADER.
9191The search stars on the current article and goes forwards unless
9192BACKWARD is non-nil. If BACKWARD is `all', do all articles.
9193If UNREAD is non-nil, only unread articles will
9194be taken into consideration. If NOT-CASE-FOLD, case won't be folded
a1506d29 9195in the comparisons. If NOT-MATCHING, return a list of all articles that
47b63dfa
SZ
9196not match REGEXP on HEADER."
9197 (let ((case-fold-search (not not-case-fold))
16409b0b
GM
9198 articles d func)
9199 (if (consp header)
9200 (if (eq (car header) 'extra)
9201 (setq func
9202 `(lambda (h)
9203 (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9204 "")))
9205 (error "%s is an invalid header" header))
9206 (unless (fboundp (intern (concat "mail-header-" header)))
9207 (error "%s is not a valid header" header))
9208 (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
47b63dfa
SZ
9209 (dolist (d (if (eq backward 'all)
9210 gnus-newsgroup-data
9211 (gnus-data-find-list
9212 (gnus-summary-article-number)
9213 (gnus-data-list backward))))
9214 (when (and (or (not unread) ; We want all articles...
9215 (gnus-data-unread-p d)) ; Or just unreads.
9216 (vectorp (gnus-data-header d)) ; It's not a pseudo.
9217 (if not-matching
a1506d29 9218 (not (string-match
47b63dfa
SZ
9219 regexp
9220 (funcall func (gnus-data-header d))))
9221 (string-match regexp
9222 (funcall func (gnus-data-header d)))))
9223 (push (gnus-data-number d) articles))) ; Success!
eec82323
LMI
9224 (nreverse articles)))
9225
9226(defun gnus-summary-execute-command (header regexp command &optional backward)
9227 "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9228If HEADER is an empty string (or nil), the match is done on the entire
9229article. If BACKWARD (the prefix) is non-nil, search backward instead."
9230 (interactive
9231 (list (let ((completion-ignore-case t))
9232 (completing-read
9233 "Header name: "
23f87bed
MB
9234 (mapcar (lambda (header) (list (format "%s" header)))
9235 (append
9236 '("Number" "Subject" "From" "Lines" "Date"
9237 "Message-ID" "Xref" "References" "Body")
9238 gnus-extra-headers))
eec82323
LMI
9239 nil 'require-match))
9240 (read-string "Regexp: ")
9241 (read-key-sequence "Command: ")
9242 current-prefix-arg))
9243 (when (equal header "Body")
9244 (setq header ""))
eec82323
LMI
9245 ;; Hidden thread subtrees must be searched as well.
9246 (gnus-summary-show-all-threads)
9247 ;; We don't want to change current point nor window configuration.
9248 (save-excursion
9249 (save-window-excursion
23f87bed
MB
9250 (let (gnus-visual
9251 gnus-treat-strip-trailing-blank-lines
9252 gnus-treat-strip-leading-blank-lines
9253 gnus-treat-strip-multiple-blank-lines
9254 gnus-treat-hide-boring-headers
9255 gnus-treat-fold-newsgroups
9256 gnus-article-prepare-hook)
9257 (gnus-message 6 "Executing %s..." (key-description command))
9258 ;; We'd like to execute COMMAND interactively so as to give arguments.
9259 (gnus-execute header regexp
9260 `(call-interactively ',(key-binding command))
9261 backward)
9262 (gnus-message 6 "Executing %s...done" (key-description command))))))
eec82323
LMI
9263
9264(defun gnus-summary-beginning-of-article ()
9265 "Scroll the article back to the beginning."
9266 (interactive)
eec82323
LMI
9267 (gnus-summary-select-article)
9268 (gnus-configure-windows 'article)
9269 (gnus-eval-in-buffer-window gnus-article-buffer
9270 (widen)
9271 (goto-char (point-min))
23f87bed 9272 (when gnus-break-pages
eec82323
LMI
9273 (gnus-narrow-to-page))))
9274
9275(defun gnus-summary-end-of-article ()
9276 "Scroll to the end of the article."
9277 (interactive)
eec82323
LMI
9278 (gnus-summary-select-article)
9279 (gnus-configure-windows 'article)
9280 (gnus-eval-in-buffer-window gnus-article-buffer
9281 (widen)
9282 (goto-char (point-max))
9283 (recenter -3)
23f87bed 9284 (when gnus-break-pages
eec82323
LMI
9285 (gnus-narrow-to-page))))
9286
23f87bed
MB
9287(defun gnus-summary-print-truncate-and-quote (string &optional len)
9288 "Truncate to LEN and quote all \"(\"'s in STRING."
9289 (gnus-replace-in-string (if (and len (> (length string) len))
9290 (substring string 0 len)
9291 string)
9292 "[()]" "\\\\\\&"))
9293
6748645f 9294(defun gnus-summary-print-article (&optional filename n)
23f87bed
MB
9295 "Generate and print a PostScript image of the process-marked (mail) articles.
9296
9297If used interactively, print the current article if none are
9298process-marked. With prefix arg, prompt the user for the name of the
9299file to save in.
6748645f 9300
23f87bed
MB
9301When used from Lisp, accept two optional args FILENAME and N. N means
9302to print the next N articles. If N is negative, print the N previous
9303articles. If N is nil and articles have been marked with the process
9304mark, print these instead.
eec82323 9305
16409b0b 9306If the optional first argument FILENAME is nil, send the image to the
6748645f
LMI
9307printer. If FILENAME is a string, save the PostScript image in a file with
9308that name. If FILENAME is a number, prompt the user for the name of the file
eec82323 9309to save in."
676a7cc9 9310 (interactive (list (ps-print-preprint current-prefix-arg)))
6748645f
LMI
9311 (dolist (article (gnus-summary-work-articles n))
9312 (gnus-summary-select-article nil nil 'pseudo article)
9313 (gnus-eval-in-buffer-window gnus-article-buffer
23f87bed 9314 (gnus-print-buffer))
676a7cc9
SZ
9315 (gnus-summary-remove-process-mark article))
9316 (ps-despool filename))
eec82323 9317
23f87bed
MB
9318(defun gnus-print-buffer ()
9319 (let ((buffer (generate-new-buffer " *print*")))
9320 (unwind-protect
9321 (progn
9322 (copy-to-buffer buffer (point-min) (point-max))
9323 (set-buffer buffer)
9324 (gnus-remove-text-with-property 'gnus-decoration)
9325 (when (gnus-visual-p 'article-highlight 'highlight)
9326 ;; Copy-to-buffer doesn't copy overlay. So redo
9327 ;; highlight.
9328 (let ((gnus-article-buffer buffer))
9329 (gnus-article-highlight-citation t)
9330 (gnus-article-highlight-signature)
9331 (gnus-article-emphasize)
9332 (gnus-article-delete-invisible-text)))
9333 (let ((ps-left-header
9334 (list
9335 (concat "("
9336 (gnus-summary-print-truncate-and-quote
9337 (mail-header-subject gnus-current-headers)
9338 66) ")")
9339 (concat "("
9340 (gnus-summary-print-truncate-and-quote
9341 (mail-header-from gnus-current-headers)
9342 45) ")")))
9343 (ps-right-header
9344 (list
9345 "/pagenumberstring load"
9346 (concat "("
9347 (mail-header-date gnus-current-headers) ")"))))
9348 (gnus-run-hooks 'gnus-ps-print-hook)
9349 (save-excursion
a7b50e1c 9350 (if ps-print-color-p
23f87bed
MB
9351 (ps-spool-buffer-with-faces)
9352 (ps-spool-buffer)))))
9353 (kill-buffer buffer))))
9354
8ccbef23
G
9355(defun gnus-summary-show-complete-article ()
9356 "Show a complete version of the current article.
9357This is only useful if you're looking at a partial version of the
9358article currently."
9359 (interactive)
9360 (let ((gnus-keep-backlog nil)
9361 (gnus-use-cache nil)
9362 (gnus-agent nil)
9363 (gnus-fetch-partial-articles nil))
9364 (gnus-flush-original-article-buffer)
9365 (gnus-summary-show-article)))
9366
eec82323 9367(defun gnus-summary-show-article (&optional arg)
23f87bed 9368 "Force redisplaying of the current article.
16409b0b
GM
9369If ARG (the prefix) is a number, show the article with the charset
9370defined in `gnus-summary-show-article-charset-alist', or the charset
23f87bed 9371input.
16409b0b 9372If ARG (the prefix) is non-nil and not a number, show the raw article
23f87bed
MB
9373without any article massaging functions being run. Normally, the key
9374strokes are `C-u g'."
eec82323 9375 (interactive "P")
16409b0b
GM
9376 (cond
9377 ((numberp arg)
23f87bed 9378 (gnus-summary-show-article t)
16409b0b
GM
9379 (let ((gnus-newsgroup-charset
9380 (or (cdr (assq arg gnus-summary-show-article-charset-alist))
23f87bed
MB
9381 (mm-read-coding-system
9382 "View as charset: " ;; actually it is coding system.
01c52d31 9383 (with-current-buffer gnus-article-buffer
23f87bed 9384 (mm-detect-coding-region (point) (point-max))))))
16409b0b 9385 (gnus-newsgroup-ignored-charsets 'gnus-all))
23f87bed
MB
9386 (gnus-summary-select-article nil 'force)
9387 (let ((deps gnus-newsgroup-dependencies)
9388 head header lines)
c7a91ce1 9389 (with-current-buffer gnus-original-article-buffer
23f87bed
MB
9390 (save-restriction
9391 (message-narrow-to-head)
9392 (setq head (buffer-string))
9393 (goto-char (point-min))
9394 (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9395 (goto-char (point-max))
9396 (widen)
9397 (setq lines (1- (count-lines (point) (point-max))))))
9398 (with-temp-buffer
9399 (insert (format "211 %d Article retrieved.\n"
9400 (cdr gnus-article-current)))
9401 (insert head)
9402 (if lines (insert (format "Lines: %d\n" lines)))
9403 (insert ".\n")
9404 (let ((nntp-server-buffer (current-buffer)))
9405 (setq header (car (gnus-get-newsgroup-headers deps t))))))
9406 (gnus-data-set-header
9407 (gnus-data-find (cdr gnus-article-current))
9408 header)
9409 (gnus-summary-update-article-line
9410 (cdr gnus-article-current) header)
9411 (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9412 (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
16409b0b
GM
9413 ((not arg)
9414 ;; Select the article the normal way.
9415 (gnus-summary-select-article nil 'force))
9416 (t
9417 ;; We have to require this here to make sure that the following
9418 ;; dynamic binding isn't shadowed by autoloading.
9419 (require 'gnus-async)
9420 (require 'gnus-art)
eec82323
LMI
9421 ;; Bind the article treatment functions to nil.
9422 (let ((gnus-have-all-headers t)
eec82323 9423 gnus-article-prepare-hook
16409b0b
GM
9424 gnus-article-decode-hook
9425 gnus-display-mime-function
9426 gnus-break-pages)
9427 ;; Destroy any MIME parts.
9428 (when (gnus-buffer-live-p gnus-article-buffer)
c7a91ce1 9429 (with-current-buffer gnus-article-buffer
16409b0b
GM
9430 (mm-destroy-parts gnus-article-mime-handles)
9431 ;; Set it to nil for safety reason.
9432 (setq gnus-article-mime-handle-alist nil)
9433 (setq gnus-article-mime-handles nil)))
9434 (gnus-summary-select-article nil 'force))))
eec82323
LMI
9435 (gnus-summary-goto-subject gnus-current-article)
9436 (gnus-summary-position-point))
9437
23f87bed
MB
9438(defun gnus-summary-show-raw-article ()
9439 "Show the raw article without any article massaging functions being run."
9440 (interactive)
9441 (gnus-summary-show-article t))
9442
eec82323
LMI
9443(defun gnus-summary-verbose-headers (&optional arg)
9444 "Toggle permanent full header display.
9445If ARG is a positive number, turn header display on.
9446If ARG is a negative number, turn header display off."
9447 (interactive "P")
eec82323
LMI
9448 (setq gnus-show-all-headers
9449 (cond ((or (not (numberp arg))
9450 (zerop arg))
9451 (not gnus-show-all-headers))
9452 ((natnump arg)
9453 t)))
9454 (gnus-summary-show-article))
9455
9456(defun gnus-summary-toggle-header (&optional arg)
9457 "Show the headers if they are hidden, or hide them if they are shown.
9458If ARG is a positive number, show the entire header.
9459If ARG is a negative number, hide the unwanted header lines."
9460 (interactive "P")
23f87bed
MB
9461 (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9462 (get-buffer-window gnus-article-buffer t))))
9463 (with-current-buffer gnus-article-buffer
9464 (widen)
9465 (article-narrow-to-head)
c7a91ce1 9466 (let* ((inhibit-read-only t)
16409b0b 9467 (inhibit-point-motion-hooks t)
23f87bed
MB
9468 (hidden (if (numberp arg)
9469 (>= arg 0)
f0096211
MB
9470 (or (not (looking-at "[^ \t\n]+:"))
9471 (gnus-article-hidden-text-p 'headers))))
23f87bed
MB
9472 s e)
9473 (delete-region (point-min) (point-max))
667e0ba6
SM
9474 (with-current-buffer gnus-original-article-buffer
9475 (goto-char (setq s (point-min)))
23f87bed
MB
9476 (setq e (if (search-forward "\n\n" nil t)
9477 (1- (point))
9478 (point-max))))
667e0ba6 9479 (insert-buffer-substring gnus-original-article-buffer s e)
23f87bed
MB
9480 (run-hooks 'gnus-article-decode-hook)
9481 (if hidden
9482 (let ((gnus-treat-hide-headers nil)
9483 (gnus-treat-hide-boring-headers nil))
9484 (gnus-delete-wash-type 'headers)
9485 (gnus-treat-article 'head))
9486 (gnus-treat-article 'head))
9487 (widen)
9488 (if window
9489 (set-window-start window (goto-char (point-min))))
9490 (if gnus-break-pages
9491 (gnus-narrow-to-page)
9492 (when (gnus-visual-p 'page-marker)
c7a91ce1 9493 (let ((inhibit-read-only t))
23f87bed
MB
9494 (gnus-remove-text-with-property 'gnus-prev)
9495 (gnus-remove-text-with-property 'gnus-next))))
16409b0b 9496 (gnus-set-mode-line 'article)))))
eec82323
LMI
9497
9498(defun gnus-summary-show-all-headers ()
9499 "Make all header lines visible."
9500 (interactive)
23f87bed 9501 (gnus-summary-toggle-header 1))
eec82323 9502
eec82323
LMI
9503(defun gnus-summary-caesar-message (&optional arg)
9504 "Caesar rotate the current article by 13.
01c52d31
MB
9505With a non-numerical prefix, also rotate headers. A numerical
9506prefix specifies how many places to rotate each letter forward."
eec82323 9507 (interactive "P")
eec82323
LMI
9508 (gnus-summary-select-article)
9509 (let ((mail-header-separator ""))
9510 (gnus-eval-in-buffer-window gnus-article-buffer
9511 (save-restriction
9512 (widen)
9513 (let ((start (window-start))
c7a91ce1 9514 (inhibit-read-only t))
01c52d31
MB
9515 (if (equal arg '(4))
9516 (message-caesar-buffer-body nil t)
9517 (message-caesar-buffer-body arg))
ff4d3926
MB
9518 (set-window-start (get-buffer-window (current-buffer)) start)))))
9519 ;; Create buttons and stuff...
9520 (gnus-treat-article nil))
eec82323 9521
704f1663
GM
9522(declare-function idna-to-unicode "ext:idna" (str))
9523
01c52d31
MB
9524(defun gnus-summary-idna-message (&optional arg)
9525 "Decode IDNA encoded domain names in the current articles.
9526IDNA encoded domain names looks like `xn--bar'. If a string
9527remain unencoded after running this function, it is likely an
9528invalid IDNA string (`xn--bar' is invalid).
9529
0b10e437 9530You must have GNU Libidn (URL `http://www.gnu.org/software/libidn/')
01c52d31
MB
9531installed for this command to work."
9532 (interactive "P")
9533 (if (not (and (condition-case nil (require 'idna)
9534 (file-error))
9535 (mm-coding-system-p 'utf-8)
9536 (executable-find (symbol-value 'idna-program))))
9537 (gnus-message
9538 5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9539 (gnus-summary-select-article)
9540 (let ((mail-header-separator ""))
9541 (gnus-eval-in-buffer-window gnus-article-buffer
9542 (save-restriction
9543 (widen)
9544 (let ((start (window-start))
9545 buffer-read-only)
9546 (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9547 (replace-match (idna-to-unicode (match-string 1))))
9548 (set-window-start (get-buffer-window (current-buffer)) start)))))))
23f87bed
MB
9549
9550(defun gnus-summary-morse-message (&optional arg)
9551 "Morse decode the current article."
9552 (interactive "P")
9553 (gnus-summary-select-article)
9554 (let ((mail-header-separator ""))
9555 (gnus-eval-in-buffer-window gnus-article-buffer
9556 (save-excursion
9557 (save-restriction
9558 (widen)
9559 (let ((pos (window-start))
c7a91ce1 9560 (inhibit-read-only t))
23f87bed
MB
9561 (goto-char (point-min))
9562 (when (message-goto-body)
9563 (gnus-narrow-to-body))
9564 (goto-char (point-min))
01c52d31 9565