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