2001-10-31 Simon Josefsson <jas@extundo.com>
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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
29 (eval-when-compile (require 'cl))
30
31 (require 'gnus)
32 (require 'gnus-group)
33 (require 'gnus-spec)
34 (require 'gnus-range)
35 (require 'gnus-int)
36 (require 'gnus-undo)
37 (require 'gnus-util)
38 (require 'mm-decode)
39 ;; Recursive :-(.
40 ;; (require 'gnus-art)
41 (require 'nnoo)
42 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
43 (autoload 'gnus-cache-write-active "gnus-cache")
44 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
45 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
46 (autoload 'mm-uu-dissect "mm-uu")
47
48 (defcustom gnus-kill-summary-on-exit t
49   "*If non-nil, kill the summary buffer when you exit from it.
50 If nil, the summary will become a \"*Dead Summary*\" buffer, and
51 it will be killed sometime later."
52   :group 'gnus-summary-exit
53   :type 'boolean)
54
55 (defcustom gnus-fetch-old-headers nil
56   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
57 If an unread article in the group refers to an older, already read (or
58 just marked as read) article, the old article will not normally be
59 displayed in the Summary buffer.  If this variable is non-nil, Gnus
60 will attempt to grab the headers to the old articles, and thereby
61 build complete threads.  If it has the value `some', only enough
62 headers to connect otherwise loose threads will be displayed.  This
63 variable can also be a number.  In that case, no more than that number
64 of old headers will be fetched.  If it has the value `invisible', all
65 old headers will be fetched, but none will be displayed.
66
67 The server has to support NOV for any of this to work."
68   :group 'gnus-thread
69   :type '(choice (const :tag "off" nil)
70                  (const some)
71                  number
72                  (sexp :menu-tag "other" t)))
73
74 (defcustom gnus-refer-thread-limit 200
75   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
76 If t, fetch all the available old headers."
77   :group 'gnus-thread
78   :type '(choice number
79                  (sexp :menu-tag "other" t)))
80
81 (defcustom gnus-summary-make-false-root 'adopt
82   "*nil means that Gnus won't gather loose threads.
83 If the root of a thread has expired or been read in a previous
84 session, the information necessary to build a complete thread has been
85 lost.  Instead of having many small sub-threads from this original thread
86 scattered all over the summary buffer, Gnus can gather them.
87
88 If non-nil, Gnus will try to gather all loose sub-threads from an
89 original thread into one large thread.
90
91 If this variable is non-nil, it should be one of `none', `adopt',
92 `dummy' or `empty'.
93
94 If this variable is `none', Gnus will not make a false root, but just
95 present the sub-threads after another.
96 If this variable is `dummy', Gnus will create a dummy root that will
97 have all the sub-threads as children.
98 If this variable is `adopt', Gnus will make one of the \"children\"
99 the parent and mark all the step-children as such.
100 If this variable is `empty', the \"children\" are printed with empty
101 subject fields.  (Or rather, they will be printed with a string
102 given by the `gnus-summary-same-subject' variable.)"
103   :group 'gnus-thread
104   :type '(choice (const :tag "off" nil)
105                  (const none)
106                  (const dummy)
107                  (const adopt)
108                  (const empty)))
109
110 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
111   "*A regexp to match subjects to be excluded from loose thread gathering.
112 As loose thread gathering is done on subjects only, that means that
113 there can be many false gatherings performed.  By rooting out certain
114 common subjects, gathering might become saner."
115   :group 'gnus-thread
116   :type 'regexp)
117
118 (defcustom gnus-summary-gather-subject-limit nil
119   "*Maximum length of subject comparisons when gathering loose threads.
120 Use nil to compare full subjects.  Setting this variable to a low
121 number will help gather threads that have been corrupted by
122 newsreaders chopping off subject lines, but it might also mean that
123 unrelated articles that have subject that happen to begin with the
124 same few characters will be incorrectly gathered.
125
126 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
127 comparing subjects."
128   :group 'gnus-thread
129   :type '(choice (const :tag "off" nil)
130                  (const fuzzy)
131                  (sexp :menu-tag "on" t)))
132
133 (defcustom gnus-simplify-subject-functions nil
134   "List of functions taking a string argument that simplify subjects.
135 The functions are applied recursively.
136
137 Useful functions to put in this list include: `gnus-simplify-subject-re',
138 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
139   :group 'gnus-thread
140   :type '(repeat function))
141
142 (defcustom gnus-simplify-ignored-prefixes nil
143   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
144   :group 'gnus-thread
145   :type '(choice (const :tag "off" nil)
146                  regexp))
147
148 (defcustom gnus-build-sparse-threads nil
149   "*If non-nil, fill in the gaps in threads.
150 If `some', only fill in the gaps that are needed to tie loose threads
151 together.  If `more', fill in all leaf nodes that Gnus can find.  If
152 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
153   :group 'gnus-thread
154   :type '(choice (const :tag "off" nil)
155                  (const some)
156                  (const more)
157                  (sexp :menu-tag "all" t)))
158
159 (defcustom gnus-summary-thread-gathering-function
160   'gnus-gather-threads-by-subject
161   "*Function used for gathering loose threads.
162 There are two pre-defined functions: `gnus-gather-threads-by-subject',
163 which only takes Subjects into consideration; and
164 `gnus-gather-threads-by-references', which compared the References
165 headers of the articles to find matches."
166   :group 'gnus-thread
167   :type '(radio (function-item gnus-gather-threads-by-subject)
168                 (function-item gnus-gather-threads-by-references)
169                 (function :tag "other")))
170
171 (defcustom gnus-summary-same-subject ""
172   "*String indicating that the current article has the same subject as the previous.
173 This variable will only be used if the value of
174 `gnus-summary-make-false-root' is `empty'."
175   :group 'gnus-summary-format
176   :type 'string)
177
178 (defcustom gnus-summary-goto-unread t
179   "*If t, many commands will go to the next unread article.
180 This applies to marking commands as well as other commands that
181 \"naturally\" select the next article, like, for instance, `SPC' at
182 the end of an article.
183
184 If nil, the marking commands do NOT go to the next unread article
185 (they go to the next article instead).  If `never', commands that
186 usually go to the next unread article, will go to the next article,
187 whether it is read or not."
188   :group 'gnus-summary-marks
189   :link '(custom-manual "(gnus)Setting Marks")
190   :type '(choice (const :tag "off" nil)
191                  (const never)
192                  (sexp :menu-tag "on" t)))
193
194 (defcustom gnus-summary-default-score 0
195   "*Default article score level.
196 All scores generated by the score files will be added to this score.
197 If this variable is nil, scoring will be disabled."
198   :group 'gnus-score-default
199   :type '(choice (const :tag "disable")
200                  integer))
201
202 (defcustom gnus-summary-default-high-score 0
203   "*Default threshold for a high scored article.
204 An article will be highlighted as high scored if its score is greater
205 than this score."
206   :group 'gnus-score-default
207   :type 'integer)
208
209 (defcustom gnus-summary-default-low-score 0
210   "*Default threshold for a low scored article.
211 An article will be highlighted as low scored if its score is smaller
212 than this score."
213   :group 'gnus-score-default
214   :type 'integer)
215
216 (defcustom gnus-summary-zcore-fuzz 0
217   "*Fuzziness factor for the zcore in the summary buffer.
218 Articles with scores closer than this to `gnus-summary-default-score'
219 will not be marked."
220   :group 'gnus-summary-format
221   :type 'integer)
222
223 (defcustom gnus-simplify-subject-fuzzy-regexp nil
224   "*Strings to be removed when doing fuzzy matches.
225 This can either be a regular expression or list of regular expressions
226 that will be removed from subject strings if fuzzy subject
227 simplification is selected."
228   :group 'gnus-thread
229   :type '(repeat regexp))
230
231 (defcustom gnus-show-threads t
232   "*If non-nil, display threads in summary mode."
233   :group 'gnus-thread
234   :type 'boolean)
235
236 (defcustom gnus-thread-hide-subtree nil
237   "*If non-nil, hide all threads initially.
238 If threads are hidden, you have to run the command
239 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
240 to expose hidden threads."
241   :group 'gnus-thread
242   :type 'boolean)
243
244 (defcustom gnus-thread-hide-killed t
245   "*If non-nil, hide killed threads automatically."
246   :group 'gnus-thread
247   :type 'boolean)
248
249 (defcustom gnus-thread-ignore-subject t
250   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
251 If nil, articles that have different subjects from their parents will
252 start separate threads."
253   :group 'gnus-thread
254   :type 'boolean)
255
256 (defcustom gnus-thread-operation-ignore-subject t
257   "*If non-nil, subjects will be ignored when doing thread commands.
258 This affects commands like `gnus-summary-kill-thread' and
259 `gnus-summary-lower-thread'.
260
261 If this variable is nil, articles in the same thread with different
262 subjects will not be included in the operation in question.  If this
263 variable is `fuzzy', only articles that have subjects that are fuzzily
264 equal will be included."
265   :group 'gnus-thread
266   :type '(choice (const :tag "off" nil)
267                  (const fuzzy)
268                  (sexp :tag "on" t)))
269
270 (defcustom gnus-thread-indent-level 4
271   "*Number that says how much each sub-thread should be indented."
272   :group 'gnus-thread
273   :type 'integer)
274
275 (defcustom gnus-auto-extend-newsgroup t
276   "*If non-nil, extend newsgroup forward and backward when requested."
277   :group 'gnus-summary-choose
278   :type 'boolean)
279
280 (defcustom gnus-auto-select-first t
281   "*If nil, don't select the first unread article when entering a group.
282 If this variable is `best', select the highest-scored unread article
283 in the group.  If t, select the first unread article.
284
285 This variable can also be a function to place point on a likely
286 subject line.  Useful values include `gnus-summary-first-unread-subject',
287 `gnus-summary-first-unread-article' and
288 `gnus-summary-best-unread-article'.
289
290 If you want to prevent automatic selection of the first unread article
291 in some newsgroups, set the variable to nil in
292 `gnus-select-group-hook'."
293   :group 'gnus-group-select
294   :type '(choice (const :tag "none" nil)
295                  (const best)
296                  (sexp :menu-tag "first" t)
297                  (function-item gnus-summary-first-unread-subject)
298                  (function-item gnus-summary-first-unread-article)
299                  (function-item gnus-summary-best-unread-article)))
300
301 (defcustom gnus-auto-select-next t
302   "*If non-nil, offer to go to the next group from the end of the previous.
303 If the value is t and the next newsgroup is empty, Gnus will exit
304 summary mode and go back to group mode.  If the value is neither nil
305 nor t, Gnus will select the following unread newsgroup.  In
306 particular, if the value is the symbol `quietly', the next unread
307 newsgroup will be selected without any confirmation, and if it is
308 `almost-quietly', the next group will be selected without any
309 confirmation if you are located on the last article in the group.
310 Finally, if this variable is `slightly-quietly', the `Z n' command
311 will go to the next group without confirmation."
312   :group 'gnus-summary-maneuvering
313   :type '(choice (const :tag "off" nil)
314                  (const quietly)
315                  (const almost-quietly)
316                  (const slightly-quietly)
317                  (sexp :menu-tag "on" t)))
318
319 (defcustom gnus-auto-select-same nil
320   "*If non-nil, select the next article with the same subject.
321 If there are no more articles with the same subject, go to
322 the first unread article."
323   :group 'gnus-summary-maneuvering
324   :type 'boolean)
325
326 (defcustom gnus-summary-check-current nil
327   "*If non-nil, consider the current article when moving.
328 The \"unread\" movement commands will stay on the same line if the
329 current article is unread."
330   :group 'gnus-summary-maneuvering
331   :type 'boolean)
332
333 (defcustom gnus-auto-center-summary t
334   "*If non-nil, always center the current summary buffer.
335 In particular, if `vertical' do only vertical recentering.  If non-nil
336 and non-`vertical', do both horizontal and vertical recentering."
337   :group 'gnus-summary-maneuvering
338   :type '(choice (const :tag "none" nil)
339                  (const vertical)
340                  (integer :tag "height")
341                  (sexp :menu-tag "both" t)))
342
343 (defcustom gnus-show-all-headers nil
344   "*If non-nil, don't hide any headers."
345   :group 'gnus-article-hiding
346   :group 'gnus-article-headers
347   :type 'boolean)
348
349 (defcustom gnus-summary-ignore-duplicates nil
350   "*If non-nil, ignore articles with identical Message-ID headers."
351   :group 'gnus-summary
352   :type 'boolean)
353
354 (defcustom gnus-single-article-buffer t
355   "*If non-nil, display all articles in the same buffer.
356 If nil, each group will get its own article buffer."
357   :group 'gnus-article-various
358   :type 'boolean)
359
360 (defcustom gnus-break-pages t
361   "*If non-nil, do page breaking on articles.
362 The page delimiter is specified by the `gnus-page-delimiter'
363 variable."
364   :group 'gnus-article-various
365   :type 'boolean)
366
367 (defcustom gnus-move-split-methods nil
368   "*Variable used to suggest where articles are to be moved to.
369 It uses the same syntax as the `gnus-split-methods' variable.
370 However, whereas `gnus-split-methods' specifies file names as targets,
371 this variable specifies group names."
372   :group 'gnus-summary-mail
373   :type '(repeat (choice (list :value (fun) function)
374                          (cons :value ("" "") regexp (repeat string))
375                          (sexp :value nil))))
376
377 (defcustom gnus-unread-mark ?           ;Whitespace
378   "*Mark used for unread articles."
379   :group 'gnus-summary-marks
380   :type 'character)
381
382 (defcustom gnus-ticked-mark ?!
383   "*Mark used for ticked articles."
384   :group 'gnus-summary-marks
385   :type 'character)
386
387 (defcustom gnus-dormant-mark ??
388   "*Mark used for dormant articles."
389   :group 'gnus-summary-marks
390   :type 'character)
391
392 (defcustom gnus-del-mark ?r
393   "*Mark used for del'd articles."
394   :group 'gnus-summary-marks
395   :type 'character)
396
397 (defcustom gnus-read-mark ?R
398   "*Mark used for read articles."
399   :group 'gnus-summary-marks
400   :type 'character)
401
402 (defcustom gnus-expirable-mark ?E
403   "*Mark used for expirable articles."
404   :group 'gnus-summary-marks
405   :type 'character)
406
407 (defcustom gnus-killed-mark ?K
408   "*Mark used for killed articles."
409   :group 'gnus-summary-marks
410   :type 'character)
411
412 (defcustom gnus-souped-mark ?F
413   "*Mark used for souped articles."
414   :group 'gnus-summary-marks
415   :type 'character)
416
417 (defcustom gnus-kill-file-mark ?X
418   "*Mark used for articles killed by kill files."
419   :group 'gnus-summary-marks
420   :type 'character)
421
422 (defcustom gnus-low-score-mark ?Y
423   "*Mark used for articles with a low score."
424   :group 'gnus-summary-marks
425   :type 'character)
426
427 (defcustom gnus-catchup-mark ?C
428   "*Mark used for articles that are caught up."
429   :group 'gnus-summary-marks
430   :type 'character)
431
432 (defcustom gnus-replied-mark ?A
433   "*Mark used for articles that have been replied to."
434   :group 'gnus-summary-marks
435   :type 'character)
436
437 (defcustom gnus-forwarded-mark ?F
438   "*Mark used for articles that have been forwarded."
439   :group 'gnus-summary-marks
440   :type 'character)
441
442 (defcustom gnus-recent-mark ?N
443   "*Mark used for articles that are recent."
444   :group 'gnus-summary-marks
445   :type 'character)
446
447 (defcustom gnus-cached-mark ?*
448   "*Mark used for articles that are in the cache."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-saved-mark ?S
453   "*Mark used for articles that have been saved."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-unseen-mark ?.
458   "*Mark used for articles that haven't been seen."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-no-mark ?               ;Whitespace
463   "*Mark used for articles that have no other secondary mark."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-ancient-mark ?O
468   "*Mark used for ancient articles."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-sparse-mark ?Q
473   "*Mark used for sparsely reffed articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-canceled-mark ?G
478   "*Mark used for canceled articles."
479   :group 'gnus-summary-marks
480   :type 'character)
481
482 (defcustom gnus-duplicate-mark ?M
483   "*Mark used for duplicate articles."
484   :group 'gnus-summary-marks
485   :type 'character)
486
487 (defcustom gnus-undownloaded-mark ?@
488   "*Mark used for articles that weren't downloaded."
489   :group 'gnus-summary-marks
490   :type 'character)
491
492 (defcustom gnus-downloadable-mark ?%
493   "*Mark used for articles that are to be downloaded."
494   :group 'gnus-summary-marks
495   :type 'character)
496
497 (defcustom gnus-unsendable-mark ?=
498   "*Mark used for articles that won't be sent."
499   :group 'gnus-summary-marks
500   :type 'character)
501
502 (defcustom gnus-score-over-mark ?+
503   "*Score mark used for articles with high scores."
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-score-below-mark ?-
508   "*Score mark used for articles with low scores."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-empty-thread-mark ?     ;Whitespace
513   "*There is no thread under the article."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-not-empty-thread-mark ?=
518   "*There is a thread under the article."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-view-pseudo-asynchronously nil
523   "*If non-nil, Gnus will view pseudo-articles asynchronously."
524   :group 'gnus-extract-view
525   :type 'boolean)
526
527 (defcustom gnus-auto-expirable-marks
528   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
529         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
530         gnus-souped-mark gnus-duplicate-mark)
531   "*The list of marks converted into expiration if a group is auto-expirable."
532   :version "21.1"
533   :group 'gnus-summary
534   :type '(repeat character))
535
536 (defcustom gnus-inhibit-user-auto-expire t
537   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
538   :version "21.1"
539   :group 'gnus-summary
540   :type 'boolean)
541
542 (defcustom gnus-view-pseudos nil
543   "*If `automatic', pseudo-articles will be viewed automatically.
544 If `not-confirm', pseudos will be viewed automatically, and the user
545 will not be asked to confirm the command."
546   :group 'gnus-extract-view
547   :type '(choice (const :tag "off" nil)
548                  (const automatic)
549                  (const not-confirm)))
550
551 (defcustom gnus-view-pseudos-separately t
552   "*If non-nil, one pseudo-article will be created for each file to be viewed.
553 If nil, all files that use the same viewing command will be given as a
554 list of parameters to that command."
555   :group 'gnus-extract-view
556   :type 'boolean)
557
558 (defcustom gnus-insert-pseudo-articles t
559   "*If non-nil, insert pseudo-articles when decoding articles."
560   :group 'gnus-extract-view
561   :type 'boolean)
562
563 (defcustom gnus-summary-dummy-line-format
564   "  %(:                          :%) %S\n"
565   "*The format specification for the dummy roots in the summary buffer.
566 It works along the same lines as a normal formatting string,
567 with some simple extensions.
568
569 %S  The subject"
570   :group 'gnus-threading
571   :type 'string)
572
573 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
574   "*The format specification for the summary mode line.
575 It works along the same lines as a normal formatting string,
576 with some simple extensions:
577
578 %G  Group name
579 %p  Unprefixed group name
580 %A  Current article number
581 %z  Current article score
582 %V  Gnus version
583 %U  Number of unread articles in the group
584 %e  Number of unselected articles in the group
585 %Z  A string with unread/unselected article counts
586 %g  Shortish group name
587 %S  Subject of the current article
588 %u  User-defined spec
589 %s  Current score file name
590 %d  Number of dormant articles
591 %r  Number of articles that have been marked as read in this session
592 %E  Number of articles expunged by the score files"
593   :group 'gnus-summary-format
594   :type 'string)
595
596 (defcustom gnus-list-identifiers nil
597   "Regexp that matches list identifiers to be removed from subject.
598 This can also be a list of regexps."
599   :version "21.1"
600   :group 'gnus-summary-format
601   :group 'gnus-article-hiding
602   :type '(choice (const :tag "none" nil)
603                  (regexp :value ".*")
604                  (repeat :value (".*") regexp)))
605
606 (defcustom gnus-summary-mark-below 0
607   "*Mark all articles with a score below this variable as read.
608 This variable is local to each summary buffer and usually set by the
609 score file."
610   :group 'gnus-score-default
611   :type 'integer)
612
613 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
614   "*List of functions used for sorting articles in the summary buffer.
615
616 Each function takes two articles and returns non-nil if the first
617 article should be sorted before the other.  If you use more than one
618 function, the primary sort function should be the last.  You should
619 probably always include `gnus-article-sort-by-number' in the list of
620 sorting functions -- preferably first.  Also note that sorting by date
621 is often much slower than sorting by number, and the sorting order is
622 very similar.  (Sorting by date means sorting by the time the message
623 was sent, sorting by number means sorting by arrival time.)
624
625 Ready-made functions include `gnus-article-sort-by-number',
626 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
627 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
628
629 When threading is turned on, the variable `gnus-thread-sort-functions'
630 controls how articles are sorted."
631   :group 'gnus-summary-sort
632   :type '(repeat (choice (function-item gnus-article-sort-by-number)
633                          (function-item gnus-article-sort-by-author)
634                          (function-item gnus-article-sort-by-subject)
635                          (function-item gnus-article-sort-by-date)
636                          (function-item gnus-article-sort-by-score)
637                          (function :tag "other"))))
638
639 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
640   "*List of functions used for sorting threads in the summary buffer.
641 By default, threads are sorted by article number.
642
643 Each function takes two threads and returns non-nil if the first
644 thread should be sorted before the other.  If you use more than one
645 function, the primary sort function should be the last.  You should
646 probably always include `gnus-thread-sort-by-number' in the list of
647 sorting functions -- preferably first.  Also note that sorting by date
648 is often much slower than sorting by number, and the sorting order is
649 very similar.  (Sorting by date means sorting by the time the message
650 was sent, sorting by number means sorting by arrival time.)
651
652 Ready-made functions include `gnus-thread-sort-by-number',
653 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
654 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
655 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
656
657 When threading is turned off, the variable
658 `gnus-article-sort-functions' controls how articles are sorted."
659   :group 'gnus-summary-sort
660   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
661                          (function-item gnus-thread-sort-by-author)
662                          (function-item gnus-thread-sort-by-subject)
663                          (function-item gnus-thread-sort-by-date)
664                          (function-item gnus-thread-sort-by-score)
665                          (function-item gnus-thread-sort-by-total-score)
666                          (function :tag "other"))))
667
668 (defcustom gnus-thread-score-function '+
669   "*Function used for calculating the total score of a thread.
670
671 The function is called with the scores of the article and each
672 subthread and should then return the score of the thread.
673
674 Some functions you can use are `+', `max', or `min'."
675   :group 'gnus-summary-sort
676   :type 'function)
677
678 (defcustom gnus-summary-expunge-below nil
679   "All articles that have a score less than this variable will be expunged.
680 This variable is local to the summary buffers."
681   :group 'gnus-score-default
682   :type '(choice (const :tag "off" nil)
683                  integer))
684
685 (defcustom gnus-thread-expunge-below nil
686   "All threads that have a total score less than this variable will be expunged.
687 See `gnus-thread-score-function' for en explanation of what a
688 \"thread score\" is.
689
690 This variable is local to the summary buffers."
691   :group 'gnus-threading
692   :group 'gnus-score-default
693   :type '(choice (const :tag "off" nil)
694                  integer))
695
696 (defcustom gnus-summary-mode-hook nil
697   "*A hook for Gnus summary mode.
698 This hook is run before any variables are set in the summary buffer."
699   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
700   :group 'gnus-summary-various
701   :type 'hook)
702
703 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
704 (when (featurep 'xemacs)
705   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
706   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
707   (add-hook 'gnus-summary-mode-hook
708             'gnus-xmas-switch-horizontal-scrollbar-off))
709
710 (defcustom gnus-summary-menu-hook nil
711   "*Hook run after the creation of the summary mode menu."
712   :group 'gnus-summary-visual
713   :type 'hook)
714
715 (defcustom gnus-summary-exit-hook nil
716   "*A hook called on exit from the summary buffer.
717 It will be called with point in the group buffer."
718   :group 'gnus-summary-exit
719   :type 'hook)
720
721 (defcustom gnus-summary-prepare-hook nil
722   "*A hook called after the summary buffer has been generated.
723 If you want to modify the summary buffer, you can use this hook."
724   :group 'gnus-summary-various
725   :type 'hook)
726
727 (defcustom gnus-summary-prepared-hook nil
728   "*A hook called as the last thing after the summary buffer has been generated."
729   :group 'gnus-summary-various
730   :type 'hook)
731
732 (defcustom gnus-summary-generate-hook nil
733   "*A hook run just before generating the summary buffer.
734 This hook is commonly used to customize threading variables and the
735 like."
736   :group 'gnus-summary-various
737   :type 'hook)
738
739 (defcustom gnus-select-group-hook nil
740   "*A hook called when a newsgroup is selected.
741
742 If you'd like to simplify subjects like the
743 `gnus-summary-next-same-subject' command does, you can use the
744 following hook:
745
746  (setq gnus-select-group-hook
747       (list
748         (lambda ()
749           (mapcar (lambda (header)
750                      (mail-header-set-subject
751                       header
752                       (gnus-simplify-subject
753                        (mail-header-subject header) 're-only)))
754                   gnus-newsgroup-headers))))"
755   :group 'gnus-group-select
756   :type 'hook)
757
758 (defcustom gnus-select-article-hook nil
759   "*A hook called when an article is selected."
760   :group 'gnus-summary-choose
761   :type 'hook)
762
763 (defcustom gnus-visual-mark-article-hook
764   (list 'gnus-highlight-selected-summary)
765   "*Hook run after selecting an article in the summary buffer.
766 It is meant to be used for highlighting the article in some way.  It
767 is not run if `gnus-visual' is nil."
768   :group 'gnus-summary-visual
769   :type 'hook)
770
771 (defcustom gnus-parse-headers-hook nil
772   "*A hook called before parsing the headers."
773   :group 'gnus-various
774   :type 'hook)
775
776 (defcustom gnus-exit-group-hook nil
777   "*A hook called when exiting summary mode.
778 This hook is not called from the non-updating exit commands like `Q'."
779   :group 'gnus-various
780   :type 'hook)
781
782 (defcustom gnus-summary-update-hook
783   (list 'gnus-summary-highlight-line)
784   "*A hook called when a summary line is changed.
785 The hook will not be called if `gnus-visual' is nil.
786
787 The default function `gnus-summary-highlight-line' will
788 highlight the line according to the `gnus-summary-highlight'
789 variable."
790   :group 'gnus-summary-visual
791   :type 'hook)
792
793 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
794   "*A hook called when an article is selected for the first time.
795 The hook is intended to mark an article as read (or unread)
796 automatically when it is selected."
797   :group 'gnus-summary-choose
798   :type 'hook)
799
800 (defcustom gnus-group-no-more-groups-hook nil
801   "*A hook run when returning to group mode having no more (unread) groups."
802   :group 'gnus-group-select
803   :type 'hook)
804
805 (defcustom gnus-ps-print-hook nil
806   "*A hook run before ps-printing something from Gnus."
807   :group 'gnus-summary
808   :type 'hook)
809
810 (defcustom gnus-summary-display-arrow
811   (and (fboundp 'display-graphic-p)
812        (display-graphic-p))
813   "*If non-nil, display an arrow highlighting the current article."
814   :version "21.1"
815   :group 'gnus-summary
816   :type 'boolean)
817
818 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
819   "Face used for highlighting the current article in the summary buffer."
820   :group 'gnus-summary-visual
821   :type 'face)
822
823 (defcustom gnus-summary-highlight
824   '(((= mark gnus-canceled-mark)
825      . gnus-summary-cancelled-face)
826     ((and (> score default-high)
827           (or (= mark gnus-dormant-mark)
828               (= mark gnus-ticked-mark)))
829      . gnus-summary-high-ticked-face)
830     ((and (< score default-low)
831           (or (= mark gnus-dormant-mark)
832               (= mark gnus-ticked-mark)))
833      . gnus-summary-low-ticked-face)
834     ((or (= mark gnus-dormant-mark)
835          (= mark gnus-ticked-mark))
836      . gnus-summary-normal-ticked-face)
837     ((and (> score default-high) (= mark gnus-ancient-mark))
838      . gnus-summary-high-ancient-face)
839     ((and (< score default-low) (= mark gnus-ancient-mark))
840      . gnus-summary-low-ancient-face)
841     ((= mark gnus-ancient-mark)
842      . gnus-summary-normal-ancient-face)
843     ((and (> score default-high) (= mark gnus-unread-mark))
844      . gnus-summary-high-unread-face)
845     ((and (< score default-low) (= mark gnus-unread-mark))
846      . gnus-summary-low-unread-face)
847     ((= mark gnus-unread-mark)
848      . gnus-summary-normal-unread-face)
849     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
850                                                   gnus-undownloaded-mark)))
851      . gnus-summary-high-unread-face)
852     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
853                                                  gnus-undownloaded-mark)))
854      . gnus-summary-low-unread-face)
855     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
856           (memq article gnus-newsgroup-unreads))
857      . gnus-summary-normal-unread-face)
858     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
859      . gnus-summary-normal-read-face)
860     ((> score default-high)
861      . gnus-summary-high-read-face)
862     ((< score default-low)
863      . gnus-summary-low-read-face)
864     (t
865      . gnus-summary-normal-read-face))
866   "*Controls the highlighting of summary buffer lines.
867
868 A list of (FORM . FACE) pairs.  When deciding how a a particular
869 summary line should be displayed, each form is evaluated.  The content
870 of the face field after the first true form is used.  You can change
871 how those summary lines are displayed, by editing the face field.
872
873 You can use the following variables in the FORM field.
874
875 score:        The article's score
876 default:      The default article score.
877 default-high: The default score for high scored articles.
878 default-low:  The default score for low scored articles.
879 below:        The score below which articles are automatically marked as read.
880 mark:         The articles mark."
881   :group 'gnus-summary-visual
882   :type '(repeat (cons (sexp :tag "Form" nil)
883                        face)))
884
885 (defcustom gnus-alter-header-function nil
886   "Function called to allow alteration of article header structures.
887 The function is called with one parameter, the article header vector,
888 which it may alter in any way.")
889
890 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
891   "Variable that says which function should be used to decode a string with encoded words.")
892
893 (defcustom gnus-extra-headers nil
894   "*Extra headers to parse."
895   :version "21.1"
896   :group 'gnus-summary
897   :type '(repeat symbol))
898
899 (defcustom gnus-ignored-from-addresses
900   (and user-mail-address (regexp-quote user-mail-address))
901   "*Regexp of From headers that may be suppressed in favor of To headers."
902   :version "21.1"
903   :group 'gnus-summary
904   :type 'regexp)
905
906 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
907   "List of charsets that should be ignored.
908 When these charsets are used in the \"charset\" parameter, the
909 default charset will be used instead."
910   :version "21.1"
911   :type '(repeat symbol)
912   :group 'gnus-charset)
913
914 (gnus-define-group-parameter
915  ignored-charsets
916  :type list
917  :function-document
918  "Return the ignored charsets of GROUP."
919  :variable gnus-group-ignored-charsets-alist
920  :variable-default
921  '(("alt\\.chinese\\.text" iso-8859-1))
922  :variable-document
923  "Alist of regexps (to match group names) and charsets that should be ignored.
924 When these charsets are used in the \"charset\" parameter, the
925 default charset will be used instead."
926  :variable-group gnus-charset
927  :variable-type '(repeat (cons (regexp :tag "Group")
928                                (repeat symbol)))
929  :parameter-type '(choice :tag "Ignored charsets"
930                           :value nil
931                           (repeat (symbol)))
932  :parameter-document       "\
933 List of charsets that should be ignored.
934
935 When these charsets are used in the \"charset\" parameter, the
936 default charset will be used instead.")
937
938 (defcustom gnus-group-highlight-words-alist nil
939   "Alist of group regexps and highlight regexps.
940 This variable uses the same syntax as `gnus-emphasis-alist'."
941   :version "21.1"
942   :type '(repeat (cons (regexp :tag "Group")
943                        (repeat (list (regexp :tag "Highlight regexp")
944                                      (number :tag "Group for entire word" 0)
945                                      (number :tag "Group for displayed part" 0)
946                                      (symbol :tag "Face"
947                                              gnus-emphasis-highlight-words)))))
948   :group 'gnus-summary-visual)
949
950 (defcustom gnus-summary-show-article-charset-alist
951   nil
952   "Alist of number and charset.
953 The article will be shown with the charset corresponding to the
954 numbered argument.
955 For example: ((1 . cn-gb-2312) (2 . big5))."
956   :version "21.1"
957   :type '(repeat (cons (number :tag "Argument" 1)
958                        (symbol :tag "Charset")))
959   :group 'gnus-charset)
960
961 (defcustom gnus-preserve-marks t
962   "Whether marks are preserved when moving, copying and respooling messages."
963   :version "21.1"
964   :type 'boolean
965   :group 'gnus-summary-marks)
966
967 (defcustom gnus-alter-articles-to-read-function nil
968   "Function to be called to alter the list of articles to be selected."
969   :type '(choice (const nil) function)
970   :group 'gnus-summary)
971
972 (defcustom gnus-orphan-score nil
973   "*All orphans get this score added.  Set in the score file."
974   :group 'gnus-score-default
975   :type '(choice (const nil)
976                  integer))
977
978 (defcustom gnus-summary-save-parts-default-mime "image/.*"
979   "*A regexp to match MIME parts when saving multiple parts of a message
980 with gnus-summary-save-parts (X m). This regexp will be used by default
981 when prompting the user for which type of files to save."
982   :group 'gnus-summary
983   :type 'regexp)
984
985
986 (defcustom gnus-summary-save-parts-default-mime "image/.*"
987   "*A regexp to match MIME parts when saving multiple parts of a message
988 with gnus-summary-save-parts (X m). This regexp will be used by default
989 when prompting the user for which type of files to save."
990   :group 'gnus-summary
991   :type 'regexp)
992
993 (defcustom gnus-read-all-available-headers nil
994   "Whether Gnus should parse all headers made available to it.
995 This is mostly relevant for slow backends where the user may
996 wish to widen the summary buffer to include all headers
997 that were fetched.  Say, for nnultimate groups."
998   :group 'gnus-summary
999   :type '(choice boolean regexp))
1000
1001 ;;; Internal variables
1002
1003 (defvar gnus-summary-display-cache nil)
1004 (defvar gnus-article-mime-handles nil)
1005 (defvar gnus-article-decoded-p nil)
1006 (defvar gnus-article-charset nil)
1007 (defvar gnus-article-ignored-charsets nil)
1008 (defvar gnus-scores-exclude-files nil)
1009 (defvar gnus-page-broken nil)
1010 (defvar gnus-inhibit-mime-unbuttonizing nil)
1011
1012 (defvar gnus-original-article nil)
1013 (defvar gnus-article-internal-prepare-hook nil)
1014 (defvar gnus-newsgroup-process-stack nil)
1015
1016 (defvar gnus-thread-indent-array nil)
1017 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1018 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1019   "Function called to sort the articles within a thread after it has been gathered together.")
1020
1021 (defvar gnus-summary-save-parts-type-history nil)
1022 (defvar gnus-summary-save-parts-last-directory nil)
1023
1024 (defvar gnus-summary-save-parts-type-history nil)
1025 (defvar gnus-summary-save-parts-last-directory nil)
1026
1027 ;; Avoid highlighting in kill files.
1028 (defvar gnus-summary-inhibit-highlight nil)
1029 (defvar gnus-newsgroup-selected-overlay nil)
1030 (defvar gnus-inhibit-limiting nil)
1031 (defvar gnus-newsgroup-adaptive-score-file nil)
1032 (defvar gnus-current-score-file nil)
1033 (defvar gnus-current-move-group nil)
1034 (defvar gnus-current-copy-group nil)
1035 (defvar gnus-current-crosspost-group nil)
1036 (defvar gnus-newsgroup-display nil)
1037
1038 (defvar gnus-newsgroup-dependencies nil)
1039 (defvar gnus-newsgroup-adaptive nil)
1040 (defvar gnus-summary-display-article-function nil)
1041 (defvar gnus-summary-highlight-line-function nil
1042   "Function called after highlighting a summary line.")
1043
1044 (defvar gnus-summary-line-format-alist
1045   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1046     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1047     (?s gnus-tmp-subject-or-nil ?s)
1048     (?n gnus-tmp-name ?s)
1049     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1050         ?s)
1051     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1052             gnus-tmp-from) ?s)
1053     (?F gnus-tmp-from ?s)
1054     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1055     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1056     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1057     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1058     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1059     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1060     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1061     (?L gnus-tmp-lines ?s)
1062     (?I gnus-tmp-indentation ?s)
1063     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1064     (?R gnus-tmp-replied ?c)
1065     (?\[ gnus-tmp-opening-bracket ?c)
1066     (?\] gnus-tmp-closing-bracket ?c)
1067     (?\> (make-string gnus-tmp-level ? ) ?s)
1068     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1069     (?i gnus-tmp-score ?d)
1070     (?z gnus-tmp-score-char ?c)
1071     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1072     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1073     (?U gnus-tmp-unread ?c)
1074     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1075         ?s)
1076     (?t (gnus-summary-number-of-articles-in-thread
1077          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1078         ?d)
1079     (?e (gnus-summary-number-of-articles-in-thread
1080          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1081         ?c)
1082     (?u gnus-tmp-user-defined ?s)
1083     (?P (gnus-pick-line-number) ?d)
1084     (?B gnus-tmp-thread-tree-header-string ?s)
1085     (user-date (gnus-user-date 
1086                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1087   "An alist of format specifications that can appear in summary lines.
1088 These are paired with what variables they correspond with, along with
1089 the type of the variable (string, integer, character, etc).")
1090
1091 (defvar gnus-summary-dummy-line-format-alist
1092   `((?S gnus-tmp-subject ?s)
1093     (?N gnus-tmp-number ?d)
1094     (?u gnus-tmp-user-defined ?s)))
1095
1096 (defvar gnus-summary-mode-line-format-alist
1097   `((?G gnus-tmp-group-name ?s)
1098     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1099     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1100     (?A gnus-tmp-article-number ?d)
1101     (?Z gnus-tmp-unread-and-unselected ?s)
1102     (?V gnus-version ?s)
1103     (?U gnus-tmp-unread-and-unticked ?d)
1104     (?S gnus-tmp-subject ?s)
1105     (?e gnus-tmp-unselected ?d)
1106     (?u gnus-tmp-user-defined ?s)
1107     (?d (length gnus-newsgroup-dormant) ?d)
1108     (?t (length gnus-newsgroup-marked) ?d)
1109     (?r (length gnus-newsgroup-reads) ?d)
1110     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1111     (?E gnus-newsgroup-expunged-tally ?d)
1112     (?s (gnus-current-score-file-nondirectory) ?s)))
1113
1114 (defvar gnus-last-search-regexp nil
1115   "Default regexp for article search command.")
1116
1117 (defvar gnus-last-shell-command nil
1118   "Default shell command on article.")
1119
1120 (defvar gnus-newsgroup-begin nil)
1121 (defvar gnus-newsgroup-end nil)
1122 (defvar gnus-newsgroup-last-rmail nil)
1123 (defvar gnus-newsgroup-last-mail nil)
1124 (defvar gnus-newsgroup-last-folder nil)
1125 (defvar gnus-newsgroup-last-file nil)
1126 (defvar gnus-newsgroup-auto-expire nil)
1127 (defvar gnus-newsgroup-active nil)
1128
1129 (defvar gnus-newsgroup-data nil)
1130 (defvar gnus-newsgroup-data-reverse nil)
1131 (defvar gnus-newsgroup-limit nil)
1132 (defvar gnus-newsgroup-limits nil)
1133
1134 (defvar gnus-newsgroup-unreads nil
1135   "List of unread articles in the current newsgroup.")
1136
1137 (defvar gnus-newsgroup-unselected nil
1138   "List of unselected unread articles in the current newsgroup.")
1139
1140 (defvar gnus-newsgroup-reads nil
1141   "Alist of read articles and article marks in the current newsgroup.")
1142
1143 (defvar gnus-newsgroup-expunged-tally nil)
1144
1145 (defvar gnus-newsgroup-marked nil
1146   "List of ticked articles in the current newsgroup (a subset of unread art).")
1147
1148 (defvar gnus-newsgroup-killed nil
1149   "List of ranges of articles that have been through the scoring process.")
1150
1151 (defvar gnus-newsgroup-cached nil
1152   "List of articles that come from the article cache.")
1153
1154 (defvar gnus-newsgroup-saved nil
1155   "List of articles that have been saved.")
1156
1157 (defvar gnus-newsgroup-kill-headers nil)
1158
1159 (defvar gnus-newsgroup-replied nil
1160   "List of articles that have been replied to in the current newsgroup.")
1161
1162 (defvar gnus-newsgroup-forwarded nil
1163   "List of articles that have been forwarded in the current newsgroup.")
1164
1165 (defvar gnus-newsgroup-recent nil
1166   "List of articles that have are recent in the current newsgroup.")
1167
1168 (defvar gnus-newsgroup-expirable nil
1169   "List of articles in the current newsgroup that can be expired.")
1170
1171 (defvar gnus-newsgroup-processable nil
1172   "List of articles in the current newsgroup that can be processed.")
1173
1174 (defvar gnus-newsgroup-downloadable nil
1175   "List of articles in the current newsgroup that can be processed.")
1176
1177 (defvar gnus-newsgroup-undownloaded nil
1178   "List of articles in the current newsgroup that haven't been downloaded..")
1179
1180 (defvar gnus-newsgroup-unsendable nil
1181   "List of articles in the current newsgroup that won't be sent.")
1182
1183 (defvar gnus-newsgroup-bookmarks nil
1184   "List of articles in the current newsgroup that have bookmarks.")
1185
1186 (defvar gnus-newsgroup-dormant nil
1187   "List of dormant articles in the current newsgroup.")
1188
1189 (defvar gnus-newsgroup-unseen nil
1190   "List of unseen articles in the current newsgroup.")
1191
1192 (defvar gnus-newsgroup-seen nil
1193   "Range of seen articles in the current newsgroup.")
1194
1195 (defvar gnus-newsgroup-articles nil
1196   "List of articles in the current newsgroup.")
1197
1198 (defvar gnus-newsgroup-scored nil
1199   "List of scored articles in the current newsgroup.")
1200
1201 (defvar gnus-newsgroup-headers nil
1202   "List of article headers in the current newsgroup.")
1203
1204 (defvar gnus-newsgroup-threads nil)
1205
1206 (defvar gnus-newsgroup-prepared nil
1207   "Whether the current group has been prepared properly.")
1208
1209 (defvar gnus-newsgroup-ancient nil
1210   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1211
1212 (defvar gnus-newsgroup-sparse nil)
1213
1214 (defvar gnus-current-article nil)
1215 (defvar gnus-article-current nil)
1216 (defvar gnus-current-headers nil)
1217 (defvar gnus-have-all-headers nil)
1218 (defvar gnus-last-article nil)
1219 (defvar gnus-newsgroup-history nil)
1220 (defvar gnus-newsgroup-charset nil)
1221 (defvar gnus-newsgroup-ephemeral-charset nil)
1222 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1223
1224 (defvar gnus-article-before-search nil)
1225
1226 (defconst gnus-summary-local-variables
1227   '(gnus-newsgroup-name
1228     gnus-newsgroup-begin gnus-newsgroup-end
1229     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1230     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1231     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1232     gnus-newsgroup-unselected gnus-newsgroup-marked
1233     gnus-newsgroup-reads gnus-newsgroup-saved
1234     gnus-newsgroup-replied gnus-newsgroup-forwarded
1235     gnus-newsgroup-recent
1236     gnus-newsgroup-expirable
1237     gnus-newsgroup-processable gnus-newsgroup-killed
1238     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1239     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1240     gnus-newsgroup-seen gnus-newsgroup-articles
1241     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1242     gnus-newsgroup-headers gnus-newsgroup-threads
1243     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1244     gnus-current-article gnus-current-headers gnus-have-all-headers
1245     gnus-last-article gnus-article-internal-prepare-hook
1246     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1247     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1248     gnus-thread-expunge-below
1249     gnus-score-alist gnus-current-score-file
1250     (gnus-summary-expunge-below . global)
1251     (gnus-summary-mark-below . global)
1252     (gnus-orphan-score . global)
1253     gnus-newsgroup-active gnus-scores-exclude-files
1254     gnus-newsgroup-history gnus-newsgroup-ancient
1255     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1256     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1257     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1258     (gnus-newsgroup-expunged-tally . 0)
1259     gnus-cache-removable-articles gnus-newsgroup-cached
1260     gnus-newsgroup-data gnus-newsgroup-data-reverse
1261     gnus-newsgroup-limit gnus-newsgroup-limits
1262     gnus-newsgroup-charset gnus-newsgroup-display)
1263   "Variables that are buffer-local to the summary buffers.")
1264
1265 (defvar gnus-newsgroup-variables nil
1266   "Variables that have separate values in the newsgroups.")
1267
1268 ;; Byte-compiler warning.
1269 (eval-when-compile (defvar gnus-article-mode-map))
1270
1271 ;; MIME stuff.
1272
1273 (defvar gnus-decode-encoded-word-methods
1274   '(mail-decode-encoded-word-string)
1275   "List of methods used to decode encoded words.
1276
1277 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item is
1278 FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1279 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1280 whose names match REGEXP.
1281
1282 For example:
1283 ((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1284  mail-decode-encoded-word-string
1285  (\"chinese\" . rfc1843-decode-string))")
1286
1287 (defvar gnus-decode-encoded-word-methods-cache nil)
1288
1289 (defun gnus-multi-decode-encoded-word-string (string)
1290   "Apply the functions from `gnus-encoded-word-methods' that match."
1291   (unless (and gnus-decode-encoded-word-methods-cache
1292                (eq gnus-newsgroup-name
1293                    (car gnus-decode-encoded-word-methods-cache)))
1294     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1295     (mapcar (lambda (x)
1296               (if (symbolp x)
1297                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1298                 (if (and gnus-newsgroup-name
1299                          (string-match (car x) gnus-newsgroup-name))
1300                     (nconc gnus-decode-encoded-word-methods-cache
1301                            (list (cdr x))))))
1302             gnus-decode-encoded-word-methods))
1303   (let ((xlist gnus-decode-encoded-word-methods-cache))
1304     (pop xlist)
1305     (while xlist
1306       (setq string (funcall (pop xlist) string))))
1307   string)
1308
1309 ;; Subject simplification.
1310
1311 (defun gnus-simplify-whitespace (str)
1312   "Remove excessive whitespace from STR."
1313   (let ((mystr str))
1314     ;; Multiple spaces.
1315     (while (string-match "[ \t][ \t]+" mystr)
1316       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1317                           " "
1318                           (substring mystr (match-end 0)))))
1319     ;; Leading spaces.
1320     (when (string-match "^[ \t]+" mystr)
1321       (setq mystr (substring mystr (match-end 0))))
1322     ;; Trailing spaces.
1323     (when (string-match "[ \t]+$" mystr)
1324       (setq mystr (substring mystr 0 (match-beginning 0))))
1325     mystr))
1326
1327 (defsubst gnus-simplify-subject-re (subject)
1328   "Remove \"Re:\" from subject lines."
1329   (if (string-match message-subject-re-regexp subject)
1330       (substring subject (match-end 0))
1331     subject))
1332
1333 (defun gnus-simplify-subject (subject &optional re-only)
1334   "Remove `Re:' and words in parentheses.
1335 If RE-ONLY is non-nil, strip leading `Re:'s only."
1336   (let ((case-fold-search t))           ;Ignore case.
1337     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1338     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1339       (setq subject (substring subject (match-end 0))))
1340     ;; Remove uninteresting prefixes.
1341     (when (and (not re-only)
1342                gnus-simplify-ignored-prefixes
1343                (string-match gnus-simplify-ignored-prefixes subject))
1344       (setq subject (substring subject (match-end 0))))
1345     ;; Remove words in parentheses from end.
1346     (unless re-only
1347       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1348         (setq subject (substring subject 0 (match-beginning 0)))))
1349     ;; Return subject string.
1350     subject))
1351
1352 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1353 ;; all whitespace.
1354 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1355   (goto-char (point-min))
1356   (while (re-search-forward regexp nil t)
1357     (replace-match (or newtext ""))))
1358
1359 (defun gnus-simplify-buffer-fuzzy ()
1360   "Simplify string in the buffer fuzzily.
1361 The string in the accessible portion of the current buffer is simplified.
1362 It is assumed to be a single-line subject.
1363 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1364 matter is removed.  Additional things can be deleted by setting
1365 `gnus-simplify-subject-fuzzy-regexp'."
1366   (let ((case-fold-search t)
1367         (modified-tick))
1368     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1369
1370     (while (not (eq modified-tick (buffer-modified-tick)))
1371       (setq modified-tick (buffer-modified-tick))
1372       (cond
1373        ((listp gnus-simplify-subject-fuzzy-regexp)
1374         (mapcar 'gnus-simplify-buffer-fuzzy-step
1375                 gnus-simplify-subject-fuzzy-regexp))
1376        (gnus-simplify-subject-fuzzy-regexp
1377         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1378       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1379       (gnus-simplify-buffer-fuzzy-step
1380        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1381       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1382
1383     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1384     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1385     (gnus-simplify-buffer-fuzzy-step " $")
1386     (gnus-simplify-buffer-fuzzy-step "^ +")))
1387
1388 (defun gnus-simplify-subject-fuzzy (subject)
1389   "Simplify a subject string fuzzily.
1390 See `gnus-simplify-buffer-fuzzy' for details."
1391   (save-excursion
1392     (gnus-set-work-buffer)
1393     (let ((case-fold-search t))
1394       ;; Remove uninteresting prefixes.
1395       (when (and gnus-simplify-ignored-prefixes
1396                  (string-match gnus-simplify-ignored-prefixes subject))
1397         (setq subject (substring subject (match-end 0))))
1398       (insert subject)
1399       (inline (gnus-simplify-buffer-fuzzy))
1400       (buffer-string))))
1401
1402 (defsubst gnus-simplify-subject-fully (subject)
1403   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1404   (cond
1405    (gnus-simplify-subject-functions
1406     (gnus-map-function gnus-simplify-subject-functions subject))
1407    ((null gnus-summary-gather-subject-limit)
1408     (gnus-simplify-subject-re subject))
1409    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1410     (gnus-simplify-subject-fuzzy subject))
1411    ((numberp gnus-summary-gather-subject-limit)
1412     (gnus-limit-string (gnus-simplify-subject-re subject)
1413                        gnus-summary-gather-subject-limit))
1414    (t
1415     subject)))
1416
1417 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1418   "Check whether two subjects are equal.
1419 If optional argument simple-first is t, first argument is already
1420 simplified."
1421   (cond
1422    ((null simple-first)
1423     (equal (gnus-simplify-subject-fully s1)
1424            (gnus-simplify-subject-fully s2)))
1425    (t
1426     (equal s1
1427            (gnus-simplify-subject-fully s2)))))
1428
1429 (defun gnus-summary-bubble-group ()
1430   "Increase the score of the current group.
1431 This is a handy function to add to `gnus-summary-exit-hook' to
1432 increase the score of each group you read."
1433   (gnus-group-add-score gnus-newsgroup-name))
1434
1435 \f
1436 ;;;
1437 ;;; Gnus summary mode
1438 ;;;
1439
1440 (put 'gnus-summary-mode 'mode-class 'special)
1441
1442 (defvar gnus-article-commands-menu)
1443
1444 (when t
1445   ;; Non-orthogonal keys
1446
1447   (gnus-define-keys gnus-summary-mode-map
1448     " " gnus-summary-next-page
1449     "\177" gnus-summary-prev-page
1450     [delete] gnus-summary-prev-page
1451     [backspace] gnus-summary-prev-page
1452     "\r" gnus-summary-scroll-up
1453     "\M-\r" gnus-summary-scroll-down
1454     "n" gnus-summary-next-unread-article
1455     "p" gnus-summary-prev-unread-article
1456     "N" gnus-summary-next-article
1457     "P" gnus-summary-prev-article
1458     "\M-\C-n" gnus-summary-next-same-subject
1459     "\M-\C-p" gnus-summary-prev-same-subject
1460     "\M-n" gnus-summary-next-unread-subject
1461     "\M-p" gnus-summary-prev-unread-subject
1462     "." gnus-summary-first-unread-article
1463     "," gnus-summary-best-unread-article
1464     "\M-s" gnus-summary-search-article-forward
1465     "\M-r" gnus-summary-search-article-backward
1466     "<" gnus-summary-beginning-of-article
1467     ">" gnus-summary-end-of-article
1468     "j" gnus-summary-goto-article
1469     "^" gnus-summary-refer-parent-article
1470     "\M-^" gnus-summary-refer-article
1471     "u" gnus-summary-tick-article-forward
1472     "!" gnus-summary-tick-article-forward
1473     "U" gnus-summary-tick-article-backward
1474     "d" gnus-summary-mark-as-read-forward
1475     "D" gnus-summary-mark-as-read-backward
1476     "E" gnus-summary-mark-as-expirable
1477     "\M-u" gnus-summary-clear-mark-forward
1478     "\M-U" gnus-summary-clear-mark-backward
1479     "k" gnus-summary-kill-same-subject-and-select
1480     "\C-k" gnus-summary-kill-same-subject
1481     "\M-\C-k" gnus-summary-kill-thread
1482     "\M-\C-l" gnus-summary-lower-thread
1483     "e" gnus-summary-edit-article
1484     "#" gnus-summary-mark-as-processable
1485     "\M-#" gnus-summary-unmark-as-processable
1486     "\M-\C-t" gnus-summary-toggle-threads
1487     "\M-\C-s" gnus-summary-show-thread
1488     "\M-\C-h" gnus-summary-hide-thread
1489     "\M-\C-f" gnus-summary-next-thread
1490     "\M-\C-b" gnus-summary-prev-thread
1491     [(meta down)] gnus-summary-next-thread
1492     [(meta up)] gnus-summary-prev-thread
1493     "\M-\C-u" gnus-summary-up-thread
1494     "\M-\C-d" gnus-summary-down-thread
1495     "&" gnus-summary-execute-command
1496     "c" gnus-summary-catchup-and-exit
1497     "\C-w" gnus-summary-mark-region-as-read
1498     "\C-t" gnus-summary-toggle-truncation
1499     "?" gnus-summary-mark-as-dormant
1500     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1501     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1502     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1503     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1504     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1505     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1506     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1507     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1508     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1509     "=" gnus-summary-expand-window
1510     "\C-x\C-s" gnus-summary-reselect-current-group
1511     "\M-g" gnus-summary-rescan-group
1512     "w" gnus-summary-stop-page-breaking
1513     "\C-c\C-r" gnus-summary-caesar-message
1514     "f" gnus-summary-followup
1515     "F" gnus-summary-followup-with-original
1516     "C" gnus-summary-cancel-article
1517     "r" gnus-summary-reply
1518     "R" gnus-summary-reply-with-original
1519     "\C-c\C-f" gnus-summary-mail-forward
1520     "o" gnus-summary-save-article
1521     "\C-o" gnus-summary-save-article-mail
1522     "|" gnus-summary-pipe-output
1523     "\M-k" gnus-summary-edit-local-kill
1524     "\M-K" gnus-summary-edit-global-kill
1525     ;; "V" gnus-version
1526     "\C-c\C-d" gnus-summary-describe-group
1527     "q" gnus-summary-exit
1528     "Q" gnus-summary-exit-no-update
1529     "\C-c\C-i" gnus-info-find-node
1530     gnus-mouse-2 gnus-mouse-pick-article
1531     "m" gnus-summary-mail-other-window
1532     "a" gnus-summary-post-news
1533     "x" gnus-summary-limit-to-unread
1534     "s" gnus-summary-isearch-article
1535     "t" gnus-summary-toggle-header
1536     "g" gnus-summary-show-article
1537     "l" gnus-summary-goto-last-article
1538     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1539     "\C-d" gnus-summary-enter-digest-group
1540     "\M-\C-d" gnus-summary-read-document
1541     "\M-\C-e" gnus-summary-edit-parameters
1542     "\M-\C-a" gnus-summary-customize-parameters
1543     "\C-c\C-b" gnus-bug
1544     "*" gnus-cache-enter-article
1545     "\M-*" gnus-cache-remove-article
1546     "\M-&" gnus-summary-universal-argument
1547     "\C-l" gnus-recenter
1548     "I" gnus-summary-increase-score
1549     "L" gnus-summary-lower-score
1550     "\M-i" gnus-symbolic-argument
1551     "h" gnus-summary-select-article-buffer
1552
1553     "b" gnus-article-view-part
1554     "\M-t" gnus-summary-toggle-display-buttonized
1555
1556     "V" gnus-summary-score-map
1557     "X" gnus-uu-extract-map
1558     "S" gnus-summary-send-map)
1559
1560   ;; Sort of orthogonal keymap
1561   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1562     "t" gnus-summary-tick-article-forward
1563     "!" gnus-summary-tick-article-forward
1564     "d" gnus-summary-mark-as-read-forward
1565     "r" gnus-summary-mark-as-read-forward
1566     "c" gnus-summary-clear-mark-forward
1567     " " gnus-summary-clear-mark-forward
1568     "e" gnus-summary-mark-as-expirable
1569     "x" gnus-summary-mark-as-expirable
1570     "?" gnus-summary-mark-as-dormant
1571     "b" gnus-summary-set-bookmark
1572     "B" gnus-summary-remove-bookmark
1573     "#" gnus-summary-mark-as-processable
1574     "\M-#" gnus-summary-unmark-as-processable
1575     "S" gnus-summary-limit-include-expunged
1576     "C" gnus-summary-catchup
1577     "H" gnus-summary-catchup-to-here
1578     "h" gnus-summary-catchup-from-here
1579     "\C-c" gnus-summary-catchup-all
1580     "k" gnus-summary-kill-same-subject-and-select
1581     "K" gnus-summary-kill-same-subject
1582     "P" gnus-uu-mark-map)
1583
1584   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1585     "c" gnus-summary-clear-above
1586     "u" gnus-summary-tick-above
1587     "m" gnus-summary-mark-above
1588     "k" gnus-summary-kill-below)
1589
1590   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1591     "/" gnus-summary-limit-to-subject
1592     "n" gnus-summary-limit-to-articles
1593     "w" gnus-summary-pop-limit
1594     "s" gnus-summary-limit-to-subject
1595     "a" gnus-summary-limit-to-author
1596     "u" gnus-summary-limit-to-unread
1597     "m" gnus-summary-limit-to-marks
1598     "M" gnus-summary-limit-exclude-marks
1599     "v" gnus-summary-limit-to-score
1600     "*" gnus-summary-limit-include-cached
1601     "D" gnus-summary-limit-include-dormant
1602     "T" gnus-summary-limit-include-thread
1603     "d" gnus-summary-limit-exclude-dormant
1604     "t" gnus-summary-limit-to-age
1605     "x" gnus-summary-limit-to-extra
1606     "p" gnus-summary-limit-to-display-predicate
1607     "E" gnus-summary-limit-include-expunged
1608     "c" gnus-summary-limit-exclude-childless-dormant
1609     "C" gnus-summary-limit-mark-excluded-as-read
1610     "o" gnus-summary-insert-old-articles
1611     "N" gnus-summary-insert-new-articles)
1612
1613   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1614     "n" gnus-summary-next-unread-article
1615     "p" gnus-summary-prev-unread-article
1616     "N" gnus-summary-next-article
1617     "P" gnus-summary-prev-article
1618     "\C-n" gnus-summary-next-same-subject
1619     "\C-p" gnus-summary-prev-same-subject
1620     "\M-n" gnus-summary-next-unread-subject
1621     "\M-p" gnus-summary-prev-unread-subject
1622     "f" gnus-summary-first-unread-article
1623     "b" gnus-summary-best-unread-article
1624     "j" gnus-summary-goto-article
1625     "g" gnus-summary-goto-subject
1626     "l" gnus-summary-goto-last-article
1627     "o" gnus-summary-pop-article)
1628
1629   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1630     "k" gnus-summary-kill-thread
1631     "l" gnus-summary-lower-thread
1632     "i" gnus-summary-raise-thread
1633     "T" gnus-summary-toggle-threads
1634     "t" gnus-summary-rethread-current
1635     "^" gnus-summary-reparent-thread
1636     "s" gnus-summary-show-thread
1637     "S" gnus-summary-show-all-threads
1638     "h" gnus-summary-hide-thread
1639     "H" gnus-summary-hide-all-threads
1640     "n" gnus-summary-next-thread
1641     "p" gnus-summary-prev-thread
1642     "u" gnus-summary-up-thread
1643     "o" gnus-summary-top-thread
1644     "d" gnus-summary-down-thread
1645     "#" gnus-uu-mark-thread
1646     "\M-#" gnus-uu-unmark-thread)
1647
1648   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1649     "g" gnus-summary-prepare
1650     "c" gnus-summary-insert-cached-articles)
1651
1652   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1653     "c" gnus-summary-catchup-and-exit
1654     "C" gnus-summary-catchup-all-and-exit
1655     "E" gnus-summary-exit-no-update
1656     "Q" gnus-summary-exit
1657     "Z" gnus-summary-exit
1658     "n" gnus-summary-catchup-and-goto-next-group
1659     "R" gnus-summary-reselect-current-group
1660     "G" gnus-summary-rescan-group
1661     "N" gnus-summary-next-group
1662     "s" gnus-summary-save-newsrc
1663     "P" gnus-summary-prev-group)
1664
1665   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1666     " " gnus-summary-next-page
1667     "n" gnus-summary-next-page
1668     "\177" gnus-summary-prev-page
1669     [delete] gnus-summary-prev-page
1670     "p" gnus-summary-prev-page
1671     "\r" gnus-summary-scroll-up
1672     "\M-\r" gnus-summary-scroll-down
1673     "<" gnus-summary-beginning-of-article
1674     ">" gnus-summary-end-of-article
1675     "b" gnus-summary-beginning-of-article
1676     "e" gnus-summary-end-of-article
1677     "^" gnus-summary-refer-parent-article
1678     "r" gnus-summary-refer-parent-article
1679     "D" gnus-summary-enter-digest-group
1680     "R" gnus-summary-refer-references
1681     "T" gnus-summary-refer-thread
1682     "g" gnus-summary-show-article
1683     "s" gnus-summary-isearch-article
1684     "P" gnus-summary-print-article
1685     "M" gnus-mailing-list-insinuate
1686     "t" gnus-article-babel)
1687
1688   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1689     "b" gnus-article-add-buttons
1690     "B" gnus-article-add-buttons-to-head
1691     "o" gnus-article-treat-overstrike
1692     "e" gnus-article-emphasize
1693     "w" gnus-article-fill-cited-article
1694     "Q" gnus-article-fill-long-lines
1695     "C" gnus-article-capitalize-sentences
1696     "c" gnus-article-remove-cr
1697     "q" gnus-article-de-quoted-unreadable
1698     "6" gnus-article-de-base64-unreadable
1699     "Z" gnus-article-decode-HZ
1700     "h" gnus-article-wash-html
1701     "s" gnus-summary-force-verify-and-decrypt
1702     "f" gnus-article-display-x-face
1703     "l" gnus-summary-stop-page-breaking
1704     "r" gnus-summary-caesar-message
1705     "t" gnus-summary-toggle-header
1706     "g" gnus-summary-toggle-smiley
1707     "v" gnus-summary-verbose-headers
1708     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1709     "p" gnus-article-verify-x-pgp-sig
1710     "d" gnus-article-treat-dumbquotes)
1711
1712   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1713     "a" gnus-article-hide
1714     "h" gnus-article-hide-headers
1715     "b" gnus-article-hide-boring-headers
1716     "s" gnus-article-hide-signature
1717     "c" gnus-article-hide-citation
1718     "C" gnus-article-hide-citation-in-followups
1719     "l" gnus-article-hide-list-identifiers
1720     "p" gnus-article-hide-pgp
1721     "B" gnus-article-strip-banner
1722     "P" gnus-article-hide-pem
1723     "\C-c" gnus-article-hide-citation-maybe)
1724
1725   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1726     "a" gnus-article-highlight
1727     "h" gnus-article-highlight-headers
1728     "c" gnus-article-highlight-citation
1729     "s" gnus-article-highlight-signature)
1730
1731   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1732     "w" gnus-article-decode-mime-words
1733     "c" gnus-article-decode-charset
1734     "v" gnus-mime-view-all-parts
1735     "b" gnus-article-view-part)
1736
1737   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1738     "z" gnus-article-date-ut
1739     "u" gnus-article-date-ut
1740     "l" gnus-article-date-local
1741     "p" gnus-article-date-english
1742     "e" gnus-article-date-lapsed
1743     "o" gnus-article-date-original
1744     "i" gnus-article-date-iso8601
1745     "s" gnus-article-date-user)
1746
1747   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1748     "t" gnus-article-remove-trailing-blank-lines
1749     "l" gnus-article-strip-leading-blank-lines
1750     "m" gnus-article-strip-multiple-blank-lines
1751     "a" gnus-article-strip-blank-lines
1752     "A" gnus-article-strip-all-blank-lines
1753     "s" gnus-article-strip-leading-space
1754     "e" gnus-article-strip-trailing-space
1755     "w" gnus-article-remove-leading-whitespace)
1756
1757   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1758     "v" gnus-version
1759     "f" gnus-summary-fetch-faq
1760     "d" gnus-summary-describe-group
1761     "h" gnus-summary-describe-briefly
1762     "i" gnus-info-find-node)
1763
1764   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1765     "e" gnus-summary-expire-articles
1766     "\M-\C-e" gnus-summary-expire-articles-now
1767     "\177" gnus-summary-delete-article
1768     [delete] gnus-summary-delete-article
1769     [backspace] gnus-summary-delete-article
1770     "m" gnus-summary-move-article
1771     "r" gnus-summary-respool-article
1772     "w" gnus-summary-edit-article
1773     "c" gnus-summary-copy-article
1774     "B" gnus-summary-crosspost-article
1775     "q" gnus-summary-respool-query
1776     "t" gnus-summary-respool-trace
1777     "i" gnus-summary-import-article
1778     "I" gnus-summary-create-article
1779     "p" gnus-summary-article-posted-p)
1780
1781   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1782     "o" gnus-summary-save-article
1783     "m" gnus-summary-save-article-mail
1784     "F" gnus-summary-write-article-file
1785     "r" gnus-summary-save-article-rmail
1786     "f" gnus-summary-save-article-file
1787     "b" gnus-summary-save-article-body-file
1788     "h" gnus-summary-save-article-folder
1789     "v" gnus-summary-save-article-vm
1790     "p" gnus-summary-pipe-output
1791     "s" gnus-soup-add-article)
1792
1793   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1794     "b" gnus-summary-display-buttonized
1795     "m" gnus-summary-repair-multipart
1796     "v" gnus-article-view-part
1797     "o" gnus-article-save-part
1798     "c" gnus-article-copy-part
1799     "C" gnus-article-view-part-as-charset
1800     "e" gnus-article-externalize-part
1801     "E" gnus-article-encrypt-body
1802     "i" gnus-article-inline-part
1803     "|" gnus-article-pipe-part))
1804
1805 (defvar gnus-article-post-menu nil)
1806
1807 (defun gnus-summary-make-menu-bar ()
1808   (gnus-turn-off-edit-menu 'summary)
1809
1810   (unless (boundp 'gnus-summary-misc-menu)
1811
1812     (easy-menu-define
1813       gnus-summary-kill-menu gnus-summary-mode-map ""
1814       (cons
1815        "Score"
1816        (nconc
1817         (list
1818          ["Customize" gnus-score-customize t])
1819         (gnus-make-score-map 'increase)
1820         (gnus-make-score-map 'lower)
1821         '(("Mark"
1822            ["Kill below" gnus-summary-kill-below t]
1823            ["Mark above" gnus-summary-mark-above t]
1824            ["Tick above" gnus-summary-tick-above t]
1825            ["Clear above" gnus-summary-clear-above t])
1826           ["Current score" gnus-summary-current-score t]
1827           ["Set score" gnus-summary-set-score t]
1828           ["Switch current score file..." gnus-score-change-score-file t]
1829           ["Set mark below..." gnus-score-set-mark-below t]
1830           ["Set expunge below..." gnus-score-set-expunge-below t]
1831           ["Edit current score file" gnus-score-edit-current-scores t]
1832           ["Edit score file" gnus-score-edit-file t]
1833           ["Trace score" gnus-score-find-trace t]
1834           ["Find words" gnus-score-find-favourite-words t]
1835           ["Rescore buffer" gnus-summary-rescore t]
1836           ["Increase score..." gnus-summary-increase-score t]
1837           ["Lower score..." gnus-summary-lower-score t]))))
1838
1839 ;; Define both the Article menu in the summary buffer and the equivalent
1840     ;; Commands menu in the article buffer here for consistency.
1841     (let ((innards
1842            `(("Hide"
1843               ["All" gnus-article-hide t]
1844               ["Headers" gnus-article-hide-headers t]
1845               ["Signature" gnus-article-hide-signature t]
1846               ["Citation" gnus-article-hide-citation t]
1847               ["List identifiers" gnus-article-hide-list-identifiers t]
1848               ["PGP" gnus-article-hide-pgp t]
1849               ["Banner" gnus-article-strip-banner t]
1850               ["Boring headers" gnus-article-hide-boring-headers t])
1851              ("Highlight"
1852               ["All" gnus-article-highlight t]
1853               ["Headers" gnus-article-highlight-headers t]
1854               ["Signature" gnus-article-highlight-signature t]
1855               ["Citation" gnus-article-highlight-citation t])
1856              ("MIME"
1857               ["Words" gnus-article-decode-mime-words t]
1858               ["Charset" gnus-article-decode-charset t]
1859               ["QP" gnus-article-de-quoted-unreadable t]
1860               ["Base64" gnus-article-de-base64-unreadable t]
1861               ["View all" gnus-mime-view-all-parts t]
1862               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
1863               ["Encrypt body" gnus-article-encrypt-body t])
1864              ("Date"
1865               ["Local" gnus-article-date-local t]
1866               ["ISO8601" gnus-article-date-iso8601 t]
1867               ["UT" gnus-article-date-ut t]
1868               ["Original" gnus-article-date-original t]
1869               ["Lapsed" gnus-article-date-lapsed t]
1870               ["User-defined" gnus-article-date-user t])
1871              ("Washing"
1872               ("Remove Blanks"
1873                ["Leading" gnus-article-strip-leading-blank-lines t]
1874                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1875                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1876                ["All of the above" gnus-article-strip-blank-lines t]
1877                ["All" gnus-article-strip-all-blank-lines t]
1878                ["Leading space" gnus-article-strip-leading-space t]
1879                ["Trailing space" gnus-article-strip-trailing-space t]
1880                ["Leading space in headers"
1881                 gnus-article-remove-leading-whitespace t])
1882               ["Overstrike" gnus-article-treat-overstrike t]
1883               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1884               ["Emphasis" gnus-article-emphasize t]
1885               ["Word wrap" gnus-article-fill-cited-article t]
1886               ["Fill long lines" gnus-article-fill-long-lines t]
1887               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1888               ["CR" gnus-article-remove-cr t]
1889               ["Show X-Face" gnus-article-display-x-face t]
1890               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
1891               ["Base64" gnus-article-de-base64-unreadable t]
1892               ["Rot 13" gnus-summary-caesar-message
1893                ,@(if (featurep 'xemacs) '(t)
1894                    '(:help "\"Caesar rotate\" article by 13"))]
1895               ["Unix pipe" gnus-summary-pipe-message t]
1896               ["Add buttons" gnus-article-add-buttons t]
1897               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1898               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1899               ["Verbose header" gnus-summary-verbose-headers t]
1900               ["Toggle header" gnus-summary-toggle-header t]
1901               ["Toggle smiley" gnus-summary-toggle-smiley t]
1902               ["Html" gnus-article-wash-html t]
1903               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1904               ["HZ" gnus-article-decode-HZ t])
1905              ("Output"
1906               ["Save in default format" gnus-summary-save-article
1907                ,@(if (featurep 'xemacs) '(t)
1908                    '(:help "Save article using default method"))]
1909               ["Save in file" gnus-summary-save-article-file
1910                ,@(if (featurep 'xemacs) '(t)
1911                    '(:help "Save article in file"))]
1912               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1913               ["Save in MH folder" gnus-summary-save-article-folder t]
1914               ["Save in VM folder" gnus-summary-save-article-vm t]
1915               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1916               ["Save body in file" gnus-summary-save-article-body-file t]
1917               ["Pipe through a filter" gnus-summary-pipe-output t]
1918               ["Add to SOUP packet" gnus-soup-add-article t]
1919               ["Print" gnus-summary-print-article t])
1920              ("Backend"
1921               ["Respool article..." gnus-summary-respool-article t]
1922               ["Move article..." gnus-summary-move-article
1923                (gnus-check-backend-function
1924                 'request-move-article gnus-newsgroup-name)]
1925               ["Copy article..." gnus-summary-copy-article t]
1926               ["Crosspost article..." gnus-summary-crosspost-article
1927                (gnus-check-backend-function
1928                 'request-replace-article gnus-newsgroup-name)]
1929               ["Import file..." gnus-summary-import-article t]
1930               ["Create article..." gnus-summary-create-article t]
1931               ["Check if posted" gnus-summary-article-posted-p t]
1932               ["Edit article" gnus-summary-edit-article
1933                (not (gnus-group-read-only-p))]
1934               ["Delete article" gnus-summary-delete-article
1935                (gnus-check-backend-function
1936                 'request-expire-articles gnus-newsgroup-name)]
1937               ["Query respool" gnus-summary-respool-query t]
1938               ["Trace respool" gnus-summary-respool-trace t]
1939               ["Delete expirable articles" gnus-summary-expire-articles-now
1940                (gnus-check-backend-function
1941                 'request-expire-articles gnus-newsgroup-name)])
1942              ("Extract"
1943               ["Uudecode" gnus-uu-decode-uu
1944                ,@(if (featurep 'xemacs) '(t)
1945                    '(:help "Decode uuencoded article(s)"))]
1946               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1947               ["Unshar" gnus-uu-decode-unshar t]
1948               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1949               ["Save" gnus-uu-decode-save t]
1950               ["Binhex" gnus-uu-decode-binhex t]
1951               ["Postscript" gnus-uu-decode-postscript t])
1952              ("Cache"
1953               ["Enter article" gnus-cache-enter-article t]
1954               ["Remove article" gnus-cache-remove-article t])
1955              ["Translate" gnus-article-babel t]
1956              ["Select article buffer" gnus-summary-select-article-buffer t]
1957              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1958              ["Isearch article..." gnus-summary-isearch-article t]
1959              ["Beginning of the article" gnus-summary-beginning-of-article t]
1960              ["End of the article" gnus-summary-end-of-article t]
1961              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1962              ["Fetch referenced articles" gnus-summary-refer-references t]
1963              ["Fetch current thread" gnus-summary-refer-thread t]
1964              ["Fetch article with id..." gnus-summary-refer-article t]
1965              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
1966              ["Redisplay" gnus-summary-show-article t]
1967              ["Raw article" gnus-summary-show-raw-article t])))
1968       (easy-menu-define
1969         gnus-summary-article-menu gnus-summary-mode-map ""
1970         (cons "Article" innards))
1971
1972       (if (not (keymapp gnus-summary-article-menu))
1973           (easy-menu-define
1974             gnus-article-commands-menu gnus-article-mode-map ""
1975             (cons "Commands" innards))
1976         ;; in Emacs, don't share menu.
1977         (setq gnus-article-commands-menu
1978               (copy-keymap gnus-summary-article-menu))
1979         (define-key gnus-article-mode-map [menu-bar commands]
1980           (cons "Commands" gnus-article-commands-menu))))
1981
1982     (easy-menu-define
1983       gnus-summary-thread-menu gnus-summary-mode-map ""
1984       '("Threads"
1985         ["Toggle threading" gnus-summary-toggle-threads t]
1986         ["Hide threads" gnus-summary-hide-all-threads t]
1987         ["Show threads" gnus-summary-show-all-threads t]
1988         ["Hide thread" gnus-summary-hide-thread t]
1989         ["Show thread" gnus-summary-show-thread t]
1990         ["Go to next thread" gnus-summary-next-thread t]
1991         ["Go to previous thread" gnus-summary-prev-thread t]
1992         ["Go down thread" gnus-summary-down-thread t]
1993         ["Go up thread" gnus-summary-up-thread t]
1994         ["Top of thread" gnus-summary-top-thread t]
1995         ["Mark thread as read" gnus-summary-kill-thread t]
1996         ["Lower thread score" gnus-summary-lower-thread t]
1997         ["Raise thread score" gnus-summary-raise-thread t]
1998         ["Rethread current" gnus-summary-rethread-current t]))
1999
2000     (easy-menu-define
2001       gnus-summary-post-menu gnus-summary-mode-map ""
2002       `("Post"
2003         ["Post an article" gnus-summary-post-news
2004          ,@(if (featurep 'xemacs) '(t)
2005              '(:help "Post an article"))]
2006         ["Followup" gnus-summary-followup
2007          ,@(if (featurep 'xemacs) '(t)
2008              '(:help "Post followup to this article"))]
2009         ["Followup and yank" gnus-summary-followup-with-original
2010          ,@(if (featurep 'xemacs) '(t)
2011              '(:help "Post followup to this article, quoting its contents"))]
2012         ["Supersede article" gnus-summary-supersede-article t]
2013         ["Cancel article" gnus-summary-cancel-article
2014          ,@(if (featurep 'xemacs) '(t)
2015              '(:help "Cancel an article you posted"))]
2016         ["Reply" gnus-summary-reply t]
2017         ["Reply and yank" gnus-summary-reply-with-original t]
2018         ["Wide reply" gnus-summary-wide-reply t]
2019         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2020          ,@(if (featurep 'xemacs) '(t)
2021              '(:help "Mail a reply, quoting this article"))]
2022         ["Mail forward" gnus-summary-mail-forward t]
2023         ["Post forward" gnus-summary-post-forward t]
2024         ["Digest and mail" gnus-uu-digest-mail-forward t]
2025         ["Digest and post" gnus-uu-digest-post-forward t]
2026         ["Resend message" gnus-summary-resend-message t]
2027         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2028         ["Send a mail" gnus-summary-mail-other-window t]
2029         ["Uuencode and post" gnus-uu-post-news
2030          ,@(if (featurep 'xemacs) '(t)
2031              '(:help "Post a uuencoded article"))]
2032         ["Followup via news" gnus-summary-followup-to-mail t]
2033         ["Followup via news and yank"
2034          gnus-summary-followup-to-mail-with-original t]
2035         ;;("Draft"
2036         ;;["Send" gnus-summary-send-draft t]
2037         ;;["Send bounced" gnus-resend-bounced-mail t])
2038         ))
2039
2040     (cond
2041      ((not (keymapp gnus-summary-post-menu))
2042       (setq gnus-article-post-menu gnus-summary-post-menu))
2043      ((not gnus-article-post-menu)
2044       ;; Don't share post menu.
2045       (setq gnus-article-post-menu
2046             (copy-keymap gnus-summary-post-menu))))
2047     (define-key gnus-article-mode-map [menu-bar post]
2048       (cons "Post" gnus-article-post-menu))
2049
2050     (easy-menu-define
2051       gnus-summary-misc-menu gnus-summary-mode-map ""
2052       `("Gnus"
2053         ("Mark Read"
2054          ["Mark as read" gnus-summary-mark-as-read-forward t]
2055          ["Mark same subject and select"
2056           gnus-summary-kill-same-subject-and-select t]
2057          ["Mark same subject" gnus-summary-kill-same-subject t]
2058          ["Catchup" gnus-summary-catchup
2059           ,@(if (featurep 'xemacs) '(t)
2060               '(:help "Mark unread articles in this group as read"))]
2061          ["Catchup all" gnus-summary-catchup-all t]
2062          ["Catchup to here" gnus-summary-catchup-to-here t]
2063          ["Catchup from here" gnus-summary-catchup-from-here t]
2064          ["Catchup region" gnus-summary-mark-region-as-read t]
2065          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2066         ("Mark Various"
2067          ["Tick" gnus-summary-tick-article-forward t]
2068          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2069          ["Remove marks" gnus-summary-clear-mark-forward t]
2070          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2071          ["Set bookmark" gnus-summary-set-bookmark t]
2072          ["Remove bookmark" gnus-summary-remove-bookmark t])
2073         ("Mark Limit"
2074          ["Marks..." gnus-summary-limit-to-marks t]
2075          ["Subject..." gnus-summary-limit-to-subject t]
2076          ["Author..." gnus-summary-limit-to-author t]
2077          ["Age..." gnus-summary-limit-to-age t]
2078          ["Extra..." gnus-summary-limit-to-extra t]
2079          ["Score" gnus-summary-limit-to-score t]
2080          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2081          ["Unread" gnus-summary-limit-to-unread t]
2082          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2083          ["Articles" gnus-summary-limit-to-articles t]
2084          ["Pop limit" gnus-summary-pop-limit t]
2085          ["Show dormant" gnus-summary-limit-include-dormant t]
2086          ["Hide childless dormant"
2087           gnus-summary-limit-exclude-childless-dormant t]
2088          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2089          ["Hide marked" gnus-summary-limit-exclude-marks t]
2090          ["Show expunged" gnus-summary-limit-include-expunged t])
2091         ("Process Mark"
2092          ["Set mark" gnus-summary-mark-as-processable t]
2093          ["Remove mark" gnus-summary-unmark-as-processable t]
2094          ["Remove all marks" gnus-summary-unmark-all-processable t]
2095          ["Mark above" gnus-uu-mark-over t]
2096          ["Mark series" gnus-uu-mark-series t]
2097          ["Mark region" gnus-uu-mark-region t]
2098          ["Unmark region" gnus-uu-unmark-region t]
2099          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2100          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2101          ["Mark all" gnus-uu-mark-all t]
2102          ["Mark buffer" gnus-uu-mark-buffer t]
2103          ["Mark sparse" gnus-uu-mark-sparse t]
2104          ["Mark thread" gnus-uu-mark-thread t]
2105          ["Unmark thread" gnus-uu-unmark-thread t]
2106          ("Process Mark Sets"
2107           ["Kill" gnus-summary-kill-process-mark t]
2108           ["Yank" gnus-summary-yank-process-mark
2109            gnus-newsgroup-process-stack]
2110           ["Save" gnus-summary-save-process-mark t]))
2111         ("Scroll article"
2112          ["Page forward" gnus-summary-next-page
2113           ,@(if (featurep 'xemacs) '(t)
2114               '(:help "Show next page of article"))]
2115          ["Page backward" gnus-summary-prev-page
2116           ,@(if (featurep 'xemacs) '(t)
2117               '(:help "Show previous page of article"))]
2118          ["Line forward" gnus-summary-scroll-up t])
2119         ("Move"
2120          ["Next unread article" gnus-summary-next-unread-article t]
2121          ["Previous unread article" gnus-summary-prev-unread-article t]
2122          ["Next article" gnus-summary-next-article t]
2123          ["Previous article" gnus-summary-prev-article t]
2124          ["Next unread subject" gnus-summary-next-unread-subject t]
2125          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2126          ["Next article same subject" gnus-summary-next-same-subject t]
2127          ["Previous article same subject" gnus-summary-prev-same-subject t]
2128          ["First unread article" gnus-summary-first-unread-article t]
2129          ["Best unread article" gnus-summary-best-unread-article t]
2130          ["Go to subject number..." gnus-summary-goto-subject t]
2131          ["Go to article number..." gnus-summary-goto-article t]
2132          ["Go to the last article" gnus-summary-goto-last-article t]
2133          ["Pop article off history" gnus-summary-pop-article t])
2134         ("Sort"
2135          ["Sort by number" gnus-summary-sort-by-number t]
2136          ["Sort by author" gnus-summary-sort-by-author t]
2137          ["Sort by subject" gnus-summary-sort-by-subject t]
2138          ["Sort by date" gnus-summary-sort-by-date t]
2139          ["Sort by score" gnus-summary-sort-by-score t]
2140          ["Sort by lines" gnus-summary-sort-by-lines t]
2141          ["Sort by characters" gnus-summary-sort-by-chars t]
2142          ["Original sort" gnus-summary-sort-by-original t])
2143         ("Help"
2144          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2145          ["Describe group" gnus-summary-describe-group t]
2146          ["Read manual" gnus-info-find-node t])
2147         ("Modes"
2148          ["Pick and read" gnus-pick-mode t]
2149          ["Binary" gnus-binary-mode t])
2150         ("Regeneration"
2151          ["Regenerate" gnus-summary-prepare t]
2152          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2153          ["Toggle threading" gnus-summary-toggle-threads t])
2154         ["See old articles" gnus-summary-insert-old-articles t]
2155         ["See new articles" gnus-summary-insert-new-articles t]
2156         ["Filter articles..." gnus-summary-execute-command t]
2157         ["Run command on subjects..." gnus-summary-universal-argument t]
2158         ["Search articles forward..." gnus-summary-search-article-forward t]
2159         ["Search articles backward..." gnus-summary-search-article-backward t]
2160         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2161         ["Expand window" gnus-summary-expand-window t]
2162         ["Expire expirable articles" gnus-summary-expire-articles
2163          (gnus-check-backend-function
2164           'request-expire-articles gnus-newsgroup-name)]
2165         ["Edit local kill file" gnus-summary-edit-local-kill t]
2166         ["Edit main kill file" gnus-summary-edit-global-kill t]
2167         ["Edit group parameters" gnus-summary-edit-parameters t]
2168         ["Customize group parameters" gnus-summary-customize-parameters t]
2169         ["Send a bug report" gnus-bug t]
2170         ("Exit"
2171          ["Catchup and exit" gnus-summary-catchup-and-exit
2172           ,@(if (featurep 'xemacs) '(t)
2173               '(:help "Mark unread articles in this group as read, then exit"))]
2174          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2175          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2176          ["Exit group" gnus-summary-exit
2177           ,@(if (featurep 'xemacs) '(t)
2178               '(:help "Exit current group, return to group selection mode"))]
2179          ["Exit group without updating" gnus-summary-exit-no-update t]
2180          ["Exit and goto next group" gnus-summary-next-group t]
2181          ["Exit and goto prev group" gnus-summary-prev-group t]
2182          ["Reselect group" gnus-summary-reselect-current-group t]
2183          ["Rescan group" gnus-summary-rescan-group t]
2184          ["Update dribble" gnus-summary-save-newsrc t])))
2185
2186     (gnus-run-hooks 'gnus-summary-menu-hook)))
2187
2188 (defvar gnus-summary-tool-bar-map nil)
2189
2190 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2191 (defun gnus-summary-make-tool-bar ()
2192   (if (and (fboundp 'tool-bar-add-item-from-menu)
2193            (default-value 'tool-bar-mode)
2194            (not gnus-summary-tool-bar-map))
2195       (setq gnus-summary-tool-bar-map
2196             (let ((tool-bar-map (make-sparse-keymap))
2197                   (load-path (mm-image-load-path)))
2198               (tool-bar-add-item-from-menu
2199                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2200               (tool-bar-add-item-from-menu
2201                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2202               (tool-bar-add-item-from-menu
2203                'gnus-summary-post-news "post" gnus-summary-mode-map)
2204               (tool-bar-add-item-from-menu
2205                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2206               (tool-bar-add-item-from-menu
2207                'gnus-summary-followup "followup" gnus-summary-mode-map)
2208               (tool-bar-add-item-from-menu
2209                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2210               (tool-bar-add-item-from-menu
2211                'gnus-summary-reply "reply" gnus-summary-mode-map)
2212               (tool-bar-add-item-from-menu
2213                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2214               (tool-bar-add-item-from-menu
2215                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2216               (tool-bar-add-item-from-menu
2217                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2218               (tool-bar-add-item-from-menu
2219                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2220               (tool-bar-add-item-from-menu
2221                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2222               (tool-bar-add-item-from-menu
2223                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2224               (tool-bar-add-item-from-menu
2225                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2226               (tool-bar-add-item-from-menu
2227                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2228               tool-bar-map)))
2229   (if gnus-summary-tool-bar-map
2230       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2231
2232 (defun gnus-score-set-default (var value)
2233   "A version of set that updates the GNU Emacs menu-bar."
2234   (set var value)
2235   ;; It is the message that forces the active status to be updated.
2236   (message ""))
2237
2238 (defun gnus-make-score-map (type)
2239   "Make a summary score map of type TYPE."
2240   (if t
2241       nil
2242     (let ((headers '(("author" "from" string)
2243                      ("subject" "subject" string)
2244                      ("article body" "body" string)
2245                      ("article head" "head" string)
2246                      ("xref" "xref" string)
2247                      ("extra header" "extra" string)
2248                      ("lines" "lines" number)
2249                      ("followups to author" "followup" string)))
2250           (types '((number ("less than" <)
2251                            ("greater than" >)
2252                            ("equal" =))
2253                    (string ("substring" s)
2254                            ("exact string" e)
2255                            ("fuzzy string" f)
2256                            ("regexp" r))))
2257           (perms '(("temporary" (current-time-string))
2258                    ("permanent" nil)
2259                    ("immediate" now)))
2260           header)
2261       (list
2262        (apply
2263         'nconc
2264         (list
2265          (if (eq type 'lower)
2266              "Lower score"
2267            "Increase score"))
2268         (let (outh)
2269           (while headers
2270             (setq header (car headers))
2271             (setq outh
2272                   (cons
2273                    (apply
2274                     'nconc
2275                     (list (car header))
2276                     (let ((ts (cdr (assoc (nth 2 header) types)))
2277                           outt)
2278                       (while ts
2279                         (setq outt
2280                               (cons
2281                                (apply
2282                                 'nconc
2283                                 (list (caar ts))
2284                                 (let ((ps perms)
2285                                       outp)
2286                                   (while ps
2287                                     (setq outp
2288                                           (cons
2289                                            (vector
2290                                             (caar ps)
2291                                             (list
2292                                              'gnus-summary-score-entry
2293                                              (nth 1 header)
2294                                              (if (or (string= (nth 1 header)
2295                                                               "head")
2296                                                      (string= (nth 1 header)
2297                                                               "body"))
2298                                                  ""
2299                                                (list 'gnus-summary-header
2300                                                      (nth 1 header)))
2301                                              (list 'quote (nth 1 (car ts)))
2302                                              (list 'gnus-score-delta-default
2303                                                    nil)
2304                                              (nth 1 (car ps))
2305                                              t)
2306                                             t)
2307                                            outp))
2308                                     (setq ps (cdr ps)))
2309                                   (list (nreverse outp))))
2310                                outt))
2311                         (setq ts (cdr ts)))
2312                       (list (nreverse outt))))
2313                    outh))
2314             (setq headers (cdr headers)))
2315           (list (nreverse outh))))))))
2316
2317 \f
2318
2319 (defun gnus-summary-mode (&optional group)
2320   "Major mode for reading articles.
2321
2322 All normal editing commands are switched off.
2323 \\<gnus-summary-mode-map>
2324 Each line in this buffer represents one article.  To read an
2325 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2326 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2327 respectively.
2328
2329 You can also post articles and send mail from this buffer.  To
2330 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2331 of an article, type `\\[gnus-summary-reply]'.
2332
2333 There are approx. one gazillion commands you can execute in this
2334 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2335
2336 The following commands are available:
2337
2338 \\{gnus-summary-mode-map}"
2339   (interactive)
2340   (kill-all-local-variables)
2341   (when (gnus-visual-p 'summary-menu 'menu)
2342     (gnus-summary-make-menu-bar)
2343     (gnus-summary-make-tool-bar))
2344   (gnus-summary-make-local-variables)
2345   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2346     (gnus-summary-make-local-variables))
2347   (gnus-make-thread-indent-array)
2348   (gnus-simplify-mode-line)
2349   (setq major-mode 'gnus-summary-mode)
2350   (setq mode-name "Summary")
2351   (make-local-variable 'minor-mode-alist)
2352   (use-local-map gnus-summary-mode-map)
2353   (buffer-disable-undo)
2354   (setq buffer-read-only t)             ;Disable modification
2355   (setq truncate-lines t)
2356   (setq selective-display t)
2357   (setq selective-display-ellipses t)   ;Display `...'
2358   (gnus-summary-set-display-table)
2359   (gnus-set-default-directory)
2360   (setq gnus-newsgroup-name group)
2361   (make-local-variable 'gnus-summary-line-format)
2362   (make-local-variable 'gnus-summary-line-format-spec)
2363   (make-local-variable 'gnus-summary-dummy-line-format)
2364   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2365   (make-local-variable 'gnus-summary-mark-positions)
2366   (make-local-hook 'pre-command-hook)
2367   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2368   (gnus-run-hooks 'gnus-summary-mode-hook)
2369   (turn-on-gnus-mailing-list-mode)
2370   (mm-enable-multibyte-mule4)
2371   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2372   (gnus-update-summary-mark-positions))
2373
2374 (defun gnus-summary-make-local-variables ()
2375   "Make all the local summary buffer variables."
2376   (let (global)
2377     (dolist (local gnus-summary-local-variables)
2378       (if (consp local)
2379           (progn
2380             (if (eq (cdr local) 'global)
2381                 ;; Copy the global value of the variable.
2382                 (setq global (symbol-value (car local)))
2383               ;; Use the value from the list.
2384               (setq global (eval (cdr local))))
2385             (set (make-local-variable (car local)) global))
2386         ;; Simple nil-valued local variable.
2387         (set (make-local-variable local) nil)))))
2388
2389 (defun gnus-summary-clear-local-variables ()
2390   (let ((locals gnus-summary-local-variables))
2391     (while locals
2392       (if (consp (car locals))
2393           (and (vectorp (caar locals))
2394                (set (caar locals) nil))
2395         (and (vectorp (car locals))
2396              (set (car locals) nil)))
2397       (setq locals (cdr locals)))))
2398
2399 ;; Summary data functions.
2400
2401 (defmacro gnus-data-number (data)
2402   `(car ,data))
2403
2404 (defmacro gnus-data-set-number (data number)
2405   `(setcar ,data ,number))
2406
2407 (defmacro gnus-data-mark (data)
2408   `(nth 1 ,data))
2409
2410 (defmacro gnus-data-set-mark (data mark)
2411   `(setcar (nthcdr 1 ,data) ,mark))
2412
2413 (defmacro gnus-data-pos (data)
2414   `(nth 2 ,data))
2415
2416 (defmacro gnus-data-set-pos (data pos)
2417   `(setcar (nthcdr 2 ,data) ,pos))
2418
2419 (defmacro gnus-data-header (data)
2420   `(nth 3 ,data))
2421
2422 (defmacro gnus-data-set-header (data header)
2423   `(setf (nth 3 ,data) ,header))
2424
2425 (defmacro gnus-data-level (data)
2426   `(nth 4 ,data))
2427
2428 (defmacro gnus-data-unread-p (data)
2429   `(= (nth 1 ,data) gnus-unread-mark))
2430
2431 (defmacro gnus-data-read-p (data)
2432   `(/= (nth 1 ,data) gnus-unread-mark))
2433
2434 (defmacro gnus-data-pseudo-p (data)
2435   `(consp (nth 3 ,data)))
2436
2437 (defmacro gnus-data-find (number)
2438   `(assq ,number gnus-newsgroup-data))
2439
2440 (defmacro gnus-data-find-list (number &optional data)
2441   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2442      (memq (assq ,number bdata)
2443            bdata)))
2444
2445 (defmacro gnus-data-make (number mark pos header level)
2446   `(list ,number ,mark ,pos ,header ,level))
2447
2448 (defun gnus-data-enter (after-article number mark pos header level offset)
2449   (let ((data (gnus-data-find-list after-article)))
2450     (unless data
2451       (error "No such article: %d" after-article))
2452     (setcdr data (cons (gnus-data-make number mark pos header level)
2453                        (cdr data)))
2454     (setq gnus-newsgroup-data-reverse nil)
2455     (gnus-data-update-list (cddr data) offset)))
2456
2457 (defun gnus-data-enter-list (after-article list &optional offset)
2458   (when list
2459     (let ((data (and after-article (gnus-data-find-list after-article)))
2460           (ilist list))
2461       (if (not (or data
2462                    after-article))
2463           (let ((odata gnus-newsgroup-data))
2464             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2465             (when offset
2466               (gnus-data-update-list odata offset)))
2467       ;; Find the last element in the list to be spliced into the main
2468         ;; list.
2469         (while (cdr list)
2470           (setq list (cdr list)))
2471         (if (not data)
2472             (progn
2473               (setcdr list gnus-newsgroup-data)
2474               (setq gnus-newsgroup-data ilist)
2475               (when offset
2476                 (gnus-data-update-list (cdr list) offset)))
2477           (setcdr list (cdr data))
2478           (setcdr data ilist)
2479           (when offset
2480             (gnus-data-update-list (cdr list) offset))))
2481       (setq gnus-newsgroup-data-reverse nil))))
2482
2483 (defun gnus-data-remove (article &optional offset)
2484   (let ((data gnus-newsgroup-data))
2485     (if (= (gnus-data-number (car data)) article)
2486         (progn
2487           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2488                 gnus-newsgroup-data-reverse nil)
2489           (when offset
2490             (gnus-data-update-list gnus-newsgroup-data offset)))
2491       (while (cdr data)
2492         (when (= (gnus-data-number (cadr data)) article)
2493           (setcdr data (cddr data))
2494           (when offset
2495             (gnus-data-update-list (cdr data) offset))
2496           (setq data nil
2497                 gnus-newsgroup-data-reverse nil))
2498         (setq data (cdr data))))))
2499
2500 (defmacro gnus-data-list (backward)
2501   `(if ,backward
2502        (or gnus-newsgroup-data-reverse
2503            (setq gnus-newsgroup-data-reverse
2504                  (reverse gnus-newsgroup-data)))
2505      gnus-newsgroup-data))
2506
2507 (defun gnus-data-update-list (data offset)
2508   "Add OFFSET to the POS of all data entries in DATA."
2509   (setq gnus-newsgroup-data-reverse nil)
2510   (while data
2511     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2512     (setq data (cdr data))))
2513
2514 (defun gnus-summary-article-pseudo-p (article)
2515   "Say whether this article is a pseudo article or not."
2516   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2517
2518 (defmacro gnus-summary-article-sparse-p (article)
2519   "Say whether this article is a sparse article or not."
2520   `(memq ,article gnus-newsgroup-sparse))
2521
2522 (defmacro gnus-summary-article-ancient-p (article)
2523   "Say whether this article is a sparse article or not."
2524   `(memq ,article gnus-newsgroup-ancient))
2525
2526 (defun gnus-article-parent-p (number)
2527   "Say whether this article is a parent or not."
2528   (let ((data (gnus-data-find-list number)))
2529     (and (cdr data)              ; There has to be an article after...
2530          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2531             (gnus-data-level (nth 1 data))))))
2532
2533 (defun gnus-article-children (number)
2534   "Return a list of all children to NUMBER."
2535   (let* ((data (gnus-data-find-list number))
2536          (level (gnus-data-level (car data)))
2537          children)
2538     (setq data (cdr data))
2539     (while (and data
2540                 (= (gnus-data-level (car data)) (1+ level)))
2541       (push (gnus-data-number (car data)) children)
2542       (setq data (cdr data)))
2543     children))
2544
2545 (defmacro gnus-summary-skip-intangible ()
2546   "If the current article is intangible, then jump to a different article."
2547   '(let ((to (get-text-property (point) 'gnus-intangible)))
2548      (and to (gnus-summary-goto-subject to))))
2549
2550 (defmacro gnus-summary-article-intangible-p ()
2551   "Say whether this article is intangible or not."
2552   '(get-text-property (point) 'gnus-intangible))
2553
2554 (defun gnus-article-read-p (article)
2555   "Say whether ARTICLE is read or not."
2556   (not (or (memq article gnus-newsgroup-marked)
2557            (memq article gnus-newsgroup-unreads)
2558            (memq article gnus-newsgroup-unselected)
2559            (memq article gnus-newsgroup-dormant))))
2560
2561 ;; Some summary mode macros.
2562
2563 (defmacro gnus-summary-article-number ()
2564   "The article number of the article on the current line.
2565 If there isn's an article number here, then we return the current
2566 article number."
2567   '(progn
2568      (gnus-summary-skip-intangible)
2569      (or (get-text-property (point) 'gnus-number)
2570          (gnus-summary-last-subject))))
2571
2572 (defmacro gnus-summary-article-header (&optional number)
2573   "Return the header of article NUMBER."
2574   `(gnus-data-header (gnus-data-find
2575                       ,(or number '(gnus-summary-article-number)))))
2576
2577 (defmacro gnus-summary-thread-level (&optional number)
2578   "Return the level of thread that starts with article NUMBER."
2579   `(if (and (eq gnus-summary-make-false-root 'dummy)
2580             (get-text-property (point) 'gnus-intangible))
2581        0
2582      (gnus-data-level (gnus-data-find
2583                        ,(or number '(gnus-summary-article-number))))))
2584
2585 (defmacro gnus-summary-article-mark (&optional number)
2586   "Return the mark of article NUMBER."
2587   `(gnus-data-mark (gnus-data-find
2588                     ,(or number '(gnus-summary-article-number)))))
2589
2590 (defmacro gnus-summary-article-pos (&optional number)
2591   "Return the position of the line of article NUMBER."
2592   `(gnus-data-pos (gnus-data-find
2593                    ,(or number '(gnus-summary-article-number)))))
2594
2595 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2596 (defmacro gnus-summary-article-subject (&optional number)
2597   "Return current subject string or nil if nothing."
2598   `(let ((headers
2599           ,(if number
2600                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2601              '(gnus-data-header (assq (gnus-summary-article-number)
2602                                       gnus-newsgroup-data)))))
2603      (and headers
2604           (vectorp headers)
2605           (mail-header-subject headers))))
2606
2607 (defmacro gnus-summary-article-score (&optional number)
2608   "Return current article score."
2609   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2610                   gnus-newsgroup-scored))
2611        gnus-summary-default-score 0))
2612
2613 (defun gnus-summary-article-children (&optional number)
2614   "Return a list of article numbers that are children of article NUMBER."
2615   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2616          (level (gnus-data-level (car data)))
2617          l children)
2618     (while (and (setq data (cdr data))
2619                 (> (setq l (gnus-data-level (car data))) level))
2620       (and (= (1+ level) l)
2621            (push (gnus-data-number (car data))
2622                  children)))
2623     (nreverse children)))
2624
2625 (defun gnus-summary-article-parent (&optional number)
2626   "Return the article number of the parent of article NUMBER."
2627   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2628                                     (gnus-data-list t)))
2629          (level (gnus-data-level (car data))))
2630     (if (zerop level)
2631         ()                              ; This is a root.
2632       ;; We search until we find an article with a level less than
2633       ;; this one.  That function has to be the parent.
2634       (while (and (setq data (cdr data))
2635                   (not (< (gnus-data-level (car data)) level))))
2636       (and data (gnus-data-number (car data))))))
2637
2638 (defun gnus-unread-mark-p (mark)
2639   "Say whether MARK is the unread mark."
2640   (= mark gnus-unread-mark))
2641
2642 (defun gnus-read-mark-p (mark)
2643   "Say whether MARK is one of the marks that mark as read.
2644 This is all marks except unread, ticked, dormant, and expirable."
2645   (not (or (= mark gnus-unread-mark)
2646            (= mark gnus-ticked-mark)
2647            (= mark gnus-dormant-mark)
2648            (= mark gnus-expirable-mark))))
2649
2650 (defmacro gnus-article-mark (number)
2651   "Return the MARK of article NUMBER.
2652 This macro should only be used when computing the mark the \"first\"
2653 time; i.e., when generating the summary lines.  After that,
2654 `gnus-summary-article-mark' should be used to examine the
2655 marks of articles."
2656   `(cond
2657     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2658     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2659     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2660     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2661     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2662     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2663     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2664     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2665            gnus-ancient-mark))))
2666
2667 ;; Saving hidden threads.
2668
2669 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2670 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2671
2672 (defmacro gnus-save-hidden-threads (&rest forms)
2673   "Save hidden threads, eval FORMS, and restore the hidden threads."
2674   (let ((config (make-symbol "config")))
2675     `(let ((,config (gnus-hidden-threads-configuration)))
2676        (unwind-protect
2677            (save-excursion
2678              ,@forms)
2679          (gnus-restore-hidden-threads-configuration ,config)))))
2680
2681 (defun gnus-data-compute-positions ()
2682   "Compute the positions of all articles."
2683   (setq gnus-newsgroup-data-reverse nil)
2684   (let ((data gnus-newsgroup-data))
2685     (save-excursion
2686       (gnus-save-hidden-threads
2687         (gnus-summary-show-all-threads)
2688         (goto-char (point-min))
2689         (while data
2690           (while (get-text-property (point) 'gnus-intangible)
2691             (forward-line 1))
2692           (gnus-data-set-pos (car data) (+ (point) 3))
2693           (setq data (cdr data))
2694           (forward-line 1))))))
2695
2696 (defun gnus-hidden-threads-configuration ()
2697   "Return the current hidden threads configuration."
2698   (save-excursion
2699     (let (config)
2700       (goto-char (point-min))
2701       (while (search-forward "\r" nil t)
2702         (push (1- (point)) config))
2703       config)))
2704
2705 (defun gnus-restore-hidden-threads-configuration (config)
2706   "Restore hidden threads configuration from CONFIG."
2707   (save-excursion
2708     (let (point buffer-read-only)
2709       (while (setq point (pop config))
2710         (when (and (< point (point-max))
2711                    (goto-char point)
2712                    (eq (char-after) ?\n))
2713           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2714
2715 ;; Various summary mode internalish functions.
2716
2717 (defun gnus-mouse-pick-article (e)
2718   (interactive "e")
2719   (mouse-set-point e)
2720   (gnus-summary-next-page nil t))
2721
2722 (defun gnus-summary-set-display-table ()
2723   "Change the display table.
2724 Odd characters have a tendency to mess
2725 up nicely formatted displays - we make all possible glyphs
2726 display only a single character."
2727
2728   ;; We start from the standard display table, if any.
2729   (let ((table (or (copy-sequence standard-display-table)
2730                    (make-display-table)))
2731         (i 32))
2732     ;; Nix out all the control chars...
2733     (while (>= (setq i (1- i)) 0)
2734       (aset table i [??]))
2735    ;; ... but not newline and cr, of course.  (cr is necessary for the
2736     ;; selective display).
2737     (aset table ?\n nil)
2738     (aset table ?\r nil)
2739     ;; We keep TAB as well.
2740     (aset table ?\t nil)
2741     ;; We nix out any glyphs over 126 that are not set already.
2742     (let ((i 256))
2743       (while (>= (setq i (1- i)) 127)
2744         ;; Only modify if the entry is nil.
2745         (unless (aref table i)
2746           (aset table i [??]))))
2747     (setq buffer-display-table table)))
2748
2749 (defun gnus-summary-set-article-display-arrow (pos)
2750   "Update the overlay arrow to point to line at position POS."
2751   (when (and gnus-summary-display-arrow
2752              (boundp 'overlay-arrow-position)
2753              (boundp 'overlay-arrow-string))
2754     (save-excursion
2755       (goto-char pos)
2756       (beginning-of-line)
2757       (unless overlay-arrow-position
2758         (setq overlay-arrow-position (make-marker)))
2759       (setq overlay-arrow-string "=>"
2760             overlay-arrow-position (set-marker overlay-arrow-position
2761                                                (point)
2762                                                (current-buffer))))))
2763
2764 (defun gnus-summary-buffer-name (group)
2765   "Return the summary buffer name of GROUP."
2766   (concat "*Summary " group "*"))
2767
2768 (defun gnus-summary-setup-buffer (group)
2769   "Initialize summary buffer."
2770   (let ((buffer (gnus-summary-buffer-name group)))
2771     (if (get-buffer buffer)
2772         (progn
2773           (set-buffer buffer)
2774           (setq gnus-summary-buffer (current-buffer))
2775           (not gnus-newsgroup-prepared))
2776       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2777       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2778       (gnus-summary-mode group)
2779       (when gnus-carpal
2780         (gnus-carpal-setup-buffer 'summary))
2781       (unless gnus-single-article-buffer
2782         (make-local-variable 'gnus-article-buffer)
2783         (make-local-variable 'gnus-article-current)
2784         (make-local-variable 'gnus-original-article-buffer))
2785       (setq gnus-newsgroup-name group)
2786       ;; Set any local variables in the group parameters.
2787       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2788       t)))
2789
2790 (defun gnus-set-global-variables ()
2791   "Set the global equivalents of the buffer-local variables.
2792 They are set to the latest values they had.  These reflect the summary
2793 buffer that was in action when the last article was fetched."
2794   (when (eq major-mode 'gnus-summary-mode)
2795     (setq gnus-summary-buffer (current-buffer))
2796     (let ((name gnus-newsgroup-name)
2797           (marked gnus-newsgroup-marked)
2798           (unread gnus-newsgroup-unreads)
2799           (headers gnus-current-headers)
2800           (data gnus-newsgroup-data)
2801           (summary gnus-summary-buffer)
2802           (article-buffer gnus-article-buffer)
2803           (original gnus-original-article-buffer)
2804           (gac gnus-article-current)
2805           (reffed gnus-reffed-article-number)
2806           (score-file gnus-current-score-file)
2807           (default-charset gnus-newsgroup-charset)
2808           vlist)
2809       (let ((locals gnus-newsgroup-variables))
2810         (while locals
2811           (if (consp (car locals))
2812               (push (eval (caar locals)) vlist)
2813             (push (eval (car locals)) vlist))
2814           (setq locals (cdr locals)))
2815         (setq vlist (nreverse vlist)))
2816       (save-excursion
2817         (set-buffer gnus-group-buffer)
2818         (setq gnus-newsgroup-name name
2819               gnus-newsgroup-marked marked
2820               gnus-newsgroup-unreads unread
2821               gnus-current-headers headers
2822               gnus-newsgroup-data data
2823               gnus-article-current gac
2824               gnus-summary-buffer summary
2825               gnus-article-buffer article-buffer
2826               gnus-original-article-buffer original
2827               gnus-reffed-article-number reffed
2828               gnus-current-score-file score-file
2829               gnus-newsgroup-charset default-charset)
2830         (let ((locals gnus-newsgroup-variables))
2831           (while locals
2832             (if (consp (car locals))
2833                 (set (caar locals) (pop vlist))
2834               (set (car locals) (pop vlist)))
2835             (setq locals (cdr locals))))
2836         ;; The article buffer also has local variables.
2837         (when (gnus-buffer-live-p gnus-article-buffer)
2838           (set-buffer gnus-article-buffer)
2839           (setq gnus-summary-buffer summary))))))
2840
2841 (defun gnus-summary-article-unread-p (article)
2842   "Say whether ARTICLE is unread or not."
2843   (memq article gnus-newsgroup-unreads))
2844
2845 (defun gnus-summary-first-article-p (&optional article)
2846   "Return whether ARTICLE is the first article in the buffer."
2847   (if (not (setq article (or article (gnus-summary-article-number))))
2848       nil
2849     (eq article (caar gnus-newsgroup-data))))
2850
2851 (defun gnus-summary-last-article-p (&optional article)
2852   "Return whether ARTICLE is the last article in the buffer."
2853   (if (not (setq article (or article (gnus-summary-article-number))))
2854       ;; All non-existent numbers are the last article.  :-)
2855       t
2856     (not (cdr (gnus-data-find-list article)))))
2857
2858 (defun gnus-make-thread-indent-array ()
2859   (let ((n 200))
2860     (unless (and gnus-thread-indent-array
2861                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2862       (setq gnus-thread-indent-array (make-vector 201 "")
2863             gnus-thread-indent-array-level gnus-thread-indent-level)
2864       (while (>= n 0)
2865         (aset gnus-thread-indent-array n
2866               (make-string (* n gnus-thread-indent-level) ? ))
2867         (setq n (1- n))))))
2868
2869 (defun gnus-update-summary-mark-positions ()
2870   "Compute where the summary marks are to go."
2871   (save-excursion
2872     (when (gnus-buffer-exists-p gnus-summary-buffer)
2873       (set-buffer gnus-summary-buffer))
2874     (let ((gnus-replied-mark 129)
2875           (gnus-score-below-mark 130)
2876           (gnus-score-over-mark 130)
2877           (gnus-download-mark 131)
2878           (spec gnus-summary-line-format-spec)
2879           gnus-visual pos)
2880       (save-excursion
2881         (gnus-set-work-buffer)
2882         (let ((gnus-summary-line-format-spec spec)
2883               (gnus-newsgroup-downloadable '((0 . t))))
2884           (gnus-summary-insert-line
2885            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
2886            0 nil 128 t nil "" nil 1)
2887           (goto-char (point-min))
2888           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2889                                              (- (point) 2)))))
2890           (goto-char (point-min))
2891           (push (cons 'replied (and (search-forward "\201" nil t)
2892                                     (- (point) 2)))
2893                 pos)
2894           (goto-char (point-min))
2895           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2896                 pos)
2897           (goto-char (point-min))
2898           (push (cons 'download
2899                       (and (search-forward "\203" nil t) (- (point) 2)))
2900                 pos)))
2901       (setq gnus-summary-mark-positions pos))))
2902
2903 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2904   "Insert a dummy root in the summary buffer."
2905   (beginning-of-line)
2906   (gnus-add-text-properties
2907    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2908    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2909
2910 (defun gnus-summary-extract-address-component (from)
2911   (or (car (funcall gnus-extract-address-components from))
2912       from))
2913
2914 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2915   (let ((mail-parse-charset gnus-newsgroup-charset)
2916         ; Is it really necessary to do this next part for each summary line?
2917         ; Luckily, doesn't seem to slow things down much.
2918         (mail-parse-ignored-charsets
2919          (save-excursion (set-buffer gnus-summary-buffer)
2920                          gnus-newsgroup-ignored-charsets)))
2921     (or
2922      (and gnus-ignored-from-addresses
2923           (string-match gnus-ignored-from-addresses gnus-tmp-from)
2924           (let ((extra-headers (mail-header-extra header))
2925                 to
2926                 newsgroups)
2927             (cond
2928              ((setq to (cdr (assq 'To extra-headers)))
2929               (concat "-> "
2930                       (gnus-summary-extract-address-component
2931                        (funcall gnus-decode-encoded-word-function to))))
2932              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
2933               (concat "=> " newsgroups)))))
2934      (gnus-summary-extract-address-component gnus-tmp-from))))
2935
2936 (defun gnus-summary-insert-line (gnus-tmp-header
2937                                  gnus-tmp-level gnus-tmp-current
2938                                  gnus-tmp-unread gnus-tmp-replied
2939                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2940                                  &optional gnus-tmp-dummy gnus-tmp-score
2941                                  gnus-tmp-process)
2942   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2943          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2944          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2945          (gnus-tmp-score-char
2946           (if (or (null gnus-summary-default-score)
2947                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2948                       gnus-summary-zcore-fuzz))
2949               ?                         ;Whitespace
2950             (if (< gnus-tmp-score gnus-summary-default-score)
2951                 gnus-score-below-mark gnus-score-over-mark)))
2952          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2953          (gnus-tmp-replied
2954           (cond (gnus-tmp-process gnus-process-mark)
2955                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2956                  gnus-cached-mark)
2957                 (gnus-tmp-replied gnus-replied-mark)
2958                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
2959                  gnus-forwarded-mark)
2960                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2961                  gnus-saved-mark)
2962                 ((memq gnus-tmp-number gnus-newsgroup-recent)
2963                  gnus-recent-mark)
2964                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
2965                  gnus-unseen-mark)
2966                 (t gnus-no-mark)))
2967          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2968          (gnus-tmp-name
2969           (cond
2970            ((string-match "<[^>]+> *$" gnus-tmp-from)
2971             (let ((beg (match-beginning 0)))
2972               (or (and (string-match "^\".+\"" gnus-tmp-from)
2973                        (substring gnus-tmp-from 1 (1- (match-end 0))))
2974                   (substring gnus-tmp-from 0 beg))))
2975            ((string-match "(.+)" gnus-tmp-from)
2976             (substring gnus-tmp-from
2977                        (1+ (match-beginning 0)) (1- (match-end 0))))
2978            (t gnus-tmp-from)))
2979          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2980          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2981          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2982          (buffer-read-only nil))
2983     (when (string= gnus-tmp-name "")
2984       (setq gnus-tmp-name gnus-tmp-from))
2985     (unless (numberp gnus-tmp-lines)
2986       (setq gnus-tmp-lines -1))
2987     (if (= gnus-tmp-lines -1)
2988         (setq gnus-tmp-lines "?")
2989       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
2990     (gnus-put-text-property
2991      (point)
2992      (progn (eval gnus-summary-line-format-spec) (point))
2993      'gnus-number gnus-tmp-number)
2994     (when (gnus-visual-p 'summary-highlight 'highlight)
2995       (forward-line -1)
2996       (gnus-run-hooks 'gnus-summary-update-hook)
2997       (forward-line 1))))
2998
2999 (defun gnus-summary-update-line (&optional dont-update)
3000   "Update summary line after change."
3001   (when (and gnus-summary-default-score
3002              (not gnus-summary-inhibit-highlight))
3003     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3004            (article (gnus-summary-article-number))
3005            (score (gnus-summary-article-score article)))
3006       (unless dont-update
3007         (if (and gnus-summary-mark-below
3008                  (< (gnus-summary-article-score)
3009                     gnus-summary-mark-below))
3010             ;; This article has a low score, so we mark it as read.
3011             (when (memq article gnus-newsgroup-unreads)
3012               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3013           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3014             ;; This article was previously marked as read on account
3015             ;; of a low score, but now it has risen, so we mark it as
3016             ;; unread.
3017             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3018         (gnus-summary-update-mark
3019          (if (or (null gnus-summary-default-score)
3020                  (<= (abs (- score gnus-summary-default-score))
3021                      gnus-summary-zcore-fuzz))
3022              ?                          ;Whitespace
3023            (if (< score gnus-summary-default-score)
3024                gnus-score-below-mark gnus-score-over-mark))
3025          'score))
3026       ;; Do visual highlighting.
3027       (when (gnus-visual-p 'summary-highlight 'highlight)
3028         (gnus-run-hooks 'gnus-summary-update-hook)))))
3029
3030 (defvar gnus-tmp-new-adopts nil)
3031
3032 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3033   "Return the number of articles in THREAD.
3034 This may be 0 in some cases -- if none of the articles in
3035 the thread are to be displayed."
3036   (let* ((number
3037          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3038           (cond
3039            ((not (listp thread))
3040             1)
3041            ((and (consp thread) (cdr thread))
3042             (apply
3043              '+ 1 (mapcar
3044                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3045            ((null thread)
3046             1)
3047            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3048             1)
3049            (t 0))))
3050     (when (and level (zerop level) gnus-tmp-new-adopts)
3051       (incf number
3052             (apply '+ (mapcar
3053                        'gnus-summary-number-of-articles-in-thread
3054                        gnus-tmp-new-adopts))))
3055     (if char
3056         (if (> number 1) gnus-not-empty-thread-mark
3057           gnus-empty-thread-mark)
3058       number)))
3059
3060 (defun gnus-summary-set-local-parameters (group)
3061   "Go through the local params of GROUP and set all variable specs in that list."
3062   (let ((params (gnus-group-find-parameter group))
3063         (vars '(quit-config))           ; Ignore quit-config.
3064         elem)
3065     (while params
3066       (setq elem (car params)
3067             params (cdr params))
3068       (and (consp elem)                 ; Has to be a cons.
3069            (consp (cdr elem))           ; The cdr has to be a list.
3070            (symbolp (car elem))         ; Has to be a symbol in there.
3071            (not (memq (car elem) vars))
3072            (ignore-errors               ; So we set it.
3073              (push (car elem) vars)
3074              (make-local-variable (car elem))
3075              (set (car elem) (eval (nth 1 elem))))))))
3076
3077 (defun gnus-summary-read-group (group &optional show-all no-article
3078                                       kill-buffer no-display backward
3079                                       select-articles)
3080   "Start reading news in newsgroup GROUP.
3081 If SHOW-ALL is non-nil, already read articles are also listed.
3082 If NO-ARTICLE is non-nil, no article is selected initially.
3083 If NO-DISPLAY, don't generate a summary buffer."
3084   (let (result)
3085     (while (and group
3086                 (null (setq result
3087                             (let ((gnus-auto-select-next nil))
3088                               (or (gnus-summary-read-group-1
3089                                    group show-all no-article
3090                                    kill-buffer no-display
3091                                    select-articles)
3092                                   (setq show-all nil
3093                                         select-articles nil)))))
3094                 (eq gnus-auto-select-next 'quietly))
3095       (set-buffer gnus-group-buffer)
3096       ;; The entry function called above goes to the next
3097       ;; group automatically, so we go two groups back
3098       ;; if we are searching for the previous group.
3099       (when backward
3100         (gnus-group-prev-unread-group 2))
3101       (if (not (equal group (gnus-group-group-name)))
3102           (setq group (gnus-group-group-name))
3103         (setq group nil)))
3104     result))
3105
3106 (defun gnus-summary-read-group-1 (group show-all no-article
3107                                         kill-buffer no-display
3108                                         &optional select-articles)
3109   ;; Killed foreign groups can't be entered.
3110   ;;  (when (and (not (gnus-group-native-p group))
3111   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3112   ;;    (error "Dead non-native groups can't be entered"))
3113   (gnus-message 5 "Retrieving newsgroup: %s..."
3114                 (gnus-group-decoded-name group))
3115   (let* ((new-group (gnus-summary-setup-buffer group))
3116          (quit-config (gnus-group-quit-config group))
3117          (did-select (and new-group (gnus-select-newsgroup
3118                                      group show-all select-articles))))
3119     (cond
3120      ;; This summary buffer exists already, so we just select it.
3121      ((not new-group)
3122       (gnus-set-global-variables)
3123       (when kill-buffer
3124         (gnus-kill-or-deaden-summary kill-buffer))
3125       (gnus-configure-windows 'summary 'force)
3126       (gnus-set-mode-line 'summary)
3127       (gnus-summary-position-point)
3128       (message "")
3129       t)
3130      ;; We couldn't select this group.
3131      ((null did-select)
3132       (when (and (eq major-mode 'gnus-summary-mode)
3133                  (not (equal (current-buffer) kill-buffer)))
3134         (kill-buffer (current-buffer))
3135         (if (not quit-config)
3136             (progn
3137               ;; Update the info -- marks might need to be removed,
3138               ;; for instance.
3139               (gnus-summary-update-info)
3140               (set-buffer gnus-group-buffer)
3141               (gnus-group-jump-to-group group)
3142               (gnus-group-next-unread-group 1))
3143           (gnus-handle-ephemeral-exit quit-config)))
3144       (let ((grpinfo (gnus-get-info group)))
3145         (if (null (gnus-info-read grpinfo))
3146             (gnus-message 3 "Group %s contains no messages"
3147                           (gnus-group-decoded-name group))
3148           (gnus-message 3 "Can't select group")))
3149       nil)
3150      ;; The user did a `C-g' while prompting for number of articles,
3151      ;; so we exit this group.
3152      ((eq did-select 'quit)
3153       (and (eq major-mode 'gnus-summary-mode)
3154            (not (equal (current-buffer) kill-buffer))
3155            (kill-buffer (current-buffer)))
3156       (when kill-buffer
3157         (gnus-kill-or-deaden-summary kill-buffer))
3158       (if (not quit-config)
3159           (progn
3160             (set-buffer gnus-group-buffer)
3161             (gnus-group-jump-to-group group)
3162             (gnus-group-next-unread-group 1)
3163             (gnus-configure-windows 'group 'force))
3164         (gnus-handle-ephemeral-exit quit-config))
3165       ;; Finally signal the quit.
3166       (signal 'quit nil))
3167      ;; The group was successfully selected.
3168      (t
3169       (gnus-set-global-variables)
3170       ;; Save the active value in effect when the group was entered.
3171       (setq gnus-newsgroup-active
3172             (gnus-copy-sequence
3173              (gnus-active gnus-newsgroup-name)))
3174       ;; You can change the summary buffer in some way with this hook.
3175       (gnus-run-hooks 'gnus-select-group-hook)
3176       (gnus-update-format-specifications
3177        nil 'summary 'summary-mode 'summary-dummy)
3178       (gnus-update-summary-mark-positions)
3179       ;; Do score processing.
3180       (when gnus-use-scoring
3181         (gnus-possibly-score-headers))
3182       ;; Check whether to fill in the gaps in the threads.
3183       (when gnus-build-sparse-threads
3184         (gnus-build-sparse-threads))
3185       ;; Find the initial limit.
3186       (if gnus-show-threads
3187           (if show-all
3188               (let ((gnus-newsgroup-dormant nil))
3189                 (gnus-summary-initial-limit show-all))
3190             (gnus-summary-initial-limit show-all))
3191         ;; When untreaded, all articles are always shown.
3192         (setq gnus-newsgroup-limit
3193               (mapcar
3194                (lambda (header) (mail-header-number header))
3195                gnus-newsgroup-headers)))
3196       ;; Generate the summary buffer.
3197       (unless no-display
3198         (gnus-summary-prepare))
3199       (when gnus-use-trees
3200         (gnus-tree-open group)
3201         (setq gnus-summary-highlight-line-function
3202               'gnus-tree-highlight-article))
3203       ;; If the summary buffer is empty, but there are some low-scored
3204       ;; articles or some excluded dormants, we include these in the
3205       ;; buffer.
3206       (when (and (zerop (buffer-size))
3207                  (not no-display))
3208         (cond (gnus-newsgroup-dormant
3209                (gnus-summary-limit-include-dormant))
3210               ((and gnus-newsgroup-scored show-all)
3211                (gnus-summary-limit-include-expunged t))))
3212       ;; Function `gnus-apply-kill-file' must be called in this hook.
3213       (gnus-run-hooks 'gnus-apply-kill-hook)
3214       (if (and (zerop (buffer-size))
3215                (not no-display))
3216           (progn
3217             ;; This newsgroup is empty.
3218             (gnus-summary-catchup-and-exit nil t)
3219             (gnus-message 6 "No unread news")
3220             (when kill-buffer
3221               (gnus-kill-or-deaden-summary kill-buffer))
3222             ;; Return nil from this function.
3223             nil)
3224         ;; Hide conversation thread subtrees.  We cannot do this in
3225         ;; gnus-summary-prepare-hook since kill processing may not
3226         ;; work with hidden articles.
3227         (and gnus-show-threads
3228              gnus-thread-hide-subtree
3229              (gnus-summary-hide-all-threads))
3230         (when kill-buffer
3231           (gnus-kill-or-deaden-summary kill-buffer))
3232         ;; Show first unread article if requested.
3233         (if (and (not no-article)
3234                  (not no-display)
3235                  gnus-newsgroup-unreads
3236                  gnus-auto-select-first)
3237             (progn
3238               (gnus-configure-windows 'summary)
3239               (cond
3240                ((eq gnus-auto-select-first 'best)
3241                 (gnus-summary-best-unread-article))
3242                ((eq gnus-auto-select-first t)
3243                 (gnus-summary-first-unread-article))
3244                ((gnus-functionp gnus-auto-select-first)
3245                 (funcall gnus-auto-select-first))))
3246           ;; Don't select any articles, just move point to the first
3247           ;; article in the group.
3248           (goto-char (point-min))
3249           (gnus-summary-position-point)
3250           (gnus-configure-windows 'summary 'force)
3251           (gnus-set-mode-line 'summary))
3252         (when (get-buffer-window gnus-group-buffer t)
3253           ;; Gotta use windows, because recenter does weird stuff if
3254           ;; the current buffer ain't the displayed window.
3255           (let ((owin (selected-window)))
3256             (select-window (get-buffer-window gnus-group-buffer t))
3257             (when (gnus-group-goto-group group)
3258               (recenter))
3259             (select-window owin)))
3260         ;; Mark this buffer as "prepared".
3261         (setq gnus-newsgroup-prepared t)
3262         (gnus-run-hooks 'gnus-summary-prepared-hook)
3263         t)))))
3264
3265 (defun gnus-summary-prepare ()
3266   "Generate the summary buffer."
3267   (interactive)
3268   (let ((buffer-read-only nil))
3269     (erase-buffer)
3270     (setq gnus-newsgroup-data nil
3271           gnus-newsgroup-data-reverse nil)
3272     (gnus-run-hooks 'gnus-summary-generate-hook)
3273     ;; Generate the buffer, either with threads or without.
3274     (when gnus-newsgroup-headers
3275       (gnus-summary-prepare-threads
3276        (if gnus-show-threads
3277            (gnus-sort-gathered-threads
3278             (funcall gnus-summary-thread-gathering-function
3279                      (gnus-sort-threads
3280                       (gnus-cut-threads (gnus-make-threads)))))
3281          ;; Unthreaded display.
3282          (gnus-sort-articles gnus-newsgroup-headers))))
3283     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3284     ;; Call hooks for modifying summary buffer.
3285     (goto-char (point-min))
3286     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3287
3288 (defsubst gnus-general-simplify-subject (subject)
3289   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3290   (setq subject
3291         (cond
3292          ;; Truncate the subject.
3293          (gnus-simplify-subject-functions
3294           (gnus-map-function gnus-simplify-subject-functions subject))
3295          ((numberp gnus-summary-gather-subject-limit)
3296           (setq subject (gnus-simplify-subject-re subject))
3297           (if (> (length subject) gnus-summary-gather-subject-limit)
3298               (substring subject 0 gnus-summary-gather-subject-limit)
3299             subject))
3300          ;; Fuzzily simplify it.
3301          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3302           (gnus-simplify-subject-fuzzy subject))
3303          ;; Just remove the leading "Re:".
3304          (t
3305           (gnus-simplify-subject-re subject))))
3306
3307   (if (and gnus-summary-gather-exclude-subject
3308            (string-match gnus-summary-gather-exclude-subject subject))
3309       nil                         ; This article shouldn't be gathered
3310     subject))
3311
3312 (defun gnus-summary-simplify-subject-query ()
3313   "Query where the respool algorithm would put this article."
3314   (interactive)
3315   (gnus-summary-select-article)
3316   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3317
3318 (defun gnus-gather-threads-by-subject (threads)
3319   "Gather threads by looking at Subject headers."
3320   (if (not gnus-summary-make-false-root)
3321       threads
3322     (let ((hashtb (gnus-make-hashtable 1024))
3323           (prev threads)
3324           (result threads)
3325           subject hthread whole-subject)
3326       (while threads
3327         (setq subject (gnus-general-simplify-subject
3328                        (setq whole-subject (mail-header-subject
3329                                             (caar threads)))))
3330         (when subject
3331           (if (setq hthread (gnus-gethash subject hashtb))
3332               (progn
3333                 ;; We enter a dummy root into the thread, if we
3334                 ;; haven't done that already.
3335                 (unless (stringp (caar hthread))
3336                   (setcar hthread (list whole-subject (car hthread))))
3337                 ;; We add this new gathered thread to this gathered
3338                 ;; thread.
3339                 (setcdr (car hthread)
3340                         (nconc (cdar hthread) (list (car threads))))
3341                 ;; Remove it from the list of threads.
3342                 (setcdr prev (cdr threads))
3343                 (setq threads prev))
3344             ;; Enter this thread into the hash table.
3345             (gnus-sethash subject threads hashtb)))
3346         (setq prev threads)
3347         (setq threads (cdr threads)))
3348       result)))
3349
3350 (defun gnus-gather-threads-by-references (threads)
3351   "Gather threads by looking at References headers."
3352   (let ((idhashtb (gnus-make-hashtable 1024))
3353         (thhashtb (gnus-make-hashtable 1024))
3354         (prev threads)
3355         (result threads)
3356         ids references id gthread gid entered ref)
3357     (while threads
3358       (when (setq references (mail-header-references (caar threads)))
3359         (setq id (mail-header-id (caar threads))
3360               ids (gnus-split-references references)
3361               entered nil)
3362         (while (setq ref (pop ids))
3363           (setq ids (delete ref ids))
3364           (if (not (setq gid (gnus-gethash ref idhashtb)))
3365               (progn
3366                 (gnus-sethash ref id idhashtb)
3367                 (gnus-sethash id threads thhashtb))
3368             (setq gthread (gnus-gethash gid thhashtb))
3369             (unless entered
3370               ;; We enter a dummy root into the thread, if we
3371               ;; haven't done that already.
3372               (unless (stringp (caar gthread))
3373                 (setcar gthread (list (mail-header-subject (caar gthread))
3374                                       (car gthread))))
3375               ;; We add this new gathered thread to this gathered
3376               ;; thread.
3377               (setcdr (car gthread)
3378                       (nconc (cdar gthread) (list (car threads)))))
3379             ;; Add it into the thread hash table.
3380             (gnus-sethash id gthread thhashtb)
3381             (setq entered t)
3382             ;; Remove it from the list of threads.
3383             (setcdr prev (cdr threads))
3384             (setq threads prev))))
3385       (setq prev threads)
3386       (setq threads (cdr threads)))
3387     result))
3388
3389 (defun gnus-sort-gathered-threads (threads)
3390   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3391   (let ((result threads))
3392     (while threads
3393       (when (stringp (caar threads))
3394         (setcdr (car threads)
3395                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3396       (setq threads (cdr threads)))
3397     result))
3398
3399 (defun gnus-thread-loop-p (root thread)
3400   "Say whether ROOT is in THREAD."
3401   (let ((stack (list thread))
3402         (infloop 0)
3403         th)
3404     (while (setq thread (pop stack))
3405       (setq th (cdr thread))
3406       (while (and th
3407                   (not (eq (caar th) root)))
3408         (pop th))
3409       (if th
3410           ;; We have found a loop.
3411           (let (ref-dep)
3412             (setcdr thread (delq (car th) (cdr thread)))
3413             (if (boundp (setq ref-dep (intern "none"
3414                                               gnus-newsgroup-dependencies)))
3415                 (setcdr (symbol-value ref-dep)
3416                         (nconc (cdr (symbol-value ref-dep))
3417                                (list (car th))))
3418               (set ref-dep (list nil (car th))))
3419             (setq infloop 1
3420                   stack nil))
3421         ;; Push all the subthreads onto the stack.
3422         (push (cdr thread) stack)))
3423     infloop))
3424
3425 (defun gnus-make-threads ()
3426   "Go through the dependency hashtb and find the roots.  Return all threads."
3427   (let (threads)
3428     (while (catch 'infloop
3429              (mapatoms
3430               (lambda (refs)
3431                 ;; Deal with self-referencing References loops.
3432                 (when (and (car (symbol-value refs))
3433                            (not (zerop
3434                                  (apply
3435                                   '+
3436                                   (mapcar
3437                                    (lambda (thread)
3438                                      (gnus-thread-loop-p
3439                                       (car (symbol-value refs)) thread))
3440                                    (cdr (symbol-value refs)))))))
3441                   (setq threads nil)
3442                   (throw 'infloop t))
3443                 (unless (car (symbol-value refs))
3444              ;; These threads do not refer back to any other articles,
3445                   ;; so they're roots.
3446                   (setq threads (append (cdr (symbol-value refs)) threads))))
3447               gnus-newsgroup-dependencies)))
3448     threads))
3449
3450 ;; Build the thread tree.
3451 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3452   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3453
3454 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3455 if it was already present.
3456
3457 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3458 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3459 Message-IDs will be renamed be renamed to a unique Message-ID before
3460 being entered.
3461
3462 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3463   (let* ((id (mail-header-id header))
3464          (id-dep (and id (intern id dependencies)))
3465          ref ref-dep ref-header)
3466     ;; Enter this `header' in the `dependencies' table.
3467     (cond
3468      ((not id-dep)
3469       (setq header nil))
3470      ;; The first two cases do the normal part: enter a new `header'
3471      ;; in the `dependencies' table.
3472      ((not (boundp id-dep))
3473       (set id-dep (list header)))
3474      ((null (car (symbol-value id-dep)))
3475       (setcar (symbol-value id-dep) header))
3476
3477      ;; From here the `header' was already present in the
3478      ;; `dependencies' table.
3479      (force-new
3480       ;; Overrides an existing entry;
3481       ;; just set the header part of the entry.
3482       (setcar (symbol-value id-dep) header))
3483
3484      ;; Renames the existing `header' to a unique Message-ID.
3485      ((not gnus-summary-ignore-duplicates)
3486       ;; An article with this Message-ID has already been seen.
3487       ;; We rename the Message-ID.
3488       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3489            (list header))
3490       (mail-header-set-id header id))
3491
3492      ;; The last case ignores an existing entry, except it adds any
3493      ;; additional Xrefs (in case the two articles came from different
3494      ;; servers.
3495      ;; Also sets `header' to `nil' meaning that the `dependencies'
3496      ;; table was *not* modified.
3497      (t
3498       (mail-header-set-xref
3499        (car (symbol-value id-dep))
3500        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3501                    "")
3502                (or (mail-header-xref header) "")))
3503       (setq header nil)))
3504
3505     (when header
3506       ;; First check if that we are not creating a References loop.
3507       (setq ref (gnus-parent-id (mail-header-references header)))
3508       (while (and ref
3509                   (setq ref-dep (intern-soft ref dependencies))
3510                   (boundp ref-dep)
3511                   (setq ref-header (car (symbol-value ref-dep))))
3512         (if (string= id ref)
3513             ;; Yuk!  This is a reference loop.  Make the article be a
3514             ;; root article.
3515             (progn
3516               (mail-header-set-references (car (symbol-value id-dep)) "none")
3517               (setq ref nil))
3518           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3519       (setq ref (gnus-parent-id (mail-header-references header)))
3520       (setq ref-dep (intern (or ref "none") dependencies))
3521       (if (boundp ref-dep)
3522           (setcdr (symbol-value ref-dep)
3523                   (nconc (cdr (symbol-value ref-dep))
3524                          (list (symbol-value id-dep))))
3525         (set ref-dep (list nil (symbol-value id-dep)))))
3526     header))
3527
3528 (defun gnus-build-sparse-threads ()
3529   (let ((headers gnus-newsgroup-headers)
3530         (mail-parse-charset gnus-newsgroup-charset)
3531         (gnus-summary-ignore-duplicates t)
3532         header references generation relations
3533         subject child end new-child date)
3534     ;; First we create an alist of generations/relations, where
3535     ;; generations is how much we trust the relation, and the relation
3536     ;; is parent/child.
3537     (gnus-message 7 "Making sparse threads...")
3538     (save-excursion
3539       (nnheader-set-temp-buffer " *gnus sparse threads*")
3540       (while (setq header (pop headers))
3541         (when (and (setq references (mail-header-references header))
3542                    (not (string= references "")))
3543           (insert references)
3544           (setq child (mail-header-id header)
3545                 subject (mail-header-subject header)
3546                 date (mail-header-date header)
3547                 generation 0)
3548           (while (search-backward ">" nil t)
3549             (setq end (1+ (point)))
3550             (when (search-backward "<" nil t)
3551               (setq new-child (buffer-substring (point) end))
3552               (push (list (incf generation)
3553                           child (setq child new-child)
3554                           subject date)
3555                     relations)))
3556           (when child
3557             (push (list (1+ generation) child nil subject) relations))
3558           (erase-buffer)))
3559       (kill-buffer (current-buffer)))
3560     ;; Sort over trustworthiness.
3561     (mapcar
3562      (lambda (relation)
3563        (when (gnus-dependencies-add-header
3564               (make-full-mail-header
3565                gnus-reffed-article-number
3566                (nth 3 relation) "" (or (nth 4 relation) "")
3567                (nth 1 relation)
3568                (or (nth 2 relation) "") 0 0 "")
3569               gnus-newsgroup-dependencies nil)
3570          (push gnus-reffed-article-number gnus-newsgroup-limit)
3571          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3572          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3573                gnus-newsgroup-reads)
3574          (decf gnus-reffed-article-number)))
3575      (sort relations 'car-less-than-car))
3576     (gnus-message 7 "Making sparse threads...done")))
3577
3578 (defun gnus-build-old-threads ()
3579   ;; Look at all the articles that refer back to old articles, and
3580   ;; fetch the headers for the articles that aren't there.  This will
3581   ;; build complete threads - if the roots haven't been expired by the
3582   ;; server, that is.
3583   (let ((mail-parse-charset gnus-newsgroup-charset)
3584         id heads)
3585     (mapatoms
3586      (lambda (refs)
3587        (when (not (car (symbol-value refs)))
3588          (setq heads (cdr (symbol-value refs)))
3589          (while heads
3590            (if (memq (mail-header-number (caar heads))
3591                      gnus-newsgroup-dormant)
3592                (setq heads (cdr heads))
3593              (setq id (symbol-name refs))
3594              (while (and (setq id (gnus-build-get-header id))
3595                          (not (car (gnus-id-to-thread id)))))
3596              (setq heads nil)))))
3597      gnus-newsgroup-dependencies)))
3598
3599 ;; This function has to be called with point after the article number
3600 ;; on the beginning of the line.
3601 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3602   (let ((eol (gnus-point-at-eol))
3603         (buffer (current-buffer))
3604         header)
3605
3606     ;; overview: [num subject from date id refs chars lines misc]
3607     (unwind-protect
3608         (progn
3609           (narrow-to-region (point) eol)
3610           (unless (eobp)
3611             (forward-char))
3612
3613           (setq header
3614                 (make-full-mail-header
3615                  number                 ; number
3616                  (funcall gnus-decode-encoded-word-function
3617                           (nnheader-nov-field)) ; subject
3618                  (funcall gnus-decode-encoded-word-function
3619                           (nnheader-nov-field)) ; from
3620                  (nnheader-nov-field)   ; date
3621                  (nnheader-nov-read-message-id) ; id
3622                  (nnheader-nov-field)   ; refs
3623                  (nnheader-nov-read-integer) ; chars
3624                  (nnheader-nov-read-integer) ; lines
3625                  (unless (eobp)
3626                    (if (looking-at "Xref: ")
3627                        (goto-char (match-end 0)))
3628                    (nnheader-nov-field)) ; Xref
3629                  (nnheader-nov-parse-extra)))) ; extra
3630
3631       (widen))
3632
3633     (when gnus-alter-header-function
3634       (funcall gnus-alter-header-function header))
3635     (gnus-dependencies-add-header header dependencies force-new)))
3636
3637 (defun gnus-build-get-header (id)
3638   "Look through the buffer of NOV lines and find the header to ID.
3639 Enter this line into the dependencies hash table, and return
3640 the id of the parent article (if any)."
3641   (let ((deps gnus-newsgroup-dependencies)
3642         found header)
3643     (prog1
3644         (save-excursion
3645           (set-buffer nntp-server-buffer)
3646           (let ((case-fold-search nil))
3647             (goto-char (point-min))
3648             (while (and (not found)
3649                         (search-forward id nil t))
3650               (beginning-of-line)
3651               (setq found (looking-at
3652                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3653                                    (regexp-quote id))))
3654               (or found (beginning-of-line 2)))
3655             (when found
3656               (beginning-of-line)
3657               (and
3658                (setq header (gnus-nov-parse-line
3659                              (read (current-buffer)) deps))
3660                (gnus-parent-id (mail-header-references header))))))
3661       (when header
3662         (let ((number (mail-header-number header)))
3663           (push number gnus-newsgroup-limit)
3664           (push header gnus-newsgroup-headers)
3665           (if (memq number gnus-newsgroup-unselected)
3666               (progn
3667                 (push number gnus-newsgroup-unreads)
3668                 (setq gnus-newsgroup-unselected
3669                       (delq number gnus-newsgroup-unselected)))
3670             (push number gnus-newsgroup-ancient)))))))
3671
3672 (defun gnus-build-all-threads ()
3673   "Read all the headers."
3674   (let ((gnus-summary-ignore-duplicates t)
3675         (mail-parse-charset gnus-newsgroup-charset)
3676         (dependencies gnus-newsgroup-dependencies)
3677         header article)
3678     (save-excursion
3679       (set-buffer nntp-server-buffer)
3680       (let ((case-fold-search nil))
3681         (goto-char (point-min))
3682         (while (not (eobp))
3683           (ignore-errors
3684             (setq article (read (current-buffer))
3685                   header (gnus-nov-parse-line article dependencies)))
3686           (when header
3687             (save-excursion
3688               (set-buffer gnus-summary-buffer)
3689               (push header gnus-newsgroup-headers)
3690               (if (memq (setq article (mail-header-number header))
3691                         gnus-newsgroup-unselected)
3692                   (progn
3693                     (push article gnus-newsgroup-unreads)
3694                     (setq gnus-newsgroup-unselected
3695                           (delq article gnus-newsgroup-unselected)))
3696                 (push article gnus-newsgroup-ancient)))
3697             (forward-line 1)))))))
3698
3699 (defun gnus-summary-update-article-line (article header)
3700   "Update the line for ARTICLE using HEADERS."
3701   (let* ((id (mail-header-id header))
3702          (thread (gnus-id-to-thread id)))
3703     (unless thread
3704       (error "Article in no thread"))
3705     ;; Update the thread.
3706     (setcar thread header)
3707     (gnus-summary-goto-subject article)
3708     (let* ((datal (gnus-data-find-list article))
3709            (data (car datal))
3710            (length (when (cdr datal)
3711                      (- (gnus-data-pos data)
3712                         (gnus-data-pos (cadr datal)))))
3713            (buffer-read-only nil)
3714            (level (gnus-summary-thread-level)))
3715       (gnus-delete-line)
3716       (gnus-summary-insert-line
3717        header level nil (gnus-article-mark article)
3718        (memq article gnus-newsgroup-replied)
3719        (memq article gnus-newsgroup-expirable)
3720        ;; Only insert the Subject string when it's different
3721        ;; from the previous Subject string.
3722        (if (and
3723             gnus-show-threads
3724             (gnus-subject-equal
3725              (condition-case ()
3726                  (mail-header-subject
3727                   (gnus-data-header
3728                    (cadr
3729                     (gnus-data-find-list
3730                      article
3731                      (gnus-data-list t)))))
3732                ;; Error on the side of excessive subjects.
3733                (error ""))
3734              (mail-header-subject header)))
3735            ""
3736          (mail-header-subject header))
3737        nil (cdr (assq article gnus-newsgroup-scored))
3738        (memq article gnus-newsgroup-processable))
3739       (when length
3740         (gnus-data-update-list
3741          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3742
3743 (defun gnus-summary-update-article (article &optional iheader)
3744   "Update ARTICLE in the summary buffer."
3745   (set-buffer gnus-summary-buffer)
3746   (let* ((header (gnus-summary-article-header article))
3747          (id (mail-header-id header))
3748          (data (gnus-data-find article))
3749          (thread (gnus-id-to-thread id))
3750          (references (mail-header-references header))
3751          (parent
3752           (gnus-id-to-thread
3753            (or (gnus-parent-id
3754                 (when (and references
3755                            (not (equal "" references)))
3756                   references))
3757                "none")))
3758          (buffer-read-only nil)
3759          (old (car thread)))
3760     (when thread
3761       (unless iheader
3762         (setcar thread nil)
3763         (when parent
3764           (delq thread parent)))
3765       (if (gnus-summary-insert-subject id header)
3766        ;; Set the (possibly) new article number in the data structure.
3767           (gnus-data-set-number data (gnus-id-to-article id))
3768         (setcar thread old)
3769         nil))))
3770
3771 (defun gnus-rebuild-thread (id &optional line)
3772   "Rebuild the thread containing ID.
3773 If LINE, insert the rebuilt thread starting on line LINE."
3774   (let ((buffer-read-only nil)
3775         old-pos current thread data)
3776     (if (not gnus-show-threads)
3777         (setq thread (list (car (gnus-id-to-thread id))))