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