* gnus-sum.el (gnus-summary-from-or-to-or-newsgroups): Handle case
[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,
4;; 2005 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
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 2, or (at your option)
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
eec82323
LMI
25
26;;; Commentary:
27
28;;; Code:
29
23f87bed
MB
30(eval-when-compile
31 (require 'cl)
32 (defvar tool-bar-map))
5ab7173c 33
eec82323
LMI
34(require 'gnus)
35(require 'gnus-group)
36(require 'gnus-spec)
37(require 'gnus-range)
38(require 'gnus-int)
39(require 'gnus-undo)
6748645f 40(require 'gnus-util)
16409b0b 41(require 'mm-decode)
08c9a385 42(require 'nnoo)
23f87bed 43
6748645f 44(autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
d4dfaa19 45(autoload 'gnus-cache-write-active "gnus-cache")
23f87bed
MB
46(autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
47(autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
531e5812 48(autoload 'gnus-pick-line-number "gnus-salt" nil t)
08c9a385 49(autoload 'mm-uu-dissect "mm-uu")
23f87bed
MB
50(autoload 'gnus-article-outlook-deuglify-article "deuglify"
51 "Deuglify broken Outlook (Express) articles and redisplay."
52 t)
53(autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
54(autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
55(autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
eec82323
LMI
56
57(defcustom gnus-kill-summary-on-exit t
58 "*If non-nil, kill the summary buffer when you exit from it.
59If nil, the summary will become a \"*Dead Summary*\" buffer, and
60it will be killed sometime later."
61 :group 'gnus-summary-exit
62 :type 'boolean)
63
64(defcustom gnus-fetch-old-headers nil
65 "*Non-nil means that Gnus will try to build threads by grabbing old headers.
66If an unread article in the group refers to an older, already read (or
67just marked as read) article, the old article will not normally be
1232b9cb 68displayed in the Summary buffer. If this variable is t, Gnus
eec82323 69will attempt to grab the headers to the old articles, and thereby
6748645f
LMI
70build complete threads. If it has the value `some', only enough
71headers to connect otherwise loose threads will be displayed. This
72variable can also be a number. In that case, no more than that number
73of old headers will be fetched. If it has the value `invisible', all
74old headers will be fetched, but none will be displayed.
eec82323
LMI
75
76The server has to support NOV for any of this to work."
77 :group 'gnus-thread
78 :type '(choice (const :tag "off" nil)
1232b9cb 79 (const :tag "on" t)
eec82323 80 (const some)
1232b9cb 81 (const invisible)
eec82323
LMI
82 number
83 (sexp :menu-tag "other" t)))
84
6748645f
LMI
85(defcustom gnus-refer-thread-limit 200
86 "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
87If t, fetch all the available old headers."
88 :group 'gnus-thread
89 :type '(choice number
90 (sexp :menu-tag "other" t)))
91
eec82323
LMI
92(defcustom gnus-summary-make-false-root 'adopt
93 "*nil means that Gnus won't gather loose threads.
94If the root of a thread has expired or been read in a previous
95session, the information necessary to build a complete thread has been
96lost. Instead of having many small sub-threads from this original thread
97scattered all over the summary buffer, Gnus can gather them.
98
99If non-nil, Gnus will try to gather all loose sub-threads from an
100original thread into one large thread.
101
102If this variable is non-nil, it should be one of `none', `adopt',
103`dummy' or `empty'.
104
105If this variable is `none', Gnus will not make a false root, but just
106present the sub-threads after another.
107If this variable is `dummy', Gnus will create a dummy root that will
108have all the sub-threads as children.
109If this variable is `adopt', Gnus will make one of the \"children\"
110the parent and mark all the step-children as such.
111If this variable is `empty', the \"children\" are printed with empty
112subject fields. (Or rather, they will be printed with a string
113given by the `gnus-summary-same-subject' variable.)"
114 :group 'gnus-thread
115 :type '(choice (const :tag "off" nil)
116 (const none)
117 (const dummy)
118 (const adopt)
119 (const empty)))
120
23f87bed
MB
121(defcustom gnus-summary-make-false-root-always nil
122 "Always make a false dummy root."
bf247b6e 123 :version "22.1"
23f87bed
MB
124 :group 'gnus-thread
125 :type 'boolean)
126
eec82323
LMI
127(defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
128 "*A regexp to match subjects to be excluded from loose thread gathering.
129As loose thread gathering is done on subjects only, that means that
130there can be many false gatherings performed. By rooting out certain
131common subjects, gathering might become saner."
132 :group 'gnus-thread
133 :type 'regexp)
134
135(defcustom gnus-summary-gather-subject-limit nil
136 "*Maximum length of subject comparisons when gathering loose threads.
137Use nil to compare full subjects. Setting this variable to a low
138number will help gather threads that have been corrupted by
139newsreaders chopping off subject lines, but it might also mean that
140unrelated articles that have subject that happen to begin with the
141same few characters will be incorrectly gathered.
142
143If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
144comparing subjects."
145 :group 'gnus-thread
146 :type '(choice (const :tag "off" nil)
147 (const fuzzy)
148 (sexp :menu-tag "on" t)))
149
6748645f
LMI
150(defcustom gnus-simplify-subject-functions nil
151 "List of functions taking a string argument that simplify subjects.
152The functions are applied recursively.
153
23f87bed
MB
154Useful functions to put in this list include:
155`gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
156`gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
6748645f
LMI
157 :group 'gnus-thread
158 :type '(repeat function))
159
eec82323 160(defcustom gnus-simplify-ignored-prefixes nil
23f87bed 161 "*Remove matches for this regexp from subject lines when simplifying fuzzily."
eec82323
LMI
162 :group 'gnus-thread
163 :type '(choice (const :tag "off" nil)
164 regexp))
165
166(defcustom gnus-build-sparse-threads nil
167 "*If non-nil, fill in the gaps in threads.
168If `some', only fill in the gaps that are needed to tie loose threads
169together. If `more', fill in all leaf nodes that Gnus can find. If
170non-nil and non-`some', fill in all gaps that Gnus manages to guess."
171 :group 'gnus-thread
172 :type '(choice (const :tag "off" nil)
173 (const some)
174 (const more)
175 (sexp :menu-tag "all" t)))
176
177(defcustom gnus-summary-thread-gathering-function
178 'gnus-gather-threads-by-subject
6748645f 179 "*Function used for gathering loose threads.
eec82323
LMI
180There are two pre-defined functions: `gnus-gather-threads-by-subject',
181which only takes Subjects into consideration; and
182`gnus-gather-threads-by-references', which compared the References
183headers of the articles to find matches."
184 :group 'gnus-thread
22115a9e
RS
185 :type '(radio (function-item gnus-gather-threads-by-subject)
186 (function-item gnus-gather-threads-by-references)
187 (function :tag "other")))
eec82323 188
eec82323
LMI
189(defcustom gnus-summary-same-subject ""
190 "*String indicating that the current article has the same subject as the previous.
191This variable will only be used if the value of
192`gnus-summary-make-false-root' is `empty'."
193 :group 'gnus-summary-format
194 :type 'string)
195
196(defcustom gnus-summary-goto-unread t
16409b0b
GM
197 "*If t, many commands will go to the next unread article.
198This applies to marking commands as well as other commands that
199\"naturally\" select the next article, like, for instance, `SPC' at
200the end of an article.
201
202If nil, the marking commands do NOT go to the next unread article
2642ac8f 203\(they go to the next article instead). If `never', commands that
16409b0b
GM
204usually go to the next unread article, will go to the next article,
205whether it is read or not."
eec82323
LMI
206 :group 'gnus-summary-marks
207 :link '(custom-manual "(gnus)Setting Marks")
208 :type '(choice (const :tag "off" nil)
209 (const never)
210 (sexp :menu-tag "on" t)))
211
212(defcustom gnus-summary-default-score 0
213 "*Default article score level.
214All scores generated by the score files will be added to this score.
215If this variable is nil, scoring will be disabled."
216 :group 'gnus-score-default
217 :type '(choice (const :tag "disable")
218 integer))
219
23f87bed
MB
220(defcustom gnus-summary-default-high-score 0
221 "*Default threshold for a high scored article.
222An article will be highlighted as high scored if its score is greater
223than this score."
bf247b6e 224 :version "22.1"
23f87bed
MB
225 :group 'gnus-score-default
226 :type 'integer)
227
228(defcustom gnus-summary-default-low-score 0
229 "*Default threshold for a low scored article.
230An article will be highlighted as low scored if its score is smaller
231than this score."
bf247b6e 232 :version "22.1"
23f87bed
MB
233 :group 'gnus-score-default
234 :type 'integer)
235
eec82323
LMI
236(defcustom gnus-summary-zcore-fuzz 0
237 "*Fuzziness factor for the zcore in the summary buffer.
238Articles with scores closer than this to `gnus-summary-default-score'
239will not be marked."
240 :group 'gnus-summary-format
241 :type 'integer)
242
243(defcustom gnus-simplify-subject-fuzzy-regexp nil
244 "*Strings to be removed when doing fuzzy matches.
245This can either be a regular expression or list of regular expressions
246that will be removed from subject strings if fuzzy subject
247simplification is selected."
248 :group 'gnus-thread
249 :type '(repeat regexp))
250
251(defcustom gnus-show-threads t
252 "*If non-nil, display threads in summary mode."
253 :group 'gnus-thread
254 :type 'boolean)
255
256(defcustom gnus-thread-hide-subtree nil
257 "*If non-nil, hide all threads initially.
23f87bed 258This can be a predicate specifier which says which threads to hide.
eec82323 259If threads are hidden, you have to run the command
4a2358e9 260`gnus-summary-show-thread' by hand or select an article."
eec82323 261 :group 'gnus-thread
23f87bed
MB
262 :type '(radio (sexp :format "Non-nil\n"
263 :match (lambda (widget value)
264 (not (or (consp value) (functionp value))))
265 :value t)
266 (const nil)
ad136a7c 267 (sexp :tag "Predicate specifier")))
eec82323
LMI
268
269(defcustom gnus-thread-hide-killed t
270 "*If non-nil, hide killed threads automatically."
271 :group 'gnus-thread
272 :type 'boolean)
273
6748645f
LMI
274(defcustom gnus-thread-ignore-subject t
275 "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
276If nil, articles that have different subjects from their parents will
277start separate threads."
eec82323
LMI
278 :group 'gnus-thread
279 :type 'boolean)
280
281(defcustom gnus-thread-operation-ignore-subject t
282 "*If non-nil, subjects will be ignored when doing thread commands.
283This affects commands like `gnus-summary-kill-thread' and
284`gnus-summary-lower-thread'.
285
286If this variable is nil, articles in the same thread with different
287subjects will not be included in the operation in question. If this
288variable is `fuzzy', only articles that have subjects that are fuzzily
289equal will be included."
290 :group 'gnus-thread
291 :type '(choice (const :tag "off" nil)
292 (const fuzzy)
293 (sexp :tag "on" t)))
294
295(defcustom gnus-thread-indent-level 4
296 "*Number that says how much each sub-thread should be indented."
297 :group 'gnus-thread
298 :type 'integer)
299
300(defcustom gnus-auto-extend-newsgroup t
301 "*If non-nil, extend newsgroup forward and backward when requested."
302 :group 'gnus-summary-choose
303 :type 'boolean)
304
305(defcustom gnus-auto-select-first t
23f87bed
MB
306 "*If non-nil, select the article under point.
307Which article this is is controlled by the `gnus-auto-select-subject'
308variable.
309
310If you want to prevent automatic selection of articles in some
311newsgroups, set the variable to nil in `gnus-select-group-hook'."
eec82323
LMI
312 :group 'gnus-group-select
313 :type '(choice (const :tag "none" nil)
23f87bed
MB
314 (sexp :menu-tag "first" t)))
315
316(defcustom gnus-auto-select-subject 'unread
317 "*Says what subject to place under point when entering a group.
318
319This variable can either be the symbols `first' (place point on the
320first subject), `unread' (place point on the subject line of the first
321unread article), `best' (place point on the subject line of the
322higest-scored article), `unseen' (place point on the subject line of
99b5aab7 323the first unseen article), `unseen-or-unread' (place point on the subject
23f87bed
MB
324line of the first unseen article or, if all article have been seen, on the
325subject line of the first unread article), or a function to be called to
326place point on some subject line."
bf247b6e 327 :version "22.1"
23f87bed
MB
328 :group 'gnus-group-select
329 :type '(choice (const best)
330 (const unread)
331 (const first)
332 (const unseen)
333 (const unseen-or-unread)))
eec82323
LMI
334
335(defcustom gnus-auto-select-next t
336 "*If non-nil, offer to go to the next group from the end of the previous.
337If the value is t and the next newsgroup is empty, Gnus will exit
23f87bed
MB
338summary mode and go back to group mode. If the value is neither nil
339nor t, Gnus will select the following unread newsgroup. In
eec82323
LMI
340particular, if the value is the symbol `quietly', the next unread
341newsgroup will be selected without any confirmation, and if it is
342`almost-quietly', the next group will be selected without any
343confirmation if you are located on the last article in the group.
23f87bed 344Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
eec82323
LMI
345will go to the next group without confirmation."
346 :group 'gnus-summary-maneuvering
347 :type '(choice (const :tag "off" nil)
348 (const quietly)
349 (const almost-quietly)
350 (const slightly-quietly)
351 (sexp :menu-tag "on" t)))
352
353(defcustom gnus-auto-select-same nil
6748645f
LMI
354 "*If non-nil, select the next article with the same subject.
355If there are no more articles with the same subject, go to
356the first unread article."
eec82323
LMI
357 :group 'gnus-summary-maneuvering
358 :type 'boolean)
359
23f87bed
MB
360(defcustom gnus-auto-goto-ignores 'unfetched
361 "*Says how to handle unfetched articles when maneuvering.
362
363This variable can either be the symbols nil (maneuver to any
364article), `undownloaded' (maneuvering while unplugged ignores articles
365that have not been fetched), `always-undownloaded' (maneuvering always
366ignores articles that have not been fetched), `unfetched' (maneuvering
367ignores articles whose headers have not been fetched).
368
369NOTE: The list of unfetched articles will always be nil when plugged
370and, when unplugged, a subset of the undownloaded article list."
bf247b6e 371 :version "22.1"
23f87bed
MB
372 :group 'gnus-summary-maneuvering
373 :type '(choice (const :tag "None" nil)
374 (const :tag "Undownloaded when unplugged" undownloaded)
375 (const :tag "Undownloaded" always-undownloaded)
376 (const :tag "Unfetched" unfetched)))
377
eec82323
LMI
378(defcustom gnus-summary-check-current nil
379 "*If non-nil, consider the current article when moving.
380The \"unread\" movement commands will stay on the same line if the
381current article is unread."
382 :group 'gnus-summary-maneuvering
383 :type 'boolean)
384
385(defcustom gnus-auto-center-summary t
386 "*If non-nil, always center the current summary buffer.
387In particular, if `vertical' do only vertical recentering. If non-nil
388and non-`vertical', do both horizontal and vertical recentering."
389 :group 'gnus-summary-maneuvering
390 :type '(choice (const :tag "none" nil)
391 (const vertical)
16409b0b 392 (integer :tag "height")
eec82323
LMI
393 (sexp :menu-tag "both" t)))
394
23f87bed
MB
395(defvar gnus-auto-center-group t
396 "*If non-nil, always center the group buffer.")
397
eec82323
LMI
398(defcustom gnus-show-all-headers nil
399 "*If non-nil, don't hide any headers."
400 :group 'gnus-article-hiding
401 :group 'gnus-article-headers
402 :type 'boolean)
403
404(defcustom gnus-summary-ignore-duplicates nil
405 "*If non-nil, ignore articles with identical Message-ID headers."
406 :group 'gnus-summary
407 :type 'boolean)
6748645f 408
eec82323
LMI
409(defcustom gnus-single-article-buffer t
410 "*If non-nil, display all articles in the same buffer.
411If nil, each group will get its own article buffer."
412 :group 'gnus-article-various
413 :type 'boolean)
414
415(defcustom gnus-break-pages t
416 "*If non-nil, do page breaking on articles.
417The page delimiter is specified by the `gnus-page-delimiter'
418variable."
419 :group 'gnus-article-various
420 :type 'boolean)
421
eec82323
LMI
422(defcustom gnus-move-split-methods nil
423 "*Variable used to suggest where articles are to be moved to.
23f87bed
MB
424It uses the same syntax as the `gnus-split-methods' variable.
425However, whereas `gnus-split-methods' specifies file names as targets,
426this variable specifies group names."
eec82323 427 :group 'gnus-summary-mail
6748645f
LMI
428 :type '(repeat (choice (list :value (fun) function)
429 (cons :value ("" "") regexp (repeat string))
430 (sexp :value nil))))
eec82323 431
e62e7654
MB
432;; FIXME: Although the custom type is `character' for the following variables,
433;; using multibyte characters (Latin-1, UTF-8) doesn't work. -- rs
434
23f87bed 435(defcustom gnus-unread-mark ? ;Whitespace
eec82323
LMI
436 "*Mark used for unread articles."
437 :group 'gnus-summary-marks
438 :type 'character)
439
440(defcustom gnus-ticked-mark ?!
441 "*Mark used for ticked articles."
442 :group 'gnus-summary-marks
443 :type 'character)
444
445(defcustom gnus-dormant-mark ??
446 "*Mark used for dormant articles."
447 :group 'gnus-summary-marks
448 :type 'character)
449
450(defcustom gnus-del-mark ?r
451 "*Mark used for del'd articles."
452 :group 'gnus-summary-marks
453 :type 'character)
454
455(defcustom gnus-read-mark ?R
456 "*Mark used for read articles."
457 :group 'gnus-summary-marks
458 :type 'character)
459
460(defcustom gnus-expirable-mark ?E
461 "*Mark used for expirable articles."
462 :group 'gnus-summary-marks
463 :type 'character)
464
465(defcustom gnus-killed-mark ?K
466 "*Mark used for killed articles."
467 :group 'gnus-summary-marks
468 :type 'character)
469
23f87bed
MB
470(defcustom gnus-spam-mark ?$
471 "*Mark used for spam articles."
bf247b6e 472 :version "22.1"
23f87bed
MB
473 :group 'gnus-summary-marks
474 :type 'character)
475
eec82323 476(defcustom gnus-souped-mark ?F
23f87bed 477 "*Mark used for souped articles."
eec82323
LMI
478 :group 'gnus-summary-marks
479 :type 'character)
480
481(defcustom gnus-kill-file-mark ?X
482 "*Mark used for articles killed by kill files."
483 :group 'gnus-summary-marks
484 :type 'character)
485
486(defcustom gnus-low-score-mark ?Y
487 "*Mark used for articles with a low score."
488 :group 'gnus-summary-marks
489 :type 'character)
490
491(defcustom gnus-catchup-mark ?C
492 "*Mark used for articles that are caught up."
493 :group 'gnus-summary-marks
494 :type 'character)
495
496(defcustom gnus-replied-mark ?A
497 "*Mark used for articles that have been replied to."
498 :group 'gnus-summary-marks
499 :type 'character)
500
23f87bed
MB
501(defcustom gnus-forwarded-mark ?F
502 "*Mark used for articles that have been forwarded."
bf247b6e 503 :version "22.1"
23f87bed
MB
504 :group 'gnus-summary-marks
505 :type 'character)
506
507(defcustom gnus-recent-mark ?N
508 "*Mark used for articles that are recent."
bf247b6e 509 :version "22.1"
23f87bed
MB
510 :group 'gnus-summary-marks
511 :type 'character)
512
eec82323
LMI
513(defcustom gnus-cached-mark ?*
514 "*Mark used for articles that are in the cache."
515 :group 'gnus-summary-marks
516 :type 'character)
517
518(defcustom gnus-saved-mark ?S
23f87bed
MB
519 "*Mark used for articles that have been saved."
520 :group 'gnus-summary-marks
521 :type 'character)
522
523(defcustom gnus-unseen-mark ?.
524 "*Mark used for articles that haven't been seen."
bf247b6e 525 :version "22.1"
23f87bed
MB
526 :group 'gnus-summary-marks
527 :type 'character)
528
529(defcustom gnus-no-mark ? ;Whitespace
530 "*Mark used for articles that have no other secondary mark."
bf247b6e 531 :version "22.1"
eec82323
LMI
532 :group 'gnus-summary-marks
533 :type 'character)
534
535(defcustom gnus-ancient-mark ?O
536 "*Mark used for ancient articles."
537 :group 'gnus-summary-marks
538 :type 'character)
539
540(defcustom gnus-sparse-mark ?Q
541 "*Mark used for sparsely reffed articles."
542 :group 'gnus-summary-marks
543 :type 'character)
544
545(defcustom gnus-canceled-mark ?G
546 "*Mark used for canceled articles."
547 :group 'gnus-summary-marks
548 :type 'character)
549
550(defcustom gnus-duplicate-mark ?M
551 "*Mark used for duplicate articles."
552 :group 'gnus-summary-marks
553 :type 'character)
554
23f87bed 555(defcustom gnus-undownloaded-mark ?-
6748645f 556 "*Mark used for articles that weren't downloaded."
bf247b6e 557 :version "22.1"
6748645f
LMI
558 :group 'gnus-summary-marks
559 :type 'character)
560
23f87bed
MB
561(defcustom gnus-downloaded-mark ?+
562 "*Mark used for articles that were downloaded."
563 :group 'gnus-summary-marks
564 :type 'character)
565
6748645f
LMI
566(defcustom gnus-downloadable-mark ?%
567 "*Mark used for articles that are to be downloaded."
568 :group 'gnus-summary-marks
569 :type 'character)
570
571(defcustom gnus-unsendable-mark ?=
572 "*Mark used for articles that won't be sent."
573 :group 'gnus-summary-marks
574 :type 'character)
575
eec82323
LMI
576(defcustom gnus-score-over-mark ?+
577 "*Score mark used for articles with high scores."
578 :group 'gnus-summary-marks
579 :type 'character)
580
581(defcustom gnus-score-below-mark ?-
582 "*Score mark used for articles with low scores."
583 :group 'gnus-summary-marks
584 :type 'character)
585
23f87bed 586(defcustom gnus-empty-thread-mark ? ;Whitespace
eec82323
LMI
587 "*There is no thread under the article."
588 :group 'gnus-summary-marks
589 :type 'character)
590
591(defcustom gnus-not-empty-thread-mark ?=
592 "*There is a thread under the article."
593 :group 'gnus-summary-marks
594 :type 'character)
595
596(defcustom gnus-view-pseudo-asynchronously nil
597 "*If non-nil, Gnus will view pseudo-articles asynchronously."
598 :group 'gnus-extract-view
599 :type 'boolean)
600
16409b0b
GM
601(defcustom gnus-auto-expirable-marks
602 (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
603 gnus-low-score-mark gnus-ancient-mark gnus-read-mark
604 gnus-souped-mark gnus-duplicate-mark)
605 "*The list of marks converted into expiration if a group is auto-expirable."
58e39d05 606 :version "21.1"
16409b0b
GM
607 :group 'gnus-summary
608 :type '(repeat character))
609
610(defcustom gnus-inhibit-user-auto-expire t
611 "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
58e39d05 612 :version "21.1"
16409b0b
GM
613 :group 'gnus-summary
614 :type 'boolean)
615
eec82323
LMI
616(defcustom gnus-view-pseudos nil
617 "*If `automatic', pseudo-articles will be viewed automatically.
618If `not-confirm', pseudos will be viewed automatically, and the user
619will not be asked to confirm the command."
620 :group 'gnus-extract-view
621 :type '(choice (const :tag "off" nil)
622 (const automatic)
623 (const not-confirm)))
624
625(defcustom gnus-view-pseudos-separately t
626 "*If non-nil, one pseudo-article will be created for each file to be viewed.
627If nil, all files that use the same viewing command will be given as a
628list of parameters to that command."
629 :group 'gnus-extract-view
630 :type 'boolean)
631
632(defcustom gnus-insert-pseudo-articles t
633 "*If non-nil, insert pseudo-articles when decoding articles."
634 :group 'gnus-extract-view
635 :type 'boolean)
636
637(defcustom gnus-summary-dummy-line-format
23f87bed 638 " %(: :%) %S\n"
eec82323
LMI
639 "*The format specification for the dummy roots in the summary buffer.
640It works along the same lines as a normal formatting string,
641with some simple extensions.
642
23f87bed
MB
643%S The subject
644
645General format specifiers can also be used.
646See `(gnus)Formatting Variables'."
647 :link '(custom-manual "(gnus)Formatting Variables")
eec82323
LMI
648 :group 'gnus-threading
649 :type 'string)
650
16409b0b 651(defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
eec82323
LMI
652 "*The format specification for the summary mode line.
653It works along the same lines as a normal formatting string,
654with some simple extensions:
655
656%G Group name
657%p Unprefixed group name
658%A Current article number
6748645f 659%z Current article score
eec82323
LMI
660%V Gnus version
661%U Number of unread articles in the group
662%e Number of unselected articles in the group
663%Z A string with unread/unselected article counts
664%g Shortish group name
665%S Subject of the current article
666%u User-defined spec
667%s Current score file name
668%d Number of dormant articles
669%r Number of articles that have been marked as read in this session
670%E Number of articles expunged by the score files"
671 :group 'gnus-summary-format
672 :type 'string)
673
16409b0b
GM
674(defcustom gnus-list-identifiers nil
675 "Regexp that matches list identifiers to be removed from subject.
676This can also be a list of regexps."
58e39d05 677 :version "21.1"
16409b0b
GM
678 :group 'gnus-summary-format
679 :group 'gnus-article-hiding
680 :type '(choice (const :tag "none" nil)
681 (regexp :value ".*")
682 (repeat :value (".*") regexp)))
683
eec82323
LMI
684(defcustom gnus-summary-mark-below 0
685 "*Mark all articles with a score below this variable as read.
686This variable is local to each summary buffer and usually set by the
687score file."
688 :group 'gnus-score-default
689 :type 'integer)
690
691(defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
692 "*List of functions used for sorting articles in the summary buffer.
23f87bed
MB
693
694Each function takes two articles and returns non-nil if the first
695article should be sorted before the other. If you use more than one
696function, the primary sort function should be the last. You should
697probably always include `gnus-article-sort-by-number' in the list of
698sorting functions -- preferably first. Also note that sorting by date
699is often much slower than sorting by number, and the sorting order is
700very similar. (Sorting by date means sorting by the time the message
701was sent, sorting by number means sorting by arrival time.)
702
703Ready-made functions include `gnus-article-sort-by-number',
704`gnus-article-sort-by-author', `gnus-article-sort-by-subject',
705`gnus-article-sort-by-date', `gnus-article-sort-by-random'
706and `gnus-article-sort-by-score'.
707
708When threading is turned on, the variable `gnus-thread-sort-functions'
709controls how articles are sorted."
eec82323
LMI
710 :group 'gnus-summary-sort
711 :type '(repeat (choice (function-item gnus-article-sort-by-number)
712 (function-item gnus-article-sort-by-author)
713 (function-item gnus-article-sort-by-subject)
714 (function-item gnus-article-sort-by-date)
715 (function-item gnus-article-sort-by-score)
23f87bed 716 (function-item gnus-article-sort-by-random)
eec82323
LMI
717 (function :tag "other"))))
718
719(defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
720 "*List of functions used for sorting threads in the summary buffer.
721By default, threads are sorted by article number.
722
23f87bed
MB
723Each function takes two threads and returns non-nil if the first
724thread should be sorted before the other. If you use more than one
725function, the primary sort function should be the last. You should
726probably always include `gnus-thread-sort-by-number' in the list of
727sorting functions -- preferably first. Also note that sorting by date
728is often much slower than sorting by number, and the sorting order is
729very similar. (Sorting by date means sorting by the time the message
730was sent, sorting by number means sorting by arrival time.)
eec82323
LMI
731
732Ready-made functions include `gnus-thread-sort-by-number',
733`gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
23f87bed
MB
734`gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
735`gnus-thread-sort-by-most-recent-number',
736`gnus-thread-sort-by-most-recent-date',
737`gnus-thread-sort-by-random', and
738`gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
739
740When threading is turned off, the variable
741`gnus-article-sort-functions' controls how articles are sorted."
eec82323
LMI
742 :group 'gnus-summary-sort
743 :type '(repeat (choice (function-item gnus-thread-sort-by-number)
744 (function-item gnus-thread-sort-by-author)
745 (function-item gnus-thread-sort-by-subject)
746 (function-item gnus-thread-sort-by-date)
747 (function-item gnus-thread-sort-by-score)
748 (function-item gnus-thread-sort-by-total-score)
23f87bed 749 (function-item gnus-thread-sort-by-random)
eec82323
LMI
750 (function :tag "other"))))
751
752(defcustom gnus-thread-score-function '+
753 "*Function used for calculating the total score of a thread.
754
755The function is called with the scores of the article and each
756subthread and should then return the score of the thread.
757
758Some functions you can use are `+', `max', or `min'."
759 :group 'gnus-summary-sort
760 :type 'function)
761
762(defcustom gnus-summary-expunge-below nil
6748645f
LMI
763 "All articles that have a score less than this variable will be expunged.
764This variable is local to the summary buffers."
eec82323
LMI
765 :group 'gnus-score-default
766 :type '(choice (const :tag "off" nil)
767 integer))
768
769(defcustom gnus-thread-expunge-below nil
770 "All threads that have a total score less than this variable will be expunged.
771See `gnus-thread-score-function' for en explanation of what a
6748645f
LMI
772\"thread score\" is.
773
774This variable is local to the summary buffers."
16409b0b 775 :group 'gnus-threading
eec82323
LMI
776 :group 'gnus-score-default
777 :type '(choice (const :tag "off" nil)
778 integer))
779
780(defcustom gnus-summary-mode-hook nil
781 "*A hook for Gnus summary mode.
782This hook is run before any variables are set in the summary buffer."
23f87bed 783 :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
eec82323
LMI
784 :group 'gnus-summary-various
785 :type 'hook)
786
23f87bed
MB
787;; Extracted from gnus-xmas-redefine in order to preserve user settings
788(when (featurep 'xemacs)
789 (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
790 (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
791 (add-hook 'gnus-summary-mode-hook
792 'gnus-xmas-switch-horizontal-scrollbar-off))
793
eec82323
LMI
794(defcustom gnus-summary-menu-hook nil
795 "*Hook run after the creation of the summary mode menu."
796 :group 'gnus-summary-visual
797 :type 'hook)
798
799(defcustom gnus-summary-exit-hook nil
800 "*A hook called on exit from the summary buffer.
801It will be called with point in the group buffer."
802 :group 'gnus-summary-exit
803 :type 'hook)
804
805(defcustom gnus-summary-prepare-hook nil
806 "*A hook called after the summary buffer has been generated.
807If you want to modify the summary buffer, you can use this hook."
808 :group 'gnus-summary-various
809 :type 'hook)
810
6748645f
LMI
811(defcustom gnus-summary-prepared-hook nil
812 "*A hook called as the last thing after the summary buffer has been generated."
813 :group 'gnus-summary-various
814 :type 'hook)
815
eec82323
LMI
816(defcustom gnus-summary-generate-hook nil
817 "*A hook run just before generating the summary buffer.
818This hook is commonly used to customize threading variables and the
819like."
820 :group 'gnus-summary-various
821 :type 'hook)
822
823(defcustom gnus-select-group-hook nil
824 "*A hook called when a newsgroup is selected.
825
826If you'd like to simplify subjects like the
827`gnus-summary-next-same-subject' command does, you can use the
828following hook:
829
23f87bed
MB
830 (add-hook gnus-select-group-hook
831 (lambda ()
832 (mapcar (lambda (header)
833 (mail-header-set-subject
834 header
835 (gnus-simplify-subject
836 (mail-header-subject header) 're-only)))
837 gnus-newsgroup-headers)))"
eec82323
LMI
838 :group 'gnus-group-select
839 :type 'hook)
840
841(defcustom gnus-select-article-hook nil
842 "*A hook called when an article is selected."
843 :group 'gnus-summary-choose
23f87bed 844 :options '(gnus-agent-fetch-selected-article)
eec82323
LMI
845 :type 'hook)
846
847(defcustom gnus-visual-mark-article-hook
848 (list 'gnus-highlight-selected-summary)
849 "*Hook run after selecting an article in the summary buffer.
850It is meant to be used for highlighting the article in some way. It
851is not run if `gnus-visual' is nil."
852 :group 'gnus-summary-visual
853 :type 'hook)
854
16409b0b 855(defcustom gnus-parse-headers-hook nil
eec82323
LMI
856 "*A hook called before parsing the headers."
857 :group 'gnus-various
858 :type 'hook)
859
860(defcustom gnus-exit-group-hook nil
16409b0b
GM
861 "*A hook called when exiting summary mode.
862This hook is not called from the non-updating exit commands like `Q'."
eec82323
LMI
863 :group 'gnus-various
864 :type 'hook)
865
866(defcustom gnus-summary-update-hook
867 (list 'gnus-summary-highlight-line)
868 "*A hook called when a summary line is changed.
869The hook will not be called if `gnus-visual' is nil.
870
871The default function `gnus-summary-highlight-line' will
872highlight the line according to the `gnus-summary-highlight'
873variable."
874 :group 'gnus-summary-visual
875 :type 'hook)
876
877(defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
878 "*A hook called when an article is selected for the first time.
879The hook is intended to mark an article as read (or unread)
880automatically when it is selected."
881 :group 'gnus-summary-choose
882 :type 'hook)
883
884(defcustom gnus-group-no-more-groups-hook nil
885 "*A hook run when returning to group mode having no more (unread) groups."
886 :group 'gnus-group-select
887 :type 'hook)
888
889(defcustom gnus-ps-print-hook nil
890 "*A hook run before ps-printing something from Gnus."
891 :group 'gnus-summary
892 :type 'hook)
893
23f87bed
MB
894(defcustom gnus-summary-article-move-hook nil
895 "*A hook called after an article is moved, copied, respooled, or crossposted."
bf247b6e 896 :version "22.1"
23f87bed
MB
897 :group 'gnus-summary
898 :type 'hook)
899
900(defcustom gnus-summary-article-delete-hook nil
901 "*A hook called after an article is deleted."
bf247b6e 902 :version "22.1"
23f87bed
MB
903 :group 'gnus-summary
904 :type 'hook)
905
906(defcustom gnus-summary-article-expire-hook nil
907 "*A hook called after an article is expired."
bf247b6e 908 :version "22.1"
23f87bed
MB
909 :group 'gnus-summary
910 :type 'hook)
911
912(defcustom gnus-summary-display-arrow
913 (and (fboundp 'display-graphic-p)
914 (display-graphic-p))
915 "*If non-nil, display an arrow highlighting the current article."
bf247b6e 916 :version "22.1"
23f87bed
MB
917 :group 'gnus-summary
918 :type 'boolean)
919
0f49874b 920(defcustom gnus-summary-selected-face 'gnus-summary-selected
eec82323
LMI
921 "Face used for highlighting the current article in the summary buffer."
922 :group 'gnus-summary-visual
923 :type 'face)
924
23f87bed
MB
925(defvar gnus-tmp-downloaded nil)
926
eec82323 927(defcustom gnus-summary-highlight
23f87bed 928 '(((eq mark gnus-canceled-mark)
0f49874b 929 . gnus-summary-cancelled)
23f87bed 930 ((and uncached (> score default-high))
0f49874b 931 . gnus-summary-high-undownloaded)
23f87bed 932 ((and uncached (< score default-low))
0f49874b 933 . gnus-summary-low-undownloaded)
23f87bed 934 (uncached
0f49874b 935 . gnus-summary-normal-undownloaded)
23f87bed
MB
936 ((and (> score default-high)
937 (or (eq mark gnus-dormant-mark)
938 (eq mark gnus-ticked-mark)))
0f49874b 939 . gnus-summary-high-ticked)
23f87bed
MB
940 ((and (< score default-low)
941 (or (eq mark gnus-dormant-mark)
942 (eq mark gnus-ticked-mark)))
0f49874b 943 . gnus-summary-low-ticked)
23f87bed
MB
944 ((or (eq mark gnus-dormant-mark)
945 (eq mark gnus-ticked-mark))
0f49874b 946 . gnus-summary-normal-ticked)
23f87bed 947 ((and (> score default-high) (eq mark gnus-ancient-mark))
0f49874b 948 . gnus-summary-high-ancient)
23f87bed 949 ((and (< score default-low) (eq mark gnus-ancient-mark))
0f49874b 950 . gnus-summary-low-ancient)
23f87bed 951 ((eq mark gnus-ancient-mark)
0f49874b 952 . gnus-summary-normal-ancient)
23f87bed 953 ((and (> score default-high) (eq mark gnus-unread-mark))
0f49874b 954 . gnus-summary-high-unread)
23f87bed 955 ((and (< score default-low) (eq mark gnus-unread-mark))
0f49874b 956 . gnus-summary-low-unread)
23f87bed 957 ((eq mark gnus-unread-mark)
0f49874b 958 . gnus-summary-normal-unread)
23f87bed 959 ((> score default-high)
0f49874b 960 . gnus-summary-high-read)
23f87bed 961 ((< score default-low)
0f49874b 962 . gnus-summary-low-read)
eec82323 963 (t
0f49874b 964 . gnus-summary-normal-read))
6748645f 965 "*Controls the highlighting of summary buffer lines.
eec82323 966
23f87bed
MB
967A list of (FORM . FACE) pairs. When deciding how a a particular
968summary line should be displayed, each form is evaluated. The content
969of the face field after the first true form is used. You can change
970how those summary lines are displayed, by editing the face field.
eec82323
LMI
971
972You can use the following variables in the FORM field.
973
23f87bed
MB
974score: The article's score
975default: The default article score.
976default-high: The default score for high scored articles.
977default-low: The default score for low scored articles.
978below: The score below which articles are automatically marked as read.
979mark: The article's mark.
980uncached: Non-nil if the article is uncached."
eec82323
LMI
981 :group 'gnus-summary-visual
982 :type '(repeat (cons (sexp :tag "Form" nil)
983 face)))
984
6748645f
LMI
985(defcustom gnus-alter-header-function nil
986 "Function called to allow alteration of article header structures.
987The function is called with one parameter, the article header vector,
0ab0f2d3
SZ
988which it may alter in any way."
989 :type '(choice (const :tag "None" nil)
990 function)
991 :group 'gnus-summary)
eec82323 992
16409b0b
GM
993(defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
994 "Variable that says which function should be used to decode a string with encoded words.")
995
23f87bed 996(defcustom gnus-extra-headers '(To Newsgroups)
16409b0b 997 "*Extra headers to parse."
58e39d05 998 :version "21.1"
16409b0b
GM
999 :group 'gnus-summary
1000 :type '(repeat symbol))
1001
1002(defcustom gnus-ignored-from-addresses
1003 (and user-mail-address (regexp-quote user-mail-address))
1004 "*Regexp of From headers that may be suppressed in favor of To headers."
58e39d05 1005 :version "21.1"
16409b0b
GM
1006 :group 'gnus-summary
1007 :type 'regexp)
1008
16409b0b
GM
1009(defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1010 "List of charsets that should be ignored.
1011When these charsets are used in the \"charset\" parameter, the
1012default charset will be used instead."
58e39d05 1013 :version "21.1"
16409b0b
GM
1014 :type '(repeat symbol)
1015 :group 'gnus-charset)
1016
23f87bed
MB
1017(gnus-define-group-parameter
1018 ignored-charsets
1019 :type list
1020 :function-document
1021 "Return the ignored charsets of GROUP."
1022 :variable gnus-group-ignored-charsets-alist
1023 :variable-default
1024 '(("alt\\.chinese\\.text" iso-8859-1))
1025 :variable-document
1026 "Alist of regexps (to match group names) and charsets that should be ignored.
16409b0b
GM
1027When these charsets are used in the \"charset\" parameter, the
1028default charset will be used instead."
23f87bed
MB
1029 :variable-group gnus-charset
1030 :variable-type '(repeat (cons (regexp :tag "Group")
1031 (repeat symbol)))
1032 :parameter-type '(choice :tag "Ignored charsets"
1033 :value nil
1034 (repeat (symbol)))
1035 :parameter-document "\
1036List of charsets that should be ignored.
1037
1038When these charsets are used in the \"charset\" parameter, the
1039default charset will be used instead.")
16409b0b
GM
1040
1041(defcustom gnus-group-highlight-words-alist nil
1042 "Alist of group regexps and highlight regexps.
1043This variable uses the same syntax as `gnus-emphasis-alist'."
58e39d05 1044 :version "21.1"
16409b0b
GM
1045 :type '(repeat (cons (regexp :tag "Group")
1046 (repeat (list (regexp :tag "Highlight regexp")
1047 (number :tag "Group for entire word" 0)
1048 (number :tag "Group for displayed part" 0)
1049 (symbol :tag "Face"
1050 gnus-emphasis-highlight-words)))))
1051 :group 'gnus-summary-visual)
1052
1053(defcustom gnus-summary-show-article-charset-alist
1054 nil
1055 "Alist of number and charset.
1056The article will be shown with the charset corresponding to the
1057numbered argument.
1058For example: ((1 . cn-gb-2312) (2 . big5))."
58e39d05 1059 :version "21.1"
16409b0b
GM
1060 :type '(repeat (cons (number :tag "Argument" 1)
1061 (symbol :tag "Charset")))
1062 :group 'gnus-charset)
1063
1064(defcustom gnus-preserve-marks t
1065 "Whether marks are preserved when moving, copying and respooling messages."
58e39d05 1066 :version "21.1"
16409b0b
GM
1067 :type 'boolean
1068 :group 'gnus-summary-marks)
1069
1070(defcustom gnus-alter-articles-to-read-function nil
1071 "Function to be called to alter the list of articles to be selected."
8fc7a9a1 1072 :type '(choice (const nil) function)
16409b0b
GM
1073 :group 'gnus-summary)
1074
1075(defcustom gnus-orphan-score nil
1076 "*All orphans get this score added. Set in the score file."
1077 :group 'gnus-score-default
1078 :type '(choice (const nil)
1079 integer))
1080
8b93df01 1081(defcustom gnus-summary-save-parts-default-mime "image/.*"
23f87bed
MB
1082 "*A regexp to match MIME parts when saving multiple parts of a
1083message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1084This regexp will be used by default when prompting the user for which
1085type of files to save."
8b93df01
DL
1086 :group 'gnus-summary
1087 :type 'regexp)
1088
23f87bed
MB
1089(defcustom gnus-read-all-available-headers nil
1090 "Whether Gnus should parse all headers made available to it.
1091This is mostly relevant for slow back ends where the user may
1092wish to widen the summary buffer to include all headers
1093that were fetched. Say, for nnultimate groups."
bf247b6e 1094 :version "22.1"
23f87bed
MB
1095 :group 'gnus-summary
1096 :type '(choice boolean regexp))
1097
1098(defcustom gnus-summary-muttprint-program "muttprint"
1099 "Command (and optional arguments) used to run Muttprint."
bf247b6e 1100 :version "22.1"
23f87bed
MB
1101 :group 'gnus-summary
1102 :type 'string)
1103
1104(defcustom gnus-article-loose-mime nil
1105 "If non-nil, don't require MIME-Version header.
1106Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
a08b59c9 1107supply the MIME-Version header or deliberately strip it from the mail.
23f87bed
MB
1108Set it to non-nil, Gnus will treat some articles as MIME even if
1109the MIME-Version header is missed."
bf247b6e 1110 :version "22.1"
23f87bed
MB
1111 :type 'boolean
1112 :group 'gnus-article-mime)
1113
1114(defcustom gnus-article-emulate-mime t
1115 "If non-nil, use MIME emulation for uuencode and the like.
1116This means that Gnus will search message bodies for text that look
1117like uuencoded bits, yEncoded bits, and so on, and present that using
1118the normal Gnus MIME machinery."
bf247b6e 1119 :version "22.1"
23f87bed
MB
1120 :type 'boolean
1121 :group 'gnus-article-mime)
8b93df01 1122
eec82323
LMI
1123;;; Internal variables
1124
23f87bed 1125(defvar gnus-summary-display-cache nil)
16409b0b
GM
1126(defvar gnus-article-mime-handles nil)
1127(defvar gnus-article-decoded-p nil)
23f87bed
MB
1128(defvar gnus-article-charset nil)
1129(defvar gnus-article-ignored-charsets nil)
eec82323
LMI
1130(defvar gnus-scores-exclude-files nil)
1131(defvar gnus-page-broken nil)
1132
1133(defvar gnus-original-article nil)
1134(defvar gnus-article-internal-prepare-hook nil)
1135(defvar gnus-newsgroup-process-stack nil)
1136
1137(defvar gnus-thread-indent-array nil)
1138(defvar gnus-thread-indent-array-level gnus-thread-indent-level)
16409b0b
GM
1139(defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1140 "Function called to sort the articles within a thread after it has been gathered together.")
eec82323 1141
8b93df01 1142(defvar gnus-summary-save-parts-type-history nil)
23f87bed 1143(defvar gnus-summary-save-parts-last-directory mm-default-directory)
8b93df01 1144
eec82323
LMI
1145;; Avoid highlighting in kill files.
1146(defvar gnus-summary-inhibit-highlight nil)
1147(defvar gnus-newsgroup-selected-overlay nil)
1148(defvar gnus-inhibit-limiting nil)
1149(defvar gnus-newsgroup-adaptive-score-file nil)
1150(defvar gnus-current-score-file nil)
1151(defvar gnus-current-move-group nil)
1152(defvar gnus-current-copy-group nil)
1153(defvar gnus-current-crosspost-group nil)
23f87bed 1154(defvar gnus-newsgroup-display nil)
eec82323
LMI
1155
1156(defvar gnus-newsgroup-dependencies nil)
1157(defvar gnus-newsgroup-adaptive nil)
1158(defvar gnus-summary-display-article-function nil)
1159(defvar gnus-summary-highlight-line-function nil
1160 "Function called after highlighting a summary line.")
1161
1162(defvar gnus-summary-line-format-alist
1163 `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1164 (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1165 (?s gnus-tmp-subject-or-nil ?s)
1166 (?n gnus-tmp-name ?s)
1167 (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1168 ?s)
1169 (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1170 gnus-tmp-from) ?s)
1171 (?F gnus-tmp-from ?s)
1172 (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1173 (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1174 (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
6748645f 1175 (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
eec82323
LMI
1176 (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1177 (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1178 (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
23f87bed
MB
1179 (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1180 (?L gnus-tmp-lines ?s)
1181 (?O gnus-tmp-downloaded ?c)
eec82323
LMI
1182 (?I gnus-tmp-indentation ?s)
1183 (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1184 (?R gnus-tmp-replied ?c)
1185 (?\[ gnus-tmp-opening-bracket ?c)
1186 (?\] gnus-tmp-closing-bracket ?c)
1187 (?\> (make-string gnus-tmp-level ? ) ?s)
1188 (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1189 (?i gnus-tmp-score ?d)
1190 (?z gnus-tmp-score-char ?c)
1191 (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1192 (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1193 (?U gnus-tmp-unread ?c)
23f87bed
MB
1194 (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1195 ?s)
eec82323
LMI
1196 (?t (gnus-summary-number-of-articles-in-thread
1197 (and (boundp 'thread) (car thread)) gnus-tmp-level)
1198 ?d)
1199 (?e (gnus-summary-number-of-articles-in-thread
1200 (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1201 ?c)
1202 (?u gnus-tmp-user-defined ?s)
23f87bed
MB
1203 (?P (gnus-pick-line-number) ?d)
1204 (?B gnus-tmp-thread-tree-header-string ?s)
1205 (user-date (gnus-user-date
1206 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
16409b0b
GM
1207 "An alist of format specifications that can appear in summary lines.
1208These are paired with what variables they correspond with, along with
1209the type of the variable (string, integer, character, etc).")
eec82323
LMI
1210
1211(defvar gnus-summary-dummy-line-format-alist
1212 `((?S gnus-tmp-subject ?s)
1213 (?N gnus-tmp-number ?d)
1214 (?u gnus-tmp-user-defined ?s)))
1215
1216(defvar gnus-summary-mode-line-format-alist
1217 `((?G gnus-tmp-group-name ?s)
1218 (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1219 (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1220 (?A gnus-tmp-article-number ?d)
1221 (?Z gnus-tmp-unread-and-unselected ?s)
1222 (?V gnus-version ?s)
1223 (?U gnus-tmp-unread-and-unticked ?d)
1224 (?S gnus-tmp-subject ?s)
1225 (?e gnus-tmp-unselected ?d)
1226 (?u gnus-tmp-user-defined ?s)
1227 (?d (length gnus-newsgroup-dormant) ?d)
1228 (?t (length gnus-newsgroup-marked) ?d)
23f87bed 1229 (?h (length gnus-newsgroup-spam-marked) ?d)
eec82323 1230 (?r (length gnus-newsgroup-reads) ?d)
6748645f 1231 (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
eec82323
LMI
1232 (?E gnus-newsgroup-expunged-tally ?d)
1233 (?s (gnus-current-score-file-nondirectory) ?s)))
1234
1235(defvar gnus-last-search-regexp nil
1236 "Default regexp for article search command.")
1237
1238(defvar gnus-last-shell-command nil
1239 "Default shell command on article.")
1240
23f87bed
MB
1241(defvar gnus-newsgroup-agentized nil
1242 "Locally bound in each summary buffer to indicate whether the server has been agentized.")
eec82323
LMI
1243(defvar gnus-newsgroup-begin nil)
1244(defvar gnus-newsgroup-end nil)
1245(defvar gnus-newsgroup-last-rmail nil)
1246(defvar gnus-newsgroup-last-mail nil)
1247(defvar gnus-newsgroup-last-folder nil)
1248(defvar gnus-newsgroup-last-file nil)
1249(defvar gnus-newsgroup-auto-expire nil)
1250(defvar gnus-newsgroup-active nil)
1251
1252(defvar gnus-newsgroup-data nil)
1253(defvar gnus-newsgroup-data-reverse nil)
1254(defvar gnus-newsgroup-limit nil)
1255(defvar gnus-newsgroup-limits nil)
23f87bed 1256(defvar gnus-summary-use-undownloaded-faces nil)
eec82323
LMI
1257
1258(defvar gnus-newsgroup-unreads nil
23f87bed 1259 "Sorted list of unread articles in the current newsgroup.")
eec82323
LMI
1260
1261(defvar gnus-newsgroup-unselected nil
23f87bed 1262 "Sorted list of unselected unread articles in the current newsgroup.")
eec82323
LMI
1263
1264(defvar gnus-newsgroup-reads nil
1265 "Alist of read articles and article marks in the current newsgroup.")
1266
1267(defvar gnus-newsgroup-expunged-tally nil)
1268
1269(defvar gnus-newsgroup-marked nil
23f87bed
MB
1270 "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1271
1272(defvar gnus-newsgroup-spam-marked nil
1273 "List of ranges of articles that have been marked as spam.")
eec82323
LMI
1274
1275(defvar gnus-newsgroup-killed nil
1276 "List of ranges of articles that have been through the scoring process.")
1277
1278(defvar gnus-newsgroup-cached nil
23f87bed 1279 "Sorted list of articles that come from the article cache.")
eec82323
LMI
1280
1281(defvar gnus-newsgroup-saved nil
1282 "List of articles that have been saved.")
1283
1284(defvar gnus-newsgroup-kill-headers nil)
1285
1286(defvar gnus-newsgroup-replied nil
1287 "List of articles that have been replied to in the current newsgroup.")
1288
23f87bed
MB
1289(defvar gnus-newsgroup-forwarded nil
1290 "List of articles that have been forwarded in the current newsgroup.")
1291
1292(defvar gnus-newsgroup-recent nil
1293 "List of articles that have are recent in the current newsgroup.")
1294
eec82323 1295(defvar gnus-newsgroup-expirable nil
23f87bed 1296 "Sorted list of articles in the current newsgroup that can be expired.")
eec82323
LMI
1297
1298(defvar gnus-newsgroup-processable nil
1299 "List of articles in the current newsgroup that can be processed.")
1300
6748645f 1301(defvar gnus-newsgroup-downloadable nil
23f87bed
MB
1302 "Sorted list of articles in the current newsgroup that can be processed.")
1303
1304(defvar gnus-newsgroup-unfetched nil
1305 "Sorted list of articles in the current newsgroup whose headers have
1306not been fetched into the agent.
1307
1308This list will always be a subset of gnus-newsgroup-undownloaded.")
6748645f
LMI
1309
1310(defvar gnus-newsgroup-undownloaded nil
23f87bed 1311 "List of articles in the current newsgroup that haven't been downloaded.")
6748645f
LMI
1312
1313(defvar gnus-newsgroup-unsendable nil
1314 "List of articles in the current newsgroup that won't be sent.")
1315
eec82323
LMI
1316(defvar gnus-newsgroup-bookmarks nil
1317 "List of articles in the current newsgroup that have bookmarks.")
1318
1319(defvar gnus-newsgroup-dormant nil
23f87bed
MB
1320 "Sorted list of dormant articles in the current newsgroup.")
1321
1322(defvar gnus-newsgroup-unseen nil
1323 "List of unseen articles in the current newsgroup.")
1324
1325(defvar gnus-newsgroup-seen nil
1326 "Range of seen articles in the current newsgroup.")
1327
1328(defvar gnus-newsgroup-articles nil
1329 "List of articles in the current newsgroup.")
eec82323
LMI
1330
1331(defvar gnus-newsgroup-scored nil
1332 "List of scored articles in the current newsgroup.")
1333
1334(defvar gnus-newsgroup-headers nil
1335 "List of article headers in the current newsgroup.")
1336
1337(defvar gnus-newsgroup-threads nil)
1338
1339(defvar gnus-newsgroup-prepared nil
1340 "Whether the current group has been prepared properly.")
1341
1342(defvar gnus-newsgroup-ancient nil
1343 "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1344
1345(defvar gnus-newsgroup-sparse nil)
1346
1347(defvar gnus-current-article nil)
1348(defvar gnus-article-current nil)
1349(defvar gnus-current-headers nil)
1350(defvar gnus-have-all-headers nil)
1351(defvar gnus-last-article nil)
1352(defvar gnus-newsgroup-history nil)
16409b0b
GM
1353(defvar gnus-newsgroup-charset nil)
1354(defvar gnus-newsgroup-ephemeral-charset nil)
1355(defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
eec82323 1356
23f87bed
MB
1357(defvar gnus-article-before-search nil)
1358
1359(defvar gnus-summary-local-variables
eec82323
LMI
1360 '(gnus-newsgroup-name
1361 gnus-newsgroup-begin gnus-newsgroup-end
1362 gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1363 gnus-newsgroup-last-folder gnus-newsgroup-last-file
1364 gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1365 gnus-newsgroup-unselected gnus-newsgroup-marked
23f87bed 1366 gnus-newsgroup-spam-marked
eec82323 1367 gnus-newsgroup-reads gnus-newsgroup-saved
23f87bed
MB
1368 gnus-newsgroup-replied gnus-newsgroup-forwarded
1369 gnus-newsgroup-recent
1370 gnus-newsgroup-expirable
eec82323 1371 gnus-newsgroup-processable gnus-newsgroup-killed
6748645f 1372 gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
23f87bed
MB
1373 gnus-newsgroup-unfetched
1374 gnus-newsgroup-unsendable gnus-newsgroup-unseen
1375 gnus-newsgroup-seen gnus-newsgroup-articles
eec82323
LMI
1376 gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1377 gnus-newsgroup-headers gnus-newsgroup-threads
1378 gnus-newsgroup-prepared gnus-summary-highlight-line-function
1379 gnus-current-article gnus-current-headers gnus-have-all-headers
1380 gnus-last-article gnus-article-internal-prepare-hook
1381 gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1382 gnus-newsgroup-scored gnus-newsgroup-kill-headers
1383 gnus-thread-expunge-below
16409b0b
GM
1384 gnus-score-alist gnus-current-score-file
1385 (gnus-summary-expunge-below . global)
eec82323 1386 (gnus-summary-mark-below . global)
16409b0b 1387 (gnus-orphan-score . global)
eec82323
LMI
1388 gnus-newsgroup-active gnus-scores-exclude-files
1389 gnus-newsgroup-history gnus-newsgroup-ancient
1390 gnus-newsgroup-sparse gnus-newsgroup-process-stack
1391 (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1392 gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1393 (gnus-newsgroup-expunged-tally . 0)
1394 gnus-cache-removable-articles gnus-newsgroup-cached
1395 gnus-newsgroup-data gnus-newsgroup-data-reverse
16409b0b 1396 gnus-newsgroup-limit gnus-newsgroup-limits
23f87bed
MB
1397 gnus-newsgroup-charset gnus-newsgroup-display
1398 gnus-summary-use-undownloaded-faces)
eec82323
LMI
1399 "Variables that are buffer-local to the summary buffers.")
1400
23f87bed
MB
1401(defvar gnus-newsgroup-variables nil
1402 "A list of variables that have separate values in different newsgroups.
1403A list of newsgroup (summary buffer) local variables, or cons of
1404variables and their default expressions to be evalled (when the default
1405values are not nil), that should be made global while the summary buffer
1406is active.
1407
1408Note: The default expressions will be evaluated (using function `eval')
1409before assignment to the local variable rather than just assigned to it.
1410If the default expression is the symbol `global', that symbol will not
1411be evaluated but the global value of the local variable will be used
1412instead.
1413
1414These variables can be used to set variables in the group parameters
1415while still allowing them to affect operations done in other buffers.
1416For example:
1417
1418\(setq gnus-newsgroup-variables
1419 '(message-use-followup-to
1420 (gnus-visible-headers .
1421 \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1422")
1423
eec82323 1424;; Byte-compiler warning.
23f87bed
MB
1425(eval-when-compile
1426 ;; Bind features so that require will believe that gnus-sum has
1427 ;; already been loaded (avoids infinite recursion)
1428 (let ((features (cons 'gnus-sum features)))
1429 ;; Several of the declarations in gnus-sum are needed to load the
1430 ;; following files. Right now, these definitions have been
1431 ;; compiled but not defined (evaluated). We could either do a
1432 ;; eval-and-compile about all of the declarations or evaluate the
1433 ;; source file.
1434 (if (boundp 'gnus-newsgroup-variables)
1435 nil
1436 (load "gnus-sum.el" t t t))
1437 (require 'gnus)
1438 (require 'gnus-agent)
1439 (require 'gnus-art)))
eec82323 1440
16409b0b
GM
1441;; MIME stuff.
1442
1443(defvar gnus-decode-encoded-word-methods
1444 '(mail-decode-encoded-word-string)
1445 "List of methods used to decode encoded words.
1446
23f87bed
MB
1447This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
1448is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
1449\(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
16409b0b
GM
1450whose names match REGEXP.
1451
1452For example:
23f87bed 1453\((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
16409b0b
GM
1454 mail-decode-encoded-word-string
1455 (\"chinese\" . rfc1843-decode-string))")
1456
1457(defvar gnus-decode-encoded-word-methods-cache nil)
1458
1459(defun gnus-multi-decode-encoded-word-string (string)
1460 "Apply the functions from `gnus-encoded-word-methods' that match."
1461 (unless (and gnus-decode-encoded-word-methods-cache
1462 (eq gnus-newsgroup-name
1463 (car gnus-decode-encoded-word-methods-cache)))
1464 (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1465 (mapcar (lambda (x)
1466 (if (symbolp x)
1467 (nconc gnus-decode-encoded-word-methods-cache (list x))
1468 (if (and gnus-newsgroup-name
1469 (string-match (car x) gnus-newsgroup-name))
1470 (nconc gnus-decode-encoded-word-methods-cache
1471 (list (cdr x))))))
23f87bed 1472 gnus-decode-encoded-word-methods))
16409b0b
GM
1473 (let ((xlist gnus-decode-encoded-word-methods-cache))
1474 (pop xlist)
1475 (while xlist
1476 (setq string (funcall (pop xlist) string))))
1477 string)
1478
eec82323
LMI
1479;; Subject simplification.
1480
6748645f 1481(defun gnus-simplify-whitespace (str)
16409b0b 1482 "Remove excessive whitespace from STR."
23f87bed
MB
1483 ;; Multiple spaces.
1484 (while (string-match "[ \t][ \t]+" str)
1485 (setq str (concat (substring str 0 (match-beginning 0))
1486 " "
1487 (substring str (match-end 0)))))
1488 ;; Leading spaces.
1489 (when (string-match "^[ \t]+" str)
1490 (setq str (substring str (match-end 0))))
1491 ;; Trailing spaces.
1492 (when (string-match "[ \t]+$" str)
1493 (setq str (substring str 0 (match-beginning 0))))
1494 str)
1495
1496(defun gnus-simplify-all-whitespace (str)
1497 "Remove all whitespace from STR."
1498 (while (string-match "[ \t\n]+" str)
1499 (setq str (replace-match "" nil nil str)))
1500 str)
6748645f 1501
eec82323
LMI
1502(defsubst gnus-simplify-subject-re (subject)
1503 "Remove \"Re:\" from subject lines."
23f87bed 1504 (if (string-match message-subject-re-regexp subject)
eec82323
LMI
1505 (substring subject (match-end 0))
1506 subject))
1507
1508(defun gnus-simplify-subject (subject &optional re-only)
1509 "Remove `Re:' and words in parentheses.
1510If RE-ONLY is non-nil, strip leading `Re:'s only."
1511 (let ((case-fold-search t)) ;Ignore case.
1512 ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1513 (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1514 (setq subject (substring subject (match-end 0))))
1515 ;; Remove uninteresting prefixes.
1516 (when (and (not re-only)
1517 gnus-simplify-ignored-prefixes
1518 (string-match gnus-simplify-ignored-prefixes subject))
1519 (setq subject (substring subject (match-end 0))))
1520 ;; Remove words in parentheses from end.
1521 (unless re-only
1522 (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1523 (setq subject (substring subject 0 (match-beginning 0)))))
1524 ;; Return subject string.
1525 subject))
1526
1527;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1528;; all whitespace.
1529(defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1530 (goto-char (point-min))
1531 (while (re-search-forward regexp nil t)
16409b0b 1532 (replace-match (or newtext ""))))
eec82323
LMI
1533
1534(defun gnus-simplify-buffer-fuzzy ()
1535 "Simplify string in the buffer fuzzily.
1536The string in the accessible portion of the current buffer is simplified.
1537It is assumed to be a single-line subject.
1538Whitespace is generally cleaned up, and miscellaneous leading/trailing
1539matter is removed. Additional things can be deleted by setting
16409b0b 1540`gnus-simplify-subject-fuzzy-regexp'."
eec82323
LMI
1541 (let ((case-fold-search t)
1542 (modified-tick))
1543 (gnus-simplify-buffer-fuzzy-step "\t" " ")
1544
1545 (while (not (eq modified-tick (buffer-modified-tick)))
1546 (setq modified-tick (buffer-modified-tick))
1547 (cond
1548 ((listp gnus-simplify-subject-fuzzy-regexp)
1549 (mapcar 'gnus-simplify-buffer-fuzzy-step
1550 gnus-simplify-subject-fuzzy-regexp))
1551 (gnus-simplify-subject-fuzzy-regexp
1552 (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1553 (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1554 (gnus-simplify-buffer-fuzzy-step
1555 "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1556 (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1557
1558 (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1559 (gnus-simplify-buffer-fuzzy-step " +" " ")
1560 (gnus-simplify-buffer-fuzzy-step " $")
1561 (gnus-simplify-buffer-fuzzy-step "^ +")))
1562
1563(defun gnus-simplify-subject-fuzzy (subject)
1564 "Simplify a subject string fuzzily.
6748645f 1565See `gnus-simplify-buffer-fuzzy' for details."
eec82323
LMI
1566 (save-excursion
1567 (gnus-set-work-buffer)
1568 (let ((case-fold-search t))
6748645f
LMI
1569 ;; Remove uninteresting prefixes.
1570 (when (and gnus-simplify-ignored-prefixes
1571 (string-match gnus-simplify-ignored-prefixes subject))
1572 (setq subject (substring subject (match-end 0))))
eec82323
LMI
1573 (insert subject)
1574 (inline (gnus-simplify-buffer-fuzzy))
1575 (buffer-string))))
1576
1577(defsubst gnus-simplify-subject-fully (subject)
23f87bed 1578 "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
eec82323 1579 (cond
6748645f
LMI
1580 (gnus-simplify-subject-functions
1581 (gnus-map-function gnus-simplify-subject-functions subject))
eec82323
LMI
1582 ((null gnus-summary-gather-subject-limit)
1583 (gnus-simplify-subject-re subject))
1584 ((eq gnus-summary-gather-subject-limit 'fuzzy)
1585 (gnus-simplify-subject-fuzzy subject))
1586 ((numberp gnus-summary-gather-subject-limit)
1587 (gnus-limit-string (gnus-simplify-subject-re subject)
1588 gnus-summary-gather-subject-limit))
1589 (t
1590 subject)))
1591
1592(defsubst gnus-subject-equal (s1 s2 &optional simple-first)
6748645f 1593 "Check whether two subjects are equal.
23f87bed 1594If optional argument SIMPLE-FIRST is t, first argument is already
6748645f 1595simplified."
eec82323
LMI
1596 (cond
1597 ((null simple-first)
1598 (equal (gnus-simplify-subject-fully s1)
1599 (gnus-simplify-subject-fully s2)))
1600 (t
1601 (equal s1
1602 (gnus-simplify-subject-fully s2)))))
1603
1604(defun gnus-summary-bubble-group ()
1605 "Increase the score of the current group.
1606This is a handy function to add to `gnus-summary-exit-hook' to
1607increase the score of each group you read."
1608 (gnus-group-add-score gnus-newsgroup-name))
1609
1610\f
1611;;;
1612;;; Gnus summary mode
1613;;;
1614
1615(put 'gnus-summary-mode 'mode-class 'special)
1616
1653df0f
SZ
1617(defvar gnus-article-commands-menu)
1618
23f87bed
MB
1619;; Non-orthogonal keys
1620
1621(gnus-define-keys gnus-summary-mode-map
1622 " " gnus-summary-next-page
1623 "\177" gnus-summary-prev-page
1624 [delete] gnus-summary-prev-page
1625 [backspace] gnus-summary-prev-page
1626 "\r" gnus-summary-scroll-up
1627 "\M-\r" gnus-summary-scroll-down
1628 "n" gnus-summary-next-unread-article
1629 "p" gnus-summary-prev-unread-article
1630 "N" gnus-summary-next-article
1631 "P" gnus-summary-prev-article
1632 "\M-\C-n" gnus-summary-next-same-subject
1633 "\M-\C-p" gnus-summary-prev-same-subject
1634 "\M-n" gnus-summary-next-unread-subject
1635 "\M-p" gnus-summary-prev-unread-subject
1636 "." gnus-summary-first-unread-article
1637 "," gnus-summary-best-unread-article
1638 "\M-s" gnus-summary-search-article-forward
1639 "\M-r" gnus-summary-search-article-backward
1640 "<" gnus-summary-beginning-of-article
1641 ">" gnus-summary-end-of-article
1642 "j" gnus-summary-goto-article
1643 "^" gnus-summary-refer-parent-article
1644 "\M-^" gnus-summary-refer-article
1645 "u" gnus-summary-tick-article-forward
1646 "!" gnus-summary-tick-article-forward
1647 "U" gnus-summary-tick-article-backward
1648 "d" gnus-summary-mark-as-read-forward
1649 "D" gnus-summary-mark-as-read-backward
1650 "E" gnus-summary-mark-as-expirable
1651 "\M-u" gnus-summary-clear-mark-forward
1652 "\M-U" gnus-summary-clear-mark-backward
1653 "k" gnus-summary-kill-same-subject-and-select
1654 "\C-k" gnus-summary-kill-same-subject
1655 "\M-\C-k" gnus-summary-kill-thread
1656 "\M-\C-l" gnus-summary-lower-thread
1657 "e" gnus-summary-edit-article
1658 "#" gnus-summary-mark-as-processable
1659 "\M-#" gnus-summary-unmark-as-processable
1660 "\M-\C-t" gnus-summary-toggle-threads
1661 "\M-\C-s" gnus-summary-show-thread
1662 "\M-\C-h" gnus-summary-hide-thread
1663 "\M-\C-f" gnus-summary-next-thread
1664 "\M-\C-b" gnus-summary-prev-thread
1665 [(meta down)] gnus-summary-next-thread
1666 [(meta up)] gnus-summary-prev-thread
1667 "\M-\C-u" gnus-summary-up-thread
1668 "\M-\C-d" gnus-summary-down-thread
1669 "&" gnus-summary-execute-command
1670 "c" gnus-summary-catchup-and-exit
1671 "\C-w" gnus-summary-mark-region-as-read
1672 "\C-t" gnus-summary-toggle-truncation
1673 "?" gnus-summary-mark-as-dormant
1674 "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1675 "\C-c\C-s\C-n" gnus-summary-sort-by-number
1676 "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1677 "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1678 "\C-c\C-s\C-a" gnus-summary-sort-by-author
1679 "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1680 "\C-c\C-s\C-d" gnus-summary-sort-by-date
1681 "\C-c\C-s\C-i" gnus-summary-sort-by-score
1682 "\C-c\C-s\C-o" gnus-summary-sort-by-original
1683 "\C-c\C-s\C-r" gnus-summary-sort-by-random
1684 "=" gnus-summary-expand-window
1685 "\C-x\C-s" gnus-summary-reselect-current-group
1686 "\M-g" gnus-summary-rescan-group
1687 "w" gnus-summary-stop-page-breaking
1688 "\C-c\C-r" gnus-summary-caesar-message
1689 "f" gnus-summary-followup
1690 "F" gnus-summary-followup-with-original
1691 "C" gnus-summary-cancel-article
1692 "r" gnus-summary-reply
1693 "R" gnus-summary-reply-with-original
1694 "\C-c\C-f" gnus-summary-mail-forward
1695 "o" gnus-summary-save-article
1696 "\C-o" gnus-summary-save-article-mail
1697 "|" gnus-summary-pipe-output
1698 "\M-k" gnus-summary-edit-local-kill
1699 "\M-K" gnus-summary-edit-global-kill
1700 ;; "V" gnus-version
1701 "\C-c\C-d" gnus-summary-describe-group
1702 "q" gnus-summary-exit
1703 "Q" gnus-summary-exit-no-update
1704 "\C-c\C-i" gnus-info-find-node
1705 gnus-mouse-2 gnus-mouse-pick-article
132cf96d 1706 [follow-link] mouse-face
23f87bed
MB
1707 "m" gnus-summary-mail-other-window
1708 "a" gnus-summary-post-news
1709 "i" gnus-summary-news-other-window
1710 "x" gnus-summary-limit-to-unread
1711 "s" gnus-summary-isearch-article
1712 "t" gnus-summary-toggle-header
1713 "g" gnus-summary-show-article
1714 "l" gnus-summary-goto-last-article
1715 "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1716 "\C-d" gnus-summary-enter-digest-group
1717 "\M-\C-d" gnus-summary-read-document
1718 "\M-\C-e" gnus-summary-edit-parameters
1719 "\M-\C-a" gnus-summary-customize-parameters
1720 "\C-c\C-b" gnus-bug
1721 "*" gnus-cache-enter-article
1722 "\M-*" gnus-cache-remove-article
1723 "\M-&" gnus-summary-universal-argument
1724 "\C-l" gnus-recenter
1725 "I" gnus-summary-increase-score
1726 "L" gnus-summary-lower-score
1727 "\M-i" gnus-symbolic-argument
1728 "h" gnus-summary-select-article-buffer
1729
1730 "b" gnus-article-view-part
1731 "\M-t" gnus-summary-toggle-display-buttonized
1732
1733 "V" gnus-summary-score-map
1734 "X" gnus-uu-extract-map
1735 "S" gnus-summary-send-map)
1736
1737;; Sort of orthogonal keymap
1738(gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1739 "t" gnus-summary-tick-article-forward
1740 "!" gnus-summary-tick-article-forward
1741 "d" gnus-summary-mark-as-read-forward
1742 "r" gnus-summary-mark-as-read-forward
1743 "c" gnus-summary-clear-mark-forward
1744 " " gnus-summary-clear-mark-forward
1745 "e" gnus-summary-mark-as-expirable
1746 "x" gnus-summary-mark-as-expirable
1747 "?" gnus-summary-mark-as-dormant
1748 "b" gnus-summary-set-bookmark
1749 "B" gnus-summary-remove-bookmark
1750 "#" gnus-summary-mark-as-processable
1751 "\M-#" gnus-summary-unmark-as-processable
1752 "S" gnus-summary-limit-include-expunged
1753 "C" gnus-summary-catchup
1754 "H" gnus-summary-catchup-to-here
1755 "h" gnus-summary-catchup-from-here
1756 "\C-c" gnus-summary-catchup-all
1757 "k" gnus-summary-kill-same-subject-and-select
1758 "K" gnus-summary-kill-same-subject
1759 "P" gnus-uu-mark-map)
1760
1761(gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1762 "c" gnus-summary-clear-above
1763 "u" gnus-summary-tick-above
1764 "m" gnus-summary-mark-above
1765 "k" gnus-summary-kill-below)
1766
1767(gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1768 "/" gnus-summary-limit-to-subject
1769 "n" gnus-summary-limit-to-articles
1770 "w" gnus-summary-pop-limit
1771 "s" gnus-summary-limit-to-subject
1772 "a" gnus-summary-limit-to-author
1773 "u" gnus-summary-limit-to-unread
1774 "m" gnus-summary-limit-to-marks
1775 "M" gnus-summary-limit-exclude-marks
1776 "v" gnus-summary-limit-to-score
1777 "*" gnus-summary-limit-include-cached
1778 "D" gnus-summary-limit-include-dormant
1779 "T" gnus-summary-limit-include-thread
1780 "d" gnus-summary-limit-exclude-dormant
1781 "t" gnus-summary-limit-to-age
1782 "." gnus-summary-limit-to-unseen
1783 "x" gnus-summary-limit-to-extra
1784 "p" gnus-summary-limit-to-display-predicate
1785 "E" gnus-summary-limit-include-expunged
1786 "c" gnus-summary-limit-exclude-childless-dormant
1787 "C" gnus-summary-limit-mark-excluded-as-read
1788 "o" gnus-summary-insert-old-articles
1789 "N" gnus-summary-insert-new-articles)
1790
1791(gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1792 "n" gnus-summary-next-unread-article
1793 "p" gnus-summary-prev-unread-article
1794 "N" gnus-summary-next-article
1795 "P" gnus-summary-prev-article
1796 "\C-n" gnus-summary-next-same-subject
1797 "\C-p" gnus-summary-prev-same-subject
1798 "\M-n" gnus-summary-next-unread-subject
1799 "\M-p" gnus-summary-prev-unread-subject
1800 "f" gnus-summary-first-unread-article
1801 "b" gnus-summary-best-unread-article
1802 "j" gnus-summary-goto-article
1803 "g" gnus-summary-goto-subject
1804 "l" gnus-summary-goto-last-article
1805 "o" gnus-summary-pop-article)
1806
1807(gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1808 "k" gnus-summary-kill-thread
1809 "l" gnus-summary-lower-thread
1810 "i" gnus-summary-raise-thread
1811 "T" gnus-summary-toggle-threads
1812 "t" gnus-summary-rethread-current
1813 "^" gnus-summary-reparent-thread
1814 "s" gnus-summary-show-thread
1815 "S" gnus-summary-show-all-threads
1816 "h" gnus-summary-hide-thread
1817 "H" gnus-summary-hide-all-threads
1818 "n" gnus-summary-next-thread
1819 "p" gnus-summary-prev-thread
1820 "u" gnus-summary-up-thread
1821 "o" gnus-summary-top-thread
1822 "d" gnus-summary-down-thread
1823 "#" gnus-uu-mark-thread
1824 "\M-#" gnus-uu-unmark-thread)
1825
1826(gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1827 "g" gnus-summary-prepare
1828 "c" gnus-summary-insert-cached-articles
1829 "d" gnus-summary-insert-dormant-articles)
1830
1831(gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1832 "c" gnus-summary-catchup-and-exit
1833 "C" gnus-summary-catchup-all-and-exit
1834 "E" gnus-summary-exit-no-update
1835 "Q" gnus-summary-exit
1836 "Z" gnus-summary-exit
1837 "n" gnus-summary-catchup-and-goto-next-group
1838 "R" gnus-summary-reselect-current-group
1839 "G" gnus-summary-rescan-group
1840 "N" gnus-summary-next-group
1841 "s" gnus-summary-save-newsrc
1842 "P" gnus-summary-prev-group)
1843
1844(gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1845 " " gnus-summary-next-page
1846 "n" gnus-summary-next-page
1847 "\177" gnus-summary-prev-page
1848 [delete] gnus-summary-prev-page
1849 "p" gnus-summary-prev-page
1850 "\r" gnus-summary-scroll-up
1851 "\M-\r" gnus-summary-scroll-down
1852 "<" gnus-summary-beginning-of-article
1853 ">" gnus-summary-end-of-article
1854 "b" gnus-summary-beginning-of-article
1855 "e" gnus-summary-end-of-article
1856 "^" gnus-summary-refer-parent-article
1857 "r" gnus-summary-refer-parent-article
1858 "D" gnus-summary-enter-digest-group
1859 "R" gnus-summary-refer-references
1860 "T" gnus-summary-refer-thread
1861 "g" gnus-summary-show-article
1862 "s" gnus-summary-isearch-article
1863 "P" gnus-summary-print-article
1864 "M" gnus-mailing-list-insinuate
1865 "t" gnus-article-babel)
1866
1867(gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1868 "b" gnus-article-add-buttons
1869 "B" gnus-article-add-buttons-to-head
1870 "o" gnus-article-treat-overstrike
1871 "e" gnus-article-emphasize
1872 "w" gnus-article-fill-cited-article
1873 "Q" gnus-article-fill-long-lines
1874 "C" gnus-article-capitalize-sentences
1875 "c" gnus-article-remove-cr
1876 "q" gnus-article-de-quoted-unreadable
1877 "6" gnus-article-de-base64-unreadable
1878 "Z" gnus-article-decode-HZ
1879 "h" gnus-article-wash-html
1880 "u" gnus-article-unsplit-urls
1881 "s" gnus-summary-force-verify-and-decrypt
1882 "f" gnus-article-display-x-face
1883 "l" gnus-summary-stop-page-breaking
1884 "r" gnus-summary-caesar-message
1885 "m" gnus-summary-morse-message
1886 "t" gnus-summary-toggle-header
1887 "g" gnus-treat-smiley
1888 "v" gnus-summary-verbose-headers
1889 "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1890 "p" gnus-article-verify-x-pgp-sig
1891 "d" gnus-article-treat-dumbquotes)
1892
1893(gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1894 ;; mnemonic: deuglif*Y*
1895 "u" gnus-article-outlook-unwrap-lines
1896 "a" gnus-article-outlook-repair-attribution
1897 "c" gnus-article-outlook-rearrange-citation
1898 "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1899
1900(gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1901 "a" gnus-article-hide
1902 "h" gnus-article-hide-headers
1903 "b" gnus-article-hide-boring-headers
1904 "s" gnus-article-hide-signature
1905 "c" gnus-article-hide-citation
1906 "C" gnus-article-hide-citation-in-followups
1907 "l" gnus-article-hide-list-identifiers
1908 "B" gnus-article-strip-banner
1909 "P" gnus-article-hide-pem
1910 "\C-c" gnus-article-hide-citation-maybe)
1911
1912(gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1913 "a" gnus-article-highlight
1914 "h" gnus-article-highlight-headers
1915 "c" gnus-article-highlight-citation
1916 "s" gnus-article-highlight-signature)
1917
1918(gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1919 "f" gnus-article-treat-fold-headers
1920 "u" gnus-article-treat-unfold-headers
1921 "n" gnus-article-treat-fold-newsgroups)
1922
1923(gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1924 "x" gnus-article-display-x-face
1925 "d" gnus-article-display-face
1926 "s" gnus-treat-smiley
1927 "D" gnus-article-remove-images
1928 "f" gnus-treat-from-picon
1929 "m" gnus-treat-mail-picon
1930 "n" gnus-treat-newsgroups-picon)
1931
1932(gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1933 "w" gnus-article-decode-mime-words
1934 "c" gnus-article-decode-charset
1935 "v" gnus-mime-view-all-parts
1936 "b" gnus-article-view-part)
1937
1938(gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1939 "z" gnus-article-date-ut
1940 "u" gnus-article-date-ut
1941 "l" gnus-article-date-local
1942 "p" gnus-article-date-english
1943 "e" gnus-article-date-lapsed
1944 "o" gnus-article-date-original
1945 "i" gnus-article-date-iso8601
1946 "s" gnus-article-date-user)
1947
1948(gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1949 "t" gnus-article-remove-trailing-blank-lines
1950 "l" gnus-article-strip-leading-blank-lines
1951 "m" gnus-article-strip-multiple-blank-lines
1952 "a" gnus-article-strip-blank-lines
1953 "A" gnus-article-strip-all-blank-lines
1954 "s" gnus-article-strip-leading-space
1955 "e" gnus-article-strip-trailing-space
1956 "w" gnus-article-remove-leading-whitespace)
1957
1958(gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1959 "v" gnus-version
1960 "f" gnus-summary-fetch-faq
1961 "d" gnus-summary-describe-group
1962 "h" gnus-summary-describe-briefly
1963 "i" gnus-info-find-node
1964 "c" gnus-group-fetch-charter
1965 "C" gnus-group-fetch-control)
1966
1967(gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1968 "e" gnus-summary-expire-articles
1969 "\M-\C-e" gnus-summary-expire-articles-now
1970 "\177" gnus-summary-delete-article
1971 [delete] gnus-summary-delete-article
1972 [backspace] gnus-summary-delete-article
1973 "m" gnus-summary-move-article
1974 "r" gnus-summary-respool-article
1975 "w" gnus-summary-edit-article
1976 "c" gnus-summary-copy-article
1977 "B" gnus-summary-crosspost-article
1978 "q" gnus-summary-respool-query
1979 "t" gnus-summary-respool-trace
1980 "i" gnus-summary-import-article
1981 "I" gnus-summary-create-article
1982 "p" gnus-summary-article-posted-p)
1983
1984(gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1985 "o" gnus-summary-save-article
1986 "m" gnus-summary-save-article-mail
1987 "F" gnus-summary-write-article-file
1988 "r" gnus-summary-save-article-rmail
1989 "f" gnus-summary-save-article-file
1990 "b" gnus-summary-save-article-body-file
1991 "h" gnus-summary-save-article-folder
1992 "v" gnus-summary-save-article-vm
1993 "p" gnus-summary-pipe-output
1994 "P" gnus-summary-muttprint
1995 "s" gnus-soup-add-article)
1996
1997(gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1998 "b" gnus-summary-display-buttonized
1999 "m" gnus-summary-repair-multipart
2000 "v" gnus-article-view-part
2001 "o" gnus-article-save-part
2002 "c" gnus-article-copy-part
2003 "C" gnus-article-view-part-as-charset
2004 "e" gnus-article-view-part-externally
2005 "E" gnus-article-encrypt-body
2006 "i" gnus-article-inline-part
2007 "|" gnus-article-pipe-part)
2008
2009(gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2010 "p" gnus-summary-mark-as-processable
2011 "u" gnus-summary-unmark-as-processable
2012 "U" gnus-summary-unmark-all-processable
2013 "v" gnus-uu-mark-over
2014 "s" gnus-uu-mark-series
2015 "r" gnus-uu-mark-region
2016 "g" gnus-uu-unmark-region
2017 "R" gnus-uu-mark-by-regexp
2018 "G" gnus-uu-unmark-by-regexp
2019 "t" gnus-uu-mark-thread
2020 "T" gnus-uu-unmark-thread
2021 "a" gnus-uu-mark-all
2022 "b" gnus-uu-mark-buffer
2023 "S" gnus-uu-mark-sparse
2024 "k" gnus-summary-kill-process-mark
2025 "y" gnus-summary-yank-process-mark
2026 "w" gnus-summary-save-process-mark
2027 "i" gnus-uu-invert-processable)
2028
2029(gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2030 ;;"x" gnus-uu-extract-any
2031 "m" gnus-summary-save-parts
2032 "u" gnus-uu-decode-uu
2033 "U" gnus-uu-decode-uu-and-save
2034 "s" gnus-uu-decode-unshar
2035 "S" gnus-uu-decode-unshar-and-save
2036 "o" gnus-uu-decode-save
2037 "O" gnus-uu-decode-save
2038 "b" gnus-uu-decode-binhex
2039 "B" gnus-uu-decode-binhex
2040 "p" gnus-uu-decode-postscript
2041 "P" gnus-uu-decode-postscript-and-save)
2042
2043(gnus-define-keys
2044 (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2045 "u" gnus-uu-decode-uu-view
2046 "U" gnus-uu-decode-uu-and-save-view
2047 "s" gnus-uu-decode-unshar-view
2048 "S" gnus-uu-decode-unshar-and-save-view
2049 "o" gnus-uu-decode-save-view
2050 "O" gnus-uu-decode-save-view
2051 "b" gnus-uu-decode-binhex-view
2052 "B" gnus-uu-decode-binhex-view
2053 "p" gnus-uu-decode-postscript-view
2054 "P" gnus-uu-decode-postscript-and-save-view)
2055
2056(defvar gnus-article-post-menu nil)
2057
2058(defconst gnus-summary-menu-maxlen 20)
2059
2060(defun gnus-summary-menu-split (menu)
2061 ;; If we have lots of elements, divide them into groups of 20
2062 ;; and make a pane (or submenu) for each one.
2063 (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2064 (let ((menu menu) sublists next
2065 (i 1))
2066 (while menu
2067 ;; Pull off the next gnus-summary-menu-maxlen elements
2068 ;; and make them the next element of sublist.
2069 (setq next (nthcdr gnus-summary-menu-maxlen menu))
2070 (if next
2071 (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2072 nil))
2073 (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2074 (aref (car (last menu)) 0)) menu)
2075 sublists))
2076 (setq i (1+ i))
2077 (setq menu next))
2078 (nreverse sublists))
2079 ;; Few elements--put them all in one pane.
2080 menu))
eec82323
LMI
2081
2082(defun gnus-summary-make-menu-bar ()
2083 (gnus-turn-off-edit-menu 'summary)
2084
2085 (unless (boundp 'gnus-summary-misc-menu)
2086
2087 (easy-menu-define
23f87bed
MB
2088 gnus-summary-kill-menu gnus-summary-mode-map ""
2089 (cons
2090 "Score"
2091 (nconc
2092 (list
2093 ["Customize" gnus-score-customize t])
2094 (gnus-make-score-map 'increase)
2095 (gnus-make-score-map 'lower)
2096 '(("Mark"
2097 ["Kill below" gnus-summary-kill-below t]
2098 ["Mark above" gnus-summary-mark-above t]
2099 ["Tick above" gnus-summary-tick-above t]
2100 ["Clear above" gnus-summary-clear-above t])
2101 ["Current score" gnus-summary-current-score t]
2102 ["Set score" gnus-summary-set-score t]
2103 ["Switch current score file..." gnus-score-change-score-file t]
2104 ["Set mark below..." gnus-score-set-mark-below t]
2105 ["Set expunge below..." gnus-score-set-expunge-below t]
2106 ["Edit current score file" gnus-score-edit-current-scores t]
2107 ["Edit score file" gnus-score-edit-file t]
2108 ["Trace score" gnus-score-find-trace t]
2109 ["Find words" gnus-score-find-favourite-words t]
2110 ["Rescore buffer" gnus-summary-rescore t]
2111 ["Increase score..." gnus-summary-increase-score t]
2112 ["Lower score..." gnus-summary-lower-score t]))))
2113
2114 ;; Define both the Article menu in the summary buffer and the
2115 ;; equivalent Commands menu in the article buffer here for
2116 ;; consistency.
6748645f 2117 (let ((innards
23f87bed
MB
2118 `(("Hide"
2119 ["All" gnus-article-hide t]
2120 ["Headers" gnus-article-hide-headers t]
2121 ["Signature" gnus-article-hide-signature t]
2122 ["Citation" gnus-article-hide-citation t]
16409b0b 2123 ["List identifiers" gnus-article-hide-list-identifiers t]
16409b0b 2124 ["Banner" gnus-article-strip-banner t]
23f87bed
MB
2125 ["Boring headers" gnus-article-hide-boring-headers t])
2126 ("Highlight"
2127 ["All" gnus-article-highlight t]
2128 ["Headers" gnus-article-highlight-headers t]
2129 ["Signature" gnus-article-highlight-signature t]
2130 ["Citation" gnus-article-highlight-citation t])
16409b0b
GM
2131 ("MIME"
2132 ["Words" gnus-article-decode-mime-words t]
2133 ["Charset" gnus-article-decode-charset t]
2134 ["QP" gnus-article-de-quoted-unreadable t]
2135 ["Base64" gnus-article-de-base64-unreadable t]
23f87bed
MB
2136 ["View MIME buttons" gnus-summary-display-buttonized t]
2137 ["View all" gnus-mime-view-all-parts t]
2138 ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2139 ["Encrypt body" gnus-article-encrypt-body
2140 :active (not (gnus-group-read-only-p))
2141 ,@(if (featurep 'xemacs) nil
2142 '(:help "Encrypt the message body on disk"))]
2143 ["Extract all parts..." gnus-summary-save-parts t]
2144 ("Multipart"
2145 ["Repair multipart" gnus-summary-repair-multipart t]
2146 ["Pipe part..." gnus-article-pipe-part t]
2147 ["Inline part" gnus-article-inline-part t]
2148 ["Encrypt body" gnus-article-encrypt-body
2149 :active (not (gnus-group-read-only-p))
2150 ,@(if (featurep 'xemacs) nil
2151 '(:help "Encrypt the message body on disk"))]
2152 ["View part externally" gnus-article-view-part-externally t]
2153 ["View part with charset..." gnus-article-view-part-as-charset t]
2154 ["Copy part" gnus-article-copy-part t]
2155 ["Save part..." gnus-article-save-part t]
2156 ["View part" gnus-article-view-part t]))
2157 ("Date"
2158 ["Local" gnus-article-date-local t]
2159 ["ISO8601" gnus-article-date-iso8601 t]
2160 ["UT" gnus-article-date-ut t]
2161 ["Original" gnus-article-date-original t]
2162 ["Lapsed" gnus-article-date-lapsed t]
2163 ["User-defined" gnus-article-date-user t])
2164 ("Display"
2165 ["Remove images" gnus-article-remove-images t]
2166 ["Toggle smiley" gnus-treat-smiley t]
2167 ["Show X-Face" gnus-article-display-x-face t]
2168 ["Show picons in From" gnus-treat-from-picon t]
2169 ["Show picons in mail headers" gnus-treat-mail-picon t]
2170 ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2171 ("View as different encoding"
2172 ,@(gnus-summary-menu-split
2173 (mapcar
2174 (lambda (cs)
2175 ;; Since easymenu under Emacs doesn't allow
2176 ;; lambda forms for menu commands, we should
2177 ;; provide intern'ed function symbols.
2178 (let ((command (intern (format "\
2179gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2180 (fset command
2181 `(lambda ()
2182 (interactive)
2183 (let ((gnus-summary-show-article-charset-alist
2184 '((1 . ,cs))))
2185 (gnus-summary-show-article 1))))
2186 `[,(symbol-name cs) ,command t]))
2187 (sort (if (fboundp 'coding-system-list)
2188 (coding-system-list)
2189 (mapcar 'car mm-mime-mule-charset-alist))
2190 'string<)))))
2191 ("Washing"
2192 ("Remove Blanks"
2193 ["Leading" gnus-article-strip-leading-blank-lines t]
2194 ["Multiple" gnus-article-strip-multiple-blank-lines t]
2195 ["Trailing" gnus-article-remove-trailing-blank-lines t]
2196 ["All of the above" gnus-article-strip-blank-lines t]
2197 ["All" gnus-article-strip-all-blank-lines t]
2198 ["Leading space" gnus-article-strip-leading-space t]
2199 ["Trailing space" gnus-article-strip-trailing-space t]
2200 ["Leading space in headers"
2201 gnus-article-remove-leading-whitespace t])
2202 ["Overstrike" gnus-article-treat-overstrike t]
2203 ["Dumb quotes" gnus-article-treat-dumbquotes t]
2204 ["Emphasis" gnus-article-emphasize t]
2205 ["Word wrap" gnus-article-fill-cited-article t]
16409b0b
GM
2206 ["Fill long lines" gnus-article-fill-long-lines t]
2207 ["Capitalize sentences" gnus-article-capitalize-sentences t]
23f87bed
MB
2208 ["Remove CR" gnus-article-remove-cr t]
2209 ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2210 ["Base64" gnus-article-de-base64-unreadable t]
2211 ["Rot 13" gnus-summary-caesar-message
2212 ,@(if (featurep 'xemacs) '(t)
2213 '(:help "\"Caesar rotate\" article by 13"))]
2214 ["Morse decode" gnus-summary-morse-message t]
2215 ["Unix pipe..." gnus-summary-pipe-message t]
2216 ["Add buttons" gnus-article-add-buttons t]
2217 ["Add buttons to head" gnus-article-add-buttons-to-head t]
2218 ["Stop page breaking" gnus-summary-stop-page-breaking t]
2219 ["Verbose header" gnus-summary-verbose-headers t]
2220 ["Toggle header" gnus-summary-toggle-header t]
2221 ["Unfold headers" gnus-article-treat-unfold-headers t]
2222 ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
16409b0b 2223 ["Html" gnus-article-wash-html t]
23f87bed
MB
2224 ["Unsplit URLs" gnus-article-unsplit-urls t]
2225 ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2226 ["Decode HZ" gnus-article-decode-HZ t]
2227 ("(Outlook) Deuglify"
2228 ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2229 ["Repair attribution" gnus-article-outlook-repair-attribution t]
2230 ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2231 ["Full (Outlook) deuglify"
2232 gnus-article-outlook-deuglify-article t])
2233 )
2234 ("Output"
2235 ["Save in default format..." gnus-summary-save-article
2236 ,@(if (featurep 'xemacs) '(t)
2237 '(:help "Save article using default method"))]
2238 ["Save in file..." gnus-summary-save-article-file
2239 ,@(if (featurep 'xemacs) '(t)
2240 '(:help "Save article in file"))]
2241 ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2242 ["Save in MH folder..." gnus-summary-save-article-folder t]
2243 ["Save in VM folder..." gnus-summary-save-article-vm t]
2244 ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2245 ["Save body in file..." gnus-summary-save-article-body-file t]
2246 ["Pipe through a filter..." gnus-summary-pipe-output t]
2247 ["Add to SOUP packet" gnus-soup-add-article t]
2248 ["Print with Muttprint..." gnus-summary-muttprint t]
531e5812
MB
2249 ["Print" gnus-summary-print-article
2250 ,@(if (featurep 'xemacs) '(t)
2251 '(:help "Generate and print a PostScript image"))])
2252 ("Copy, move,... (Backend)"
707f2b38 2253 ,@(if (featurep 'xemacs) nil
531e5812 2254 '(:help "Copying, moving, expiring articles..."))
23f87bed
MB
2255 ["Respool article..." gnus-summary-respool-article t]
2256 ["Move article..." gnus-summary-move-article
2257 (gnus-check-backend-function
2258 'request-move-article gnus-newsgroup-name)]
2259 ["Copy article..." gnus-summary-copy-article t]
2260 ["Crosspost article..." gnus-summary-crosspost-article
2261 (gnus-check-backend-function
2262 'request-replace-article gnus-newsgroup-name)]
2263 ["Import file..." gnus-summary-import-article
2264 (gnus-check-backend-function
2265 'request-accept-article gnus-newsgroup-name)]
2266 ["Create article..." gnus-summary-create-article
2267 (gnus-check-backend-function
2268 'request-accept-article gnus-newsgroup-name)]
2269 ["Check if posted" gnus-summary-article-posted-p t]
2270 ["Edit article" gnus-summary-edit-article
2271 (not (gnus-group-read-only-p))]
2272 ["Delete article" gnus-summary-delete-article
2273 (gnus-check-backend-function
2274 'request-expire-articles gnus-newsgroup-name)]
2275 ["Query respool" gnus-summary-respool-query t]
6748645f 2276 ["Trace respool" gnus-summary-respool-trace t]
23f87bed
MB
2277 ["Delete expirable articles" gnus-summary-expire-articles-now
2278 (gnus-check-backend-function
2279 'request-expire-articles gnus-newsgroup-name)])
2280 ("Extract"
2281 ["Uudecode" gnus-uu-decode-uu
2282 ,@(if (featurep 'xemacs) '(t)
2283 '(:help "Decode uuencoded article(s)"))]
2284 ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2285 ["Unshar" gnus-uu-decode-unshar t]
2286 ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2287 ["Save" gnus-uu-decode-save t]
2288 ["Binhex" gnus-uu-decode-binhex t]
2289 ["Postscript" gnus-uu-decode-postscript t]
2290 ["All MIME parts" gnus-summary-save-parts t])
2291 ("Cache"
2292 ["Enter article" gnus-cache-enter-article t]
2293 ["Remove article" gnus-cache-remove-article t])
16409b0b 2294 ["Translate" gnus-article-babel t]
23f87bed
MB
2295 ["Select article buffer" gnus-summary-select-article-buffer t]
2296 ["Enter digest buffer" gnus-summary-enter-digest-group t]
2297 ["Isearch article..." gnus-summary-isearch-article t]
2298 ["Beginning of the article" gnus-summary-beginning-of-article t]
2299 ["End of the article" gnus-summary-end-of-article t]
2300 ["Fetch parent of article" gnus-summary-refer-parent-article t]
2301 ["Fetch referenced articles" gnus-summary-refer-references t]
2302 ["Fetch current thread" gnus-summary-refer-thread t]
2303 ["Fetch article with id..." gnus-summary-refer-article t]
2304 ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2305 ["Redisplay" gnus-summary-show-article t]
2306 ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
6748645f 2307 (easy-menu-define
23f87bed
MB
2308 gnus-summary-article-menu gnus-summary-mode-map ""
2309 (cons "Article" innards))
6748645f 2310
1653df0f
SZ
2311 (if (not (keymapp gnus-summary-article-menu))
2312 (easy-menu-define
2313 gnus-article-commands-menu gnus-article-mode-map ""
2314 (cons "Commands" innards))
2315 ;; in Emacs, don't share menu.
a1506d29 2316 (setq gnus-article-commands-menu
1653df0f
SZ
2317 (copy-keymap gnus-summary-article-menu))
2318 (define-key gnus-article-mode-map [menu-bar commands]
2319 (cons "Commands" gnus-article-commands-menu))))
eec82323
LMI
2320
2321 (easy-menu-define
23f87bed
MB
2322 gnus-summary-thread-menu gnus-summary-mode-map ""
2323 '("Threads"
2324 ["Find all messages in thread" gnus-summary-refer-thread t]
2325 ["Toggle threading" gnus-summary-toggle-threads t]
2326 ["Hide threads" gnus-summary-hide-all-threads t]
2327 ["Show threads" gnus-summary-show-all-threads t]
2328 ["Hide thread" gnus-summary-hide-thread t]
2329 ["Show thread" gnus-summary-show-thread t]
2330 ["Go to next thread" gnus-summary-next-thread t]
2331 ["Go to previous thread" gnus-summary-prev-thread t]
2332 ["Go down thread" gnus-summary-down-thread t]
2333 ["Go up thread" gnus-summary-up-thread t]
2334 ["Top of thread" gnus-summary-top-thread t]
2335 ["Mark thread as read" gnus-summary-kill-thread t]
2336 ["Lower thread score" gnus-summary-lower-thread t]
2337 ["Raise thread score" gnus-summary-raise-thread t]
2338 ["Rethread current" gnus-summary-rethread-current t]))
eec82323
LMI
2339
2340 (easy-menu-define
23f87bed
MB
2341 gnus-summary-post-menu gnus-summary-mode-map ""
2342 `("Post"
2343 ["Send a message (mail or news)" gnus-summary-post-news
2344 ,@(if (featurep 'xemacs) '(t)
531e5812 2345 '(:help "Compose a new message (mail or news)"))]
23f87bed
MB
2346 ["Followup" gnus-summary-followup
2347 ,@(if (featurep 'xemacs) '(t)
2348 '(:help "Post followup to this article"))]
2349 ["Followup and yank" gnus-summary-followup-with-original
2350 ,@(if (featurep 'xemacs) '(t)
2351 '(:help "Post followup to this article, quoting its contents"))]
2352 ["Supersede article" gnus-summary-supersede-article t]
2353 ["Cancel article" gnus-summary-cancel-article
2354 ,@(if (featurep 'xemacs) '(t)
2355 '(:help "Cancel an article you posted"))]
2356 ["Reply" gnus-summary-reply t]
2357 ["Reply and yank" gnus-summary-reply-with-original t]
2358 ["Wide reply" gnus-summary-wide-reply t]
2359 ["Wide reply and yank" gnus-summary-wide-reply-with-original
2360 ,@(if (featurep 'xemacs) '(t)
2361 '(:help "Mail a reply, quoting this article"))]
2362 ["Very wide reply" gnus-summary-very-wide-reply t]
2363 ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2364 ,@(if (featurep 'xemacs) '(t)
2365 '(:help "Mail a very wide reply, quoting this article"))]
2366 ["Mail forward" gnus-summary-mail-forward t]
2367 ["Post forward" gnus-summary-post-forward t]
2368 ["Digest and mail" gnus-uu-digest-mail-forward t]
2369 ["Digest and post" gnus-uu-digest-post-forward t]
2370 ["Resend message" gnus-summary-resend-message t]
2371 ["Resend message edit" gnus-summary-resend-message-edit t]
2372 ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2373 ["Send a mail" gnus-summary-mail-other-window t]
2374 ["Create a local message" gnus-summary-news-other-window t]
2375 ["Uuencode and post" gnus-uu-post-news
2376 ,@(if (featurep 'xemacs) '(t)
2377 '(:help "Post a uuencoded article"))]
2378 ["Followup via news" gnus-summary-followup-to-mail t]
2379 ["Followup via news and yank"
2380 gnus-summary-followup-to-mail-with-original t]
2381 ;;("Draft"
2382 ;;["Send" gnus-summary-send-draft t]
2383 ;;["Send bounced" gnus-resend-bounced-mail t])
2384 ))
2385
2386 (cond
2387 ((not (keymapp gnus-summary-post-menu))
2388 (setq gnus-article-post-menu gnus-summary-post-menu))
2389 ((not gnus-article-post-menu)
2390 ;; Don't share post menu.
2391 (setq gnus-article-post-menu
2392 (copy-keymap gnus-summary-post-menu))))
2393 (define-key gnus-article-mode-map [menu-bar post]
2394 (cons "Post" gnus-article-post-menu))
eec82323
LMI
2395
2396 (easy-menu-define
23f87bed
MB
2397 gnus-summary-misc-menu gnus-summary-mode-map ""
2398 `("Gnus"
2399 ("Mark Read"
2400 ["Mark as read" gnus-summary-mark-as-read-forward t]
2401 ["Mark same subject and select"
2402 gnus-summary-kill-same-subject-and-select t]
2403 ["Mark same subject" gnus-summary-kill-same-subject t]
2404 ["Catchup" gnus-summary-catchup
2405 ,@(if (featurep 'xemacs) '(t)
2406 '(:help "Mark unread articles in this group as read"))]
2407 ["Catchup all" gnus-summary-catchup-all t]
2408 ["Catchup to here" gnus-summary-catchup-to-here t]
2409 ["Catchup from here" gnus-summary-catchup-from-here t]
2410 ["Catchup region" gnus-summary-mark-region-as-read
2411 (gnus-mark-active-p)]
2412 ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2413 ("Mark Various"
2414 ["Tick" gnus-summary-tick-article-forward t]
2415 ["Mark as dormant" gnus-summary-mark-as-dormant t]
2416 ["Remove marks" gnus-summary-clear-mark-forward t]
2417 ["Set expirable mark" gnus-summary-mark-as-expirable t]
2418 ["Set bookmark" gnus-summary-set-bookmark t]
2419 ["Remove bookmark" gnus-summary-remove-bookmark t])
2420 ("Limit to"
2421 ["Marks..." gnus-summary-limit-to-marks t]
2422 ["Subject..." gnus-summary-limit-to-subject t]
2423 ["Author..." gnus-summary-limit-to-author t]
2424 ["Age..." gnus-summary-limit-to-age t]
2425 ["Extra..." gnus-summary-limit-to-extra t]
2426 ["Score..." gnus-summary-limit-to-score t]
2427 ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2428 ["Unread" gnus-summary-limit-to-unread t]
2429 ["Unseen" gnus-summary-limit-to-unseen t]
2430 ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2431 ["Next articles" gnus-summary-limit-to-articles t]
2432 ["Pop limit" gnus-summary-pop-limit t]
2433 ["Show dormant" gnus-summary-limit-include-dormant t]
2434 ["Hide childless dormant"
2435 gnus-summary-limit-exclude-childless-dormant t]
2436 ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2437 ["Hide marked" gnus-summary-limit-exclude-marks t]
2438 ["Show expunged" gnus-summary-limit-include-expunged t])
2439 ("Process Mark"
2440 ["Set mark" gnus-summary-mark-as-processable t]
2441 ["Remove mark" gnus-summary-unmark-as-processable t]
2442 ["Remove all marks" gnus-summary-unmark-all-processable t]
2443 ["Mark above" gnus-uu-mark-over t]
2444 ["Mark series" gnus-uu-mark-series t]
2445 ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2446 ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2447 ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2448 ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2449 ["Mark all" gnus-uu-mark-all t]
2450 ["Mark buffer" gnus-uu-mark-buffer t]
2451 ["Mark sparse" gnus-uu-mark-sparse t]
2452 ["Mark thread" gnus-uu-mark-thread t]
2453 ["Unmark thread" gnus-uu-unmark-thread t]
2454 ("Process Mark Sets"
2455 ["Kill" gnus-summary-kill-process-mark t]
2456 ["Yank" gnus-summary-yank-process-mark
2457 gnus-newsgroup-process-stack]
2458 ["Save" gnus-summary-save-process-mark t]
2459 ["Run command on marked..." gnus-summary-universal-argument t]))
2460 ("Scroll article"
2461 ["Page forward" gnus-summary-next-page
2462 ,@(if (featurep 'xemacs) '(t)
2463 '(:help "Show next page of article"))]
2464 ["Page backward" gnus-summary-prev-page
2465 ,@(if (featurep 'xemacs) '(t)
2466 '(:help "Show previous page of article"))]
2467 ["Line forward" gnus-summary-scroll-up t])
2468 ("Move"
2469 ["Next unread article" gnus-summary-next-unread-article t]
2470 ["Previous unread article" gnus-summary-prev-unread-article t]
2471 ["Next article" gnus-summary-next-article t]
2472 ["Previous article" gnus-summary-prev-article t]
2473 ["Next unread subject" gnus-summary-next-unread-subject t]
2474 ["Previous unread subject" gnus-summary-prev-unread-subject t]
2475 ["Next article same subject" gnus-summary-next-same-subject t]
2476 ["Previous article same subject" gnus-summary-prev-same-subject t]
2477 ["First unread article" gnus-summary-first-unread-article t]
2478 ["Best unread article" gnus-summary-best-unread-article t]
2479 ["Go to subject number..." gnus-summary-goto-subject t]
2480 ["Go to article number..." gnus-summary-goto-article t]
2481 ["Go to the last article" gnus-summary-goto-last-article t]
2482 ["Pop article off history" gnus-summary-pop-article t])
2483 ("Sort"
2484 ["Sort by number" gnus-summary-sort-by-number t]
2485 ["Sort by author" gnus-summary-sort-by-author t]
2486 ["Sort by subject" gnus-summary-sort-by-subject t]
2487 ["Sort by date" gnus-summary-sort-by-date t]
2488 ["Sort by score" gnus-summary-sort-by-score t]
2489 ["Sort by lines" gnus-summary-sort-by-lines t]
2490 ["Sort by characters" gnus-summary-sort-by-chars t]
2491 ["Randomize" gnus-summary-sort-by-random t]
2492 ["Original sort" gnus-summary-sort-by-original t])
2493 ("Help"
2494 ["Fetch group FAQ" gnus-summary-fetch-faq t]
2495 ["Describe group" gnus-summary-describe-group t]
2496 ["Fetch charter" gnus-group-fetch-charter
2497 ,@(if (featurep 'xemacs) nil
2498 '(:help "Display the charter of the current group"))]
2499 ["Fetch control message" gnus-group-fetch-control
2500 ,@(if (featurep 'xemacs) nil
2501 '(:help "Display the archived control message for the current group"))]
2502 ["Read manual" gnus-info-find-node t])
2503 ("Modes"
2504 ["Pick and read" gnus-pick-mode t]
2505 ["Binary" gnus-binary-mode t])
2506 ("Regeneration"
2507 ["Regenerate" gnus-summary-prepare t]
2508 ["Insert cached articles" gnus-summary-insert-cached-articles t]
2509 ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2510 ["Toggle threading" gnus-summary-toggle-threads t])
2511 ["See old articles" gnus-summary-insert-old-articles t]
2512 ["See new articles" gnus-summary-insert-new-articles t]
2513 ["Filter articles..." gnus-summary-execute-command t]
2514 ["Run command on articles..." gnus-summary-universal-argument t]
2515 ["Search articles forward..." gnus-summary-search-article-forward t]
2516 ["Search articles backward..." gnus-summary-search-article-backward t]
2517 ["Toggle line truncation" gnus-summary-toggle-truncation t]
2518 ["Expand window" gnus-summary-expand-window t]
2519 ["Expire expirable articles" gnus-summary-expire-articles
2520 (gnus-check-backend-function
2521 'request-expire-articles gnus-newsgroup-name)]
2522 ["Edit local kill file" gnus-summary-edit-local-kill t]
2523 ["Edit main kill file" gnus-summary-edit-global-kill t]
2524 ["Edit group parameters" gnus-summary-edit-parameters t]
2525 ["Customize group parameters" gnus-summary-customize-parameters t]
2526 ["Send a bug report" gnus-bug t]
2527 ("Exit"
2528 ["Catchup and exit" gnus-summary-catchup-and-exit
2529 ,@(if (featurep 'xemacs) '(t)
2530 '(:help "Mark unread articles in this group as read, then exit"))]
2531 ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2532 ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2533 ["Exit group" gnus-summary-exit
2534 ,@(if (featurep 'xemacs) '(t)
2535 '(:help "Exit current group, return to group selection mode"))]
2536 ["Exit group without updating" gnus-summary-exit-no-update t]
2537 ["Exit and goto next group" gnus-summary-next-group t]
2538 ["Exit and goto prev group" gnus-summary-prev-group t]
2539 ["Reselect group" gnus-summary-reselect-current-group t]
2540 ["Rescan group" gnus-summary-rescan-group t]
2541 ["Update dribble" gnus-summary-save-newsrc t])))
eec82323 2542
6748645f 2543 (gnus-run-hooks 'gnus-summary-menu-hook)))
eec82323 2544
60bd5589
DL
2545(defvar gnus-summary-tool-bar-map nil)
2546
9a0026a6 2547;; Emacs 21 tool bar. Should be no-op otherwise.
60bd5589 2548(defun gnus-summary-make-tool-bar ()
23f87bed
MB
2549 (if (and (fboundp 'tool-bar-add-item-from-menu)
2550 (default-value 'tool-bar-mode)
2551 (not gnus-summary-tool-bar-map))
60bd5589 2552 (setq gnus-summary-tool-bar-map
23f87bed
MB
2553 (let ((tool-bar-map (make-sparse-keymap))
2554 (load-path (mm-image-load-path)))
60bd5589
DL
2555 (tool-bar-add-item-from-menu
2556 'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2557 (tool-bar-add-item-from-menu
2558 'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2559 (tool-bar-add-item-from-menu
2560 'gnus-summary-post-news "post" gnus-summary-mode-map)
2561 (tool-bar-add-item-from-menu
2562 'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2563 (tool-bar-add-item-from-menu
2564 'gnus-summary-followup "followup" gnus-summary-mode-map)
2565 (tool-bar-add-item-from-menu
2566 'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2567 (tool-bar-add-item-from-menu
2568 'gnus-summary-reply "reply" gnus-summary-mode-map)
2569 (tool-bar-add-item-from-menu
2570 'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2571 (tool-bar-add-item-from-menu
2572 'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2573 (tool-bar-add-item-from-menu
2574 'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2575 (tool-bar-add-item-from-menu
2576 'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2577 (tool-bar-add-item-from-menu
2578 'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2579 (tool-bar-add-item-from-menu
2580 'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2581 (tool-bar-add-item-from-menu
2582 'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2583 (tool-bar-add-item-from-menu
2584 'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2585 tool-bar-map)))
2586 (if gnus-summary-tool-bar-map
2587 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2588
eec82323
LMI
2589(defun gnus-score-set-default (var value)
2590 "A version of set that updates the GNU Emacs menu-bar."
2591 (set var value)
2592 ;; It is the message that forces the active status to be updated.
2593 (message ""))
2594
2595(defun gnus-make-score-map (type)
2596 "Make a summary score map of type TYPE."
2597 (if t
2598 nil
2599 (let ((headers '(("author" "from" string)
2600 ("subject" "subject" string)
2601 ("article body" "body" string)
2602 ("article head" "head" string)
2603 ("xref" "xref" string)
16409b0b 2604 ("extra header" "extra" string)
eec82323
LMI
2605 ("lines" "lines" number)
2606 ("followups to author" "followup" string)))
2607 (types '((number ("less than" <)
2608 ("greater than" >)
2609 ("equal" =))
2610 (string ("substring" s)
2611 ("exact string" e)
2612 ("fuzzy string" f)
2613 ("regexp" r))))
2614 (perms '(("temporary" (current-time-string))
2615 ("permanent" nil)
2616 ("immediate" now)))
2617 header)
2618 (list
2619 (apply
2620 'nconc
2621 (list
2622 (if (eq type 'lower)
2623 "Lower score"
2624 "Increase score"))
2625 (let (outh)
2626 (while headers
2627 (setq header (car headers))
2628 (setq outh
2629 (cons
2630 (apply
2631 'nconc
2632 (list (car header))
2633 (let ((ts (cdr (assoc (nth 2 header) types)))
2634 outt)
2635 (while ts
2636 (setq outt
2637 (cons
2638 (apply
2639 'nconc
2640 (list (caar ts))
2641 (let ((ps perms)
2642 outp)
2643 (while ps
2644 (setq outp
2645 (cons
2646 (vector
2647 (caar ps)
2648 (list
2649 'gnus-summary-score-entry
2650 (nth 1 header)
2651 (if (or (string= (nth 1 header)
2652 "head")
2653 (string= (nth 1 header)
2654 "body"))
2655 ""
2656 (list 'gnus-summary-header
2657 (nth 1 header)))
2658 (list 'quote (nth 1 (car ts)))
16409b0b
GM
2659 (list 'gnus-score-delta-default
2660 nil)
eec82323
LMI
2661 (nth 1 (car ps))
2662 t)
2663 t)
2664 outp))
2665 (setq ps (cdr ps)))
2666 (list (nreverse outp))))
2667 outt))
2668 (setq ts (cdr ts)))
2669 (list (nreverse outt))))
2670 outh))
2671 (setq headers (cdr headers)))
2672 (list (nreverse outh))))))))
2673
2674\f
2675
2676(defun gnus-summary-mode (&optional group)
2677 "Major mode for reading articles.
2678
2679All normal editing commands are switched off.
2680\\<gnus-summary-mode-map>
2681Each line in this buffer represents one article. To read an
2682article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
2683and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2684respectively.
2685
2686You can also post articles and send mail from this buffer. To
23f87bed 2687follow up an article, type `\\[gnus-summary-followup]'. To mail a reply to the author
eec82323
LMI
2688of an article, type `\\[gnus-summary-reply]'.
2689
2690There are approx. one gazillion commands you can execute in this
2691buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2692
2693The following commands are available:
2694
2695\\{gnus-summary-mode-map}"
2696 (interactive)
eec82323 2697 (kill-all-local-variables)
60bd5589
DL
2698 (when (gnus-visual-p 'summary-menu 'menu)
2699 (gnus-summary-make-menu-bar)
2700 (gnus-summary-make-tool-bar))
eec82323 2701 (gnus-summary-make-local-variables)
23f87bed
MB
2702 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2703 (gnus-summary-make-local-variables))
eec82323
LMI
2704 (gnus-make-thread-indent-array)
2705 (gnus-simplify-mode-line)
2706 (setq major-mode 'gnus-summary-mode)
2707 (setq mode-name "Summary")
2708 (make-local-variable 'minor-mode-alist)
2709 (use-local-map gnus-summary-mode-map)
16409b0b 2710 (buffer-disable-undo)
eec82323
LMI
2711 (setq buffer-read-only t) ;Disable modification
2712 (setq truncate-lines t)
2713 (setq selective-display t)
2714 (setq selective-display-ellipses t) ;Display `...'
2715 (gnus-summary-set-display-table)
2716 (gnus-set-default-directory)
2717 (setq gnus-newsgroup-name group)
2718 (make-local-variable 'gnus-summary-line-format)
2719 (make-local-variable 'gnus-summary-line-format-spec)
6748645f
LMI
2720 (make-local-variable 'gnus-summary-dummy-line-format)
2721 (make-local-variable 'gnus-summary-dummy-line-format-spec)
eec82323 2722 (make-local-variable 'gnus-summary-mark-positions)
23f87bed 2723 (gnus-make-local-hook 'pre-command-hook)
6748645f 2724 (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
cfcd5c91 2725 (gnus-run-mode-hooks 'gnus-summary-mode-hook)
23f87bed 2726 (turn-on-gnus-mailing-list-mode)
87545352 2727 (mm-enable-multibyte)
eec82323
LMI
2728 (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2729 (gnus-update-summary-mark-positions))
2730
2731(defun gnus-summary-make-local-variables ()
2732 "Make all the local summary buffer variables."
16409b0b
GM
2733 (let (global)
2734 (dolist (local gnus-summary-local-variables)
eec82323
LMI
2735 (if (consp local)
2736 (progn
2737 (if (eq (cdr local) 'global)
2738 ;; Copy the global value of the variable.
2739 (setq global (symbol-value (car local)))
2740 ;; Use the value from the list.
2741 (setq global (eval (cdr local))))
16409b0b 2742 (set (make-local-variable (car local)) global))
eec82323 2743 ;; Simple nil-valued local variable.
16409b0b 2744 (set (make-local-variable local) nil)))))
eec82323
LMI
2745
2746(defun gnus-summary-clear-local-variables ()
2747 (let ((locals gnus-summary-local-variables))
2748 (while locals
2749 (if (consp (car locals))
2750 (and (vectorp (caar locals))
2751 (set (caar locals) nil))
2752 (and (vectorp (car locals))
2753 (set (car locals) nil)))
2754 (setq locals (cdr locals)))))
2755
2756;; Summary data functions.
2757
2758(defmacro gnus-data-number (data)
2759 `(car ,data))
2760
2761(defmacro gnus-data-set-number (data number)
2762 `(setcar ,data ,number))
2763
2764(defmacro gnus-data-mark (data)
2765 `(nth 1 ,data))
2766
2767(defmacro gnus-data-set-mark (data mark)
2768 `(setcar (nthcdr 1 ,data) ,mark))
2769
2770(defmacro gnus-data-pos (data)
2771 `(nth 2 ,data))
2772
2773(defmacro gnus-data-set-pos (data pos)
2774 `(setcar (nthcdr 2 ,data) ,pos))
2775
2776(defmacro gnus-data-header (data)
2777 `(nth 3 ,data))
2778
2779(defmacro gnus-data-set-header (data header)
2780 `(setf (nth 3 ,data) ,header))
2781
2782(defmacro gnus-data-level (data)
2783 `(nth 4 ,data))
2784
2785(defmacro gnus-data-unread-p (data)
2786 `(= (nth 1 ,data) gnus-unread-mark))
2787
2788(defmacro gnus-data-read-p (data)
2789 `(/= (nth 1 ,data) gnus-unread-mark))
2790
2791(defmacro gnus-data-pseudo-p (data)
2792 `(consp (nth 3 ,data)))
2793
2794(defmacro gnus-data-find (number)
2795 `(assq ,number gnus-newsgroup-data))
2796
2797(defmacro gnus-data-find-list (number &optional data)
2798 `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2799 (memq (assq ,number bdata)
2800 bdata)))
2801
2802(defmacro gnus-data-make (number mark pos header level)
2803 `(list ,number ,mark ,pos ,header ,level))
2804
2805(defun gnus-data-enter (after-article number mark pos header level offset)
2806 (let ((data (gnus-data-find-list after-article)))
2807 (unless data
2808 (error "No such article: %d" after-article))
2809 (setcdr data (cons (gnus-data-make number mark pos header level)
2810 (cdr data)))
2811 (setq gnus-newsgroup-data-reverse nil)
2812 (gnus-data-update-list (cddr data) offset)))
2813
2814(defun gnus-data-enter-list (after-article list &optional offset)
2815 (when list
2816 (let ((data (and after-article (gnus-data-find-list after-article)))
2817 (ilist list))
6748645f
LMI
2818 (if (not (or data
2819 after-article))
2820 (let ((odata gnus-newsgroup-data))
2821 (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
eec82323 2822 (when offset
6748645f 2823 (gnus-data-update-list odata offset)))
23f87bed 2824 ;; Find the last element in the list to be spliced into the main
6748645f
LMI
2825 ;; list.
2826 (while (cdr list)
2827 (setq list (cdr list)))
2828 (if (not data)
2829 (progn
2830 (setcdr list gnus-newsgroup-data)
2831 (setq gnus-newsgroup-data ilist)
2832 (when offset
2833 (gnus-data-update-list (cdr list) offset)))
2834 (setcdr list (cdr data))
2835 (setcdr data ilist)
2836 (when offset
2837 (gnus-data-update-list (cdr list) offset))))
eec82323
LMI
2838 (setq gnus-newsgroup-data-reverse nil))))
2839
2840(defun gnus-data-remove (article &optional offset)
2841 (let ((data gnus-newsgroup-data))
2842 (if (= (gnus-data-number (car data)) article)
2843 (progn
2844 (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2845 gnus-newsgroup-data-reverse nil)
2846 (when offset
2847 (gnus-data-update-list gnus-newsgroup-data offset)))
2848 (while (cdr data)
2849 (when (= (gnus-data-number (cadr data)) article)
2850 (setcdr data (cddr data))
2851 (when offset
2852 (gnus-data-update-list (cdr data) offset))
2853 (setq data nil
2854 gnus-newsgroup-data-reverse nil))
2855 (setq data (cdr data))))))
2856
2857(defmacro gnus-data-list (backward)
2858 `(if ,backward
2859 (or gnus-newsgroup-data-reverse
2860 (setq gnus-newsgroup-data-reverse
2861 (reverse gnus-newsgroup-data)))
2862 gnus-newsgroup-data))
2863
2864(defun gnus-data-update-list (data offset)
2865 "Add OFFSET to the POS of all data entries in DATA."
6748645f 2866 (setq gnus-newsgroup-data-reverse nil)
eec82323
LMI
2867 (while data
2868 (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2869 (setq data (cdr data))))
2870
eec82323
LMI
2871(defun gnus-summary-article-pseudo-p (article)
2872 "Say whether this article is a pseudo article or not."
2873 (not (vectorp (gnus-data-header (gnus-data-find article)))))
2874
2875(defmacro gnus-summary-article-sparse-p (article)
2876 "Say whether this article is a sparse article or not."
a8151ef7 2877 `(memq ,article gnus-newsgroup-sparse))
eec82323
LMI
2878
2879(defmacro gnus-summary-article-ancient-p (article)
2880 "Say whether this article is a sparse article or not."
2881 `(memq ,article gnus-newsgroup-ancient))
2882
2883(defun gnus-article-parent-p (number)
2884 "Say whether this article is a parent or not."
2885 (let ((data (gnus-data-find-list number)))
23f87bed 2886 (and (cdr data) ; There has to be an article after...
eec82323
LMI
2887 (< (gnus-data-level (car data)) ; And it has to have a higher level.
2888 (gnus-data-level (nth 1 data))))))
2889
2890(defun gnus-article-children (number)
2891 "Return a list of all children to NUMBER."
2892 (let* ((data (gnus-data-find-list number))
2893 (level (gnus-data-level (car data)))
2894 children)
2895 (setq data (cdr data))
2896 (while (and data
2897 (= (gnus-data-level (car data)) (1+ level)))
2898 (push (gnus-data-number (car data)) children)
2899 (setq data (cdr data)))
2900 children))
2901
2902(defmacro gnus-summary-skip-intangible ()
2903 "If the current article is intangible, then jump to a different article."
2904 '(let ((to (get-text-property (point) 'gnus-intangible)))
2905 (and to (gnus-summary-goto-subject to))))
2906
2907(defmacro gnus-summary-article-intangible-p ()
2908 "Say whether this article is intangible or not."
2909 '(get-text-property (point) 'gnus-intangible))
2910
2911(defun gnus-article-read-p (article)
2912 "Say whether ARTICLE is read or not."
2913 (not (or (memq article gnus-newsgroup-marked)
23f87bed 2914 (memq article gnus-newsgroup-spam-marked)
eec82323
LMI
2915 (memq article gnus-newsgroup-unreads)
2916 (memq article gnus-newsgroup-unselected)
2917 (memq article gnus-newsgroup-dormant))))
2918
2919;; Some summary mode macros.
2920
2921(defmacro gnus-summary-article-number ()
2922 "The article number of the article on the current line.
8f688cb0 2923If there isn't an article number here, then we return the current
eec82323
LMI
2924article number."
2925 '(progn
2926 (gnus-summary-skip-intangible)
2927 (or (get-text-property (point) 'gnus-number)
2928 (gnus-summary-last-subject))))
2929
2930(defmacro gnus-summary-article-header (&optional number)
6748645f 2931 "Return the header of article NUMBER."
eec82323
LMI
2932 `(gnus-data-header (gnus-data-find
2933 ,(or number '(gnus-summary-article-number)))))
2934
2935(defmacro gnus-summary-thread-level (&optional number)
6748645f 2936 "Return the level of thread that starts with article NUMBER."
eec82323
LMI
2937 `(if (and (eq gnus-summary-make-false-root 'dummy)
2938 (get-text-property (point) 'gnus-intangible))
2939 0
2940 (gnus-data-level (gnus-data-find
2941 ,(or number '(gnus-summary-article-number))))))
2942
2943(defmacro gnus-summary-article-mark (&optional number)
6748645f 2944 "Return the mark of article NUMBER."
eec82323
LMI
2945 `(gnus-data-mark (gnus-data-find
2946 ,(or number '(gnus-summary-article-number)))))
2947
2948(defmacro gnus-summary-article-pos (&optional number)
6748645f 2949 "Return the position of the line of article NUMBER."
eec82323
LMI
2950 `(gnus-data-pos (gnus-data-find
2951 ,(or number '(gnus-summary-article-number)))))
2952
2953(defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2954(defmacro gnus-summary-article-subject (&optional number)
2955 "Return current subject string or nil if nothing."
2956 `(let ((headers
2957 ,(if number
2958 `(gnus-data-header (assq ,number gnus-newsgroup-data))
2959 '(gnus-data-header (assq (gnus-summary-article-number)
2960 gnus-newsgroup-data)))))
2961 (and headers
2962 (vectorp headers)
2963 (mail-header-subject headers))))
2964
2965(defmacro gnus-summary-article-score (&optional number)
2966 "Return current article score."
2967 `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2968 gnus-newsgroup-scored))
2969 gnus-summary-default-score 0))
2970
2971(defun gnus-summary-article-children (&optional number)
6748645f 2972 "Return a list of article numbers that are children of article NUMBER."
eec82323
LMI
2973 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2974 (level (gnus-data-level (car data)))
2975 l children)
2976 (while (and (setq data (cdr data))
2977 (> (setq l (gnus-data-level (car data))) level))
2978 (and (= (1+ level) l)
2979 (push (gnus-data-number (car data))
2980 children)))
2981 (nreverse children)))
2982
2983(defun gnus-summary-article-parent (&optional number)
6748645f 2984 "Return the article number of the parent of article NUMBER."
eec82323
LMI
2985 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2986 (gnus-data-list t)))
2987 (level (gnus-data-level (car data))))
2988 (if (zerop level)
2989 () ; This is a root.
2990 ;; We search until we find an article with a level less than
2991 ;; this one. That function has to be the parent.
2992 (while (and (setq data (cdr data))
2993 (not (< (gnus-data-level (car data)) level))))
2994 (and data (gnus-data-number (car data))))))
2995
2996(defun gnus-unread-mark-p (mark)
2997 "Say whether MARK is the unread mark."
2998 (= mark gnus-unread-mark))
2999
3000(defun gnus-read-mark-p (mark)
3001 "Say whether MARK is one of the marks that mark as read.
3002This is all marks except unread, ticked, dormant, and expirable."
3003 (not (or (= mark gnus-unread-mark)
3004 (= mark gnus-ticked-mark)
23f87bed 3005 (= mark gnus-spam-mark)
eec82323
LMI
3006 (= mark gnus-dormant-mark)
3007 (= mark gnus-expirable-mark))))
3008
3009(defmacro gnus-article-mark (number)
6748645f
LMI
3010 "Return the MARK of article NUMBER.
3011This macro should only be used when computing the mark the \"first\"
3012time; i.e., when generating the summary lines. After that,
3013`gnus-summary-article-mark' should be used to examine the
3014marks of articles."
eec82323 3015 `(cond
6748645f 3016 ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
6748645f 3017 ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
eec82323
LMI
3018 ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3019 ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
23f87bed 3020 ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
eec82323
LMI
3021 ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3022 ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3023 (t (or (cdr (assq ,number gnus-newsgroup-reads))
3024 gnus-ancient-mark))))
3025
3026;; Saving hidden threads.
3027
eec82323
LMI
3028(defmacro gnus-save-hidden-threads (&rest forms)
3029 "Save hidden threads, eval FORMS, and restore the hidden threads."
3030 (let ((config (make-symbol "config")))
3031 `(let ((,config (gnus-hidden-threads-configuration)))
3032 (unwind-protect
3033 (save-excursion
3034 ,@forms)
3035 (gnus-restore-hidden-threads-configuration ,config)))))
23f87bed
MB
3036(put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3037(put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
eec82323 3038
107ecebb
AS
3039(defun gnus-data-compute-positions ()
3040 "Compute the positions of all articles."
3041 (setq gnus-newsgroup-data-reverse nil)
3042 (let ((data gnus-newsgroup-data))
3043 (save-excursion
3044 (gnus-save-hidden-threads
3045 (gnus-summary-show-all-threads)
3046 (goto-char (point-min))
3047 (while data
3048 (while (get-text-property (point) 'gnus-intangible)
3049 (forward-line 1))
3050 (gnus-data-set-pos (car data) (+ (point) 3))
3051 (setq data (cdr data))
3052 (forward-line 1))))))
3053
16409b0b
GM
3054(defun gnus-hidden-threads-configuration ()
3055 "Return the current hidden threads configuration."
3056 (save-excursion
3057 (let (config)
3058 (goto-char (point-min))
3059 (while (search-forward "\r" nil t)
3060 (push (1- (point)) config))
3061 config)))
3062
3063(defun gnus-restore-hidden-threads-configuration (config)
3064 "Restore hidden threads configuration from CONFIG."
3065 (save-excursion
3066 (let (point buffer-read-only)
3067 (while (setq point (pop config))
3068 (when (and (< point (point-max))
3069 (goto-char point)
3070 (eq (char-after) ?\n))
3071 (subst-char-in-region point (1+ point) ?\n ?\r))))))
3072
eec82323
LMI
3073;; Various summary mode internalish functions.
3074
3075(defun gnus-mouse-pick-article (e)
3076 (interactive "e")
3077 (mouse-set-point e)
3078 (gnus-summary-next-page nil t))
3079
3080(defun gnus-summary-set-display-table ()
16409b0b
GM
3081 "Change the display table.
3082Odd characters have a tendency to mess
3083up nicely formatted displays - we make all possible glyphs
3084display only a single character."
eec82323
LMI
3085
3086 ;; We start from the standard display table, if any.
3087 (let ((table (or (copy-sequence standard-display-table)
3088 (make-display-table)))
3089 (i 32))
3090 ;; Nix out all the control chars...
3091 (while (>= (setq i (1- i)) 0)
3092 (aset table i [??]))
23f87bed 3093 ;; ... but not newline and cr, of course. (cr is necessary for the
eec82323
LMI
3094 ;; selective display).
3095 (aset table ?\n nil)
3096 (aset table ?\r nil)
6748645f
LMI
3097 ;; We keep TAB as well.
3098 (aset table ?\t nil)
eec82323
LMI
3099 ;; We nix out any glyphs over 126 that are not set already.
3100 (let ((i 256))
3101 (while (>= (setq i (1- i)) 127)
3102 ;; Only modify if the entry is nil.
3103 (unless (aref table i)
3104 (aset table i [??]))))
3105 (setq buffer-display-table table)))
3106
23f87bed
MB
3107(defun gnus-summary-set-article-display-arrow (pos)
3108 "Update the overlay arrow to point to line at position POS."
3109 (when (and gnus-summary-display-arrow
3110 (boundp 'overlay-arrow-position)
3111 (boundp 'overlay-arrow-string))
3112 (save-excursion
3113 (goto-char pos)
3114 (beginning-of-line)
3115 (unless overlay-arrow-position
3116 (setq overlay-arrow-position (make-marker)))
3117 (setq overlay-arrow-string "=>"
3118 overlay-arrow-position (set-marker overlay-arrow-position
3119 (point)
3120 (current-buffer))))))
3121
eec82323
LMI
3122(defun gnus-summary-setup-buffer (group)
3123 "Initialize summary buffer."
23f87bed
MB
3124 (let ((buffer (gnus-summary-buffer-name group))
3125 (dead-name (concat "*Dead Summary "
3126 (gnus-group-decoded-name group) "*")))
3127 ;; If a dead summary buffer exists, we kill it.
3128 (when (gnus-buffer-live-p dead-name)
3129 (gnus-kill-buffer dead-name))
eec82323
LMI
3130 (if (get-buffer buffer)
3131 (progn
3132 (set-buffer buffer)
3133 (setq gnus-summary-buffer (current-buffer))
3134 (not gnus-newsgroup-prepared))
3135 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
6748645f 3136 (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
eec82323
LMI
3137 (gnus-summary-mode group)
3138 (when gnus-carpal
3139 (gnus-carpal-setup-buffer 'summary))
3140 (unless gnus-single-article-buffer
3141 (make-local-variable 'gnus-article-buffer)
3142 (make-local-variable 'gnus-article-current)
3143 (make-local-variable 'gnus-original-article-buffer))
3144 (setq gnus-newsgroup-name group)
23f87bed
MB
3145 ;; Set any local variables in the group parameters.
3146 (gnus-summary-set-local-parameters gnus-newsgroup-name)
eec82323
LMI
3147 t)))
3148
3149(defun gnus-set-global-variables ()
16409b0b
GM
3150 "Set the global equivalents of the buffer-local variables.
3151They are set to the latest values they had. These reflect the summary
3152buffer that was in action when the last article was fetched."
eec82323
LMI
3153 (when (eq major-mode 'gnus-summary-mode)
3154 (setq gnus-summary-buffer (current-buffer))
3155 (let ((name gnus-newsgroup-name)
3156 (marked gnus-newsgroup-marked)
23f87bed 3157 (spam gnus-newsgroup-spam-marked)
eec82323
LMI
3158 (unread gnus-newsgroup-unreads)
3159 (headers gnus-current-headers)
3160 (data gnus-newsgroup-data)
3161 (summary gnus-summary-buffer)
3162 (article-buffer gnus-article-buffer)
3163 (original gnus-original-article-buffer)
3164 (gac gnus-article-current)
3165 (reffed gnus-reffed-article-number)
16409b0b 3166 (score-file gnus-current-score-file)
23f87bed
MB
3167 (default-charset gnus-newsgroup-charset)
3168 vlist)
3169 (let ((locals gnus-newsgroup-variables))
3170 (while locals
3171 (if (consp (car locals))
3172 (push (eval (caar locals)) vlist)
3173 (push (eval (car locals)) vlist))
3174 (setq locals (cdr locals)))
3175 (setq vlist (nreverse vlist)))
eec82323
LMI
3176 (save-excursion
3177 (set-buffer gnus-group-buffer)
6748645f
LMI
3178 (setq gnus-newsgroup-name name
3179 gnus-newsgroup-marked marked
23f87bed 3180 gnus-newsgroup-spam-marked spam
6748645f
LMI
3181 gnus-newsgroup-unreads unread
3182 gnus-current-headers headers
3183 gnus-newsgroup-data data
3184 gnus-article-current gac
3185 gnus-summary-buffer summary
3186 gnus-article-buffer article-buffer
3187 gnus-original-article-buffer original
3188 gnus-reffed-article-number reffed
16409b0b
GM
3189 gnus-current-score-file score-file
3190 gnus-newsgroup-charset default-charset)
23f87bed
MB
3191 (let ((locals gnus-newsgroup-variables))
3192 (while locals
3193 (if (consp (car locals))
3194 (set (caar locals) (pop vlist))
3195 (set (car locals) (pop vlist)))
3196 (setq locals (cdr locals))))
eec82323
LMI
3197 ;; The article buffer also has local variables.
3198 (when (gnus-buffer-live-p gnus-article-buffer)
3199 (set-buffer gnus-article-buffer)
3200 (setq gnus-summary-buffer summary))))))
3201
3202(defun gnus-summary-article-unread-p (article)
3203 "Say whether ARTICLE is unread or not."
3204 (memq article gnus-newsgroup-unreads))
3205
3206(defun gnus-summary-first-article-p (&optional article)
3207 "Return whether ARTICLE is the first article in the buffer."
3208 (if (not (setq article (or article (gnus-summary-article-number))))
3209 nil
3210 (eq article (caar gnus-newsgroup-data))))
3211
3212(defun gnus-summary-last-article-p (&optional article)
3213 "Return whether ARTICLE is the last article in the buffer."
3214 (if (not (setq article (or article (gnus-summary-article-number))))
16409b0b
GM
3215 ;; All non-existent numbers are the last article. :-)
3216 t
eec82323
LMI
3217 (not (cdr (gnus-data-find-list article)))))
3218
3219(defun gnus-make-thread-indent-array ()
3220 (let ((n 200))
3221 (unless (and gnus-thread-indent-array
3222 (= gnus-thread-indent-level gnus-thread-indent-array-level))
3223 (setq gnus-thread-indent-array (make-vector 201 "")
3224 gnus-thread-indent-array-level gnus-thread-indent-level)
3225 (while (>= n 0)
3226 (aset gnus-thread-indent-array n
3227 (make-string (* n gnus-thread-indent-level) ? ))
3228 (setq n (1- n))))))
3229
3230(defun gnus-update-summary-mark-positions ()
3231 "Compute where the summary marks are to go."
3232 (save-excursion
6748645f 3233 (when (gnus-buffer-exists-p gnus-summary-buffer)
eec82323 3234 (set-buffer gnus-summary-buffer))
5153a47a
MB
3235 (let ((spec gnus-summary-line-format-spec)
3236 pos)
eec82323
LMI
3237 (save-excursion
3238 (gnus-set-work-buffer)
5153a47a
MB
3239 (let ((gnus-tmp-unread ?Z)
3240 (gnus-replied-mark ?Z)
3241 (gnus-score-below-mark ?Z)
3242 (gnus-score-over-mark ?Z)
3243 (gnus-undownloaded-mark ?Z)
3244 (gnus-summary-line-format-spec spec)
54506618 3245 (gnus-newsgroup-downloadable '(0))
5153a47a
MB
3246 (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3247 case-fold-search ignores)
3248 ;; Here, all marks are bound to Z.
3249 (gnus-summary-insert-line header
3250 0 nil t gnus-tmp-unread t nil "" nil 1)
3251 (goto-char (point-min))
3252 ;; Memorize the positions of the same characters as dummy marks.
3253 (while (re-search-forward "[A-D]" nil t)
3254 (push (point) ignores))
54506618 3255 (erase-buffer)
5153a47a
MB
3256 ;; We use A-D as dummy marks in order to know column positions
3257 ;; where marks should be inserted.
3258 (setq gnus-tmp-unread ?A
3259 gnus-replied-mark ?B
3260 gnus-score-below-mark ?C
3261 gnus-score-over-mark ?C
3262 gnus-undownloaded-mark ?D)
3263 (gnus-summary-insert-line header
3264 0 nil t gnus-tmp-unread t nil "" nil 1)
3265 ;; Ignore characters which aren't dummy marks.
3266 (dolist (p ignores)
3267 (delete-region (goto-char (1- p)) p)
3268 (insert ?Z))
eec82323 3269 (goto-char (point-min))
7c3bb5a5 3270 (setq pos (list (cons 'unread
5153a47a 3271 (and (search-forward "A" nil t)
7c3bb5a5 3272 (- (point) (point-min) 1)))))
eec82323 3273 (goto-char (point-min))
5153a47a 3274 (push (cons 'replied (and (search-forward "B" nil t)
667e0ba6 3275 (- (point) (point-min) 1)))
eec82323
LMI
3276 pos)
3277 (goto-char (point-min))
5153a47a 3278 (push (cons 'score (and (search-forward "C" nil t)
667e0ba6 3279 (- (point) (point-min) 1)))
6748645f
LMI
3280 pos)
3281 (goto-char (point-min))
5153a47a 3282 (push (cons 'download (and (search-forward "D" nil t)
7c3bb5a5 3283 (- (point) (point-min) 1)))
eec82323
LMI
3284 pos)))
3285 (setq gnus-summary-mark-positions pos))))
3286
3287(defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3288 "Insert a dummy root in the summary buffer."
3289 (beginning-of-line)
3290 (gnus-add-text-properties
3291 (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3292 (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3293
23f87bed
MB
3294(defun gnus-summary-extract-address-component (from)
3295 (or (car (funcall gnus-extract-address-components from))
3296 from))
3297
3298(defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3299 (let ((mail-parse-charset gnus-newsgroup-charset)
3300 ; Is it really necessary to do this next part for each summary line?
3301 ; Luckily, doesn't seem to slow things down much.
16409b0b
GM
3302 (mail-parse-ignored-charsets
3303 (save-excursion (set-buffer gnus-summary-buffer)
3304 gnus-newsgroup-ignored-charsets)))
23f87bed
MB
3305 (or
3306 (and gnus-ignored-from-addresses
2a0d53ac 3307 (not (string= gnus-ignored-from-addresses ""))
23f87bed
MB
3308 (string-match gnus-ignored-from-addresses gnus-tmp-from)
3309 (let ((extra-headers (mail-header-extra header))
3310 to
3311 newsgroups)
3312 (cond
3313 ((setq to (cdr (assq 'To extra-headers)))
3314 (concat "-> "
3315 (inline
3316 (gnus-summary-extract-address-component
3317 (funcall gnus-decode-encoded-word-function to)))))
3318 ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3319 (concat "=> " newsgroups)))))
3320 (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
16409b0b 3321
eec82323
LMI
3322(defun gnus-summary-insert-line (gnus-tmp-header
3323 gnus-tmp-level gnus-tmp-current
23f87bed 3324 undownloaded gnus-tmp-unread gnus-tmp-replied
eec82323
LMI
3325 gnus-tmp-expirable gnus-tmp-subject-or-nil
3326 &optional gnus-tmp-dummy gnus-tmp-score
3327 gnus-tmp-process)
3328 (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3329 (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3330 (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3331 (gnus-tmp-score-char
3332 (if (or (null gnus-summary-default-score)
3333 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3334 gnus-summary-zcore-fuzz))
23f87bed 3335 ? ;Whitespace
eec82323
LMI
3336 (if (< gnus-tmp-score gnus-summary-default-score)
3337 gnus-score-below-mark gnus-score-over-mark)))
23f87bed 3338 (gnus-tmp-number (mail-header-number gnus-tmp-header))
eec82323
LMI
3339 (gnus-tmp-replied
3340 (cond (gnus-tmp-process gnus-process-mark)
3341 ((memq gnus-tmp-current gnus-newsgroup-cached)
3342 gnus-cached-mark)
3343 (gnus-tmp-replied gnus-replied-mark)
23f87bed
MB
3344 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3345 gnus-forwarded-mark)
eec82323
LMI
3346 ((memq gnus-tmp-current gnus-newsgroup-saved)
3347 gnus-saved-mark)
23f87bed
MB
3348 ((memq gnus-tmp-number gnus-newsgroup-recent)
3349 gnus-recent-mark)
3350 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3351 gnus-unseen-mark)
3352 (t gnus-no-mark)))
3353 (gnus-tmp-downloaded
3354 (cond (undownloaded
3355 gnus-undownloaded-mark)
3356 (gnus-newsgroup-agentized
3357 gnus-downloaded-mark)
3358 (t
3359 gnus-no-mark)))
eec82323
LMI
3360 (gnus-tmp-from (mail-header-from gnus-tmp-header))
3361 (gnus-tmp-name
3362 (cond
3363 ((string-match "<[^>]+> *$" gnus-tmp-from)
3364 (let ((beg (match-beginning 0)))
23f87bed
MB
3365 (or (and (string-match "^\".+\"" gnus-tmp-from)
3366 (substring gnus-tmp-from 1 (1- (match-end 0))))
eec82323
LMI
3367 (substring gnus-tmp-from 0 beg))))
3368 ((string-match "(.+)" gnus-tmp-from)
3369 (substring gnus-tmp-from
3370 (1+ (match-beginning 0)) (1- (match-end 0))))
3371 (t gnus-tmp-from)))
3372 (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
eec82323
LMI
3373 (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3374 (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3375 (buffer-read-only nil))
3376 (when (string= gnus-tmp-name "")
3377 (setq gnus-tmp-name gnus-tmp-from))
3378 (unless (numberp gnus-tmp-lines)
23f87bed
MB
3379 (setq gnus-tmp-lines -1))
3380 (if (= gnus-tmp-lines -1)
3381 (setq gnus-tmp-lines "?")
3382 (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3383 (gnus-put-text-property
eec82323
LMI
3384 (point)
3385 (progn (eval gnus-summary-line-format-spec) (point))
23f87bed 3386 'gnus-number gnus-tmp-number)
eec82323
LMI
3387 (when (gnus-visual-p 'summary-highlight 'highlight)
3388 (forward-line -1)
6748645f 3389 (gnus-run-hooks 'gnus-summary-update-hook)
eec82323
LMI
3390 (forward-line 1))))
3391
3392(defun gnus-summary-update-line (&optional dont-update)
16409b0b 3393 "Update summary line after change."
eec82323
LMI
3394 (when (and gnus-summary-default-score
3395 (not gnus-summary-inhibit-highlight))
3396 (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3397 (article (gnus-summary-article-number))
3398 (score (gnus-summary-article-score article)))
3399 (unless dont-update
3400 (if (and gnus-summary-mark-below
3401 (< (gnus-summary-article-score)
3402 gnus-summary-mark-below))
3403 ;; This article has a low score, so we mark it as read.
3404 (when (memq article gnus-newsgroup-unreads)
3405 (gnus-summary-mark-article-as-read gnus-low-score-mark))
3406 (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3407 ;; This article was previously marked as read on account
3408 ;; of a low score, but now it has risen, so we mark it as
3409 ;; unread.
3410 (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3411 (gnus-summary-update-mark
3412 (if (or (null gnus-summary-default-score)
3413 (<= (abs (- score gnus-summary-default-score))
3414 gnus-summary-zcore-fuzz))
23f87bed 3415 ? ;Whitespace
eec82323
LMI
3416 (if (< score gnus-summary-default-score)
3417 gnus-score-below-mark gnus-score-over-mark))
3418 'score))
3419 ;; Do visual highlighting.
3420 (when (gnus-visual-p 'summary-highlight 'highlight)
6748645f 3421 (gnus-run-hooks 'gnus-summary-update-hook)))))
eec82323
LMI
3422
3423(defvar gnus-tmp-new-adopts nil)
3424
3425(defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3426 "Return the number of articles in THREAD.
3427This may be 0 in some cases -- if none of the articles in
3428the thread are to be displayed."
3429 (let* ((number
23f87bed 3430 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
eec82323
LMI
3431 (cond
3432 ((not (listp thread))
3433 1)
3434 ((and (consp thread) (cdr thread))
3435 (apply
3436 '+ 1 (mapcar
3437 'gnus-summary-number-of-articles-in-thread (cdr thread))))
3438 ((null thread)
3439 1)
3440 ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3441 1)
3442 (t 0))))
3443 (when (and level (zerop level) gnus-tmp-new-adopts)
3444 (incf number
3445 (apply '+ (mapcar
3446 'gnus-summary-number-of-articles-in-thread
3447 gnus-tmp-new-adopts))))
3448 (if char
3449 (if (> number 1) gnus-not-empty-thread-mark
3450 gnus-empty-thread-mark)
3451 number)))
3452
23f87bed
MB
3453(defsubst gnus-summary-line-message-size (head)
3454 "Return pretty-printed version of message size.
3455This function is intended to be used in
3456`gnus-summary-line-format-alist'."
3457 (let ((c (or (mail-header-chars head) -1)))
3458 (cond ((< c 0) "n/a") ; chars not available
3459 ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3460 ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3461 ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3462 (t (format "%dM" (/ c (* 1024.0 1024)))))))
3463
3464
eec82323
LMI
3465(defun gnus-summary-set-local-parameters (group)
3466 "Go through the local params of GROUP and set all variable specs in that list."
3467 (let ((params (gnus-group-find-parameter group))
23f87bed 3468 (vars '(quit-config)) ; Ignore quit-config.
eec82323
LMI
3469 elem)
3470 (while params
3471 (setq elem (car params)
3472 params (cdr params))
3473 (and (consp elem) ; Has to be a cons.
3474 (consp (cdr elem)) ; The cdr has to be a list.
3475 (symbolp (car elem)) ; Has to be a symbol in there.
23f87bed 3476 (not (memq (car elem) vars))
eec82323 3477 (ignore-errors ; So we set it.
23f87bed 3478 (push (car elem) vars)
eec82323
LMI
3479 (make-local-variable (car elem))
3480 (set (car elem) (eval (nth 1 elem))))))))
3481
3482(defun gnus-summary-read-group (group &optional show-all no-article
6748645f
LMI
3483 kill-buffer no-display backward
3484 select-articles)
eec82323
LMI
3485 "Start reading news in newsgroup GROUP.
3486If SHOW-ALL is non-nil, already read articles are also listed.
3487If NO-ARTICLE is non-nil, no article is selected initially.
3488If NO-DISPLAY, don't generate a summary buffer."
3489 (let (result)
3490 (while (and group
3491 (null (setq result
3492 (let ((gnus-auto-select-next nil))
6748645f
LMI
3493 (or (gnus-summary-read-group-1
3494 group show-all no-article
3495 kill-buffer no-display
3496 select-articles)
3497 (setq show-all nil
16409b0b 3498 select-articles nil)))))
eec82323
LMI
3499 (eq gnus-auto-select-next 'quietly))
3500 (set-buffer gnus-group-buffer)
6748645f
LMI
3501 ;; The entry function called above goes to the next
3502 ;; group automatically, so we go two groups back
3503 ;; if we are searching for the previous group.
3504 (when backward
3505 (gnus-group-prev-unread-group 2))
eec82323
LMI
3506 (if (not (equal group (gnus-group-group-name)))
3507 (setq group (gnus-group-group-name))
3508 (setq group nil)))
3509 result))
3510
3511(defun gnus-summary-read-group-1 (group show-all no-article
6748645f
LMI
3512 kill-buffer no-display
3513 &optional select-articles)
eec82323 3514 ;; Killed foreign groups can't be entered.
23f87bed
MB
3515 ;; (when (and (not (gnus-group-native-p group))
3516 ;; (not (gnus-gethash group gnus-newsrc-hashtb)))
3517 ;; (error "Dead non-native groups can't be entered"))
3518 (gnus-message 5 "Retrieving newsgroup: %s..."
3519 (gnus-group-decoded-name group))
eec82323
LMI
3520 (let* ((new-group (gnus-summary-setup-buffer group))
3521 (quit-config (gnus-group-quit-config group))
6748645f
LMI
3522 (did-select (and new-group (gnus-select-newsgroup
3523 group show-all select-articles))))
eec82323
LMI
3524 (cond
3525 ;; This summary buffer exists already, so we just select it.
3526 ((not new-group)
3527 (gnus-set-global-variables)
3528 (when kill-buffer
3529 (gnus-kill-or-deaden-summary kill-buffer))
3530 (gnus-configure-windows 'summary 'force)
3531 (gnus-set-mode-line 'summary)
3532 (gnus-summary-position-point)
3533 (message "")
3534 t)
3535 ;; We couldn't select this group.
3536 ((null did-select)
3537 (when (and (eq major-mode 'gnus-summary-mode)
3538 (not (equal (current-buffer) kill-buffer)))
3539 (kill-buffer (current-buffer))
3540 (if (not quit-config)
3541 (progn
6748645f
LMI
3542 ;; Update the info -- marks might need to be removed,
3543 ;; for instance.
3544 (gnus-summary-update-info)
eec82323
LMI
3545 (set-buffer gnus-group-buffer)
3546 (gnus-group-jump-to-group group)
3547 (gnus-group-next-unread-group 1))
3548 (gnus-handle-ephemeral-exit quit-config)))
23f87bed
MB
3549 (let ((grpinfo (gnus-get-info group)))
3550 (if (null (gnus-info-read grpinfo))
3551 (gnus-message 3 "Group %s contains no messages"
3552 (gnus-group-decoded-name group))
3553 (gnus-message 3 "Can't select group")))
eec82323
LMI
3554 nil)
3555 ;; The user did a `C-g' while prompting for number of articles,
3556 ;; so we exit this group.
3557 ((eq did-select 'quit)
3558 (and (eq major-mode 'gnus-summary-mode)
3559 (not (equal (current-buffer) kill-buffer))
3560 (kill-buffer (current-buffer)))
3561 (when kill-buffer
3562 (gnus-kill-or-deaden-summary kill-buffer))
3563 (if (not quit-config)
3564 (progn
3565 (set-buffer gnus-group-buffer)
3566 (gnus-group-jump-to-group group)
3567 (gnus-group-next-unread-group 1)
3568 (gnus-configure-windows 'group 'force))
3569 (gnus-handle-ephemeral-exit quit-config))
3570 ;; Finally signal the quit.
3571 (signal 'quit nil))
3572 ;; The group was successfully selected.
3573 (t
3574 (gnus-set-global-variables)
3575 ;; Save the active value in effect when the group was entered.
3576 (setq gnus-newsgroup-active
3577 (gnus-copy-sequence
3578 (gnus-active gnus-newsgroup-name)))
3579 ;; You can change the summary buffer in some way with this hook.
6748645f 3580 (gnus-run-hooks 'gnus-select-group-hook)
5153a47a
MB
3581 (when (memq 'summary (gnus-update-format-specifications
3582 nil 'summary 'summary-mode 'summary-dummy))
3583 ;; The format specification for the summary line was updated,
3584 ;; so we need to update the mark positions as well.
3585 (gnus-update-summary-mark-positions))
eec82323
LMI
3586 ;; Do score processing.
3587 (when gnus-use-scoring
3588 (gnus-possibly-score-headers))
3589 ;; Check whether to fill in the gaps in the threads.
3590 (when gnus-build-sparse-threads
3591 (gnus-build-sparse-threads))
3592 ;; Find the initial limit.
3593 (if gnus-show-threads
3594 (if show-all
3595 (let ((gnus-newsgroup-dormant nil))
3596 (gnus-summary-initial-limit show-all))
3597 (gnus-summary-initial-limit show-all))
8f688cb0 3598 ;; When unthreaded, all articles are always shown.
eec82323
LMI
3599 (setq gnus-newsgroup-limit
3600 (mapcar
3601 (lambda (header) (mail-header-number header))
3602 gnus-newsgroup-headers)))
3603 ;; Generate the summary buffer.
3604 (unless no-display
3605 (gnus-summary-prepare))
3606 (when gnus-use-trees
3607 (gnus-tree-open group)
3608 (setq gnus-summary-highlight-line-function
3609 'gnus-tree-highlight-article))
3610 ;; If the summary buffer is empty, but there are some low-scored
3611 ;; articles or some excluded dormants, we include these in the
3612 ;; buffer.
3613 (when (and (zerop (buffer-size))
3614 (not no-display))
3615 (cond (gnus-newsgroup-dormant
3616 (gnus-summary-limit-include-dormant))
3617 ((and gnus-newsgroup-scored show-all)
3618 (gnus-summary-limit-include-expunged t))))
3619 ;; Function `gnus-apply-kill-file' must be called in this hook.
6748645f 3620 (gnus-run-hooks 'gnus-apply-kill-hook)
eec82323
LMI
3621 (if (and (zerop (buffer-size))
3622 (not no-display))
3623 (progn
3624 ;; This newsgroup is empty.
3625 (gnus-summary-catchup-and-exit nil t)
3626 (gnus-message 6 "No unread news")
3627 (when kill-buffer
3628 (gnus-kill-or-deaden-summary kill-buffer))
3629 ;; Return nil from this function.
3630 nil)
3631 ;; Hide conversation thread subtrees. We cannot do this in
3632 ;; gnus-summary-prepare-hook since kill processing may not
3633 ;; work with hidden articles.
23f87bed 3634 (gnus-summary-maybe-hide-threads)
6748645f
LMI
3635 (when kill-buffer
3636 (gnus-kill-or-deaden-summary kill-buffer))
23f87bed 3637 (gnus-summary-auto-select-subject)
eec82323
LMI
3638 ;; Show first unread article if requested.
3639 (if (and (not no-article)
3640 (not no-display)
3641 gnus-newsgroup-unreads
3642 gnus-auto-select-first)
16409b0b
GM
3643 (progn
3644 (gnus-configure-windows 'summary)
23f87bed
MB
3645 (let ((art (gnus-summary-article-number)))
3646 (unless (and (not gnus-plugged)
3647 (or (memq art gnus-newsgroup-undownloaded)
3648 (memq art gnus-newsgroup-downloadable)))
3649 (gnus-summary-goto-article art))))
3650 ;; Don't select any articles.
eec82323 3651 (gnus-summary-position-point)
6748645f
LMI
3652 (gnus-configure-windows 'summary 'force)
3653 (gnus-set-mode-line 'summary))
23f87bed
MB
3654 (when (and gnus-auto-center-group
3655 (get-buffer-window gnus-group-buffer t))
eec82323
LMI
3656 ;; Gotta use windows, because recenter does weird stuff if
3657 ;; the current buffer ain't the displayed window.
3658 (let ((owin (selected-window)))
3659 (select-window (get-buffer-window gnus-group-buffer t))
3660 (when (gnus-group-goto-group group)
3661 (recenter))
3662 (select-window owin)))
3663 ;; Mark this buffer as "prepared".
3664 (setq gnus-newsgroup-prepared t)
6748645f 3665 (gnus-run-hooks 'gnus-summary-prepared-hook)
23f87bed
MB
3666 (unless (gnus-ephemeral-group-p group)
3667 (gnus-group-update-group group))
eec82323
LMI
3668 t)))))
3669
23f87bed
MB
3670(defun gnus-summary-auto-select-subject ()
3671 "Select the subject line on initial group entry."
3672 (goto-char (point-min))
3673 (cond
3674 ((eq gnus-auto-select-subject 'best)
3675 (gnus-summary-best-unread-subject))
3676 ((eq gnus-auto-select-subject 'unread)
3677 (gnus-summary-first-unread-subject))
3678 ((eq gnus-auto-select-subject 'unseen)
3679 (gnus-summary-first-unseen-subject))
3680 ((eq gnus-auto-select-subject 'unseen-or-unread)
3681 (gnus-summary-first-unseen-or-unread-subject))
3682 ((eq gnus-auto-select-subject 'first)
3683 ;; Do nothing.
3684 )
3685 ((functionp gnus-auto-select-subject)
3686 (funcall gnus-auto-select-subject))))
3687
eec82323
LMI
3688(defun gnus-summary-prepare ()
3689 "Generate the summary buffer."
3690 (interactive)
3691 (let ((buffer-read-only nil))
3692 (erase-buffer)
3693 (setq gnus-newsgroup-data nil
3694 gnus-newsgroup-data-reverse nil)
6748645f 3695 (gnus-run-hooks 'gnus-summary-generate-hook)
eec82323
LMI
3696 ;; Generate the buffer, either with threads or without.
3697 (when gnus-newsgroup-headers
3698 (gnus-summary-prepare-threads
3699 (if gnus-show-threads
3700 (gnus-sort-gathered-threads
3701 (funcall gnus-summary-thread-gathering-function
3702 (gnus-sort-threads
3703 (gnus-cut-threads (gnus-make-threads)))))
3704 ;; Unthreaded display.
3705 (gnus-sort-articles gnus-newsgroup-headers))))
3706 (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3707 ;; Call hooks for modifying summary buffer.
3708 (goto-char (point-min))
6748645f 3709 (gnus-run-hooks 'gnus-summary-prepare-hook)))
eec82323
LMI
3710
3711(defsubst gnus-general-simplify-subject (subject)
23f87bed 3712 "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
eec82323
LMI
3713 (setq subject
3714 (cond
3715 ;; Truncate the subject.
6748645f
LMI
3716 (gnus-simplify-subject-functions
3717 (gnus-map-function gnus-simplify-subject-functions subject))
eec82323
LMI
3718 ((numberp gnus-summary-gather-subject-limit)
3719 (setq subject (gnus-simplify-subject-re subject))
3720 (if (> (length subject) gnus-summary-gather-subject-limit)
3721 (substring subject 0 gnus-summary-gather-subject-limit)
3722 subject))
3723 ;; Fuzzily simplify it.
3724 ((eq 'fuzzy gnus-summary-gather-subject-limit)
3725 (gnus-simplify-subject-fuzzy subject))
3726 ;; Just remove the leading "Re:".
3727 (t
3728 (gnus-simplify-subject-re subject))))
3729
3730 (if (and gnus-summary-gather-exclude-subject
3731 (string-match gnus-summary-gather-exclude-subject subject))
23f87bed 3732 nil ; This article shouldn't be gathered
eec82323
LMI
3733 subject))
3734
3735(defun gnus-summary-simplify-subject-query ()
3736 "Query where the respool algorithm would put this article."
3737 (interactive)
eec82323
LMI
3738 (gnus-summary-select-article)
3739 (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3740
3741(defun gnus-gather-threads-by-subject (threads)
3742 "Gather threads by looking at Subject headers."
3743 (if (not gnus-summary-make-false-root)
3744 threads
3745 (let ((hashtb (gnus-make-hashtable 1024))
3746 (prev threads)
3747 (result threads)
3748 subject hthread whole-subject)
3749 (while threads
3750 (setq subject (gnus-general-simplify-subject
3751 (setq whole-subject (mail-header-subject
3752 (caar threads)))))
3753 (when subject
3754 (if (setq hthread (gnus-gethash subject hashtb))
3755 (progn
3756 ;; We enter a dummy root into the thread, if we
3757 ;; haven't done that already.
3758 (unless (stringp (caar hthread))
3759 (setcar hthread (list whole-subject (car hthread))))
3760 ;; We add this new gathered thread to this gathered
3761 ;; thread.
3762 (setcdr (car hthread)
3763 (nconc (cdar hthread) (list (car threads))))
3764 ;; Remove it from the list of threads.
3765 (setcdr prev (cdr threads))
3766 (setq threads prev))
3767 ;; Enter this thread into the hash table.
23f87bed
MB
3768 (gnus-sethash subject
3769 (if gnus-summary-make-false-root-always
3770 (progn
3771 ;; If you want a dummy root above all
3772 ;; threads...
3773 (setcar threads (list whole-subject
3774 (car threads)))
3775 threads)
3776 threads)
3777 hashtb)))
eec82323
LMI
3778 (setq prev threads)
3779 (setq threads (cdr threads)))
3780 result)))
3781
3782(defun gnus-gather-threads-by-references (threads)
3783 "Gather threads by looking at References headers."
3784 (let ((idhashtb (gnus-make-hashtable 1024))
3785 (thhashtb (gnus-make-hashtable 1024))
3786 (prev threads)
3787 (result threads)
3788 ids references id gthread gid entered ref)
3789 (while threads
3790 (when (setq references (mail-header-references (caar threads)))
3791 (setq id (mail-header-id (caar threads))
23f87bed 3792 ids (inline (gnus-split-references references))
eec82323
LMI
3793 entered nil)
3794 (while (setq ref (pop ids))
3795 (setq ids (delete ref ids))
3796 (if (not (setq gid (gnus-gethash ref idhashtb)))
3797 (progn
3798 (gnus-sethash ref id idhashtb)
3799 (gnus-sethash id threads thhashtb))
3800 (setq gthread (gnus-gethash gid thhashtb))
3801 (unless entered
3802 ;; We enter a dummy root into the thread, if we
3803 ;; haven't done that already.
3804 (unless (stringp (caar gthread))
3805 (setcar gthread (list (mail-header-subject (caar gthread))
3806 (car gthread))))
3807 ;; We add this new gathered thread to this gathered
3808 ;; thread.
3809 (setcdr (car gthread)
3810 (nconc (cdar gthread) (list (car threads)))))
3811 ;; Add it into the thread hash table.
3812 (gnus-sethash id gthread thhashtb)
3813 (setq entered t)
3814 ;; Remove it from the list of threads.
3815 (setcdr prev (cdr threads))
3816 (setq threads prev))))
3817 (setq prev threads)
3818 (setq threads (cdr threads)))
3819 result))
3820
3821(defun gnus-sort-gathered-threads (threads)
16409b0b 3822 "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
eec82323
LMI
3823 (let ((result threads))
3824 (while threads
3825 (when (stringp (caar threads))
3826 (setcdr (car threads)
16409b0b 3827 (sort (cdar threads) gnus-sort-gathered-threads-function)))
eec82323
LMI
3828 (setq threads (cdr threads)))
3829 result))
3830
3831(defun gnus-thread-loop-p (root thread)
3832 "Say whether ROOT is in THREAD."
3833 (let ((stack (list thread))
3834 (infloop 0)
3835 th)
3836 (while (setq thread (pop stack))
3837 (setq th (cdr thread))
3838 (while (and th
3839 (not (eq (caar th) root)))
3840 (pop th))
3841 (if th
3842 ;; We have found a loop.
3843 (let (ref-dep)
3844 (setcdr thread (delq (car th) (cdr thread)))
3845 (if (boundp (setq ref-dep (intern "none"
3846 gnus-newsgroup-dependencies)))
3847 (setcdr (symbol-value ref-dep)
3848 (nconc (cdr (symbol-value ref-dep))
3849 (list (car th))))
3850 (set ref-dep (list nil (car th))))
3851 (setq infloop 1
3852 stack nil))
3853 ;; Push all the subthreads onto the stack.
3854 (push (cdr thread) stack)))
3855 infloop))
3856
3857(defun gnus-make-threads ()
3858 "Go through the dependency hashtb and find the roots. Return all threads."
3859 (let (threads)
3860 (while (catch 'infloop
3861 (mapatoms
3862 (lambda (refs)
3863 ;; Deal with self-referencing References loops.
3864 (when (and (car (symbol-value refs))
3865 (not (zerop
3866 (apply
3867 '+
3868 (mapcar
3869 (lambda (thread)
3870 (gnus-thread-loop-p
3871 (car (symbol-value refs)) thread))
3872 (cdr (symbol-value refs)))))))
3873 (setq threads nil)
3874 (throw 'infloop t))
3875 (unless (car (symbol-value refs))
23f87bed
MB
3876 ;; These threads do not refer back to any other
3877 ;; articles, so they're roots.
eec82323
LMI
3878 (setq threads (append (cdr (symbol-value refs)) threads))))
3879 gnus-newsgroup-dependencies)))
3880 threads))
3881
6748645f 3882;; Build the thread tree.
16409b0b 3883(defsubst gnus-dependencies-add-header (header dependencies force-new)
6748645f
LMI
3884 "Enter HEADER into the DEPENDENCIES table if it is not already there.
3885
3886If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3887if it was already present.
3888
3889If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3890will not be entered in the DEPENDENCIES table. Otherwise duplicate
23f87bed
MB
3891Message-IDs will be renamed to a unique Message-ID before being
3892entered.
6748645f
LMI
3893
3894Returns HEADER if it was entered in the DEPENDENCIES. Returns nil otherwise."
3895 (let* ((id (mail-header-id header))
3896 (id-dep (and id (intern id dependencies)))
23f87bed 3897 parent-id ref ref-dep ref-header replaced)
6748645f
LMI
3898 ;; Enter this `header' in the `dependencies' table.
3899 (cond
3900 ((not id-dep)
3901 (setq header nil))
3902 ;; The first two cases do the normal part: enter a new `header'
3903 ;; in the `dependencies' table.
3904 ((not (boundp id-dep))
3905 (set id-dep (list header)))
3906 ((null (car (symbol-value id-dep)))
3907 (setcar (symbol-value id-dep) header))
3908
3909 ;; From here the `header' was already present in the
3910 ;; `dependencies' table.
3911 (force-new
3912 ;; Overrides an existing entry;
3913 ;; just set the header part of the entry.
23f87bed
MB
3914 (setcar (symbol-value id-dep) header)
3915 (setq replaced t))
6748645f
LMI
3916
3917 ;; Renames the existing `header' to a unique Message-ID.
3918 ((not gnus-summary-ignore-duplicates)
3919 ;; An article with this Message-ID has already been seen.
3920 ;; We rename the Message-ID.
3921 (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3922 (list header))
3923 (mail-header-set-id header id))
3924
3925 ;; The last case ignores an existing entry, except it adds any
3926 ;; additional Xrefs (in case the two articles came from different
3927 ;; servers.
3928 ;; Also sets `header' to `nil' meaning that the `dependencies'
3929 ;; table was *not* modified.
3930 (t
3931 (mail-header-set-xref
3932 (car (symbol-value id-dep))
3933 (concat (or (mail-header-xref (car (symbol-value id-dep)))
3934 "")
3935 (or (mail-header-xref header) "")))
3936 (setq header nil)))
3937
23f87bed
MB
3938 (when (and header (not replaced))
3939 ;; First check that we are not creating a References loop.
3940 (setq parent-id (gnus-parent-id (mail-header-references header)))
3941 (setq ref parent-id)
6748645f
LMI
3942 (while (and ref
3943 (setq ref-dep (intern-soft ref dependencies))
3944 (boundp ref-dep)
3945 (setq ref-header (car (symbol-value ref-dep))))
3946 (if (string= id ref)
3947 ;; Yuk! This is a reference loop. Make the article be a
3948 ;; root article.
3949 (progn
3950 (mail-header-set-references (car (symbol-value id-dep)) "none")
23f87bed
MB
3951 (setq ref nil)
3952 (setq parent-id nil))
6748645f 3953 (setq ref (gnus-parent-id (mail-header-references ref-header)))))
23f87bed 3954 (setq ref-dep (intern (or parent-id "none") dependencies))
6748645f
LMI
3955 (if (boundp ref-dep)
3956 (setcdr (symbol-value ref-dep)
3957 (nconc (cdr (symbol-value ref-dep))
3958 (list (symbol-value id-dep))))
3959 (set ref-dep (list nil (symbol-value id-dep)))))
3960 header))
3961
23f87bed
MB
3962(defun gnus-extract-message-id-from-in-reply-to (string)
3963 (if (string-match "<[^>]+>" string)
3964 (substring string (match-beginning 0) (match-end 0))
3965 nil))
3966
eec82323
LMI
3967(defun gnus-build-sparse-threads ()
3968 (let ((headers gnus-newsgroup-headers)
16409b0b 3969 (mail-parse-charset gnus-newsgroup-charset)
6748645f 3970 (gnus-summary-ignore-duplicates t)
eec82323 3971 header references generation relations
6748645f 3972 subject child end new-child date)
eec82323
LMI
3973 ;; First we create an alist of generations/relations, where
3974 ;; generations is how much we trust the relation, and the relation
3975 ;; is parent/child.
3976 (gnus-message 7 "Making sparse threads...")
3977 (save-excursion
3978 (nnheader-set-temp-buffer " *gnus sparse threads*")
3979 (while (setq header (pop headers))
3980 (when (and (setq references (mail-header-references header))
3981 (not (string= references "")))
3982 (insert references)
3983 (setq child (mail-header-id header)
6748645f
LMI
3984 subject (mail-header-subject header)
3985 date (mail-header-date header)
3986 generation 0)
eec82323
LMI
3987 (while (search-backward ">" nil t)
3988 (setq end (1+ (point)))
3989 (when (search-backward "<" nil t)
6748645f 3990 (setq new-child (buffer-substring (point) end))
eec82323 3991 (push (list (incf generation)
6748645f
LMI
3992 child (setq child new-child)
3993 subject date)
eec82323 3994 relations)))
6748645f
LMI
3995 (when child
3996 (push (list (1+ generation) child nil subject) relations))
eec82323
LMI
3997 (erase-buffer)))
3998 (kill-buffer (current-buffer)))
3999 ;; Sort over trustworthiness.
6748645f
LMI
4000 (mapcar
4001 (lambda (relation)
4002 (when (gnus-dependencies-add-header
4003 (make-full-mail-header
4004 gnus-reffed-article-number
4005 (nth 3 relation) "" (or (nth 4 relation) "")
4006 (nth 1 relation)
4007 (or (nth 2 relation) "") 0 0 "")
4008 gnus-newsgroup-dependencies nil)
4009 (push gnus-reffed-article-number gnus-newsgroup-limit)
4010 (push gnus-reffed-article-number gnus-newsgroup-sparse)
4011 (push (cons gnus-reffed-article-number gnus-sparse-mark)
4012 gnus-newsgroup-reads)
4013 (decf gnus-reffed-article-number)))
4014 (sort relations 'car-less-than-car))
eec82323
LMI
4015 (gnus-message 7 "Making sparse threads...done")))
4016
4017(defun gnus-build-old-threads ()
4018 ;; Look at all the articles that refer back to old articles, and
4019 ;; fetch the headers for the articles that aren't there. This will
4020 ;; build complete threads - if the roots haven't been expired by the
4021 ;; server, that is.
16409b0b
GM
4022 (let ((mail-parse-charset gnus-newsgroup-charset)
4023 id heads)
eec82323
LMI
4024 (mapatoms
4025 (lambda (refs)
4026 (when (not (car (symbol-value refs)))
4027 (setq heads (cdr (symbol-value refs)))
4028 (while heads
4029 (if (memq (mail-header-number (caar heads))
4030 gnus-newsgroup-dormant)
4031 (setq heads (cdr heads))
4032 (setq id (symbol-name refs))
4033 (while (and (setq id (gnus-build-get-header id))
6748645f 4034 (not (car (gnus-id-to-thread id)))))
eec82323
LMI
4035 (setq heads nil)))))
4036 gnus-newsgroup-dependencies)))
4037
23f87bed
MB
4038(defsubst gnus-remove-odd-characters (string)
4039 "Translate STRING into something that doesn't contain weird characters."
4040 (mm-subst-char-in-string
4041 ?\r ?\-
4042 (mm-subst-char-in-string
4043 ?\n ?\- string)))
4044
6748645f
LMI
4045;; This function has to be called with point after the article number
4046;; on the beginning of the line.
4047(defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4048 (let ((eol (gnus-point-at-eol))
4049 (buffer (current-buffer))
23f87bed 4050 header references in-reply-to)
6748645f
LMI
4051
4052 ;; overview: [num subject from date id refs chars lines misc]
4053 (unwind-protect
23f87bed 4054 (let (x)
6748645f
LMI
4055 (narrow-to-region (point) eol)
4056 (unless (eobp)
4057 (forward-char))
4058
4059 (setq header
4060 (make-full-mail-header
4061 number ; number
23f87bed
MB
4062 (condition-case () ; subject
4063 (gnus-remove-odd-characters
4064 (funcall gnus-decode-encoded-word-function
4065 (setq x (nnheader-nov-field))))
4066 (error x))
4067 (condition-case () ; from
4068 (gnus-remove-odd-characters
4069 (funcall gnus-decode-encoded-word-function
4070 (setq x (nnheader-nov-field))))
4071 (error x))
16409b0b
GM
4072 (nnheader-nov-field) ; date
4073 (nnheader-nov-read-message-id) ; id
23f87bed 4074 (setq references (nnheader-nov-field)) ; refs
16409b0b
GM
4075 (nnheader-nov-read-integer) ; chars
4076 (nnheader-nov-read-integer) ; lines
4077 (unless (eobp)
8b93df01
DL
4078 (if (looking-at "Xref: ")
4079 (goto-char (match-end 0)))
4080 (nnheader-nov-field)) ; Xref
16409b0b 4081 (nnheader-nov-parse-extra)))) ; extra
6748645f
LMI
4082
4083 (widen))
4084
23f87bed
MB
4085 (when (and (string= references "")
4086 (setq in-reply-to (mail-header-extra header))
4087 (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4088 (mail-header-set-references
4089 header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4090
6748645f
LMI
4091 (when gnus-alter-header-function
4092 (funcall gnus-alter-header-function header))
4093 (gnus-dependencies-add-header header dependencies force-new)))
4094
eec82323 4095(defun gnus-build-get-header (id)
16409b0b
GM
4096 "Look through the buffer of NOV lines and find the header to ID.
4097Enter this line into the dependencies hash table, and return
4098the id of the parent article (if any)."
eec82323
LMI
4099 (let ((deps gnus-newsgroup-dependencies)
4100 found header)
4101 (prog1
4102 (save-excursion
4103 (set-buffer nntp-server-buffer)
4104 (let ((case-fold-search nil))
4105 (goto-char (point-min))
4106 (while (and (not found)
4107 (search-forward id nil t))
4108 (beginning-of-line)
4109 (setq found (looking-at
4110 (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4111 (regexp-quote id))))
4112 (or found (beginning-of-line 2)))
4113 (when found
4114 (beginning-of-line)
4115 (and
4116 (setq header (gnus-nov-parse-line
4117 (read (current-buffer)) deps))
4118 (gnus-parent-id (mail-header-references header))))))
4119 (when header
4120 (let ((number (mail-header-number header)))
4121 (push number gnus-newsgroup-limit)
4122 (push header gnus-newsgroup-headers)
4123 (if (memq number gnus-newsgroup-unselected)
4124 (progn
23f87bed
MB
4125 (setq gnus-newsgroup-unreads
4126 (gnus-add-to-sorted-list gnus-newsgroup-unreads
4127 number))
eec82323
LMI
4128 (setq gnus-newsgroup-unselected
4129 (delq number gnus-newsgroup-unselected)))
4130 (push number gnus-newsgroup-ancient)))))))
4131
6748645f
LMI
4132(defun gnus-build-all-threads ()
4133 "Read all the headers."
4134 (let ((gnus-summary-ignore-duplicates t)
16409b0b 4135 (mail-parse-charset gnus-newsgroup-charset)
6748645f
LMI
4136 (dependencies gnus-newsgroup-dependencies)
4137 header article)
4138 (save-excursion
4139 (set-buffer nntp-server-buffer)
4140 (let ((case-fold-search nil))
4141 (goto-char (point-min))
4142 (while (not (eobp))
4143 (ignore-errors
4144 (setq article (read (current-buffer))
16409b0b 4145 header (gnus-nov-parse-line article dependencies)))
6748645f
LMI
4146 (when header
4147 (save-excursion
4148 (set-buffer gnus-summary-buffer)
4149 (push header gnus-newsgroup-headers)
4150 (if (memq (setq article (mail-header-number header))
4151 gnus-newsgroup-unselected)
4152 (progn
23f87bed
MB
4153 (setq gnus-newsgroup-unreads
4154 (gnus-add-to-sorted-list
4155 gnus-newsgroup-unreads article))
6748645f
LMI
4156 (setq gnus-newsgroup-unselected
4157 (delq article gnus-newsgroup-unselected)))
4158 (push article gnus-newsgroup-ancient)))
4159 (forward-line 1)))))))
4160
eec82323 4161(defun gnus-summary-update-article-line (article header)
23f87bed 4162 "Update the line for ARTICLE using HEADER."
eec82323
LMI
4163 (let* ((id (mail-header-id header))
4164 (thread (gnus-id-to-thread id)))
4165 (unless thread
4166 (error "Article in no thread"))
4167 ;; Update the thread.
4168 (setcar thread header)
4169 (gnus-summary-goto-subject article)
4170 (let* ((datal (gnus-data-find-list article))
4171 (data (car datal))
eec82323
LMI
4172 (buffer-read-only nil)
4173 (level (gnus-summary-thread-level)))
4174 (gnus-delete-line)
23f87bed
MB
4175 (let ((inserted (- (point)
4176 (progn
4177 (gnus-summary-insert-line
4178 header level nil
4179 (memq article gnus-newsgroup-undownloaded)
4180 (gnus-article-mark article)
4181 (memq article gnus-newsgroup-replied)
4182 (memq article gnus-newsgroup-expirable)
4183 ;; Only insert the Subject string when it's different
4184 ;; from the previous Subject string.
4185 (if (and
4186 gnus-show-threads
4187 (gnus-subject-equal
4188 (condition-case ()
4189 (mail-header-subject
4190 (gnus-data-header
4191 (cadr
4192 (gnus-data-find-list
4193 article
4194 (gnus-data-list t)))))
4195 ;; Error on the side of excessive subjects.
4196 (error ""))
4197 (mail-header-subject header)))
4198 ""
4199 (mail-header-subject header))
4200 nil (cdr (assq article gnus-newsgroup-scored))
4201 (memq article gnus-newsgroup-processable))
4202 (point)))))
4203 (when (cdr datal)
4204 (gnus-data-update-list
4205 (cdr datal)
4206 (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
eec82323
LMI
4207
4208(defun gnus-summary-update-article (article &optional iheader)
4209 "Update ARTICLE in the summary buffer."
4210 (set-buffer gnus-summary-buffer)
6748645f 4211 (let* ((header (gnus-summary-article-header article))
eec82323
LMI
4212 (id (mail-header-id header))
4213 (data (gnus-data-find article))
4214 (thread (gnus-id-to-thread id))
4215 (references (mail-header-references header))
4216 (parent
4217 (gnus-id-to-thread
4218 (or (gnus-parent-id
4219 (when (and references
4220 (not (equal "" references)))
4221 references))
4222 "none")))
4223 (buffer-read-only nil)
6748645f 4224 (old (car thread)))
eec82323 4225 (when thread
eec82323 4226 (unless iheader
6748645f
LMI
4227 (setcar thread nil)
4228 (when parent
4229 (delq thread parent)))
4230 (if (gnus-summary-insert-subject id header)
eec82323
LMI
4231 ;; Set the (possibly) new article number in the data structure.
4232 (gnus-data-set-number data (gnus-id-to-article id))
4233 (setcar thread old)
4234 nil))))
4235
6748645f
LMI
4236(defun gnus-rebuild-thread (id &optional line)
4237 "Rebuild the thread containing ID.
4238If LINE, insert the rebuilt thread starting on line LINE."
eec82323
LMI
4239 (let ((buffer-read-only nil)
4240 old-pos current thread data)
4241 (if (not gnus-show-threads)
4242 (setq thread (list (car (gnus-id-to-thread id))))
4243 ;; Get the thread this article is part of.
4244 (setq thread (gnus-remove-thread id)))
4245 (setq old-pos (gnus-point-at-bol))
4246 (setq current (save-excursion
94384150 4247 (and (re-search-backward "[\r\n]" nil t)
eec82323
LMI
4248 (gnus-summary-article-number))))
4249 ;; If this is a gathered thread, we have to go some re-gathering.
4250 (when (stringp (car thread))
4251 (let ((subject (car thread))
4252 roots thr)
4253 (setq thread (cdr thread))
4254 (while thread
4255 (unless (memq (setq thr (gnus-id-to-thread
4256 (gnus-root-id
4257 (mail-header-id (caar thread)))))
4258 roots)
4259 (push thr roots))
4260 (setq thread (cdr thread)))
4261 ;; We now have all (unique) roots.
4262 (if (= (length roots) 1)
4263 ;; All the loose roots are now one solid root.
4264 (setq thread (car roots))
4265 (setq thread (cons subject (gnus-sort-threads roots))))))
4266 (let (threads)
4267 ;; We then insert this thread into the summary buffer.
6748645f
LMI
4268 (when line
4269 (goto-char (point-min))
4270 (forward-line (1- line)))
eec82323
LMI
4271 (let (gnus-newsgroup-data gnus-newsgroup-threads)
4272 (if gnus-show-threads
4273 (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4274 (gnus-summary-prepare-unthreaded thread))
4275 (setq data (nreverse gnus-newsgroup-data))
4276 (setq threads gnus-newsgroup-threads))
4277 ;; We splice the new data into the data structure.
6748645f
LMI
4278 ;;!!! This is kinda bogus. We assume that in LINE is non-nil,
4279 ;;!!! then we want to insert at the beginning of the buffer.
4280 ;;!!! That happens to be true with Gnus now, but that may
4281 ;;!!! change in the future. Perhaps.
4282 (gnus-data-enter-list
4283 (if line nil current) data (- (point) old-pos))
4284 (setq gnus-newsgroup-threads
4285 (nconc threads gnus-newsgroup-threads))
4286 (gnus-data-compute-positions))))
eec82323
LMI
4287
4288(defun gnus-number-to-header (number)
4289 "Return the header for article NUMBER."
4290 (let ((headers gnus-newsgroup-headers))
4291 (while (and headers
4292 (not (= number (mail-header-number (car headers)))))
4293 (pop headers))
4294 (when headers
4295 (car headers))))
4296
6748645f 4297(defun gnus-parent-headers (in-headers &optional generation)
eec82323
LMI
4298 "Return the headers of the GENERATIONeth parent of HEADERS."
4299 (unless generation
4300 (setq generation 1))
a8151ef7 4301 (let ((parent t)
6748645f 4302 (headers in-headers)
a8151ef7 4303 references)
6748645f
LMI
4304 (while (and parent
4305 (not (zerop generation))
4306 (setq references (mail-header-references headers)))
4307 (setq headers (if (and references
4308 (setq parent (gnus-parent-id references)))
4309 (car (gnus-id-to-thread parent))
4310 nil))
4311 (decf generation))
4312 (and (not (eq headers in-headers))
4313 headers)))
eec82323
LMI
4314
4315(defun gnus-id-to-thread (id)
4316 "Return the (sub-)thread where ID appears."
4317 (gnus-gethash id gnus-newsgroup-dependencies))
4318
4319(defun gnus-id-to-article (id)
4320 "Return the article number of ID."
4321 (let ((thread (gnus-id-to-thread id)))
4322 (when (and thread
4323 (car thread))
4324 (mail-header-number (car thread)))))
4325
4326(defun gnus-id-to-header (id)
4327 "Return the article headers of ID."
4328 (car (gnus-id-to-thread id)))
4329
4330(defun gnus-article-displayed-root-p (article)
4331 "Say whether ARTICLE is a root(ish) article."
4332 (let ((level (gnus-summary-thread-level article))
4333 (refs (mail-header-references (gnus-summary-article-header article)))
4334 particle)
4335 (cond
4336 ((null level) nil)
4337 ((zerop level) t)
4338 ((null refs) t)
4339 ((null (gnus-parent-id refs)) t)
4340 ((and (= 1 level)
4341 (null (setq particle (gnus-id-to-article
4342 (gnus-parent-id refs))))
4343 (null (gnus-summary-thread-level particle)))))))
4344
4345(defun gnus-root-id (id)
4346 "Return the id of the root of the thread where ID appears."
4347 (let (last-id prev)
6748645f 4348 (while (and id (setq prev (car (gnus-id-to-thread id))))
eec82323
LMI
4349 (setq last-id id
4350 id (gnus-parent-id (mail-header-references prev))))
4351 last-id))
4352
6748645f
LMI
4353(defun gnus-articles-in-thread (thread)
4354 "Return the list of articles in THREAD."
4355 (cons (mail-header-number (car thread))
4356 (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4357
eec82323
LMI
4358(defun gnus-remove-thread (id &optional dont-remove)
4359 "Remove the thread that has ID in it."
6748645f 4360 (let (headers thread last-id)
eec82323 4361 ;; First go up in this thread until we find the root.
6748645f
LMI
4362 (setq last-id (gnus-root-id id)
4363 headers (message-flatten-list (gnus-id-to-thread last-id)))
eec82323
LMI
4364 ;; We have now found the real root of this thread. It might have
4365 ;; been gathered into some loose thread, so we have to search
4366 ;; through the threads to find the thread we wanted.
4367 (let ((threads gnus-newsgroup-threads)
4368 sub)
4369 (while threads
4370 (setq sub (car threads))
4371 (if (stringp (car sub))
4372 ;; This is a gathered thread, so we look at the roots
4373 ;; below it to find whether this article is in this
4374 ;; gathered root.
4375 (progn
4376 (setq sub (cdr sub))
4377 (while sub
4378 (when (member (caar sub) headers)
4379 (setq thread (car threads)
4380 threads nil
4381 sub nil))
4382 (setq sub (cdr sub))))
4383 ;; It's an ordinary thread, so we check it.
4384 (when (eq (car sub) (car headers))
4385 (setq thread sub
4386 threads nil)))
4387 (setq threads (cdr threads)))
4388 ;; If this article is in no thread, then it's a root.
4389 (if thread
4390 (unless dont-remove
4391 (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
6748645f 4392 (setq thread (gnus-id-to-thread last-id)))
eec82323
LMI
4393 (when thread
4394 (prog1
4395 thread ; We return this thread.
4396 (unless dont-remove
4397 (if (stringp (car thread))
4398 (progn
4399 ;; If we use dummy roots, then we have to remove the
4400 ;; dummy root as well.
4401 (when (eq gnus-summary-make-false-root 'dummy)
6748645f
LMI
4402 ;; We go to the dummy root by going to
4403 ;; the first sub-"thread", and then one line up.
4404 (gnus-summary-goto-article
4405 (mail-header-number (caadr thread)))
4406 (forward-line -1)
eec82323
LMI
4407 (gnus-delete-line)
4408 (gnus-data-compute-positions))
4409 (setq thread (cdr thread))
4410 (while thread
4411 (gnus-remove-thread-1 (car thread))
4412 (setq thread (cdr thread))))
4413 (gnus-remove-thread-1 thread))))))))
4414
4415(defun gnus-remove-thread-1 (thread)
4416 "Remove the thread THREAD recursively."
4417 (let ((number (mail-header-number (pop thread)))
4418 d)
4419 (setq thread (reverse thread))
4420 (while thread
4421 (gnus-remove-thread-1 (pop thread)))
4422 (when (setq d (gnus-data-find number))
4423 (goto-char (gnus-data-pos d))
16409b0b 4424 (gnus-summary-show-thread)
eec82323
LMI
4425 (gnus-data-remove
4426 number
4427 (- (gnus-point-at-bol)
4428 (prog1
4429 (1+ (gnus-point-at-eol))
4430 (gnus-delete-line)))))))
4431
16409b0b
GM
4432(defun gnus-sort-threads-1 (threads func)
4433 (sort (mapcar (lambda (thread)
4434 (cons (car thread)
4435 (and (cdr thread)
4436 (gnus-sort-threads-1 (cdr thread) func))))
4437 threads) func))
4438
eec82323
LMI
4439(defun gnus-sort-threads (threads)
4440 "Sort THREADS."
4441 (if (not gnus-thread-sort-functions)
4442 threads
6748645f 4443 (gnus-message 8 "Sorting threads...")
23f87bed
MB
4444 (let ((max-lisp-eval-depth 5000))
4445 (prog1 (gnus-sort-threads-1
a1506d29 4446 threads
16409b0b 4447 (gnus-make-sort-function gnus-thread-sort-functions))
23f87bed 4448 (gnus-message 8 "Sorting threads...done")))))
eec82323
LMI
4449
4450(defun gnus-sort-articles (articles)
4451 "Sort ARTICLES."
4452 (when gnus-article-sort-functions
4453 (gnus-message 7 "Sorting articles...")
4454 (prog1
4455 (setq gnus-newsgroup-headers
4456 (sort articles (gnus-make-sort-function
4457 gnus-article-sort-functions)))
4458 (gnus-message 7 "Sorting articles...done"))))
4459
4460;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4461(defmacro gnus-thread-header (thread)
16409b0b
GM
4462 "Return header of first article in THREAD.
4463Note that THREAD must never, ever be anything else than a variable -
4464using some other form will lead to serious barfage."
eec82323
LMI
4465 (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4466 ;; (8% speedup to gnus-summary-prepare, just for fun :-)
16409b0b 4467 (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
eec82323
LMI
4468 (vector thread) 2))
4469
4470(defsubst gnus-article-sort-by-number (h1 h2)
4471 "Sort articles by article number."
4472 (< (mail-header-number h1)
4473 (mail-header-number h2)))
4474
4475(defun gnus-thread-sort-by-number (h1 h2)
4476 "Sort threads by root article number."
4477 (gnus-article-sort-by-number
4478 (gnus-thread-header h1) (gnus-thread-header h2)))
4479
23f87bed
MB
4480(defsubst gnus-article-sort-by-random (h1 h2)
4481 "Sort articles by article number."
4482 (zerop (random 2)))
4483
4484(defun gnus-thread-sort-by-random (h1 h2)
4485 "Sort threads by root article number."
4486 (gnus-article-sort-by-random
4487 (gnus-thread-header h1) (gnus-thread-header h2)))
4488
eec82323
LMI
4489(defsubst gnus-article-sort-by-lines (h1 h2)
4490 "Sort articles by article Lines header."
4491 (< (mail-header-lines h1)
4492 (mail-header-lines h2)))
4493
4494(defun gnus-thread-sort-by-lines (h1 h2)
4495 "Sort threads by root article Lines header."
4496 (gnus-article-sort-by-lines
4497 (gnus-thread-header h1) (gnus-thread-header h2)))
4498
16409b0b
GM
4499(defsubst gnus-article-sort-by-chars (h1 h2)
4500 "Sort articles by octet length."
4501 (< (mail-header-chars h1)
4502 (mail-header-chars h2)))
4503
4504(defun gnus-thread-sort-by-chars (h1 h2)
4505 "Sort threads by root article octet length."
4506 (gnus-article-sort-by-chars
4507 (gnus-thread-header h1) (gnus-thread-header h2)))
4508
eec82323
LMI
4509(defsubst gnus-article-sort-by-author (h1 h2)
4510 "Sort articles by root author."
4511 (string-lessp
4512 (let ((extract (funcall
4513 gnus-extract-address-components
4514 (mail-header-from h1))))
4515 (or (car extract) (cadr extract) ""))
4516 (let ((extract (funcall
4517 gnus-extract-address-components
4518 (mail-header-from h2))))
4519 (or (car extract) (cadr extract) ""))))
4520
4521(defun gnus-thread-sort-by-author (h1 h2)
4522 "Sort threads by root author."
4523 (gnus-article-sort-by-author
4524 (gnus-thread-header h1) (gnus-thread-header h2)))
4525
4526(defsubst gnus-article-sort-by-subject (h1 h2)
4527 "Sort articles by root subject."
4528 (string-lessp
4529 (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4530 (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4531
4532(defun gnus-thread-sort-by-subject (h1 h2)
4533 "Sort threads by root subject."
4534 (gnus-article-sort-by-subject
4535 (gnus-thread-header h1) (gnus-thread-header h2)))
4536
4537(defsubst gnus-article-sort-by-date (h1 h2)
4538 "Sort articles by root article date."
16409b0b 4539 (time-less-p
eec82323
LMI
4540 (gnus-date-get-time (mail-header-date h1))
4541 (gnus-date-get-time (mail-header-date h2))))
4542
4543(defun gnus-thread-sort-by-date (h1 h2)
4544 "Sort threads by root article date."
4545 (gnus-article-sort-by-date
4546 (gnus-thread-header h1) (gnus-thread-header h2)))
4547
4548(defsubst gnus-article-sort-by-score (h1 h2)
4549 "Sort articles by root article score.
4550Unscored articles will be counted as having a score of zero."
4551 (> (or (cdr (assq (mail-header-number h1)
4552 gnus-newsgroup-scored))
4553 gnus-summary-default-score 0)
4554 (or (cdr (assq (mail-header-number h2)
4555 gnus-newsgroup-scored))
4556 gnus-summary-default-score 0)))
4557
4558(defun gnus-thread-sort-by-score (h1 h2)
4559 "Sort threads by root article score."
4560 (gnus-article-sort-by-score
4561 (gnus-thread-header h1) (gnus-thread-header h2)))
4562
4563(defun gnus-thread-sort-by-total-score (h1 h2)
4564 "Sort threads by the sum of all scores in the thread.
4565Unscored articles will be counted as having a score of zero."
4566 (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4567
4568(defun gnus-thread-total-score (thread)
16409b0b 4569 ;; This function find the total score of THREAD.
23f87bed
MB
4570 (cond
4571 ((null thread)
4572 0)
4573 ((consp thread)
4574 (if (stringp (car thread))
4575 (apply gnus-thread-score-function 0
4576 (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4577 (gnus-thread-total-score-1 thread)))
4578 (t
4579 (gnus-thread-total-score-1 (list thread)))))
4580
4581(defun gnus-thread-sort-by-most-recent-number (h1 h2)
4582 "Sort threads such that the thread with the most recently arrived article comes first."
4583 (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4584
4585(defun gnus-thread-highest-number (thread)
4586 "Return the highest article number in THREAD."
4587 (apply 'max (mapcar (lambda (header)
4588 (mail-header-number header))
4589 (message-flatten-list thread))))
4590
4591(defun gnus-thread-sort-by-most-recent-date (h1 h2)
4592 "Sort threads such that the thread with the most recently dated article comes first."
4593 (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4594
4595(defun gnus-thread-latest-date (thread)
4596 "Return the highest article date in THREAD."
4597 (let ((previous-time 0))
4598 (apply 'max
4599 (mapcar
4600 (lambda (header)
4601 (setq previous-time
4602 (condition-case ()
4603 (time-to-seconds (mail-header-parse-date
4604 (mail-header-date header)))
4605 (error previous-time))))
4606 (sort
4607 (message-flatten-list thread)
4608 (lambda (h1 h2)
4609 (< (mail-header-number h1)
4610 (mail-header-number h2))))))))
eec82323
LMI
4611
4612(defun gnus-thread-total-score-1 (root)
4613 ;; This function find the total score of the thread below ROOT.
4614 (setq root (car root))
4615 (apply gnus-thread-score-function
4616 (or (append
4617 (mapcar 'gnus-thread-total-score
6748645f 4618 (cdr (gnus-id-to-thread (mail-header-id root))))
eec82323
LMI
4619 (when (> (mail-header-number root) 0)
4620 (list (or (cdr (assq (mail-header-number root)
4621 gnus-newsgroup-scored))
4622 gnus-summary-default-score 0))))
4623 (list gnus-summary-default-score)
4624 '(0))))
4625
4626;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4627(defvar gnus-tmp-prev-subject nil)
4628(defvar gnus-tmp-false-parent nil)
4629(defvar gnus-tmp-root-expunged nil)
4630(defvar gnus-tmp-dummy-line nil)
4631
60bd5589 4632(eval-when-compile (defvar gnus-tmp-header))
16409b0b
GM
4633(defun gnus-extra-header (type &optional header)
4634 "Return the extra header of TYPE."
4635 (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4636 ""))
4637
23f87bed
MB
4638(defvar gnus-tmp-thread-tree-header-string "")
4639
4640(defcustom gnus-sum-thread-tree-root "> "
4641 "With %B spec, used for the root of a thread.
4642If nil, use subject instead."
bf247b6e 4643 :version "22.1"
ad136a7c 4644 :type '(radio (const :format "%v " nil) string)
23f87bed
MB
4645 :group 'gnus-thread)
4646(defcustom gnus-sum-thread-tree-false-root "> "
4647 "With %B spec, used for a false root of a thread.
4648If nil, use subject instead."
bf247b6e 4649 :version "22.1"
ad136a7c 4650 :type '(radio (const :format "%v " nil) string)
23f87bed
MB
4651 :group 'gnus-thread)
4652(defcustom gnus-sum-thread-tree-single-indent ""
4653 "With %B spec, used for a thread with just one message.
4654If nil, use subject instead."
bf247b6e 4655 :version "22.1"
ad136a7c 4656 :type '(radio (const :format "%v " nil) string)
23f87bed
MB
4657 :group 'gnus-thread)
4658(defcustom gnus-sum-thread-tree-vertical "| "
4659 "With %B spec, used for drawing a vertical line."
bf247b6e 4660 :version "22.1"
23f87bed
MB
4661 :type 'string
4662 :group 'gnus-thread)
4663(defcustom gnus-sum-thread-tree-indent " "
4664 "With %B spec, used for indenting."
bf247b6e 4665 :version "22.1"
23f87bed
MB
4666 :type 'string
4667 :group 'gnus-thread)
4668(defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4669 "With %B spec, used for a leaf with brothers."
bf247b6e 4670 :version "22.1"
23f87bed
MB
4671 :type 'string
4672 :group 'gnus-thread)
4673(defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4674 "With %B spec, used for a leaf without brothers."
bf247b6e 4675 :version "22.1"
23f87bed
MB
4676 :type 'string
4677 :group 'gnus-thread)
4678
eec82323
LMI
4679(defun gnus-summary-prepare-threads (threads)
4680 "Prepare summary buffer from THREADS and indentation LEVEL.
4681THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4682or a straight list of headers."
4683 (gnus-message 7 "Generating summary...")
4684
4685 (setq gnus-newsgroup-threads threads)
4686 (beginning-of-line)
4687
4688 (let ((gnus-tmp-level 0)
4689 (default-score (or gnus-summary-default-score 0))
4690 (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
23f87bed
MB
4691 (building-line-count gnus-summary-display-while-building)
4692 (building-count (integerp gnus-summary-display-while-building))
eec82323 4693 thread number subject stack state gnus-tmp-gathered beg-match
23f87bed
MB
4694 new-roots gnus-tmp-new-adopts thread-end simp-subject
4695 gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
eec82323
LMI
4696 gnus-tmp-replied gnus-tmp-subject-or-nil
4697 gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4698 gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
23f87bed
MB
4699 gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4700 tree-stack)
eec82323 4701
23f87bed
MB
4702 (setq gnus-tmp-prev-subject nil
4703 gnus-tmp-thread-tree-header-string "")
eec82323
LMI
4704
4705 (if (vectorp (car threads))
4706 ;; If this is a straight (sic) list of headers, then a
4707 ;; threaded summary display isn't required, so we just create
4708 ;; an unthreaded one.
4709 (gnus-summary-prepare-unthreaded threads)
4710
4711 ;; Do the threaded display.
4712
23f87bed
MB
4713 (if gnus-summary-display-while-building
4714 (switch-to-buffer (buffer-name)))
eec82323
LMI
4715 (while (or threads stack gnus-tmp-new-adopts new-roots)
4716
4717 (if (and (= gnus-tmp-level 0)
eec82323
LMI
4718 (or (not stack)
4719 (= (caar stack) 0))
4720 (not gnus-tmp-false-parent)
4721 (or gnus-tmp-new-adopts new-roots))
4722 (if gnus-tmp-new-adopts
4723 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4724 thread (list (car gnus-tmp-new-adopts))
4725 gnus-tmp-header (caar thread)
4726 gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4727 (when new-roots
4728 (setq thread (list (car new-roots))
4729 gnus-tmp-header (caar thread)
4730 new-roots (cdr new-roots))))
4731
4732 (if threads
4733 ;; If there are some threads, we do them before the
4734 ;; threads on the stack.
4735 (setq thread threads
4736 gnus-tmp-header (caar thread))
4737 ;; There were no current threads, so we pop something off
4738 ;; the stack.
4739 (setq state (car stack)
4740 gnus-tmp-level (car state)
23f87bed
MB
4741 tree-stack (cadr state)
4742 thread (caddr state)
eec82323
LMI
4743 stack (cdr stack)
4744 gnus-tmp-header (caar thread))))
4745
4746 (setq gnus-tmp-false-parent nil)
4747 (setq gnus-tmp-root-expunged nil)
4748 (setq thread-end nil)
4749
4750 (if (stringp gnus-tmp-header)
4751 ;; The header is a dummy root.
4752 (cond
4753 ((eq gnus-summary-make-false-root 'adopt)
4754 ;; We let the first article adopt the rest.
4755 (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4756 (cddar thread)))
4757 (setq gnus-tmp-gathered
4758 (nconc (mapcar
4759 (lambda (h) (mail-header-number (car h)))
4760 (cddar thread))
4761 gnus-tmp-gathered))
4762 (setq thread (cons (list (caar thread)
4763 (cadar thread))
4764 (cdr thread)))
4765 (setq gnus-tmp-level -1
4766 gnus-tmp-false-parent t))
4767 ((eq gnus-summary-make-false-root 'empty)
4768 ;; We print adopted articles with empty subject fields.
4769 (setq gnus-tmp-gathered
4770 (nconc (mapcar
4771 (lambda (h) (mail-header-number (car h)))
4772 (cddar thread))
4773 gnus-tmp-gathered))
4774 (setq gnus-tmp-level -1))
4775 ((eq gnus-summary-make-false-root 'dummy)
4776 ;; We remember that we probably want to output a dummy
4777 ;; root.
4778 (setq gnus-tmp-dummy-line gnus-tmp-header)
4779 (setq gnus-tmp-prev-subject gnus-tmp-header))
4780 (t
4781 ;; We do not make a root for the gathered
4782 ;; sub-threads at all.
4783 (setq gnus-tmp-level -1)))
4784
4785 (setq number (mail-header-number gnus-tmp-header)
23f87bed
MB
4786 subject (mail-header-subject gnus-tmp-header)
4787 simp-subject (gnus-simplify-subject-fully subject))
eec82323
LMI
4788
4789 (cond
4790 ;; If the thread has changed subject, we might want to make
4791 ;; this subthread into a root.
4792 ((and (null gnus-thread-ignore-subject)
4793 (not (zerop gnus-tmp-level))
4794 gnus-tmp-prev-subject
23f87bed 4795 (not (string= gnus-tmp-prev-subject simp-subject)))
eec82323
LMI
4796 (setq new-roots (nconc new-roots (list (car thread)))
4797 thread-end t
4798 gnus-tmp-header nil))
4799 ;; If the article lies outside the current limit,
4800 ;; then we do not display it.
4801 ((not (memq number gnus-newsgroup-limit))
4802 (setq gnus-tmp-gathered
4803 (nconc (mapcar
4804 (lambda (h) (mail-header-number (car h)))
4805 (cdar thread))
4806 gnus-tmp-gathered))
4807 (setq gnus-tmp-new-adopts (if (cdar thread)
4808 (append gnus-tmp-new-adopts
4809 (cdar thread))
4810 gnus-tmp-new-adopts)
4811 thread-end t
4812 gnus-tmp-header nil)
4813 (when (zerop gnus-tmp-level)
4814 (setq gnus-tmp-root-expunged t)))
4815 ;; Perhaps this article is to be marked as read?
4816 ((and gnus-summary-mark-below
4817 (< (or (cdr (assq number gnus-newsgroup-scored))
4818 default-score)
4819 gnus-summary-mark-below)
4820 ;; Don't touch sparse articles.
4821 (not (gnus-summary-article-sparse-p number))
4822 (not (gnus-summary-article-ancient-p number)))
4823 (setq gnus-newsgroup-unreads
4824 (delq number gnus-newsgroup-unreads))
4825 (if gnus-newsgroup-auto-expire
23f87bed
MB
4826 (setq gnus-newsgroup-expirable
4827 (gnus-add-to-sorted-list
4828 gnus-newsgroup-expirable number))
eec82323
LMI
4829 (push (cons number gnus-low-score-mark)
4830 gnus-newsgroup-reads))))
4831
4832 (when gnus-tmp-header
4833 ;; We may have an old dummy line to output before this
4834 ;; article.
6748645f
LMI
4835 (when (and gnus-tmp-dummy-line
4836 (gnus-subject-equal
4837 gnus-tmp-dummy-line
4838 (mail-header-subject gnus-tmp-header)))
eec82323
LMI
4839 (gnus-summary-insert-dummy-line
4840 gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4841 (setq gnus-tmp-dummy-line nil))
4842
4843 ;; Compute the mark.
4844 (setq gnus-tmp-unread (gnus-article-mark number))
4845
4846 (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4847 gnus-tmp-header gnus-tmp-level)
4848 gnus-newsgroup-data)
4849
4850 ;; Actually insert the line.
4851 (setq
4852 gnus-tmp-subject-or-nil
4853 (cond
4854 ((and gnus-thread-ignore-subject
4855 gnus-tmp-prev-subject
23f87bed 4856 (not (string= gnus-tmp-prev-subject simp-subject)))
eec82323
LMI
4857 subject)
4858 ((zerop gnus-tmp-level)
4859 (if (and (eq gnus-summary-make-false-root 'empty)
4860 (memq number gnus-tmp-gathered)
4861 gnus-tmp-prev-subject
23f87bed 4862 (string= gnus-tmp-prev-subject simp-subject))
eec82323
LMI
4863 gnus-summary-same-subject
4864 subject))
4865 (t gnus-summary-same-subject)))
4866 (if (and (eq gnus-summary-make-false-root 'adopt)
4867 (= gnus-tmp-level 1)
4868 (memq number gnus-tmp-gathered))
4869 (setq gnus-tmp-opening-bracket ?\<
4870 gnus-tmp-closing-bracket ?\>)
4871 (setq gnus-tmp-opening-bracket ?\[
4872 gnus-tmp-closing-bracket ?\]))
4873 (setq
4874 gnus-tmp-indentation
4875 (aref gnus-thread-indent-array gnus-tmp-level)
4876 gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4877 gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4878 gnus-summary-default-score 0)
4879 gnus-tmp-score-char
4880 (if (or (null gnus-summary-default-score)
4881 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4882 gnus-summary-zcore-fuzz))
23f87bed 4883 ? ;Whitespace
eec82323
LMI
4884 (if (< gnus-tmp-score gnus-summary-default-score)
4885 gnus-score-below-mark gnus-score-over-mark))
4886 gnus-tmp-replied
4887 (cond ((memq number gnus-newsgroup-processable)
4888 gnus-process-mark)
4889 ((memq number gnus-newsgroup-cached)
4890 gnus-cached-mark)
4891 ((memq number gnus-newsgroup-replied)
4892 gnus-replied-mark)
23f87bed
MB
4893 ((memq number gnus-newsgroup-forwarded)
4894 gnus-forwarded-mark)
eec82323
LMI
4895 ((memq number gnus-newsgroup-saved)
4896 gnus-saved-mark)
23f87bed
MB
4897 ((memq number gnus-newsgroup-recent)
4898 gnus-recent-mark)
4899 ((memq number gnus-newsgroup-unseen)
4900 gnus-unseen-mark)
4901 (t gnus-no-mark))
4902 gnus-tmp-downloaded
4903 (cond ((memq number gnus-newsgroup-undownloaded)
4904 gnus-undownloaded-mark)
4905 (gnus-newsgroup-agentized
4906 gnus-downloaded-mark)
4907 (t
4908 gnus-no-mark))
eec82323
LMI
4909 gnus-tmp-from (mail-header-from gnus-tmp-header)
4910 gnus-tmp-name
4911 (cond
4912 ((string-match "<[^>]+> *$" gnus-tmp-from)
4913 (setq beg-match (match-beginning 0))
23f87bed
MB
4914 (or (and (string-match "^\".+\"" gnus-tmp-from)
4915 (substring gnus-tmp-from 1 (1- (match-end 0))))
eec82323
LMI
4916 (substring gnus-tmp-from 0 beg-match)))
4917 ((string-match "(.+)" gnus-tmp-from)
4918 (substring gnus-tmp-from
4919 (1+ (match-beginning 0)) (1- (match-end 0))))
23f87bed
MB
4920 (t gnus-tmp-from))
4921
4922 ;; Do the %B string
4923 gnus-tmp-thread-tree-header-string
4924 (cond
4925 ((not gnus-show-threads) "")
4926 ((zerop gnus-tmp-level)
4927 (cond ((cdar thread)
4928 (or gnus-sum-thread-tree-root subject))
4929 (gnus-tmp-new-adopts
4930 (or gnus-sum-thread-tree-false-root subject))
4931 (t
4932 (or gnus-sum-thread-tree-single-indent subject))))
4933 (t
4934 (concat (apply 'concat
4935 (mapcar (lambda (item)
4936 (if (= item 1)
4937 gnus-sum-thread-tree-vertical
4938 gnus-sum-thread-tree-indent))
4939 (cdr (reverse tree-stack))))
4940 (if (nth 1 thread)
4941 gnus-sum-thread-tree-leaf-with-other
4942 gnus-sum-thread-tree-single-leaf)))))
eec82323
LMI
4943 (when (string= gnus-tmp-name "")
4944 (setq gnus-tmp-name gnus-tmp-from))
4945 (unless (numberp gnus-tmp-lines)
23f87bed
MB
4946 (setq gnus-tmp-lines -1))
4947 (if (= gnus-tmp-lines -1)
4948 (setq gnus-tmp-lines "?")
4949 (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4950 (gnus-put-text-property
eec82323
LMI
4951 (point)
4952 (progn (eval gnus-summary-line-format-spec) (point))
23f87bed 4953 'gnus-number number)
eec82323
LMI
4954 (when gnus-visual-p
4955 (forward-line -1)
6748645f 4956 (gnus-run-hooks 'gnus-summary-update-hook)
eec82323
LMI
4957 (forward-line 1))
4958
23f87bed 4959 (setq gnus-tmp-prev-subject simp-subject)))
eec82323
LMI
4960
4961 (when (nth 1 thread)
23f87bed
MB
4962 (push (list (max 0 gnus-tmp-level)
4963 (copy-sequence tree-stack)
4964 (nthcdr 1 thread))
4965 stack))
4966 (push (if (nth 1 thread) 1 0) tree-stack)
eec82323
LMI
4967 (incf gnus-tmp-level)
4968 (setq threads (if thread-end nil (cdar thread)))
23f87bed
MB
4969 (if gnus-summary-display-while-building
4970 (if building-count
4971 (progn
4972 ;; use a set frequency
4973 (setq building-line-count (1- building-line-count))
4974 (when (= building-line-count 0)
4975 (sit-for 0)
4976 (setq building-line-count
4977 gnus-summary-display-while-building)))
4978 ;; always
4979 (sit-for 0)))
eec82323
LMI
4980 (unless threads
4981 (setq gnus-tmp-level 0)))))
4982 (gnus-message 7 "Generating summary...done"))
4983
4984(defun gnus-summary-prepare-unthreaded (headers)
4985 "Generate an unthreaded summary buffer based on HEADERS."
4986 (let (header number mark)
4987
4988 (beginning-of-line)
4989
4990 (while headers
4991 ;; We may have to root out some bad articles...
4992 (when (memq (setq number (mail-header-number
4993 (setq header (pop headers))))
4994 gnus-newsgroup-limit)
4995 ;; Mark article as read when it has a low score.
4996 (when (and gnus-summary-mark-below
4997 (< (or (cdr (assq number gnus-newsgroup-scored))
4998 gnus-summary-default-score 0)
4999 gnus-summary-mark-below)
5000 (not (gnus-summary-article-ancient-p number)))
5001 (setq gnus-newsgroup-unreads
5002 (delq number gnus-newsgroup-unreads))
5003 (if gnus-newsgroup-auto-expire
5004 (push number gnus-newsgroup-expirable)
5005 (push (cons number gnus-low-score-mark)
5006 gnus-newsgroup-reads)))
5007
5008 (setq mark (gnus-article-mark number))
5009 (push (gnus-data-make number mark (1+ (point)) header 0)
5010 gnus-newsgroup-data)
5011 (gnus-summary-insert-line
5012 header 0 number
23f87bed 5013 (memq number gnus-newsgroup-undownloaded)
eec82323
LMI
5014 mark (memq number gnus-newsgroup-replied)
5015 (memq number gnus-newsgroup-expirable)
5016 (mail-header-subject header) nil
5017 (cdr (assq number gnus-newsgroup-scored))
5018 (memq number gnus-newsgroup-processable))))))
5019
16409b0b
GM
5020(defun gnus-summary-remove-list-identifiers ()
5021 "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
23f87bed
MB
5022 (let ((regexp (if (consp gnus-list-identifiers)
5023 (mapconcat 'identity gnus-list-identifiers " *\\|")
5024 gnus-list-identifiers))
5025 changed subject)
5026 (when regexp
5027 (dolist (header gnus-newsgroup-headers)
5028 (setq subject (mail-header-subject header)
5029 changed nil)
5030 (while (string-match
5031 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
5032 subject)
5033 (setq subject
5034 (concat (substring subject 0 (match-beginning 2))
5035 (substring subject (match-end 0)))
5036 changed t))
5037 (when (and changed
5038 (string-match
5039 "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
5040 (setq subject
5041 (concat (substring subject 0 (match-beginning 1))
5042 (substring subject (match-end 1)))))
5043 (when changed
5044 (mail-header-set-subject header subject))))))
5045
5046(defun gnus-fetch-headers (articles)
5047 "Fetch headers of ARTICLES."
5048 (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5049 (gnus-message 5 "Fetching headers for %s..." name)
5050 (prog1
5051 (if (eq 'nov
5052 (setq gnus-headers-retrieved-by
5053 (gnus-retrieve-headers
5054 articles gnus-newsgroup-name
5055 ;; We might want to fetch old headers, but
5056 ;; not if there is only 1 article.
5057 (and (or (and
5058 (not (eq gnus-fetch-old-headers 'some))
5059 (not (numberp gnus-fetch-old-headers)))
5060 (> (length articles) 1))
5061 gnus-fetch-old-headers))))
5062 (gnus-get-newsgroup-headers-xover
5063 articles nil nil gnus-newsgroup-name t)
5064 (gnus-get-newsgroup-headers))
5065 (gnus-message 5 "Fetching headers for %s...done" name))))
16409b0b 5066
6748645f 5067(defun gnus-select-newsgroup (group &optional read-all select-articles)
eec82323 5068 "Select newsgroup GROUP.
6748645f
LMI
5069If READ-ALL is non-nil, all articles in the group are selected.
5070If SELECT-ARTICLES, only select those articles from GROUP."
eec82323
LMI
5071 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5072 ;;!!! Dirty hack; should be removed.
5073 (gnus-summary-ignore-duplicates
23f87bed 5074 (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
eec82323
LMI
5075 t
5076 gnus-summary-ignore-duplicates))
5077 (info (nth 2 entry))
5078 articles fetched-articles cached)
5079
5080 (unless (gnus-check-server
475e0e0c
GM
5081 (set (make-local-variable 'gnus-current-select-method)
5082 (gnus-find-method-for-group group)))
eec82323
LMI
5083 (error "Couldn't open server"))
5084
5085 (or (and entry (not (eq (car entry) t))) ; Either it's active...
5086 (gnus-activate-group group) ; Or we can activate it...
5087 (progn ; Or we bug out.
5088 (when (equal major-mode 'gnus-summary-mode)
23f87bed
MB
5089 (gnus-kill-buffer (current-buffer)))
5090 (error "Couldn't activate group %s: %s"
eec82323
LMI
5091 group (gnus-status-message group))))
5092
5093 (unless (gnus-request-group group t)
5094 (when (equal major-mode 'gnus-summary-mode)
23f87bed 5095 (gnus-kill-buffer (current-buffer)))
eec82323
LMI
5096 (error "Couldn't request group %s: %s"
5097 group (gnus-status-message group)))
5098
23f87bed 5099 (when gnus-agent
54506618 5100 (gnus-agent-possibly-alter-active group (gnus-active group) info)
132cf96d 5101
23f87bed
MB
5102 (setq gnus-summary-use-undownloaded-faces
5103 (gnus-agent-find-parameter
5104 group
5105 'agent-enable-undownloaded-faces)))
5106
5107 (setq gnus-newsgroup-name group
5108 gnus-newsgroup-unselected nil
5109 gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5110
5111 (let ((display (gnus-group-find-parameter group 'display)))
5112 (setq gnus-newsgroup-display
5113 (cond
5114 ((not (zerop (or (car-safe read-all) 0)))
5115 ;; The user entered the group with C-u SPC/RET, let's show
5116 ;; all articles.
5117 'gnus-not-ignore)
5118 ((eq display 'all)
5119 'gnus-not-ignore)
5120 ((arrayp display)
5121 (gnus-summary-display-make-predicate (mapcar 'identity display)))
5122 ((numberp display)
5123 ;; The following is probably the "correct" solution, but
5124 ;; it makes Gnus fetch all headers and then limit the
5125 ;; articles (which is slow), so instead we hack the
5126 ;; select-articles parameter instead. -- Simon Josefsson
5127 ;; <jas@kth.se>
5128 ;;
5129 ;; (gnus-byte-compile
5130 ;; `(lambda () (> number ,(- (cdr (gnus-active group))
5131 ;; display)))))
5132 (setq select-articles
5133 (gnus-uncompress-range
5134 (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5135 (if (> tmp 0)
5136 tmp
5137 1))
5138 (cdr (gnus-active group)))))
5139 nil)
5140 (t
5141 nil))))
eec82323 5142
23f87bed 5143 (gnus-summary-setup-default-charset)
eec82323
LMI
5144
5145 ;; Kludge to avoid having cached articles nixed out in virtual groups.
5146 (when (gnus-virtual-group-p group)
5147 (setq cached gnus-newsgroup-cached))
5148
5149 (setq gnus-newsgroup-unreads
23f87bed
MB
5150 (gnus-sorted-ndifference
5151 (gnus-sorted-ndifference gnus-newsgroup-unreads
5152 gnus-newsgroup-marked)
eec82323
LMI
5153 gnus-newsgroup-dormant))
5154
5155 (setq gnus-newsgroup-processable nil)
5156
5157 (gnus-update-read-articles group gnus-newsgroup-unreads)
eec82323 5158
23f87bed
MB
5159 ;; Adjust and set lists of article marks.
5160 (when info
5161 (gnus-adjust-marked-articles info))
6748645f
LMI
5162 (if (setq articles select-articles)
5163 (setq gnus-newsgroup-unselected
23f87bed 5164 (gnus-sorted-difference gnus-newsgroup-unreads articles))
6748645f 5165 (setq articles (gnus-articles-to-read group read-all)))
eec82323
LMI
5166
5167 (cond
5168 ((null articles)
5169 ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5170 'quit)
5171 ((eq articles 0) nil)
5172 (t
5173 ;; Init the dependencies hash table.
5174 (setq gnus-newsgroup-dependencies
5175 (gnus-make-hashtable (length articles)))
16409b0b 5176 (gnus-set-global-variables)
eec82323 5177 ;; Retrieve the headers and read them in.
23f87bed
MB
5178
5179 (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
eec82323
LMI
5180
5181 ;; Kludge to avoid having cached articles nixed out in virtual groups.
5182 (when cached
5183 (setq gnus-newsgroup-cached cached))
5184
5185 ;; Suppress duplicates?
5186 (when gnus-suppress-duplicates
5187 (gnus-dup-suppress-articles))
5188
5189 ;; Set the initial limit.
5190 (setq gnus-newsgroup-limit (copy-sequence articles))
5191 ;; Remove canceled articles from the list of unread articles.
23f87bed
MB
5192 (setq fetched-articles
5193 (mapcar (lambda (headers) (mail-header-number headers))
5194 gnus-newsgroup-headers))
5195 (setq gnus-newsgroup-articles fetched-articles)
eec82323 5196 (setq gnus-newsgroup-unreads
23f87bed
MB
5197 (gnus-sorted-nintersection
5198 gnus-newsgroup-unreads fetched-articles))
5199 (gnus-compute-unseen-list)
5200
eec82323
LMI
5201 ;; Removed marked articles that do not exist.
5202 (gnus-update-missing-marks
23f87bed 5203 (gnus-sorted-difference articles fetched-articles))
eec82323 5204 ;; We might want to build some more threads first.
6748645f
LMI
5205 (when (and gnus-fetch-old-headers
5206 (eq gnus-headers-retrieved-by 'nov))
5207 (if (eq gnus-fetch-old-headers 'invisible)
5208 (gnus-build-all-threads)
5209 (gnus-build-old-threads)))
5210 ;; Let the Gnus agent mark articles as read.
5211 (when gnus-agent
5212 (gnus-agent-get-undownloaded-list))
16409b0b
GM
5213 ;; Remove list identifiers from subject
5214 (when gnus-list-identifiers
5215 (gnus-summary-remove-list-identifiers))
eec82323
LMI
5216 ;; Check whether auto-expire is to be done in this group.
5217 (setq gnus-newsgroup-auto-expire
5218 (gnus-group-auto-expirable-p group))
5219 ;; Set up the article buffer now, if necessary.
5220 (unless gnus-single-article-buffer
5221 (gnus-article-setup-buffer))
5222 ;; First and last article in this newsgroup.
5223 (when gnus-newsgroup-headers
5224 (setq gnus-newsgroup-begin
5225 (mail-header-number (car gnus-newsgroup-headers))
5226 gnus-newsgroup-end
5227 (mail-header-number
5228 (gnus-last-element gnus-newsgroup-headers))))
5229 ;; GROUP is successfully selected.
5230 (or gnus-newsgroup-headers t)))))
5231
23f87bed
MB
5232(defun gnus-compute-unseen-list ()
5233 ;; The `seen' marks are treated specially.
5234 (if (not gnus-newsgroup-seen)
5235 (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5236 (setq gnus-newsgroup-unseen
5237 (gnus-inverse-list-range-intersection
5238 gnus-newsgroup-articles gnus-newsgroup-seen))))
5239
5240(defun gnus-summary-display-make-predicate (display)
5241 (require 'gnus-agent)
5242 (when (= (length display) 1)
5243 (setq display (car display)))
5244 (unless gnus-summary-display-cache
5245 (dolist (elem (append '((unread . unread)
5246 (read . read)
5247 (unseen . unseen))
5248 gnus-article-mark-lists))
5249 (push (cons (cdr elem)
5250 (gnus-byte-compile
5251 `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5252 gnus-summary-display-cache)))
5253 (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5254 (gnus-category-predicate-cache gnus-summary-display-cache))
5255 (gnus-get-predicate display)))
5256
5257;; Uses the dynamically bound `number' variable.
5258(eval-when-compile
5259 (defvar number))
5260(defun gnus-article-marked-p (type &optional article)
5261 (let ((article (or article number)))
5262 (cond
5263 ((eq type 'tick)
5264 (memq article gnus-newsgroup-marked))
5265 ((eq type 'spam)
5266 (memq article gnus-newsgroup-spam-marked))
5267 ((eq type 'unsend)
5268 (memq article gnus-newsgroup-unsendable))
5269 ((eq type 'undownload)
5270 (memq article gnus-newsgroup-undownloaded))
5271 ((eq type 'download)
5272 (memq article gnus-newsgroup-downloadable))
5273 ((eq type 'unread)
5274 (memq article gnus-newsgroup-unreads))
5275 ((eq type 'read)
5276 (memq article gnus-newsgroup-reads))
5277 ((eq type 'dormant)
5278 (memq article gnus-newsgroup-dormant) )
5279 ((eq type 'expire)
5280 (memq article gnus-newsgroup-expirable))
5281 ((eq type 'reply)
5282 (memq article gnus-newsgroup-replied))
5283 ((eq type 'killed)
5284 (memq article gnus-newsgroup-killed))
5285 ((eq type 'bookmark)
5286 (assq article gnus-newsgroup-bookmarks))
5287 ((eq type 'score)
5288 (assq article gnus-newsgroup-scored))
5289 ((eq type 'save)
5290 (memq article gnus-newsgroup-saved))
5291 ((eq type 'cache)
5292 (memq article gnus-newsgroup-cached))
5293 ((eq type 'forward)
5294 (memq article gnus-newsgroup-forwarded))
5295 ((eq type 'seen)
5296 (not (memq article gnus-newsgroup-unseen)))
5297 ((eq type 'recent)
5298 (memq article gnus-newsgroup-recent))
5299 (t t))))
5300
eec82323 5301(defun gnus-articles-to-read (group &optional read-all)
16409b0b 5302 "Find out what articles the user wants to read."
23f87bed
MB
5303 (let* ((display (gnus-group-find-parameter group 'display))
5304 (articles
eec82323
LMI
5305 ;; Select all articles if `read-all' is non-nil, or if there
5306 ;; are no unread articles.
5307 (if (or read-all
5308 (and (zerop (length gnus-newsgroup-marked))
5309 (zerop (length gnus-newsgroup-unreads)))
23f87bed
MB
5310 ;; Fetch all if the predicate is non-nil.
5311 gnus-newsgroup-display)
5312 ;; We want to select the headers for all the articles in
5313 ;; the group, so we select either all the active
5314 ;; articles in the group, or (if that's nil), the
5315 ;; articles in the cache.
16409b0b
GM
5316 (or
5317 (gnus-uncompress-range (gnus-active group))
5318 (gnus-cache-articles-in-group group))
23f87bed
MB
5319 ;; Select only the "normal" subset of articles.
5320 (gnus-sorted-nunion
5321 (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5322 gnus-newsgroup-unreads)))
eec82323
LMI
5323 (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5324 (scored (length scored-list))
5325 (number (length articles))
5326 (marked (+ (length gnus-newsgroup-marked)
5327 (length gnus-newsgroup-dormant)))
5328 (select
5329 (cond
5330 ((numberp read-all)
5331 read-all)
23f87bed
MB
5332 ((numberp gnus-newsgroup-display)
5333 gnus-newsgroup-display)
eec82323
LMI
5334 (t
5335 (condition-case ()
5336 (cond
5337 ((and (or (<= scored marked) (= scored number))
5338 (numberp gnus-large-newsgroup)
5339 (> number gnus-large-newsgroup))
23f87bed
MB
5340 (let* ((cursor-in-echo-area nil)
5341 (initial (gnus-parameter-large-newsgroup-initial
5342 gnus-newsgroup-name))
5343 (input
5344 (read-string
5345 (format
5346 "How many articles from %s (%s %d): "
5347 (gnus-limit-string
5348 (gnus-group-decoded-name gnus-newsgroup-name)
5349 35)
5350 (if initial "max" "default")
5351 number)
5352 (if initial
5353 (cons (number-to-string initial)
5354 0)))))
eec82323
LMI
5355 (if (string-match "^[ \t]*$" input) number input)))
5356 ((and (> scored marked) (< scored number)
5357 (> (- scored number) 20))
5358 (let ((input
5359 (read-string
5360 (format "%s %s (%d scored, %d total): "
5361 "How many articles from"
23f87bed
MB
5362 (gnus-group-decoded-name group)
5363 scored number))))
eec82323
LMI
5364 (if (string-match "^[ \t]*$" input)
5365 number input)))
5366 (t number))
d4dfaa19
DL
5367 (quit
5368 (message "Quit getting the articles to read")
5369 nil))))))
eec82323
LMI
5370 (setq select (if (stringp select) (string-to-number select) select))
5371 (if (or (null select) (zerop select))
5372 select
5373 (if (and (not (zerop scored)) (<= (abs select) scored))
5374 (progn
5375 (setq articles (sort scored-list '<))
5376 (setq number (length articles)))
5377 (setq articles (copy-sequence articles)))
5378
5379 (when (< (abs select) number)
5380 (if (< select 0)
5381 ;; Select the N oldest articles.
5382 (setcdr (nthcdr (1- (abs select)) articles) nil)
5383 ;; Select the N most recent articles.
5384 (setq articles (nthcdr (- number select) articles))))
5385 (setq gnus-newsgroup-unselected
23f87bed 5386 (gnus-sorted-difference gnus-newsgroup-unreads articles))
16409b0b 5387 (when gnus-alter-articles-to-read-function
23f87bed 5388 (setq articles
a1506d29 5389 (sort
16409b0b 5390 (funcall gnus-alter-articles-to-read-function
23f87bed 5391 gnus-newsgroup-name articles)
16409b0b 5392 '<)))
eec82323
LMI
5393 articles)))
5394
5395(defun gnus-killed-articles (killed articles)
5396 (let (out)
5397 (while articles
5398 (when (inline (gnus-member-of-range (car articles) killed))
5399 (push (car articles) out))
5400 (setq articles (cdr articles)))
5401 out))
5402
5403(defun gnus-uncompress-marks (marks)
5404 "Uncompress the mark ranges in MARKS."
5405 (let ((uncompressed '(score bookmark))
5406 out)
5407 (while marks
5408 (if (memq (caar marks) uncompressed)
5409 (push (car marks) out)
5410 (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5411 (setq marks (cdr marks)))
5412 out))
5413
23f87bed
MB
5414(defun gnus-article-mark-to-type (mark)
5415 "Return the type of MARK."
5416 (or (cadr (assq mark gnus-article-special-mark-lists))
5417 'list))
5418
5419(defun gnus-article-unpropagatable-p (mark)
5420 "Return whether MARK should be propagated to back end."
5421 (memq mark gnus-article-unpropagated-mark-lists))
5422
eec82323 5423(defun gnus-adjust-marked-articles (info)
16409b0b 5424 "Set all article lists and remove all marks that are no longer valid."
eec82323
LMI
5425 (let* ((marked-lists (gnus-info-marks info))
5426 (active (gnus-active (gnus-info-group info)))
5427 (min (car active))
5428 (max (cdr active))
5429 (types gnus-article-mark-lists)
54506618
MB
5430 marks var articles article mark mark-type
5431 bgn end)
eec82323 5432
23f87bed
MB
5433 (dolist (marks marked-lists)
5434 (setq mark (car marks)
5435 mark-type (gnus-article-mark-to-type mark)
5436 var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
eec82323 5437
23f87bed
MB
5438 ;; We set the variable according to the type of the marks list,
5439 ;; and then adjust the marks to a subset of the active articles.
eec82323 5440 (cond
54506618 5441 ;; Adjust "simple" lists - compressed yet unsorted
23f87bed 5442 ((eq mark-type 'list)
54506618
MB
5443 ;; Simultaneously uncompress and clip to active range
5444 ;; See gnus-uncompress-range for a description of possible marks
5445 (let (l lh)
5446 (if (not (cadr marks))
5447 (set var nil)
5448 (setq articles (if (numberp (cddr marks))
5449 (list (cdr marks))
5450 (cdr marks))
5451 lh (cons nil nil)
5452 l lh)
5453
5454 (while (setq article (pop articles))
5455 (cond ((consp article)
5456 (setq bgn (max (car article) min)
5457 end (min (cdr article) max))
5458 (while (<= bgn end)
5459 (setq l (setcdr l (cons bgn nil))
5460 bgn (1+ bgn))))
5461 ((and (<= min article)
5462 (>= max article))
5463 (setq l (setcdr l (cons article nil))))))
5464 (set var (cdr lh)))))
eec82323 5465 ;; Adjust assocs.
23f87bed
MB
5466 ((eq mark-type 'tuple)
5467 (set var (setq articles (cdr marks)))
a8151ef7
LMI
5468 (when (not (listp (cdr (symbol-value var))))
5469 (set var (list (symbol-value var))))
5470 (when (not (listp (cdr articles)))
5471 (setq articles (list articles)))
eec82323
LMI
5472 (while articles
5473 (when (or (not (consp (setq article (pop articles))))
5474 (< (car article) min)
5475 (> (car article) max))
23f87bed
MB
5476 (set var (delq article (symbol-value var))))))
5477 ;; Adjust ranges (sloppily).
5478 ((eq mark-type 'range)
5479 (cond
5480 ((eq mark 'seen)
5481 ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5482 ;; It should be (seen (NUM1 . NUM2)).
5483 (when (numberp (cddr marks))
5484 (setcdr marks (list (cdr marks))))
5485 (setq articles (cdr marks))
5486 (while (and articles
5487 (or (and (consp (car articles))
5488 (> min (cdar articles)))
5489 (and (numberp (car articles))
5490 (> min (car articles)))))
5491 (pop articles))
5492 (set var articles))))))))
eec82323
LMI
5493
5494(defun gnus-update-missing-marks (missing)
6748645f 5495 "Go through the list of MISSING articles and remove them from the mark lists."
eec82323 5496 (when missing
23f87bed 5497 (let (var m)
eec82323 5498 ;; Go through all types.
23f87bed
MB
5499 (dolist (elem gnus-article-mark-lists)
5500 (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5501 (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5502 (when (symbol-value var)
5503 ;; This list has articles. So we delete all missing
5504 ;; articles from it.
5505 (setq m missing)
5506 (while m
5507 (set var (delq (pop m) (symbol-value var))))))))))
eec82323
LMI
5508
5509(defun gnus-update-marks ()
5510 "Enter the various lists of marked articles into the newsgroup info list."
5511 (let ((types gnus-article-mark-lists)
5512 (info (gnus-get-info gnus-newsgroup-name))
16409b0b 5513 type list newmarked symbol delta-marks)
eec82323 5514 (when info
16409b0b 5515 ;; Add all marks lists to the list of marks lists.
eec82323 5516 (while (setq type (pop types))
16409b0b
GM
5517 (setq list (symbol-value
5518 (setq symbol
23f87bed 5519 (intern (format "gnus-newsgroup-%s" (car type))))))
eec82323 5520
16409b0b 5521 (when list
eec82323
LMI
5522 ;; Get rid of the entries of the articles that have the
5523 ;; default score.
5524 (when (and (eq (cdr type) 'score)
5525 gnus-save-score
5526 list)
5527 (let* ((arts list)
5528 (prev (cons nil list))
5529 (all prev))
5530 (while arts
5531 (if (or (not (consp (car arts)))
5532 (= (cdar arts) gnus-summary-default-score))
5533 (setcdr prev (cdr arts))
5534 (setq prev arts))
5535 (setq arts (cdr arts)))
16409b0b
GM
5536 (setq list (cdr all)))))
5537
23f87bed
MB
5538 (when (eq (cdr type) 'seen)
5539 (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5540
5541 (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
16409b0b 5542 (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
a1506d29 5543
23f87bed
MB
5544 (when (and (gnus-check-backend-function
5545 'request-set-mark gnus-newsgroup-name)
5546 (not (gnus-article-unpropagatable-p (cdr type))))
5547 (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5548 (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5549 (add (gnus-remove-from-range
5550 (gnus-copy-sequence list) old)))
5551 (when add
5552 (push (list add 'add (list (cdr type))) delta-marks))
5553 (when del
5554 (push (list del 'del (list (cdr type))) delta-marks))))
a1506d29 5555
16409b0b
GM
5556 (when list
5557 (push (cons (cdr type) list) newmarked)))
5558
5559 (when delta-marks
5560 (unless (gnus-check-group gnus-newsgroup-name)
5561 (error "Can't open server for %s" gnus-newsgroup-name))
5562 (gnus-request-set-mark gnus-newsgroup-name delta-marks))
a1506d29 5563
eec82323
LMI
5564 ;; Enter these new marks into the info of the group.
5565 (if (nthcdr 3 info)
5566 (setcar (nthcdr 3 info) newmarked)
5567 ;; Add the marks lists to the end of the info.
5568 (when newmarked
5569 (setcdr (nthcdr 2 info) (list newmarked))))
5570
5571 ;; Cut off the end of the info if there's nothing else there.
5572 (let ((i 5))
5573 (while (and (> i 2)
5574 (not (nth i info)))
5575 (when (nthcdr (decf i) info)
5576 (setcdr (nthcdr i info) nil)))))))
5577
5578(defun gnus-set-mode-line (where)
16409b0b 5579 "Set the mode line of the article or summary buffers.
eec82323
LMI
5580If WHERE is `summary', the summary mode line format will be used."
5581 ;; Is this mode line one we keep updated?
16409b0b
GM
5582 (when (and (memq where gnus-updated-mode-lines)
5583 (symbol-value
5584 (intern (format "gnus-%s-mode-line-format-spec" where))))
eec82323
LMI
5585 (let (mode-string)
5586 (save-excursion
5587 ;; We evaluate this in the summary buffer since these
5588 ;; variables are buffer-local to that buffer.
5589 (set-buffer gnus-summary-buffer)
23f87bed 5590 ;; We bind all these variables that are used in the `eval' form
eec82323
LMI
5591 ;; below.
5592 (let* ((mformat (symbol-value
5593 (intern
5594 (format "gnus-%s-mode-line-format-spec" where))))
23f87bed
MB
5595 (gnus-tmp-group-name (gnus-group-decoded-name
5596 gnus-newsgroup-name))
eec82323
LMI
5597 (gnus-tmp-article-number (or gnus-current-article 0))
5598 (gnus-tmp-unread gnus-newsgroup-unreads)
5599 (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5600 (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5601 (gnus-tmp-unread-and-unselected
5602 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5603 (zerop gnus-tmp-unselected))
5604 "")
5605 ((zerop gnus-tmp-unselected)
5606 (format "{%d more}" gnus-tmp-unread-and-unticked))
5607 (t (format "{%d(+%d) more}"
5608 gnus-tmp-unread-and-unticked
5609 gnus-tmp-unselected))))
5610 (gnus-tmp-subject
5611 (if (and gnus-current-headers
5612 (vectorp gnus-current-headers))
5613 (gnus-mode-string-quote
5614 (mail-header-subject gnus-current-headers))
5615 ""))
5616 bufname-length max-len
23f87bed 5617 gnus-tmp-header) ;; passed as argument to any user-format-funcs
eec82323
LMI
5618 (setq mode-string (eval mformat))
5619 (setq bufname-length (if (string-match "%b" mode-string)
5620 (- (length
5621 (buffer-name
5622 (if (eq where 'summary)
5623 nil
5624 (get-buffer gnus-article-buffer))))
5625 2)
5626 0))
5627 (setq max-len (max 4 (if gnus-mode-non-string-length
5628 (- (window-width)
5629 gnus-mode-non-string-length
5630 bufname-length)
5631 (length mode-string))))
5632 ;; We might have to chop a bit of the string off...
5633 (when (> (length mode-string) max-len)
5634 (setq mode-string
16409b0b 5635 (concat (truncate-string-to-width mode-string (- max-len 3))
eec82323
LMI
5636 "...")))
5637 ;; Pad the mode string a bit.
5638 (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5639 ;; Update the mode line.
5640 (setq mode-line-buffer-identification
5641 (gnus-mode-line-buffer-identification (list mode-string)))
5642 (set-buffer-modified-p t))))
5643
5644(defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5645 "Go through the HEADERS list and add all Xrefs to a hash table.
5646The resulting hash table is returned, or nil if no Xrefs were found."
5647 (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5648 (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5649 (xref-hashtb (gnus-make-hashtable))
5650 start group entry number xrefs header)
5651 (while headers
5652 (setq header (pop headers))
5653 (when (and (setq xrefs (mail-header-xref header))
5654 (not (memq (setq number (mail-header-number header))
5655 unreads)))
5656 (setq start 0)
5657 (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5658 (setq start (match-end 0))
5659 (setq group (if prefix
5660 (concat prefix (substring xrefs (match-beginning 1)
5661 (match-end 1)))
5662 (substring xrefs (match-beginning 1) (match-end 1))))
5663 (setq number
e9bd5782 5664 (string-to-number (substring xrefs (match-beginning 2)
eec82323
LMI
5665 (match-end 2))))
5666 (if (setq entry (gnus-gethash group xref-hashtb))
5667 (setcdr entry (cons number (cdr entry)))
5668 (gnus-sethash group (cons number nil) xref-hashtb)))))
5669 (and start xref-hashtb)))
5670
5671(defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5672 "Look through all the headers and mark the Xrefs as read."
5673 (let ((virtual (gnus-virtual-group-p from-newsgroup))
5674 name entry info xref-hashtb idlist method nth4)
5675 (save-excursion
5676 (set-buffer gnus-group-buffer)
5677 (when (setq xref-hashtb
5678 (gnus-create-xref-hashtb from-newsgroup headers unreads))
5679 (mapatoms
5680 (lambda (group)
5681 (unless (string= from-newsgroup (setq name (symbol-name group)))
5682 (setq idlist (symbol-value group))
5683 ;; Dead groups are not updated.
5684 (and (prog1
5685 (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5686 info (nth 2 entry))
5687 (when (stringp (setq nth4 (gnus-info-method info)))
5688 (setq nth4 (gnus-server-to-method nth4))))
5689 ;; Only do the xrefs if the group has the same
5690 ;; select method as the group we have just read.
5691 (or (gnus-methods-equal-p
5692 nth4 (gnus-find-method-for-group from-newsgroup))
5693 virtual
5694 (equal nth4 (setq method (gnus-find-method-for-group
5695 from-newsgroup)))
5696 (and (equal (car nth4) (car method))
5697 (equal (nth 1 nth4) (nth 1 method))))
5698 gnus-use-cross-reference
5699 (or (not (eq gnus-use-cross-reference t))
5700 virtual
5701 ;; Only do cross-references on subscribed
5702 ;; groups, if that is what is wanted.
5703 (<= (gnus-info-level info) gnus-level-subscribed))
5704 (gnus-group-make-articles-read name idlist))))
5705 xref-hashtb)))))
5706
6748645f
LMI
5707(defun gnus-compute-read-articles (group articles)
5708 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5709 (info (nth 2 entry))
5710 (active (gnus-active group))
5711 ninfo)
5712 (when entry
16409b0b 5713 ;; First peel off all invalid article numbers.
6748645f
LMI
5714 (when active
5715 (let ((ids articles)
5716 id first)
5717 (while (setq id (pop ids))
5718 (when (and first (> id (cdr active)))
5719 ;; We'll end up in this situation in one particular
5720 ;; obscure situation. If you re-scan a group and get
5721 ;; a new article that is cross-posted to a different
5722 ;; group that has not been re-scanned, you might get
5723 ;; crossposted article that has a higher number than
5724 ;; Gnus believes possible. So we re-activate this
5725 ;; group as well. This might mean doing the
5726 ;; crossposting thingy will *increase* the number
5727 ;; of articles in some groups. Tsk, tsk.
5728 (setq active (or (gnus-activate-group group) active)))
5729 (when (or (> id (cdr active))
5730 (< id (car active)))
5731 (setq articles (delq id articles))))))
5732 ;; If the read list is nil, we init it.
5733 (if (and active
5734 (null (gnus-info-read info))
5735 (> (car active) 1))
5736 (setq ninfo (cons 1 (1- (car active))))
5737 (setq ninfo (gnus-info-read info)))
5738 ;; Then we add the read articles to the range.
5739 (gnus-add-to-range
5740 ninfo (setq articles (sort articles '<))))))
5741
eec82323
LMI
5742(defun gnus-group-make-articles-read (group articles)
5743 "Update the info of GROUP to say that ARTICLES are read."
5744 (let* ((num 0)
5745 (entry (gnus-gethash group gnus-newsrc-hashtb))
5746 (info (nth 2 entry))
5747 (active (gnus-active group))
5748 range)
6748645f
LMI
5749 (when entry
5750 (setq range (gnus-compute-read-articles group articles))
5751 (save-excursion
5752 (set-buffer gnus-group-buffer)
5753 (gnus-undo-register
5754 `(progn
5755 (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5756 (gnus-info-set-read ',info ',(gnus-info-read info))
5757 (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
23f87bed 5758 (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6748645f
LMI
5759 (gnus-group-update-group ,group t))))
5760 ;; Add the read articles to the range.
5761 (gnus-info-set-read info range)
23f87bed 5762 (gnus-request-set-mark group (list (list range 'add '(read))))
6748645f
LMI
5763 ;; Then we have to re-compute how many unread
5764 ;; articles there are in this group.
5765 (when active
5766 (cond
5767 ((not range)
5768 (setq num (- (1+ (cdr active)) (car active))))
5769 ((not (listp (cdr range)))
5770 (setq num (- (cdr active) (- (1+ (cdr range))
5771 (car range)))))
5772 (t
5773 (while range
5774 (if (numberp (car range))
5775 (setq num (1+ num))
5776 (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5777 (setq range (cdr range)))
5778 (setq num (- (cdr active) num))))
5779 ;; Update the number of unread articles.
5780 (setcar entry num)
5781 ;; Update the group buffer.
23f87bed
MB
5782 (unless (gnus-ephemeral-group-p group)
5783 (gnus-group-update-group group t))))))
eec82323 5784
eec82323
LMI
5785(defvar gnus-newsgroup-none-id 0)
5786
5787(defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5788 (let ((cur nntp-server-buffer)
5789 (dependencies
5790 (or dependencies
5791 (save-excursion (set-buffer gnus-summary-buffer)
5792 gnus-newsgroup-dependencies)))
16409b0b
GM
5793 headers id end ref
5794 (mail-parse-charset gnus-newsgroup-charset)
5795 (mail-parse-ignored-charsets
5796 (save-excursion (condition-case nil
5797 (set-buffer gnus-summary-buffer)
5798 (error))
5799 gnus-newsgroup-ignored-charsets)))
eec82323
LMI
5800 (save-excursion
5801 (set-buffer nntp-server-buffer)
5802 ;; Translate all TAB characters into SPACE characters.
5803 (subst-char-in-region (point-min) (point-max) ?\t ? t)
16409b0b 5804 (subst-char-in-region (point-min) (point-max) ?\r ? t)
23f87bed 5805 (ietf-drums-unfold-fws)
6748645f 5806 (gnus-run-hooks 'gnus-parse-headers-hook)
eec82323 5807 (let ((case-fold-search t)
6748645f 5808 in-reply-to header p lines chars)
eec82323
LMI
5809 (goto-char (point-min))
5810 ;; Search to the beginning of the next header. Error messages
5811 ;; do not begin with 2 or 3.
5812 (while (re-search-forward "^[23][0-9]+ " nil t)
5813 (setq id nil
5814 ref nil)
5815 ;; This implementation of this function, with nine
5816 ;; search-forwards instead of the one re-search-forward and
5817 ;; a case (which basically was the old function) is actually
5818 ;; about twice as fast, even though it looks messier. You
5819 ;; can't have everything, I guess. Speed and elegance
5820 ;; doesn't always go hand in hand.
5821 (setq
5822 header
5823 (vector
5824 ;; Number.
5825 (prog1
5826 (read cur)
5827 (end-of-line)
5828 (setq p (point))
5829 (narrow-to-region (point)
5830 (or (and (search-forward "\n.\n" nil t)
5831 (- (point) 2))
5832 (point))))
5833 ;; Subject.
5834 (progn
5835 (goto-char p)
23f87bed 5836 (if (search-forward "\nsubject:" nil t)
16409b0b
GM
5837 (funcall gnus-decode-encoded-word-function
5838 (nnheader-header-value))
2bd3dcae 5839 "(none)"))
eec82323
LMI
5840 ;; From.
5841 (progn
5842 (goto-char p)
23f87bed 5843 (if (search-forward "\nfrom:" nil t)
16409b0b
GM
5844 (funcall gnus-decode-encoded-word-function
5845 (nnheader-header-value))
2bd3dcae 5846 "(nobody)"))
eec82323
LMI
5847 ;; Date.
5848 (progn
5849 (goto-char p)
23f87bed 5850 (if (search-forward "\ndate:" nil t)
eec82323
LMI
5851 (nnheader-header-value) ""))
5852 ;; Message-ID.
5853 (progn
5854 (goto-char p)
6748645f
LMI
5855 (setq id (if (re-search-forward
5856 "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5857 ;; We do it this way to make sure the Message-ID
5858 ;; is (somewhat) syntactically valid.
5859 (buffer-substring (match-beginning 1)
5860 (match-end 1))
eec82323
LMI
5861 ;; If there was no message-id, we just fake one
5862 ;; to make subsequent routines simpler.
5863 (nnheader-generate-fake-message-id))))
5864 ;; References.
5865 (progn
5866 (goto-char p)
23f87bed 5867 (if (search-forward "\nreferences:" nil t)
eec82323
LMI
5868 (progn
5869 (setq end (point))
5870 (prog1
5871 (nnheader-header-value)
5872 (setq ref
5873 (buffer-substring
5874 (progn
5875 (end-of-line)
5876 (search-backward ">" end t)
5877 (1+ (point)))
5878 (progn
5879 (search-backward "<" end t)
5880 (point))))))
5881 ;; Get the references from the in-reply-to header if there
5882 ;; were no references and the in-reply-to header looks
5883 ;; promising.
23f87bed 5884 (if (and (search-forward "\nin-reply-to:" nil t)
eec82323
LMI
5885 (setq in-reply-to (nnheader-header-value))
5886 (string-match "<[^>]+>" in-reply-to))
6748645f
LMI
5887 (let (ref2)
5888 (setq ref (substring in-reply-to (match-beginning 0)
5889 (match-end 0)))
5890 (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5891 (setq ref2 (substring in-reply-to (match-beginning 0)
5892 (match-end 0)))
5893 (when (> (length ref2) (length ref))
5894 (setq ref ref2)))
5895 ref)
eec82323
LMI
5896 (setq ref nil))))
5897 ;; Chars.
6748645f
LMI
5898 (progn
5899 (goto-char p)
5900 (if (search-forward "\nchars: " nil t)
5901 (if (numberp (setq chars (ignore-errors (read cur))))
23f87bed
MB
5902 chars -1)
5903 -1))
eec82323
LMI
5904 ;; Lines.
5905 (progn
5906 (goto-char p)
5907 (if (search-forward "\nlines: " nil t)
a8151ef7 5908 (if (numberp (setq lines (ignore-errors (read cur))))
23f87bed
MB
5909 lines -1)
5910 -1))
eec82323
LMI
5911 ;; Xref.
5912 (progn
5913 (goto-char p)
23f87bed 5914 (and (search-forward "\nxref:" nil t)
16409b0b
GM
5915 (nnheader-header-value)))
5916 ;; Extra.
5917 (when gnus-extra-headers
5918 (let ((extra gnus-extra-headers)
5919 out)
5920 (while extra
5921 (goto-char p)
5922 (when (search-forward
23f87bed 5923 (concat "\n" (symbol-name (car extra)) ":") nil t)
16409b0b
GM
5924 (push (cons (car extra) (nnheader-header-value))
5925 out))
5926 (pop extra))
5927 out))))
eec82323
LMI
5928 (when (equal id ref)
5929 (setq ref nil))
6748645f
LMI
5930
5931 (when gnus-alter-header-function
5932 (funcall gnus-alter-header-function header)
5933 (setq id (mail-header-id header)
5934 ref (gnus-parent-id (mail-header-references header))))
5935
5936 (when (setq header
5937 (gnus-dependencies-add-header
5938 header dependencies force-new))
eec82323
LMI
5939 (push header headers))
5940 (goto-char (point-max))
5941 (widen))
5942 (nreverse headers)))))
5943
eec82323
LMI
5944;; Goes through the xover lines and returns a list of vectors
5945(defun gnus-get-newsgroup-headers-xover (sequence &optional
5946 force-new dependencies
5947 group also-fetch-heads)
16409b0b
GM
5948 "Parse the news overview data in the server buffer.
5949Return a list of headers that match SEQUENCE (see
5950`nntp-retrieve-headers')."
eec82323
LMI
5951 ;; Get the Xref when the users reads the articles since most/some
5952 ;; NNTP servers do not include Xrefs when using XOVER.
5953 (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
16409b0b
GM
5954 (let ((mail-parse-charset gnus-newsgroup-charset)
5955 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5956 (cur nntp-server-buffer)
eec82323 5957 (dependencies (or dependencies gnus-newsgroup-dependencies))
23f87bed
MB
5958 (allp (cond
5959 ((eq gnus-read-all-available-headers t)
5960 t)
5961 ((stringp gnus-read-all-available-headers)
5962 (string-match gnus-read-all-available-headers group))
5963 (t
5964 nil)))
eec82323
LMI
5965 number headers header)
5966 (save-excursion
5967 (set-buffer nntp-server-buffer)
16409b0b 5968 (subst-char-in-region (point-min) (point-max) ?\r ? t)
eec82323 5969 ;; Allow the user to mangle the headers before parsing them.
6748645f 5970 (gnus-run-hooks 'gnus-parse-headers-hook)
eec82323 5971 (goto-char (point-min))
23f87bed
MB
5972 (gnus-parse-without-error
5973 (while (and (or sequence allp)
5974 (not (eobp)))
5975 (setq number (read cur))
5976 (when (not allp)
5977 (while (and sequence
5978 (< (car sequence) number))
5979 (setq sequence (cdr sequence))))
5980 (when (and (or allp
5981 (and sequence
5982 (eq number (car sequence))))
5983 (progn
5984 (setq sequence (cdr sequence))
5985 (setq header (inline
5986 (gnus-nov-parse-line
5987 number dependencies force-new)))))
5988 (push header headers))
5989 (forward-line 1)))
eec82323
LMI
5990 ;; A common bug in inn is that if you have posted an article and
5991 ;; then retrieves the active file, it will answer correctly --
5992 ;; the new article is included. However, a NOV entry for the
5993 ;; article may not have been generated yet, so this may fail.
5994 ;; We work around this problem by retrieving the last few
5995 ;; headers using HEAD.
5996 (if (or (not also-fetch-heads)
5997 (not sequence))
5998 ;; We (probably) got all the headers.
5999 (nreverse headers)
6000 (let ((gnus-nov-is-evil t))
6001 (nconc
6002 (nreverse headers)
23f87bed 6003 (when (eq (gnus-retrieve-headers sequence group) 'headers)
eec82323
LMI
6004 (gnus-get-newsgroup-headers))))))))
6005
6006(defun gnus-article-get-xrefs ()
6007 "Fill in the Xref value in `gnus-current-headers', if necessary.
6008This is meant to be called in `gnus-article-internal-prepare-hook'."
6009 (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
6010 gnus-current-headers)))
6011 (or (not gnus-use-cross-reference)
6012 (not headers)
6013 (and (mail-header-xref headers)
6014 (not (string= (mail-header-xref headers) "")))
6015 (let ((case-fold-search t)
6016 xref)
6017 (save-restriction
6018 (nnheader-narrow-to-headers)
6019 (goto-char (point-min))
16409b0b
GM
6020 (when (or (and (not (eobp))
6021 (eq (downcase (char-after)) ?x)
eec82323
LMI
6022 (looking-at "Xref:"))
6023 (search-forward "\nXref:" nil t))
6024 (goto-char (1+ (match-end 0)))
23f87bed 6025 (setq xref (buffer-substring (point) (gnus-point-at-eol)))
eec82323
LMI
6026 (mail-header-set-xref headers xref)))))))
6027
6028(defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6748645f
LMI
6029 "Find article ID and insert the summary line for that article.
6030OLD-HEADER can either be a header or a line number to insert
6031the subject line on."
6032 (let* ((line (and (numberp old-header) old-header))
6033 (old-header (and (vectorp old-header) old-header))
6034 (header (cond ((and old-header use-old-header)
16409b0b
GM
6035 old-header)
6036 ((and (numberp id)
6037 (gnus-number-to-header id))
6038 (gnus-number-to-header id))
6039 (t
6040 (gnus-read-header id))))
6041 (number (and (numberp id) id))
6042 d)
eec82323
LMI
6043 (when header
6044 ;; Rebuild the thread that this article is part of and go to the
6045 ;; article we have fetched.
6046 (when (and (not gnus-show-threads)
6047 old-header)
6748645f
LMI
6048 (when (and number
6049 (setq d (gnus-data-find (mail-header-number old-header))))
eec82323
LMI
6050 (goto-char (gnus-data-pos d))
6051 (gnus-data-remove
6052 number
6053 (- (gnus-point-at-bol)
6054 (prog1
6055 (1+ (gnus-point-at-eol))
6056 (gnus-delete-line))))))
23f87bed
MB
6057 ;; Remove list identifiers from subject.
6058 (when gnus-list-identifiers
6059 (let ((gnus-newsgroup-headers (list header)))
c3bc41c2 6060 (gnus-summary-remove-list-identifiers)))
eec82323
LMI
6061 (when old-header
6062 (mail-header-set-number header (mail-header-number old-header)))
6063 (setq gnus-newsgroup-sparse
6064 (delq (setq number (mail-header-number header))
6065 gnus-newsgroup-sparse))
6066 (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6748645f
LMI
6067 (push number gnus-newsgroup-limit)
6068 (gnus-rebuild-thread (mail-header-id header) line)
eec82323
LMI
6069 (gnus-summary-goto-subject number nil t))
6070 (when (and (numberp number)
6071 (> number 0))
6072 ;; We have to update the boundaries even if we can't fetch the
6073 ;; article if ID is a number -- so that the next `P' or `N'
6074 ;; command will fetch the previous (or next) article even
6075 ;; if the one we tried to fetch this time has been canceled.
6076 (when (> number gnus-newsgroup-end)
6077 (setq gnus-newsgroup-end number))
6078 (when (< number gnus-newsgroup-begin)
6079 (setq gnus-newsgroup-begin number))
6080 (setq gnus-newsgroup-unselected
6081 (delq number gnus-newsgroup-unselected)))
6082 ;; Report back a success?
6083 (and header (mail-header-number header))))
6084
6085;;; Process/prefix in the summary buffer
6086
6087(defun gnus-summary-work-articles (n)
6748645f
LMI
6088 "Return a list of articles to be worked upon.
6089The prefix argument, the list of process marked articles, and the
6090current article will be taken into consideration."
6091 (save-excursion
6092 (set-buffer gnus-summary-buffer)
6093 (cond
6094 (n
6095 ;; A numerical prefix has been given.
6096 (setq n (prefix-numeric-value n))
6097 (let ((backward (< n 0))
6098 (n (abs (prefix-numeric-value n)))
6099 articles article)
6100 (save-excursion
6101 (while
6102 (and (> n 0)
6103 (push (setq article (gnus-summary-article-number))
6104 articles)
6105 (if backward
6106 (gnus-summary-find-prev nil article)
6107 (gnus-summary-find-next nil article)))
6108 (decf n)))
6109 (nreverse articles)))
6110 ((and (gnus-region-active-p) (mark))
6111 (message "region active")
6112 ;; Work on the region between point and mark.
6113 (let ((max (max (point) (mark)))
6114 articles article)
6115 (save-excursion
6116 (goto-char (min (min (point) (mark))))
6117 (while
6118 (and
6119 (push (setq article (gnus-summary-article-number)) articles)
6120 (gnus-summary-find-next nil article)
6121 (< (point) max)))
6122 (nreverse articles))))
6123 (gnus-newsgroup-processable
6124 ;; There are process-marked articles present.
6125 ;; Save current state.
6126 (gnus-summary-save-process-mark)
6127 ;; Return the list.
6128 (reverse gnus-newsgroup-processable))
6129 (t
6130 ;; Just return the current article.
6131 (list (gnus-summary-article-number))))))
6132
6133(defmacro gnus-summary-iterate (arg &rest forms)
6134 "Iterate over the process/prefixed articles and do FORMS.
6135ARG is the interactive prefix given to the command. FORMS will be
6136executed with point over the summary line of the articles."
6137 (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6138 `(let ((,articles (gnus-summary-work-articles ,arg)))
6139 (while ,articles
6140 (gnus-summary-goto-subject (car ,articles))
16409b0b
GM
6141 ,@forms
6142 (pop ,articles)))))
6748645f
LMI
6143
6144(put 'gnus-summary-iterate 'lisp-indent-function 1)
6145(put 'gnus-summary-iterate 'edebug-form-spec '(form body))
eec82323
LMI
6146
6147(defun gnus-summary-save-process-mark ()
6148 "Push the current set of process marked articles on the stack."
6149 (interactive)
6150 (push (copy-sequence gnus-newsgroup-processable)
6151 gnus-newsgroup-process-stack))
6152
6153(defun gnus-summary-kill-process-mark ()
6154 "Push the current set of process marked articles on the stack and unmark."
6155 (interactive)
6156 (gnus-summary-save-process-mark)
6157 (gnus-summary-unmark-all-processable))
6158
6159(defun gnus-summary-yank-process-mark ()
6160 "Pop the last process mark state off the stack and restore it."
6161 (interactive)
6162 (unless gnus-newsgroup-process-stack
6163 (error "Empty mark stack"))
6164 (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6165
6166(defun gnus-summary-process-mark-set (set)
6167 "Make SET into the current process marked articles."
6168 (gnus-summary-unmark-all-processable)
6169 (while set
6170 (gnus-summary-set-process-mark (pop set))))
6171
6172;;; Searching and stuff
6173
6174(defun gnus-summary-search-group (&optional backward use-level)
6175 "Search for next unread newsgroup.
6176If optional argument BACKWARD is non-nil, search backward instead."
6177 (save-excursion
6178 (set-buffer gnus-group-buffer)
6179 (when (gnus-group-search-forward
6180 backward nil (if use-level (gnus-group-group-level) nil))
6181 (gnus-group-group-name))))
6182
6183(defun gnus-summary-best-group (&optional exclude-group)
6184 "Find the name of the best unread group.
6185If EXCLUDE-GROUP, do not go to this group."
6186 (save-excursion
6187 (set-buffer gnus-group-buffer)
6188 (save-excursion
6189 (gnus-group-best-unread-group exclude-group))))
6190
23f87bed
MB
6191(defun gnus-summary-find-next (&optional unread article backward)
6192 (if backward
6193 (gnus-summary-find-prev unread article)
eec82323
LMI
6194 (let* ((dummy (gnus-summary-article-intangible-p))
6195 (article (or article (gnus-summary-article-number)))
23f87bed 6196 (data (gnus-data-find-list article))
eec82323
LMI
6197 result)
6198 (when (and (not dummy)
6199 (or (not gnus-summary-check-current)
6200 (not unread)
23f87bed
MB
6201 (not (gnus-data-unread-p (car data)))))
6202 (setq data (cdr data)))
eec82323
LMI
6203 (when (setq result
6204 (if unread
6205 (progn
23f87bed
MB
6206 (while data
6207 (unless (memq (gnus-data-number (car data))
6208 (cond
6209 ((eq gnus-auto-goto-ignores
6210 'always-undownloaded)
6211 gnus-newsgroup-undownloaded)
6212 (gnus-plugged
6213 nil)
6214 ((eq gnus-auto-goto-ignores
6215 'unfetched)
6216 gnus-newsgroup-unfetched)
6217 ((eq gnus-auto-goto-ignores
6218 'undownloaded)
6219 gnus-newsgroup-undownloaded)))
6220 (when (gnus-data-unread-p (car data))
6221 (setq result (car data)
6222 data nil)))
6223 (setq data (cdr data)))
eec82323 6224 result)
23f87bed 6225 (car data)))
eec82323
LMI
6226 (goto-char (gnus-data-pos result))
6227 (gnus-data-number result)))))
6228
6229(defun gnus-summary-find-prev (&optional unread article)
6230 (let* ((eobp (eobp))
6231 (article (or article (gnus-summary-article-number)))
23f87bed 6232 (data (gnus-data-find-list article (gnus-data-list 'rev)))
eec82323
LMI
6233 result)
6234 (when (and (not eobp)
6235 (or (not gnus-summary-check-current)
6236 (not unread)
23f87bed
MB
6237 (not (gnus-data-unread-p (car data)))))
6238 (setq data (cdr data)))
eec82323
LMI
6239 (when (setq result
6240 (if unread
6241 (progn
23f87bed
MB
6242 (while data
6243 (unless (memq (gnus-data-number (car data))
6244 (cond
6245 ((eq gnus-auto-goto-ignores
6246 'always-undownloaded)
6247 gnus-newsgroup-undownloaded)
6248 (gnus-plugged
6249 nil)
6250 ((eq gnus-auto-goto-ignores
6251 'unfetched)
6252 gnus-newsgroup-unfetched)
6253 ((eq gnus-auto-goto-ignores
6254 'undownloaded)
6255 gnus-newsgroup-undownloaded)))
6256 (when (gnus-data-unread-p (car data))
6257 (setq result (car data)
6258 data nil)))
6259 (setq data (cdr data)))
eec82323 6260 result)
23f87bed 6261 (car data)))
eec82323
LMI
6262 (goto-char (gnus-data-pos result))
6263 (gnus-data-number result))))
6264
6265(defun gnus-summary-find-subject (subject &optional unread backward article)
6266 (let* ((simp-subject (gnus-simplify-subject-fully subject))
6267 (article (or article (gnus-summary-article-number)))
6268 (articles (gnus-data-list backward))
6269 (arts (gnus-data-find-list article articles))
6270 result)
6271 (when (or (not gnus-summary-check-current)
6272 (not unread)
6273 (not (gnus-data-unread-p (car arts))))
6274 (setq arts (cdr arts)))
6275 (while arts
6276 (and (or (not unread)
6277 (gnus-data-unread-p (car arts)))
6278 (vectorp (gnus-data-header (car arts)))
6279 (gnus-subject-equal
6280 simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6281 (setq result (car arts)
6282 arts nil))
6283 (setq arts (cdr arts)))
6284 (and result
6285 (goto-char (gnus-data-pos result))
6286 (gnus-data-number result))))
6287
6288(defun gnus-summary-search-forward (&optional unread subject backward)
6289 "Search forward for an article.
6290If UNREAD, look for unread articles. If SUBJECT, look for
6291articles with that subject. If BACKWARD, search backward instead."
6292 (cond (subject (gnus-summary-find-subject subject unread backward))
6293 (backward (gnus-summary-find-prev unread))
6294 (t (gnus-summary-find-next unread))))
6295
6296(defun gnus-recenter (&optional n)
6297 "Center point in window and redisplay frame.
6298Also do horizontal recentering."
6299 (interactive "P")
6300 (when (and gnus-auto-center-summary
6301 (not (eq gnus-auto-center-summary 'vertical)))
6302 (gnus-horizontal-recenter))
6303 (recenter n))
6304
6305(defun gnus-summary-recenter ()
6306 "Center point in the summary window.
6307If `gnus-auto-center-summary' is nil, or the article buffer isn't
6308displayed, no centering will be performed."
6309 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6310 ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
16409b0b 6311 (interactive)
23f87bed
MB
6312 ;; The user has to want it.
6313 (when gnus-auto-center-summary
6314 (let* ((top (cond ((< (window-height) 4) 0)
6315 ((< (window-height) 7) 1)
6316 (t (if (numberp gnus-auto-center-summary)
6317 gnus-auto-center-summary
6318 2))))
6319 (height (1- (window-height)))
6320 (bottom (save-excursion (goto-char (point-max))
6321 (forward-line (- height))
6322 (point)))
6323 (window (get-buffer-window (current-buffer))))
eec82323
LMI
6324 (when (get-buffer-window gnus-article-buffer)
6325 ;; Only do recentering when the article buffer is displayed,
6326 ;; Set the window start to either `bottom', which is the biggest
6327 ;; possible valid number, or the second line from the top,
6328 ;; whichever is the least.
db7ebd73
MB
6329 (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6330 (if (> bottom top-pos)
6331 ;; Keep the second line from the top visible
6332 (set-window-start window top-pos t)
6333 ;; Try to keep the bottom line visible; if it's partially
6334 ;; obscured, either scroll one more line to make it fully
6335 ;; visible, or revert to using TOP-POS.
6336 (save-excursion
6337 (goto-char (point-max))
6338 (forward-line -1)
6339 (let ((last-line-start (point)))
6340 (goto-char bottom)
6341 (set-window-start window (point) t)
6342 (when (not (pos-visible-in-window-p last-line-start window))
6343 (forward-line 1)
6344 (set-window-start window (min (point) top-pos) t)))))))
eec82323
LMI
6345 ;; Do horizontal recentering while we're at it.
6346 (when (and (get-buffer-window (current-buffer) t)
6347 (not (eq gnus-auto-center-summary 'vertical)))
6348 (let ((selected (selected-window)))
6349 (select-window (get-buffer-window (current-buffer) t))
6350 (gnus-summary-position-point)
6351 (gnus-horizontal-recenter)
6352 (select-window selected))))))
6353
6354(defun gnus-summary-jump-to-group (newsgroup)
6355 "Move point to NEWSGROUP in group mode buffer."
6356 ;; Keep update point of group mode buffer if visible.
6357 (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6358 (save-window-excursion
6359 ;; Take care of tree window mode.
6360 (when (get-buffer-window gnus-group-buffer)
6361 (pop-to-buffer gnus-group-buffer))
6362 (gnus-group-jump-to-group newsgroup))
6363 (save-excursion
6364 ;; Take care of tree window mode.
6365 (if (get-buffer-window gnus-group-buffer)
6366 (pop-to-buffer gnus-group-buffer)
6367 (set-buffer gnus-group-buffer))
6368 (gnus-group-jump-to-group newsgroup))))
6369
6370;; This function returns a list of article numbers based on the
6371;; difference between the ranges of read articles in this group and
6372;; the range of active articles.
6373(defun gnus-list-of-unread-articles (group)
6374 (let* ((read (gnus-info-read (gnus-get-info group)))
6375 (active (or (gnus-active group) (gnus-activate-group group)))
6376 (last (cdr active))
6377 first nlast unread)
6378 ;; If none are read, then all are unread.
6379 (if (not read)
6380 (setq first (car active))
6381 ;; If the range of read articles is a single range, then the
6382 ;; first unread article is the article after the last read
6383 ;; article. Sounds logical, doesn't it?
16409b0b
GM
6384 (if (and (not (listp (cdr read)))
6385 (or (< (car read) (car active))
6386 (progn (setq read (list read))
6387 nil)))
6748645f 6388 (setq first (max (car active) (1+ (cdr read))))
eec82323
LMI
6389 ;; `read' is a list of ranges.
6390 (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6391 (caar read)))
6392 1)
6748645f 6393 (setq first (car active)))
eec82323
LMI
6394 (while read
6395 (when first
6396 (while (< first nlast)
54506618
MB
6397 (setq unread (cons first unread)
6398 first (1+ first))))
eec82323
LMI
6399 (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6400 (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6401 (setq read (cdr read)))))
6402 ;; And add the last unread articles.
6403 (while (<= first last)
54506618
MB
6404 (setq unread (cons first unread)
6405 first (1+ first)))
eec82323 6406 ;; Return the list of unread articles.
6748645f 6407 (delq 0 (nreverse unread))))
eec82323
LMI
6408
6409(defun gnus-list-of-read-articles (group)
6410 "Return a list of unread, unticked and non-dormant articles."
6411 (let* ((info (gnus-get-info group))
6412 (marked (gnus-info-marks info))
6413 (active (gnus-active group)))
6414 (and info active
23f87bed
MB
6415 (gnus-list-range-difference
6416 (gnus-list-range-difference
6417 (gnus-sorted-complement
6418 (gnus-uncompress-range active)
6419 (gnus-list-of-unread-articles group))
6420 (cdr (assq 'dormant marked)))
6421 (cdr (assq 'tick marked))))))
eec82323 6422
54506618
MB
6423;; This function returns a sequence of article numbers based on the
6424;; difference between the ranges of read articles in this group and
6425;; the range of active articles.
6426(defun gnus-sequence-of-unread-articles (group)
6427 (let* ((read (gnus-info-read (gnus-get-info group)))
6428 (active (or (gnus-active group) (gnus-activate-group group)))
6429 (last (cdr active))
6430 first nlast unread)
6431 ;; If none are read, then all are unread.
6432 (if (not read)
6433 (setq first (car active))
6434 ;; If the range of read articles is a single range, then the
6435 ;; first unread article is the article after the last read
6436 ;; article. Sounds logical, doesn't it?
6437 (if (and (not (listp (cdr read)))
6438 (or (< (car read) (car active))
6439 (progn (setq read (list read))
6440 nil)))
6441 (setq first (max (car active) (1+ (cdr read))))
6442 ;; `read' is a list of ranges.
6443 (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6444 (caar read)))
6445 1)
6446 (setq first (car active)))
6447 (while read
6448 (when first
6449 (push (cons first nlast) unread))
6450 (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6451 (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6452 (setq read (cdr read)))))
6453 ;; And add the last unread articles.
6454 (cond ((< first last)
6455 (push (cons first last) unread))
6456 ((= first last)
6457 (push first unread)))
6458 ;; Return the sequence of unread articles.
6459 (delq 0 (nreverse unread))))
6460
eec82323
LMI
6461;; Various summary commands
6462
6748645f
LMI
6463(defun gnus-summary-select-article-buffer ()
6464 "Reconfigure windows to show article buffer."
6465 (interactive)
6466 (if (not (gnus-buffer-live-p gnus-article-buffer))
6467 (error "There is no article buffer for this summary buffer")
6468 (gnus-configure-windows 'article)
6469 (select-window (get-buffer-window gnus-article-buffer))))
6470
eec82323
LMI
6471(defun gnus-summary-universal-argument (arg)
6472 "Perform any operation on all articles that are process/prefixed."
6473 (interactive "P")
eec82323
LMI
6474 (let ((articles (gnus-summary-work-articles arg))
6475 func article)
6476 (if (eq
6477 (setq
6478 func
6479 (key-binding
6480 (read-key-sequence
6481 (substitute-command-keys
16409b0b 6482 "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
eec82323
LMI
6483 'undefined)
6484 (gnus-error 1 "Undefined key")
6485 (save-excursion
6486 (while articles
6487 (gnus-summary-goto-subject (setq article (pop articles)))
6488 (let (gnus-newsgroup-processable)
6489 (command-execute func))
6490 (gnus-summary-remove-process-mark article)))))
6491 (gnus-summary-position-point))
6492
6493(defun gnus-summary-toggle-truncation (&optional arg)
6494 "Toggle truncation of summary lines.
23f87bed 6495With ARG, turn line truncation on if ARG is positive."
eec82323
LMI
6496 (interactive "P")
6497 (setq truncate-lines
6498 (if (null arg) (not truncate-lines)
6499 (> (prefix-numeric-value arg) 0)))
6500 (redraw-display))
6501
23f87bed
MB
6502(defun gnus-summary-find-for-reselect ()
6503 "Return the number of an article to stay on across a reselect.
6504The current article is considered, then following articles, then previous
6505articles. An article is sought which is not cancelled and isn't a temporary
6506insertion from another group. If there's no such then return a dummy 0."
6507 (let (found)
6508 (dolist (rev '(nil t))
6509 (unless found ; don't demand the reverse list if we don't need it
6510 (let ((data (gnus-data-find-list
6511 (gnus-summary-article-number) (gnus-data-list rev))))
6512 (while (and data (not found))
6513 (if (and (< 0 (gnus-data-number (car data)))
6514 (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6515 (setq found (gnus-data-number (car data))))
6516 (setq data (cdr data))))))
6517 (or found 0)))
6518
eec82323
LMI
6519(defun gnus-summary-reselect-current-group (&optional all rescan)
6520 "Exit and then reselect the current newsgroup.
6521The prefix argument ALL means to select all articles."
6522 (interactive "P")
eec82323
LMI
6523 (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6524 (error "Ephemeral groups can't be reselected"))
23f87bed 6525 (let ((current-subject (gnus-summary-find-for-reselect))
eec82323
LMI
6526 (group gnus-newsgroup-name))
6527 (setq gnus-newsgroup-begin nil)
23f87bed 6528 (gnus-summary-exit nil 'leave-hidden)
eec82323
LMI
6529 ;; We have to adjust the point of group mode buffer because
6530 ;; point was moved to the next unread newsgroup by exiting.
6531 (gnus-summary-jump-to-group group)
6532 (when rescan
6533 (save-excursion
6534 (gnus-group-get-new-news-this-group 1)))
6535 (gnus-group-read-group all t)
6536 (gnus-summary-goto-subject current-subject nil t)))
6537
6538(defun gnus-summary-rescan-group (&optional all)
6539 "Exit the newsgroup, ask for new articles, and select the newsgroup."
6540 (interactive "P")
6541 (gnus-summary-reselect-current-group all t))
6542
6543(defun gnus-summary-update-info (&optional non-destructive)
6544 (save-excursion
6545 (let ((group gnus-newsgroup-name))
6748645f
LMI
6546 (when group
6547 (when gnus-newsgroup-kill-headers
6548 (setq gnus-newsgroup-killed
6549 (gnus-compress-sequence
23f87bed
MB
6550 (gnus-sorted-union
6551 (gnus-list-range-intersection
6552 gnus-newsgroup-unselected gnus-newsgroup-killed)
6553 gnus-newsgroup-unreads)
6748645f
LMI
6554 t)))
6555 (unless (listp (cdr gnus-newsgroup-killed))
6556 (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6557 (let ((headers gnus-newsgroup-headers))
6558 ;; Set the new ranges of read articles.
6559 (save-excursion
6560 (set-buffer gnus-group-buffer)
6561 (gnus-undo-force-boundary))
6562 (gnus-update-read-articles
23f87bed
MB
6563 group (gnus-sorted-union
6564 gnus-newsgroup-unreads gnus-newsgroup-unselected))
6748645f
LMI
6565 ;; Set the current article marks.
6566 (let ((gnus-newsgroup-scored
6567 (if (and (not gnus-save-score)
6568 (not non-destructive))
6569 nil
6570 gnus-newsgroup-scored)))
6571 (save-excursion
6572 (gnus-update-marks)))
6573 ;; Do the cross-ref thing.
6574 (when gnus-use-cross-reference
6575 (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6576 ;; Do not switch windows but change the buffer to work.
a8151ef7 6577 (set-buffer gnus-group-buffer)
6748645f
LMI
6578 (unless (gnus-ephemeral-group-p group)
6579 (gnus-group-update-group group)))))))
eec82323
LMI
6580
6581(defun gnus-summary-save-newsrc (&optional force)
6582 "Save the current number of read/marked articles in the dribble buffer.
6583The dribble buffer will then be saved.
6584If FORCE (the prefix), also save the .newsrc file(s)."
6585 (interactive "P")
6586 (gnus-summary-update-info t)
6587 (if force
6588 (gnus-save-newsrc-file)
6589 (gnus-dribble-save)))
6590
23f87bed 6591(defun gnus-summary-exit (&optional temporary leave-hidden)
eec82323 6592 "Exit reading current newsgroup, and then return to group selection mode.
16409b0b 6593`gnus-exit-group-hook' is called with no arguments if that value is non-nil."
eec82323
LMI
6594 (interactive)
6595 (gnus-set-global-variables)
16409b0b
GM
6596 (when (gnus-buffer-live-p gnus-article-buffer)
6597 (save-excursion
6598 (set-buffer gnus-article-buffer)
6599 (mm-destroy-parts gnus-article-mime-handles)
6600 ;; Set it to nil for safety reason.
6601 (setq gnus-article-mime-handle-alist nil)
6602 (setq gnus-article-mime-handles nil)))
eec82323 6603 (gnus-kill-save-kill-buffer)
6748645f 6604 (gnus-async-halt-prefetch)
eec82323
LMI
6605 (let* ((group gnus-newsgroup-name)
6606 (quit-config (gnus-group-quit-config gnus-newsgroup-name))
23f87bed 6607 (gnus-group-is-exiting-p t)
eec82323 6608 (mode major-mode)
23f87bed 6609 (group-point nil)
eec82323 6610 (buf (current-buffer)))
16409b0b
GM
6611 (unless quit-config
6612 ;; Do adaptive scoring, and possibly save score files.
6613 (when gnus-newsgroup-adaptive
6614 (gnus-score-adaptive))
6615 (when gnus-use-scoring
6616 (gnus-score-save)))
6748645f 6617 (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
eec82323
LMI
6618 ;; If we have several article buffers, we kill them at exit.
6619 (unless gnus-single-article-buffer
6620 (gnus-kill-buffer gnus-original-article-buffer)
6621 (setq gnus-article-current nil))
6622 (when gnus-use-cache
6623 (gnus-cache-possibly-remove-articles)
6624 (gnus-cache-save-buffers))
6625 (gnus-async-prefetch-remove-group group)
6626 (when gnus-suppress-duplicates
6627 (gnus-dup-enter-articles))
6628 (when gnus-use-trees
6629 (gnus-tree-close group))
16409b0b
GM
6630 (when gnus-use-cache
6631 (gnus-cache-write-active))
6748645f
LMI
6632 ;; Remove entries for this group.
6633 (nnmail-purge-split-history (gnus-group-real-name group))
eec82323
LMI
6634 ;; Make all changes in this group permanent.
6635 (unless quit-config
6748645f 6636 (gnus-run-hooks 'gnus-exit-group-hook)
16409b0b 6637 (gnus-summary-update-info))
eec82323
LMI
6638 (gnus-close-group group)
6639 ;; Make sure where we were, and go to next newsgroup.
6640 (set-buffer gnus-group-buffer)
6641 (unless quit-config
6642 (gnus-group-jump-to-group group))
6748645f
LMI
6643 (gnus-run-hooks 'gnus-summary-exit-hook)
6644 (unless (or quit-config
6645 ;; If this group has disappeared from the summary
6646 ;; buffer, don't skip forwards.
6647 (not (string= group (gnus-group-group-name))))
eec82323 6648 (gnus-group-next-unread-group 1))
a8151ef7 6649 (setq group-point (point))
eec82323
LMI
6650 (if temporary
6651 nil ;Nothing to do.
6652 ;; If we have several article buffers, we kill them at exit.
6653 (unless gnus-single-article-buffer
6654 (gnus-kill-buffer gnus-article-buffer)
6655 (gnus-kill-buffer gnus-original-article-buffer)
6656 (setq gnus-article-current nil))
6657 (set-buffer buf)
6658 (if (not gnus-kill-summary-on-exit)
23f87bed
MB
6659 (progn
6660 (gnus-deaden-summary)
6661 (setq mode nil))
eec82323
LMI
6662 ;; We set all buffer-local variables to nil. It is unclear why
6663 ;; this is needed, but if we don't, buffer-local variables are
6664 ;; not garbage-collected, it seems. This would the lead to en
6665 ;; ever-growing Emacs.
6666 (gnus-summary-clear-local-variables)
23f87bed
MB
6667 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6668 (gnus-summary-clear-local-variables))
eec82323
LMI
6669 (when (get-buffer gnus-article-buffer)
6670 (bury-buffer gnus-article-buffer))
6671 ;; We clear the global counterparts of the buffer-local
6672 ;; variables as well, just to be on the safe side.
6673 (set-buffer gnus-group-buffer)
6674 (gnus-summary-clear-local-variables)
23f87bed
MB
6675 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6676 (gnus-summary-clear-local-variables))
eec82323
LMI
6677 ;; Return to group mode buffer.
6678 (when (eq mode 'gnus-summary-mode)
6679 (gnus-kill-buffer buf)))
6680 (setq gnus-current-select-method gnus-select-method)
d61c212b
SM
6681 (set-buffer gnus-group-buffer)
6682 (if quit-config
6683 (gnus-handle-ephemeral-exit quit-config)
4e90f2b9
SM
6684 (goto-char group-point)
6685 ;; If gnus-group-buffer is already displayed, make sure we also move
6686 ;; the cursor in the window that displays it.
6687 (let ((win (get-buffer-window (current-buffer) 0)))
6688 (if win (set-window-point win (point))))
d61c212b 6689 (unless leave-hidden
4e90f2b9 6690 (gnus-configure-windows 'group 'force)))
6748645f 6691 ;; Clear the current group name.
eec82323
LMI
6692 (unless quit-config
6693 (setq gnus-newsgroup-name nil)))))
6694
6695(defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6696(defun gnus-summary-exit-no-update (&optional no-questions)
6697 "Quit reading current newsgroup without updating read article info."
6698 (interactive)
eec82323 6699 (let* ((group gnus-newsgroup-name)
23f87bed
MB
6700 (gnus-group-is-exiting-p t)
6701 (gnus-group-is-exiting-without-update-p t)
eec82323
LMI
6702 (quit-config (gnus-group-quit-config group)))
6703 (when (or no-questions
6704 gnus-expert-user
6705 (gnus-y-or-n-p "Discard changes to this group and exit? "))
6748645f 6706 (gnus-async-halt-prefetch)
23f87bed 6707 (run-hooks 'gnus-summary-prepare-exit-hook)
16409b0b
GM
6708 (when (gnus-buffer-live-p gnus-article-buffer)
6709 (save-excursion
6710 (set-buffer gnus-article-buffer)
6711 (mm-destroy-parts gnus-article-mime-handles)
6712 ;; Set it to nil for safety reason.
6713 (setq gnus-article-mime-handle-alist nil)
6714 (setq gnus-article-mime-handles nil)))
eec82323
LMI
6715 ;; If we have several article buffers, we kill them at exit.
6716 (unless gnus-single-article-buffer
6717 (gnus-kill-buffer gnus-article-buffer)
6718 (gnus-kill-buffer gnus-original-article-buffer)
6719 (setq gnus-article-current nil))
6720 (if (not gnus-kill-summary-on-exit)
6721 (gnus-deaden-summary)
6722 (gnus-close-group group)
6723 (gnus-summary-clear-local-variables)
23f87bed
MB
6724 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6725 (gnus-summary-clear-local-variables))
eec82323
LMI
6726 (set-buffer gnus-group-buffer)
6727 (gnus-summary-clear-local-variables)
23f87bed
MB
6728 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6729 (gnus-summary-clear-local-variables))
6730 (gnus-kill-buffer gnus-summary-buffer))
eec82323
LMI
6731 (unless gnus-single-article-buffer
6732 (setq gnus-article-current nil))
6733 (when gnus-use-trees
6734 (gnus-tree-close group))
6735 (gnus-async-prefetch-remove-group group)
6736 (when (get-buffer gnus-article-buffer)
6737 (bury-buffer gnus-article-buffer))
6738 ;; Return to the group buffer.
6739 (gnus-configure-windows 'group 'force)
6740 ;; Clear the current group name.
6741 (setq gnus-newsgroup-name nil)
23f87bed
MB
6742 (unless (gnus-ephemeral-group-p group)
6743 (gnus-group-update-group group))
eec82323
LMI
6744 (when (equal (gnus-group-group-name) group)
6745 (gnus-group-next-unread-group 1))
6746 (when quit-config
23f87bed 6747 (gnus-handle-ephemeral-exit quit-config)))))
eec82323
LMI
6748
6749(defun gnus-handle-ephemeral-exit (quit-config)
6748645f
LMI
6750 "Handle movement when leaving an ephemeral group.
6751The state which existed when entering the ephemeral is reset."
eec82323
LMI
6752 (if (not (buffer-name (car quit-config)))
6753 (gnus-configure-windows 'group 'force)
6754 (set-buffer (car quit-config))
6755 (cond ((eq major-mode 'gnus-summary-mode)
23f87bed
MB
6756 (gnus-set-global-variables))
6757 ((eq major-mode 'gnus-article-mode)
6758 (save-excursion
6759 ;; The `gnus-summary-buffer' variable may point
6760 ;; to the old summary buffer when using a single
6761 ;; article buffer.
6762 (unless (gnus-buffer-live-p gnus-summary-buffer)
6763 (set-buffer gnus-group-buffer))
6764 (set-buffer gnus-summary-buffer)
6765 (gnus-set-global-variables))))
eec82323 6766 (if (or (eq (cdr quit-config) 'article)
23f87bed
MB
6767 (eq (cdr quit-config) 'pick))
6768 (progn
6769 ;; The current article may be from the ephemeral group
6770 ;; thus it is best that we reload this article
6771 ;;
6772 ;; If we're exiting from a large digest, this can be
6773 ;; extremely slow. So, it's better not to reload it. -- jh.
6774 ;;(gnus-summary-show-article)
6775 (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6776 (gnus-configure-windows 'pick 'force)
6777 (gnus-configure-windows (cdr quit-config) 'force)))
eec82323
LMI
6778 (gnus-configure-windows (cdr quit-config) 'force))
6779 (when (eq major-mode 'gnus-summary-mode)
6780 (gnus-summary-next-subject 1 nil t)
6781 (gnus-summary-recenter)
6782 (gnus-summary-position-point))))
6783
6784;;; Dead summaries.
6785
6786(defvar gnus-dead-summary-mode-map nil)
6787
6788(unless gnus-dead-summary-mode-map
6789 (setq gnus-dead-summary-mode-map (make-keymap))
6790 (suppress-keymap gnus-dead-summary-mode-map)
6791 (substitute-key-definition
6792 'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
23f87bed
MB
6793 (dolist (key '("\C-d" "\r" "\177" [delete]))
6794 (define-key gnus-dead-summary-mode-map
6795 key 'gnus-summary-wake-up-the-dead))
6796 (dolist (key '("q" "Q"))
6797 (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
eec82323
LMI
6798
6799(defvar gnus-dead-summary-mode nil
6800 "Minor mode for Gnus summary buffers.")
6801
6802(defun gnus-dead-summary-mode (&optional arg)
6803 "Minor mode for Gnus summary buffers."
6804 (interactive "P")
6805 (when (eq major-mode 'gnus-summary-mode)
6806 (make-local-variable 'gnus-dead-summary-mode)
6807 (setq gnus-dead-summary-mode
6808 (if (null arg) (not gnus-dead-summary-mode)
6809 (> (prefix-numeric-value arg) 0)))
6810 (when gnus-dead-summary-mode
a8151ef7
LMI
6811 (gnus-add-minor-mode
6812 'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
eec82323
LMI
6813
6814(defun gnus-deaden-summary ()
6815 "Make the current summary buffer into a dead summary buffer."
6816 ;; Kill any previous dead summary buffer.
6817 (when (and gnus-dead-summary
6818 (buffer-name gnus-dead-summary))
6819 (save-excursion
6820 (set-buffer gnus-dead-summary)
6821 (when gnus-dead-summary-mode
6822 (kill-buffer (current-buffer)))))
6823 ;; Make this the current dead summary.
6824 (setq gnus-dead-summary (current-buffer))
6825 (gnus-dead-summary-mode 1)
6826 (let ((name (buffer-name)))
6827 (when (string-match "Summary" name)
6828 (rename-buffer
6829 (concat (substring name 0 (match-beginning 0)) "Dead "
6830 (substring name (match-beginning 0)))
16409b0b
GM
6831 t)
6832 (bury-buffer))))
eec82323
LMI
6833
6834(defun gnus-kill-or-deaden-summary (buffer)
6835 "Kill or deaden the summary BUFFER."
6748645f
LMI
6836 (save-excursion
6837 (when (and (buffer-name buffer)
6838 (not gnus-single-article-buffer))
6839 (save-excursion
6840 (set-buffer buffer)
6841 (gnus-kill-buffer gnus-article-buffer)
6842 (gnus-kill-buffer gnus-original-article-buffer)))
23f87bed
MB
6843 (cond
6844 ;; Kill the buffer.
6845 (gnus-kill-summary-on-exit
6846 (when (and gnus-use-trees
6847 (gnus-buffer-exists-p buffer))
6848 (save-excursion
6849 (set-buffer buffer)
6850 (gnus-tree-close gnus-newsgroup-name)))
6851 (gnus-kill-buffer buffer))
6852 ;; Deaden the buffer.
6853 ((gnus-buffer-exists-p buffer)
6854 (save-excursion
6855 (set-buffer buffer)
6856 (gnus-deaden-summary))))))
eec82323
LMI
6857
6858(defun gnus-summary-wake-up-the-dead (&rest args)
6859 "Wake up the dead summary buffer."
6860 (interactive)
6861 (gnus-dead-summary-mode -1)
6862 (let ((name (buffer-name)))
6863 (when (string-match "Dead " name)
6864 (rename-buffer
6865 (concat (substring name 0 (match-beginning 0))
6866 (substring name (match-end 0)))
6867 t)))
6868 (gnus-message 3 "This dead summary is now alive again"))
6869
6870;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6871(defun gnus-summary-fetch-faq (&optional faq-dir)
6872 "Fetch the FAQ for the current group.
6873If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6874in."
6875 (interactive
6876 (list
6877 (when current-prefix-arg
6878 (completing-read
8f688cb0 6879 "FAQ dir: " (and (listp gnus-group-faq-directory)
a8151ef7
LMI
6880 (mapcar (lambda (file) (list file))
6881 gnus-group-faq-directory))))))
eec82323
LMI
6882 (let (gnus-faq-buffer)
6883 (when (setq gnus-faq-buffer
6884 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6885 (gnus-configure-windows 'summary-faq))))
6886
6887;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6888(defun gnus-summary-describe-group (&optional force)
6889 "Describe the current newsgroup."
6890 (interactive "P")
6891 (gnus-group-describe-group force gnus-newsgroup-name))
6892
6893(defun gnus-summary-describe-briefly ()
6894 "Describe summary mode commands briefly."
6895 (interactive)
16409b0b 6896 (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
6897
6898;; Walking around group mode buffer from summary mode.
6899
6900(defun gnus-summary-next-group (&optional no-article target-group backward)
6901 "Exit current newsgroup and then select next unread newsgroup.
6902If prefix argument NO-ARTICLE is non-nil, no article is selected
23f87bed 6903initially. If TARGET-GROUP, go to this group. If BACKWARD, go to
eec82323
LMI
6904previous group instead."
6905 (interactive "P")
eec82323
LMI
6906 ;; Stop pre-fetching.
6907 (gnus-async-halt-prefetch)
6908 (let ((current-group gnus-newsgroup-name)
6909 (current-buffer (current-buffer))
6910 entered)
6911 ;; First we semi-exit this group to update Xrefs and all variables.
6912 ;; We can't do a real exit, because the window conf must remain
6913 ;; the same in case the user is prompted for info, and we don't
6914 ;; want the window conf to change before that...
6915 (gnus-summary-exit t)
6916 (while (not entered)
6917 ;; Then we find what group we are supposed to enter.
6918 (set-buffer gnus-group-buffer)
6919 (gnus-group-jump-to-group current-group)
6920 (setq target-group
6921 (or target-group
6922 (if (eq gnus-keep-same-level 'best)
6923 (gnus-summary-best-group gnus-newsgroup-name)
6924 (gnus-summary-search-group backward gnus-keep-same-level))))
6925 (if (not target-group)
6926 ;; There are no further groups, so we return to the group
6927 ;; buffer.
6928 (progn
6929 (gnus-message 5 "Returning to the group buffer")
6930 (setq entered t)
6931 (when (gnus-buffer-live-p current-buffer)
6932 (set-buffer current-buffer)
6933 (gnus-summary-exit))
6748645f 6934 (gnus-run-hooks 'gnus-group-no-more-groups-hook))
eec82323
LMI
6935 ;; We try to enter the target group.
6936 (gnus-group-jump-to-group target-group)
6937 (let ((unreads (gnus-group-group-unread)))
6938 (if (and (or (eq t unreads)
6939 (and unreads (not (zerop unreads))))
23f87bed
MB
6940 (gnus-summary-read-group
6941 target-group nil no-article
6942 (and (buffer-name current-buffer) current-buffer)
6943 nil backward))
eec82323
LMI
6944 (setq entered t)
6945 (setq current-group target-group
6946 target-group nil)))))))
6947
6948(defun gnus-summary-prev-group (&optional no-article)
6949 "Exit current newsgroup and then select previous unread newsgroup.
6950If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6951 (interactive "P")
6952 (gnus-summary-next-group no-article nil t))
6953
6954;; Walking around summary lines.
6955
23f87bed
MB
6956(defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6957 "Go to the first subject satisfying any non-nil constraint.
6958If UNREAD is non-nil, the article should be unread.
6959If UNDOWNLOADED is non-nil, the article should be undownloaded.
6960If UNSEEN is non-nil, the article should be unseen.
6961Returns the article selected or nil if there are no matching articles."
eec82323 6962 (interactive "P")
23f87bed
MB
6963 (cond
6964 ;; Empty summary.
6965 ((null gnus-newsgroup-data)
6966 (gnus-message 3 "No articles in the group")
6967 nil)
6968 ;; Pick the first article.
6969 ((not (or unread undownloaded unseen))
6970 (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6971 (gnus-data-number (car gnus-newsgroup-data)))
6972 ;; Find the first unread article.
6973 (t
6974 (let ((data gnus-newsgroup-data))
6975 (while (and data
6976 (let ((num (gnus-data-number (car data))))
6977 (or (memq num gnus-newsgroup-unfetched)
6978 (not (or (and unread
6979 (memq num gnus-newsgroup-unreads))
6980 (and undownloaded
6981 (memq num gnus-newsgroup-undownloaded))
6982 (and unseen
6983 (memq num gnus-newsgroup-unseen)))))))
6984 (setq data (cdr data)))
6985 (prog1
6986 (if data
6987 (progn
6988 (goto-char (gnus-data-pos (car data)))
6989 (gnus-data-number (car data)))
6990 (gnus-message 3 "No more%s articles"
6991 (let* ((r (when unread " unread"))
6992 (d (when undownloaded " undownloaded"))
6993 (s (when unseen " unseen"))
6994 (l (delq nil (list r d s))))
6995 (cond ((= 3 (length l))
6996 (concat r "," d ", or" s))
6997 ((= 2 (length l))
6998 (concat (car l) ", or" (cadr l)))
6999 ((= 1 (length l))
7000 (car l))
7001 (t
7002 ""))))
7003 nil
7004 )
7005 (gnus-summary-position-point))))))
eec82323
LMI
7006
7007(defun gnus-summary-next-subject (n &optional unread dont-display)
7008 "Go to next N'th summary line.
7009If N is negative, go to the previous N'th subject line.
7010If UNREAD is non-nil, only unread articles are selected.
7011The difference between N and the actual number of steps taken is
7012returned."
7013 (interactive "p")
7014 (let ((backward (< n 0))
7015 (n (abs n)))
7016 (while (and (> n 0)
7017 (if backward
7018 (gnus-summary-find-prev unread)
7019 (gnus-summary-find-next unread)))
16409b0b
GM
7020 (unless (zerop (setq n (1- n)))
7021 (gnus-summary-show-thread)))
eec82323
LMI
7022 (when (/= 0 n)
7023 (gnus-message 7 "No more%s articles"
7024 (if unread " unread" "")))
7025 (unless dont-display
7026 (gnus-summary-recenter)
7027 (gnus-summary-position-point))
7028 n))
7029
7030(defun gnus-summary-next-unread-subject (n)
7031 "Go to next N'th unread summary line."
7032 (interactive "p")
7033 (gnus-summary-next-subject n t))
7034
7035(defun gnus-summary-prev-subject (n &optional unread)
7036 "Go to previous N'th summary line.
7037If optional argument UNREAD is non-nil, only unread article is selected."
7038 (interactive "p")
7039 (gnus-summary-next-subject (- n) unread))
7040
7041(defun gnus-summary-prev-unread-subject (n)
7042 "Go to previous N'th unread summary line."
7043 (interactive "p")
7044 (gnus-summary-next-subject (- n) t))
7045
23f87bed
MB
7046(defun gnus-summary-goto-subjects (articles)
7047 "Insert the subject header for ARTICLES in the current buffer."
7048 (save-excursion
7049 (dolist (article articles)
7050 (gnus-summary-goto-subject article t)))
7051 (gnus-summary-limit (append articles gnus-newsgroup-limit))
7052 (gnus-summary-position-point))
132cf96d 7053
eec82323
LMI
7054(defun gnus-summary-goto-subject (article &optional force silent)
7055 "Go the subject line of ARTICLE.
7056If FORCE, also allow jumping to articles not currently shown."
7057 (interactive "nArticle number: ")
23f87bed
MB
7058 (unless (numberp article)
7059 (error "Article %s is not a number" article))
eec82323
LMI
7060 (let ((b (point))
7061 (data (gnus-data-find article)))
7062 ;; We read in the article if we have to.
7063 (and (not data)
7064 force
6748645f
LMI
7065 (gnus-summary-insert-subject
7066 article
7067 (if (or (numberp force) (vectorp force)) force)
7068 t)
eec82323
LMI
7069 (setq data (gnus-data-find article)))
7070 (goto-char b)
7071 (if (not data)
7072 (progn
7073 (unless silent
7074 (gnus-message 3 "Can't find article %d" article))
7075 nil)
23f87bed
MB
7076 (let ((pt (gnus-data-pos data)))
7077 (goto-char pt)
7078 (gnus-summary-set-article-display-arrow pt))
6748645f 7079 (gnus-summary-position-point)
eec82323
LMI
7080 article)))
7081
7082;; Walking around summary lines with displaying articles.
7083
7084(defun gnus-summary-expand-window (&optional arg)
7085 "Make the summary buffer take up the entire Emacs frame.
7086Given a prefix, will force an `article' buffer configuration."
7087 (interactive "P")
eec82323
LMI
7088 (if arg
7089 (gnus-configure-windows 'article 'force)
7090 (gnus-configure-windows 'summary 'force)))
7091
7092(defun gnus-summary-display-article (article &optional all-header)
7093 "Display ARTICLE in article buffer."
d4dfaa19
DL
7094 (when (gnus-buffer-live-p gnus-article-buffer)
7095 (with-current-buffer gnus-article-buffer
87545352 7096 (mm-enable-multibyte)))
eec82323 7097 (gnus-set-global-variables)
23f87bed
MB
7098 (when (gnus-buffer-live-p gnus-article-buffer)
7099 (with-current-buffer gnus-article-buffer
7100 (setq gnus-article-charset gnus-newsgroup-charset)
7101 (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7102 (mm-enable-multibyte)))
eec82323
LMI
7103 (if (null article)
7104 nil
7105 (prog1
7106 (if gnus-summary-display-article-function
7107 (funcall gnus-summary-display-article-function article all-header)
7108 (gnus-article-prepare article all-header))
6748645f 7109 (gnus-run-hooks 'gnus-select-article-hook)
eec82323
LMI
7110 (when (and gnus-current-article
7111 (not (zerop gnus-current-article)))
7112 (gnus-summary-goto-subject gnus-current-article))
7113 (gnus-summary-recenter)
7114 (when (and gnus-use-trees gnus-show-threads)
7115 (gnus-possibly-generate-tree article)
7116 (gnus-highlight-selected-tree article))
7117 ;; Successfully display article.
7118 (gnus-article-set-window-start
7119 (cdr (assq article gnus-newsgroup-bookmarks))))))
7120
7121(defun gnus-summary-select-article (&optional all-headers force pseudo article)
7122 "Select the current article.
7123If ALL-HEADERS is non-nil, show all header fields. If FORCE is
7124non-nil, the article will be re-fetched even if it already present in
7125the article buffer. If PSEUDO is non-nil, pseudo-articles will also
7126be displayed."
7127 ;; Make sure we are in the summary buffer to work around bbdb bug.
7128 (unless (eq major-mode 'gnus-summary-mode)
7129 (set-buffer gnus-summary-buffer))
7130 (let ((article (or article (gnus-summary-article-number)))
f0529b5b 7131 (all-headers (not (not all-headers))) ;Must be t or nil.
16409b0b 7132 gnus-summary-display-article-function)
eec82323
LMI
7133 (and (not pseudo)
7134 (gnus-summary-article-pseudo-p article)
a8151ef7 7135 (error "This is a pseudo-article"))
16409b0b
GM
7136 (save-excursion
7137 (set-buffer gnus-summary-buffer)
7138 (if (or (and gnus-single-article-buffer
7139 (or (null gnus-current-article)
7140 (null gnus-article-current)
7141 (null (get-buffer gnus-article-buffer))
7142 (not (eq article (cdr gnus-article-current)))
7143 (not (equal (car gnus-article-current)
7144 gnus-newsgroup-name))))
7145 (and (not gnus-single-article-buffer)
7146 (or (null gnus-current-article)
7147 (not (eq gnus-current-article article))))
7148 force)
7149 ;; The requested article is different from the current article.
7150 (progn
16409b0b
GM
7151 (gnus-summary-display-article article all-headers)
7152 (when (gnus-buffer-live-p gnus-article-buffer)
23f87bed 7153 (with-current-buffer gnus-article-buffer
16409b0b 7154 (if (not gnus-article-decoded-p) ;; a local variable
87545352 7155 (mm-disable-multibyte))))
16409b0b
GM
7156 (gnus-article-set-window-start
7157 (cdr (assq article gnus-newsgroup-bookmarks)))
7158 article)
16409b0b 7159 'old))))
eec82323 7160
23f87bed
MB
7161(defun gnus-summary-force-verify-and-decrypt ()
7162 "Display buttons for signed/encrypted parts and verify/decrypt them."
7163 (interactive)
7164 (let ((mm-verify-option 'known)
7165 (mm-decrypt-option 'known)
7166 (gnus-article-emulate-mime t)
7167 (gnus-buttonized-mime-types (append (list "multipart/signed"
7168 "multipart/encrypted")
7169 gnus-buttonized-mime-types)))
7170 (gnus-summary-select-article nil 'force)))
7171
eec82323
LMI
7172(defun gnus-summary-set-current-mark (&optional current-mark)
7173 "Obsolete function."
7174 nil)
7175
7176(defun gnus-summary-next-article (&optional unread subject backward push)
7177 "Select the next article.
7178If UNREAD, only unread articles are selected.
7179If SUBJECT, only articles with SUBJECT are selected.
7180If BACKWARD, the previous article is selected instead of the next."
7181 (interactive "P")
eec82323
LMI
7182 (cond
7183 ;; Is there such an article?
7184 ((and (gnus-summary-search-forward unread subject backward)
7185 (or (gnus-summary-display-article (gnus-summary-article-number))
7186 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7187 (gnus-summary-position-point))
7188 ;; If not, we try the first unread, if that is wanted.
7189 ((and subject
7190 gnus-auto-select-same
7191 (gnus-summary-first-unread-article))
7192 (gnus-summary-position-point)
7193 (gnus-message 6 "Wrapped"))
7194 ;; Try to get next/previous article not displayed in this group.
7195 ((and gnus-auto-extend-newsgroup
7196 (not unread) (not subject))
7197 (gnus-summary-goto-article
7198 (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6748645f 7199 nil (count-lines (point-min) (point))))
eec82323
LMI
7200 ;; Go to next/previous group.
7201 (t
7202 (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7203 (gnus-summary-jump-to-group gnus-newsgroup-name))
7204 (let ((cmd last-command-char)
7205 (point
7206 (save-excursion
7207 (set-buffer gnus-group-buffer)
7208 (point)))
7209 (group
7210 (if (eq gnus-keep-same-level 'best)
7211 (gnus-summary-best-group gnus-newsgroup-name)
7212 (gnus-summary-search-group backward gnus-keep-same-level))))
7213 ;; For some reason, the group window gets selected. We change
7214 ;; it back.
7215 (select-window (get-buffer-window (current-buffer)))
7216 ;; Select next unread newsgroup automagically.
7217 (cond
7218 ((or (not gnus-auto-select-next)
7219 (not cmd))
7220 (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7221 ((or (eq gnus-auto-select-next 'quietly)
7222 (and (eq gnus-auto-select-next 'slightly-quietly)
7223 push)
7224 (and (eq gnus-auto-select-next 'almost-quietly)
7225 (gnus-summary-last-article-p)))
7226 ;; Select quietly.
7227 (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7228 (gnus-summary-exit)
7229 (gnus-message 7 "No more%s articles (%s)..."
7230 (if unread " unread" "")
7231 (if group (concat "selecting " group)
7232 "exiting"))
7233 (gnus-summary-next-group nil group backward)))
7234 (t
7235 (when (gnus-key-press-event-p last-input-event)
7236 (gnus-summary-walk-group-buffer
7237 gnus-newsgroup-name cmd unread backward point))))))))
7238
7239(defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7240 (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7241 (?\C-p (gnus-group-prev-unread-group 1))))
7242 (cursor-in-echo-area t)
23f87bed 7243 keve key group ended prompt)
eec82323
LMI
7244 (save-excursion
7245 (set-buffer gnus-group-buffer)
7246 (goto-char start)
7247 (setq group
7248 (if (eq gnus-keep-same-level 'best)
7249 (gnus-summary-best-group gnus-newsgroup-name)
7250 (gnus-summary-search-group backward gnus-keep-same-level))))
7251 (while (not ended)
23f87bed
MB
7252 (setq prompt
7253 (format
7254 "No more%s articles%s " (if unread " unread" "")
7255 (if (and group
7256 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7257 (format " (Type %s for %s [%s])"
91472578
MB
7258 (single-key-description cmd)
7259 (gnus-group-decoded-name group)
23f87bed
MB
7260 (car (gnus-gethash group gnus-newsrc-hashtb)))
7261 (format " (Type %s to exit %s)"
7262 (single-key-description cmd)
91472578 7263 (gnus-group-decoded-name gnus-newsgroup-name)))))
eec82323 7264 ;; Confirm auto selection.
23f87bed
MB
7265 (setq key (car (setq keve (gnus-read-event-char prompt)))
7266 ended t)
eec82323
LMI
7267 (cond
7268 ((assq key keystrokes)
7269 (let ((obuf (current-buffer)))
7270 (switch-to-buffer gnus-group-buffer)
7271 (when group
7272 (gnus-group-jump-to-group group))
7273 (eval (cadr (assq key keystrokes)))
7274 (setq group (gnus-group-group-name))
7275 (switch-to-buffer obuf))
7276 (setq ended nil))
7277 ((equal key cmd)
7278 (if (or (not group)
7279 (gnus-ephemeral-group-p gnus-newsgroup-name))
7280 (gnus-summary-exit)
7281 (gnus-summary-next-group nil group backward)))
7282 (t
7283 (push (cdr keve) unread-command-events))))))
7284
7285(defun gnus-summary-next-unread-article ()
7286 "Select unread article after current one."
7287 (interactive)
7288 (gnus-summary-next-article
7289 (or (not (eq gnus-summary-goto-unread 'never))
7290 (gnus-summary-last-article-p (gnus-summary-article-number)))
7291 (and gnus-auto-select-same
7292 (gnus-summary-article-subject))))
7293
7294(defun gnus-summary-prev-article (&optional unread subject)
7295 "Select the article after the current one.
7296If UNREAD is non-nil, only unread articles are selected."
7297 (interactive "P")
7298 (gnus-summary-next-article unread subject t))
7299
7300(defun gnus-summary-prev-unread-article ()
7301 "Select unread article before current one."
7302 (interactive)
7303 (gnus-summary-prev-article
7304 (or (not (eq gnus-summary-goto-unread 'never))
7305 (gnus-summary-first-article-p (gnus-summary-article-number)))
7306 (and gnus-auto-select-same
7307 (gnus-summary-article-subject))))
7308
23f87bed 7309(defun gnus-summary-next-page (&optional lines circular stop)
eec82323
LMI
7310 "Show next page of the selected article.
7311If at the end of the current article, select the next article.
7312LINES says how many lines should be scrolled up.
7313
7314If CIRCULAR is non-nil, go to the start of the article instead of
7315selecting the next article when reaching the end of the current
23f87bed
MB
7316article.
7317
7318If STOP is non-nil, just stop when reaching the end of the message.
7319
7320Also see the variable `gnus-article-skip-boring'."
eec82323
LMI
7321 (interactive "P")
7322 (setq gnus-summary-buffer (current-buffer))
7323 (gnus-set-global-variables)
7324 (let ((article (gnus-summary-article-number))
7325 (article-window (get-buffer-window gnus-article-buffer t))
7326 endp)
6748645f
LMI
7327 ;; If the buffer is empty, we have no article.
7328 (unless article
7329 (error "No article to select"))
eec82323
LMI
7330 (gnus-configure-windows 'article)
7331 (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7332 (if (and (eq gnus-summary-goto-unread 'never)
7333 (not (gnus-summary-last-article-p article)))
7334 (gnus-summary-next-article)
7335 (gnus-summary-next-unread-article))
7336 (if (or (null gnus-current-article)
7337 (null gnus-article-current)
7338 (/= article (cdr gnus-article-current))
7339 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7340 ;; Selected subject is different from current article's.
7341 (gnus-summary-display-article article)
7342 (when article-window
7343 (gnus-eval-in-buffer-window gnus-article-buffer
23f87bed
MB
7344 (setq endp (or (gnus-article-next-page lines)
7345 (gnus-article-only-boring-p))))
eec82323 7346 (when endp
23f87bed
MB
7347 (cond (stop
7348 (gnus-message 3 "End of message"))
7349 (circular
eec82323
LMI
7350 (gnus-summary-beginning-of-article))
7351 (lines
7352 (gnus-message 3 "End of message"))
7353 ((null lines)
7354 (if (and (eq gnus-summary-goto-unread 'never)
7355 (not (gnus-summary-last-article-p article)))
7356 (gnus-summary-next-article)
7357 (gnus-summary-next-unread-article))))))))
7358 (gnus-summary-recenter)
7359 (gnus-summary-position-point)))
7360
7361(defun gnus-summary-prev-page (&optional lines move)
7362 "Show previous page of selected article.
7363Argument LINES specifies lines to be scrolled down.
7364If MOVE, move to the previous unread article if point is at
7365the beginning of the buffer."
7366 (interactive "P")
eec82323
LMI
7367 (let ((article (gnus-summary-article-number))
7368 (article-window (get-buffer-window gnus-article-buffer t))
7369 endp)
7370 (gnus-configure-windows 'article)
7371 (if (or (null gnus-current-article)
7372 (null gnus-article-current)
7373 (/= article (cdr gnus-article-current))
7374 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7375 ;; Selected subject is different from current article's.
7376 (gnus-summary-display-article article)
7377 (gnus-summary-recenter)
7378 (when article-window
7379 (gnus-eval-in-buffer-window gnus-article-buffer
7380 (setq endp (gnus-article-prev-page lines)))
7381 (when (and move endp)
7382 (cond (lines
7383 (gnus-message 3 "Beginning of message"))
7384 ((null lines)
7385 (if (and (eq gnus-summary-goto-unread 'never)
7386 (not (gnus-summary-first-article-p article)))
7387 (gnus-summary-prev-article)
7388 (gnus-summary-prev-unread-article))))))))
7389 (gnus-summary-position-point))
7390
7391(defun gnus-summary-prev-page-or-article (&optional lines)
7392 "Show previous page of selected article.
7393Argument LINES specifies lines to be scrolled down.
7394If at the beginning of the article, go to the next article."
7395 (interactive "P")
7396 (gnus-summary-prev-page lines t))
7397
7398(defun gnus-summary-scroll-up (lines)
7399 "Scroll up (or down) one line current article.
7400Argument LINES specifies lines to be scrolled up (or down if negative)."
7401 (interactive "p")
eec82323
LMI
7402 (gnus-configure-windows 'article)
7403 (gnus-summary-show-thread)
7404 (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7405 (gnus-eval-in-buffer-window gnus-article-buffer
7406 (cond ((> lines 0)
7407 (when (gnus-article-next-page lines)
7408 (gnus-message 3 "End of message")))
7409 ((< lines 0)
7410 (gnus-article-prev-page (- lines))))))
7411 (gnus-summary-recenter)
7412 (gnus-summary-position-point))
7413
6748645f
LMI
7414(defun gnus-summary-scroll-down (lines)
7415 "Scroll down (or up) one line current article.
7416Argument LINES specifies lines to be scrolled down (or up if negative)."
7417 (interactive "p")
7418 (gnus-summary-scroll-up (- lines)))
7419
eec82323
LMI
7420(defun gnus-summary-next-same-subject ()
7421 "Select next article which has the same subject as current one."
7422 (interactive)
eec82323
LMI
7423 (gnus-summary-next-article nil (gnus-summary-article-subject)))
7424
7425(defun gnus-summary-prev-same-subject ()
7426 "Select previous article which has the same subject as current one."
7427 (interactive)
eec82323
LMI
7428 (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7429
7430(defun gnus-summary-next-unread-same-subject ()
7431 "Select next unread article which has the same subject as current one."
7432 (interactive)
eec82323
LMI
7433 (gnus-summary-next-article t (gnus-summary-article-subject)))
7434
7435(defun gnus-summary-prev-unread-same-subject ()
7436 "Select previous unread article which has the same subject as current one."
7437 (interactive)
eec82323
LMI
7438 (gnus-summary-prev-article t (gnus-summary-article-subject)))
7439
7440(defun gnus-summary-first-unread-article ()
7441 "Select the first unread article.
7442Return nil if there are no unread articles."
7443 (interactive)
eec82323
LMI
7444 (prog1
7445 (when (gnus-summary-first-subject t)
7446 (gnus-summary-show-thread)
7447 (gnus-summary-first-subject t)
7448 (gnus-summary-display-article (gnus-summary-article-number)))
7449 (gnus-summary-position-point)))
7450
16409b0b
GM
7451(defun gnus-summary-first-unread-subject ()
7452 "Place the point on the subject line of the first unread article.
7453Return nil if there are no unread articles."
7454 (interactive)
7455 (prog1
7456 (when (gnus-summary-first-subject t)
7457 (gnus-summary-show-thread)
7458 (gnus-summary-first-subject t))
7459 (gnus-summary-position-point)))
7460
23f87bed
MB
7461(defun gnus-summary-first-unseen-subject ()
7462 "Place the point on the subject line of the first unseen article.
7463Return nil if there are no unseen articles."
7464 (interactive)
7465 (prog1
7466 (when (gnus-summary-first-subject nil nil t)
7467 (gnus-summary-show-thread)
7468 (gnus-summary-first-subject nil nil t))
7469 (gnus-summary-position-point)))
7470
7471(defun gnus-summary-first-unseen-or-unread-subject ()
7472 "Place the point on the subject line of the first unseen article or,
7473if all article have been seen, on the subject line of the first unread
7474article."
7475 (interactive)
7476 (prog1
7477 (unless (when (gnus-summary-first-subject nil nil t)
7478 (gnus-summary-show-thread)
7479 (gnus-summary-first-subject nil nil t))
7480 (when (gnus-summary-first-subject t)
7481 (gnus-summary-show-thread)
7482 (gnus-summary-first-subject t)))
7483 (gnus-summary-position-point)))
7484
eec82323
LMI
7485(defun gnus-summary-first-article ()
7486 "Select the first article.
7487Return nil if there are no articles."
7488 (interactive)
eec82323
LMI
7489 (prog1
7490 (when (gnus-summary-first-subject)
16409b0b
GM
7491 (gnus-summary-show-thread)
7492 (gnus-summary-first-subject)
7493 (gnus-summary-display-article (gnus-summary-article-number)))
eec82323
LMI
7494 (gnus-summary-position-point)))
7495
23f87bed
MB
7496(defun gnus-summary-best-unread-article (&optional arg)
7497 "Select the unread article with the highest score.
7498If given a prefix argument, select the next unread article that has a
7499score higher than the default score."
7500 (interactive "P")
7501 (let ((article (if arg
7502 (gnus-summary-better-unread-subject)
7503 (gnus-summary-best-unread-subject))))
7504 (if article
7505 (gnus-summary-goto-article article)
7506 (error "No unread articles"))))
7507
7508(defun gnus-summary-best-unread-subject ()
7509 "Select the unread subject with the highest score."
eec82323 7510 (interactive)
eec82323
LMI
7511 (let ((best -1000000)
7512 (data gnus-newsgroup-data)
7513 article score)
7514 (while data
7515 (and (gnus-data-unread-p (car data))
7516 (> (setq score
7517 (gnus-summary-article-score (gnus-data-number (car data))))
7518 best)
7519 (setq best score
7520 article (gnus-data-number (car data))))
7521 (setq data (cdr data)))
23f87bed
MB
7522 (when article
7523 (gnus-summary-goto-subject article))
7524 (gnus-summary-position-point)
7525 article))
7526
7527(defun gnus-summary-better-unread-subject ()
7528 "Select the first unread subject that has a score over the default score."
7529 (interactive)
7530 (let ((data gnus-newsgroup-data)
7531 article score)
7532 (while (and (setq article (gnus-data-number (car data)))
7533 (or (gnus-data-read-p (car data))
7534 (not (> (gnus-summary-article-score article)
7535 gnus-summary-default-score))))
7536 (setq data (cdr data)))
7537 (when article
7538 (gnus-summary-goto-subject article))
7539 (gnus-summary-position-point)
7540 article))
eec82323
LMI
7541
7542(defun gnus-summary-last-subject ()
7543 "Go to the last displayed subject line in the group."
7544 (let ((article (gnus-data-number (car (gnus-data-list t)))))
7545 (when article
7546 (gnus-summary-goto-subject article))))
7547
7548(defun gnus-summary-goto-article (article &optional all-headers force)
6748645f
LMI
7549 "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7550If ALL-HEADERS is non-nil, no header lines are hidden.
7551If FORCE, go to the article even if it isn't displayed. If FORCE
7552is a number, it is the line the article is to be displayed on."
eec82323
LMI
7553 (interactive
7554 (list
6748645f
LMI
7555 (completing-read
7556 "Article number or Message-ID: "
7557 (mapcar (lambda (number) (list (int-to-string number)))
7558 gnus-newsgroup-limit))
eec82323
LMI
7559 current-prefix-arg
7560 t))
7561 (prog1
6748645f 7562 (if (and (stringp article)
23f87bed 7563 (string-match "@\\|%40" article))
6748645f
LMI
7564 (gnus-summary-refer-article article)
7565 (when (stringp article)
7566 (setq article (string-to-number article)))
7567 (if (gnus-summary-goto-subject article force)
7568 (gnus-summary-display-article article all-headers)
7569 (gnus-message 4 "Couldn't go to article %s" article) nil))
eec82323
LMI
7570 (gnus-summary-position-point)))
7571
7572(defun gnus-summary-goto-last-article ()
7573 "Go to the previously read article."
7574 (interactive)
7575 (prog1
7576 (when gnus-last-article
6748645f 7577 (gnus-summary-goto-article gnus-last-article nil t))
eec82323
LMI
7578 (gnus-summary-position-point)))
7579
7580(defun gnus-summary-pop-article (number)
7581 "Pop one article off the history and go to the previous.
7582NUMBER articles will be popped off."
7583 (interactive "p")
7584 (let (to)
7585 (setq gnus-newsgroup-history
7586 (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7587 (if to
6748645f 7588 (gnus-summary-goto-article (car to) nil t)
eec82323
LMI
7589 (error "Article history empty")))
7590 (gnus-summary-position-point))
7591
7592;; Summary commands and functions for limiting the summary buffer.
7593
7594(defun gnus-summary-limit-to-articles (n)
7595 "Limit the summary buffer to the next N articles.
7596If not given a prefix, use the process marked articles instead."
7597 (interactive "P")
eec82323
LMI
7598 (prog1
7599 (let ((articles (gnus-summary-work-articles n)))
7600 (setq gnus-newsgroup-processable nil)
7601 (gnus-summary-limit articles))
7602 (gnus-summary-position-point)))
7603
7604(defun gnus-summary-pop-limit (&optional total)
7605 "Restore the previous limit.
7606If given a prefix, remove all limits."
7607 (interactive "P")
eec82323
LMI
7608 (when total
7609 (setq gnus-newsgroup-limits
7610 (list (mapcar (lambda (h) (mail-header-number h))
7611 gnus-newsgroup-headers))))
7612 (unless gnus-newsgroup-limits
7613 (error "No limit to pop"))
7614 (prog1
7615 (gnus-summary-limit nil 'pop)
7616 (gnus-summary-position-point)))
7617
47b63dfa
SZ
7618(defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7619 "Limit the summary buffer to articles that have subjects that match a regexp.
7620If NOT-MATCHING, excluding articles that have subjects that match a regexp."
a1506d29 7621 (interactive
47b63dfa
SZ
7622 (list (read-string (if current-prefix-arg
7623 "Exclude subject (regexp): "
a1506d29 7624 "Limit to subject (regexp): "))
47b63dfa 7625 nil current-prefix-arg))
eec82323
LMI
7626 (unless header
7627 (setq header "subject"))
7628 (when (not (equal "" subject))
7629 (prog1
7630 (let ((articles (gnus-summary-find-matching
a1506d29 7631 (or header "subject") subject 'all nil nil
47b63dfa 7632 not-matching)))
eec82323
LMI
7633 (unless articles
7634 (error "Found no matches for \"%s\"" subject))
7635 (gnus-summary-limit articles))
7636 (gnus-summary-position-point))))
7637
ef6e0ec7 7638(defun gnus-summary-limit-to-author (from &optional not-matching)
47b63dfa
SZ
7639 "Limit the summary buffer to articles that have authors that match a regexp.
7640If NOT-MATCHING, excluding articles that have authors that match a regexp."
a1506d29 7641 (interactive
47b63dfa
SZ
7642 (list (read-string (if current-prefix-arg
7643 "Exclude author (regexp): "
a1506d29 7644 "Limit to author (regexp): "))
ef6e0ec7
SZ
7645 current-prefix-arg))
7646 (gnus-summary-limit-to-subject from "from" not-matching))
eec82323
LMI
7647
7648(defun gnus-summary-limit-to-age (age &optional younger-p)
7649 "Limit the summary buffer to articles that are older than (or equal) AGE days.
7650If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7651articles that are younger than AGE days."
16409b0b
GM
7652 (interactive
7653 (let ((younger current-prefix-arg)
7654 (days-got nil)
7655 days)
7656 (while (not days-got)
7657 (setq days (if younger
23f87bed
MB
7658 (read-string "Limit to articles younger than (in days, older when negative): ")
7659 (read-string
7660 "Limit to articles older than (in days, younger when negative): ")))
16409b0b
GM
7661 (when (> (length days) 0)
7662 (setq days (read days)))
7663 (if (numberp days)
23f87bed
MB
7664 (progn
7665 (setq days-got t)
7666 (if (< days 0)
7667 (progn
7668 (setq younger (not younger))
7669 (setq days (* days -1)))))
16409b0b
GM
7670 (message "Please enter a number.")
7671 (sleep-for 1)))
7672 (list days younger)))
eec82323
LMI
7673 (prog1
7674 (let ((data gnus-newsgroup-data)
16409b0b 7675 (cutoff (days-to-time age))
eec82323
LMI
7676 articles d date is-younger)
7677 (while (setq d (pop data))
7678 (when (and (vectorp (gnus-data-header d))
7679 (setq date (mail-header-date (gnus-data-header d))))
16409b0b
GM
7680 (setq is-younger (time-less-p
7681 (time-since (condition-case ()
7682 (date-to-time date)
7683 (error '(0 0))))
eec82323 7684 cutoff))
6748645f
LMI
7685 (when (if younger-p
7686 is-younger
7687 (not is-younger))
eec82323
LMI
7688 (push (gnus-data-number d) articles))))
7689 (gnus-summary-limit (nreverse articles)))
7690 (gnus-summary-position-point)))
7691
47b63dfa 7692(defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
16409b0b
GM
7693 "Limit the summary buffer to articles that match an 'extra' header."
7694 (interactive
7695 (let ((header
7696 (intern
23f87bed 7697 (gnus-completing-read-with-default
16409b0b 7698 (symbol-name (car gnus-extra-headers))
47b63dfa 7699 (if current-prefix-arg
81df110a
RF
7700 "Exclude extra header"
7701 "Limit extra header")
16409b0b
GM
7702 (mapcar (lambda (x)
7703 (cons (symbol-name x) x))
7704 gnus-extra-headers)
7705 nil
7706 t))))
7707 (list header
a1506d29 7708 (read-string (format "%s header %s (regexp): "
47b63dfa
SZ
7709 (if current-prefix-arg "Exclude" "Limit to")
7710 header))
7711 current-prefix-arg)))
16409b0b
GM
7712 (when (not (equal "" regexp))
7713 (prog1
7714 (let ((articles (gnus-summary-find-matching
a1506d29 7715 (cons 'extra header) regexp 'all nil nil
47b63dfa 7716 not-matching)))
16409b0b
GM
7717 (unless articles
7718 (error "Found no matches for \"%s\"" regexp))
7719 (gnus-summary-limit articles))
7720 (gnus-summary-position-point))))
7721
23f87bed
MB
7722(defun gnus-summary-limit-to-display-predicate ()
7723 "Limit the summary buffer to the predicated in the `display' group parameter."
7724 (interactive)
7725 (unless gnus-newsgroup-display
7726 (error "There is no `display' group parameter"))
7727 (let (articles)
7728 (dolist (number gnus-newsgroup-articles)
7729 (when (funcall gnus-newsgroup-display)
7730 (push number articles)))
7731 (gnus-summary-limit articles))
7732 (gnus-summary-position-point))
7733
eec82323
LMI
7734(defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7735(make-obsolete
7736 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7737
7738(defun gnus-summary-limit-to-unread (&optional all)
7739 "Limit the summary buffer to articles that are not marked as read.
7740If ALL is non-nil, limit strictly to unread articles."
7741 (interactive "P")
7742 (if all
7743 (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7744 (gnus-summary-limit-to-marks
7745 ;; Concat all the marks that say that an article is read and have
7746 ;; those removed.
7747 (list gnus-del-mark gnus-read-mark gnus-ancient-mark
23f87bed 7748 gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
eec82323
LMI
7749 gnus-low-score-mark gnus-expirable-mark
7750 gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7751 gnus-duplicate-mark gnus-souped-mark)
7752 'reverse)))
7753
7754(defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7755(make-obsolete 'gnus-summary-delete-marked-with
81ceefe2 7756 'gnus-summary-limit-exclude-marks)
eec82323
LMI
7757
7758(defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7759 "Exclude articles that are marked with MARKS (e.g. \"DK\").
7760If REVERSE, limit the summary buffer to articles that are marked
7761with MARKS. MARKS can either be a string of marks or a list of marks.
7762Returns how many articles were removed."
7763 (interactive "sMarks: ")
7764 (gnus-summary-limit-to-marks marks t))
7765
7766(defun gnus-summary-limit-to-marks (marks &optional reverse)
7767 "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7768If REVERSE (the prefix), limit the summary buffer to articles that are
7769not marked with MARKS. MARKS can either be a string of marks or a
7770list of marks.
7771Returns how many articles were removed."
6748645f 7772 (interactive "sMarks: \nP")
eec82323
LMI
7773 (prog1
7774 (let ((data gnus-newsgroup-data)
7775 (marks (if (listp marks) marks
7776 (append marks nil))) ; Transform to list.
7777 articles)
7778 (while data
7779 (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7780 (memq (gnus-data-mark (car data)) marks))
7781 (push (gnus-data-number (car data)) articles))
7782 (setq data (cdr data)))
7783 (gnus-summary-limit articles))
7784 (gnus-summary-position-point)))
7785
23f87bed 7786(defun gnus-summary-limit-to-score (score)
eec82323 7787 "Limit to articles with score at or above SCORE."
23f87bed 7788 (interactive "NLimit to articles with score of at least: ")
eec82323
LMI
7789 (let ((data gnus-newsgroup-data)
7790 articles)
7791 (while data
7792 (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7793 score)
7794 (push (gnus-data-number (car data)) articles))
7795 (setq data (cdr data)))
7796 (prog1
7797 (gnus-summary-limit articles)
7798 (gnus-summary-position-point))))
7799
23f87bed
MB
7800(defun gnus-summary-limit-to-unseen ()
7801 "Limit to unseen articles."
7802 (interactive)
7803 (prog1
7804 (gnus-summary-limit gnus-newsgroup-unseen)
7805 (gnus-summary-position-point)))
7806
6748645f 7807(defun gnus-summary-limit-include-thread (id)
23f87bed
MB
7808 "Display all the hidden articles that is in the thread with ID in it.
7809When called interactively, ID is the Message-ID of the current
7810article."
6748645f
LMI
7811 (interactive (list (mail-header-id (gnus-summary-article-header))))
7812 (let ((articles (gnus-articles-in-thread
7813 (gnus-id-to-thread (gnus-root-id id)))))
7814 (prog1
7815 (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
23f87bed
MB
7816 (gnus-summary-limit-include-matching-articles
7817 "subject"
7818 (regexp-quote (gnus-simplify-subject-re
7819 (mail-header-subject (gnus-id-to-header id)))))
6748645f
LMI
7820 (gnus-summary-position-point))))
7821
23f87bed
MB
7822(defun gnus-summary-limit-include-matching-articles (header regexp)
7823 "Display all the hidden articles that have HEADERs that match REGEXP."
7824 (interactive (list (read-string "Match on header: ")
7825 (read-string "Regexp: ")))
7826 (let ((articles (gnus-find-matching-articles header regexp)))
7827 (prog1
7828 (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7829 (gnus-summary-position-point))))
7830
7831(defun gnus-summary-insert-dormant-articles ()
7832 "Insert all the dormant articles for this group into the current buffer."
7833 (interactive)
7834 (let ((gnus-verbose (max 6 gnus-verbose)))
7835 (if (not gnus-newsgroup-dormant)
7836 (gnus-message 3 "No cached articles for this group")
7837 (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7838
eec82323 7839(defun gnus-summary-limit-include-dormant ()
6748645f
LMI
7840 "Display all the hidden articles that are marked as dormant.
7841Note that this command only works on a subset of the articles currently
7842fetched for this group."
eec82323 7843 (interactive)
eec82323
LMI
7844 (unless gnus-newsgroup-dormant
7845 (error "There are no dormant articles in this group"))
7846 (prog1
7847 (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7848 (gnus-summary-position-point)))
7849
7850(defun gnus-summary-limit-exclude-dormant ()
7851 "Hide all dormant articles."
7852 (interactive)
eec82323
LMI
7853 (prog1
7854 (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7855 (gnus-summary-position-point)))
7856
7857(defun gnus-summary-limit-exclude-childless-dormant ()
7858 "Hide all dormant articles that have no children."
7859 (interactive)
eec82323
LMI
7860 (let ((data (gnus-data-list t))
7861 articles d children)
7862 ;; Find all articles that are either not dormant or have
7863 ;; children.
7864 (while (setq d (pop data))
7865 (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7866 (and (setq children
7867 (gnus-article-children (gnus-data-number d)))
7868 (let (found)
7869 (while children
7870 (when (memq (car children) articles)
7871 (setq children nil
7872 found t))
7873 (pop children))
7874 found)))
7875 (push (gnus-data-number d) articles)))
7876 ;; Do the limiting.
7877 (prog1
7878 (gnus-summary-limit articles)
7879 (gnus-summary-position-point))))
7880
7881(defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7882 "Mark all unread excluded articles as read.
7883If ALL, mark even excluded ticked and dormants as read."
7884 (interactive "P")
23f87bed
MB
7885 (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7886 (let ((articles (gnus-sorted-ndifference
eec82323
LMI
7887 (sort
7888 (mapcar (lambda (h) (mail-header-number h))
7889 gnus-newsgroup-headers)
7890 '<)
23f87bed 7891 gnus-newsgroup-limit))
eec82323 7892 article)
6748645f 7893 (setq gnus-newsgroup-unreads
23f87bed
MB
7894 (gnus-sorted-intersection gnus-newsgroup-unreads
7895 gnus-newsgroup-limit))
eec82323
LMI
7896 (if all
7897 (setq gnus-newsgroup-dormant nil
7898 gnus-newsgroup-marked nil
7899 gnus-newsgroup-reads
7900 (nconc
7901 (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7902 gnus-newsgroup-reads))
7903 (while (setq article (pop articles))
7904 (unless (or (memq article gnus-newsgroup-dormant)
7905 (memq article gnus-newsgroup-marked))
7906 (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7907
7908(defun gnus-summary-limit (articles &optional pop)
7909 (if pop
7910 ;; We pop the previous limit off the stack and use that.
7911 (setq articles (car gnus-newsgroup-limits)
7912 gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7913 ;; We use the new limit, so we push the old limit on the stack.
7914 (push gnus-newsgroup-limit gnus-newsgroup-limits))
7915 ;; Set the limit.
7916 (setq gnus-newsgroup-limit articles)
7917 (let ((total (length gnus-newsgroup-data))
7918 (data (gnus-data-find-list (gnus-summary-article-number)))
7919 (gnus-summary-mark-below nil) ; Inhibit this.
7920 found)
7921 ;; This will do all the work of generating the new summary buffer
7922 ;; according to the new limit.
7923 (gnus-summary-prepare)
7924 ;; Hide any threads, possibly.
23f87bed 7925 (gnus-summary-maybe-hide-threads)
eec82323
LMI
7926 ;; Try to return to the article you were at, or one in the
7927 ;; neighborhood.
7928 (when data
7929 ;; We try to find some article after the current one.
7930 (while data
7931 (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7932 (setq data nil
7933 found t))
7934 (setq data (cdr data))))
7935 (unless found
7936 ;; If there is no data, that means that we were after the last
7937 ;; article. The same goes when we can't find any articles
7938 ;; after the current one.
7939 (goto-char (point-max))
7940 (gnus-summary-find-prev))
6748645f 7941 (gnus-set-mode-line 'summary)
eec82323
LMI
7942 ;; We return how many articles were removed from the summary
7943 ;; buffer as a result of the new limit.
7944 (- total (length gnus-newsgroup-data))))
7945
7946(defsubst gnus-invisible-cut-children (threads)
7947 (let ((num 0))
7948 (while threads
7949 (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7950 (incf num))
7951 (pop threads))
7952 (< num 2)))
7953
7954(defsubst gnus-cut-thread (thread)
7955 "Go forwards in the thread until we find an article that we want to display."
7956 (when (or (eq gnus-fetch-old-headers 'some)
6748645f 7957 (eq gnus-fetch-old-headers 'invisible)
16409b0b 7958 (numberp gnus-fetch-old-headers)
eec82323
LMI
7959 (eq gnus-build-sparse-threads 'some)
7960 (eq gnus-build-sparse-threads 'more))
7961 ;; Deal with old-fetched headers and sparse threads.
7962 (while (and
7963 thread
7964 (or
7965 (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7966 (gnus-summary-article-ancient-p
7967 (mail-header-number (car thread))))
6748645f
LMI
7968 (if (or (<= (length (cdr thread)) 1)
7969 (eq gnus-fetch-old-headers 'invisible))
7970 (setq gnus-newsgroup-limit
7971 (delq (mail-header-number (car thread))
7972 gnus-newsgroup-limit)
7973 thread (cadr thread))
7974 (when (gnus-invisible-cut-children (cdr thread))
7975 (let ((th (cdr thread)))
7976 (while th
7977 (if (memq (mail-header-number (caar th))
a8151ef7 7978 gnus-newsgroup-limit)
6748645f
LMI
7979 (setq thread (car th)
7980 th nil)
7981 (setq th (cdr th))))))))))
eec82323
LMI
7982 thread)
7983
7984(defun gnus-cut-threads (threads)
23f87bed 7985 "Cut off all uninteresting articles from the beginning of THREADS."
eec82323 7986 (when (or (eq gnus-fetch-old-headers 'some)
6748645f 7987 (eq gnus-fetch-old-headers 'invisible)
16409b0b 7988 (numberp gnus-fetch-old-headers)
eec82323
LMI
7989 (eq gnus-build-sparse-threads 'some)
7990 (eq gnus-build-sparse-threads 'more))
7991 (let ((th threads))
7992 (while th
7993 (setcar th (gnus-cut-thread (car th)))
7994 (setq th (cdr th)))))
7995 ;; Remove nixed out threads.
7996 (delq nil threads))
7997
7998(defun gnus-summary-initial-limit (&optional show-if-empty)
7999 "Figure out what the initial limit is supposed to be on group entry.
8000This entails weeding out unwanted dormants, low-scored articles,
8001fetch-old-headers verbiage, and so on."
8002 ;; Most groups have nothing to remove.
8003 (if (or gnus-inhibit-limiting
8004 (and (null gnus-newsgroup-dormant)
23f87bed 8005 (eq gnus-newsgroup-display 'gnus-not-ignore)
eec82323 8006 (not (eq gnus-fetch-old-headers 'some))
16409b0b 8007 (not (numberp gnus-fetch-old-headers))
6748645f 8008 (not (eq gnus-fetch-old-headers 'invisible))
eec82323
LMI
8009 (null gnus-summary-expunge-below)
8010 (not (eq gnus-build-sparse-threads 'some))
8011 (not (eq gnus-build-sparse-threads 'more))
8012 (null gnus-thread-expunge-below)
8013 (not gnus-use-nocem)))
8014 () ; Do nothing.
8015 (push gnus-newsgroup-limit gnus-newsgroup-limits)
8016 (setq gnus-newsgroup-limit nil)
8017 (mapatoms
8018 (lambda (node)
8019 (unless (car (symbol-value node))
8020 ;; These threads have no parents -- they are roots.
8021 (let ((nodes (cdr (symbol-value node)))
8022 thread)
8023 (while nodes
8024 (if (and gnus-thread-expunge-below
8025 (< (gnus-thread-total-score (car nodes))
8026 gnus-thread-expunge-below))
8027 (gnus-expunge-thread (pop nodes))
8028 (setq thread (pop nodes))
8029 (gnus-summary-limit-children thread))))))
8030 gnus-newsgroup-dependencies)
8031 ;; If this limitation resulted in an empty group, we might
8032 ;; pop the previous limit and use it instead.
8033 (when (and (not gnus-newsgroup-limit)
8034 show-if-empty)
8035 (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8036 gnus-newsgroup-limit))
8037
8038(defun gnus-summary-limit-children (thread)
8039 "Return 1 if this subthread is visible and 0 if it is not."
8040 ;; First we get the number of visible children to this thread. This
8041 ;; is done by recursing down the thread using this function, so this
8042 ;; will really go down to a leaf article first, before slowly
8043 ;; working its way up towards the root.
8044 (when thread
23f87bed
MB
8045 (let* ((max-lisp-eval-depth 5000)
8046 (children
eec82323
LMI
8047 (if (cdr thread)
8048 (apply '+ (mapcar 'gnus-summary-limit-children
8049 (cdr thread)))
8050 0))
8051 (number (mail-header-number (car thread)))
8052 score)
8053 (if (and
8054 (not (memq number gnus-newsgroup-marked))
8055 (or
8056 ;; If this article is dormant and has absolutely no visible
8057 ;; children, then this article isn't visible.
8058 (and (memq number gnus-newsgroup-dormant)
8059 (zerop children))
8060 ;; If this is "fetch-old-headered" and there is no
8061 ;; visible children, then we don't want this article.
16409b0b
GM
8062 (and (or (eq gnus-fetch-old-headers 'some)
8063 (numberp gnus-fetch-old-headers))
eec82323
LMI
8064 (gnus-summary-article-ancient-p number)
8065 (zerop children))
6748645f
LMI
8066 ;; If this is "fetch-old-headered" and `invisible', then
8067 ;; we don't want this article.
8068 (and (eq gnus-fetch-old-headers 'invisible)
8069 (gnus-summary-article-ancient-p number))
eec82323
LMI
8070 ;; If this is a sparsely inserted article with no children,
8071 ;; we don't want it.
8072 (and (eq gnus-build-sparse-threads 'some)
8073 (gnus-summary-article-sparse-p number)
8074 (zerop children))
8075 ;; If we use expunging, and this article is really
8076 ;; low-scored, then we don't want this article.
8077 (when (and gnus-summary-expunge-below
8078 (< (setq score
8079 (or (cdr (assq number gnus-newsgroup-scored))
8080 gnus-summary-default-score))
8081 gnus-summary-expunge-below))
8082 ;; We increase the expunge-tally here, but that has
8083 ;; nothing to do with the limits, really.
8084 (incf gnus-newsgroup-expunged-tally)
8085 ;; We also mark as read here, if that's wanted.
8086 (when (and gnus-summary-mark-below
8087 (< score gnus-summary-mark-below))
8088 (setq gnus-newsgroup-unreads
8089 (delq number gnus-newsgroup-unreads))
8090 (if gnus-newsgroup-auto-expire
8091 (push number gnus-newsgroup-expirable)
8092 (push (cons number gnus-low-score-mark)
8093 gnus-newsgroup-reads)))
8094 t)
23f87bed
MB
8095 ;; Do the `display' group parameter.
8096 (and gnus-newsgroup-display
8097 (not (funcall gnus-newsgroup-display)))
eec82323
LMI
8098 ;; Check NoCeM things.
8099 (if (and gnus-use-nocem
8100 (gnus-nocem-unwanted-article-p
8101 (mail-header-id (car thread))))
8102 (progn
a8151ef7 8103 (setq gnus-newsgroup-unreads
eec82323
LMI
8104 (delq number gnus-newsgroup-unreads))
8105 t))))
8106 ;; Nope, invisible article.
8107 0
8108 ;; Ok, this article is to be visible, so we add it to the limit
8109 ;; and return 1.
8110 (push number gnus-newsgroup-limit)
8111 1))))
8112
8113(defun gnus-expunge-thread (thread)
8114 "Mark all articles in THREAD as read."
8115 (let* ((number (mail-header-number (car thread))))
8116 (incf gnus-newsgroup-expunged-tally)
8117 ;; We also mark as read here, if that's wanted.
8118 (setq gnus-newsgroup-unreads
8119 (delq number gnus-newsgroup-unreads))
8120 (if gnus-newsgroup-auto-expire
8121 (push number gnus-newsgroup-expirable)
8122 (push (cons number gnus-low-score-mark)
8123 gnus-newsgroup-reads)))
8124 ;; Go recursively through all subthreads.
8125 (mapcar 'gnus-expunge-thread (cdr thread)))
8126
8127;; Summary article oriented commands
8128
8129(defun gnus-summary-refer-parent-article (n)
8130 "Refer parent article N times.
8131If N is negative, go to ancestor -N instead.
8132The difference between N and the number of articles fetched is returned."
8133 (interactive "p")
eec82323
LMI
8134 (let ((skip 1)
8135 error header ref)
8136 (when (not (natnump n))
8137 (setq skip (abs n)
8138 n 1))
8139 (while (and (> n 0)
8140 (not error))
8141 (setq header (gnus-summary-article-header))
8142 (if (and (eq (mail-header-number header)
8143 (cdr gnus-article-current))
8144 (equal gnus-newsgroup-name
8145 (car gnus-article-current)))
8146 ;; If we try to find the parent of the currently
8147 ;; displayed article, then we take a look at the actual
8148 ;; References header, since this is slightly more
8149 ;; reliable than the References field we got from the
8150 ;; server.
8151 (save-excursion
8152 (set-buffer gnus-original-article-buffer)
8153 (nnheader-narrow-to-headers)
8154 (unless (setq ref (message-fetch-field "references"))
23f87bed
MB
8155 (when (setq ref (message-fetch-field "in-reply-to"))
8156 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
eec82323
LMI
8157 (widen))
8158 (setq ref
8159 ;; It's not the current article, so we take a bet on
8160 ;; the value we got from the server.
8161 (mail-header-references header)))
8162 (if (and ref
8163 (not (equal ref "")))
8164 (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8165 (gnus-message 1 "Couldn't find parent"))
8166 (gnus-message 1 "No references in article %d"
8167 (gnus-summary-article-number))
8168 (setq error t))
8169 (decf n))
8170 (gnus-summary-position-point)
8171 n))
8172
8173(defun gnus-summary-refer-references ()
8174 "Fetch all articles mentioned in the References header.
6748645f 8175Return the number of articles fetched."
eec82323 8176 (interactive)
eec82323
LMI
8177 (let ((ref (mail-header-references (gnus-summary-article-header)))
8178 (current (gnus-summary-article-number))
8179 (n 0))
8180 (if (or (not ref)
8181 (equal ref ""))
8182 (error "No References in the current article")
8183 ;; For each Message-ID in the References header...
8184 (while (string-match "<[^>]*>" ref)
8185 (incf n)
8186 ;; ... fetch that article.
8187 (gnus-summary-refer-article
8188 (prog1 (match-string 0 ref)
8189 (setq ref (substring ref (match-end 0))))))
8190 (gnus-summary-goto-subject current)
8191 (gnus-summary-position-point)
8192 n)))
8193
6748645f
LMI
8194(defun gnus-summary-refer-thread (&optional limit)
8195 "Fetch all articles in the current thread.
8196If LIMIT (the numerical prefix), fetch that many old headers instead
8197of what's specified by the `gnus-refer-thread-limit' variable."
8198 (interactive "P")
8199 (let ((id (mail-header-id (gnus-summary-article-header)))
8200 (limit (if limit (prefix-numeric-value limit)
8201 gnus-refer-thread-limit)))
6748645f
LMI
8202 (unless (eq gnus-fetch-old-headers 'invisible)
8203 (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8204 ;; Retrieve the headers and read them in.
23f87bed
MB
8205 (if (eq (if (numberp limit)
8206 (gnus-retrieve-headers
8207 (list (min
8208 (+ (mail-header-number
8209 (gnus-summary-article-header))
8210 limit)
8211 gnus-newsgroup-end))
8212 gnus-newsgroup-name (* limit 2))
8213 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8214 ;; headers.
8215 (gnus-retrieve-headers (list gnus-newsgroup-end)
8216 gnus-newsgroup-name limit))
6748645f
LMI
8217 'nov)
8218 (gnus-build-all-threads)
23f87bed 8219 (error "Can't fetch thread from back ends that don't support NOV"))
6748645f
LMI
8220 (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8221 (gnus-summary-limit-include-thread id)))
8222
16409b0b
GM
8223(defun gnus-summary-refer-article (message-id)
8224 "Fetch an article specified by MESSAGE-ID."
8225 (interactive "sMessage-ID: ")
eec82323
LMI
8226 (when (and (stringp message-id)
8227 (not (zerop (length message-id))))
23f87bed 8228 (setq message-id (gnus-replace-in-string message-id " " ""))
eec82323
LMI
8229 ;; Construct the correct Message-ID if necessary.
8230 ;; Suggested by tale@pawl.rpi.edu.
8231 (unless (string-match "^<" message-id)
8232 (setq message-id (concat "<" message-id)))
8233 (unless (string-match ">$" message-id)
8234 (setq message-id (concat message-id ">")))
23f87bed
MB
8235 ;; People often post MIDs from URLs, so unhex it:
8236 (unless (string-match "@" message-id)
8237 (setq message-id (gnus-url-unhex-string message-id)))
eec82323
LMI
8238 (let* ((header (gnus-id-to-header message-id))
8239 (sparse (and header
8240 (gnus-summary-article-sparse-p
a8151ef7
LMI
8241 (mail-header-number header))
8242 (memq (mail-header-number header)
16409b0b
GM
8243 gnus-newsgroup-limit)))
8244 number)
6748645f
LMI
8245 (cond
8246 ;; If the article is present in the buffer we just go to it.
8247 ((and header
8248 (or (not (gnus-summary-article-sparse-p
8249 (mail-header-number header)))
8250 sparse))
8251 (prog1
8252 (gnus-summary-goto-article
8253 (mail-header-number header) nil t)
8254 (when sparse
8255 (gnus-summary-update-article (mail-header-number header)))))
8256 (t
16409b0b
GM
8257 ;; We fetch the article.
8258 (catch 'found
8259 (dolist (gnus-override-method (gnus-refer-article-methods))
23f87bed
MB
8260 (when (and (gnus-check-server gnus-override-method)
8261 ;; Fetch the header,
8262 (setq number (gnus-summary-insert-subject message-id)))
8263 ;; and display the article.
eec82323 8264 (gnus-summary-select-article nil nil nil number)
16409b0b
GM
8265 (throw 'found t)))
8266 (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8267
8268(defun gnus-refer-article-methods ()
8f688cb0 8269 "Return a list of referable methods."
16409b0b
GM
8270 (cond
8271 ;; No method, so we default to current and native.
8272 ((null gnus-refer-article-method)
8273 (list gnus-current-select-method gnus-select-method))
8274 ;; Current.
8275 ((eq 'current gnus-refer-article-method)
8276 (list gnus-current-select-method))
8277 ;; List of select methods.
d4dfaa19
DL
8278 ((not (and (symbolp (car gnus-refer-article-method))
8279 (assq (car gnus-refer-article-method) nnoo-definition-alist)))
16409b0b
GM
8280 (let (out)
8281 (dolist (method gnus-refer-article-method)
8282 (push (if (eq 'current method)
8283 gnus-current-select-method
8284 method)
8285 out))
8286 (nreverse out)))
8287 ;; One single select method.
8288 (t
8289 (list gnus-refer-article-method))))
6748645f
LMI
8290
8291(defun gnus-summary-edit-parameters ()
8292 "Edit the group parameters of the current group."
8293 (interactive)
8294 (gnus-group-edit-group gnus-newsgroup-name 'params))
eec82323 8295
16409b0b
GM
8296(defun gnus-summary-customize-parameters ()
8297 "Customize the group parameters of the current group."
8298 (interactive)
8299 (gnus-group-customize gnus-newsgroup-name))
8300
eec82323
LMI
8301(defun gnus-summary-enter-digest-group (&optional force)
8302 "Enter an nndoc group based on the current article.
8303If FORCE, force a digest interpretation. If not, try
8304to guess what the document format is."
8305 (interactive "P")
eec82323 8306 (let ((conf gnus-current-window-configuration))
23f87bed
MB
8307 (save-window-excursion
8308 (save-excursion
8309 (let (gnus-article-prepare-hook
8310 gnus-display-mime-function
8311 gnus-break-pages)
8312 (gnus-summary-select-article))))
eec82323
LMI
8313 (setq gnus-current-window-configuration conf)
8314 (let* ((name (format "%s-%d"
8315 (gnus-group-prefixed-name
8316 gnus-newsgroup-name (list 'nndoc ""))
8317 (save-excursion
8318 (set-buffer gnus-summary-buffer)
8319 gnus-current-article)))
8320 (ogroup gnus-newsgroup-name)
8321 (params (append (gnus-info-params (gnus-get-info ogroup))
8322 (list (cons 'to-group ogroup))
23f87bed 8323 (list (cons 'parent-group ogroup))
eec82323
LMI
8324 (list (cons 'save-article-group ogroup))))
8325 (case-fold-search t)
8326 (buf (current-buffer))
16409b0b 8327 dig to-address)
eec82323 8328 (save-excursion
16409b0b
GM
8329 (set-buffer gnus-original-article-buffer)
8330 ;; Have the digest group inherit the main mail address of
8331 ;; the parent article.
23f87bed
MB
8332 (when (setq to-address (or (gnus-fetch-field "reply-to")
8333 (gnus-fetch-field "from")))
a1506d29
JB
8334 (setq params (append
8335 (list (cons 'to-address
d4dfaa19
DL
8336 (funcall gnus-decode-encoded-word-function
8337 to-address))))))
eec82323
LMI
8338 (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8339 (insert-buffer-substring gnus-original-article-buffer)
8340 ;; Remove lines that may lead nndoc to misinterpret the
8341 ;; document type.
8342 (narrow-to-region
8343 (goto-char (point-min))
8344 (or (search-forward "\n\n" nil t) (point)))
8345 (goto-char (point-min))
16409b0b 8346 (delete-matching-lines "^Path:\\|^From ")
eec82323
LMI
8347 (widen))
8348 (unwind-protect
23f87bed 8349 (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
16409b0b
GM
8350 (gnus-newsgroup-ephemeral-ignored-charsets
8351 gnus-newsgroup-ignored-charsets))
8352 (gnus-group-read-ephemeral-group
8353 name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8354 (nndoc-article-type
23f87bed
MB
8355 ,(if force 'mbox 'guess)))
8356 t nil nil nil
8357 `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8358 "ADAPT")))))
16409b0b 8359 ;; Make all postings to this group go to the parent group.
23f87bed
MB
8360 (nconc (gnus-info-params (gnus-get-info name))
8361 params)
8362 ;; Couldn't select this doc group.
8363 (switch-to-buffer buf)
8364 (gnus-set-global-variables)
8365 (gnus-configure-windows 'summary)
8366 (gnus-message 3 "Article couldn't be entered?"))
eec82323
LMI
8367 (kill-buffer dig)))))
8368
8369(defun gnus-summary-read-document (n)
8370 "Open a new group based on the current article(s).
8371This will allow you to read digests and other similar
8372documents as newsgroups.
8373Obeys the standard process/prefix convention."
8374 (interactive "P")
8375 (let* ((articles (gnus-summary-work-articles n))
8376 (ogroup gnus-newsgroup-name)
8377 (params (append (gnus-info-params (gnus-get-info ogroup))
8378 (list (cons 'to-group ogroup))))
8379 article group egroup groups vgroup)
8380 (while (setq article (pop articles))
8381 (setq group (format "%s-%d" gnus-newsgroup-name article))
8382 (gnus-summary-remove-process-mark article)
8383 (when (gnus-summary-display-article article)
8384 (save-excursion
16409b0b 8385 (with-temp-buffer
eec82323
LMI
8386 (insert-buffer-substring gnus-original-article-buffer)
8387 ;; Remove some headers that may lead nndoc to make
8388 ;; the wrong guess.
8389 (message-narrow-to-head)
8390 (goto-char (point-min))
8391 (delete-matching-lines "^\\(Path\\):\\|^From ")
8392 (widen)
8393 (if (setq egroup
8394 (gnus-group-read-ephemeral-group
8395 group `(nndoc ,group (nndoc-address ,(current-buffer))
8396 (nndoc-article-type guess))
8397 t nil t))
8398 (progn
23f87bed 8399 ;; Make all postings to this group go to the parent group.
eec82323
LMI
8400 (nconc (gnus-info-params (gnus-get-info egroup))
8401 params)
8402 (push egroup groups))
8403 ;; Couldn't select this doc group.
8404 (gnus-error 3 "Article couldn't be entered"))))))
8405 ;; Now we have selected all the documents.
8406 (cond
8407 ((not groups)
8408 (error "None of the articles could be interpreted as documents"))
8409 ((gnus-group-read-ephemeral-group
8410 (setq vgroup (format
8411 "nnvirtual:%s-%s" gnus-newsgroup-name
8412 (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8413 `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8414 t
8415 (cons (current-buffer) 'summary)))
8416 (t
8417 (error "Couldn't select virtual nndoc group")))))
8418
8419(defun gnus-summary-isearch-article (&optional regexp-p)
8420 "Do incremental search forward on the current article.
8421If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8422 (interactive "P")
eec82323
LMI
8423 (gnus-summary-select-article)
8424 (gnus-configure-windows 'article)
8425 (gnus-eval-in-buffer-window gnus-article-buffer
6748645f
LMI
8426 (save-restriction
8427 (widen)
8428 (isearch-forward regexp-p))))
eec82323
LMI
8429
8430(defun gnus-summary-search-article-forward (regexp &optional backward)
8431 "Search for an article containing REGEXP forward.
8432If BACKWARD, search backward instead."
8433 (interactive
8434 (list (read-string
8435 (format "Search article %s (regexp%s): "
8436 (if current-prefix-arg "backward" "forward")
8437 (if gnus-last-search-regexp
8438 (concat ", default " gnus-last-search-regexp)
8439 "")))
8440 current-prefix-arg))
eec82323
LMI
8441 (if (string-equal regexp "")
8442 (setq regexp (or gnus-last-search-regexp ""))
23f87bed
MB
8443 (setq gnus-last-search-regexp regexp)
8444 (setq gnus-article-before-search gnus-current-article))
8445 ;; Intentionally set gnus-last-article.
8446 (setq gnus-last-article gnus-article-before-search)
8447 (let ((gnus-last-article gnus-last-article))
8448 (if (gnus-summary-search-article regexp backward)
8449 (gnus-summary-show-thread)
abc40aab 8450 (signal 'search-failed (list regexp)))))
eec82323
LMI
8451
8452(defun gnus-summary-search-article-backward (regexp)
8453 "Search for an article containing REGEXP backward."
8454 (interactive
8455 (list (read-string
8456 (format "Search article backward (regexp%s): "
8457 (if gnus-last-search-regexp
8458 (concat ", default " gnus-last-search-regexp)
8459 "")))))
8460 (gnus-summary-search-article-forward regexp 'backward))
8461
8462(defun gnus-summary-search-article (regexp &optional backward)
8463 "Search for an article containing REGEXP.
8464Optional argument BACKWARD means do search for backward.
8465`gnus-select-article-hook' is not called during the search."
a8151ef7
LMI
8466 ;; We have to require this here to make sure that the following
8467 ;; dynamic binding isn't shadowed by autoloading.
8468 (require 'gnus-async)
16409b0b 8469 (require 'gnus-art)
eec82323 8470 (let ((gnus-select-article-hook nil) ;Disable hook.
16409b0b 8471 (gnus-article-prepare-hook nil)
eec82323
LMI
8472 (gnus-mark-article-hook nil) ;Inhibit marking as read.
8473 (gnus-use-article-prefetch nil)
8474 (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
a8151ef7 8475 (gnus-use-trees nil) ;Inhibit updating tree buffer.
23f87bed
MB
8476 (gnus-visual nil)
8477 (gnus-keep-backlog nil)
8478 (gnus-break-pages nil)
8479 (gnus-summary-display-arrow nil)
8480 (gnus-updated-mode-lines nil)
8481 (gnus-auto-center-summary nil)
eec82323 8482 (sum (current-buffer))
16409b0b 8483 (gnus-display-mime-function nil)
eec82323
LMI
8484 (found nil)
8485 point)
8486 (gnus-save-hidden-threads
8487 (gnus-summary-select-article)
8488 (set-buffer gnus-article-buffer)
16409b0b 8489 (goto-char (window-point (get-buffer-window (current-buffer))))
eec82323
LMI
8490 (when backward
8491 (forward-line -1))
8492 (while (not found)
8493 (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8494 (if (if backward
8495 (re-search-backward regexp nil t)
8496 (re-search-forward regexp nil t))
8497 ;; We found the regexp.
8498 (progn
8499 (setq found 'found)
8500 (beginning-of-line)
8501 (set-window-start
8502 (get-buffer-window (current-buffer))
8503 (point))
8504 (forward-line 1)
16409b0b
GM
8505 (set-window-point
8506 (get-buffer-window (current-buffer))
8507 (point))
eec82323
LMI
8508 (set-buffer sum)
8509 (setq point (point)))
8510 ;; We didn't find it, so we go to the next article.
8511 (set-buffer sum)
8512 (setq found 'not)
8513 (while (eq found 'not)
8514 (if (not (if backward (gnus-summary-find-prev)
8515 (gnus-summary-find-next)))
8516 ;; No more articles.
8517 (setq found t)
8518 ;; Select the next article and adjust point.
8519 (unless (gnus-summary-article-sparse-p
8520 (gnus-summary-article-number))
8521 (setq found nil)
8522 (gnus-summary-select-article)
8523 (set-buffer gnus-article-buffer)
8524 (widen)
8525 (goto-char (if backward (point-max) (point-min))))))))
8526 (gnus-message 7 ""))
8527 ;; Return whether we found the regexp.
8528 (when (eq found 'found)
8529 (goto-char point)
8530 (gnus-summary-show-thread)
8531 (gnus-summary-goto-subject gnus-current-article)
8532 (gnus-summary-position-point)
8533 t)))
8534
23f87bed
MB
8535(defun gnus-find-matching-articles (header regexp)
8536 "Return a list of all articles that match REGEXP on HEADER.
8537This search includes all articles in the current group that Gnus has
8538fetched headers for, whether they are displayed or not."
8539 (let ((articles nil)
8540 (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8541 (case-fold-search t))
8542 (dolist (header gnus-newsgroup-headers)
8543 (when (string-match regexp (funcall func header))
8544 (push (mail-header-number header) articles)))
8545 (nreverse articles)))
8546
eec82323 8547(defun gnus-summary-find-matching (header regexp &optional backward unread
47b63dfa 8548 not-case-fold not-matching)
eec82323
LMI
8549 "Return a list of all articles that match REGEXP on HEADER.
8550The search stars on the current article and goes forwards unless
8551BACKWARD is non-nil. If BACKWARD is `all', do all articles.
8552If UNREAD is non-nil, only unread articles will
8553be taken into consideration. If NOT-CASE-FOLD, case won't be folded
a1506d29 8554in the comparisons. If NOT-MATCHING, return a list of all articles that
47b63dfa
SZ
8555not match REGEXP on HEADER."
8556 (let ((case-fold-search (not not-case-fold))
16409b0b
GM
8557 articles d func)
8558 (if (consp header)
8559 (if (eq (car header) 'extra)
8560 (setq func
8561 `(lambda (h)
8562 (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8563 "")))
8564 (error "%s is an invalid header" header))
8565 (unless (fboundp (intern (concat "mail-header-" header)))
8566 (error "%s is not a valid header" header))
8567 (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
47b63dfa
SZ
8568 (dolist (d (if (eq backward 'all)
8569 gnus-newsgroup-data
8570 (gnus-data-find-list
8571 (gnus-summary-article-number)
8572 (gnus-data-list backward))))
8573 (when (and (or (not unread) ; We want all articles...
8574 (gnus-data-unread-p d)) ; Or just unreads.
8575 (vectorp (gnus-data-header d)) ; It's not a pseudo.
8576 (if not-matching
a1506d29 8577 (not (string-match
47b63dfa
SZ
8578 regexp
8579 (funcall func (gnus-data-header d))))
8580 (string-match regexp
8581 (funcall func (gnus-data-header d)))))
8582 (push (gnus-data-number d) articles))) ; Success!
eec82323
LMI
8583 (nreverse articles)))
8584
8585(defun gnus-summary-execute-command (header regexp command &optional backward)
8586 "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8587If HEADER is an empty string (or nil), the match is done on the entire
8588article. If BACKWARD (the prefix) is non-nil, search backward instead."
8589 (interactive
8590 (list (let ((completion-ignore-case t))
8591 (completing-read
8592 "Header name: "
23f87bed
MB
8593 (mapcar (lambda (header) (list (format "%s" header)))
8594 (append
8595 '("Number" "Subject" "From" "Lines" "Date"
8596 "Message-ID" "Xref" "References" "Body")
8597 gnus-extra-headers))
eec82323
LMI
8598 nil 'require-match))
8599 (read-string "Regexp: ")
8600 (read-key-sequence "Command: ")
8601 current-prefix-arg))
8602 (when (equal header "Body")
8603 (setq header ""))
eec82323
LMI
8604 ;; Hidden thread subtrees must be searched as well.
8605 (gnus-summary-show-all-threads)
8606 ;; We don't want to change current point nor window configuration.
8607 (save-excursion
8608 (save-window-excursion
23f87bed
MB
8609 (let (gnus-visual
8610 gnus-treat-strip-trailing-blank-lines
8611 gnus-treat-strip-leading-blank-lines
8612 gnus-treat-strip-multiple-blank-lines
8613 gnus-treat-hide-boring-headers
8614 gnus-treat-fold-newsgroups
8615 gnus-article-prepare-hook)
8616 (gnus-message 6 "Executing %s..." (key-description command))
8617 ;; We'd like to execute COMMAND interactively so as to give arguments.
8618 (gnus-execute header regexp
8619 `(call-interactively ',(key-binding command))
8620 backward)
8621 (gnus-message 6 "Executing %s...done" (key-description command))))))
eec82323
LMI
8622
8623(defun gnus-summary-beginning-of-article ()
8624 "Scroll the article back to the beginning."
8625 (interactive)
eec82323
LMI
8626 (gnus-summary-select-article)
8627 (gnus-configure-windows 'article)
8628 (gnus-eval-in-buffer-window gnus-article-buffer
8629 (widen)
8630 (goto-char (point-min))
23f87bed 8631 (when gnus-break-pages
eec82323
LMI
8632 (gnus-narrow-to-page))))
8633
8634(defun gnus-summary-end-of-article ()
8635 "Scroll to the end of the article."
8636 (interactive)
eec82323
LMI
8637 (gnus-summary-select-article)
8638 (gnus-configure-windows 'article)
8639 (gnus-eval-in-buffer-window gnus-article-buffer
8640 (widen)
8641 (goto-char (point-max))
8642 (recenter -3)
23f87bed
MB
8643 (when gnus-break-pages
8644 (when (re-search-backward page-delimiter nil t)
8645 (narrow-to-region (match-end 0) (point-max)))
eec82323
LMI
8646 (gnus-narrow-to-page))))
8647
23f87bed
MB
8648(defun gnus-summary-print-truncate-and-quote (string &optional len)
8649 "Truncate to LEN and quote all \"(\"'s in STRING."
8650 (gnus-replace-in-string (if (and len (> (length string) len))
8651 (substring string 0 len)
8652 string)
8653 "[()]" "\\\\\\&"))
8654
6748645f 8655(defun gnus-summary-print-article (&optional filename n)
23f87bed
MB
8656 "Generate and print a PostScript image of the process-marked (mail) articles.
8657
8658If used interactively, print the current article if none are
8659process-marked. With prefix arg, prompt the user for the name of the
8660file to save in.
6748645f 8661
23f87bed
MB
8662When used from Lisp, accept two optional args FILENAME and N. N means
8663to print the next N articles. If N is negative, print the N previous
8664articles. If N is nil and articles have been marked with the process
8665mark, print these instead.
eec82323 8666
16409b0b 8667If the optional first argument FILENAME is nil, send the image to the
6748645f
LMI
8668printer. If FILENAME is a string, save the PostScript image in a file with
8669that name. If FILENAME is a number, prompt the user for the name of the file
eec82323 8670to save in."
676a7cc9 8671 (interactive (list (ps-print-preprint current-prefix-arg)))
6748645f
LMI
8672 (dolist (article (gnus-summary-work-articles n))
8673 (gnus-summary-select-article nil nil 'pseudo article)
8674 (gnus-eval-in-buffer-window gnus-article-buffer
23f87bed 8675 (gnus-print-buffer))
676a7cc9
SZ
8676 (gnus-summary-remove-process-mark article))
8677 (ps-despool filename))
eec82323 8678
23f87bed
MB
8679(defun gnus-print-buffer ()
8680 (let ((buffer (generate-new-buffer " *print*")))
8681 (unwind-protect
8682 (progn
8683 (copy-to-buffer buffer (point-min) (point-max))
8684 (set-buffer buffer)
8685 (gnus-remove-text-with-property 'gnus-decoration)
8686 (when (gnus-visual-p 'article-highlight 'highlight)
8687 ;; Copy-to-buffer doesn't copy overlay. So redo
8688 ;; highlight.
8689 (let ((gnus-article-buffer buffer))
8690 (gnus-article-highlight-citation t)
8691 (gnus-article-highlight-signature)
8692 (gnus-article-emphasize)
8693 (gnus-article-delete-invisible-text)))
8694 (let ((ps-left-header
8695 (list
8696 (concat "("
8697 (gnus-summary-print-truncate-and-quote
8698 (mail-header-subject gnus-current-headers)
8699 66) ")")
8700 (concat "("
8701 (gnus-summary-print-truncate-and-quote
8702 (mail-header-from gnus-current-headers)
8703 45) ")")))
8704 (ps-right-header
8705 (list
8706 "/pagenumberstring load"
8707 (concat "("
8708 (mail-header-date gnus-current-headers) ")"))))
8709 (gnus-run-hooks 'gnus-ps-print-hook)
8710 (save-excursion
8711 (if window-system
8712 (ps-spool-buffer-with-faces)
8713 (ps-spool-buffer)))))
8714 (kill-buffer buffer))))
8715
eec82323 8716(defun gnus-summary-show-article (&optional arg)
23f87bed 8717 "Force redisplaying of the current article.
16409b0b
GM
8718If ARG (the prefix) is a number, show the article with the charset
8719defined in `gnus-summary-show-article-charset-alist', or the charset
23f87bed 8720input.
16409b0b 8721If ARG (the prefix) is non-nil and not a number, show the raw article
23f87bed
MB
8722without any article massaging functions being run. Normally, the key
8723strokes are `C-u g'."
eec82323 8724 (interactive "P")
16409b0b
GM
8725 (cond
8726 ((numberp arg)
23f87bed 8727 (gnus-summary-show-article t)
16409b0b
GM
8728 (let ((gnus-newsgroup-charset
8729 (or (cdr (assq arg gnus-summary-show-article-charset-alist))
23f87bed
MB
8730 (mm-read-coding-system
8731 "View as charset: " ;; actually it is coding system.
8732 (save-excursion
8733 (set-buffer gnus-article-buffer)
8734 (mm-detect-coding-region (point) (point-max))))))
16409b0b 8735 (gnus-newsgroup-ignored-charsets 'gnus-all))
23f87bed
MB
8736 (gnus-summary-select-article nil 'force)
8737 (let ((deps gnus-newsgroup-dependencies)
8738 head header lines)
8739 (save-excursion
8740 (set-buffer gnus-original-article-buffer)
8741 (save-restriction
8742 (message-narrow-to-head)
8743 (setq head (buffer-string))
8744 (goto-char (point-min))
8745 (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8746 (goto-char (point-max))
8747 (widen)
8748 (setq lines (1- (count-lines (point) (point-max))))))
8749 (with-temp-buffer
8750 (insert (format "211 %d Article retrieved.\n"
8751 (cdr gnus-article-current)))
8752 (insert head)
8753 (if lines (insert (format "Lines: %d\n" lines)))
8754 (insert ".\n")
8755 (let ((nntp-server-buffer (current-buffer)))
8756 (setq header (car (gnus-get-newsgroup-headers deps t))))))
8757 (gnus-data-set-header
8758 (gnus-data-find (cdr gnus-article-current))
8759 header)
8760 (gnus-summary-update-article-line
8761 (cdr gnus-article-current) header)
8762 (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8763 (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
16409b0b
GM
8764 ((not arg)
8765 ;; Select the article the normal way.
8766 (gnus-summary-select-article nil 'force))
8767 (t
8768 ;; We have to require this here to make sure that the following
8769 ;; dynamic binding isn't shadowed by autoloading.
8770 (require 'gnus-async)
8771 (require 'gnus-art)
eec82323
LMI
8772 ;; Bind the article treatment functions to nil.
8773 (let ((gnus-have-all-headers t)
eec82323 8774 gnus-article-prepare-hook
16409b0b
GM
8775 gnus-article-decode-hook
8776 gnus-display-mime-function
8777 gnus-break-pages)
8778 ;; Destroy any MIME parts.
8779 (when (gnus-buffer-live-p gnus-article-buffer)
8780 (save-excursion
8781 (set-buffer gnus-article-buffer)
8782 (mm-destroy-parts gnus-article-mime-handles)
8783 ;; Set it to nil for safety reason.
8784 (setq gnus-article-mime-handle-alist nil)
8785 (setq gnus-article-mime-handles nil)))
8786 (gnus-summary-select-article nil 'force))))
eec82323
LMI
8787 (gnus-summary-goto-subject gnus-current-article)
8788 (gnus-summary-position-point))
8789
23f87bed
MB
8790(defun gnus-summary-show-raw-article ()
8791 "Show the raw article without any article massaging functions being run."
8792 (interactive)
8793 (gnus-summary-show-article t))
8794
eec82323
LMI
8795(defun gnus-summary-verbose-headers (&optional arg)
8796 "Toggle permanent full header display.
8797If ARG is a positive number, turn header display on.
8798If ARG is a negative number, turn header display off."
8799 (interactive "P")
eec82323
LMI
8800 (setq gnus-show-all-headers
8801 (cond ((or (not (numberp arg))
8802 (zerop arg))
8803 (not gnus-show-all-headers))
8804 ((natnump arg)
8805 t)))
8806 (gnus-summary-show-article))
8807
8808(defun gnus-summary-toggle-header (&optional arg)
8809 "Show the headers if they are hidden, or hide them if they are shown.
8810If ARG is a positive number, show the entire header.
8811If ARG is a negative number, hide the unwanted header lines."
8812 (interactive "P")
23f87bed
MB
8813 (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8814 (get-buffer-window gnus-article-buffer t))))
8815 (with-current-buffer gnus-article-buffer
8816 (widen)
8817 (article-narrow-to-head)
16409b0b
GM
8818 (let* ((buffer-read-only nil)
8819 (inhibit-point-motion-hooks t)
23f87bed
MB
8820 (hidden (if (numberp arg)
8821 (>= arg 0)
f0096211
MB
8822 (or (not (looking-at "[^ \t\n]+:"))
8823 (gnus-article-hidden-text-p 'headers))))
23f87bed
MB
8824 s e)
8825 (delete-region (point-min) (point-max))
667e0ba6
SM
8826 (with-current-buffer gnus-original-article-buffer
8827 (goto-char (setq s (point-min)))
23f87bed
MB
8828 (setq e (if (search-forward "\n\n" nil t)
8829 (1- (point))
8830 (point-max))))
667e0ba6 8831 (insert-buffer-substring gnus-original-article-buffer s e)
23f87bed
MB
8832 (run-hooks 'gnus-article-decode-hook)
8833 (if hidden
8834 (let ((gnus-treat-hide-headers nil)
8835 (gnus-treat-hide-boring-headers nil))
8836 (gnus-delete-wash-type 'headers)
8837 (gnus-treat-article 'head))
8838 (gnus-treat-article 'head))
8839 (widen)
8840 (if window
8841 (set-window-start window (goto-char (point-min))))
8842 (if gnus-break-pages
8843 (gnus-narrow-to-page)
8844 (when (gnus-visual-p 'page-marker)
8845 (let ((buffer-read-only nil))
8846 (gnus-remove-text-with-property 'gnus-prev)
8847 (gnus-remove-text-with-property 'gnus-next))))
16409b0b 8848 (gnus-set-mode-line 'article)))))
eec82323
LMI
8849
8850(defun gnus-summary-show-all-headers ()
8851 "Make all header lines visible."
8852 (interactive)
23f87bed 8853 (gnus-summary-toggle-header 1))
eec82323 8854
eec82323
LMI
8855(defun gnus-summary-caesar-message (&optional arg)
8856 "Caesar rotate the current article by 13.
8857The numerical prefix specifies how many places to rotate each letter
8858forward."
8859 (interactive "P")
eec82323
LMI
8860 (gnus-summary-select-article)
8861 (let ((mail-header-separator ""))
8862 (gnus-eval-in-buffer-window gnus-article-buffer
8863 (save-restriction
8864 (widen)
8865 (let ((start (window-start))
8866 buffer-read-only)
8867 (message-caesar-buffer-body arg)
ff4d3926
MB
8868 (set-window-start (get-buffer-window (current-buffer)) start)))))
8869 ;; Create buttons and stuff...
8870 (gnus-treat-article nil))
eec82323 8871
23f87bed
MB
8872(autoload 'unmorse-region "morse"
8873 "Convert morse coded text in region to ordinary ASCII text."
8874 t)
8875
8876(defun gnus-summary-morse-message (&optional arg)
8877 "Morse decode the current article."
8878 (interactive "P")
8879 (gnus-summary-select-article)
8880 (let ((mail-header-separator ""))
8881 (gnus-eval-in-buffer-window gnus-article-buffer
8882 (save-excursion
8883 (save-restriction
8884 (widen)
8885 (let ((pos (window-start))
8886 buffer-read-only)
8887 (goto-char (point-min))
8888 (when (message-goto-body)
8889 (gnus-narrow-to-body))
8890 (goto-char (point-min))
8891