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