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