Misc Gnus fixes by Lars Magne Ingebrigtsen <larsi@gnus.org>.
[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
83 :type 'boolean)
84
eec82323
LMI
85(defcustom gnus-fetch-old-headers nil
86 "*Non-nil means that Gnus will try to build threads by grabbing old headers.
01c52d31
MB
87If an unread article in the group refers to an older, already
88read (or just marked as read) article, the old article will not
89normally be displayed in the Summary buffer. If this variable is
90t, Gnus will attempt to grab the headers to the old articles, and
91thereby build complete threads. If it has the value `some', all
92old headers will be fetched but only enough headers to connect
93otherwise loose threads will be displayed. This variable can
94also be a number. In that case, no more than that number of old
95headers will be fetched. If it has the value `invisible', all
6748645f 96old headers will be fetched, but none will be displayed.
eec82323 97
01c52d31
MB
98The server has to support NOV for any of this to work.
99
100This feature can seriously impact performance it ignores all
f394fa25
MB
101locally cached header entries. Setting it to t for groups for a
102server that doesn't expire articles (such as news.gmane.org),
103leads to very slow summary generation."
eec82323
LMI
104 :group 'gnus-thread
105 :type '(choice (const :tag "off" nil)
1232b9cb 106 (const :tag "on" t)
eec82323 107 (const some)
1232b9cb 108 (const invisible)
eec82323
LMI
109 number
110 (sexp :menu-tag "other" t)))
111
01c52d31 112(defcustom gnus-refer-thread-limit 500
6748645f
LMI
113 "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
114If t, fetch all the available old headers."
115 :group 'gnus-thread
116 :type '(choice number
117 (sexp :menu-tag "other" t)))
118
eec82323
LMI
119(defcustom gnus-summary-make-false-root 'adopt
120 "*nil means that Gnus won't gather loose threads.
121If the root of a thread has expired or been read in a previous
122session, the information necessary to build a complete thread has been
123lost. Instead of having many small sub-threads from this original thread
124scattered all over the summary buffer, Gnus can gather them.
125
126If non-nil, Gnus will try to gather all loose sub-threads from an
127original thread into one large thread.
128
129If this variable is non-nil, it should be one of `none', `adopt',
130`dummy' or `empty'.
131
132If this variable is `none', Gnus will not make a false root, but just
133present the sub-threads after another.
134If this variable is `dummy', Gnus will create a dummy root that will
135have all the sub-threads as children.
136If this variable is `adopt', Gnus will make one of the \"children\"
137the parent and mark all the step-children as such.
138If this variable is `empty', the \"children\" are printed with empty
01ccbb85 139subject fields. (Or rather, they will be printed with a string
eec82323
LMI
140given by the `gnus-summary-same-subject' variable.)"
141 :group 'gnus-thread
142 :type '(choice (const :tag "off" nil)
143 (const none)
144 (const dummy)
145 (const adopt)
146 (const empty)))
147
23f87bed
MB
148(defcustom gnus-summary-make-false-root-always nil
149 "Always make a false dummy root."
bf247b6e 150 :version "22.1"
23f87bed
MB
151 :group 'gnus-thread
152 :type 'boolean)
153
eec82323
LMI
154(defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
155 "*A regexp to match subjects to be excluded from loose thread gathering.
156As loose thread gathering is done on subjects only, that means that
157there can be many false gatherings performed. By rooting out certain
158common subjects, gathering might become saner."
159 :group 'gnus-thread
160 :type 'regexp)
161
162(defcustom gnus-summary-gather-subject-limit nil
163 "*Maximum length of subject comparisons when gathering loose threads.
164Use nil to compare full subjects. Setting this variable to a low
165number will help gather threads that have been corrupted by
166newsreaders chopping off subject lines, but it might also mean that
167unrelated articles that have subject that happen to begin with the
168same few characters will be incorrectly gathered.
169
170If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
171comparing subjects."
172 :group 'gnus-thread
173 :type '(choice (const :tag "off" nil)
174 (const fuzzy)
175 (sexp :menu-tag "on" t)))
176
6748645f
LMI
177(defcustom gnus-simplify-subject-functions nil
178 "List of functions taking a string argument that simplify subjects.
179The functions are applied recursively.
180
23f87bed
MB
181Useful functions to put in this list include:
182`gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
183`gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
6748645f
LMI
184 :group 'gnus-thread
185 :type '(repeat function))
186
eec82323 187(defcustom gnus-simplify-ignored-prefixes nil
23f87bed 188 "*Remove matches for this regexp from subject lines when simplifying fuzzily."
eec82323
LMI
189 :group 'gnus-thread
190 :type '(choice (const :tag "off" nil)
191 regexp))
192
193(defcustom gnus-build-sparse-threads nil
194 "*If non-nil, fill in the gaps in threads.
195If `some', only fill in the gaps that are needed to tie loose threads
196together. If `more', fill in all leaf nodes that Gnus can find. If
197non-nil and non-`some', fill in all gaps that Gnus manages to guess."
198 :group 'gnus-thread
199 :type '(choice (const :tag "off" nil)
200 (const some)
201 (const more)
202 (sexp :menu-tag "all" t)))
203
204(defcustom gnus-summary-thread-gathering-function
205 'gnus-gather-threads-by-subject
6748645f 206 "*Function used for gathering loose threads.
eec82323
LMI
207There are two pre-defined functions: `gnus-gather-threads-by-subject',
208which only takes Subjects into consideration; and
209`gnus-gather-threads-by-references', which compared the References
210headers of the articles to find matches."
211 :group 'gnus-thread
22115a9e
RS
212 :type '(radio (function-item gnus-gather-threads-by-subject)
213 (function-item gnus-gather-threads-by-references)
214 (function :tag "other")))
eec82323 215
eec82323
LMI
216(defcustom gnus-summary-same-subject ""
217 "*String indicating that the current article has the same subject as the previous.
218This variable will only be used if the value of
219`gnus-summary-make-false-root' is `empty'."
220 :group 'gnus-summary-format
221 :type 'string)
222
223(defcustom gnus-summary-goto-unread t
16409b0b
GM
224 "*If t, many commands will go to the next unread article.
225This applies to marking commands as well as other commands that
226\"naturally\" select the next article, like, for instance, `SPC' at
227the end of an article.
228
229If nil, the marking commands do NOT go to the next unread article
2642ac8f 230\(they go to the next article instead). If `never', commands that
16409b0b
GM
231usually go to the next unread article, will go to the next article,
232whether it is read or not."
eec82323
LMI
233 :group 'gnus-summary-marks
234 :link '(custom-manual "(gnus)Setting Marks")
235 :type '(choice (const :tag "off" nil)
236 (const never)
237 (sexp :menu-tag "on" t)))
238
239(defcustom gnus-summary-default-score 0
240 "*Default article score level.
241All scores generated by the score files will be added to this score.
242If this variable is nil, scoring will be disabled."
243 :group 'gnus-score-default
244 :type '(choice (const :tag "disable")
245 integer))
246
23f87bed
MB
247(defcustom gnus-summary-default-high-score 0
248 "*Default threshold for a high scored article.
249An article will be highlighted as high scored if its score is greater
250than this score."
bf247b6e 251 :version "22.1"
23f87bed
MB
252 :group 'gnus-score-default
253 :type 'integer)
254
255(defcustom gnus-summary-default-low-score 0
256 "*Default threshold for a low scored article.
257An article will be highlighted as low scored if its score is smaller
258than this score."
bf247b6e 259 :version "22.1"
23f87bed
MB
260 :group 'gnus-score-default
261 :type 'integer)
262
eec82323
LMI
263(defcustom gnus-summary-zcore-fuzz 0
264 "*Fuzziness factor for the zcore in the summary buffer.
265Articles with scores closer than this to `gnus-summary-default-score'
266will not be marked."
267 :group 'gnus-summary-format
268 :type 'integer)
269
270(defcustom gnus-simplify-subject-fuzzy-regexp nil
271 "*Strings to be removed when doing fuzzy matches.
272This can either be a regular expression or list of regular expressions
273that will be removed from subject strings if fuzzy subject
274simplification is selected."
275 :group 'gnus-thread
276 :type '(repeat regexp))
277
278(defcustom gnus-show-threads t
279 "*If non-nil, display threads in summary mode."
280 :group 'gnus-thread
281 :type 'boolean)
282
283(defcustom gnus-thread-hide-subtree nil
284 "*If non-nil, hide all threads initially.
23f87bed 285This can be a predicate specifier which says which threads to hide.
eec82323 286If threads are hidden, you have to run the command
4a2358e9 287`gnus-summary-show-thread' by hand or select an article."
eec82323 288 :group 'gnus-thread
23f87bed
MB
289 :type '(radio (sexp :format "Non-nil\n"
290 :match (lambda (widget value)
291 (not (or (consp value) (functionp value))))
292 :value t)
293 (const nil)
ad136a7c 294 (sexp :tag "Predicate specifier")))
eec82323
LMI
295
296(defcustom gnus-thread-hide-killed t
297 "*If non-nil, hide killed threads automatically."
298 :group 'gnus-thread
299 :type 'boolean)
300
6748645f
LMI
301(defcustom gnus-thread-ignore-subject t
302 "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
303If nil, articles that have different subjects from their parents will
304start separate threads."
eec82323
LMI
305 :group 'gnus-thread
306 :type 'boolean)
307
308(defcustom gnus-thread-operation-ignore-subject t
309 "*If non-nil, subjects will be ignored when doing thread commands.
310This affects commands like `gnus-summary-kill-thread' and
311`gnus-summary-lower-thread'.
312
313If this variable is nil, articles in the same thread with different
314subjects will not be included in the operation in question. If this
315variable is `fuzzy', only articles that have subjects that are fuzzily
316equal will be included."
317 :group 'gnus-thread
318 :type '(choice (const :tag "off" nil)
319 (const fuzzy)
320 (sexp :tag "on" t)))
321
322(defcustom gnus-thread-indent-level 4
323 "*Number that says how much each sub-thread should be indented."
324 :group 'gnus-thread
325 :type 'integer)
326
327(defcustom gnus-auto-extend-newsgroup t
328 "*If non-nil, extend newsgroup forward and backward when requested."
329 :group 'gnus-summary-choose
330 :type 'boolean)
331
332(defcustom gnus-auto-select-first t
651408cb
MB
333 "If non-nil, select an article on group entry.
334An article is selected automatically when entering a group
335e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
336`gnus-summary-catchup-and-goto-next-group'.
337
338Which article is selected is controlled by the variable
339`gnus-auto-select-subject'.
23f87bed
MB
340
341If you want to prevent automatic selection of articles in some
342newsgroups, set the variable to nil in `gnus-select-group-hook'."
651408cb
MB
343 ;; Commands include...
344 ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
345 ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
346 ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
eec82323
LMI
347 :group 'gnus-group-select
348 :type '(choice (const :tag "none" nil)
23f87bed
MB
349 (sexp :menu-tag "first" t)))
350
351(defcustom gnus-auto-select-subject 'unread
352 "*Says what subject to place under point when entering a group.
353
354This variable can either be the symbols `first' (place point on the
355first subject), `unread' (place point on the subject line of the first
356unread article), `best' (place point on the subject line of the
357higest-scored article), `unseen' (place point on the subject line of
99b5aab7 358the first unseen article), `unseen-or-unread' (place point on the subject
23f87bed
MB
359line of the first unseen article or, if all article have been seen, on the
360subject line of the first unread article), or a function to be called to
361place point on some subject line."
bf247b6e 362 :version "22.1"
23f87bed
MB
363 :group 'gnus-group-select
364 :type '(choice (const best)
365 (const unread)
366 (const first)
367 (const unseen)
368 (const unseen-or-unread)))
eec82323
LMI
369
370(defcustom gnus-auto-select-next t
371 "*If non-nil, offer to go to the next group from the end of the previous.
372If the value is t and the next newsgroup is empty, Gnus will exit
23f87bed
MB
373summary mode and go back to group mode. If the value is neither nil
374nor t, Gnus will select the following unread newsgroup. In
eec82323
LMI
375particular, if the value is the symbol `quietly', the next unread
376newsgroup will be selected without any confirmation, and if it is
377`almost-quietly', the next group will be selected without any
378confirmation if you are located on the last article in the group.
23f87bed 379Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
eec82323
LMI
380will go to the next group without confirmation."
381 :group 'gnus-summary-maneuvering
382 :type '(choice (const :tag "off" nil)
383 (const quietly)
384 (const almost-quietly)
385 (const slightly-quietly)
386 (sexp :menu-tag "on" t)))
387
388(defcustom gnus-auto-select-same nil
6748645f
LMI
389 "*If non-nil, select the next article with the same subject.
390If there are no more articles with the same subject, go to
391the first unread article."
eec82323
LMI
392 :group 'gnus-summary-maneuvering
393 :type 'boolean)
394
01c52d31
MB
395(defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
396 "What article should be selected after exiting an ephemeral group.
397Valid values include:
398
399`next'
400 Select the next article.
401`next-unread'
402 Select the next unread article.
403`next-noselect'
404 Move the cursor to the next article. This is the default.
405`next-unread-noselect'
406 Move the cursor to the next unread article.
407
408If it has any other value or there is no next (unread) article, the
409article selected before entering to the ephemeral group will appear."
330f707b 410 :version "23.1" ;; No Gnus
01c52d31
MB
411 :group 'gnus-summary-maneuvering
412 :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
413 (const next) (const next-unread)
414 (const next-noselect) (const next-unread-noselect)
415 (sexp :tag "other" :value nil)))
416
23f87bed
MB
417(defcustom gnus-auto-goto-ignores 'unfetched
418 "*Says how to handle unfetched articles when maneuvering.
419
420This variable can either be the symbols nil (maneuver to any
421article), `undownloaded' (maneuvering while unplugged ignores articles
422that have not been fetched), `always-undownloaded' (maneuvering always
423ignores articles that have not been fetched), `unfetched' (maneuvering
424ignores articles whose headers have not been fetched).
425
426NOTE: The list of unfetched articles will always be nil when plugged
427and, when unplugged, a subset of the undownloaded article list."
bf247b6e 428 :version "22.1"
23f87bed
MB
429 :group 'gnus-summary-maneuvering
430 :type '(choice (const :tag "None" nil)
431 (const :tag "Undownloaded when unplugged" undownloaded)
432 (const :tag "Undownloaded" always-undownloaded)
433 (const :tag "Unfetched" unfetched)))
434
eec82323
LMI
435(defcustom gnus-summary-check-current nil
436 "*If non-nil, consider the current article when moving.
437The \"unread\" movement commands will stay on the same line if the
438current article is unread."
439 :group 'gnus-summary-maneuvering
440 :type 'boolean)
441
01c52d31 442(defcustom gnus-auto-center-summary 2
eec82323
LMI
443 "*If non-nil, always center the current summary buffer.
444In particular, if `vertical' do only vertical recentering. If non-nil
445and non-`vertical', do both horizontal and vertical recentering."
446 :group 'gnus-summary-maneuvering
447 :type '(choice (const :tag "none" nil)
448 (const vertical)
16409b0b 449 (integer :tag "height")
eec82323
LMI
450 (sexp :menu-tag "both" t)))
451
23f87bed
MB
452(defvar gnus-auto-center-group t
453 "*If non-nil, always center the group buffer.")
454
eec82323
LMI
455(defcustom gnus-show-all-headers nil
456 "*If non-nil, don't hide any headers."
457 :group 'gnus-article-hiding
458 :group 'gnus-article-headers
459 :type 'boolean)
460
461(defcustom gnus-summary-ignore-duplicates nil
462 "*If non-nil, ignore articles with identical Message-ID headers."
463 :group 'gnus-summary
464 :type 'boolean)
6748645f 465
eec82323
LMI
466(defcustom gnus-single-article-buffer t
467 "*If non-nil, display all articles in the same buffer.
468If nil, each group will get its own article buffer."
469 :group 'gnus-article-various
470 :type 'boolean)
471
472(defcustom gnus-break-pages t
473 "*If non-nil, do page breaking on articles.
474The page delimiter is specified by the `gnus-page-delimiter'
475variable."
476 :group 'gnus-article-various
477 :type 'boolean)
478
eec82323
LMI
479(defcustom gnus-move-split-methods nil
480 "*Variable used to suggest where articles are to be moved to.
23f87bed
MB
481It uses the same syntax as the `gnus-split-methods' variable.
482However, whereas `gnus-split-methods' specifies file names as targets,
483this variable specifies group names."
eec82323 484 :group 'gnus-summary-mail
6748645f
LMI
485 :type '(repeat (choice (list :value (fun) function)
486 (cons :value ("" "") regexp (repeat string))
487 (sexp :value nil))))
eec82323 488
01c52d31
MB
489(defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
490 "Function used to compute default prefix for article move/copy/etc prompts.
491The function should take one argument, a group name, and return a
492string with the suggested prefix."
493 :group 'gnus-summary-mail
494 :type 'function)
495
e62e7654
MB
496;; FIXME: Although the custom type is `character' for the following variables,
497;; using multibyte characters (Latin-1, UTF-8) doesn't work. -- rs
498
23f87bed 499(defcustom gnus-unread-mark ? ;Whitespace
eec82323
LMI
500 "*Mark used for unread articles."
501 :group 'gnus-summary-marks
502 :type 'character)
503
504(defcustom gnus-ticked-mark ?!
505 "*Mark used for ticked articles."
506 :group 'gnus-summary-marks
507 :type 'character)
508
509(defcustom gnus-dormant-mark ??
510 "*Mark used for dormant articles."
511 :group 'gnus-summary-marks
512 :type 'character)
513
514(defcustom gnus-del-mark ?r
515 "*Mark used for del'd articles."
516 :group 'gnus-summary-marks
517 :type 'character)
518
519(defcustom gnus-read-mark ?R
520 "*Mark used for read articles."
521 :group 'gnus-summary-marks
522 :type 'character)
523
524(defcustom gnus-expirable-mark ?E
525 "*Mark used for expirable articles."
526 :group 'gnus-summary-marks
527 :type 'character)
528
529(defcustom gnus-killed-mark ?K
530 "*Mark used for killed articles."
531 :group 'gnus-summary-marks
532 :type 'character)
533
23f87bed
MB
534(defcustom gnus-spam-mark ?$
535 "*Mark used for spam articles."
bf247b6e 536 :version "22.1"
23f87bed
MB
537 :group 'gnus-summary-marks
538 :type 'character)
539
eec82323 540(defcustom gnus-souped-mark ?F
23f87bed 541 "*Mark used for souped articles."
eec82323
LMI
542 :group 'gnus-summary-marks
543 :type 'character)
544
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
668 gnus-souped-mark gnus-duplicate-mark)
669 "*The list of marks converted into expiration if a group is auto-expirable."
58e39d05 670 :version "21.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
990(defcustom gnus-summary-update-hook
991 (list 'gnus-summary-highlight-line)
992 "*A hook called when a summary line is changed.
993The hook will not be called if `gnus-visual' is nil.
994
995The default function `gnus-summary-highlight-line' will
996highlight the line according to the `gnus-summary-highlight'
997variable."
998 :group 'gnus-summary-visual
999 :type 'hook)
1000
1001(defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
1002 "*A hook called when an article is selected for the first time.
1003The hook is intended to mark an article as read (or unread)
1004automatically when it is selected."
1005 :group 'gnus-summary-choose
1006 :type 'hook)
1007
1008(defcustom gnus-group-no-more-groups-hook nil
1009 "*A hook run when returning to group mode having no more (unread) groups."
1010 :group 'gnus-group-select
1011 :type 'hook)
1012
1013(defcustom gnus-ps-print-hook nil
1014 "*A hook run before ps-printing something from Gnus."
1015 :group 'gnus-summary
1016 :type 'hook)
1017
23f87bed
MB
1018(defcustom gnus-summary-article-move-hook nil
1019 "*A hook called after an article is moved, copied, respooled, or crossposted."
bf247b6e 1020 :version "22.1"
23f87bed
MB
1021 :group 'gnus-summary
1022 :type 'hook)
1023
1024(defcustom gnus-summary-article-delete-hook nil
1025 "*A hook called after an article is deleted."
bf247b6e 1026 :version "22.1"
23f87bed
MB
1027 :group 'gnus-summary
1028 :type 'hook)
1029
1030(defcustom gnus-summary-article-expire-hook nil
1031 "*A hook called after an article is expired."
bf247b6e 1032 :version "22.1"
23f87bed
MB
1033 :group 'gnus-summary
1034 :type 'hook)
1035
1036(defcustom gnus-summary-display-arrow
1037 (and (fboundp 'display-graphic-p)
1038 (display-graphic-p))
1039 "*If non-nil, display an arrow highlighting the current article."
bf247b6e 1040 :version "22.1"
23f87bed
MB
1041 :group 'gnus-summary
1042 :type 'boolean)
1043
0f49874b 1044(defcustom gnus-summary-selected-face 'gnus-summary-selected
eec82323
LMI
1045 "Face used for highlighting the current article in the summary buffer."
1046 :group 'gnus-summary-visual
1047 :type 'face)
1048
23f87bed
MB
1049(defvar gnus-tmp-downloaded nil)
1050
eec82323 1051(defcustom gnus-summary-highlight
23f87bed 1052 '(((eq mark gnus-canceled-mark)
0f49874b 1053 . gnus-summary-cancelled)
23f87bed 1054 ((and uncached (> score default-high))
0f49874b 1055 . gnus-summary-high-undownloaded)
23f87bed 1056 ((and uncached (< score default-low))
0f49874b 1057 . gnus-summary-low-undownloaded)
23f87bed 1058 (uncached
0f49874b 1059 . gnus-summary-normal-undownloaded)
23f87bed
MB
1060 ((and (> score default-high)
1061 (or (eq mark gnus-dormant-mark)
1062 (eq mark gnus-ticked-mark)))
0f49874b 1063 . gnus-summary-high-ticked)
23f87bed
MB
1064 ((and (< score default-low)
1065 (or (eq mark gnus-dormant-mark)
1066 (eq mark gnus-ticked-mark)))
0f49874b 1067 . gnus-summary-low-ticked)
23f87bed
MB
1068 ((or (eq mark gnus-dormant-mark)
1069 (eq mark gnus-ticked-mark))
0f49874b 1070 . gnus-summary-normal-ticked)
23f87bed 1071 ((and (> score default-high) (eq mark gnus-ancient-mark))
0f49874b 1072 . gnus-summary-high-ancient)
23f87bed 1073 ((and (< score default-low) (eq mark gnus-ancient-mark))
0f49874b 1074 . gnus-summary-low-ancient)
23f87bed 1075 ((eq mark gnus-ancient-mark)
0f49874b 1076 . gnus-summary-normal-ancient)
23f87bed 1077 ((and (> score default-high) (eq mark gnus-unread-mark))
0f49874b 1078 . gnus-summary-high-unread)
23f87bed 1079 ((and (< score default-low) (eq mark gnus-unread-mark))
0f49874b 1080 . gnus-summary-low-unread)
23f87bed 1081 ((eq mark gnus-unread-mark)
0f49874b 1082 . gnus-summary-normal-unread)
23f87bed 1083 ((> score default-high)
0f49874b 1084 . gnus-summary-high-read)
23f87bed 1085 ((< score default-low)
0f49874b 1086 . gnus-summary-low-read)
eec82323 1087 (t
0f49874b 1088 . gnus-summary-normal-read))
6748645f 1089 "*Controls the highlighting of summary buffer lines.
eec82323 1090
107cf8ec 1091A list of (FORM . FACE) pairs. When deciding how a particular
23f87bed
MB
1092summary line should be displayed, each form is evaluated. The content
1093of the face field after the first true form is used. You can change
1094how those summary lines are displayed, by editing the face field.
eec82323
LMI
1095
1096You can use the following variables in the FORM field.
1097
107cf8ec 1098score: The article's score.
23f87bed
MB
1099default: The default article score.
1100default-high: The default score for high scored articles.
1101default-low: The default score for low scored articles.
1102below: The score below which articles are automatically marked as read.
1103mark: The article's mark.
1104uncached: Non-nil if the article is uncached."
eec82323
LMI
1105 :group 'gnus-summary-visual
1106 :type '(repeat (cons (sexp :tag "Form" nil)
1107 face)))
c12ecb0a 1108(put 'gnus-summary-highlight 'risky-local-variable t)
eec82323 1109
6748645f
LMI
1110(defcustom gnus-alter-header-function nil
1111 "Function called to allow alteration of article header structures.
1112The function is called with one parameter, the article header vector,
0ab0f2d3
SZ
1113which it may alter in any way."
1114 :type '(choice (const :tag "None" nil)
1115 function)
1116 :group 'gnus-summary)
eec82323 1117
16409b0b 1118(defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
343d6628
MB
1119 "Function used to decode a string with encoded words.")
1120
1121(defvar gnus-decode-encoded-address-function
1122 'mail-decode-encoded-address-string
1123 "Function used to decode addresses with encoded words.")
16409b0b 1124
23f87bed 1125(defcustom gnus-extra-headers '(To Newsgroups)
16409b0b 1126 "*Extra headers to parse."
58e39d05 1127 :version "21.1"
16409b0b
GM
1128 :group 'gnus-summary
1129 :type '(repeat symbol))
1130
1131(defcustom gnus-ignored-from-addresses
343d6628 1132 (and user-mail-address
7cd9f860
CY
1133 (not (string= user-mail-address ""))
1134 (regexp-quote user-mail-address))
01c52d31
MB
1135 "*From headers that may be suppressed in favor of To headers.
1136This can be a regexp or a list of regexps."
58e39d05 1137 :version "21.1"
16409b0b 1138 :group 'gnus-summary
01c52d31
MB
1139 :type '(choice regexp
1140 (repeat :tag "Regexp List" regexp)))
1141
1142(defsubst gnus-ignored-from-addresses ()
1143 (gmm-regexp-concat gnus-ignored-from-addresses))
1144
1145(defcustom gnus-summary-to-prefix "-> "
1146 "*String prefixed to the To field in the summary line when
1147using `gnus-ignored-from-addresses'."
1148 :version "22.1"
1149 :group 'gnus-summary
1150 :type 'string)
1151
1152(defcustom gnus-summary-newsgroup-prefix "=> "
1153 "*String prefixed to the Newsgroup field in the summary
1154line when using `gnus-ignored-from-addresses'."
1155 :version "22.1"
1156 :group 'gnus-summary
1157 :type 'string)
16409b0b 1158
16409b0b
GM
1159(defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1160 "List of charsets that should be ignored.
1161When these charsets are used in the \"charset\" parameter, the
1162default charset will be used instead."
58e39d05 1163 :version "21.1"
16409b0b
GM
1164 :type '(repeat symbol)
1165 :group 'gnus-charset)
1166
4b70e299
MB
1167(defcustom gnus-newsgroup-maximum-articles nil
1168 "The maximum number of articles a newsgroup.
1169If this is a number, old articles in a newsgroup exceeding this number
1170are silently ignored. If it is nil, no article is ignored. Note that
1171setting this variable to a number might prevent you from reading very
1172old articles."
1173 :group 'gnus-group-select
1174 :version "22.2"
1175 :type '(choice (const :tag "No limit" nil)
1176 integer))
1177
23f87bed
MB
1178(gnus-define-group-parameter
1179 ignored-charsets
1180 :type list
1181 :function-document
1182 "Return the ignored charsets of GROUP."
1183 :variable gnus-group-ignored-charsets-alist
1184 :variable-default
1185 '(("alt\\.chinese\\.text" iso-8859-1))
1186 :variable-document
1187 "Alist of regexps (to match group names) and charsets that should be ignored.
16409b0b
GM
1188When these charsets are used in the \"charset\" parameter, the
1189default charset will be used instead."
23f87bed
MB
1190 :variable-group gnus-charset
1191 :variable-type '(repeat (cons (regexp :tag "Group")
1192 (repeat symbol)))
1193 :parameter-type '(choice :tag "Ignored charsets"
1194 :value nil
1195 (repeat (symbol)))
1196 :parameter-document "\
1197List of charsets that should be ignored.
1198
1199When these charsets are used in the \"charset\" parameter, the
1200default charset will be used instead.")
16409b0b
GM
1201
1202(defcustom gnus-group-highlight-words-alist nil
1203 "Alist of group regexps and highlight regexps.
1204This variable uses the same syntax as `gnus-emphasis-alist'."
58e39d05 1205 :version "21.1"
16409b0b
GM
1206 :type '(repeat (cons (regexp :tag "Group")
1207 (repeat (list (regexp :tag "Highlight regexp")
1208 (number :tag "Group for entire word" 0)
1209 (number :tag "Group for displayed part" 0)
1210 (symbol :tag "Face"
1211 gnus-emphasis-highlight-words)))))
1212 :group 'gnus-summary-visual)
1213
1214(defcustom gnus-summary-show-article-charset-alist
1215 nil
1216 "Alist of number and charset.
1217The article will be shown with the charset corresponding to the
1218numbered argument.
1219For example: ((1 . cn-gb-2312) (2 . big5))."
58e39d05 1220 :version "21.1"
16409b0b
GM
1221 :type '(repeat (cons (number :tag "Argument" 1)
1222 (symbol :tag "Charset")))
1223 :group 'gnus-charset)
1224
1225(defcustom gnus-preserve-marks t
1226 "Whether marks are preserved when moving, copying and respooling messages."
58e39d05 1227 :version "21.1"
16409b0b
GM
1228 :type 'boolean
1229 :group 'gnus-summary-marks)
1230
3a23a519
MB
1231(defcustom gnus-propagate-marks t
1232 "If non-nil, do not propagate marks to the backends."
f8a29505 1233 :version "23.1" ;; No Gnus
3a23a519
MB
1234 :type 'boolean
1235 :group 'gnus-summary-marks)
1236
16409b0b
GM
1237(defcustom gnus-alter-articles-to-read-function nil
1238 "Function to be called to alter the list of articles to be selected."
8fc7a9a1 1239 :type '(choice (const nil) function)
16409b0b
GM
1240 :group 'gnus-summary)
1241
1242(defcustom gnus-orphan-score nil
1243 "*All orphans get this score added. Set in the score file."
1244 :group 'gnus-score-default
1245 :type '(choice (const nil)
1246 integer))
1247
8b93df01 1248(defcustom gnus-summary-save-parts-default-mime "image/.*"
23f87bed
MB
1249 "*A regexp to match MIME parts when saving multiple parts of a
1250message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1251This regexp will be used by default when prompting the user for which
1252type of files to save."
8b93df01
DL
1253 :group 'gnus-summary
1254 :type 'regexp)
1255
23f87bed
MB
1256(defcustom gnus-read-all-available-headers nil
1257 "Whether Gnus should parse all headers made available to it.
1258This is mostly relevant for slow back ends where the user may
1259wish to widen the summary buffer to include all headers
1260that were fetched. Say, for nnultimate groups."
bf247b6e 1261 :version "22.1"
23f87bed
MB
1262 :group 'gnus-summary
1263 :type '(choice boolean regexp))
1264
89167438
MB
1265(defcustom gnus-summary-pipe-output-default-command nil
1266 "Command (and optional arguments) used to pipe article to subprocess.
1267This will be used as the default command if it is non-nil. The value
1268will be updated if you modify it when executing the command
1269`gnus-summary-pipe-output' or the function `gnus-summary-save-in-pipe'."
1270 :version "23.1" ;; No Gnus
1271 :group 'gnus-summary
1272 :type '(radio (const :tag "None" nil) (string :tag "Command")))
1273
23f87bed 1274(defcustom gnus-summary-muttprint-program "muttprint"
89167438
MB
1275 "Command (and optional arguments) used to run Muttprint.
1276The value will be updated if you modify it when executing the command
1277`gnus-summary-muttprint'."
bf247b6e 1278 :version "22.1"
23f87bed
MB
1279 :group 'gnus-summary
1280 :type 'string)
1281
01c52d31 1282(defcustom gnus-article-loose-mime t
23f87bed
MB
1283 "If non-nil, don't require MIME-Version header.
1284Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
a08b59c9 1285supply the MIME-Version header or deliberately strip it from the mail.
01c52d31
MB
1286If non-nil (the default), Gnus will treat some articles as MIME
1287even if the MIME-Version header is missing."
bf247b6e 1288 :version "22.1"
23f87bed
MB
1289 :type 'boolean
1290 :group 'gnus-article-mime)
1291
1292(defcustom gnus-article-emulate-mime t
1293 "If non-nil, use MIME emulation for uuencode and the like.
1294This means that Gnus will search message bodies for text that look
1295like uuencoded bits, yEncoded bits, and so on, and present that using
1296the normal Gnus MIME machinery."
bf247b6e 1297 :version "22.1"
23f87bed
MB
1298 :type 'boolean
1299 :group 'gnus-article-mime)
8b93df01 1300
eec82323
LMI
1301;;; Internal variables
1302
23f87bed 1303(defvar gnus-summary-display-cache nil)
16409b0b
GM
1304(defvar gnus-article-mime-handles nil)
1305(defvar gnus-article-decoded-p nil)
23f87bed
MB
1306(defvar gnus-article-charset nil)
1307(defvar gnus-article-ignored-charsets nil)
eec82323
LMI
1308(defvar gnus-scores-exclude-files nil)
1309(defvar gnus-page-broken nil)
1310
1311(defvar gnus-original-article nil)
1312(defvar gnus-article-internal-prepare-hook nil)
1313(defvar gnus-newsgroup-process-stack nil)
1314
1315(defvar gnus-thread-indent-array nil)
1316(defvar gnus-thread-indent-array-level gnus-thread-indent-level)
16409b0b
GM
1317(defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1318 "Function called to sort the articles within a thread after it has been gathered together.")
eec82323 1319
8b93df01 1320(defvar gnus-summary-save-parts-type-history nil)
23f87bed 1321(defvar gnus-summary-save-parts-last-directory mm-default-directory)
8b93df01 1322
eec82323
LMI
1323;; Avoid highlighting in kill files.
1324(defvar gnus-summary-inhibit-highlight nil)
1325(defvar gnus-newsgroup-selected-overlay nil)
1326(defvar gnus-inhibit-limiting nil)
1327(defvar gnus-newsgroup-adaptive-score-file nil)
1328(defvar gnus-current-score-file nil)
1329(defvar gnus-current-move-group nil)
1330(defvar gnus-current-copy-group nil)
1331(defvar gnus-current-crosspost-group nil)
23f87bed 1332(defvar gnus-newsgroup-display nil)
eec82323
LMI
1333
1334(defvar gnus-newsgroup-dependencies nil)
1335(defvar gnus-newsgroup-adaptive nil)
1336(defvar gnus-summary-display-article-function nil)
1337(defvar gnus-summary-highlight-line-function nil
1338 "Function called after highlighting a summary line.")
1339
1340(defvar gnus-summary-line-format-alist
1341 `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1342 (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1343 (?s gnus-tmp-subject-or-nil ?s)
1344 (?n gnus-tmp-name ?s)
1345 (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1346 ?s)
1347 (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1348 gnus-tmp-from) ?s)
1349 (?F gnus-tmp-from ?s)
1350 (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1351 (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1352 (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
6748645f 1353 (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
eec82323
LMI
1354 (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1355 (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1356 (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
23f87bed
MB
1357 (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1358 (?L gnus-tmp-lines ?s)
1359 (?O gnus-tmp-downloaded ?c)
eec82323
LMI
1360 (?I gnus-tmp-indentation ?s)
1361 (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1362 (?R gnus-tmp-replied ?c)
1363 (?\[ gnus-tmp-opening-bracket ?c)
1364 (?\] gnus-tmp-closing-bracket ?c)
1365 (?\> (make-string gnus-tmp-level ? ) ?s)
1366 (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1367 (?i gnus-tmp-score ?d)
1368 (?z gnus-tmp-score-char ?c)
eec82323
LMI
1369 (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1370 (?U gnus-tmp-unread ?c)
23f87bed
MB
1371 (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1372 ?s)
eec82323
LMI
1373 (?t (gnus-summary-number-of-articles-in-thread
1374 (and (boundp 'thread) (car thread)) gnus-tmp-level)
1375 ?d)
1376 (?e (gnus-summary-number-of-articles-in-thread
1377 (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1378 ?c)
1379 (?u gnus-tmp-user-defined ?s)
23f87bed
MB
1380 (?P (gnus-pick-line-number) ?d)
1381 (?B gnus-tmp-thread-tree-header-string ?s)
1382 (user-date (gnus-user-date
1383 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
16409b0b
GM
1384 "An alist of format specifications that can appear in summary lines.
1385These are paired with what variables they correspond with, along with
1386the type of the variable (string, integer, character, etc).")
eec82323
LMI
1387
1388(defvar gnus-summary-dummy-line-format-alist
1389 `((?S gnus-tmp-subject ?s)
1390 (?N gnus-tmp-number ?d)
1391 (?u gnus-tmp-user-defined ?s)))
1392
1393(defvar gnus-summary-mode-line-format-alist
1394 `((?G gnus-tmp-group-name ?s)
1395 (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1396 (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1397 (?A gnus-tmp-article-number ?d)
1398 (?Z gnus-tmp-unread-and-unselected ?s)
1399 (?V gnus-version ?s)
1400 (?U gnus-tmp-unread-and-unticked ?d)
1401 (?S gnus-tmp-subject ?s)
1402 (?e gnus-tmp-unselected ?d)
1403 (?u gnus-tmp-user-defined ?s)
1404 (?d (length gnus-newsgroup-dormant) ?d)
1405 (?t (length gnus-newsgroup-marked) ?d)
23f87bed 1406 (?h (length gnus-newsgroup-spam-marked) ?d)
eec82323 1407 (?r (length gnus-newsgroup-reads) ?d)
6748645f 1408 (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
eec82323
LMI
1409 (?E gnus-newsgroup-expunged-tally ?d)
1410 (?s (gnus-current-score-file-nondirectory) ?s)))
1411
c1717fbd
GM
1412;; This is here rather than in gnus-art for compilation reasons.
1413(defvar gnus-article-mode-line-format-alist
1414 (nconc '((?w (gnus-article-wash-status) ?s)
1415 (?m (gnus-article-mime-part-status) ?s))
1416 gnus-summary-mode-line-format-alist))
1417
eec82323
LMI
1418(defvar gnus-last-search-regexp nil
1419 "Default regexp for article search command.")
1420
1421(defvar gnus-last-shell-command nil
1422 "Default shell command on article.")
1423
23f87bed
MB
1424(defvar gnus-newsgroup-agentized nil
1425 "Locally bound in each summary buffer to indicate whether the server has been agentized.")
eec82323
LMI
1426(defvar gnus-newsgroup-begin nil)
1427(defvar gnus-newsgroup-end nil)
1428(defvar gnus-newsgroup-last-rmail nil)
1429(defvar gnus-newsgroup-last-mail nil)
1430(defvar gnus-newsgroup-last-folder nil)
1431(defvar gnus-newsgroup-last-file nil)
26c9afc3 1432(defvar gnus-newsgroup-last-directory nil)
eec82323
LMI
1433(defvar gnus-newsgroup-auto-expire nil)
1434(defvar gnus-newsgroup-active nil)
1435
1436(defvar gnus-newsgroup-data nil)
1437(defvar gnus-newsgroup-data-reverse nil)
1438(defvar gnus-newsgroup-limit nil)
1439(defvar gnus-newsgroup-limits nil)
23f87bed 1440(defvar gnus-summary-use-undownloaded-faces nil)
eec82323
LMI
1441
1442(defvar gnus-newsgroup-unreads nil
23f87bed 1443 "Sorted list of unread articles in the current newsgroup.")
eec82323
LMI
1444
1445(defvar gnus-newsgroup-unselected nil
23f87bed 1446 "Sorted list of unselected unread articles in the current newsgroup.")
eec82323
LMI
1447
1448(defvar gnus-newsgroup-reads nil
1449 "Alist of read articles and article marks in the current newsgroup.")
1450
1451(defvar gnus-newsgroup-expunged-tally nil)
1452
1453(defvar gnus-newsgroup-marked nil
23f87bed
MB
1454 "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1455
1456(defvar gnus-newsgroup-spam-marked nil
1457 "List of ranges of articles that have been marked as spam.")
eec82323
LMI
1458
1459(defvar gnus-newsgroup-killed nil
1460 "List of ranges of articles that have been through the scoring process.")
1461
1462(defvar gnus-newsgroup-cached nil
23f87bed 1463 "Sorted list of articles that come from the article cache.")
eec82323
LMI
1464
1465(defvar gnus-newsgroup-saved nil
1466 "List of articles that have been saved.")
1467
1468(defvar gnus-newsgroup-kill-headers nil)
1469
1470(defvar gnus-newsgroup-replied nil
1471 "List of articles that have been replied to in the current newsgroup.")
1472
23f87bed
MB
1473(defvar gnus-newsgroup-forwarded nil
1474 "List of articles that have been forwarded in the current newsgroup.")
1475
1476(defvar gnus-newsgroup-recent nil
1477 "List of articles that have are recent in the current newsgroup.")
1478
eec82323 1479(defvar gnus-newsgroup-expirable nil
23f87bed 1480 "Sorted list of articles in the current newsgroup that can be expired.")
eec82323
LMI
1481
1482(defvar gnus-newsgroup-processable nil
1483 "List of articles in the current newsgroup that can be processed.")
1484
6748645f 1485(defvar gnus-newsgroup-downloadable nil
23f87bed
MB
1486 "Sorted list of articles in the current newsgroup that can be processed.")
1487
1488(defvar gnus-newsgroup-unfetched nil
1489 "Sorted list of articles in the current newsgroup whose headers have
1490not been fetched into the agent.
1491
1492This list will always be a subset of gnus-newsgroup-undownloaded.")
6748645f
LMI
1493
1494(defvar gnus-newsgroup-undownloaded nil
23f87bed 1495 "List of articles in the current newsgroup that haven't been downloaded.")
6748645f
LMI
1496
1497(defvar gnus-newsgroup-unsendable nil
1498 "List of articles in the current newsgroup that won't be sent.")
1499
eec82323
LMI
1500(defvar gnus-newsgroup-bookmarks nil
1501 "List of articles in the current newsgroup that have bookmarks.")
1502
1503(defvar gnus-newsgroup-dormant nil
23f87bed
MB
1504 "Sorted list of dormant articles in the current newsgroup.")
1505
1506(defvar gnus-newsgroup-unseen nil
1507 "List of unseen articles in the current newsgroup.")
1508
1509(defvar gnus-newsgroup-seen nil
1510 "Range of seen articles in the current newsgroup.")
1511
1512(defvar gnus-newsgroup-articles nil
1513 "List of articles in the current newsgroup.")
eec82323
LMI
1514
1515(defvar gnus-newsgroup-scored nil
1516 "List of scored articles in the current newsgroup.")
1517
1518(defvar gnus-newsgroup-headers nil
1519 "List of article headers in the current newsgroup.")
1520
1521(defvar gnus-newsgroup-threads nil)
1522
1523(defvar gnus-newsgroup-prepared nil
1524 "Whether the current group has been prepared properly.")
1525
1526(defvar gnus-newsgroup-ancient nil
1527 "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1528
1529(defvar gnus-newsgroup-sparse nil)
1530
1531(defvar gnus-current-article nil)
1532(defvar gnus-article-current nil)
1533(defvar gnus-current-headers nil)
1534(defvar gnus-have-all-headers nil)
1535(defvar gnus-last-article nil)
1536(defvar gnus-newsgroup-history nil)
16409b0b
GM
1537(defvar gnus-newsgroup-charset nil)
1538(defvar gnus-newsgroup-ephemeral-charset nil)
1539(defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
eec82323 1540
23f87bed
MB
1541(defvar gnus-article-before-search nil)
1542
1543(defvar gnus-summary-local-variables
eec82323
LMI
1544 '(gnus-newsgroup-name
1545 gnus-newsgroup-begin gnus-newsgroup-end
1546 gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1547 gnus-newsgroup-last-folder gnus-newsgroup-last-file
26c9afc3 1548 gnus-newsgroup-last-directory
eec82323
LMI
1549 gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1550 gnus-newsgroup-unselected gnus-newsgroup-marked
23f87bed 1551 gnus-newsgroup-spam-marked
eec82323 1552 gnus-newsgroup-reads gnus-newsgroup-saved
23f87bed
MB
1553 gnus-newsgroup-replied gnus-newsgroup-forwarded
1554 gnus-newsgroup-recent
1555 gnus-newsgroup-expirable
eec82323 1556 gnus-newsgroup-processable gnus-newsgroup-killed
6748645f 1557 gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
23f87bed
MB
1558 gnus-newsgroup-unfetched
1559 gnus-newsgroup-unsendable gnus-newsgroup-unseen
1560 gnus-newsgroup-seen gnus-newsgroup-articles
eec82323
LMI
1561 gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1562 gnus-newsgroup-headers gnus-newsgroup-threads
1563 gnus-newsgroup-prepared gnus-summary-highlight-line-function
1564 gnus-current-article gnus-current-headers gnus-have-all-headers
1565 gnus-last-article gnus-article-internal-prepare-hook
1566 gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1567 gnus-newsgroup-scored gnus-newsgroup-kill-headers
1568 gnus-thread-expunge-below
16409b0b
GM
1569 gnus-score-alist gnus-current-score-file
1570 (gnus-summary-expunge-below . global)
eec82323 1571 (gnus-summary-mark-below . global)
16409b0b 1572 (gnus-orphan-score . global)
eec82323
LMI
1573 gnus-newsgroup-active gnus-scores-exclude-files
1574 gnus-newsgroup-history gnus-newsgroup-ancient
1575 gnus-newsgroup-sparse gnus-newsgroup-process-stack
1576 (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1577 gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1578 (gnus-newsgroup-expunged-tally . 0)
1579 gnus-cache-removable-articles gnus-newsgroup-cached
1580 gnus-newsgroup-data gnus-newsgroup-data-reverse
16409b0b 1581 gnus-newsgroup-limit gnus-newsgroup-limits
23f87bed
MB
1582 gnus-newsgroup-charset gnus-newsgroup-display
1583 gnus-summary-use-undownloaded-faces)
eec82323
LMI
1584 "Variables that are buffer-local to the summary buffers.")
1585
23f87bed
MB
1586(defvar gnus-newsgroup-variables nil
1587 "A list of variables that have separate values in different newsgroups.
1588A list of newsgroup (summary buffer) local variables, or cons of
1589variables and their default expressions to be evalled (when the default
1590values are not nil), that should be made global while the summary buffer
1591is active.
1592
1593Note: The default expressions will be evaluated (using function `eval')
1594before assignment to the local variable rather than just assigned to it.
1595If the default expression is the symbol `global', that symbol will not
1596be evaluated but the global value of the local variable will be used
1597instead.
1598
1599These variables can be used to set variables in the group parameters
1600while still allowing them to affect operations done in other buffers.
1601For example:
1602
1603\(setq gnus-newsgroup-variables
1604 '(message-use-followup-to
1605 (gnus-visible-headers .
1606 \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1607")
1608
23f87bed
MB
1609(eval-when-compile
1610 ;; Bind features so that require will believe that gnus-sum has
1611 ;; already been loaded (avoids infinite recursion)
1612 (let ((features (cons 'gnus-sum features)))
23f87bed 1613 (require 'gnus-art)))
eec82323 1614
16409b0b
GM
1615;; MIME stuff.
1616
1617(defvar gnus-decode-encoded-word-methods
1618 '(mail-decode-encoded-word-string)
1619 "List of methods used to decode encoded words.
1620
23f87bed
MB
1621This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
1622is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
1623\(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
16409b0b
GM
1624whose names match REGEXP.
1625
1626For example:
23f87bed 1627\((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
16409b0b
GM
1628 mail-decode-encoded-word-string
1629 (\"chinese\" . rfc1843-decode-string))")
1630
1631(defvar gnus-decode-encoded-word-methods-cache nil)
1632
1633(defun gnus-multi-decode-encoded-word-string (string)
1634 "Apply the functions from `gnus-encoded-word-methods' that match."
1635 (unless (and gnus-decode-encoded-word-methods-cache
1636 (eq gnus-newsgroup-name
1637 (car gnus-decode-encoded-word-methods-cache)))
1638 (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
01c52d31
MB
1639 (dolist (method gnus-decode-encoded-word-methods)
1640 (if (symbolp method)
1641 (nconc gnus-decode-encoded-word-methods-cache (list method))
1642 (if (and gnus-newsgroup-name
1643 (string-match (car method) gnus-newsgroup-name))
1644 (nconc gnus-decode-encoded-word-methods-cache
1645 (list (cdr method)))))))
1646 (dolist (method (cdr gnus-decode-encoded-word-methods-cache) string)
1647 (setq string (funcall method string))))
16409b0b 1648
eec82323
LMI
1649;; Subject simplification.
1650
6748645f 1651(defun gnus-simplify-whitespace (str)
16409b0b 1652 "Remove excessive whitespace from STR."
23f87bed
MB
1653 ;; Multiple spaces.
1654 (while (string-match "[ \t][ \t]+" str)
1655 (setq str (concat (substring str 0 (match-beginning 0))
1656 " "
1657 (substring str (match-end 0)))))
1658 ;; Leading spaces.
1659 (when (string-match "^[ \t]+" str)
1660 (setq str (substring str (match-end 0))))
1661 ;; Trailing spaces.
1662 (when (string-match "[ \t]+$" str)
1663 (setq str (substring str 0 (match-beginning 0))))
1664 str)
1665
1666(defun gnus-simplify-all-whitespace (str)
1667 "Remove all whitespace from STR."
1668 (while (string-match "[ \t\n]+" str)
1669 (setq str (replace-match "" nil nil str)))
1670 str)
6748645f 1671
eec82323
LMI
1672(defsubst gnus-simplify-subject-re (subject)
1673 "Remove \"Re:\" from subject lines."
23f87bed 1674 (if (string-match message-subject-re-regexp subject)
eec82323
LMI
1675 (substring subject (match-end 0))
1676 subject))
1677
1678(defun gnus-simplify-subject (subject &optional re-only)
1679 "Remove `Re:' and words in parentheses.
1680If RE-ONLY is non-nil, strip leading `Re:'s only."
1681 (let ((case-fold-search t)) ;Ignore case.
1682 ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1683 (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1684 (setq subject (substring subject (match-end 0))))
1685 ;; Remove uninteresting prefixes.
1686 (when (and (not re-only)
1687 gnus-simplify-ignored-prefixes
1688 (string-match gnus-simplify-ignored-prefixes subject))
1689 (setq subject (substring subject (match-end 0))))
1690 ;; Remove words in parentheses from end.
1691 (unless re-only
1692 (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1693 (setq subject (substring subject 0 (match-beginning 0)))))
1694 ;; Return subject string.
1695 subject))
1696
1697;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1698;; all whitespace.
1699(defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1700 (goto-char (point-min))
1701 (while (re-search-forward regexp nil t)
16409b0b 1702 (replace-match (or newtext ""))))
eec82323
LMI
1703
1704(defun gnus-simplify-buffer-fuzzy ()
1705 "Simplify string in the buffer fuzzily.
1706The string in the accessible portion of the current buffer is simplified.
1707It is assumed to be a single-line subject.
1708Whitespace is generally cleaned up, and miscellaneous leading/trailing
1709matter is removed. Additional things can be deleted by setting
16409b0b 1710`gnus-simplify-subject-fuzzy-regexp'."
eec82323
LMI
1711 (let ((case-fold-search t)
1712 (modified-tick))
1713 (gnus-simplify-buffer-fuzzy-step "\t" " ")
1714
1715 (while (not (eq modified-tick (buffer-modified-tick)))
1716 (setq modified-tick (buffer-modified-tick))
1717 (cond
1718 ((listp gnus-simplify-subject-fuzzy-regexp)
01c52d31
MB
1719 (mapc 'gnus-simplify-buffer-fuzzy-step
1720 gnus-simplify-subject-fuzzy-regexp))
eec82323
LMI
1721 (gnus-simplify-subject-fuzzy-regexp
1722 (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1723 (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1724 (gnus-simplify-buffer-fuzzy-step
1725 "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1726 (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1727
1728 (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1729 (gnus-simplify-buffer-fuzzy-step " +" " ")
1730 (gnus-simplify-buffer-fuzzy-step " $")
1731 (gnus-simplify-buffer-fuzzy-step "^ +")))
1732
1733(defun gnus-simplify-subject-fuzzy (subject)
1734 "Simplify a subject string fuzzily.
6748645f 1735See `gnus-simplify-buffer-fuzzy' for details."
eec82323
LMI
1736 (save-excursion
1737 (gnus-set-work-buffer)
1738 (let ((case-fold-search t))
6748645f
LMI
1739 ;; Remove uninteresting prefixes.
1740 (when (and gnus-simplify-ignored-prefixes
1741 (string-match gnus-simplify-ignored-prefixes subject))
1742 (setq subject (substring subject (match-end 0))))
eec82323
LMI
1743 (insert subject)
1744 (inline (gnus-simplify-buffer-fuzzy))
1745 (buffer-string))))
1746
1747(defsubst gnus-simplify-subject-fully (subject)
23f87bed 1748 "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
eec82323 1749 (cond
6748645f
LMI
1750 (gnus-simplify-subject-functions
1751 (gnus-map-function gnus-simplify-subject-functions subject))
eec82323
LMI
1752 ((null gnus-summary-gather-subject-limit)
1753 (gnus-simplify-subject-re subject))
1754 ((eq gnus-summary-gather-subject-limit 'fuzzy)
1755 (gnus-simplify-subject-fuzzy subject))
1756 ((numberp gnus-summary-gather-subject-limit)
01c52d31
MB
1757 (truncate-string-to-width (gnus-simplify-subject-re subject)
1758 gnus-summary-gather-subject-limit))
eec82323
LMI
1759 (t
1760 subject)))
1761
1762(defsubst gnus-subject-equal (s1 s2 &optional simple-first)
6748645f 1763 "Check whether two subjects are equal.
23f87bed 1764If optional argument SIMPLE-FIRST is t, first argument is already
6748645f 1765simplified."
eec82323
LMI
1766 (cond
1767 ((null simple-first)
1768 (equal (gnus-simplify-subject-fully s1)
1769 (gnus-simplify-subject-fully s2)))
1770 (t
1771 (equal s1
1772 (gnus-simplify-subject-fully s2)))))
1773
1774(defun gnus-summary-bubble-group ()
1775 "Increase the score of the current group.
1776This is a handy function to add to `gnus-summary-exit-hook' to
1777increase the score of each group you read."
1778 (gnus-group-add-score gnus-newsgroup-name))
1779
1780\f
1781;;;
1782;;; Gnus summary mode
1783;;;
1784
1785(put 'gnus-summary-mode 'mode-class 'special)
1786
1653df0f
SZ
1787(defvar gnus-article-commands-menu)
1788
23f87bed
MB
1789;; Non-orthogonal keys
1790
1791(gnus-define-keys gnus-summary-mode-map
1792 " " gnus-summary-next-page
1793 "\177" gnus-summary-prev-page
1794 [delete] gnus-summary-prev-page
1795 [backspace] gnus-summary-prev-page
1796 "\r" gnus-summary-scroll-up
1797 "\M-\r" gnus-summary-scroll-down
1798 "n" gnus-summary-next-unread-article
1799 "p" gnus-summary-prev-unread-article
1800 "N" gnus-summary-next-article
1801 "P" gnus-summary-prev-article
1802 "\M-\C-n" gnus-summary-next-same-subject
1803 "\M-\C-p" gnus-summary-prev-same-subject
1804 "\M-n" gnus-summary-next-unread-subject
1805 "\M-p" gnus-summary-prev-unread-subject
1806 "." gnus-summary-first-unread-article
1807 "," gnus-summary-best-unread-article
1808 "\M-s" gnus-summary-search-article-forward
1809 "\M-r" gnus-summary-search-article-backward
01c52d31
MB
1810 "\M-S" gnus-summary-repeat-search-article-forward
1811 "\M-R" gnus-summary-repeat-search-article-backward
23f87bed
MB
1812 "<" gnus-summary-beginning-of-article
1813 ">" gnus-summary-end-of-article
1814 "j" gnus-summary-goto-article
1815 "^" gnus-summary-refer-parent-article
1816 "\M-^" gnus-summary-refer-article
1817 "u" gnus-summary-tick-article-forward
1818 "!" gnus-summary-tick-article-forward
1819 "U" gnus-summary-tick-article-backward
1820 "d" gnus-summary-mark-as-read-forward
1821 "D" gnus-summary-mark-as-read-backward
1822 "E" gnus-summary-mark-as-expirable
1823 "\M-u" gnus-summary-clear-mark-forward
1824 "\M-U" gnus-summary-clear-mark-backward
1825 "k" gnus-summary-kill-same-subject-and-select
1826 "\C-k" gnus-summary-kill-same-subject
1827 "\M-\C-k" gnus-summary-kill-thread
1828 "\M-\C-l" gnus-summary-lower-thread
1829 "e" gnus-summary-edit-article
1830 "#" gnus-summary-mark-as-processable
1831 "\M-#" gnus-summary-unmark-as-processable
1832 "\M-\C-t" gnus-summary-toggle-threads
1833 "\M-\C-s" gnus-summary-show-thread
1834 "\M-\C-h" gnus-summary-hide-thread
1835 "\M-\C-f" gnus-summary-next-thread
1836 "\M-\C-b" gnus-summary-prev-thread
1837 [(meta down)] gnus-summary-next-thread
1838 [(meta up)] gnus-summary-prev-thread
1839 "\M-\C-u" gnus-summary-up-thread
1840 "\M-\C-d" gnus-summary-down-thread
1841 "&" gnus-summary-execute-command
1842 "c" gnus-summary-catchup-and-exit
1843 "\C-w" gnus-summary-mark-region-as-read
1844 "\C-t" gnus-summary-toggle-truncation
1845 "?" gnus-summary-mark-as-dormant
1846 "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1847 "\C-c\C-s\C-n" gnus-summary-sort-by-number
6ecfe5c2 1848 "\C-c\C-s\C-m\C-n" gnus-summary-sort-by-most-recent-number
23f87bed
MB
1849 "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1850 "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1851 "\C-c\C-s\C-a" gnus-summary-sort-by-author
01c52d31 1852 "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
23f87bed
MB
1853 "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1854 "\C-c\C-s\C-d" gnus-summary-sort-by-date
6ecfe5c2 1855 "\C-c\C-s\C-m\C-d" gnus-summary-sort-by-most-recent-date
23f87bed
MB
1856 "\C-c\C-s\C-i" gnus-summary-sort-by-score
1857 "\C-c\C-s\C-o" gnus-summary-sort-by-original
1858 "\C-c\C-s\C-r" gnus-summary-sort-by-random
1859 "=" gnus-summary-expand-window
1860 "\C-x\C-s" gnus-summary-reselect-current-group
1861 "\M-g" gnus-summary-rescan-group
1862 "w" gnus-summary-stop-page-breaking
1863 "\C-c\C-r" gnus-summary-caesar-message
1864 "f" gnus-summary-followup
1865 "F" gnus-summary-followup-with-original
1866 "C" gnus-summary-cancel-article
1867 "r" gnus-summary-reply
1868 "R" gnus-summary-reply-with-original
1869 "\C-c\C-f" gnus-summary-mail-forward
1870 "o" gnus-summary-save-article
1871 "\C-o" gnus-summary-save-article-mail
1872 "|" gnus-summary-pipe-output
1873 "\M-k" gnus-summary-edit-local-kill
1874 "\M-K" gnus-summary-edit-global-kill
1875 ;; "V" gnus-version
1876 "\C-c\C-d" gnus-summary-describe-group
1877 "q" gnus-summary-exit
1878 "Q" gnus-summary-exit-no-update
1879 "\C-c\C-i" gnus-info-find-node
1880 gnus-mouse-2 gnus-mouse-pick-article
132cf96d 1881 [follow-link] mouse-face
23f87bed
MB
1882 "m" gnus-summary-mail-other-window
1883 "a" gnus-summary-post-news
1884 "i" gnus-summary-news-other-window
1885 "x" gnus-summary-limit-to-unread
1886 "s" gnus-summary-isearch-article
1887 "t" gnus-summary-toggle-header
1888 "g" gnus-summary-show-article
1889 "l" gnus-summary-goto-last-article
1890 "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1891 "\C-d" gnus-summary-enter-digest-group
1892 "\M-\C-d" gnus-summary-read-document
1893 "\M-\C-e" gnus-summary-edit-parameters
1894 "\M-\C-a" gnus-summary-customize-parameters
1895 "\C-c\C-b" gnus-bug
1896 "*" gnus-cache-enter-article
1897 "\M-*" gnus-cache-remove-article
1898 "\M-&" gnus-summary-universal-argument
1899 "\C-l" gnus-recenter
1900 "I" gnus-summary-increase-score
1901 "L" gnus-summary-lower-score
1902 "\M-i" gnus-symbolic-argument
1903 "h" gnus-summary-select-article-buffer
1904
1905 "b" gnus-article-view-part
1906 "\M-t" gnus-summary-toggle-display-buttonized
1907
1908 "V" gnus-summary-score-map
1909 "X" gnus-uu-extract-map
1910 "S" gnus-summary-send-map)
1911
1912;; Sort of orthogonal keymap
1913(gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1914 "t" gnus-summary-tick-article-forward
1915 "!" gnus-summary-tick-article-forward
1916 "d" gnus-summary-mark-as-read-forward
1917 "r" gnus-summary-mark-as-read-forward
1918 "c" gnus-summary-clear-mark-forward
1919 " " gnus-summary-clear-mark-forward
1920 "e" gnus-summary-mark-as-expirable
1921 "x" gnus-summary-mark-as-expirable
1922 "?" gnus-summary-mark-as-dormant
1923 "b" gnus-summary-set-bookmark
1924 "B" gnus-summary-remove-bookmark
1925 "#" gnus-summary-mark-as-processable
1926 "\M-#" gnus-summary-unmark-as-processable
1927 "S" gnus-summary-limit-include-expunged
1928 "C" gnus-summary-catchup
1929 "H" gnus-summary-catchup-to-here
1930 "h" gnus-summary-catchup-from-here
1931 "\C-c" gnus-summary-catchup-all
1932 "k" gnus-summary-kill-same-subject-and-select
1933 "K" gnus-summary-kill-same-subject
1934 "P" gnus-uu-mark-map)
1935
1936(gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1937 "c" gnus-summary-clear-above
1938 "u" gnus-summary-tick-above
1939 "m" gnus-summary-mark-above
1940 "k" gnus-summary-kill-below)
1941
1942(gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1943 "/" gnus-summary-limit-to-subject
1944 "n" gnus-summary-limit-to-articles
01c52d31
MB
1945 "b" gnus-summary-limit-to-bodies
1946 "h" gnus-summary-limit-to-headers
23f87bed
MB
1947 "w" gnus-summary-pop-limit
1948 "s" gnus-summary-limit-to-subject
1949 "a" gnus-summary-limit-to-author
1950 "u" gnus-summary-limit-to-unread
1951 "m" gnus-summary-limit-to-marks
1952 "M" gnus-summary-limit-exclude-marks
1953 "v" gnus-summary-limit-to-score
1954 "*" gnus-summary-limit-include-cached
1955 "D" gnus-summary-limit-include-dormant
1956 "T" gnus-summary-limit-include-thread
1957 "d" gnus-summary-limit-exclude-dormant
1958 "t" gnus-summary-limit-to-age
1959 "." gnus-summary-limit-to-unseen
1960 "x" gnus-summary-limit-to-extra
1961 "p" gnus-summary-limit-to-display-predicate
1962 "E" gnus-summary-limit-include-expunged
1963 "c" gnus-summary-limit-exclude-childless-dormant
1964 "C" gnus-summary-limit-mark-excluded-as-read
1965 "o" gnus-summary-insert-old-articles
01c52d31
MB
1966 "N" gnus-summary-insert-new-articles
1967 "S" gnus-summary-limit-to-singletons
1968 "r" gnus-summary-limit-to-replied
1969 "R" gnus-summary-limit-to-recipient
1970 "A" gnus-summary-limit-to-address)
23f87bed
MB
1971
1972(gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1973 "n" gnus-summary-next-unread-article
1974 "p" gnus-summary-prev-unread-article
1975 "N" gnus-summary-next-article
1976 "P" gnus-summary-prev-article
1977 "\C-n" gnus-summary-next-same-subject
1978 "\C-p" gnus-summary-prev-same-subject
1979 "\M-n" gnus-summary-next-unread-subject
1980 "\M-p" gnus-summary-prev-unread-subject
1981 "f" gnus-summary-first-unread-article
1982 "b" gnus-summary-best-unread-article
1983 "j" gnus-summary-goto-article
1984 "g" gnus-summary-goto-subject
1985 "l" gnus-summary-goto-last-article
1986 "o" gnus-summary-pop-article)
1987
1988(gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1989 "k" gnus-summary-kill-thread
01c52d31 1990 "E" gnus-summary-expire-thread
23f87bed
MB
1991 "l" gnus-summary-lower-thread
1992 "i" gnus-summary-raise-thread
1993 "T" gnus-summary-toggle-threads
1994 "t" gnus-summary-rethread-current
1995 "^" gnus-summary-reparent-thread
01c52d31 1996 "\M-^" gnus-summary-reparent-children
23f87bed
MB
1997 "s" gnus-summary-show-thread
1998 "S" gnus-summary-show-all-threads
1999 "h" gnus-summary-hide-thread
2000 "H" gnus-summary-hide-all-threads
2001 "n" gnus-summary-next-thread
2002 "p" gnus-summary-prev-thread
2003 "u" gnus-summary-up-thread
2004 "o" gnus-summary-top-thread
2005 "d" gnus-summary-down-thread
2006 "#" gnus-uu-mark-thread
2007 "\M-#" gnus-uu-unmark-thread)
2008
2009(gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
2010 "g" gnus-summary-prepare
2011 "c" gnus-summary-insert-cached-articles
01c52d31
MB
2012 "d" gnus-summary-insert-dormant-articles
2013 "t" gnus-summary-insert-ticked-articles)
23f87bed
MB
2014
2015(gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
2016 "c" gnus-summary-catchup-and-exit
2017 "C" gnus-summary-catchup-all-and-exit
2018 "E" gnus-summary-exit-no-update
2019 "Q" gnus-summary-exit
2020 "Z" gnus-summary-exit
2021 "n" gnus-summary-catchup-and-goto-next-group
01c52d31 2022 "p" gnus-summary-catchup-and-goto-prev-group
23f87bed
MB
2023 "R" gnus-summary-reselect-current-group
2024 "G" gnus-summary-rescan-group
2025 "N" gnus-summary-next-group
2026 "s" gnus-summary-save-newsrc
2027 "P" gnus-summary-prev-group)
2028
2029(gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
2030 " " gnus-summary-next-page
2031 "n" gnus-summary-next-page
2032 "\177" gnus-summary-prev-page
2033 [delete] gnus-summary-prev-page
2034 "p" gnus-summary-prev-page
2035 "\r" gnus-summary-scroll-up
2036 "\M-\r" gnus-summary-scroll-down
2037 "<" gnus-summary-beginning-of-article
2038 ">" gnus-summary-end-of-article
2039 "b" gnus-summary-beginning-of-article
2040 "e" gnus-summary-end-of-article
2041 "^" gnus-summary-refer-parent-article
2042 "r" gnus-summary-refer-parent-article
2043 "D" gnus-summary-enter-digest-group
2044 "R" gnus-summary-refer-references
2045 "T" gnus-summary-refer-thread
2046 "g" gnus-summary-show-article
2047 "s" gnus-summary-isearch-article
2048 "P" gnus-summary-print-article
01c52d31 2049 "S" gnus-sticky-article
23f87bed
MB
2050 "M" gnus-mailing-list-insinuate
2051 "t" gnus-article-babel)
2052
2053(gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2054 "b" gnus-article-add-buttons
2055 "B" gnus-article-add-buttons-to-head
2056 "o" gnus-article-treat-overstrike
2057 "e" gnus-article-emphasize
2058 "w" gnus-article-fill-cited-article
2059 "Q" gnus-article-fill-long-lines
01c52d31 2060 "L" gnus-article-toggle-truncate-lines
23f87bed
MB
2061 "C" gnus-article-capitalize-sentences
2062 "c" gnus-article-remove-cr
2063 "q" gnus-article-de-quoted-unreadable
2064 "6" gnus-article-de-base64-unreadable
2065 "Z" gnus-article-decode-HZ
01c52d31 2066 "A" gnus-article-treat-ansi-sequences
23f87bed
MB
2067 "h" gnus-article-wash-html
2068 "u" gnus-article-unsplit-urls
2069 "s" gnus-summary-force-verify-and-decrypt
2070 "f" gnus-article-display-x-face
2071 "l" gnus-summary-stop-page-breaking
2072 "r" gnus-summary-caesar-message
2073 "m" gnus-summary-morse-message
2074 "t" gnus-summary-toggle-header
2075 "g" gnus-treat-smiley
2076 "v" gnus-summary-verbose-headers
2077 "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2078 "p" gnus-article-verify-x-pgp-sig
01c52d31
MB
2079 "d" gnus-article-treat-dumbquotes
2080 "i" gnus-summary-idna-message)
23f87bed
MB
2081
2082(gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2083 ;; mnemonic: deuglif*Y*
2084 "u" gnus-article-outlook-unwrap-lines
2085 "a" gnus-article-outlook-repair-attribution
2086 "c" gnus-article-outlook-rearrange-citation
2087 "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2088
2089(gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2090 "a" gnus-article-hide
2091 "h" gnus-article-hide-headers
2092 "b" gnus-article-hide-boring-headers
2093 "s" gnus-article-hide-signature
2094 "c" gnus-article-hide-citation
2095 "C" gnus-article-hide-citation-in-followups
2096 "l" gnus-article-hide-list-identifiers
2097 "B" gnus-article-strip-banner
2098 "P" gnus-article-hide-pem
2099 "\C-c" gnus-article-hide-citation-maybe)
2100
2101(gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2102 "a" gnus-article-highlight
2103 "h" gnus-article-highlight-headers
2104 "c" gnus-article-highlight-citation
2105 "s" gnus-article-highlight-signature)
2106
2107(gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2108 "f" gnus-article-treat-fold-headers
2109 "u" gnus-article-treat-unfold-headers
2110 "n" gnus-article-treat-fold-newsgroups)
2111
2112(gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2113 "x" gnus-article-display-x-face
2114 "d" gnus-article-display-face
2115 "s" gnus-treat-smiley
2116 "D" gnus-article-remove-images
2117 "f" gnus-treat-from-picon
2118 "m" gnus-treat-mail-picon
2119 "n" gnus-treat-newsgroups-picon)
2120
2121(gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2122 "w" gnus-article-decode-mime-words
2123 "c" gnus-article-decode-charset
2124 "v" gnus-mime-view-all-parts
2125 "b" gnus-article-view-part)
2126
2127(gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2128 "z" gnus-article-date-ut
2129 "u" gnus-article-date-ut
2130 "l" gnus-article-date-local
2131 "p" gnus-article-date-english
2132 "e" gnus-article-date-lapsed
2133 "o" gnus-article-date-original
2134 "i" gnus-article-date-iso8601
2135 "s" gnus-article-date-user)
2136
2137(gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2138 "t" gnus-article-remove-trailing-blank-lines
2139 "l" gnus-article-strip-leading-blank-lines
2140 "m" gnus-article-strip-multiple-blank-lines
2141 "a" gnus-article-strip-blank-lines
2142 "A" gnus-article-strip-all-blank-lines
2143 "s" gnus-article-strip-leading-space
2144 "e" gnus-article-strip-trailing-space
2145 "w" gnus-article-remove-leading-whitespace)
2146
2147(gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2148 "v" gnus-version
2149 "f" gnus-summary-fetch-faq
2150 "d" gnus-summary-describe-group
2151 "h" gnus-summary-describe-briefly
2152 "i" gnus-info-find-node
2153 "c" gnus-group-fetch-charter
2154 "C" gnus-group-fetch-control)
2155
2156(gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2157 "e" gnus-summary-expire-articles
2158 "\M-\C-e" gnus-summary-expire-articles-now
2159 "\177" gnus-summary-delete-article
2160 [delete] gnus-summary-delete-article
2161 [backspace] gnus-summary-delete-article
2162 "m" gnus-summary-move-article
2163 "r" gnus-summary-respool-article
2164 "w" gnus-summary-edit-article
2165 "c" gnus-summary-copy-article
2166 "B" gnus-summary-crosspost-article
2167 "q" gnus-summary-respool-query
2168 "t" gnus-summary-respool-trace
2169 "i" gnus-summary-import-article
2170 "I" gnus-summary-create-article
2171 "p" gnus-summary-article-posted-p)
2172
2173(gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2174 "o" gnus-summary-save-article
2175 "m" gnus-summary-save-article-mail
2176 "F" gnus-summary-write-article-file
2177 "r" gnus-summary-save-article-rmail
2178 "f" gnus-summary-save-article-file
2179 "b" gnus-summary-save-article-body-file
26c9afc3 2180 "B" gnus-summary-write-article-body-file
23f87bed
MB
2181 "h" gnus-summary-save-article-folder
2182 "v" gnus-summary-save-article-vm
2183 "p" gnus-summary-pipe-output
2184 "P" gnus-summary-muttprint
2185 "s" gnus-soup-add-article)
2186
2187(gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2188 "b" gnus-summary-display-buttonized
2189 "m" gnus-summary-repair-multipart
2190 "v" gnus-article-view-part
2191 "o" gnus-article-save-part
01c52d31
MB
2192 "O" gnus-article-save-part-and-strip
2193 "r" gnus-article-replace-part
2194 "d" gnus-article-delete-part
2195 "t" gnus-article-view-part-as-type
2196 "j" gnus-article-jump-to-part
23f87bed
MB
2197 "c" gnus-article-copy-part
2198 "C" gnus-article-view-part-as-charset
2199 "e" gnus-article-view-part-externally
01c52d31 2200 "H" gnus-article-browse-html-article
23f87bed
MB
2201 "E" gnus-article-encrypt-body
2202 "i" gnus-article-inline-part
2203 "|" gnus-article-pipe-part)
2204
2205(gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2206 "p" gnus-summary-mark-as-processable
2207 "u" gnus-summary-unmark-as-processable
2208 "U" gnus-summary-unmark-all-processable
2209 "v" gnus-uu-mark-over
2210 "s" gnus-uu-mark-series
2211 "r" gnus-uu-mark-region
2212 "g" gnus-uu-unmark-region
2213 "R" gnus-uu-mark-by-regexp
2214 "G" gnus-uu-unmark-by-regexp
2215 "t" gnus-uu-mark-thread
2216 "T" gnus-uu-unmark-thread
2217 "a" gnus-uu-mark-all
2218 "b" gnus-uu-mark-buffer
2219 "S" gnus-uu-mark-sparse
2220 "k" gnus-summary-kill-process-mark
2221 "y" gnus-summary-yank-process-mark
2222 "w" gnus-summary-save-process-mark
2223 "i" gnus-uu-invert-processable)
2224
2225(gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2226 ;;"x" gnus-uu-extract-any
2227 "m" gnus-summary-save-parts
2228 "u" gnus-uu-decode-uu
2229 "U" gnus-uu-decode-uu-and-save
2230 "s" gnus-uu-decode-unshar
2231 "S" gnus-uu-decode-unshar-and-save
2232 "o" gnus-uu-decode-save
2233 "O" gnus-uu-decode-save
2234 "b" gnus-uu-decode-binhex
2235 "B" gnus-uu-decode-binhex
b890d447 2236 "Y" gnus-uu-decode-yenc
23f87bed
MB
2237 "p" gnus-uu-decode-postscript
2238 "P" gnus-uu-decode-postscript-and-save)
2239
2240(gnus-define-keys
2241 (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2242 "u" gnus-uu-decode-uu-view
2243 "U" gnus-uu-decode-uu-and-save-view
2244 "s" gnus-uu-decode-unshar-view
2245 "S" gnus-uu-decode-unshar-and-save-view
2246 "o" gnus-uu-decode-save-view
2247 "O" gnus-uu-decode-save-view
2248 "b" gnus-uu-decode-binhex-view
2249 "B" gnus-uu-decode-binhex-view
2250 "p" gnus-uu-decode-postscript-view
2251 "P" gnus-uu-decode-postscript-and-save-view)
2252
2253(defvar gnus-article-post-menu nil)
2254
2255(defconst gnus-summary-menu-maxlen 20)
2256
2257(defun gnus-summary-menu-split (menu)
2258 ;; If we have lots of elements, divide them into groups of 20
2259 ;; and make a pane (or submenu) for each one.
2260 (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2261 (let ((menu menu) sublists next
2262 (i 1))
2263 (while menu
2264 ;; Pull off the next gnus-summary-menu-maxlen elements
2265 ;; and make them the next element of sublist.
2266 (setq next (nthcdr gnus-summary-menu-maxlen menu))
2267 (if next
2268 (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2269 nil))
2270 (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2271 (aref (car (last menu)) 0)) menu)
2272 sublists))
2273 (setq i (1+ i))
2274 (setq menu next))
2275 (nreverse sublists))
2276 ;; Few elements--put them all in one pane.
2277 menu))
eec82323
LMI
2278
2279(defun gnus-summary-make-menu-bar ()
2280 (gnus-turn-off-edit-menu 'summary)
2281
2282 (unless (boundp 'gnus-summary-misc-menu)
2283
2284 (easy-menu-define
23f87bed
MB
2285 gnus-summary-kill-menu gnus-summary-mode-map ""
2286 (cons
2287 "Score"
2288 (nconc
2289 (list
2290 ["Customize" gnus-score-customize t])
2291 (gnus-make-score-map 'increase)
2292 (gnus-make-score-map 'lower)
2293 '(("Mark"
2294 ["Kill below" gnus-summary-kill-below t]
2295 ["Mark above" gnus-summary-mark-above t]
2296 ["Tick above" gnus-summary-tick-above t]
2297 ["Clear above" gnus-summary-clear-above t])
2298 ["Current score" gnus-summary-current-score t]
2299 ["Set score" gnus-summary-set-score t]
2300 ["Switch current score file..." gnus-score-change-score-file t]
2301 ["Set mark below..." gnus-score-set-mark-below t]
2302 ["Set expunge below..." gnus-score-set-expunge-below t]
2303 ["Edit current score file" gnus-score-edit-current-scores t]
59429511 2304 ["Edit score file..." gnus-score-edit-file t]
23f87bed
MB
2305 ["Trace score" gnus-score-find-trace t]
2306 ["Find words" gnus-score-find-favourite-words t]
2307 ["Rescore buffer" gnus-summary-rescore t]
2308 ["Increase score..." gnus-summary-increase-score t]
2309 ["Lower score..." gnus-summary-lower-score t]))))
2310
2311 ;; Define both the Article menu in the summary buffer and the
2312 ;; equivalent Commands menu in the article buffer here for
2313 ;; consistency.
6748645f 2314 (let ((innards
23f87bed
MB
2315 `(("Hide"
2316 ["All" gnus-article-hide t]
2317 ["Headers" gnus-article-hide-headers t]
2318 ["Signature" gnus-article-hide-signature t]
2319 ["Citation" gnus-article-hide-citation t]
16409b0b 2320 ["List identifiers" gnus-article-hide-list-identifiers t]
16409b0b 2321 ["Banner" gnus-article-strip-banner t]
23f87bed
MB
2322 ["Boring headers" gnus-article-hide-boring-headers t])
2323 ("Highlight"
2324 ["All" gnus-article-highlight t]
2325 ["Headers" gnus-article-highlight-headers t]
2326 ["Signature" gnus-article-highlight-signature t]
2327 ["Citation" gnus-article-highlight-citation t])
16409b0b
GM
2328 ("MIME"
2329 ["Words" gnus-article-decode-mime-words t]
2330 ["Charset" gnus-article-decode-charset t]
2331 ["QP" gnus-article-de-quoted-unreadable t]
2332 ["Base64" gnus-article-de-base64-unreadable t]
23f87bed
MB
2333 ["View MIME buttons" gnus-summary-display-buttonized t]
2334 ["View all" gnus-mime-view-all-parts t]
2335 ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2336 ["Encrypt body" gnus-article-encrypt-body
2337 :active (not (gnus-group-read-only-p))
2338 ,@(if (featurep 'xemacs) nil
2339 '(:help "Encrypt the message body on disk"))]
2340 ["Extract all parts..." gnus-summary-save-parts t]
2341 ("Multipart"
2342 ["Repair multipart" gnus-summary-repair-multipart t]
2343 ["Pipe part..." gnus-article-pipe-part t]
2344 ["Inline part" gnus-article-inline-part t]
01c52d31 2345 ["View part as type..." gnus-article-view-part-as-type t]
23f87bed
MB
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 ["View part externally" gnus-article-view-part-externally t]
01c52d31 2351 ["View HTML parts in browser" gnus-article-browse-html-article t]
23f87bed
MB
2352 ["View part with charset..." gnus-article-view-part-as-charset t]
2353 ["Copy part" gnus-article-copy-part t]
2354 ["Save part..." gnus-article-save-part t]
2355 ["View part" gnus-article-view-part t]))
2356 ("Date"
2357 ["Local" gnus-article-date-local t]
2358 ["ISO8601" gnus-article-date-iso8601 t]
2359 ["UT" gnus-article-date-ut t]
2360 ["Original" gnus-article-date-original t]
2361 ["Lapsed" gnus-article-date-lapsed t]
2362 ["User-defined" gnus-article-date-user t])
2363 ("Display"
2364 ["Remove images" gnus-article-remove-images t]
2365 ["Toggle smiley" gnus-treat-smiley t]
2366 ["Show X-Face" gnus-article-display-x-face t]
2367 ["Show picons in From" gnus-treat-from-picon t]
2368 ["Show picons in mail headers" gnus-treat-mail-picon t]
2369 ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2370 ("View as different encoding"
2371 ,@(gnus-summary-menu-split
2372 (mapcar
2373 (lambda (cs)
2374 ;; Since easymenu under Emacs doesn't allow
2375 ;; lambda forms for menu commands, we should
2376 ;; provide intern'ed function symbols.
2377 (let ((command (intern (format "\
2378gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2379 (fset command
2380 `(lambda ()
2381 (interactive)
2382 (let ((gnus-summary-show-article-charset-alist
2383 '((1 . ,cs))))
2384 (gnus-summary-show-article 1))))
2385 `[,(symbol-name cs) ,command t]))
2386 (sort (if (fboundp 'coding-system-list)
2387 (coding-system-list)
2388 (mapcar 'car mm-mime-mule-charset-alist))
2389 'string<)))))
2390 ("Washing"
2391 ("Remove Blanks"
2392 ["Leading" gnus-article-strip-leading-blank-lines t]
2393 ["Multiple" gnus-article-strip-multiple-blank-lines t]
2394 ["Trailing" gnus-article-remove-trailing-blank-lines t]
2395 ["All of the above" gnus-article-strip-blank-lines t]
2396 ["All" gnus-article-strip-all-blank-lines t]
2397 ["Leading space" gnus-article-strip-leading-space t]
2398 ["Trailing space" gnus-article-strip-trailing-space t]
2399 ["Leading space in headers"
2400 gnus-article-remove-leading-whitespace t])
2401 ["Overstrike" gnus-article-treat-overstrike t]
2402 ["Dumb quotes" gnus-article-treat-dumbquotes t]
2403 ["Emphasis" gnus-article-emphasize t]
2404 ["Word wrap" gnus-article-fill-cited-article t]
16409b0b 2405 ["Fill long lines" gnus-article-fill-long-lines t]
01c52d31 2406 ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
16409b0b 2407 ["Capitalize sentences" gnus-article-capitalize-sentences t]
23f87bed
MB
2408 ["Remove CR" gnus-article-remove-cr t]
2409 ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2410 ["Base64" gnus-article-de-base64-unreadable t]
2411 ["Rot 13" gnus-summary-caesar-message
2412 ,@(if (featurep 'xemacs) '(t)
2413 '(:help "\"Caesar rotate\" article by 13"))]
01c52d31 2414 ["De-IDNA" gnus-summary-idna-message t]
23f87bed
MB
2415 ["Morse decode" gnus-summary-morse-message t]
2416 ["Unix pipe..." gnus-summary-pipe-message t]
2417 ["Add buttons" gnus-article-add-buttons t]
2418 ["Add buttons to head" gnus-article-add-buttons-to-head t]
2419 ["Stop page breaking" gnus-summary-stop-page-breaking t]
2420 ["Verbose header" gnus-summary-verbose-headers t]
2421 ["Toggle header" gnus-summary-toggle-header t]
2422 ["Unfold headers" gnus-article-treat-unfold-headers t]
2423 ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
16409b0b 2424 ["Html" gnus-article-wash-html t]
23f87bed
MB
2425 ["Unsplit URLs" gnus-article-unsplit-urls t]
2426 ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2427 ["Decode HZ" gnus-article-decode-HZ t]
01c52d31 2428 ["ANSI sequences" gnus-article-treat-ansi-sequences t]
23f87bed
MB
2429 ("(Outlook) Deuglify"
2430 ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2431 ["Repair attribution" gnus-article-outlook-repair-attribution t]
2432 ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2433 ["Full (Outlook) deuglify"
2434 gnus-article-outlook-deuglify-article t])
2435 )
2436 ("Output"
2437 ["Save in default format..." gnus-summary-save-article
2438 ,@(if (featurep 'xemacs) '(t)
2439 '(:help "Save article using default method"))]
2440 ["Save in file..." gnus-summary-save-article-file
2441 ,@(if (featurep 'xemacs) '(t)
2442 '(:help "Save article in file"))]
2443 ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2444 ["Save in MH folder..." gnus-summary-save-article-folder t]
2445 ["Save in VM folder..." gnus-summary-save-article-vm t]
2446 ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2447 ["Save body in file..." gnus-summary-save-article-body-file t]
2448 ["Pipe through a filter..." gnus-summary-pipe-output t]
2449 ["Add to SOUP packet" gnus-soup-add-article t]
2450 ["Print with Muttprint..." gnus-summary-muttprint t]
531e5812
MB
2451 ["Print" gnus-summary-print-article
2452 ,@(if (featurep 'xemacs) '(t)
2453 '(:help "Generate and print a PostScript image"))])
2454 ("Copy, move,... (Backend)"
707f2b38 2455 ,@(if (featurep 'xemacs) nil
531e5812 2456 '(:help "Copying, moving, expiring articles..."))
23f87bed
MB
2457 ["Respool article..." gnus-summary-respool-article t]
2458 ["Move article..." gnus-summary-move-article
2459 (gnus-check-backend-function
2460 'request-move-article gnus-newsgroup-name)]
2461 ["Copy article..." gnus-summary-copy-article t]
2462 ["Crosspost article..." gnus-summary-crosspost-article
2463 (gnus-check-backend-function
2464 'request-replace-article gnus-newsgroup-name)]
2465 ["Import file..." gnus-summary-import-article
2466 (gnus-check-backend-function
2467 'request-accept-article gnus-newsgroup-name)]
2468 ["Create article..." gnus-summary-create-article
2469 (gnus-check-backend-function
2470 'request-accept-article gnus-newsgroup-name)]
2471 ["Check if posted" gnus-summary-article-posted-p t]
2472 ["Edit article" gnus-summary-edit-article
2473 (not (gnus-group-read-only-p))]
2474 ["Delete article" gnus-summary-delete-article
2475 (gnus-check-backend-function
2476 'request-expire-articles gnus-newsgroup-name)]
2477 ["Query respool" gnus-summary-respool-query t]
6748645f 2478 ["Trace respool" gnus-summary-respool-trace t]
23f87bed
MB
2479 ["Delete expirable articles" gnus-summary-expire-articles-now
2480 (gnus-check-backend-function
2481 'request-expire-articles gnus-newsgroup-name)])
2482 ("Extract"
2483 ["Uudecode" gnus-uu-decode-uu
2484 ,@(if (featurep 'xemacs) '(t)
2485 '(:help "Decode uuencoded article(s)"))]
2486 ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2487 ["Unshar" gnus-uu-decode-unshar t]
2488 ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2489 ["Save" gnus-uu-decode-save t]
2490 ["Binhex" gnus-uu-decode-binhex t]
2491 ["Postscript" gnus-uu-decode-postscript t]
2492 ["All MIME parts" gnus-summary-save-parts t])
2493 ("Cache"
2494 ["Enter article" gnus-cache-enter-article t]
2495 ["Remove article" gnus-cache-remove-article t])
16409b0b 2496 ["Translate" gnus-article-babel t]
23f87bed 2497 ["Select article buffer" gnus-summary-select-article-buffer t]
01c52d31 2498 ["Make article buffer sticky" gnus-sticky-article t]
23f87bed
MB
2499 ["Enter digest buffer" gnus-summary-enter-digest-group t]
2500 ["Isearch article..." gnus-summary-isearch-article t]
2501 ["Beginning of the article" gnus-summary-beginning-of-article t]
2502 ["End of the article" gnus-summary-end-of-article t]
2503 ["Fetch parent of article" gnus-summary-refer-parent-article t]
2504 ["Fetch referenced articles" gnus-summary-refer-references t]
2505 ["Fetch current thread" gnus-summary-refer-thread t]
2506 ["Fetch article with id..." gnus-summary-refer-article t]
2507 ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2508 ["Redisplay" gnus-summary-show-article t]
2509 ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
6748645f 2510 (easy-menu-define
23f87bed
MB
2511 gnus-summary-article-menu gnus-summary-mode-map ""
2512 (cons "Article" innards))
6748645f 2513
1653df0f
SZ
2514 (if (not (keymapp gnus-summary-article-menu))
2515 (easy-menu-define
2516 gnus-article-commands-menu gnus-article-mode-map ""
2517 (cons "Commands" innards))
2518 ;; in Emacs, don't share menu.
a1506d29 2519 (setq gnus-article-commands-menu
1653df0f
SZ
2520 (copy-keymap gnus-summary-article-menu))
2521 (define-key gnus-article-mode-map [menu-bar commands]
2522 (cons "Commands" gnus-article-commands-menu))))
eec82323
LMI
2523
2524 (easy-menu-define
23f87bed
MB
2525 gnus-summary-thread-menu gnus-summary-mode-map ""
2526 '("Threads"
2527 ["Find all messages in thread" gnus-summary-refer-thread t]
2528 ["Toggle threading" gnus-summary-toggle-threads t]
2529 ["Hide threads" gnus-summary-hide-all-threads t]
2530 ["Show threads" gnus-summary-show-all-threads t]
2531 ["Hide thread" gnus-summary-hide-thread t]
2532 ["Show thread" gnus-summary-show-thread t]
2533 ["Go to next thread" gnus-summary-next-thread t]
2534 ["Go to previous thread" gnus-summary-prev-thread t]
2535 ["Go down thread" gnus-summary-down-thread t]
2536 ["Go up thread" gnus-summary-up-thread t]
2537 ["Top of thread" gnus-summary-top-thread t]
2538 ["Mark thread as read" gnus-summary-kill-thread t]
01c52d31 2539 ["Mark thread as expired" gnus-summary-expire-thread t]
23f87bed
MB
2540 ["Lower thread score" gnus-summary-lower-thread t]
2541 ["Raise thread score" gnus-summary-raise-thread t]
2542 ["Rethread current" gnus-summary-rethread-current t]))
eec82323
LMI
2543
2544 (easy-menu-define
23f87bed
MB
2545 gnus-summary-post-menu gnus-summary-mode-map ""
2546 `("Post"
2547 ["Send a message (mail or news)" gnus-summary-post-news
2548 ,@(if (featurep 'xemacs) '(t)
531e5812 2549 '(:help "Compose a new message (mail or news)"))]
23f87bed
MB
2550 ["Followup" gnus-summary-followup
2551 ,@(if (featurep 'xemacs) '(t)
2552 '(:help "Post followup to this article"))]
2553 ["Followup and yank" gnus-summary-followup-with-original
2554 ,@(if (featurep 'xemacs) '(t)
2555 '(:help "Post followup to this article, quoting its contents"))]
2556 ["Supersede article" gnus-summary-supersede-article t]
2557 ["Cancel article" gnus-summary-cancel-article
2558 ,@(if (featurep 'xemacs) '(t)
2559 '(:help "Cancel an article you posted"))]
2560 ["Reply" gnus-summary-reply t]
2561 ["Reply and yank" gnus-summary-reply-with-original t]
2562 ["Wide reply" gnus-summary-wide-reply t]
2563 ["Wide reply and yank" gnus-summary-wide-reply-with-original
2564 ,@(if (featurep 'xemacs) '(t)
2565 '(:help "Mail a reply, quoting this article"))]
2566 ["Very wide reply" gnus-summary-very-wide-reply t]
2567 ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2568 ,@(if (featurep 'xemacs) '(t)
2569 '(:help "Mail a very wide reply, quoting this article"))]
2570 ["Mail forward" gnus-summary-mail-forward t]
2571 ["Post forward" gnus-summary-post-forward t]
2572 ["Digest and mail" gnus-uu-digest-mail-forward t]
2573 ["Digest and post" gnus-uu-digest-post-forward t]
2574 ["Resend message" gnus-summary-resend-message t]
2575 ["Resend message edit" gnus-summary-resend-message-edit t]
2576 ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2577 ["Send a mail" gnus-summary-mail-other-window t]
2578 ["Create a local message" gnus-summary-news-other-window t]
2579 ["Uuencode and post" gnus-uu-post-news
2580 ,@(if (featurep 'xemacs) '(t)
2581 '(:help "Post a uuencoded article"))]
2582 ["Followup via news" gnus-summary-followup-to-mail t]
2583 ["Followup via news and yank"
2584 gnus-summary-followup-to-mail-with-original t]
9b3ebcb6
MB
2585 ["Strip signature on reply"
2586 (lambda ()
2587 (interactive)
2588 (if (not (memq message-cite-function
2589 '(message-cite-original-without-signature
2590 message-cite-original)))
2591 ;; Stupid workaround for XEmacs not honoring :visible.
2592 (message "Can't toggle this value of `message-cite-function'")
2593 (setq message-cite-function
2594 (if (eq message-cite-function
2595 'message-cite-original-without-signature)
2596 'message-cite-original
2597 'message-cite-original-without-signature))))
2598 ;; XEmacs barfs on :visible.
2599 ,@(if (featurep 'xemacs) nil
2600 '(:visible (memq message-cite-function
2601 '(message-cite-original-without-signature
2602 message-cite-original))))
2603 :style toggle
2604 :selected (eq message-cite-function
2605 'message-cite-original-without-signature)
2606 ,@(if (featurep 'xemacs) nil
2607 '(:help "Strip signature from cited article when replying."))]
23f87bed
MB
2608 ;;("Draft"
2609 ;;["Send" gnus-summary-send-draft t]
2610 ;;["Send bounced" gnus-resend-bounced-mail t])
2611 ))
2612
2613 (cond
2614 ((not (keymapp gnus-summary-post-menu))
2615 (setq gnus-article-post-menu gnus-summary-post-menu))
2616 ((not gnus-article-post-menu)
2617 ;; Don't share post menu.
2618 (setq gnus-article-post-menu
2619 (copy-keymap gnus-summary-post-menu))))
2620 (define-key gnus-article-mode-map [menu-bar post]
2621 (cons "Post" gnus-article-post-menu))
eec82323
LMI
2622
2623 (easy-menu-define
23f87bed
MB
2624 gnus-summary-misc-menu gnus-summary-mode-map ""
2625 `("Gnus"
2626 ("Mark Read"
2627 ["Mark as read" gnus-summary-mark-as-read-forward t]
2628 ["Mark same subject and select"
2629 gnus-summary-kill-same-subject-and-select t]
2630 ["Mark same subject" gnus-summary-kill-same-subject t]
2631 ["Catchup" gnus-summary-catchup
2632 ,@(if (featurep 'xemacs) '(t)
2633 '(:help "Mark unread articles in this group as read"))]
2634 ["Catchup all" gnus-summary-catchup-all t]
2635 ["Catchup to here" gnus-summary-catchup-to-here t]
2636 ["Catchup from here" gnus-summary-catchup-from-here t]
2637 ["Catchup region" gnus-summary-mark-region-as-read
2638 (gnus-mark-active-p)]
2639 ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2640 ("Mark Various"
2641 ["Tick" gnus-summary-tick-article-forward t]
2642 ["Mark as dormant" gnus-summary-mark-as-dormant t]
2643 ["Remove marks" gnus-summary-clear-mark-forward t]
2644 ["Set expirable mark" gnus-summary-mark-as-expirable t]
2645 ["Set bookmark" gnus-summary-set-bookmark t]
2646 ["Remove bookmark" gnus-summary-remove-bookmark t])
2647 ("Limit to"
2648 ["Marks..." gnus-summary-limit-to-marks t]
2649 ["Subject..." gnus-summary-limit-to-subject t]
2650 ["Author..." gnus-summary-limit-to-author t]
01c52d31
MB
2651 ["Recipient..." gnus-summary-limit-to-recipient t]
2652 ["Address..." gnus-summary-limit-to-address t]
23f87bed
MB
2653 ["Age..." gnus-summary-limit-to-age t]
2654 ["Extra..." gnus-summary-limit-to-extra t]
2655 ["Score..." gnus-summary-limit-to-score t]
2656 ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2657 ["Unread" gnus-summary-limit-to-unread t]
2658 ["Unseen" gnus-summary-limit-to-unseen t]
01c52d31
MB
2659 ["Singletons" gnus-summary-limit-to-singletons t]
2660 ["Replied" gnus-summary-limit-to-replied t]
23f87bed 2661 ["Non-dormant" gnus-summary-limit-exclude-dormant t]
996aa8c1 2662 ["Next or process marked articles" gnus-summary-limit-to-articles t]
23f87bed
MB
2663 ["Pop limit" gnus-summary-pop-limit t]
2664 ["Show dormant" gnus-summary-limit-include-dormant t]
2665 ["Hide childless dormant"
2666 gnus-summary-limit-exclude-childless-dormant t]
2667 ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2668 ["Hide marked" gnus-summary-limit-exclude-marks t]
2669 ["Show expunged" gnus-summary-limit-include-expunged t])
2670 ("Process Mark"
2671 ["Set mark" gnus-summary-mark-as-processable t]
2672 ["Remove mark" gnus-summary-unmark-as-processable t]
2673 ["Remove all marks" gnus-summary-unmark-all-processable t]
01c52d31 2674 ["Invert marks" gnus-uu-invert-processable t]
23f87bed
MB
2675 ["Mark above" gnus-uu-mark-over t]
2676 ["Mark series" gnus-uu-mark-series t]
2677 ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2678 ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2679 ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2680 ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2681 ["Mark all" gnus-uu-mark-all t]
2682 ["Mark buffer" gnus-uu-mark-buffer t]
2683 ["Mark sparse" gnus-uu-mark-sparse t]
2684 ["Mark thread" gnus-uu-mark-thread t]
2685 ["Unmark thread" gnus-uu-unmark-thread t]
2686 ("Process Mark Sets"
2687 ["Kill" gnus-summary-kill-process-mark t]
2688 ["Yank" gnus-summary-yank-process-mark
2689 gnus-newsgroup-process-stack]
2690 ["Save" gnus-summary-save-process-mark t]
2691 ["Run command on marked..." gnus-summary-universal-argument t]))
ec7995fa 2692 ("Registry Marks")
23f87bed
MB
2693 ("Scroll article"
2694 ["Page forward" gnus-summary-next-page
2695 ,@(if (featurep 'xemacs) '(t)
2696 '(:help "Show next page of article"))]
2697 ["Page backward" gnus-summary-prev-page
2698 ,@(if (featurep 'xemacs) '(t)
2699 '(:help "Show previous page of article"))]
2700 ["Line forward" gnus-summary-scroll-up t])
2701 ("Move"
2702 ["Next unread article" gnus-summary-next-unread-article t]
2703 ["Previous unread article" gnus-summary-prev-unread-article t]
2704 ["Next article" gnus-summary-next-article t]
2705 ["Previous article" gnus-summary-prev-article t]
2706 ["Next unread subject" gnus-summary-next-unread-subject t]
2707 ["Previous unread subject" gnus-summary-prev-unread-subject t]
2708 ["Next article same subject" gnus-summary-next-same-subject t]
2709 ["Previous article same subject" gnus-summary-prev-same-subject t]
2710 ["First unread article" gnus-summary-first-unread-article t]
2711 ["Best unread article" gnus-summary-best-unread-article t]
2712 ["Go to subject number..." gnus-summary-goto-subject t]
2713 ["Go to article number..." gnus-summary-goto-article t]
2714 ["Go to the last article" gnus-summary-goto-last-article t]
2715 ["Pop article off history" gnus-summary-pop-article t])
2716 ("Sort"
2717 ["Sort by number" gnus-summary-sort-by-number t]
6ecfe5c2 2718 ["Sort by most recent number" gnus-summary-sort-by-most-recent-number t]
23f87bed 2719 ["Sort by author" gnus-summary-sort-by-author t]
01c52d31 2720 ["Sort by recipient" gnus-summary-sort-by-recipient t]
23f87bed
MB
2721 ["Sort by subject" gnus-summary-sort-by-subject t]
2722 ["Sort by date" gnus-summary-sort-by-date t]
6ecfe5c2 2723 ["Sort by most recent date" gnus-summary-sort-by-most-recent-date t]
23f87bed
MB
2724 ["Sort by score" gnus-summary-sort-by-score t]
2725 ["Sort by lines" gnus-summary-sort-by-lines t]
2726 ["Sort by characters" gnus-summary-sort-by-chars t]
2727 ["Randomize" gnus-summary-sort-by-random t]
2728 ["Original sort" gnus-summary-sort-by-original t])
2729 ("Help"
2730 ["Fetch group FAQ" gnus-summary-fetch-faq t]
2731 ["Describe group" gnus-summary-describe-group t]
2732 ["Fetch charter" gnus-group-fetch-charter
2733 ,@(if (featurep 'xemacs) nil
2734 '(:help "Display the charter of the current group"))]
2735 ["Fetch control message" gnus-group-fetch-control
2736 ,@(if (featurep 'xemacs) nil
2737 '(:help "Display the archived control message for the current group"))]
2738 ["Read manual" gnus-info-find-node t])
2739 ("Modes"
2740 ["Pick and read" gnus-pick-mode t]
2741 ["Binary" gnus-binary-mode t])
2742 ("Regeneration"
2743 ["Regenerate" gnus-summary-prepare t]
2744 ["Insert cached articles" gnus-summary-insert-cached-articles t]
2745 ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
01c52d31 2746 ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
23f87bed
MB
2747 ["Toggle threading" gnus-summary-toggle-threads t])
2748 ["See old articles" gnus-summary-insert-old-articles t]
2749 ["See new articles" gnus-summary-insert-new-articles t]
2750 ["Filter articles..." gnus-summary-execute-command t]
2751 ["Run command on articles..." gnus-summary-universal-argument t]
2752 ["Search articles forward..." gnus-summary-search-article-forward t]
2753 ["Search articles backward..." gnus-summary-search-article-backward t]
2754 ["Toggle line truncation" gnus-summary-toggle-truncation t]
2755 ["Expand window" gnus-summary-expand-window t]
2756 ["Expire expirable articles" gnus-summary-expire-articles
2757 (gnus-check-backend-function
2758 'request-expire-articles gnus-newsgroup-name)]
2759 ["Edit local kill file" gnus-summary-edit-local-kill t]
2760 ["Edit main kill file" gnus-summary-edit-global-kill t]
2761 ["Edit group parameters" gnus-summary-edit-parameters t]
2762 ["Customize group parameters" gnus-summary-customize-parameters t]
2763 ["Send a bug report" gnus-bug t]
2764 ("Exit"
2765 ["Catchup and exit" gnus-summary-catchup-and-exit
2766 ,@(if (featurep 'xemacs) '(t)
2767 '(:help "Mark unread articles in this group as read, then exit"))]
2768 ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2769 ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
01c52d31 2770 ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
23f87bed
MB
2771 ["Exit group" gnus-summary-exit
2772 ,@(if (featurep 'xemacs) '(t)
2773 '(:help "Exit current group, return to group selection mode"))]
2774 ["Exit group without updating" gnus-summary-exit-no-update t]
2775 ["Exit and goto next group" gnus-summary-next-group t]
2776 ["Exit and goto prev group" gnus-summary-prev-group t]
2777 ["Reselect group" gnus-summary-reselect-current-group t]
2778 ["Rescan group" gnus-summary-rescan-group t]
2779 ["Update dribble" gnus-summary-save-newsrc t])))
eec82323 2780
6748645f 2781 (gnus-run-hooks 'gnus-summary-menu-hook)))
eec82323 2782
60bd5589
DL
2783(defvar gnus-summary-tool-bar-map nil)
2784
18c06a99
RS
2785;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2786;; affect _new_ message buffers. We might add a function that walks thru all
2787;; summary-mode buffers and force the update.
2788(defun gnus-summary-tool-bar-update (&optional symbol value)
2789 "Update summary mode toolbar.
2790Setter function for custom variables."
2791 (setq-default gnus-summary-tool-bar-map nil)
2792 (when symbol
2793 ;; When used as ":set" function:
2794 (set-default symbol value))
2795 (when (gnus-buffer-live-p gnus-summary-buffer)
2796 (with-current-buffer gnus-summary-buffer
2797 (gnus-summary-make-tool-bar))))
2798
2799(defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2800 'gnus-summary-tool-bar-gnome
2801 'gnus-summary-tool-bar-retro)
2802 "Specifies the Gnus summary tool bar.
2803
2804It can be either a list or a symbol refering to a list. See
2805`gmm-tool-bar-from-list' for the format of the list. The
2806default key map is `gnus-summary-mode-map'.
2807
2808Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2809`gnus-summary-tool-bar-retro'."
2810 :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2811 (const :tag "Retro look" gnus-summary-tool-bar-retro)
2812 (repeat :tag "User defined list" gmm-tool-bar-item)
2813 (symbol))
330f707b 2814 :version "23.1" ;; No Gnus
18c06a99
RS
2815 :initialize 'custom-initialize-default
2816 :set 'gnus-summary-tool-bar-update
2817 :group 'gnus-summary)
2818
2819(defcustom gnus-summary-tool-bar-gnome
2820 '((gnus-summary-post-news "mail/compose" nil)
2821 (gnus-summary-insert-new-articles "mail/inbox" nil
2822 :visible (or (not gnus-agent)
2823 gnus-plugged))
2824 (gnus-summary-reply-with-original "mail/reply")
2825 (gnus-summary-reply "mail/reply" nil :visible nil)
2826 (gnus-summary-followup-with-original "mail/reply-all")
2827 (gnus-summary-followup "mail/reply-all" nil :visible nil)
2828 (gnus-summary-mail-forward "mail/forward")
2829 (gnus-summary-save-article "mail/save")
2830 (gnus-summary-search-article-forward "search" nil :visible nil)
2831 (gnus-summary-print-article "print")
2832 (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2833 ;; Some new commands that may need more suitable icons:
2834 (gnus-summary-save-newsrc "save" nil :visible nil)
2835 ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2836 (gnus-summary-prev-article "left-arrow")
2837 (gnus-summary-next-article "right-arrow")
2838 (gnus-summary-next-page "next-page")
2839 ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2840 ;;
2841 ;; Maybe some sort-by-... could be added:
2842 ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2843 ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2844 (gnus-summary-mark-as-expirable
2845 "delete" nil
2846 :visible (gnus-check-backend-function 'request-expire-articles
2847 gnus-newsgroup-name))
2848 (gnus-summary-mark-as-spam
2849 "mail/spam" t
2850 :visible (and (fboundp 'spam-group-ham-contents-p)
2851 (spam-group-ham-contents-p gnus-newsgroup-name))
2852 :help "Mark as spam")
2853 (gnus-summary-mark-as-read-forward
2854 "mail/not-spam" nil
2855 :visible (and (fboundp 'spam-group-spam-contents-p)
2856 (spam-group-spam-contents-p gnus-newsgroup-name)))
2857 ;;
2858 (gnus-summary-exit "exit")
2859 (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2860 (gnus-info-find-node "help"))
2861 "List of functions for the summary tool bar (GNOME style).
2862
2863See `gmm-tool-bar-from-list' for the format of the list."
2864 :type '(repeat gmm-tool-bar-item)
330f707b 2865 :version "23.1" ;; No Gnus
18c06a99
RS
2866 :initialize 'custom-initialize-default
2867 :set 'gnus-summary-tool-bar-update
2868 :group 'gnus-summary)
2869
2870(defcustom gnus-summary-tool-bar-retro
2871 '((gnus-summary-prev-unread-article "gnus/prev-ur")
2872 (gnus-summary-next-unread-article "gnus/next-ur")
2873 (gnus-summary-post-news "gnus/post")
2874 (gnus-summary-followup-with-original "gnus/fuwo")
2875 (gnus-summary-followup "gnus/followup")
2876 (gnus-summary-reply-with-original "gnus/reply-wo")
2877 (gnus-summary-reply "gnus/reply")
2878 (gnus-summary-caesar-message "gnus/rot13")
2879 (gnus-uu-decode-uu "gnus/uu-decode")
2880 (gnus-summary-save-article-file "gnus/save-aif")
2881 (gnus-summary-save-article "gnus/save-art")
2882 (gnus-uu-post-news "gnus/uu-post")
2883 (gnus-summary-catchup "gnus/catchup")
2884 (gnus-summary-catchup-and-exit "gnus/cu-exit")
2885 (gnus-summary-exit "gnus/exit-summ")
2886 ;; Some new command that may need more suitable icons:
2887 (gnus-summary-print-article "gnus/print" nil :visible nil)
2888 (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2889 (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2890 ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2891 (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2892 ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2893 ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2894 ;;
2895 (gnus-info-find-node "gnus/help" nil :visible nil))
2896 "List of functions for the summary tool bar (retro look).
2897
2898See `gmm-tool-bar-from-list' for the format of the list."
2899 :type '(repeat gmm-tool-bar-item)
330f707b 2900 :version "23.1" ;; No Gnus
18c06a99
RS
2901 :initialize 'custom-initialize-default
2902 :set 'gnus-summary-tool-bar-update
2903 :group 'gnus-summary)
2904
2905(defcustom gnus-summary-tool-bar-zap-list t
2906 "List of icon items from the global tool bar.
2907These items are not displayed in the Gnus summary mode tool bar.
2908
2909See `gmm-tool-bar-from-list' for the format of the list."
2910 :type 'gmm-tool-bar-zap-list
330f707b 2911 :version "23.1" ;; No Gnus
18c06a99
RS
2912 :initialize 'custom-initialize-default
2913 :set 'gnus-summary-tool-bar-update
2914 :group 'gnus-summary)
2915
2916(defvar image-load-path)
f654fa04 2917(defvar tool-bar-map)
18c06a99
RS
2918
2919(defun gnus-summary-make-tool-bar (&optional force)
2920 "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2921When FORCE, rebuild the tool bar."
2922 (when (and (not (featurep 'xemacs))
2923 (boundp 'tool-bar-mode)
2924 tool-bar-mode
2925 (or (not gnus-summary-tool-bar-map) force))
2926 (let* ((load-path
2927 (gmm-image-load-path-for-library "gnus"
2928 "mail/save.xpm"
2929 nil t))
2930 (image-load-path (cons (car load-path)
2931 (when (boundp 'image-load-path)
2932 image-load-path)))
2933 (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2934 gnus-summary-tool-bar-zap-list
2935 'gnus-summary-mode-map)))
2936 (when map
2937 ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2938 ;; uses it's value.
2939 (setq gnus-summary-tool-bar-map map))))
2940 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
60bd5589 2941
eec82323
LMI
2942(defun gnus-score-set-default (var value)
2943 "A version of set that updates the GNU Emacs menu-bar."
2944 (set var value)
2945 ;; It is the message that forces the active status to be updated.
2946 (message ""))
2947
2948(defun gnus-make-score-map (type)
2949 "Make a summary score map of type TYPE."
2950 (if t
2951 nil
2952 (let ((headers '(("author" "from" string)
2953 ("subject" "subject" string)
2954 ("article body" "body" string)
2955 ("article head" "head" string)
2956 ("xref" "xref" string)
16409b0b 2957 ("extra header" "extra" string)
eec82323
LMI
2958 ("lines" "lines" number)
2959 ("followups to author" "followup" string)))
2960 (types '((number ("less than" <)
2961 ("greater than" >)
2962 ("equal" =))
2963 (string ("substring" s)
2964 ("exact string" e)
2965 ("fuzzy string" f)
2966 ("regexp" r))))
2967 (perms '(("temporary" (current-time-string))
2968 ("permanent" nil)
2969 ("immediate" now)))
2970 header)
2971 (list
2972 (apply
2973 'nconc
2974 (list
2975 (if (eq type 'lower)
2976 "Lower score"
2977 "Increase score"))
2978 (let (outh)
2979 (while headers
2980 (setq header (car headers))
2981 (setq outh
2982 (cons
2983 (apply
2984 'nconc
2985 (list (car header))
2986 (let ((ts (cdr (assoc (nth 2 header) types)))
2987 outt)
2988 (while ts
2989 (setq outt
2990 (cons
2991 (apply
2992 'nconc
2993 (list (caar ts))
2994 (let ((ps perms)
2995 outp)
2996 (while ps
2997 (setq outp
2998 (cons
2999 (vector
3000 (caar ps)
3001 (list
3002 'gnus-summary-score-entry
3003 (nth 1 header)
3004 (if (or (string= (nth 1 header)
3005 "head")
3006 (string= (nth 1 header)
3007 "body"))
3008 ""
3009 (list 'gnus-summary-header
3010 (nth 1 header)))
3011 (list 'quote (nth 1 (car ts)))
16409b0b
GM
3012 (list 'gnus-score-delta-default
3013 nil)
eec82323
LMI
3014 (nth 1 (car ps))
3015 t)
3016 t)
3017 outp))
3018 (setq ps (cdr ps)))
3019 (list (nreverse outp))))
3020 outt))
3021 (setq ts (cdr ts)))
3022 (list (nreverse outt))))
3023 outh))
3024 (setq headers (cdr headers)))
3025 (list (nreverse outh))))))))
3026
704f1663
GM
3027
3028(declare-function turn-on-gnus-mailing-list-mode "gnus-ml" ())
398a825b 3029(defvar bookmark-make-record-function)
eec82323
LMI
3030\f
3031
3032(defun gnus-summary-mode (&optional group)
3033 "Major mode for reading articles.
3034
3035All normal editing commands are switched off.
3036\\<gnus-summary-mode-map>
3037Each line in this buffer represents one article. To read an
3038article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
3039and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
3040respectively.
3041
3042You can also post articles and send mail from this buffer. To
23f87bed 3043follow up an article, type `\\[gnus-summary-followup]'. To mail a reply to the author
eec82323
LMI
3044of an article, type `\\[gnus-summary-reply]'.
3045
3046There are approx. one gazillion commands you can execute in this
3047buffer; read the info pages for more information (`\\[gnus-info-find-node]').
3048
3049The following commands are available:
3050
3051\\{gnus-summary-mode-map}"
3052 (interactive)
eec82323 3053 (kill-all-local-variables)
01c52d31
MB
3054 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
3055 (gnus-summary-make-local-variables))
3056 (gnus-summary-make-local-variables)
3057 (setq gnus-newsgroup-name group)
60bd5589
DL
3058 (when (gnus-visual-p 'summary-menu 'menu)
3059 (gnus-summary-make-menu-bar)
3060 (gnus-summary-make-tool-bar))
eec82323
LMI
3061 (gnus-make-thread-indent-array)
3062 (gnus-simplify-mode-line)
3063 (setq major-mode 'gnus-summary-mode)
3064 (setq mode-name "Summary")
eec82323 3065 (use-local-map gnus-summary-mode-map)
16409b0b 3066 (buffer-disable-undo)
01c52d31
MB
3067 (setq buffer-read-only t ;Disable modification
3068 show-trailing-whitespace nil)
eec82323 3069 (setq truncate-lines t)
9bfd9a76 3070 (add-to-invisibility-spec '(gnus-sum . t))
eec82323
LMI
3071 (gnus-summary-set-display-table)
3072 (gnus-set-default-directory)
eec82323
LMI
3073 (make-local-variable 'gnus-summary-line-format)
3074 (make-local-variable 'gnus-summary-line-format-spec)
6748645f
LMI
3075 (make-local-variable 'gnus-summary-dummy-line-format)
3076 (make-local-variable 'gnus-summary-dummy-line-format-spec)
eec82323 3077 (make-local-variable 'gnus-summary-mark-positions)
23f87bed 3078 (gnus-make-local-hook 'pre-command-hook)
6748645f 3079 (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
cfcd5c91 3080 (gnus-run-mode-hooks 'gnus-summary-mode-hook)
23f87bed 3081 (turn-on-gnus-mailing-list-mode)
87545352 3082 (mm-enable-multibyte)
45be326a
TV
3083 (set (make-local-variable 'bookmark-make-record-function)
3084 'gnus-summary-bookmark-make-record)
eec82323
LMI
3085 (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3086 (gnus-update-summary-mark-positions))
3087
3088(defun gnus-summary-make-local-variables ()
3089 "Make all the local summary buffer variables."
16409b0b
GM
3090 (let (global)
3091 (dolist (local gnus-summary-local-variables)
eec82323
LMI
3092 (if (consp local)
3093 (progn
3094 (if (eq (cdr local) 'global)
3095 ;; Copy the global value of the variable.
3096 (setq global (symbol-value (car local)))
3097 ;; Use the value from the list.
3098 (setq global (eval (cdr local))))
16409b0b 3099 (set (make-local-variable (car local)) global))
eec82323 3100 ;; Simple nil-valued local variable.
16409b0b 3101 (set (make-local-variable local) nil)))))
eec82323
LMI
3102
3103(defun gnus-summary-clear-local-variables ()
3104 (let ((locals gnus-summary-local-variables))
3105 (while locals
3106 (if (consp (car locals))
01c52d31 3107 (and (symbolp (caar locals))
eec82323 3108 (set (caar locals) nil))
01c52d31 3109 (and (symbolp (car locals))
eec82323
LMI
3110 (set (car locals) nil)))
3111 (setq locals (cdr locals)))))
3112
3113;; Summary data functions.
3114
3115(defmacro gnus-data-number (data)
3116 `(car ,data))
3117
3118(defmacro gnus-data-set-number (data number)
3119 `(setcar ,data ,number))
3120
3121(defmacro gnus-data-mark (data)
3122 `(nth 1 ,data))
3123
3124(defmacro gnus-data-set-mark (data mark)
3125 `(setcar (nthcdr 1 ,data) ,mark))
3126
3127(defmacro gnus-data-pos (data)
3128 `(nth 2 ,data))
3129
3130(defmacro gnus-data-set-pos (data pos)
3131 `(setcar (nthcdr 2 ,data) ,pos))
3132
3133(defmacro gnus-data-header (data)
3134 `(nth 3 ,data))
3135
3136(defmacro gnus-data-set-header (data header)
3137 `(setf (nth 3 ,data) ,header))
3138
3139(defmacro gnus-data-level (data)
3140 `(nth 4 ,data))
3141
3142(defmacro gnus-data-unread-p (data)
3143 `(= (nth 1 ,data) gnus-unread-mark))
3144
3145(defmacro gnus-data-read-p (data)
3146 `(/= (nth 1 ,data) gnus-unread-mark))
3147
3148(defmacro gnus-data-pseudo-p (data)
3149 `(consp (nth 3 ,data)))
3150
3151(defmacro gnus-data-find (number)
3152 `(assq ,number gnus-newsgroup-data))
3153
3154(defmacro gnus-data-find-list (number &optional data)
3155 `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3156 (memq (assq ,number bdata)
3157 bdata)))
3158
3159(defmacro gnus-data-make (number mark pos header level)
3160 `(list ,number ,mark ,pos ,header ,level))
3161
3162(defun gnus-data-enter (after-article number mark pos header level offset)
3163 (let ((data (gnus-data-find-list after-article)))
3164 (unless data
3165 (error "No such article: %d" after-article))
3166 (setcdr data (cons (gnus-data-make number mark pos header level)
3167 (cdr data)))
3168 (setq gnus-newsgroup-data-reverse nil)
3169 (gnus-data-update-list (cddr data) offset)))
3170
3171(defun gnus-data-enter-list (after-article list &optional offset)
3172 (when list
3173 (let ((data (and after-article (gnus-data-find-list after-article)))
3174 (ilist list))
6748645f
LMI
3175 (if (not (or data
3176 after-article))
3177 (let ((odata gnus-newsgroup-data))
3178 (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
eec82323 3179 (when offset
6748645f 3180 (gnus-data-update-list odata offset)))
01c52d31 3181 ;; Find the last element in the list to be spliced into the main
6748645f 3182 ;; list.
01c52d31 3183 (setq list (last list))
6748645f
LMI
3184 (if (not data)
3185 (progn
3186 (setcdr list gnus-newsgroup-data)
3187 (setq gnus-newsgroup-data ilist)
3188 (when offset
3189 (gnus-data-update-list (cdr list) offset)))
3190 (setcdr list (cdr data))
3191 (setcdr data ilist)
3192 (when offset
3193 (gnus-data-update-list (cdr list) offset))))
eec82323
LMI
3194 (setq gnus-newsgroup-data-reverse nil))))
3195
3196(defun gnus-data-remove (article &optional offset)
3197 (let ((data gnus-newsgroup-data))
3198 (if (= (gnus-data-number (car data)) article)
3199 (progn
3200 (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3201 gnus-newsgroup-data-reverse nil)
3202 (when offset
3203 (gnus-data-update-list gnus-newsgroup-data offset)))
3204 (while (cdr data)
3205 (when (= (gnus-data-number (cadr data)) article)
3206 (setcdr data (cddr data))
3207 (when offset
3208 (gnus-data-update-list (cdr data) offset))
3209 (setq data nil
3210 gnus-newsgroup-data-reverse nil))
3211 (setq data (cdr data))))))
3212
3213(defmacro gnus-data-list (backward)
3214 `(if ,backward
3215 (or gnus-newsgroup-data-reverse
3216 (setq gnus-newsgroup-data-reverse
3217 (reverse gnus-newsgroup-data)))
3218 gnus-newsgroup-data))
3219
3220(defun gnus-data-update-list (data offset)
3221 "Add OFFSET to the POS of all data entries in DATA."
6748645f 3222 (setq gnus-newsgroup-data-reverse nil)
eec82323
LMI
3223 (while data
3224 (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3225 (setq data (cdr data))))
3226
eec82323
LMI
3227(defun gnus-summary-article-pseudo-p (article)
3228 "Say whether this article is a pseudo article or not."
3229 (not (vectorp (gnus-data-header (gnus-data-find article)))))
3230
3231(defmacro gnus-summary-article-sparse-p (article)
3232 "Say whether this article is a sparse article or not."
a8151ef7 3233 `(memq ,article gnus-newsgroup-sparse))
eec82323
LMI
3234
3235(defmacro gnus-summary-article-ancient-p (article)
3236 "Say whether this article is a sparse article or not."
3237 `(memq ,article gnus-newsgroup-ancient))
3238
3239(defun gnus-article-parent-p (number)
3240 "Say whether this article is a parent or not."
3241 (let ((data (gnus-data-find-list number)))
23f87bed 3242 (and (cdr data) ; There has to be an article after...
eec82323
LMI
3243 (< (gnus-data-level (car data)) ; And it has to have a higher level.
3244 (gnus-data-level (nth 1 data))))))
3245
3246(defun gnus-article-children (number)
3247 "Return a list of all children to NUMBER."
3248 (let* ((data (gnus-data-find-list number))
3249 (level (gnus-data-level (car data)))
3250 children)
3251 (setq data (cdr data))
3252 (while (and data
3253 (= (gnus-data-level (car data)) (1+ level)))
3254 (push (gnus-data-number (car data)) children)
3255 (setq data (cdr data)))
3256 children))
3257
3258(defmacro gnus-summary-skip-intangible ()
3259 "If the current article is intangible, then jump to a different article."
3260 '(let ((to (get-text-property (point) 'gnus-intangible)))
3261 (and to (gnus-summary-goto-subject to))))
3262
3263(defmacro gnus-summary-article-intangible-p ()
3264 "Say whether this article is intangible or not."
3265 '(get-text-property (point) 'gnus-intangible))
3266
3267(defun gnus-article-read-p (article)
3268 "Say whether ARTICLE is read or not."
3269 (not (or (memq article gnus-newsgroup-marked)
23f87bed 3270 (memq article gnus-newsgroup-spam-marked)
eec82323
LMI
3271 (memq article gnus-newsgroup-unreads)
3272 (memq article gnus-newsgroup-unselected)
3273 (memq article gnus-newsgroup-dormant))))
3274
3275;; Some summary mode macros.
3276
3277(defmacro gnus-summary-article-number ()
3278 "The article number of the article on the current line.
8f688cb0 3279If there isn't an article number here, then we return the current
eec82323
LMI
3280article number."
3281 '(progn
3282 (gnus-summary-skip-intangible)
3283 (or (get-text-property (point) 'gnus-number)
3284 (gnus-summary-last-subject))))
3285
3286(defmacro gnus-summary-article-header (&optional number)
6748645f 3287 "Return the header of article NUMBER."
eec82323
LMI
3288 `(gnus-data-header (gnus-data-find
3289 ,(or number '(gnus-summary-article-number)))))
3290
3291(defmacro gnus-summary-thread-level (&optional number)
6748645f 3292 "Return the level of thread that starts with article NUMBER."
eec82323
LMI
3293 `(if (and (eq gnus-summary-make-false-root 'dummy)
3294 (get-text-property (point) 'gnus-intangible))
3295 0
3296 (gnus-data-level (gnus-data-find
3297 ,(or number '(gnus-summary-article-number))))))
3298
3299(defmacro gnus-summary-article-mark (&optional number)
6748645f 3300 "Return the mark of article NUMBER."
eec82323
LMI
3301 `(gnus-data-mark (gnus-data-find
3302 ,(or number '(gnus-summary-article-number)))))
3303
3304(defmacro gnus-summary-article-pos (&optional number)
6748645f 3305 "Return the position of the line of article NUMBER."
eec82323
LMI
3306 `(gnus-data-pos (gnus-data-find
3307 ,(or number '(gnus-summary-article-number)))))
3308
3309(defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3310(defmacro gnus-summary-article-subject (&optional number)
3311 "Return current subject string or nil if nothing."
3312 `(let ((headers
3313 ,(if number
3314 `(gnus-data-header (assq ,number gnus-newsgroup-data))
3315 '(gnus-data-header (assq (gnus-summary-article-number)
3316 gnus-newsgroup-data)))))
3317 (and headers
3318 (vectorp headers)
3319 (mail-header-subject headers))))
3320
3321(defmacro gnus-summary-article-score (&optional number)
3322 "Return current article score."
3323 `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3324 gnus-newsgroup-scored))
3325 gnus-summary-default-score 0))
3326
3327(defun gnus-summary-article-children (&optional number)
6748645f 3328 "Return a list of article numbers that are children of article NUMBER."
eec82323
LMI
3329 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3330 (level (gnus-data-level (car data)))
3331 l children)
3332 (while (and (setq data (cdr data))
3333 (> (setq l (gnus-data-level (car data))) level))
3334 (and (= (1+ level) l)
3335 (push (gnus-data-number (car data))
3336 children)))
3337 (nreverse children)))
3338
3339(defun gnus-summary-article-parent (&optional number)
6748645f 3340 "Return the article number of the parent of article NUMBER."
eec82323
LMI
3341 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3342 (gnus-data-list t)))
3343 (level (gnus-data-level (car data))))
3344 (if (zerop level)
3345 () ; This is a root.
3346 ;; We search until we find an article with a level less than
3347 ;; this one. That function has to be the parent.
3348 (while (and (setq data (cdr data))
3349 (not (< (gnus-data-level (car data)) level))))
3350 (and data (gnus-data-number (car data))))))
3351
3352(defun gnus-unread-mark-p (mark)
3353 "Say whether MARK is the unread mark."
3354 (= mark gnus-unread-mark))
3355
3356(defun gnus-read-mark-p (mark)
3357 "Say whether MARK is one of the marks that mark as read.
3358This is all marks except unread, ticked, dormant, and expirable."
3359 (not (or (= mark gnus-unread-mark)
3360 (= mark gnus-ticked-mark)
23f87bed 3361 (= mark gnus-spam-mark)
eec82323
LMI
3362 (= mark gnus-dormant-mark)
3363 (= mark gnus-expirable-mark))))
3364
3365(defmacro gnus-article-mark (number)
6748645f
LMI
3366 "Return the MARK of article NUMBER.
3367This macro should only be used when computing the mark the \"first\"
3368time; i.e., when generating the summary lines. After that,
3369`gnus-summary-article-mark' should be used to examine the
3370marks of articles."
eec82323 3371 `(cond
6748645f 3372 ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
6748645f 3373 ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
eec82323
LMI
3374 ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3375 ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
23f87bed 3376 ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
eec82323
LMI
3377 ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3378 ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3379 (t (or (cdr (assq ,number gnus-newsgroup-reads))
3380 gnus-ancient-mark))))
3381
3382;; Saving hidden threads.
3383
eec82323
LMI
3384(defmacro gnus-save-hidden-threads (&rest forms)
3385 "Save hidden threads, eval FORMS, and restore the hidden threads."
3386 (let ((config (make-symbol "config")))
3387 `(let ((,config (gnus-hidden-threads-configuration)))
3388 (unwind-protect
3389 (save-excursion
3390 ,@forms)
3391 (gnus-restore-hidden-threads-configuration ,config)))))
23f87bed
MB
3392(put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3393(put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
eec82323 3394
107ecebb
AS
3395(defun gnus-data-compute-positions ()
3396 "Compute the positions of all articles."
3397 (setq gnus-newsgroup-data-reverse nil)
3398 (let ((data gnus-newsgroup-data))
3399 (save-excursion
3400 (gnus-save-hidden-threads
3401 (gnus-summary-show-all-threads)
3402 (goto-char (point-min))
3403 (while data
3404 (while (get-text-property (point) 'gnus-intangible)
3405 (forward-line 1))
3406 (gnus-data-set-pos (car data) (+ (point) 3))
3407 (setq data (cdr data))
3408 (forward-line 1))))))
3409
16409b0b
GM
3410(defun gnus-hidden-threads-configuration ()
3411 "Return the current hidden threads configuration."
3412 (save-excursion
3413 (let (config)
3414 (goto-char (point-min))
62a83cc8
KY
3415 (while (not (eobp))
3416 (when (eq (get-char-property (point-at-eol) 'invisible) 'gnus-sum)
3417 (push (save-excursion (forward-line 0) (point)) config))
3418 (forward-line 1))
16409b0b
GM
3419 config)))
3420
3421(defun gnus-restore-hidden-threads-configuration (config)
3422 "Restore hidden threads configuration from CONFIG."
3423 (save-excursion
c7a91ce1 3424 (let (point (inhibit-read-only t))
16409b0b 3425 (while (setq point (pop config))
62a83cc8
KY
3426 (goto-char point)
3427 (gnus-summary-hide-thread)))))
16409b0b 3428
eec82323
LMI
3429;; Various summary mode internalish functions.
3430
3431(defun gnus-mouse-pick-article (e)
3432 (interactive "e")
3433 (mouse-set-point e)
3434 (gnus-summary-next-page nil t))
3435
3436(defun gnus-summary-set-display-table ()
16409b0b
GM
3437 "Change the display table.
3438Odd characters have a tendency to mess
3439up nicely formatted displays - we make all possible glyphs
3440display only a single character."
eec82323
LMI
3441
3442 ;; We start from the standard display table, if any.
3443 (let ((table (or (copy-sequence standard-display-table)
3444 (make-display-table)))
3445 (i 32))
3446 ;; Nix out all the control chars...
3447 (while (>= (setq i (1- i)) 0)
2b968687 3448 (gnus-put-display-table i [??] table))
23f87bed 3449 ;; ... but not newline and cr, of course. (cr is necessary for the
eec82323 3450 ;; selective display).
2b968687
MB
3451 (gnus-put-display-table ?\n nil table)
3452 (gnus-put-display-table ?\r nil table)
6748645f 3453 ;; We keep TAB as well.
2b968687 3454 (gnus-put-display-table ?\t nil table)
719120ef 3455 ;; We nix out any glyphs 127 through 255, or 127 through 159 in
fe62aacc 3456 ;; Emacs 23 (unicode), that are not set already.
719120ef
MB
3457 (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3458 160
3459 256)))
eec82323
LMI
3460 (while (>= (setq i (1- i)) 127)
3461 ;; Only modify if the entry is nil.
2b968687
MB
3462 (unless (gnus-get-display-table i table)
3463 (gnus-put-display-table i [??] table))))
eec82323
LMI
3464 (setq buffer-display-table table)))
3465
23f87bed
MB
3466(defun gnus-summary-set-article-display-arrow (pos)
3467 "Update the overlay arrow to point to line at position POS."
e3e955fe
MB
3468 (when gnus-summary-display-arrow
3469 (make-local-variable 'overlay-arrow-position)
3470 (make-local-variable 'overlay-arrow-string)
23f87bed
MB
3471 (save-excursion
3472 (goto-char pos)
3473 (beginning-of-line)
3474 (unless overlay-arrow-position
3475 (setq overlay-arrow-position (make-marker)))
3476 (setq overlay-arrow-string "=>"
3477 overlay-arrow-position (set-marker overlay-arrow-position
3478 (point)
3479 (current-buffer))))))
3480
eec82323
LMI
3481(defun gnus-summary-setup-buffer (group)
3482 "Initialize summary buffer."
23f87bed
MB
3483 (let ((buffer (gnus-summary-buffer-name group))
3484 (dead-name (concat "*Dead Summary "
3485 (gnus-group-decoded-name group) "*")))
3486 ;; If a dead summary buffer exists, we kill it.
3487 (when (gnus-buffer-live-p dead-name)
3488 (gnus-kill-buffer dead-name))
eec82323
LMI
3489 (if (get-buffer buffer)
3490 (progn
3491 (set-buffer buffer)
3492 (setq gnus-summary-buffer (current-buffer))
3493 (not gnus-newsgroup-prepared))
3494 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
6748645f 3495 (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
eec82323
LMI
3496 (gnus-summary-mode group)
3497 (when gnus-carpal
3498 (gnus-carpal-setup-buffer 'summary))
01c52d31
MB
3499 (when (gnus-group-quit-config group)
3500 (set (make-local-variable 'gnus-single-article-buffer) nil))
3501 (make-local-variable 'gnus-article-buffer)
3502 (make-local-variable 'gnus-article-current)
3503 (make-local-variable 'gnus-original-article-buffer)
eec82323 3504 (setq gnus-newsgroup-name group)
23f87bed
MB
3505 ;; Set any local variables in the group parameters.
3506 (gnus-summary-set-local-parameters gnus-newsgroup-name)
eec82323
LMI
3507 t)))
3508
3509(defun gnus-set-global-variables ()
16409b0b
GM
3510 "Set the global equivalents of the buffer-local variables.
3511They are set to the latest values they had. These reflect the summary
3512buffer that was in action when the last article was fetched."
eec82323
LMI
3513 (when (eq major-mode 'gnus-summary-mode)
3514 (setq gnus-summary-buffer (current-buffer))
3515 (let ((name gnus-newsgroup-name)
3516 (marked gnus-newsgroup-marked)
23f87bed 3517 (spam gnus-newsgroup-spam-marked)
eec82323
LMI
3518 (unread gnus-newsgroup-unreads)
3519 (headers gnus-current-headers)
3520 (data gnus-newsgroup-data)
3521 (summary gnus-summary-buffer)
3522 (article-buffer gnus-article-buffer)
3523 (original gnus-original-article-buffer)
3524 (gac gnus-article-current)
3525 (reffed gnus-reffed-article-number)
16409b0b 3526 (score-file gnus-current-score-file)
23f87bed
MB
3527 (default-charset gnus-newsgroup-charset)
3528 vlist)
3529 (let ((locals gnus-newsgroup-variables))
3530 (while locals
3531 (if (consp (car locals))
3532 (push (eval (caar locals)) vlist)
3533 (push (eval (car locals)) vlist))
3534 (setq locals (cdr locals)))
3535 (setq vlist (nreverse vlist)))
01c52d31 3536 (with-current-buffer gnus-group-buffer
6748645f
LMI
3537 (setq gnus-newsgroup-name name
3538 gnus-newsgroup-marked marked
23f87bed 3539 gnus-newsgroup-spam-marked spam
6748645f
LMI
3540 gnus-newsgroup-unreads unread
3541 gnus-current-headers headers
3542 gnus-newsgroup-data data
3543 gnus-article-current gac
3544 gnus-summary-buffer summary
3545 gnus-article-buffer article-buffer
3546 gnus-original-article-buffer original
3547 gnus-reffed-article-number reffed
16409b0b
GM
3548 gnus-current-score-file score-file
3549 gnus-newsgroup-charset default-charset)
23f87bed
MB
3550 (let ((locals gnus-newsgroup-variables))
3551 (while locals
3552 (if (consp (car locals))
3553 (set (caar locals) (pop vlist))
3554 (set (car locals) (pop vlist)))
3555 (setq locals (cdr locals))))
eec82323
LMI
3556 ;; The article buffer also has local variables.
3557 (when (gnus-buffer-live-p gnus-article-buffer)
3558 (set-buffer gnus-article-buffer)
3559 (setq gnus-summary-buffer summary))))))
3560
3561(defun gnus-summary-article-unread-p (article)
3562 "Say whether ARTICLE is unread or not."
3563 (memq article gnus-newsgroup-unreads))
3564
3565(defun gnus-summary-first-article-p (&optional article)
3566 "Return whether ARTICLE is the first article in the buffer."
3567 (if (not (setq article (or article (gnus-summary-article-number))))
3568 nil
3569 (eq article (caar gnus-newsgroup-data))))
3570
3571(defun gnus-summary-last-article-p (&optional article)
3572 "Return whether ARTICLE is the last article in the buffer."
3573 (if (not (setq article (or article (gnus-summary-article-number))))
16409b0b
GM
3574 ;; All non-existent numbers are the last article. :-)
3575 t
eec82323
LMI
3576 (not (cdr (gnus-data-find-list article)))))
3577
4921bbdd
CY
3578(defun gnus-make-thread-indent-array (&optional n)
3579 (when (or n
3580 (progn (setq n 200) nil)
3581 (null gnus-thread-indent-array)
3582 (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3583 (setq gnus-thread-indent-array (make-vector (1+ n) "")
3584 gnus-thread-indent-array-level gnus-thread-indent-level)
3585 (while (>= n 0)
3586 (aset gnus-thread-indent-array n
6a30c01d 3587 (make-string (* n gnus-thread-indent-level) ? ))
4921bbdd 3588 (setq n (1- n)))))
eec82323
LMI
3589
3590(defun gnus-update-summary-mark-positions ()
3591 "Compute where the summary marks are to go."
3592 (save-excursion
6748645f 3593 (when (gnus-buffer-exists-p gnus-summary-buffer)
eec82323 3594 (set-buffer gnus-summary-buffer))
5153a47a
MB
3595 (let ((spec gnus-summary-line-format-spec)
3596 pos)
eec82323
LMI
3597 (save-excursion
3598 (gnus-set-work-buffer)
5153a47a
MB
3599 (let ((gnus-tmp-unread ?Z)
3600 (gnus-replied-mark ?Z)
3601 (gnus-score-below-mark ?Z)
3602 (gnus-score-over-mark ?Z)
3603 (gnus-undownloaded-mark ?Z)
3604 (gnus-summary-line-format-spec spec)
54506618 3605 (gnus-newsgroup-downloadable '(0))
5153a47a
MB
3606 (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3607 case-fold-search ignores)
3608 ;; Here, all marks are bound to Z.
3609 (gnus-summary-insert-line header
3610 0 nil t gnus-tmp-unread t nil "" nil 1)
3611 (goto-char (point-min))
3612 ;; Memorize the positions of the same characters as dummy marks.
3613 (while (re-search-forward "[A-D]" nil t)
3614 (push (point) ignores))
54506618 3615 (erase-buffer)
5153a47a
MB
3616 ;; We use A-D as dummy marks in order to know column positions
3617 ;; where marks should be inserted.
3618 (setq gnus-tmp-unread ?A
3619 gnus-replied-mark ?B
3620 gnus-score-below-mark ?C
3621 gnus-score-over-mark ?C
3622 gnus-undownloaded-mark ?D)
3623 (gnus-summary-insert-line header
3624 0 nil t gnus-tmp-unread t nil "" nil 1)
3625 ;; Ignore characters which aren't dummy marks.
3626 (dolist (p ignores)
3627 (delete-region (goto-char (1- p)) p)
3628 (insert ?Z))
eec82323 3629 (goto-char (point-min))
7c3bb5a5 3630 (setq pos (list (cons 'unread
5153a47a 3631 (and (search-forward "A" nil t)
7c3bb5a5 3632 (- (point) (point-min) 1)))))
eec82323 3633 (goto-char (point-min))
5153a47a 3634 (push (cons 'replied (and (search-forward "B" nil t)
667e0ba6 3635 (- (point) (point-min) 1)))
eec82323
LMI
3636 pos)
3637 (goto-char (point-min))
5153a47a 3638 (push (cons 'score (and (search-forward "C" nil t)
667e0ba6 3639 (- (point) (point-min) 1)))
6748645f
LMI
3640 pos)
3641 (goto-char (point-min))
5153a47a 3642 (push (cons 'download (and (search-forward "D" nil t)
7c3bb5a5 3643 (- (point) (point-min) 1)))
eec82323
LMI
3644 pos)))
3645 (setq gnus-summary-mark-positions pos))))
3646
3647(defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3648 "Insert a dummy root in the summary buffer."
3649 (beginning-of-line)
3650 (gnus-add-text-properties
3651 (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3652 (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3653
23f87bed
MB
3654(defun gnus-summary-extract-address-component (from)
3655 (or (car (funcall gnus-extract-address-components from))
3656 from))
3657
3658(defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3659 (let ((mail-parse-charset gnus-newsgroup-charset)
01c52d31 3660 (ignored-from-addresses (gnus-ignored-from-addresses))
23f87bed
MB
3661 ; Is it really necessary to do this next part for each summary line?
3662 ; Luckily, doesn't seem to slow things down much.
16409b0b 3663 (mail-parse-ignored-charsets
01c52d31
MB
3664 (with-current-buffer gnus-summary-buffer
3665 gnus-newsgroup-ignored-charsets)))
23f87bed 3666 (or
01c52d31
MB
3667 (and ignored-from-addresses
3668 (string-match ignored-from-addresses gnus-tmp-from)
23f87bed
MB
3669 (let ((extra-headers (mail-header-extra header))
3670 to
3671 newsgroups)
3672 (cond
3673 ((setq to (cdr (assq 'To extra-headers)))
01c52d31 3674 (concat gnus-summary-to-prefix
23f87bed
MB
3675 (inline
3676 (gnus-summary-extract-address-component
343d6628 3677 (funcall gnus-decode-encoded-address-function to)))))
01c52d31
MB
3678 ((setq newsgroups
3679 (or
3680 (cdr (assq 'Newsgroups extra-headers))
3681 (and
3682 (memq 'Newsgroups gnus-extra-headers)
3683 (eq (car (gnus-find-method-for-group
3684 gnus-newsgroup-name)) 'nntp)
3685 (gnus-group-real-name gnus-newsgroup-name))))
3686 (concat gnus-summary-newsgroup-prefix newsgroups)))))
23f87bed 3687 (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
16409b0b 3688
eec82323
LMI
3689(defun gnus-summary-insert-line (gnus-tmp-header
3690 gnus-tmp-level gnus-tmp-current
23f87bed 3691 undownloaded gnus-tmp-unread gnus-tmp-replied
eec82323
LMI
3692 gnus-tmp-expirable gnus-tmp-subject-or-nil
3693 &optional gnus-tmp-dummy gnus-tmp-score
3694 gnus-tmp-process)
4921bbdd
CY
3695 (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3696 (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3697 gnus-tmp-level)))
eec82323
LMI
3698 (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3699 (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3700 (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3701 (gnus-tmp-score-char
3702 (if (or (null gnus-summary-default-score)
3703 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3704 gnus-summary-zcore-fuzz))
23f87bed 3705 ? ;Whitespace
eec82323
LMI
3706 (if (< gnus-tmp-score gnus-summary-default-score)
3707 gnus-score-below-mark gnus-score-over-mark)))
23f87bed 3708 (gnus-tmp-number (mail-header-number gnus-tmp-header))
eec82323
LMI
3709 (gnus-tmp-replied
3710 (cond (gnus-tmp-process gnus-process-mark)
3711 ((memq gnus-tmp-current gnus-newsgroup-cached)
3712 gnus-cached-mark)
3713 (gnus-tmp-replied gnus-replied-mark)
23f87bed
MB
3714 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3715 gnus-forwarded-mark)
eec82323
LMI
3716 ((memq gnus-tmp-current gnus-newsgroup-saved)
3717 gnus-saved-mark)
23f87bed
MB
3718 ((memq gnus-tmp-number gnus-newsgroup-recent)
3719 gnus-recent-mark)
3720 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3721 gnus-unseen-mark)
3722 (t gnus-no-mark)))
3723 (gnus-tmp-downloaded
3724 (cond (undownloaded
3725 gnus-undownloaded-mark)
3726 (gnus-newsgroup-agentized
3727 gnus-downloaded-mark)
3728 (t
3729 gnus-no-mark)))
eec82323
LMI
3730 (gnus-tmp-from (mail-header-from gnus-tmp-header))
3731 (gnus-tmp-name
3732 (cond
3733 ((string-match "<[^>]+> *$" gnus-tmp-from)
3734 (let ((beg (match-beginning 0)))
23f87bed
MB
3735 (or (and (string-match "^\".+\"" gnus-tmp-from)
3736 (substring gnus-tmp-from 1 (1- (match-end 0))))
eec82323
LMI
3737 (substring gnus-tmp-from 0 beg))))
3738 ((string-match "(.+)" gnus-tmp-from)
3739 (substring gnus-tmp-from
3740 (1+ (match-beginning 0)) (1- (match-end 0))))
3741 (t gnus-tmp-from)))
3742 (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
eec82323
LMI
3743 (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3744 (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
c7a91ce1 3745 (inhibit-read-only t))
eec82323
LMI
3746 (when (string= gnus-tmp-name "")
3747 (setq gnus-tmp-name gnus-tmp-from))
3748 (unless (numberp gnus-tmp-lines)
23f87bed
MB
3749 (setq gnus-tmp-lines -1))
3750 (if (= gnus-tmp-lines -1)
3751 (setq gnus-tmp-lines "?")
3752 (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
64763fe3
MB
3753 (condition-case ()
3754 (gnus-put-text-property
3755 (point)
3756 (progn (eval gnus-summary-line-format-spec) (point))
3757 'gnus-number gnus-tmp-number)
3758 (error (gnus-message 5 "Error updating the summary line")))
eec82323
LMI
3759 (when (gnus-visual-p 'summary-highlight 'highlight)
3760 (forward-line -1)
6748645f 3761 (gnus-run-hooks 'gnus-summary-update-hook)
eec82323
LMI
3762 (forward-line 1))))
3763
3764(defun gnus-summary-update-line (&optional dont-update)
16409b0b 3765 "Update summary line after change."
eec82323
LMI
3766 (when (and gnus-summary-default-score
3767 (not gnus-summary-inhibit-highlight))
3768 (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3769 (article (gnus-summary-article-number))
3770 (score (gnus-summary-article-score article)))
3771 (unless dont-update
3772 (if (and gnus-summary-mark-below
3773 (< (gnus-summary-article-score)
3774 gnus-summary-mark-below))
3775 ;; This article has a low score, so we mark it as read.
3776 (when (memq article gnus-newsgroup-unreads)
3777 (gnus-summary-mark-article-as-read gnus-low-score-mark))
3778 (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3779 ;; This article was previously marked as read on account
3780 ;; of a low score, but now it has risen, so we mark it as
3781 ;; unread.
3782 (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3783 (gnus-summary-update-mark
3784 (if (or (null gnus-summary-default-score)
3785 (<= (abs (- score gnus-summary-default-score))
3786 gnus-summary-zcore-fuzz))
23f87bed 3787 ? ;Whitespace
eec82323
LMI
3788 (if (< score gnus-summary-default-score)
3789 gnus-score-below-mark gnus-score-over-mark))
3790 'score))
3791 ;; Do visual highlighting.
3792 (when (gnus-visual-p 'summary-highlight 'highlight)
6748645f 3793 (gnus-run-hooks 'gnus-summary-update-hook)))))
eec82323
LMI
3794
3795(defvar gnus-tmp-new-adopts nil)
3796
3797(defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3798 "Return the number of articles in THREAD.
3799This may be 0 in some cases -- if none of the articles in
3800the thread are to be displayed."
3801 (let* ((number
23f87bed 3802 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
eec82323
LMI
3803 (cond
3804 ((not (listp thread))
3805 1)
3806 ((and (consp thread) (cdr thread))
3807 (apply
3808 '+ 1 (mapcar
3809 'gnus-summary-number-of-articles-in-thread (cdr thread))))
3810 ((null thread)
3811 1)
3812 ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3813 1)
3814 (t 0))))
3815 (when (and level (zerop level) gnus-tmp-new-adopts)
3816 (incf number
3817 (apply '+ (mapcar
3818 'gnus-summary-number-of-articles-in-thread
3819 gnus-tmp-new-adopts))))
3820 (if char
3821 (if (> number 1) gnus-not-empty-thread-mark
3822 gnus-empty-thread-mark)
3823 number)))
3824
23f87bed
MB
3825(defsubst gnus-summary-line-message-size (head)
3826 "Return pretty-printed version of message size.
3827This function is intended to be used in
3828`gnus-summary-line-format-alist'."
3829 (let ((c (or (mail-header-chars head) -1)))
3830 (cond ((< c 0) "n/a") ; chars not available
3831 ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3832 ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3833 ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3834 (t (format "%dM" (/ c (* 1024.0 1024)))))))
3835
3836
eec82323
LMI
3837(defun gnus-summary-set-local-parameters (group)
3838 "Go through the local params of GROUP and set all variable specs in that list."
01c52d31
MB
3839 (let ((vars '(quit-config))) ; Ignore quit-config.
3840 (dolist (elem (gnus-group-find-parameter group))
eec82323
LMI
3841 (and (consp elem) ; Has to be a cons.
3842 (consp (cdr elem)) ; The cdr has to be a list.
3843 (symbolp (car elem)) ; Has to be a symbol in there.
23f87bed 3844 (not (memq (car elem) vars))
e3e955fe 3845 (ignore-errors
23f87bed 3846 (push (car elem) vars)
e3e955fe
MB
3847 ;; Variables like `gnus-show-threads' that are globally
3848 ;; bound, if used as group parameters, need to get to be
3849 ;; buffer-local, whereas just parameters like `gcc-self',
3850 ;; `timestamp', etc. should not be bound as variables.
3851 (if (boundp (car elem))
3852 (set (make-local-variable (car elem)) (eval (nth 1 elem)))
3853 (eval (nth 1 elem))))))))
eec82323
LMI
3854
3855(defun gnus-summary-read-group (group &optional show-all no-article
6748645f
LMI
3856 kill-buffer no-display backward
3857 select-articles)
eec82323
LMI
3858 "Start reading news in newsgroup GROUP.
3859If SHOW-ALL is non-nil, already read articles are also listed.
3860If NO-ARTICLE is non-nil, no article is selected initially.
3861If NO-DISPLAY, don't generate a summary buffer."
3862 (let (result)
3863 (while (and group
3864 (null (setq result
3865 (let ((gnus-auto-select-next nil))
6748645f
LMI
3866 (or (gnus-summary-read-group-1
3867 group show-all no-article
3868 kill-buffer no-display
3869 select-articles)
3870 (setq show-all nil
16409b0b 3871 select-articles nil)))))
eec82323
LMI
3872 (eq gnus-auto-select-next 'quietly))
3873 (set-buffer gnus-group-buffer)
6748645f
LMI
3874 ;; The entry function called above goes to the next
3875 ;; group automatically, so we go two groups back
3876 ;; if we are searching for the previous group.
3877 (when backward
3878 (gnus-group-prev-unread-group 2))
eec82323
LMI
3879 (if (not (equal group (gnus-group-group-name)))
3880 (setq group (gnus-group-group-name))
3881 (setq group nil)))
3882 result))
3883
3884(defun gnus-summary-read-group-1 (group show-all no-article
6748645f
LMI
3885 kill-buffer no-display
3886 &optional select-articles)
eec82323 3887 ;; Killed foreign groups can't be entered.
23f87bed
MB
3888 ;; (when (and (not (gnus-group-native-p group))
3889 ;; (not (gnus-gethash group gnus-newsrc-hashtb)))
3890 ;; (error "Dead non-native groups can't be entered"))
3891 (gnus-message 5 "Retrieving newsgroup: %s..."
3892 (gnus-group-decoded-name group))
eec82323
LMI
3893 (let* ((new-group (gnus-summary-setup-buffer group))
3894 (quit-config (gnus-group-quit-config group))
6748645f
LMI
3895 (did-select (and new-group (gnus-select-newsgroup
3896 group show-all select-articles))))
eec82323
LMI
3897 (cond
3898 ;; This summary buffer exists already, so we just select it.
3899 ((not new-group)
3900 (gnus-set-global-variables)
3901 (when kill-buffer
3902 (gnus-kill-or-deaden-summary kill-buffer))
3903 (gnus-configure-windows 'summary 'force)
3904 (gnus-set-mode-line 'summary)
3905 (gnus-summary-position-point)
3906 (message "")
3907 t)
3908 ;; We couldn't select this group.
3909 ((null did-select)
3910 (when (and (eq major-mode 'gnus-summary-mode)
3911 (not (equal (current-buffer) kill-buffer)))
3912 (kill-buffer (current-buffer))
3913 (if (not quit-config)
3914 (progn
6748645f
LMI
3915 ;; Update the info -- marks might need to be removed,
3916 ;; for instance.
3917 (gnus-summary-update-info)
eec82323
LMI
3918 (set-buffer gnus-group-buffer)
3919 (gnus-group-jump-to-group group)
3920 (gnus-group-next-unread-group 1))
3921 (gnus-handle-ephemeral-exit quit-config)))
23f87bed
MB
3922 (let ((grpinfo (gnus-get-info group)))
3923 (if (null (gnus-info-read grpinfo))
3924 (gnus-message 3 "Group %s contains no messages"
3925 (gnus-group-decoded-name group))
3926 (gnus-message 3 "Can't select group")))
eec82323
LMI
3927 nil)
3928 ;; The user did a `C-g' while prompting for number of articles,
3929 ;; so we exit this group.
3930 ((eq did-select 'quit)
3931 (and (eq major-mode 'gnus-summary-mode)
3932 (not (equal (current-buffer) kill-buffer))
3933 (kill-buffer (current-buffer)))
3934 (when kill-buffer
3935 (gnus-kill-or-deaden-summary kill-buffer))
3936 (if (not quit-config)
3937 (progn
3938 (set-buffer gnus-group-buffer)
3939 (gnus-group-jump-to-group group)
eec82323
LMI
3940 (gnus-configure-windows 'group 'force))
3941 (gnus-handle-ephemeral-exit quit-config))
3942 ;; Finally signal the quit.
3943 (signal 'quit nil))
3944 ;; The group was successfully selected.
3945 (t
3946 (gnus-set-global-variables)
3947 ;; Save the active value in effect when the group was entered.
3948 (setq gnus-newsgroup-active
3949 (gnus-copy-sequence
3950 (gnus-active gnus-newsgroup-name)))
3951 ;; You can change the summary buffer in some way with this hook.
6748645f 3952 (gnus-run-hooks 'gnus-select-group-hook)
5153a47a
MB
3953 (when (memq 'summary (gnus-update-format-specifications
3954 nil 'summary 'summary-mode 'summary-dummy))
3955 ;; The format specification for the summary line was updated,
3956 ;; so we need to update the mark positions as well.
3957 (gnus-update-summary-mark-positions))
eec82323
LMI
3958 ;; Do score processing.
3959 (when gnus-use-scoring
3960 (gnus-possibly-score-headers))
3961 ;; Check whether to fill in the gaps in the threads.
3962 (when gnus-build-sparse-threads
3963 (gnus-build-sparse-threads))
3964 ;; Find the initial limit.
26c9afc3
MB
3965 (if show-all
3966 (let ((gnus-newsgroup-dormant nil))
eec82323 3967 (gnus-summary-initial-limit show-all))
26c9afc3 3968 (gnus-summary-initial-limit show-all))
eec82323
LMI
3969 ;; Generate the summary buffer.
3970 (unless no-display
3971 (gnus-summary-prepare))
3972 (when gnus-use-trees
3973 (gnus-tree-open group)
3974 (setq gnus-summary-highlight-line-function
3975 'gnus-tree-highlight-article))
3976 ;; If the summary buffer is empty, but there are some low-scored
3977 ;; articles or some excluded dormants, we include these in the
3978 ;; buffer.
3979 (when (and (zerop (buffer-size))
3980 (not no-display))
3981 (cond (gnus-newsgroup-dormant
3982 (gnus-summary-limit-include-dormant))
3983 ((and gnus-newsgroup-scored show-all)
3984 (gnus-summary-limit-include-expunged t))))
3985 ;; Function `gnus-apply-kill-file' must be called in this hook.
6748645f 3986 (gnus-run-hooks 'gnus-apply-kill-hook)
eec82323
LMI
3987 (if (and (zerop (buffer-size))
3988 (not no-display))
3989 (progn
3990 ;; This newsgroup is empty.
3991 (gnus-summary-catchup-and-exit nil t)
3992 (gnus-message 6 "No unread news")
3993 (when kill-buffer
3994 (gnus-kill-or-deaden-summary kill-buffer))
3995 ;; Return nil from this function.
3996 nil)
3997 ;; Hide conversation thread subtrees. We cannot do this in
3998 ;; gnus-summary-prepare-hook since kill processing may not
3999 ;; work with hidden articles.
23f87bed 4000 (gnus-summary-maybe-hide-threads)
6748645f
LMI
4001 (when kill-buffer
4002 (gnus-kill-or-deaden-summary kill-buffer))
23f87bed 4003 (gnus-summary-auto-select-subject)
eec82323
LMI
4004 ;; Show first unread article if requested.
4005 (if (and (not no-article)
4006 (not no-display)
4007 gnus-newsgroup-unreads
4008 gnus-auto-select-first)
16409b0b
GM
4009 (progn
4010 (gnus-configure-windows 'summary)
23f87bed
MB
4011 (let ((art (gnus-summary-article-number)))
4012 (unless (and (not gnus-plugged)
4013 (or (memq art gnus-newsgroup-undownloaded)
4014 (memq art gnus-newsgroup-downloadable)))
4015 (gnus-summary-goto-article art))))
4016 ;; Don't select any articles.
eec82323 4017 (gnus-summary-position-point)
6748645f
LMI
4018 (gnus-configure-windows 'summary 'force)
4019 (gnus-set-mode-line 'summary))
23f87bed
MB
4020 (when (and gnus-auto-center-group
4021 (get-buffer-window gnus-group-buffer t))
eec82323
LMI
4022 ;; Gotta use windows, because recenter does weird stuff if
4023 ;; the current buffer ain't the displayed window.
4024 (let ((owin (selected-window)))
4025 (select-window (get-buffer-window gnus-group-buffer t))
4026 (when (gnus-group-goto-group group)
4027 (recenter))
4028 (select-window owin)))
4029 ;; Mark this buffer as "prepared".
4030 (setq gnus-newsgroup-prepared t)
6748645f 4031 (gnus-run-hooks 'gnus-summary-prepared-hook)
23f87bed
MB
4032 (unless (gnus-ephemeral-group-p group)
4033 (gnus-group-update-group group))
eec82323
LMI
4034 t)))))
4035
23f87bed
MB
4036(defun gnus-summary-auto-select-subject ()
4037 "Select the subject line on initial group entry."
4038 (goto-char (point-min))
4039 (cond
4040 ((eq gnus-auto-select-subject 'best)
4041 (gnus-summary-best-unread-subject))
4042 ((eq gnus-auto-select-subject 'unread)
4043 (gnus-summary-first-unread-subject))
4044 ((eq gnus-auto-select-subject 'unseen)
4045 (gnus-summary-first-unseen-subject))
4046 ((eq gnus-auto-select-subject 'unseen-or-unread)
4047 (gnus-summary-first-unseen-or-unread-subject))
4048 ((eq gnus-auto-select-subject 'first)
4049 ;; Do nothing.
4050 )
4051 ((functionp gnus-auto-select-subject)
4052 (funcall gnus-auto-select-subject))))
4053
eec82323
LMI
4054(defun gnus-summary-prepare ()
4055 "Generate the summary buffer."
4056 (interactive)
c7a91ce1 4057 (let ((inhibit-read-only t))
eec82323
LMI
4058 (erase-buffer)
4059 (setq gnus-newsgroup-data nil
4060 gnus-newsgroup-data-reverse nil)
6748645f 4061 (gnus-run-hooks 'gnus-summary-generate-hook)
eec82323
LMI
4062 ;; Generate the buffer, either with threads or without.
4063 (when gnus-newsgroup-headers
4064 (gnus-summary-prepare-threads
4065 (if gnus-show-threads
4066 (gnus-sort-gathered-threads
4067 (funcall gnus-summary-thread-gathering-function
4068 (gnus-sort-threads
4069 (gnus-cut-threads (gnus-make-threads)))))
4070 ;; Unthreaded display.
4071 (gnus-sort-articles gnus-newsgroup-headers))))
4072 (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
4073 ;; Call hooks for modifying summary buffer.
4074 (goto-char (point-min))
6748645f 4075 (gnus-run-hooks 'gnus-summary-prepare-hook)))
eec82323
LMI
4076
4077(defsubst gnus-general-simplify-subject (subject)
23f87bed 4078 "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
eec82323
LMI
4079 (setq subject
4080 (cond
4081 ;; Truncate the subject.
6748645f
LMI
4082 (gnus-simplify-subject-functions
4083 (gnus-map-function gnus-simplify-subject-functions subject))
eec82323
LMI
4084 ((numberp gnus-summary-gather-subject-limit)
4085 (setq subject (gnus-simplify-subject-re subject))
4086 (if (> (length subject) gnus-summary-gather-subject-limit)
4087 (substring subject 0 gnus-summary-gather-subject-limit)
4088 subject))
4089 ;; Fuzzily simplify it.
4090 ((eq 'fuzzy gnus-summary-gather-subject-limit)
4091 (gnus-simplify-subject-fuzzy subject))
4092 ;; Just remove the leading "Re:".
4093 (t
4094 (gnus-simplify-subject-re subject))))
4095
4096 (if (and gnus-summary-gather-exclude-subject
4097 (string-match gnus-summary-gather-exclude-subject subject))
23f87bed 4098 nil ; This article shouldn't be gathered
eec82323
LMI
4099 subject))
4100
4101(defun gnus-summary-simplify-subject-query ()
4102 "Query where the respool algorithm would put this article."
4103 (interactive)
eec82323 4104 (gnus-summary-select-article)
274f1353 4105 (message "%s" (gnus-general-simplify-subject (gnus-summary-article-subject))))
eec82323
LMI
4106
4107(defun gnus-gather-threads-by-subject (threads)
4108 "Gather threads by looking at Subject headers."
4109 (if (not gnus-summary-make-false-root)
4110 threads
4111 (let ((hashtb (gnus-make-hashtable 1024))
4112 (prev threads)
4113 (result threads)
4114 subject hthread whole-subject)
4115 (while threads
4116 (setq subject (gnus-general-simplify-subject
4117 (setq whole-subject (mail-header-subject
4118 (caar threads)))))
4119 (when subject
4120 (if (setq hthread (gnus-gethash subject hashtb))
4121 (progn
4122 ;; We enter a dummy root into the thread, if we
4123 ;; haven't done that already.
4124 (unless (stringp (caar hthread))
4125 (setcar hthread (list whole-subject (car hthread))))
4126 ;; We add this new gathered thread to this gathered
4127 ;; thread.
4128 (setcdr (car hthread)
4129 (nconc (cdar hthread) (list (car threads))))
4130 ;; Remove it from the list of threads.
4131 (setcdr prev (cdr threads))
4132 (setq threads prev))
4133 ;; Enter this thread into the hash table.
23f87bed
MB
4134 (gnus-sethash subject
4135 (if gnus-summary-make-false-root-always
4136 (progn
4137 ;; If you want a dummy root above all
4138 ;; threads...
4139 (setcar threads (list whole-subject
4140 (car threads)))
4141 threads)
4142 threads)
4143 hashtb)))
eec82323
LMI
4144 (setq prev threads)
4145 (setq threads (cdr threads)))
4146 result)))
4147
4148(defun gnus-gather-threads-by-references (threads)
4149 "Gather threads by looking at References headers."
4150 (let ((idhashtb (gnus-make-hashtable 1024))
4151 (thhashtb (gnus-make-hashtable 1024))
4152 (prev threads)
4153 (result threads)
4154 ids references id gthread gid entered ref)
4155 (while threads
4156 (when (setq references (mail-header-references (caar threads)))
4157 (setq id (mail-header-id (caar threads))
23f87bed 4158 ids (inline (gnus-split-references references))
eec82323
LMI
4159 entered nil)
4160 (while (setq ref (pop ids))
4161 (setq ids (delete ref ids))
4162 (if (not (setq gid (gnus-gethash ref idhashtb)))
4163 (progn
4164 (gnus-sethash ref id idhashtb)
4165 (gnus-sethash id threads thhashtb))
4166 (setq gthread (gnus-gethash gid thhashtb))
4167 (unless entered
4168 ;; We enter a dummy root into the thread, if we
4169 ;; haven't done that already.
4170 (unless (stringp (caar gthread))
4171 (setcar gthread (list (mail-header-subject (caar gthread))
4172 (car gthread))))
4173 ;; We add this new gathered thread to this gathered
4174 ;; thread.
4175 (setcdr (car gthread)
4176 (nconc (cdar gthread) (list (car threads)))))
4177 ;; Add it into the thread hash table.
4178 (gnus-sethash id gthread thhashtb)
4179 (setq entered t)
4180 ;; Remove it from the list of threads.
4181 (setcdr prev (cdr threads))
4182 (setq threads prev))))
4183 (setq prev threads)
4184 (setq threads (cdr threads)))
4185 result))
4186
4187(defun gnus-sort-gathered-threads (threads)
16409b0b 4188 "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
eec82323
LMI
4189 (let ((result threads))
4190 (while threads
4191 (when (stringp (caar threads))
4192 (setcdr (car threads)
16409b0b 4193 (sort (cdar threads) gnus-sort-gathered-threads-function)))
eec82323
LMI
4194 (setq threads (cdr threads)))
4195 result))
4196
4197(defun gnus-thread-loop-p (root thread)
4198 "Say whether ROOT is in THREAD."
4199 (let ((stack (list thread))
4200 (infloop 0)
4201 th)
4202 (while (setq thread (pop stack))
4203 (setq th (cdr thread))
4204 (while (and th
4205 (not (eq (caar th) root)))
4206 (pop th))
4207 (if th
4208 ;; We have found a loop.
4209 (let (ref-dep)
4210 (setcdr thread (delq (car th) (cdr thread)))
4211 (if (boundp (setq ref-dep (intern "none"
4212 gnus-newsgroup-dependencies)))
4213 (setcdr (symbol-value ref-dep)
4214 (nconc (cdr (symbol-value ref-dep))
4215 (list (car th))))
4216 (set ref-dep (list nil (car th))))
4217 (setq infloop 1
4218 stack nil))
4219 ;; Push all the subthreads onto the stack.
4220 (push (cdr thread) stack)))
4221 infloop))
4222
4223(defun gnus-make-threads ()
01ccbb85 4224 "Go through the dependency hashtb and find the roots. Return all threads."
eec82323
LMI
4225 (let (threads)
4226 (while (catch 'infloop
4227 (mapatoms
4228 (lambda (refs)
4229 ;; Deal with self-referencing References loops.
4230 (when (and (car (symbol-value refs))
4231 (not (zerop
4232 (apply
4233 '+
4234 (mapcar
4235 (lambda (thread)
4236 (gnus-thread-loop-p
4237 (car (symbol-value refs)) thread))
4238 (cdr (symbol-value refs)))))))
4239 (setq threads nil)
4240 (throw 'infloop t))
4241 (unless (car (symbol-value refs))
23f87bed
MB
4242 ;; These threads do not refer back to any other
4243 ;; articles, so they're roots.
eec82323
LMI
4244 (setq threads (append (cdr (symbol-value refs)) threads))))
4245 gnus-newsgroup-dependencies)))
4246 threads))
4247
6748645f 4248;; Build the thread tree.
16409b0b 4249(defsubst gnus-dependencies-add-header (header dependencies force-new)
6748645f
LMI
4250 "Enter HEADER into the DEPENDENCIES table if it is not already there.
4251
4252If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4253if it was already present.
4254
4255If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4256will not be entered in the DEPENDENCIES table. Otherwise duplicate
23f87bed
MB
4257Message-IDs will be renamed to a unique Message-ID before being
4258entered.
6748645f
LMI
4259
4260Returns HEADER if it was entered in the DEPENDENCIES. Returns nil otherwise."
4261 (let* ((id (mail-header-id header))
4262 (id-dep (and id (intern id dependencies)))
23f87bed 4263 parent-id ref ref-dep ref-header replaced)
6748645f
LMI
4264 ;; Enter this `header' in the `dependencies' table.
4265 (cond
4266 ((not id-dep)
4267 (setq header nil))
4268 ;; The first two cases do the normal part: enter a new `header'
4269 ;; in the `dependencies' table.
4270 ((not (boundp id-dep))
4271 (set id-dep (list header)))
4272 ((null (car (symbol-value id-dep)))
4273 (setcar (symbol-value id-dep) header))
4274
4275 ;; From here the `header' was already present in the
4276 ;; `dependencies' table.
4277 (force-new
4278 ;; Overrides an existing entry;
4279 ;; just set the header part of the entry.
23f87bed
MB
4280 (setcar (symbol-value id-dep) header)
4281 (setq replaced t))
6748645f
LMI
4282
4283 ;; Renames the existing `header' to a unique Message-ID.
4284 ((not gnus-summary-ignore-duplicates)
4285 ;; An article with this Message-ID has already been seen.
4286 ;; We rename the Message-ID.
4287 (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4288 (list header))
4289 (mail-header-set-id header id))
4290
4291 ;; The last case ignores an existing entry, except it adds any
4292 ;; additional Xrefs (in case the two articles came from different
4293 ;; servers.
4294 ;; Also sets `header' to `nil' meaning that the `dependencies'
4295 ;; table was *not* modified.
4296 (t
4297 (mail-header-set-xref
4298 (car (symbol-value id-dep))
4299 (concat (or (mail-header-xref (car (symbol-value id-dep)))
4300 "")
4301 (or (mail-header-xref header) "")))
4302 (setq header nil)))
4303
23f87bed
MB
4304 (when (and header (not replaced))
4305 ;; First check that we are not creating a References loop.
4306 (setq parent-id (gnus-parent-id (mail-header-references header)))
4307 (setq ref parent-id)
6748645f
LMI
4308 (while (and ref
4309 (setq ref-dep (intern-soft ref dependencies))
4310 (boundp ref-dep)
4311 (setq ref-header (car (symbol-value ref-dep))))
4312 (if (string= id ref)
4313 ;; Yuk! This is a reference loop. Make the article be a
4314 ;; root article.
4315 (progn
4316 (mail-header-set-references (car (symbol-value id-dep)) "none")
23f87bed
MB
4317 (setq ref nil)
4318 (setq parent-id nil))
6748645f 4319 (setq ref (gnus-parent-id (mail-header-references ref-header)))))
23f87bed 4320 (setq ref-dep (intern (or parent-id "none") dependencies))
6748645f
LMI
4321 (if (boundp ref-dep)
4322 (setcdr (symbol-value ref-dep)
4323 (nconc (cdr (symbol-value ref-dep))
4324 (list (symbol-value id-dep))))
4325 (set ref-dep (list nil (symbol-value id-dep)))))
4326 header))
4327
23f87bed
MB
4328(defun gnus-extract-message-id-from-in-reply-to (string)
4329 (if (string-match "<[^>]+>" string)
4330 (substring string (match-beginning 0) (match-end 0))
4331 nil))
4332
eec82323
LMI
4333(defun gnus-build-sparse-threads ()
4334 (let ((headers gnus-newsgroup-headers)
16409b0b 4335 (mail-parse-charset gnus-newsgroup-charset)
6748645f 4336 (gnus-summary-ignore-duplicates t)
eec82323 4337 header references generation relations
6748645f 4338 subject child end new-child date)
eec82323
LMI
4339 ;; First we create an alist of generations/relations, where
4340 ;; generations is how much we trust the relation, and the relation
4341 ;; is parent/child.
4342 (gnus-message 7 "Making sparse threads...")
4343 (save-excursion
4344 (nnheader-set-temp-buffer " *gnus sparse threads*")
4345 (while (setq header (pop headers))
4346 (when (and (setq references (mail-header-references header))
4347 (not (string= references "")))
4348 (insert references)
4349 (setq child (mail-header-id header)
6748645f
LMI
4350 subject (mail-header-subject header)
4351 date (mail-header-date header)
4352 generation 0)
eec82323
LMI
4353 (while (search-backward ">" nil t)
4354 (setq end (1+ (point)))
4355 (when (search-backward "<" nil t)
6748645f 4356 (setq new-child (buffer-substring (point) end))
eec82323 4357 (push (list (incf generation)
6748645f
LMI
4358 child (setq child new-child)
4359 subject date)
eec82323 4360 relations)))
6748645f
LMI
4361 (when child
4362 (push (list (1+ generation) child nil subject) relations))
eec82323
LMI
4363 (erase-buffer)))
4364 (kill-buffer (current-buffer)))
4365 ;; Sort over trustworthiness.
01c52d31
MB
4366 (dolist (relation (sort relations 'car-less-than-car))
4367 (when (gnus-dependencies-add-header
4368 (make-full-mail-header
4369 gnus-reffed-article-number
4370 (nth 3 relation) "" (or (nth 4 relation) "")
4371 (nth 1 relation)
4372 (or (nth 2 relation) "") 0 0 "")
4373 gnus-newsgroup-dependencies nil)
4374 (push gnus-reffed-article-number gnus-newsgroup-limit)
4375 (push gnus-reffed-article-number gnus-newsgroup-sparse)
4376 (push (cons gnus-reffed-article-number gnus-sparse-mark)
4377 gnus-newsgroup-reads)
4378 (decf gnus-reffed-article-number)))
eec82323
LMI
4379 (gnus-message 7 "Making sparse threads...done")))
4380
4381(defun gnus-build-old-threads ()
4382 ;; Look at all the articles that refer back to old articles, and
4383 ;; fetch the headers for the articles that aren't there. This will
4384 ;; build complete threads - if the roots haven't been expired by the
4385 ;; server, that is.
16409b0b
GM
4386 (let ((mail-parse-charset gnus-newsgroup-charset)
4387 id heads)
eec82323
LMI
4388 (mapatoms
4389 (lambda (refs)
4390 (when (not (car (symbol-value refs)))
4391 (setq heads (cdr (symbol-value refs)))
4392 (while heads
4393 (if (memq (mail-header-number (caar heads))
4394 gnus-newsgroup-dormant)
4395 (setq heads (cdr heads))
4396 (setq id (symbol-name refs))
4397 (while (and (setq id (gnus-build-get-header id))
6748645f 4398 (not (car (gnus-id-to-thread id)))))
eec82323
LMI
4399 (setq heads nil)))))
4400 gnus-newsgroup-dependencies)))
4401
23f87bed
MB
4402(defsubst gnus-remove-odd-characters (string)
4403 "Translate STRING into something that doesn't contain weird characters."
4404 (mm-subst-char-in-string
4405 ?\r ?\-
01c52d31 4406 (mm-subst-char-in-string ?\n ?\- string t) t))
23f87bed 4407
6748645f
LMI
4408;; This function has to be called with point after the article number
4409;; on the beginning of the line.
4410(defsubst gnus-nov-parse-line (number dependencies &optional force-new)
01c52d31 4411 (let ((eol (point-at-eol))
6748645f 4412 (buffer (current-buffer))
23f87bed 4413 header references in-reply-to)
6748645f
LMI
4414
4415 ;; overview: [num subject from date id refs chars lines misc]
4416 (unwind-protect
23f87bed 4417 (let (x)
6748645f
LMI
4418 (narrow-to-region (point) eol)
4419 (unless (eobp)
4420 (forward-char))
4421
4422 (setq header
4423 (make-full-mail-header
4424 number ; number
23f87bed
MB
4425 (condition-case () ; subject
4426 (gnus-remove-odd-characters
4427 (funcall gnus-decode-encoded-word-function
4428 (setq x (nnheader-nov-field))))
4429 (error x))
4430 (condition-case () ; from
4431 (gnus-remove-odd-characters
343d6628 4432 (funcall gnus-decode-encoded-address-function
23f87bed
MB
4433 (setq x (nnheader-nov-field))))
4434 (error x))
16409b0b 4435 (nnheader-nov-field) ; date
01c52d31 4436 (nnheader-nov-read-message-id number) ; id
23f87bed 4437 (setq references (nnheader-nov-field)) ; refs
16409b0b
GM
4438 (nnheader-nov-read-integer) ; chars
4439 (nnheader-nov-read-integer) ; lines
4440 (unless (eobp)
8b93df01
DL
4441 (if (looking-at "Xref: ")
4442 (goto-char (match-end 0)))
4443 (nnheader-nov-field)) ; Xref
16409b0b 4444 (nnheader-nov-parse-extra)))) ; extra
6748645f
LMI
4445
4446 (widen))
4447
23f87bed
MB
4448 (when (and (string= references "")
4449 (setq in-reply-to (mail-header-extra header))
4450 (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4451 (mail-header-set-references
4452 header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4453
6748645f
LMI
4454 (when gnus-alter-header-function
4455 (funcall gnus-alter-header-function header))
4456 (gnus-dependencies-add-header header dependencies force-new)))
4457
eec82323 4458(defun gnus-build-get-header (id)
16409b0b
GM
4459 "Look through the buffer of NOV lines and find the header to ID.
4460Enter this line into the dependencies hash table, and return
4461the id of the parent article (if any)."
eec82323
LMI
4462 (let ((deps gnus-newsgroup-dependencies)
4463 found header)
4464 (prog1
c7a91ce1 4465 (with-current-buffer nntp-server-buffer
eec82323
LMI
4466 (let ((case-fold-search nil))
4467 (goto-char (point-min))
4468 (while (and (not found)
4469 (search-forward id nil t))
4470 (beginning-of-line)
4471 (setq found (looking-at
4472 (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4473 (regexp-quote id))))
4474 (or found (beginning-of-line 2)))
4475 (when found
4476 (beginning-of-line)
4477 (and
4478 (setq header (gnus-nov-parse-line
4479 (read (current-buffer)) deps))
4480 (gnus-parent-id (mail-header-references header))))))
4481 (when header
4482 (let ((number (mail-header-number header)))
4483 (push number gnus-newsgroup-limit)
4484 (push header gnus-newsgroup-headers)
4485 (if (memq number gnus-newsgroup-unselected)
4486 (progn
23f87bed
MB
4487 (setq gnus-newsgroup-unreads
4488 (gnus-add-to-sorted-list gnus-newsgroup-unreads
4489 number))
eec82323
LMI
4490 (setq gnus-newsgroup-unselected
4491 (delq number gnus-newsgroup-unselected)))
4492 (push number gnus-newsgroup-ancient)))))))
4493
6748645f
LMI
4494(defun gnus-build-all-threads ()
4495 "Read all the headers."
4496 (let ((gnus-summary-ignore-duplicates t)
16409b0b 4497 (mail-parse-charset gnus-newsgroup-charset)
6748645f
LMI
4498 (dependencies gnus-newsgroup-dependencies)
4499 header article)
c7a91ce1 4500 (with-current-buffer nntp-server-buffer
6748645f
LMI
4501 (let ((case-fold-search nil))
4502 (goto-char (point-min))
4503 (while (not (eobp))
4504 (ignore-errors
4505 (setq article (read (current-buffer))
16409b0b 4506 header (gnus-nov-parse-line article dependencies)))
6748645f 4507 (when header
01c52d31 4508 (with-current-buffer gnus-summary-buffer
6748645f
LMI
4509 (push header gnus-newsgroup-headers)
4510 (if (memq (setq article (mail-header-number header))
4511 gnus-newsgroup-unselected)
4512 (progn
23f87bed
MB
4513 (setq gnus-newsgroup-unreads
4514 (gnus-add-to-sorted-list
4515 gnus-newsgroup-unreads article))
6748645f
LMI
4516 (setq gnus-newsgroup-unselected
4517 (delq article gnus-newsgroup-unselected)))
4518 (push article gnus-newsgroup-ancient)))
4519 (forward-line 1)))))))
4520
eec82323 4521(defun gnus-summary-update-article-line (article header)
23f87bed 4522 "Update the line for ARTICLE using HEADER."
eec82323
LMI
4523 (let* ((id (mail-header-id header))
4524 (thread (gnus-id-to-thread id)))
4525 (unless thread
4526 (error "Article in no thread"))
4527 ;; Update the thread.
4528 (setcar thread header)
4529 (gnus-summary-goto-subject article)
4530 (let* ((datal (gnus-data-find-list article))
4531 (data (car datal))
c7a91ce1 4532 (inhibit-read-only t)
eec82323
LMI
4533 (level (gnus-summary-thread-level)))
4534 (gnus-delete-line)
23f87bed
MB
4535 (let ((inserted (- (point)
4536 (progn
4537 (gnus-summary-insert-line
4538 header level nil
4539 (memq article gnus-newsgroup-undownloaded)
4540 (gnus-article-mark article)
4541 (memq article gnus-newsgroup-replied)
4542 (memq article gnus-newsgroup-expirable)
4543 ;; Only insert the Subject string when it's different
4544 ;; from the previous Subject string.
4545 (if (and
4546 gnus-show-threads
4547 (gnus-subject-equal
4548 (condition-case ()
4549 (mail-header-subject
4550 (gnus-data-header
4551 (cadr
4552 (gnus-data-find-list
4553 article
4554 (gnus-data-list t)))))
4555 ;; Error on the side of excessive subjects.
4556 (error ""))
4557 (mail-header-subject header)))
4558 ""
4559 (mail-header-subject header))
4560 nil (cdr (assq article gnus-newsgroup-scored))
4561 (memq article gnus-newsgroup-processable))
4562 (point)))))
4563 (when (cdr datal)
4564 (gnus-data-update-list
4565 (cdr datal)
4566 (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
eec82323
LMI
4567
4568(defun gnus-summary-update-article (article &optional iheader)
4569 "Update ARTICLE in the summary buffer."
4570 (set-buffer gnus-summary-buffer)
6748645f 4571 (let* ((header (gnus-summary-article-header article))
eec82323
LMI
4572 (id (mail-header-id header))
4573 (data (gnus-data-find article))
4574 (thread (gnus-id-to-thread id))
4575 (references (mail-header-references header))
4576 (parent
4577 (gnus-id-to-thread
4578 (or (gnus-parent-id
4579 (when (and references
4580 (not (equal "" references)))
4581 references))
4582 "none")))
c7a91ce1 4583 (inhibit-read-only t)
6748645f 4584 (old (car thread)))
eec82323 4585 (when thread
eec82323 4586 (unless iheader
6748645f
LMI
4587 (setcar thread nil)
4588 (when parent
4589 (delq thread parent)))
4590 (if (gnus-summary-insert-subject id header)
eec82323
LMI
4591 ;; Set the (possibly) new article number in the data structure.
4592 (gnus-data-set-number data (gnus-id-to-article id))
4593 (setcar thread old)
4594 nil))))
4595
6748645f
LMI
4596(defun gnus-rebuild-thread (id &optional line)
4597 "Rebuild the thread containing ID.
4598If LINE, insert the rebuilt thread starting on line LINE."
c7a91ce1 4599 (let ((inhibit-read-only t)
eec82323
LMI
4600 old-pos current thread data)
4601 (if (not gnus-show-threads)
4602 (setq thread (list (car (gnus-id-to-thread id))))
4603 ;; Get the thread this article is part of.
4604 (setq thread (gnus-remove-thread id)))
01c52d31 4605 (setq old-pos (point-at-bol))
eec82323 4606 (setq current (save-excursion
94384150 4607 (and (re-search-backward "[\r\n]" nil t)
eec82323
LMI
4608 (gnus-summary-article-number))))
4609 ;; If this is a gathered thread, we have to go some re-gathering.
4610 (when (stringp (car thread))
4611 (let ((subject (car thread))
4612 roots thr)
4613 (setq thread (cdr thread))
4614 (while thread
4615 (unless (memq (setq thr (gnus-id-to-thread
4616 (gnus-root-id
4617 (mail-header-id (caar thread)))))
4618 roots)
4619 (push thr roots))
4620 (setq thread (cdr thread)))
4621 ;; We now have all (unique) roots.
4622 (if (= (length roots) 1)
4623 ;; All the loose roots are now one solid root.
4624 (setq thread (car roots))
4625 (setq thread (cons subject (gnus-sort-threads roots))))))
4626 (let (threads)
4627 ;; We then insert this thread into the summary buffer.
6748645f
LMI
4628 (when line
4629 (goto-char (point-min))
4630 (forward-line (1- line)))
eec82323
LMI
4631 (let (gnus-newsgroup-data gnus-newsgroup-threads)
4632 (if gnus-show-threads
4633 (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4634 (gnus-summary-prepare-unthreaded thread))
4635 (setq data (nreverse gnus-newsgroup-data))
4636 (setq threads gnus-newsgroup-threads))
4637 ;; We splice the new data into the data structure.
6748645f
LMI
4638 ;;!!! This is kinda bogus. We assume that in LINE is non-nil,
4639 ;;!!! then we want to insert at the beginning of the buffer.
4640 ;;!!! That happens to be true with Gnus now, but that may
4641 ;;!!! change in the future. Perhaps.
4642 (gnus-data-enter-list
4643 (if line nil current) data (- (point) old-pos))
4644 (setq gnus-newsgroup-threads
4645 (nconc threads gnus-newsgroup-threads))
4646 (gnus-data-compute-positions))))
eec82323
LMI
4647
4648(defun gnus-number-to-header (number)
4649 "Return the header for article NUMBER."
4650 (let ((headers gnus-newsgroup-headers))
4651 (while (and headers
4652 (not (= number (mail-header-number (car headers)))))
4653 (pop headers))
4654 (when headers
4655 (car headers))))
4656
6748645f 4657(defun gnus-parent-headers (in-headers &optional generation)
eec82323
LMI
4658 "Return the headers of the GENERATIONeth parent of HEADERS."
4659 (unless generation
4660 (setq generation 1))
a8151ef7 4661 (let ((parent t)
6748645f 4662 (headers in-headers)
a8151ef7 4663 references)
6748645f
LMI
4664 (while (and parent
4665 (not (zerop generation))
4666 (setq references (mail-header-references headers)))
4667 (setq headers (if (and references
4668 (setq parent (gnus-parent-id references)))
4669 (car (gnus-id-to-thread parent))
4670 nil))
4671 (decf generation))
4672 (and (not (eq headers in-headers))
4673 headers)))
eec82323
LMI
4674
4675(defun gnus-id-to-thread (id)
4676 "Return the (sub-)thread where ID appears."
4677 (gnus-gethash id gnus-newsgroup-dependencies))
4678
4679(defun gnus-id-to-article (id)
4680 "Return the article number of ID."
4681 (let ((thread (gnus-id-to-thread id)))
4682 (when (and thread
4683 (car thread))
4684 (mail-header-number (car thread)))))
4685
4686(defun gnus-id-to-header (id)
4687 "Return the article headers of ID."
4688 (car (gnus-id-to-thread id)))
4689
4690(defun gnus-article-displayed-root-p (article)
4691 "Say whether ARTICLE is a root(ish) article."
4692 (let ((level (gnus-summary-thread-level article))
4693 (refs (mail-header-references (gnus-summary-article-header article)))
4694 particle)
4695 (cond
4696 ((null level) nil)
4697 ((zerop level) t)
4698 ((null refs) t)
4699 ((null (gnus-parent-id refs)) t)
4700 ((and (= 1 level)
4701 (null (setq particle (gnus-id-to-article
4702 (gnus-parent-id refs))))
4703 (null (gnus-summary-thread-level particle)))))))
4704
4705(defun gnus-root-id (id)
4706 "Return the id of the root of the thread where ID appears."
4707 (let (last-id prev)
6748645f 4708 (while (and id (setq prev (car (gnus-id-to-thread id))))
eec82323
LMI
4709 (setq last-id id
4710 id (gnus-parent-id (mail-header-references prev))))
4711 last-id))
4712
6748645f
LMI
4713(defun gnus-articles-in-thread (thread)
4714 "Return the list of articles in THREAD."
4715 (cons (mail-header-number (car thread))
4716 (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4717
eec82323
LMI
4718(defun gnus-remove-thread (id &optional dont-remove)
4719 "Remove the thread that has ID in it."
6748645f 4720 (let (headers thread last-id)
eec82323 4721 ;; First go up in this thread until we find the root.
6748645f
LMI
4722 (setq last-id (gnus-root-id id)
4723 headers (message-flatten-list (gnus-id-to-thread last-id)))
01ccbb85 4724 ;; We have now found the real root of this thread. It might have
eec82323
LMI
4725 ;; been gathered into some loose thread, so we have to search
4726 ;; through the threads to find the thread we wanted.
4727 (let ((threads gnus-newsgroup-threads)
4728 sub)
4729 (while threads
4730 (setq sub (car threads))
4731 (if (stringp (car sub))
4732 ;; This is a gathered thread, so we look at the roots
4733 ;; below it to find whether this article is in this
4734 ;; gathered root.
4735 (progn
4736 (setq sub (cdr sub))
4737 (while sub
4738 (when (member (caar sub) headers)
4739 (setq thread (car threads)
4740 threads nil
4741 sub nil))
4742 (setq sub (cdr sub))))
4743 ;; It's an ordinary thread, so we check it.
4744 (when (eq (car sub) (car headers))
4745 (setq thread sub
4746 threads nil)))
4747 (setq threads (cdr threads)))
4748 ;; If this article is in no thread, then it's a root.
4749 (if thread
4750 (unless dont-remove
4751 (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
6748645f 4752 (setq thread (gnus-id-to-thread last-id)))
eec82323
LMI
4753 (when thread
4754 (prog1
4755 thread ; We return this thread.
4756 (unless dont-remove
4757 (if (stringp (car thread))
4758 (progn
4759 ;; If we use dummy roots, then we have to remove the
4760 ;; dummy root as well.
4761 (when (eq gnus-summary-make-false-root 'dummy)
6748645f
LMI
4762 ;; We go to the dummy root by going to
4763 ;; the first sub-"thread", and then one line up.
4764 (gnus-summary-goto-article
4765 (mail-header-number (caadr thread)))
4766 (forward-line -1)
eec82323
LMI
4767 (gnus-delete-line)
4768 (gnus-data-compute-positions))
4769 (setq thread (cdr thread))
4770 (while thread
4771 (gnus-remove-thread-1 (car thread))
4772 (setq thread (cdr thread))))
4773 (gnus-remove-thread-1 thread))))))))
4774
4775(defun gnus-remove-thread-1 (thread)
4776 "Remove the thread THREAD recursively."
4777 (let ((number (mail-header-number (pop thread)))
4778 d)
4779 (setq thread (reverse thread))
4780 (while thread
4781 (gnus-remove-thread-1 (pop thread)))
4782 (when (setq d (gnus-data-find number))
4783 (goto-char (gnus-data-pos d))
16409b0b 4784 (gnus-summary-show-thread)
eec82323
LMI
4785 (gnus-data-remove
4786 number
01c52d31 4787 (- (point-at-bol)
eec82323 4788 (prog1
01c52d31 4789 (1+ (point-at-eol))
eec82323
LMI
4790 (gnus-delete-line)))))))
4791
4921bbdd 4792(defun gnus-sort-threads-recursive (threads func)
16409b0b
GM
4793 (sort (mapcar (lambda (thread)
4794 (cons (car thread)
4795 (and (cdr thread)
4921bbdd 4796 (gnus-sort-threads-recursive (cdr thread) func))))
16409b0b
GM
4797 threads) func))
4798
4921bbdd
CY
4799(defun gnus-sort-threads-loop (threads func)
4800 (let* ((superthread (cons nil threads))
4801 (stack (list (cons superthread threads)))
4802 remaining-threads thread)
4803 (while stack
4804 (setq remaining-threads (cdr (car stack)))
4805 (if remaining-threads
4806 (progn (setq thread (car remaining-threads))
4807 (setcdr (car stack) (cdr remaining-threads))
4808 (if (cdr thread)
4809 (push (cons thread (cdr thread)) stack)))
4810 (setq thread (caar stack))
4811 (setcdr thread (sort (cdr thread) func))
4812 (pop stack)))
4813 (cdr superthread)))
4814
eec82323
LMI
4815(defun gnus-sort-threads (threads)
4816 "Sort THREADS."
4817 (if (not gnus-thread-sort-functions)
4818 threads
6748645f 4819 (gnus-message 8 "Sorting threads...")
4921bbdd
CY
4820 (prog1
4821 (condition-case nil
4822 (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4823 (gnus-sort-threads-recursive
4824 threads (gnus-make-sort-function gnus-thread-sort-functions)))
4825 ;; Even after binding max-lisp-eval-depth, the recursive
4826 ;; sorter might fail for very long threads. In that case,
4827 ;; try using a (less well-tested) non-recursive sorter.
3d6e7a43
KY
4828 (error (gnus-message 9 "Sorting threads with loop...")
4829 (gnus-sort-threads-loop
4921bbdd
CY
4830 threads (gnus-make-sort-function
4831 gnus-thread-sort-functions))))
4832 (gnus-message 8 "Sorting threads...done"))))
eec82323
LMI
4833
4834(defun gnus-sort-articles (articles)
4835 "Sort ARTICLES."
4836 (when gnus-article-sort-functions
4837 (gnus-message 7 "Sorting articles...")
4838 (prog1
4839 (setq gnus-newsgroup-headers
4840 (sort articles (gnus-make-sort-function
4841 gnus-article-sort-functions)))
4842 (gnus-message 7 "Sorting articles...done"))))
4843
4844;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4845(defmacro gnus-thread-header (thread)
16409b0b
GM
4846 "Return header of first article in THREAD.
4847Note that THREAD must never, ever be anything else than a variable -
4848using some other form will lead to serious barfage."
eec82323
LMI
4849 (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4850 ;; (8% speedup to gnus-summary-prepare, just for fun :-)
16409b0b 4851 (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
eec82323
LMI
4852 (vector thread) 2))
4853
4854(defsubst gnus-article-sort-by-number (h1 h2)
4855 "Sort articles by article number."
4856 (< (mail-header-number h1)
4857 (mail-header-number h2)))
4858
4859(defun gnus-thread-sort-by-number (h1 h2)
4860 "Sort threads by root article number."
4861 (gnus-article-sort-by-number
4862 (gnus-thread-header h1) (gnus-thread-header h2)))
4863
23f87bed 4864(defsubst gnus-article-sort-by-random (h1 h2)
0b6799c3 4865 "Sort articles randomly."
23f87bed
MB
4866 (zerop (random 2)))
4867
4868(defun gnus-thread-sort-by-random (h1 h2)
0b6799c3 4869 "Sort threads randomly."
23f87bed
MB
4870 (gnus-article-sort-by-random
4871 (gnus-thread-header h1) (gnus-thread-header h2)))
4872
eec82323
LMI
4873(defsubst gnus-article-sort-by-lines (h1 h2)
4874 "Sort articles by article Lines header."
4875 (< (mail-header-lines h1)
4876 (mail-header-lines h2)))
4877
4878(defun gnus-thread-sort-by-lines (h1 h2)
4879 "Sort threads by root article Lines header."
4880 (gnus-article-sort-by-lines
4881 (gnus-thread-header h1) (gnus-thread-header h2)))
4882
16409b0b
GM
4883(defsubst gnus-article-sort-by-chars (h1 h2)
4884 "Sort articles by octet length."
4885 (< (mail-header-chars h1)
4886 (mail-header-chars h2)))
4887
4888(defun gnus-thread-sort-by-chars (h1 h2)
4889 "Sort threads by root article octet length."
4890 (gnus-article-sort-by-chars
4891 (gnus-thread-header h1) (gnus-thread-header h2)))
4892
eec82323
LMI
4893(defsubst gnus-article-sort-by-author (h1 h2)
4894 "Sort articles by root author."
b4fde39f 4895 (gnus-string<
eec82323
LMI
4896 (let ((extract (funcall
4897 gnus-extract-address-components
4898 (mail-header-from h1))))
4899 (or (car extract) (cadr extract) ""))
4900 (let ((extract (funcall
4901 gnus-extract-address-components
4902 (mail-header-from h2))))
4903 (or (car extract) (cadr extract) ""))))
4904
4905(defun gnus-thread-sort-by-author (h1 h2)
4906 "Sort threads by root author."
4907 (gnus-article-sort-by-author
4908 (gnus-thread-header h1) (gnus-thread-header h2)))
4909
01c52d31
MB
4910(defsubst gnus-article-sort-by-recipient (h1 h2)
4911 "Sort articles by recipient."
4912 (gnus-string<
4913 (let ((extract (funcall
4914 gnus-extract-address-components
4915 (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4916 (or (car extract) (cadr extract)))
4917 (let ((extract (funcall
4918 gnus-extract-address-components
4919 (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4920 (or (car extract) (cadr extract)))))
4921
4922(defun gnus-thread-sort-by-recipient (h1 h2)
4923 "Sort threads by root recipient."
4924 (gnus-article-sort-by-recipient
4925 (gnus-thread-header h1) (gnus-thread-header h2)))
4926
eec82323
LMI
4927(defsubst gnus-article-sort-by-subject (h1 h2)
4928 "Sort articles by root subject."
b4fde39f 4929 (gnus-string<
eec82323
LMI
4930 (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4931 (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4932
4933(defun gnus-thread-sort-by-subject (h1 h2)
4934 "Sort threads by root subject."
4935 (gnus-article-sort-by-subject
4936 (gnus-thread-header h1) (gnus-thread-header h2)))
4937
4938(defsubst gnus-article-sort-by-date (h1 h2)
4939 "Sort articles by root article date."
16409b0b 4940 (time-less-p
eec82323
LMI
4941 (gnus-date-get-time (mail-header-date h1))
4942 (gnus-date-get-time (mail-header-date h2))))
4943
4944(defun gnus-thread-sort-by-date (h1 h2)
4945 "Sort threads by root article date."
4946 (gnus-article-sort-by-date
4947 (gnus-thread-header h1) (gnus-thread-header h2)))
4948
4949(defsubst gnus-article-sort-by-score (h1 h2)
4950 "Sort articles by root article score.
4951Unscored articles will be counted as having a score of zero."
4952 (> (or (cdr (assq (mail-header-number h1)
4953 gnus-newsgroup-scored))
4954 gnus-summary-default-score 0)
4955 (or (cdr (assq (mail-header-number h2)
4956 gnus-newsgroup-scored))
4957 gnus-summary-default-score 0)))
4958
4959(defun gnus-thread-sort-by-score (h1 h2)
4960 "Sort threads by root article score."
4961 (gnus-article-sort-by-score
4962 (gnus-thread-header h1) (gnus-thread-header h2)))
4963
4964(defun gnus-thread-sort-by-total-score (h1 h2)
4965 "Sort threads by the sum of all scores in the thread.
4966Unscored articles will be counted as having a score of zero."
4967 (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4968
4969(defun gnus-thread-total-score (thread)
16409b0b 4970 ;; This function find the total score of THREAD.
23f87bed
MB
4971 (cond
4972 ((null thread)
4973 0)
4974 ((consp thread)
4975 (if (stringp (car thread))
4976 (apply gnus-thread-score-function 0
4977 (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4978 (gnus-thread-total-score-1 thread)))
4979 (t
4980 (gnus-thread-total-score-1 (list thread)))))
4981
4982(defun gnus-thread-sort-by-most-recent-number (h1 h2)
4983 "Sort threads such that the thread with the most recently arrived article comes first."
4984 (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4985
4986(defun gnus-thread-highest-number (thread)
4987 "Return the highest article number in THREAD."
4988 (apply 'max (mapcar (lambda (header)
4989 (mail-header-number header))
4990 (message-flatten-list thread))))
4991
4992(defun gnus-thread-sort-by-most-recent-date (h1 h2)
4993 "Sort threads such that the thread with the most recently dated article comes first."
4994 (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4995
3d6e7a43
KY
4996; Since this is called not only to sort the top-level threads, but
4997; also in recursive sorts to order the articles within a thread, each
4998; article will be processed many times. Thus it speeds things up
4999; quite a bit to use gnus-date-get-time, which caches the time value.
23f87bed
MB
5000(defun gnus-thread-latest-date (thread)
5001 "Return the highest article date in THREAD."
3d6e7a43
KY
5002 (apply 'max
5003 (mapcar (lambda (header) (gnus-float-time
5004 (gnus-date-get-time
5005 (mail-header-date header))))
5006 (message-flatten-list thread))))
eec82323
LMI
5007
5008(defun gnus-thread-total-score-1 (root)
5009 ;; This function find the total score of the thread below ROOT.
5010 (setq root (car root))
5011 (apply gnus-thread-score-function
5012 (or (append
5013 (mapcar 'gnus-thread-total-score
6748645f 5014 (cdr (gnus-id-to-thread (mail-header-id root))))
eec82323
LMI
5015 (when (> (mail-header-number root) 0)
5016 (list (or (cdr (assq (mail-header-number root)
5017 gnus-newsgroup-scored))
5018 gnus-summary-default-score 0))))
5019 (list gnus-summary-default-score)
5020 '(0))))
5021
5022;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
5023(defvar gnus-tmp-prev-subject nil)
5024(defvar gnus-tmp-false-parent nil)
5025(defvar gnus-tmp-root-expunged nil)
5026(defvar gnus-tmp-dummy-line nil)
5027
16409b0b
GM
5028(defun gnus-extra-header (type &optional header)
5029 "Return the extra header of TYPE."
5030 (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
5031 ""))
5032
23f87bed
MB
5033(defvar gnus-tmp-thread-tree-header-string "")
5034
5035(defcustom gnus-sum-thread-tree-root "> "
5036 "With %B spec, used for the root of a thread.
5037If nil, use subject instead."
bf247b6e 5038 :version "22.1"
ad136a7c 5039 :type '(radio (const :format "%v " nil) string)
23f87bed 5040 :group 'gnus-thread)
01c52d31 5041
23f87bed
MB
5042(defcustom gnus-sum-thread-tree-false-root "> "
5043 "With %B spec, used for a false root of a thread.
5044If nil, use subject instead."
bf247b6e 5045 :version "22.1"
ad136a7c 5046 :type '(radio (const :format "%v " nil) string)
23f87bed 5047 :group 'gnus-thread)
01c52d31 5048
23f87bed
MB
5049(defcustom gnus-sum-thread-tree-single-indent ""
5050 "With %B spec, used for a thread with just one message.
5051If nil, use subject instead."
bf247b6e 5052 :version "22.1"
ad136a7c 5053 :type '(radio (const :format "%v " nil) string)
23f87bed 5054 :group 'gnus-thread)
01c52d31 5055
23f87bed
MB
5056(defcustom gnus-sum-thread-tree-vertical "| "
5057 "With %B spec, used for drawing a vertical line."
bf247b6e 5058 :version "22.1"
23f87bed
MB
5059 :type 'string
5060 :group 'gnus-thread)
01c52d31 5061
23f87bed
MB
5062(defcustom gnus-sum-thread-tree-indent " "
5063 "With %B spec, used for indenting."
bf247b6e 5064 :version "22.1"
23f87bed
MB
5065 :type 'string
5066 :group 'gnus-thread)
01c52d31 5067
23f87bed
MB
5068(defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5069 "With %B spec, used for a leaf with brothers."
bf247b6e 5070 :version "22.1"
23f87bed
MB
5071 :type 'string
5072 :group 'gnus-thread)
01c52d31 5073
23f87bed
MB
5074(defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5075 "With %B spec, used for a leaf without brothers."
bf247b6e 5076 :version "22.1"
23f87bed
MB
5077 :type 'string
5078 :group 'gnus-thread)
5079
1fc34624
GM
5080(defcustom gnus-summary-display-while-building nil
5081 "If non-nil, show and update the summary buffer as it's being built.
5082If the value is t, update the buffer after every line is inserted. If
5083the value is an integer (N), update the display every N lines."
5084 :version "22.1"
5085 :group 'gnus-thread
5086 :type '(choice (const :tag "off" nil)
5087 number
5088 (const :tag "frequently" t)))
5089
eec82323
LMI
5090(defun gnus-summary-prepare-threads (threads)
5091 "Prepare summary buffer from THREADS and indentation LEVEL.
5092THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5093or a straight list of headers."
5094 (gnus-message 7 "Generating summary...")
5095
5096 (setq gnus-newsgroup-threads threads)
5097 (beginning-of-line)
5098
5099 (let ((gnus-tmp-level 0)
5100 (default-score (or gnus-summary-default-score 0))
5101 (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
23f87bed
MB
5102 (building-line-count gnus-summary-display-while-building)
5103 (building-count (integerp gnus-summary-display-while-building))
eec82323 5104 thread number subject stack state gnus-tmp-gathered beg-match
23f87bed
MB
5105 new-roots gnus-tmp-new-adopts thread-end simp-subject
5106 gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
eec82323
LMI
5107 gnus-tmp-replied gnus-tmp-subject-or-nil
5108 gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5109 gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
23f87bed
MB
5110 gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5111 tree-stack)
eec82323 5112
23f87bed
MB
5113 (setq gnus-tmp-prev-subject nil
5114 gnus-tmp-thread-tree-header-string "")
eec82323
LMI
5115
5116 (if (vectorp (car threads))
5117 ;; If this is a straight (sic) list of headers, then a
5118 ;; threaded summary display isn't required, so we just create
5119 ;; an unthreaded one.
5120 (gnus-summary-prepare-unthreaded threads)
5121
5122 ;; Do the threaded display.
5123
23f87bed
MB
5124 (if gnus-summary-display-while-building
5125 (switch-to-buffer (buffer-name)))
eec82323
LMI
5126 (while (or threads stack gnus-tmp-new-adopts new-roots)
5127
5128 (if (and (= gnus-tmp-level 0)
eec82323
LMI
5129 (or (not stack)
5130 (= (caar stack) 0))
5131 (not gnus-tmp-false-parent)
5132 (or gnus-tmp-new-adopts new-roots))
5133 (if gnus-tmp-new-adopts
5134 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5135 thread (list (car gnus-tmp-new-adopts))
5136 gnus-tmp-header (caar thread)
5137 gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5138 (when new-roots
5139 (setq thread (list (car new-roots))
5140 gnus-tmp-header (caar thread)
5141 new-roots (cdr new-roots))))
5142
5143 (if threads
5144 ;; If there are some threads, we do them before the
5145 ;; threads on the stack.
5146 (setq thread threads
5147 gnus-tmp-header (caar thread))
5148 ;; There were no current threads, so we pop something off
5149 ;; the stack.
5150 (setq state (car stack)
5151 gnus-tmp-level (car state)
23f87bed
MB
5152 tree-stack (cadr state)
5153 thread (caddr state)
eec82323
LMI
5154 stack (cdr stack)
5155 gnus-tmp-header (caar thread))))
5156
5157 (setq gnus-tmp-false-parent nil)
5158 (setq gnus-tmp-root-expunged nil)
5159 (setq thread-end nil)
5160
5161 (if (stringp gnus-tmp-header)
5162 ;; The header is a dummy root.
5163 (cond
5164 ((eq gnus-summary-make-false-root 'adopt)
5165 ;; We let the first article adopt the rest.
5166 (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5167 (cddar thread)))
5168 (setq gnus-tmp-gathered
5169 (nconc (mapcar
5170 (lambda (h) (mail-header-number (car h)))
5171 (cddar thread))
5172 gnus-tmp-gathered))
5173 (setq thread (cons (list (caar thread)
5174 (cadar thread))
5175 (cdr thread)))
5176 (setq gnus-tmp-level -1
5177 gnus-tmp-false-parent t))
5178 ((eq gnus-summary-make-false-root 'empty)
5179 ;; We print adopted articles with empty subject fields.
5180 (setq gnus-tmp-gathered
5181 (nconc (mapcar
5182 (lambda (h) (mail-header-number (car h)))
5183 (cddar thread))
5184 gnus-tmp-gathered))
5185 (setq gnus-tmp-level -1))
5186 ((eq gnus-summary-make-false-root 'dummy)
5187 ;; We remember that we probably want to output a dummy
5188 ;; root.
5189 (setq gnus-tmp-dummy-line gnus-tmp-header)
5190 (setq gnus-tmp-prev-subject gnus-tmp-header))
5191 (t
5192 ;; We do not make a root for the gathered
5193 ;; sub-threads at all.
5194 (setq gnus-tmp-level -1)))
5195
5196 (setq number (mail-header-number gnus-tmp-header)
23f87bed
MB
5197 subject (mail-header-subject gnus-tmp-header)
5198 simp-subject (gnus-simplify-subject-fully subject))
eec82323
LMI
5199
5200 (cond
5201 ;; If the thread has changed subject, we might want to make
5202 ;; this subthread into a root.
5203 ((and (null gnus-thread-ignore-subject)
5204 (not (zerop gnus-tmp-level))
5205 gnus-tmp-prev-subject
23f87bed 5206 (not (string= gnus-tmp-prev-subject simp-subject)))
eec82323
LMI
5207 (setq new-roots (nconc new-roots (list (car thread)))
5208 thread-end t
5209 gnus-tmp-header nil))
5210 ;; If the article lies outside the current limit,
5211 ;; then we do not display it.
5212 ((not (memq number gnus-newsgroup-limit))
5213 (setq gnus-tmp-gathered
5214 (nconc (mapcar
5215 (lambda (h) (mail-header-number (car h)))
5216 (cdar thread))
5217 gnus-tmp-gathered))
5218 (setq gnus-tmp-new-adopts (if (cdar thread)
5219 (append gnus-tmp-new-adopts
5220 (cdar thread))
5221 gnus-tmp-new-adopts)
5222 thread-end t
5223 gnus-tmp-header nil)
5224 (when (zerop gnus-tmp-level)
5225 (setq gnus-tmp-root-expunged t)))
5226 ;; Perhaps this article is to be marked as read?
5227 ((and gnus-summary-mark-below
5228 (< (or (cdr (assq number gnus-newsgroup-scored))
5229 default-score)
5230 gnus-summary-mark-below)
5231 ;; Don't touch sparse articles.
5232 (not (gnus-summary-article-sparse-p number))
5233 (not (gnus-summary-article-ancient-p number)))
5234 (setq gnus-newsgroup-unreads
5235 (delq number gnus-newsgroup-unreads))
5236 (if gnus-newsgroup-auto-expire
23f87bed
MB
5237 (setq gnus-newsgroup-expirable
5238 (gnus-add-to-sorted-list
5239 gnus-newsgroup-expirable number))
eec82323
LMI
5240 (push (cons number gnus-low-score-mark)
5241 gnus-newsgroup-reads))))
5242
5243 (when gnus-tmp-header
5244 ;; We may have an old dummy line to output before this
5245 ;; article.
6748645f
LMI
5246 (when (and gnus-tmp-dummy-line
5247 (gnus-subject-equal
5248 gnus-tmp-dummy-line
5249 (mail-header-subject gnus-tmp-header)))
eec82323
LMI
5250 (gnus-summary-insert-dummy-line
5251 gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5252 (setq gnus-tmp-dummy-line nil))
5253
5254 ;; Compute the mark.
5255 (setq gnus-tmp-unread (gnus-article-mark number))
5256
5257 (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5258 gnus-tmp-header gnus-tmp-level)
5259 gnus-newsgroup-data)
5260
5261 ;; Actually insert the line.
5262 (setq
5263 gnus-tmp-subject-or-nil
5264 (cond
5265 ((and gnus-thread-ignore-subject
5266 gnus-tmp-prev-subject
23f87bed 5267 (not (string= gnus-tmp-prev-subject simp-subject)))
eec82323
LMI
5268 subject)
5269 ((zerop gnus-tmp-level)
5270 (if (and (eq gnus-summary-make-false-root 'empty)
5271 (memq number gnus-tmp-gathered)
5272 gnus-tmp-prev-subject
23f87bed 5273 (string= gnus-tmp-prev-subject simp-subject))
eec82323
LMI
5274 gnus-summary-same-subject
5275 subject))
5276 (t gnus-summary-same-subject)))
5277 (if (and (eq gnus-summary-make-false-root 'adopt)
5278 (= gnus-tmp-level 1)
5279 (memq number gnus-tmp-gathered))
5280 (setq gnus-tmp-opening-bracket ?\<
5281 gnus-tmp-closing-bracket ?\>)
5282 (setq gnus-tmp-opening-bracket ?\[
5283 gnus-tmp-closing-bracket ?\]))
4921bbdd
CY
5284 (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5285 (gnus-make-thread-indent-array
5286 (max (* 2 (length gnus-thread-indent-array))
5287 gnus-tmp-level)))
eec82323
LMI
5288 (setq
5289 gnus-tmp-indentation
5290 (aref gnus-thread-indent-array gnus-tmp-level)
5291 gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5292 gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5293 gnus-summary-default-score 0)
5294 gnus-tmp-score-char
5295 (if (or (null gnus-summary-default-score)
5296 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5297 gnus-summary-zcore-fuzz))
23f87bed 5298 ? ;Whitespace
eec82323
LMI
5299 (if (< gnus-tmp-score gnus-summary-default-score)
5300 gnus-score-below-mark gnus-score-over-mark))
5301 gnus-tmp-replied
5302 (cond ((memq number gnus-newsgroup-processable)
5303 gnus-process-mark)
5304 ((memq number gnus-newsgroup-cached)
5305 gnus-cached-mark)
5306 ((memq number gnus-newsgroup-replied)
5307 gnus-replied-mark)
23f87bed
MB
5308 ((memq number gnus-newsgroup-forwarded)
5309 gnus-forwarded-mark)
eec82323
LMI
5310 ((memq number gnus-newsgroup-saved)
5311 gnus-saved-mark)
23f87bed
MB
5312 ((memq number gnus-newsgroup-recent)
5313 gnus-recent-mark)
5314 ((memq number gnus-newsgroup-unseen)
5315 gnus-unseen-mark)
5316 (t gnus-no-mark))
5317 gnus-tmp-downloaded
5318 (cond ((memq number gnus-newsgroup-undownloaded)
5319 gnus-undownloaded-mark)
5320 (gnus-newsgroup-agentized
5321 gnus-downloaded-mark)
5322 (t
5323 gnus-no-mark))
eec82323
LMI
5324 gnus-tmp-from (mail-header-from gnus-tmp-header)
5325 gnus-tmp-name
5326 (cond
5327 ((string-match "<[^>]+> *$" gnus-tmp-from)
5328 (setq beg-match (match-beginning 0))
23f87bed
MB
5329 (or (and (string-match "^\".+\"" gnus-tmp-from)
5330 (substring gnus-tmp-from 1 (1- (match-end 0))))
eec82323
LMI
5331 (substring gnus-tmp-from 0 beg-match)))
5332 ((string-match "(.+)" gnus-tmp-from)
5333 (substring gnus-tmp-from
5334 (1+ (match-beginning 0)) (1- (match-end 0))))
23f87bed
MB
5335 (t gnus-tmp-from))
5336
5337 ;; Do the %B string
5338 gnus-tmp-thread-tree-header-string
5339 (cond
5340 ((not gnus-show-threads) "")
5341 ((zerop gnus-tmp-level)
5342 (cond ((cdar thread)
5343 (or gnus-sum-thread-tree-root subject))
5344 (gnus-tmp-new-adopts
5345 (or gnus-sum-thread-tree-false-root subject))
5346 (t
5347 (or gnus-sum-thread-tree-single-indent subject))))
5348 (t
5349 (concat (apply 'concat
5350 (mapcar (lambda (item)
5351 (if (= item 1)
5352 gnus-sum-thread-tree-vertical
5353 gnus-sum-thread-tree-indent))
5354 (cdr (reverse tree-stack))))
5355 (if (nth 1 thread)
5356 gnus-sum-thread-tree-leaf-with-other
5357 gnus-sum-thread-tree-single-leaf)))))
eec82323
LMI
5358 (when (string= gnus-tmp-name "")
5359 (setq gnus-tmp-name gnus-tmp-from))
5360 (unless (numberp gnus-tmp-lines)
23f87bed
MB
5361 (setq gnus-tmp-lines -1))
5362 (if (= gnus-tmp-lines -1)
5363 (setq gnus-tmp-lines "?")
5364 (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5365 (gnus-put-text-property
64763fe3
MB
5366 (point)
5367 (progn (eval gnus-summary-line-format-spec) (point))
23f87bed 5368 'gnus-number number)
64763fe3
MB
5369 (when gnus-visual-p
5370 (forward-line -1)
5371 (gnus-run-hooks 'gnus-summary-update-hook)
5372 (forward-line 1))
eec82323 5373
64763fe3 5374 (setq gnus-tmp-prev-subject simp-subject)))
eec82323
LMI
5375
5376 (when (nth 1 thread)
23f87bed
MB
5377 (push (list (max 0 gnus-tmp-level)
5378 (copy-sequence tree-stack)
5379 (nthcdr 1 thread))
5380 stack))
5381 (push (if (nth 1 thread) 1 0) tree-stack)
eec82323
LMI
5382 (incf gnus-tmp-level)
5383 (setq threads (if thread-end nil (cdar thread)))
23f87bed
MB
5384 (if gnus-summary-display-while-building
5385 (if building-count
5386 (progn
5387 ;; use a set frequency
5388 (setq building-line-count (1- building-line-count))
5389 (when (= building-line-count 0)
5390 (sit-for 0)
5391 (setq building-line-count
5392 gnus-summary-display-while-building)))
5393 ;; always
5394 (sit-for 0)))
eec82323
LMI
5395 (unless threads
5396 (setq gnus-tmp-level 0)))))
5397 (gnus-message 7 "Generating summary...done"))
5398
5399(defun gnus-summary-prepare-unthreaded (headers)
5400 "Generate an unthreaded summary buffer based on HEADERS."
5401 (let (header number mark)
5402
5403 (beginning-of-line)
5404
5405 (while headers
5406 ;; We may have to root out some bad articles...
5407 (when (memq (setq number (mail-header-number
5408 (setq header (pop headers))))
5409 gnus-newsgroup-limit)
5410 ;; Mark article as read when it has a low score.
5411 (when (and gnus-summary-mark-below
5412 (< (or (cdr (assq number gnus-newsgroup-scored))
5413 gnus-summary-default-score 0)
5414 gnus-summary-mark-below)
5415 (not (gnus-summary-article-ancient-p number)))
5416 (setq gnus-newsgroup-unreads
5417 (delq number gnus-newsgroup-unreads))
5418 (if gnus-newsgroup-auto-expire
5419 (push number gnus-newsgroup-expirable)
5420 (push (cons number gnus-low-score-mark)
5421 gnus-newsgroup-reads)))
5422
5423 (setq mark (gnus-article-mark number))
5424 (push (gnus-data-make number mark (1+ (point)) header 0)
5425 gnus-newsgroup-data)
5426 (gnus-summary-insert-line
5427 header 0 number
23f87bed 5428 (memq number gnus-newsgroup-undownloaded)
eec82323
LMI
5429 mark (memq number gnus-newsgroup-replied)
5430 (memq number gnus-newsgroup-expirable)
5431 (mail-header-subject header) nil
5432 (cdr (assq number gnus-newsgroup-scored))
5433 (memq number gnus-newsgroup-processable))))))
5434
16409b0b
GM
5435(defun gnus-summary-remove-list-identifiers ()
5436 "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
23f87bed
MB
5437 (let ((regexp (if (consp gnus-list-identifiers)
5438 (mapconcat 'identity gnus-list-identifiers " *\\|")
5439 gnus-list-identifiers))
5440 changed subject)
5441 (when regexp
01c52d31 5442 (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
23f87bed
MB
5443 (dolist (header gnus-newsgroup-headers)
5444 (setq subject (mail-header-subject header)
5445 changed nil)
01c52d31 5446 (while (string-match regexp subject)
23f87bed 5447 (setq subject
01c52d31 5448 (concat (substring subject 0 (match-beginning 1))
23f87bed
MB
5449 (substring subject (match-end 0)))
5450 changed t))
23f87bed 5451 (when changed
01c52d31
MB
5452 (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5453 (setq subject
5454 (concat (substring subject 0 (match-beginning 1))
5455 (substring subject (match-end 1)))))
23f87bed
MB
5456 (mail-header-set-subject header subject))))))
5457
5458(defun gnus-fetch-headers (articles)
5459 "Fetch headers of ARTICLES."
5460 (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5461 (gnus-message 5 "Fetching headers for %s..." name)
5462 (prog1
5463 (if (eq 'nov
5464 (setq gnus-headers-retrieved-by
5465 (gnus-retrieve-headers
5466 articles gnus-newsgroup-name
5467 ;; We might want to fetch old headers, but
5468 ;; not if there is only 1 article.
5469 (and (or (and
5470 (not (eq gnus-fetch-old-headers 'some))
5471 (not (numberp gnus-fetch-old-headers)))
5472 (> (length articles) 1))
5473 gnus-fetch-old-headers))))
5474 (gnus-get-newsgroup-headers-xover
5475 articles nil nil gnus-newsgroup-name t)
5476 (gnus-get-newsgroup-headers))
5477 (gnus-message 5 "Fetching headers for %s...done" name))))
16409b0b 5478
6748645f 5479(defun gnus-select-newsgroup (group &optional read-all select-articles)
eec82323 5480 "Select newsgroup GROUP.
6748645f
LMI
5481If READ-ALL is non-nil, all articles in the group are selected.
5482If SELECT-ARTICLES, only select those articles from GROUP."
01c52d31 5483 (let* ((entry (gnus-group-entry group))
eec82323
LMI
5484 ;;!!! Dirty hack; should be removed.
5485 (gnus-summary-ignore-duplicates
23f87bed 5486 (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
eec82323
LMI
5487 t
5488 gnus-summary-ignore-duplicates))
5489 (info (nth 2 entry))
01c52d31 5490 charset articles fetched-articles cached)
eec82323
LMI
5491
5492 (unless (gnus-check-server
475e0e0c
GM
5493 (set (make-local-variable 'gnus-current-select-method)
5494 (gnus-find-method-for-group group)))
eec82323 5495 (error "Couldn't open server"))
01c52d31 5496 (setq charset (gnus-group-name-charset gnus-current-select-method group))
eec82323
LMI
5497
5498 (or (and entry (not (eq (car entry) t))) ; Either it's active...
5499 (gnus-activate-group group) ; Or we can activate it...
5500 (progn ; Or we bug out.
5501 (when (equal major-mode 'gnus-summary-mode)
23f87bed 5502 (gnus-kill-buffer (current-buffer)))
01c52d31
MB
5503 (error
5504 "Couldn't activate group %s: %s"
5505 (mm-decode-coding-string group charset)
5506 (mm-decode-coding-string (gnus-status-message group) charset))))
eec82323
LMI
5507
5508 (unless (gnus-request-group group t)
01c52d31
MB
5509 (when (equal major-mode 'gnus-summary-mode)
5510 (gnus-kill-buffer (current-buffer)))
5511 (error "Couldn't request group %s: %s"
5512 (mm-decode-coding-string group charset)
5513 (mm-decode-coding-string (gnus-status-message group) charset)))
eec82323 5514
23f87bed 5515 (when gnus-agent
54506618 5516 (gnus-agent-possibly-alter-active group (gnus-active group) info)
132cf96d 5517
23f87bed
MB
5518 (setq gnus-summary-use-undownloaded-faces
5519 (gnus-agent-find-parameter
5520 group
5521 'agent-enable-undownloaded-faces)))
5522
5523 (setq gnus-newsgroup-name group
5524 gnus-newsgroup-unselected nil
5525 gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5526
5527 (let ((display (gnus-group-find-parameter group 'display)))
5528 (setq gnus-newsgroup-display
5529 (cond
5530 ((not (zerop (or (car-safe read-all) 0)))
5531 ;; The user entered the group with C-u SPC/RET, let's show
5532 ;; all articles.
5533 'gnus-not-ignore)
5534 ((eq display 'all)
5535 'gnus-not-ignore)
5536 ((arrayp display)
5537 (gnus-summary-display-make-predicate (mapcar 'identity display)))
5538 ((numberp display)
5539 ;; The following is probably the "correct" solution, but
5540 ;; it makes Gnus fetch all headers and then limit the
5541 ;; articles (which is slow), so instead we hack the
5542 ;; select-articles parameter instead. -- Simon Josefsson
5543 ;; <jas@kth.se>
5544 ;;
5545 ;; (gnus-byte-compile
5546 ;; `(lambda () (> number ,(- (cdr (gnus-active group))
5547 ;; display)))))
5548 (setq select-articles
5549 (gnus-uncompress-range
5550 (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5551 (if (> tmp 0)
5552 tmp
5553 1))
5554 (cdr (gnus-active group)))))
5555 nil)
5556 (t
5557 nil))))
eec82323 5558
23f87bed 5559 (gnus-summary-setup-default-charset)
eec82323
LMI
5560
5561 ;; Kludge to avoid having cached articles nixed out in virtual groups.
5562 (when (gnus-virtual-group-p group)
5563 (setq cached gnus-newsgroup-cached))
5564
5565 (setq gnus-newsgroup-unreads
23f87bed
MB
5566 (gnus-sorted-ndifference
5567 (gnus-sorted-ndifference gnus-newsgroup-unreads
5568 gnus-newsgroup-marked)
eec82323
LMI
5569 gnus-newsgroup-dormant))
5570
5571 (setq gnus-newsgroup-processable nil)
5572
5573 (gnus-update-read-articles group gnus-newsgroup-unreads)
eec82323 5574
23f87bed
MB
5575 ;; Adjust and set lists of article marks.
5576 (when info
5577 (gnus-adjust-marked-articles info))
6748645f
LMI
5578 (if (setq articles select-articles)
5579 (setq gnus-newsgroup-unselected
23f87bed 5580 (gnus-sorted-difference gnus-newsgroup-unreads articles))
6748645f 5581 (setq articles (gnus-articles-to-read group read-all)))
eec82323
LMI
5582
5583 (cond
5584 ((null articles)
5585 ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5586 'quit)
5587 ((eq articles 0) nil)
5588 (t
5589 ;; Init the dependencies hash table.
5590 (setq gnus-newsgroup-dependencies
5591 (gnus-make-hashtable (length articles)))
16409b0b 5592 (gnus-set-global-variables)
eec82323 5593 ;; Retrieve the headers and read them in.
23f87bed
MB
5594
5595 (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
eec82323
LMI
5596
5597 ;; Kludge to avoid having cached articles nixed out in virtual groups.
5598 (when cached
5599 (setq gnus-newsgroup-cached cached))
5600
5601 ;; Suppress duplicates?
5602 (when gnus-suppress-duplicates
5603 (gnus-dup-suppress-articles))
5604
5605 ;; Set the initial limit.
5606 (setq gnus-newsgroup-limit (copy-sequence articles))
5607 ;; Remove canceled articles from the list of unread articles.
23f87bed
MB
5608 (setq fetched-articles
5609 (mapcar (lambda (headers) (mail-header-number headers))
5610 gnus-newsgroup-headers))
5611 (setq gnus-newsgroup-articles fetched-articles)
eec82323 5612 (setq gnus-newsgroup-unreads
23f87bed
MB
5613 (gnus-sorted-nintersection
5614 gnus-newsgroup-unreads fetched-articles))
5615 (gnus-compute-unseen-list)
5616
eec82323
LMI
5617 ;; Removed marked articles that do not exist.
5618 (gnus-update-missing-marks
23f87bed 5619 (gnus-sorted-difference articles fetched-articles))
eec82323 5620 ;; We might want to build some more threads first.
6748645f
LMI
5621 (when (and gnus-fetch-old-headers
5622 (eq gnus-headers-retrieved-by 'nov))
5623 (if (eq gnus-fetch-old-headers 'invisible)
5624 (gnus-build-all-threads)
5625 (gnus-build-old-threads)))
5626 ;; Let the Gnus agent mark articles as read.
5627 (when gnus-agent
5628 (gnus-agent-get-undownloaded-list))
16409b0b
GM
5629 ;; Remove list identifiers from subject
5630 (when gnus-list-identifiers
5631 (gnus-summary-remove-list-identifiers))
eec82323
LMI
5632 ;; Check whether auto-expire is to be done in this group.
5633 (setq gnus-newsgroup-auto-expire
5634 (gnus-group-auto-expirable-p group))
5635 ;; Set up the article buffer now, if necessary.
01c52d31
MB
5636 (unless (and gnus-single-article-buffer
5637 (equal gnus-article-buffer "*Article*"))
eec82323
LMI
5638 (gnus-article-setup-buffer))
5639 ;; First and last article in this newsgroup.
5640 (when gnus-newsgroup-headers
5641 (setq gnus-newsgroup-begin
5642 (mail-header-number (car gnus-newsgroup-headers))
5643 gnus-newsgroup-end
5644 (mail-header-number
5645 (gnus-last-element gnus-newsgroup-headers))))
5646 ;; GROUP is successfully selected.
5647 (or gnus-newsgroup-headers t)))))
5648
23f87bed
MB
5649(defun gnus-compute-unseen-list ()
5650 ;; The `seen' marks are treated specially.
5651 (if (not gnus-newsgroup-seen)
5652 (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5653 (setq gnus-newsgroup-unseen
5654 (gnus-inverse-list-range-intersection
5655 gnus-newsgroup-articles gnus-newsgroup-seen))))
5656
d09ae6ca
GM
5657(declare-function gnus-get-predicate "gnus-agent" (predicate))
5658
23f87bed
MB
5659(defun gnus-summary-display-make-predicate (display)
5660 (require 'gnus-agent)
5661 (when (= (length display) 1)
5662 (setq display (car display)))
5663 (unless gnus-summary-display-cache
5664 (dolist (elem (append '((unread . unread)
5665 (read . read)
5666 (unseen . unseen))
5667 gnus-article-mark-lists))
5668 (push (cons (cdr elem)
5669 (gnus-byte-compile
5670 `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5671 gnus-summary-display-cache)))
5672 (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5673 (gnus-category-predicate-cache gnus-summary-display-cache))
5674 (gnus-get-predicate display)))
5675
5676;; Uses the dynamically bound `number' variable.
9efa445f 5677(defvar number)
23f87bed
MB
5678(defun gnus-article-marked-p (type &optional article)
5679 (let ((article (or article number)))
5680 (cond
5681 ((eq type 'tick)
5682 (memq article gnus-newsgroup-marked))
5683 ((eq type 'spam)
5684 (memq article gnus-newsgroup-spam-marked))
5685 ((eq type 'unsend)
5686 (memq article gnus-newsgroup-unsendable))
5687 ((eq type 'undownload)
5688 (memq article gnus-newsgroup-undownloaded))
5689 ((eq type 'download)
5690 (memq article gnus-newsgroup-downloadable))
5691 ((eq type 'unread)
5692 (memq article gnus-newsgroup-unreads))
5693 ((eq type 'read)
5694 (memq article gnus-newsgroup-reads))
5695 ((eq type 'dormant)
5696 (memq article gnus-newsgroup-dormant) )
5697 ((eq type 'expire)
5698 (memq article gnus-newsgroup-expirable))
5699 ((eq type 'reply)
5700 (memq article gnus-newsgroup-replied))
5701 ((eq type 'killed)
5702 (memq article gnus-newsgroup-killed))
5703 ((eq type 'bookmark)
5704 (assq article gnus-newsgroup-bookmarks))
5705 ((eq type 'score)
5706 (assq article gnus-newsgroup-scored))
5707 ((eq type 'save)
5708 (memq article gnus-newsgroup-saved))
5709 ((eq type 'cache)
5710 (memq article gnus-newsgroup-cached))
5711 ((eq type 'forward)
5712 (memq article gnus-newsgroup-forwarded))
5713 ((eq type 'seen)
5714 (not (memq article gnus-newsgroup-unseen)))
5715 ((eq type 'recent)
5716 (memq article gnus-newsgroup-recent))
5717 (t t))))
5718
eec82323 5719(defun gnus-articles-to-read (group &optional read-all)
16409b0b 5720 "Find out what articles the user wants to read."
26c9afc3 5721 (let* ((articles
eec82323
LMI
5722 ;; Select all articles if `read-all' is non-nil, or if there
5723 ;; are no unread articles.
5724 (if (or read-all
5725 (and (zerop (length gnus-newsgroup-marked))
5726 (zerop (length gnus-newsgroup-unreads)))
23f87bed
MB
5727 ;; Fetch all if the predicate is non-nil.
5728 gnus-newsgroup-display)
5729 ;; We want to select the headers for all the articles in
5730 ;; the group, so we select either all the active
5731 ;; articles in the group, or (if that's nil), the
5732 ;; articles in the cache.
16409b0b 5733 (or
4b70e299 5734 (if gnus-newsgroup-maximum-articles
11abff8e
MB
5735 (let ((active (gnus-active group)))
5736 (gnus-uncompress-range
5737 (cons (max (car active)
4b70e299
MB
5738 (- (cdr active)
5739 gnus-newsgroup-maximum-articles
5740 -1))
11abff8e
MB
5741 (cdr active))))
5742 (gnus-uncompress-range (gnus-active group)))
16409b0b 5743 (gnus-cache-articles-in-group group))
23f87bed
MB
5744 ;; Select only the "normal" subset of articles.
5745 (gnus-sorted-nunion
5746 (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5747 gnus-newsgroup-unreads)))
eec82323
LMI
5748 (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5749 (scored (length scored-list))
5750 (number (length articles))
5751 (marked (+ (length gnus-newsgroup-marked)
5752 (length gnus-newsgroup-dormant)))
5753 (select
5754 (cond
5755 ((numberp read-all)
5756 read-all)
23f87bed
MB
5757 ((numberp gnus-newsgroup-display)
5758 gnus-newsgroup-display)
eec82323
LMI
5759 (t
5760 (condition-case ()
5761 (cond
5762 ((and (or (<= scored marked) (= scored number))
5763 (numberp gnus-large-newsgroup)
5764 (> number gnus-large-newsgroup))
23f87bed
MB
5765 (let* ((cursor-in-echo-area nil)
5766 (initial (gnus-parameter-large-newsgroup-initial
5767 gnus-newsgroup-name))
5768 (input
5769 (read-string
5770 (format
5771 "How many articles from %s (%s %d): "
01c52d31 5772 (gnus-group-decoded-name gnus-newsgroup-name)
23f87bed
MB
5773 (if initial "max" "default")
5774 number)
5775 (if initial
5776 (cons (number-to-string initial)
5777 0)))))
eec82323
LMI
5778 (if (string-match "^[ \t]*$" input) number input)))
5779 ((and (> scored marked) (< scored number)
5780 (> (- scored number) 20))
5781 (let ((input
5782 (read-string
5783 (format "%s %s (%d scored, %d total): "
5784 "How many articles from"
23f87bed
MB
5785 (gnus-group-decoded-name group)
5786 scored number))))
eec82323
LMI
5787 (if (string-match "^[ \t]*$" input)
5788 number input)))
5789 (t number))
d4dfaa19
DL
5790 (quit
5791 (message "Quit getting the articles to read")
5792 nil))))))
eec82323
LMI
5793 (setq select (if (stringp select) (string-to-number select) select))
5794 (if (or (null select) (zerop select))
5795 select
5796 (if (and (not (zerop scored)) (<= (abs select) scored))
5797 (progn
5798 (setq articles (sort scored-list '<))
5799 (setq number (length articles)))
5800 (setq articles (copy-sequence articles)))
5801
5802 (when (< (abs select) number)
5803 (if (< select 0)
5804 ;; Select the N oldest articles.
5805 (setcdr (nthcdr (1- (abs select)) articles) nil)
5806 ;; Select the N most recent articles.
5807 (setq articles (nthcdr (- number select) articles))))
5808 (setq gnus-newsgroup-unselected
23f87bed 5809 (gnus-sorted-difference gnus-newsgroup-unreads articles))
16409b0b 5810 (when gnus-alter-articles-to-read-function
23f87bed 5811 (setq articles
a1506d29 5812 (sort
16409b0b 5813 (funcall gnus-alter-articles-to-read-function
23f87bed 5814 gnus-newsgroup-name articles)
16409b0b 5815 '<)))
eec82323
LMI
5816 articles)))
5817
5818(defun gnus-killed-articles (killed articles)
5819 (let (out)
5820 (while articles
5821 (when (inline (gnus-member-of-range (car articles) killed))
5822 (push (car articles) out))
5823 (setq articles (cdr articles)))
5824 out))
5825
5826(defun gnus-uncompress-marks (marks)
5827 "Uncompress the mark ranges in MARKS."
5828 (let ((uncompressed '(score bookmark))
5829 out)
5830 (while marks
5831 (if (memq (caar marks) uncompressed)
5832 (push (car marks) out)
5833 (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5834 (setq marks (cdr marks)))
5835 out))
5836
23f87bed
MB
5837(defun gnus-article-mark-to-type (mark)
5838 "Return the type of MARK."
5839 (or (cadr (assq mark gnus-article-special-mark-lists))
5840 'list))
5841
5842(defun gnus-article-unpropagatable-p (mark)
5843 "Return whether MARK should be propagated to back end."
5844 (memq mark gnus-article-unpropagated-mark-lists))
5845
eec82323 5846(defun gnus-adjust-marked-articles (info)
16409b0b 5847 "Set all article lists and remove all marks that are no longer valid."
eec82323
LMI
5848 (let* ((marked-lists (gnus-info-marks info))
5849 (active (gnus-active (gnus-info-group info)))
5850 (min (car active))
5851 (max (cdr active))
5852 (types gnus-article-mark-lists)
54506618
MB
5853 marks var articles article mark mark-type
5854 bgn end)
eec82323 5855
23f87bed
MB
5856 (dolist (marks marked-lists)
5857 (setq mark (car marks)
5858 mark-type (gnus-article-mark-to-type mark)
5859 var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
eec82323 5860
23f87bed
MB
5861 ;; We set the variable according to the type of the marks list,
5862 ;; and then adjust the marks to a subset of the active articles.
eec82323 5863 (cond
54506618 5864 ;; Adjust "simple" lists - compressed yet unsorted
23f87bed 5865 ((eq mark-type 'list)
54506618
MB
5866 ;; Simultaneously uncompress and clip to active range
5867 ;; See gnus-uncompress-range for a description of possible marks
5868 (let (l lh)
5869 (if (not (cadr marks))
5870 (set var nil)
5871 (setq articles (if (numberp (cddr marks))
5872 (list (cdr marks))
5873 (cdr marks))
5874 lh (cons nil nil)
5875 l lh)
5876
5877 (while (setq article (pop articles))
5878 (cond ((consp article)
5879 (setq bgn (max (car article) min)
5880 end (min (cdr article) max))
5881 (while (<= bgn end)
5882 (setq l (setcdr l (cons bgn nil))
5883 bgn (1+ bgn))))
5884 ((and (<= min article)
5885 (>= max article))
5886 (setq l (setcdr l (cons article nil))))))
5887 (set var (cdr lh)))))
eec82323 5888 ;; Adjust assocs.
23f87bed
MB
5889 ((eq mark-type 'tuple)
5890 (set var (setq articles (cdr marks)))
a8151ef7
LMI
5891 (when (not (listp (cdr (symbol-value var))))
5892 (set var (list (symbol-value var))))
5893 (when (not (listp (cdr articles)))
5894 (setq articles (list articles)))
eec82323
LMI
5895 (while articles
5896 (when (or (not (consp (setq article (pop articles))))
5897 (< (car article) min)
5898 (> (car article) max))
23f87bed
MB
5899 (set var (delq article (symbol-value var))))))
5900 ;; Adjust ranges (sloppily).
5901 ((eq mark-type 'range)
5902 (cond
5903 ((eq mark 'seen)
5904 ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5905 ;; It should be (seen (NUM1 . NUM2)).
5906 (when (numberp (cddr marks))
5907 (setcdr marks (list (cdr marks))))
5908 (setq articles (cdr marks))
5909 (while (and articles
5910 (or (and (consp (car articles))
5911 (> min (cdar articles)))
5912 (and (numberp (car articles))
5913 (> min (car articles)))))
5914 (pop articles))
5915 (set var articles))))))))
eec82323
LMI
5916
5917(defun gnus-update-missing-marks (missing)
6748645f 5918 "Go through the list of MISSING articles and remove them from the mark lists."
eec82323 5919 (when missing
23f87bed 5920 (let (var m)
eec82323 5921 ;; Go through all types.
23f87bed
MB
5922 (dolist (elem gnus-article-mark-lists)
5923 (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5924 (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5925 (when (symbol-value var)
5926 ;; This list has articles. So we delete all missing
5927 ;; articles from it.
5928 (setq m missing)
5929 (while m
5930 (set var (delq (pop m) (symbol-value var))))))))))
eec82323
LMI
5931
5932(defun gnus-update-marks ()
5933 "Enter the various lists of marked articles into the newsgroup info list."
5934 (let ((types gnus-article-mark-lists)
5935 (info (gnus-get-info gnus-newsgroup-name))
16409b0b 5936 type list newmarked symbol delta-marks)
eec82323 5937 (when info
16409b0b 5938 ;; Add all marks lists to the list of marks lists.
eec82323 5939 (while (setq type (pop types))
16409b0b
GM
5940 (setq list (symbol-value
5941 (setq symbol
23f87bed 5942 (intern (format "gnus-newsgroup-%s" (car type))))))
eec82323 5943
16409b0b 5944 (when list
eec82323
LMI
5945 ;; Get rid of the entries of the articles that have the
5946 ;; default score.
5947 (when (and (eq (cdr type) 'score)
5948 gnus-save-score
5949 list)
5950 (let* ((arts list)
5951 (prev (cons nil list))
5952 (all prev))
5953 (while arts
5954 (if (or (not (consp (car arts)))
5955 (= (cdar arts) gnus-summary-default-score))
5956 (setcdr prev (cdr arts))
5957 (setq prev arts))
5958 (setq arts (cdr arts)))
16409b0b
GM
5959 (setq list (cdr all)))))
5960
23f87bed
MB
5961 (when (eq (cdr type) 'seen)
5962 (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5963
5964 (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
16409b0b 5965 (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
a1506d29 5966
23f87bed
MB
5967 (when (and (gnus-check-backend-function
5968 'request-set-mark gnus-newsgroup-name)
5969 (not (gnus-article-unpropagatable-p (cdr type))))
5970 (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5971 (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5972 (add (gnus-remove-from-range
5973 (gnus-copy-sequence list) old)))
5974 (when add
5975 (push (list add 'add (list (cdr type))) delta-marks))
5976 (when del
5977 (push (list del 'del (list (cdr type))) delta-marks))))
a1506d29 5978
16409b0b
GM
5979 (when list
5980 (push (cons (cdr type) list) newmarked)))
5981
5982 (when delta-marks
5983 (unless (gnus-check-group gnus-newsgroup-name)
5984 (error "Can't open server for %s" gnus-newsgroup-name))
5985 (gnus-request-set-mark gnus-newsgroup-name delta-marks))
a1506d29 5986
eec82323
LMI
5987 ;; Enter these new marks into the info of the group.
5988 (if (nthcdr 3 info)
5989 (setcar (nthcdr 3 info) newmarked)
5990 ;; Add the marks lists to the end of the info.
5991 (when newmarked
5992 (setcdr (nthcdr 2 info) (list newmarked))))
5993
5994 ;; Cut off the end of the info if there's nothing else there.
5995 (let ((i 5))
5996 (while (and (> i 2)
5997 (not (nth i info)))
5998 (when (nthcdr (decf i) info)
5999 (setcdr (nthcdr i info) nil)))))))
6000
6001(defun gnus-set-mode-line (where)
16409b0b 6002 "Set the mode line of the article or summary buffers.
eec82323
LMI
6003If WHERE is `summary', the summary mode line format will be used."
6004 ;; Is this mode line one we keep updated?
16409b0b
GM
6005 (when (and (memq where gnus-updated-mode-lines)
6006 (symbol-value
6007 (intern (format "gnus-%s-mode-line-format-spec" where))))
eec82323 6008 (let (mode-string)
c7a91ce1
SM
6009 ;; We evaluate this in the summary buffer since these
6010 ;; variables are buffer-local to that buffer.
6011 (with-current-buffer gnus-summary-buffer
6012 ;; We bind all these variables that are used in the `eval' form
eec82323
LMI
6013 ;; below.
6014 (let* ((mformat (symbol-value
6015 (intern
6016 (format "gnus-%s-mode-line-format-spec" where))))
b90a6149
MB
6017 (gnus-tmp-group-name (gnus-mode-string-quote
6018 (gnus-group-decoded-name
6019 gnus-newsgroup-name)))
eec82323
LMI
6020 (gnus-tmp-article-number (or gnus-current-article 0))
6021 (gnus-tmp-unread gnus-newsgroup-unreads)
6022 (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
6023 (gnus-tmp-unselected (length gnus-newsgroup-unselected))
6024 (gnus-tmp-unread-and-unselected
6025 (cond ((and (zerop gnus-tmp-unread-and-unticked)
6026 (zerop gnus-tmp-unselected))
6027 "")
6028 ((zerop gnus-tmp-unselected)
6029 (format "{%d more}" gnus-tmp-unread-and-unticked))
6030 (t (format "{%d(+%d) more}"
6031 gnus-tmp-unread-and-unticked
6032 gnus-tmp-unselected))))
6033 (gnus-tmp-subject
6034 (if (and gnus-current-headers
6035 (vectorp gnus-current-headers))
6036 (gnus-mode-string-quote
6037 (mail-header-subject gnus-current-headers))
6038 ""))
6039 bufname-length max-len
23f87bed 6040 gnus-tmp-header) ;; passed as argument to any user-format-funcs
eec82323
LMI
6041 (setq mode-string (eval mformat))
6042 (setq bufname-length (if (string-match "%b" mode-string)
6043 (- (length
6044 (buffer-name
6045 (if (eq where 'summary)
6046 nil
6047 (get-buffer gnus-article-buffer))))
6048 2)
6049 0))
6050 (setq max-len (max 4 (if gnus-mode-non-string-length
6051 (- (window-width)
6052 gnus-mode-non-string-length
6053 bufname-length)
6054 (length mode-string))))
6055 ;; We might have to chop a bit of the string off...
6056 (when (> (length mode-string) max-len)
6057 (setq mode-string
16409b0b 6058 (concat (truncate-string-to-width mode-string (- max-len 3))
eec82323
LMI
6059 "...")))
6060 ;; Pad the mode string a bit.
6061 (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
6062 ;; Update the mode line.
6063 (setq mode-line-buffer-identification
6064 (gnus-mode-line-buffer-identification (list mode-string)))
6065 (set-buffer-modified-p t))))
6066
6067(defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
6068 "Go through the HEADERS list and add all Xrefs to a hash table.
6069The resulting hash table is returned, or nil if no Xrefs were found."
6070 (let* ((virtual (gnus-virtual-group-p from-newsgroup))
6071 (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
6072 (xref-hashtb (gnus-make-hashtable))
6073 start group entry number xrefs header)
6074 (while headers
6075 (setq header (pop headers))
6076 (when (and (setq xrefs (mail-header-xref header))
6077 (not (memq (setq number (mail-header-number header))
6078 unreads)))
6079 (setq start 0)
6080 (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6081 (setq start (match-end 0))
6082 (setq group (if prefix
6083 (concat prefix (substring xrefs (match-beginning 1)
6084 (match-end 1)))
6085 (substring xrefs (match-beginning 1) (match-end 1))))
6086 (setq number
e9bd5782 6087 (string-to-number (substring xrefs (match-beginning 2)
eec82323
LMI
6088 (match-end 2))))
6089 (if (setq entry (gnus-gethash group xref-hashtb))
6090 (setcdr entry (cons number (cdr entry)))
6091 (gnus-sethash group (cons number nil) xref-hashtb)))))
6092 (and start xref-hashtb)))
6093
6094(defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6095 "Look through all the headers and mark the Xrefs as read."
6096 (let ((virtual (gnus-virtual-group-p from-newsgroup))
01c52d31 6097 name info xref-hashtb idlist method nth4)
398a825b 6098 (with-current-buffer gnus-group-buffer
eec82323
LMI
6099 (when (setq xref-hashtb
6100 (gnus-create-xref-hashtb from-newsgroup headers unreads))
6101 (mapatoms
6102 (lambda (group)
6103 (unless (string= from-newsgroup (setq name (symbol-name group)))
6104 (setq idlist (symbol-value group))
6105 ;; Dead groups are not updated.
6106 (and (prog1
01c52d31 6107 (setq info (gnus-get-info name))
eec82323
LMI
6108 (when (stringp (setq nth4 (gnus-info-method info)))
6109 (setq nth4 (gnus-server-to-method nth4))))
6110 ;; Only do the xrefs if the group has the same
6111 ;; select method as the group we have just read.
6112 (or (gnus-methods-equal-p
6113 nth4 (gnus-find-method-for-group from-newsgroup))
6114 virtual
6115 (equal nth4 (setq method (gnus-find-method-for-group
6116 from-newsgroup)))
6117 (and (equal (car nth4) (car method))
6118 (equal (nth 1 nth4) (nth 1 method))))
6119 gnus-use-cross-reference
6120 (or (not (eq gnus-use-cross-reference t))
6121 virtual
6122 ;; Only do cross-references on subscribed
6123 ;; groups, if that is what is wanted.
6124 (<= (gnus-info-level info) gnus-level-subscribed))
6125 (gnus-group-make-articles-read name idlist))))
6126 xref-hashtb)))))
6127
6748645f 6128(defun gnus-compute-read-articles (group articles)
01c52d31 6129 (let* ((entry (gnus-group-entry group))
6748645f
LMI
6130 (info (nth 2 entry))
6131 (active (gnus-active group))
6132 ninfo)
6133 (when entry
16409b0b 6134 ;; First peel off all invalid article numbers.
6748645f
LMI
6135 (when active
6136 (let ((ids articles)
6137 id first)
6138 (while (setq id (pop ids))
6139 (when (and first (> id (cdr active)))
6140 ;; We'll end up in this situation in one particular
6141 ;; obscure situation. If you re-scan a group and get
6142 ;; a new article that is cross-posted to a different
6143 ;; group that has not been re-scanned, you might get
6144 ;; crossposted article that has a higher number than
6145 ;; Gnus believes possible. So we re-activate this
6146 ;; group as well. This might mean doing the
6147 ;; crossposting thingy will *increase* the number
6148 ;; of articles in some groups. Tsk, tsk.
6149 (setq active (or (gnus-activate-group group) active)))
6150 (when (or (> id (cdr active))
6151 (< id (car active)))
6152 (setq articles (delq id articles))))))
6153 ;; If the read list is nil, we init it.
6154 (if (and active
6155 (null (gnus-info-read info))
6156 (> (car active) 1))
6157 (setq ninfo (cons 1 (1- (car active))))
6158 (setq ninfo (gnus-info-read info)))
6159 ;; Then we add the read articles to the range.
6160 (gnus-add-to-range
6161 ninfo (setq articles (sort articles '<))))))
6162
eec82323
LMI
6163(defun gnus-group-make-articles-read (group articles)
6164 "Update the info of GROUP to say that ARTICLES are read."
6165 (let* ((num 0)
01c52d31 6166 (entry (gnus-group-entry group))
eec82323
LMI
6167 (info (nth 2 entry))
6168 (active (gnus-active group))
6169 range)
6748645f
LMI
6170 (when entry
6171 (setq range (gnus-compute-read-articles group articles))
01c52d31 6172 (with-current-buffer gnus-group-buffer
6748645f
LMI
6173 (gnus-undo-register
6174 `(progn
6175 (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6176 (gnus-info-set-read ',info ',(gnus-info-read info))
6177 (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
23f87bed 6178 (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6748645f
LMI
6179 (gnus-group-update-group ,group t))))
6180 ;; Add the read articles to the range.
6181 (gnus-info-set-read info range)
23f87bed 6182 (gnus-request-set-mark group (list (list range 'add '(read))))
6748645f
LMI
6183 ;; Then we have to re-compute how many unread
6184 ;; articles there are in this group.
6185 (when active
6186 (cond
6187 ((not range)
6188 (setq num (- (1+ (cdr active)) (car active))))
6189 ((not (listp (cdr range)))
6190 (setq num (- (cdr active) (- (1+ (cdr range))
6191 (car range)))))
6192 (t
6193 (while range
6194 (if (numberp (car range))
6195 (setq num (1+ num))
6196 (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6197 (setq range (cdr range)))
6198 (setq num (- (cdr active) num))))
6199 ;; Update the number of unread articles.
6200 (setcar entry num)
6201 ;; Update the group buffer.
23f87bed
MB
6202 (unless (gnus-ephemeral-group-p group)
6203 (gnus-group-update-group group t))))))
eec82323 6204
eec82323
LMI
6205(defvar gnus-newsgroup-none-id 0)
6206
6207(defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6208 (let ((cur nntp-server-buffer)
6209 (dependencies
6210 (or dependencies
01c52d31
MB
6211 (with-current-buffer gnus-summary-buffer
6212 gnus-newsgroup-dependencies)))
6213 headers id end ref number
16409b0b
GM
6214 (mail-parse-charset gnus-newsgroup-charset)
6215 (mail-parse-ignored-charsets
c7a91ce1
SM
6216 (save-current-buffer (condition-case nil
6217 (set-buffer gnus-summary-buffer)
6218 (error))
6219 gnus-newsgroup-ignored-charsets)))
6220 (with-current-buffer nntp-server-buffer
eec82323
LMI
6221 ;; Translate all TAB characters into SPACE characters.
6222 (subst-char-in-region (point-min) (point-max) ?\t ? t)
16409b0b 6223 (subst-char-in-region (point-min) (point-max) ?\r ? t)
23f87bed 6224 (ietf-drums-unfold-fws)
6748645f 6225 (gnus-run-hooks 'gnus-parse-headers-hook)
eec82323 6226 (let ((case-fold-search t)
6748645f 6227 in-reply-to header p lines chars)
eec82323 6228 (goto-char (point-min))
01ccbb85 6229 ;; Search to the beginning of the next header. Error messages
eec82323
LMI
6230 ;; do not begin with 2 or 3.
6231 (while (re-search-forward "^[23][0-9]+ " nil t)
6232 (setq id nil
6233 ref nil)
6234 ;; This implementation of this function, with nine
6235 ;; search-forwards instead of the one re-search-forward and
6236 ;; a case (which basically was the old function) is actually
01ccbb85 6237 ;; about twice as fast, even though it looks messier. You
eec82323
LMI
6238 ;; can't have everything, I guess. Speed and elegance
6239 ;; doesn't always go hand in hand.
6240 (setq
6241 header
6242 (vector
6243 ;; Number.
6244 (prog1
01c52d31 6245 (setq number (read cur))
eec82323
LMI
6246 (end-of-line)
6247 (setq p (point))
6248 (narrow-to-region (point)
6249 (or (and (search-forward "\n.\n" nil t)
6250 (- (point) 2))
6251 (point))))
6252 ;; Subject.
6253 (progn
6254 (goto-char p)
23f87bed 6255 (if (search-forward "\nsubject:" nil t)
16409b0b
GM
6256 (funcall gnus-decode-encoded-word-function
6257 (nnheader-header-value))
2bd3dcae 6258 "(none)"))
eec82323
LMI
6259 ;; From.
6260 (progn
6261 (goto-char p)
23f87bed 6262 (if (search-forward "\nfrom:" nil t)
343d6628 6263 (funcall gnus-decode-encoded-address-function
16409b0b 6264 (nnheader-header-value))
2bd3dcae 6265 "(nobody)"))
eec82323
LMI
6266 ;; Date.
6267 (progn
6268 (goto-char p)
23f87bed 6269 (if (search-forward "\ndate:" nil t)
eec82323
LMI
6270 (nnheader-header-value) ""))
6271 ;; Message-ID.
6272 (progn
6273 (goto-char p)
6748645f
LMI
6274 (setq id (if (re-search-forward
6275 "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6276 ;; We do it this way to make sure the Message-ID
6277 ;; is (somewhat) syntactically valid.
6278 (buffer-substring (match-beginning 1)
6279 (match-end 1))
eec82323
LMI
6280 ;; If there was no message-id, we just fake one
6281 ;; to make subsequent routines simpler.
01c52d31 6282 (nnheader-generate-fake-message-id number))))
eec82323
LMI
6283 ;; References.
6284 (progn
6285 (goto-char p)
23f87bed 6286 (if (search-forward "\nreferences:" nil t)
eec82323
LMI
6287 (progn
6288 (setq end (point))
6289 (prog1
6290 (nnheader-header-value)
6291 (setq ref
6292 (buffer-substring
6293 (progn
6294 (end-of-line)
6295 (search-backward ">" end t)
6296 (1+ (point)))
6297 (progn
6298 (search-backward "<" end t)
6299 (point))))))
6300 ;; Get the references from the in-reply-to header if there
6301 ;; were no references and the in-reply-to header looks
6302 ;; promising.
23f87bed 6303 (if (and (search-forward "\nin-reply-to:" nil t)
eec82323
LMI
6304 (setq in-reply-to (nnheader-header-value))
6305 (string-match "<[^>]+>" in-reply-to))
6748645f
LMI
6306 (let (ref2)
6307 (setq ref (substring in-reply-to (match-beginning 0)
6308 (match-end 0)))
6309 (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6310 (setq ref2 (substring in-reply-to (match-beginning 0)
6311 (match-end 0)))
6312 (when (> (length ref2) (length ref))
6313 (setq ref ref2)))
6314 ref)
eec82323
LMI
6315 (setq ref nil))))
6316 ;; Chars.
6748645f
LMI
6317 (progn
6318 (goto-char p)
6319 (if (search-forward "\nchars: " nil t)
6320 (if (numberp (setq chars (ignore-errors (read cur))))
23f87bed
MB
6321 chars -1)
6322 -1))
eec82323
LMI
6323 ;; Lines.
6324 (progn
6325 (goto-char p)
6326 (if (search-forward "\nlines: " nil t)
a8151ef7 6327 (if (numberp (setq lines (ignore-errors (read cur))))
23f87bed
MB
6328 lines -1)
6329 -1))
eec82323
LMI
6330 ;; Xref.
6331 (progn
6332 (goto-char p)
23f87bed 6333 (and (search-forward "\nxref:" nil t)
16409b0b
GM
6334 (nnheader-header-value)))
6335 ;; Extra.
6336 (when gnus-extra-headers
6337 (let ((extra gnus-extra-headers)
6338 out)
6339 (while extra
6340 (goto-char p)
6341 (when (search-forward
23f87bed 6342 (concat "\n" (symbol-name (car extra)) ":") nil t)
16409b0b
GM
6343 (push (cons (car extra) (nnheader-header-value))
6344 out))
6345 (pop extra))
6346 out))))
eec82323
LMI
6347 (when (equal id ref)
6348 (setq ref nil))
6748645f
LMI
6349
6350 (when gnus-alter-header-function
6351 (funcall gnus-alter-header-function header)
6352 (setq id (mail-header-id header)
6353 ref (gnus-parent-id (mail-header-references header))))
6354
6355 (when (setq header
6356 (gnus-dependencies-add-header
6357 header dependencies force-new))
eec82323
LMI
6358 (push header headers))
6359 (goto-char (point-max))
6360 (widen))
6361 (nreverse headers)))))
6362
eec82323
LMI
6363;; Goes through the xover lines and returns a list of vectors
6364(defun gnus-get-newsgroup-headers-xover (sequence &optional
6365 force-new dependencies
6366 group also-fetch-heads)
16409b0b
GM
6367 "Parse the news overview data in the server buffer.
6368Return a list of headers that match SEQUENCE (see
6369`nntp-retrieve-headers')."
eec82323
LMI
6370 ;; Get the Xref when the users reads the articles since most/some
6371 ;; NNTP servers do not include Xrefs when using XOVER.
6372 (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
16409b0b
GM
6373 (let ((mail-parse-charset gnus-newsgroup-charset)
6374 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6375 (cur nntp-server-buffer)
eec82323 6376 (dependencies (or dependencies gnus-newsgroup-dependencies))
23f87bed
MB
6377 (allp (cond
6378 ((eq gnus-read-all-available-headers t)
6379 t)
14e6dc54
MB
6380 ((and (stringp gnus-read-all-available-headers)
6381 group)
23f87bed
MB
6382 (string-match gnus-read-all-available-headers group))
6383 (t
6384 nil)))
eec82323 6385 number headers header)
c7a91ce1 6386 (with-current-buffer nntp-server-buffer
16409b0b 6387 (subst-char-in-region (point-min) (point-max) ?\r ? t)
eec82323 6388 ;; Allow the user to mangle the headers before parsing them.
6748645f 6389 (gnus-run-hooks 'gnus-parse-headers-hook)
eec82323 6390 (goto-char (point-min))
23f87bed
MB
6391 (gnus-parse-without-error
6392 (while (and (or sequence allp)
6393 (not (eobp)))
6394 (setq number (read cur))
6395 (when (not allp)
6396 (while (and sequence
6397 (< (car sequence) number))
6398 (setq sequence (cdr sequence))))
6399 (when (and (or allp
6400 (and sequence
6401 (eq number (car sequence))))
6402 (progn
6403 (setq sequence (cdr sequence))
6404 (setq header (inline
6405 (gnus-nov-parse-line
6406 number dependencies force-new)))))
6407 (push header headers))
6408 (forward-line 1)))
eec82323
LMI
6409 ;; A common bug in inn is that if you have posted an article and
6410 ;; then retrieves the active file, it will answer correctly --
6411 ;; the new article is included. However, a NOV entry for the
6412 ;; article may not have been generated yet, so this may fail.
6413 ;; We work around this problem by retrieving the last few
6414 ;; headers using HEAD.
6415 (if (or (not also-fetch-heads)
6416 (not sequence))
6417 ;; We (probably) got all the headers.
6418 (nreverse headers)
6419 (let ((gnus-nov-is-evil t))
6420 (nconc
6421 (nreverse headers)
23f87bed 6422 (when (eq (gnus-retrieve-headers sequence group) 'headers)
eec82323
LMI
6423 (gnus-get-newsgroup-headers))))))))
6424
6425(defun gnus-article-get-xrefs ()
6426 "Fill in the Xref value in `gnus-current-headers', if necessary.
6427This is meant to be called in `gnus-article-internal-prepare-hook'."
01c52d31
MB
6428 (let ((headers (with-current-buffer gnus-summary-buffer
6429 gnus-current-headers)))
eec82323
LMI
6430 (or (not gnus-use-cross-reference)
6431 (not headers)
6432 (and (mail-header-xref headers)
6433 (not (string= (mail-header-xref headers) "")))
6434 (let ((case-fold-search t)
6435 xref)
6436 (save-restriction
6437 (nnheader-narrow-to-headers)
6438 (goto-char (point-min))
16409b0b
GM
6439 (when (or (and (not (eobp))
6440 (eq (downcase (char-after)) ?x)
eec82323
LMI
6441 (looking-at "Xref:"))
6442 (search-forward "\nXref:" nil t))
6443 (goto-char (1+ (match-end 0)))
01c52d31 6444 (setq xref (buffer-substring (point) (point-at-eol)))
eec82323
LMI
6445 (mail-header-set-xref headers xref)))))))
6446
6447(defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6748645f
LMI
6448 "Find article ID and insert the summary line for that article.
6449OLD-HEADER can either be a header or a line number to insert
6450the subject line on."
6451 (let* ((line (and (numberp old-header) old-header))
6452 (old-header (and (vectorp old-header) old-header))
6453 (header (cond ((and old-header use-old-header)
16409b0b
GM
6454 old-header)
6455 ((and (numberp id)
6456 (gnus-number-to-header id))
6457 (gnus-number-to-header id))
6458 (t
6459 (gnus-read-header id))))
6460 (number (and (numberp id) id))
6461 d)
eec82323
LMI
6462 (when header
6463 ;; Rebuild the thread that this article is part of and go to the
6464 ;; article we have fetched.
6465 (when (and (not gnus-show-threads)
6466 old-header)
6748645f
LMI
6467 (when (and number
6468 (setq d (gnus-data-find (mail-header-number old-header))))
eec82323
LMI
6469 (goto-char (gnus-data-pos d))
6470 (gnus-data-remove
6471 number
01c52d31 6472 (- (point-at-bol)
eec82323 6473 (prog1
01c52d31 6474 (1+ (point-at-eol))
eec82323 6475 (gnus-delete-line))))))
23f87bed
MB
6476 ;; Remove list identifiers from subject.
6477 (when gnus-list-identifiers
6478 (let ((gnus-newsgroup-headers (list header)))
c3bc41c2 6479 (gnus-summary-remove-list-identifiers)))
eec82323
LMI
6480 (when old-header
6481 (mail-header-set-number header (mail-header-number old-header)))
6482 (setq gnus-newsgroup-sparse
6483 (delq (setq number (mail-header-number header))
6484 gnus-newsgroup-sparse))
6485 (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6748645f
LMI
6486 (push number gnus-newsgroup-limit)
6487 (gnus-rebuild-thread (mail-header-id header) line)
eec82323
LMI
6488 (gnus-summary-goto-subject number nil t))
6489 (when (and (numberp number)
6490 (> number 0))
6491 ;; We have to update the boundaries even if we can't fetch the
6492 ;; article if ID is a number -- so that the next `P' or `N'
6493 ;; command will fetch the previous (or next) article even
6494 ;; if the one we tried to fetch this time has been canceled.
6495 (when (> number gnus-newsgroup-end)
6496 (setq gnus-newsgroup-end number))
6497 (when (< number gnus-newsgroup-begin)
6498 (setq gnus-newsgroup-begin number))
6499 (setq gnus-newsgroup-unselected
6500 (delq number gnus-newsgroup-unselected)))
6501 ;; Report back a success?
6502 (and header (mail-header-number header))))
6503
6504;;; Process/prefix in the summary buffer
6505
6506(defun gnus-summary-work-articles (n)
6748645f
LMI
6507 "Return a list of articles to be worked upon.
6508The prefix argument, the list of process marked articles, and the
6509current article will be taken into consideration."
c7a91ce1 6510 (with-current-buffer gnus-summary-buffer
6748645f
LMI
6511 (cond
6512 (n
6513 ;; A numerical prefix has been given.
6514 (setq n (prefix-numeric-value n))
6515 (let ((backward (< n 0))
6516 (n (abs (prefix-numeric-value n)))
6517 articles article)
6518 (save-excursion
6519 (while
6520 (and (> n 0)
6521 (push (setq article (gnus-summary-article-number))
6522 articles)
6523 (if backward
6524 (gnus-summary-find-prev nil article)
6525 (gnus-summary-find-next nil article)))
6526 (decf n)))
6527 (nreverse articles)))
6528 ((and (gnus-region-active-p) (mark))
6529 (message "region active")
6530 ;; Work on the region between point and mark.
6531 (let ((max (max (point) (mark)))
6532 articles article)
6533 (save-excursion
7dafe00b 6534 (goto-char (min (point) (mark)))
6748645f
LMI
6535 (while
6536 (and
6537 (push (setq article (gnus-summary-article-number)) articles)
6538 (gnus-summary-find-next nil article)
6539 (< (point) max)))
6540 (nreverse articles))))
6541 (gnus-newsgroup-processable
6542 ;; There are process-marked articles present.
6543 ;; Save current state.
6544 (gnus-summary-save-process-mark)
6545 ;; Return the list.
6546 (reverse gnus-newsgroup-processable))
6547 (t
6548 ;; Just return the current article.
6549 (list (gnus-summary-article-number))))))
6550
6551(defmacro gnus-summary-iterate (arg &rest forms)
6552 "Iterate over the process/prefixed articles and do FORMS.
6553ARG is the interactive prefix given to the command. FORMS will be
6554executed with point over the summary line of the articles."
6555 (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6556 `(let ((,articles (gnus-summary-work-articles ,arg)))
6557 (while ,articles
6558 (gnus-summary-goto-subject (car ,articles))
16409b0b
GM
6559 ,@forms
6560 (pop ,articles)))))
6748645f
LMI
6561
6562(put 'gnus-summary-iterate 'lisp-indent-function 1)
6563(put 'gnus-summary-iterate 'edebug-form-spec '(form body))
eec82323
LMI
6564
6565(defun gnus-summary-save-process-mark ()
6566 "Push the current set of process marked articles on the stack."
6567 (interactive)
6568 (push (copy-sequence gnus-newsgroup-processable)
6569 gnus-newsgroup-process-stack))
6570
6571(defun gnus-summary-kill-process-mark ()
6572 "Push the current set of process marked articles on the stack and unmark."
6573 (interactive)
6574 (gnus-summary-save-process-mark)
6575 (gnus-summary-unmark-all-processable))
6576
6577(defun gnus-summary-yank-process-mark ()
6578 "Pop the last process mark state off the stack and restore it."
6579 (interactive)
6580 (unless gnus-newsgroup-process-stack
6581 (error "Empty mark stack"))
6582 (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6583
6584(defun gnus-summary-process-mark-set (set)
6585 "Make SET into the current process marked articles."
6586 (gnus-summary-unmark-all-processable)
01c52d31 6587 (mapc 'gnus-summary-set-process-mark set))
eec82323
LMI
6588
6589;;; Searching and stuff
6590
6591(defun gnus-summary-search-group (&optional backward use-level)
6592 "Search for next unread newsgroup.
6593If optional argument BACKWARD is non-nil, search backward instead."
c7a91ce1 6594 (with-current-buffer gnus-group-buffer
eec82323
LMI
6595 (when (gnus-group-search-forward
6596 backward nil (if use-level (gnus-group-group-level) nil))
6597 (gnus-group-group-name))))
6598
6599(defun gnus-summary-best-group (&optional exclude-group)
6600 "Find the name of the best unread group.
6601If EXCLUDE-GROUP, do not go to this group."
01c52d31 6602 (with-current-buffer gnus-group-buffer
eec82323
LMI
6603 (save-excursion
6604 (gnus-group-best-unread-group exclude-group))))
6605
23f87bed
MB
6606(defun gnus-summary-find-next (&optional unread article backward)
6607 (if backward
6608 (gnus-summary-find-prev unread article)
eec82323
LMI
6609 (let* ((dummy (gnus-summary-article-intangible-p))
6610 (article (or article (gnus-summary-article-number)))
23f87bed 6611 (data (gnus-data-find-list article))
eec82323
LMI
6612 result)
6613 (when (and (not dummy)
6614 (or (not gnus-summary-check-current)
6615 (not unread)
23f87bed
MB
6616 (not (gnus-data-unread-p (car data)))))
6617 (setq data (cdr data)))
eec82323
LMI
6618 (when (setq result
6619 (if unread
6620 (progn
23f87bed
MB
6621 (while data
6622 (unless (memq (gnus-data-number (car data))
6623 (cond
6624 ((eq gnus-auto-goto-ignores
6625 'always-undownloaded)
6626 gnus-newsgroup-undownloaded)
6627 (gnus-plugged
6628 nil)
6629 ((eq gnus-auto-goto-ignores
6630 'unfetched)
6631 gnus-newsgroup-unfetched)
6632 ((eq gnus-auto-goto-ignores
6633 'undownloaded)
6634 gnus-newsgroup-undownloaded)))
6635 (when (gnus-data-unread-p (car data))
6636 (setq result (car data)
6637 data nil)))
6638 (setq data (cdr data)))
eec82323 6639 result)
23f87bed 6640 (car data)))
eec82323
LMI
6641 (goto-char (gnus-data-pos result))
6642 (gnus-data-number result)))))
6643
6644(defun gnus-summary-find-prev (&optional unread article)
6645 (let* ((eobp (eobp))
6646 (article (or article (gnus-summary-article-number)))
23f87bed 6647 (data (gnus-data-find-list article (gnus-data-list 'rev)))
eec82323
LMI
6648 result)
6649 (when (and (not eobp)
6650 (or (not gnus-summary-check-current)
6651 (not unread)
23f87bed
MB
6652 (not (gnus-data-unread-p (car data)))))
6653 (setq data (cdr data)))
eec82323
LMI
6654 (when (setq result
6655 (if unread
6656 (progn
23f87bed
MB
6657 (while data
6658 (unless (memq (gnus-data-number (car data))
6659 (cond
6660 ((eq gnus-auto-goto-ignores
6661 'always-undownloaded)
6662 gnus-newsgroup-undownloaded)
6663 (gnus-plugged
6664 nil)
6665 ((eq gnus-auto-goto-ignores
6666 'unfetched)
6667 gnus-newsgroup-unfetched)
6668 ((eq gnus-auto-goto-ignores
6669 'undownloaded)
6670 gnus-newsgroup-undownloaded)))
6671 (when (gnus-data-unread-p (car data))
6672 (setq result (car data)
6673 data nil)))
6674 (setq data (cdr data)))
eec82323 6675 result)
23f87bed 6676 (car data)))
eec82323
LMI
6677 (goto-char (gnus-data-pos result))
6678 (gnus-data-number result))))
6679
6680(defun gnus-summary-find-subject (subject &optional unread backward article)
6681 (let* ((simp-subject (gnus-simplify-subject-fully subject))
6682 (article (or article (gnus-summary-article-number)))
6683 (articles (gnus-data-list backward))
6684 (arts (gnus-data-find-list article articles))
6685 result)
6686 (when (or (not gnus-summary-check-current)
6687 (not unread)
6688 (not (gnus-data-unread-p (car arts))))
6689 (setq arts (cdr arts)))
6690 (while arts
6691 (and (or (not unread)
6692 (gnus-data-unread-p (car arts)))
6693 (vectorp (gnus-data-header (car arts)))
6694 (gnus-subject-equal
6695 simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6696 (setq result (car arts)
6697 arts nil))
6698 (setq arts (cdr arts)))
6699 (and result
6700 (goto-char (gnus-data-pos result))
6701 (gnus-data-number result))))
6702
6703(defun gnus-summary-search-forward (&optional unread subject backward)
6704 "Search forward for an article.
6705If UNREAD, look for unread articles. If SUBJECT, look for
6706articles with that subject. If BACKWARD, search backward instead."
6707 (cond (subject (gnus-summary-find-subject subject unread backward))
6708 (backward (gnus-summary-find-prev unread))
6709 (t (gnus-summary-find-next unread))))
6710
6711(defun gnus-recenter (&optional n)
6712 "Center point in window and redisplay frame.
6713Also do horizontal recentering."
6714 (interactive "P")
6715 (when (and gnus-auto-center-summary
6716 (not (eq gnus-auto-center-summary 'vertical)))
6717 (gnus-horizontal-recenter))
5aa75bd8
JL
6718 (if (fboundp 'recenter-top-bottom)
6719 (recenter-top-bottom n)
6720 (recenter n)))
6721
6722(put 'gnus-recenter 'isearch-scroll t)
eec82323 6723
7b47345b
AS
6724(defun gnus-forward-line-ignore-invisible (n)
6725 "Move N lines forward (backward if N is negative).
6726Like forward-line, but skip over (and don't count) invisible lines."
6727 (let (done)
6728 (while (and (> n 0) (not done))
6729 ;; If the following character is currently invisible,
6730 ;; skip all characters with that same `invisible' property value.
770d9a1f
KY
6731 (while (gnus-invisible-p (point))
6732 (goto-char (gnus-next-char-property-change (point))))
7b47345b
AS
6733 (forward-line 1)
6734 (if (eobp)
6735 (setq done t)
6736 (setq n (1- n))))
6737 (while (and (< n 0) (not done))
6738 (forward-line -1)
6739 (if (bobp) (setq done t)
6740 (setq n (1+ n))
770d9a1f
KY
6741 (while (and (not (bobp)) (gnus-invisible-p (1- (point))))
6742 (goto-char (gnus-previous-char-property-change (point))))))))
6743
eec82323
LMI
6744(defun gnus-summary-recenter ()
6745 "Center point in the summary window.
6746If `gnus-auto-center-summary' is nil, or the article buffer isn't
6747displayed, no centering will be performed."
6748 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6749 ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
16409b0b 6750 (interactive)
23f87bed
MB
6751 ;; The user has to want it.
6752 (when gnus-auto-center-summary
6753 (let* ((top (cond ((< (window-height) 4) 0)
6754 ((< (window-height) 7) 1)
6755 (t (if (numberp gnus-auto-center-summary)
6756 gnus-auto-center-summary
01c52d31 6757 (/ (1- (window-height)) 2)))))
23f87bed 6758 (height (1- (window-height)))
7b47345b
AS
6759 (bottom (save-excursion
6760 (goto-char (point-max))
6761 (gnus-forward-line-ignore-invisible (- height))
6762 (point)))
23f87bed 6763 (window (get-buffer-window (current-buffer))))
eec82323
LMI
6764 (when (get-buffer-window gnus-article-buffer)
6765 ;; Only do recentering when the article buffer is displayed,
6766 ;; Set the window start to either `bottom', which is the biggest
6767 ;; possible valid number, or the second line from the top,
6768 ;; whichever is the least.
7b47345b
AS
6769 (let ((top-pos (save-excursion
6770 (gnus-forward-line-ignore-invisible (- top))
6771 (point))))
db7ebd73
MB
6772 (if (> bottom top-pos)
6773 ;; Keep the second line from the top visible
01c52d31 6774 (set-window-start window top-pos)
db7ebd73
MB
6775 ;; Try to keep the bottom line visible; if it's partially
6776 ;; obscured, either scroll one more line to make it fully
6777 ;; visible, or revert to using TOP-POS.
6778 (save-excursion
6779 (goto-char (point-max))
7b47345b 6780 (gnus-forward-line-ignore-invisible -1)
db7ebd73
MB
6781 (let ((last-line-start (point)))
6782 (goto-char bottom)
6783 (set-window-start window (point) t)
6784 (when (not (pos-visible-in-window-p last-line-start window))
7b47345b 6785 (gnus-forward-line-ignore-invisible 1)
db7ebd73 6786 (set-window-start window (min (point) top-pos) t)))))))
eec82323
LMI
6787 ;; Do horizontal recentering while we're at it.
6788 (when (and (get-buffer-window (current-buffer) t)
6789 (not (eq gnus-auto-center-summary 'vertical)))
6790 (let ((selected (selected-window)))
6791 (select-window (get-buffer-window (current-buffer) t))
6792 (gnus-summary-position-point)
6793 (gnus-horizontal-recenter)
6794 (select-window selected))))))
6795
6796(defun gnus-summary-jump-to-group (newsgroup)
6797 "Move point to NEWSGROUP in group mode buffer."
6798 ;; Keep update point of group mode buffer if visible.
6799 (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6800 (save-window-excursion
6801 ;; Take care of tree window mode.
6802 (when (get-buffer-window gnus-group-buffer)
6803 (pop-to-buffer gnus-group-buffer))
6804 (gnus-group-jump-to-group newsgroup))
6805 (save-excursion
6806 ;; Take care of tree window mode.
c7a91ce1 6807 (if (get-buffer-window gnus-group-buffer 0)
eec82323
LMI
6808 (pop-to-buffer gnus-group-buffer)
6809 (set-buffer gnus-group-buffer))
6810 (gnus-group-jump-to-group newsgroup))))
6811
6812;; This function returns a list of article numbers based on the
6813;; difference between the ranges of read articles in this group and
6814;; the range of active articles.
6815(defun gnus-list-of-unread-articles (group)
6816 (let* ((read (gnus-info-read (gnus-get-info group)))
6817 (active (or (gnus-active group) (gnus-activate-group group)))
01c52d31
MB
6818 (last (or (cdr active)
6819 (error "Group %s couldn't be activated " group)))
4b70e299
MB
6820 (bottom (if gnus-newsgroup-maximum-articles
6821 (max (car active)
6822 (- last gnus-newsgroup-maximum-articles -1))
11abff8e 6823 (car active)))
eec82323
LMI
6824 first nlast unread)
6825 ;; If none are read, then all are unread.
6826 (if (not read)
11abff8e 6827 (setq first bottom)
eec82323
LMI
6828 ;; If the range of read articles is a single range, then the
6829 ;; first unread article is the article after the last read
6830 ;; article. Sounds logical, doesn't it?
16409b0b 6831 (if (and (not (listp (cdr read)))
11abff8e 6832 (or (< (car read) bottom)
16409b0b
GM
6833 (progn (setq read (list read))
6834 nil)))
11abff8e 6835 (setq first (max bottom (1+ (cdr read))))
eec82323
LMI
6836 ;; `read' is a list of ranges.
6837 (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6838 (caar read)))
6839 1)
11abff8e 6840 (setq first bottom))
eec82323
LMI
6841 (while read
6842 (when first
6843 (while (< first nlast)
54506618
MB
6844 (setq unread (cons first unread)
6845 first (1+ first))))
eec82323
LMI
6846 (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6847 (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6848 (setq read (cdr read)))))
6849 ;; And add the last unread articles.
6850 (while (<= first last)
54506618
MB
6851 (setq unread (cons first unread)
6852 first (1+ first)))
eec82323 6853 ;; Return the list of unread articles.
6748645f 6854 (delq 0 (nreverse unread))))
eec82323
LMI
6855
6856(defun gnus-list-of-read-articles (group)
6857 "Return a list of unread, unticked and non-dormant articles."
6858 (let* ((info (gnus-get-info group))
6859 (marked (gnus-info-marks info))
6860 (active (gnus-active group)))
6861 (and info active
23f87bed
MB
6862 (gnus-list-range-difference
6863 (gnus-list-range-difference
6864 (gnus-sorted-complement
11abff8e 6865 (gnus-uncompress-range
4b70e299 6866 (if gnus-newsgroup-maximum-articles
11abff8e 6867 (cons (max (car active)
4b70e299
MB
6868 (- (cdr active)
6869 gnus-newsgroup-maximum-articles
6870 -1))
11abff8e
MB
6871 (cdr active))
6872 active))
23f87bed
MB
6873 (gnus-list-of-unread-articles group))
6874 (cdr (assq 'dormant marked)))
6875 (cdr (assq 'tick marked))))))
eec82323 6876
54506618
MB
6877;; This function returns a sequence of article numbers based on the
6878;; difference between the ranges of read articles in this group and
6879;; the range of active articles.
6880(defun gnus-sequence-of-unread-articles (group)
6881 (let* ((read (gnus-info-read (gnus-get-info group)))
6882 (active (or (gnus-active group) (gnus-activate-group group)))
6883 (last (cdr active))
4b70e299
MB
6884 (bottom (if gnus-newsgroup-maximum-articles
6885 (max (car active)
6886 (- last gnus-newsgroup-maximum-articles -1))
11abff8e 6887 (car active)))
54506618
MB
6888 first nlast unread)
6889 ;; If none are read, then all are unread.
6890 (if (not read)
11abff8e 6891 (setq first bottom)
54506618
MB
6892 ;; If the range of read articles is a single range, then the
6893 ;; first unread article is the article after the last read
6894 ;; article. Sounds logical, doesn't it?
6895 (if (and (not (listp (cdr read)))
11abff8e 6896 (or (< (car read) bottom)
54506618
MB
6897 (progn (setq read (list read))
6898 nil)))
11abff8e 6899 (setq first (max bottom (1+ (cdr read))))
54506618
MB
6900 ;; `read' is a list of ranges.
6901 (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6902 (caar read)))
6903 1)
11abff8e 6904 (setq first bottom))
54506618
MB
6905 (while read
6906 (when first
6907 (push (cons first nlast) unread))
6908 (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6909 (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6910 (setq read (cdr read)))))
6911 ;; And add the last unread articles.
ba0226dd
MB
6912 (cond ((not (and first last))
6913 nil)
6914 ((< first last)
6915 (push (cons first last) unread))
6916 ((= first last)
6917 (push first unread)))
54506618
MB
6918 ;; Return the sequence of unread articles.
6919 (delq 0 (nreverse unread))))
6920
eec82323
LMI
6921;; Various summary commands
6922
6748645f
LMI
6923(defun gnus-summary-select-article-buffer ()
6924 "Reconfigure windows to show article buffer."
6925 (interactive)
6926 (if (not (gnus-buffer-live-p gnus-article-buffer))
6927 (error "There is no article buffer for this summary buffer")
6928 (gnus-configure-windows 'article)
6929 (select-window (get-buffer-window gnus-article-buffer))))
6930
eec82323
LMI
6931(defun gnus-summary-universal-argument (arg)
6932 "Perform any operation on all articles that are process/prefixed."
6933 (interactive "P")
eec82323
LMI
6934 (let ((articles (gnus-summary-work-articles arg))
6935 func article)
6936 (if (eq
6937 (setq
6938 func
6939 (key-binding
6940 (read-key-sequence
6941 (substitute-command-keys
16409b0b 6942 "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
eec82323
LMI
6943 'undefined)
6944 (gnus-error 1 "Undefined key")
6945 (save-excursion
6946 (while articles
6947 (gnus-summary-goto-subject (setq article (pop articles)))
6948 (let (gnus-newsgroup-processable)
6949 (command-execute func))
6950 (gnus-summary-remove-process-mark article)))))
6951 (gnus-summary-position-point))
6952
6953(defun gnus-summary-toggle-truncation (&optional arg)
6954 "Toggle truncation of summary lines.
23f87bed 6955With ARG, turn line truncation on if ARG is positive."
eec82323
LMI
6956 (interactive "P")
6957 (setq truncate-lines
6958 (if (null arg) (not truncate-lines)
6959 (> (prefix-numeric-value arg) 0)))
6960 (redraw-display))
6961
23f87bed
MB
6962(defun gnus-summary-find-for-reselect ()
6963 "Return the number of an article to stay on across a reselect.
6964The current article is considered, then following articles, then previous
6965articles. An article is sought which is not cancelled and isn't a temporary
6966insertion from another group. If there's no such then return a dummy 0."
6967 (let (found)
6968 (dolist (rev '(nil t))
6969 (unless found ; don't demand the reverse list if we don't need it
6970 (let ((data (gnus-data-find-list
6971 (gnus-summary-article-number) (gnus-data-list rev))))
6972 (while (and data (not found))
6973 (if (and (< 0 (gnus-data-number (car data)))
6974 (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6975 (setq found (gnus-data-number (car data))))
6976 (setq data (cdr data))))))
6977 (or found 0)))
6978
eec82323
LMI
6979(defun gnus-summary-reselect-current-group (&optional all rescan)
6980 "Exit and then reselect the current newsgroup.
6981The prefix argument ALL means to select all articles."
6982 (interactive "P")
eec82323
LMI
6983 (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6984 (error "Ephemeral groups can't be reselected"))
23f87bed 6985 (let ((current-subject (gnus-summary-find-for-reselect))
eec82323
LMI
6986 (group gnus-newsgroup-name))
6987 (setq gnus-newsgroup-begin nil)
23f87bed 6988 (gnus-summary-exit nil 'leave-hidden)
eec82323
LMI
6989 ;; We have to adjust the point of group mode buffer because
6990 ;; point was moved to the next unread newsgroup by exiting.
6991 (gnus-summary-jump-to-group group)
6992 (when rescan
6993 (save-excursion
6994 (gnus-group-get-new-news-this-group 1)))
6995 (gnus-group-read-group all t)
6996 (gnus-summary-goto-subject current-subject nil t)))
6997
6998(defun gnus-summary-rescan-group (&optional all)
6999 "Exit the newsgroup, ask for new articles, and select the newsgroup."
7000 (interactive "P")
7001 (gnus-summary-reselect-current-group all t))
7002
7003(defun gnus-summary-update-info (&optional non-destructive)
7004 (save-excursion
7005 (let ((group gnus-newsgroup-name))
6748645f
LMI
7006 (when group
7007 (when gnus-newsgroup-kill-headers
7008 (setq gnus-newsgroup-killed
7009 (gnus-compress-sequence
23f87bed
MB
7010 (gnus-sorted-union
7011 (gnus-list-range-intersection
7012 gnus-newsgroup-unselected gnus-newsgroup-killed)
7013 gnus-newsgroup-unreads)
6748645f
LMI
7014 t)))
7015 (unless (listp (cdr gnus-newsgroup-killed))
7016 (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
7017 (let ((headers gnus-newsgroup-headers))
7018 ;; Set the new ranges of read articles.
01c52d31 7019 (with-current-buffer gnus-group-buffer
6748645f
LMI
7020 (gnus-undo-force-boundary))
7021 (gnus-update-read-articles
23f87bed
MB
7022 group (gnus-sorted-union
7023 gnus-newsgroup-unreads gnus-newsgroup-unselected))
6748645f
LMI
7024 ;; Set the current article marks.
7025 (let ((gnus-newsgroup-scored
7026 (if (and (not gnus-save-score)
7027 (not non-destructive))
7028 nil
7029 gnus-newsgroup-scored)))
7030 (save-excursion
7031 (gnus-update-marks)))
7032 ;; Do the cross-ref thing.
7033 (when gnus-use-cross-reference
7034 (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
7035 ;; Do not switch windows but change the buffer to work.
a8151ef7 7036 (set-buffer gnus-group-buffer)
6748645f
LMI
7037 (unless (gnus-ephemeral-group-p group)
7038 (gnus-group-update-group group)))))))
eec82323
LMI
7039
7040(defun gnus-summary-save-newsrc (&optional force)
7041 "Save the current number of read/marked articles in the dribble buffer.
7042The dribble buffer will then be saved.
7043If FORCE (the prefix), also save the .newsrc file(s)."
7044 (interactive "P")
7045 (gnus-summary-update-info t)
7046 (if force
7047 (gnus-save-newsrc-file)
7048 (gnus-dribble-save)))
7049
704f1663
GM
7050(declare-function gnus-cache-write-active "gnus-cache" (&optional force))
7051
23f87bed 7052(defun gnus-summary-exit (&optional temporary leave-hidden)
eec82323 7053 "Exit reading current newsgroup, and then return to group selection mode.
16409b0b 7054`gnus-exit-group-hook' is called with no arguments if that value is non-nil."
eec82323
LMI
7055 (interactive)
7056 (gnus-set-global-variables)
16409b0b 7057 (when (gnus-buffer-live-p gnus-article-buffer)
c7a91ce1 7058 (with-current-buffer gnus-article-buffer
16409b0b
GM
7059 (mm-destroy-parts gnus-article-mime-handles)
7060 ;; Set it to nil for safety reason.
7061 (setq gnus-article-mime-handle-alist nil)
7062 (setq gnus-article-mime-handles nil)))
eec82323 7063 (gnus-kill-save-kill-buffer)
6748645f 7064 (gnus-async-halt-prefetch)
eec82323
LMI
7065 (let* ((group gnus-newsgroup-name)
7066 (quit-config (gnus-group-quit-config gnus-newsgroup-name))
23f87bed 7067 (gnus-group-is-exiting-p t)
eec82323 7068 (mode major-mode)
23f87bed 7069 (group-point nil)
eec82323 7070 (buf (current-buffer)))
16409b0b
GM
7071 (unless quit-config
7072 ;; Do adaptive scoring, and possibly save score files.
7073 (when gnus-newsgroup-adaptive
7074 (gnus-score-adaptive))
7075 (when gnus-use-scoring
7076 (gnus-score-save)))
6748645f 7077 (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
eec82323
LMI
7078 ;; If we have several article buffers, we kill them at exit.
7079 (unless gnus-single-article-buffer
01c52d31
MB
7080 (when (gnus-buffer-live-p gnus-article-buffer)
7081 (with-current-buffer gnus-article-buffer
7082 ;; Don't kill sticky article buffers
7083 (unless (eq major-mode 'gnus-sticky-article-mode)
7084 (gnus-kill-buffer gnus-article-buffer)
7085 (setq gnus-article-current nil))))
7086 (gnus-kill-buffer gnus-original-article-buffer))
eec82323
LMI
7087 (when gnus-use-cache
7088 (gnus-cache-possibly-remove-articles)
7089 (gnus-cache-save-buffers))
7090 (gnus-async-prefetch-remove-group group)
7091 (when gnus-suppress-duplicates
7092 (gnus-dup-enter-articles))
7093 (when gnus-use-trees
7094 (gnus-tree-close group))
16409b0b
GM
7095 (when gnus-use-cache
7096 (gnus-cache-write-active))
6748645f
LMI
7097 ;; Remove entries for this group.
7098 (nnmail-purge-split-history (gnus-group-real-name group))
eec82323
LMI
7099 ;; Make all changes in this group permanent.
7100 (unless quit-config
6748645f 7101 (gnus-run-hooks 'gnus-exit-group-hook)
16409b0b 7102 (gnus-summary-update-info))
eec82323
LMI
7103 (gnus-close-group group)
7104 ;; Make sure where we were, and go to next newsgroup.
7105 (set-buffer gnus-group-buffer)
7106 (unless quit-config
7107 (gnus-group-jump-to-group group))
6748645f
LMI
7108 (gnus-run-hooks 'gnus-summary-exit-hook)
7109 (unless (or quit-config
01c52d31 7110 (not gnus-summary-next-group-on-exit)
6748645f
LMI
7111 ;; If this group has disappeared from the summary
7112 ;; buffer, don't skip forwards.
7113 (not (string= group (gnus-group-group-name))))
eec82323 7114 (gnus-group-next-unread-group 1))
a8151ef7 7115 (setq group-point (point))
eec82323
LMI
7116 (if temporary
7117 nil ;Nothing to do.
eec82323
LMI
7118 (set-buffer buf)
7119 (if (not gnus-kill-summary-on-exit)
23f87bed
MB
7120 (progn
7121 (gnus-deaden-summary)
7122 (setq mode nil))
eec82323
LMI
7123 ;; We set all buffer-local variables to nil. It is unclear why
7124 ;; this is needed, but if we don't, buffer-local variables are
7125 ;; not garbage-collected, it seems. This would the lead to en
7126 ;; ever-growing Emacs.
7127 (gnus-summary-clear-local-variables)
23f87bed
MB
7128 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7129 (gnus-summary-clear-local-variables))
eec82323
LMI
7130 (when (get-buffer gnus-article-buffer)
7131 (bury-buffer gnus-article-buffer))
eec82323
LMI
7132 ;; Return to group mode buffer.
7133 (when (eq mode 'gnus-summary-mode)
7134 (gnus-kill-buffer buf)))
7135 (setq gnus-current-select-method gnus-select-method)
d61c212b
SM
7136 (set-buffer gnus-group-buffer)
7137 (if quit-config
7138 (gnus-handle-ephemeral-exit quit-config)
4e90f2b9
SM
7139 (goto-char group-point)
7140 ;; If gnus-group-buffer is already displayed, make sure we also move
7141 ;; the cursor in the window that displays it.
7142 (let ((win (get-buffer-window (current-buffer) 0)))
7143 (if win (set-window-point win (point))))
d61c212b 7144 (unless leave-hidden
4e90f2b9 7145 (gnus-configure-windows 'group 'force)))
6748645f 7146 ;; Clear the current group name.
eec82323
LMI
7147 (unless quit-config
7148 (setq gnus-newsgroup-name nil)))))
7149
7150(defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7151(defun gnus-summary-exit-no-update (&optional no-questions)
7152 "Quit reading current newsgroup without updating read article info."
7153 (interactive)
eec82323 7154 (let* ((group gnus-newsgroup-name)
23f87bed
MB
7155 (gnus-group-is-exiting-p t)
7156 (gnus-group-is-exiting-without-update-p t)
eec82323
LMI
7157 (quit-config (gnus-group-quit-config group)))
7158 (when (or no-questions
7159 gnus-expert-user
7160 (gnus-y-or-n-p "Discard changes to this group and exit? "))
6748645f 7161 (gnus-async-halt-prefetch)
23f87bed 7162 (run-hooks 'gnus-summary-prepare-exit-hook)
16409b0b 7163 (when (gnus-buffer-live-p gnus-article-buffer)
c7a91ce1 7164 (with-current-buffer gnus-article-buffer
16409b0b
GM
7165 (mm-destroy-parts gnus-article-mime-handles)
7166 ;; Set it to nil for safety reason.
7167 (setq gnus-article-mime-handle-alist nil)
7168 (setq gnus-article-mime-handles nil)))
eec82323
LMI
7169 ;; If we have several article buffers, we kill them at exit.
7170 (unless gnus-single-article-buffer
7171 (gnus-kill-buffer gnus-article-buffer)
7172 (gnus-kill-buffer gnus-original-article-buffer)
7173 (setq gnus-article-current nil))
7174 (if (not gnus-kill-summary-on-exit)
7175 (gnus-deaden-summary)
7176 (gnus-close-group group)
7177 (gnus-summary-clear-local-variables)
23f87bed
MB
7178 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7179 (gnus-summary-clear-local-variables))
7180 (gnus-kill-buffer gnus-summary-buffer))
eec82323
LMI
7181 (unless gnus-single-article-buffer
7182 (setq gnus-article-current nil))
7183 (when gnus-use-trees
7184 (gnus-tree-close group))
7185 (gnus-async-prefetch-remove-group group)
7186 (when (get-buffer gnus-article-buffer)
7187 (bury-buffer gnus-article-buffer))
7188 ;; Return to the group buffer.
7189 (gnus-configure-windows 'group 'force)
7190 ;; Clear the current group name.
7191 (setq gnus-newsgroup-name nil)
23f87bed
MB
7192 (unless (gnus-ephemeral-group-p group)
7193 (gnus-group-update-group group))
eec82323
LMI
7194 (when (equal (gnus-group-group-name) group)
7195 (gnus-group-next-unread-group 1))
7196 (when quit-config
23f87bed 7197 (gnus-handle-ephemeral-exit quit-config)))))
eec82323
LMI
7198
7199(defun gnus-handle-ephemeral-exit (quit-config)
6748645f
LMI
7200 "Handle movement when leaving an ephemeral group.
7201The state which existed when entering the ephemeral is reset."
eec82323
LMI
7202 (if (not (buffer-name (car quit-config)))
7203 (gnus-configure-windows 'group 'force)
7204 (set-buffer (car quit-config))
7205 (cond ((eq major-mode 'gnus-summary-mode)
23f87bed
MB
7206 (gnus-set-global-variables))
7207 ((eq major-mode 'gnus-article-mode)
c7a91ce1 7208 (save-current-buffer
23f87bed
MB
7209 ;; The `gnus-summary-buffer' variable may point
7210 ;; to the old summary buffer when using a single
7211 ;; article buffer.
7212 (unless (gnus-buffer-live-p gnus-summary-buffer)
7213 (set-buffer gnus-group-buffer))
7214 (set-buffer gnus-summary-buffer)
7215 (gnus-set-global-variables))))
eec82323 7216 (if (or (eq (cdr quit-config) 'article)
23f87bed 7217 (eq (cdr quit-config) 'pick))
01c52d31
MB
7218 (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7219 (gnus-configure-windows 'pick 'force)
7220 (gnus-configure-windows (cdr quit-config) 'force))
eec82323
LMI
7221 (gnus-configure-windows (cdr quit-config) 'force))
7222 (when (eq major-mode 'gnus-summary-mode)
01c52d31
MB
7223 (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7224 next-unread-noselect))
7225 (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7226 'next-noselect)
7227 (gnus-summary-next-subject 1 nil t))
7228 ((eq gnus-auto-select-on-ephemeral-exit
7229 'next-unread-noselect)
7230 (gnus-summary-next-subject 1 t t))))
7231 ;; Hide the article buffer which displays the article different
7232 ;; from the one that the cursor points to in the summary buffer.
7233 (gnus-configure-windows 'summary 'force))
7234 (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7235 (gnus-summary-next-subject 1))
7236 ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7237 (gnus-summary-next-subject 1 t))))
eec82323
LMI
7238 (gnus-summary-recenter)
7239 (gnus-summary-position-point))))
7240
7241;;; Dead summaries.
7242
bbf52f1e
SM
7243(defvar gnus-dead-summary-mode-map
7244 (let ((map (make-keymap)))
7245 (suppress-keymap map)
7246 (substitute-key-definition 'undefined 'gnus-summary-wake-up-the-dead map)
7247 (dolist (key '("\C-d" "\r" "\177" [delete]))
7248 (define-key map key 'gnus-summary-wake-up-the-dead))
7249 (dolist (key '("q" "Q"))
7250 (define-key map key 'bury-buffer))
7251 map))
7252
7253(define-minor-mode gnus-dead-summary-mode
eec82323 7254 "Minor mode for Gnus summary buffers."
bbf52f1e
SM
7255 :lighter " Dead" :keymap gnus-dead-summary-mode-map
7256 (unless (derived-mode-p 'gnus-summary-mode)
7257 (setq gnus-dead-summary-mode nil)))
eec82323
LMI
7258
7259(defun gnus-deaden-summary ()
7260 "Make the current summary buffer into a dead summary buffer."
7261 ;; Kill any previous dead summary buffer.
7262 (when (and gnus-dead-summary
7263 (buffer-name gnus-dead-summary))
01c52d31 7264 (with-current-buffer gnus-dead-summary
eec82323
LMI
7265 (when gnus-dead-summary-mode
7266 (kill-buffer (current-buffer)))))
7267 ;; Make this the current dead summary.
7268 (setq gnus-dead-summary (current-buffer))
7269 (gnus-dead-summary-mode 1)
7270 (let ((name (buffer-name)))
7271 (when (string-match "Summary" name)
7272 (rename-buffer
7273 (concat (substring name 0 (match-beginning 0)) "Dead "
7274 (substring name (match-beginning 0)))
16409b0b
GM
7275 t)
7276 (bury-buffer))))
eec82323
LMI
7277
7278(defun gnus-kill-or-deaden-summary (buffer)
7279 "Kill or deaden the summary BUFFER."
6748645f
LMI
7280 (save-excursion
7281 (when (and (buffer-name buffer)
7282 (not gnus-single-article-buffer))
01c52d31 7283 (with-current-buffer buffer
6748645f
LMI
7284 (gnus-kill-buffer gnus-article-buffer)
7285 (gnus-kill-buffer gnus-original-article-buffer)))
23f87bed
MB
7286 (cond
7287 ;; Kill the buffer.
7288 (gnus-kill-summary-on-exit
7289 (when (and gnus-use-trees
7290 (gnus-buffer-exists-p buffer))
c7a91ce1 7291 (with-current-buffer buffer
23f87bed
MB
7292 (gnus-tree-close gnus-newsgroup-name)))
7293 (gnus-kill-buffer buffer))
7294 ;; Deaden the buffer.
7295 ((gnus-buffer-exists-p buffer)
c7a91ce1 7296 (with-current-buffer buffer
23f87bed 7297 (gnus-deaden-summary))))))
eec82323
LMI
7298
7299(defun gnus-summary-wake-up-the-dead (&rest args)
7300 "Wake up the dead summary buffer."
7301 (interactive)
7302 (gnus-dead-summary-mode -1)
7303 (let ((name (buffer-name)))
7304 (when (string-match "Dead " name)
7305 (rename-buffer
7306 (concat (substring name 0 (match-beginning 0))
7307 (substring name (match-end 0)))
7308 t)))
7309 (gnus-message 3 "This dead summary is now alive again"))
7310
7311;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7312(defun gnus-summary-fetch-faq (&optional faq-dir)
7313 "Fetch the FAQ for the current group.
7314If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7315in."
7316 (interactive
7317 (list
7318 (when current-prefix-arg
7319 (completing-read
8f688cb0 7320 "FAQ dir: " (and (listp gnus-group-faq-directory)
01c52d31 7321 (mapcar 'list
a8151ef7 7322 gnus-group-faq-directory))))))
eec82323
LMI
7323 (let (gnus-faq-buffer)
7324 (when (setq gnus-faq-buffer
7325 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7326 (gnus-configure-windows 'summary-faq))))
7327
7328;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7329(defun gnus-summary-describe-group (&optional force)
7330 "Describe the current newsgroup."
7331 (interactive "P")
7332 (gnus-group-describe-group force gnus-newsgroup-name))
7333
7334(defun gnus-summary-describe-briefly ()
7335 "Describe summary mode commands briefly."
7336 (interactive)
16409b0b 7337 (gnus-message 6 (substitute-command-keys "\\<gnus-summary-mode-map>\\[gnus-summary-next-page]:Select \\[gnus-summary-next-unread-article]:Forward \\[gnus-summary-prev-unread-article]:Backward \\[gnus-summary-exit]:Exit \\[gnus-info-find-node]:Run Info \\[gnus-summary-describe-briefly]:This help")))
eec82323
LMI
7338
7339;; Walking around group mode buffer from summary mode.
7340
7341(defun gnus-summary-next-group (&optional no-article target-group backward)
7342 "Exit current newsgroup and then select next unread newsgroup.
7343If prefix argument NO-ARTICLE is non-nil, no article is selected
23f87bed 7344initially. If TARGET-GROUP, go to this group. If BACKWARD, go to
eec82323
LMI
7345previous group instead."
7346 (interactive "P")
eec82323
LMI
7347 ;; Stop pre-fetching.
7348 (gnus-async-halt-prefetch)
7349 (let ((current-group gnus-newsgroup-name)
7350 (current-buffer (current-buffer))
7351 entered)
7352 ;; First we semi-exit this group to update Xrefs and all variables.
7353 ;; We can't do a real exit, because the window conf must remain
7354 ;; the same in case the user is prompted for info, and we don't
7355 ;; want the window conf to change before that...
7356 (gnus-summary-exit t)
7357 (while (not entered)
7358 ;; Then we find what group we are supposed to enter.
7359 (set-buffer gnus-group-buffer)
7360 (gnus-group-jump-to-group current-group)
7361 (setq target-group
7362 (or target-group
7363 (if (eq gnus-keep-same-level 'best)
7364 (gnus-summary-best-group gnus-newsgroup-name)
7365 (gnus-summary-search-group backward gnus-keep-same-level))))
7366 (if (not target-group)
7367 ;; There are no further groups, so we return to the group
7368 ;; buffer.
7369 (progn
7370 (gnus-message 5 "Returning to the group buffer")
7371 (setq entered t)
7372 (when (gnus-buffer-live-p current-buffer)
7373 (set-buffer current-buffer)
7374 (gnus-summary-exit))
6748645f 7375 (gnus-run-hooks 'gnus-group-no-more-groups-hook))
eec82323
LMI
7376 ;; We try to enter the target group.
7377 (gnus-group-jump-to-group target-group)
7378 (let ((unreads (gnus-group-group-unread)))
7379 (if (and (or (eq t unreads)
7380 (and unreads (not (zerop unreads))))
23f87bed
MB
7381 (gnus-summary-read-group
7382 target-group nil no-article
7383 (and (buffer-name current-buffer) current-buffer)
7384 nil backward))
eec82323
LMI
7385 (setq entered t)
7386 (setq current-group target-group
7387 target-group nil)))))))
7388
7389(defun gnus-summary-prev-group (&optional no-article)
7390 "Exit current newsgroup and then select previous unread newsgroup.
7391If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7392 (interactive "P")
7393 (gnus-summary-next-group no-article nil t))
7394
7395;; Walking around summary lines.
7396
23f87bed
MB
7397(defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7398 "Go to the first subject satisfying any non-nil constraint.
7399If UNREAD is non-nil, the article should be unread.
7400If UNDOWNLOADED is non-nil, the article should be undownloaded.
7401If UNSEEN is non-nil, the article should be unseen.
7402Returns the article selected or nil if there are no matching articles."
eec82323 7403 (interactive "P")
23f87bed
MB
7404 (cond
7405 ;; Empty summary.
7406 ((null gnus-newsgroup-data)
7407 (gnus-message 3 "No articles in the group")
7408 nil)
7409 ;; Pick the first article.
7410 ((not (or unread undownloaded unseen))
7411 (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7412 (gnus-data-number (car gnus-newsgroup-data)))
7413 ;; Find the first unread article.
7414 (t
7415 (let ((data gnus-newsgroup-data))
7416 (while (and data
7417 (let ((num (gnus-data-number (car data))))
7418 (or (memq num gnus-newsgroup-unfetched)
7419 (not (or (and unread
7420 (memq num gnus-newsgroup-unreads))
7421 (and undownloaded
7422 (memq num gnus-newsgroup-undownloaded))
7423 (and unseen
7424 (memq num gnus-newsgroup-unseen)))))))
7425 (setq data (cdr data)))
7426 (prog1
7427 (if data
7428 (progn
7429 (goto-char (gnus-data-pos (car data)))
7430 (gnus-data-number (car data)))
7431 (gnus-message 3 "No more%s articles"
7432 (let* ((r (when unread " unread"))
7433 (d (when undownloaded " undownloaded"))
7434 (s (when unseen " unseen"))
7435 (l (delq nil (list r d s))))
7436 (cond ((= 3 (length l))
7437 (concat r "," d ", or" s))
7438 ((= 2 (length l))
7439 (concat (car l) ", or" (cadr l)))
7440 ((= 1 (length l))
7441 (car l))
7442 (t
7443 ""))))
7444 nil
7445 )
7446 (gnus-summary-position-point))))))
eec82323
LMI
7447
7448(defun gnus-summary-next-subject (n &optional unread dont-display)
7449 "Go to next N'th summary line.
7450If N is negative, go to the previous N'th subject line.
7451If UNREAD is non-nil, only unread articles are selected.
7452The difference between N and the actual number of steps taken is
7453returned."
7454 (interactive "p")
7455 (let ((backward (< n 0))
7456 (n (abs n)))
7457 (while (and (> n 0)
7458 (if backward
7459 (gnus-summary-find-prev unread)
7460 (gnus-summary-find-next unread)))
16409b0b
GM
7461 (unless (zerop (setq n (1- n)))
7462 (gnus-summary-show-thread)))
eec82323
LMI
7463 (when (/= 0 n)
7464 (gnus-message 7 "No more%s articles"
7465 (if unread " unread" "")))
7466 (unless dont-display
7467 (gnus-summary-recenter)
7468 (gnus-summary-position-point))
7469 n))
7470
7471(defun gnus-summary-next-unread-subject (n)
7472 "Go to next N'th unread summary line."
7473 (interactive "p")
7474 (gnus-summary-next-subject n t))
7475
7476(defun gnus-summary-prev-subject (n &optional unread)
7477 "Go to previous N'th summary line.
7478If optional argument UNREAD is non-nil, only unread article is selected."
7479 (interactive "p")
7480 (gnus-summary-next-subject (- n) unread))
7481
7482(defun gnus-summary-prev-unread-subject (n)
7483 "Go to previous N'th unread summary line."
7484 (interactive "p")
7485 (gnus-summary-next-subject (- n) t))
7486
23f87bed
MB
7487(defun gnus-summary-goto-subjects (articles)
7488 "Insert the subject header for ARTICLES in the current buffer."
7489 (save-excursion
7490 (dolist (article articles)
7491 (gnus-summary-goto-subject article t)))
7492 (gnus-summary-limit (append articles gnus-newsgroup-limit))
7493 (gnus-summary-position-point))
132cf96d 7494
eec82323 7495(defun gnus-summary-goto-subject (article &optional force silent)
d55fe5bb 7496 "Go to the subject line of ARTICLE.
eec82323
LMI
7497If FORCE, also allow jumping to articles not currently shown."
7498 (interactive "nArticle number: ")
23f87bed
MB
7499 (unless (numberp article)
7500 (error "Article %s is not a number" article))
eec82323
LMI
7501 (let ((b (point))
7502 (data (gnus-data-find article)))
7503 ;; We read in the article if we have to.
7504 (and (not data)
7505 force
6748645f
LMI
7506 (gnus-summary-insert-subject
7507 article
7508 (if (or (numberp force) (vectorp force)) force)
7509 t)
eec82323
LMI
7510 (setq data (gnus-data-find article)))
7511 (goto-char b)
7512 (if (not data)
7513 (progn
7514 (unless silent
7515 (gnus-message 3 "Can't find article %d" article))
7516 nil)
23f87bed
MB
7517 (let ((pt (gnus-data-pos data)))
7518 (goto-char pt)
7519 (gnus-summary-set-article-display-arrow pt))
6748645f 7520 (gnus-summary-position-point)
eec82323
LMI
7521 article)))
7522
7523;; Walking around summary lines with displaying articles.
7524
7525(defun gnus-summary-expand-window (&optional arg)
7526 "Make the summary buffer take up the entire Emacs frame.
7527Given a prefix, will force an `article' buffer configuration."
7528 (interactive "P")
eec82323
LMI
7529 (if arg
7530 (gnus-configure-windows 'article 'force)
7531 (gnus-configure-windows 'summary 'force)))
7532
7533(defun gnus-summary-display-article (article &optional all-header)
7534 "Display ARTICLE in article buffer."
01c52d31
MB
7535 (unless (and (gnus-buffer-live-p gnus-article-buffer)
7536 (with-current-buffer gnus-article-buffer
7537 (eq major-mode 'gnus-article-mode)))
7538 (gnus-article-setup-buffer))
eec82323 7539 (gnus-set-global-variables)
01c52d31
MB
7540 (with-current-buffer gnus-article-buffer
7541 (setq gnus-article-charset gnus-newsgroup-charset)
7542 (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7543 (mm-enable-multibyte))
eec82323
LMI
7544 (if (null article)
7545 nil
7546 (prog1
7547 (if gnus-summary-display-article-function
7548 (funcall gnus-summary-display-article-function article all-header)
7549 (gnus-article-prepare article all-header))
6748645f 7550 (gnus-run-hooks 'gnus-select-article-hook)
eec82323
LMI
7551 (when (and gnus-current-article
7552 (not (zerop gnus-current-article)))
7553 (gnus-summary-goto-subject gnus-current-article))
7554 (gnus-summary-recenter)
7555 (when (and gnus-use-trees gnus-show-threads)
7556 (gnus-possibly-generate-tree article)
7557 (gnus-highlight-selected-tree article))
7558 ;; Successfully display article.
7559 (gnus-article-set-window-start
7560 (cdr (assq article gnus-newsgroup-bookmarks))))))
7561
7562(defun gnus-summary-select-article (&optional all-headers force pseudo article)
7563 "Select the current article.
7564If ALL-HEADERS is non-nil, show all header fields. If FORCE is
7565non-nil, the article will be re-fetched even if it already present in
7566the article buffer. If PSEUDO is non-nil, pseudo-articles will also
7567be displayed."
7568 ;; Make sure we are in the summary buffer to work around bbdb bug.
7569 (unless (eq major-mode 'gnus-summary-mode)
7570 (set-buffer gnus-summary-buffer))
7571 (let ((article (or article (gnus-summary-article-number)))
f0529b5b 7572 (all-headers (not (not all-headers))) ;Must be t or nil.
16409b0b 7573 gnus-summary-display-article-function)
eec82323
LMI
7574 (and (not pseudo)
7575 (gnus-summary-article-pseudo-p article)
a8151ef7 7576 (error "This is a pseudo-article"))
c7a91ce1 7577 (with-current-buffer gnus-summary-buffer
16409b0b
GM
7578 (if (or (and gnus-single-article-buffer
7579 (or (null gnus-current-article)
7580 (null gnus-article-current)
7581 (null (get-buffer gnus-article-buffer))
7582 (not (eq article (cdr gnus-article-current)))
7583 (not (equal (car gnus-article-current)
7584 gnus-newsgroup-name))))
7585 (and (not gnus-single-article-buffer)
7586 (or (null gnus-current-article)
7587 (not (eq gnus-current-article article))))
7588 force)
7589 ;; The requested article is different from the current article.
7590 (progn
16409b0b
GM
7591 (gnus-summary-display-article article all-headers)
7592 (when (gnus-buffer-live-p gnus-article-buffer)
23f87bed 7593 (with-current-buffer gnus-article-buffer
16409b0b 7594 (if (not gnus-article-decoded-p) ;; a local variable
87545352 7595 (mm-disable-multibyte))))
16409b0b
GM
7596 (gnus-article-set-window-start
7597 (cdr (assq article gnus-newsgroup-bookmarks)))
7598 article)
16409b0b 7599 'old))))
eec82323 7600
23f87bed
MB
7601(defun gnus-summary-force-verify-and-decrypt ()
7602 "Display buttons for signed/encrypted parts and verify/decrypt them."
7603 (interactive)
7604 (let ((mm-verify-option 'known)
7605 (mm-decrypt-option 'known)
7606 (gnus-article-emulate-mime t)
7607 (gnus-buttonized-mime-types (append (list "multipart/signed"
7608 "multipart/encrypted")
7609 gnus-buttonized-mime-types)))
7610 (gnus-summary-select-article nil 'force)))
7611
eec82323
LMI
7612(defun gnus-summary-set-current-mark (&optional current-mark)
7613 "Obsolete function."
7614 nil)
7615
7616(defun gnus-summary-next-article (&optional unread subject backward push)
7617 "Select the next article.
7618If UNREAD, only unread articles are selected.
7619If SUBJECT, only articles with SUBJECT are selected.
7620If BACKWARD, the previous article is selected instead of the next."
7621 (interactive "P")
11e95b02
MB
7622 ;; Make sure we are in the summary buffer.
7623 (unless (eq major-mode 'gnus-summary-mode)
7624 (set-buffer gnus-summary-buffer))
eec82323
LMI
7625 (cond
7626 ;; Is there such an article?
7627 ((and (gnus-summary-search-forward unread subject backward)
7628 (or (gnus-summary-display-article (gnus-summary-article-number))
7629 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7630 (gnus-summary-position-point))
7631 ;; If not, we try the first unread, if that is wanted.
7632 ((and subject
7633 gnus-auto-select-same
7634 (gnus-summary-first-unread-article))
7635 (gnus-summary-position-point)
7636 (gnus-message 6 "Wrapped"))
7637 ;; Try to get next/previous article not displayed in this group.
7638 ((and gnus-auto-extend-newsgroup
7639 (not unread) (not subject))
7640 (gnus-summary-goto-article
7641 (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6748645f 7642 nil (count-lines (point-min) (point))))
eec82323
LMI
7643 ;; Go to next/previous group.
7644 (t
7645 (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7646 (gnus-summary-jump-to-group gnus-newsgroup-name))
49e787c9
GM
7647 (let ((cmd (if (featurep 'xemacs)
7648 last-command-char
7649 last-command-event))
eec82323 7650 (point
01c52d31 7651 (with-current-buffer gnus-group-buffer
eec82323
LMI
7652 (point)))
7653 (group
7654 (if (eq gnus-keep-same-level 'best)
7655 (gnus-summary-best-group gnus-newsgroup-name)
7656 (gnus-summary-search-group backward gnus-keep-same-level))))
7657 ;; For some reason, the group window gets selected. We change
7658 ;; it back.
7659 (select-window (get-buffer-window (current-buffer)))
7660 ;; Select next unread newsgroup automagically.
7661 (cond
7662 ((or (not gnus-auto-select-next)
7663 (not cmd))
7664 (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7665 ((or (eq gnus-auto-select-next 'quietly)
7666 (and (eq gnus-auto-select-next 'slightly-quietly)
7667 push)
7668 (and (eq gnus-auto-select-next 'almost-quietly)
7669 (gnus-summary-last-article-p)))
7670 ;; Select quietly.
7671 (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7672 (gnus-summary-exit)
7673 (gnus-message 7 "No more%s articles (%s)..."
7674 (if unread " unread" "")
7675 (if group (concat "selecting " group)
7676 "exiting"))
7677 (gnus-summary-next-group nil group backward)))
7678 (t
7679 (when (gnus-key-press-event-p last-input-event)
7680 (gnus-summary-walk-group-buffer
7681 gnus-newsgroup-name cmd unread backward point))))))))
7682
7683(defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7684 (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7685 (?\C-p (gnus-group-prev-unread-group 1))))
7686 (cursor-in-echo-area t)
23f87bed 7687 keve key group ended prompt)
c7a91ce1 7688 (with-current-buffer gnus-group-buffer
eec82323
LMI
7689 (goto-char start)
7690 (setq group
7691 (if (eq gnus-keep-same-level 'best)
7692 (gnus-summary-best-group gnus-newsgroup-name)
7693 (gnus-summary-search-group backward gnus-keep-same-level))))
7694 (while (not ended)
23f87bed
MB
7695 (setq prompt
7696 (format
7697 "No more%s articles%s " (if unread " unread" "")
7698 (if (and group
7699 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7700 (format " (Type %s for %s [%s])"
91472578
MB
7701 (single-key-description cmd)
7702 (gnus-group-decoded-name group)
01c52d31 7703 (gnus-group-unread group))
23f87bed
MB
7704 (format " (Type %s to exit %s)"
7705 (single-key-description cmd)
91472578 7706 (gnus-group-decoded-name gnus-newsgroup-name)))))
eec82323 7707 ;; Confirm auto selection.
23f87bed
MB
7708 (setq key (car (setq keve (gnus-read-event-char prompt)))
7709 ended t)
eec82323
LMI
7710 (cond
7711 ((assq key keystrokes)
7712 (let ((obuf (current-buffer)))
7713 (switch-to-buffer gnus-group-buffer)
7714 (when group
7715 (gnus-group-jump-to-group group))
7716 (eval (cadr (assq key keystrokes)))
7717 (setq group (gnus-group-group-name))
7718 (switch-to-buffer obuf))
7719 (setq ended nil))
7720 ((equal key cmd)
7721 (if (or (not group)
7722 (gnus-ephemeral-group-p gnus-newsgroup-name))
7723 (gnus-summary-exit)
7724 (gnus-summary-next-group nil group backward)))
7725 (t
7726 (push (cdr keve) unread-command-events))))))
7727
7728(defun gnus-summary-next-unread-article ()
7729 "Select unread article after current one."
7730 (interactive)
7731 (gnus-summary-next-article
7732 (or (not (eq gnus-summary-goto-unread 'never))
7733 (gnus-summary-last-article-p (gnus-summary-article-number)))
7734 (and gnus-auto-select-same
7735 (gnus-summary-article-subject))))
7736
7737(defun gnus-summary-prev-article (&optional unread subject)
bbbe940b 7738 "Select the article before the current one.
eec82323
LMI
7739If UNREAD is non-nil, only unread articles are selected."
7740 (interactive "P")
7741 (gnus-summary-next-article unread subject t))
7742
7743(defun gnus-summary-prev-unread-article ()
7744 "Select unread article before current one."
7745 (interactive)
7746 (gnus-summary-prev-article
7747 (or (not (eq gnus-summary-goto-unread 'never))
7748 (gnus-summary-first-article-p (gnus-summary-article-number)))
7749 (and gnus-auto-select-same
7750 (gnus-summary-article-subject))))
7751
23f87bed 7752(defun gnus-summary-next-page (&optional lines circular stop)
eec82323
LMI
7753 "Show next page of the selected article.
7754If at the end of the current article, select the next article.
7755LINES says how many lines should be scrolled up.
7756
7757If CIRCULAR is non-nil, go to the start of the article instead of
7758selecting the next article when reaching the end of the current
23f87bed
MB
7759article.
7760
7761If STOP is non-nil, just stop when reaching the end of the message.
7762
7763Also see the variable `gnus-article-skip-boring'."
eec82323
LMI
7764 (interactive "P")
7765 (setq gnus-summary-buffer (current-buffer))
7766 (gnus-set-global-variables)
7767 (let ((article (gnus-summary-article-number))
7768 (article-window (get-buffer-window gnus-article-buffer t))
7769 endp)
6748645f
LMI
7770 ;; If the buffer is empty, we have no article.
7771 (unless article
7772 (error "No article to select"))
eec82323
LMI
7773 (gnus-configure-windows 'article)
7774 (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7775 (if (and (eq gnus-summary-goto-unread 'never)
7776 (not (gnus-summary-last-article-p article)))
7777 (gnus-summary-next-article)
7778 (gnus-summary-next-unread-article))
7779 (if (or (null gnus-current-article)
7780 (null gnus-article-current)
7781 (/= article (cdr gnus-article-current))
7782 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7783 ;; Selected subject is different from current article's.
7784 (gnus-summary-display-article article)
7785 (when article-window
7786 (gnus-eval-in-buffer-window gnus-article-buffer
23f87bed
MB
7787 (setq endp (or (gnus-article-next-page lines)
7788 (gnus-article-only-boring-p))))
eec82323 7789 (when endp
b1992461 7790 (cond ((or stop gnus-summary-stop-at-end-of-message)
23f87bed
MB
7791 (gnus-message 3 "End of message"))
7792 (circular
eec82323
LMI
7793 (gnus-summary-beginning-of-article))
7794 (lines
7795 (gnus-message 3 "End of message"))
7796 ((null lines)
7797 (if (and (eq gnus-summary-goto-unread 'never)
7798 (not (gnus-summary-last-article-p article)))
7799 (gnus-summary-next-article)
7800 (gnus-summary-next-unread-article))))))))
7801 (gnus-summary-recenter)
7802 (gnus-summary-position-point)))
7803
7804(defun gnus-summary-prev-page (&optional lines move)
7805 "Show previous page of selected article.
7806Argument LINES specifies lines to be scrolled down.
7807If MOVE, move to the previous unread article if point is at
7808the beginning of the buffer."
7809 (interactive "P")
eec82323
LMI
7810 (let ((article (gnus-summary-article-number))
7811 (article-window (get-buffer-window gnus-article-buffer t))
7812 endp)
7813 (gnus-configure-windows 'article)
7814 (if (or (null gnus-current-article)
7815 (null gnus-article-current)
7816 (/= article (cdr gnus-article-current))
7817 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7818 ;; Selected subject is different from current article's.
7819 (gnus-summary-display-article article)
7820 (gnus-summary-recenter)
7821 (when article-window
7822 (gnus-eval-in-buffer-window gnus-article-buffer
7823 (setq endp (gnus-article-prev-page lines)))
7824 (when (and move endp)
7825 (cond (lines
7826 (gnus-message 3 "Beginning of message"))
7827 ((null lines)
7828 (if (and (eq gnus-summary-goto-unread 'never)
7829 (not (gnus-summary-first-article-p article)))
7830 (gnus-summary-prev-article)
7831 (gnus-summary-prev-unread-article))))))))
7832 (gnus-summary-position-point))
7833
7834(defun gnus-summary-prev-page-or-article (&optional lines)
7835 "Show previous page of selected article.
7836Argument LINES specifies lines to be scrolled down.
7837If at the beginning of the article, go to the next article."
7838 (interactive "P")
7839 (gnus-summary-prev-page lines t))
7840
7841(defun gnus-summary-scroll-up (lines)
7842 "Scroll up (or down) one line current article.
7843Argument LINES specifies lines to be scrolled up (or down if negative)."
7844 (interactive "p")
eec82323
LMI
7845 (gnus-configure-windows 'article)
7846 (gnus-summary-show-thread)
7847 (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7848 (gnus-eval-in-buffer-window gnus-article-buffer
7849 (cond ((> lines 0)
7850 (when (gnus-article-next-page lines)
7851 (gnus-message 3 "End of message")))
7852 ((< lines 0)
7853 (gnus-article-prev-page (- lines))))))
7854 (gnus-summary-recenter)
7855 (gnus-summary-position-point))
7856
6748645f
LMI
7857(defun gnus-summary-scroll-down (lines)
7858 "Scroll down (or up) one line current article.
7859Argument LINES specifies lines to be scrolled down (or up if negative)."
7860 (interactive "p")
7861 (gnus-summary-scroll-up (- lines)))
7862
eec82323
LMI
7863(defun gnus-summary-next-same-subject ()
7864 "Select next article which has the same subject as current one."
7865 (interactive)
eec82323
LMI
7866 (gnus-summary-next-article nil (gnus-summary-article-subject)))
7867
7868(defun gnus-summary-prev-same-subject ()
7869 "Select previous article which has the same subject as current one."
7870 (interactive)
eec82323
LMI
7871 (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7872
7873(defun gnus-summary-next-unread-same-subject ()
7874 "Select next unread article which has the same subject as current one."
7875 (interactive)
eec82323
LMI
7876 (gnus-summary-next-article t (gnus-summary-article-subject)))
7877
7878(defun gnus-summary-prev-unread-same-subject ()
7879 "Select previous unread article which has the same subject as current one."
7880 (interactive)
eec82323
LMI
7881 (gnus-summary-prev-article t (gnus-summary-article-subject)))
7882
7883(defun gnus-summary-first-unread-article ()
7884 "Select the first unread article.
7885Return nil if there are no unread articles."
7886 (interactive)
eec82323
LMI
7887 (prog1
7888 (when (gnus-summary-first-subject t)
7889 (gnus-summary-show-thread)
7890 (gnus-summary-first-subject t)
7891 (gnus-summary-display-article (gnus-summary-article-number)))
7892 (gnus-summary-position-point)))
7893
16409b0b
GM
7894(defun gnus-summary-first-unread-subject ()
7895 "Place the point on the subject line of the first unread article.
7896Return nil if there are no unread articles."
7897 (interactive)
7898 (prog1
7899 (when (gnus-summary-first-subject t)
7900 (gnus-summary-show-thread)
7901 (gnus-summary-first-subject t))
7902 (gnus-summary-position-point)))
7903
23f87bed
MB
7904(defun gnus-summary-first-unseen-subject ()
7905 "Place the point on the subject line of the first unseen article.
7906Return nil if there are no unseen articles."
7907 (interactive)
7908 (prog1
7909 (when (gnus-summary-first-subject nil nil t)
7910 (gnus-summary-show-thread)
7911 (gnus-summary-first-subject nil nil t))
7912 (gnus-summary-position-point)))
7913
7914(defun gnus-summary-first-unseen-or-unread-subject ()
7915 "Place the point on the subject line of the first unseen article or,
7916if all article have been seen, on the subject line of the first unread
7917article."
7918 (interactive)
7919 (prog1
7920 (unless (when (gnus-summary-first-subject nil nil t)
7921 (gnus-summary-show-thread)
7922 (gnus-summary-first-subject nil nil t))
7923 (when (gnus-summary-first-subject t)
7924 (gnus-summary-show-thread)
7925 (gnus-summary-first-subject t)))
7926 (gnus-summary-position-point)))
7927
eec82323
LMI
7928(defun gnus-summary-first-article ()
7929 "Select the first article.
7930Return nil if there are no articles."
7931 (interactive)
eec82323
LMI
7932 (prog1
7933 (when (gnus-summary-first-subject)
16409b0b
GM
7934 (gnus-summary-show-thread)
7935 (gnus-summary-first-subject)
7936 (gnus-summary-display-article (gnus-summary-article-number)))
eec82323
LMI
7937 (gnus-summary-position-point)))
7938
23f87bed
MB
7939(defun gnus-summary-best-unread-article (&optional arg)
7940 "Select the unread article with the highest score.
7941If given a prefix argument, select the next unread article that has a
7942score higher than the default score."
7943 (interactive "P")
7944 (let ((article (if arg
7945 (gnus-summary-better-unread-subject)
7946 (gnus-summary-best-unread-subject))))
7947 (if article
7948 (gnus-summary-goto-article article)
7949 (error "No unread articles"))))
7950
7951(defun gnus-summary-best-unread-subject ()
7952 "Select the unread subject with the highest score."
eec82323 7953 (interactive)
eec82323
LMI
7954 (let ((best -1000000)
7955 (data gnus-newsgroup-data)
7956 article score)
7957 (while data
7958 (and (gnus-data-unread-p (car data))
7959 (> (setq score
7960 (gnus-summary-article-score (gnus-data-number (car data))))
7961 best)
7962 (setq best score
7963 article (gnus-data-number (car data))))
7964 (setq data (cdr data)))
23f87bed
MB
7965 (when article
7966 (gnus-summary-goto-subject article))
7967 (gnus-summary-position-point)
7968 article))
7969
7970(defun gnus-summary-better-unread-subject ()
7971 "Select the first unread subject that has a score over the default score."
7972 (interactive)
7973 (let ((data gnus-newsgroup-data)
7974 article score)
7975 (while (and (setq article (gnus-data-number (car data)))
7976 (or (gnus-data-read-p (car data))
7977 (not (> (gnus-summary-article-score article)
7978 gnus-summary-default-score))))
7979 (setq data (cdr data)))
7980 (when article
7981 (gnus-summary-goto-subject article))
7982 (gnus-summary-position-point)
7983 article))
eec82323
LMI
7984
7985(defun gnus-summary-last-subject ()
7986 "Go to the last displayed subject line in the group."
7987 (let ((article (gnus-data-number (car (gnus-data-list t)))))
7988 (when article
7989 (gnus-summary-goto-subject article))))
7990
7991(defun gnus-summary-goto-article (article &optional all-headers force)
6748645f
LMI
7992 "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7993If ALL-HEADERS is non-nil, no header lines are hidden.
7994If FORCE, go to the article even if it isn't displayed. If FORCE
7995is a number, it is the line the article is to be displayed on."
eec82323
LMI
7996 (interactive
7997 (list
6748645f
LMI
7998 (completing-read
7999 "Article number or Message-ID: "
8000 (mapcar (lambda (number) (list (int-to-string number)))
8001 gnus-newsgroup-limit))
eec82323
LMI
8002 current-prefix-arg
8003 t))
8004 (prog1
6748645f 8005 (if (and (stringp article)
23f87bed 8006 (string-match "@\\|%40" article))
6748645f
LMI
8007 (gnus-summary-refer-article article)
8008 (when (stringp article)
8009 (setq article (string-to-number article)))
8010 (if (gnus-summary-goto-subject article force)
8011 (gnus-summary-display-article article all-headers)
8012 (gnus-message 4 "Couldn't go to article %s" article) nil))
eec82323
LMI
8013 (gnus-summary-position-point)))
8014
8015(defun gnus-summary-goto-last-article ()
8016 "Go to the previously read article."
8017 (interactive)
8018 (prog1
8019 (when gnus-last-article
6748645f 8020 (gnus-summary-goto-article gnus-last-article nil t))
eec82323
LMI
8021 (gnus-summary-position-point)))
8022
8023(defun gnus-summary-pop-article (number)
8024 "Pop one article off the history and go to the previous.
8025NUMBER articles will be popped off."
8026 (interactive "p")
8027 (let (to)
8028 (setq gnus-newsgroup-history
8029 (cdr (setq to (nthcdr number gnus-newsgroup-history))))
8030 (if to
6748645f 8031 (gnus-summary-goto-article (car to) nil t)
eec82323
LMI
8032 (error "Article history empty")))
8033 (gnus-summary-position-point))
8034
8035;; Summary commands and functions for limiting the summary buffer.
8036
8037(defun gnus-summary-limit-to-articles (n)
8038 "Limit the summary buffer to the next N articles.
8039If not given a prefix, use the process marked articles instead."
8040 (interactive "P")
eec82323
LMI
8041 (prog1
8042 (let ((articles (gnus-summary-work-articles n)))
8043 (setq gnus-newsgroup-processable nil)
8044 (gnus-summary-limit articles))
8045 (gnus-summary-position-point)))
8046
8047(defun gnus-summary-pop-limit (&optional total)
8048 "Restore the previous limit.
8049If given a prefix, remove all limits."
8050 (interactive "P")
eec82323
LMI
8051 (when total
8052 (setq gnus-newsgroup-limits
8053 (list (mapcar (lambda (h) (mail-header-number h))
8054 gnus-newsgroup-headers))))
8055 (unless gnus-newsgroup-limits
8056 (error "No limit to pop"))
8057 (prog1
8058 (gnus-summary-limit nil 'pop)
8059 (gnus-summary-position-point)))
8060
47b63dfa
SZ
8061(defun gnus-summary-limit-to-subject (subject &optional header not-matching)
8062 "Limit the summary buffer to articles that have subjects that match a regexp.
8063If NOT-MATCHING, excluding articles that have subjects that match a regexp."
a1506d29 8064 (interactive
47b63dfa
SZ
8065 (list (read-string (if current-prefix-arg
8066 "Exclude subject (regexp): "
a1506d29 8067 "Limit to subject (regexp): "))
47b63dfa 8068 nil current-prefix-arg))
eec82323
LMI
8069 (unless header
8070 (setq header "subject"))
8071 (when (not (equal "" subject))
8072 (prog1
8073 (let ((articles (gnus-summary-find-matching
a1506d29 8074 (or header "subject") subject 'all nil nil
47b63dfa 8075 not-matching)))
eec82323
LMI
8076 (unless articles
8077 (error "Found no matches for \"%s\"" subject))
8078 (gnus-summary-limit articles))
8079 (gnus-summary-position-point))))
8080
ef6e0ec7 8081(defun gnus-summary-limit-to-author (from &optional not-matching)
47b63dfa
SZ
8082 "Limit the summary buffer to articles that have authors that match a regexp.
8083If NOT-MATCHING, excluding articles that have authors that match a regexp."
a1506d29 8084 (interactive
47b63dfa
SZ
8085 (list (read-string (if current-prefix-arg
8086 "Exclude author (regexp): "
a1506d29 8087 "Limit to author (regexp): "))
ef6e0ec7
SZ
8088 current-prefix-arg))
8089 (gnus-summary-limit-to-subject from "from" not-matching))
eec82323 8090
01c52d31
MB
8091(defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8092 "Limit the summary buffer to articles with the given RECIPIENT.
8093
8094If NOT-MATCHING, exclude RECIPIENT.
8095
8096To and Cc headers are checked. You need to include them in
8097`nnmail-extra-headers'."
8098 ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8099 (interactive
8100 (list (read-string (format "%s recipient (regexp): "
8101 (if current-prefix-arg "Exclude" "Limit to")))
8102 current-prefix-arg))
8103 (when (not (equal "" recipient))
8104 (prog1 (let* ((to
8105 (if (memq 'To nnmail-extra-headers)
8106 (gnus-summary-find-matching
8107 (cons 'extra 'To) recipient 'all nil nil
8108 not-matching)
8109 (gnus-message
8110 1 "`To' isn't present in `nnmail-extra-headers'")
8111 (sit-for 1)
8112 nil))
8113 (cc
8114 (if (memq 'Cc nnmail-extra-headers)
8115 (gnus-summary-find-matching
8116 (cons 'extra 'Cc) recipient 'all nil nil
8117 not-matching)
8118 (gnus-message
8119 1 "`Cc' isn't present in `nnmail-extra-headers'")
8120 (sit-for 1)
8121 nil))
8122 (articles
8123 (if not-matching
8124 ;; We need the numbers that are in both lists:
8125 (mapcar (lambda (a)
8126 (and (memq a to) a))
8127 cc)
8128 (nconc to cc))))
8129 (unless articles
8130 (error "Found no matches for \"%s\"" recipient))
8131 (gnus-summary-limit articles))
8132 (gnus-summary-position-point))))
8133
8134(defun gnus-summary-limit-to-address (address &optional not-matching)
8135 "Limit the summary buffer to articles with the given ADDRESS.
8136
8137If NOT-MATCHING, exclude ADDRESS.
8138
8139To, Cc and From headers are checked. You need to include `To' and `Cc'
8140in `nnmail-extra-headers'."
8141 (interactive
8142 (list (read-string (format "%s address (regexp): "
8143 (if current-prefix-arg "Exclude" "Limit to")))
8144 current-prefix-arg))
8145 (when (not (equal "" address))
8146 (prog1 (let* ((to
8147 (if (memq 'To nnmail-extra-headers)
8148 (gnus-summary-find-matching
8149 (cons 'extra 'To) address 'all nil nil
8150 not-matching)
8151 (gnus-message
8152 1 "`To' isn't present in `nnmail-extra-headers'")
8153 (sit-for 1)
8154 t))
8155 (cc
8156 (if (memq 'Cc nnmail-extra-headers)
8157 (gnus-summary-find-matching
8158 (cons 'extra 'Cc) address 'all nil nil
8159 not-matching)
8160 (gnus-message
8161 1 "`Cc' isn't present in `nnmail-extra-headers'")
8162 (sit-for 1)
8163 t))
8164 (from
8165 (gnus-summary-find-matching "from" address
8166 'all nil nil not-matching))
8167 (articles
8168 (if not-matching
8169 ;; We need the numbers that are in all lists:
8170 (if (eq cc t)
8171 (if (eq to t)
8172 from
8173 (mapcar (lambda (a) (car (memq a from))) to))
8174 (if (eq to t)
8175 (mapcar (lambda (a) (car (memq a from))) cc)
8176 (mapcar (lambda (a) (car (memq a from)))
8177 (mapcar (lambda (a) (car (memq a to)))
8178 cc))))
8179 (nconc (if (eq to t) nil to)
8180 (if (eq cc t) nil cc)
8181 from))))
8182 (unless articles
8183 (error "Found no matches for \"%s\"" address))
8184 (gnus-summary-limit articles))
8185 (gnus-summary-position-point))))
8186
8187(defun gnus-summary-limit-strange-charsets-predicate (header)
765d4319
KY
8188 (when (fboundp 'char-charset)
8189 (let ((string (concat (mail-header-subject header)
8190 (mail-header-from header)))
8191 charset found)
8192 (dotimes (i (1- (length string)))
8193 (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8194 (when (string-match "unicode\\|big\\|japanese" charset)
8195 (setq found t)))
8196 found)))
01c52d31
MB
8197
8198(defun gnus-summary-limit-to-predicate (predicate)
8199 "Limit to articles where PREDICATE returns non-nil.
8200PREDICATE will be called with the header structures of the
8201articles."
8202 (let ((articles nil)
8203 (case-fold-search t))
8204 (dolist (header gnus-newsgroup-headers)
8205 (when (funcall predicate header)
8206 (push (mail-header-number header) articles)))
8207 (gnus-summary-limit (nreverse articles))))
8208
eec82323
LMI
8209(defun gnus-summary-limit-to-age (age &optional younger-p)
8210 "Limit the summary buffer to articles that are older than (or equal) AGE days.
8211If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8212articles that are younger than AGE days."
16409b0b
GM
8213 (interactive
8214 (let ((younger current-prefix-arg)
8215 (days-got nil)
8216 days)
8217 (while (not days-got)
8218 (setq days (if younger
23f87bed
MB
8219 (read-string "Limit to articles younger than (in days, older when negative): ")
8220 (read-string
8221 "Limit to articles older than (in days, younger when negative): ")))
16409b0b
GM
8222 (when (> (length days) 0)
8223 (setq days (read days)))
8224 (if (numberp days)
23f87bed
MB
8225 (progn
8226 (setq days-got t)
01c52d31
MB
8227 (when (< days 0)
8228 (setq younger (not younger))
8229 (setq days (* days -1))))
16409b0b
GM
8230 (message "Please enter a number.")
8231 (sleep-for 1)))
8232 (list days younger)))
eec82323
LMI
8233 (prog1
8234 (let ((data gnus-newsgroup-data)
16409b0b 8235 (cutoff (days-to-time age))
eec82323
LMI
8236 articles d date is-younger)
8237 (while (setq d (pop data))
8238 (when (and (vectorp (gnus-data-header d))
8239 (setq date (mail-header-date (gnus-data-header d))))
16409b0b 8240 (setq is-younger (time-less-p
3d6e7a43 8241 (time-since (gnus-date-get-time date))
eec82323 8242 cutoff))
6748645f
LMI
8243 (when (if younger-p
8244 is-younger
8245 (not is-younger))
eec82323
LMI
8246 (push (gnus-data-number d) articles))))
8247 (gnus-summary-limit (nreverse articles)))
8248 (gnus-summary-position-point)))
8249
47b63dfa 8250(defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
16409b0b
GM
8251 "Limit the summary buffer to articles that match an 'extra' header."
8252 (interactive
8253 (let ((header
8254 (intern
23f87bed 8255 (gnus-completing-read-with-default
16409b0b 8256 (symbol-name (car gnus-extra-headers))
47b63dfa 8257 (if current-prefix-arg
81df110a
RF
8258 "Exclude extra header"
8259 "Limit extra header")
16409b0b
GM
8260 (mapcar (lambda (x)
8261 (cons (symbol-name x) x))
8262 gnus-extra-headers)
8263 nil
8264 t))))
8265 (list header
a1506d29 8266 (read-string (format "%s header %s (regexp): "
47b63dfa
SZ
8267 (if current-prefix-arg "Exclude" "Limit to")
8268 header))
8269 current-prefix-arg)))
16409b0b
GM
8270 (when (not (equal "" regexp))
8271 (prog1
8272 (let ((articles (gnus-summary-find-matching
a1506d29 8273 (cons 'extra header) regexp 'all nil nil
47b63dfa 8274 not-matching)))
16409b0b
GM
8275 (unless articles
8276 (error "Found no matches for \"%s\"" regexp))
8277 (gnus-summary-limit articles))
8278 (gnus-summary-position-point))))
8279
23f87bed
MB
8280(defun gnus-summary-limit-to-display-predicate ()
8281 "Limit the summary buffer to the predicated in the `display' group parameter."
8282 (interactive)
8283 (unless gnus-newsgroup-display
8284 (error "There is no `display' group parameter"))
8285 (let (articles)
8286 (dolist (number gnus-newsgroup-articles)
8287 (when (funcall gnus-newsgroup-display)
8288 (push number articles)))
8289 (gnus-summary-limit articles))
8290 (gnus-summary-position-point))
8291
eec82323
LMI
8292(defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8293(make-obsolete
265ac10b 8294 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread "Emacs 20.4")
eec82323
LMI
8295
8296(defun gnus-summary-limit-to-unread (&optional all)
8297 "Limit the summary buffer to articles that are not marked as read.
8298If ALL is non-nil, limit strictly to unread articles."
8299 (interactive "P")
8300 (if all
8301 (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8302 (gnus-summary-limit-to-marks
8303 ;; Concat all the marks that say that an article is read and have
8304 ;; those removed.
8305 (list gnus-del-mark gnus-read-mark gnus-ancient-mark
23f87bed 8306 gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
eec82323
LMI
8307 gnus-low-score-mark gnus-expirable-mark
8308 gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8309 gnus-duplicate-mark gnus-souped-mark)
8310 'reverse)))
8311
01c52d31
MB
8312(defun gnus-summary-limit-to-headers (match &optional reverse)
8313 "Limit the summary buffer to articles that have headers that match MATCH.
8314If REVERSE (the prefix), limit to articles that don't match."
8315 (interactive "sMatch headers (regexp): \nP")
8316 (gnus-summary-limit-to-bodies match reverse t))
8317
8318(defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8319 "Limit the summary buffer to articles that have bodies that match MATCH.
8320If REVERSE (the prefix), limit to articles that don't match."
8321 (interactive "sMatch body (regexp): \nP")
8322 (let ((articles nil)
8323 (gnus-select-article-hook nil) ;Disable hook.
8324 (gnus-article-prepare-hook nil)
8325 (gnus-use-article-prefetch nil)
8326 (gnus-keep-backlog nil)
8327 (gnus-break-pages nil)
8328 (gnus-summary-display-arrow nil)
8329 (gnus-updated-mode-lines nil)
8330 (gnus-auto-center-summary nil)
8331 (gnus-display-mime-function nil))
8332 (dolist (data gnus-newsgroup-data)
8333 (let (gnus-mark-article-hook)
8334 (gnus-summary-select-article t t nil (gnus-data-number data)))
398a825b 8335 (with-current-buffer gnus-article-buffer
01c52d31
MB
8336 (article-goto-body)
8337 (let* ((case-fold-search t)
8338 (found (if headersp
8339 (re-search-backward match nil t)
8340 (re-search-forward match nil t))))
8341 (when (or (and found
8342 (not reverse))
8343 (and (not found)
8344 reverse))
8345 (push (gnus-data-number data) articles)))))
8346 (if (not articles)
8347 (message "No messages matched")
8348 (gnus-summary-limit articles)))
8349 (gnus-summary-position-point))
8350
8351(defun gnus-summary-limit-to-singletons (&optional threadsp)
8352 "Limit the summary buffer to articles that aren't part on any thread.
8353If THREADSP (the prefix), limit to articles that are in threads."
8354 (interactive "P")
8355 (let ((articles nil)
8356 thread-articles
8357 threads)
8358 (dolist (thread gnus-newsgroup-threads)
8359 (if (stringp (car thread))
8360 (dolist (thread (cdr thread))
8361 (push thread threads))
8362 (push thread threads)))
8363 (dolist (thread threads)
8364 (setq thread-articles (gnus-articles-in-thread thread))
8365 (when (or (and threadsp
8366 (> (length thread-articles) 1))
8367 (and (not threadsp)
8368 (= (length thread-articles) 1)))
8369 (setq articles (nconc thread-articles articles))))
8370 (if (not articles)
8371 (message "No messages matched")
8372 (gnus-summary-limit articles))
8373 (gnus-summary-position-point)))
8374
8375(defun gnus-summary-limit-to-replied (&optional unreplied)
8376 "Limit the summary buffer to replied articles.
8377If UNREPLIED (the prefix), limit to unreplied articles."
8378 (interactive "P")
8379 (if unreplied
8380 (gnus-summary-limit
8381 (gnus-set-difference gnus-newsgroup-articles
8382 gnus-newsgroup-replied))
8383 (gnus-summary-limit gnus-newsgroup-replied))
8384 (gnus-summary-position-point))
8385
eec82323
LMI
8386(defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8387(make-obsolete 'gnus-summary-delete-marked-with
265ac10b 8388 'gnus-summary-limit-exclude-marks "Emacs 20.4")
eec82323
LMI
8389
8390(defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8391 "Exclude articles that are marked with MARKS (e.g. \"DK\").
8392If REVERSE, limit the summary buffer to articles that are marked
8393with MARKS. MARKS can either be a string of marks or a list of marks.
8394Returns how many articles were removed."
8395 (interactive "sMarks: ")
8396 (gnus-summary-limit-to-marks marks t))
8397
8398(defun gnus-summary-limit-to-marks (marks &optional reverse)
8399 "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8400If REVERSE (the prefix), limit the summary buffer to articles that are
8401not marked with MARKS. MARKS can either be a string of marks or a
8402list of marks.
8403Returns how many articles were removed."
6748645f 8404 (interactive "sMarks: \nP")
eec82323
LMI
8405 (prog1
8406 (let ((data gnus-newsgroup-data)
8407 (marks (if (listp marks) marks
8408 (append marks nil))) ; Transform to list.
8409 articles)
8410 (while data
8411 (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8412 (memq (gnus-data-mark (car data)) marks))
8413 (push (gnus-data-number (car data)) articles))
8414 (setq data (cdr data)))
8415 (gnus-summary-limit articles))
8416 (gnus-summary-position-point)))
8417
23f87bed 8418(defun gnus-summary-limit-to-score (score)
eec82323 8419 "Limit to articles with score at or above SCORE."
23f87bed 8420 (interactive "NLimit to articles with score of at least: ")
eec82323
LMI
8421 (let ((data gnus-newsgroup-data)
8422 articles)
8423 (while data
8424 (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8425 score)
8426 (push (gnus-data-number (car data)) articles))
8427 (setq data (cdr data)))
8428 (prog1
8429 (gnus-summary-limit articles)
8430 (gnus-summary-position-point))))
8431
23f87bed
MB
8432(defun gnus-summary-limit-to-unseen ()
8433 "Limit to unseen articles."
8434 (interactive)
8435 (prog1
8436 (gnus-summary-limit gnus-newsgroup-unseen)
8437 (gnus-summary-position-point)))
8438
6748645f 8439(defun gnus-summary-limit-include-thread (id)
23f87bed
MB
8440 "Display all the hidden articles that is in the thread with ID in it.
8441When called interactively, ID is the Message-ID of the current
8442article."
6748645f
LMI
8443 (interactive (list (mail-header-id (gnus-summary-article-header))))
8444 (let ((articles (gnus-articles-in-thread
8445 (gnus-id-to-thread (gnus-root-id id)))))
8446 (prog1
8447 (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
23f87bed
MB
8448 (gnus-summary-limit-include-matching-articles
8449 "subject"
8450 (regexp-quote (gnus-simplify-subject-re
8451 (mail-header-subject (gnus-id-to-header id)))))
6748645f
LMI
8452 (gnus-summary-position-point))))
8453
23f87bed
MB
8454(defun gnus-summary-limit-include-matching-articles (header regexp)
8455 "Display all the hidden articles that have HEADERs that match REGEXP."
8456 (interactive (list (read-string "Match on header: ")
8457 (read-string "Regexp: ")))
8458 (let ((articles (gnus-find-matching-articles header regexp)))
8459 (prog1
8460 (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8461 (gnus-summary-position-point))))
8462
8463(defun gnus-summary-insert-dormant-articles ()
8464 "Insert all the dormant articles for this group into the current buffer."
8465 (interactive)
8466 (let ((gnus-verbose (max 6 gnus-verbose)))
8467 (if (not gnus-newsgroup-dormant)
db629244 8468 (gnus-message 3 "No dormant articles for this group")
23f87bed
MB
8469 (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8470
01c52d31
MB
8471(defun gnus-summary-insert-ticked-articles ()
8472 "Insert ticked articles for this group into the current buffer."
8473 (interactive)
8474 (let ((gnus-verbose (max 6 gnus-verbose)))
8475 (if (not gnus-newsgroup-marked)
8476 (gnus-message 3 "No ticked articles for this group")
8477 (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8478
eec82323 8479(defun gnus-summary-limit-include-dormant ()
6748645f
LMI
8480 "Display all the hidden articles that are marked as dormant.
8481Note that this command only works on a subset of the articles currently
8482fetched for this group."
eec82323 8483 (interactive)
eec82323
LMI
8484 (unless gnus-newsgroup-dormant
8485 (error "There are no dormant articles in this group"))
8486 (prog1
8487 (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8488 (gnus-summary-position-point)))
8489
8490(defun gnus-summary-limit-exclude-dormant ()
8491 "Hide all dormant articles."
8492 (interactive)
eec82323
LMI
8493 (prog1
8494 (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8495 (gnus-summary-position-point)))
8496
8497(defun gnus-summary-limit-exclude-childless-dormant ()
8498 "Hide all dormant articles that have no children."
8499 (interactive)
eec82323
LMI
8500 (let ((data (gnus-data-list t))
8501 articles d children)
8502 ;; Find all articles that are either not dormant or have
8503 ;; children.
8504 (while (setq d (pop data))
8505 (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8506 (and (setq children
8507 (gnus-article-children (gnus-data-number d)))
8508 (let (found)
8509 (while children
8510 (when (memq (car children) articles)
8511 (setq children nil
8512 found t))
8513 (pop children))
8514 found)))
8515 (push (gnus-data-number d) articles)))
8516 ;; Do the limiting.
8517 (prog1
8518 (gnus-summary-limit articles)
8519 (gnus-summary-position-point))))
8520
8521(defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8522 "Mark all unread excluded articles as read.
8523If ALL, mark even excluded ticked and dormants as read."
8524 (interactive "P")
23f87bed
MB
8525 (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8526 (let ((articles (gnus-sorted-ndifference
eec82323
LMI
8527 (sort
8528 (mapcar (lambda (h) (mail-header-number h))
8529 gnus-newsgroup-headers)
8530 '<)
23f87bed 8531 gnus-newsgroup-limit))
eec82323 8532 article)
6748645f 8533 (setq gnus-newsgroup-unreads
23f87bed
MB
8534 (gnus-sorted-intersection gnus-newsgroup-unreads
8535 gnus-newsgroup-limit))
eec82323
LMI
8536 (if all
8537 (setq gnus-newsgroup-dormant nil
8538 gnus-newsgroup-marked nil
8539 gnus-newsgroup-reads
8540 (nconc
8541 (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8542 gnus-newsgroup-reads))
8543 (while (setq article (pop articles))
8544 (unless (or (memq article gnus-newsgroup-dormant)
8545 (memq article gnus-newsgroup-marked))
8546 (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8547
8548(defun gnus-summary-limit (articles &optional pop)
8549 (if pop
8550 ;; We pop the previous limit off the stack and use that.
8551 (setq articles (car gnus-newsgroup-limits)
8552 gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8553 ;; We use the new limit, so we push the old limit on the stack.
8554 (push gnus-newsgroup-limit gnus-newsgroup-limits))
8555 ;; Set the limit.
8556 (setq gnus-newsgroup-limit articles)
8557 (let ((total (length gnus-newsgroup-data))
8558 (data (gnus-data-find-list (gnus-summary-article-number)))
8559 (gnus-summary-mark-below nil) ; Inhibit this.
8560 found)
8561 ;; This will do all the work of generating the new summary buffer
8562 ;; according to the new limit.
8563 (gnus-summary-prepare)
8564 ;; Hide any threads, possibly.
23f87bed 8565 (gnus-summary-maybe-hide-threads)
eec82323
LMI
8566 ;; Try to return to the article you were at, or one in the
8567 ;; neighborhood.
8568 (when data
8569 ;; We try to find some article after the current one.
8570 (while data
8571 (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8572 (setq data nil
8573 found t))
8574 (setq data (cdr data))))
8575 (unless found
8576 ;; If there is no data, that means that we were after the last
8577 ;; article. The same goes when we can't find any articles
8578 ;; after the current one.
8579 (goto-char (point-max))
8580 (gnus-summary-find-prev))
6748645f 8581 (gnus-set-mode-line 'summary)
eec82323
LMI
8582 ;; We return how many articles were removed from the summary
8583 ;; buffer as a result of the new limit.
8584 (- total (length gnus-newsgroup-data))))
8585
8586(defsubst gnus-invisible-cut-children (threads)
8587 (let ((num 0))
8588 (while threads
8589 (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8590 (incf num))
8591 (pop threads))
8592 (< num 2)))
8593
8594(defsubst gnus-cut-thread (thread)
8595 "Go forwards in the thread until we find an article that we want to display."
8596 (when (or (eq gnus-fetch-old-headers 'some)
6748645f 8597 (eq gnus-fetch-old-headers 'invisible)
16409b0b 8598 (numberp gnus-fetch-old-headers)
eec82323
LMI
8599 (eq gnus-build-sparse-threads 'some)
8600 (eq gnus-build-sparse-threads 'more))
8601 ;; Deal with old-fetched headers and sparse threads.
8602 (while (and
8603 thread
8604 (or
8605 (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8606 (gnus-summary-article-ancient-p
8607 (mail-header-number (car thread))))
6748645f
LMI
8608 (if (or (<= (length (cdr thread)) 1)
8609 (eq gnus-fetch-old-headers 'invisible))
8610 (setq gnus-newsgroup-limit
8611 (delq (mail-header-number (car thread))
8612 gnus-newsgroup-limit)
8613 thread (cadr thread))
8614 (when (gnus-invisible-cut-children (cdr thread))
8615 (let ((th (cdr thread)))
8616 (while th
8617 (if (memq (mail-header-number (caar th))
a8151ef7 8618 gnus-newsgroup-limit)
6748645f
LMI
8619 (setq thread (car th)
8620 th nil)
8621 (setq th (cdr th))))))))))
eec82323
LMI
8622 thread)
8623
8624(defun gnus-cut-threads (threads)
23f87bed 8625 "Cut off all uninteresting articles from the beginning of THREADS."
eec82323 8626 (when (or (eq gnus-fetch-old-headers 'some)
6748645f 8627 (eq gnus-fetch-old-headers 'invisible)
16409b0b 8628 (numberp gnus-fetch-old-headers)
eec82323
LMI
8629 (eq gnus-build-sparse-threads 'some)
8630 (eq gnus-build-sparse-threads 'more))
8631 (let ((th threads))
8632 (while th
8633 (setcar th (gnus-cut-thread (car th)))
8634 (setq th (cdr th)))))
8635 ;; Remove nixed out threads.
8636 (delq nil threads))
8637
8638(defun gnus-summary-initial-limit (&optional show-if-empty)
8639 "Figure out what the initial limit is supposed to be on group entry.
8640This entails weeding out unwanted dormants, low-scored articles,
8641fetch-old-headers verbiage, and so on."
8642 ;; Most groups have nothing to remove.
f394fa25
MB
8643 (unless (or gnus-inhibit-limiting
8644 (and (null gnus-newsgroup-dormant)
8645 (eq gnus-newsgroup-display 'gnus-not-ignore)
8646 (not (eq gnus-fetch-old-headers 'some))
8647 (not (numberp gnus-fetch-old-headers))
8648 (not (eq gnus-fetch-old-headers 'invisible))
8649 (null gnus-summary-expunge-below)
8650 (not (eq gnus-build-sparse-threads 'some))
8651 (not (eq gnus-build-sparse-threads 'more))
8652 (null gnus-thread-expunge-below)
8653 (not gnus-use-nocem)))
eec82323
LMI
8654 (push gnus-newsgroup-limit gnus-newsgroup-limits)
8655 (setq gnus-newsgroup-limit nil)
8656 (mapatoms
8657 (lambda (node)
8658 (unless (car (symbol-value node))
8659 ;; These threads have no parents -- they are roots.
8660 (let ((nodes (cdr (symbol-value node)))
8661 thread)
8662 (while nodes
8663 (if (and gnus-thread-expunge-below
8664 (< (gnus-thread-total-score (car nodes))
8665 gnus-thread-expunge-below))
8666 (gnus-expunge-thread (pop nodes))
8667 (setq thread (pop nodes))
8668 (gnus-summary-limit-children thread))))))
8669 gnus-newsgroup-dependencies)
8670 ;; If this limitation resulted in an empty group, we might
8671 ;; pop the previous limit and use it instead.
8672 (when (and (not gnus-newsgroup-limit)
8673 show-if-empty)
8674 (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8675 gnus-newsgroup-limit))
8676
8677(defun gnus-summary-limit-children (thread)
8678 "Return 1 if this subthread is visible and 0 if it is not."
8679 ;; First we get the number of visible children to this thread. This
8680 ;; is done by recursing down the thread using this function, so this
8681 ;; will really go down to a leaf article first, before slowly
8682 ;; working its way up towards the root.
8683 (when thread
04b61ae9 8684 (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
23f87bed 8685 (children
eec82323
LMI
8686 (if (cdr thread)
8687 (apply '+ (mapcar 'gnus-summary-limit-children
8688 (cdr thread)))
8689 0))
8690 (number (mail-header-number (car thread)))
8691 score)
8692 (if (and
8693 (not (memq number gnus-newsgroup-marked))
8694 (or
8695 ;; If this article is dormant and has absolutely no visible
8696 ;; children, then this article isn't visible.
8697 (and (memq number gnus-newsgroup-dormant)
8698 (zerop children))
8699 ;; If this is "fetch-old-headered" and there is no
8700 ;; visible children, then we don't want this article.
16409b0b
GM
8701 (and (or (eq gnus-fetch-old-headers 'some)
8702 (numberp gnus-fetch-old-headers))
eec82323
LMI
8703 (gnus-summary-article-ancient-p number)
8704 (zerop children))
6748645f
LMI
8705 ;; If this is "fetch-old-headered" and `invisible', then
8706 ;; we don't want this article.
8707 (and (eq gnus-fetch-old-headers 'invisible)
8708 (gnus-summary-article-ancient-p number))
eec82323
LMI
8709 ;; If this is a sparsely inserted article with no children,
8710 ;; we don't want it.
8711 (and (eq gnus-build-sparse-threads 'some)
8712 (gnus-summary-article-sparse-p number)
8713 (zerop children))
8714 ;; If we use expunging, and this article is really
8715 ;; low-scored, then we don't want this article.
8716 (when (and gnus-summary-expunge-below
8717 (< (setq score
8718 (or (cdr (assq number gnus-newsgroup-scored))
8719 gnus-summary-default-score))
8720 gnus-summary-expunge-below))
8721 ;; We increase the expunge-tally here, but that has
8722 ;; nothing to do with the limits, really.
8723 (incf gnus-newsgroup-expunged-tally)
8724 ;; We also mark as read here, if that's wanted.
8725 (when (and gnus-summary-mark-below
8726 (< score gnus-summary-mark-below))
8727 (setq gnus-newsgroup-unreads
8728 (delq number gnus-newsgroup-unreads))
8729 (if gnus-newsgroup-auto-expire
8730 (push number gnus-newsgroup-expirable)
8731 (push (cons number gnus-low-score-mark)
8732 gnus-newsgroup-reads)))
8733 t)
23f87bed
MB
8734 ;; Do the `display' group parameter.
8735 (and gnus-newsgroup-display
8736 (not (funcall gnus-newsgroup-display)))
eec82323 8737 ;; Check NoCeM things.
01c52d31
MB
8738 (when (and gnus-use-nocem
8739 (gnus-nocem-unwanted-article-p
8740 (mail-header-id (car thread))))
8741 (setq gnus-newsgroup-unreads
8742 (delq number gnus-newsgroup-unreads))
8743 t)))
eec82323
LMI
8744 ;; Nope, invisible article.
8745 0
8746 ;; Ok, this article is to be visible, so we add it to the limit
8747 ;; and return 1.
8748 (push number gnus-newsgroup-limit)
8749 1))))
8750
8751(defun gnus-expunge-thread (thread)
8752 "Mark all articles in THREAD as read."
8753 (let* ((number (mail-header-number (car thread))))
8754 (incf gnus-newsgroup-expunged-tally)
8755 ;; We also mark as read here, if that's wanted.
8756 (setq gnus-newsgroup-unreads
8757 (delq number gnus-newsgroup-unreads))
8758 (if gnus-newsgroup-auto-expire
8759 (push number gnus-newsgroup-expirable)
8760 (push (cons number gnus-low-score-mark)
8761 gnus-newsgroup-reads)))
8762 ;; Go recursively through all subthreads.
8763 (mapcar 'gnus-expunge-thread (cdr thread)))
8764
8765;; Summary article oriented commands
8766
8767(defun gnus-summary-refer-parent-article (n)
8768 "Refer parent article N times.
8769If N is negative, go to ancestor -N instead.
8770The difference between N and the number of articles fetched is returned."
8771 (interactive "p")
eec82323
LMI
8772 (let ((skip 1)
8773 error header ref)
8774 (when (not (natnump n))
8775 (setq skip (abs n)
8776 n 1))
8777 (while (and (> n 0)
8778 (not error))
8779 (setq header (gnus-summary-article-header))
8780 (if (and (eq (mail-header-number header)
8781 (cdr gnus-article-current))
8782 (equal gnus-newsgroup-name
8783 (car gnus-article-current)))
8784 ;; If we try to find the parent of the currently
8785 ;; displayed article, then we take a look at the actual
8786 ;; References header, since this is slightly more
8787 ;; reliable than the References field we got from the
8788 ;; server.
c7a91ce1 8789 (with-current-buffer gnus-original-article-buffer
eec82323
LMI
8790 (nnheader-narrow-to-headers)
8791 (unless (setq ref (message-fetch-field "references"))
23f87bed
MB
8792 (when (setq ref (message-fetch-field "in-reply-to"))
8793 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
eec82323
LMI
8794 (widen))
8795 (setq ref
8796 ;; It's not the current article, so we take a bet on
8797 ;; the value we got from the server.
8798 (mail-header-references header)))
8799 (if (and ref
8800 (not (equal ref "")))
8801 (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8802 (gnus-message 1 "Couldn't find parent"))
8803 (gnus-message 1 "No references in article %d"
8804 (gnus-summary-article-number))
8805 (setq error t))
8806 (decf n))
8807 (gnus-summary-position-point)
8808 n))
8809
8810(defun gnus-summary-refer-references ()
8811 "Fetch all articles mentioned in the References header.
6748645f 8812Return the number of articles fetched."
eec82323 8813 (interactive)
eec82323
LMI
8814 (let ((ref (mail-header-references (gnus-summary-article-header)))
8815 (current (gnus-summary-article-number))
8816 (n 0))
8817 (if (or (not ref)
8818 (equal ref ""))
8819 (error "No References in the current article")
8820 ;; For each Message-ID in the References header...
8821 (while (string-match "<[^>]*>" ref)
8822 (incf n)
8823 ;; ... fetch that article.
8824 (gnus-summary-refer-article
8825 (prog1 (match-string 0 ref)
8826 (setq ref (substring ref (match-end 0))))))
8827 (gnus-summary-goto-subject current)
8828 (gnus-summary-position-point)
8829 n)))
8830
6748645f
LMI
8831(defun gnus-summary-refer-thread (&optional limit)
8832 "Fetch all articles in the current thread.
8833If LIMIT (the numerical prefix), fetch that many old headers instead
8834of what's specified by the `gnus-refer-thread-limit' variable."
8835 (interactive "P")
8836 (let ((id (mail-header-id (gnus-summary-article-header)))
8837 (limit (if limit (prefix-numeric-value limit)
8838 gnus-refer-thread-limit)))
6748645f
LMI
8839 (unless (eq gnus-fetch-old-headers 'invisible)
8840 (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8841 ;; Retrieve the headers and read them in.
23f87bed
MB
8842 (if (eq (if (numberp limit)
8843 (gnus-retrieve-headers
8844 (list (min
8845 (+ (mail-header-number
8846 (gnus-summary-article-header))
8847 limit)
8848 gnus-newsgroup-end))
8849 gnus-newsgroup-name (* limit 2))
8850 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8851 ;; headers.
8852 (gnus-retrieve-headers (list gnus-newsgroup-end)
8853 gnus-newsgroup-name limit))
6748645f
LMI
8854 'nov)
8855 (gnus-build-all-threads)
23f87bed 8856 (error "Can't fetch thread from back ends that don't support NOV"))
6748645f
LMI
8857 (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8858 (gnus-summary-limit-include-thread id)))
8859
16409b0b
GM
8860(defun gnus-summary-refer-article (message-id)
8861 "Fetch an article specified by MESSAGE-ID."
8862 (interactive "sMessage-ID: ")
eec82323
LMI
8863 (when (and (stringp message-id)
8864 (not (zerop (length message-id))))
23f87bed 8865 (setq message-id (gnus-replace-in-string message-id " " ""))
eec82323
LMI
8866 ;; Construct the correct Message-ID if necessary.
8867 ;; Suggested by tale@pawl.rpi.edu.
8868 (unless (string-match "^<" message-id)
8869 (setq message-id (concat "<" message-id)))
8870 (unless (string-match ">$" message-id)
8871 (setq message-id (concat message-id ">")))
23f87bed
MB
8872 ;; People often post MIDs from URLs, so unhex it:
8873 (unless (string-match "@" message-id)
8874 (setq message-id (gnus-url-unhex-string message-id)))
eec82323
LMI
8875 (let* ((header (gnus-id-to-header message-id))
8876 (sparse (and header
8877 (gnus-summary-article-sparse-p
a8151ef7
LMI
8878 (mail-header-number header))
8879 (memq (mail-header-number header)
16409b0b
GM
8880 gnus-newsgroup-limit)))
8881 number)
6748645f
LMI
8882 (cond
8883 ;; If the article is present in the buffer we just go to it.
8884 ((and header
8885 (or (not (gnus-summary-article-sparse-p
8886 (mail-header-number header)))
8887 sparse))
8888 (prog1
8889 (gnus-summary-goto-article
8890 (mail-header-number header) nil t)
8891 (when sparse
8892 (gnus-summary-update-article (mail-header-number header)))))
8893 (t
16409b0b
GM
8894 ;; We fetch the article.
8895 (catch 'found
8896 (dolist (gnus-override-method (gnus-refer-article-methods))
23f87bed
MB
8897 (when (and (gnus-check-server gnus-override-method)
8898 ;; Fetch the header,
8899 (setq number (gnus-summary-insert-subject message-id)))
8900 ;; and display the article.
eec82323 8901 (gnus-summary-select-article nil nil nil number)
16409b0b
GM
8902 (throw 'found t)))
8903 (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8904
8905(defun gnus-refer-article-methods ()
8f688cb0 8906 "Return a list of referable methods."
16409b0b
GM
8907 (cond
8908 ;; No method, so we default to current and native.
8909 ((null gnus-refer-article-method)
8910 (list gnus-current-select-method gnus-select-method))
8911 ;; Current.
8912 ((eq 'current gnus-refer-article-method)
8913 (list gnus-current-select-method))
8914 ;; List of select methods.
d4dfaa19
DL
8915 ((not (and (symbolp (car gnus-refer-article-method))
8916 (assq (car gnus-refer-article-method) nnoo-definition-alist)))
16409b0b
GM
8917 (let (out)
8918 (dolist (method gnus-refer-article-method)
8919 (push (if (eq 'current method)
8920 gnus-current-select-method
8921 method)
8922 out))
8923 (nreverse out)))
8924 ;; One single select method.
8925 (t
8926 (list gnus-refer-article-method))))
6748645f
LMI
8927
8928(defun gnus-summary-edit-parameters ()
8929 "Edit the group parameters of the current group."
8930 (interactive)
8931 (gnus-group-edit-group gnus-newsgroup-name 'params))
eec82323 8932
16409b0b
GM
8933(defun gnus-summary-customize-parameters ()
8934 "Customize the group parameters of the current group."
8935 (interactive)
8936 (gnus-group-customize gnus-newsgroup-name))
8937
eec82323
LMI
8938(defun gnus-summary-enter-digest-group (&optional force)
8939 "Enter an nndoc group based on the current article.
8940If FORCE, force a digest interpretation. If not, try
8941to guess what the document format is."
8942 (interactive "P")
eec82323 8943 (let ((conf gnus-current-window-configuration))
23f87bed
MB
8944 (save-window-excursion
8945 (save-excursion
8946 (let (gnus-article-prepare-hook
8947 gnus-display-mime-function
8948 gnus-break-pages)
8949 (gnus-summary-select-article))))
eec82323
LMI
8950 (setq gnus-current-window-configuration conf)
8951 (let* ((name (format "%s-%d"
8952 (gnus-group-prefixed-name
8953 gnus-newsgroup-name (list 'nndoc ""))
01c52d31 8954 (with-current-buffer gnus-summary-buffer
eec82323
LMI
8955 gnus-current-article)))
8956 (ogroup gnus-newsgroup-name)
8957 (params (append (gnus-info-params (gnus-get-info ogroup))
8958 (list (cons 'to-group ogroup))
23f87bed 8959 (list (cons 'parent-group ogroup))
eec82323
LMI
8960 (list (cons 'save-article-group ogroup))))
8961 (case-fold-search t)
8962 (buf (current-buffer))
16409b0b 8963 dig to-address)
c7a91ce1 8964 (with-current-buffer gnus-original-article-buffer
16409b0b
GM
8965 ;; Have the digest group inherit the main mail address of
8966 ;; the parent article.
23f87bed
MB
8967 (when (setq to-address (or (gnus-fetch-field "reply-to")
8968 (gnus-fetch-field "from")))
343d6628
MB
8969 (setq params
8970 (append
8971 (list (cons 'to-address
8972 (funcall gnus-decode-encoded-address-function
8973 to-address))))))
eec82323
LMI
8974 (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8975 (insert-buffer-substring gnus-original-article-buffer)
8976 ;; Remove lines that may lead nndoc to misinterpret the
8977 ;; document type.
8978 (narrow-to-region
8979 (goto-char (point-min))
8980 (or (search-forward "\n\n" nil t) (point)))
8981 (goto-char (point-min))
16409b0b 8982 (delete-matching-lines "^Path:\\|^From ")
eec82323
LMI
8983 (widen))
8984 (unwind-protect
23f87bed 8985 (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
16409b0b
GM
8986 (gnus-newsgroup-ephemeral-ignored-charsets
8987 gnus-newsgroup-ignored-charsets))
8988 (gnus-group-read-ephemeral-group
8989 name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8990 (nndoc-article-type
23f87bed
MB
8991 ,(if force 'mbox 'guess)))
8992 t nil nil nil
8993 `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8994 "ADAPT")))))
16409b0b 8995 ;; Make all postings to this group go to the parent group.
23f87bed
MB
8996 (nconc (gnus-info-params (gnus-get-info name))
8997 params)
8998 ;; Couldn't select this doc group.
8999 (switch-to-buffer buf)
9000 (gnus-set-global-variables)
9001 (gnus-configure-windows 'summary)
9002 (gnus-message 3 "Article couldn't be entered?"))
eec82323
LMI
9003 (kill-buffer dig)))))
9004
9005(defun gnus-summary-read-document (n)
9006 "Open a new group based on the current article(s).
9007This will allow you to read digests and other similar
9008documents as newsgroups.
9009Obeys the standard process/prefix convention."
9010 (interactive "P")
01c52d31 9011 (let* ((ogroup gnus-newsgroup-name)
eec82323
LMI
9012 (params (append (gnus-info-params (gnus-get-info ogroup))
9013 (list (cons 'to-group ogroup))))
01c52d31
MB
9014 group egroup groups vgroup)
9015 (dolist (article (gnus-summary-work-articles n))
eec82323
LMI
9016 (setq group (format "%s-%d" gnus-newsgroup-name article))
9017 (gnus-summary-remove-process-mark article)
9018 (when (gnus-summary-display-article article)
398a825b 9019 (save-excursion ;;What for?
16409b0b 9020 (with-temp-buffer
eec82323
LMI
9021 (insert-buffer-substring gnus-original-article-buffer)
9022 ;; Remove some headers that may lead nndoc to make
9023 ;; the wrong guess.
9024 (message-narrow-to-head)
9025 (goto-char (point-min))
01c52d31 9026 (delete-matching-lines "^Path:\\|^From ")
eec82323
LMI
9027 (widen)
9028 (if (setq egroup
9029 (gnus-group-read-ephemeral-group
9030 group `(nndoc ,group (nndoc-address ,(current-buffer))
9031 (nndoc-article-type guess))
9032 t nil t))
9033 (progn
c7a91ce1 9034 ;; Make all postings to this group go to the parent group.
eec82323
LMI
9035 (nconc (gnus-info-params (gnus-get-info egroup))
9036 params)
9037 (push egroup groups))
9038 ;; Couldn't select this doc group.
9039 (gnus-error 3 "Article couldn't be entered"))))))
9040 ;; Now we have selected all the documents.
9041 (cond
9042 ((not groups)
9043 (error "None of the articles could be interpreted as documents"))
9044 ((gnus-group-read-ephemeral-group
9045 (setq vgroup (format
9046 "nnvirtual:%s-%s" gnus-newsgroup-name
9047 (format-time-string "%Y%m%dT%H%M%S" (current-time))))
9048 `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
9049 t
9050 (cons (current-buffer) 'summary)))
9051 (t
9052 (error "Couldn't select virtual nndoc group")))))
9053
9054(defun gnus-summary-isearch-article (&optional regexp-p)
9055 "Do incremental search forward on the current article.
9056If REGEXP-P (the prefix) is non-nil, do regexp isearch."
9057 (interactive "P")
eec82323
LMI
9058 (gnus-summary-select-article)
9059 (gnus-configure-windows 'article)
9060 (gnus-eval-in-buffer-window gnus-article-buffer
6748645f
LMI
9061 (save-restriction
9062 (widen)
9063 (isearch-forward regexp-p))))
eec82323 9064
01c52d31
MB
9065(defun gnus-summary-repeat-search-article-forward ()
9066 "Repeat the previous search forwards."
9067 (interactive)
9068 (unless gnus-last-search-regexp
9069 (error "No previous search"))
9070 (gnus-summary-search-article-forward gnus-last-search-regexp))
9071
9072(defun gnus-summary-repeat-search-article-backward ()
9073 "Repeat the previous search backwards."
9074 (interactive)
9075 (unless gnus-last-search-regexp
9076 (error "No previous search"))
9077 (gnus-summary-search-article-forward gnus-last-search-regexp t))
9078
eec82323
LMI
9079(defun gnus-summary-search-article-forward (regexp &optional backward)
9080 "Search for an article containing REGEXP forward.
9081If BACKWARD, search backward instead."
9082 (interactive
9083 (list (read-string
9084 (format "Search article %s (regexp%s): "
9085 (if current-prefix-arg "backward" "forward")
9086 (if gnus-last-search-regexp
9087 (concat ", default " gnus-last-search-regexp)
9088 "")))
9089 current-prefix-arg))
eec82323
LMI
9090 (if (string-equal regexp "")
9091 (setq regexp (or gnus-last-search-regexp ""))
23f87bed
MB
9092 (setq gnus-last-search-regexp regexp)
9093 (setq gnus-article-before-search gnus-current-article))
9094 ;; Intentionally set gnus-last-article.
9095 (setq gnus-last-article gnus-article-before-search)
9096 (let ((gnus-last-article gnus-last-article))
9097 (if (gnus-summary-search-article regexp backward)
9098 (gnus-summary-show-thread)
abc40aab 9099 (signal 'search-failed (list regexp)))))
eec82323
LMI
9100
9101(defun gnus-summary-search-article-backward (regexp)
9102 "Search for an article containing REGEXP backward."
9103 (interactive
9104 (list (read-string
9105 (format "Search article backward (regexp%s): "
9106 (if gnus-last-search-regexp
9107 (concat ", default " gnus-last-search-regexp)
9108 "")))))
9109 (gnus-summary-search-article-forward regexp 'backward))
9110
9111(defun gnus-summary-search-article (regexp &optional backward)
9112 "Search for an article containing REGEXP.
9113Optional argument BACKWARD means do search for backward.
9114`gnus-select-article-hook' is not called during the search."
a8151ef7
LMI
9115 ;; We have to require this here to make sure that the following
9116 ;; dynamic binding isn't shadowed by autoloading.
9117 (require 'gnus-async)
16409b0b 9118 (require 'gnus-art)
eec82323 9119 (let ((gnus-select-article-hook nil) ;Disable hook.
16409b0b 9120 (gnus-article-prepare-hook nil)
eec82323
LMI
9121 (gnus-mark-article-hook nil) ;Inhibit marking as read.
9122 (gnus-use-article-prefetch nil)
9123 (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
a8151ef7 9124 (gnus-use-trees nil) ;Inhibit updating tree buffer.
23f87bed
MB
9125 (gnus-visual nil)
9126 (gnus-keep-backlog nil)
9127 (gnus-break-pages nil)
9128 (gnus-summary-display-arrow nil)
9129 (gnus-updated-mode-lines nil)
9130 (gnus-auto-center-summary nil)
eec82323 9131 (sum (current-buffer))
16409b0b 9132 (gnus-display-mime-function nil)
eec82323
LMI
9133 (found nil)
9134 point)
9135 (gnus-save-hidden-threads
9136 (gnus-summary-select-article)
9137 (set-buffer gnus-article-buffer)
16409b0b 9138 (goto-char (window-point (get-buffer-window (current-buffer))))
eec82323
LMI
9139 (when backward
9140 (forward-line -1))
9141 (while (not found)
9142 (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9143 (if (if backward
9144 (re-search-backward regexp nil t)
9145 (re-search-forward regexp nil t))
9146 ;; We found the regexp.
9147 (progn
9148 (setq found 'found)
9149 (beginning-of-line)
9150 (set-window-start
9151 (get-buffer-window (current-buffer))
9152 (point))
9153 (forward-line 1)
16409b0b
GM
9154 (set-window-point
9155 (get-buffer-window (current-buffer))
9156 (point))
eec82323
LMI
9157 (set-buffer sum)
9158 (setq point (point)))
9159 ;; We didn't find it, so we go to the next article.
9160 (set-buffer sum)
9161 (setq found 'not)
9162 (while (eq found 'not)
9163 (if (not (if backward (gnus-summary-find-prev)
9164 (gnus-summary-find-next)))
9165 ;; No more articles.
9166 (setq found t)
9167 ;; Select the next article and adjust point.
9168 (unless (gnus-summary-article-sparse-p
9169 (gnus-summary-article-number))
9170 (setq found nil)
9171 (gnus-summary-select-article)
9172 (set-buffer gnus-article-buffer)
9173 (widen)
9174 (goto-char (if backward (point-max) (point-min))))))))
9175 (gnus-message 7 ""))
9176 ;; Return whether we found the regexp.
9177 (when (eq found 'found)
9178 (goto-char point)
9179 (gnus-summary-show-thread)
9180 (gnus-summary-goto-subject gnus-current-article)
9181 (gnus-summary-position-point)
9182 t)))
9183
23f87bed
MB
9184(defun gnus-find-matching-articles (header regexp)
9185 "Return a list of all articles that match REGEXP on HEADER.
9186This search includes all articles in the current group that Gnus has
9187fetched headers for, whether they are displayed or not."
9188 (let ((articles nil)
c7a91ce1 9189 ;; Can't eta-reduce because it's a macro.
23f87bed
MB
9190 (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9191 (case-fold-search t))
9192 (dolist (header gnus-newsgroup-headers)
9193 (when (string-match regexp (funcall func header))
9194 (push (mail-header-number header) articles)))
9195 (nreverse articles)))
9196
eec82323 9197(defun gnus-summary-find-matching (header regexp &optional backward unread
47b63dfa 9198 not-case-fold not-matching)
eec82323
LMI
9199 "Return a list of all articles that match REGEXP on HEADER.
9200The search stars on the current article and goes forwards unless
9201BACKWARD is non-nil. If BACKWARD is `all', do all articles.
9202If UNREAD is non-nil, only unread articles will
9203be taken into consideration. If NOT-CASE-FOLD, case won't be folded
a1506d29 9204in the comparisons. If NOT-MATCHING, return a list of all articles that
47b63dfa
SZ
9205not match REGEXP on HEADER."
9206 (let ((case-fold-search (not not-case-fold))
16409b0b
GM
9207 articles d func)
9208 (if (consp header)
9209 (if (eq (car header) 'extra)
9210 (setq func
9211 `(lambda (h)
9212 (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9213 "")))
9214 (error "%s is an invalid header" header))
9215 (unless (fboundp (intern (concat "mail-header-" header)))
9216 (error "%s is not a valid header" header))
9217 (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
47b63dfa
SZ
9218 (dolist (d (if (eq backward 'all)
9219 gnus-newsgroup-data
9220 (gnus-data-find-list
9221 (gnus-summary-article-number)
9222 (gnus-data-list backward))))
9223 (when (and (or (not unread) ; We want all articles...
9224 (gnus-data-unread-p d)) ; Or just unreads.
9225 (vectorp (gnus-data-header d)) ; It's not a pseudo.
9226 (if not-matching
a1506d29 9227 (not (string-match
47b63dfa
SZ
9228 regexp
9229 (funcall func (gnus-data-header d))))
9230 (string-match regexp
9231 (funcall func (gnus-data-header d)))))
9232 (push (gnus-data-number d) articles))) ; Success!
eec82323
LMI
9233 (nreverse articles)))
9234
9235(defun gnus-summary-execute-command (header regexp command &optional backward)
9236 "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9237If HEADER is an empty string (or nil), the match is done on the entire
9238article. If BACKWARD (the prefix) is non-nil, search backward instead."
9239 (interactive
9240 (list (let ((completion-ignore-case t))
9241 (completing-read
9242 "Header name: "
23f87bed
MB
9243 (mapcar (lambda (header) (list (format "%s" header)))
9244 (append
9245 '("Number" "Subject" "From" "Lines" "Date"
9246 "Message-ID" "Xref" "References" "Body")
9247 gnus-extra-headers))
eec82323
LMI
9248 nil 'require-match))
9249 (read-string "Regexp: ")
9250 (read-key-sequence "Command: ")
9251 current-prefix-arg))
9252 (when (equal header "Body")
9253 (setq header ""))
eec82323
LMI
9254 ;; Hidden thread subtrees must be searched as well.
9255 (gnus-summary-show-all-threads)
9256 ;; We don't want to change current point nor window configuration.
9257 (save-excursion
9258 (save-window-excursion
23f87bed
MB
9259 (let (gnus-visual
9260 gnus-treat-strip-trailing-blank-lines
9261 gnus-treat-strip-leading-blank-lines
9262 gnus-treat-strip-multiple-blank-lines
9263 gnus-treat-hide-boring-headers
9264 gnus-treat-fold-newsgroups
9265 gnus-article-prepare-hook)
9266 (gnus-message 6 "Executing %s..." (key-description command))
9267 ;; We'd like to execute COMMAND interactively so as to give arguments.
9268 (gnus-execute header regexp
9269 `(call-interactively ',(key-binding command))
9270 backward)
9271 (gnus-message 6 "Executing %s...done" (key-description command))))))
eec82323
LMI
9272
9273(defun gnus-summary-beginning-of-article ()
9274 "Scroll the article back to the beginning."
9275 (interactive)
eec82323
LMI
9276 (gnus-summary-select-article)
9277 (gnus-configure-windows 'article)
9278 (gnus-eval-in-buffer-window gnus-article-buffer
9279 (widen)
9280 (goto-char (point-min))
23f87bed 9281 (when gnus-break-pages
eec82323
LMI
9282 (gnus-narrow-to-page))))
9283
9284(defun gnus-summary-end-of-article ()
9285 "Scroll to the end of the article."
9286 (interactive)
eec82323
LMI
9287 (gnus-summary-select-article)
9288 (gnus-configure-windows 'article)
9289 (gnus-eval-in-buffer-window gnus-article-buffer
9290 (widen)
9291 (goto-char (point-max))
9292 (recenter -3)
23f87bed 9293 (when gnus-break-pages
eec82323
LMI
9294 (gnus-narrow-to-page))))
9295
23f87bed
MB
9296(defun gnus-summary-print-truncate-and-quote (string &optional len)
9297 "Truncate to LEN and quote all \"(\"'s in STRING."
9298 (gnus-replace-in-string (if (and len (> (length string) len))
9299 (substring string 0 len)
9300 string)
9301 "[()]" "\\\\\\&"))
9302
6748645f 9303(defun gnus-summary-print-article (&optional filename n)
23f87bed
MB
9304 "Generate and print a PostScript image of the process-marked (mail) articles.
9305
9306If used interactively, print the current article if none are
9307process-marked. With prefix arg, prompt the user for the name of the
9308file to save in.
6748645f 9309
23f87bed
MB
9310When used from Lisp, accept two optional args FILENAME and N. N means
9311to print the next N articles. If N is negative, print the N previous
9312articles. If N is nil and articles have been marked with the process
9313mark, print these instead.
eec82323 9314
16409b0b 9315If the optional first argument FILENAME is nil, send the image to the
6748645f
LMI
9316printer. If FILENAME is a string, save the PostScript image in a file with
9317that name. If FILENAME is a number, prompt the user for the name of the file
eec82323 9318to save in."
676a7cc9 9319 (interactive (list (ps-print-preprint current-prefix-arg)))
6748645f
LMI
9320 (dolist (article (gnus-summary-work-articles n))
9321 (gnus-summary-select-article nil nil 'pseudo article)
9322 (gnus-eval-in-buffer-window gnus-article-buffer
23f87bed 9323 (gnus-print-buffer))
676a7cc9
SZ
9324 (gnus-summary-remove-process-mark article))
9325 (ps-despool filename))
eec82323 9326
23f87bed
MB
9327(defun gnus-print-buffer ()
9328 (let ((buffer (generate-new-buffer " *print*")))
9329 (unwind-protect
9330 (progn
9331 (copy-to-buffer buffer (point-min) (point-max))
9332 (set-buffer buffer)
9333 (gnus-remove-text-with-property 'gnus-decoration)
9334 (when (gnus-visual-p 'article-highlight 'highlight)
9335 ;; Copy-to-buffer doesn't copy overlay. So redo
9336 ;; highlight.
9337 (let ((gnus-article-buffer buffer))
9338 (gnus-article-highlight-citation t)
9339 (gnus-article-highlight-signature)
9340 (gnus-article-emphasize)
9341 (gnus-article-delete-invisible-text)))
9342 (let ((ps-left-header
9343 (list
9344 (concat "("
9345 (gnus-summary-print-truncate-and-quote
9346 (mail-header-subject gnus-current-headers)
9347 66) ")")
9348 (concat "("
9349 (gnus-summary-print-truncate-and-quote
9350 (mail-header-from gnus-current-headers)
9351 45) ")")))
9352 (ps-right-header
9353 (list
9354 "/pagenumberstring load"
9355 (concat "("
9356 (mail-header-date gnus-current-headers) ")"))))
9357 (gnus-run-hooks 'gnus-ps-print-hook)
9358 (save-excursion
a7b50e1c 9359 (if ps-print-color-p
23f87bed
MB
9360 (ps-spool-buffer-with-faces)
9361 (ps-spool-buffer)))))
9362 (kill-buffer buffer))))
9363
eec82323 9364(defun gnus-summary-show-article (&optional arg)
23f87bed 9365 "Force redisplaying of the current article.
16409b0b
GM
9366If ARG (the prefix) is a number, show the article with the charset
9367defined in `gnus-summary-show-article-charset-alist', or the charset
23f87bed 9368input.
16409b0b 9369If ARG (the prefix) is non-nil and not a number, show the raw article
23f87bed
MB
9370without any article massaging functions being run. Normally, the key
9371strokes are `C-u g'."
eec82323 9372 (interactive "P")
16409b0b
GM
9373 (cond
9374 ((numberp arg)
23f87bed 9375 (gnus-summary-show-article t)
16409b0b
GM
9376 (let ((gnus-newsgroup-charset
9377 (or (cdr (assq arg gnus-summary-show-article-charset-alist))
23f87bed
MB
9378 (mm-read-coding-system
9379 "View as charset: " ;; actually it is coding system.
01c52d31 9380 (with-current-buffer gnus-article-buffer
23f87bed 9381 (mm-detect-coding-region (point) (point-max))))))
16409b0b 9382 (gnus-newsgroup-ignored-charsets 'gnus-all))
23f87bed
MB
9383 (gnus-summary-select-article nil 'force)
9384 (let ((deps gnus-newsgroup-dependencies)
9385 head header lines)
c7a91ce1 9386 (with-current-buffer gnus-original-article-buffer
23f87bed
MB
9387 (save-restriction
9388 (message-narrow-to-head)
9389 (setq head (buffer-string))
9390 (goto-char (point-min))
9391 (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9392 (goto-char (point-max))
9393 (widen)
9394 (setq lines (1- (count-lines (point) (point-max))))))
9395 (with-temp-buffer
9396 (insert (format "211 %d Article retrieved.\n"
9397 (cdr gnus-article-current)))
9398 (insert head)
9399 (if lines (insert (format "Lines: %d\n" lines)))
9400 (insert ".\n")
9401 (let ((nntp-server-buffer (current-buffer)))
9402 (setq header (car (gnus-get-newsgroup-headers deps t))))))
9403 (gnus-data-set-header
9404 (gnus-data-find (cdr gnus-article-current))
9405 header)
9406 (gnus-summary-update-article-line
9407 (cdr gnus-article-current) header)
9408 (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9409 (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
16409b0b
GM
9410 ((not arg)
9411 ;; Select the article the normal way.
9412 (gnus-summary-select-article nil 'force))
9413 (t
9414 ;; We have to require this here to make sure that the following
9415 ;; dynamic binding isn't shadowed by autoloading.
9416 (require 'gnus-async)
9417 (require 'gnus-art)
eec82323
LMI
9418 ;; Bind the article treatment functions to nil.
9419 (let ((gnus-have-all-headers t)
eec82323 9420 gnus-article-prepare-hook
16409b0b
GM
9421 gnus-article-decode-hook
9422 gnus-display-mime-function
9423 gnus-break-pages)
9424 ;; Destroy any MIME parts.
9425 (when (gnus-buffer-live-p gnus-article-buffer)
c7a91ce1 9426 (with-current-buffer gnus-article-buffer
16409b0b
GM
9427 (mm-destroy-parts gnus-article-mime-handles)
9428 ;; Set it to nil for safety reason.
9429 (setq gnus-article-mime-handle-alist nil)
9430 (setq gnus-article-mime-handles nil)))
9431 (gnus-summary-select-article nil 'force))))
eec82323
LMI
9432 (gnus-summary-goto-subject gnus-current-article)
9433 (gnus-summary-position-point))
9434
23f87bed
MB
9435(defun gnus-summary-show-raw-article ()
9436 "Show the raw article without any article massaging functions being run."
9437 (interactive)
9438 (gnus-summary-show-article t))
9439
eec82323
LMI
9440(defun gnus-summary-verbose-headers (&optional arg)
9441 "Toggle permanent full header display.
9442If ARG is a positive number, turn header display on.
9443If ARG is a negative number, turn header display off."
9444 (interactive "P")
eec82323
LMI
9445 (setq gnus-show-all-headers
9446 (cond ((or (not (numberp arg))
9447 (zerop arg))
9448 (not gnus-show-all-headers))
9449 ((natnump arg)
9450 t)))
9451 (gnus-summary-show-article))
9452
9453(defun gnus-summary-toggle-header (&optional arg)
9454 "Show the headers if they are hidden, or hide them if they are shown.
9455If ARG is a positive number, show the entire header.
9456If ARG is a negative number, hide the unwanted header lines."
9457 (interactive "P")
23f87bed
MB
9458 (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9459 (get-buffer-window gnus-article-buffer t))))
9460 (with-current-buffer gnus-article-buffer
9461 (widen)
9462 (article-narrow-to-head)
c7a91ce1 9463 (let* ((inhibit-read-only t)
16409b0b 9464 (inhibit-point-motion-hooks t)
23f87bed
MB
9465 (hidden (if (numberp arg)
9466 (>= arg 0)
f0096211
MB
9467 (or (not (looking-at "[^ \t\n]+:"))
9468 (gnus-article-hidden-text-p 'headers))))
23f87bed
MB
9469 s e)
9470 (delete-region (point-min) (point-max))
667e0ba6
SM
9471 (with-current-buffer gnus-original-article-buffer
9472 (goto-char (setq s (point-min)))
23f87bed
MB
9473 (setq e (if (search-forward "\n\n" nil t)
9474 (1- (point))
9475 (point-max))))
667e0ba6 9476 (insert-buffer-substring gnus-original-article-buffer s e)
23f87bed
MB
9477 (run-hooks 'gnus-article-decode-hook)
9478 (if hidden
9479 (let ((gnus-treat-hide-headers nil)
9480 (gnus-treat-hide-boring-headers nil))
9481 (gnus-delete-wash-type 'headers)
9482 (gnus-treat-article 'head))
9483 (gnus-treat-article 'head))
9484 (widen)
9485 (if window
9486 (set-window-start window (goto-char (point-min))))
9487 (if gnus-break-pages
9488 (gnus-narrow-to-page)
9489 (when (gnus-visual-p 'page-marker)
c7a91ce1 9490 (let ((inhibit-read-only t))
23f87bed
MB
9491 (gnus-remove-text-with-property 'gnus-prev)
9492 (gnus-remove-text-with-property 'gnus-next))))
16409b0b 9493 (gnus-set-mode-line 'article)))))
eec82323
LMI
9494
9495(defun gnus-summary-show-all-headers ()
9496 "Make all header lines visible."
9497 (interactive)
23f87bed 9498 (gnus-summary-toggle-header 1))
eec82323 9499
eec82323
LMI
9500(defun gnus-summary-caesar-message (&optional arg)
9501 "Caesar rotate the current article by 13.
01c52d31
MB
9502With a non-numerical prefix, also rotate headers. A numerical
9503prefix specifies how many places to rotate each letter forward."
eec82323 9504 (interactive "P")
eec82323
LMI
9505 (gnus-summary-select-article)
9506 (let ((mail-header-separator ""))
9507 (gnus-eval-in-buffer-window gnus-article-buffer
9508 (save-restriction
9509 (widen)
9510 (let ((start (window-start))
c7a91ce1 9511 (inhibit-read-only t))
01c52d31
MB
9512 (if (equal arg '(4))
9513 (message-caesar-buffer-body nil t)
9514 (message-caesar-buffer-body arg))
ff4d3926
MB
9515 (set-window-start (get-buffer-window (current-buffer)) start)))))
9516 ;; Create buttons and stuff...
9517 (gnus-treat-article nil))
eec82323 9518
704f1663
GM
9519(declare-function idna-to-unicode "ext:idna" (str))
9520
01c52d31
MB
9521(defun gnus-summary-idna-message (&optional arg)
9522 "Decode IDNA encoded domain names in the current articles.
9523IDNA encoded domain names looks like `xn--bar'. If a string
9524remain unencoded after running this function, it is likely an
9525invalid IDNA string (`xn--bar' is invalid).
9526
9527You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9528installed for this command to work."
9529 (interactive "P")
9530 (if (not (and (condition-case nil (require 'idna)
9531 (file-error))
9532 (mm-coding-system-p 'utf-8)
9533 (executable-find (symbol-value 'idna-program))))
9534 (gnus-message
9535 5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9536 (gnus-summary-select-article)
9537 (let ((mail-header-separator ""))
9538 (gnus-eval-in-buffer-window gnus-article-buffer
9539 (save-restriction
9540 (widen)
9541 (let ((start (window-start))
9542 buffer-read-only)
9543 (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9544 (replace-match (idna-to-unicode (match-string 1))))
9545 (set-window-start (get-buffer-window (current-buffer)) start)))))))
23f87bed
MB
9546
9547(defun gnus-summary-morse-message (&optional arg)
9548 "Morse decode the current article."
9549 (interactive "P")
9550 (gnus-summary-select-article)
9551 (let ((mail-header-separator ""))
9552 (gnus-eval-in-buffer-window gnus-article-buffer
9553 (save-excursion
9554 (save-restriction
9555 (widen)
9556 (let ((pos (window-start))
c7a91ce1 9557 (inhibit-read-only t))
23f87bed
MB
9558 (goto-char (point-min))
9559 (when (message-goto-body)
9560 (gnus-narrow-to-body))
9561 (goto-char (point-min))
01c52d31 9562