(tex-font-lock-match-suscript): Paren typo.
[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,
c4288669 4;; 2005, 2006 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
7cd9f860
CY
1003 (and user-mail-address
1004 (not (string= user-mail-address ""))
1005 (regexp-quote user-mail-address))
16409b0b 1006 "*Regexp of From headers that may be suppressed in favor of To headers."
58e39d05 1007 :version "21.1"
16409b0b
GM
1008 :group 'gnus-summary
1009 :type 'regexp)
1010
16409b0b
GM
1011(defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1012 "List of charsets that should be ignored.
1013When these charsets are used in the \"charset\" parameter, the
1014default charset will be used instead."
58e39d05 1015 :version "21.1"
16409b0b
GM
1016 :type '(repeat symbol)
1017 :group 'gnus-charset)
1018
23f87bed
MB
1019(gnus-define-group-parameter
1020 ignored-charsets
1021 :type list
1022 :function-document
1023 "Return the ignored charsets of GROUP."
1024 :variable gnus-group-ignored-charsets-alist
1025 :variable-default
1026 '(("alt\\.chinese\\.text" iso-8859-1))
1027 :variable-document
1028 "Alist of regexps (to match group names) and charsets that should be ignored.
16409b0b
GM
1029When these charsets are used in the \"charset\" parameter, the
1030default charset will be used instead."
23f87bed
MB
1031 :variable-group gnus-charset
1032 :variable-type '(repeat (cons (regexp :tag "Group")
1033 (repeat symbol)))
1034 :parameter-type '(choice :tag "Ignored charsets"
1035 :value nil
1036 (repeat (symbol)))
1037 :parameter-document "\
1038List of charsets that should be ignored.
1039
1040When these charsets are used in the \"charset\" parameter, the
1041default charset will be used instead.")
16409b0b
GM
1042
1043(defcustom gnus-group-highlight-words-alist nil
1044 "Alist of group regexps and highlight regexps.
1045This variable uses the same syntax as `gnus-emphasis-alist'."
58e39d05 1046 :version "21.1"
16409b0b
GM
1047 :type '(repeat (cons (regexp :tag "Group")
1048 (repeat (list (regexp :tag "Highlight regexp")
1049 (number :tag "Group for entire word" 0)
1050 (number :tag "Group for displayed part" 0)
1051 (symbol :tag "Face"
1052 gnus-emphasis-highlight-words)))))
1053 :group 'gnus-summary-visual)
1054
1055(defcustom gnus-summary-show-article-charset-alist
1056 nil
1057 "Alist of number and charset.
1058The article will be shown with the charset corresponding to the
1059numbered argument.
1060For example: ((1 . cn-gb-2312) (2 . big5))."
58e39d05 1061 :version "21.1"
16409b0b
GM
1062 :type '(repeat (cons (number :tag "Argument" 1)
1063 (symbol :tag "Charset")))
1064 :group 'gnus-charset)
1065
1066(defcustom gnus-preserve-marks t
1067 "Whether marks are preserved when moving, copying and respooling messages."
58e39d05 1068 :version "21.1"
16409b0b
GM
1069 :type 'boolean
1070 :group 'gnus-summary-marks)
1071
1072(defcustom gnus-alter-articles-to-read-function nil
1073 "Function to be called to alter the list of articles to be selected."
8fc7a9a1 1074 :type '(choice (const nil) function)
16409b0b
GM
1075 :group 'gnus-summary)
1076
1077(defcustom gnus-orphan-score nil
1078 "*All orphans get this score added. Set in the score file."
1079 :group 'gnus-score-default
1080 :type '(choice (const nil)
1081 integer))
1082
8b93df01 1083(defcustom gnus-summary-save-parts-default-mime "image/.*"
23f87bed
MB
1084 "*A regexp to match MIME parts when saving multiple parts of a
1085message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1086This regexp will be used by default when prompting the user for which
1087type of files to save."
8b93df01
DL
1088 :group 'gnus-summary
1089 :type 'regexp)
1090
23f87bed
MB
1091(defcustom gnus-read-all-available-headers nil
1092 "Whether Gnus should parse all headers made available to it.
1093This is mostly relevant for slow back ends where the user may
1094wish to widen the summary buffer to include all headers
1095that were fetched. Say, for nnultimate groups."
bf247b6e 1096 :version "22.1"
23f87bed
MB
1097 :group 'gnus-summary
1098 :type '(choice boolean regexp))
1099
1100(defcustom gnus-summary-muttprint-program "muttprint"
1101 "Command (and optional arguments) used to run Muttprint."
bf247b6e 1102 :version "22.1"
23f87bed
MB
1103 :group 'gnus-summary
1104 :type 'string)
1105
1106(defcustom gnus-article-loose-mime nil
1107 "If non-nil, don't require MIME-Version header.
1108Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
a08b59c9 1109supply the MIME-Version header or deliberately strip it from the mail.
23f87bed
MB
1110Set it to non-nil, Gnus will treat some articles as MIME even if
1111the MIME-Version header is missed."
bf247b6e 1112 :version "22.1"
23f87bed
MB
1113 :type 'boolean
1114 :group 'gnus-article-mime)
1115
1116(defcustom gnus-article-emulate-mime t
1117 "If non-nil, use MIME emulation for uuencode and the like.
1118This means that Gnus will search message bodies for text that look
1119like uuencoded bits, yEncoded bits, and so on, and present that using
1120the normal Gnus MIME machinery."
bf247b6e 1121 :version "22.1"
23f87bed
MB
1122 :type 'boolean
1123 :group 'gnus-article-mime)
8b93df01 1124
eec82323
LMI
1125;;; Internal variables
1126
23f87bed 1127(defvar gnus-summary-display-cache nil)
16409b0b
GM
1128(defvar gnus-article-mime-handles nil)
1129(defvar gnus-article-decoded-p nil)
23f87bed
MB
1130(defvar gnus-article-charset nil)
1131(defvar gnus-article-ignored-charsets nil)
eec82323
LMI
1132(defvar gnus-scores-exclude-files nil)
1133(defvar gnus-page-broken nil)
1134
1135(defvar gnus-original-article nil)
1136(defvar gnus-article-internal-prepare-hook nil)
1137(defvar gnus-newsgroup-process-stack nil)
1138
1139(defvar gnus-thread-indent-array nil)
1140(defvar gnus-thread-indent-array-level gnus-thread-indent-level)
16409b0b
GM
1141(defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1142 "Function called to sort the articles within a thread after it has been gathered together.")
eec82323 1143
8b93df01 1144(defvar gnus-summary-save-parts-type-history nil)
23f87bed 1145(defvar gnus-summary-save-parts-last-directory mm-default-directory)
8b93df01 1146
eec82323
LMI
1147;; Avoid highlighting in kill files.
1148(defvar gnus-summary-inhibit-highlight nil)
1149(defvar gnus-newsgroup-selected-overlay nil)
1150(defvar gnus-inhibit-limiting nil)
1151(defvar gnus-newsgroup-adaptive-score-file nil)
1152(defvar gnus-current-score-file nil)
1153(defvar gnus-current-move-group nil)
1154(defvar gnus-current-copy-group nil)
1155(defvar gnus-current-crosspost-group nil)
23f87bed 1156(defvar gnus-newsgroup-display nil)
eec82323
LMI
1157
1158(defvar gnus-newsgroup-dependencies nil)
1159(defvar gnus-newsgroup-adaptive nil)
1160(defvar gnus-summary-display-article-function nil)
1161(defvar gnus-summary-highlight-line-function nil
1162 "Function called after highlighting a summary line.")
1163
1164(defvar gnus-summary-line-format-alist
1165 `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1166 (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1167 (?s gnus-tmp-subject-or-nil ?s)
1168 (?n gnus-tmp-name ?s)
1169 (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1170 ?s)
1171 (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1172 gnus-tmp-from) ?s)
1173 (?F gnus-tmp-from ?s)
1174 (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1175 (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1176 (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
6748645f 1177 (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
eec82323
LMI
1178 (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1179 (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1180 (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
23f87bed
MB
1181 (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1182 (?L gnus-tmp-lines ?s)
1183 (?O gnus-tmp-downloaded ?c)
eec82323
LMI
1184 (?I gnus-tmp-indentation ?s)
1185 (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1186 (?R gnus-tmp-replied ?c)
1187 (?\[ gnus-tmp-opening-bracket ?c)
1188 (?\] gnus-tmp-closing-bracket ?c)
1189 (?\> (make-string gnus-tmp-level ? ) ?s)
1190 (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1191 (?i gnus-tmp-score ?d)
1192 (?z gnus-tmp-score-char ?c)
1193 (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1194 (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1195 (?U gnus-tmp-unread ?c)
23f87bed
MB
1196 (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1197 ?s)
eec82323
LMI
1198 (?t (gnus-summary-number-of-articles-in-thread
1199 (and (boundp 'thread) (car thread)) gnus-tmp-level)
1200 ?d)
1201 (?e (gnus-summary-number-of-articles-in-thread
1202 (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1203 ?c)
1204 (?u gnus-tmp-user-defined ?s)
23f87bed
MB
1205 (?P (gnus-pick-line-number) ?d)
1206 (?B gnus-tmp-thread-tree-header-string ?s)
1207 (user-date (gnus-user-date
1208 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
16409b0b
GM
1209 "An alist of format specifications that can appear in summary lines.
1210These are paired with what variables they correspond with, along with
1211the type of the variable (string, integer, character, etc).")
eec82323
LMI
1212
1213(defvar gnus-summary-dummy-line-format-alist
1214 `((?S gnus-tmp-subject ?s)
1215 (?N gnus-tmp-number ?d)
1216 (?u gnus-tmp-user-defined ?s)))
1217
1218(defvar gnus-summary-mode-line-format-alist
1219 `((?G gnus-tmp-group-name ?s)
1220 (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1221 (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1222 (?A gnus-tmp-article-number ?d)
1223 (?Z gnus-tmp-unread-and-unselected ?s)
1224 (?V gnus-version ?s)
1225 (?U gnus-tmp-unread-and-unticked ?d)
1226 (?S gnus-tmp-subject ?s)
1227 (?e gnus-tmp-unselected ?d)
1228 (?u gnus-tmp-user-defined ?s)
1229 (?d (length gnus-newsgroup-dormant) ?d)
1230 (?t (length gnus-newsgroup-marked) ?d)
23f87bed 1231 (?h (length gnus-newsgroup-spam-marked) ?d)
eec82323 1232 (?r (length gnus-newsgroup-reads) ?d)
6748645f 1233 (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
eec82323
LMI
1234 (?E gnus-newsgroup-expunged-tally ?d)
1235 (?s (gnus-current-score-file-nondirectory) ?s)))
1236
1237(defvar gnus-last-search-regexp nil
1238 "Default regexp for article search command.")
1239
1240(defvar gnus-last-shell-command nil
1241 "Default shell command on article.")
1242
23f87bed
MB
1243(defvar gnus-newsgroup-agentized nil
1244 "Locally bound in each summary buffer to indicate whether the server has been agentized.")
eec82323
LMI
1245(defvar gnus-newsgroup-begin nil)
1246(defvar gnus-newsgroup-end nil)
1247(defvar gnus-newsgroup-last-rmail nil)
1248(defvar gnus-newsgroup-last-mail nil)
1249(defvar gnus-newsgroup-last-folder nil)
1250(defvar gnus-newsgroup-last-file nil)
1251(defvar gnus-newsgroup-auto-expire nil)
1252(defvar gnus-newsgroup-active nil)
1253
1254(defvar gnus-newsgroup-data nil)
1255(defvar gnus-newsgroup-data-reverse nil)
1256(defvar gnus-newsgroup-limit nil)
1257(defvar gnus-newsgroup-limits nil)
23f87bed 1258(defvar gnus-summary-use-undownloaded-faces nil)
eec82323
LMI
1259
1260(defvar gnus-newsgroup-unreads nil
23f87bed 1261 "Sorted list of unread articles in the current newsgroup.")
eec82323
LMI
1262
1263(defvar gnus-newsgroup-unselected nil
23f87bed 1264 "Sorted list of unselected unread articles in the current newsgroup.")
eec82323
LMI
1265
1266(defvar gnus-newsgroup-reads nil
1267 "Alist of read articles and article marks in the current newsgroup.")
1268
1269(defvar gnus-newsgroup-expunged-tally nil)
1270
1271(defvar gnus-newsgroup-marked nil
23f87bed
MB
1272 "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1273
1274(defvar gnus-newsgroup-spam-marked nil
1275 "List of ranges of articles that have been marked as spam.")
eec82323
LMI
1276
1277(defvar gnus-newsgroup-killed nil
1278 "List of ranges of articles that have been through the scoring process.")
1279
1280(defvar gnus-newsgroup-cached nil
23f87bed 1281 "Sorted list of articles that come from the article cache.")
eec82323
LMI
1282
1283(defvar gnus-newsgroup-saved nil
1284 "List of articles that have been saved.")
1285
1286(defvar gnus-newsgroup-kill-headers nil)
1287
1288(defvar gnus-newsgroup-replied nil
1289 "List of articles that have been replied to in the current newsgroup.")
1290
23f87bed
MB
1291(defvar gnus-newsgroup-forwarded nil
1292 "List of articles that have been forwarded in the current newsgroup.")
1293
1294(defvar gnus-newsgroup-recent nil
1295 "List of articles that have are recent in the current newsgroup.")
1296
eec82323 1297(defvar gnus-newsgroup-expirable nil
23f87bed 1298 "Sorted list of articles in the current newsgroup that can be expired.")
eec82323
LMI
1299
1300(defvar gnus-newsgroup-processable nil
1301 "List of articles in the current newsgroup that can be processed.")
1302
6748645f 1303(defvar gnus-newsgroup-downloadable nil
23f87bed
MB
1304 "Sorted list of articles in the current newsgroup that can be processed.")
1305
1306(defvar gnus-newsgroup-unfetched nil
1307 "Sorted list of articles in the current newsgroup whose headers have
1308not been fetched into the agent.
1309
1310This list will always be a subset of gnus-newsgroup-undownloaded.")
6748645f
LMI
1311
1312(defvar gnus-newsgroup-undownloaded nil
23f87bed 1313 "List of articles in the current newsgroup that haven't been downloaded.")
6748645f
LMI
1314
1315(defvar gnus-newsgroup-unsendable nil
1316 "List of articles in the current newsgroup that won't be sent.")
1317
eec82323
LMI
1318(defvar gnus-newsgroup-bookmarks nil
1319 "List of articles in the current newsgroup that have bookmarks.")
1320
1321(defvar gnus-newsgroup-dormant nil
23f87bed
MB
1322 "Sorted list of dormant articles in the current newsgroup.")
1323
1324(defvar gnus-newsgroup-unseen nil
1325 "List of unseen articles in the current newsgroup.")
1326
1327(defvar gnus-newsgroup-seen nil
1328 "Range of seen articles in the current newsgroup.")
1329
1330(defvar gnus-newsgroup-articles nil
1331 "List of articles in the current newsgroup.")
eec82323
LMI
1332
1333(defvar gnus-newsgroup-scored nil
1334 "List of scored articles in the current newsgroup.")
1335
1336(defvar gnus-newsgroup-headers nil
1337 "List of article headers in the current newsgroup.")
1338
1339(defvar gnus-newsgroup-threads nil)
1340
1341(defvar gnus-newsgroup-prepared nil
1342 "Whether the current group has been prepared properly.")
1343
1344(defvar gnus-newsgroup-ancient nil
1345 "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1346
1347(defvar gnus-newsgroup-sparse nil)
1348
1349(defvar gnus-current-article nil)
1350(defvar gnus-article-current nil)
1351(defvar gnus-current-headers nil)
1352(defvar gnus-have-all-headers nil)
1353(defvar gnus-last-article nil)
1354(defvar gnus-newsgroup-history nil)
16409b0b
GM
1355(defvar gnus-newsgroup-charset nil)
1356(defvar gnus-newsgroup-ephemeral-charset nil)
1357(defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
eec82323 1358
23f87bed
MB
1359(defvar gnus-article-before-search nil)
1360
1361(defvar gnus-summary-local-variables
eec82323
LMI
1362 '(gnus-newsgroup-name
1363 gnus-newsgroup-begin gnus-newsgroup-end
1364 gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1365 gnus-newsgroup-last-folder gnus-newsgroup-last-file
1366 gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1367 gnus-newsgroup-unselected gnus-newsgroup-marked
23f87bed 1368 gnus-newsgroup-spam-marked
eec82323 1369 gnus-newsgroup-reads gnus-newsgroup-saved
23f87bed
MB
1370 gnus-newsgroup-replied gnus-newsgroup-forwarded
1371 gnus-newsgroup-recent
1372 gnus-newsgroup-expirable
eec82323 1373 gnus-newsgroup-processable gnus-newsgroup-killed
6748645f 1374 gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
23f87bed
MB
1375 gnus-newsgroup-unfetched
1376 gnus-newsgroup-unsendable gnus-newsgroup-unseen
1377 gnus-newsgroup-seen gnus-newsgroup-articles
eec82323
LMI
1378 gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1379 gnus-newsgroup-headers gnus-newsgroup-threads
1380 gnus-newsgroup-prepared gnus-summary-highlight-line-function
1381 gnus-current-article gnus-current-headers gnus-have-all-headers
1382 gnus-last-article gnus-article-internal-prepare-hook
1383 gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1384 gnus-newsgroup-scored gnus-newsgroup-kill-headers
1385 gnus-thread-expunge-below
16409b0b
GM
1386 gnus-score-alist gnus-current-score-file
1387 (gnus-summary-expunge-below . global)
eec82323 1388 (gnus-summary-mark-below . global)
16409b0b 1389 (gnus-orphan-score . global)
eec82323
LMI
1390 gnus-newsgroup-active gnus-scores-exclude-files
1391 gnus-newsgroup-history gnus-newsgroup-ancient
1392 gnus-newsgroup-sparse gnus-newsgroup-process-stack
1393 (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1394 gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1395 (gnus-newsgroup-expunged-tally . 0)
1396 gnus-cache-removable-articles gnus-newsgroup-cached
1397 gnus-newsgroup-data gnus-newsgroup-data-reverse
16409b0b 1398 gnus-newsgroup-limit gnus-newsgroup-limits
23f87bed
MB
1399 gnus-newsgroup-charset gnus-newsgroup-display
1400 gnus-summary-use-undownloaded-faces)
eec82323
LMI
1401 "Variables that are buffer-local to the summary buffers.")
1402
23f87bed
MB
1403(defvar gnus-newsgroup-variables nil
1404 "A list of variables that have separate values in different newsgroups.
1405A list of newsgroup (summary buffer) local variables, or cons of
1406variables and their default expressions to be evalled (when the default
1407values are not nil), that should be made global while the summary buffer
1408is active.
1409
1410Note: The default expressions will be evaluated (using function `eval')
1411before assignment to the local variable rather than just assigned to it.
1412If the default expression is the symbol `global', that symbol will not
1413be evaluated but the global value of the local variable will be used
1414instead.
1415
1416These variables can be used to set variables in the group parameters
1417while still allowing them to affect operations done in other buffers.
1418For example:
1419
1420\(setq gnus-newsgroup-variables
1421 '(message-use-followup-to
1422 (gnus-visible-headers .
1423 \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1424")
1425
eec82323 1426;; Byte-compiler warning.
23f87bed
MB
1427(eval-when-compile
1428 ;; Bind features so that require will believe that gnus-sum has
1429 ;; already been loaded (avoids infinite recursion)
1430 (let ((features (cons 'gnus-sum features)))
1431 ;; Several of the declarations in gnus-sum are needed to load the
1432 ;; following files. Right now, these definitions have been
1433 ;; compiled but not defined (evaluated). We could either do a
1434 ;; eval-and-compile about all of the declarations or evaluate the
1435 ;; source file.
1436 (if (boundp 'gnus-newsgroup-variables)
1437 nil
1438 (load "gnus-sum.el" t t t))
1439 (require 'gnus)
1440 (require 'gnus-agent)
1441 (require 'gnus-art)))
eec82323 1442
16409b0b
GM
1443;; MIME stuff.
1444
1445(defvar gnus-decode-encoded-word-methods
1446 '(mail-decode-encoded-word-string)
1447 "List of methods used to decode encoded words.
1448
23f87bed
MB
1449This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
1450is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
1451\(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
16409b0b
GM
1452whose names match REGEXP.
1453
1454For example:
23f87bed 1455\((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
16409b0b
GM
1456 mail-decode-encoded-word-string
1457 (\"chinese\" . rfc1843-decode-string))")
1458
1459(defvar gnus-decode-encoded-word-methods-cache nil)
1460
1461(defun gnus-multi-decode-encoded-word-string (string)
1462 "Apply the functions from `gnus-encoded-word-methods' that match."
1463 (unless (and gnus-decode-encoded-word-methods-cache
1464 (eq gnus-newsgroup-name
1465 (car gnus-decode-encoded-word-methods-cache)))
1466 (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1467 (mapcar (lambda (x)
1468 (if (symbolp x)
1469 (nconc gnus-decode-encoded-word-methods-cache (list x))
1470 (if (and gnus-newsgroup-name
1471 (string-match (car x) gnus-newsgroup-name))
1472 (nconc gnus-decode-encoded-word-methods-cache
1473 (list (cdr x))))))
23f87bed 1474 gnus-decode-encoded-word-methods))
16409b0b
GM
1475 (let ((xlist gnus-decode-encoded-word-methods-cache))
1476 (pop xlist)
1477 (while xlist
1478 (setq string (funcall (pop xlist) string))))
1479 string)
1480
eec82323
LMI
1481;; Subject simplification.
1482
6748645f 1483(defun gnus-simplify-whitespace (str)
16409b0b 1484 "Remove excessive whitespace from STR."
23f87bed
MB
1485 ;; Multiple spaces.
1486 (while (string-match "[ \t][ \t]+" str)
1487 (setq str (concat (substring str 0 (match-beginning 0))
1488 " "
1489 (substring str (match-end 0)))))
1490 ;; Leading spaces.
1491 (when (string-match "^[ \t]+" str)
1492 (setq str (substring str (match-end 0))))
1493 ;; Trailing spaces.
1494 (when (string-match "[ \t]+$" str)
1495 (setq str (substring str 0 (match-beginning 0))))
1496 str)
1497
1498(defun gnus-simplify-all-whitespace (str)
1499 "Remove all whitespace from STR."
1500 (while (string-match "[ \t\n]+" str)
1501 (setq str (replace-match "" nil nil str)))
1502 str)
6748645f 1503
eec82323
LMI
1504(defsubst gnus-simplify-subject-re (subject)
1505 "Remove \"Re:\" from subject lines."
23f87bed 1506 (if (string-match message-subject-re-regexp subject)
eec82323
LMI
1507 (substring subject (match-end 0))
1508 subject))
1509
1510(defun gnus-simplify-subject (subject &optional re-only)
1511 "Remove `Re:' and words in parentheses.
1512If RE-ONLY is non-nil, strip leading `Re:'s only."
1513 (let ((case-fold-search t)) ;Ignore case.
1514 ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1515 (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1516 (setq subject (substring subject (match-end 0))))
1517 ;; Remove uninteresting prefixes.
1518 (when (and (not re-only)
1519 gnus-simplify-ignored-prefixes
1520 (string-match gnus-simplify-ignored-prefixes subject))
1521 (setq subject (substring subject (match-end 0))))
1522 ;; Remove words in parentheses from end.
1523 (unless re-only
1524 (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1525 (setq subject (substring subject 0 (match-beginning 0)))))
1526 ;; Return subject string.
1527 subject))
1528
1529;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1530;; all whitespace.
1531(defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1532 (goto-char (point-min))
1533 (while (re-search-forward regexp nil t)
16409b0b 1534 (replace-match (or newtext ""))))
eec82323
LMI
1535
1536(defun gnus-simplify-buffer-fuzzy ()
1537 "Simplify string in the buffer fuzzily.
1538The string in the accessible portion of the current buffer is simplified.
1539It is assumed to be a single-line subject.
1540Whitespace is generally cleaned up, and miscellaneous leading/trailing
1541matter is removed. Additional things can be deleted by setting
16409b0b 1542`gnus-simplify-subject-fuzzy-regexp'."
eec82323
LMI
1543 (let ((case-fold-search t)
1544 (modified-tick))
1545 (gnus-simplify-buffer-fuzzy-step "\t" " ")
1546
1547 (while (not (eq modified-tick (buffer-modified-tick)))
1548 (setq modified-tick (buffer-modified-tick))
1549 (cond
1550 ((listp gnus-simplify-subject-fuzzy-regexp)
1551 (mapcar 'gnus-simplify-buffer-fuzzy-step
1552 gnus-simplify-subject-fuzzy-regexp))
1553 (gnus-simplify-subject-fuzzy-regexp
1554 (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1555 (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1556 (gnus-simplify-buffer-fuzzy-step
1557 "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1558 (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1559
1560 (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1561 (gnus-simplify-buffer-fuzzy-step " +" " ")
1562 (gnus-simplify-buffer-fuzzy-step " $")
1563 (gnus-simplify-buffer-fuzzy-step "^ +")))
1564
1565(defun gnus-simplify-subject-fuzzy (subject)
1566 "Simplify a subject string fuzzily.
6748645f 1567See `gnus-simplify-buffer-fuzzy' for details."
eec82323
LMI
1568 (save-excursion
1569 (gnus-set-work-buffer)
1570 (let ((case-fold-search t))
6748645f
LMI
1571 ;; Remove uninteresting prefixes.
1572 (when (and gnus-simplify-ignored-prefixes
1573 (string-match gnus-simplify-ignored-prefixes subject))
1574 (setq subject (substring subject (match-end 0))))
eec82323
LMI
1575 (insert subject)
1576 (inline (gnus-simplify-buffer-fuzzy))
1577 (buffer-string))))
1578
1579(defsubst gnus-simplify-subject-fully (subject)
23f87bed 1580 "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
eec82323 1581 (cond
6748645f
LMI
1582 (gnus-simplify-subject-functions
1583 (gnus-map-function gnus-simplify-subject-functions subject))
eec82323
LMI
1584 ((null gnus-summary-gather-subject-limit)
1585 (gnus-simplify-subject-re subject))
1586 ((eq gnus-summary-gather-subject-limit 'fuzzy)
1587 (gnus-simplify-subject-fuzzy subject))
1588 ((numberp gnus-summary-gather-subject-limit)
1589 (gnus-limit-string (gnus-simplify-subject-re subject)
1590 gnus-summary-gather-subject-limit))
1591 (t
1592 subject)))
1593
1594(defsubst gnus-subject-equal (s1 s2 &optional simple-first)
6748645f 1595 "Check whether two subjects are equal.
23f87bed 1596If optional argument SIMPLE-FIRST is t, first argument is already
6748645f 1597simplified."
eec82323
LMI
1598 (cond
1599 ((null simple-first)
1600 (equal (gnus-simplify-subject-fully s1)
1601 (gnus-simplify-subject-fully s2)))
1602 (t
1603 (equal s1
1604 (gnus-simplify-subject-fully s2)))))
1605
1606(defun gnus-summary-bubble-group ()
1607 "Increase the score of the current group.
1608This is a handy function to add to `gnus-summary-exit-hook' to
1609increase the score of each group you read."
1610 (gnus-group-add-score gnus-newsgroup-name))
1611
1612\f
1613;;;
1614;;; Gnus summary mode
1615;;;
1616
1617(put 'gnus-summary-mode 'mode-class 'special)
1618
1653df0f
SZ
1619(defvar gnus-article-commands-menu)
1620
23f87bed
MB
1621;; Non-orthogonal keys
1622
1623(gnus-define-keys gnus-summary-mode-map
1624 " " gnus-summary-next-page
1625 "\177" gnus-summary-prev-page
1626 [delete] gnus-summary-prev-page
1627 [backspace] gnus-summary-prev-page
1628 "\r" gnus-summary-scroll-up
1629 "\M-\r" gnus-summary-scroll-down
1630 "n" gnus-summary-next-unread-article
1631 "p" gnus-summary-prev-unread-article
1632 "N" gnus-summary-next-article
1633 "P" gnus-summary-prev-article
1634 "\M-\C-n" gnus-summary-next-same-subject
1635 "\M-\C-p" gnus-summary-prev-same-subject
1636 "\M-n" gnus-summary-next-unread-subject
1637 "\M-p" gnus-summary-prev-unread-subject
1638 "." gnus-summary-first-unread-article
1639 "," gnus-summary-best-unread-article
1640 "\M-s" gnus-summary-search-article-forward
1641 "\M-r" gnus-summary-search-article-backward
1642 "<" gnus-summary-beginning-of-article
1643 ">" gnus-summary-end-of-article
1644 "j" gnus-summary-goto-article
1645 "^" gnus-summary-refer-parent-article
1646 "\M-^" gnus-summary-refer-article
1647 "u" gnus-summary-tick-article-forward
1648 "!" gnus-summary-tick-article-forward
1649 "U" gnus-summary-tick-article-backward
1650 "d" gnus-summary-mark-as-read-forward
1651 "D" gnus-summary-mark-as-read-backward
1652 "E" gnus-summary-mark-as-expirable
1653 "\M-u" gnus-summary-clear-mark-forward
1654 "\M-U" gnus-summary-clear-mark-backward
1655 "k" gnus-summary-kill-same-subject-and-select
1656 "\C-k" gnus-summary-kill-same-subject
1657 "\M-\C-k" gnus-summary-kill-thread
1658 "\M-\C-l" gnus-summary-lower-thread
1659 "e" gnus-summary-edit-article
1660 "#" gnus-summary-mark-as-processable
1661 "\M-#" gnus-summary-unmark-as-processable
1662 "\M-\C-t" gnus-summary-toggle-threads
1663 "\M-\C-s" gnus-summary-show-thread
1664 "\M-\C-h" gnus-summary-hide-thread
1665 "\M-\C-f" gnus-summary-next-thread
1666 "\M-\C-b" gnus-summary-prev-thread
1667 [(meta down)] gnus-summary-next-thread
1668 [(meta up)] gnus-summary-prev-thread
1669 "\M-\C-u" gnus-summary-up-thread
1670 "\M-\C-d" gnus-summary-down-thread
1671 "&" gnus-summary-execute-command
1672 "c" gnus-summary-catchup-and-exit
1673 "\C-w" gnus-summary-mark-region-as-read
1674 "\C-t" gnus-summary-toggle-truncation
1675 "?" gnus-summary-mark-as-dormant
1676 "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1677 "\C-c\C-s\C-n" gnus-summary-sort-by-number
1678 "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1679 "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1680 "\C-c\C-s\C-a" gnus-summary-sort-by-author
1681 "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1682 "\C-c\C-s\C-d" gnus-summary-sort-by-date
1683 "\C-c\C-s\C-i" gnus-summary-sort-by-score
1684 "\C-c\C-s\C-o" gnus-summary-sort-by-original
1685 "\C-c\C-s\C-r" gnus-summary-sort-by-random
1686 "=" gnus-summary-expand-window
1687 "\C-x\C-s" gnus-summary-reselect-current-group
1688 "\M-g" gnus-summary-rescan-group
1689 "w" gnus-summary-stop-page-breaking
1690 "\C-c\C-r" gnus-summary-caesar-message
1691 "f" gnus-summary-followup
1692 "F" gnus-summary-followup-with-original
1693 "C" gnus-summary-cancel-article
1694 "r" gnus-summary-reply
1695 "R" gnus-summary-reply-with-original
1696 "\C-c\C-f" gnus-summary-mail-forward
1697 "o" gnus-summary-save-article
1698 "\C-o" gnus-summary-save-article-mail
1699 "|" gnus-summary-pipe-output
1700 "\M-k" gnus-summary-edit-local-kill
1701 "\M-K" gnus-summary-edit-global-kill
1702 ;; "V" gnus-version
1703 "\C-c\C-d" gnus-summary-describe-group
1704 "q" gnus-summary-exit
1705 "Q" gnus-summary-exit-no-update
1706 "\C-c\C-i" gnus-info-find-node
1707 gnus-mouse-2 gnus-mouse-pick-article
132cf96d 1708 [follow-link] mouse-face
23f87bed
MB
1709 "m" gnus-summary-mail-other-window
1710 "a" gnus-summary-post-news
1711 "i" gnus-summary-news-other-window
1712 "x" gnus-summary-limit-to-unread
1713 "s" gnus-summary-isearch-article
1714 "t" gnus-summary-toggle-header
1715 "g" gnus-summary-show-article
1716 "l" gnus-summary-goto-last-article
1717 "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1718 "\C-d" gnus-summary-enter-digest-group
1719 "\M-\C-d" gnus-summary-read-document
1720 "\M-\C-e" gnus-summary-edit-parameters
1721 "\M-\C-a" gnus-summary-customize-parameters
1722 "\C-c\C-b" gnus-bug
1723 "*" gnus-cache-enter-article
1724 "\M-*" gnus-cache-remove-article
1725 "\M-&" gnus-summary-universal-argument
1726 "\C-l" gnus-recenter
1727 "I" gnus-summary-increase-score
1728 "L" gnus-summary-lower-score
1729 "\M-i" gnus-symbolic-argument
1730 "h" gnus-summary-select-article-buffer
1731
1732 "b" gnus-article-view-part
1733 "\M-t" gnus-summary-toggle-display-buttonized
1734
1735 "V" gnus-summary-score-map
1736 "X" gnus-uu-extract-map
1737 "S" gnus-summary-send-map)
1738
1739;; Sort of orthogonal keymap
1740(gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1741 "t" gnus-summary-tick-article-forward
1742 "!" gnus-summary-tick-article-forward
1743 "d" gnus-summary-mark-as-read-forward
1744 "r" gnus-summary-mark-as-read-forward
1745 "c" gnus-summary-clear-mark-forward
1746 " " gnus-summary-clear-mark-forward
1747 "e" gnus-summary-mark-as-expirable
1748 "x" gnus-summary-mark-as-expirable
1749 "?" gnus-summary-mark-as-dormant
1750 "b" gnus-summary-set-bookmark
1751 "B" gnus-summary-remove-bookmark
1752 "#" gnus-summary-mark-as-processable
1753 "\M-#" gnus-summary-unmark-as-processable
1754 "S" gnus-summary-limit-include-expunged
1755 "C" gnus-summary-catchup
1756 "H" gnus-summary-catchup-to-here
1757 "h" gnus-summary-catchup-from-here
1758 "\C-c" gnus-summary-catchup-all
1759 "k" gnus-summary-kill-same-subject-and-select
1760 "K" gnus-summary-kill-same-subject
1761 "P" gnus-uu-mark-map)
1762
1763(gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1764 "c" gnus-summary-clear-above
1765 "u" gnus-summary-tick-above
1766 "m" gnus-summary-mark-above
1767 "k" gnus-summary-kill-below)
1768
1769(gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1770 "/" gnus-summary-limit-to-subject
1771 "n" gnus-summary-limit-to-articles
1772 "w" gnus-summary-pop-limit
1773 "s" gnus-summary-limit-to-subject
1774 "a" gnus-summary-limit-to-author
1775 "u" gnus-summary-limit-to-unread
1776 "m" gnus-summary-limit-to-marks
1777 "M" gnus-summary-limit-exclude-marks
1778 "v" gnus-summary-limit-to-score
1779 "*" gnus-summary-limit-include-cached
1780 "D" gnus-summary-limit-include-dormant
1781 "T" gnus-summary-limit-include-thread
1782 "d" gnus-summary-limit-exclude-dormant
1783 "t" gnus-summary-limit-to-age
1784 "." gnus-summary-limit-to-unseen
1785 "x" gnus-summary-limit-to-extra
1786 "p" gnus-summary-limit-to-display-predicate
1787 "E" gnus-summary-limit-include-expunged
1788 "c" gnus-summary-limit-exclude-childless-dormant
1789 "C" gnus-summary-limit-mark-excluded-as-read
1790 "o" gnus-summary-insert-old-articles
1791 "N" gnus-summary-insert-new-articles)
1792
1793(gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1794 "n" gnus-summary-next-unread-article
1795 "p" gnus-summary-prev-unread-article
1796 "N" gnus-summary-next-article
1797 "P" gnus-summary-prev-article
1798 "\C-n" gnus-summary-next-same-subject
1799 "\C-p" gnus-summary-prev-same-subject
1800 "\M-n" gnus-summary-next-unread-subject
1801 "\M-p" gnus-summary-prev-unread-subject
1802 "f" gnus-summary-first-unread-article
1803 "b" gnus-summary-best-unread-article
1804 "j" gnus-summary-goto-article
1805 "g" gnus-summary-goto-subject
1806 "l" gnus-summary-goto-last-article
1807 "o" gnus-summary-pop-article)
1808
1809(gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1810 "k" gnus-summary-kill-thread
1811 "l" gnus-summary-lower-thread
1812 "i" gnus-summary-raise-thread
1813 "T" gnus-summary-toggle-threads
1814 "t" gnus-summary-rethread-current
1815 "^" gnus-summary-reparent-thread
1816 "s" gnus-summary-show-thread
1817 "S" gnus-summary-show-all-threads
1818 "h" gnus-summary-hide-thread
1819 "H" gnus-summary-hide-all-threads
1820 "n" gnus-summary-next-thread
1821 "p" gnus-summary-prev-thread
1822 "u" gnus-summary-up-thread
1823 "o" gnus-summary-top-thread
1824 "d" gnus-summary-down-thread
1825 "#" gnus-uu-mark-thread
1826 "\M-#" gnus-uu-unmark-thread)
1827
1828(gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1829 "g" gnus-summary-prepare
1830 "c" gnus-summary-insert-cached-articles
1831 "d" gnus-summary-insert-dormant-articles)
1832
1833(gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1834 "c" gnus-summary-catchup-and-exit
1835 "C" gnus-summary-catchup-all-and-exit
1836 "E" gnus-summary-exit-no-update
1837 "Q" gnus-summary-exit
1838 "Z" gnus-summary-exit
1839 "n" gnus-summary-catchup-and-goto-next-group
1840 "R" gnus-summary-reselect-current-group
1841 "G" gnus-summary-rescan-group
1842 "N" gnus-summary-next-group
1843 "s" gnus-summary-save-newsrc
1844 "P" gnus-summary-prev-group)
1845
1846(gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1847 " " gnus-summary-next-page
1848 "n" gnus-summary-next-page
1849 "\177" gnus-summary-prev-page
1850 [delete] gnus-summary-prev-page
1851 "p" gnus-summary-prev-page
1852 "\r" gnus-summary-scroll-up
1853 "\M-\r" gnus-summary-scroll-down
1854 "<" gnus-summary-beginning-of-article
1855 ">" gnus-summary-end-of-article
1856 "b" gnus-summary-beginning-of-article
1857 "e" gnus-summary-end-of-article
1858 "^" gnus-summary-refer-parent-article
1859 "r" gnus-summary-refer-parent-article
1860 "D" gnus-summary-enter-digest-group
1861 "R" gnus-summary-refer-references
1862 "T" gnus-summary-refer-thread
1863 "g" gnus-summary-show-article
1864 "s" gnus-summary-isearch-article
1865 "P" gnus-summary-print-article
1866 "M" gnus-mailing-list-insinuate
1867 "t" gnus-article-babel)
1868
1869(gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1870 "b" gnus-article-add-buttons
1871 "B" gnus-article-add-buttons-to-head
1872 "o" gnus-article-treat-overstrike
1873 "e" gnus-article-emphasize
1874 "w" gnus-article-fill-cited-article
1875 "Q" gnus-article-fill-long-lines
1876 "C" gnus-article-capitalize-sentences
1877 "c" gnus-article-remove-cr
1878 "q" gnus-article-de-quoted-unreadable
1879 "6" gnus-article-de-base64-unreadable
1880 "Z" gnus-article-decode-HZ
1881 "h" gnus-article-wash-html
1882 "u" gnus-article-unsplit-urls
1883 "s" gnus-summary-force-verify-and-decrypt
1884 "f" gnus-article-display-x-face
1885 "l" gnus-summary-stop-page-breaking
1886 "r" gnus-summary-caesar-message
1887 "m" gnus-summary-morse-message
1888 "t" gnus-summary-toggle-header
1889 "g" gnus-treat-smiley
1890 "v" gnus-summary-verbose-headers
1891 "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1892 "p" gnus-article-verify-x-pgp-sig
1893 "d" gnus-article-treat-dumbquotes)
1894
1895(gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1896 ;; mnemonic: deuglif*Y*
1897 "u" gnus-article-outlook-unwrap-lines
1898 "a" gnus-article-outlook-repair-attribution
1899 "c" gnus-article-outlook-rearrange-citation
1900 "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1901
1902(gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1903 "a" gnus-article-hide
1904 "h" gnus-article-hide-headers
1905 "b" gnus-article-hide-boring-headers
1906 "s" gnus-article-hide-signature
1907 "c" gnus-article-hide-citation
1908 "C" gnus-article-hide-citation-in-followups
1909 "l" gnus-article-hide-list-identifiers
1910 "B" gnus-article-strip-banner
1911 "P" gnus-article-hide-pem
1912 "\C-c" gnus-article-hide-citation-maybe)
1913
1914(gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1915 "a" gnus-article-highlight
1916 "h" gnus-article-highlight-headers
1917 "c" gnus-article-highlight-citation
1918 "s" gnus-article-highlight-signature)
1919
1920(gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1921 "f" gnus-article-treat-fold-headers
1922 "u" gnus-article-treat-unfold-headers
1923 "n" gnus-article-treat-fold-newsgroups)
1924
1925(gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1926 "x" gnus-article-display-x-face
1927 "d" gnus-article-display-face
1928 "s" gnus-treat-smiley
1929 "D" gnus-article-remove-images
1930 "f" gnus-treat-from-picon
1931 "m" gnus-treat-mail-picon
1932 "n" gnus-treat-newsgroups-picon)
1933
1934(gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1935 "w" gnus-article-decode-mime-words
1936 "c" gnus-article-decode-charset
1937 "v" gnus-mime-view-all-parts
1938 "b" gnus-article-view-part)
1939
1940(gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1941 "z" gnus-article-date-ut
1942 "u" gnus-article-date-ut
1943 "l" gnus-article-date-local
1944 "p" gnus-article-date-english
1945 "e" gnus-article-date-lapsed
1946 "o" gnus-article-date-original
1947 "i" gnus-article-date-iso8601
1948 "s" gnus-article-date-user)
1949
1950(gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1951 "t" gnus-article-remove-trailing-blank-lines
1952 "l" gnus-article-strip-leading-blank-lines
1953 "m" gnus-article-strip-multiple-blank-lines
1954 "a" gnus-article-strip-blank-lines
1955 "A" gnus-article-strip-all-blank-lines
1956 "s" gnus-article-strip-leading-space
1957 "e" gnus-article-strip-trailing-space
1958 "w" gnus-article-remove-leading-whitespace)
1959
1960(gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1961 "v" gnus-version
1962 "f" gnus-summary-fetch-faq
1963 "d" gnus-summary-describe-group
1964 "h" gnus-summary-describe-briefly
1965 "i" gnus-info-find-node
1966 "c" gnus-group-fetch-charter
1967 "C" gnus-group-fetch-control)
1968
1969(gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1970 "e" gnus-summary-expire-articles
1971 "\M-\C-e" gnus-summary-expire-articles-now
1972 "\177" gnus-summary-delete-article
1973 [delete] gnus-summary-delete-article
1974 [backspace] gnus-summary-delete-article
1975 "m" gnus-summary-move-article
1976 "r" gnus-summary-respool-article
1977 "w" gnus-summary-edit-article
1978 "c" gnus-summary-copy-article
1979 "B" gnus-summary-crosspost-article
1980 "q" gnus-summary-respool-query
1981 "t" gnus-summary-respool-trace
1982 "i" gnus-summary-import-article
1983 "I" gnus-summary-create-article
1984 "p" gnus-summary-article-posted-p)
1985
1986(gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1987 "o" gnus-summary-save-article
1988 "m" gnus-summary-save-article-mail
1989 "F" gnus-summary-write-article-file
1990 "r" gnus-summary-save-article-rmail
1991 "f" gnus-summary-save-article-file
1992 "b" gnus-summary-save-article-body-file
1993 "h" gnus-summary-save-article-folder
1994 "v" gnus-summary-save-article-vm
1995 "p" gnus-summary-pipe-output
1996 "P" gnus-summary-muttprint
1997 "s" gnus-soup-add-article)
1998
1999(gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2000 "b" gnus-summary-display-buttonized
2001 "m" gnus-summary-repair-multipart
2002 "v" gnus-article-view-part
2003 "o" gnus-article-save-part
2004 "c" gnus-article-copy-part
2005 "C" gnus-article-view-part-as-charset
2006 "e" gnus-article-view-part-externally
2007 "E" gnus-article-encrypt-body
2008 "i" gnus-article-inline-part
2009 "|" gnus-article-pipe-part)
2010
2011(gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2012 "p" gnus-summary-mark-as-processable
2013 "u" gnus-summary-unmark-as-processable
2014 "U" gnus-summary-unmark-all-processable
2015 "v" gnus-uu-mark-over
2016 "s" gnus-uu-mark-series
2017 "r" gnus-uu-mark-region
2018 "g" gnus-uu-unmark-region
2019 "R" gnus-uu-mark-by-regexp
2020 "G" gnus-uu-unmark-by-regexp
2021 "t" gnus-uu-mark-thread
2022 "T" gnus-uu-unmark-thread
2023 "a" gnus-uu-mark-all
2024 "b" gnus-uu-mark-buffer
2025 "S" gnus-uu-mark-sparse
2026 "k" gnus-summary-kill-process-mark
2027 "y" gnus-summary-yank-process-mark
2028 "w" gnus-summary-save-process-mark
2029 "i" gnus-uu-invert-processable)
2030
2031(gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2032 ;;"x" gnus-uu-extract-any
2033 "m" gnus-summary-save-parts
2034 "u" gnus-uu-decode-uu
2035 "U" gnus-uu-decode-uu-and-save
2036 "s" gnus-uu-decode-unshar
2037 "S" gnus-uu-decode-unshar-and-save
2038 "o" gnus-uu-decode-save
2039 "O" gnus-uu-decode-save
2040 "b" gnus-uu-decode-binhex
2041 "B" gnus-uu-decode-binhex
2042 "p" gnus-uu-decode-postscript
2043 "P" gnus-uu-decode-postscript-and-save)
2044
2045(gnus-define-keys
2046 (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2047 "u" gnus-uu-decode-uu-view
2048 "U" gnus-uu-decode-uu-and-save-view
2049 "s" gnus-uu-decode-unshar-view
2050 "S" gnus-uu-decode-unshar-and-save-view
2051 "o" gnus-uu-decode-save-view
2052 "O" gnus-uu-decode-save-view
2053 "b" gnus-uu-decode-binhex-view
2054 "B" gnus-uu-decode-binhex-view
2055 "p" gnus-uu-decode-postscript-view
2056 "P" gnus-uu-decode-postscript-and-save-view)
2057
2058(defvar gnus-article-post-menu nil)
2059
2060(defconst gnus-summary-menu-maxlen 20)
2061
2062(defun gnus-summary-menu-split (menu)
2063 ;; If we have lots of elements, divide them into groups of 20
2064 ;; and make a pane (or submenu) for each one.
2065 (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2066 (let ((menu menu) sublists next
2067 (i 1))
2068 (while menu
2069 ;; Pull off the next gnus-summary-menu-maxlen elements
2070 ;; and make them the next element of sublist.
2071 (setq next (nthcdr gnus-summary-menu-maxlen menu))
2072 (if next
2073 (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2074 nil))
2075 (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2076 (aref (car (last menu)) 0)) menu)
2077 sublists))
2078 (setq i (1+ i))
2079 (setq menu next))
2080 (nreverse sublists))
2081 ;; Few elements--put them all in one pane.
2082 menu))
eec82323
LMI
2083
2084(defun gnus-summary-make-menu-bar ()
2085 (gnus-turn-off-edit-menu 'summary)
2086
2087 (unless (boundp 'gnus-summary-misc-menu)
2088
2089 (easy-menu-define
23f87bed
MB
2090 gnus-summary-kill-menu gnus-summary-mode-map ""
2091 (cons
2092 "Score"
2093 (nconc
2094 (list
2095 ["Customize" gnus-score-customize t])
2096 (gnus-make-score-map 'increase)
2097 (gnus-make-score-map 'lower)
2098 '(("Mark"
2099 ["Kill below" gnus-summary-kill-below t]
2100 ["Mark above" gnus-summary-mark-above t]
2101 ["Tick above" gnus-summary-tick-above t]
2102 ["Clear above" gnus-summary-clear-above t])
2103 ["Current score" gnus-summary-current-score t]
2104 ["Set score" gnus-summary-set-score t]
2105 ["Switch current score file..." gnus-score-change-score-file t]
2106 ["Set mark below..." gnus-score-set-mark-below t]
2107 ["Set expunge below..." gnus-score-set-expunge-below t]
2108 ["Edit current score file" gnus-score-edit-current-scores t]
2109 ["Edit score file" gnus-score-edit-file t]
2110 ["Trace score" gnus-score-find-trace t]
2111 ["Find words" gnus-score-find-favourite-words t]
2112 ["Rescore buffer" gnus-summary-rescore t]
2113 ["Increase score..." gnus-summary-increase-score t]
2114 ["Lower score..." gnus-summary-lower-score t]))))
2115
2116 ;; Define both the Article menu in the summary buffer and the
2117 ;; equivalent Commands menu in the article buffer here for
2118 ;; consistency.
6748645f 2119 (let ((innards
23f87bed
MB
2120 `(("Hide"
2121 ["All" gnus-article-hide t]
2122 ["Headers" gnus-article-hide-headers t]
2123 ["Signature" gnus-article-hide-signature t]
2124 ["Citation" gnus-article-hide-citation t]
16409b0b 2125 ["List identifiers" gnus-article-hide-list-identifiers t]
16409b0b 2126 ["Banner" gnus-article-strip-banner t]
23f87bed
MB
2127 ["Boring headers" gnus-article-hide-boring-headers t])
2128 ("Highlight"
2129 ["All" gnus-article-highlight t]
2130 ["Headers" gnus-article-highlight-headers t]
2131 ["Signature" gnus-article-highlight-signature t]
2132 ["Citation" gnus-article-highlight-citation t])
16409b0b
GM
2133 ("MIME"
2134 ["Words" gnus-article-decode-mime-words t]
2135 ["Charset" gnus-article-decode-charset t]
2136 ["QP" gnus-article-de-quoted-unreadable t]
2137 ["Base64" gnus-article-de-base64-unreadable t]
23f87bed
MB
2138 ["View MIME buttons" gnus-summary-display-buttonized t]
2139 ["View all" gnus-mime-view-all-parts t]
2140 ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2141 ["Encrypt body" gnus-article-encrypt-body
2142 :active (not (gnus-group-read-only-p))
2143 ,@(if (featurep 'xemacs) nil
2144 '(:help "Encrypt the message body on disk"))]
2145 ["Extract all parts..." gnus-summary-save-parts t]
2146 ("Multipart"
2147 ["Repair multipart" gnus-summary-repair-multipart t]
2148 ["Pipe part..." gnus-article-pipe-part t]
2149 ["Inline part" gnus-article-inline-part t]
2150 ["Encrypt body" gnus-article-encrypt-body
2151 :active (not (gnus-group-read-only-p))
2152 ,@(if (featurep 'xemacs) nil
2153 '(:help "Encrypt the message body on disk"))]
2154 ["View part externally" gnus-article-view-part-externally t]
2155 ["View part with charset..." gnus-article-view-part-as-charset t]
2156 ["Copy part" gnus-article-copy-part t]
2157 ["Save part..." gnus-article-save-part t]
2158 ["View part" gnus-article-view-part t]))
2159 ("Date"
2160 ["Local" gnus-article-date-local t]
2161 ["ISO8601" gnus-article-date-iso8601 t]
2162 ["UT" gnus-article-date-ut t]
2163 ["Original" gnus-article-date-original t]
2164 ["Lapsed" gnus-article-date-lapsed t]
2165 ["User-defined" gnus-article-date-user t])
2166 ("Display"
2167 ["Remove images" gnus-article-remove-images t]
2168 ["Toggle smiley" gnus-treat-smiley t]
2169 ["Show X-Face" gnus-article-display-x-face t]
2170 ["Show picons in From" gnus-treat-from-picon t]
2171 ["Show picons in mail headers" gnus-treat-mail-picon t]
2172 ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2173 ("View as different encoding"
2174 ,@(gnus-summary-menu-split
2175 (mapcar
2176 (lambda (cs)
2177 ;; Since easymenu under Emacs doesn't allow
2178 ;; lambda forms for menu commands, we should
2179 ;; provide intern'ed function symbols.
2180 (let ((command (intern (format "\
2181gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2182 (fset command
2183 `(lambda ()
2184 (interactive)
2185 (let ((gnus-summary-show-article-charset-alist
2186 '((1 . ,cs))))
2187 (gnus-summary-show-article 1))))
2188 `[,(symbol-name cs) ,command t]))
2189 (sort (if (fboundp 'coding-system-list)
2190 (coding-system-list)
2191 (mapcar 'car mm-mime-mule-charset-alist))
2192 'string<)))))
2193 ("Washing"
2194 ("Remove Blanks"
2195 ["Leading" gnus-article-strip-leading-blank-lines t]
2196 ["Multiple" gnus-article-strip-multiple-blank-lines t]
2197 ["Trailing" gnus-article-remove-trailing-blank-lines t]
2198 ["All of the above" gnus-article-strip-blank-lines t]
2199 ["All" gnus-article-strip-all-blank-lines t]
2200 ["Leading space" gnus-article-strip-leading-space t]
2201 ["Trailing space" gnus-article-strip-trailing-space t]
2202 ["Leading space in headers"
2203 gnus-article-remove-leading-whitespace t])
2204 ["Overstrike" gnus-article-treat-overstrike t]
2205 ["Dumb quotes" gnus-article-treat-dumbquotes t]
2206 ["Emphasis" gnus-article-emphasize t]
2207 ["Word wrap" gnus-article-fill-cited-article t]
16409b0b
GM
2208 ["Fill long lines" gnus-article-fill-long-lines t]
2209 ["Capitalize sentences" gnus-article-capitalize-sentences t]
23f87bed
MB
2210 ["Remove CR" gnus-article-remove-cr t]
2211 ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2212 ["Base64" gnus-article-de-base64-unreadable t]
2213 ["Rot 13" gnus-summary-caesar-message
2214 ,@(if (featurep 'xemacs) '(t)
2215 '(:help "\"Caesar rotate\" article by 13"))]
2216 ["Morse decode" gnus-summary-morse-message t]
2217 ["Unix pipe..." gnus-summary-pipe-message t]
2218 ["Add buttons" gnus-article-add-buttons t]
2219 ["Add buttons to head" gnus-article-add-buttons-to-head t]
2220 ["Stop page breaking" gnus-summary-stop-page-breaking t]
2221 ["Verbose header" gnus-summary-verbose-headers t]
2222 ["Toggle header" gnus-summary-toggle-header t]
2223 ["Unfold headers" gnus-article-treat-unfold-headers t]
2224 ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
16409b0b 2225 ["Html" gnus-article-wash-html t]
23f87bed
MB
2226 ["Unsplit URLs" gnus-article-unsplit-urls t]
2227 ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2228 ["Decode HZ" gnus-article-decode-HZ t]
2229 ("(Outlook) Deuglify"
2230 ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2231 ["Repair attribution" gnus-article-outlook-repair-attribution t]
2232 ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2233 ["Full (Outlook) deuglify"
2234 gnus-article-outlook-deuglify-article t])
2235 )
2236 ("Output"
2237 ["Save in default format..." gnus-summary-save-article
2238 ,@(if (featurep 'xemacs) '(t)
2239 '(:help "Save article using default method"))]
2240 ["Save in file..." gnus-summary-save-article-file
2241 ,@(if (featurep 'xemacs) '(t)
2242 '(:help "Save article in file"))]
2243 ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2244 ["Save in MH folder..." gnus-summary-save-article-folder t]
2245 ["Save in VM folder..." gnus-summary-save-article-vm t]
2246 ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2247 ["Save body in file..." gnus-summary-save-article-body-file t]
2248 ["Pipe through a filter..." gnus-summary-pipe-output t]
2249 ["Add to SOUP packet" gnus-soup-add-article t]
2250 ["Print with Muttprint..." gnus-summary-muttprint t]
531e5812
MB
2251 ["Print" gnus-summary-print-article
2252 ,@(if (featurep 'xemacs) '(t)
2253 '(:help "Generate and print a PostScript image"))])
2254 ("Copy, move,... (Backend)"
707f2b38 2255 ,@(if (featurep 'xemacs) nil
531e5812 2256 '(:help "Copying, moving, expiring articles..."))
23f87bed
MB
2257 ["Respool article..." gnus-summary-respool-article t]
2258 ["Move article..." gnus-summary-move-article
2259 (gnus-check-backend-function
2260 'request-move-article gnus-newsgroup-name)]
2261 ["Copy article..." gnus-summary-copy-article t]
2262 ["Crosspost article..." gnus-summary-crosspost-article
2263 (gnus-check-backend-function
2264 'request-replace-article gnus-newsgroup-name)]
2265 ["Import file..." gnus-summary-import-article
2266 (gnus-check-backend-function
2267 'request-accept-article gnus-newsgroup-name)]
2268 ["Create article..." gnus-summary-create-article
2269 (gnus-check-backend-function
2270 'request-accept-article gnus-newsgroup-name)]
2271 ["Check if posted" gnus-summary-article-posted-p t]
2272 ["Edit article" gnus-summary-edit-article
2273 (not (gnus-group-read-only-p))]
2274 ["Delete article" gnus-summary-delete-article
2275 (gnus-check-backend-function
2276 'request-expire-articles gnus-newsgroup-name)]
2277 ["Query respool" gnus-summary-respool-query t]
6748645f 2278 ["Trace respool" gnus-summary-respool-trace t]
23f87bed
MB
2279 ["Delete expirable articles" gnus-summary-expire-articles-now
2280 (gnus-check-backend-function
2281 'request-expire-articles gnus-newsgroup-name)])
2282 ("Extract"
2283 ["Uudecode" gnus-uu-decode-uu
2284 ,@(if (featurep 'xemacs) '(t)
2285 '(:help "Decode uuencoded article(s)"))]
2286 ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2287 ["Unshar" gnus-uu-decode-unshar t]
2288 ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2289 ["Save" gnus-uu-decode-save t]
2290 ["Binhex" gnus-uu-decode-binhex t]
2291 ["Postscript" gnus-uu-decode-postscript t]
2292 ["All MIME parts" gnus-summary-save-parts t])
2293 ("Cache"
2294 ["Enter article" gnus-cache-enter-article t]
2295 ["Remove article" gnus-cache-remove-article t])
16409b0b 2296 ["Translate" gnus-article-babel t]
23f87bed
MB
2297 ["Select article buffer" gnus-summary-select-article-buffer t]
2298 ["Enter digest buffer" gnus-summary-enter-digest-group t]
2299 ["Isearch article..." gnus-summary-isearch-article t]
2300 ["Beginning of the article" gnus-summary-beginning-of-article t]
2301 ["End of the article" gnus-summary-end-of-article t]
2302 ["Fetch parent of article" gnus-summary-refer-parent-article t]
2303 ["Fetch referenced articles" gnus-summary-refer-references t]
2304 ["Fetch current thread" gnus-summary-refer-thread t]
2305 ["Fetch article with id..." gnus-summary-refer-article t]
2306 ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2307 ["Redisplay" gnus-summary-show-article t]
2308 ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
6748645f 2309 (easy-menu-define
23f87bed
MB
2310 gnus-summary-article-menu gnus-summary-mode-map ""
2311 (cons "Article" innards))
6748645f 2312
1653df0f
SZ
2313 (if (not (keymapp gnus-summary-article-menu))
2314 (easy-menu-define
2315 gnus-article-commands-menu gnus-article-mode-map ""
2316 (cons "Commands" innards))
2317 ;; in Emacs, don't share menu.
a1506d29 2318 (setq gnus-article-commands-menu
1653df0f
SZ
2319 (copy-keymap gnus-summary-article-menu))
2320 (define-key gnus-article-mode-map [menu-bar commands]
2321 (cons "Commands" gnus-article-commands-menu))))
eec82323
LMI
2322
2323 (easy-menu-define
23f87bed
MB
2324 gnus-summary-thread-menu gnus-summary-mode-map ""
2325 '("Threads"
2326 ["Find all messages in thread" gnus-summary-refer-thread t]
2327 ["Toggle threading" gnus-summary-toggle-threads t]
2328 ["Hide threads" gnus-summary-hide-all-threads t]
2329 ["Show threads" gnus-summary-show-all-threads t]
2330 ["Hide thread" gnus-summary-hide-thread t]
2331 ["Show thread" gnus-summary-show-thread t]
2332 ["Go to next thread" gnus-summary-next-thread t]
2333 ["Go to previous thread" gnus-summary-prev-thread t]
2334 ["Go down thread" gnus-summary-down-thread t]
2335 ["Go up thread" gnus-summary-up-thread t]
2336 ["Top of thread" gnus-summary-top-thread t]
2337 ["Mark thread as read" gnus-summary-kill-thread t]
2338 ["Lower thread score" gnus-summary-lower-thread t]
2339 ["Raise thread score" gnus-summary-raise-thread t]
2340 ["Rethread current" gnus-summary-rethread-current t]))
eec82323
LMI
2341
2342 (easy-menu-define
23f87bed
MB
2343 gnus-summary-post-menu gnus-summary-mode-map ""
2344 `("Post"
2345 ["Send a message (mail or news)" gnus-summary-post-news
2346 ,@(if (featurep 'xemacs) '(t)
531e5812 2347 '(:help "Compose a new message (mail or news)"))]
23f87bed
MB
2348 ["Followup" gnus-summary-followup
2349 ,@(if (featurep 'xemacs) '(t)
2350 '(:help "Post followup to this article"))]
2351 ["Followup and yank" gnus-summary-followup-with-original
2352 ,@(if (featurep 'xemacs) '(t)
2353 '(:help "Post followup to this article, quoting its contents"))]
2354 ["Supersede article" gnus-summary-supersede-article t]
2355 ["Cancel article" gnus-summary-cancel-article
2356 ,@(if (featurep 'xemacs) '(t)
2357 '(:help "Cancel an article you posted"))]
2358 ["Reply" gnus-summary-reply t]
2359 ["Reply and yank" gnus-summary-reply-with-original t]
2360 ["Wide reply" gnus-summary-wide-reply t]
2361 ["Wide reply and yank" gnus-summary-wide-reply-with-original
2362 ,@(if (featurep 'xemacs) '(t)
2363 '(:help "Mail a reply, quoting this article"))]
2364 ["Very wide reply" gnus-summary-very-wide-reply t]
2365 ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2366 ,@(if (featurep 'xemacs) '(t)
2367 '(:help "Mail a very wide reply, quoting this article"))]
2368 ["Mail forward" gnus-summary-mail-forward t]
2369 ["Post forward" gnus-summary-post-forward t]
2370 ["Digest and mail" gnus-uu-digest-mail-forward t]
2371 ["Digest and post" gnus-uu-digest-post-forward t]
2372 ["Resend message" gnus-summary-resend-message t]
2373 ["Resend message edit" gnus-summary-resend-message-edit t]
2374 ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2375 ["Send a mail" gnus-summary-mail-other-window t]
2376 ["Create a local message" gnus-summary-news-other-window t]
2377 ["Uuencode and post" gnus-uu-post-news
2378 ,@(if (featurep 'xemacs) '(t)
2379 '(:help "Post a uuencoded article"))]
2380 ["Followup via news" gnus-summary-followup-to-mail t]
2381 ["Followup via news and yank"
2382 gnus-summary-followup-to-mail-with-original t]
2383 ;;("Draft"
2384 ;;["Send" gnus-summary-send-draft t]
2385 ;;["Send bounced" gnus-resend-bounced-mail t])
2386 ))
2387
2388 (cond
2389 ((not (keymapp gnus-summary-post-menu))
2390 (setq gnus-article-post-menu gnus-summary-post-menu))
2391 ((not gnus-article-post-menu)
2392 ;; Don't share post menu.
2393 (setq gnus-article-post-menu
2394 (copy-keymap gnus-summary-post-menu))))
2395 (define-key gnus-article-mode-map [menu-bar post]
2396 (cons "Post" gnus-article-post-menu))
eec82323
LMI
2397
2398 (easy-menu-define
23f87bed
MB
2399 gnus-summary-misc-menu gnus-summary-mode-map ""
2400 `("Gnus"
2401 ("Mark Read"
2402 ["Mark as read" gnus-summary-mark-as-read-forward t]
2403 ["Mark same subject and select"
2404 gnus-summary-kill-same-subject-and-select t]
2405 ["Mark same subject" gnus-summary-kill-same-subject t]
2406 ["Catchup" gnus-summary-catchup
2407 ,@(if (featurep 'xemacs) '(t)
2408 '(:help "Mark unread articles in this group as read"))]
2409 ["Catchup all" gnus-summary-catchup-all t]
2410 ["Catchup to here" gnus-summary-catchup-to-here t]
2411 ["Catchup from here" gnus-summary-catchup-from-here t]
2412 ["Catchup region" gnus-summary-mark-region-as-read
2413 (gnus-mark-active-p)]
2414 ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2415 ("Mark Various"
2416 ["Tick" gnus-summary-tick-article-forward t]
2417 ["Mark as dormant" gnus-summary-mark-as-dormant t]
2418 ["Remove marks" gnus-summary-clear-mark-forward t]
2419 ["Set expirable mark" gnus-summary-mark-as-expirable t]
2420 ["Set bookmark" gnus-summary-set-bookmark t]
2421 ["Remove bookmark" gnus-summary-remove-bookmark t])
2422 ("Limit to"
2423 ["Marks..." gnus-summary-limit-to-marks t]
2424 ["Subject..." gnus-summary-limit-to-subject t]
2425 ["Author..." gnus-summary-limit-to-author t]
2426 ["Age..." gnus-summary-limit-to-age t]
2427 ["Extra..." gnus-summary-limit-to-extra t]
2428 ["Score..." gnus-summary-limit-to-score t]
2429 ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2430 ["Unread" gnus-summary-limit-to-unread t]
2431 ["Unseen" gnus-summary-limit-to-unseen t]
2432 ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2433 ["Next articles" gnus-summary-limit-to-articles t]
2434 ["Pop limit" gnus-summary-pop-limit t]
2435 ["Show dormant" gnus-summary-limit-include-dormant t]
2436 ["Hide childless dormant"
2437 gnus-summary-limit-exclude-childless-dormant t]
2438 ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2439 ["Hide marked" gnus-summary-limit-exclude-marks t]
2440 ["Show expunged" gnus-summary-limit-include-expunged t])
2441 ("Process Mark"
2442 ["Set mark" gnus-summary-mark-as-processable t]
2443 ["Remove mark" gnus-summary-unmark-as-processable t]
2444 ["Remove all marks" gnus-summary-unmark-all-processable t]
2445 ["Mark above" gnus-uu-mark-over t]
2446 ["Mark series" gnus-uu-mark-series t]
2447 ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2448 ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2449 ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2450 ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2451 ["Mark all" gnus-uu-mark-all t]
2452 ["Mark buffer" gnus-uu-mark-buffer t]
2453 ["Mark sparse" gnus-uu-mark-sparse t]
2454 ["Mark thread" gnus-uu-mark-thread t]
2455 ["Unmark thread" gnus-uu-unmark-thread t]
2456 ("Process Mark Sets"
2457 ["Kill" gnus-summary-kill-process-mark t]
2458 ["Yank" gnus-summary-yank-process-mark
2459 gnus-newsgroup-process-stack]
2460 ["Save" gnus-summary-save-process-mark t]
2461 ["Run command on marked..." gnus-summary-universal-argument t]))
2462 ("Scroll article"
2463 ["Page forward" gnus-summary-next-page
2464 ,@(if (featurep 'xemacs) '(t)
2465 '(:help "Show next page of article"))]
2466 ["Page backward" gnus-summary-prev-page
2467 ,@(if (featurep 'xemacs) '(t)
2468 '(:help "Show previous page of article"))]
2469 ["Line forward" gnus-summary-scroll-up t])
2470 ("Move"
2471 ["Next unread article" gnus-summary-next-unread-article t]
2472 ["Previous unread article" gnus-summary-prev-unread-article t]
2473 ["Next article" gnus-summary-next-article t]
2474 ["Previous article" gnus-summary-prev-article t]
2475 ["Next unread subject" gnus-summary-next-unread-subject t]
2476 ["Previous unread subject" gnus-summary-prev-unread-subject t]
2477 ["Next article same subject" gnus-summary-next-same-subject t]
2478 ["Previous article same subject" gnus-summary-prev-same-subject t]
2479 ["First unread article" gnus-summary-first-unread-article t]
2480 ["Best unread article" gnus-summary-best-unread-article t]
2481 ["Go to subject number..." gnus-summary-goto-subject t]
2482 ["Go to article number..." gnus-summary-goto-article t]
2483 ["Go to the last article" gnus-summary-goto-last-article t]
2484 ["Pop article off history" gnus-summary-pop-article t])
2485 ("Sort"
2486 ["Sort by number" gnus-summary-sort-by-number t]
2487 ["Sort by author" gnus-summary-sort-by-author t]
2488 ["Sort by subject" gnus-summary-sort-by-subject t]
2489 ["Sort by date" gnus-summary-sort-by-date t]
2490 ["Sort by score" gnus-summary-sort-by-score t]
2491 ["Sort by lines" gnus-summary-sort-by-lines t]
2492 ["Sort by characters" gnus-summary-sort-by-chars t]
2493 ["Randomize" gnus-summary-sort-by-random t]
2494 ["Original sort" gnus-summary-sort-by-original t])
2495 ("Help"
2496 ["Fetch group FAQ" gnus-summary-fetch-faq t]
2497 ["Describe group" gnus-summary-describe-group t]
2498 ["Fetch charter" gnus-group-fetch-charter
2499 ,@(if (featurep 'xemacs) nil
2500 '(:help "Display the charter of the current group"))]
2501 ["Fetch control message" gnus-group-fetch-control
2502 ,@(if (featurep 'xemacs) nil
2503 '(:help "Display the archived control message for the current group"))]
2504 ["Read manual" gnus-info-find-node t])
2505 ("Modes"
2506 ["Pick and read" gnus-pick-mode t]
2507 ["Binary" gnus-binary-mode t])
2508 ("Regeneration"
2509 ["Regenerate" gnus-summary-prepare t]
2510 ["Insert cached articles" gnus-summary-insert-cached-articles t]
2511 ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2512 ["Toggle threading" gnus-summary-toggle-threads t])
2513 ["See old articles" gnus-summary-insert-old-articles t]
2514 ["See new articles" gnus-summary-insert-new-articles t]
2515 ["Filter articles..." gnus-summary-execute-command t]
2516 ["Run command on articles..." gnus-summary-universal-argument t]
2517 ["Search articles forward..." gnus-summary-search-article-forward t]
2518 ["Search articles backward..." gnus-summary-search-article-backward t]
2519 ["Toggle line truncation" gnus-summary-toggle-truncation t]
2520 ["Expand window" gnus-summary-expand-window t]
2521 ["Expire expirable articles" gnus-summary-expire-articles
2522 (gnus-check-backend-function
2523 'request-expire-articles gnus-newsgroup-name)]
2524 ["Edit local kill file" gnus-summary-edit-local-kill t]
2525 ["Edit main kill file" gnus-summary-edit-global-kill t]
2526 ["Edit group parameters" gnus-summary-edit-parameters t]
2527 ["Customize group parameters" gnus-summary-customize-parameters t]
2528 ["Send a bug report" gnus-bug t]
2529 ("Exit"
2530 ["Catchup and exit" gnus-summary-catchup-and-exit
2531 ,@(if (featurep 'xemacs) '(t)
2532 '(:help "Mark unread articles in this group as read, then exit"))]
2533 ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2534 ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2535 ["Exit group" gnus-summary-exit
2536 ,@(if (featurep 'xemacs) '(t)
2537 '(:help "Exit current group, return to group selection mode"))]
2538 ["Exit group without updating" gnus-summary-exit-no-update t]
2539 ["Exit and goto next group" gnus-summary-next-group t]
2540 ["Exit and goto prev group" gnus-summary-prev-group t]
2541 ["Reselect group" gnus-summary-reselect-current-group t]
2542 ["Rescan group" gnus-summary-rescan-group t]
2543 ["Update dribble" gnus-summary-save-newsrc t])))
eec82323 2544
6748645f 2545 (gnus-run-hooks 'gnus-summary-menu-hook)))
eec82323 2546
60bd5589
DL
2547(defvar gnus-summary-tool-bar-map nil)
2548
9a0026a6 2549;; Emacs 21 tool bar. Should be no-op otherwise.
60bd5589 2550(defun gnus-summary-make-tool-bar ()
23f87bed
MB
2551 (if (and (fboundp 'tool-bar-add-item-from-menu)
2552 (default-value 'tool-bar-mode)
2553 (not gnus-summary-tool-bar-map))
60bd5589 2554 (setq gnus-summary-tool-bar-map
23f87bed
MB
2555 (let ((tool-bar-map (make-sparse-keymap))
2556 (load-path (mm-image-load-path)))
60bd5589
DL
2557 (tool-bar-add-item-from-menu
2558 'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2559 (tool-bar-add-item-from-menu
2560 'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2561 (tool-bar-add-item-from-menu
2562 'gnus-summary-post-news "post" gnus-summary-mode-map)
2563 (tool-bar-add-item-from-menu
2564 'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2565 (tool-bar-add-item-from-menu
2566 'gnus-summary-followup "followup" gnus-summary-mode-map)
2567 (tool-bar-add-item-from-menu
2568 'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2569 (tool-bar-add-item-from-menu
2570 'gnus-summary-reply "reply" gnus-summary-mode-map)
2571 (tool-bar-add-item-from-menu
2572 'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2573 (tool-bar-add-item-from-menu
2574 'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2575 (tool-bar-add-item-from-menu
2576 'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2577 (tool-bar-add-item-from-menu
2578 'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2579 (tool-bar-add-item-from-menu
2580 'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2581 (tool-bar-add-item-from-menu
2582 'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2583 (tool-bar-add-item-from-menu
2584 'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2585 (tool-bar-add-item-from-menu
2586 'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2587 tool-bar-map)))
2588 (if gnus-summary-tool-bar-map
2589 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2590
eec82323
LMI
2591(defun gnus-score-set-default (var value)
2592 "A version of set that updates the GNU Emacs menu-bar."
2593 (set var value)
2594 ;; It is the message that forces the active status to be updated.
2595 (message ""))
2596
2597(defun gnus-make-score-map (type)
2598 "Make a summary score map of type TYPE."
2599 (if t
2600 nil
2601 (let ((headers '(("author" "from" string)
2602 ("subject" "subject" string)
2603 ("article body" "body" string)
2604 ("article head" "head" string)
2605 ("xref" "xref" string)
16409b0b 2606 ("extra header" "extra" string)
eec82323
LMI
2607 ("lines" "lines" number)
2608 ("followups to author" "followup" string)))
2609 (types '((number ("less than" <)
2610 ("greater than" >)
2611 ("equal" =))
2612 (string ("substring" s)
2613 ("exact string" e)
2614 ("fuzzy string" f)
2615 ("regexp" r))))
2616 (perms '(("temporary" (current-time-string))
2617 ("permanent" nil)
2618 ("immediate" now)))
2619 header)
2620 (list
2621 (apply
2622 'nconc
2623 (list
2624 (if (eq type 'lower)
2625 "Lower score"
2626 "Increase score"))
2627 (let (outh)
2628 (while headers
2629 (setq header (car headers))
2630 (setq outh
2631 (cons
2632 (apply
2633 'nconc
2634 (list (car header))
2635 (let ((ts (cdr (assoc (nth 2 header) types)))
2636 outt)
2637 (while ts
2638 (setq outt
2639 (cons
2640 (apply
2641 'nconc
2642 (list (caar ts))
2643 (let ((ps perms)
2644 outp)
2645 (while ps
2646 (setq outp
2647 (cons
2648 (vector
2649 (caar ps)
2650 (list
2651 'gnus-summary-score-entry
2652 (nth 1 header)
2653 (if (or (string= (nth 1 header)
2654 "head")
2655 (string= (nth 1 header)
2656 "body"))
2657 ""
2658 (list 'gnus-summary-header
2659 (nth 1 header)))
2660 (list 'quote (nth 1 (car ts)))
16409b0b
GM
2661 (list 'gnus-score-delta-default
2662 nil)
eec82323
LMI
2663 (nth 1 (car ps))
2664 t)
2665 t)
2666 outp))
2667 (setq ps (cdr ps)))
2668 (list (nreverse outp))))
2669 outt))
2670 (setq ts (cdr ts)))
2671 (list (nreverse outt))))
2672 outh))
2673 (setq headers (cdr headers)))
2674 (list (nreverse outh))))))))
2675
2676\f
2677
2678(defun gnus-summary-mode (&optional group)
2679 "Major mode for reading articles.
2680
2681All normal editing commands are switched off.
2682\\<gnus-summary-mode-map>
2683Each line in this buffer represents one article. To read an
2684article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
2685and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2686respectively.
2687
2688You can also post articles and send mail from this buffer. To
23f87bed 2689follow up an article, type `\\[gnus-summary-followup]'. To mail a reply to the author
eec82323
LMI
2690of an article, type `\\[gnus-summary-reply]'.
2691
2692There are approx. one gazillion commands you can execute in this
2693buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2694
2695The following commands are available:
2696
2697\\{gnus-summary-mode-map}"
2698 (interactive)
eec82323 2699 (kill-all-local-variables)
60bd5589
DL
2700 (when (gnus-visual-p 'summary-menu 'menu)
2701 (gnus-summary-make-menu-bar)
2702 (gnus-summary-make-tool-bar))
eec82323 2703 (gnus-summary-make-local-variables)
23f87bed
MB
2704 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2705 (gnus-summary-make-local-variables))
eec82323
LMI
2706 (gnus-make-thread-indent-array)
2707 (gnus-simplify-mode-line)
2708 (setq major-mode 'gnus-summary-mode)
2709 (setq mode-name "Summary")
2710 (make-local-variable 'minor-mode-alist)
2711 (use-local-map gnus-summary-mode-map)
16409b0b 2712 (buffer-disable-undo)
eec82323
LMI
2713 (setq buffer-read-only t) ;Disable modification
2714 (setq truncate-lines t)
2715 (setq selective-display t)
2716 (setq selective-display-ellipses t) ;Display `...'
2717 (gnus-summary-set-display-table)
2718 (gnus-set-default-directory)
2719 (setq gnus-newsgroup-name group)
2720 (make-local-variable 'gnus-summary-line-format)
2721 (make-local-variable 'gnus-summary-line-format-spec)
6748645f
LMI
2722 (make-local-variable 'gnus-summary-dummy-line-format)
2723 (make-local-variable 'gnus-summary-dummy-line-format-spec)
eec82323 2724 (make-local-variable 'gnus-summary-mark-positions)
23f87bed 2725 (gnus-make-local-hook 'pre-command-hook)
6748645f 2726 (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
cfcd5c91 2727 (gnus-run-mode-hooks 'gnus-summary-mode-hook)
23f87bed 2728 (turn-on-gnus-mailing-list-mode)
87545352 2729 (mm-enable-multibyte)
eec82323
LMI
2730 (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2731 (gnus-update-summary-mark-positions))
2732
2733(defun gnus-summary-make-local-variables ()
2734 "Make all the local summary buffer variables."
16409b0b
GM
2735 (let (global)
2736 (dolist (local gnus-summary-local-variables)
eec82323
LMI
2737 (if (consp local)
2738 (progn
2739 (if (eq (cdr local) 'global)
2740 ;; Copy the global value of the variable.
2741 (setq global (symbol-value (car local)))
2742 ;; Use the value from the list.
2743 (setq global (eval (cdr local))))
16409b0b 2744 (set (make-local-variable (car local)) global))
eec82323 2745 ;; Simple nil-valued local variable.
16409b0b 2746 (set (make-local-variable local) nil)))))
eec82323
LMI
2747
2748(defun gnus-summary-clear-local-variables ()
2749 (let ((locals gnus-summary-local-variables))
2750 (while locals
2751 (if (consp (car locals))
2752 (and (vectorp (caar locals))
2753 (set (caar locals) nil))
2754 (and (vectorp (car locals))
2755 (set (car locals) nil)))
2756 (setq locals (cdr locals)))))
2757
2758;; Summary data functions.
2759
2760(defmacro gnus-data-number (data)
2761 `(car ,data))
2762
2763(defmacro gnus-data-set-number (data number)
2764 `(setcar ,data ,number))
2765
2766(defmacro gnus-data-mark (data)
2767 `(nth 1 ,data))
2768
2769(defmacro gnus-data-set-mark (data mark)
2770 `(setcar (nthcdr 1 ,data) ,mark))
2771
2772(defmacro gnus-data-pos (data)
2773 `(nth 2 ,data))
2774
2775(defmacro gnus-data-set-pos (data pos)
2776 `(setcar (nthcdr 2 ,data) ,pos))
2777
2778(defmacro gnus-data-header (data)
2779 `(nth 3 ,data))
2780
2781(defmacro gnus-data-set-header (data header)
2782 `(setf (nth 3 ,data) ,header))
2783
2784(defmacro gnus-data-level (data)
2785 `(nth 4 ,data))
2786
2787(defmacro gnus-data-unread-p (data)
2788 `(= (nth 1 ,data) gnus-unread-mark))
2789
2790(defmacro gnus-data-read-p (data)
2791 `(/= (nth 1 ,data) gnus-unread-mark))
2792
2793(defmacro gnus-data-pseudo-p (data)
2794 `(consp (nth 3 ,data)))
2795
2796(defmacro gnus-data-find (number)
2797 `(assq ,number gnus-newsgroup-data))
2798
2799(defmacro gnus-data-find-list (number &optional data)
2800 `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2801 (memq (assq ,number bdata)
2802 bdata)))
2803
2804(defmacro gnus-data-make (number mark pos header level)
2805 `(list ,number ,mark ,pos ,header ,level))
2806
2807(defun gnus-data-enter (after-article number mark pos header level offset)
2808 (let ((data (gnus-data-find-list after-article)))
2809 (unless data
2810 (error "No such article: %d" after-article))
2811 (setcdr data (cons (gnus-data-make number mark pos header level)
2812 (cdr data)))
2813 (setq gnus-newsgroup-data-reverse nil)
2814 (gnus-data-update-list (cddr data) offset)))
2815
2816(defun gnus-data-enter-list (after-article list &optional offset)
2817 (when list
2818 (let ((data (and after-article (gnus-data-find-list after-article)))
2819 (ilist list))
6748645f
LMI
2820 (if (not (or data
2821 after-article))
2822 (let ((odata gnus-newsgroup-data))
2823 (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
eec82323 2824 (when offset
6748645f 2825 (gnus-data-update-list odata offset)))
23f87bed 2826 ;; Find the last element in the list to be spliced into the main
6748645f
LMI
2827 ;; list.
2828 (while (cdr list)
2829 (setq list (cdr list)))
2830 (if (not data)
2831 (progn
2832 (setcdr list gnus-newsgroup-data)
2833 (setq gnus-newsgroup-data ilist)
2834 (when offset
2835 (gnus-data-update-list (cdr list) offset)))
2836 (setcdr list (cdr data))
2837 (setcdr data ilist)
2838 (when offset
2839 (gnus-data-update-list (cdr list) offset))))
eec82323
LMI
2840 (setq gnus-newsgroup-data-reverse nil))))
2841
2842(defun gnus-data-remove (article &optional offset)
2843 (let ((data gnus-newsgroup-data))
2844 (if (= (gnus-data-number (car data)) article)
2845 (progn
2846 (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2847 gnus-newsgroup-data-reverse nil)
2848 (when offset
2849 (gnus-data-update-list gnus-newsgroup-data offset)))
2850 (while (cdr data)
2851 (when (= (gnus-data-number (cadr data)) article)
2852 (setcdr data (cddr data))
2853 (when offset
2854 (gnus-data-update-list (cdr data) offset))
2855 (setq data nil
2856 gnus-newsgroup-data-reverse nil))
2857 (setq data (cdr data))))))
2858
2859(defmacro gnus-data-list (backward)
2860 `(if ,backward
2861 (or gnus-newsgroup-data-reverse
2862 (setq gnus-newsgroup-data-reverse
2863 (reverse gnus-newsgroup-data)))
2864 gnus-newsgroup-data))
2865
2866(defun gnus-data-update-list (data offset)
2867 "Add OFFSET to the POS of all data entries in DATA."
6748645f 2868 (setq gnus-newsgroup-data-reverse nil)
eec82323
LMI
2869 (while data
2870 (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2871 (setq data (cdr data))))
2872
eec82323
LMI
2873(defun gnus-summary-article-pseudo-p (article)
2874 "Say whether this article is a pseudo article or not."
2875 (not (vectorp (gnus-data-header (gnus-data-find article)))))
2876
2877(defmacro gnus-summary-article-sparse-p (article)
2878 "Say whether this article is a sparse article or not."
a8151ef7 2879 `(memq ,article gnus-newsgroup-sparse))
eec82323
LMI
2880
2881(defmacro gnus-summary-article-ancient-p (article)
2882 "Say whether this article is a sparse article or not."
2883 `(memq ,article gnus-newsgroup-ancient))
2884
2885(defun gnus-article-parent-p (number)
2886 "Say whether this article is a parent or not."
2887 (let ((data (gnus-data-find-list number)))
23f87bed 2888 (and (cdr data) ; There has to be an article after...
eec82323
LMI
2889 (< (gnus-data-level (car data)) ; And it has to have a higher level.
2890 (gnus-data-level (nth 1 data))))))
2891
2892(defun gnus-article-children (number)
2893 "Return a list of all children to NUMBER."
2894 (let* ((data (gnus-data-find-list number))
2895 (level (gnus-data-level (car data)))
2896 children)
2897 (setq data (cdr data))
2898 (while (and data
2899 (= (gnus-data-level (car data)) (1+ level)))
2900 (push (gnus-data-number (car data)) children)
2901 (setq data (cdr data)))
2902 children))
2903
2904(defmacro gnus-summary-skip-intangible ()
2905 "If the current article is intangible, then jump to a different article."
2906 '(let ((to (get-text-property (point) 'gnus-intangible)))
2907 (and to (gnus-summary-goto-subject to))))
2908
2909(defmacro gnus-summary-article-intangible-p ()
2910 "Say whether this article is intangible or not."
2911 '(get-text-property (point) 'gnus-intangible))
2912
2913(defun gnus-article-read-p (article)
2914 "Say whether ARTICLE is read or not."
2915 (not (or (memq article gnus-newsgroup-marked)
23f87bed 2916 (memq article gnus-newsgroup-spam-marked)
eec82323
LMI
2917 (memq article gnus-newsgroup-unreads)
2918 (memq article gnus-newsgroup-unselected)
2919 (memq article gnus-newsgroup-dormant))))
2920
2921;; Some summary mode macros.
2922
2923(defmacro gnus-summary-article-number ()
2924 "The article number of the article on the current line.
8f688cb0 2925If there isn't an article number here, then we return the current
eec82323
LMI
2926article number."
2927 '(progn
2928 (gnus-summary-skip-intangible)
2929 (or (get-text-property (point) 'gnus-number)
2930 (gnus-summary-last-subject))))
2931
2932(defmacro gnus-summary-article-header (&optional number)
6748645f 2933 "Return the header of article NUMBER."
eec82323
LMI
2934 `(gnus-data-header (gnus-data-find
2935 ,(or number '(gnus-summary-article-number)))))
2936
2937(defmacro gnus-summary-thread-level (&optional number)
6748645f 2938 "Return the level of thread that starts with article NUMBER."
eec82323
LMI
2939 `(if (and (eq gnus-summary-make-false-root 'dummy)
2940 (get-text-property (point) 'gnus-intangible))
2941 0
2942 (gnus-data-level (gnus-data-find
2943 ,(or number '(gnus-summary-article-number))))))
2944
2945(defmacro gnus-summary-article-mark (&optional number)
6748645f 2946 "Return the mark of article NUMBER."
eec82323
LMI
2947 `(gnus-data-mark (gnus-data-find
2948 ,(or number '(gnus-summary-article-number)))))
2949
2950(defmacro gnus-summary-article-pos (&optional number)
6748645f 2951 "Return the position of the line of article NUMBER."
eec82323
LMI
2952 `(gnus-data-pos (gnus-data-find
2953 ,(or number '(gnus-summary-article-number)))))
2954
2955(defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2956(defmacro gnus-summary-article-subject (&optional number)
2957 "Return current subject string or nil if nothing."
2958 `(let ((headers
2959 ,(if number
2960 `(gnus-data-header (assq ,number gnus-newsgroup-data))
2961 '(gnus-data-header (assq (gnus-summary-article-number)
2962 gnus-newsgroup-data)))))
2963 (and headers
2964 (vectorp headers)
2965 (mail-header-subject headers))))
2966
2967(defmacro gnus-summary-article-score (&optional number)
2968 "Return current article score."
2969 `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2970 gnus-newsgroup-scored))
2971 gnus-summary-default-score 0))
2972
2973(defun gnus-summary-article-children (&optional number)
6748645f 2974 "Return a list of article numbers that are children of article NUMBER."
eec82323
LMI
2975 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2976 (level (gnus-data-level (car data)))
2977 l children)
2978 (while (and (setq data (cdr data))
2979 (> (setq l (gnus-data-level (car data))) level))
2980 (and (= (1+ level) l)
2981 (push (gnus-data-number (car data))
2982 children)))
2983 (nreverse children)))
2984
2985(defun gnus-summary-article-parent (&optional number)
6748645f 2986 "Return the article number of the parent of article NUMBER."
eec82323
LMI
2987 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2988 (gnus-data-list t)))
2989 (level (gnus-data-level (car data))))
2990 (if (zerop level)
2991 () ; This is a root.
2992 ;; We search until we find an article with a level less than
2993 ;; this one. That function has to be the parent.
2994 (while (and (setq data (cdr data))
2995 (not (< (gnus-data-level (car data)) level))))
2996 (and data (gnus-data-number (car data))))))
2997
2998(defun gnus-unread-mark-p (mark)
2999 "Say whether MARK is the unread mark."
3000 (= mark gnus-unread-mark))
3001
3002(defun gnus-read-mark-p (mark)
3003 "Say whether MARK is one of the marks that mark as read.
3004This is all marks except unread, ticked, dormant, and expirable."
3005 (not (or (= mark gnus-unread-mark)
3006 (= mark gnus-ticked-mark)
23f87bed 3007 (= mark gnus-spam-mark)
eec82323
LMI
3008 (= mark gnus-dormant-mark)
3009 (= mark gnus-expirable-mark))))
3010
3011(defmacro gnus-article-mark (number)
6748645f
LMI
3012 "Return the MARK of article NUMBER.
3013This macro should only be used when computing the mark the \"first\"
3014time; i.e., when generating the summary lines. After that,
3015`gnus-summary-article-mark' should be used to examine the
3016marks of articles."
eec82323 3017 `(cond
6748645f 3018 ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
6748645f 3019 ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
eec82323
LMI
3020 ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3021 ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
23f87bed 3022 ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
eec82323
LMI
3023 ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3024 ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3025 (t (or (cdr (assq ,number gnus-newsgroup-reads))
3026 gnus-ancient-mark))))
3027
3028;; Saving hidden threads.
3029
eec82323
LMI
3030(defmacro gnus-save-hidden-threads (&rest forms)
3031 "Save hidden threads, eval FORMS, and restore the hidden threads."
3032 (let ((config (make-symbol "config")))
3033 `(let ((,config (gnus-hidden-threads-configuration)))
3034 (unwind-protect
3035 (save-excursion
3036 ,@forms)
3037 (gnus-restore-hidden-threads-configuration ,config)))))
23f87bed
MB
3038(put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3039(put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
eec82323 3040
107ecebb
AS
3041(defun gnus-data-compute-positions ()
3042 "Compute the positions of all articles."
3043 (setq gnus-newsgroup-data-reverse nil)
3044 (let ((data gnus-newsgroup-data))
3045 (save-excursion
3046 (gnus-save-hidden-threads
3047 (gnus-summary-show-all-threads)
3048 (goto-char (point-min))
3049 (while data
3050 (while (get-text-property (point) 'gnus-intangible)
3051 (forward-line 1))
3052 (gnus-data-set-pos (car data) (+ (point) 3))
3053 (setq data (cdr data))
3054 (forward-line 1))))))
3055
16409b0b
GM
3056(defun gnus-hidden-threads-configuration ()
3057 "Return the current hidden threads configuration."
3058 (save-excursion
3059 (let (config)
3060 (goto-char (point-min))
3061 (while (search-forward "\r" nil t)
3062 (push (1- (point)) config))
3063 config)))
3064
3065(defun gnus-restore-hidden-threads-configuration (config)
3066 "Restore hidden threads configuration from CONFIG."
3067 (save-excursion
3068 (let (point buffer-read-only)
3069 (while (setq point (pop config))
3070 (when (and (< point (point-max))
3071 (goto-char point)
3072 (eq (char-after) ?\n))
3073 (subst-char-in-region point (1+ point) ?\n ?\r))))))
3074
eec82323
LMI
3075;; Various summary mode internalish functions.
3076
3077(defun gnus-mouse-pick-article (e)
3078 (interactive "e")
3079 (mouse-set-point e)
3080 (gnus-summary-next-page nil t))
3081
3082(defun gnus-summary-set-display-table ()
16409b0b
GM
3083 "Change the display table.
3084Odd characters have a tendency to mess
3085up nicely formatted displays - we make all possible glyphs
3086display only a single character."
eec82323
LMI
3087
3088 ;; We start from the standard display table, if any.
3089 (let ((table (or (copy-sequence standard-display-table)
3090 (make-display-table)))
3091 (i 32))
3092 ;; Nix out all the control chars...
3093 (while (>= (setq i (1- i)) 0)
3094 (aset table i [??]))
23f87bed 3095 ;; ... but not newline and cr, of course. (cr is necessary for the
eec82323
LMI
3096 ;; selective display).
3097 (aset table ?\n nil)
3098 (aset table ?\r nil)
6748645f
LMI
3099 ;; We keep TAB as well.
3100 (aset table ?\t nil)
719120ef 3101 ;; We nix out any glyphs 127 through 255, or 127 through 159 in
fe62aacc 3102 ;; Emacs 23 (unicode), that are not set already.
719120ef
MB
3103 (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3104 160
3105 256)))
eec82323
LMI
3106 (while (>= (setq i (1- i)) 127)
3107 ;; Only modify if the entry is nil.
3108 (unless (aref table i)
3109 (aset table i [??]))))
3110 (setq buffer-display-table table)))
3111
23f87bed
MB
3112(defun gnus-summary-set-article-display-arrow (pos)
3113 "Update the overlay arrow to point to line at position POS."
3114 (when (and gnus-summary-display-arrow
3115 (boundp 'overlay-arrow-position)
3116 (boundp 'overlay-arrow-string))
3117 (save-excursion
3118 (goto-char pos)
3119 (beginning-of-line)
3120 (unless overlay-arrow-position
3121 (setq overlay-arrow-position (make-marker)))
3122 (setq overlay-arrow-string "=>"
3123 overlay-arrow-position (set-marker overlay-arrow-position
3124 (point)
3125 (current-buffer))))))
3126
eec82323
LMI
3127(defun gnus-summary-setup-buffer (group)
3128 "Initialize summary buffer."
23f87bed
MB
3129 (let ((buffer (gnus-summary-buffer-name group))
3130 (dead-name (concat "*Dead Summary "
3131 (gnus-group-decoded-name group) "*")))
3132 ;; If a dead summary buffer exists, we kill it.
3133 (when (gnus-buffer-live-p dead-name)
3134 (gnus-kill-buffer dead-name))
eec82323
LMI
3135 (if (get-buffer buffer)
3136 (progn
3137 (set-buffer buffer)
3138 (setq gnus-summary-buffer (current-buffer))
3139 (not gnus-newsgroup-prepared))
3140 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
6748645f 3141 (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
eec82323
LMI
3142 (gnus-summary-mode group)
3143 (when gnus-carpal
3144 (gnus-carpal-setup-buffer 'summary))
3145 (unless gnus-single-article-buffer
3146 (make-local-variable 'gnus-article-buffer)
3147 (make-local-variable 'gnus-article-current)
3148 (make-local-variable 'gnus-original-article-buffer))
3149 (setq gnus-newsgroup-name group)
23f87bed
MB
3150 ;; Set any local variables in the group parameters.
3151 (gnus-summary-set-local-parameters gnus-newsgroup-name)
eec82323
LMI
3152 t)))
3153
3154(defun gnus-set-global-variables ()
16409b0b
GM
3155 "Set the global equivalents of the buffer-local variables.
3156They are set to the latest values they had. These reflect the summary
3157buffer that was in action when the last article was fetched."
eec82323
LMI
3158 (when (eq major-mode 'gnus-summary-mode)
3159 (setq gnus-summary-buffer (current-buffer))
3160 (let ((name gnus-newsgroup-name)
3161 (marked gnus-newsgroup-marked)
23f87bed 3162 (spam gnus-newsgroup-spam-marked)
eec82323
LMI
3163 (unread gnus-newsgroup-unreads)
3164 (headers gnus-current-headers)
3165 (data gnus-newsgroup-data)
3166 (summary gnus-summary-buffer)
3167 (article-buffer gnus-article-buffer)
3168 (original gnus-original-article-buffer)
3169 (gac gnus-article-current)
3170 (reffed gnus-reffed-article-number)
16409b0b 3171 (score-file gnus-current-score-file)
23f87bed
MB
3172 (default-charset gnus-newsgroup-charset)
3173 vlist)
3174 (let ((locals gnus-newsgroup-variables))
3175 (while locals
3176 (if (consp (car locals))
3177 (push (eval (caar locals)) vlist)
3178 (push (eval (car locals)) vlist))
3179 (setq locals (cdr locals)))
3180 (setq vlist (nreverse vlist)))
eec82323
LMI
3181 (save-excursion
3182 (set-buffer gnus-group-buffer)
6748645f
LMI
3183 (setq gnus-newsgroup-name name
3184 gnus-newsgroup-marked marked
23f87bed 3185 gnus-newsgroup-spam-marked spam
6748645f
LMI
3186 gnus-newsgroup-unreads unread
3187 gnus-current-headers headers
3188 gnus-newsgroup-data data
3189 gnus-article-current gac
3190 gnus-summary-buffer summary
3191 gnus-article-buffer article-buffer
3192 gnus-original-article-buffer original
3193 gnus-reffed-article-number reffed
16409b0b
GM
3194 gnus-current-score-file score-file
3195 gnus-newsgroup-charset default-charset)
23f87bed
MB
3196 (let ((locals gnus-newsgroup-variables))
3197 (while locals
3198 (if (consp (car locals))
3199 (set (caar locals) (pop vlist))
3200 (set (car locals) (pop vlist)))
3201 (setq locals (cdr locals))))
eec82323
LMI
3202 ;; The article buffer also has local variables.
3203 (when (gnus-buffer-live-p gnus-article-buffer)
3204 (set-buffer gnus-article-buffer)
3205 (setq gnus-summary-buffer summary))))))
3206
3207(defun gnus-summary-article-unread-p (article)
3208 "Say whether ARTICLE is unread or not."
3209 (memq article gnus-newsgroup-unreads))
3210
3211(defun gnus-summary-first-article-p (&optional article)
3212 "Return whether ARTICLE is the first article in the buffer."
3213 (if (not (setq article (or article (gnus-summary-article-number))))
3214 nil
3215 (eq article (caar gnus-newsgroup-data))))
3216
3217(defun gnus-summary-last-article-p (&optional article)
3218 "Return whether ARTICLE is the last article in the buffer."
3219 (if (not (setq article (or article (gnus-summary-article-number))))
16409b0b
GM
3220 ;; All non-existent numbers are the last article. :-)
3221 t
eec82323
LMI
3222 (not (cdr (gnus-data-find-list article)))))
3223
3224(defun gnus-make-thread-indent-array ()
3225 (let ((n 200))
3226 (unless (and gnus-thread-indent-array
3227 (= gnus-thread-indent-level gnus-thread-indent-array-level))
3228 (setq gnus-thread-indent-array (make-vector 201 "")
3229 gnus-thread-indent-array-level gnus-thread-indent-level)
3230 (while (>= n 0)
3231 (aset gnus-thread-indent-array n
3232 (make-string (* n gnus-thread-indent-level) ? ))
3233 (setq n (1- n))))))
3234
3235(defun gnus-update-summary-mark-positions ()
3236 "Compute where the summary marks are to go."
3237 (save-excursion
6748645f 3238 (when (gnus-buffer-exists-p gnus-summary-buffer)
eec82323 3239 (set-buffer gnus-summary-buffer))
5153a47a
MB
3240 (let ((spec gnus-summary-line-format-spec)
3241 pos)
eec82323
LMI
3242 (save-excursion
3243 (gnus-set-work-buffer)
5153a47a
MB
3244 (let ((gnus-tmp-unread ?Z)
3245 (gnus-replied-mark ?Z)
3246 (gnus-score-below-mark ?Z)
3247 (gnus-score-over-mark ?Z)
3248 (gnus-undownloaded-mark ?Z)
3249 (gnus-summary-line-format-spec spec)
54506618 3250 (gnus-newsgroup-downloadable '(0))
5153a47a
MB
3251 (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3252 case-fold-search ignores)
3253 ;; Here, all marks are bound to Z.
3254 (gnus-summary-insert-line header
3255 0 nil t gnus-tmp-unread t nil "" nil 1)
3256 (goto-char (point-min))
3257 ;; Memorize the positions of the same characters as dummy marks.
3258 (while (re-search-forward "[A-D]" nil t)
3259 (push (point) ignores))
54506618 3260 (erase-buffer)
5153a47a
MB
3261 ;; We use A-D as dummy marks in order to know column positions
3262 ;; where marks should be inserted.
3263 (setq gnus-tmp-unread ?A
3264 gnus-replied-mark ?B
3265 gnus-score-below-mark ?C
3266 gnus-score-over-mark ?C
3267 gnus-undownloaded-mark ?D)
3268 (gnus-summary-insert-line header
3269 0 nil t gnus-tmp-unread t nil "" nil 1)
3270 ;; Ignore characters which aren't dummy marks.
3271 (dolist (p ignores)
3272 (delete-region (goto-char (1- p)) p)
3273 (insert ?Z))
eec82323 3274 (goto-char (point-min))
7c3bb5a5 3275 (setq pos (list (cons 'unread
5153a47a 3276 (and (search-forward "A" nil t)
7c3bb5a5 3277 (- (point) (point-min) 1)))))
eec82323 3278 (goto-char (point-min))
5153a47a 3279 (push (cons 'replied (and (search-forward "B" nil t)
667e0ba6 3280 (- (point) (point-min) 1)))
eec82323
LMI
3281 pos)
3282 (goto-char (point-min))
5153a47a 3283 (push (cons 'score (and (search-forward "C" nil t)
667e0ba6 3284 (- (point) (point-min) 1)))
6748645f
LMI
3285 pos)
3286 (goto-char (point-min))
5153a47a 3287 (push (cons 'download (and (search-forward "D" nil t)
7c3bb5a5 3288 (- (point) (point-min) 1)))
eec82323
LMI
3289 pos)))
3290 (setq gnus-summary-mark-positions pos))))
3291
3292(defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3293 "Insert a dummy root in the summary buffer."
3294 (beginning-of-line)
3295 (gnus-add-text-properties
3296 (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3297 (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3298
23f87bed
MB
3299(defun gnus-summary-extract-address-component (from)
3300 (or (car (funcall gnus-extract-address-components from))
3301 from))
3302
3303(defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3304 (let ((mail-parse-charset gnus-newsgroup-charset)
3305 ; Is it really necessary to do this next part for each summary line?
3306 ; Luckily, doesn't seem to slow things down much.
16409b0b
GM
3307 (mail-parse-ignored-charsets
3308 (save-excursion (set-buffer gnus-summary-buffer)
3309 gnus-newsgroup-ignored-charsets)))
23f87bed
MB
3310 (or
3311 (and gnus-ignored-from-addresses
3312 (string-match gnus-ignored-from-addresses gnus-tmp-from)
3313 (let ((extra-headers (mail-header-extra header))
3314 to
3315 newsgroups)
3316 (cond
3317 ((setq to (cdr (assq 'To extra-headers)))
3318 (concat "-> "
3319 (inline
3320 (gnus-summary-extract-address-component
3321 (funcall gnus-decode-encoded-word-function to)))))
3322 ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3323 (concat "=> " newsgroups)))))
3324 (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
16409b0b 3325
eec82323
LMI
3326(defun gnus-summary-insert-line (gnus-tmp-header
3327 gnus-tmp-level gnus-tmp-current
23f87bed 3328 undownloaded gnus-tmp-unread gnus-tmp-replied
eec82323
LMI
3329 gnus-tmp-expirable gnus-tmp-subject-or-nil
3330 &optional gnus-tmp-dummy gnus-tmp-score
3331 gnus-tmp-process)
3332 (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3333 (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3334 (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3335 (gnus-tmp-score-char
3336 (if (or (null gnus-summary-default-score)
3337 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3338 gnus-summary-zcore-fuzz))
23f87bed 3339 ? ;Whitespace
eec82323
LMI
3340 (if (< gnus-tmp-score gnus-summary-default-score)
3341 gnus-score-below-mark gnus-score-over-mark)))
23f87bed 3342 (gnus-tmp-number (mail-header-number gnus-tmp-header))
eec82323
LMI
3343 (gnus-tmp-replied
3344 (cond (gnus-tmp-process gnus-process-mark)
3345 ((memq gnus-tmp-current gnus-newsgroup-cached)
3346 gnus-cached-mark)
3347 (gnus-tmp-replied gnus-replied-mark)
23f87bed
MB
3348 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3349 gnus-forwarded-mark)
eec82323
LMI
3350 ((memq gnus-tmp-current gnus-newsgroup-saved)
3351 gnus-saved-mark)
23f87bed
MB
3352 ((memq gnus-tmp-number gnus-newsgroup-recent)
3353 gnus-recent-mark)
3354 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3355 gnus-unseen-mark)
3356 (t gnus-no-mark)))
3357 (gnus-tmp-downloaded
3358 (cond (undownloaded
3359 gnus-undownloaded-mark)
3360 (gnus-newsgroup-agentized
3361 gnus-downloaded-mark)
3362 (t
3363 gnus-no-mark)))
eec82323
LMI
3364 (gnus-tmp-from (mail-header-from gnus-tmp-header))
3365 (gnus-tmp-name
3366 (cond
3367 ((string-match "<[^>]+> *$" gnus-tmp-from)
3368 (let ((beg (match-beginning 0)))
23f87bed
MB
3369 (or (and (string-match "^\".+\"" gnus-tmp-from)
3370 (substring gnus-tmp-from 1 (1- (match-end 0))))
eec82323
LMI
3371 (substring gnus-tmp-from 0 beg))))
3372 ((string-match "(.+)" gnus-tmp-from)
3373 (substring gnus-tmp-from
3374 (1+ (match-beginning 0)) (1- (match-end 0))))
3375 (t gnus-tmp-from)))
3376 (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
eec82323
LMI
3377 (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3378 (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3379 (buffer-read-only nil))
3380 (when (string= gnus-tmp-name "")
3381 (setq gnus-tmp-name gnus-tmp-from))
3382 (unless (numberp gnus-tmp-lines)
23f87bed
MB
3383 (setq gnus-tmp-lines -1))
3384 (if (= gnus-tmp-lines -1)
3385 (setq gnus-tmp-lines "?")
3386 (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3387 (gnus-put-text-property
eec82323
LMI
3388 (point)
3389 (progn (eval gnus-summary-line-format-spec) (point))
23f87bed 3390 'gnus-number gnus-tmp-number)
eec82323
LMI
3391 (when (gnus-visual-p 'summary-highlight 'highlight)
3392 (forward-line -1)
6748645f 3393 (gnus-run-hooks 'gnus-summary-update-hook)
eec82323
LMI
3394 (forward-line 1))))
3395
3396(defun gnus-summary-update-line (&optional dont-update)
16409b0b 3397 "Update summary line after change."
eec82323
LMI
3398 (when (and gnus-summary-default-score
3399 (not gnus-summary-inhibit-highlight))
3400 (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3401 (article (gnus-summary-article-number))
3402 (score (gnus-summary-article-score article)))
3403 (unless dont-update
3404 (if (and gnus-summary-mark-below
3405 (< (gnus-summary-article-score)
3406 gnus-summary-mark-below))
3407 ;; This article has a low score, so we mark it as read.
3408 (when (memq article gnus-newsgroup-unreads)
3409 (gnus-summary-mark-article-as-read gnus-low-score-mark))
3410 (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3411 ;; This article was previously marked as read on account
3412 ;; of a low score, but now it has risen, so we mark it as
3413 ;; unread.
3414 (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3415 (gnus-summary-update-mark
3416 (if (or (null gnus-summary-default-score)
3417 (<= (abs (- score gnus-summary-default-score))
3418 gnus-summary-zcore-fuzz))
23f87bed 3419 ? ;Whitespace
eec82323
LMI
3420 (if (< score gnus-summary-default-score)
3421 gnus-score-below-mark gnus-score-over-mark))
3422 'score))
3423 ;; Do visual highlighting.
3424 (when (gnus-visual-p 'summary-highlight 'highlight)
6748645f 3425 (gnus-run-hooks 'gnus-summary-update-hook)))))
eec82323
LMI
3426
3427(defvar gnus-tmp-new-adopts nil)
3428
3429(defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3430 "Return the number of articles in THREAD.
3431This may be 0 in some cases -- if none of the articles in
3432the thread are to be displayed."
3433 (let* ((number
23f87bed 3434 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
eec82323
LMI
3435 (cond
3436 ((not (listp thread))
3437 1)
3438 ((and (consp thread) (cdr thread))
3439 (apply
3440 '+ 1 (mapcar
3441 'gnus-summary-number-of-articles-in-thread (cdr thread))))
3442 ((null thread)
3443 1)
3444 ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3445 1)
3446 (t 0))))
3447 (when (and level (zerop level) gnus-tmp-new-adopts)
3448 (incf number
3449 (apply '+ (mapcar
3450 'gnus-summary-number-of-articles-in-thread
3451 gnus-tmp-new-adopts))))
3452 (if char
3453 (if (> number 1) gnus-not-empty-thread-mark
3454 gnus-empty-thread-mark)
3455 number)))
3456
23f87bed
MB
3457(defsubst gnus-summary-line-message-size (head)
3458 "Return pretty-printed version of message size.
3459This function is intended to be used in
3460`gnus-summary-line-format-alist'."
3461 (let ((c (or (mail-header-chars head) -1)))
3462 (cond ((< c 0) "n/a") ; chars not available
3463 ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3464 ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3465 ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3466 (t (format "%dM" (/ c (* 1024.0 1024)))))))
3467
3468
eec82323
LMI
3469(defun gnus-summary-set-local-parameters (group)
3470 "Go through the local params of GROUP and set all variable specs in that list."
3471 (let ((params (gnus-group-find-parameter group))
23f87bed 3472 (vars '(quit-config)) ; Ignore quit-config.
eec82323
LMI
3473 elem)
3474 (while params
3475 (setq elem (car params)
3476 params (cdr params))
3477 (and (consp elem) ; Has to be a cons.
3478 (consp (cdr elem)) ; The cdr has to be a list.
3479 (symbolp (car elem)) ; Has to be a symbol in there.
23f87bed 3480 (not (memq (car elem) vars))
eec82323 3481 (ignore-errors ; So we set it.
23f87bed 3482 (push (car elem) vars)
eec82323
LMI
3483 (make-local-variable (car elem))
3484 (set (car elem) (eval (nth 1 elem))))))))
3485
3486(defun gnus-summary-read-group (group &optional show-all no-article
6748645f
LMI
3487 kill-buffer no-display backward
3488 select-articles)
eec82323
LMI
3489 "Start reading news in newsgroup GROUP.
3490If SHOW-ALL is non-nil, already read articles are also listed.
3491If NO-ARTICLE is non-nil, no article is selected initially.
3492If NO-DISPLAY, don't generate a summary buffer."
3493 (let (result)
3494 (while (and group
3495 (null (setq result
3496 (let ((gnus-auto-select-next nil))
6748645f
LMI
3497 (or (gnus-summary-read-group-1
3498 group show-all no-article
3499 kill-buffer no-display
3500 select-articles)
3501 (setq show-all nil
16409b0b 3502 select-articles nil)))))
eec82323
LMI
3503 (eq gnus-auto-select-next 'quietly))
3504 (set-buffer gnus-group-buffer)
6748645f
LMI
3505 ;; The entry function called above goes to the next
3506 ;; group automatically, so we go two groups back
3507 ;; if we are searching for the previous group.
3508 (when backward
3509 (gnus-group-prev-unread-group 2))
eec82323
LMI
3510 (if (not (equal group (gnus-group-group-name)))
3511 (setq group (gnus-group-group-name))
3512 (setq group nil)))
3513 result))
3514
3515(defun gnus-summary-read-group-1 (group show-all no-article
6748645f
LMI
3516 kill-buffer no-display
3517 &optional select-articles)
eec82323 3518 ;; Killed foreign groups can't be entered.
23f87bed
MB
3519 ;; (when (and (not (gnus-group-native-p group))
3520 ;; (not (gnus-gethash group gnus-newsrc-hashtb)))
3521 ;; (error "Dead non-native groups can't be entered"))
3522 (gnus-message 5 "Retrieving newsgroup: %s..."
3523 (gnus-group-decoded-name group))
eec82323
LMI
3524 (let* ((new-group (gnus-summary-setup-buffer group))
3525 (quit-config (gnus-group-quit-config group))
6748645f
LMI
3526 (did-select (and new-group (gnus-select-newsgroup
3527 group show-all select-articles))))
eec82323
LMI
3528 (cond
3529 ;; This summary buffer exists already, so we just select it.
3530 ((not new-group)
3531 (gnus-set-global-variables)
3532 (when kill-buffer
3533 (gnus-kill-or-deaden-summary kill-buffer))
3534 (gnus-configure-windows 'summary 'force)
3535 (gnus-set-mode-line 'summary)
3536 (gnus-summary-position-point)
3537 (message "")
3538 t)
3539 ;; We couldn't select this group.
3540 ((null did-select)
3541 (when (and (eq major-mode 'gnus-summary-mode)
3542 (not (equal (current-buffer) kill-buffer)))
3543 (kill-buffer (current-buffer))
3544 (if (not quit-config)
3545 (progn
6748645f
LMI
3546 ;; Update the info -- marks might need to be removed,
3547 ;; for instance.
3548 (gnus-summary-update-info)
eec82323
LMI
3549 (set-buffer gnus-group-buffer)
3550 (gnus-group-jump-to-group group)
3551 (gnus-group-next-unread-group 1))
3552 (gnus-handle-ephemeral-exit quit-config)))
23f87bed
MB
3553 (let ((grpinfo (gnus-get-info group)))
3554 (if (null (gnus-info-read grpinfo))
3555 (gnus-message 3 "Group %s contains no messages"
3556 (gnus-group-decoded-name group))
3557 (gnus-message 3 "Can't select group")))
eec82323
LMI
3558 nil)
3559 ;; The user did a `C-g' while prompting for number of articles,
3560 ;; so we exit this group.
3561 ((eq did-select 'quit)
3562 (and (eq major-mode 'gnus-summary-mode)
3563 (not (equal (current-buffer) kill-buffer))
3564 (kill-buffer (current-buffer)))
3565 (when kill-buffer
3566 (gnus-kill-or-deaden-summary kill-buffer))
3567 (if (not quit-config)
3568 (progn
3569 (set-buffer gnus-group-buffer)
3570 (gnus-group-jump-to-group group)
3571 (gnus-group-next-unread-group 1)
3572 (gnus-configure-windows 'group 'force))
3573 (gnus-handle-ephemeral-exit quit-config))
3574 ;; Finally signal the quit.
3575 (signal 'quit nil))
3576 ;; The group was successfully selected.
3577 (t
3578 (gnus-set-global-variables)
3579 ;; Save the active value in effect when the group was entered.
3580 (setq gnus-newsgroup-active
3581 (gnus-copy-sequence
3582 (gnus-active gnus-newsgroup-name)))
3583 ;; You can change the summary buffer in some way with this hook.
6748645f 3584 (gnus-run-hooks 'gnus-select-group-hook)
5153a47a
MB
3585 (when (memq 'summary (gnus-update-format-specifications
3586 nil 'summary 'summary-mode 'summary-dummy))
3587 ;; The format specification for the summary line was updated,
3588 ;; so we need to update the mark positions as well.
3589 (gnus-update-summary-mark-positions))
eec82323
LMI
3590 ;; Do score processing.
3591 (when gnus-use-scoring
3592 (gnus-possibly-score-headers))
3593 ;; Check whether to fill in the gaps in the threads.
3594 (when gnus-build-sparse-threads
3595 (gnus-build-sparse-threads))
3596 ;; Find the initial limit.
3597 (if gnus-show-threads
3598 (if show-all
3599 (let ((gnus-newsgroup-dormant nil))
3600 (gnus-summary-initial-limit show-all))
3601 (gnus-summary-initial-limit show-all))
8f688cb0 3602 ;; When unthreaded, all articles are always shown.
eec82323
LMI
3603 (setq gnus-newsgroup-limit
3604 (mapcar
3605 (lambda (header) (mail-header-number header))
3606 gnus-newsgroup-headers)))
3607 ;; Generate the summary buffer.
3608 (unless no-display
3609 (gnus-summary-prepare))
3610 (when gnus-use-trees
3611 (gnus-tree-open group)
3612 (setq gnus-summary-highlight-line-function
3613 'gnus-tree-highlight-article))
3614 ;; If the summary buffer is empty, but there are some low-scored
3615 ;; articles or some excluded dormants, we include these in the
3616 ;; buffer.
3617 (when (and (zerop (buffer-size))
3618 (not no-display))
3619 (cond (gnus-newsgroup-dormant
3620 (gnus-summary-limit-include-dormant))
3621 ((and gnus-newsgroup-scored show-all)
3622 (gnus-summary-limit-include-expunged t))))
3623 ;; Function `gnus-apply-kill-file' must be called in this hook.
6748645f 3624 (gnus-run-hooks 'gnus-apply-kill-hook)
eec82323
LMI
3625 (if (and (zerop (buffer-size))
3626 (not no-display))
3627 (progn
3628 ;; This newsgroup is empty.
3629 (gnus-summary-catchup-and-exit nil t)
3630 (gnus-message 6 "No unread news")
3631 (when kill-buffer
3632 (gnus-kill-or-deaden-summary kill-buffer))
3633 ;; Return nil from this function.
3634 nil)
3635 ;; Hide conversation thread subtrees. We cannot do this in
3636 ;; gnus-summary-prepare-hook since kill processing may not
3637 ;; work with hidden articles.
23f87bed 3638 (gnus-summary-maybe-hide-threads)
6748645f
LMI
3639 (when kill-buffer
3640 (gnus-kill-or-deaden-summary kill-buffer))
23f87bed 3641 (gnus-summary-auto-select-subject)
eec82323
LMI
3642 ;; Show first unread article if requested.
3643 (if (and (not no-article)
3644 (not no-display)
3645 gnus-newsgroup-unreads
3646 gnus-auto-select-first)
16409b0b
GM
3647 (progn
3648 (gnus-configure-windows 'summary)
23f87bed
MB
3649 (let ((art (gnus-summary-article-number)))
3650 (unless (and (not gnus-plugged)
3651 (or (memq art gnus-newsgroup-undownloaded)
3652 (memq art gnus-newsgroup-downloadable)))
3653 (gnus-summary-goto-article art))))
3654 ;; Don't select any articles.
eec82323 3655 (gnus-summary-position-point)
6748645f
LMI
3656 (gnus-configure-windows 'summary 'force)
3657 (gnus-set-mode-line 'summary))
23f87bed
MB
3658 (when (and gnus-auto-center-group
3659 (get-buffer-window gnus-group-buffer t))
eec82323
LMI
3660 ;; Gotta use windows, because recenter does weird stuff if
3661 ;; the current buffer ain't the displayed window.
3662 (let ((owin (selected-window)))
3663 (select-window (get-buffer-window gnus-group-buffer t))
3664 (when (gnus-group-goto-group group)
3665 (recenter))
3666 (select-window owin)))
3667 ;; Mark this buffer as "prepared".
3668 (setq gnus-newsgroup-prepared t)
6748645f 3669 (gnus-run-hooks 'gnus-summary-prepared-hook)
23f87bed
MB
3670 (unless (gnus-ephemeral-group-p group)
3671 (gnus-group-update-group group))
eec82323
LMI
3672 t)))))
3673
23f87bed
MB
3674(defun gnus-summary-auto-select-subject ()
3675 "Select the subject line on initial group entry."
3676 (goto-char (point-min))
3677 (cond
3678 ((eq gnus-auto-select-subject 'best)
3679 (gnus-summary-best-unread-subject))
3680 ((eq gnus-auto-select-subject 'unread)
3681 (gnus-summary-first-unread-subject))
3682 ((eq gnus-auto-select-subject 'unseen)
3683 (gnus-summary-first-unseen-subject))
3684 ((eq gnus-auto-select-subject 'unseen-or-unread)
3685 (gnus-summary-first-unseen-or-unread-subject))
3686 ((eq gnus-auto-select-subject 'first)
3687 ;; Do nothing.
3688 )
3689 ((functionp gnus-auto-select-subject)
3690 (funcall gnus-auto-select-subject))))
3691
eec82323
LMI
3692(defun gnus-summary-prepare ()
3693 "Generate the summary buffer."
3694 (interactive)
3695 (let ((buffer-read-only nil))
3696 (erase-buffer)
3697 (setq gnus-newsgroup-data nil
3698 gnus-newsgroup-data-reverse nil)
6748645f 3699 (gnus-run-hooks 'gnus-summary-generate-hook)
eec82323
LMI
3700 ;; Generate the buffer, either with threads or without.
3701 (when gnus-newsgroup-headers
3702 (gnus-summary-prepare-threads
3703 (if gnus-show-threads
3704 (gnus-sort-gathered-threads
3705 (funcall gnus-summary-thread-gathering-function
3706 (gnus-sort-threads
3707 (gnus-cut-threads (gnus-make-threads)))))
3708 ;; Unthreaded display.
3709 (gnus-sort-articles gnus-newsgroup-headers))))
3710 (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3711 ;; Call hooks for modifying summary buffer.
3712 (goto-char (point-min))
6748645f 3713 (gnus-run-hooks 'gnus-summary-prepare-hook)))
eec82323
LMI
3714
3715(defsubst gnus-general-simplify-subject (subject)
23f87bed 3716 "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
eec82323
LMI
3717 (setq subject
3718 (cond
3719 ;; Truncate the subject.
6748645f
LMI
3720 (gnus-simplify-subject-functions
3721 (gnus-map-function gnus-simplify-subject-functions subject))
eec82323
LMI
3722 ((numberp gnus-summary-gather-subject-limit)
3723 (setq subject (gnus-simplify-subject-re subject))
3724 (if (> (length subject) gnus-summary-gather-subject-limit)
3725 (substring subject 0 gnus-summary-gather-subject-limit)
3726 subject))
3727 ;; Fuzzily simplify it.
3728 ((eq 'fuzzy gnus-summary-gather-subject-limit)
3729 (gnus-simplify-subject-fuzzy subject))
3730 ;; Just remove the leading "Re:".
3731 (t
3732 (gnus-simplify-subject-re subject))))
3733
3734 (if (and gnus-summary-gather-exclude-subject
3735 (string-match gnus-summary-gather-exclude-subject subject))
23f87bed 3736 nil ; This article shouldn't be gathered
eec82323
LMI
3737 subject))
3738
3739(defun gnus-summary-simplify-subject-query ()
3740 "Query where the respool algorithm would put this article."
3741 (interactive)
eec82323
LMI
3742 (gnus-summary-select-article)
3743 (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3744
3745(defun gnus-gather-threads-by-subject (threads)
3746 "Gather threads by looking at Subject headers."
3747 (if (not gnus-summary-make-false-root)
3748 threads
3749 (let ((hashtb (gnus-make-hashtable 1024))
3750 (prev threads)
3751 (result threads)
3752 subject hthread whole-subject)
3753 (while threads
3754 (setq subject (gnus-general-simplify-subject
3755 (setq whole-subject (mail-header-subject
3756 (caar threads)))))
3757 (when subject
3758 (if (setq hthread (gnus-gethash subject hashtb))
3759 (progn
3760 ;; We enter a dummy root into the thread, if we
3761 ;; haven't done that already.
3762 (unless (stringp (caar hthread))
3763 (setcar hthread (list whole-subject (car hthread))))
3764 ;; We add this new gathered thread to this gathered
3765 ;; thread.
3766 (setcdr (car hthread)
3767 (nconc (cdar hthread) (list (car threads))))
3768 ;; Remove it from the list of threads.
3769 (setcdr prev (cdr threads))
3770 (setq threads prev))
3771 ;; Enter this thread into the hash table.
23f87bed
MB
3772 (gnus-sethash subject
3773 (if gnus-summary-make-false-root-always
3774 (progn
3775 ;; If you want a dummy root above all
3776 ;; threads...
3777 (setcar threads (list whole-subject
3778 (car threads)))
3779 threads)
3780 threads)
3781 hashtb)))
eec82323
LMI
3782 (setq prev threads)
3783 (setq threads (cdr threads)))
3784 result)))
3785
3786(defun gnus-gather-threads-by-references (threads)
3787 "Gather threads by looking at References headers."
3788 (let ((idhashtb (gnus-make-hashtable 1024))
3789 (thhashtb (gnus-make-hashtable 1024))
3790 (prev threads)
3791 (result threads)
3792 ids references id gthread gid entered ref)
3793 (while threads
3794 (when (setq references (mail-header-references (caar threads)))
3795 (setq id (mail-header-id (caar threads))
23f87bed 3796 ids (inline (gnus-split-references references))
eec82323
LMI
3797 entered nil)
3798 (while (setq ref (pop ids))
3799 (setq ids (delete ref ids))
3800 (if (not (setq gid (gnus-gethash ref idhashtb)))
3801 (progn
3802 (gnus-sethash ref id idhashtb)
3803 (gnus-sethash id threads thhashtb))
3804 (setq gthread (gnus-gethash gid thhashtb))
3805 (unless entered
3806 ;; We enter a dummy root into the thread, if we
3807 ;; haven't done that already.
3808 (unless (stringp (caar gthread))
3809 (setcar gthread (list (mail-header-subject (caar gthread))
3810 (car gthread))))
3811 ;; We add this new gathered thread to this gathered
3812 ;; thread.
3813 (setcdr (car gthread)
3814 (nconc (cdar gthread) (list (car threads)))))
3815 ;; Add it into the thread hash table.
3816 (gnus-sethash id gthread thhashtb)
3817 (setq entered t)
3818 ;; Remove it from the list of threads.
3819 (setcdr prev (cdr threads))
3820 (setq threads prev))))
3821 (setq prev threads)
3822 (setq threads (cdr threads)))
3823 result))
3824
3825(defun gnus-sort-gathered-threads (threads)
16409b0b 3826 "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
eec82323
LMI
3827 (let ((result threads))
3828 (while threads
3829 (when (stringp (caar threads))
3830 (setcdr (car threads)
16409b0b 3831 (sort (cdar threads) gnus-sort-gathered-threads-function)))
eec82323
LMI
3832 (setq threads (cdr threads)))
3833 result))
3834
3835(defun gnus-thread-loop-p (root thread)
3836 "Say whether ROOT is in THREAD."
3837 (let ((stack (list thread))
3838 (infloop 0)
3839 th)
3840 (while (setq thread (pop stack))
3841 (setq th (cdr thread))
3842 (while (and th
3843 (not (eq (caar th) root)))
3844 (pop th))
3845 (if th
3846 ;; We have found a loop.
3847 (let (ref-dep)
3848 (setcdr thread (delq (car th) (cdr thread)))
3849 (if (boundp (setq ref-dep (intern "none"
3850 gnus-newsgroup-dependencies)))
3851 (setcdr (symbol-value ref-dep)
3852 (nconc (cdr (symbol-value ref-dep))
3853 (list (car th))))
3854 (set ref-dep (list nil (car th))))
3855 (setq infloop 1
3856 stack nil))
3857 ;; Push all the subthreads onto the stack.
3858 (push (cdr thread) stack)))
3859 infloop))
3860
3861(defun gnus-make-threads ()
3862 "Go through the dependency hashtb and find the roots. Return all threads."
3863 (let (threads)
3864 (while (catch 'infloop
3865 (mapatoms
3866 (lambda (refs)
3867 ;; Deal with self-referencing References loops.
3868 (when (and (car (symbol-value refs))
3869 (not (zerop
3870 (apply
3871 '+
3872 (mapcar
3873 (lambda (thread)
3874 (gnus-thread-loop-p
3875 (car (symbol-value refs)) thread))
3876 (cdr (symbol-value refs)))))))
3877 (setq threads nil)
3878 (throw 'infloop t))
3879 (unless (car (symbol-value refs))
23f87bed
MB
3880 ;; These threads do not refer back to any other
3881 ;; articles, so they're roots.
eec82323
LMI
3882 (setq threads (append (cdr (symbol-value refs)) threads))))
3883 gnus-newsgroup-dependencies)))
3884 threads))
3885
6748645f 3886;; Build the thread tree.
16409b0b 3887(defsubst gnus-dependencies-add-header (header dependencies force-new)
6748645f
LMI
3888 "Enter HEADER into the DEPENDENCIES table if it is not already there.
3889
3890If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3891if it was already present.
3892
3893If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3894will not be entered in the DEPENDENCIES table. Otherwise duplicate
23f87bed
MB
3895Message-IDs will be renamed to a unique Message-ID before being
3896entered.
6748645f
LMI
3897
3898Returns HEADER if it was entered in the DEPENDENCIES. Returns nil otherwise."
3899 (let* ((id (mail-header-id header))
3900 (id-dep (and id (intern id dependencies)))
23f87bed 3901 parent-id ref ref-dep ref-header replaced)
6748645f
LMI
3902 ;; Enter this `header' in the `dependencies' table.
3903 (cond
3904 ((not id-dep)
3905 (setq header nil))
3906 ;; The first two cases do the normal part: enter a new `header'
3907 ;; in the `dependencies' table.
3908 ((not (boundp id-dep))
3909 (set id-dep (list header)))
3910 ((null (car (symbol-value id-dep)))
3911 (setcar (symbol-value id-dep) header))
3912
3913 ;; From here the `header' was already present in the
3914 ;; `dependencies' table.
3915 (force-new
3916 ;; Overrides an existing entry;
3917 ;; just set the header part of the entry.
23f87bed
MB
3918 (setcar (symbol-value id-dep) header)
3919 (setq replaced t))
6748645f
LMI
3920
3921 ;; Renames the existing `header' to a unique Message-ID.
3922 ((not gnus-summary-ignore-duplicates)
3923 ;; An article with this Message-ID has already been seen.
3924 ;; We rename the Message-ID.
3925 (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3926 (list header))
3927 (mail-header-set-id header id))
3928
3929 ;; The last case ignores an existing entry, except it adds any
3930 ;; additional Xrefs (in case the two articles came from different
3931 ;; servers.
3932 ;; Also sets `header' to `nil' meaning that the `dependencies'
3933 ;; table was *not* modified.
3934 (t
3935 (mail-header-set-xref
3936 (car (symbol-value id-dep))
3937 (concat (or (mail-header-xref (car (symbol-value id-dep)))
3938 "")
3939 (or (mail-header-xref header) "")))
3940 (setq header nil)))
3941
23f87bed
MB
3942 (when (and header (not replaced))
3943 ;; First check that we are not creating a References loop.
3944 (setq parent-id (gnus-parent-id (mail-header-references header)))
3945 (setq ref parent-id)
6748645f
LMI
3946 (while (and ref
3947 (setq ref-dep (intern-soft ref dependencies))
3948 (boundp ref-dep)
3949 (setq ref-header (car (symbol-value ref-dep))))
3950 (if (string= id ref)
3951 ;; Yuk! This is a reference loop. Make the article be a
3952 ;; root article.
3953 (progn
3954 (mail-header-set-references (car (symbol-value id-dep)) "none")
23f87bed
MB
3955 (setq ref nil)
3956 (setq parent-id nil))
6748645f 3957 (setq ref (gnus-parent-id (mail-header-references ref-header)))))
23f87bed 3958 (setq ref-dep (intern (or parent-id "none") dependencies))
6748645f
LMI
3959 (if (boundp ref-dep)
3960 (setcdr (symbol-value ref-dep)
3961 (nconc (cdr (symbol-value ref-dep))
3962 (list (symbol-value id-dep))))
3963 (set ref-dep (list nil (symbol-value id-dep)))))
3964 header))
3965
23f87bed
MB
3966(defun gnus-extract-message-id-from-in-reply-to (string)
3967 (if (string-match "<[^>]+>" string)
3968 (substring string (match-beginning 0) (match-end 0))
3969 nil))
3970
eec82323
LMI
3971(defun gnus-build-sparse-threads ()
3972 (let ((headers gnus-newsgroup-headers)
16409b0b 3973 (mail-parse-charset gnus-newsgroup-charset)
6748645f 3974 (gnus-summary-ignore-duplicates t)
eec82323 3975 header references generation relations
6748645f 3976 subject child end new-child date)
eec82323
LMI
3977 ;; First we create an alist of generations/relations, where
3978 ;; generations is how much we trust the relation, and the relation
3979 ;; is parent/child.
3980 (gnus-message 7 "Making sparse threads...")
3981 (save-excursion
3982 (nnheader-set-temp-buffer " *gnus sparse threads*")
3983 (while (setq header (pop headers))
3984 (when (and (setq references (mail-header-references header))
3985 (not (string= references "")))
3986 (insert references)
3987 (setq child (mail-header-id header)
6748645f
LMI
3988 subject (mail-header-subject header)
3989 date (mail-header-date header)
3990 generation 0)
eec82323
LMI
3991 (while (search-backward ">" nil t)
3992 (setq end (1+ (point)))
3993 (when (search-backward "<" nil t)
6748645f 3994 (setq new-child (buffer-substring (point) end))
eec82323 3995 (push (list (incf generation)
6748645f
LMI
3996 child (setq child new-child)
3997 subject date)
eec82323 3998 relations)))
6748645f
LMI
3999 (when child
4000 (push (list (1+ generation) child nil subject) relations))
eec82323
LMI
4001 (erase-buffer)))
4002 (kill-buffer (current-buffer)))
4003 ;; Sort over trustworthiness.
6748645f
LMI
4004 (mapcar
4005 (lambda (relation)
4006 (when (gnus-dependencies-add-header
4007 (make-full-mail-header
4008 gnus-reffed-article-number
4009 (nth 3 relation) "" (or (nth 4 relation) "")
4010 (nth 1 relation)
4011 (or (nth 2 relation) "") 0 0 "")
4012 gnus-newsgroup-dependencies nil)
4013 (push gnus-reffed-article-number gnus-newsgroup-limit)
4014 (push gnus-reffed-article-number gnus-newsgroup-sparse)
4015 (push (cons gnus-reffed-article-number gnus-sparse-mark)
4016 gnus-newsgroup-reads)
4017 (decf gnus-reffed-article-number)))
4018 (sort relations 'car-less-than-car))
eec82323
LMI
4019 (gnus-message 7 "Making sparse threads...done")))
4020
4021(defun gnus-build-old-threads ()
4022 ;; Look at all the articles that refer back to old articles, and
4023 ;; fetch the headers for the articles that aren't there. This will
4024 ;; build complete threads - if the roots haven't been expired by the
4025 ;; server, that is.
16409b0b
GM
4026 (let ((mail-parse-charset gnus-newsgroup-charset)
4027 id heads)
eec82323
LMI
4028 (mapatoms
4029 (lambda (refs)
4030 (when (not (car (symbol-value refs)))
4031 (setq heads (cdr (symbol-value refs)))
4032 (while heads
4033 (if (memq (mail-header-number (caar heads))
4034 gnus-newsgroup-dormant)
4035 (setq heads (cdr heads))
4036 (setq id (symbol-name refs))
4037 (while (and (setq id (gnus-build-get-header id))
6748645f 4038 (not (car (gnus-id-to-thread id)))))
eec82323
LMI
4039 (setq heads nil)))))
4040 gnus-newsgroup-dependencies)))
4041
23f87bed
MB
4042(defsubst gnus-remove-odd-characters (string)
4043 "Translate STRING into something that doesn't contain weird characters."
4044 (mm-subst-char-in-string
4045 ?\r ?\-
4046 (mm-subst-char-in-string
4047 ?\n ?\- string)))
4048
6748645f
LMI
4049;; This function has to be called with point after the article number
4050;; on the beginning of the line.
4051(defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4052 (let ((eol (gnus-point-at-eol))
4053 (buffer (current-buffer))
23f87bed 4054 header references in-reply-to)
6748645f
LMI
4055
4056 ;; overview: [num subject from date id refs chars lines misc]
4057 (unwind-protect
23f87bed 4058 (let (x)
6748645f
LMI
4059 (narrow-to-region (point) eol)
4060 (unless (eobp)
4061 (forward-char))
4062
4063 (setq header
4064 (make-full-mail-header
4065 number ; number
23f87bed
MB
4066 (condition-case () ; subject
4067 (gnus-remove-odd-characters
4068 (funcall gnus-decode-encoded-word-function
4069 (setq x (nnheader-nov-field))))
4070 (error x))
4071 (condition-case () ; from
4072 (gnus-remove-odd-characters
4073 (funcall gnus-decode-encoded-word-function
4074 (setq x (nnheader-nov-field))))
4075 (error x))
16409b0b
GM
4076 (nnheader-nov-field) ; date
4077 (nnheader-nov-read-message-id) ; id
23f87bed 4078 (setq references (nnheader-nov-field)) ; refs
16409b0b
GM
4079 (nnheader-nov-read-integer) ; chars
4080 (nnheader-nov-read-integer) ; lines
4081 (unless (eobp)
8b93df01
DL
4082 (if (looking-at "Xref: ")
4083 (goto-char (match-end 0)))
4084 (nnheader-nov-field)) ; Xref
16409b0b 4085 (nnheader-nov-parse-extra)))) ; extra
6748645f
LMI
4086
4087 (widen))
4088
23f87bed
MB
4089 (when (and (string= references "")
4090 (setq in-reply-to (mail-header-extra header))
4091 (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4092 (mail-header-set-references
4093 header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4094
6748645f
LMI
4095 (when gnus-alter-header-function
4096 (funcall gnus-alter-header-function header))
4097 (gnus-dependencies-add-header header dependencies force-new)))
4098
eec82323 4099(defun gnus-build-get-header (id)
16409b0b
GM
4100 "Look through the buffer of NOV lines and find the header to ID.
4101Enter this line into the dependencies hash table, and return
4102the id of the parent article (if any)."
eec82323
LMI
4103 (let ((deps gnus-newsgroup-dependencies)
4104 found header)
4105 (prog1
4106 (save-excursion
4107 (set-buffer nntp-server-buffer)
4108 (let ((case-fold-search nil))
4109 (goto-char (point-min))
4110 (while (and (not found)
4111 (search-forward id nil t))
4112 (beginning-of-line)
4113 (setq found (looking-at
4114 (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4115 (regexp-quote id))))
4116 (or found (beginning-of-line 2)))
4117 (when found
4118 (beginning-of-line)
4119 (and
4120 (setq header (gnus-nov-parse-line
4121 (read (current-buffer)) deps))
4122 (gnus-parent-id (mail-header-references header))))))
4123 (when header
4124 (let ((number (mail-header-number header)))
4125 (push number gnus-newsgroup-limit)
4126 (push header gnus-newsgroup-headers)
4127 (if (memq number gnus-newsgroup-unselected)
4128 (progn
23f87bed
MB
4129 (setq gnus-newsgroup-unreads
4130 (gnus-add-to-sorted-list gnus-newsgroup-unreads
4131 number))
eec82323
LMI
4132 (setq gnus-newsgroup-unselected
4133 (delq number gnus-newsgroup-unselected)))
4134 (push number gnus-newsgroup-ancient)))))))
4135
6748645f
LMI
4136(defun gnus-build-all-threads ()
4137 "Read all the headers."
4138 (let ((gnus-summary-ignore-duplicates t)
16409b0b 4139 (mail-parse-charset gnus-newsgroup-charset)
6748645f
LMI
4140 (dependencies gnus-newsgroup-dependencies)
4141 header article)
4142 (save-excursion
4143 (set-buffer nntp-server-buffer)
4144 (let ((case-fold-search nil))
4145 (goto-char (point-min))
4146 (while (not (eobp))
4147 (ignore-errors
4148 (setq article (read (current-buffer))
16409b0b 4149 header (gnus-nov-parse-line article dependencies)))
6748645f
LMI
4150 (when header
4151 (save-excursion
4152 (set-buffer gnus-summary-buffer)
4153 (push header gnus-newsgroup-headers)
4154 (if (memq (setq article (mail-header-number header))
4155 gnus-newsgroup-unselected)
4156 (progn
23f87bed
MB
4157 (setq gnus-newsgroup-unreads
4158 (gnus-add-to-sorted-list
4159 gnus-newsgroup-unreads article))
6748645f
LMI
4160 (setq gnus-newsgroup-unselected
4161 (delq article gnus-newsgroup-unselected)))
4162 (push article gnus-newsgroup-ancient)))
4163 (forward-line 1)))))))
4164
eec82323 4165(defun gnus-summary-update-article-line (article header)
23f87bed 4166 "Update the line for ARTICLE using HEADER."
eec82323
LMI
4167 (let* ((id (mail-header-id header))
4168 (thread (gnus-id-to-thread id)))
4169 (unless thread
4170 (error "Article in no thread"))
4171 ;; Update the thread.
4172 (setcar thread header)
4173 (gnus-summary-goto-subject article)
4174 (let* ((datal (gnus-data-find-list article))
4175 (data (car datal))
eec82323
LMI
4176 (buffer-read-only nil)
4177 (level (gnus-summary-thread-level)))
4178 (gnus-delete-line)
23f87bed
MB
4179 (let ((inserted (- (point)
4180 (progn
4181 (gnus-summary-insert-line
4182 header level nil
4183 (memq article gnus-newsgroup-undownloaded)
4184 (gnus-article-mark article)
4185 (memq article gnus-newsgroup-replied)
4186 (memq article gnus-newsgroup-expirable)
4187 ;; Only insert the Subject string when it's different
4188 ;; from the previous Subject string.
4189 (if (and
4190 gnus-show-threads
4191 (gnus-subject-equal
4192 (condition-case ()
4193 (mail-header-subject
4194 (gnus-data-header
4195 (cadr
4196 (gnus-data-find-list
4197 article
4198 (gnus-data-list t)))))
4199 ;; Error on the side of excessive subjects.
4200 (error ""))
4201 (mail-header-subject header)))
4202 ""
4203 (mail-header-subject header))
4204 nil (cdr (assq article gnus-newsgroup-scored))
4205 (memq article gnus-newsgroup-processable))
4206 (point)))))
4207 (when (cdr datal)
4208 (gnus-data-update-list
4209 (cdr datal)
4210 (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
eec82323
LMI
4211
4212(defun gnus-summary-update-article (article &optional iheader)
4213 "Update ARTICLE in the summary buffer."
4214 (set-buffer gnus-summary-buffer)
6748645f 4215 (let* ((header (gnus-summary-article-header article))
eec82323
LMI
4216 (id (mail-header-id header))
4217 (data (gnus-data-find article))
4218 (thread (gnus-id-to-thread id))
4219 (references (mail-header-references header))
4220 (parent
4221 (gnus-id-to-thread
4222 (or (gnus-parent-id
4223 (when (and references
4224 (not (equal "" references)))
4225 references))
4226 "none")))
4227 (buffer-read-only nil)
6748645f 4228 (old (car thread)))
eec82323 4229 (when thread
eec82323 4230 (unless iheader
6748645f
LMI
4231 (setcar thread nil)
4232 (when parent
4233 (delq thread parent)))
4234 (if (gnus-summary-insert-subject id header)
eec82323
LMI
4235 ;; Set the (possibly) new article number in the data structure.
4236 (gnus-data-set-number data (gnus-id-to-article id))
4237 (setcar thread old)
4238 nil))))
4239
6748645f
LMI
4240(defun gnus-rebuild-thread (id &optional line)
4241 "Rebuild the thread containing ID.
4242If LINE, insert the rebuilt thread starting on line LINE."
eec82323
LMI
4243 (let ((buffer-read-only nil)
4244 old-pos current thread data)
4245 (if (not gnus-show-threads)
4246 (setq thread (list (car (gnus-id-to-thread id))))
4247 ;; Get the thread this article is part of.
4248 (setq thread (gnus-remove-thread id)))
4249 (setq old-pos (gnus-point-at-bol))
4250 (setq current (save-excursion
94384150 4251 (and (re-search-backward "[\r\n]" nil t)
eec82323
LMI
4252 (gnus-summary-article-number))))
4253 ;; If this is a gathered thread, we have to go some re-gathering.
4254 (when (stringp (car thread))
4255 (let ((subject (car thread))
4256 roots thr)
4257 (setq thread (cdr thread))
4258 (while thread
4259 (unless (memq (setq thr (gnus-id-to-thread
4260 (gnus-root-id
4261 (mail-header-id (caar thread)))))
4262 roots)
4263 (push thr roots))
4264 (setq thread (cdr thread)))
4265 ;; We now have all (unique) roots.
4266 (if (= (length roots) 1)
4267 ;; All the loose roots are now one solid root.
4268 (setq thread (car roots))
4269 (setq thread (cons subject (gnus-sort-threads roots))))))
4270 (let (threads)
4271 ;; We then insert this thread into the summary buffer.
6748645f
LMI
4272 (when line
4273 (goto-char (point-min))
4274 (forward-line (1- line)))
eec82323
LMI
4275 (let (gnus-newsgroup-data gnus-newsgroup-threads)
4276 (if gnus-show-threads
4277 (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4278 (gnus-summary-prepare-unthreaded thread))
4279 (setq data (nreverse gnus-newsgroup-data))
4280 (setq threads gnus-newsgroup-threads))
4281 ;; We splice the new data into the data structure.
6748645f
LMI
4282 ;;!!! This is kinda bogus. We assume that in LINE is non-nil,
4283 ;;!!! then we want to insert at the beginning of the buffer.
4284 ;;!!! That happens to be true with Gnus now, but that may
4285 ;;!!! change in the future. Perhaps.
4286 (gnus-data-enter-list
4287 (if line nil current) data (- (point) old-pos))
4288 (setq gnus-newsgroup-threads
4289 (nconc threads gnus-newsgroup-threads))
4290 (gnus-data-compute-positions))))
eec82323
LMI
4291
4292(defun gnus-number-to-header (number)
4293 "Return the header for article NUMBER."
4294 (let ((headers gnus-newsgroup-headers))
4295 (while (and headers
4296 (not (= number (mail-header-number (car headers)))))
4297 (pop headers))
4298 (when headers
4299 (car headers))))
4300
6748645f 4301(defun gnus-parent-headers (in-headers &optional generation)
eec82323
LMI
4302 "Return the headers of the GENERATIONeth parent of HEADERS."
4303 (unless generation
4304 (setq generation 1))
a8151ef7 4305 (let ((parent t)
6748645f 4306 (headers in-headers)
a8151ef7 4307 references)
6748645f
LMI
4308 (while (and parent
4309 (not (zerop generation))
4310 (setq references (mail-header-references headers)))
4311 (setq headers (if (and references
4312 (setq parent (gnus-parent-id references)))
4313 (car (gnus-id-to-thread parent))
4314 nil))
4315 (decf generation))
4316 (and (not (eq headers in-headers))
4317 headers)))
eec82323
LMI
4318
4319(defun gnus-id-to-thread (id)
4320 "Return the (sub-)thread where ID appears."
4321 (gnus-gethash id gnus-newsgroup-dependencies))
4322
4323(defun gnus-id-to-article (id)
4324 "Return the article number of ID."
4325 (let ((thread (gnus-id-to-thread id)))
4326 (when (and thread
4327 (car thread))
4328 (mail-header-number (car thread)))))
4329
4330(defun gnus-id-to-header (id)
4331 "Return the article headers of ID."
4332 (car (gnus-id-to-thread id)))
4333
4334(defun gnus-article-displayed-root-p (article)
4335 "Say whether ARTICLE is a root(ish) article."
4336 (let ((level (gnus-summary-thread-level article))
4337 (refs (mail-header-references (gnus-summary-article-header article)))
4338 particle)
4339 (cond
4340 ((null level) nil)
4341 ((zerop level) t)
4342 ((null refs) t)
4343 ((null (gnus-parent-id refs)) t)
4344 ((and (= 1 level)
4345 (null (setq particle (gnus-id-to-article
4346 (gnus-parent-id refs))))
4347 (null (gnus-summary-thread-level particle)))))))
4348
4349(defun gnus-root-id (id)
4350 "Return the id of the root of the thread where ID appears."
4351 (let (last-id prev)
6748645f 4352 (while (and id (setq prev (car (gnus-id-to-thread id))))
eec82323
LMI
4353 (setq last-id id
4354 id (gnus-parent-id (mail-header-references prev))))
4355 last-id))
4356
6748645f
LMI
4357(defun gnus-articles-in-thread (thread)
4358 "Return the list of articles in THREAD."
4359 (cons (mail-header-number (car thread))
4360 (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4361
eec82323
LMI
4362(defun gnus-remove-thread (id &optional dont-remove)
4363 "Remove the thread that has ID in it."
6748645f 4364 (let (headers thread last-id)
eec82323 4365 ;; First go up in this thread until we find the root.
6748645f
LMI
4366 (setq last-id (gnus-root-id id)
4367 headers (message-flatten-list (gnus-id-to-thread last-id)))
eec82323
LMI
4368 ;; We have now found the real root of this thread. It might have
4369 ;; been gathered into some loose thread, so we have to search
4370 ;; through the threads to find the thread we wanted.
4371 (let ((threads gnus-newsgroup-threads)
4372 sub)
4373 (while threads
4374 (setq sub (car threads))
4375 (if (stringp (car sub))
4376 ;; This is a gathered thread, so we look at the roots
4377 ;; below it to find whether this article is in this
4378 ;; gathered root.
4379 (progn
4380 (setq sub (cdr sub))
4381 (while sub
4382 (when (member (caar sub) headers)
4383 (setq thread (car threads)
4384 threads nil
4385 sub nil))
4386 (setq sub (cdr sub))))
4387 ;; It's an ordinary thread, so we check it.
4388 (when (eq (car sub) (car headers))
4389 (setq thread sub
4390 threads nil)))
4391 (setq threads (cdr threads)))
4392 ;; If this article is in no thread, then it's a root.
4393 (if thread
4394 (unless dont-remove
4395 (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
6748645f 4396 (setq thread (gnus-id-to-thread last-id)))
eec82323
LMI
4397 (when thread
4398 (prog1
4399 thread ; We return this thread.
4400 (unless dont-remove
4401 (if (stringp (car thread))
4402 (progn
4403 ;; If we use dummy roots, then we have to remove the
4404 ;; dummy root as well.
4405 (when (eq gnus-summary-make-false-root 'dummy)
6748645f
LMI
4406 ;; We go to the dummy root by going to
4407 ;; the first sub-"thread", and then one line up.
4408 (gnus-summary-goto-article
4409 (mail-header-number (caadr thread)))
4410 (forward-line -1)
eec82323
LMI
4411 (gnus-delete-line)
4412 (gnus-data-compute-positions))
4413 (setq thread (cdr thread))
4414 (while thread
4415 (gnus-remove-thread-1 (car thread))
4416 (setq thread (cdr thread))))
4417 (gnus-remove-thread-1 thread))))))))
4418
4419(defun gnus-remove-thread-1 (thread)
4420 "Remove the thread THREAD recursively."
4421 (let ((number (mail-header-number (pop thread)))
4422 d)
4423 (setq thread (reverse thread))
4424 (while thread
4425 (gnus-remove-thread-1 (pop thread)))
4426 (when (setq d (gnus-data-find number))
4427 (goto-char (gnus-data-pos d))
16409b0b 4428 (gnus-summary-show-thread)
eec82323
LMI
4429 (gnus-data-remove
4430 number
4431 (- (gnus-point-at-bol)
4432 (prog1
4433 (1+ (gnus-point-at-eol))
4434 (gnus-delete-line)))))))
4435
16409b0b
GM
4436(defun gnus-sort-threads-1 (threads func)
4437 (sort (mapcar (lambda (thread)
4438 (cons (car thread)
4439 (and (cdr thread)
4440 (gnus-sort-threads-1 (cdr thread) func))))
4441 threads) func))
4442
eec82323
LMI
4443(defun gnus-sort-threads (threads)
4444 "Sort THREADS."
4445 (if (not gnus-thread-sort-functions)
4446 threads
6748645f 4447 (gnus-message 8 "Sorting threads...")
23f87bed
MB
4448 (let ((max-lisp-eval-depth 5000))
4449 (prog1 (gnus-sort-threads-1
a1506d29 4450 threads
16409b0b 4451 (gnus-make-sort-function gnus-thread-sort-functions))
23f87bed 4452 (gnus-message 8 "Sorting threads...done")))))
eec82323
LMI
4453
4454(defun gnus-sort-articles (articles)
4455 "Sort ARTICLES."
4456 (when gnus-article-sort-functions
4457 (gnus-message 7 "Sorting articles...")
4458 (prog1
4459 (setq gnus-newsgroup-headers
4460 (sort articles (gnus-make-sort-function
4461 gnus-article-sort-functions)))
4462 (gnus-message 7 "Sorting articles...done"))))
4463
4464;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4465(defmacro gnus-thread-header (thread)
16409b0b
GM
4466 "Return header of first article in THREAD.
4467Note that THREAD must never, ever be anything else than a variable -
4468using some other form will lead to serious barfage."
eec82323
LMI
4469 (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4470 ;; (8% speedup to gnus-summary-prepare, just for fun :-)
16409b0b 4471 (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
eec82323
LMI
4472 (vector thread) 2))
4473
4474(defsubst gnus-article-sort-by-number (h1 h2)
4475 "Sort articles by article number."
4476 (< (mail-header-number h1)
4477 (mail-header-number h2)))
4478
4479(defun gnus-thread-sort-by-number (h1 h2)
4480 "Sort threads by root article number."
4481 (gnus-article-sort-by-number
4482 (gnus-thread-header h1) (gnus-thread-header h2)))
4483
23f87bed
MB
4484(defsubst gnus-article-sort-by-random (h1 h2)
4485 "Sort articles by article number."
4486 (zerop (random 2)))
4487
4488(defun gnus-thread-sort-by-random (h1 h2)
4489 "Sort threads by root article number."
4490 (gnus-article-sort-by-random
4491 (gnus-thread-header h1) (gnus-thread-header h2)))
4492
eec82323
LMI
4493(defsubst gnus-article-sort-by-lines (h1 h2)
4494 "Sort articles by article Lines header."
4495 (< (mail-header-lines h1)
4496 (mail-header-lines h2)))
4497
4498(defun gnus-thread-sort-by-lines (h1 h2)
4499 "Sort threads by root article Lines header."
4500 (gnus-article-sort-by-lines
4501 (gnus-thread-header h1) (gnus-thread-header h2)))
4502
16409b0b
GM
4503(defsubst gnus-article-sort-by-chars (h1 h2)
4504 "Sort articles by octet length."
4505 (< (mail-header-chars h1)
4506 (mail-header-chars h2)))
4507
4508(defun gnus-thread-sort-by-chars (h1 h2)
4509 "Sort threads by root article octet length."
4510 (gnus-article-sort-by-chars
4511 (gnus-thread-header h1) (gnus-thread-header h2)))
4512
eec82323
LMI
4513(defsubst gnus-article-sort-by-author (h1 h2)
4514 "Sort articles by root author."
4515 (string-lessp
4516 (let ((extract (funcall
4517 gnus-extract-address-components
4518 (mail-header-from h1))))
4519 (or (car extract) (cadr extract) ""))
4520 (let ((extract (funcall
4521 gnus-extract-address-components
4522 (mail-header-from h2))))
4523 (or (car extract) (cadr extract) ""))))
4524
4525(defun gnus-thread-sort-by-author (h1 h2)
4526 "Sort threads by root author."
4527 (gnus-article-sort-by-author
4528 (gnus-thread-header h1) (gnus-thread-header h2)))
4529
4530(defsubst gnus-article-sort-by-subject (h1 h2)
4531 "Sort articles by root subject."
4532 (string-lessp
4533 (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4534 (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4535
4536(defun gnus-thread-sort-by-subject (h1 h2)
4537 "Sort threads by root subject."
4538 (gnus-article-sort-by-subject
4539 (gnus-thread-header h1) (gnus-thread-header h2)))
4540
4541(defsubst gnus-article-sort-by-date (h1 h2)
4542 "Sort articles by root article date."
16409b0b 4543 (time-less-p
eec82323
LMI
4544 (gnus-date-get-time (mail-header-date h1))
4545 (gnus-date-get-time (mail-header-date h2))))
4546
4547(defun gnus-thread-sort-by-date (h1 h2)
4548 "Sort threads by root article date."
4549 (gnus-article-sort-by-date
4550 (gnus-thread-header h1) (gnus-thread-header h2)))
4551
4552(defsubst gnus-article-sort-by-score (h1 h2)
4553 "Sort articles by root article score.
4554Unscored articles will be counted as having a score of zero."
4555 (> (or (cdr (assq (mail-header-number h1)
4556 gnus-newsgroup-scored))
4557 gnus-summary-default-score 0)
4558 (or (cdr (assq (mail-header-number h2)
4559 gnus-newsgroup-scored))
4560 gnus-summary-default-score 0)))
4561
4562(defun gnus-thread-sort-by-score (h1 h2)
4563 "Sort threads by root article score."
4564 (gnus-article-sort-by-score
4565 (gnus-thread-header h1) (gnus-thread-header h2)))
4566
4567(defun gnus-thread-sort-by-total-score (h1 h2)
4568 "Sort threads by the sum of all scores in the thread.
4569Unscored articles will be counted as having a score of zero."
4570 (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4571
4572(defun gnus-thread-total-score (thread)
16409b0b 4573 ;; This function find the total score of THREAD.
23f87bed
MB
4574 (cond
4575 ((null thread)
4576 0)
4577 ((consp thread)
4578 (if (stringp (car thread))
4579 (apply gnus-thread-score-function 0
4580 (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4581 (gnus-thread-total-score-1 thread)))
4582 (t
4583 (gnus-thread-total-score-1 (list thread)))))
4584
4585(defun gnus-thread-sort-by-most-recent-number (h1 h2)
4586 "Sort threads such that the thread with the most recently arrived article comes first."
4587 (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4588
4589(defun gnus-thread-highest-number (thread)
4590 "Return the highest article number in THREAD."
4591 (apply 'max (mapcar (lambda (header)
4592 (mail-header-number header))
4593 (message-flatten-list thread))))
4594
4595(defun gnus-thread-sort-by-most-recent-date (h1 h2)
4596 "Sort threads such that the thread with the most recently dated article comes first."
4597 (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4598
4599(defun gnus-thread-latest-date (thread)
4600 "Return the highest article date in THREAD."
4601 (let ((previous-time 0))
4602 (apply 'max
4603 (mapcar
4604 (lambda (header)
4605 (setq previous-time
4606 (condition-case ()
4607 (time-to-seconds (mail-header-parse-date
4608 (mail-header-date header)))
4609 (error previous-time))))
4610 (sort
4611 (message-flatten-list thread)
4612 (lambda (h1 h2)
4613 (< (mail-header-number h1)
4614 (mail-header-number h2))))))))
eec82323
LMI
4615
4616(defun gnus-thread-total-score-1 (root)
4617 ;; This function find the total score of the thread below ROOT.
4618 (setq root (car root))
4619 (apply gnus-thread-score-function
4620 (or (append
4621 (mapcar 'gnus-thread-total-score
6748645f 4622 (cdr (gnus-id-to-thread (mail-header-id root))))
eec82323
LMI
4623 (when (> (mail-header-number root) 0)
4624 (list (or (cdr (assq (mail-header-number root)
4625 gnus-newsgroup-scored))
4626 gnus-summary-default-score 0))))
4627 (list gnus-summary-default-score)
4628 '(0))))
4629
4630;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4631(defvar gnus-tmp-prev-subject nil)
4632(defvar gnus-tmp-false-parent nil)
4633(defvar gnus-tmp-root-expunged nil)
4634(defvar gnus-tmp-dummy-line nil)
4635
60bd5589 4636(eval-when-compile (defvar gnus-tmp-header))
16409b0b
GM
4637(defun gnus-extra-header (type &optional header)
4638 "Return the extra header of TYPE."
4639 (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4640 ""))
4641
23f87bed
MB
4642(defvar gnus-tmp-thread-tree-header-string "")
4643
4644(defcustom gnus-sum-thread-tree-root "> "
4645 "With %B spec, used for the root of a thread.
4646If nil, use subject instead."
bf247b6e 4647 :version "22.1"
ad136a7c 4648 :type '(radio (const :format "%v " nil) string)
23f87bed
MB
4649 :group 'gnus-thread)
4650(defcustom gnus-sum-thread-tree-false-root "> "
4651 "With %B spec, used for a false root of a thread.
4652If nil, use subject instead."
bf247b6e 4653 :version "22.1"
ad136a7c 4654 :type '(radio (const :format "%v " nil) string)
23f87bed
MB
4655 :group 'gnus-thread)
4656(defcustom gnus-sum-thread-tree-single-indent ""
4657 "With %B spec, used for a thread with just one message.
4658If nil, use subject instead."
bf247b6e 4659 :version "22.1"
ad136a7c 4660 :type '(radio (const :format "%v " nil) string)
23f87bed
MB
4661 :group 'gnus-thread)
4662(defcustom gnus-sum-thread-tree-vertical "| "
4663 "With %B spec, used for drawing a vertical line."
bf247b6e 4664 :version "22.1"
23f87bed
MB
4665 :type 'string
4666 :group 'gnus-thread)
4667(defcustom gnus-sum-thread-tree-indent " "
4668 "With %B spec, used for indenting."
bf247b6e 4669 :version "22.1"
23f87bed
MB
4670 :type 'string
4671 :group 'gnus-thread)
4672(defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4673 "With %B spec, used for a leaf with brothers."
bf247b6e 4674 :version "22.1"
23f87bed
MB
4675 :type 'string
4676 :group 'gnus-thread)
4677(defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4678 "With %B spec, used for a leaf without brothers."
bf247b6e 4679 :version "22.1"
23f87bed
MB
4680 :type 'string
4681 :group 'gnus-thread)
4682
eec82323
LMI
4683(defun gnus-summary-prepare-threads (threads)
4684 "Prepare summary buffer from THREADS and indentation LEVEL.
4685THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4686or a straight list of headers."
4687 (gnus-message 7 "Generating summary...")
4688
4689 (setq gnus-newsgroup-threads threads)
4690 (beginning-of-line)
4691
4692 (let ((gnus-tmp-level 0)
4693 (default-score (or gnus-summary-default-score 0))
4694 (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
23f87bed
MB
4695 (building-line-count gnus-summary-display-while-building)
4696 (building-count (integerp gnus-summary-display-while-building))
eec82323 4697 thread number subject stack state gnus-tmp-gathered beg-match
23f87bed
MB
4698 new-roots gnus-tmp-new-adopts thread-end simp-subject
4699 gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
eec82323
LMI
4700 gnus-tmp-replied gnus-tmp-subject-or-nil
4701 gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4702 gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
23f87bed
MB
4703 gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4704 tree-stack)
eec82323 4705
23f87bed
MB
4706 (setq gnus-tmp-prev-subject nil
4707 gnus-tmp-thread-tree-header-string "")
eec82323
LMI
4708
4709 (if (vectorp (car threads))
4710 ;; If this is a straight (sic) list of headers, then a
4711 ;; threaded summary display isn't required, so we just create
4712 ;; an unthreaded one.
4713 (gnus-summary-prepare-unthreaded threads)
4714
4715 ;; Do the threaded display.
4716
23f87bed
MB
4717 (if gnus-summary-display-while-building
4718 (switch-to-buffer (buffer-name)))
eec82323
LMI
4719 (while (or threads stack gnus-tmp-new-adopts new-roots)
4720
4721 (if (and (= gnus-tmp-level 0)
eec82323
LMI
4722 (or (not stack)
4723 (= (caar stack) 0))
4724 (not gnus-tmp-false-parent)
4725 (or gnus-tmp-new-adopts new-roots))
4726 (if gnus-tmp-new-adopts
4727 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4728 thread (list (car gnus-tmp-new-adopts))
4729 gnus-tmp-header (caar thread)
4730 gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4731 (when new-roots
4732 (setq thread (list (car new-roots))
4733 gnus-tmp-header (caar thread)
4734 new-roots (cdr new-roots))))
4735
4736 (if threads
4737 ;; If there are some threads, we do them before the
4738 ;; threads on the stack.
4739 (setq thread threads
4740 gnus-tmp-header (caar thread))
4741 ;; There were no current threads, so we pop something off
4742 ;; the stack.
4743 (setq state (car stack)
4744 gnus-tmp-level (car state)
23f87bed
MB
4745 tree-stack (cadr state)
4746 thread (caddr state)
eec82323
LMI
4747 stack (cdr stack)
4748 gnus-tmp-header (caar thread))))
4749
4750 (setq gnus-tmp-false-parent nil)
4751 (setq gnus-tmp-root-expunged nil)
4752 (setq thread-end nil)
4753
4754 (if (stringp gnus-tmp-header)
4755 ;; The header is a dummy root.
4756 (cond
4757 ((eq gnus-summary-make-false-root 'adopt)
4758 ;; We let the first article adopt the rest.
4759 (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4760 (cddar thread)))
4761 (setq gnus-tmp-gathered
4762 (nconc (mapcar
4763 (lambda (h) (mail-header-number (car h)))
4764 (cddar thread))
4765 gnus-tmp-gathered))
4766 (setq thread (cons (list (caar thread)
4767 (cadar thread))
4768 (cdr thread)))
4769 (setq gnus-tmp-level -1
4770 gnus-tmp-false-parent t))
4771 ((eq gnus-summary-make-false-root 'empty)
4772 ;; We print adopted articles with empty subject fields.
4773 (setq gnus-tmp-gathered
4774 (nconc (mapcar
4775 (lambda (h) (mail-header-number (car h)))
4776 (cddar thread))
4777 gnus-tmp-gathered))
4778 (setq gnus-tmp-level -1))
4779 ((eq gnus-summary-make-false-root 'dummy)
4780 ;; We remember that we probably want to output a dummy
4781 ;; root.
4782 (setq gnus-tmp-dummy-line gnus-tmp-header)
4783 (setq gnus-tmp-prev-subject gnus-tmp-header))
4784 (t
4785 ;; We do not make a root for the gathered
4786 ;; sub-threads at all.
4787 (setq gnus-tmp-level -1)))
4788
4789 (setq number (mail-header-number gnus-tmp-header)
23f87bed
MB
4790 subject (mail-header-subject gnus-tmp-header)
4791 simp-subject (gnus-simplify-subject-fully subject))
eec82323
LMI
4792
4793 (cond
4794 ;; If the thread has changed subject, we might want to make
4795 ;; this subthread into a root.
4796 ((and (null gnus-thread-ignore-subject)
4797 (not (zerop gnus-tmp-level))
4798 gnus-tmp-prev-subject
23f87bed 4799 (not (string= gnus-tmp-prev-subject simp-subject)))
eec82323
LMI
4800 (setq new-roots (nconc new-roots (list (car thread)))
4801 thread-end t
4802 gnus-tmp-header nil))
4803 ;; If the article lies outside the current limit,
4804 ;; then we do not display it.
4805 ((not (memq number gnus-newsgroup-limit))
4806 (setq gnus-tmp-gathered
4807 (nconc (mapcar
4808 (lambda (h) (mail-header-number (car h)))
4809 (cdar thread))
4810 gnus-tmp-gathered))
4811 (setq gnus-tmp-new-adopts (if (cdar thread)
4812 (append gnus-tmp-new-adopts
4813 (cdar thread))
4814 gnus-tmp-new-adopts)
4815 thread-end t
4816 gnus-tmp-header nil)
4817 (when (zerop gnus-tmp-level)
4818 (setq gnus-tmp-root-expunged t)))
4819 ;; Perhaps this article is to be marked as read?
4820 ((and gnus-summary-mark-below
4821 (< (or (cdr (assq number gnus-newsgroup-scored))
4822 default-score)
4823 gnus-summary-mark-below)
4824 ;; Don't touch sparse articles.
4825 (not (gnus-summary-article-sparse-p number))
4826 (not (gnus-summary-article-ancient-p number)))
4827 (setq gnus-newsgroup-unreads
4828 (delq number gnus-newsgroup-unreads))
4829 (if gnus-newsgroup-auto-expire
23f87bed
MB
4830 (setq gnus-newsgroup-expirable
4831 (gnus-add-to-sorted-list
4832 gnus-newsgroup-expirable number))
eec82323
LMI
4833 (push (cons number gnus-low-score-mark)
4834 gnus-newsgroup-reads))))
4835
4836 (when gnus-tmp-header
4837 ;; We may have an old dummy line to output before this
4838 ;; article.
6748645f
LMI
4839 (when (and gnus-tmp-dummy-line
4840 (gnus-subject-equal
4841 gnus-tmp-dummy-line
4842 (mail-header-subject gnus-tmp-header)))
eec82323
LMI
4843 (gnus-summary-insert-dummy-line
4844 gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4845 (setq gnus-tmp-dummy-line nil))
4846
4847 ;; Compute the mark.
4848 (setq gnus-tmp-unread (gnus-article-mark number))
4849
4850 (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4851 gnus-tmp-header gnus-tmp-level)
4852 gnus-newsgroup-data)
4853
4854 ;; Actually insert the line.
4855 (setq
4856 gnus-tmp-subject-or-nil
4857 (cond
4858 ((and gnus-thread-ignore-subject
4859 gnus-tmp-prev-subject
23f87bed 4860 (not (string= gnus-tmp-prev-subject simp-subject)))
eec82323
LMI
4861 subject)
4862 ((zerop gnus-tmp-level)
4863 (if (and (eq gnus-summary-make-false-root 'empty)
4864 (memq number gnus-tmp-gathered)
4865 gnus-tmp-prev-subject
23f87bed 4866 (string= gnus-tmp-prev-subject simp-subject))
eec82323
LMI
4867 gnus-summary-same-subject
4868 subject))
4869 (t gnus-summary-same-subject)))
4870 (if (and (eq gnus-summary-make-false-root 'adopt)
4871 (= gnus-tmp-level 1)
4872 (memq number gnus-tmp-gathered))
4873 (setq gnus-tmp-opening-bracket ?\<
4874 gnus-tmp-closing-bracket ?\>)
4875 (setq gnus-tmp-opening-bracket ?\[
4876 gnus-tmp-closing-bracket ?\]))
4877 (setq
4878 gnus-tmp-indentation
4879 (aref gnus-thread-indent-array gnus-tmp-level)
4880 gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4881 gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4882 gnus-summary-default-score 0)
4883 gnus-tmp-score-char
4884 (if (or (null gnus-summary-default-score)
4885 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4886 gnus-summary-zcore-fuzz))
23f87bed 4887 ? ;Whitespace
eec82323
LMI
4888 (if (< gnus-tmp-score gnus-summary-default-score)
4889 gnus-score-below-mark gnus-score-over-mark))
4890 gnus-tmp-replied
4891 (cond ((memq number gnus-newsgroup-processable)
4892 gnus-process-mark)
4893 ((memq number gnus-newsgroup-cached)
4894 gnus-cached-mark)
4895 ((memq number gnus-newsgroup-replied)
4896 gnus-replied-mark)
23f87bed
MB
4897 ((memq number gnus-newsgroup-forwarded)
4898 gnus-forwarded-mark)
eec82323
LMI
4899 ((memq number gnus-newsgroup-saved)
4900 gnus-saved-mark)
23f87bed
MB
4901 ((memq number gnus-newsgroup-recent)
4902 gnus-recent-mark)
4903 ((memq number gnus-newsgroup-unseen)
4904 gnus-unseen-mark)
4905 (t gnus-no-mark))
4906 gnus-tmp-downloaded
4907 (cond ((memq number gnus-newsgroup-undownloaded)
4908 gnus-undownloaded-mark)
4909 (gnus-newsgroup-agentized
4910 gnus-downloaded-mark)
4911 (t
4912 gnus-no-mark))
eec82323
LMI
4913 gnus-tmp-from (mail-header-from gnus-tmp-header)
4914 gnus-tmp-name
4915 (cond
4916 ((string-match "<[^>]+> *$" gnus-tmp-from)
4917 (setq beg-match (match-beginning 0))
23f87bed
MB
4918 (or (and (string-match "^\".+\"" gnus-tmp-from)
4919 (substring gnus-tmp-from 1 (1- (match-end 0))))
eec82323
LMI
4920 (substring gnus-tmp-from 0 beg-match)))
4921 ((string-match "(.+)" gnus-tmp-from)
4922 (substring gnus-tmp-from
4923 (1+ (match-beginning 0)) (1- (match-end 0))))
23f87bed
MB
4924 (t gnus-tmp-from))
4925
4926 ;; Do the %B string
4927 gnus-tmp-thread-tree-header-string
4928 (cond
4929 ((not gnus-show-threads) "")
4930 ((zerop gnus-tmp-level)
4931 (cond ((cdar thread)
4932 (or gnus-sum-thread-tree-root subject))
4933 (gnus-tmp-new-adopts
4934 (or gnus-sum-thread-tree-false-root subject))
4935 (t
4936 (or gnus-sum-thread-tree-single-indent subject))))
4937 (t
4938 (concat (apply 'concat
4939 (mapcar (lambda (item)
4940 (if (= item 1)
4941 gnus-sum-thread-tree-vertical
4942 gnus-sum-thread-tree-indent))
4943 (cdr (reverse tree-stack))))
4944 (if (nth 1 thread)
4945 gnus-sum-thread-tree-leaf-with-other
4946 gnus-sum-thread-tree-single-leaf)))))
eec82323
LMI
4947 (when (string= gnus-tmp-name "")
4948 (setq gnus-tmp-name gnus-tmp-from))
4949 (unless (numberp gnus-tmp-lines)
23f87bed
MB
4950 (setq gnus-tmp-lines -1))
4951 (if (= gnus-tmp-lines -1)
4952 (setq gnus-tmp-lines "?")
4953 (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4954 (gnus-put-text-property
eec82323
LMI
4955 (point)
4956 (progn (eval gnus-summary-line-format-spec) (point))
23f87bed 4957 'gnus-number number)
eec82323
LMI
4958 (when gnus-visual-p
4959 (forward-line -1)
6748645f 4960 (gnus-run-hooks 'gnus-summary-update-hook)
eec82323
LMI
4961 (forward-line 1))
4962
23f87bed 4963 (setq gnus-tmp-prev-subject simp-subject)))
eec82323
LMI
4964
4965 (when (nth 1 thread)
23f87bed
MB
4966 (push (list (max 0 gnus-tmp-level)
4967 (copy-sequence tree-stack)
4968 (nthcdr 1 thread))
4969 stack))
4970 (push (if (nth 1 thread) 1 0) tree-stack)
eec82323
LMI
4971 (incf gnus-tmp-level)
4972 (setq threads (if thread-end nil (cdar thread)))
23f87bed
MB
4973 (if gnus-summary-display-while-building
4974 (if building-count
4975 (progn
4976 ;; use a set frequency
4977 (setq building-line-count (1- building-line-count))
4978 (when (= building-line-count 0)
4979 (sit-for 0)
4980 (setq building-line-count
4981 gnus-summary-display-while-building)))
4982 ;; always
4983 (sit-for 0)))
eec82323
LMI
4984 (unless threads
4985 (setq gnus-tmp-level 0)))))
4986 (gnus-message 7 "Generating summary...done"))
4987
4988(defun gnus-summary-prepare-unthreaded (headers)
4989 "Generate an unthreaded summary buffer based on HEADERS."
4990 (let (header number mark)
4991
4992 (beginning-of-line)
4993
4994 (while headers
4995 ;; We may have to root out some bad articles...
4996 (when (memq (setq number (mail-header-number
4997 (setq header (pop headers))))
4998 gnus-newsgroup-limit)
4999 ;; Mark article as read when it has a low score.
5000 (when (and gnus-summary-mark-below
5001 (< (or (cdr (assq number gnus-newsgroup-scored))
5002 gnus-summary-default-score 0)
5003 gnus-summary-mark-below)
5004 (not (gnus-summary-article-ancient-p number)))
5005 (setq gnus-newsgroup-unreads
5006 (delq number gnus-newsgroup-unreads))
5007 (if gnus-newsgroup-auto-expire
5008 (push number gnus-newsgroup-expirable)
5009 (push (cons number gnus-low-score-mark)
5010 gnus-newsgroup-reads)))
5011
5012 (setq mark (gnus-article-mark number))
5013 (push (gnus-data-make number mark (1+ (point)) header 0)
5014 gnus-newsgroup-data)
5015 (gnus-summary-insert-line
5016 header 0 number
23f87bed 5017 (memq number gnus-newsgroup-undownloaded)
eec82323
LMI
5018 mark (memq number gnus-newsgroup-replied)
5019 (memq number gnus-newsgroup-expirable)
5020 (mail-header-subject header) nil
5021 (cdr (assq number gnus-newsgroup-scored))
5022 (memq number gnus-newsgroup-processable))))))
5023
16409b0b
GM
5024(defun gnus-summary-remove-list-identifiers ()
5025 "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
23f87bed
MB
5026 (let ((regexp (if (consp gnus-list-identifiers)
5027 (mapconcat 'identity gnus-list-identifiers " *\\|")
5028 gnus-list-identifiers))
5029 changed subject)
5030 (when regexp
5031 (dolist (header gnus-newsgroup-headers)
5032 (setq subject (mail-header-subject header)
5033 changed nil)
5034 (while (string-match
5035 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
5036 subject)
5037 (setq subject
5038 (concat (substring subject 0 (match-beginning 2))
5039 (substring subject (match-end 0)))
5040 changed t))
5041 (when (and changed
5042 (string-match
5043 "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
5044 (setq subject
5045 (concat (substring subject 0 (match-beginning 1))
5046 (substring subject (match-end 1)))))
5047 (when changed
5048 (mail-header-set-subject header subject))))))
5049
5050(defun gnus-fetch-headers (articles)
5051 "Fetch headers of ARTICLES."
5052 (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5053 (gnus-message 5 "Fetching headers for %s..." name)
5054 (prog1
5055 (if (eq 'nov
5056 (setq gnus-headers-retrieved-by
5057 (gnus-retrieve-headers
5058 articles gnus-newsgroup-name
5059 ;; We might want to fetch old headers, but
5060 ;; not if there is only 1 article.
5061 (and (or (and
5062 (not (eq gnus-fetch-old-headers 'some))
5063 (not (numberp gnus-fetch-old-headers)))
5064 (> (length articles) 1))
5065 gnus-fetch-old-headers))))
5066 (gnus-get-newsgroup-headers-xover
5067 articles nil nil gnus-newsgroup-name t)
5068 (gnus-get-newsgroup-headers))
5069 (gnus-message 5 "Fetching headers for %s...done" name))))
16409b0b 5070
6748645f 5071(defun gnus-select-newsgroup (group &optional read-all select-articles)
eec82323 5072 "Select newsgroup GROUP.
6748645f
LMI
5073If READ-ALL is non-nil, all articles in the group are selected.
5074If SELECT-ARTICLES, only select those articles from GROUP."
eec82323
LMI
5075 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5076 ;;!!! Dirty hack; should be removed.
5077 (gnus-summary-ignore-duplicates
23f87bed 5078 (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
eec82323
LMI
5079 t
5080 gnus-summary-ignore-duplicates))
5081 (info (nth 2 entry))
5082 articles fetched-articles cached)
5083
5084 (unless (gnus-check-server
475e0e0c
GM
5085 (set (make-local-variable 'gnus-current-select-method)
5086 (gnus-find-method-for-group group)))
eec82323
LMI
5087 (error "Couldn't open server"))
5088
5089 (or (and entry (not (eq (car entry) t))) ; Either it's active...
5090 (gnus-activate-group group) ; Or we can activate it...
5091 (progn ; Or we bug out.
5092 (when (equal major-mode 'gnus-summary-mode)
23f87bed
MB
5093 (gnus-kill-buffer (current-buffer)))
5094 (error "Couldn't activate group %s: %s"
eec82323
LMI
5095 group (gnus-status-message group))))
5096
5097 (unless (gnus-request-group group t)
5098 (when (equal major-mode 'gnus-summary-mode)
23f87bed 5099 (gnus-kill-buffer (current-buffer)))
eec82323
LMI
5100 (error "Couldn't request group %s: %s"
5101 group (gnus-status-message group)))
5102
23f87bed 5103 (when gnus-agent
54506618 5104 (gnus-agent-possibly-alter-active group (gnus-active group) info)
132cf96d 5105
23f87bed
MB
5106 (setq gnus-summary-use-undownloaded-faces
5107 (gnus-agent-find-parameter
5108 group
5109 'agent-enable-undownloaded-faces)))
5110
5111 (setq gnus-newsgroup-name group
5112 gnus-newsgroup-unselected nil
5113 gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5114
5115 (let ((display (gnus-group-find-parameter group 'display)))
5116 (setq gnus-newsgroup-display
5117 (cond
5118 ((not (zerop (or (car-safe read-all) 0)))
5119 ;; The user entered the group with C-u SPC/RET, let's show
5120 ;; all articles.
5121 'gnus-not-ignore)
5122 ((eq display 'all)
5123 'gnus-not-ignore)
5124 ((arrayp display)
5125 (gnus-summary-display-make-predicate (mapcar 'identity display)))
5126 ((numberp display)
5127 ;; The following is probably the "correct" solution, but
5128 ;; it makes Gnus fetch all headers and then limit the
5129 ;; articles (which is slow), so instead we hack the
5130 ;; select-articles parameter instead. -- Simon Josefsson
5131 ;; <jas@kth.se>
5132 ;;
5133 ;; (gnus-byte-compile
5134 ;; `(lambda () (> number ,(- (cdr (gnus-active group))
5135 ;; display)))))
5136 (setq select-articles
5137 (gnus-uncompress-range
5138 (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5139 (if (> tmp 0)
5140 tmp
5141 1))
5142 (cdr (gnus-active group)))))
5143 nil)
5144 (t
5145 nil))))
eec82323 5146
23f87bed 5147 (gnus-summary-setup-default-charset)
eec82323
LMI
5148
5149 ;; Kludge to avoid having cached articles nixed out in virtual groups.
5150 (when (gnus-virtual-group-p group)
5151 (setq cached gnus-newsgroup-cached))
5152
5153 (setq gnus-newsgroup-unreads
23f87bed
MB
5154 (gnus-sorted-ndifference
5155 (gnus-sorted-ndifference gnus-newsgroup-unreads
5156 gnus-newsgroup-marked)
eec82323
LMI
5157 gnus-newsgroup-dormant))
5158
5159 (setq gnus-newsgroup-processable nil)
5160
5161 (gnus-update-read-articles group gnus-newsgroup-unreads)
eec82323 5162
23f87bed
MB
5163 ;; Adjust and set lists of article marks.
5164 (when info
5165 (gnus-adjust-marked-articles info))
6748645f
LMI
5166 (if (setq articles select-articles)
5167 (setq gnus-newsgroup-unselected
23f87bed 5168 (gnus-sorted-difference gnus-newsgroup-unreads articles))
6748645f 5169 (setq articles (gnus-articles-to-read group read-all)))
eec82323
LMI
5170
5171 (cond
5172 ((null articles)
5173 ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5174 'quit)
5175 ((eq articles 0) nil)
5176 (t
5177 ;; Init the dependencies hash table.
5178 (setq gnus-newsgroup-dependencies
5179 (gnus-make-hashtable (length articles)))
16409b0b 5180 (gnus-set-global-variables)
eec82323 5181 ;; Retrieve the headers and read them in.
23f87bed
MB
5182
5183 (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
eec82323
LMI
5184
5185 ;; Kludge to avoid having cached articles nixed out in virtual groups.
5186 (when cached
5187 (setq gnus-newsgroup-cached cached))
5188
5189 ;; Suppress duplicates?
5190 (when gnus-suppress-duplicates
5191 (gnus-dup-suppress-articles))
5192
5193 ;; Set the initial limit.
5194 (setq gnus-newsgroup-limit (copy-sequence articles))
5195 ;; Remove canceled articles from the list of unread articles.
23f87bed
MB
5196 (setq fetched-articles
5197 (mapcar (lambda (headers) (mail-header-number headers))
5198 gnus-newsgroup-headers))
5199 (setq gnus-newsgroup-articles fetched-articles)
eec82323 5200 (setq gnus-newsgroup-unreads
23f87bed
MB
5201 (gnus-sorted-nintersection
5202 gnus-newsgroup-unreads fetched-articles))
5203 (gnus-compute-unseen-list)
5204
eec82323
LMI
5205 ;; Removed marked articles that do not exist.
5206 (gnus-update-missing-marks
23f87bed 5207 (gnus-sorted-difference articles fetched-articles))
eec82323 5208 ;; We might want to build some more threads first.
6748645f
LMI
5209 (when (and gnus-fetch-old-headers
5210 (eq gnus-headers-retrieved-by 'nov))
5211 (if (eq gnus-fetch-old-headers 'invisible)
5212 (gnus-build-all-threads)
5213 (gnus-build-old-threads)))
5214 ;; Let the Gnus agent mark articles as read.
5215 (when gnus-agent
5216 (gnus-agent-get-undownloaded-list))
16409b0b
GM
5217 ;; Remove list identifiers from subject
5218 (when gnus-list-identifiers
5219 (gnus-summary-remove-list-identifiers))
eec82323
LMI
5220 ;; Check whether auto-expire is to be done in this group.
5221 (setq gnus-newsgroup-auto-expire
5222 (gnus-group-auto-expirable-p group))
5223 ;; Set up the article buffer now, if necessary.
5224 (unless gnus-single-article-buffer
5225 (gnus-article-setup-buffer))
5226 ;; First and last article in this newsgroup.
5227 (when gnus-newsgroup-headers
5228 (setq gnus-newsgroup-begin
5229 (mail-header-number (car gnus-newsgroup-headers))
5230 gnus-newsgroup-end
5231 (mail-header-number
5232 (gnus-last-element gnus-newsgroup-headers))))
5233 ;; GROUP is successfully selected.
5234 (or gnus-newsgroup-headers t)))))
5235
23f87bed
MB
5236(defun gnus-compute-unseen-list ()
5237 ;; The `seen' marks are treated specially.
5238 (if (not gnus-newsgroup-seen)
5239 (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5240 (setq gnus-newsgroup-unseen
5241 (gnus-inverse-list-range-intersection
5242 gnus-newsgroup-articles gnus-newsgroup-seen))))
5243
5244(defun gnus-summary-display-make-predicate (display)
5245 (require 'gnus-agent)
5246 (when (= (length display) 1)
5247 (setq display (car display)))
5248 (unless gnus-summary-display-cache
5249 (dolist (elem (append '((unread . unread)
5250 (read . read)
5251 (unseen . unseen))
5252 gnus-article-mark-lists))
5253 (push (cons (cdr elem)
5254 (gnus-byte-compile
5255 `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5256 gnus-summary-display-cache)))
5257 (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5258 (gnus-category-predicate-cache gnus-summary-display-cache))
5259 (gnus-get-predicate display)))
5260
5261;; Uses the dynamically bound `number' variable.
5262(eval-when-compile
5263 (defvar number))
5264(defun gnus-article-marked-p (type &optional article)
5265 (let ((article (or article number)))
5266 (cond
5267 ((eq type 'tick)
5268 (memq article gnus-newsgroup-marked))
5269 ((eq type 'spam)
5270 (memq article gnus-newsgroup-spam-marked))
5271 ((eq type 'unsend)
5272 (memq article gnus-newsgroup-unsendable))
5273 ((eq type 'undownload)
5274 (memq article gnus-newsgroup-undownloaded))
5275 ((eq type 'download)
5276 (memq article gnus-newsgroup-downloadable))
5277 ((eq type 'unread)
5278 (memq article gnus-newsgroup-unreads))
5279 ((eq type 'read)
5280 (memq article gnus-newsgroup-reads))
5281 ((eq type 'dormant)
5282 (memq article gnus-newsgroup-dormant) )
5283 ((eq type 'expire)
5284 (memq article gnus-newsgroup-expirable))
5285 ((eq type 'reply)
5286 (memq article gnus-newsgroup-replied))
5287 ((eq type 'killed)
5288 (memq article gnus-newsgroup-killed))
5289 ((eq type 'bookmark)
5290 (assq article gnus-newsgroup-bookmarks))
5291 ((eq type 'score)
5292 (assq article gnus-newsgroup-scored))
5293 ((eq type 'save)
5294 (memq article gnus-newsgroup-saved))
5295 ((eq type 'cache)
5296 (memq article gnus-newsgroup-cached))
5297 ((eq type 'forward)
5298 (memq article gnus-newsgroup-forwarded))
5299 ((eq type 'seen)
5300 (not (memq article gnus-newsgroup-unseen)))
5301 ((eq type 'recent)
5302 (memq article gnus-newsgroup-recent))
5303 (t t))))
5304
eec82323 5305(defun gnus-articles-to-read (group &optional read-all)
16409b0b 5306 "Find out what articles the user wants to read."
23f87bed
MB
5307 (let* ((display (gnus-group-find-parameter group 'display))
5308 (articles
eec82323
LMI
5309 ;; Select all articles if `read-all' is non-nil, or if there
5310 ;; are no unread articles.
5311 (if (or read-all
5312 (and (zerop (length gnus-newsgroup-marked))
5313 (zerop (length gnus-newsgroup-unreads)))
23f87bed
MB
5314 ;; Fetch all if the predicate is non-nil.
5315 gnus-newsgroup-display)
5316 ;; We want to select the headers for all the articles in
5317 ;; the group, so we select either all the active
5318 ;; articles in the group, or (if that's nil), the
5319 ;; articles in the cache.
16409b0b
GM
5320 (or
5321 (gnus-uncompress-range (gnus-active group))
5322 (gnus-cache-articles-in-group group))
23f87bed
MB
5323 ;; Select only the "normal" subset of articles.
5324 (gnus-sorted-nunion
5325 (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5326 gnus-newsgroup-unreads)))
eec82323
LMI
5327 (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5328 (scored (length scored-list))
5329 (number (length articles))
5330 (marked (+ (length gnus-newsgroup-marked)
5331 (length gnus-newsgroup-dormant)))
5332 (select
5333 (cond
5334 ((numberp read-all)
5335 read-all)
23f87bed
MB
5336 ((numberp gnus-newsgroup-display)
5337 gnus-newsgroup-display)
eec82323
LMI
5338 (t
5339 (condition-case ()
5340 (cond
5341 ((and (or (<= scored marked) (= scored number))
5342 (numberp gnus-large-newsgroup)
5343 (> number gnus-large-newsgroup))
23f87bed
MB
5344 (let* ((cursor-in-echo-area nil)
5345 (initial (gnus-parameter-large-newsgroup-initial
5346 gnus-newsgroup-name))
5347 (input
5348 (read-string
5349 (format
5350 "How many articles from %s (%s %d): "
5351 (gnus-limit-string
5352 (gnus-group-decoded-name gnus-newsgroup-name)
5353 35)
5354 (if initial "max" "default")
5355 number)
5356 (if initial
5357 (cons (number-to-string initial)
5358 0)))))
eec82323
LMI
5359 (if (string-match "^[ \t]*$" input) number input)))
5360 ((and (> scored marked) (< scored number)
5361 (> (- scored number) 20))
5362 (let ((input
5363 (read-string
5364 (format "%s %s (%d scored, %d total): "
5365 "How many articles from"
23f87bed
MB
5366 (gnus-group-decoded-name group)
5367 scored number))))
eec82323
LMI
5368 (if (string-match "^[ \t]*$" input)
5369 number input)))
5370 (t number))
d4dfaa19
DL
5371 (quit
5372 (message "Quit getting the articles to read")
5373 nil))))))
eec82323
LMI
5374 (setq select (if (stringp select) (string-to-number select) select))
5375 (if (or (null select) (zerop select))
5376 select
5377 (if (and (not (zerop scored)) (<= (abs select) scored))
5378 (progn
5379 (setq articles (sort scored-list '<))
5380 (setq number (length articles)))
5381 (setq articles (copy-sequence articles)))
5382
5383 (when (< (abs select) number)
5384 (if (< select 0)
5385 ;; Select the N oldest articles.
5386 (setcdr (nthcdr (1- (abs select)) articles) nil)
5387 ;; Select the N most recent articles.
5388 (setq articles (nthcdr (- number select) articles))))
5389 (setq gnus-newsgroup-unselected
23f87bed 5390 (gnus-sorted-difference gnus-newsgroup-unreads articles))
16409b0b 5391 (when gnus-alter-articles-to-read-function
23f87bed 5392 (setq articles
a1506d29 5393 (sort
16409b0b 5394 (funcall gnus-alter-articles-to-read-function
23f87bed 5395 gnus-newsgroup-name articles)
16409b0b 5396 '<)))
eec82323
LMI
5397 articles)))
5398
5399(defun gnus-killed-articles (killed articles)
5400 (let (out)
5401 (while articles
5402 (when (inline (gnus-member-of-range (car articles) killed))
5403 (push (car articles) out))
5404 (setq articles (cdr articles)))
5405 out))
5406
5407(defun gnus-uncompress-marks (marks)
5408 "Uncompress the mark ranges in MARKS."
5409 (let ((uncompressed '(score bookmark))
5410 out)
5411 (while marks
5412 (if (memq (caar marks) uncompressed)
5413 (push (car marks) out)
5414 (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5415 (setq marks (cdr marks)))
5416 out))
5417
23f87bed
MB
5418(defun gnus-article-mark-to-type (mark)
5419 "Return the type of MARK."
5420 (or (cadr (assq mark gnus-article-special-mark-lists))
5421 'list))
5422
5423(defun gnus-article-unpropagatable-p (mark)
5424 "Return whether MARK should be propagated to back end."
5425 (memq mark gnus-article-unpropagated-mark-lists))
5426
eec82323 5427(defun gnus-adjust-marked-articles (info)
16409b0b 5428 "Set all article lists and remove all marks that are no longer valid."
eec82323
LMI
5429 (let* ((marked-lists (gnus-info-marks info))
5430 (active (gnus-active (gnus-info-group info)))
5431 (min (car active))
5432 (max (cdr active))
5433 (types gnus-article-mark-lists)
54506618
MB
5434 marks var articles article mark mark-type
5435 bgn end)
eec82323 5436
23f87bed
MB
5437 (dolist (marks marked-lists)
5438 (setq mark (car marks)
5439 mark-type (gnus-article-mark-to-type mark)
5440 var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
eec82323 5441
23f87bed
MB
5442 ;; We set the variable according to the type of the marks list,
5443 ;; and then adjust the marks to a subset of the active articles.
eec82323 5444 (cond
54506618 5445 ;; Adjust "simple" lists - compressed yet unsorted
23f87bed 5446 ((eq mark-type 'list)
54506618
MB
5447 ;; Simultaneously uncompress and clip to active range
5448 ;; See gnus-uncompress-range for a description of possible marks
5449 (let (l lh)
5450 (if (not (cadr marks))
5451 (set var nil)
5452 (setq articles (if (numberp (cddr marks))
5453 (list (cdr marks))
5454 (cdr marks))
5455 lh (cons nil nil)
5456 l lh)
5457
5458 (while (setq article (pop articles))
5459 (cond ((consp article)
5460 (setq bgn (max (car article) min)
5461 end (min (cdr article) max))
5462 (while (<= bgn end)
5463 (setq l (setcdr l (cons bgn nil))
5464 bgn (1+ bgn))))
5465 ((and (<= min article)
5466 (>= max article))
5467 (setq l (setcdr l (cons article nil))))))
5468 (set var (cdr lh)))))
eec82323 5469 ;; Adjust assocs.
23f87bed
MB
5470 ((eq mark-type 'tuple)
5471 (set var (setq articles (cdr marks)))
a8151ef7
LMI
5472 (when (not (listp (cdr (symbol-value var))))
5473 (set var (list (symbol-value var))))
5474 (when (not (listp (cdr articles)))
5475 (setq articles (list articles)))
eec82323
LMI
5476 (while articles
5477 (when (or (not (consp (setq article (pop articles))))
5478 (< (car article) min)
5479 (> (car article) max))
23f87bed
MB
5480 (set var (delq article (symbol-value var))))))
5481 ;; Adjust ranges (sloppily).
5482 ((eq mark-type 'range)
5483 (cond
5484 ((eq mark 'seen)
5485 ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5486 ;; It should be (seen (NUM1 . NUM2)).
5487 (when (numberp (cddr marks))
5488 (setcdr marks (list (cdr marks))))
5489 (setq articles (cdr marks))
5490 (while (and articles
5491 (or (and (consp (car articles))
5492 (> min (cdar articles)))
5493 (and (numberp (car articles))
5494 (> min (car articles)))))
5495 (pop articles))
5496 (set var articles))))))))
eec82323
LMI
5497
5498(defun gnus-update-missing-marks (missing)
6748645f 5499 "Go through the list of MISSING articles and remove them from the mark lists."
eec82323 5500 (when missing
23f87bed 5501 (let (var m)
eec82323 5502 ;; Go through all types.
23f87bed
MB
5503 (dolist (elem gnus-article-mark-lists)
5504 (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5505 (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5506 (when (symbol-value var)
5507 ;; This list has articles. So we delete all missing
5508 ;; articles from it.
5509 (setq m missing)
5510 (while m
5511 (set var (delq (pop m) (symbol-value var))))))))))
eec82323
LMI
5512
5513(defun gnus-update-marks ()
5514 "Enter the various lists of marked articles into the newsgroup info list."
5515 (let ((types gnus-article-mark-lists)
5516 (info (gnus-get-info gnus-newsgroup-name))
16409b0b 5517 type list newmarked symbol delta-marks)
eec82323 5518 (when info
16409b0b 5519 ;; Add all marks lists to the list of marks lists.
eec82323 5520 (while (setq type (pop types))
16409b0b
GM
5521 (setq list (symbol-value
5522 (setq symbol
23f87bed 5523 (intern (format "gnus-newsgroup-%s" (car type))))))
eec82323 5524
16409b0b 5525 (when list
eec82323
LMI
5526 ;; Get rid of the entries of the articles that have the
5527 ;; default score.
5528 (when (and (eq (cdr type) 'score)
5529 gnus-save-score
5530 list)
5531 (let* ((arts list)
5532 (prev (cons nil list))
5533 (all prev))
5534 (while arts
5535 (if (or (not (consp (car arts)))
5536 (= (cdar arts) gnus-summary-default-score))
5537 (setcdr prev (cdr arts))
5538 (setq prev arts))
5539 (setq arts (cdr arts)))
16409b0b
GM
5540 (setq list (cdr all)))))
5541
23f87bed
MB
5542 (when (eq (cdr type) 'seen)
5543 (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5544
5545 (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
16409b0b 5546 (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
a1506d29 5547
23f87bed
MB
5548 (when (and (gnus-check-backend-function
5549 'request-set-mark gnus-newsgroup-name)
5550 (not (gnus-article-unpropagatable-p (cdr type))))
5551 (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5552 (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5553 (add (gnus-remove-from-range
5554 (gnus-copy-sequence list) old)))
5555 (when add
5556 (push (list add 'add (list (cdr type))) delta-marks))
5557 (when del
5558 (push (list del 'del (list (cdr type))) delta-marks))))
a1506d29 5559
16409b0b
GM
5560 (when list
5561 (push (cons (cdr type) list) newmarked)))
5562
5563 (when delta-marks
5564 (unless (gnus-check-group gnus-newsgroup-name)
5565 (error "Can't open server for %s" gnus-newsgroup-name))
5566 (gnus-request-set-mark gnus-newsgroup-name delta-marks))
a1506d29 5567
eec82323
LMI
5568 ;; Enter these new marks into the info of the group.
5569 (if (nthcdr 3 info)
5570 (setcar (nthcdr 3 info) newmarked)
5571 ;; Add the marks lists to the end of the info.
5572 (when newmarked
5573 (setcdr (nthcdr 2 info) (list newmarked))))
5574
5575 ;; Cut off the end of the info if there's nothing else there.
5576 (let ((i 5))
5577 (while (and (> i 2)
5578 (not (nth i info)))
5579 (when (nthcdr (decf i) info)
5580 (setcdr (nthcdr i info) nil)))))))
5581
5582(defun gnus-set-mode-line (where)
16409b0b 5583 "Set the mode line of the article or summary buffers.
eec82323
LMI
5584If WHERE is `summary', the summary mode line format will be used."
5585 ;; Is this mode line one we keep updated?
16409b0b
GM
5586 (when (and (memq where gnus-updated-mode-lines)
5587 (symbol-value
5588 (intern (format "gnus-%s-mode-line-format-spec" where))))
eec82323
LMI
5589 (let (mode-string)
5590 (save-excursion
5591 ;; We evaluate this in the summary buffer since these
5592 ;; variables are buffer-local to that buffer.
5593 (set-buffer gnus-summary-buffer)
23f87bed 5594 ;; We bind all these variables that are used in the `eval' form
eec82323
LMI
5595 ;; below.
5596 (let* ((mformat (symbol-value
5597 (intern
5598 (format "gnus-%s-mode-line-format-spec" where))))
23f87bed
MB
5599 (gnus-tmp-group-name (gnus-group-decoded-name
5600 gnus-newsgroup-name))
eec82323
LMI
5601 (gnus-tmp-article-number (or gnus-current-article 0))
5602 (gnus-tmp-unread gnus-newsgroup-unreads)
5603 (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5604 (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5605 (gnus-tmp-unread-and-unselected
5606 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5607 (zerop gnus-tmp-unselected))
5608 "")
5609 ((zerop gnus-tmp-unselected)
5610 (format "{%d more}" gnus-tmp-unread-and-unticked))
5611 (t (format "{%d(+%d) more}"
5612 gnus-tmp-unread-and-unticked
5613 gnus-tmp-unselected))))
5614 (gnus-tmp-subject
5615 (if (and gnus-current-headers
5616 (vectorp gnus-current-headers))
5617 (gnus-mode-string-quote
5618 (mail-header-subject gnus-current-headers))
5619 ""))
5620 bufname-length max-len
23f87bed 5621 gnus-tmp-header) ;; passed as argument to any user-format-funcs
eec82323
LMI
5622 (setq mode-string (eval mformat))
5623 (setq bufname-length (if (string-match "%b" mode-string)
5624 (- (length
5625 (buffer-name
5626 (if (eq where 'summary)
5627 nil
5628 (get-buffer gnus-article-buffer))))
5629 2)
5630 0))
5631 (setq max-len (max 4 (if gnus-mode-non-string-length
5632 (- (window-width)
5633 gnus-mode-non-string-length
5634 bufname-length)
5635 (length mode-string))))
5636 ;; We might have to chop a bit of the string off...
5637 (when (> (length mode-string) max-len)
5638 (setq mode-string
16409b0b 5639 (concat (truncate-string-to-width mode-string (- max-len 3))
eec82323
LMI
5640 "...")))
5641 ;; Pad the mode string a bit.
5642 (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5643 ;; Update the mode line.
5644 (setq mode-line-buffer-identification
5645 (gnus-mode-line-buffer-identification (list mode-string)))
5646 (set-buffer-modified-p t))))
5647
5648(defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5649 "Go through the HEADERS list and add all Xrefs to a hash table.
5650The resulting hash table is returned, or nil if no Xrefs were found."
5651 (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5652 (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5653 (xref-hashtb (gnus-make-hashtable))
5654 start group entry number xrefs header)
5655 (while headers
5656 (setq header (pop headers))
5657 (when (and (setq xrefs (mail-header-xref header))
5658 (not (memq (setq number (mail-header-number header))
5659 unreads)))
5660 (setq start 0)
5661 (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5662 (setq start (match-end 0))
5663 (setq group (if prefix
5664 (concat prefix (substring xrefs (match-beginning 1)
5665 (match-end 1)))
5666 (substring xrefs (match-beginning 1) (match-end 1))))
5667 (setq number
e9bd5782 5668 (string-to-number (substring xrefs (match-beginning 2)
eec82323
LMI
5669 (match-end 2))))
5670 (if (setq entry (gnus-gethash group xref-hashtb))
5671 (setcdr entry (cons number (cdr entry)))
5672 (gnus-sethash group (cons number nil) xref-hashtb)))))
5673 (and start xref-hashtb)))
5674
5675(defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5676 "Look through all the headers and mark the Xrefs as read."
5677 (let ((virtual (gnus-virtual-group-p from-newsgroup))
5678 name entry info xref-hashtb idlist method nth4)
5679 (save-excursion
5680 (set-buffer gnus-group-buffer)
5681 (when (setq xref-hashtb
5682 (gnus-create-xref-hashtb from-newsgroup headers unreads))
5683 (mapatoms
5684 (lambda (group)
5685 (unless (string= from-newsgroup (setq name (symbol-name group)))
5686 (setq idlist (symbol-value group))
5687 ;; Dead groups are not updated.
5688 (and (prog1
5689 (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5690 info (nth 2 entry))
5691 (when (stringp (setq nth4 (gnus-info-method info)))
5692 (setq nth4 (gnus-server-to-method nth4))))
5693 ;; Only do the xrefs if the group has the same
5694 ;; select method as the group we have just read.
5695 (or (gnus-methods-equal-p
5696 nth4 (gnus-find-method-for-group from-newsgroup))
5697 virtual
5698 (equal nth4 (setq method (gnus-find-method-for-group
5699 from-newsgroup)))
5700 (and (equal (car nth4) (car method))
5701 (equal (nth 1 nth4) (nth 1 method))))
5702 gnus-use-cross-reference
5703 (or (not (eq gnus-use-cross-reference t))
5704 virtual
5705 ;; Only do cross-references on subscribed
5706 ;; groups, if that is what is wanted.
5707 (<= (gnus-info-level info) gnus-level-subscribed))
5708 (gnus-group-make-articles-read name idlist))))
5709 xref-hashtb)))))
5710
6748645f
LMI
5711(defun gnus-compute-read-articles (group articles)
5712 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5713 (info (nth 2 entry))
5714 (active (gnus-active group))
5715 ninfo)
5716 (when entry
16409b0b 5717 ;; First peel off all invalid article numbers.
6748645f
LMI
5718 (when active
5719 (let ((ids articles)
5720 id first)
5721 (while (setq id (pop ids))
5722 (when (and first (> id (cdr active)))
5723 ;; We'll end up in this situation in one particular
5724 ;; obscure situation. If you re-scan a group and get
5725 ;; a new article that is cross-posted to a different
5726 ;; group that has not been re-scanned, you might get
5727 ;; crossposted article that has a higher number than
5728 ;; Gnus believes possible. So we re-activate this
5729 ;; group as well. This might mean doing the
5730 ;; crossposting thingy will *increase* the number
5731 ;; of articles in some groups. Tsk, tsk.
5732 (setq active (or (gnus-activate-group group) active)))
5733 (when (or (> id (cdr active))
5734 (< id (car active)))
5735 (setq articles (delq id articles))))))
5736 ;; If the read list is nil, we init it.
5737 (if (and active
5738 (null (gnus-info-read info))
5739 (> (car active) 1))
5740 (setq ninfo (cons 1 (1- (car active))))
5741 (setq ninfo (gnus-info-read info)))
5742 ;; Then we add the read articles to the range.
5743 (gnus-add-to-range
5744 ninfo (setq articles (sort articles '<))))))
5745
eec82323
LMI
5746(defun gnus-group-make-articles-read (group articles)
5747 "Update the info of GROUP to say that ARTICLES are read."
5748 (let* ((num 0)
5749 (entry (gnus-gethash group gnus-newsrc-hashtb))
5750 (info (nth 2 entry))
5751 (active (gnus-active group))
5752 range)
6748645f
LMI
5753 (when entry
5754 (setq range (gnus-compute-read-articles group articles))
5755 (save-excursion
5756 (set-buffer gnus-group-buffer)
5757 (gnus-undo-register
5758 `(progn
5759 (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5760 (gnus-info-set-read ',info ',(gnus-info-read info))
5761 (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
23f87bed 5762 (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6748645f
LMI
5763 (gnus-group-update-group ,group t))))
5764 ;; Add the read articles to the range.
5765 (gnus-info-set-read info range)
23f87bed 5766 (gnus-request-set-mark group (list (list range 'add '(read))))
6748645f
LMI
5767 ;; Then we have to re-compute how many unread
5768 ;; articles there are in this group.
5769 (when active
5770 (cond
5771 ((not range)
5772 (setq num (- (1+ (cdr active)) (car active))))
5773 ((not (listp (cdr range)))
5774 (setq num (- (cdr active) (- (1+ (cdr range))
5775 (car range)))))
5776 (t
5777 (while range
5778 (if (numberp (car range))
5779 (setq num (1+ num))
5780 (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5781 (setq range (cdr range)))
5782 (setq num (- (cdr active) num))))
5783 ;; Update the number of unread articles.
5784 (setcar entry num)
5785 ;; Update the group buffer.
23f87bed
MB
5786 (unless (gnus-ephemeral-group-p group)
5787 (gnus-group-update-group group t))))))
eec82323 5788
eec82323
LMI
5789(defvar gnus-newsgroup-none-id 0)
5790
5791(defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5792 (let ((cur nntp-server-buffer)
5793 (dependencies
5794 (or dependencies
5795 (save-excursion (set-buffer gnus-summary-buffer)
5796 gnus-newsgroup-dependencies)))
16409b0b
GM
5797 headers id end ref
5798 (mail-parse-charset gnus-newsgroup-charset)
5799 (mail-parse-ignored-charsets
5800 (save-excursion (condition-case nil
5801 (set-buffer gnus-summary-buffer)
5802 (error))
5803 gnus-newsgroup-ignored-charsets)))
eec82323
LMI
5804 (save-excursion
5805 (set-buffer nntp-server-buffer)
5806 ;; Translate all TAB characters into SPACE characters.
5807 (subst-char-in-region (point-min) (point-max) ?\t ? t)
16409b0b 5808 (subst-char-in-region (point-min) (point-max) ?\r ? t)
23f87bed 5809 (ietf-drums-unfold-fws)
6748645f 5810 (gnus-run-hooks 'gnus-parse-headers-hook)
eec82323 5811 (let ((case-fold-search t)
6748645f 5812 in-reply-to header p lines chars)
eec82323
LMI
5813 (goto-char (point-min))
5814 ;; Search to the beginning of the next header. Error messages
5815 ;; do not begin with 2 or 3.
5816 (while (re-search-forward "^[23][0-9]+ " nil t)
5817 (setq id nil
5818 ref nil)
5819 ;; This implementation of this function, with nine
5820 ;; search-forwards instead of the one re-search-forward and
5821 ;; a case (which basically was the old function) is actually
5822 ;; about twice as fast, even though it looks messier. You
5823 ;; can't have everything, I guess. Speed and elegance
5824 ;; doesn't always go hand in hand.
5825 (setq
5826 header
5827 (vector
5828 ;; Number.
5829 (prog1
5830 (read cur)
5831 (end-of-line)
5832 (setq p (point))
5833 (narrow-to-region (point)
5834 (or (and (search-forward "\n.\n" nil t)
5835 (- (point) 2))
5836 (point))))
5837 ;; Subject.
5838 (progn
5839 (goto-char p)
23f87bed 5840 (if (search-forward "\nsubject:" nil t)
16409b0b
GM
5841 (funcall gnus-decode-encoded-word-function
5842 (nnheader-header-value))
2bd3dcae 5843 "(none)"))
eec82323
LMI
5844 ;; From.
5845 (progn
5846 (goto-char p)
23f87bed 5847 (if (search-forward "\nfrom:" nil t)
16409b0b
GM
5848 (funcall gnus-decode-encoded-word-function
5849 (nnheader-header-value))
2bd3dcae 5850 "(nobody)"))
eec82323
LMI
5851 ;; Date.
5852 (progn
5853 (goto-char p)
23f87bed 5854 (if (search-forward "\ndate:" nil t)
eec82323
LMI
5855 (nnheader-header-value) ""))
5856 ;; Message-ID.
5857 (progn
5858 (goto-char p)
6748645f
LMI
5859 (setq id (if (re-search-forward
5860 "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5861 ;; We do it this way to make sure the Message-ID
5862 ;; is (somewhat) syntactically valid.
5863 (buffer-substring (match-beginning 1)
5864 (match-end 1))
eec82323
LMI
5865 ;; If there was no message-id, we just fake one
5866 ;; to make subsequent routines simpler.
5867 (nnheader-generate-fake-message-id))))
5868 ;; References.
5869 (progn
5870 (goto-char p)
23f87bed 5871 (if (search-forward "\nreferences:" nil t)
eec82323
LMI
5872 (progn
5873 (setq end (point))
5874 (prog1
5875 (nnheader-header-value)
5876 (setq ref
5877 (buffer-substring
5878 (progn
5879 (end-of-line)
5880 (search-backward ">" end t)
5881 (1+ (point)))
5882 (progn
5883 (search-backward "<" end t)
5884 (point))))))
5885 ;; Get the references from the in-reply-to header if there
5886 ;; were no references and the in-reply-to header looks
5887 ;; promising.
23f87bed 5888 (if (and (search-forward "\nin-reply-to:" nil t)
eec82323
LMI
5889 (setq in-reply-to (nnheader-header-value))
5890 (string-match "<[^>]+>" in-reply-to))
6748645f
LMI
5891 (let (ref2)
5892 (setq ref (substring in-reply-to (match-beginning 0)
5893 (match-end 0)))
5894 (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5895 (setq ref2 (substring in-reply-to (match-beginning 0)
5896 (match-end 0)))
5897 (when (> (length ref2) (length ref))
5898 (setq ref ref2)))
5899 ref)
eec82323
LMI
5900 (setq ref nil))))
5901 ;; Chars.
6748645f
LMI
5902 (progn
5903 (goto-char p)
5904 (if (search-forward "\nchars: " nil t)
5905 (if (numberp (setq chars (ignore-errors (read cur))))
23f87bed
MB
5906 chars -1)
5907 -1))
eec82323
LMI
5908 ;; Lines.
5909 (progn
5910 (goto-char p)
5911 (if (search-forward "\nlines: " nil t)
a8151ef7 5912 (if (numberp (setq lines (ignore-errors (read cur))))
23f87bed
MB
5913 lines -1)
5914 -1))
eec82323
LMI
5915 ;; Xref.
5916 (progn
5917 (goto-char p)
23f87bed 5918 (and (search-forward "\nxref:" nil t)
16409b0b
GM
5919 (nnheader-header-value)))
5920 ;; Extra.
5921 (when gnus-extra-headers
5922 (let ((extra gnus-extra-headers)
5923 out)
5924 (while extra
5925 (goto-char p)
5926 (when (search-forward
23f87bed 5927 (concat "\n" (symbol-name (car extra)) ":") nil t)
16409b0b
GM
5928 (push (cons (car extra) (nnheader-header-value))
5929 out))
5930 (pop extra))
5931 out))))
eec82323
LMI
5932 (when (equal id ref)
5933 (setq ref nil))
6748645f
LMI
5934
5935 (when gnus-alter-header-function
5936 (funcall gnus-alter-header-function header)
5937 (setq id (mail-header-id header)
5938 ref (gnus-parent-id (mail-header-references header))))
5939
5940 (when (setq header
5941 (gnus-dependencies-add-header
5942 header dependencies force-new))
eec82323
LMI
5943 (push header headers))
5944 (goto-char (point-max))
5945 (widen))
5946 (nreverse headers)))))
5947
eec82323
LMI
5948;; Goes through the xover lines and returns a list of vectors
5949(defun gnus-get-newsgroup-headers-xover (sequence &optional
5950 force-new dependencies
5951 group also-fetch-heads)
16409b0b
GM
5952 "Parse the news overview data in the server buffer.
5953Return a list of headers that match SEQUENCE (see
5954`nntp-retrieve-headers')."
eec82323
LMI
5955 ;; Get the Xref when the users reads the articles since most/some
5956 ;; NNTP servers do not include Xrefs when using XOVER.
5957 (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
16409b0b
GM
5958 (let ((mail-parse-charset gnus-newsgroup-charset)
5959 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5960 (cur nntp-server-buffer)
eec82323 5961 (dependencies (or dependencies gnus-newsgroup-dependencies))
23f87bed
MB
5962 (allp (cond
5963 ((eq gnus-read-all-available-headers t)
5964 t)
14e6dc54
MB
5965 ((and (stringp gnus-read-all-available-headers)
5966 group)
23f87bed
MB
5967 (string-match gnus-read-all-available-headers group))
5968 (t
5969 nil)))
eec82323
LMI
5970 number headers header)
5971 (save-excursion
5972 (set-buffer nntp-server-buffer)
16409b0b 5973 (subst-char-in-region (point-min) (point-max) ?\r ? t)
eec82323 5974 ;; Allow the user to mangle the headers before parsing them.
6748645f 5975 (gnus-run-hooks 'gnus-parse-headers-hook)
eec82323 5976 (goto-char (point-min))
23f87bed
MB
5977 (gnus-parse-without-error
5978 (while (and (or sequence allp)
5979 (not (eobp)))
5980 (setq number (read cur))
5981 (when (not allp)
5982 (while (and sequence
5983 (< (car sequence) number))
5984 (setq sequence (cdr sequence))))
5985 (when (and (or allp
5986 (and sequence
5987 (eq number (car sequence))))
5988 (progn
5989 (setq sequence (cdr sequence))
5990 (setq header (inline
5991 (gnus-nov-parse-line
5992 number dependencies force-new)))))
5993 (push header headers))
5994 (forward-line 1)))
eec82323
LMI
5995 ;; A common bug in inn is that if you have posted an article and
5996 ;; then retrieves the active file, it will answer correctly --
5997 ;; the new article is included. However, a NOV entry for the
5998 ;; article may not have been generated yet, so this may fail.
5999 ;; We work around this problem by retrieving the last few
6000 ;; headers using HEAD.
6001 (if (or (not also-fetch-heads)
6002 (not sequence))
6003 ;; We (probably) got all the headers.
6004 (nreverse headers)
6005 (let ((gnus-nov-is-evil t))
6006 (nconc
6007 (nreverse headers)
23f87bed 6008 (when (eq (gnus-retrieve-headers sequence group) 'headers)
eec82323
LMI
6009 (gnus-get-newsgroup-headers))))))))
6010
6011(defun gnus-article-get-xrefs ()
6012 "Fill in the Xref value in `gnus-current-headers', if necessary.
6013This is meant to be called in `gnus-article-internal-prepare-hook'."
6014 (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
6015 gnus-current-headers)))
6016 (or (not gnus-use-cross-reference)
6017 (not headers)
6018 (and (mail-header-xref headers)
6019 (not (string= (mail-header-xref headers) "")))
6020 (let ((case-fold-search t)
6021 xref)
6022 (save-restriction
6023 (nnheader-narrow-to-headers)
6024 (goto-char (point-min))
16409b0b
GM
6025 (when (or (and (not (eobp))
6026 (eq (downcase (char-after)) ?x)
eec82323
LMI
6027 (looking-at "Xref:"))
6028 (search-forward "\nXref:" nil t))
6029 (goto-char (1+ (match-end 0)))
23f87bed 6030 (setq xref (buffer-substring (point) (gnus-point-at-eol)))
eec82323
LMI
6031 (mail-header-set-xref headers xref)))))))
6032
6033(defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6748645f
LMI
6034 "Find article ID and insert the summary line for that article.
6035OLD-HEADER can either be a header or a line number to insert
6036the subject line on."
6037 (let* ((line (and (numberp old-header) old-header))
6038 (old-header (and (vectorp old-header) old-header))
6039 (header (cond ((and old-header use-old-header)
16409b0b
GM
6040 old-header)
6041 ((and (numberp id)
6042 (gnus-number-to-header id))
6043 (gnus-number-to-header id))
6044 (t
6045 (gnus-read-header id))))
6046 (number (and (numberp id) id))
6047 d)
eec82323
LMI
6048 (when header
6049 ;; Rebuild the thread that this article is part of and go to the
6050 ;; article we have fetched.
6051 (when (and (not gnus-show-threads)
6052 old-header)
6748645f
LMI
6053 (when (and number
6054 (setq d (gnus-data-find (mail-header-number old-header))))
eec82323
LMI
6055 (goto-char (gnus-data-pos d))
6056 (gnus-data-remove
6057 number
6058 (- (gnus-point-at-bol)
6059 (prog1
6060 (1+ (gnus-point-at-eol))
6061 (gnus-delete-line))))))
23f87bed
MB
6062 ;; Remove list identifiers from subject.
6063 (when gnus-list-identifiers
6064 (let ((gnus-newsgroup-headers (list header)))
c3bc41c2 6065 (gnus-summary-remove-list-identifiers)))
eec82323
LMI
6066 (when old-header
6067 (mail-header-set-number header (mail-header-number old-header)))
6068 (setq gnus-newsgroup-sparse
6069 (delq (setq number (mail-header-number header))
6070 gnus-newsgroup-sparse))
6071 (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6748645f
LMI
6072 (push number gnus-newsgroup-limit)
6073 (gnus-rebuild-thread (mail-header-id header) line)
eec82323
LMI
6074 (gnus-summary-goto-subject number nil t))
6075 (when (and (numberp number)
6076 (> number 0))
6077 ;; We have to update the boundaries even if we can't fetch the
6078 ;; article if ID is a number -- so that the next `P' or `N'
6079 ;; command will fetch the previous (or next) article even
6080 ;; if the one we tried to fetch this time has been canceled.
6081 (when (> number gnus-newsgroup-end)
6082 (setq gnus-newsgroup-end number))
6083 (when (< number gnus-newsgroup-begin)
6084 (setq gnus-newsgroup-begin number))
6085 (setq gnus-newsgroup-unselected
6086 (delq number gnus-newsgroup-unselected)))
6087 ;; Report back a success?
6088 (and header (mail-header-number header))))
6089
6090;;; Process/prefix in the summary buffer
6091
6092(defun gnus-summary-work-articles (n)
6748645f
LMI
6093 "Return a list of articles to be worked upon.
6094The prefix argument, the list of process marked articles, and the
6095current article will be taken into consideration."
6096 (save-excursion
6097 (set-buffer gnus-summary-buffer)
6098 (cond
6099 (n
6100 ;; A numerical prefix has been given.
6101 (setq n (prefix-numeric-value n))
6102 (let ((backward (< n 0))
6103 (n (abs (prefix-numeric-value n)))
6104 articles article)
6105 (save-excursion
6106 (while
6107 (and (> n 0)
6108 (push (setq article (gnus-summary-article-number))
6109 articles)
6110 (if backward
6111 (gnus-summary-find-prev nil article)
6112 (gnus-summary-find-next nil article)))
6113 (decf n)))
6114 (nreverse articles)))
6115 ((and (gnus-region-active-p) (mark))
6116 (message "region active")
6117 ;; Work on the region between point and mark.
6118 (let ((max (max (point) (mark)))
6119 articles article)
6120 (save-excursion
7dafe00b 6121 (goto-char (min (point) (mark)))
6748645f
LMI
6122 (while
6123 (and
6124 (push (setq article (gnus-summary-article-number)) articles)
6125 (gnus-summary-find-next nil article)
6126 (< (point) max)))
6127 (nreverse articles))))
6128 (gnus-newsgroup-processable
6129 ;; There are process-marked articles present.
6130 ;; Save current state.
6131 (gnus-summary-save-process-mark)
6132 ;; Return the list.
6133 (reverse gnus-newsgroup-processable))
6134 (t
6135 ;; Just return the current article.
6136 (list (gnus-summary-article-number))))))
6137
6138(defmacro gnus-summary-iterate (arg &rest forms)
6139 "Iterate over the process/prefixed articles and do FORMS.
6140ARG is the interactive prefix given to the command. FORMS will be
6141executed with point over the summary line of the articles."
6142 (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6143 `(let ((,articles (gnus-summary-work-articles ,arg)))
6144 (while ,articles
6145 (gnus-summary-goto-subject (car ,articles))
16409b0b
GM
6146 ,@forms
6147 (pop ,articles)))))
6748645f
LMI
6148
6149(put 'gnus-summary-iterate 'lisp-indent-function 1)
6150(put 'gnus-summary-iterate 'edebug-form-spec '(form body))
eec82323
LMI
6151
6152(defun gnus-summary-save-process-mark ()
6153 "Push the current set of process marked articles on the stack."
6154 (interactive)
6155 (push (copy-sequence gnus-newsgroup-processable)
6156 gnus-newsgroup-process-stack))
6157
6158(defun gnus-summary-kill-process-mark ()
6159 "Push the current set of process marked articles on the stack and unmark."
6160 (interactive)
6161 (gnus-summary-save-process-mark)
6162 (gnus-summary-unmark-all-processable))
6163
6164(defun gnus-summary-yank-process-mark ()
6165 "Pop the last process mark state off the stack and restore it."
6166 (interactive)
6167 (unless gnus-newsgroup-process-stack
6168 (error "Empty mark stack"))
6169 (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6170
6171(defun gnus-summary-process-mark-set (set)
6172 "Make SET into the current process marked articles."
6173 (gnus-summary-unmark-all-processable)
6174 (while set
6175 (gnus-summary-set-process-mark (pop set))))
6176
6177;;; Searching and stuff
6178
6179(defun gnus-summary-search-group (&optional backward use-level)
6180 "Search for next unread newsgroup.
6181If optional argument BACKWARD is non-nil, search backward instead."
6182 (save-excursion
6183 (set-buffer gnus-group-buffer)
6184 (when (gnus-group-search-forward
6185 backward nil (if use-level (gnus-group-group-level) nil))
6186 (gnus-group-group-name))))
6187
6188(defun gnus-summary-best-group (&optional exclude-group)
6189 "Find the name of the best unread group.
6190If EXCLUDE-GROUP, do not go to this group."
6191 (save-excursion
6192 (set-buffer gnus-group-buffer)
6193 (save-excursion
6194 (gnus-group-best-unread-group exclude-group))))
6195
23f87bed
MB
6196(defun gnus-summary-find-next (&optional unread article backward)
6197 (if backward
6198 (gnus-summary-find-prev unread article)
eec82323
LMI
6199 (let* ((dummy (gnus-summary-article-intangible-p))
6200 (article (or article (gnus-summary-article-number)))
23f87bed 6201 (data (gnus-data-find-list article))
eec82323
LMI
6202 result)
6203 (when (and (not dummy)
6204 (or (not gnus-summary-check-current)
6205 (not unread)
23f87bed
MB
6206 (not (gnus-data-unread-p (car data)))))
6207 (setq data (cdr data)))
eec82323
LMI
6208 (when (setq result
6209 (if unread
6210 (progn
23f87bed
MB
6211 (while data
6212 (unless (memq (gnus-data-number (car data))
6213 (cond
6214 ((eq gnus-auto-goto-ignores
6215 'always-undownloaded)
6216 gnus-newsgroup-undownloaded)
6217 (gnus-plugged
6218 nil)
6219 ((eq gnus-auto-goto-ignores
6220 'unfetched)
6221 gnus-newsgroup-unfetched)
6222 ((eq gnus-auto-goto-ignores
6223 'undownloaded)
6224 gnus-newsgroup-undownloaded)))
6225 (when (gnus-data-unread-p (car data))
6226 (setq result (car data)
6227 data nil)))
6228 (setq data (cdr data)))
eec82323 6229 result)
23f87bed 6230 (car data)))
eec82323
LMI
6231 (goto-char (gnus-data-pos result))
6232 (gnus-data-number result)))))
6233
6234(defun gnus-summary-find-prev (&optional unread article)
6235 (let* ((eobp (eobp))
6236 (article (or article (gnus-summary-article-number)))
23f87bed 6237 (data (gnus-data-find-list article (gnus-data-list 'rev)))
eec82323
LMI
6238 result)
6239 (when (and (not eobp)
6240 (or (not gnus-summary-check-current)
6241 (not unread)
23f87bed
MB
6242 (not (gnus-data-unread-p (car data)))))
6243 (setq data (cdr data)))
eec82323
LMI
6244 (when (setq result
6245 (if unread
6246 (progn
23f87bed
MB
6247 (while data
6248 (unless (memq (gnus-data-number (car data))
6249 (cond
6250 ((eq gnus-auto-goto-ignores
6251 'always-undownloaded)
6252 gnus-newsgroup-undownloaded)
6253 (gnus-plugged
6254 nil)
6255 ((eq gnus-auto-goto-ignores
6256 'unfetched)
6257 gnus-newsgroup-unfetched)
6258 ((eq gnus-auto-goto-ignores
6259 'undownloaded)
6260 gnus-newsgroup-undownloaded)))
6261 (when (gnus-data-unread-p (car data))
6262 (setq result (car data)
6263 data nil)))
6264 (setq data (cdr data)))
eec82323 6265 result)
23f87bed 6266 (car data)))
eec82323
LMI
6267 (goto-char (gnus-data-pos result))
6268 (gnus-data-number result))))
6269
6270(defun gnus-summary-find-subject (subject &optional unread backward article)
6271 (let* ((simp-subject (gnus-simplify-subject-fully subject))
6272 (article (or article (gnus-summary-article-number)))
6273 (articles (gnus-data-list backward))
6274 (arts (gnus-data-find-list article articles))
6275 result)
6276 (when (or (not gnus-summary-check-current)
6277 (not unread)
6278 (not (gnus-data-unread-p (car arts))))
6279 (setq arts (cdr arts)))
6280 (while arts
6281 (and (or (not unread)
6282 (gnus-data-unread-p (car arts)))
6283 (vectorp (gnus-data-header (car arts)))
6284 (gnus-subject-equal
6285 simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6286 (setq result (car arts)
6287 arts nil))
6288 (setq arts (cdr arts)))
6289 (and result
6290 (goto-char (gnus-data-pos result))
6291 (gnus-data-number result))))
6292
6293(defun gnus-summary-search-forward (&optional unread subject backward)
6294 "Search forward for an article.
6295If UNREAD, look for unread articles. If SUBJECT, look for
6296articles with that subject. If BACKWARD, search backward instead."
6297 (cond (subject (gnus-summary-find-subject subject unread backward))
6298 (backward (gnus-summary-find-prev unread))
6299 (t (gnus-summary-find-next unread))))
6300
6301(defun gnus-recenter (&optional n)
6302 "Center point in window and redisplay frame.
6303Also do horizontal recentering."
6304 (interactive "P")
6305 (when (and gnus-auto-center-summary
6306 (not (eq gnus-auto-center-summary 'vertical)))
6307 (gnus-horizontal-recenter))
6308 (recenter n))
6309
6310(defun gnus-summary-recenter ()
6311 "Center point in the summary window.
6312If `gnus-auto-center-summary' is nil, or the article buffer isn't
6313displayed, no centering will be performed."
6314 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6315 ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
16409b0b 6316 (interactive)
23f87bed
MB
6317 ;; The user has to want it.
6318 (when gnus-auto-center-summary
6319 (let* ((top (cond ((< (window-height) 4) 0)
6320 ((< (window-height) 7) 1)
6321 (t (if (numberp gnus-auto-center-summary)
6322 gnus-auto-center-summary
6323 2))))
6324 (height (1- (window-height)))
6325 (bottom (save-excursion (goto-char (point-max))
6326 (forward-line (- height))
6327 (point)))
6328 (window (get-buffer-window (current-buffer))))
eec82323
LMI
6329 (when (get-buffer-window gnus-article-buffer)
6330 ;; Only do recentering when the article buffer is displayed,
6331 ;; Set the window start to either `bottom', which is the biggest
6332 ;; possible valid number, or the second line from the top,
6333 ;; whichever is the least.
db7ebd73
MB
6334 (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6335 (if (> bottom top-pos)
6336 ;; Keep the second line from the top visible
6337 (set-window-start window top-pos t)
6338 ;; Try to keep the bottom line visible; if it's partially
6339 ;; obscured, either scroll one more line to make it fully
6340 ;; visible, or revert to using TOP-POS.
6341 (save-excursion
6342 (goto-char (point-max))
6343 (forward-line -1)
6344 (let ((last-line-start (point)))
6345 (goto-char bottom)
6346 (set-window-start window (point) t)
6347 (when (not (pos-visible-in-window-p last-line-start window))
6348 (forward-line 1)
6349 (set-window-start window (min (point) top-pos) t)))))))
eec82323
LMI
6350 ;; Do horizontal recentering while we're at it.
6351 (when (and (get-buffer-window (current-buffer) t)
6352 (not (eq gnus-auto-center-summary 'vertical)))
6353 (let ((selected (selected-window)))
6354 (select-window (get-buffer-window (current-buffer) t))
6355 (gnus-summary-position-point)
6356 (gnus-horizontal-recenter)
6357 (select-window selected))))))
6358
6359(defun gnus-summary-jump-to-group (newsgroup)
6360 "Move point to NEWSGROUP in group mode buffer."
6361 ;; Keep update point of group mode buffer if visible.
6362 (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6363 (save-window-excursion
6364 ;; Take care of tree window mode.
6365 (when (get-buffer-window gnus-group-buffer)
6366 (pop-to-buffer gnus-group-buffer))
6367 (gnus-group-jump-to-group newsgroup))
6368 (save-excursion
6369 ;; Take care of tree window mode.
6370 (if (get-buffer-window gnus-group-buffer)
6371 (pop-to-buffer gnus-group-buffer)
6372 (set-buffer gnus-group-buffer))
6373 (gnus-group-jump-to-group newsgroup))))
6374
6375;; This function returns a list of article numbers based on the
6376;; difference between the ranges of read articles in this group and
6377;; the range of active articles.
6378(defun gnus-list-of-unread-articles (group)
6379 (let* ((read (gnus-info-read (gnus-get-info group)))
6380 (active (or (gnus-active group) (gnus-activate-group group)))
6381 (last (cdr active))
6382 first nlast unread)
6383 ;; If none are read, then all are unread.
6384 (if (not read)
6385 (setq first (car active))
6386 ;; If the range of read articles is a single range, then the
6387 ;; first unread article is the article after the last read
6388 ;; article. Sounds logical, doesn't it?
16409b0b
GM
6389 (if (and (not (listp (cdr read)))
6390 (or (< (car read) (car active))
6391 (progn (setq read (list read))
6392 nil)))
6748645f 6393 (setq first (max (car active) (1+ (cdr read))))
eec82323
LMI
6394 ;; `read' is a list of ranges.
6395 (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6396 (caar read)))
6397 1)
6748645f 6398 (setq first (car active)))
eec82323
LMI
6399 (while read
6400 (when first
6401 (while (< first nlast)
54506618
MB
6402 (setq unread (cons first unread)
6403 first (1+ first))))
eec82323
LMI
6404 (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6405 (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6406 (setq read (cdr read)))))
6407 ;; And add the last unread articles.
6408 (while (<= first last)
54506618
MB
6409 (setq unread (cons first unread)
6410 first (1+ first)))
eec82323 6411 ;; Return the list of unread articles.
6748645f 6412 (delq 0 (nreverse unread))))
eec82323
LMI
6413
6414(defun gnus-list-of-read-articles (group)
6415 "Return a list of unread, unticked and non-dormant articles."
6416 (let* ((info (gnus-get-info group))
6417 (marked (gnus-info-marks info))
6418 (active (gnus-active group)))
6419 (and info active
23f87bed
MB
6420 (gnus-list-range-difference
6421 (gnus-list-range-difference
6422 (gnus-sorted-complement
6423 (gnus-uncompress-range active)
6424 (gnus-list-of-unread-articles group))
6425 (cdr (assq 'dormant marked)))
6426 (cdr (assq 'tick marked))))))
eec82323 6427
54506618
MB
6428;; This function returns a sequence of article numbers based on the
6429;; difference between the ranges of read articles in this group and
6430;; the range of active articles.
6431(defun gnus-sequence-of-unread-articles (group)
6432 (let* ((read (gnus-info-read (gnus-get-info group)))
6433 (active (or (gnus-active group) (gnus-activate-group group)))
6434 (last (cdr active))
6435 first nlast unread)
6436 ;; If none are read, then all are unread.
6437 (if (not read)
6438 (setq first (car active))
6439 ;; If the range of read articles is a single range, then the
6440 ;; first unread article is the article after the last read
6441 ;; article. Sounds logical, doesn't it?
6442 (if (and (not (listp (cdr read)))
6443 (or (< (car read) (car active))
6444 (progn (setq read (list read))
6445 nil)))
6446 (setq first (max (car active) (1+ (cdr read))))
6447 ;; `read' is a list of ranges.
6448 (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6449 (caar read)))
6450 1)
6451 (setq first (car active)))
6452 (while read
6453 (when first
6454 (push (cons first nlast) unread))
6455 (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6456 (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6457 (setq read (cdr read)))))
6458 ;; And add the last unread articles.
ba0226dd
MB
6459 (cond ((not (and first last))
6460 nil)
6461 ((< first last)
6462 (push (cons first last) unread))
6463 ((= first last)
6464 (push first unread)))
54506618
MB
6465 ;; Return the sequence of unread articles.
6466 (delq 0 (nreverse unread))))
6467
eec82323
LMI
6468;; Various summary commands
6469
6748645f
LMI
6470(defun gnus-summary-select-article-buffer ()
6471 "Reconfigure windows to show article buffer."
6472 (interactive)
6473 (if (not (gnus-buffer-live-p gnus-article-buffer))
6474 (error "There is no article buffer for this summary buffer")
6475 (gnus-configure-windows 'article)
6476 (select-window (get-buffer-window gnus-article-buffer))))
6477
eec82323
LMI
6478(defun gnus-summary-universal-argument (arg)
6479 "Perform any operation on all articles that are process/prefixed."
6480 (interactive "P")
eec82323
LMI
6481 (let ((articles (gnus-summary-work-articles arg))
6482 func article)
6483 (if (eq
6484 (setq
6485 func
6486 (key-binding
6487 (read-key-sequence
6488 (substitute-command-keys
16409b0b 6489 "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
eec82323
LMI
6490 'undefined)
6491 (gnus-error 1 "Undefined key")
6492 (save-excursion
6493 (while articles
6494 (gnus-summary-goto-subject (setq article (pop articles)))
6495 (let (gnus-newsgroup-processable)
6496 (command-execute func))
6497 (gnus-summary-remove-process-mark article)))))
6498 (gnus-summary-position-point))
6499
6500(defun gnus-summary-toggle-truncation (&optional arg)
6501 "Toggle truncation of summary lines.
23f87bed 6502With ARG, turn line truncation on if ARG is positive."
eec82323
LMI
6503 (interactive "P")
6504 (setq truncate-lines
6505 (if (null arg) (not truncate-lines)
6506 (> (prefix-numeric-value arg) 0)))
6507 (redraw-display))
6508
23f87bed
MB
6509(defun gnus-summary-find-for-reselect ()
6510 "Return the number of an article to stay on across a reselect.
6511The current article is considered, then following articles, then previous
6512articles. An article is sought which is not cancelled and isn't a temporary
6513insertion from another group. If there's no such then return a dummy 0."
6514 (let (found)
6515 (dolist (rev '(nil t))
6516 (unless found ; don't demand the reverse list if we don't need it
6517 (let ((data (gnus-data-find-list
6518 (gnus-summary-article-number) (gnus-data-list rev))))
6519 (while (and data (not found))
6520 (if (and (< 0 (gnus-data-number (car data)))
6521 (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6522 (setq found (gnus-data-number (car data))))
6523 (setq data (cdr data))))))
6524 (or found 0)))
6525
eec82323
LMI
6526(defun gnus-summary-reselect-current-group (&optional all rescan)
6527 "Exit and then reselect the current newsgroup.
6528The prefix argument ALL means to select all articles."
6529 (interactive "P")
eec82323
LMI
6530 (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6531 (error "Ephemeral groups can't be reselected"))
23f87bed 6532 (let ((current-subject (gnus-summary-find-for-reselect))
eec82323
LMI
6533 (group gnus-newsgroup-name))
6534 (setq gnus-newsgroup-begin nil)
23f87bed 6535 (gnus-summary-exit nil 'leave-hidden)
eec82323
LMI
6536 ;; We have to adjust the point of group mode buffer because
6537 ;; point was moved to the next unread newsgroup by exiting.
6538 (gnus-summary-jump-to-group group)
6539 (when rescan
6540 (save-excursion
6541 (gnus-group-get-new-news-this-group 1)))
6542 (gnus-group-read-group all t)
6543 (gnus-summary-goto-subject current-subject nil t)))
6544
6545(defun gnus-summary-rescan-group (&optional all)
6546 "Exit the newsgroup, ask for new articles, and select the newsgroup."
6547 (interactive "P")
6548 (gnus-summary-reselect-current-group all t))
6549
6550(defun gnus-summary-update-info (&optional non-destructive)
6551 (save-excursion
6552 (let ((group gnus-newsgroup-name))
6748645f
LMI
6553 (when group
6554 (when gnus-newsgroup-kill-headers
6555 (setq gnus-newsgroup-killed
6556 (gnus-compress-sequence
23f87bed
MB
6557 (gnus-sorted-union
6558 (gnus-list-range-intersection
6559 gnus-newsgroup-unselected gnus-newsgroup-killed)
6560 gnus-newsgroup-unreads)
6748645f
LMI
6561 t)))
6562 (unless (listp (cdr gnus-newsgroup-killed))
6563 (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6564 (let ((headers gnus-newsgroup-headers))
6565 ;; Set the new ranges of read articles.
6566 (save-excursion
6567 (set-buffer gnus-group-buffer)
6568 (gnus-undo-force-boundary))
6569 (gnus-update-read-articles
23f87bed
MB
6570 group (gnus-sorted-union
6571 gnus-newsgroup-unreads gnus-newsgroup-unselected))
6748645f
LMI
6572 ;; Set the current article marks.
6573 (let ((gnus-newsgroup-scored
6574 (if (and (not gnus-save-score)
6575 (not non-destructive))
6576 nil
6577 gnus-newsgroup-scored)))
6578 (save-excursion
6579 (gnus-update-marks)))
6580 ;; Do the cross-ref thing.
6581 (when gnus-use-cross-reference
6582 (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6583 ;; Do not switch windows but change the buffer to work.
a8151ef7 6584 (set-buffer gnus-group-buffer)
6748645f
LMI
6585 (unless (gnus-ephemeral-group-p group)
6586 (gnus-group-update-group group)))))))
eec82323
LMI
6587
6588(defun gnus-summary-save-newsrc (&optional force)
6589 "Save the current number of read/marked articles in the dribble buffer.
6590The dribble buffer will then be saved.
6591If FORCE (the prefix), also save the .newsrc file(s)."
6592 (interactive "P")
6593 (gnus-summary-update-info t)
6594 (if force
6595 (gnus-save-newsrc-file)
6596 (gnus-dribble-save)))
6597
23f87bed 6598(defun gnus-summary-exit (&optional temporary leave-hidden)
eec82323 6599 "Exit reading current newsgroup, and then return to group selection mode.
16409b0b 6600`gnus-exit-group-hook' is called with no arguments if that value is non-nil."
eec82323
LMI
6601 (interactive)
6602 (gnus-set-global-variables)
16409b0b
GM
6603 (when (gnus-buffer-live-p gnus-article-buffer)
6604 (save-excursion
6605 (set-buffer gnus-article-buffer)
6606 (mm-destroy-parts gnus-article-mime-handles)
6607 ;; Set it to nil for safety reason.
6608 (setq gnus-article-mime-handle-alist nil)
6609 (setq gnus-article-mime-handles nil)))
eec82323 6610 (gnus-kill-save-kill-buffer)
6748645f 6611 (gnus-async-halt-prefetch)
eec82323
LMI
6612 (let* ((group gnus-newsgroup-name)
6613 (quit-config (gnus-group-quit-config gnus-newsgroup-name))
23f87bed 6614 (gnus-group-is-exiting-p t)
eec82323 6615 (mode major-mode)
23f87bed 6616 (group-point nil)
eec82323 6617 (buf (current-buffer)))
16409b0b
GM
6618 (unless quit-config
6619 ;; Do adaptive scoring, and possibly save score files.
6620 (when gnus-newsgroup-adaptive
6621 (gnus-score-adaptive))
6622 (when gnus-use-scoring
6623 (gnus-score-save)))
6748645f 6624 (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
eec82323
LMI
6625 ;; If we have several article buffers, we kill them at exit.
6626 (unless gnus-single-article-buffer
6627 (gnus-kill-buffer gnus-original-article-buffer)
6628 (setq gnus-article-current nil))
6629 (when gnus-use-cache
6630 (gnus-cache-possibly-remove-articles)
6631 (gnus-cache-save-buffers))
6632 (gnus-async-prefetch-remove-group group)
6633 (when gnus-suppress-duplicates
6634 (gnus-dup-enter-articles))
6635 (when gnus-use-trees
6636 (gnus-tree-close group))
16409b0b
GM
6637 (when gnus-use-cache
6638 (gnus-cache-write-active))
6748645f
LMI
6639 ;; Remove entries for this group.
6640 (nnmail-purge-split-history (gnus-group-real-name group))
eec82323
LMI
6641 ;; Make all changes in this group permanent.
6642 (unless quit-config
6748645f 6643 (gnus-run-hooks 'gnus-exit-group-hook)
16409b0b 6644 (gnus-summary-update-info))
eec82323
LMI
6645 (gnus-close-group group)
6646 ;; Make sure where we were, and go to next newsgroup.
6647 (set-buffer gnus-group-buffer)
6648 (unless quit-config
6649 (gnus-group-jump-to-group group))
6748645f
LMI
6650 (gnus-run-hooks 'gnus-summary-exit-hook)
6651 (unless (or quit-config
6652 ;; If this group has disappeared from the summary
6653 ;; buffer, don't skip forwards.
6654 (not (string= group (gnus-group-group-name))))
eec82323 6655 (gnus-group-next-unread-group 1))
a8151ef7 6656 (setq group-point (point))
eec82323
LMI
6657 (if temporary
6658 nil ;Nothing to do.
6659 ;; If we have several article buffers, we kill them at exit.
6660 (unless gnus-single-article-buffer
6661 (gnus-kill-buffer gnus-article-buffer)
6662 (gnus-kill-buffer gnus-original-article-buffer)
6663 (setq gnus-article-current nil))
6664 (set-buffer buf)
6665 (if (not gnus-kill-summary-on-exit)
23f87bed
MB
6666 (progn
6667 (gnus-deaden-summary)
6668 (setq mode nil))
eec82323
LMI
6669 ;; We set all buffer-local variables to nil. It is unclear why
6670 ;; this is needed, but if we don't, buffer-local variables are
6671 ;; not garbage-collected, it seems. This would the lead to en
6672 ;; ever-growing Emacs.
6673 (gnus-summary-clear-local-variables)
23f87bed
MB
6674 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6675 (gnus-summary-clear-local-variables))
eec82323
LMI
6676 (when (get-buffer gnus-article-buffer)
6677 (bury-buffer gnus-article-buffer))
6678 ;; We clear the global counterparts of the buffer-local
6679 ;; variables as well, just to be on the safe side.
6680 (set-buffer gnus-group-buffer)
6681 (gnus-summary-clear-local-variables)
23f87bed
MB
6682 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6683 (gnus-summary-clear-local-variables))
eec82323
LMI
6684 ;; Return to group mode buffer.
6685 (when (eq mode 'gnus-summary-mode)
6686 (gnus-kill-buffer buf)))
6687 (setq gnus-current-select-method gnus-select-method)
d61c212b
SM
6688 (set-buffer gnus-group-buffer)
6689 (if quit-config
6690 (gnus-handle-ephemeral-exit quit-config)
4e90f2b9
SM
6691 (goto-char group-point)
6692 ;; If gnus-group-buffer is already displayed, make sure we also move
6693 ;; the cursor in the window that displays it.
6694 (let ((win (get-buffer-window (current-buffer) 0)))
6695 (if win (set-window-point win (point))))
d61c212b 6696 (unless leave-hidden
4e90f2b9 6697 (gnus-configure-windows 'group 'force)))
6748645f 6698 ;; Clear the current group name.
eec82323
LMI
6699 (unless quit-config
6700 (setq gnus-newsgroup-name nil)))))
6701
6702(defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6703(defun gnus-summary-exit-no-update (&optional no-questions)
6704 "Quit reading current newsgroup without updating read article info."
6705 (interactive)
eec82323 6706 (let* ((group gnus-newsgroup-name)
23f87bed
MB
6707 (gnus-group-is-exiting-p t)
6708 (gnus-group-is-exiting-without-update-p t)
eec82323
LMI
6709 (quit-config (gnus-group-quit-config group)))
6710 (when (or no-questions
6711 gnus-expert-user
6712 (gnus-y-or-n-p "Discard changes to this group and exit? "))
6748645f 6713 (gnus-async-halt-prefetch)
23f87bed 6714 (run-hooks 'gnus-summary-prepare-exit-hook)
16409b0b
GM
6715 (when (gnus-buffer-live-p gnus-article-buffer)
6716 (save-excursion
6717 (set-buffer gnus-article-buffer)
6718 (mm-destroy-parts gnus-article-mime-handles)
6719 ;; Set it to nil for safety reason.
6720 (setq gnus-article-mime-handle-alist nil)
6721 (setq gnus-article-mime-handles nil)))
eec82323
LMI
6722 ;; If we have several article buffers, we kill them at exit.
6723 (unless gnus-single-article-buffer
6724 (gnus-kill-buffer gnus-article-buffer)
6725 (gnus-kill-buffer gnus-original-article-buffer)
6726 (setq gnus-article-current nil))
6727 (if (not gnus-kill-summary-on-exit)
6728 (gnus-deaden-summary)
6729 (gnus-close-group group)
6730 (gnus-summary-clear-local-variables)
23f87bed
MB
6731 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6732 (gnus-summary-clear-local-variables))
eec82323
LMI
6733 (set-buffer gnus-group-buffer)
6734 (gnus-summary-clear-local-variables)
23f87bed
MB
6735 (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6736 (gnus-summary-clear-local-variables))
6737 (gnus-kill-buffer gnus-summary-buffer))
eec82323
LMI
6738 (unless gnus-single-article-buffer
6739 (setq gnus-article-current nil))
6740 (when gnus-use-trees
6741 (gnus-tree-close group))
6742 (gnus-async-prefetch-remove-group group)
6743 (when (get-buffer gnus-article-buffer)
6744 (bury-buffer gnus-article-buffer))
6745 ;; Return to the group buffer.
6746 (gnus-configure-windows 'group 'force)
6747 ;; Clear the current group name.
6748 (setq gnus-newsgroup-name nil)
23f87bed
MB
6749 (unless (gnus-ephemeral-group-p group)
6750 (gnus-group-update-group group))
eec82323
LMI
6751 (when (equal (gnus-group-group-name) group)
6752 (gnus-group-next-unread-group 1))
6753 (when quit-config
23f87bed 6754 (gnus-handle-ephemeral-exit quit-config)))))
eec82323
LMI
6755
6756(defun gnus-handle-ephemeral-exit (quit-config)
6748645f
LMI
6757 "Handle movement when leaving an ephemeral group.
6758The state which existed when entering the ephemeral is reset."
eec82323
LMI
6759 (if (not (buffer-name (car quit-config)))
6760 (gnus-configure-windows 'group 'force)
6761 (set-buffer (car quit-config))
6762 (cond ((eq major-mode 'gnus-summary-mode)
23f87bed
MB
6763 (gnus-set-global-variables))
6764 ((eq major-mode 'gnus-article-mode)
6765 (save-excursion
6766 ;; The `gnus-summary-buffer' variable may point
6767 ;; to the old summary buffer when using a single
6768 ;; article buffer.
6769 (unless (gnus-buffer-live-p gnus-summary-buffer)
6770 (set-buffer gnus-group-buffer))
6771 (set-buffer gnus-summary-buffer)
6772 (gnus-set-global-variables))))
eec82323 6773 (if (or (eq (cdr quit-config) 'article)
23f87bed
MB
6774 (eq (cdr quit-config) 'pick))
6775 (progn
6776 ;; The current article may be from the ephemeral group
6777 ;; thus it is best that we reload this article
6778 ;;
6779 ;; If we're exiting from a large digest, this can be
6780 ;; extremely slow. So, it's better not to reload it. -- jh.
6781 ;;(gnus-summary-show-article)
6782 (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6783 (gnus-configure-windows 'pick 'force)
6784 (gnus-configure-windows (cdr quit-config) 'force)))
eec82323
LMI
6785 (gnus-configure-windows (cdr quit-config) 'force))
6786 (when (eq major-mode 'gnus-summary-mode)
6787 (gnus-summary-next-subject 1 nil t)
6788 (gnus-summary-recenter)
6789 (gnus-summary-position-point))))
6790
6791;;; Dead summaries.
6792
6793(defvar gnus-dead-summary-mode-map nil)
6794
6795(unless gnus-dead-summary-mode-map
6796 (setq gnus-dead-summary-mode-map (make-keymap))
6797 (suppress-keymap gnus-dead-summary-mode-map)
6798 (substitute-key-definition
6799 'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
23f87bed
MB
6800 (dolist (key '("\C-d" "\r" "\177" [delete]))
6801 (define-key gnus-dead-summary-mode-map
6802 key 'gnus-summary-wake-up-the-dead))
6803 (dolist (key '("q" "Q"))
6804 (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
eec82323
LMI
6805
6806(defvar gnus-dead-summary-mode nil
6807 "Minor mode for Gnus summary buffers.")
6808
6809(defun gnus-dead-summary-mode (&optional arg)
6810 "Minor mode for Gnus summary buffers."
6811 (interactive "P")
6812 (when (eq major-mode 'gnus-summary-mode)
6813 (make-local-variable 'gnus-dead-summary-mode)
6814 (setq gnus-dead-summary-mode
6815 (if (null arg) (not gnus-dead-summary-mode)
6816 (> (prefix-numeric-value arg) 0)))
6817 (when gnus-dead-summary-mode
a8151ef7
LMI
6818 (gnus-add-minor-mode
6819 'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
eec82323
LMI
6820
6821(defun gnus-deaden-summary ()
6822 "Make the current summary buffer into a dead summary buffer."
6823 ;; Kill any previous dead summary buffer.
6824 (when (and gnus-dead-summary
6825 (buffer-name gnus-dead-summary))
6826 (save-excursion
6827 (set-buffer gnus-dead-summary)
6828 (when gnus-dead-summary-mode
6829 (kill-buffer (current-buffer)))))
6830 ;; Make this the current dead summary.
6831 (setq gnus-dead-summary (current-buffer))
6832 (gnus-dead-summary-mode 1)
6833 (let ((name (buffer-name)))
6834 (when (string-match "Summary" name)
6835 (rename-buffer
6836 (concat (substring name 0 (match-beginning 0)) "Dead "
6837 (substring name (match-beginning 0)))
16409b0b
GM
6838 t)
6839 (bury-buffer))))
eec82323
LMI
6840
6841(defun gnus-kill-or-deaden-summary (buffer)
6842 "Kill or deaden the summary BUFFER."
6748645f
LMI
6843 (save-excursion
6844 (when (and (buffer-name buffer)
6845 (not gnus-single-article-buffer))
6846 (save-excursion
6847 (set-buffer buffer)
6848 (gnus-kill-buffer gnus-article-buffer)
6849 (gnus-kill-buffer gnus-original-article-buffer)))
23f87bed
MB
6850 (cond
6851 ;; Kill the buffer.
6852 (gnus-kill-summary-on-exit
6853 (when (and gnus-use-trees
6854 (gnus-buffer-exists-p buffer))
6855 (save-excursion
6856 (set-buffer buffer)
6857 (gnus-tree-close gnus-newsgroup-name)))
6858 (gnus-kill-buffer buffer))
6859 ;; Deaden the buffer.
6860 ((gnus-buffer-exists-p buffer)
6861 (save-excursion
6862 (set-buffer buffer)
6863 (gnus-deaden-summary))))))
eec82323
LMI
6864
6865(defun gnus-summary-wake-up-the-dead (&rest args)
6866 "Wake up the dead summary buffer."
6867 (interactive)
6868 (gnus-dead-summary-mode -1)
6869 (let ((name (buffer-name)))
6870 (when (string-match "Dead " name)
6871 (rename-buffer
6872 (concat (substring name 0 (match-beginning 0))
6873 (substring name (match-end 0)))
6874 t)))
6875 (gnus-message 3 "This dead summary is now alive again"))
6876
6877;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6878(defun gnus-summary-fetch-faq (&optional faq-dir)
6879 "Fetch the FAQ for the current group.
6880If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6881in."
6882 (interactive
6883 (list
6884 (when current-prefix-arg
6885 (completing-read
8f688cb0 6886 "FAQ dir: " (and (listp gnus-group-faq-directory)
a8151ef7
LMI
6887 (mapcar (lambda (file) (list file))
6888 gnus-group-faq-directory))))))
eec82323
LMI
6889 (let (gnus-faq-buffer)
6890 (when (setq gnus-faq-buffer
6891 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6892 (gnus-configure-windows 'summary-faq))))
6893
6894;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6895(defun gnus-summary-describe-group (&optional force)
6896 "Describe the current newsgroup."
6897 (interactive "P")
6898 (gnus-group-describe-group force gnus-newsgroup-name))
6899
6900(defun gnus-summary-describe-briefly ()
6901 "Describe summary mode commands briefly."
6902 (interactive)
16409b0b 6903 (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
6904
6905;; Walking around group mode buffer from summary mode.
6906
6907(defun gnus-summary-next-group (&optional no-article target-group backward)
6908 "Exit current newsgroup and then select next unread newsgroup.
6909If prefix argument NO-ARTICLE is non-nil, no article is selected
23f87bed 6910initially. If TARGET-GROUP, go to this group. If BACKWARD, go to
eec82323
LMI
6911previous group instead."
6912 (interactive "P")
eec82323
LMI
6913 ;; Stop pre-fetching.
6914 (gnus-async-halt-prefetch)
6915 (let ((current-group gnus-newsgroup-name)
6916 (current-buffer (current-buffer))
6917 entered)
6918 ;; First we semi-exit this group to update Xrefs and all variables.
6919 ;; We can't do a real exit, because the window conf must remain
6920 ;; the same in case the user is prompted for info, and we don't
6921 ;; want the window conf to change before that...
6922 (gnus-summary-exit t)
6923 (while (not entered)
6924 ;; Then we find what group we are supposed to enter.
6925 (set-buffer gnus-group-buffer)
6926 (gnus-group-jump-to-group current-group)
6927 (setq target-group
6928 (or target-group
6929 (if (eq gnus-keep-same-level 'best)
6930 (gnus-summary-best-group gnus-newsgroup-name)
6931 (gnus-summary-search-group backward gnus-keep-same-level))))
6932 (if (not target-group)
6933 ;; There are no further groups, so we return to the group
6934 ;; buffer.
6935 (progn
6936 (gnus-message 5 "Returning to the group buffer")
6937 (setq entered t)
6938 (when (gnus-buffer-live-p current-buffer)
6939 (set-buffer current-buffer)
6940 (gnus-summary-exit))
6748645f 6941 (gnus-run-hooks 'gnus-group-no-more-groups-hook))
eec82323
LMI
6942 ;; We try to enter the target group.
6943 (gnus-group-jump-to-group target-group)
6944 (let ((unreads (gnus-group-group-unread)))
6945 (if (and (or (eq t unreads)
6946 (and unreads (not (zerop unreads))))
23f87bed
MB
6947 (gnus-summary-read-group
6948 target-group nil no-article
6949 (and (buffer-name current-buffer) current-buffer)
6950 nil backward))
eec82323
LMI
6951 (setq entered t)
6952 (setq current-group target-group
6953 target-group nil)))))))
6954
6955(defun gnus-summary-prev-group (&optional no-article)
6956 "Exit current newsgroup and then select previous unread newsgroup.
6957If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6958 (interactive "P")
6959 (gnus-summary-next-group no-article nil t))
6960
6961;; Walking around summary lines.
6962
23f87bed
MB
6963(defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6964 "Go to the first subject satisfying any non-nil constraint.
6965If UNREAD is non-nil, the article should be unread.
6966If UNDOWNLOADED is non-nil, the article should be undownloaded.
6967If UNSEEN is non-nil, the article should be unseen.
6968Returns the article selected or nil if there are no matching articles."
eec82323 6969 (interactive "P")
23f87bed
MB
6970 (cond
6971 ;; Empty summary.
6972 ((null gnus-newsgroup-data)
6973 (gnus-message 3 "No articles in the group")
6974 nil)
6975 ;; Pick the first article.
6976 ((not (or unread undownloaded unseen))
6977 (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6978 (gnus-data-number (car gnus-newsgroup-data)))
6979 ;; Find the first unread article.
6980 (t
6981 (let ((data gnus-newsgroup-data))
6982 (while (and data
6983 (let ((num (gnus-data-number (car data))))
6984 (or (memq num gnus-newsgroup-unfetched)
6985 (not (or (and unread
6986 (memq num gnus-newsgroup-unreads))
6987 (and undownloaded
6988 (memq num gnus-newsgroup-undownloaded))
6989 (and unseen
6990 (memq num gnus-newsgroup-unseen)))))))
6991 (setq data (cdr data)))
6992 (prog1
6993 (if data
6994 (progn
6995 (goto-char (gnus-data-pos (car data)))
6996 (gnus-data-number (car data)))
6997 (gnus-message 3 "No more%s articles"
6998 (let* ((r (when unread " unread"))
6999 (d (when undownloaded " undownloaded"))
7000 (s (when unseen " unseen"))
7001 (l (delq nil (list r d s))))
7002 (cond ((= 3 (length l))
7003 (concat r "," d ", or" s))
7004 ((= 2 (length l))
7005 (concat (car l) ", or" (cadr l)))
7006 ((= 1 (length l))
7007 (car l))
7008 (t
7009 ""))))
7010 nil
7011 )
7012 (gnus-summary-position-point))))))
eec82323
LMI
7013
7014(defun gnus-summary-next-subject (n &optional unread dont-display)
7015 "Go to next N'th summary line.
7016If N is negative, go to the previous N'th subject line.
7017If UNREAD is non-nil, only unread articles are selected.
7018The difference between N and the actual number of steps taken is
7019returned."
7020 (interactive "p")
7021 (let ((backward (< n 0))
7022 (n (abs n)))
7023 (while (and (> n 0)
7024 (if backward
7025 (gnus-summary-find-prev unread)
7026 (gnus-summary-find-next unread)))
16409b0b
GM
7027 (unless (zerop (setq n (1- n)))
7028 (gnus-summary-show-thread)))
eec82323
LMI
7029 (when (/= 0 n)
7030 (gnus-message 7 "No more%s articles"
7031 (if unread " unread" "")))
7032 (unless dont-display
7033 (gnus-summary-recenter)
7034 (gnus-summary-position-point))
7035 n))
7036
7037(defun gnus-summary-next-unread-subject (n)
7038 "Go to next N'th unread summary line."
7039 (interactive "p")
7040 (gnus-summary-next-subject n t))
7041
7042(defun gnus-summary-prev-subject (n &optional unread)
7043 "Go to previous N'th summary line.
7044If optional argument UNREAD is non-nil, only unread article is selected."
7045 (interactive "p")
7046 (gnus-summary-next-subject (- n) unread))
7047
7048(defun gnus-summary-prev-unread-subject (n)
7049 "Go to previous N'th unread summary line."
7050 (interactive "p")
7051 (gnus-summary-next-subject (- n) t))
7052
23f87bed
MB
7053(defun gnus-summary-goto-subjects (articles)
7054 "Insert the subject header for ARTICLES in the current buffer."
7055 (save-excursion
7056 (dolist (article articles)
7057 (gnus-summary-goto-subject article t)))
7058 (gnus-summary-limit (append articles gnus-newsgroup-limit))
7059 (gnus-summary-position-point))
132cf96d 7060
eec82323
LMI
7061(defun gnus-summary-goto-subject (article &optional force silent)
7062 "Go the subject line of ARTICLE.
7063If FORCE, also allow jumping to articles not currently shown."
7064 (interactive "nArticle number: ")
23f87bed
MB
7065 (unless (numberp article)
7066 (error "Article %s is not a number" article))
eec82323
LMI
7067 (let ((b (point))
7068 (data (gnus-data-find article)))
7069 ;; We read in the article if we have to.
7070 (and (not data)
7071 force
6748645f
LMI
7072 (gnus-summary-insert-subject
7073 article
7074 (if (or (numberp force) (vectorp force)) force)
7075 t)
eec82323
LMI
7076 (setq data (gnus-data-find article)))
7077 (goto-char b)
7078 (if (not data)
7079 (progn
7080 (unless silent
7081 (gnus-message 3 "Can't find article %d" article))
7082 nil)
23f87bed
MB
7083 (let ((pt (gnus-data-pos data)))
7084 (goto-char pt)
7085 (gnus-summary-set-article-display-arrow pt))
6748645f 7086 (gnus-summary-position-point)
eec82323
LMI
7087 article)))
7088
7089;; Walking around summary lines with displaying articles.
7090
7091(defun gnus-summary-expand-window (&optional arg)
7092 "Make the summary buffer take up the entire Emacs frame.
7093Given a prefix, will force an `article' buffer configuration."
7094 (interactive "P")
eec82323
LMI
7095 (if arg
7096 (gnus-configure-windows 'article 'force)
7097 (gnus-configure-windows 'summary 'force)))
7098
7099(defun gnus-summary-display-article (article &optional all-header)
7100 "Display ARTICLE in article buffer."
d4dfaa19
DL
7101 (when (gnus-buffer-live-p gnus-article-buffer)
7102 (with-current-buffer gnus-article-buffer
87545352 7103 (mm-enable-multibyte)))
eec82323 7104 (gnus-set-global-variables)
23f87bed
MB
7105 (when (gnus-buffer-live-p gnus-article-buffer)
7106 (with-current-buffer gnus-article-buffer
7107 (setq gnus-article-charset gnus-newsgroup-charset)
7108 (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7109 (mm-enable-multibyte)))
eec82323
LMI
7110 (if (null article)
7111 nil
7112 (prog1
7113 (if gnus-summary-display-article-function
7114 (funcall gnus-summary-display-article-function article all-header)
7115 (gnus-article-prepare article all-header))
6748645f 7116 (gnus-run-hooks 'gnus-select-article-hook)
eec82323
LMI
7117 (when (and gnus-current-article
7118 (not (zerop gnus-current-article)))
7119 (gnus-summary-goto-subject gnus-current-article))
7120 (gnus-summary-recenter)
7121 (when (and gnus-use-trees gnus-show-threads)
7122 (gnus-possibly-generate-tree article)
7123 (gnus-highlight-selected-tree article))
7124 ;; Successfully display article.
7125 (gnus-article-set-window-start
7126 (cdr (assq article gnus-newsgroup-bookmarks))))))
7127
7128(defun gnus-summary-select-article (&optional all-headers force pseudo article)
7129 "Select the current article.
7130If ALL-HEADERS is non-nil, show all header fields. If FORCE is
7131non-nil, the article will be re-fetched even if it already present in
7132the article buffer. If PSEUDO is non-nil, pseudo-articles will also
7133be displayed."
7134 ;; Make sure we are in the summary buffer to work around bbdb bug.
7135 (unless (eq major-mode 'gnus-summary-mode)
7136 (set-buffer gnus-summary-buffer))
7137 (let ((article (or article (gnus-summary-article-number)))
f0529b5b 7138 (all-headers (not (not all-headers))) ;Must be t or nil.
16409b0b 7139 gnus-summary-display-article-function)
eec82323
LMI
7140 (and (not pseudo)
7141 (gnus-summary-article-pseudo-p article)
a8151ef7 7142 (error "This is a pseudo-article"))
16409b0b
GM
7143 (save-excursion
7144 (set-buffer gnus-summary-buffer)
7145 (if (or (and gnus-single-article-buffer
7146 (or (null gnus-current-article)
7147 (null gnus-article-current)
7148 (null (get-buffer gnus-article-buffer))
7149 (not (eq article (cdr gnus-article-current)))
7150 (not (equal (car gnus-article-current)
7151 gnus-newsgroup-name))))
7152 (and (not gnus-single-article-buffer)
7153 (or (null gnus-current-article)
7154 (not (eq gnus-current-article article))))
7155 force)
7156 ;; The requested article is different from the current article.
7157 (progn
16409b0b
GM
7158 (gnus-summary-display-article article all-headers)
7159 (when (gnus-buffer-live-p gnus-article-buffer)
23f87bed 7160 (with-current-buffer gnus-article-buffer
16409b0b 7161 (if (not gnus-article-decoded-p) ;; a local variable
87545352 7162 (mm-disable-multibyte))))
16409b0b
GM
7163 (gnus-article-set-window-start
7164 (cdr (assq article gnus-newsgroup-bookmarks)))
7165 article)
16409b0b 7166 'old))))
eec82323 7167
23f87bed
MB
7168(defun gnus-summary-force-verify-and-decrypt ()
7169 "Display buttons for signed/encrypted parts and verify/decrypt them."
7170 (interactive)
7171 (let ((mm-verify-option 'known)
7172 (mm-decrypt-option 'known)
7173 (gnus-article-emulate-mime t)
7174 (gnus-buttonized-mime-types (append (list "multipart/signed"
7175 "multipart/encrypted")
7176 gnus-buttonized-mime-types)))
7177 (gnus-summary-select-article nil 'force)))
7178
eec82323
LMI
7179(defun gnus-summary-set-current-mark (&optional current-mark)
7180 "Obsolete function."
7181 nil)
7182
7183(defun gnus-summary-next-article (&optional unread subject backward push)
7184 "Select the next article.
7185If UNREAD, only unread articles are selected.
7186If SUBJECT, only articles with SUBJECT are selected.
7187If BACKWARD, the previous article is selected instead of the next."
7188 (interactive "P")
eec82323
LMI
7189 (cond
7190 ;; Is there such an article?
7191 ((and (gnus-summary-search-forward unread subject backward)
7192 (or (gnus-summary-display-article (gnus-summary-article-number))
7193 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7194 (gnus-summary-position-point))
7195 ;; If not, we try the first unread, if that is wanted.
7196 ((and subject
7197 gnus-auto-select-same
7198 (gnus-summary-first-unread-article))
7199 (gnus-summary-position-point)
7200 (gnus-message 6 "Wrapped"))
7201 ;; Try to get next/previous article not displayed in this group.
7202 ((and gnus-auto-extend-newsgroup
7203 (not unread) (not subject))
7204 (gnus-summary-goto-article
7205 (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6748645f 7206 nil (count-lines (point-min) (point))))
eec82323
LMI
7207 ;; Go to next/previous group.
7208 (t
7209 (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7210 (gnus-summary-jump-to-group gnus-newsgroup-name))
7211 (let ((cmd last-command-char)
7212 (point
7213 (save-excursion
7214 (set-buffer gnus-group-buffer)
7215 (point)))
7216 (group
7217 (if (eq gnus-keep-same-level 'best)
7218 (gnus-summary-best-group gnus-newsgroup-name)
7219 (gnus-summary-search-group backward gnus-keep-same-level))))
7220 ;; For some reason, the group window gets selected. We change
7221 ;; it back.
7222 (select-window (get-buffer-window (current-buffer)))
7223 ;; Select next unread newsgroup automagically.
7224 (cond
7225 ((or (not gnus-auto-select-next)
7226 (not cmd))
7227 (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7228 ((or (eq gnus-auto-select-next 'quietly)
7229 (and (eq gnus-auto-select-next 'slightly-quietly)
7230 push)
7231 (and (eq gnus-auto-select-next 'almost-quietly)
7232 (gnus-summary-last-article-p)))
7233 ;; Select quietly.
7234 (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7235 (gnus-summary-exit)
7236 (gnus-message 7 "No more%s articles (%s)..."
7237 (if unread " unread" "")
7238 (if group (concat "selecting " group)
7239 "exiting"))
7240 (gnus-summary-next-group nil group backward)))
7241 (t
7242 (when (gnus-key-press-event-p last-input-event)
7243 (gnus-summary-walk-group-buffer
7244 gnus-newsgroup-name cmd unread backward point))))))))
7245
7246(defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7247 (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7248 (?\C-p (gnus-group-prev-unread-group 1))))
7249 (cursor-in-echo-area t)
23f87bed 7250 keve key group ended prompt)
eec82323
LMI
7251 (save-excursion
7252 (set-buffer gnus-group-buffer)
7253 (goto-char start)
7254 (setq group
7255 (if (eq gnus-keep-same-level 'best)
7256 (gnus-summary-best-group gnus-newsgroup-name)
7257 (gnus-summary-search-group backward gnus-keep-same-level))))
7258 (while (not ended)
23f87bed
MB
7259 (setq prompt
7260 (format
7261 "No more%s articles%s " (if unread " unread" "")
7262 (if (and group
7263 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7264 (format " (Type %s for %s [%s])"
91472578
MB
7265 (single-key-description cmd)
7266 (gnus-group-decoded-name group)
23f87bed
MB
7267 (car (gnus-gethash group gnus-newsrc-hashtb)))
7268 (format " (Type %s to exit %s)"
7269 (single-key-description cmd)
91472578 7270 (gnus-group-decoded-name gnus-newsgroup-name)))))
eec82323 7271 ;; Confirm auto selection.
23f87bed
MB
7272 (setq key (car (setq keve (gnus-read-event-char prompt)))
7273 ended t)
eec82323
LMI
7274 (cond
7275 ((assq key keystrokes)
7276 (let ((obuf (current-buffer)))
7277 (switch-to-buffer gnus-group-buffer)
7278 (when group
7279 (gnus-group-jump-to-group group))
7280 (eval (cadr (assq key keystrokes)))
7281 (setq group (gnus-group-group-name))
7282 (switch-to-buffer obuf))
7283 (setq ended nil))
7284 ((equal key cmd)
7285 (if (or (not group)
7286 (gnus-ephemeral-group-p gnus-newsgroup-name))
7287 (gnus-summary-exit)
7288 (gnus-summary-next-group nil group backward)))
7289 (t
7290 (push (cdr keve) unread-command-events))))))
7291
7292(defun gnus-summary-next-unread-article ()
7293 "Select unread article after current one."
7294 (interactive)
7295 (gnus-summary-next-article
7296 (or (not (eq gnus-summary-goto-unread 'never))
7297 (gnus-summary-last-article-p (gnus-summary-article-number)))
7298 (and gnus-auto-select-same
7299 (gnus-summary-article-subject))))
7300
7301(defun gnus-summary-prev-article (&optional unread subject)
7302 "Select the article after the current one.
7303If UNREAD is non-nil, only unread articles are selected."
7304 (interactive "P")
7305 (gnus-summary-next-article unread subject t))
7306
7307(defun gnus-summary-prev-unread-article ()
7308 "Select unread article before current one."
7309 (interactive)
7310 (gnus-summary-prev-article
7311 (or (not (eq gnus-summary-goto-unread 'never))
7312 (gnus-summary-first-article-p (gnus-summary-article-number)))
7313 (and gnus-auto-select-same
7314 (gnus-summary-article-subject))))
7315
23f87bed 7316(defun gnus-summary-next-page (&optional lines circular stop)
eec82323
LMI
7317 "Show next page of the selected article.
7318If at the end of the current article, select the next article.
7319LINES says how many lines should be scrolled up.
7320
7321If CIRCULAR is non-nil, go to the start of the article instead of
7322selecting the next article when reaching the end of the current
23f87bed
MB
7323article.
7324
7325If STOP is non-nil, just stop when reaching the end of the message.
7326
7327Also see the variable `gnus-article-skip-boring'."
eec82323
LMI
7328 (interactive "P")
7329 (setq gnus-summary-buffer (current-buffer))
7330 (gnus-set-global-variables)
7331 (let ((article (gnus-summary-article-number))
7332 (article-window (get-buffer-window gnus-article-buffer t))
7333 endp)
6748645f
LMI
7334 ;; If the buffer is empty, we have no article.
7335 (unless article
7336 (error "No article to select"))
eec82323
LMI
7337 (gnus-configure-windows 'article)
7338 (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7339 (if (and (eq gnus-summary-goto-unread 'never)
7340 (not (gnus-summary-last-article-p article)))
7341 (gnus-summary-next-article)
7342 (gnus-summary-next-unread-article))
7343 (if (or (null gnus-current-article)
7344 (null gnus-article-current)
7345 (/= article (cdr gnus-article-current))
7346 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7347 ;; Selected subject is different from current article's.
7348 (gnus-summary-display-article article)
7349 (when article-window
7350 (gnus-eval-in-buffer-window gnus-article-buffer
23f87bed
MB
7351 (setq endp (or (gnus-article-next-page lines)
7352 (gnus-article-only-boring-p))))
eec82323 7353 (when endp
23f87bed
MB
7354 (cond (stop
7355 (gnus-message 3 "End of message"))
7356 (circular
eec82323
LMI
7357 (gnus-summary-beginning-of-article))
7358 (lines
7359 (gnus-message 3 "End of message"))
7360 ((null lines)
7361 (if (and (eq gnus-summary-goto-unread 'never)
7362 (not (gnus-summary-last-article-p article)))
7363 (gnus-summary-next-article)
7364 (gnus-summary-next-unread-article))))))))
7365 (gnus-summary-recenter)
7366 (gnus-summary-position-point)))
7367
7368(defun gnus-summary-prev-page (&optional lines move)
7369 "Show previous page of selected article.
7370Argument LINES specifies lines to be scrolled down.
7371If MOVE, move to the previous unread article if point is at
7372the beginning of the buffer."
7373 (interactive "P")
eec82323
LMI
7374 (let ((article (gnus-summary-article-number))
7375 (article-window (get-buffer-window gnus-article-buffer t))
7376 endp)
7377 (gnus-configure-windows 'article)
7378 (if (or (null gnus-current-article)
7379 (null gnus-article-current)
7380 (/= article (cdr gnus-article-current))
7381 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7382 ;; Selected subject is different from current article's.
7383 (gnus-summary-display-article article)
7384 (gnus-summary-recenter)
7385 (when article-window
7386 (gnus-eval-in-buffer-window gnus-article-buffer
7387 (setq endp (gnus-article-prev-page lines)))
7388 (when (and move endp)
7389 (cond (lines
7390 (gnus-message 3 "Beginning of message"))
7391 ((null lines)
7392 (if (and (eq gnus-summary-goto-unread 'never)
7393 (not (gnus-summary-first-article-p article)))
7394 (gnus-summary-prev-article)
7395 (gnus-summary-prev-unread-article))))))))
7396 (gnus-summary-position-point))
7397
7398(defun gnus-summary-prev-page-or-article (&optional lines)
7399 "Show previous page of selected article.
7400Argument LINES specifies lines to be scrolled down.
7401If at the beginning of the article, go to the next article."
7402 (interactive "P")
7403 (gnus-summary-prev-page lines t))
7404
7405(defun gnus-summary-scroll-up (lines)
7406 "Scroll up (or down) one line current article.
7407Argument LINES specifies lines to be scrolled up (or down if negative)."
7408 (interactive "p")
eec82323
LMI
7409 (gnus-configure-windows 'article)
7410 (gnus-summary-show-thread)
7411 (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7412 (gnus-eval-in-buffer-window gnus-article-buffer
7413 (cond ((> lines 0)
7414 (when (gnus-article-next-page lines)
7415 (gnus-message 3 "End of message")))
7416 ((< lines 0)
7417 (gnus-article-prev-page (- lines))))))
7418 (gnus-summary-recenter)
7419 (gnus-summary-position-point))
7420
6748645f
LMI
7421(defun gnus-summary-scroll-down (lines)
7422 "Scroll down (or up) one line current article.
7423Argument LINES specifies lines to be scrolled down (or up if negative)."
7424 (interactive "p")
7425 (gnus-summary-scroll-up (- lines)))
7426
eec82323
LMI
7427(defun gnus-summary-next-same-subject ()
7428 "Select next article which has the same subject as current one."
7429 (interactive)
eec82323
LMI
7430 (gnus-summary-next-article nil (gnus-summary-article-subject)))
7431
7432(defun gnus-summary-prev-same-subject ()
7433 "Select previous article which has the same subject as current one."
7434 (interactive)
eec82323
LMI
7435 (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7436
7437(defun gnus-summary-next-unread-same-subject ()
7438 "Select next unread article which has the same subject as current one."
7439 (interactive)
eec82323
LMI
7440 (gnus-summary-next-article t (gnus-summary-article-subject)))
7441
7442(defun gnus-summary-prev-unread-same-subject ()
7443 "Select previous unread article which has the same subject as current one."
7444 (interactive)
eec82323
LMI
7445 (gnus-summary-prev-article t (gnus-summary-article-subject)))
7446
7447(defun gnus-summary-first-unread-article ()
7448 "Select the first unread article.
7449Return nil if there are no unread articles."
7450 (interactive)
eec82323
LMI
7451 (prog1
7452 (when (gnus-summary-first-subject t)
7453 (gnus-summary-show-thread)
7454 (gnus-summary-first-subject t)
7455 (gnus-summary-display-article (gnus-summary-article-number)))
7456 (gnus-summary-position-point)))
7457
16409b0b
GM
7458(defun gnus-summary-first-unread-subject ()
7459 "Place the point on the subject line of the first unread article.
7460Return nil if there are no unread articles."
7461 (interactive)
7462 (prog1
7463 (when (gnus-summary-first-subject t)
7464 (gnus-summary-show-thread)
7465 (gnus-summary-first-subject t))
7466 (gnus-summary-position-point)))
7467
23f87bed
MB
7468(defun gnus-summary-first-unseen-subject ()
7469 "Place the point on the subject line of the first unseen article.
7470Return nil if there are no unseen articles."
7471 (interactive)
7472 (prog1
7473 (when (gnus-summary-first-subject nil nil t)
7474 (gnus-summary-show-thread)
7475 (gnus-summary-first-subject nil nil t))
7476 (gnus-summary-position-point)))
7477
7478(defun gnus-summary-first-unseen-or-unread-subject ()
7479 "Place the point on the subject line of the first unseen article or,
7480if all article have been seen, on the subject line of the first unread
7481article."
7482 (interactive)
7483 (prog1
7484 (unless (when (gnus-summary-first-subject nil nil t)
7485 (gnus-summary-show-thread)
7486 (gnus-summary-first-subject nil nil t))
7487 (when (gnus-summary-first-subject t)
7488 (gnus-summary-show-thread)
7489 (gnus-summary-first-subject t)))
7490 (gnus-summary-position-point)))
7491
eec82323
LMI
7492(defun gnus-summary-first-article ()
7493 "Select the first article.
7494Return nil if there are no articles."
7495 (interactive)
eec82323
LMI
7496 (prog1
7497 (when (gnus-summary-first-subject)
16409b0b
GM
7498 (gnus-summary-show-thread)
7499 (gnus-summary-first-subject)
7500 (gnus-summary-display-article (gnus-summary-article-number)))
eec82323
LMI
7501 (gnus-summary-position-point)))
7502
23f87bed
MB
7503(defun gnus-summary-best-unread-article (&optional arg)
7504 "Select the unread article with the highest score.
7505If given a prefix argument, select the next unread article that has a
7506score higher than the default score."
7507 (interactive "P")
7508 (let ((article (if arg
7509 (gnus-summary-better-unread-subject)
7510 (gnus-summary-best-unread-subject))))
7511 (if article
7512 (gnus-summary-goto-article article)
7513 (error "No unread articles"))))
7514
7515(defun gnus-summary-best-unread-subject ()
7516 "Select the unread subject with the highest score."
eec82323 7517 (interactive)
eec82323
LMI
7518 (let ((best -1000000)
7519 (data gnus-newsgroup-data)
7520 article score)
7521 (while data
7522 (and (gnus-data-unread-p (car data))
7523 (> (setq score
7524 (gnus-summary-article-score (gnus-data-number (car data))))
7525 best)
7526 (setq best score
7527 article (gnus-data-number (car data))))
7528 (setq data (cdr data)))
23f87bed
MB
7529 (when article
7530 (gnus-summary-goto-subject article))
7531 (gnus-summary-position-point)
7532 article))
7533
7534(defun gnus-summary-better-unread-subject ()
7535 "Select the first unread subject that has a score over the default score."
7536 (interactive)
7537 (let ((data gnus-newsgroup-data)
7538 article score)
7539 (while (and (setq article (gnus-data-number (car data)))
7540 (or (gnus-data-read-p (car data))
7541 (not (> (gnus-summary-article-score article)
7542 gnus-summary-default-score))))
7543 (setq data (cdr data)))
7544 (when article
7545 (gnus-summary-goto-subject article))
7546 (gnus-summary-position-point)
7547 article))
eec82323
LMI
7548
7549(defun gnus-summary-last-subject ()
7550 "Go to the last displayed subject line in the group."
7551 (let ((article (gnus-data-number (car (gnus-data-list t)))))
7552 (when article
7553 (gnus-summary-goto-subject article))))
7554
7555(defun gnus-summary-goto-article (article &optional all-headers force)
6748645f
LMI
7556 "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7557If ALL-HEADERS is non-nil, no header lines are hidden.
7558If FORCE, go to the article even if it isn't displayed. If FORCE
7559is a number, it is the line the article is to be displayed on."
eec82323
LMI
7560 (interactive
7561 (list
6748645f
LMI
7562 (completing-read
7563 "Article number or Message-ID: "
7564 (mapcar (lambda (number) (list (int-to-string number)))
7565 gnus-newsgroup-limit))
eec82323
LMI
7566 current-prefix-arg
7567 t))
7568 (prog1
6748645f 7569 (if (and (stringp article)
23f87bed 7570 (string-match "@\\|%40" article))
6748645f
LMI
7571 (gnus-summary-refer-article article)
7572 (when (stringp article)
7573 (setq article (string-to-number article)))
7574 (if (gnus-summary-goto-subject article force)
7575 (gnus-summary-display-article article all-headers)
7576 (gnus-message 4 "Couldn't go to article %s" article) nil))
eec82323
LMI
7577 (gnus-summary-position-point)))
7578
7579(defun gnus-summary-goto-last-article ()
7580 "Go to the previously read article."
7581 (interactive)
7582 (prog1
7583 (when gnus-last-article
6748645f 7584 (gnus-summary-goto-article gnus-last-article nil t))
eec82323
LMI
7585 (gnus-summary-position-point)))
7586
7587(defun gnus-summary-pop-article (number)
7588 "Pop one article off the history and go to the previous.
7589NUMBER articles will be popped off."
7590 (interactive "p")
7591 (let (to)
7592 (setq gnus-newsgroup-history
7593 (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7594 (if to
6748645f 7595 (gnus-summary-goto-article (car to) nil t)
eec82323
LMI
7596 (error "Article history empty")))
7597 (gnus-summary-position-point))
7598
7599;; Summary commands and functions for limiting the summary buffer.
7600
7601(defun gnus-summary-limit-to-articles (n)
7602 "Limit the summary buffer to the next N articles.
7603If not given a prefix, use the process marked articles instead."
7604 (interactive "P")
eec82323
LMI
7605 (prog1
7606 (let ((articles (gnus-summary-work-articles n)))
7607 (setq gnus-newsgroup-processable nil)
7608 (gnus-summary-limit articles))
7609 (gnus-summary-position-point)))
7610
7611(defun gnus-summary-pop-limit (&optional total)
7612 "Restore the previous limit.
7613If given a prefix, remove all limits."
7614 (interactive "P")
eec82323
LMI
7615 (when total
7616 (setq gnus-newsgroup-limits
7617 (list (mapcar (lambda (h) (mail-header-number h))
7618 gnus-newsgroup-headers))))
7619 (unless gnus-newsgroup-limits
7620 (error "No limit to pop"))
7621 (prog1
7622 (gnus-summary-limit nil 'pop)
7623 (gnus-summary-position-point)))
7624
47b63dfa
SZ
7625(defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7626 "Limit the summary buffer to articles that have subjects that match a regexp.
7627If NOT-MATCHING, excluding articles that have subjects that match a regexp."
a1506d29 7628 (interactive
47b63dfa
SZ
7629 (list (read-string (if current-prefix-arg
7630 "Exclude subject (regexp): "
a1506d29 7631 "Limit to subject (regexp): "))
47b63dfa 7632 nil current-prefix-arg))
eec82323
LMI
7633 (unless header
7634 (setq header "subject"))
7635 (when (not (equal "" subject))
7636 (prog1
7637 (let ((articles (gnus-summary-find-matching
a1506d29 7638 (or header "subject") subject 'all nil nil
47b63dfa 7639 not-matching)))
eec82323
LMI
7640 (unless articles
7641 (error "Found no matches for \"%s\"" subject))
7642 (gnus-summary-limit articles))
7643 (gnus-summary-position-point))))
7644
ef6e0ec7 7645(defun gnus-summary-limit-to-author (from &optional not-matching)
47b63dfa
SZ
7646 "Limit the summary buffer to articles that have authors that match a regexp.
7647If NOT-MATCHING, excluding articles that have authors that match a regexp."
a1506d29 7648 (interactive
47b63dfa
SZ
7649 (list (read-string (if current-prefix-arg
7650 "Exclude author (regexp): "
a1506d29 7651 "Limit to author (regexp): "))
ef6e0ec7
SZ
7652 current-prefix-arg))
7653 (gnus-summary-limit-to-subject from "from" not-matching))
eec82323
LMI
7654
7655(defun gnus-summary-limit-to-age (age &optional younger-p)
7656 "Limit the summary buffer to articles that are older than (or equal) AGE days.
7657If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7658articles that are younger than AGE days."
16409b0b
GM
7659 (interactive
7660 (let ((younger current-prefix-arg)
7661 (days-got nil)
7662 days)
7663 (while (not days-got)
7664 (setq days (if younger
23f87bed
MB
7665 (read-string "Limit to articles younger than (in days, older when negative): ")
7666 (read-string
7667 "Limit to articles older than (in days, younger when negative): ")))
16409b0b
GM
7668 (when (> (length days) 0)
7669 (setq days (read days)))
7670 (if (numberp days)
23f87bed
MB
7671 (progn
7672 (setq days-got t)
7673 (if (< days 0)
7674 (progn
7675 (setq younger (not younger))
7676 (setq days (* days -1)))))
16409b0b
GM
7677 (message "Please enter a number.")
7678 (sleep-for 1)))
7679 (list days younger)))
eec82323
LMI
7680 (prog1
7681 (let ((data gnus-newsgroup-data)
16409b0b 7682 (cutoff (days-to-time age))
eec82323
LMI
7683 articles d date is-younger)
7684 (while (setq d (pop data))
7685 (when (and (vectorp (gnus-data-header d))
7686 (setq date (mail-header-date (gnus-data-header d))))
16409b0b
GM
7687 (setq is-younger (time-less-p
7688 (time-since (condition-case ()
7689 (date-to-time date)
7690 (error '(0 0))))
eec82323 7691 cutoff))
6748645f
LMI
7692 (when (if younger-p
7693 is-younger
7694 (not is-younger))
eec82323
LMI
7695 (push (gnus-data-number d) articles))))
7696 (gnus-summary-limit (nreverse articles)))
7697 (gnus-summary-position-point)))
7698
47b63dfa 7699(defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
16409b0b
GM
7700 "Limit the summary buffer to articles that match an 'extra' header."
7701 (interactive
7702 (let ((header
7703 (intern
23f87bed 7704 (gnus-completing-read-with-default
16409b0b 7705 (symbol-name (car gnus-extra-headers))
47b63dfa 7706 (if current-prefix-arg
81df110a
RF
7707 "Exclude extra header"
7708 "Limit extra header")
16409b0b
GM
7709 (mapcar (lambda (x)
7710 (cons (symbol-name x) x))
7711 gnus-extra-headers)
7712 nil
7713 t))))
7714 (list header
a1506d29 7715 (read-string (format "%s header %s (regexp): "
47b63dfa
SZ
7716 (if current-prefix-arg "Exclude" "Limit to")
7717 header))
7718 current-prefix-arg)))
16409b0b
GM
7719 (when (not (equal "" regexp))
7720 (prog1
7721 (let ((articles (gnus-summary-find-matching
a1506d29 7722 (cons 'extra header) regexp 'all nil nil
47b63dfa 7723 not-matching)))
16409b0b
GM
7724 (unless articles
7725 (error "Found no matches for \"%s\"" regexp))
7726 (gnus-summary-limit articles))
7727 (gnus-summary-position-point))))
7728
23f87bed
MB
7729(defun gnus-summary-limit-to-display-predicate ()
7730 "Limit the summary buffer to the predicated in the `display' group parameter."
7731 (interactive)
7732 (unless gnus-newsgroup-display
7733 (error "There is no `display' group parameter"))
7734 (let (articles)
7735 (dolist (number gnus-newsgroup-articles)
7736 (when (funcall gnus-newsgroup-display)
7737 (push number articles)))
7738 (gnus-summary-limit articles))
7739 (gnus-summary-position-point))
7740
eec82323
LMI
7741(defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7742(make-obsolete
7743 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7744
7745(defun gnus-summary-limit-to-unread (&optional all)
7746 "Limit the summary buffer to articles that are not marked as read.
7747If ALL is non-nil, limit strictly to unread articles."
7748 (interactive "P")
7749 (if all
7750 (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7751 (gnus-summary-limit-to-marks
7752 ;; Concat all the marks that say that an article is read and have
7753 ;; those removed.
7754 (list gnus-del-mark gnus-read-mark gnus-ancient-mark
23f87bed 7755 gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
eec82323
LMI
7756 gnus-low-score-mark gnus-expirable-mark
7757 gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7758 gnus-duplicate-mark gnus-souped-mark)
7759 'reverse)))
7760
7761(defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7762(make-obsolete 'gnus-summary-delete-marked-with
81ceefe2 7763 'gnus-summary-limit-exclude-marks)
eec82323
LMI
7764
7765(defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7766 "Exclude articles that are marked with MARKS (e.g. \"DK\").
7767If REVERSE, limit the summary buffer to articles that are marked
7768with MARKS. MARKS can either be a string of marks or a list of marks.
7769Returns how many articles were removed."
7770 (interactive "sMarks: ")
7771 (gnus-summary-limit-to-marks marks t))
7772
7773(defun gnus-summary-limit-to-marks (marks &optional reverse)
7774 "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7775If REVERSE (the prefix), limit the summary buffer to articles that are
7776not marked with MARKS. MARKS can either be a string of marks or a
7777list of marks.
7778Returns how many articles were removed."
6748645f 7779 (interactive "sMarks: \nP")
eec82323
LMI
7780 (prog1
7781 (let ((data gnus-newsgroup-data)
7782 (marks (if (listp marks) marks
7783 (append marks nil))) ; Transform to list.
7784 articles)
7785 (while data
7786 (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7787 (memq (gnus-data-mark (car data)) marks))
7788 (push (gnus-data-number (car data)) articles))
7789 (setq data (cdr data)))
7790 (gnus-summary-limit articles))
7791 (gnus-summary-position-point)))
7792
23f87bed 7793(defun gnus-summary-limit-to-score (score)
eec82323 7794 "Limit to articles with score at or above SCORE."
23f87bed 7795 (interactive "NLimit to articles with score of at least: ")
eec82323
LMI
7796 (let ((data gnus-newsgroup-data)
7797 articles)
7798 (while data
7799 (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7800 score)
7801 (push (gnus-data-number (car data)) articles))
7802 (setq data (cdr data)))
7803 (prog1
7804 (gnus-summary-limit articles)
7805 (gnus-summary-position-point))))
7806
23f87bed
MB
7807(defun gnus-summary-limit-to-unseen ()
7808 "Limit to unseen articles."
7809 (interactive)
7810 (prog1
7811 (gnus-summary-limit gnus-newsgroup-unseen)
7812 (gnus-summary-position-point)))
7813
6748645f 7814(defun gnus-summary-limit-include-thread (id)
23f87bed
MB
7815 "Display all the hidden articles that is in the thread with ID in it.
7816When called interactively, ID is the Message-ID of the current
7817article."
6748645f
LMI
7818 (interactive (list (mail-header-id (gnus-summary-article-header))))
7819 (let ((articles (gnus-articles-in-thread
7820 (gnus-id-to-thread (gnus-root-id id)))))
7821 (prog1
7822 (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
23f87bed
MB
7823 (gnus-summary-limit-include-matching-articles
7824 "subject"
7825 (regexp-quote (gnus-simplify-subject-re
7826 (mail-header-subject (gnus-id-to-header id)))))
6748645f
LMI
7827 (gnus-summary-position-point))))
7828
23f87bed
MB
7829(defun gnus-summary-limit-include-matching-articles (header regexp)
7830 "Display all the hidden articles that have HEADERs that match REGEXP."
7831 (interactive (list (read-string "Match on header: ")
7832 (read-string "Regexp: ")))
7833 (let ((articles (gnus-find-matching-articles header regexp)))
7834 (prog1
7835 (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7836 (gnus-summary-position-point))))
7837
7838(defun gnus-summary-insert-dormant-articles ()
7839 "Insert all the dormant articles for this group into the current buffer."
7840 (interactive)
7841 (let ((gnus-verbose (max 6 gnus-verbose)))
7842 (if (not gnus-newsgroup-dormant)
7843 (gnus-message 3 "No cached articles for this group")
7844 (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7845
eec82323 7846(defun gnus-summary-limit-include-dormant ()
6748645f
LMI
7847 "Display all the hidden articles that are marked as dormant.
7848Note that this command only works on a subset of the articles currently
7849fetched for this group."
eec82323 7850 (interactive)
eec82323
LMI
7851 (unless gnus-newsgroup-dormant
7852 (error "There are no dormant articles in this group"))
7853 (prog1
7854 (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7855 (gnus-summary-position-point)))
7856
7857(defun gnus-summary-limit-exclude-dormant ()
7858 "Hide all dormant articles."
7859 (interactive)
eec82323
LMI
7860 (prog1
7861 (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7862 (gnus-summary-position-point)))
7863
7864(defun gnus-summary-limit-exclude-childless-dormant ()
7865 "Hide all dormant articles that have no children."
7866 (interactive)
eec82323
LMI
7867 (let ((data (gnus-data-list t))
7868 articles d children)
7869 ;; Find all articles that are either not dormant or have
7870 ;; children.
7871 (while (setq d (pop data))
7872 (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7873 (and (setq children
7874 (gnus-article-children (gnus-data-number d)))
7875 (let (found)
7876 (while children
7877 (when (memq (car children) articles)
7878 (setq children nil
7879 found t))
7880 (pop children))
7881 found)))
7882 (push (gnus-data-number d) articles)))
7883 ;; Do the limiting.
7884 (prog1
7885 (gnus-summary-limit articles)
7886 (gnus-summary-position-point))))
7887
7888(defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7889 "Mark all unread excluded articles as read.
7890If ALL, mark even excluded ticked and dormants as read."
7891 (interactive "P")
23f87bed
MB
7892 (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7893 (let ((articles (gnus-sorted-ndifference
eec82323
LMI
7894 (sort
7895 (mapcar (lambda (h) (mail-header-number h))
7896 gnus-newsgroup-headers)
7897 '<)
23f87bed 7898 gnus-newsgroup-limit))
eec82323 7899 article)
6748645f 7900 (setq gnus-newsgroup-unreads
23f87bed
MB
7901 (gnus-sorted-intersection gnus-newsgroup-unreads
7902 gnus-newsgroup-limit))
eec82323
LMI
7903 (if all
7904 (setq gnus-newsgroup-dormant nil
7905 gnus-newsgroup-marked nil
7906 gnus-newsgroup-reads
7907 (nconc
7908 (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7909 gnus-newsgroup-reads))
7910 (while (setq article (pop articles))
7911 (unless (or (memq article gnus-newsgroup-dormant)
7912 (memq article gnus-newsgroup-marked))
7913 (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7914
7915(defun gnus-summary-limit (articles &optional pop)
7916 (if pop
7917 ;; We pop the previous limit off the stack and use that.
7918 (setq articles (car gnus-newsgroup-limits)
7919 gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7920 ;; We use the new limit, so we push the old limit on the stack.
7921 (push gnus-newsgroup-limit gnus-newsgroup-limits))
7922 ;; Set the limit.
7923 (setq gnus-newsgroup-limit articles)
7924 (let ((total (length gnus-newsgroup-data))
7925 (data (gnus-data-find-list (gnus-summary-article-number)))
7926 (gnus-summary-mark-below nil) ; Inhibit this.
7927 found)
7928 ;; This will do all the work of generating the new summary buffer
7929 ;; according to the new limit.
7930 (gnus-summary-prepare)
7931 ;; Hide any threads, possibly.
23f87bed 7932 (gnus-summary-maybe-hide-threads)
eec82323
LMI
7933 ;; Try to return to the article you were at, or one in the
7934 ;; neighborhood.
7935 (when data
7936 ;; We try to find some article after the current one.
7937 (while data
7938 (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7939 (setq data nil
7940 found t))
7941 (setq data (cdr data))))
7942 (unless found
7943 ;; If there is no data, that means that we were after the last
7944 ;; article. The same goes when we can't find any articles
7945 ;; after the current one.
7946 (goto-char (point-max))
7947 (gnus-summary-find-prev))
6748645f 7948 (gnus-set-mode-line 'summary)
eec82323
LMI
7949 ;; We return how many articles were removed from the summary
7950 ;; buffer as a result of the new limit.
7951 (- total (length gnus-newsgroup-data))))
7952
7953(defsubst gnus-invisible-cut-children (threads)
7954 (let ((num 0))
7955 (while threads
7956 (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7957 (incf num))
7958 (pop threads))
7959 (< num 2)))
7960
7961(defsubst gnus-cut-thread (thread)
7962 "Go forwards in the thread until we find an article that we want to display."
7963 (when (or (eq gnus-fetch-old-headers 'some)
6748645f 7964 (eq gnus-fetch-old-headers 'invisible)
16409b0b 7965 (numberp gnus-fetch-old-headers)
eec82323
LMI
7966 (eq gnus-build-sparse-threads 'some)
7967 (eq gnus-build-sparse-threads 'more))
7968 ;; Deal with old-fetched headers and sparse threads.
7969 (while (and
7970 thread
7971 (or
7972 (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7973 (gnus-summary-article-ancient-p
7974 (mail-header-number (car thread))))
6748645f
LMI
7975 (if (or (<= (length (cdr thread)) 1)
7976 (eq gnus-fetch-old-headers 'invisible))
7977 (setq gnus-newsgroup-limit
7978 (delq (mail-header-number (car thread))
7979 gnus-newsgroup-limit)
7980 thread (cadr thread))
7981 (when (gnus-invisible-cut-children (cdr thread))
7982 (let ((th (cdr thread)))
7983 (while th
7984 (if (memq (mail-header-number (caar th))
a8151ef7 7985 gnus-newsgroup-limit)
6748645f
LMI
7986 (setq thread (car th)
7987 th nil)
7988 (setq th (cdr th))))))))))
eec82323
LMI
7989 thread)
7990
7991(defun gnus-cut-threads (threads)
23f87bed 7992 "Cut off all uninteresting articles from the beginning of THREADS."
eec82323 7993 (when (or (eq gnus-fetch-old-headers 'some)
6748645f 7994 (eq gnus-fetch-old-headers 'invisible)
16409b0b 7995 (numberp gnus-fetch-old-headers)
eec82323
LMI
7996 (eq gnus-build-sparse-threads 'some)
7997 (eq gnus-build-sparse-threads 'more))
7998 (let ((th threads))
7999 (while th
8000 (setcar th (gnus-cut-thread (car th)))
8001 (setq th (cdr th)))))
8002 ;; Remove nixed out threads.
8003 (delq nil threads))
8004
8005(defun gnus-summary-initial-limit (&optional show-if-empty)
8006 "Figure out what the initial limit is supposed to be on group entry.
8007This entails weeding out unwanted dormants, low-scored articles,
8008fetch-old-headers verbiage, and so on."
8009 ;; Most groups have nothing to remove.
8010 (if (or gnus-inhibit-limiting
8011 (and (null gnus-newsgroup-dormant)
23f87bed 8012 (eq gnus-newsgroup-display 'gnus-not-ignore)
eec82323 8013 (not (eq gnus-fetch-old-headers 'some))
16409b0b 8014 (not (numberp gnus-fetch-old-headers))
6748645f 8015 (not (eq gnus-fetch-old-headers 'invisible))
eec82323
LMI
8016 (null gnus-summary-expunge-below)
8017 (not (eq gnus-build-sparse-threads 'some))
8018 (not (eq gnus-build-sparse-threads 'more))
8019 (null gnus-thread-expunge-below)
8020 (not gnus-use-nocem)))
8021 () ; Do nothing.
8022 (push gnus-newsgroup-limit gnus-newsgroup-limits)
8023 (setq gnus-newsgroup-limit nil)
8024 (mapatoms
8025 (lambda (node)
8026 (unless (car (symbol-value node))
8027 ;; These threads have no parents -- they are roots.
8028 (let ((nodes (cdr (symbol-value node)))
8029 thread)
8030 (while nodes
8031 (if (and gnus-thread-expunge-below
8032 (< (gnus-thread-total-score (car nodes))
8033 gnus-thread-expunge-below))
8034 (gnus-expunge-thread (pop nodes))
8035 (setq thread (pop nodes))
8036 (gnus-summary-limit-children thread))))))
8037 gnus-newsgroup-dependencies)
8038 ;; If this limitation resulted in an empty group, we might
8039 ;; pop the previous limit and use it instead.
8040 (when (and (not gnus-newsgroup-limit)
8041 show-if-empty)
8042 (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8043 gnus-newsgroup-limit))
8044
8045(defun gnus-summary-limit-children (thread)
8046 "Return 1 if this subthread is visible and 0 if it is not."
8047 ;; First we get the number of visible children to this thread. This
8048 ;; is done by recursing down the thread using this function, so this
8049 ;; will really go down to a leaf article first, before slowly
8050 ;; working its way up towards the root.
8051 (when thread
23f87bed
MB
8052 (let* ((max-lisp-eval-depth 5000)
8053 (children
eec82323
LMI
8054 (if (cdr thread)
8055 (apply '+ (mapcar 'gnus-summary-limit-children
8056 (cdr thread)))
8057 0))
8058 (number (mail-header-number (car thread)))
8059 score)
8060 (if (and
8061 (not (memq number gnus-newsgroup-marked))
8062 (or
8063 ;; If this article is dormant and has absolutely no visible
8064 ;; children, then this article isn't visible.
8065 (and (memq number gnus-newsgroup-dormant)
8066 (zerop children))
8067 ;; If this is "fetch-old-headered" and there is no
8068 ;; visible children, then we don't want this article.
16409b0b
GM
8069 (and (or (eq gnus-fetch-old-headers 'some)
8070 (numberp gnus-fetch-old-headers))
eec82323
LMI
8071 (gnus-summary-article-ancient-p number)
8072 (zerop children))
6748645f
LMI
8073 ;; If this is "fetch-old-headered" and `invisible', then
8074 ;; we don't want this article.
8075 (and (eq gnus-fetch-old-headers 'invisible)
8076 (gnus-summary-article-ancient-p number))
eec82323
LMI
8077 ;; If this is a sparsely inserted article with no children,
8078 ;; we don't want it.
8079 (and (eq gnus-build-sparse-threads 'some)
8080 (gnus-summary-article-sparse-p number)
8081 (zerop children))
8082 ;; If we use expunging, and this article is really
8083 ;; low-scored, then we don't want this article.
8084 (when (and gnus-summary-expunge-below
8085 (< (setq score
8086 (or (cdr (assq number gnus-newsgroup-scored))
8087 gnus-summary-default-score))
8088 gnus-summary-expunge-below))
8089 ;; We increase the expunge-tally here, but that has
8090 ;; nothing to do with the limits, really.
8091 (incf gnus-newsgroup-expunged-tally)
8092 ;; We also mark as read here, if that's wanted.
8093 (when (and gnus-summary-mark-below
8094 (< score gnus-summary-mark-below))
8095 (setq gnus-newsgroup-unreads
8096 (delq number gnus-newsgroup-unreads))
8097 (if gnus-newsgroup-auto-expire
8098 (push number gnus-newsgroup-expirable)
8099 (push (cons number gnus-low-score-mark)
8100 gnus-newsgroup-reads)))
8101 t)
23f87bed
MB
8102 ;; Do the `display' group parameter.
8103 (and gnus-newsgroup-display
8104 (not (funcall gnus-newsgroup-display)))
eec82323
LMI
8105 ;; Check NoCeM things.
8106 (if (and gnus-use-nocem
8107 (gnus-nocem-unwanted-article-p
8108 (mail-header-id (car thread))))
8109 (progn
a8151ef7 8110 (setq gnus-newsgroup-unreads
eec82323
LMI
8111 (delq number gnus-newsgroup-unreads))
8112 t))))
8113 ;; Nope, invisible article.
8114 0
8115 ;; Ok, this article is to be visible, so we add it to the limit
8116 ;; and return 1.
8117 (push number gnus-newsgroup-limit)
8118 1))))
8119
8120(defun gnus-expunge-thread (thread)
8121 "Mark all articles in THREAD as read."
8122 (let* ((number (mail-header-number (car thread))))
8123 (incf gnus-newsgroup-expunged-tally)
8124 ;; We also mark as read here, if that's wanted.
8125 (setq gnus-newsgroup-unreads
8126 (delq number gnus-newsgroup-unreads))
8127 (if gnus-newsgroup-auto-expire
8128 (push number gnus-newsgroup-expirable)
8129 (push (cons number gnus-low-score-mark)
8130 gnus-newsgroup-reads)))
8131 ;; Go recursively through all subthreads.
8132 (mapcar 'gnus-expunge-thread (cdr thread)))
8133
8134;; Summary article oriented commands
8135
8136(defun gnus-summary-refer-parent-article (n)
8137 "Refer parent article N times.
8138If N is negative, go to ancestor -N instead.
8139The difference between N and the number of articles fetched is returned."
8140 (interactive "p")
eec82323
LMI
8141 (let ((skip 1)
8142 error header ref)
8143 (when (not (natnump n))
8144 (setq skip (abs n)
8145 n 1))
8146 (while (and (> n 0)
8147 (not error))
8148 (setq header (gnus-summary-article-header))
8149 (if (and (eq (mail-header-number header)
8150 (cdr gnus-article-current))
8151 (equal gnus-newsgroup-name
8152 (car gnus-article-current)))
8153 ;; If we try to find the parent of the currently
8154 ;; displayed article, then we take a look at the actual
8155 ;; References header, since this is slightly more
8156 ;; reliable than the References field we got from the
8157 ;; server.
8158 (save-excursion
8159 (set-buffer gnus-original-article-buffer)
8160 (nnheader-narrow-to-headers)
8161 (unless (setq ref (message-fetch-field "references"))
23f87bed
MB
8162 (when (setq ref (message-fetch-field "in-reply-to"))
8163 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
eec82323
LMI
8164 (widen))
8165 (setq ref
8166 ;; It's not the current article, so we take a bet on
8167 ;; the value we got from the server.
8168 (mail-header-references header)))
8169 (if (and ref
8170 (not (equal ref "")))
8171 (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8172 (gnus-message 1 "Couldn't find parent"))
8173 (gnus-message 1 "No references in article %d"
8174 (gnus-summary-article-number))
8175 (setq error t))
8176 (decf n))
8177 (gnus-summary-position-point)
8178 n))
8179
8180(defun gnus-summary-refer-references ()
8181 "Fetch all articles mentioned in the References header.
6748645f 8182Return the number of articles fetched."
eec82323 8183 (interactive)
eec82323
LMI
8184 (let ((ref (mail-header-references (gnus-summary-article-header)))
8185 (current (gnus-summary-article-number))
8186 (n 0))
8187 (if (or (not ref)
8188 (equal ref ""))
8189 (error "No References in the current article")
8190 ;; For each Message-ID in the References header...
8191 (while (string-match "<[^>]*>" ref)
8192 (incf n)
8193 ;; ... fetch that article.
8194 (gnus-summary-refer-article
8195 (prog1 (match-string 0 ref)
8196 (setq ref (substring ref (match-end 0))))))
8197 (gnus-summary-goto-subject current)
8198 (gnus-summary-position-point)
8199 n)))
8200
6748645f
LMI
8201(defun gnus-summary-refer-thread (&optional limit)
8202 "Fetch all articles in the current thread.
8203If LIMIT (the numerical prefix), fetch that many old headers instead
8204of what's specified by the `gnus-refer-thread-limit' variable."
8205 (interactive "P")
8206 (let ((id (mail-header-id (gnus-summary-article-header)))
8207 (limit (if limit (prefix-numeric-value limit)
8208 gnus-refer-thread-limit)))
6748645f
LMI
8209 (unless (eq gnus-fetch-old-headers 'invisible)
8210 (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8211 ;; Retrieve the headers and read them in.
23f87bed
MB
8212 (if (eq (if (numberp limit)
8213 (gnus-retrieve-headers
8214 (list (min
8215 (+ (mail-header-number
8216 (gnus-summary-article-header))
8217 limit)
8218 gnus-newsgroup-end))
8219 gnus-newsgroup-name (* limit 2))
8220 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8221 ;; headers.
8222 (gnus-retrieve-headers (list gnus-newsgroup-end)
8223 gnus-newsgroup-name limit))
6748645f
LMI
8224 'nov)
8225 (gnus-build-all-threads)
23f87bed 8226 (error "Can't fetch thread from back ends that don't support NOV"))
6748645f
LMI
8227 (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8228 (gnus-summary-limit-include-thread id)))
8229
16409b0b
GM
8230(defun gnus-summary-refer-article (message-id)
8231 "Fetch an article specified by MESSAGE-ID."
8232 (interactive "sMessage-ID: ")
eec82323
LMI
8233 (when (and (stringp message-id)
8234 (not (zerop (length message-id))))
23f87bed 8235 (setq message-id (gnus-replace-in-string message-id " " ""))
eec82323
LMI
8236 ;; Construct the correct Message-ID if necessary.
8237 ;; Suggested by tale@pawl.rpi.edu.
8238 (unless (string-match "^<" message-id)
8239 (setq message-id (concat "<" message-id)))
8240 (unless (string-match ">$" message-id)
8241 (setq message-id (concat message-id ">")))
23f87bed
MB
8242 ;; People often post MIDs from URLs, so unhex it:
8243 (unless (string-match "@" message-id)
8244 (setq message-id (gnus-url-unhex-string message-id)))
eec82323
LMI
8245 (let* ((header (gnus-id-to-header message-id))
8246 (sparse (and header
8247 (gnus-summary-article-sparse-p
a8151ef7
LMI
8248 (mail-header-number header))
8249 (memq (mail-header-number header)
16409b0b
GM
8250 gnus-newsgroup-limit)))
8251 number)
6748645f
LMI
8252 (cond
8253 ;; If the article is present in the buffer we just go to it.
8254 ((and header
8255 (or (not (gnus-summary-article-sparse-p
8256 (mail-header-number header)))
8257 sparse))
8258 (prog1
8259 (gnus-summary-goto-article
8260 (mail-header-number header) nil t)
8261 (when sparse
8262 (gnus-summary-update-article (mail-header-number header)))))
8263 (t
16409b0b
GM
8264 ;; We fetch the article.
8265 (catch 'found
8266 (dolist (gnus-override-method (gnus-refer-article-methods))
23f87bed
MB
8267 (when (and (gnus-check-server gnus-override-method)
8268 ;; Fetch the header,
8269 (setq number (gnus-summary-insert-subject message-id)))
8270 ;; and display the article.
eec82323 8271 (gnus-summary-select-article nil nil nil number)
16409b0b
GM
8272 (throw 'found t)))
8273 (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8274
8275(defun gnus-refer-article-methods ()
8f688cb0 8276 "Return a list of referable methods."
16409b0b
GM
8277 (cond
8278 ;; No method, so we default to current and native.
8279 ((null gnus-refer-article-method)
8280 (list gnus-current-select-method gnus-select-method))
8281 ;; Current.
8282 ((eq 'current gnus-refer-article-method)
8283 (list gnus-current-select-method))
8284 ;; List of select methods.
d4dfaa19
DL
8285 ((not (and (symbolp (car gnus-refer-article-method))
8286 (assq (car gnus-refer-article-method) nnoo-definition-alist)))
16409b0b
GM
8287 (let (out)
8288 (dolist (method gnus-refer-article-method)
8289 (push (if (eq 'current method)
8290 gnus-current-select-method
8291 method)
8292 out))
8293 (nreverse out)))
8294 ;; One single select method.
8295 (t
8296 (list gnus-refer-article-method))))
6748645f
LMI
8297
8298(defun gnus-summary-edit-parameters ()
8299 "Edit the group parameters of the current group."
8300 (interactive)
8301 (gnus-group-edit-group gnus-newsgroup-name 'params))
eec82323 8302
16409b0b
GM
8303(defun gnus-summary-customize-parameters ()
8304 "Customize the group parameters of the current group."
8305 (interactive)
8306 (gnus-group-customize gnus-newsgroup-name))
8307
eec82323
LMI
8308(defun gnus-summary-enter-digest-group (&optional force)
8309 "Enter an nndoc group based on the current article.
8310If FORCE, force a digest interpretation. If not, try
8311to guess what the document format is."
8312 (interactive "P")
eec82323 8313 (let ((conf gnus-current-window-configuration))
23f87bed
MB
8314 (save-window-excursion
8315 (save-excursion
8316 (let (gnus-article-prepare-hook
8317 gnus-display-mime-function
8318 gnus-break-pages)
8319 (gnus-summary-select-article))))
eec82323
LMI
8320 (setq gnus-current-window-configuration conf)
8321 (let* ((name (format "%s-%d"
8322 (gnus-group-prefixed-name
8323 gnus-newsgroup-name (list 'nndoc ""))
8324 (save-excursion
8325 (set-buffer gnus-summary-buffer)
8326 gnus-current-article)))
8327 (ogroup gnus-newsgroup-name)
8328 (params (append (gnus-info-params (gnus-get-info ogroup))
8329 (list (cons 'to-group ogroup))
23f87bed 8330 (list (cons 'parent-group ogroup))
eec82323
LMI
8331 (list (cons 'save-article-group ogroup))))
8332 (case-fold-search t)
8333 (buf (current-buffer))
16409b0b 8334 dig to-address)
eec82323 8335 (save-excursion
16409b0b
GM
8336 (set-buffer gnus-original-article-buffer)
8337 ;; Have the digest group inherit the main mail address of
8338 ;; the parent article.
23f87bed
MB
8339 (when (setq to-address (or (gnus-fetch-field "reply-to")
8340 (gnus-fetch-field "from")))
a1506d29
JB
8341 (setq params (append
8342 (list (cons 'to-address
d4dfaa19
DL
8343 (funcall gnus-decode-encoded-word-function
8344 to-address))))))
eec82323
LMI
8345 (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8346 (insert-buffer-substring gnus-original-article-buffer)
8347 ;; Remove lines that may lead nndoc to misinterpret the
8348 ;; document type.
8349 (narrow-to-region
8350 (goto-char (point-min))
8351 (or (search-forward "\n\n" nil t) (point)))
8352 (goto-char (point-min))
16409b0b 8353 (delete-matching-lines "^Path:\\|^From ")
eec82323
LMI
8354 (widen))
8355 (unwind-protect
23f87bed 8356 (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
16409b0b
GM
8357 (gnus-newsgroup-ephemeral-ignored-charsets
8358 gnus-newsgroup-ignored-charsets))
8359 (gnus-group-read-ephemeral-group
8360 name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8361 (nndoc-article-type
23f87bed
MB
8362 ,(if force 'mbox 'guess)))
8363 t nil nil nil
8364 `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8365 "ADAPT")))))
16409b0b 8366 ;; Make all postings to this group go to the parent group.
23f87bed
MB
8367 (nconc (gnus-info-params (gnus-get-info name))
8368 params)
8369 ;; Couldn't select this doc group.
8370 (switch-to-buffer buf)
8371 (gnus-set-global-variables)
8372 (gnus-configure-windows 'summary)
8373 (gnus-message 3 "Article couldn't be entered?"))
eec82323
LMI
8374 (kill-buffer dig)))))
8375
8376(defun gnus-summary-read-document (n)
8377 "Open a new group based on the current article(s).
8378This will allow you to read digests and other similar
8379documents as newsgroups.
8380Obeys the standard process/prefix convention."
8381 (interactive "P")
8382 (let* ((articles (gnus-summary-work-articles n))
8383 (ogroup gnus-newsgroup-name)
8384 (params (append (gnus-info-params (gnus-get-info ogroup))
8385 (list (cons 'to-group ogroup))))
8386 article group egroup groups vgroup)
8387 (while (setq article (pop articles))
8388 (setq group (format "%s-%d" gnus-newsgroup-name article))
8389 (gnus-summary-remove-process-mark article)
8390 (when (gnus-summary-display-article article)
8391 (save-excursion
16409b0b 8392 (with-temp-buffer
eec82323
LMI
8393 (insert-buffer-substring gnus-original-article-buffer)
8394 ;; Remove some headers that may lead nndoc to make
8395 ;; the wrong guess.
8396 (message-narrow-to-head)
8397 (goto-char (point-min))
8398 (delete-matching-lines "^\\(Path\\):\\|^From ")
8399 (widen)
8400 (if (setq egroup
8401 (gnus-group-read-ephemeral-group
8402 group `(nndoc ,group (nndoc-address ,(current-buffer))
8403 (nndoc-article-type guess))
8404 t nil t))
8405 (progn
23f87bed 8406 ;; Make all postings to this group go to the parent group.
eec82323
LMI
8407 (nconc (gnus-info-params (gnus-get-info egroup))
8408 params)
8409 (push egroup groups))
8410 ;; Couldn't select this doc group.
8411 (gnus-error 3 "Article couldn't be entered"))))))
8412 ;; Now we have selected all the documents.
8413 (cond
8414 ((not groups)
8415 (error "None of the articles could be interpreted as documents"))
8416 ((gnus-group-read-ephemeral-group
8417 (setq vgroup (format
8418 "nnvirtual:%s-%s" gnus-newsgroup-name
8419 (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8420 `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8421 t
8422 (cons (current-buffer) 'summary)))
8423 (t
8424 (error "Couldn't select virtual nndoc group")))))
8425
8426(defun gnus-summary-isearch-article (&optional regexp-p)
8427 "Do incremental search forward on the current article.
8428If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8429 (interactive "P")
eec82323
LMI
8430 (gnus-summary-select-article)
8431 (gnus-configure-windows 'article)
8432 (gnus-eval-in-buffer-window gnus-article-buffer
6748645f
LMI
8433 (save-restriction
8434 (widen)
8435 (isearch-forward regexp-p))))
eec82323
LMI
8436
8437(defun gnus-summary-search-article-forward (regexp &optional backward)
8438 "Search for an article containing REGEXP forward.
8439If BACKWARD, search backward instead."
8440 (interactive
8441 (list (read-string
8442 (format "Search article %s (regexp%s): "
8443 (if current-prefix-arg "backward" "forward")
8444 (if gnus-last-search-regexp
8445 (concat ", default " gnus-last-search-regexp)
8446 "")))
8447 current-prefix-arg))
eec82323
LMI
8448 (if (string-equal regexp "")
8449 (setq regexp (or gnus-last-search-regexp ""))
23f87bed
MB
8450 (setq gnus-last-search-regexp regexp)
8451 (setq gnus-article-before-search gnus-current-article))
8452 ;; Intentionally set gnus-last-article.
8453 (setq gnus-last-article gnus-article-before-search)
8454 (let ((gnus-last-article gnus-last-article))
8455 (if (gnus-summary-search-article regexp backward)
8456 (gnus-summary-show-thread)
abc40aab 8457 (signal 'search-failed (list regexp)))))
eec82323
LMI
8458
8459(defun gnus-summary-search-article-backward (regexp)
8460 "Search for an article containing REGEXP backward."
8461 (interactive
8462 (list (read-string
8463 (format "Search article backward (regexp%s): "
8464 (if gnus-last-search-regexp
8465 (concat ", default " gnus-last-search-regexp)
8466 "")))))
8467 (gnus-summary-search-article-forward regexp 'backward))
8468
8469(defun gnus-summary-search-article (regexp &optional backward)
8470 "Search for an article containing REGEXP.
8471Optional argument BACKWARD means do search for backward.
8472`gnus-select-article-hook' is not called during the search."
a8151ef7
LMI
8473 ;; We have to require this here to make sure that the following
8474 ;; dynamic binding isn't shadowed by autoloading.
8475 (require 'gnus-async)
16409b0b 8476 (require 'gnus-art)
eec82323 8477 (let ((gnus-select-article-hook nil) ;Disable hook.
16409b0b 8478 (gnus-article-prepare-hook nil)
eec82323
LMI
8479 (gnus-mark-article-hook nil) ;Inhibit marking as read.
8480 (gnus-use-article-prefetch nil)
8481 (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
a8151ef7 8482 (gnus-use-trees nil) ;Inhibit updating tree buffer.
23f87bed
MB
8483 (gnus-visual nil)
8484 (gnus-keep-backlog nil)
8485 (gnus-break-pages nil)
8486 (gnus-summary-display-arrow nil)
8487 (gnus-updated-mode-lines nil)
8488 (gnus-auto-center-summary nil)
eec82323 8489 (sum (current-buffer))
16409b0b 8490 (gnus-display-mime-function nil)
eec82323
LMI
8491 (found nil)
8492 point)
8493 (gnus-save-hidden-threads
8494 (gnus-summary-select-article)
8495 (set-buffer gnus-article-buffer)
16409b0b 8496 (goto-char (window-point (get-buffer-window (current-buffer))))
eec82323
LMI
8497 (when backward
8498 (forward-line -1))
8499 (while (not found)
8500 (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8501 (if (if backward
8502 (re-search-backward regexp nil t)
8503 (re-search-forward regexp nil t))
8504 ;; We found the regexp.
8505 (progn
8506 (setq found 'found)
8507 (beginning-of-line)
8508 (set-window-start
8509 (get-buffer-window (current-buffer))
8510 (point))
8511 (forward-line 1)
16409b0b
GM
8512 (set-window-point
8513 (get-buffer-window (current-buffer))
8514 (point))
eec82323
LMI
8515 (set-buffer sum)
8516 (setq point (point)))
8517 ;; We didn't find it, so we go to the next article.
8518 (set-buffer sum)
8519 (setq found 'not)
8520 (while (eq found 'not)
8521 (if (not (if backward (gnus-summary-find-prev)
8522 (gnus-summary-find-next)))
8523 ;; No more articles.
8524 (setq found t)
8525 ;; Select the next article and adjust point.
8526 (unless (gnus-summary-article-sparse-p
8527 (gnus-summary-article-number))
8528 (setq found nil)
8529 (gnus-summary-select-article)
8530 (set-buffer gnus-article-buffer)
8531 (widen)
8532 (goto-char (if backward (point-max) (point-min))))))))
8533 (gnus-message 7 ""))
8534 ;; Return whether we found the regexp.
8535 (when (eq found 'found)
8536 (goto-char point)
8537 (gnus-summary-show-thread)
8538 (gnus-summary-goto-subject gnus-current-article)
8539 (gnus-summary-position-point)
8540 t)))
8541
23f87bed
MB
8542(defun gnus-find-matching-articles (header regexp)
8543 "Return a list of all articles that match REGEXP on HEADER.
8544This search includes all articles in the current group that Gnus has
8545fetched headers for, whether they are displayed or not."
8546 (let ((articles nil)
8547 (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8548 (case-fold-search t))
8549 (dolist (header gnus-newsgroup-headers)
8550 (when (string-match regexp (funcall func header))
8551 (push (mail-header-number header) articles)))
8552 (nreverse articles)))
8553
eec82323 8554(defun gnus-summary-find-matching (header regexp &optional backward unread
47b63dfa 8555 not-case-fold not-matching)
eec82323
LMI
8556 "Return a list of all articles that match REGEXP on HEADER.
8557The search stars on the current article and goes forwards unless
8558BACKWARD is non-nil. If BACKWARD is `all', do all articles.
8559If UNREAD is non-nil, only unread articles will
8560be taken into consideration. If NOT-CASE-FOLD, case won't be folded
a1506d29 8561in the comparisons. If NOT-MATCHING, return a list of all articles that
47b63dfa
SZ
8562not match REGEXP on HEADER."
8563 (let ((case-fold-search (not not-case-fold))
16409b0b
GM
8564 articles d func)
8565 (if (consp header)
8566 (if (eq (car header) 'extra)
8567 (setq func
8568 `(lambda (h)
8569 (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8570 "")))
8571 (error "%s is an invalid header" header))
8572 (unless (fboundp (intern (concat "mail-header-" header)))
8573 (error "%s is not a valid header" header))
8574 (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
47b63dfa
SZ
8575 (dolist (d (if (eq backward 'all)
8576 gnus-newsgroup-data
8577 (gnus-data-find-list
8578 (gnus-summary-article-number)
8579 (gnus-data-list backward))))
8580 (when (and (or (not unread) ; We want all articles...
8581 (gnus-data-unread-p d)) ; Or just unreads.
8582 (vectorp (gnus-data-header d)) ; It's not a pseudo.
8583 (if not-matching
a1506d29 8584 (not (string-match
47b63dfa
SZ
8585 regexp
8586 (funcall func (gnus-data-header d))))
8587 (string-match regexp
8588 (funcall func (gnus-data-header d)))))
8589 (push (gnus-data-number d) articles))) ; Success!
eec82323
LMI
8590 (nreverse articles)))
8591
8592(defun gnus-summary-execute-command (header regexp command &optional backward)
8593 "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8594If HEADER is an empty string (or nil), the match is done on the entire
8595article. If BACKWARD (the prefix) is non-nil, search backward instead."
8596 (interactive
8597 (list (let ((completion-ignore-case t))
8598 (completing-read
8599 "Header name: "
23f87bed
MB
8600 (mapcar (lambda (header) (list (format "%s" header)))
8601 (append
8602 '("Number" "Subject" "From" "Lines" "Date"
8603 "Message-ID" "Xref" "References" "Body")
8604 gnus-extra-headers))
eec82323
LMI
8605 nil 'require-match))
8606 (read-string "Regexp: ")
8607 (read-key-sequence "Command: ")
8608 current-prefix-arg))
8609 (when (equal header "Body")
8610 (setq header ""))
eec82323
LMI
8611 ;; Hidden thread subtrees must be searched as well.
8612 (gnus-summary-show-all-threads)
8613 ;; We don't want to change current point nor window configuration.
8614 (save-excursion
8615 (save-window-excursion
23f87bed
MB
8616 (let (gnus-visual
8617 gnus-treat-strip-trailing-blank-lines
8618 gnus-treat-strip-leading-blank-lines
8619 gnus-treat-strip-multiple-blank-lines
8620 gnus-treat-hide-boring-headers
8621 gnus-treat-fold-newsgroups
8622 gnus-article-prepare-hook)
8623 (gnus-message 6 "Executing %s..." (key-description command))
8624 ;; We'd like to execute COMMAND interactively so as to give arguments.
8625 (gnus-execute header regexp
8626 `(call-interactively ',(key-binding command))
8627 backward)
8628 (gnus-message 6 "Executing %s...done" (key-description command))))))
eec82323
LMI
8629
8630(defun gnus-summary-beginning-of-article ()
8631 "Scroll the article back to the beginning."
8632 (interactive)
eec82323
LMI
8633 (gnus-summary-select-article)
8634 (gnus-configure-windows 'article)
8635 (gnus-eval-in-buffer-window gnus-article-buffer
8636 (widen)
8637 (goto-char (point-min))
23f87bed 8638 (when gnus-break-pages
eec82323
LMI
8639 (gnus-narrow-to-page))))
8640
8641(defun gnus-summary-end-of-article ()
8642 "Scroll to the end of the article."
8643 (interactive)
eec82323
LMI
8644 (gnus-summary-select-article)
8645 (gnus-configure-windows 'article)
8646 (gnus-eval-in-buffer-window gnus-article-buffer
8647 (widen)
8648 (goto-char (point-max))
8649 (recenter -3)
23f87bed
MB
8650 (when gnus-break-pages
8651 (when (re-search-backward page-delimiter nil t)
8652 (narrow-to-region (match-end 0) (point-max)))
eec82323
LMI
8653 (gnus-narrow-to-page))))
8654
23f87bed
MB
8655(defun gnus-summary-print-truncate-and-quote (string &optional len)
8656 "Truncate to LEN and quote all \"(\"'s in STRING."
8657 (gnus-replace-in-string (if (and len (> (length string) len))
8658 (substring string 0 len)
8659 string)
8660 "[()]" "\\\\\\&"))
8661
6748645f 8662(defun gnus-summary-print-article (&optional filename n)
23f87bed
MB
8663 "Generate and print a PostScript image of the process-marked (mail) articles.
8664
8665If used interactively, print the current article if none are
8666process-marked. With prefix arg, prompt the user for the name of the
8667file to save in.
6748645f 8668
23f87bed
MB
8669When used from Lisp, accept two optional args FILENAME and N. N means
8670to print the next N articles. If N is negative, print the N previous
8671articles. If N is nil and articles have been marked with the process
8672mark, print these instead.
eec82323 8673
16409b0b 8674If the optional first argument FILENAME is nil, send the image to the
6748645f
LMI
8675printer. If FILENAME is a string, save the PostScript image in a file with
8676that name. If FILENAME is a number, prompt the user for the name of the file
eec82323 8677to save in."
676a7cc9 8678 (interactive (list (ps-print-preprint current-prefix-arg)))
6748645f
LMI
8679 (dolist (article (gnus-summary-work-articles n))
8680 (gnus-summary-select-article nil nil 'pseudo article)
8681 (gnus-eval-in-buffer-window gnus-article-buffer
23f87bed 8682 (gnus-print-buffer))
676a7cc9
SZ
8683 (gnus-summary-remove-process-mark article))
8684 (ps-despool filename))
eec82323 8685
23f87bed
MB
8686(defun gnus-print-buffer ()
8687 (let ((buffer (generate-new-buffer " *print*")))
8688 (unwind-protect
8689 (progn
8690 (copy-to-buffer buffer (point-min) (point-max))
8691 (set-buffer buffer)
8692 (gnus-remove-text-with-property 'gnus-decoration)
8693 (when (gnus-visual-p 'article-highlight 'highlight)
8694 ;; Copy-to-buffer doesn't copy overlay. So redo
8695 ;; highlight.
8696 (let ((gnus-article-buffer buffer))
8697 (gnus-article-highlight-citation t)
8698 (gnus-article-highlight-signature)
8699 (gnus-article-emphasize)
8700 (gnus-article-delete-invisible-text)))
8701 (let ((ps-left-header
8702 (list
8703 (concat "("
8704 (gnus-summary-print-truncate-and-quote
8705 (mail-header-subject gnus-current-headers)
8706 66) ")")
8707 (concat "("
8708 (gnus-summary-print-truncate-and-quote
8709 (mail-header-from gnus-current-headers)
8710 45) ")")))
8711 (ps-right-header
8712 (list
8713 "/pagenumberstring load"
8714 (concat "("
8715 (mail-header-date gnus-current-headers) ")"))))
8716 (gnus-run-hooks 'gnus-ps-print-hook)
8717 (save-excursion
8718 (if window-system
8719 (ps-spool-buffer-with-faces)
8720 (ps-spool-buffer)))))
8721 (kill-buffer buffer))))
8722
eec82323 8723(defun gnus-summary-show-article (&optional arg)
23f87bed 8724 "Force redisplaying of the current article.
16409b0b
GM
8725If ARG (the prefix) is a number, show the article with the charset
8726defined in `gnus-summary-show-article-charset-alist', or the charset
23f87bed 8727input.
16409b0b 8728If ARG (the prefix) is non-nil and not a number, show the raw article
23f87bed
MB
8729without any article massaging functions being run. Normally, the key
8730strokes are `C-u g'."
eec82323 8731 (interactive "P")
16409b0b
GM
8732 (cond
8733 ((numberp arg)
23f87bed 8734 (gnus-summary-show-article t)
16409b0b
GM
8735 (let ((gnus-newsgroup-charset
8736 (or (cdr (assq arg gnus-summary-show-article-charset-alist))
23f87bed
MB
8737 (mm-read-coding-system
8738 "View as charset: " ;; actually it is coding system.
8739 (save-excursion
8740 (set-buffer gnus-article-buffer)
8741 (mm-detect-coding-region (point) (point-max))))))
16409b0b 8742 (gnus-newsgroup-ignored-charsets 'gnus-all))
23f87bed
MB
8743 (gnus-summary-select-article nil 'force)
8744 (let ((deps gnus-newsgroup-dependencies)
8745 head header lines)
8746 (save-excursion
8747 (set-buffer gnus-original-article-buffer)
8748 (save-restriction
8749 (message-narrow-to-head)
8750 (setq head (buffer-string))
8751 (goto-char (point-min))
8752 (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8753 (goto-char (point-max))
8754 (widen)
8755 (setq lines (1- (count-lines (point) (point-max))))))
8756 (with-temp-buffer
8757 (insert (format "211 %d Article retrieved.\n"
8758 (cdr gnus-article-current)))
8759 (insert head)
8760 (if lines (insert (format "Lines: %d\n" lines)))
8761 (insert ".\n")
8762 (let ((nntp-server-buffer (current-buffer)))
8763 (setq header (car (gnus-get-newsgroup-headers deps t))))))
8764 (gnus-data-set-header
8765 (gnus-data-find (cdr gnus-article-current))
8766 header)
8767 (gnus-summary-update-article-line
8768 (cdr gnus-article-current) header)
8769 (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8770 (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
16409b0b
GM
8771 ((not arg)
8772 ;; Select the article the normal way.
8773 (gnus-summary-select-article nil 'force))
8774 (t
8775 ;; We have to require this here to make sure that the following
8776 ;; dynamic binding isn't shadowed by autoloading.
8777 (require 'gnus-async)
8778 (require 'gnus-art)
eec82323
LMI
8779 ;; Bind the article treatment functions to nil.
8780 (let ((gnus-have-all-headers t)
eec82323 8781 gnus-article-prepare-hook
16409b0b
GM
8782 gnus-article-decode-hook
8783 gnus-display-mime-function
8784 gnus-break-pages)
8785 ;; Destroy any MIME parts.
8786 (when (gnus-buffer-live-p gnus-article-buffer)
8787 (save-excursion
8788 (set-buffer gnus-article-buffer)
8789 (mm-destroy-parts gnus-article-mime-handles)
8790 ;; Set it to nil for safety reason.
8791 (setq gnus-article-mime-handle-alist nil)
8792 (setq gnus-article-mime-handles nil)))
8793 (gnus-summary-select-article nil 'force))))
eec82323
LMI
8794 (gnus-summary-goto-subject gnus-current-article)
8795 (gnus-summary-position-point))
8796
23f87bed
MB
8797(defun gnus-summary-show-raw-article ()
8798 "Show the raw article without any article massaging functions being run."
8799 (interactive)
8800 (gnus-summary-show-article t))
8801
eec82323
LMI
8802(defun gnus-summary-verbose-headers (&optional arg)
8803 "Toggle permanent full header display.
8804If ARG is a positive number, turn header display on.
8805If ARG is a negative number, turn header display off."
8806 (interactive "P")
eec82323
LMI
8807 (setq gnus-show-all-headers
8808 (cond ((or (not (numberp arg))
8809 (zerop arg))
8810 (not gnus-show-all-headers))
8811 ((natnump arg)
8812 t)))
8813 (gnus-summary-show-article))
8814
8815(defun gnus-summary-toggle-header (&optional arg)
8816 "Show the headers if they are hidden, or hide them if they are shown.
8817If ARG is a positive number, show the entire header.
8818If ARG is a negative number, hide the unwanted header lines."
8819 (interactive "P")
23f87bed
MB
8820 (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8821 (get-buffer-window gnus-article-buffer t))))
8822 (with-current-buffer gnus-article-buffer
8823 (widen)
8824 (article-narrow-to-head)
16409b0b
GM
8825 (let* ((buffer-read-only nil)
8826 (inhibit-point-motion-hooks t)
23f87bed
MB
8827 (hidden (if (numberp arg)
8828 (>= arg 0)
f0096211
MB
8829 (or (not (looking-at "[^ \t\n]+:"))
8830 (gnus-article-hidden-text-p 'headers))))
23f87bed
MB
8831 s e)
8832 (delete-region (point-min) (point-max))
667e0ba6
SM
8833 (with-current-buffer gnus-original-article-buffer
8834 (goto-char (setq s (point-min)))
23f87bed
MB
8835 (setq e (if (search-forward "\n\n" nil t)
8836 (1- (point))
8837 (point-max))))
667e0ba6 8838 (insert-buffer-substring gnus-original-article-buffer s e)
23f87bed
MB
8839 (run-hooks 'gnus-article-decode-hook)
8840 (if hidden
8841 (let ((gnus-treat-hide-headers nil)
8842 (gnus-treat-hide-boring-headers nil))
8843 (gnus-delete-wash-type 'headers)
8844 (gnus-treat-article 'head))
8845 (gnus-treat-article 'head))
8846 (widen)
8847 (if window
8848 (set-window-start window (goto-char (point-min))))
8849 (if gnus-break-pages
8850 (gnus-narrow-to-page)
8851 (when (gnus-visual-p 'page-marker)
8852 (let ((buffer-read-only nil))
8853 (gnus-remove-text-with-property 'gnus-prev)
8854 (gnus-remove-text-with-property 'gnus-next))))
16409b0b 8855 (gnus-set-mode-line 'article)))))
eec82323
LMI
8856
8857(defun gnus-summary-show-all-headers ()
8858 "Make all header lines visible."
8859 (interactive)
23f87bed 8860 (gnus-summary-toggle-header 1))
eec82323 8861
eec82323
LMI
8862(defun gnus-summary-caesar-message (&optional arg)
8863 "Caesar rotate the current article by 13.
8864The numerical prefix specifies how many places to rotate each letter
8865forward."
8866 (interactive "P")
eec82323
LMI
8867 (gnus-summary-select-article)
8868 (let ((mail-header-separator ""))
8869 (gnus-eval-in-buffer-window gnus-article-buffer
8870 (save-restriction
8871 (widen)
8872 (let ((start (window-start))
8873 buffer-read-only)
8874 (message-caesar-buffer-body arg)
ff4d3926
MB
8875 (set-window-start (get-buffer-window (current-buffer)) start)))))
8876 ;; Create buttons and stuff...
8877 (gnus-treat-article nil))
eec82323 8878
23f87bed
MB
8879(autoload 'unmorse-region "morse"
8880 "Convert morse coded text in region to ordinary ASCII text."
8881 t)
8882
8883(defun gnus-summary-morse-message (&optional arg)
8884 "Morse decode the current article."
8885 (interactive "P")
8886 (gnus-summary-select-article)
8887 (let ((mail-header-separator ""))
8888 (gnus-eval-in-buffer-window gnus-article-buffer
8889 (save-excursion
8890 (save-restriction
8891 (widen)
8892 (let ((pos (window-start))
8893 buffer-read-only)
8894 (goto-char (point-min))
8895 (when (message-goto-body)
8896 (gnus-narrow-to-body))
8897 (goto-char (point-min))
8898