Synch to No Gnus 200405230007.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile
32   (require 'cl)
33   (defvar tool-bar-map))
34
35 (require 'gnus)
36 (require 'gnus-group)
37 (require 'gnus-spec)
38 (require 'gnus-range)
39 (require 'gnus-int)
40 (require 'gnus-undo)
41 (require 'gnus-util)
42 (require 'nnoo)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
55 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
56 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
59   "Deuglify broken Outlook (Express) articles and redisplay."
60   t)
61 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
62 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
63 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
64
65 (defcustom gnus-kill-summary-on-exit t
66   "*If non-nil, kill the summary buffer when you exit from it.
67 If nil, the summary will become a \"*Dead Summary*\" buffer, and
68 it will be killed sometime later."
69   :group 'gnus-summary-exit
70   :type 'boolean)
71
72 (defcustom gnus-fetch-old-headers nil
73   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
74 If an unread article in the group refers to an older, already read (or
75 just marked as read) article, the old article will not normally be
76 displayed in the Summary buffer.  If this variable is non-nil, Gnus
77 will attempt to grab the headers to the old articles, and thereby
78 build complete threads.  If it has the value `some', only enough
79 headers to connect otherwise loose threads will be displayed.  This
80 variable can also be a number.  In that case, no more than that number
81 of old headers will be fetched.  If it has the value `invisible', all
82 old headers will be fetched, but none will be displayed.
83
84 The server has to support NOV for any of this to work."
85   :group 'gnus-thread
86   :type '(choice (const :tag "off" nil)
87                  (const some)
88                  number
89                  (sexp :menu-tag "other" t)))
90
91 (defcustom gnus-refer-thread-limit 200
92   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
93 If t, fetch all the available old headers."
94   :group 'gnus-thread
95   :type '(choice number
96                  (sexp :menu-tag "other" t)))
97
98 (defcustom gnus-summary-make-false-root 'adopt
99   "*nil means that Gnus won't gather loose threads.
100 If the root of a thread has expired or been read in a previous
101 session, the information necessary to build a complete thread has been
102 lost.  Instead of having many small sub-threads from this original thread
103 scattered all over the summary buffer, Gnus can gather them.
104
105 If non-nil, Gnus will try to gather all loose sub-threads from an
106 original thread into one large thread.
107
108 If this variable is non-nil, it should be one of `none', `adopt',
109 `dummy' or `empty'.
110
111 If this variable is `none', Gnus will not make a false root, but just
112 present the sub-threads after another.
113 If this variable is `dummy', Gnus will create a dummy root that will
114 have all the sub-threads as children.
115 If this variable is `adopt', Gnus will make one of the \"children\"
116 the parent and mark all the step-children as such.
117 If this variable is `empty', the \"children\" are printed with empty
118 subject fields.  (Or rather, they will be printed with a string
119 given by the `gnus-summary-same-subject' variable.)"
120   :group 'gnus-thread
121   :type '(choice (const :tag "off" nil)
122                  (const none)
123                  (const dummy)
124                  (const adopt)
125                  (const empty)))
126
127 (defcustom gnus-summary-make-false-root-always nil
128   "Always make a false dummy root."
129   :group 'gnus-thread
130   :type 'boolean)
131
132 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
133   "*A regexp to match subjects to be excluded from loose thread gathering.
134 As loose thread gathering is done on subjects only, that means that
135 there can be many false gatherings performed.  By rooting out certain
136 common subjects, gathering might become saner."
137   :group 'gnus-thread
138   :type 'regexp)
139
140 (defcustom gnus-summary-gather-subject-limit nil
141   "*Maximum length of subject comparisons when gathering loose threads.
142 Use nil to compare full subjects.  Setting this variable to a low
143 number will help gather threads that have been corrupted by
144 newsreaders chopping off subject lines, but it might also mean that
145 unrelated articles that have subject that happen to begin with the
146 same few characters will be incorrectly gathered.
147
148 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
149 comparing subjects."
150   :group 'gnus-thread
151   :type '(choice (const :tag "off" nil)
152                  (const fuzzy)
153                  (sexp :menu-tag "on" t)))
154
155 (defcustom gnus-simplify-subject-functions nil
156   "List of functions taking a string argument that simplify subjects.
157 The functions are applied recursively.
158
159 Useful functions to put in this list include:
160 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
161 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
162   :group 'gnus-thread
163   :type '(repeat function))
164
165 (defcustom gnus-simplify-ignored-prefixes nil
166   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  regexp))
170
171 (defcustom gnus-build-sparse-threads nil
172   "*If non-nil, fill in the gaps in threads.
173 If `some', only fill in the gaps that are needed to tie loose threads
174 together.  If `more', fill in all leaf nodes that Gnus can find.  If
175 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
176   :group 'gnus-thread
177   :type '(choice (const :tag "off" nil)
178                  (const some)
179                  (const more)
180                  (sexp :menu-tag "all" t)))
181
182 (defcustom gnus-summary-thread-gathering-function
183   'gnus-gather-threads-by-subject
184   "*Function used for gathering loose threads.
185 There are two pre-defined functions: `gnus-gather-threads-by-subject',
186 which only takes Subjects into consideration; and
187 `gnus-gather-threads-by-references', which compared the References
188 headers of the articles to find matches."
189   :group 'gnus-thread
190   :type '(radio (function-item gnus-gather-threads-by-subject)
191                 (function-item gnus-gather-threads-by-references)
192                 (function :tag "other")))
193
194 (defcustom gnus-summary-same-subject ""
195   "*String indicating that the current article has the same subject as the previous.
196 This variable will only be used if the value of
197 `gnus-summary-make-false-root' is `empty'."
198   :group 'gnus-summary-format
199   :type 'string)
200
201 (defcustom gnus-summary-goto-unread t
202   "*If t, many commands will go to the next unread article.
203 This applies to marking commands as well as other commands that
204 \"naturally\" select the next article, like, for instance, `SPC' at
205 the end of an article.
206
207 If nil, the marking commands do NOT go to the next unread article
208 \(they go to the next article instead).  If `never', commands that
209 usually go to the next unread article, will go to the next article,
210 whether it is read or not."
211   :group 'gnus-summary-marks
212   :link '(custom-manual "(gnus)Setting Marks")
213   :type '(choice (const :tag "off" nil)
214                  (const never)
215                  (sexp :menu-tag "on" t)))
216
217 (defcustom gnus-summary-default-score 0
218   "*Default article score level.
219 All scores generated by the score files will be added to this score.
220 If this variable is nil, scoring will be disabled."
221   :group 'gnus-score-default
222   :type '(choice (const :tag "disable")
223                  integer))
224
225 (defcustom gnus-summary-default-high-score 0
226   "*Default threshold for a high scored article.
227 An article will be highlighted as high scored if its score is greater
228 than this score."
229   :group 'gnus-score-default
230   :type 'integer)
231
232 (defcustom gnus-summary-default-low-score 0
233   "*Default threshold for a low scored article.
234 An article will be highlighted as low scored if its score is smaller
235 than this score."
236   :group 'gnus-score-default
237   :type 'integer)
238
239 (defcustom gnus-summary-zcore-fuzz 0
240   "*Fuzziness factor for the zcore in the summary buffer.
241 Articles with scores closer than this to `gnus-summary-default-score'
242 will not be marked."
243   :group 'gnus-summary-format
244   :type 'integer)
245
246 (defcustom gnus-simplify-subject-fuzzy-regexp nil
247   "*Strings to be removed when doing fuzzy matches.
248 This can either be a regular expression or list of regular expressions
249 that will be removed from subject strings if fuzzy subject
250 simplification is selected."
251   :group 'gnus-thread
252   :type '(repeat regexp))
253
254 (defcustom gnus-show-threads t
255   "*If non-nil, display threads in summary mode."
256   :group 'gnus-thread
257   :type 'boolean)
258
259 (defcustom gnus-thread-hide-subtree nil
260   "*If non-nil, hide all threads initially.
261 This can be a predicate specifier which says which threads to hide.
262 If threads are hidden, you have to run the command
263 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
264 to expose hidden threads."
265   :group 'gnus-thread
266   :type '(radio (sexp :format "Non-nil\n"
267                       :match (lambda (widget value)
268                                (not (or (consp value) (functionp value))))
269                       :value t)
270                 (const nil)
271                 (sexp :tag "Predicate specifier" :size 0)))
272
273 (defcustom gnus-thread-hide-killed t
274   "*If non-nil, hide killed threads automatically."
275   :group 'gnus-thread
276   :type 'boolean)
277
278 (defcustom gnus-thread-ignore-subject t
279   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
280 If nil, articles that have different subjects from their parents will
281 start separate threads."
282   :group 'gnus-thread
283   :type 'boolean)
284
285 (defcustom gnus-thread-operation-ignore-subject t
286   "*If non-nil, subjects will be ignored when doing thread commands.
287 This affects commands like `gnus-summary-kill-thread' and
288 `gnus-summary-lower-thread'.
289
290 If this variable is nil, articles in the same thread with different
291 subjects will not be included in the operation in question.  If this
292 variable is `fuzzy', only articles that have subjects that are fuzzily
293 equal will be included."
294   :group 'gnus-thread
295   :type '(choice (const :tag "off" nil)
296                  (const fuzzy)
297                  (sexp :tag "on" t)))
298
299 (defcustom gnus-thread-indent-level 4
300   "*Number that says how much each sub-thread should be indented."
301   :group 'gnus-thread
302   :type 'integer)
303
304 (defcustom gnus-auto-extend-newsgroup t
305   "*If non-nil, extend newsgroup forward and backward when requested."
306   :group 'gnus-summary-choose
307   :type 'boolean)
308
309 (defcustom gnus-auto-select-first t
310   "*If non-nil, select the article under point.
311 Which article this is is controlled by the `gnus-auto-select-subject'
312 variable.
313
314 If you want to prevent automatic selection of articles in some
315 newsgroups, set the variable to nil in `gnus-select-group-hook'."
316   :group 'gnus-group-select
317   :type '(choice (const :tag "none" nil)
318                  (sexp :menu-tag "first" t)))
319
320 (defcustom gnus-auto-select-subject 'unread
321   "*Says what subject to place under point when entering a group.
322
323 This variable can either be the symbols `first' (place point on the
324 first subject), `unread' (place point on the subject line of the first
325 unread article), `best' (place point on the subject line of the
326 higest-scored article), `unseen' (place point on the subject line of
327 the first unseen article), 'unseen-or-unread' (place point on the subject
328 line of the first unseen article or, if all article have been seen, on the
329 subject line of the first unread article), or a function to be called to
330 place point on some subject line."
331   :group 'gnus-group-select
332   :type '(choice (const best)
333                  (const unread)
334                  (const first)
335                  (const unseen)
336                  (const unseen-or-unread)))
337
338 (defcustom gnus-dont-select-after-jump-to-other-group nil
339   "If non-nil, don't select the first unread article after entering the
340 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
341 it is depend on the value of `gnus-auto-select-first' whether to select
342 or not."
343   :group 'gnus-group-select
344   :type 'boolean)
345
346 (defcustom gnus-auto-select-next t
347   "*If non-nil, offer to go to the next group from the end of the previous.
348 If the value is t and the next newsgroup is empty, Gnus will exit
349 summary mode and go back to group mode.  If the value is neither nil
350 nor t, Gnus will select the following unread newsgroup.  In
351 particular, if the value is the symbol `quietly', the next unread
352 newsgroup will be selected without any confirmation, and if it is
353 `almost-quietly', the next group will be selected without any
354 confirmation if you are located on the last article in the group.
355 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
356 will go to the next group without confirmation."
357   :group 'gnus-summary-maneuvering
358   :type '(choice (const :tag "off" nil)
359                  (const quietly)
360                  (const almost-quietly)
361                  (const slightly-quietly)
362                  (sexp :menu-tag "on" t)))
363
364 (defcustom gnus-auto-select-same nil
365   "*If non-nil, select the next article with the same subject.
366 If there are no more articles with the same subject, go to
367 the first unread article."
368   :group 'gnus-summary-maneuvering
369   :type 'boolean)
370
371 (defcustom gnus-auto-goto-ignores 'unfetched
372   "*Says how to handle unfetched articles when maneuvering.
373
374 This variable can either be the symbols nil (maneuver to any
375 article), `undownloaded' (maneuvering while unplugged ignores articles
376 that have not been fetched), `always-undownloaded' (maneuvering always
377 ignores articles that have not been fetched), `unfetched' (maneuvering
378 ignores articles whose headers have not been fetched).
379
380 NOTE: The list of unfetched articles will always be nil when plugged
381 and, when unplugged, a subset of the undownloaded article list."
382   :group 'gnus-summary-maneuvering
383   :type '(choice (const :tag "None" nil)
384                  (const :tag "Undownloaded when unplugged" undownloaded)
385                  (const :tag "Undownloaded" always-undownloaded)
386                  (const :tag "Unfetched" unfetched)))
387
388 (defcustom gnus-summary-check-current nil
389   "*If non-nil, consider the current article when moving.
390 The \"unread\" movement commands will stay on the same line if the
391 current article is unread."
392   :group 'gnus-summary-maneuvering
393   :type 'boolean)
394
395 (defcustom gnus-auto-center-summary t
396   "*If non-nil, always center the current summary buffer.
397 In particular, if `vertical' do only vertical recentering.  If non-nil
398 and non-`vertical', do both horizontal and vertical recentering."
399   :group 'gnus-summary-maneuvering
400   :type '(choice (const :tag "none" nil)
401                  (const vertical)
402                  (integer :tag "height")
403                  (sexp :menu-tag "both" t)))
404
405 (defvar gnus-auto-center-group t
406   "*If non-nil, always center the group buffer.")
407
408 (defcustom gnus-show-all-headers nil
409   "*If non-nil, don't hide any headers."
410   :group 'gnus-article-hiding
411   :group 'gnus-article-headers
412   :type 'boolean)
413
414 (defcustom gnus-summary-ignore-duplicates nil
415   "*If non-nil, ignore articles with identical Message-ID headers."
416   :group 'gnus-summary
417   :type 'boolean)
418
419 (defcustom gnus-single-article-buffer t
420   "*If non-nil, display all articles in the same buffer.
421 If nil, each group will get its own article buffer."
422   :group 'gnus-article-various
423   :type 'boolean)
424
425 (defcustom gnus-break-pages t
426   "*If non-nil, do page breaking on articles.
427 The page delimiter is specified by the `gnus-page-delimiter'
428 variable."
429   :group 'gnus-article-various
430   :type 'boolean)
431
432 (defcustom gnus-show-mime t
433   "*If non-nil, do mime processing of articles.
434 The articles will simply be fed to the function given by
435 `gnus-article-display-method-for-mime'."
436   :group 'gnus-article-mime
437   :type 'boolean)
438
439 (defcustom gnus-move-split-methods nil
440   "*Variable used to suggest where articles are to be moved to.
441 It uses the same syntax as the `gnus-split-methods' variable.
442 However, whereas `gnus-split-methods' specifies file names as targets,
443 this variable specifies group names."
444   :group 'gnus-summary-mail
445   :type '(repeat (choice (list :value (fun) function)
446                          (cons :value ("" "") regexp (repeat string))
447                          (sexp :value nil))))
448
449 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
450   "Function used to compute default prefix for article move/copy/etc prompts.
451 The function should take one argument, a group name, and return a
452 string with the suggested prefix."
453   :group 'gnus-summary-mail
454   :type 'function)
455
456 (defcustom gnus-unread-mark ?\ ;;;Whitespace
457   "*Mark used for unread articles."
458   :group 'gnus-summary-marks
459   :type 'character)
460
461 (defcustom gnus-ticked-mark ?!
462   "*Mark used for ticked articles."
463   :group 'gnus-summary-marks
464   :type 'character)
465
466 (defcustom gnus-dormant-mark ??
467   "*Mark used for dormant articles."
468   :group 'gnus-summary-marks
469   :type 'character)
470
471 (defcustom gnus-del-mark ?r
472   "*Mark used for del'd articles."
473   :group 'gnus-summary-marks
474   :type 'character)
475
476 (defcustom gnus-read-mark ?R
477   "*Mark used for read articles."
478   :group 'gnus-summary-marks
479   :type 'character)
480
481 (defcustom gnus-expirable-mark ?E
482   "*Mark used for expirable articles."
483   :group 'gnus-summary-marks
484   :type 'character)
485
486 (defcustom gnus-killed-mark ?K
487   "*Mark used for killed articles."
488   :group 'gnus-summary-marks
489   :type 'character)
490
491 (defcustom gnus-spam-mark ?$
492   "*Mark used for spam articles."
493   :group 'gnus-summary-marks
494   :type 'character)
495
496 (defcustom gnus-souped-mark ?F
497   "*Mark used for souped articles."
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-kill-file-mark ?X
502   "*Mark used for articles killed by kill files."
503   :group 'gnus-summary-marks
504   :type 'character)
505
506 (defcustom gnus-low-score-mark ?Y
507   "*Mark used for articles with a low score."
508   :group 'gnus-summary-marks
509   :type 'character)
510
511 (defcustom gnus-catchup-mark ?C
512   "*Mark used for articles that are caught up."
513   :group 'gnus-summary-marks
514   :type 'character)
515
516 (defcustom gnus-replied-mark ?A
517   "*Mark used for articles that have been replied to."
518   :group 'gnus-summary-marks
519   :type 'character)
520
521 (defcustom gnus-forwarded-mark ?F
522   "*Mark used for articles that have been forwarded."
523   :group 'gnus-summary-marks
524   :type 'character)
525
526 (defcustom gnus-recent-mark ?N
527   "*Mark used for articles that are recent."
528   :group 'gnus-summary-marks
529   :type 'character)
530
531 (defcustom gnus-cached-mark ?*
532   "*Mark used for articles that are in the cache."
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-saved-mark ?S
537   "*Mark used for articles that have been saved."
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-unseen-mark ?.
542   "*Mark used for articles that haven't been seen."
543   :group 'gnus-summary-marks
544   :type 'character)
545
546 (defcustom gnus-no-mark ?\ ;;;Whitespace
547   "*Mark used for articles that have no other secondary mark."
548   :group 'gnus-summary-marks
549   :type 'character)
550
551 (defcustom gnus-ancient-mark ?O
552   "*Mark used for ancient articles."
553   :group 'gnus-summary-marks
554   :type 'character)
555
556 (defcustom gnus-sparse-mark ?Q
557   "*Mark used for sparsely reffed articles."
558   :group 'gnus-summary-marks
559   :type 'character)
560
561 (defcustom gnus-canceled-mark ?G
562   "*Mark used for canceled articles."
563   :group 'gnus-summary-marks
564   :type 'character)
565
566 (defcustom gnus-duplicate-mark ?M
567   "*Mark used for duplicate articles."
568   :group 'gnus-summary-marks
569   :type 'character)
570
571 (defcustom gnus-undownloaded-mark ?-
572   "*Mark used for articles that weren't downloaded."
573   :group 'gnus-summary-marks
574   :type 'character)
575
576 (defcustom gnus-downloaded-mark ?+
577   "*Mark used for articles that were downloaded."
578   :group 'gnus-summary-marks
579   :type 'character)
580
581 (defcustom gnus-downloadable-mark ?%
582   "*Mark used for articles that are to be downloaded."
583   :group 'gnus-summary-marks
584   :type 'character)
585
586 (defcustom gnus-unsendable-mark ?=
587   "*Mark used for articles that won't be sent."
588   :group 'gnus-summary-marks
589   :type 'character)
590
591 (defcustom gnus-score-over-mark ?+
592   "*Score mark used for articles with high scores."
593   :group 'gnus-summary-marks
594   :type 'character)
595
596 (defcustom gnus-score-below-mark ?-
597   "*Score mark used for articles with low scores."
598   :group 'gnus-summary-marks
599   :type 'character)
600
601 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
602   "*There is no thread under the article."
603   :group 'gnus-summary-marks
604   :type 'character)
605
606 (defcustom gnus-not-empty-thread-mark ?=
607   "*There is a thread under the article."
608   :group 'gnus-summary-marks
609   :type 'character)
610
611 (defcustom gnus-view-pseudo-asynchronously nil
612   "*If non-nil, Gnus will view pseudo-articles asynchronously."
613   :group 'gnus-extract-view
614   :type 'boolean)
615
616 (defcustom gnus-auto-expirable-marks
617   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
618         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
619         gnus-souped-mark gnus-duplicate-mark)
620   "*The list of marks converted into expiration if a group is auto-expirable."
621   :version "21.1"
622   :group 'gnus-summary
623   :type '(repeat character))
624
625 (defcustom gnus-inhibit-user-auto-expire t
626   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
627   :version "21.1"
628   :group 'gnus-summary
629   :type 'boolean)
630
631 (defcustom gnus-view-pseudos nil
632   "*If `automatic', pseudo-articles will be viewed automatically.
633 If `not-confirm', pseudos will be viewed automatically, and the user
634 will not be asked to confirm the command."
635   :group 'gnus-extract-view
636   :type '(choice (const :tag "off" nil)
637                  (const automatic)
638                  (const not-confirm)))
639
640 (defcustom gnus-view-pseudos-separately t
641   "*If non-nil, one pseudo-article will be created for each file to be viewed.
642 If nil, all files that use the same viewing command will be given as a
643 list of parameters to that command."
644   :group 'gnus-extract-view
645   :type 'boolean)
646
647 (defcustom gnus-insert-pseudo-articles t
648   "*If non-nil, insert pseudo-articles when decoding articles."
649   :group 'gnus-extract-view
650   :type 'boolean)
651
652 (defcustom gnus-summary-dummy-line-format
653   "   %(:                             :%) %S\n"
654   "*The format specification for the dummy roots in the summary buffer.
655 It works along the same lines as a normal formatting string,
656 with some simple extensions.
657
658 %S  The subject
659
660 General format specifiers can also be used.
661 See `(gnus)Formatting Variables'."
662   :link '(custom-manual "(gnus)Formatting Variables")
663   :group 'gnus-threading
664   :type 'string)
665
666 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
667   "*The format specification for the summary mode line.
668 It works along the same lines as a normal formatting string,
669 with some simple extensions:
670
671 %G  Group name
672 %p  Unprefixed group name
673 %A  Current article number
674 %z  Current article score
675 %V  Gnus version
676 %U  Number of unread articles in the group
677 %e  Number of unselected articles in the group
678 %Z  A string with unread/unselected article counts
679 %g  Shortish group name
680 %S  Subject of the current article
681 %u  User-defined spec
682 %s  Current score file name
683 %d  Number of dormant articles
684 %r  Number of articles that have been marked as read in this session
685 %E  Number of articles expunged by the score files"
686   :group 'gnus-summary-format
687   :type 'string)
688
689 (defcustom gnus-list-identifiers nil
690   "Regexp that matches list identifiers to be removed from subject.
691 This can also be a list of regexps."
692   :version "21.1"
693   :group 'gnus-summary-format
694   :group 'gnus-article-hiding
695   :type '(choice (const :tag "none" nil)
696                  (regexp :value ".*")
697                  (repeat :value (".*") regexp)))
698
699 (defcustom gnus-summary-mark-below 0
700   "*Mark all articles with a score below this variable as read.
701 This variable is local to each summary buffer and usually set by the
702 score file."
703   :group 'gnus-score-default
704   :type 'integer)
705
706 (defun gnus-widget-reversible-match (widget value)
707   "Ignoring WIDGET, convert VALUE to internal form.
708 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
709   ;; (debug value)
710   (or (symbolp value)
711       (and (listp value)
712            (eq (length value) 2)
713            (eq (nth 0 value) 'not)
714            (symbolp (nth 1 value)))))
715
716 (defun gnus-widget-reversible-to-internal (widget value)
717   "Ignoring WIDGET, convert VALUE to internal form.
718 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
719 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
720   ;; (debug value)
721   (if (atom value)
722       (list value nil)
723     (list (nth 1 value) t)))
724
725 (defun gnus-widget-reversible-to-external (widget value)
726   "Ignoring WIDGET, convert VALUE to external form.
727 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
728 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
729   ;; (debug value)
730   (if (nth 1 value)
731       (list 'not (nth 0 value))
732     (nth 0 value)))
733
734 (define-widget 'gnus-widget-reversible 'group
735   "A `group' that convert values."
736   :match 'gnus-widget-reversible-match
737   :value-to-internal 'gnus-widget-reversible-to-internal
738   :value-to-external 'gnus-widget-reversible-to-external)
739                         
740
741 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
742   "*List of functions used for sorting articles in the summary buffer.
743
744 Each function takes two articles and returns non-nil if the first
745 article should be sorted before the other.  If you use more than one
746 function, the primary sort function should be the last.  You should
747 probably always include `gnus-article-sort-by-number' in the list of
748 sorting functions -- preferably first.  Also note that sorting by date
749 is often much slower than sorting by number, and the sorting order is
750 very similar.  (Sorting by date means sorting by the time the message
751 was sent, sorting by number means sorting by arrival time.)
752
753 Each item can also be a list `(not F)' where F is a function;
754 this reverses the sort order.
755
756 Ready-made functions include `gnus-article-sort-by-number',
757 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
758 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
759 and `gnus-article-sort-by-score'.
760
761 When threading is turned on, the variable `gnus-thread-sort-functions'
762 controls how articles are sorted."
763   :group 'gnus-summary-sort
764   :type '(repeat (gnus-widget-reversible
765                   (choice (function-item gnus-article-sort-by-number)
766                           (function-item gnus-article-sort-by-author)
767                           (function-item gnus-article-sort-by-subject)
768                           (function-item gnus-article-sort-by-date)
769                           (function-item gnus-article-sort-by-score)
770                           (function-item gnus-article-sort-by-random)
771                           (function :tag "other"))
772                   (boolean :tag "Reverse order"))))
773
774
775 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
776   "*List of functions used for sorting threads in the summary buffer.
777 By default, threads are sorted by article number.
778
779 Each function takes two threads and returns non-nil if the first
780 thread should be sorted before the other.  If you use more than one
781 function, the primary sort function should be the last.  You should
782 probably always include `gnus-thread-sort-by-number' in the list of
783 sorting functions -- preferably first.  Also note that sorting by date
784 is often much slower than sorting by number, and the sorting order is
785 very similar.  (Sorting by date means sorting by the time the message
786 was sent, sorting by number means sorting by arrival time.)
787
788 Each list item can also be a list `(not F)' where F is a
789 function; this specifies reversed sort order.
790
791 Ready-made functions include `gnus-thread-sort-by-number',
792 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
793 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
794 `gnus-thread-sort-by-most-recent-number',
795 `gnus-thread-sort-by-most-recent-date',
796 `gnus-thread-sort-by-random', and
797 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
798
799 When threading is turned off, the variable
800 `gnus-article-sort-functions' controls how articles are sorted."
801   :group 'gnus-summary-sort
802   :type '(repeat 
803           (gnus-widget-reversible
804            (choice (function-item gnus-thread-sort-by-number)
805                    (function-item gnus-thread-sort-by-author)
806                    (function-item gnus-thread-sort-by-subject)
807                    (function-item gnus-thread-sort-by-date)
808                    (function-item gnus-thread-sort-by-score)
809                    (function-item gnus-thread-sort-by-most-recent-number)
810                    (function-item gnus-thread-sort-by-most-recent-date)
811                    (function-item gnus-thread-sort-by-random)
812                    (function-item gnus-thread-sort-by-total-score)
813                    (function :tag "other"))
814            (boolean :tag "Reverse order"))))
815
816 (defcustom gnus-thread-score-function '+
817   "*Function used for calculating the total score of a thread.
818
819 The function is called with the scores of the article and each
820 subthread and should then return the score of the thread.
821
822 Some functions you can use are `+', `max', or `min'."
823   :group 'gnus-summary-sort
824   :type 'function)
825
826 (defcustom gnus-summary-expunge-below nil
827   "All articles that have a score less than this variable will be expunged.
828 This variable is local to the summary buffers."
829   :group 'gnus-score-default
830   :type '(choice (const :tag "off" nil)
831                  integer))
832
833 (defcustom gnus-thread-expunge-below nil
834   "All threads that have a total score less than this variable will be expunged.
835 See `gnus-thread-score-function' for en explanation of what a
836 \"thread score\" is.
837
838 This variable is local to the summary buffers."
839   :group 'gnus-threading
840   :group 'gnus-score-default
841   :type '(choice (const :tag "off" nil)
842                  integer))
843
844 (defcustom gnus-summary-mode-hook nil
845   "*A hook for Gnus summary mode.
846 This hook is run before any variables are set in the summary buffer."
847   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
848   :group 'gnus-summary-various
849   :type 'hook)
850
851 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
852 (when (featurep 'xemacs)
853   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
854   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
855   (add-hook 'gnus-summary-mode-hook
856             'gnus-xmas-switch-horizontal-scrollbar-off))
857
858 (defcustom gnus-summary-menu-hook nil
859   "*Hook run after the creation of the summary mode menu."
860   :group 'gnus-summary-visual
861   :type 'hook)
862
863 (defcustom gnus-summary-exit-hook nil
864   "*A hook called on exit from the summary buffer.
865 It will be called with point in the group buffer."
866   :group 'gnus-summary-exit
867   :type 'hook)
868
869 (defcustom gnus-summary-prepare-hook nil
870   "*A hook called after the summary buffer has been generated.
871 If you want to modify the summary buffer, you can use this hook."
872   :group 'gnus-summary-various
873   :type 'hook)
874
875 (defcustom gnus-summary-prepared-hook nil
876   "*A hook called as the last thing after the summary buffer has been generated."
877   :group 'gnus-summary-various
878   :type 'hook)
879
880 (defcustom gnus-summary-generate-hook nil
881   "*A hook run just before generating the summary buffer.
882 This hook is commonly used to customize threading variables and the
883 like."
884   :group 'gnus-summary-various
885   :type 'hook)
886
887 (defcustom gnus-select-group-hook nil
888   "*A hook called when a newsgroup is selected.
889
890 If you'd like to simplify subjects like the
891 `gnus-summary-next-same-subject' command does, you can use the
892 following hook:
893
894  (add-hook gnus-select-group-hook
895            (lambda ()
896              (mapcar (lambda (header)
897                        (mail-header-set-subject
898                         header
899                         (gnus-simplify-subject
900                          (mail-header-subject header) 're-only)))
901                      gnus-newsgroup-headers)))"
902   :group 'gnus-group-select
903   :type 'hook)
904
905 (defcustom gnus-select-article-hook nil
906   "*A hook called when an article is selected."
907   :group 'gnus-summary-choose
908   :options '(gnus-agent-fetch-selected-article)
909   :type 'hook)
910
911 (defcustom gnus-visual-mark-article-hook
912   (list 'gnus-highlight-selected-summary)
913   "*Hook run after selecting an article in the summary buffer.
914 It is meant to be used for highlighting the article in some way.  It
915 is not run if `gnus-visual' is nil."
916   :group 'gnus-summary-visual
917   :type 'hook)
918
919 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
920   "*A hook called before parsing the headers."
921   :group 'gnus-various
922   :type 'hook)
923
924 (defcustom gnus-exit-group-hook nil
925   "*A hook called when exiting summary mode.
926 This hook is not called from the non-updating exit commands like `Q'."
927   :group 'gnus-various
928   :type 'hook)
929
930 (defcustom gnus-summary-update-hook
931   (list 'gnus-summary-highlight-line)
932   "*A hook called when a summary line is changed.
933 The hook will not be called if `gnus-visual' is nil.
934
935 The default function `gnus-summary-highlight-line' will
936 highlight the line according to the `gnus-summary-highlight'
937 variable."
938   :group 'gnus-summary-visual
939   :type 'hook)
940
941 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
942   "*A hook called when an article is selected for the first time.
943 The hook is intended to mark an article as read (or unread)
944 automatically when it is selected."
945   :group 'gnus-summary-choose
946   :type 'hook)
947
948 (defcustom gnus-group-no-more-groups-hook nil
949   "*A hook run when returning to group mode having no more (unread) groups."
950   :group 'gnus-group-select
951   :type 'hook)
952
953 (defcustom gnus-ps-print-hook nil
954   "*A hook run before ps-printing something from Gnus."
955   :group 'gnus-summary
956   :type 'hook)
957
958 (defcustom gnus-summary-article-move-hook nil
959   "*A hook called after an article is moved, copied, respooled, or crossposted."
960   :group 'gnus-summary
961   :type 'hook)
962
963 (defcustom gnus-summary-article-delete-hook nil
964   "*A hook called after an article is deleted."
965   :group 'gnus-summary
966   :type 'hook)
967
968 (defcustom gnus-summary-article-expire-hook nil
969   "*A hook called after an article is expired."
970   :group 'gnus-summary
971   :type 'hook)
972
973 (defcustom gnus-summary-display-arrow
974   (and (fboundp 'display-graphic-p)
975        (display-graphic-p))
976   "*If non-nil, display an arrow highlighting the current article."
977   :version "21.1"
978   :group 'gnus-summary
979   :type 'boolean)
980
981 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
982   "Face used for highlighting the current article in the summary buffer."
983   :group 'gnus-summary-visual
984   :type 'face)
985
986 (defvar gnus-tmp-downloaded nil)
987
988 (defcustom gnus-summary-highlight
989   '(((eq mark gnus-canceled-mark)
990      . gnus-summary-cancelled-face)
991     ((and uncached (> score default-high))
992      . gnus-summary-high-undownloaded-face)
993     ((and uncached (< score default-low))
994      . gnus-summary-low-undownloaded-face)
995     (uncached
996      . gnus-summary-normal-undownloaded-face)
997     ((and (> score default-high)
998           (or (eq mark gnus-dormant-mark)
999               (eq mark gnus-ticked-mark)))
1000      . gnus-summary-high-ticked-face)
1001     ((and (< score default-low)
1002           (or (eq mark gnus-dormant-mark)
1003               (eq mark gnus-ticked-mark)))
1004      . gnus-summary-low-ticked-face)
1005     ((or (eq mark gnus-dormant-mark)
1006          (eq mark gnus-ticked-mark))
1007      . gnus-summary-normal-ticked-face)
1008     ((and (> score default-high) (eq mark gnus-ancient-mark))
1009      . gnus-summary-high-ancient-face)
1010     ((and (< score default-low) (eq mark gnus-ancient-mark))
1011      . gnus-summary-low-ancient-face)
1012     ((eq mark gnus-ancient-mark)
1013      . gnus-summary-normal-ancient-face)
1014     ((and (> score default-high) (eq mark gnus-unread-mark))
1015      . gnus-summary-high-unread-face)
1016     ((and (< score default-low) (eq mark gnus-unread-mark))
1017      . gnus-summary-low-unread-face)
1018     ((eq mark gnus-unread-mark)
1019      . gnus-summary-normal-unread-face)
1020     ((> score default-high)
1021      . gnus-summary-high-read-face)
1022     ((< score default-low)
1023      . gnus-summary-low-read-face)
1024     (t
1025      . gnus-summary-normal-read-face))
1026   "*Controls the highlighting of summary buffer lines.
1027
1028 A list of (FORM . FACE) pairs.  When deciding how a a particular
1029 summary line should be displayed, each form is evaluated.  The content
1030 of the face field after the first true form is used.  You can change
1031 how those summary lines are displayed, by editing the face field.
1032
1033 You can use the following variables in the FORM field.
1034
1035 score:        The article's score
1036 default:      The default article score.
1037 default-high: The default score for high scored articles.
1038 default-low:  The default score for low scored articles.
1039 below:        The score below which articles are automatically marked as read.
1040 mark:         The article's mark.
1041 uncached:     Non-nil if the article is uncached."
1042   :group 'gnus-summary-visual
1043   :type '(repeat (cons (sexp :tag "Form" nil)
1044                        face)))
1045
1046 (defcustom gnus-alter-header-function nil
1047   "Function called to allow alteration of article header structures.
1048 The function is called with one parameter, the article header vector,
1049 which it may alter in any way."
1050   :type '(choice (const :tag "None" nil)
1051                  function)
1052   :group 'gnus-summary)
1053
1054 (defvar gnus-decode-encoded-word-function
1055   (mime-find-field-decoder 'From 'nov)
1056   "Variable that says which function should be used to decode a string with encoded words.")
1057
1058 (defcustom gnus-extra-headers '(To Newsgroups)
1059   "*Extra headers to parse."
1060   :version "21.1"
1061   :group 'gnus-summary
1062   :type '(repeat symbol))
1063
1064 (defcustom gnus-ignored-from-addresses
1065   (and user-mail-address (regexp-quote user-mail-address))
1066   "*Regexp of From headers that may be suppressed in favor of To headers."
1067   :version "21.1"
1068   :group 'gnus-summary
1069   :type 'regexp)
1070
1071 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1072   "List of charsets that should be ignored.
1073 When these charsets are used in the \"charset\" parameter, the
1074 default charset will be used instead."
1075   :version "21.1"
1076   :type '(repeat symbol)
1077   :group 'gnus-charset)
1078
1079 (gnus-define-group-parameter
1080  ignored-charsets
1081  :type list
1082  :function-document
1083  "Return the ignored charsets of GROUP."
1084  :variable gnus-group-ignored-charsets-alist
1085  :variable-default
1086  '(("alt\\.chinese\\.text" iso-8859-1))
1087  :variable-document
1088  "Alist of regexps (to match group names) and charsets that should be ignored.
1089 When these charsets are used in the \"charset\" parameter, the
1090 default charset will be used instead."
1091  :variable-group gnus-charset
1092  :variable-type '(repeat (cons (regexp :tag "Group")
1093                                (repeat symbol)))
1094  :parameter-type '(choice :tag "Ignored charsets"
1095                           :value nil
1096                           (repeat (symbol)))
1097  :parameter-document       "\
1098 List of charsets that should be ignored.
1099
1100 When these charsets are used in the \"charset\" parameter, the
1101 default charset will be used instead.")
1102
1103 (defcustom gnus-group-highlight-words-alist nil
1104   "Alist of group regexps and highlight regexps.
1105 This variable uses the same syntax as `gnus-emphasis-alist'."
1106   :version "21.1"
1107   :type '(repeat (cons (regexp :tag "Group")
1108                        (repeat (list (regexp :tag "Highlight regexp")
1109                                      (number :tag "Group for entire word" 0)
1110                                      (number :tag "Group for displayed part" 0)
1111                                      (symbol :tag "Face"
1112                                              gnus-emphasis-highlight-words)))))
1113   :group 'gnus-summary-visual)
1114
1115 (defcustom gnus-use-wheel nil
1116   "Use Intelli-mouse on summary movement"
1117   :type 'boolean
1118   :group 'gnus-summary-maneuvering)
1119
1120 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1121   "Amount to scroll messages by spinning the mouse wheel.
1122 This is actually a cons cell, where the first item is the amount to scroll
1123 on a normal wheel event, and the second is the amount to scroll when the
1124 wheel is moved with the shift key depressed."
1125   :type '(cons (integer :tag "Shift") integer)
1126   :group 'gnus-summary-maneuvering)
1127
1128 (defcustom gnus-wheel-edge-resistance 2
1129   "How hard it should be to change the current article
1130 by moving the mouse over the edge of the article window."
1131   :type 'integer
1132   :group 'gnus-summary-maneuvering)
1133
1134 (defcustom gnus-summary-show-article-charset-alist
1135   nil
1136   "Alist of number and charset.
1137 The article will be shown with the charset corresponding to the
1138 numbered argument.
1139 For example: ((1 . cn-gb-2312) (2 . big5))."
1140   :version "21.1"
1141   :type '(repeat (cons (number :tag "Argument" 1)
1142                        (symbol :tag "Charset")))
1143   :group 'gnus-charset)
1144
1145 (defcustom gnus-preserve-marks t
1146   "Whether marks are preserved when moving, copying and respooling messages."
1147   :version "21.1"
1148   :type 'boolean
1149   :group 'gnus-summary-marks)
1150
1151 (defcustom gnus-alter-articles-to-read-function nil
1152   "Function to be called to alter the list of articles to be selected."
1153   :type '(choice (const nil) function)
1154   :group 'gnus-summary)
1155
1156 (defcustom gnus-orphan-score nil
1157   "*All orphans get this score added.  Set in the score file."
1158   :group 'gnus-score-default
1159   :type '(choice (const nil)
1160                  integer))
1161
1162 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1163   "*A regexp to match MIME parts when saving multiple parts of a
1164 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1165 This regexp will be used by default when prompting the user for which
1166 type of files to save."
1167   :group 'gnus-summary
1168   :type 'regexp)
1169
1170 (defcustom gnus-read-all-available-headers nil
1171   "Whether Gnus should parse all headers made available to it.
1172 This is mostly relevant for slow back ends where the user may
1173 wish to widen the summary buffer to include all headers
1174 that were fetched.  Say, for nnultimate groups."
1175   :group 'gnus-summary
1176   :type '(choice boolean regexp))
1177
1178 (defcustom gnus-summary-muttprint-program "muttprint"
1179   "Command (and optional arguments) used to run Muttprint."
1180   :version "21.3"
1181   :group 'gnus-summary
1182   :type 'string)
1183
1184 (defcustom gnus-article-loose-mime nil
1185   "If non-nil, don't require MIME-Version header.
1186 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1187 supply the MIME-Version header or deliberately strip it From the mail.
1188 Set it to non-nil, Gnus will treat some articles as MIME even if
1189 the MIME-Version header is missed."
1190   :version "21.3"
1191   :type 'boolean
1192   :group 'gnus-article-mime)
1193
1194 (defcustom gnus-article-emulate-mime t
1195   "If non-nil, use MIME emulation for uuencode and the like.
1196 This means that Gnus will search message bodies for text that look
1197 like uuencoded bits, yEncoded bits, and so on, and present that using
1198 the normal Gnus MIME machinery."
1199   :type 'boolean
1200   :group 'gnus-article-mime)
1201
1202 ;;; Internal variables
1203
1204 (defvar gnus-summary-display-cache nil)
1205 (defvar gnus-article-mime-handles nil)
1206 (defvar gnus-article-decoded-p nil)
1207 (defvar gnus-article-charset nil)
1208 (defvar gnus-article-ignored-charsets nil)
1209 (defvar gnus-scores-exclude-files nil)
1210 (defvar gnus-page-broken nil)
1211
1212 (defvar gnus-original-article nil)
1213 (defvar gnus-article-internal-prepare-hook nil)
1214 (defvar gnus-newsgroup-process-stack nil)
1215
1216 (defvar gnus-thread-indent-array nil)
1217 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1218 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1219   "Function called to sort the articles within a thread after it has been gathered together.")
1220
1221 (defvar gnus-summary-save-parts-type-history nil)
1222 (defvar gnus-summary-save-parts-last-directory nil)
1223
1224 ;; Avoid highlighting in kill files.
1225 (defvar gnus-summary-inhibit-highlight nil)
1226 (defvar gnus-newsgroup-selected-overlay nil)
1227 (defvar gnus-inhibit-limiting nil)
1228 (defvar gnus-newsgroup-adaptive-score-file nil)
1229 (defvar gnus-current-score-file nil)
1230 (defvar gnus-current-move-group nil)
1231 (defvar gnus-current-copy-group nil)
1232 (defvar gnus-current-crosspost-group nil)
1233 (defvar gnus-newsgroup-display nil)
1234
1235 (defvar gnus-newsgroup-dependencies nil)
1236 (defvar gnus-newsgroup-adaptive nil)
1237 (defvar gnus-summary-display-article-function nil)
1238 (defvar gnus-summary-highlight-line-function nil
1239   "Function called after highlighting a summary line.")
1240
1241 (defvar gnus-summary-line-format-alist
1242   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1243     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1244     (?s gnus-tmp-subject-or-nil ?s)
1245     (?n gnus-tmp-name ?s)
1246     (?A (std11-address-string
1247          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1248     (?a (or (std11-full-name-string
1249              (car (mime-entity-read-field gnus-tmp-header 'From)))
1250             gnus-tmp-from) ?s)
1251     (?F gnus-tmp-from ?s)
1252     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1253     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1254     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1255     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1256     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1257     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1258     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1259     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1260     (?L gnus-tmp-lines ?s)
1261     (?O gnus-tmp-downloaded ?c)
1262     (?I gnus-tmp-indentation ?s)
1263     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1264     (?R gnus-tmp-replied ?c)
1265     (?\[ gnus-tmp-opening-bracket ?c)
1266     (?\] gnus-tmp-closing-bracket ?c)
1267     (?\> (make-string gnus-tmp-level ? ) ?s)
1268     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1269     (?i gnus-tmp-score ?d)
1270     (?z gnus-tmp-score-char ?c)
1271     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1272     (?U gnus-tmp-unread ?c)
1273     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1274         ?s)
1275     (?t (gnus-summary-number-of-articles-in-thread
1276          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1277         ?d)
1278     (?e (gnus-summary-number-of-articles-in-thread
1279          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1280         ?c)
1281     (?u gnus-tmp-user-defined ?s)
1282     (?P (gnus-pick-line-number) ?d)
1283     (?B gnus-tmp-thread-tree-header-string ?s)
1284     (user-date (gnus-user-date
1285                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1286   "An alist of format specifications that can appear in summary lines.
1287 These are paired with what variables they correspond with, along with
1288 the type of the variable (string, integer, character, etc).")
1289
1290 (defvar gnus-summary-dummy-line-format-alist
1291   `((?S gnus-tmp-subject ?s)
1292     (?N gnus-tmp-number ?d)
1293     (?u gnus-tmp-user-defined ?s)))
1294
1295 (defvar gnus-summary-mode-line-format-alist
1296   `((?G gnus-tmp-group-name ?s)
1297     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1298     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1299     (?A gnus-tmp-article-number ?d)
1300     (?Z gnus-tmp-unread-and-unselected ?s)
1301     (?V gnus-version ?s)
1302     (?U gnus-tmp-unread-and-unticked ?d)
1303     (?S gnus-tmp-subject ?s)
1304     (?e gnus-tmp-unselected ?d)
1305     (?u gnus-tmp-user-defined ?s)
1306     (?d (length gnus-newsgroup-dormant) ?d)
1307     (?t (length gnus-newsgroup-marked) ?d)
1308     (?h (length gnus-newsgroup-spam-marked) ?d)
1309     (?r (length gnus-newsgroup-reads) ?d)
1310     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1311     (?E gnus-newsgroup-expunged-tally ?d)
1312     (?s (gnus-current-score-file-nondirectory) ?s)))
1313
1314 (defvar gnus-last-search-regexp nil
1315   "Default regexp for article search command.")
1316
1317 (defvar gnus-summary-search-article-matched-data nil
1318   "Last matched data of article search command.  It is the local variable
1319 in `gnus-article-buffer' which consists of the list of start position,
1320 end position and text.")
1321
1322 (defvar gnus-last-shell-command nil
1323   "Default shell command on article.")
1324
1325 (defvar gnus-newsgroup-agentized nil
1326   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1327 (defvar gnus-newsgroup-begin nil)
1328 (defvar gnus-newsgroup-end nil)
1329 (defvar gnus-newsgroup-last-rmail nil)
1330 (defvar gnus-newsgroup-last-mail nil)
1331 (defvar gnus-newsgroup-last-folder nil)
1332 (defvar gnus-newsgroup-last-file nil)
1333 (defvar gnus-newsgroup-auto-expire nil)
1334 (defvar gnus-newsgroup-active nil)
1335
1336 (defvar gnus-newsgroup-data nil)
1337 (defvar gnus-newsgroup-data-reverse nil)
1338 (defvar gnus-newsgroup-limit nil)
1339 (defvar gnus-newsgroup-limits nil)
1340 (defvar gnus-summary-use-undownloaded-faces nil)
1341
1342 (defvar gnus-newsgroup-unreads nil
1343   "Sorted list of unread articles in the current newsgroup.")
1344
1345 (defvar gnus-newsgroup-unselected nil
1346   "Sorted list of unselected unread articles in the current newsgroup.")
1347
1348 (defvar gnus-newsgroup-reads nil
1349   "Alist of read articles and article marks in the current newsgroup.")
1350
1351 (defvar gnus-newsgroup-expunged-tally nil)
1352
1353 (defvar gnus-newsgroup-marked nil
1354   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1355
1356 (defvar gnus-newsgroup-spam-marked nil
1357   "List of ranges of articles that have been marked as spam.")
1358
1359 (defvar gnus-newsgroup-killed nil
1360   "List of ranges of articles that have been through the scoring process.")
1361
1362 (defvar gnus-newsgroup-cached nil
1363   "Sorted list of articles that come from the article cache.")
1364
1365 (defvar gnus-newsgroup-saved nil
1366   "List of articles that have been saved.")
1367
1368 (defvar gnus-newsgroup-kill-headers nil)
1369
1370 (defvar gnus-newsgroup-replied nil
1371   "List of articles that have been replied to in the current newsgroup.")
1372
1373 (defvar gnus-newsgroup-forwarded nil
1374   "List of articles that have been forwarded in the current newsgroup.")
1375
1376 (defvar gnus-newsgroup-recent nil
1377   "List of articles that have are recent in the current newsgroup.")
1378
1379 (defvar gnus-newsgroup-expirable nil
1380   "Sorted list of articles in the current newsgroup that can be expired.")
1381
1382 (defvar gnus-newsgroup-processable nil
1383   "List of articles in the current newsgroup that can be processed.")
1384
1385 (defvar gnus-newsgroup-downloadable nil
1386   "Sorted list of articles in the current newsgroup that can be processed.")
1387
1388 (defvar gnus-newsgroup-unfetched nil
1389   "Sorted list of articles in the current newsgroup whose headers have
1390 not been fetched into the agent.
1391
1392 This list will always be a subset of gnus-newsgroup-undownloaded.")
1393
1394 (defvar gnus-newsgroup-undownloaded nil
1395   "List of articles in the current newsgroup that haven't been downloaded.")
1396
1397 (defvar gnus-newsgroup-unsendable nil
1398   "List of articles in the current newsgroup that won't be sent.")
1399
1400 (defvar gnus-newsgroup-bookmarks nil
1401   "List of articles in the current newsgroup that have bookmarks.")
1402
1403 (defvar gnus-newsgroup-dormant nil
1404   "Sorted list of dormant articles in the current newsgroup.")
1405
1406 (defvar gnus-newsgroup-unseen nil
1407   "List of unseen articles in the current newsgroup.")
1408
1409 (defvar gnus-newsgroup-seen nil
1410   "Range of seen articles in the current newsgroup.")
1411
1412 (defvar gnus-newsgroup-articles nil
1413   "List of articles in the current newsgroup.")
1414
1415 (defvar gnus-newsgroup-scored nil
1416   "List of scored articles in the current newsgroup.")
1417
1418 (defvar gnus-newsgroup-incorporated nil
1419   "List of incorporated articles in the current newsgroup.")
1420
1421 (defvar gnus-newsgroup-headers nil
1422   "List of article headers in the current newsgroup.")
1423
1424 (defvar gnus-newsgroup-threads nil)
1425
1426 (defvar gnus-newsgroup-prepared nil
1427   "Whether the current group has been prepared properly.")
1428
1429 (defvar gnus-newsgroup-ancient nil
1430   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1431
1432 (defvar gnus-newsgroup-sparse nil)
1433
1434 (defvar gnus-current-article nil)
1435 (defvar gnus-article-current nil)
1436 (defvar gnus-current-headers nil)
1437 (defvar gnus-have-all-headers nil)
1438 (defvar gnus-last-article nil)
1439 (defvar gnus-newsgroup-history nil)
1440 (defvar gnus-newsgroup-charset nil)
1441 (defvar gnus-newsgroup-ephemeral-charset nil)
1442 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1443
1444 (defvar gnus-article-before-search nil)
1445
1446 (defvar gnus-summary-local-variables
1447   '(gnus-newsgroup-name
1448     gnus-newsgroup-begin gnus-newsgroup-end
1449     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1450     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1451     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1452     gnus-newsgroup-unselected gnus-newsgroup-marked
1453     gnus-newsgroup-spam-marked
1454     gnus-newsgroup-reads gnus-newsgroup-saved
1455     gnus-newsgroup-replied gnus-newsgroup-forwarded
1456     gnus-newsgroup-recent
1457     gnus-newsgroup-expirable
1458     gnus-newsgroup-processable gnus-newsgroup-killed
1459     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1460     gnus-newsgroup-unfetched
1461     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1462     gnus-newsgroup-seen gnus-newsgroup-articles
1463     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1464     gnus-newsgroup-headers gnus-newsgroup-threads
1465     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1466     gnus-current-article gnus-current-headers gnus-have-all-headers
1467     gnus-last-article gnus-article-internal-prepare-hook
1468     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1469     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1470     gnus-thread-expunge-below
1471     gnus-score-alist gnus-current-score-file
1472     (gnus-summary-expunge-below . global)
1473     (gnus-summary-mark-below . global)
1474     (gnus-orphan-score . global)
1475     gnus-newsgroup-active gnus-scores-exclude-files
1476     gnus-newsgroup-history gnus-newsgroup-ancient
1477     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1478     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1479     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1480     (gnus-newsgroup-expunged-tally . 0)
1481     gnus-cache-removable-articles gnus-newsgroup-cached
1482     gnus-newsgroup-data gnus-newsgroup-data-reverse
1483     gnus-newsgroup-limit gnus-newsgroup-limits
1484     gnus-newsgroup-charset gnus-newsgroup-display
1485     gnus-summary-use-undownloaded-faces
1486     gnus-newsgroup-incorporated)
1487   "Variables that are buffer-local to the summary buffers.")
1488
1489 (defvar gnus-newsgroup-variables nil
1490   "A list of variables that have separate values in different newsgroups.
1491 A list of newsgroup (summary buffer) local variables, or cons of
1492 variables and their default expressions to be evalled (when the default
1493 values are not nil), that should be made global while the summary buffer
1494 is active.
1495
1496 Note: The default expressions will be evaluated (using function `eval')
1497 before assignment to the local variable rather than just assigned to it.
1498 If the default expression is the symbol `global', that symbol will not
1499 be evaluated but the global value of the local variable will be used
1500 instead.
1501
1502 These variables can be used to set variables in the group parameters
1503 while still allowing them to affect operations done in other buffers.
1504 For example:
1505
1506 \(setq gnus-newsgroup-variables
1507      '(message-use-followup-to
1508        (gnus-visible-headers .
1509          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1510 ")
1511
1512 ;; Byte-compiler warning.
1513 (eval-when-compile
1514   ;; Bind features so that require will believe that gnus-sum has
1515   ;; already been loaded (avoids infinite recursion)
1516   (let ((features (cons 'gnus-sum features)))
1517     ;; Several of the declarations in gnus-sum are needed to load the
1518     ;; following files. Right now, these definitions have been
1519     ;; compiled but not defined (evaluated).  We could either do a
1520     ;; eval-and-compile about all of the declarations or evaluate the
1521     ;; source file.
1522     (if (boundp 'gnus-newsgroup-variables)
1523         nil
1524       (load "gnus-sum.el" t t t))
1525     (require 'gnus)
1526     (require 'gnus-agent)
1527     (require 'gnus-art)))
1528
1529 ;; Subject simplification.
1530
1531 (defun gnus-simplify-whitespace (str)
1532   "Remove excessive whitespace from STR."
1533   ;; Multiple spaces.
1534   (while (string-match "[ \t][ \t]+" str)
1535     (setq str (concat (substring str 0 (match-beginning 0))
1536                         " "
1537                         (substring str (match-end 0)))))
1538   ;; Leading spaces.
1539   (when (string-match "^[ \t]+" str)
1540     (setq str (substring str (match-end 0))))
1541   ;; Trailing spaces.
1542   (when (string-match "[ \t]+$" str)
1543     (setq str (substring str 0 (match-beginning 0))))
1544   str)
1545
1546 (defun gnus-simplify-all-whitespace (str)
1547   "Remove all whitespace from STR."
1548   (while (string-match "[ \t\n]+" str)
1549     (setq str (replace-match "" nil nil str)))
1550   str)
1551
1552 (defsubst gnus-simplify-subject-re (subject)
1553   "Remove \"Re:\" from subject lines."
1554   (if (string-match message-subject-re-regexp subject)
1555       (substring subject (match-end 0))
1556     subject))
1557
1558 (defun gnus-simplify-subject (subject &optional re-only)
1559   "Remove `Re:' and words in parentheses.
1560 If RE-ONLY is non-nil, strip leading `Re:'s only."
1561   (let ((case-fold-search t))           ;Ignore case.
1562     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1563     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1564       (setq subject (substring subject (match-end 0))))
1565     ;; Remove uninteresting prefixes.
1566     (when (and (not re-only)
1567                gnus-simplify-ignored-prefixes
1568                (string-match gnus-simplify-ignored-prefixes subject))
1569       (setq subject (substring subject (match-end 0))))
1570     ;; Remove words in parentheses from end.
1571     (unless re-only
1572       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1573         (setq subject (substring subject 0 (match-beginning 0)))))
1574     ;; Return subject string.
1575     subject))
1576
1577 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1578 ;; all whitespace.
1579 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1580   (goto-char (point-min))
1581   (while (re-search-forward regexp nil t)
1582     (replace-match (or newtext ""))))
1583
1584 (defun gnus-simplify-buffer-fuzzy ()
1585   "Simplify string in the buffer fuzzily.
1586 The string in the accessible portion of the current buffer is simplified.
1587 It is assumed to be a single-line subject.
1588 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1589 matter is removed.  Additional things can be deleted by setting
1590 `gnus-simplify-subject-fuzzy-regexp'."
1591   (let ((case-fold-search t)
1592         (modified-tick))
1593     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1594
1595     (while (not (eq modified-tick (buffer-modified-tick)))
1596       (setq modified-tick (buffer-modified-tick))
1597       (cond
1598        ((listp gnus-simplify-subject-fuzzy-regexp)
1599         (mapcar 'gnus-simplify-buffer-fuzzy-step
1600                 gnus-simplify-subject-fuzzy-regexp))
1601        (gnus-simplify-subject-fuzzy-regexp
1602         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1603       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1604       (gnus-simplify-buffer-fuzzy-step
1605        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1606       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1607
1608     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1609     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1610     (gnus-simplify-buffer-fuzzy-step " $")
1611     (gnus-simplify-buffer-fuzzy-step "^ +")))
1612
1613 (defun gnus-simplify-subject-fuzzy (subject)
1614   "Simplify a subject string fuzzily.
1615 See `gnus-simplify-buffer-fuzzy' for details."
1616   (save-excursion
1617     (gnus-set-work-buffer)
1618     (let ((case-fold-search t))
1619       ;; Remove uninteresting prefixes.
1620       (when (and gnus-simplify-ignored-prefixes
1621                  (string-match gnus-simplify-ignored-prefixes subject))
1622         (setq subject (substring subject (match-end 0))))
1623       (insert subject)
1624       (inline (gnus-simplify-buffer-fuzzy))
1625       (buffer-string))))
1626
1627 (defsubst gnus-simplify-subject-fully (subject)
1628   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1629   (cond
1630    (gnus-simplify-subject-functions
1631     (gnus-map-function gnus-simplify-subject-functions subject))
1632    ((null gnus-summary-gather-subject-limit)
1633     (gnus-simplify-subject-re subject))
1634    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1635     (gnus-simplify-subject-fuzzy subject))
1636    ((numberp gnus-summary-gather-subject-limit)
1637     (gnus-limit-string (gnus-simplify-subject-re subject)
1638                        gnus-summary-gather-subject-limit))
1639    (t
1640     subject)))
1641
1642 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1643   "Check whether two subjects are equal.
1644 If optional argument SIMPLE-FIRST is t, first argument is already
1645 simplified."
1646   (cond
1647    ((null simple-first)
1648     (equal (gnus-simplify-subject-fully s1)
1649            (gnus-simplify-subject-fully s2)))
1650    (t
1651     (equal s1
1652            (gnus-simplify-subject-fully s2)))))
1653
1654 (defun gnus-summary-bubble-group ()
1655   "Increase the score of the current group.
1656 This is a handy function to add to `gnus-summary-exit-hook' to
1657 increase the score of each group you read."
1658   (gnus-group-add-score gnus-newsgroup-name))
1659
1660 \f
1661 ;;;
1662 ;;; Gnus summary mode
1663 ;;;
1664
1665 (put 'gnus-summary-mode 'mode-class 'special)
1666
1667 (defvar gnus-article-commands-menu)
1668
1669 ;; Non-orthogonal keys
1670
1671 (gnus-define-keys gnus-summary-mode-map
1672   " " gnus-summary-next-page
1673   "\177" gnus-summary-prev-page
1674   [delete] gnus-summary-prev-page
1675   [backspace] gnus-summary-prev-page
1676   "\r" gnus-summary-scroll-up
1677   "\M-\r" gnus-summary-scroll-down
1678   "n" gnus-summary-next-unread-article
1679   "p" gnus-summary-prev-unread-article
1680   "N" gnus-summary-next-article
1681   "P" gnus-summary-prev-article
1682   "\M-\C-n" gnus-summary-next-same-subject
1683   "\M-\C-p" gnus-summary-prev-same-subject
1684   "\M-n" gnus-summary-next-unread-subject
1685   "\M-p" gnus-summary-prev-unread-subject
1686   "." gnus-summary-first-unread-article
1687   "," gnus-summary-best-unread-article
1688   "\M-s" gnus-summary-search-article-forward
1689   "\M-r" gnus-summary-search-article-backward
1690   "<" gnus-summary-beginning-of-article
1691   ">" gnus-summary-end-of-article
1692   "j" gnus-summary-goto-article
1693   "^" gnus-summary-refer-parent-article
1694   "\M-^" gnus-summary-refer-article
1695   "u" gnus-summary-tick-article-forward
1696   "!" gnus-summary-tick-article-forward
1697   "U" gnus-summary-tick-article-backward
1698   "d" gnus-summary-mark-as-read-forward
1699   "D" gnus-summary-mark-as-read-backward
1700   "E" gnus-summary-mark-as-expirable
1701   "\M-u" gnus-summary-clear-mark-forward
1702   "\M-U" gnus-summary-clear-mark-backward
1703   "k" gnus-summary-kill-same-subject-and-select
1704   "\C-k" gnus-summary-kill-same-subject
1705   "\M-\C-k" gnus-summary-kill-thread
1706   "\M-\C-l" gnus-summary-lower-thread
1707   "e" gnus-summary-edit-article
1708   "#" gnus-summary-mark-as-processable
1709   "\M-#" gnus-summary-unmark-as-processable
1710   "\M-\C-t" gnus-summary-toggle-threads
1711   "\M-\C-s" gnus-summary-show-thread
1712   "\M-\C-h" gnus-summary-hide-thread
1713   "\M-\C-f" gnus-summary-next-thread
1714   "\M-\C-b" gnus-summary-prev-thread
1715   [(meta down)] gnus-summary-next-thread
1716   [(meta up)] gnus-summary-prev-thread
1717   "\M-\C-u" gnus-summary-up-thread
1718   "\M-\C-d" gnus-summary-down-thread
1719   "&" gnus-summary-execute-command
1720   "c" gnus-summary-catchup-and-exit
1721   "\C-w" gnus-summary-mark-region-as-read
1722   "\C-t" gnus-summary-toggle-truncation
1723   "?" gnus-summary-mark-as-dormant
1724   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1725   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1726   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1727   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1728   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1729   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1730   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1731   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1732   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1733   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1734   "=" gnus-summary-expand-window
1735   "\C-x\C-s" gnus-summary-reselect-current-group
1736   "\M-g" gnus-summary-rescan-group
1737   "w" gnus-summary-stop-page-breaking
1738   "\C-c\C-r" gnus-summary-caesar-message
1739   "\M-t" gnus-summary-toggle-mime
1740   "f" gnus-summary-followup
1741   "F" gnus-summary-followup-with-original
1742   "C" gnus-summary-cancel-article
1743   "r" gnus-summary-reply
1744   "R" gnus-summary-reply-with-original
1745   "\C-c\C-f" gnus-summary-mail-forward
1746   "o" gnus-summary-save-article
1747   "\C-o" gnus-summary-save-article-mail
1748   "|" gnus-summary-pipe-output
1749   "\M-k" gnus-summary-edit-local-kill
1750   "\M-K" gnus-summary-edit-global-kill
1751   ;; "V" gnus-version
1752   "\C-c\C-d" gnus-summary-describe-group
1753   "q" gnus-summary-exit
1754   "Q" gnus-summary-exit-no-update
1755   "\C-c\C-i" gnus-info-find-node
1756   gnus-mouse-2 gnus-mouse-pick-article
1757   "m" gnus-summary-mail-other-window
1758   "a" gnus-summary-post-news
1759   "i" gnus-summary-news-other-window
1760   "x" gnus-summary-limit-to-unread
1761   "s" gnus-summary-isearch-article
1762   "t" gnus-summary-toggle-header
1763   "g" gnus-summary-show-article
1764   "l" gnus-summary-goto-last-article
1765   "v" gnus-summary-preview-mime-message
1766   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1767   "\C-d" gnus-summary-enter-digest-group
1768   "\M-\C-d" gnus-summary-read-document
1769   "\M-\C-e" gnus-summary-edit-parameters
1770   "\M-\C-a" gnus-summary-customize-parameters
1771   "\C-c\C-b" gnus-bug
1772   "\C-c\C-n" gnus-namazu-search
1773   "*" gnus-cache-enter-article
1774   "\M-*" gnus-cache-remove-article
1775   "\M-&" gnus-summary-universal-argument
1776   "\C-l" gnus-recenter
1777   "I" gnus-summary-increase-score
1778   "L" gnus-summary-lower-score
1779   "\M-i" gnus-symbolic-argument
1780   "h" gnus-summary-select-article-buffer
1781
1782   "V" gnus-summary-score-map
1783   "X" gnus-uu-extract-map
1784   "S" gnus-summary-send-map)
1785
1786   ;; Sort of orthogonal keymap
1787 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1788   "t" gnus-summary-tick-article-forward
1789   "!" gnus-summary-tick-article-forward
1790   "d" gnus-summary-mark-as-read-forward
1791   "r" gnus-summary-mark-as-read-forward
1792   "c" gnus-summary-clear-mark-forward
1793   " " gnus-summary-clear-mark-forward
1794   "e" gnus-summary-mark-as-expirable
1795   "x" gnus-summary-mark-as-expirable
1796   "?" gnus-summary-mark-as-dormant
1797   "b" gnus-summary-set-bookmark
1798   "B" gnus-summary-remove-bookmark
1799   "#" gnus-summary-mark-as-processable
1800   "\M-#" gnus-summary-unmark-as-processable
1801   "S" gnus-summary-limit-include-expunged
1802   "C" gnus-summary-catchup
1803   "H" gnus-summary-catchup-to-here
1804   "h" gnus-summary-catchup-from-here
1805   "\C-c" gnus-summary-catchup-all
1806   "k" gnus-summary-kill-same-subject-and-select
1807   "K" gnus-summary-kill-same-subject
1808   "P" gnus-uu-mark-map)
1809
1810 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1811   "c" gnus-summary-clear-above
1812   "u" gnus-summary-tick-above
1813   "m" gnus-summary-mark-above
1814   "k" gnus-summary-kill-below)
1815
1816 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1817   "/" gnus-summary-limit-to-subject
1818   "n" gnus-summary-limit-to-articles
1819   "w" gnus-summary-pop-limit
1820   "s" gnus-summary-limit-to-subject
1821   "a" gnus-summary-limit-to-author
1822   "u" gnus-summary-limit-to-unread
1823   "m" gnus-summary-limit-to-marks
1824   "M" gnus-summary-limit-exclude-marks
1825   "v" gnus-summary-limit-to-score
1826   "*" gnus-summary-limit-include-cached
1827   "D" gnus-summary-limit-include-dormant
1828   "T" gnus-summary-limit-include-thread
1829   "d" gnus-summary-limit-exclude-dormant
1830   "t" gnus-summary-limit-to-age
1831   "." gnus-summary-limit-to-unseen
1832   "x" gnus-summary-limit-to-extra
1833   "p" gnus-summary-limit-to-display-predicate
1834   "E" gnus-summary-limit-include-expunged
1835   "c" gnus-summary-limit-exclude-childless-dormant
1836   "C" gnus-summary-limit-mark-excluded-as-read
1837   "o" gnus-summary-insert-old-articles
1838   "N" gnus-summary-insert-new-articles
1839   "r" gnus-summary-limit-to-replied)
1840
1841 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1842   "n" gnus-summary-next-unread-article
1843   "p" gnus-summary-prev-unread-article
1844   "N" gnus-summary-next-article
1845   "P" gnus-summary-prev-article
1846   "\C-n" gnus-summary-next-same-subject
1847   "\C-p" gnus-summary-prev-same-subject
1848   "\M-n" gnus-summary-next-unread-subject
1849   "\M-p" gnus-summary-prev-unread-subject
1850   "f" gnus-summary-first-unread-article
1851   "b" gnus-summary-best-unread-article
1852   "j" gnus-summary-goto-article
1853   "g" gnus-summary-goto-subject
1854   "l" gnus-summary-goto-last-article
1855   "o" gnus-summary-pop-article)
1856
1857 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1858   "k" gnus-summary-kill-thread
1859   "l" gnus-summary-lower-thread
1860   "i" gnus-summary-raise-thread
1861   "T" gnus-summary-toggle-threads
1862   "t" gnus-summary-rethread-current
1863   "^" gnus-summary-reparent-thread
1864   "s" gnus-summary-show-thread
1865   "S" gnus-summary-show-all-threads
1866   "h" gnus-summary-hide-thread
1867   "H" gnus-summary-hide-all-threads
1868   "n" gnus-summary-next-thread
1869   "p" gnus-summary-prev-thread
1870   "u" gnus-summary-up-thread
1871   "o" gnus-summary-top-thread
1872   "d" gnus-summary-down-thread
1873   "#" gnus-uu-mark-thread
1874   "\M-#" gnus-uu-unmark-thread)
1875
1876 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1877   "g" gnus-summary-prepare
1878   "c" gnus-summary-insert-cached-articles
1879   "d" gnus-summary-insert-dormant-articles)
1880
1881 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1882   "c" gnus-summary-catchup-and-exit
1883   "C" gnus-summary-catchup-all-and-exit
1884   "E" gnus-summary-exit-no-update
1885   "J" gnus-summary-jump-to-other-group
1886   "Q" gnus-summary-exit
1887   "Z" gnus-summary-exit
1888   "n" gnus-summary-catchup-and-goto-next-group
1889   "R" gnus-summary-reselect-current-group
1890   "G" gnus-summary-rescan-group
1891   "N" gnus-summary-next-group
1892   "s" gnus-summary-save-newsrc
1893   "P" gnus-summary-prev-group)
1894
1895 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1896   " " gnus-summary-next-page
1897   "n" gnus-summary-next-page
1898   "\177" gnus-summary-prev-page
1899   [delete] gnus-summary-prev-page
1900   "p" gnus-summary-prev-page
1901   "\r" gnus-summary-scroll-up
1902   "\M-\r" gnus-summary-scroll-down
1903   "<" gnus-summary-beginning-of-article
1904   ">" gnus-summary-end-of-article
1905   "b" gnus-summary-beginning-of-article
1906   "e" gnus-summary-end-of-article
1907   "^" gnus-summary-refer-parent-article
1908   "r" gnus-summary-refer-parent-article
1909   "D" gnus-summary-enter-digest-group
1910   "R" gnus-summary-refer-references
1911   "T" gnus-summary-refer-thread
1912   "g" gnus-summary-show-article
1913   "s" gnus-summary-isearch-article
1914   "P" gnus-summary-print-article
1915   "M" gnus-mailing-list-insinuate
1916   "t" gnus-article-babel)
1917
1918 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1919   "b" gnus-article-add-buttons
1920   "B" gnus-article-add-buttons-to-head
1921   "o" gnus-article-treat-overstrike
1922   "e" gnus-article-emphasize
1923   "w" gnus-article-fill-cited-article
1924   "Q" gnus-article-fill-long-lines
1925   "C" gnus-article-capitalize-sentences
1926   "c" gnus-article-remove-cr
1927   "Z" gnus-article-decode-HZ
1928   "A" gnus-article-treat-ansi-sequences
1929   "h" gnus-article-wash-html
1930   "u" gnus-article-unsplit-urls
1931   "f" gnus-article-display-x-face
1932   "l" gnus-summary-stop-page-breaking
1933   "r" gnus-summary-caesar-message
1934   "m" gnus-summary-morse-message
1935   "t" gnus-summary-toggle-header
1936   "g" gnus-treat-smiley
1937   "v" gnus-summary-verbose-headers
1938   "m" gnus-summary-toggle-mime
1939   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1940   "p" gnus-article-verify-x-pgp-sig
1941   "d" gnus-article-treat-dumbquotes)
1942
1943 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1944   ;; mnemonic: deuglif*Y*
1945   "u" gnus-article-outlook-unwrap-lines
1946   "a" gnus-article-outlook-repair-attribution
1947   "c" gnus-article-outlook-rearrange-citation
1948   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1949
1950 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1951   "a" gnus-article-hide
1952   "h" gnus-article-hide-headers
1953   "b" gnus-article-hide-boring-headers
1954   "s" gnus-article-hide-signature
1955   "c" gnus-article-hide-citation
1956   "C" gnus-article-hide-citation-in-followups
1957   "l" gnus-article-hide-list-identifiers
1958   "B" gnus-article-strip-banner
1959   "P" gnus-article-hide-pem
1960   "\C-c" gnus-article-hide-citation-maybe)
1961
1962 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1963   "a" gnus-article-highlight
1964   "h" gnus-article-highlight-headers
1965   "c" gnus-article-highlight-citation
1966   "s" gnus-article-highlight-signature)
1967
1968 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1969   "f" gnus-article-treat-fold-headers
1970   "u" gnus-article-treat-unfold-headers
1971   "n" gnus-article-treat-fold-newsgroups)
1972
1973 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1974   "x" gnus-article-display-x-face
1975   "d" gnus-article-display-face
1976   "s" gnus-treat-smiley
1977   "D" gnus-article-remove-images
1978   "f" gnus-treat-from-picon
1979   "m" gnus-treat-mail-picon
1980   "n" gnus-treat-newsgroups-picon)
1981
1982 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1983   "z" gnus-article-date-ut
1984   "u" gnus-article-date-ut
1985   "l" gnus-article-date-local
1986   "p" gnus-article-date-english
1987   "e" gnus-article-date-lapsed
1988   "o" gnus-article-date-original
1989   "i" gnus-article-date-iso8601
1990   "s" gnus-article-date-user)
1991
1992 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1993   "t" gnus-article-remove-trailing-blank-lines
1994   "l" gnus-article-strip-leading-blank-lines
1995   "m" gnus-article-strip-multiple-blank-lines
1996   "a" gnus-article-strip-blank-lines
1997   "A" gnus-article-strip-all-blank-lines
1998   "s" gnus-article-strip-leading-space
1999   "e" gnus-article-strip-trailing-space
2000   "w" gnus-article-remove-leading-whitespace)
2001
2002 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2003   "v" gnus-version
2004   "f" gnus-summary-fetch-faq
2005   "d" gnus-summary-describe-group
2006   "h" gnus-summary-describe-briefly
2007   "i" gnus-info-find-node
2008   "c" gnus-group-fetch-charter
2009   "C" gnus-group-fetch-control)
2010
2011 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2012   "e" gnus-summary-expire-articles
2013   "\M-\C-e" gnus-summary-expire-articles-now
2014   "\177" gnus-summary-delete-article
2015   [delete] gnus-summary-delete-article
2016   [backspace] gnus-summary-delete-article
2017   "m" gnus-summary-move-article
2018   "r" gnus-summary-respool-article
2019   "w" gnus-summary-edit-article
2020   "c" gnus-summary-copy-article
2021   "B" gnus-summary-crosspost-article
2022   "q" gnus-summary-respool-query
2023   "t" gnus-summary-respool-trace
2024   "i" gnus-summary-import-article
2025   "I" gnus-summary-create-article
2026   "p" gnus-summary-article-posted-p)
2027
2028 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2029   "o" gnus-summary-save-article
2030   "m" gnus-summary-save-article-mail
2031   "F" gnus-summary-write-article-file
2032   "r" gnus-summary-save-article-rmail
2033   "f" gnus-summary-save-article-file
2034   "b" gnus-summary-save-article-body-file
2035   "h" gnus-summary-save-article-folder
2036   "v" gnus-summary-save-article-vm
2037   "p" gnus-summary-pipe-output
2038   "P" gnus-summary-muttprint
2039   "s" gnus-soup-add-article)
2040
2041 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2042   "b" gnus-summary-display-buttonized
2043   "m" gnus-summary-repair-multipart
2044   "v" gnus-article-view-part
2045   "o" gnus-article-save-part
2046   "c" gnus-article-copy-part
2047   "C" gnus-article-view-part-as-charset
2048   "e" gnus-article-view-part-externally
2049   "E" gnus-article-encrypt-body
2050   "i" gnus-article-inline-part
2051   "|" gnus-article-pipe-part)
2052
2053 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2054   "p" gnus-summary-mark-as-processable
2055   "u" gnus-summary-unmark-as-processable
2056   "U" gnus-summary-unmark-all-processable
2057   "v" gnus-uu-mark-over
2058   "s" gnus-uu-mark-series
2059   "r" gnus-uu-mark-region
2060   "g" gnus-uu-unmark-region
2061   "R" gnus-uu-mark-by-regexp
2062   "G" gnus-uu-unmark-by-regexp
2063   "t" gnus-uu-mark-thread
2064   "T" gnus-uu-unmark-thread
2065   "a" gnus-uu-mark-all
2066   "b" gnus-uu-mark-buffer
2067   "S" gnus-uu-mark-sparse
2068   "k" gnus-summary-kill-process-mark
2069   "y" gnus-summary-yank-process-mark
2070   "w" gnus-summary-save-process-mark
2071   "i" gnus-uu-invert-processable)
2072
2073 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2074   ;;"x" gnus-uu-extract-any
2075   "m" gnus-summary-save-parts
2076   "u" gnus-uu-decode-uu
2077   "U" gnus-uu-decode-uu-and-save
2078   "s" gnus-uu-decode-unshar
2079   "S" gnus-uu-decode-unshar-and-save
2080   "o" gnus-uu-decode-save
2081   "O" gnus-uu-decode-save
2082   "b" gnus-uu-decode-binhex
2083   "B" gnus-uu-decode-binhex
2084   "p" gnus-uu-decode-postscript
2085   "P" gnus-uu-decode-postscript-and-save)
2086
2087 (gnus-define-keys
2088     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2089   "u" gnus-uu-decode-uu-view
2090   "U" gnus-uu-decode-uu-and-save-view
2091   "s" gnus-uu-decode-unshar-view
2092   "S" gnus-uu-decode-unshar-and-save-view
2093   "o" gnus-uu-decode-save-view
2094   "O" gnus-uu-decode-save-view
2095   "b" gnus-uu-decode-binhex-view
2096   "B" gnus-uu-decode-binhex-view
2097   "p" gnus-uu-decode-postscript-view
2098   "P" gnus-uu-decode-postscript-and-save-view)
2099
2100 (defvar gnus-article-post-menu nil)
2101
2102 (defconst gnus-summary-menu-maxlen 20)
2103
2104 (defun gnus-summary-menu-split (menu)
2105   ;; If we have lots of elements, divide them into groups of 20
2106   ;; and make a pane (or submenu) for each one.
2107   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2108       (let ((menu menu) sublists next
2109             (i 1))
2110         (while menu
2111           ;; Pull off the next gnus-summary-menu-maxlen elements
2112           ;; and make them the next element of sublist.
2113           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2114           (if next
2115               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2116                       nil))
2117           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2118                                              (aref (car (last menu)) 0)) menu)
2119                                sublists))
2120           (setq i (1+ i))
2121           (setq menu next))
2122         (nreverse sublists))
2123     ;; Few elements--put them all in one pane.
2124     menu))
2125
2126 (defun gnus-summary-make-menu-bar ()
2127   (gnus-turn-off-edit-menu 'summary)
2128
2129   (unless (boundp 'gnus-summary-misc-menu)
2130
2131     (easy-menu-define
2132      gnus-summary-kill-menu gnus-summary-mode-map ""
2133      (cons
2134       "Score"
2135       (nconc
2136        (list
2137         ["Customize" gnus-score-customize t])
2138        (gnus-make-score-map 'increase)
2139        (gnus-make-score-map 'lower)
2140        '(("Mark"
2141           ["Kill below" gnus-summary-kill-below t]
2142           ["Mark above" gnus-summary-mark-above t]
2143           ["Tick above" gnus-summary-tick-above t]
2144           ["Clear above" gnus-summary-clear-above t])
2145          ["Current score" gnus-summary-current-score t]
2146          ["Set score" gnus-summary-set-score t]
2147          ["Switch current score file..." gnus-score-change-score-file t]
2148          ["Set mark below..." gnus-score-set-mark-below t]
2149          ["Set expunge below..." gnus-score-set-expunge-below t]
2150          ["Edit current score file" gnus-score-edit-current-scores t]
2151          ["Edit score file" gnus-score-edit-file t]
2152          ["Trace score" gnus-score-find-trace t]
2153          ["Find words" gnus-score-find-favourite-words t]
2154          ["Rescore buffer" gnus-summary-rescore t]
2155          ["Increase score..." gnus-summary-increase-score t]
2156          ["Lower score..." gnus-summary-lower-score t]))))
2157
2158     ;; Define both the Article menu in the summary buffer and the
2159     ;; equivalent Commands menu in the article buffer here for
2160     ;; consistency.
2161     (let ((innards
2162            `(("Hide"
2163               ["All" gnus-article-hide t]
2164               ["Headers" gnus-article-hide-headers t]
2165               ["Signature" gnus-article-hide-signature t]
2166               ["Citation" gnus-article-hide-citation t]
2167               ["List identifiers" gnus-article-hide-list-identifiers t]
2168               ["Banner" gnus-article-strip-banner t]
2169               ["Boring headers" gnus-article-hide-boring-headers t])
2170              ("Highlight"
2171               ["All" gnus-article-highlight t]
2172               ["Headers" gnus-article-highlight-headers t]
2173               ["Signature" gnus-article-highlight-signature t]
2174               ["Citation" gnus-article-highlight-citation t])
2175              ("Date"
2176               ["Local" gnus-article-date-local t]
2177               ["ISO8601" gnus-article-date-iso8601 t]
2178               ["UT" gnus-article-date-ut t]
2179               ["Original" gnus-article-date-original t]
2180               ["Lapsed" gnus-article-date-lapsed t]
2181               ["User-defined" gnus-article-date-user t])
2182              ("Display"
2183               ["Remove images" gnus-article-remove-images t]
2184               ["Toggle smiley" gnus-treat-smiley t]
2185               ["Show X-Face" gnus-article-display-x-face t]
2186               ["Show picons in From" gnus-treat-from-picon t]
2187               ["Show picons in mail headers" gnus-treat-mail-picon t]
2188               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2189               ("View as different encoding"
2190                ,@(gnus-summary-menu-split
2191                   (mapcar
2192                    (lambda (cs)
2193                      ;; Since easymenu under Emacs doesn't allow
2194                      ;; lambda forms for menu commands, we should
2195                      ;; provide intern'ed function symbols.
2196                      (let ((command (intern (format "\
2197 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2198                        (fset command
2199                              `(lambda ()
2200                                 (interactive)
2201                                 (let ((gnus-summary-show-article-charset-alist
2202                                        '((1 . ,cs))))
2203                                   (gnus-summary-show-article 1))))
2204                        `[,(symbol-name cs) ,command t]))
2205                    (sort (if (fboundp 'coding-system-list)
2206                              (coding-system-list)
2207                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2208                            )
2209                          'string<)))))
2210              ("Washing"
2211               ("Remove Blanks"
2212                ["Leading" gnus-article-strip-leading-blank-lines t]
2213                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2214                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2215                ["All of the above" gnus-article-strip-blank-lines t]
2216                ["All" gnus-article-strip-all-blank-lines t]
2217                ["Leading space" gnus-article-strip-leading-space t]
2218                ["Trailing space" gnus-article-strip-trailing-space t]
2219                ["Leading space in headers"
2220                 gnus-article-remove-leading-whitespace t])
2221               ["Overstrike" gnus-article-treat-overstrike t]
2222               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2223               ["Emphasis" gnus-article-emphasize t]
2224               ["Word wrap" gnus-article-fill-cited-article t]
2225               ["Fill long lines" gnus-article-fill-long-lines t]
2226               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2227               ["Remove CR" gnus-article-remove-cr t]
2228               ["Rot 13" gnus-summary-caesar-message
2229                ,@(if (featurep 'xemacs) '(t)
2230                    '(:help "\"Caesar rotate\" article by 13"))]
2231               ["Morse decode" gnus-summary-morse-message t]
2232               ["Unix pipe..." gnus-summary-pipe-message t]
2233               ["Add buttons" gnus-article-add-buttons t]
2234               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2235               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2236               ["Toggle MIME" gnus-summary-toggle-mime t]
2237               ["Verbose header" gnus-summary-verbose-headers t]
2238               ["Toggle header" gnus-summary-toggle-header t]
2239               ["Unfold headers" gnus-article-treat-unfold-headers t]
2240               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2241               ["Html" gnus-article-wash-html t]
2242               ["Unsplit URLs" gnus-article-unsplit-urls t]
2243               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2244               ["Decode HZ" gnus-article-decode-HZ t]
2245               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2246               ("(Outlook) Deuglify"
2247                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2248                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2249                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2250                ["Full (Outlook) deuglify"
2251                 gnus-article-outlook-deuglify-article t])
2252               )
2253              ("Output"
2254               ["Save in default format..." gnus-summary-save-article
2255                ,@(if (featurep 'xemacs) '(t)
2256                    '(:help "Save article using default method"))]
2257               ["Save in file..." gnus-summary-save-article-file
2258                ,@(if (featurep 'xemacs) '(t)
2259                    '(:help "Save article in file"))]
2260               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2261               ["Save in MH folder..." gnus-summary-save-article-folder t]
2262               ["Save in VM folder..." gnus-summary-save-article-vm t]
2263               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2264               ["Save body in file..." gnus-summary-save-article-body-file t]
2265               ["Pipe through a filter..." gnus-summary-pipe-output t]
2266               ["Add to SOUP packet" gnus-soup-add-article t]
2267               ["Print with Muttprint..." gnus-summary-muttprint t]
2268               ["Print" gnus-summary-print-article t])
2269              ("Backend"
2270               ["Respool article..." gnus-summary-respool-article t]
2271               ["Move article..." gnus-summary-move-article
2272                (gnus-check-backend-function
2273                 'request-move-article gnus-newsgroup-name)]
2274               ["Copy article..." gnus-summary-copy-article t]
2275               ["Crosspost article..." gnus-summary-crosspost-article
2276                (gnus-check-backend-function
2277                 'request-replace-article gnus-newsgroup-name)]
2278               ["Import file..." gnus-summary-import-article
2279                (gnus-check-backend-function
2280                 'request-accept-article gnus-newsgroup-name)]
2281               ["Create article..." gnus-summary-create-article
2282                (gnus-check-backend-function
2283                 'request-accept-article gnus-newsgroup-name)]
2284               ["Check if posted" gnus-summary-article-posted-p t]
2285               ["Edit article" gnus-summary-edit-article
2286                (not (gnus-group-read-only-p))]
2287               ["Delete article" gnus-summary-delete-article
2288                (gnus-check-backend-function
2289                 'request-expire-articles gnus-newsgroup-name)]
2290               ["Query respool" gnus-summary-respool-query t]
2291               ["Trace respool" gnus-summary-respool-trace t]
2292               ["Delete expirable articles" gnus-summary-expire-articles-now
2293                (gnus-check-backend-function
2294                 'request-expire-articles gnus-newsgroup-name)])
2295              ("Extract"
2296               ["Uudecode" gnus-uu-decode-uu
2297                ,@(if (featurep 'xemacs) '(t)
2298                    '(:help "Decode uuencoded article(s)"))]
2299               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2300               ["Unshar" gnus-uu-decode-unshar t]
2301               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2302               ["Save" gnus-uu-decode-save t]
2303               ["Binhex" gnus-uu-decode-binhex t]
2304               ["Postscript" gnus-uu-decode-postscript t])
2305              ("Cache"
2306               ["Enter article" gnus-cache-enter-article t]
2307               ["Remove article" gnus-cache-remove-article t])
2308              ["Translate" gnus-article-babel t]
2309              ["Select article buffer" gnus-summary-select-article-buffer t]
2310              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2311              ["Isearch article..." gnus-summary-isearch-article t]
2312              ["Beginning of the article" gnus-summary-beginning-of-article t]
2313              ["End of the article" gnus-summary-end-of-article t]
2314              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2315              ["Fetch referenced articles" gnus-summary-refer-references t]
2316              ["Fetch current thread" gnus-summary-refer-thread t]
2317              ["Fetch article with id..." gnus-summary-refer-article t]
2318              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2319              ["Redisplay" gnus-summary-show-article t]
2320              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2321       (easy-menu-define
2322        gnus-summary-article-menu gnus-summary-mode-map ""
2323        (cons "Article" innards))
2324
2325       (if (not (keymapp gnus-summary-article-menu))
2326           (easy-menu-define
2327            gnus-article-commands-menu gnus-article-mode-map ""
2328            (cons "Commands" innards))
2329         ;; in Emacs, don't share menu.
2330         (setq gnus-article-commands-menu
2331               (copy-keymap gnus-summary-article-menu))
2332         (define-key gnus-article-mode-map [menu-bar commands]
2333           (cons "Commands" gnus-article-commands-menu))))
2334
2335     (easy-menu-define
2336      gnus-summary-thread-menu gnus-summary-mode-map ""
2337      '("Threads"
2338        ["Find all messages in thread" gnus-summary-refer-thread t]
2339        ["Toggle threading" gnus-summary-toggle-threads t]
2340        ["Hide threads" gnus-summary-hide-all-threads t]
2341        ["Show threads" gnus-summary-show-all-threads t]
2342        ["Hide thread" gnus-summary-hide-thread t]
2343        ["Show thread" gnus-summary-show-thread t]
2344        ["Go to next thread" gnus-summary-next-thread t]
2345        ["Go to previous thread" gnus-summary-prev-thread t]
2346        ["Go down thread" gnus-summary-down-thread t]
2347        ["Go up thread" gnus-summary-up-thread t]
2348        ["Top of thread" gnus-summary-top-thread t]
2349        ["Mark thread as read" gnus-summary-kill-thread t]
2350        ["Lower thread score" gnus-summary-lower-thread t]
2351        ["Raise thread score" gnus-summary-raise-thread t]
2352        ["Rethread current" gnus-summary-rethread-current t]))
2353
2354     (easy-menu-define
2355      gnus-summary-post-menu gnus-summary-mode-map ""
2356      `("Post"
2357        ["Send a message (mail or news)" gnus-summary-post-news
2358         ,@(if (featurep 'xemacs) '(t)
2359             '(:help "Post an article"))]
2360        ["Followup" gnus-summary-followup
2361         ,@(if (featurep 'xemacs) '(t)
2362             '(:help "Post followup to this article"))]
2363        ["Followup and yank" gnus-summary-followup-with-original
2364         ,@(if (featurep 'xemacs) '(t)
2365             '(:help "Post followup to this article, quoting its contents"))]
2366        ["Supersede article" gnus-summary-supersede-article t]
2367        ["Cancel article" gnus-summary-cancel-article
2368         ,@(if (featurep 'xemacs) '(t)
2369             '(:help "Cancel an article you posted"))]
2370        ["Reply" gnus-summary-reply t]
2371        ["Reply and yank" gnus-summary-reply-with-original t]
2372        ["Wide reply" gnus-summary-wide-reply t]
2373        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2374         ,@(if (featurep 'xemacs) '(t)
2375             '(:help "Mail a reply, quoting this article"))]
2376        ["Very wide reply" gnus-summary-very-wide-reply t]
2377        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2378         ,@(if (featurep 'xemacs) '(t)
2379             '(:help "Mail a very wide reply, quoting this article"))]
2380        ["Mail forward" gnus-summary-mail-forward t]
2381        ["Post forward" gnus-summary-post-forward t]
2382        ["Digest and mail" gnus-summary-digest-mail-forward t]
2383        ["Digest and post" gnus-summary-digest-post-forward t]
2384        ["Resend message" gnus-summary-resend-message t]
2385        ["Resend message edit" gnus-summary-resend-message-edit t]
2386        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2387        ["Send a mail" gnus-summary-mail-other-window t]
2388        ["Create a local message" gnus-summary-news-other-window t]
2389        ["Uuencode and post" gnus-uu-post-news
2390         ,@(if (featurep 'xemacs) '(t)
2391             '(:help "Post a uuencoded article"))]
2392        ["Followup via news" gnus-summary-followup-to-mail t]
2393        ["Followup via news and yank"
2394         gnus-summary-followup-to-mail-with-original t]
2395        ;;("Draft"
2396        ;;["Send" gnus-summary-send-draft t]
2397        ;;["Send bounced" gnus-resend-bounced-mail t])
2398        ))
2399
2400     (cond
2401      ((not (keymapp gnus-summary-post-menu))
2402       (setq gnus-article-post-menu gnus-summary-post-menu))
2403      ((not gnus-article-post-menu)
2404       ;; Don't share post menu.
2405       (setq gnus-article-post-menu
2406             (copy-keymap gnus-summary-post-menu))))
2407     (define-key gnus-article-mode-map [menu-bar post]
2408       (cons "Post" gnus-article-post-menu))
2409
2410     (easy-menu-define
2411      gnus-summary-misc-menu gnus-summary-mode-map ""
2412      `("Gnus"
2413        ("Mark Read"
2414         ["Mark as read" gnus-summary-mark-as-read-forward t]
2415         ["Mark same subject and select"
2416          gnus-summary-kill-same-subject-and-select t]
2417         ["Mark same subject" gnus-summary-kill-same-subject t]
2418         ["Catchup" gnus-summary-catchup
2419          ,@(if (featurep 'xemacs) '(t)
2420              '(:help "Mark unread articles in this group as read"))]
2421         ["Catchup all" gnus-summary-catchup-all t]
2422         ["Catchup to here" gnus-summary-catchup-to-here t]
2423         ["Catchup from here" gnus-summary-catchup-from-here t]
2424         ["Catchup region" gnus-summary-mark-region-as-read
2425          (gnus-mark-active-p)]
2426         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2427        ("Mark Various"
2428         ["Tick" gnus-summary-tick-article-forward t]
2429         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2430         ["Remove marks" gnus-summary-clear-mark-forward t]
2431         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2432         ["Set bookmark" gnus-summary-set-bookmark t]
2433         ["Remove bookmark" gnus-summary-remove-bookmark t])
2434        ("Limit to"
2435         ["Marks..." gnus-summary-limit-to-marks t]
2436         ["Subject..." gnus-summary-limit-to-subject t]
2437         ["Author..." gnus-summary-limit-to-author t]
2438         ["Age..." gnus-summary-limit-to-age t]
2439         ["Extra..." gnus-summary-limit-to-extra t]
2440         ["Score..." gnus-summary-limit-to-score t]
2441         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2442         ["Unread" gnus-summary-limit-to-unread t]
2443         ["Unseen" gnus-summary-limit-to-unseen t]
2444         ["Replied" gnus-summary-limit-to-replied t]
2445         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2446         ["Next articles" gnus-summary-limit-to-articles t]
2447         ["Pop limit" gnus-summary-pop-limit t]
2448         ["Show dormant" gnus-summary-limit-include-dormant t]
2449         ["Hide childless dormant"
2450          gnus-summary-limit-exclude-childless-dormant t]
2451         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2452         ["Hide marked" gnus-summary-limit-exclude-marks t]
2453         ["Show expunged" gnus-summary-limit-include-expunged t])
2454        ("Process Mark"
2455         ["Set mark" gnus-summary-mark-as-processable t]
2456         ["Remove mark" gnus-summary-unmark-as-processable t]
2457         ["Remove all marks" gnus-summary-unmark-all-processable t]
2458         ["Mark above" gnus-uu-mark-over t]
2459         ["Mark series" gnus-uu-mark-series t]
2460         ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2461         ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2462         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2463         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2464         ["Mark all" gnus-uu-mark-all t]
2465         ["Mark buffer" gnus-uu-mark-buffer t]
2466         ["Mark sparse" gnus-uu-mark-sparse t]
2467         ["Mark thread" gnus-uu-mark-thread t]
2468         ["Unmark thread" gnus-uu-unmark-thread t]
2469         ("Process Mark Sets"
2470          ["Kill" gnus-summary-kill-process-mark t]
2471          ["Yank" gnus-summary-yank-process-mark
2472           gnus-newsgroup-process-stack]
2473          ["Save" gnus-summary-save-process-mark t]
2474          ["Run command on marked..." gnus-summary-universal-argument t]))
2475        ("Scroll article"
2476         ["Page forward" gnus-summary-next-page
2477          ,@(if (featurep 'xemacs) '(t)
2478              '(:help "Show next page of article"))]
2479         ["Page backward" gnus-summary-prev-page
2480          ,@(if (featurep 'xemacs) '(t)
2481              '(:help "Show previous page of article"))]
2482         ["Line forward" gnus-summary-scroll-up t])
2483        ("Move"
2484         ["Next unread article" gnus-summary-next-unread-article t]
2485         ["Previous unread article" gnus-summary-prev-unread-article t]
2486         ["Next article" gnus-summary-next-article t]
2487         ["Previous article" gnus-summary-prev-article t]
2488         ["Next unread subject" gnus-summary-next-unread-subject t]
2489         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2490         ["Next article same subject" gnus-summary-next-same-subject t]
2491         ["Previous article same subject" gnus-summary-prev-same-subject t]
2492         ["First unread article" gnus-summary-first-unread-article t]
2493         ["Best unread article" gnus-summary-best-unread-article t]
2494         ["Go to subject number..." gnus-summary-goto-subject t]
2495         ["Go to article number..." gnus-summary-goto-article t]
2496         ["Go to the last article" gnus-summary-goto-last-article t]
2497         ["Pop article off history" gnus-summary-pop-article t])
2498        ("Sort"
2499         ["Sort by number" gnus-summary-sort-by-number t]
2500         ["Sort by author" gnus-summary-sort-by-author t]
2501         ["Sort by subject" gnus-summary-sort-by-subject t]
2502         ["Sort by date" gnus-summary-sort-by-date t]
2503         ["Sort by score" gnus-summary-sort-by-score t]
2504         ["Sort by lines" gnus-summary-sort-by-lines t]
2505         ["Sort by characters" gnus-summary-sort-by-chars t]
2506         ["Randomize" gnus-summary-sort-by-random t]
2507         ["Original sort" gnus-summary-sort-by-original t])
2508        ("Help"
2509         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2510         ["Describe group" gnus-summary-describe-group t]
2511         ["Fetch charter" gnus-group-fetch-charter
2512          ,@(if (featurep 'xemacs) nil
2513              '(:help "Display the charter of the current group"))]
2514         ["Fetch control message" gnus-group-fetch-control
2515          ,@(if (featurep 'xemacs) nil
2516              '(:help "Display the archived control message for the current group"))]
2517         ["Read manual" gnus-info-find-node t])
2518        ("Modes"
2519         ["Pick and read" gnus-pick-mode t]
2520         ["Binary" gnus-binary-mode t])
2521        ("Regeneration"
2522         ["Regenerate" gnus-summary-prepare t]
2523         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2524         ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2525         ["Toggle threading" gnus-summary-toggle-threads t])
2526        ["See old articles" gnus-summary-insert-old-articles t]
2527        ["See new articles" gnus-summary-insert-new-articles t]
2528        ["Filter articles..." gnus-summary-execute-command t]
2529        ["Run command on articles..." gnus-summary-universal-argument t]
2530        ["Search articles forward..." gnus-summary-search-article-forward t]
2531        ["Search articles backward..." gnus-summary-search-article-backward t]
2532        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2533        ["Expand window" gnus-summary-expand-window t]
2534        ["Expire expirable articles" gnus-summary-expire-articles
2535         (gnus-check-backend-function
2536          'request-expire-articles gnus-newsgroup-name)]
2537        ["Edit local kill file" gnus-summary-edit-local-kill t]
2538        ["Edit main kill file" gnus-summary-edit-global-kill t]
2539        ["Edit group parameters" gnus-summary-edit-parameters t]
2540        ["Customize group parameters" gnus-summary-customize-parameters t]
2541        ["Send a bug report" gnus-bug t]
2542        ("Exit"
2543         ["Catchup and exit" gnus-summary-catchup-and-exit
2544          ,@(if (featurep 'xemacs) '(t)
2545              '(:help "Mark unread articles in this group as read, then exit"))]
2546         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2547         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2548         ["Exit group" gnus-summary-exit
2549          ,@(if (featurep 'xemacs) '(t)
2550              '(:help "Exit current group, return to group selection mode"))]
2551         ["Exit group without updating" gnus-summary-exit-no-update t]
2552         ["Exit and goto next group" gnus-summary-next-group t]
2553         ["Exit and goto prev group" gnus-summary-prev-group t]
2554         ["Reselect group" gnus-summary-reselect-current-group t]
2555         ["Rescan group" gnus-summary-rescan-group t]
2556         ["Update dribble" gnus-summary-save-newsrc t])))
2557
2558     (gnus-run-hooks 'gnus-summary-menu-hook)))
2559
2560 (defvar gnus-summary-tool-bar-map nil)
2561
2562 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2563 (defun gnus-summary-make-tool-bar ()
2564   (if (and (fboundp 'tool-bar-add-item-from-menu)
2565            (default-value 'tool-bar-mode)
2566            (not gnus-summary-tool-bar-map))
2567       (setq gnus-summary-tool-bar-map
2568             (let ((tool-bar-map (make-sparse-keymap))
2569                   (load-path (mm-image-load-path)))
2570               (tool-bar-add-item-from-menu
2571                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2572               (tool-bar-add-item-from-menu
2573                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2574               (tool-bar-add-item-from-menu
2575                'gnus-summary-post-news "post" gnus-summary-mode-map)
2576               (tool-bar-add-item-from-menu
2577                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2578               (tool-bar-add-item-from-menu
2579                'gnus-summary-followup "followup" gnus-summary-mode-map)
2580               (tool-bar-add-item-from-menu
2581                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2582               (tool-bar-add-item-from-menu
2583                'gnus-summary-reply "reply" gnus-summary-mode-map)
2584               (tool-bar-add-item-from-menu
2585                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2586               (tool-bar-add-item-from-menu
2587                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2588               (tool-bar-add-item-from-menu
2589                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2590               (tool-bar-add-item-from-menu
2591                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2592               (tool-bar-add-item-from-menu
2593                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2594               (tool-bar-add-item-from-menu
2595                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2596               (tool-bar-add-item-from-menu
2597                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2598               (tool-bar-add-item-from-menu
2599                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2600               (tool-bar-add-item-from-menu
2601                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2602               tool-bar-map)))
2603   (if gnus-summary-tool-bar-map
2604       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2605
2606 (defun gnus-score-set-default (var value)
2607   "A version of set that updates the GNU Emacs menu-bar."
2608   (set var value)
2609   ;; It is the message that forces the active status to be updated.
2610   (message ""))
2611
2612 (defun gnus-make-score-map (type)
2613   "Make a summary score map of type TYPE."
2614   (if t
2615       nil
2616     (let ((headers '(("author" "from" string)
2617                      ("subject" "subject" string)
2618                      ("article body" "body" string)
2619                      ("article head" "head" string)
2620                      ("xref" "xref" string)
2621                      ("extra header" "extra" string)
2622                      ("lines" "lines" number)
2623                      ("followups to author" "followup" string)))
2624           (types '((number ("less than" <)
2625                            ("greater than" >)
2626                            ("equal" =))
2627                    (string ("substring" s)
2628                            ("exact string" e)
2629                            ("fuzzy string" f)
2630                            ("regexp" r))))
2631           (perms '(("temporary" (current-time-string))
2632                    ("permanent" nil)
2633                    ("immediate" now)))
2634           header)
2635       (list
2636        (apply
2637         'nconc
2638         (list
2639          (if (eq type 'lower)
2640              "Lower score"
2641            "Increase score"))
2642         (let (outh)
2643           (while headers
2644             (setq header (car headers))
2645             (setq outh
2646                   (cons
2647                    (apply
2648                     'nconc
2649                     (list (car header))
2650                     (let ((ts (cdr (assoc (nth 2 header) types)))
2651                           outt)
2652                       (while ts
2653                         (setq outt
2654                               (cons
2655                                (apply
2656                                 'nconc
2657                                 (list (caar ts))
2658                                 (let ((ps perms)
2659                                       outp)
2660                                   (while ps
2661                                     (setq outp
2662                                           (cons
2663                                            (vector
2664                                             (caar ps)
2665                                             (list
2666                                              'gnus-summary-score-entry
2667                                              (nth 1 header)
2668                                              (if (or (string= (nth 1 header)
2669                                                               "head")
2670                                                      (string= (nth 1 header)
2671                                                               "body"))
2672                                                  ""
2673                                                (list 'gnus-summary-header
2674                                                      (nth 1 header)))
2675                                              (list 'quote (nth 1 (car ts)))
2676                                              (list 'gnus-score-delta-default
2677                                                    nil)
2678                                              (nth 1 (car ps))
2679                                              t)
2680                                             t)
2681                                            outp))
2682                                     (setq ps (cdr ps)))
2683                                   (list (nreverse outp))))
2684                                outt))
2685                         (setq ts (cdr ts)))
2686                       (list (nreverse outt))))
2687                    outh))
2688             (setq headers (cdr headers)))
2689           (list (nreverse outh))))))))
2690
2691 \f
2692
2693 (defun gnus-summary-mode (&optional group)
2694   "Major mode for reading articles.
2695
2696 All normal editing commands are switched off.
2697 \\<gnus-summary-mode-map>
2698 Each line in this buffer represents one article.  To read an
2699 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2700 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2701 respectively.
2702
2703 You can also post articles and send mail from this buffer.  To
2704 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2705 of an article, type `\\[gnus-summary-reply]'.
2706
2707 There are approx. one gazillion commands you can execute in this
2708 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2709
2710 The following commands are available:
2711
2712 \\{gnus-summary-mode-map}"
2713   (interactive)
2714   (kill-all-local-variables)
2715   (when (gnus-visual-p 'summary-menu 'menu)
2716     (gnus-summary-make-menu-bar)
2717     (gnus-summary-make-tool-bar))
2718   (gnus-summary-make-local-variables)
2719   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2720     (gnus-summary-make-local-variables))
2721   (gnus-make-thread-indent-array)
2722   (gnus-simplify-mode-line)
2723   (setq major-mode 'gnus-summary-mode)
2724   (setq mode-name "Summary")
2725   (make-local-variable 'minor-mode-alist)
2726   (use-local-map gnus-summary-mode-map)
2727   (buffer-disable-undo)
2728   (setq buffer-read-only t              ;Disable modification
2729         show-trailing-whitespace nil)
2730   (setq truncate-lines t)
2731   (setq selective-display t)
2732   (setq selective-display-ellipses t)   ;Display `...'
2733   (gnus-summary-set-display-table)
2734   (gnus-set-default-directory)
2735   (setq gnus-newsgroup-name group)
2736   (unless (gnus-news-group-p group)
2737     (setq gnus-newsgroup-incorporated
2738           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2739   (make-local-variable 'gnus-summary-line-format)
2740   (make-local-variable 'gnus-summary-line-format-spec)
2741   (make-local-variable 'gnus-summary-dummy-line-format)
2742   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2743   (make-local-variable 'gnus-summary-mark-positions)
2744   (gnus-make-local-hook 'pre-command-hook)
2745   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2746   (gnus-run-hooks 'gnus-summary-mode-hook)
2747   (turn-on-gnus-mailing-list-mode)
2748   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2749   (gnus-update-summary-mark-positions))
2750
2751 (defun gnus-summary-make-local-variables ()
2752   "Make all the local summary buffer variables."
2753   (let (global)
2754     (dolist (local gnus-summary-local-variables)
2755       (if (consp local)
2756           (progn
2757             (if (eq (cdr local) 'global)
2758                 ;; Copy the global value of the variable.
2759                 (setq global (symbol-value (car local)))
2760               ;; Use the value from the list.
2761               (setq global (eval (cdr local))))
2762             (set (make-local-variable (car local)) global))
2763         ;; Simple nil-valued local variable.
2764         (set (make-local-variable local) nil)))))
2765
2766 (defun gnus-summary-clear-local-variables ()
2767   (let ((locals gnus-summary-local-variables))
2768     (while locals
2769       (if (consp (car locals))
2770           (and (vectorp (caar locals))
2771                (set (caar locals) nil))
2772         (and (vectorp (car locals))
2773              (set (car locals) nil)))
2774       (setq locals (cdr locals)))))
2775
2776 ;; Summary data functions.
2777
2778 (defmacro gnus-data-number (data)
2779   `(car ,data))
2780
2781 (defmacro gnus-data-set-number (data number)
2782   `(setcar ,data ,number))
2783
2784 (defmacro gnus-data-mark (data)
2785   `(nth 1 ,data))
2786
2787 (defmacro gnus-data-set-mark (data mark)
2788   `(setcar (nthcdr 1 ,data) ,mark))
2789
2790 (defmacro gnus-data-pos (data)
2791   `(nth 2 ,data))
2792
2793 (defmacro gnus-data-set-pos (data pos)
2794   `(setcar (nthcdr 2 ,data) ,pos))
2795
2796 (defmacro gnus-data-header (data)
2797   `(nth 3 ,data))
2798
2799 (defmacro gnus-data-set-header (data header)
2800   `(setcar (nthcdr 3 ,data) ,header))
2801
2802 (defmacro gnus-data-level (data)
2803   `(nth 4 ,data))
2804
2805 (defmacro gnus-data-unread-p (data)
2806   `(= (nth 1 ,data) gnus-unread-mark))
2807
2808 (defmacro gnus-data-read-p (data)
2809   `(/= (nth 1 ,data) gnus-unread-mark))
2810
2811 (defmacro gnus-data-pseudo-p (data)
2812   `(consp (nth 3 ,data)))
2813
2814 (defmacro gnus-data-find (number)
2815   `(assq ,number gnus-newsgroup-data))
2816
2817 (defmacro gnus-data-find-list (number &optional data)
2818   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2819      (memq (assq ,number bdata)
2820            bdata)))
2821
2822 (defmacro gnus-data-make (number mark pos header level)
2823   `(list ,number ,mark ,pos ,header ,level))
2824
2825 (defun gnus-data-enter (after-article number mark pos header level offset)
2826   (let ((data (gnus-data-find-list after-article)))
2827     (unless data
2828       (error "No such article: %d" after-article))
2829     (setcdr data (cons (gnus-data-make number mark pos header level)
2830                        (cdr data)))
2831     (setq gnus-newsgroup-data-reverse nil)
2832     (gnus-data-update-list (cddr data) offset)))
2833
2834 (defun gnus-data-enter-list (after-article list &optional offset)
2835   (when list
2836     (let ((data (and after-article (gnus-data-find-list after-article)))
2837           (ilist list))
2838       (if (not (or data
2839                    after-article))
2840           (let ((odata gnus-newsgroup-data))
2841             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2842             (when offset
2843               (gnus-data-update-list odata offset)))
2844         ;; Find the last element in the list to be spliced into the main
2845         ;; list.
2846         (while (cdr list)
2847           (setq list (cdr list)))
2848         (if (not data)
2849             (progn
2850               (setcdr list gnus-newsgroup-data)
2851               (setq gnus-newsgroup-data ilist)
2852               (when offset
2853                 (gnus-data-update-list (cdr list) offset)))
2854           (setcdr list (cdr data))
2855           (setcdr data ilist)
2856           (when offset
2857             (gnus-data-update-list (cdr list) offset))))
2858       (setq gnus-newsgroup-data-reverse nil))))
2859
2860 (defun gnus-data-remove (article &optional offset)
2861   (let ((data gnus-newsgroup-data))
2862     (if (= (gnus-data-number (car data)) article)
2863         (progn
2864           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2865                 gnus-newsgroup-data-reverse nil)
2866           (when offset
2867             (gnus-data-update-list gnus-newsgroup-data offset)))
2868       (while (cdr data)
2869         (when (= (gnus-data-number (cadr data)) article)
2870           (setcdr data (cddr data))
2871           (when offset
2872             (gnus-data-update-list (cdr data) offset))
2873           (setq data nil
2874                 gnus-newsgroup-data-reverse nil))
2875         (setq data (cdr data))))))
2876
2877 (defmacro gnus-data-list (backward)
2878   `(if ,backward
2879        (or gnus-newsgroup-data-reverse
2880            (setq gnus-newsgroup-data-reverse
2881                  (reverse gnus-newsgroup-data)))
2882      gnus-newsgroup-data))
2883
2884 (defun gnus-data-update-list (data offset)
2885   "Add OFFSET to the POS of all data entries in DATA."
2886   (setq gnus-newsgroup-data-reverse nil)
2887   (while data
2888     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2889     (setq data (cdr data))))
2890
2891 (defun gnus-summary-article-pseudo-p (article)
2892   "Say whether this article is a pseudo article or not."
2893   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2894
2895 (defmacro gnus-summary-article-sparse-p (article)
2896   "Say whether this article is a sparse article or not."
2897   `(memq ,article gnus-newsgroup-sparse))
2898
2899 (defmacro gnus-summary-article-ancient-p (article)
2900   "Say whether this article is a sparse article or not."
2901   `(memq ,article gnus-newsgroup-ancient))
2902
2903 (defun gnus-article-parent-p (number)
2904   "Say whether this article is a parent or not."
2905   (let ((data (gnus-data-find-list number)))
2906     (and (cdr data)                     ; There has to be an article after...
2907          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2908             (gnus-data-level (nth 1 data))))))
2909
2910 (defun gnus-article-children (number)
2911   "Return a list of all children to NUMBER."
2912   (let* ((data (gnus-data-find-list number))
2913          (level (gnus-data-level (car data)))
2914          children)
2915     (setq data (cdr data))
2916     (while (and data
2917                 (= (gnus-data-level (car data)) (1+ level)))
2918       (push (gnus-data-number (car data)) children)
2919       (setq data (cdr data)))
2920     children))
2921
2922 (defmacro gnus-summary-skip-intangible ()
2923   "If the current article is intangible, then jump to a different article."
2924   '(let ((to (get-text-property (point) 'gnus-intangible)))
2925      (and to (gnus-summary-goto-subject to))))
2926
2927 (defmacro gnus-summary-article-intangible-p ()
2928   "Say whether this article is intangible or not."
2929   '(get-text-property (point) 'gnus-intangible))
2930
2931 (defun gnus-article-read-p (article)
2932   "Say whether ARTICLE is read or not."
2933   (not (or (memq article gnus-newsgroup-marked)
2934            (memq article gnus-newsgroup-spam-marked)
2935            (memq article gnus-newsgroup-unreads)
2936            (memq article gnus-newsgroup-unselected)
2937            (memq article gnus-newsgroup-dormant))))
2938
2939 ;; Some summary mode macros.
2940
2941 (defmacro gnus-summary-article-number ()
2942   "The article number of the article on the current line.
2943 If there isn't an article number here, then we return the current
2944 article number."
2945   '(progn
2946      (gnus-summary-skip-intangible)
2947      (or (get-text-property (point) 'gnus-number)
2948          (gnus-summary-last-subject))))
2949
2950 (defmacro gnus-summary-article-header (&optional number)
2951   "Return the header of article NUMBER."
2952   `(gnus-data-header (gnus-data-find
2953                       ,(or number '(gnus-summary-article-number)))))
2954
2955 (defmacro gnus-summary-thread-level (&optional number)
2956   "Return the level of thread that starts with article NUMBER."
2957   `(if (and (eq gnus-summary-make-false-root 'dummy)
2958             (get-text-property (point) 'gnus-intangible))
2959        0
2960      (gnus-data-level (gnus-data-find
2961                        ,(or number '(gnus-summary-article-number))))))
2962
2963 (defmacro gnus-summary-article-mark (&optional number)
2964   "Return the mark of article NUMBER."
2965   `(gnus-data-mark (gnus-data-find
2966                     ,(or number '(gnus-summary-article-number)))))
2967
2968 (defmacro gnus-summary-article-pos (&optional number)
2969   "Return the position of the line of article NUMBER."
2970   `(gnus-data-pos (gnus-data-find
2971                    ,(or number '(gnus-summary-article-number)))))
2972
2973 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2974 (defmacro gnus-summary-article-subject (&optional number)
2975   "Return current subject string or nil if nothing."
2976   `(let ((headers
2977           ,(if number
2978                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2979              '(gnus-data-header (assq (gnus-summary-article-number)
2980                                       gnus-newsgroup-data)))))
2981      (and headers
2982           (vectorp headers)
2983           (mail-header-subject headers))))
2984
2985 (defmacro gnus-summary-article-score (&optional number)
2986   "Return current article score."
2987   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2988                   gnus-newsgroup-scored))
2989        gnus-summary-default-score 0))
2990
2991 (defun gnus-summary-article-children (&optional number)
2992   "Return a list of article numbers that are children of article NUMBER."
2993   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2994          (level (gnus-data-level (car data)))
2995          l children)
2996     (while (and (setq data (cdr data))
2997                 (> (setq l (gnus-data-level (car data))) level))
2998       (and (= (1+ level) l)
2999            (push (gnus-data-number (car data))
3000                  children)))
3001     (nreverse children)))
3002
3003 (defun gnus-summary-article-parent (&optional number)
3004   "Return the article number of the parent of article NUMBER."
3005   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3006                                     (gnus-data-list t)))
3007          (level (gnus-data-level (car data))))
3008     (if (zerop level)
3009         ()                              ; This is a root.
3010       ;; We search until we find an article with a level less than
3011       ;; this one.  That function has to be the parent.
3012       (while (and (setq data (cdr data))
3013                   (not (< (gnus-data-level (car data)) level))))
3014       (and data (gnus-data-number (car data))))))
3015
3016 (defun gnus-unread-mark-p (mark)
3017   "Say whether MARK is the unread mark."
3018   (= mark gnus-unread-mark))
3019
3020 (defun gnus-read-mark-p (mark)
3021   "Say whether MARK is one of the marks that mark as read.
3022 This is all marks except unread, ticked, dormant, and expirable."
3023   (not (or (= mark gnus-unread-mark)
3024            (= mark gnus-ticked-mark)
3025            (= mark gnus-spam-mark)
3026            (= mark gnus-dormant-mark)
3027            (= mark gnus-expirable-mark))))
3028
3029 (defmacro gnus-article-mark (number)
3030   "Return the MARK of article NUMBER.
3031 This macro should only be used when computing the mark the \"first\"
3032 time; i.e., when generating the summary lines.  After that,
3033 `gnus-summary-article-mark' should be used to examine the
3034 marks of articles."
3035   `(cond
3036     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3037     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3038     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3039     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3040     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3041     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3042     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3043     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3044            gnus-ancient-mark))))
3045
3046 ;; Saving hidden threads.
3047
3048 (defmacro gnus-save-hidden-threads (&rest forms)
3049   "Save hidden threads, eval FORMS, and restore the hidden threads."
3050   (let ((config (make-symbol "config")))
3051     `(let ((,config (gnus-hidden-threads-configuration)))
3052        (unwind-protect
3053            (save-excursion
3054              ,@forms)
3055          (gnus-restore-hidden-threads-configuration ,config)))))
3056 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3057 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3058
3059 (defun gnus-data-compute-positions ()
3060   "Compute the positions of all articles."
3061   (setq gnus-newsgroup-data-reverse nil)
3062   (let ((data gnus-newsgroup-data))
3063     (save-excursion
3064       (gnus-save-hidden-threads
3065         (gnus-summary-show-all-threads)
3066         (goto-char (point-min))
3067         (while data
3068           (while (get-text-property (point) 'gnus-intangible)
3069             (forward-line 1))
3070           (gnus-data-set-pos (car data) (+ (point) 3))
3071           (setq data (cdr data))
3072           (forward-line 1))))))
3073
3074 (defun gnus-hidden-threads-configuration ()
3075   "Return the current hidden threads configuration."
3076   (save-excursion
3077     (let (config)
3078       (goto-char (point-min))
3079       (while (search-forward "\r" nil t)
3080         (push (1- (point)) config))
3081       config)))
3082
3083 (defun gnus-restore-hidden-threads-configuration (config)
3084   "Restore hidden threads configuration from CONFIG."
3085   (save-excursion
3086     (let (point buffer-read-only)
3087       (while (setq point (pop config))
3088         (when (and (< point (point-max))
3089                    (goto-char point)
3090                    (eq (char-after) ?\n))
3091           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3092
3093 ;; Various summary mode internalish functions.
3094
3095 (defun gnus-mouse-pick-article (e)
3096   (interactive "e")
3097   (mouse-set-point e)
3098   (gnus-summary-next-page nil t))
3099
3100 (defun gnus-summary-set-display-table ()
3101   "Change the display table.
3102 Odd characters have a tendency to mess
3103 up nicely formatted displays - we make all possible glyphs
3104 display only a single character."
3105
3106   ;; We start from the standard display table, if any.
3107   (let ((table (or (copy-sequence standard-display-table)
3108                    (make-display-table)))
3109         (i 32))
3110     ;; Nix out all the control chars...
3111     (while (>= (setq i (1- i)) 0)
3112       (aset table i [??]))
3113     ;; ... but not newline and cr, of course.  (cr is necessary for the
3114     ;; selective display).
3115     (aset table ?\n nil)
3116     (aset table ?\r nil)
3117     ;; We keep TAB as well.
3118     (aset table ?\t nil)
3119     ;; We nix out any glyphs over 126 that are not set already.
3120     (let ((i 256))
3121       (while (>= (setq i (1- i)) 127)
3122         ;; Only modify if the entry is nil.
3123         (unless (aref table i)
3124           (aset table i [??]))))
3125     (setq buffer-display-table table)))
3126
3127 (defun gnus-summary-set-article-display-arrow (pos)
3128   "Update the overlay arrow to point to line at position POS."
3129   (when (and gnus-summary-display-arrow
3130              (boundp 'overlay-arrow-position)
3131              (boundp 'overlay-arrow-string))
3132     (save-excursion
3133       (goto-char pos)
3134       (beginning-of-line)
3135       (unless overlay-arrow-position
3136         (setq overlay-arrow-position (make-marker)))
3137       (setq overlay-arrow-string "=>"
3138             overlay-arrow-position (set-marker overlay-arrow-position
3139                                                (point)
3140                                                (current-buffer))))))
3141
3142 (defun gnus-summary-setup-buffer (group)
3143   "Initialize summary buffer."
3144   (let ((buffer (gnus-summary-buffer-name group))
3145         (dead-name (concat "*Dead Summary "
3146                            (gnus-group-decoded-name group) "*")))
3147     ;; If a dead summary buffer exists, we kill it.
3148     (when (gnus-buffer-live-p dead-name)
3149       (gnus-kill-buffer dead-name))
3150     (if (get-buffer buffer)
3151         (progn
3152           (set-buffer buffer)
3153           (setq gnus-summary-buffer (current-buffer))
3154           (not gnus-newsgroup-prepared))
3155       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3156       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3157       (gnus-summary-mode group)
3158       (when gnus-carpal
3159         (gnus-carpal-setup-buffer 'summary))
3160       (unless gnus-single-article-buffer
3161         (make-local-variable 'gnus-article-buffer)
3162         (make-local-variable 'gnus-article-current)
3163         (make-local-variable 'gnus-original-article-buffer))
3164       (setq gnus-newsgroup-name group)
3165       ;; Set any local variables in the group parameters.
3166       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3167       t)))
3168
3169 (defun gnus-set-global-variables ()
3170   "Set the global equivalents of the buffer-local variables.
3171 They are set to the latest values they had.  These reflect the summary
3172 buffer that was in action when the last article was fetched."
3173   (when (eq major-mode 'gnus-summary-mode)
3174     (setq gnus-summary-buffer (current-buffer))
3175     (let ((name gnus-newsgroup-name)
3176           (marked gnus-newsgroup-marked)
3177           (spam gnus-newsgroup-spam-marked)
3178           (unread gnus-newsgroup-unreads)
3179           (headers gnus-current-headers)
3180           (data gnus-newsgroup-data)
3181           (summary gnus-summary-buffer)
3182           (article-buffer gnus-article-buffer)
3183           (original gnus-original-article-buffer)
3184           (gac gnus-article-current)
3185           (reffed gnus-reffed-article-number)
3186           (score-file gnus-current-score-file)
3187           (default-charset gnus-newsgroup-charset)
3188           vlist)
3189       (let ((locals gnus-newsgroup-variables))
3190         (while locals
3191           (if (consp (car locals))
3192               (push (eval (caar locals)) vlist)
3193             (push (eval (car locals)) vlist))
3194           (setq locals (cdr locals)))
3195         (setq vlist (nreverse vlist)))
3196       (with-current-buffer gnus-group-buffer
3197         (setq gnus-newsgroup-name name
3198               gnus-newsgroup-marked marked
3199               gnus-newsgroup-spam-marked spam
3200               gnus-newsgroup-unreads unread
3201               gnus-current-headers headers
3202               gnus-newsgroup-data data
3203               gnus-article-current gac
3204               gnus-summary-buffer summary
3205               gnus-article-buffer article-buffer
3206               gnus-original-article-buffer original
3207               gnus-reffed-article-number reffed
3208               gnus-current-score-file score-file
3209               gnus-newsgroup-charset default-charset)
3210         (let ((locals gnus-newsgroup-variables))
3211           (while locals
3212             (if (consp (car locals))
3213                 (set (caar locals) (pop vlist))
3214               (set (car locals) (pop vlist)))
3215             (setq locals (cdr locals))))
3216         ;; The article buffer also has local variables.
3217         (when (gnus-buffer-live-p gnus-article-buffer)
3218           (set-buffer gnus-article-buffer)
3219           (setq gnus-summary-buffer summary))))))
3220
3221 (defun gnus-summary-article-unread-p (article)
3222   "Say whether ARTICLE is unread or not."
3223   (memq article gnus-newsgroup-unreads))
3224
3225 (defun gnus-summary-first-article-p (&optional article)
3226   "Return whether ARTICLE is the first article in the buffer."
3227   (if (not (setq article (or article (gnus-summary-article-number))))
3228       nil
3229     (eq article (caar gnus-newsgroup-data))))
3230
3231 (defun gnus-summary-last-article-p (&optional article)
3232   "Return whether ARTICLE is the last article in the buffer."
3233   (if (not (setq article (or article (gnus-summary-article-number))))
3234       ;; All non-existent numbers are the last article.  :-)
3235       t
3236     (not (cdr (gnus-data-find-list article)))))
3237
3238 (defun gnus-make-thread-indent-array ()
3239   (let ((n 200))
3240     (unless (and gnus-thread-indent-array
3241                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3242       (setq gnus-thread-indent-array (make-vector 201 "")
3243             gnus-thread-indent-array-level gnus-thread-indent-level)
3244       (while (>= n 0)
3245         (aset gnus-thread-indent-array n
3246               (make-string (* n gnus-thread-indent-level) ? ))
3247         (setq n (1- n))))))
3248
3249 (defun gnus-update-summary-mark-positions ()
3250   "Compute where the summary marks are to go."
3251   (save-excursion
3252     (when (gnus-buffer-exists-p gnus-summary-buffer)
3253       (set-buffer gnus-summary-buffer))
3254     (let ((gnus-replied-mark 129)
3255           (gnus-score-below-mark 130)
3256           (gnus-score-over-mark 130)
3257           (gnus-undownloaded-mark 131)
3258           (spec gnus-summary-line-format-spec)
3259           gnus-visual pos)
3260       (save-excursion
3261         (gnus-set-work-buffer)
3262         (let ((gnus-summary-line-format-spec spec)
3263               (gnus-newsgroup-downloadable '(0)))
3264           (gnus-summary-insert-line
3265            (make-full-mail-header 0 "" "nobody"
3266                                   "05 Apr 2001 23:33:09 +0400"
3267                                   "" "" 0 0 "" nil)
3268            0 nil t 128 t nil "" nil 1)
3269           (goto-char (point-min))
3270           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3271                                              (- (point) (point-min) 1)))))
3272           (goto-char (point-min))
3273           (push (cons 'replied (and (search-forward "\201" nil t)
3274                                     (- (point) (point-min) 1)))
3275                 pos)
3276           (goto-char (point-min))
3277           (push (cons 'score (and (search-forward "\202" nil t)
3278                                   (- (point) (point-min) 1)))
3279                 pos)
3280           (goto-char (point-min))
3281           (push (cons 'download
3282                       (and (search-forward "\203" nil t)
3283                            (- (point) (point-min) 1)))
3284                 pos)))
3285       (setq gnus-summary-mark-positions pos))))
3286
3287 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3288   "Insert a dummy root in the summary buffer."
3289   (beginning-of-line)
3290   (gnus-add-text-properties
3291    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3292    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3293
3294 (defun gnus-summary-extract-address-component (from)
3295   (or (car (funcall gnus-extract-address-components from))
3296       from))
3297
3298 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3299   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3300                                 default-mime-charset)))
3301     ;; Is it really necessary to do this next part for each summary line?
3302     ;; Luckily, doesn't seem to slow things down much.
3303     (or
3304      (and gnus-ignored-from-addresses
3305           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3306           (let ((extra-headers (mail-header-extra header))
3307                 to
3308                 newsgroups)
3309             (cond
3310              ((setq to (cdr (assq 'To extra-headers)))
3311               (concat "-> "
3312                       (inline
3313                         (gnus-summary-extract-address-component
3314                          (funcall gnus-decode-encoded-word-function to)))))
3315              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3316               (concat "=> " newsgroups)))))
3317      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3318
3319 (defun gnus-summary-insert-line (gnus-tmp-header
3320                                  gnus-tmp-level gnus-tmp-current
3321                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3322                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3323                                  &optional gnus-tmp-dummy gnus-tmp-score
3324                                  gnus-tmp-process)
3325   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3326          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3327          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3328          (gnus-tmp-score-char
3329           (if (or (null gnus-summary-default-score)
3330                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3331                       gnus-summary-zcore-fuzz))
3332               ?\ ;;;Whitespace
3333             (if (< gnus-tmp-score gnus-summary-default-score)
3334                 gnus-score-below-mark gnus-score-over-mark)))
3335          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3336          (gnus-tmp-replied
3337           (cond (gnus-tmp-process gnus-process-mark)
3338                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3339                  gnus-cached-mark)
3340                 (gnus-tmp-replied gnus-replied-mark)
3341                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3342                  gnus-forwarded-mark)
3343                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3344                  gnus-saved-mark)
3345                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3346                  gnus-recent-mark)
3347                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3348                  gnus-unseen-mark)
3349                 (t gnus-no-mark)))
3350          (gnus-tmp-downloaded
3351           (cond (undownloaded
3352                  gnus-undownloaded-mark)
3353                 (gnus-newsgroup-agentized
3354                  gnus-downloaded-mark)
3355                 (t
3356                  gnus-no-mark)))
3357          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3358          (gnus-tmp-name
3359           (cond
3360            ((string-match "<[^>]+> *$" gnus-tmp-from)
3361             (let ((beg (match-beginning 0)))
3362               (or (and (string-match "^\".+\"" gnus-tmp-from)
3363                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3364                   (substring gnus-tmp-from 0 beg))))
3365            ((string-match "(.+)" gnus-tmp-from)
3366             (substring gnus-tmp-from
3367                        (1+ (match-beginning 0)) (1- (match-end 0))))
3368            (t gnus-tmp-from)))
3369          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3370          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3371          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3372          (buffer-read-only nil))
3373     (when (string= gnus-tmp-name "")
3374       (setq gnus-tmp-name gnus-tmp-from))
3375     (unless (numberp gnus-tmp-lines)
3376       (setq gnus-tmp-lines -1))
3377     (if (= gnus-tmp-lines -1)
3378         (setq gnus-tmp-lines "?")
3379       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3380     (gnus-put-text-property-excluding-characters-with-faces
3381      (point)
3382      (progn (eval gnus-summary-line-format-spec) (point))
3383      'gnus-number gnus-tmp-number)
3384     (when (gnus-visual-p 'summary-highlight 'highlight)
3385       (forward-line -1)
3386       (gnus-run-hooks 'gnus-summary-update-hook)
3387       (forward-line 1))))
3388
3389 (defun gnus-summary-update-line (&optional dont-update)
3390   "Update summary line after change."
3391   (when (and gnus-summary-default-score
3392              (not gnus-summary-inhibit-highlight))
3393     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3394            (article (gnus-summary-article-number))
3395            (score (gnus-summary-article-score article)))
3396       (unless dont-update
3397         (if (and gnus-summary-mark-below
3398                  (< (gnus-summary-article-score)
3399                     gnus-summary-mark-below))
3400             ;; This article has a low score, so we mark it as read.
3401             (when (memq article gnus-newsgroup-unreads)
3402               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3403           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3404             ;; This article was previously marked as read on account
3405             ;; of a low score, but now it has risen, so we mark it as
3406             ;; unread.
3407             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3408         (gnus-summary-update-mark
3409          (if (or (null gnus-summary-default-score)
3410                  (<= (abs (- score gnus-summary-default-score))
3411                      gnus-summary-zcore-fuzz))
3412              ?\ ;;;Whitespace
3413            (if (< score gnus-summary-default-score)
3414                gnus-score-below-mark gnus-score-over-mark))
3415          'score))
3416       ;; Do visual highlighting.
3417       (when (gnus-visual-p 'summary-highlight 'highlight)
3418         (gnus-run-hooks 'gnus-summary-update-hook)))))
3419
3420 (defvar gnus-tmp-new-adopts nil)
3421
3422 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3423   "Return the number of articles in THREAD.
3424 This may be 0 in some cases -- if none of the articles in
3425 the thread are to be displayed."
3426   (let* ((number
3427           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3428           (cond
3429            ((not (listp thread))
3430             1)
3431            ((and (consp thread) (cdr thread))
3432             (apply
3433              '+ 1 (mapcar
3434                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3435            ((null thread)
3436             1)
3437            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3438             1)
3439            (t 0))))
3440     (when (and level (zerop level) gnus-tmp-new-adopts)
3441       (incf number
3442             (apply '+ (mapcar
3443                        'gnus-summary-number-of-articles-in-thread
3444                        gnus-tmp-new-adopts))))
3445     (if char
3446         (if (> number 1) gnus-not-empty-thread-mark
3447           gnus-empty-thread-mark)
3448       number)))
3449
3450 (defsubst gnus-summary-line-message-size (head)
3451   "Return pretty-printed version of message size.
3452 This function is intended to be used in
3453 `gnus-summary-line-format-alist'."
3454   (let ((c (or (mail-header-chars head) -1)))
3455     (cond ((< c 0) "n/a")               ; chars not available
3456           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3457           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3458           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3459           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3460
3461
3462 (defun gnus-summary-set-local-parameters (group)
3463   "Go through the local params of GROUP and set all variable specs in that list."
3464   (let ((params (gnus-group-find-parameter group))
3465         (vars '(quit-config))           ; Ignore quit-config.
3466         elem)
3467     (while params
3468       (setq elem (car params)
3469             params (cdr params))
3470       (and (consp elem)                 ; Has to be a cons.
3471            (consp (cdr elem))           ; The cdr has to be a list.
3472            (symbolp (car elem))         ; Has to be a symbol in there.
3473            (not (memq (car elem) vars))
3474            (ignore-errors               ; So we set it.
3475              (push (car elem) vars)
3476              (make-local-variable (car elem))
3477              (set (car elem) (eval (nth 1 elem))))))))
3478
3479 (defun gnus-summary-read-group (group &optional show-all no-article
3480                                       kill-buffer no-display backward
3481                                       select-articles)
3482   "Start reading news in newsgroup GROUP.
3483 If SHOW-ALL is non-nil, already read articles are also listed.
3484 If NO-ARTICLE is non-nil, no article is selected initially.
3485 If NO-DISPLAY, don't generate a summary buffer."
3486   (let (result)
3487     (while (and group
3488                 (null (setq result
3489                             (let ((gnus-auto-select-next nil))
3490                               (or (gnus-summary-read-group-1
3491                                    group show-all no-article
3492                                    kill-buffer no-display
3493                                    select-articles)
3494                                   (setq show-all nil
3495                                         select-articles nil)))))
3496                 (eq gnus-auto-select-next 'quietly))
3497       (set-buffer gnus-group-buffer)
3498       ;; The entry function called above goes to the next
3499       ;; group automatically, so we go two groups back
3500       ;; if we are searching for the previous group.
3501       (when backward
3502         (gnus-group-prev-unread-group 2))
3503       (if (not (equal group (gnus-group-group-name)))
3504           (setq group (gnus-group-group-name))
3505         (setq group nil)))
3506     result))
3507
3508 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3509   "Directly jump to the other GROUP from summary buffer.
3510 If SHOW-ALL is non-nil, already read articles are also listed."
3511   (interactive
3512    (if (eq gnus-summary-buffer (current-buffer))
3513        (list (completing-read
3514               "Group: " gnus-active-hashtb nil t
3515               (when (and gnus-newsgroup-name
3516                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3517                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3518               'gnus-group-history)
3519              current-prefix-arg)
3520      (error "%s must be invoked from a gnus summary buffer." this-command)))
3521   (unless (or (zerop (length group))
3522               (and gnus-newsgroup-name
3523                    (string-equal gnus-newsgroup-name group)))
3524     (gnus-summary-exit)
3525     (gnus-summary-read-group group show-all
3526                              gnus-dont-select-after-jump-to-other-group)))
3527
3528 (defun gnus-summary-read-group-1 (group show-all no-article
3529                                         kill-buffer no-display
3530                                         &optional select-articles)
3531   ;; Killed foreign groups can't be entered.
3532   ;;  (when (and (not (gnus-group-native-p group))
3533   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3534   ;;    (error "Dead non-native groups can't be entered"))
3535   (gnus-message 5 "Retrieving newsgroup: %s..."
3536                 (gnus-group-decoded-name group))
3537   (let* ((new-group (gnus-summary-setup-buffer group))
3538          (quit-config (gnus-group-quit-config group))
3539          (did-select (and new-group (gnus-select-newsgroup
3540                                      group show-all select-articles))))
3541     (cond
3542      ;; This summary buffer exists already, so we just select it.
3543      ((not new-group)
3544       (gnus-set-global-variables)
3545       (when kill-buffer
3546         (gnus-kill-or-deaden-summary kill-buffer))
3547       (gnus-configure-windows 'summary 'force)
3548       (gnus-set-mode-line 'summary)
3549       (gnus-summary-position-point)
3550       (message "")
3551       t)
3552      ;; We couldn't select this group.
3553      ((null did-select)
3554       (when (and (eq major-mode 'gnus-summary-mode)
3555                  (not (equal (current-buffer) kill-buffer)))
3556         (kill-buffer (current-buffer))
3557         (if (not quit-config)
3558             (progn
3559               ;; Update the info -- marks might need to be removed,
3560               ;; for instance.
3561               (gnus-summary-update-info)
3562               (set-buffer gnus-group-buffer)
3563               (gnus-group-jump-to-group group)
3564               (gnus-group-next-unread-group 1))
3565           (gnus-handle-ephemeral-exit quit-config)))
3566       (let ((grpinfo (gnus-get-info group)))
3567         (if (null (gnus-info-read grpinfo))
3568             (gnus-message 3 "Group %s contains no messages"
3569                           (gnus-group-decoded-name group))
3570           (gnus-message 3 "Can't select group")))
3571       nil)
3572      ;; The user did a `C-g' while prompting for number of articles,
3573      ;; so we exit this group.
3574      ((eq did-select 'quit)
3575       (and (eq major-mode 'gnus-summary-mode)
3576            (not (equal (current-buffer) kill-buffer))
3577            (kill-buffer (current-buffer)))
3578       (when kill-buffer
3579         (gnus-kill-or-deaden-summary kill-buffer))
3580       (if (not quit-config)
3581           (progn
3582             (set-buffer gnus-group-buffer)
3583             (gnus-group-jump-to-group group)
3584             (gnus-group-next-unread-group 1)
3585             (gnus-configure-windows 'group 'force))
3586         (gnus-handle-ephemeral-exit quit-config))
3587       ;; Finally signal the quit.
3588       (signal 'quit nil))
3589      ;; The group was successfully selected.
3590      (t
3591       (gnus-set-global-variables)
3592       ;; Save the active value in effect when the group was entered.
3593       (setq gnus-newsgroup-active
3594             (gnus-copy-sequence
3595              (gnus-active gnus-newsgroup-name)))
3596       ;; You can change the summary buffer in some way with this hook.
3597       (gnus-run-hooks 'gnus-select-group-hook)
3598       (gnus-update-format-specifications
3599        nil 'summary 'summary-mode 'summary-dummy)
3600       (gnus-update-summary-mark-positions)
3601       ;; Do score processing.
3602       (when gnus-use-scoring
3603         (gnus-possibly-score-headers))
3604       ;; Check whether to fill in the gaps in the threads.
3605       (when gnus-build-sparse-threads
3606         (gnus-build-sparse-threads))
3607       ;; Find the initial limit.
3608       (if gnus-show-threads
3609           (if show-all
3610               (let ((gnus-newsgroup-dormant nil))
3611                 (gnus-summary-initial-limit show-all))
3612             (gnus-summary-initial-limit show-all))
3613         ;; When unthreaded, all articles are always shown.
3614         (setq gnus-newsgroup-limit
3615               (mapcar
3616                (lambda (header) (mail-header-number header))
3617                gnus-newsgroup-headers)))
3618       ;; Generate the summary buffer.
3619       (unless no-display
3620         (gnus-summary-prepare))
3621       (when gnus-use-trees
3622         (gnus-tree-open group)
3623         (setq gnus-summary-highlight-line-function
3624               'gnus-tree-highlight-article))
3625       ;; If the summary buffer is empty, but there are some low-scored
3626       ;; articles or some excluded dormants, we include these in the
3627       ;; buffer.
3628       (when (and (zerop (buffer-size))
3629                  (not no-display))
3630         (cond (gnus-newsgroup-dormant
3631                (gnus-summary-limit-include-dormant))
3632               ((and gnus-newsgroup-scored show-all)
3633                (gnus-summary-limit-include-expunged t))))
3634       ;; Function `gnus-apply-kill-file' must be called in this hook.
3635       (gnus-run-hooks 'gnus-apply-kill-hook)
3636       (if (and (zerop (buffer-size))
3637                (not no-display))
3638           (progn
3639             ;; This newsgroup is empty.
3640             (gnus-summary-catchup-and-exit nil t)
3641             (gnus-message 6 "No unread news")
3642             (when kill-buffer
3643               (gnus-kill-or-deaden-summary kill-buffer))
3644             ;; Return nil from this function.
3645             nil)
3646         ;; Hide conversation thread subtrees.  We cannot do this in
3647         ;; gnus-summary-prepare-hook since kill processing may not
3648         ;; work with hidden articles.
3649         (gnus-summary-maybe-hide-threads)
3650         (when kill-buffer
3651           (gnus-kill-or-deaden-summary kill-buffer))
3652         (gnus-summary-auto-select-subject)
3653         ;; Show first unread article if requested.
3654         (if (and (not no-article)
3655                  (not no-display)
3656                  gnus-newsgroup-unreads
3657                  gnus-auto-select-first)
3658             (progn
3659               (gnus-configure-windows 'summary)
3660               (let ((art (gnus-summary-article-number)))
3661                 (unless (and (not gnus-plugged)
3662                              (or (memq art gnus-newsgroup-undownloaded)
3663                                  (memq art gnus-newsgroup-downloadable)))
3664                   (gnus-summary-goto-article art))))
3665           ;; Don't select any articles.
3666           (gnus-summary-position-point)
3667           (gnus-configure-windows 'summary 'force)
3668           (gnus-set-mode-line 'summary))
3669         (when (and gnus-auto-center-group
3670                    (get-buffer-window gnus-group-buffer t))
3671           ;; Gotta use windows, because recenter does weird stuff if
3672           ;; the current buffer ain't the displayed window.
3673           (let ((owin (selected-window)))
3674             (select-window (get-buffer-window gnus-group-buffer t))
3675             (when (gnus-group-goto-group group)
3676               (recenter))
3677             (select-window owin)))
3678         ;; Mark this buffer as "prepared".
3679         (setq gnus-newsgroup-prepared t)
3680         (gnus-run-hooks 'gnus-summary-prepared-hook)
3681         (unless (gnus-ephemeral-group-p group)
3682           (gnus-group-update-group group))
3683         t)))))
3684
3685 (defun gnus-summary-auto-select-subject ()
3686   "Select the subject line on initial group entry."
3687   (goto-char (point-min))
3688   (cond
3689    ((eq gnus-auto-select-subject 'best)
3690     (gnus-summary-best-unread-subject))
3691    ((eq gnus-auto-select-subject 'unread)
3692     (gnus-summary-first-unread-subject))
3693    ((eq gnus-auto-select-subject 'unseen)
3694     (gnus-summary-first-unseen-subject))
3695    ((eq gnus-auto-select-subject 'unseen-or-unread)
3696     (gnus-summary-first-unseen-or-unread-subject))
3697    ((eq gnus-auto-select-subject 'first)
3698     ;; Do nothing.
3699     )
3700    ((functionp gnus-auto-select-subject)
3701     (funcall gnus-auto-select-subject))))
3702
3703 (defun gnus-summary-prepare ()
3704   "Generate the summary buffer."
3705   (interactive)
3706   (let ((buffer-read-only nil))
3707     (erase-buffer)
3708     (setq gnus-newsgroup-data nil
3709           gnus-newsgroup-data-reverse nil)
3710     (gnus-run-hooks 'gnus-summary-generate-hook)
3711     ;; Generate the buffer, either with threads or without.
3712     (when gnus-newsgroup-headers
3713       (gnus-summary-prepare-threads
3714        (if gnus-show-threads
3715            (gnus-sort-gathered-threads
3716             (funcall gnus-summary-thread-gathering-function
3717                      (gnus-sort-threads
3718                       (gnus-cut-threads (gnus-make-threads)))))
3719          ;; Unthreaded display.
3720          (gnus-sort-articles gnus-newsgroup-headers))))
3721     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3722     ;; Call hooks for modifying summary buffer.
3723     (goto-char (point-min))
3724     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3725
3726 (defsubst gnus-general-simplify-subject (subject)
3727   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3728   (setq subject
3729         (cond
3730          ;; Truncate the subject.
3731          (gnus-simplify-subject-functions
3732           (gnus-map-function gnus-simplify-subject-functions subject))
3733          ((numberp gnus-summary-gather-subject-limit)
3734           (setq subject (gnus-simplify-subject-re subject))
3735           (if (> (length subject) gnus-summary-gather-subject-limit)
3736               (substring subject 0 gnus-summary-gather-subject-limit)
3737             subject))
3738          ;; Fuzzily simplify it.
3739          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3740           (gnus-simplify-subject-fuzzy subject))
3741          ;; Just remove the leading "Re:".
3742          (t
3743           (gnus-simplify-subject-re subject))))
3744
3745   (if (and gnus-summary-gather-exclude-subject
3746            (string-match gnus-summary-gather-exclude-subject subject))
3747       nil                               ; This article shouldn't be gathered
3748     subject))
3749
3750 (defun gnus-summary-simplify-subject-query ()
3751   "Query where the respool algorithm would put this article."
3752   (interactive)
3753   (gnus-summary-select-article)
3754   (message "%s"
3755            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3756
3757 (defun gnus-gather-threads-by-subject (threads)
3758   "Gather threads by looking at Subject headers."
3759   (if (not gnus-summary-make-false-root)
3760       threads
3761     (let ((hashtb (gnus-make-hashtable 1024))
3762           (prev threads)
3763           (result threads)
3764           subject hthread whole-subject)
3765       (while threads
3766         (setq subject (gnus-general-simplify-subject
3767                        (setq whole-subject (mail-header-subject
3768                                             (caar threads)))))
3769         (when subject
3770           (if (setq hthread (gnus-gethash subject hashtb))
3771               (progn
3772                 ;; We enter a dummy root into the thread, if we
3773                 ;; haven't done that already.
3774                 (unless (stringp (caar hthread))
3775                   (setcar hthread (list whole-subject (car hthread))))
3776                 ;; We add this new gathered thread to this gathered
3777                 ;; thread.
3778                 (setcdr (car hthread)
3779                         (nconc (cdar hthread) (list (car threads))))
3780                 ;; Remove it from the list of threads.
3781                 (setcdr prev (cdr threads))
3782                 (setq threads prev))
3783             ;; Enter this thread into the hash table.
3784             (gnus-sethash subject
3785                           (if gnus-summary-make-false-root-always
3786                               (progn
3787                                 ;; If you want a dummy root above all
3788                                 ;; threads...
3789                                 (setcar threads (list whole-subject
3790                                                       (car threads)))
3791                                 threads)
3792                             threads)
3793                           hashtb)))
3794         (setq prev threads)
3795         (setq threads (cdr threads)))
3796       result)))
3797
3798 (defun gnus-gather-threads-by-references (threads)
3799   "Gather threads by looking at References headers."
3800   (let ((idhashtb (gnus-make-hashtable 1024))
3801         (thhashtb (gnus-make-hashtable 1024))
3802         (prev threads)
3803         (result threads)
3804         ids references id gthread gid entered ref)
3805     (while threads
3806       (when (setq references (mail-header-references (caar threads)))
3807         (setq id (mail-header-id (caar threads))
3808               ids (inline (gnus-split-references references))
3809               entered nil)
3810         (while (setq ref (pop ids))
3811           (setq ids (delete ref ids))
3812           (if (not (setq gid (gnus-gethash ref idhashtb)))
3813               (progn
3814                 (gnus-sethash ref id idhashtb)
3815                 (gnus-sethash id threads thhashtb))
3816             (setq gthread (gnus-gethash gid thhashtb))
3817             (unless entered
3818               ;; We enter a dummy root into the thread, if we
3819               ;; haven't done that already.
3820               (unless (stringp (caar gthread))
3821                 (setcar gthread (list (mail-header-subject (caar gthread))
3822                                       (car gthread))))
3823               ;; We add this new gathered thread to this gathered
3824               ;; thread.
3825               (setcdr (car gthread)
3826                       (nconc (cdar gthread) (list (car threads)))))
3827             ;; Add it into the thread hash table.
3828             (gnus-sethash id gthread thhashtb)
3829             (setq entered t)
3830             ;; Remove it from the list of threads.
3831             (setcdr prev (cdr threads))
3832             (setq threads prev))))
3833       (setq prev threads)
3834       (setq threads (cdr threads)))
3835     result))
3836
3837 (defun gnus-sort-gathered-threads (threads)
3838   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3839   (let ((result threads))
3840     (while threads
3841       (when (stringp (caar threads))
3842         (setcdr (car threads)
3843                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3844       (setq threads (cdr threads)))
3845     result))
3846
3847 (defun gnus-thread-loop-p (root thread)
3848   "Say whether ROOT is in THREAD."
3849   (let ((stack (list thread))
3850         (infloop 0)
3851         th)
3852     (while (setq thread (pop stack))
3853       (setq th (cdr thread))
3854       (while (and th
3855                   (not (eq (caar th) root)))
3856         (pop th))
3857       (if th
3858           ;; We have found a loop.
3859           (let (ref-dep)
3860             (setcdr thread (delq (car th) (cdr thread)))
3861             (if (boundp (setq ref-dep (intern "none"
3862                                               gnus-newsgroup-dependencies)))
3863                 (setcdr (symbol-value ref-dep)
3864                         (nconc (cdr (symbol-value ref-dep))
3865                                (list (car th))))
3866               (set ref-dep (list nil (car th))))
3867             (setq infloop 1
3868                   stack nil))
3869         ;; Push all the subthreads onto the stack.
3870         (push (cdr thread) stack)))
3871     infloop))
3872
3873 (defun gnus-make-threads ()
3874   "Go through the dependency hashtb and find the roots.  Return all threads."
3875   (let (threads)
3876     (while (catch 'infloop
3877              (mapatoms
3878               (lambda (refs)
3879                 ;; Deal with self-referencing References loops.
3880                 (when (and (car (symbol-value refs))
3881                            (not (zerop
3882                                  (apply
3883                                   '+
3884                                   (mapcar
3885                                    (lambda (thread)
3886                                      (gnus-thread-loop-p
3887                                       (car (symbol-value refs)) thread))
3888                                    (cdr (symbol-value refs)))))))
3889                   (setq threads nil)
3890                   (throw 'infloop t))
3891                 (unless (car (symbol-value refs))
3892                   ;; These threads do not refer back to any other articles,
3893                   ;; so they're roots.
3894                   (setq threads (append (cdr (symbol-value refs)) threads))))
3895               gnus-newsgroup-dependencies)))
3896     threads))
3897
3898 ;; Build the thread tree.
3899 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3900   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3901
3902 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3903 if it was already present.
3904
3905 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3906 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3907 Message-IDs will be renamed to a unique Message-ID before being
3908 entered.
3909
3910 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3911   (let* ((id (mail-header-id header))
3912          (id-dep (and id (intern id dependencies)))
3913          parent-id ref ref-dep ref-header replaced)
3914     ;; Enter this `header' in the `dependencies' table.
3915     (cond
3916      ((not id-dep)
3917       (setq header nil))
3918      ;; The first two cases do the normal part: enter a new `header'
3919      ;; in the `dependencies' table.
3920      ((not (boundp id-dep))
3921       (set id-dep (list header)))
3922      ((null (car (symbol-value id-dep)))
3923       (setcar (symbol-value id-dep) header))
3924
3925      ;; From here the `header' was already present in the
3926      ;; `dependencies' table.
3927      (force-new
3928       ;; Overrides an existing entry;
3929       ;; just set the header part of the entry.
3930       (setcar (symbol-value id-dep) header)
3931       (setq replaced t))
3932
3933      ;; Renames the existing `header' to a unique Message-ID.
3934      ((not gnus-summary-ignore-duplicates)
3935       ;; An article with this Message-ID has already been seen.
3936       ;; We rename the Message-ID.
3937       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3938            (list header))
3939       (mail-header-set-id header id))
3940
3941      ;; The last case ignores an existing entry, except it adds any
3942      ;; additional Xrefs (in case the two articles came from different
3943      ;; servers.
3944      ;; Also sets `header' to `nil' meaning that the `dependencies'
3945      ;; table was *not* modified.
3946      (t
3947       (mail-header-set-xref
3948        (car (symbol-value id-dep))
3949        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3950                    "")
3951                (or (mail-header-xref header) "")))
3952       (setq header nil)))
3953
3954     (when (and header (not replaced))
3955       ;; First check that we are not creating a References loop.
3956       (setq parent-id (gnus-parent-id (mail-header-references header)))
3957       (setq ref parent-id)
3958       (while (and ref
3959                   (setq ref-dep (intern-soft ref dependencies))
3960                   (boundp ref-dep)
3961                   (setq ref-header (car (symbol-value ref-dep))))
3962         (if (string= id ref)
3963             ;; Yuk!  This is a reference loop.  Make the article be a
3964             ;; root article.
3965             (progn
3966               (mail-header-set-references (car (symbol-value id-dep)) "none")
3967               (setq ref nil)
3968               (setq parent-id nil))
3969           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3970       (setq ref-dep (intern (or parent-id "none") dependencies))
3971       (if (boundp ref-dep)
3972           (setcdr (symbol-value ref-dep)
3973                   (nconc (cdr (symbol-value ref-dep))
3974                          (list (symbol-value id-dep))))
3975         (set ref-dep (list nil (symbol-value id-dep)))))
3976     header))
3977
3978 (defun gnus-extract-message-id-from-in-reply-to (string)
3979   (if (string-match "<[^>]+>" string)
3980       (substring string (match-beginning 0) (match-end 0))
3981     nil))
3982
3983 (defun gnus-build-sparse-threads ()
3984   (let ((headers gnus-newsgroup-headers)
3985         (mail-parse-charset gnus-newsgroup-charset)
3986         (gnus-summary-ignore-duplicates t)
3987         header references generation relations
3988         subject child end new-child date)
3989     ;; First we create an alist of generations/relations, where
3990     ;; generations is how much we trust the relation, and the relation
3991     ;; is parent/child.
3992     (gnus-message 7 "Making sparse threads...")
3993     (save-excursion
3994       (nnheader-set-temp-buffer " *gnus sparse threads*")
3995       (while (setq header (pop headers))
3996         (when (and (setq references (mail-header-references header))
3997                    (not (string= references "")))
3998           (insert references)
3999           (setq child (mail-header-id header)
4000                 subject (mail-header-subject header)
4001                 date (mail-header-date header)
4002                 generation 0)
4003           (while (search-backward ">" nil t)
4004             (setq end (1+ (point)))
4005             (when (search-backward "<" nil t)
4006               (setq new-child (buffer-substring (point) end))
4007               (push (list (incf generation)
4008                           child (setq child new-child)
4009                           subject date)
4010                     relations)))
4011           (when child
4012             (push (list (1+ generation) child nil subject) relations))
4013           (erase-buffer)))
4014       (kill-buffer (current-buffer)))
4015     ;; Sort over trustworthiness.
4016     (mapcar
4017      (lambda (relation)
4018        (when (gnus-dependencies-add-header
4019               (make-full-mail-header-from-decoded-header
4020                gnus-reffed-article-number
4021                (nth 3 relation) "" (or (nth 4 relation) "")
4022                (nth 1 relation)
4023                (or (nth 2 relation) "") 0 0 "")
4024               gnus-newsgroup-dependencies nil)
4025          (push gnus-reffed-article-number gnus-newsgroup-limit)
4026          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4027          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4028                gnus-newsgroup-reads)
4029          (decf gnus-reffed-article-number)))
4030      (sort relations 'car-less-than-car))
4031     (gnus-message 7 "Making sparse threads...done")))
4032
4033 (defun gnus-build-old-threads ()
4034   ;; Look at all the articles that refer back to old articles, and
4035   ;; fetch the headers for the articles that aren't there.  This will
4036   ;; build complete threads - if the roots haven't been expired by the
4037   ;; server, that is.
4038   (let ((mail-parse-charset gnus-newsgroup-charset)
4039         id heads)
4040     (mapatoms
4041      (lambda (refs)
4042        (when (not (car (symbol-value refs)))
4043          (setq heads (cdr (symbol-value refs)))
4044          (while heads
4045            (if (memq (mail-header-number (caar heads))
4046                      gnus-newsgroup-dormant)
4047                (setq heads (cdr heads))
4048              (setq id (symbol-name refs))
4049              (while (and (setq id (gnus-build-get-header id))
4050                          (not (car (gnus-id-to-thread id)))))
4051              (setq heads nil)))))
4052      gnus-newsgroup-dependencies)))
4053
4054 (defsubst gnus-remove-odd-characters (string)
4055   "Translate STRING into something that doesn't contain weird characters."
4056   (mm-subst-char-in-string
4057    ?\r ?\-
4058    (mm-subst-char-in-string ?\n ?\- string t) t))
4059
4060 ;; This function has to be called with point after the article number
4061 ;; on the beginning of the line.
4062 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4063   (let ((eol (point-at-eol))
4064         (buffer (current-buffer))
4065         header references in-reply-to)
4066
4067     ;; overview: [num subject from date id refs chars lines misc]
4068     (unwind-protect
4069         (progn
4070           (narrow-to-region (point) eol)
4071           (unless (eobp)
4072             (forward-char))
4073
4074           (setq header
4075                 (make-full-mail-header
4076                  number                         ; number
4077                  (nnheader-nov-field)           ; subject
4078                  (nnheader-nov-field)           ; from
4079                  (nnheader-nov-field)           ; date
4080                  (nnheader-nov-read-message-id) ; id
4081                  (nnheader-nov-field)           ; refs
4082                  (nnheader-nov-read-integer)    ; chars
4083                  (nnheader-nov-read-integer)    ; lines
4084                  (unless (eobp)
4085                    (if (looking-at "Xref: ")
4086                        (goto-char (match-end 0)))
4087                    (nnheader-nov-field))        ; Xref
4088                  (nnheader-nov-parse-extra))))  ; extra
4089
4090       (widen))
4091
4092     (when (and (string= references "")
4093                (setq in-reply-to (mail-header-extra header))
4094                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4095       (mail-header-set-references
4096        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4097
4098     (when gnus-alter-header-function
4099       (funcall gnus-alter-header-function header))
4100     (gnus-dependencies-add-header header dependencies force-new)))
4101
4102 (defun gnus-build-get-header (id)
4103   "Look through the buffer of NOV lines and find the header to ID.
4104 Enter this line into the dependencies hash table, and return
4105 the id of the parent article (if any)."
4106   (let ((deps gnus-newsgroup-dependencies)
4107         found header)
4108     (prog1
4109         (save-excursion
4110           (set-buffer nntp-server-buffer)
4111           (let ((case-fold-search nil))
4112             (goto-char (point-min))
4113             (while (and (not found)
4114                         (search-forward id nil t))
4115               (beginning-of-line)
4116               (setq found (looking-at
4117                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4118                                    (regexp-quote id))))
4119               (or found (beginning-of-line 2)))
4120             (when found
4121               (beginning-of-line)
4122               (and
4123                (setq header (gnus-nov-parse-line
4124                              (read (current-buffer)) deps))
4125                (gnus-parent-id (mail-header-references header))))))
4126       (when header
4127         (let ((number (mail-header-number header)))
4128           (push number gnus-newsgroup-limit)
4129           (push header gnus-newsgroup-headers)
4130           (if (memq number gnus-newsgroup-unselected)
4131               (progn
4132                 (setq gnus-newsgroup-unreads
4133                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4134                                                number))
4135                 (setq gnus-newsgroup-unselected
4136                       (delq number gnus-newsgroup-unselected)))
4137             (push number gnus-newsgroup-ancient)))))))
4138
4139 (defun gnus-build-all-threads ()
4140   "Read all the headers."
4141   (let ((gnus-summary-ignore-duplicates t)
4142         (mail-parse-charset gnus-newsgroup-charset)
4143         (dependencies gnus-newsgroup-dependencies)
4144         header article)
4145     (save-excursion
4146       (set-buffer nntp-server-buffer)
4147       (let ((case-fold-search nil))
4148         (goto-char (point-min))
4149         (while (not (eobp))
4150           (ignore-errors
4151             (setq article (read (current-buffer))
4152                   header (gnus-nov-parse-line article dependencies)))
4153           (when header
4154             (with-current-buffer gnus-summary-buffer
4155               (push header gnus-newsgroup-headers)
4156               (if (memq (setq article (mail-header-number header))
4157                         gnus-newsgroup-unselected)
4158                   (progn
4159                     (setq gnus-newsgroup-unreads
4160                           (gnus-add-to-sorted-list
4161                            gnus-newsgroup-unreads article))
4162                     (setq gnus-newsgroup-unselected
4163                           (delq article gnus-newsgroup-unselected)))
4164                 (push article gnus-newsgroup-ancient)))
4165             (forward-line 1)))))))
4166
4167 (defun gnus-summary-update-article-line (article header)
4168   "Update the line for ARTICLE using HEADER."
4169   (let* ((id (mail-header-id header))
4170          (thread (gnus-id-to-thread id)))
4171     (unless thread
4172       (error "Article in no thread"))
4173     ;; Update the thread.
4174     (setcar thread header)
4175     (gnus-summary-goto-subject article)
4176     (let* ((datal (gnus-data-find-list article))
4177            (data (car datal))
4178            (buffer-read-only nil)
4179            (level (gnus-summary-thread-level)))
4180       (gnus-delete-line)
4181       (let ((inserted (- (point)
4182                          (progn
4183                            (gnus-summary-insert-line
4184                             header level nil
4185                             (memq article gnus-newsgroup-undownloaded)
4186                             (gnus-article-mark article)
4187                             (memq article gnus-newsgroup-replied)
4188                             (memq article gnus-newsgroup-expirable)
4189                             ;; Only insert the Subject string when it's different
4190                             ;; from the previous Subject string.
4191                             (if (and
4192                                  gnus-show-threads
4193                                  (gnus-subject-equal
4194                                   (condition-case ()
4195                                       (mail-header-subject
4196                                        (gnus-data-header
4197                                         (cadr
4198                                          (gnus-data-find-list
4199                                           article
4200                                           (gnus-data-list t)))))
4201                                     ;; Error on the side of excessive subjects.
4202                                     (error ""))
4203                                   (mail-header-subject header)))
4204                                 ""
4205                               (mail-header-subject header))
4206                             nil (cdr (assq article gnus-newsgroup-scored))
4207                             (memq article gnus-newsgroup-processable))
4208                            (point)))))
4209         (when (cdr datal)
4210           (gnus-data-update-list
4211            (cdr datal)
4212            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4213
4214 (defun gnus-summary-update-article (article &optional iheader)
4215   "Update ARTICLE in the summary buffer."
4216   (set-buffer gnus-summary-buffer)
4217   (let* ((header (gnus-summary-article-header article))
4218          (id (mail-header-id header))
4219          (data (gnus-data-find article))
4220          (thread (gnus-id-to-thread id))
4221          (references (mail-header-references header))
4222          (parent
4223           (gnus-id-to-thread
4224            (or (gnus-parent-id
4225                 (when (and references
4226                            (not (equal "" references)))
4227                   references))
4228                "none")))
4229          (buffer-read-only nil)
4230          (old (car thread)))
4231     (when thread
4232       (unless iheader
4233         (setcar thread nil)
4234         (when parent
4235           (delq thread parent)))
4236       (if (gnus-summary-insert-subject id header)
4237           ;; Set the (possibly) new article number in the data structure.
4238           (gnus-data-set-number data (gnus-id-to-article id))
4239         (setcar thread old)
4240         nil))))
4241
4242 (defun gnus-rebuild-thread (id &optional line)
4243   "Rebuild the thread containing ID.
4244 If LINE, insert the rebuilt thread starting on line LINE."
4245   (let ((buffer-read-only nil)
4246         old-pos current thread data)
4247     (if (not gnus-show-threads)
4248         (setq thread (list (car (gnus-id-to-thread id))))
4249       ;; Get the thread this article is part of.
4250       (setq thread (gnus-remove-thread id)))
4251     (setq old-pos (point-at-bol))
4252     (setq current (save-excursion
4253                     (and (re-search-backward "[\r\n]" nil t)
4254                          (gnus-summary-article-number))))
4255     ;; If this is a gathered thread, we have to go some re-gathering.
4256     (when (stringp (car thread))
4257       (let ((subject (car thread))
4258             roots thr)
4259         (setq thread (cdr thread))
4260         (while thread
4261           (unless (memq (setq thr (gnus-id-to-thread
4262                                    (gnus-root-id
4263                                     (mail-header-id (caar thread)))))
4264                         roots)
4265             (push thr roots))
4266           (setq thread (cdr thread)))
4267         ;; We now have all (unique) roots.
4268         (if (= (length roots) 1)
4269             ;; All the loose roots are now one solid root.
4270             (setq thread (car roots))
4271           (setq thread (cons subject (gnus-sort-threads roots))))))
4272     (let (threads)
4273       ;; We then insert this thread into the summary buffer.
4274       (when line
4275         (goto-char (point-min))
4276         (forward-line (1- line)))
4277       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4278         (if gnus-show-threads
4279             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4280           (gnus-summary-prepare-unthreaded thread))
4281         (setq data (nreverse gnus-newsgroup-data))
4282         (setq threads gnus-newsgroup-threads))
4283       ;; We splice the new data into the data structure.
4284       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4285       ;;!!! then we want to insert at the beginning of the buffer.
4286       ;;!!! That happens to be true with Gnus now, but that may
4287       ;;!!! change in the future.  Perhaps.
4288       (gnus-data-enter-list
4289        (if line nil current) data (- (point) old-pos))
4290       (setq gnus-newsgroup-threads
4291             (nconc threads gnus-newsgroup-threads))
4292       (gnus-data-compute-positions))))
4293
4294 (defun gnus-number-to-header (number)
4295   "Return the header for article NUMBER."
4296   (let ((headers gnus-newsgroup-headers))
4297     (while (and headers
4298                 (not (= number (mail-header-number (car headers)))))
4299       (pop headers))
4300     (when headers
4301       (car headers))))
4302
4303 (defun gnus-parent-headers (in-headers &optional generation)
4304   "Return the headers of the GENERATIONeth parent of HEADERS."
4305   (unless generation
4306     (setq generation 1))
4307   (let ((parent t)
4308         (headers in-headers)
4309         references)
4310     (while (and parent
4311                 (not (zerop generation))
4312                 (setq references (mail-header-references headers)))
4313       (setq headers (if (and references
4314                              (setq parent (gnus-parent-id references)))
4315                         (car (gnus-id-to-thread parent))
4316                       nil))
4317       (decf generation))
4318     (and (not (eq headers in-headers))
4319          headers)))
4320
4321 (defun gnus-id-to-thread (id)
4322   "Return the (sub-)thread where ID appears."
4323   (gnus-gethash id gnus-newsgroup-dependencies))
4324
4325 (defun gnus-id-to-article (id)
4326   "Return the article number of ID."
4327   (let ((thread (gnus-id-to-thread id)))
4328     (when (and thread
4329                (car thread))
4330       (mail-header-number (car thread)))))
4331
4332 (defun gnus-id-to-header (id)
4333   "Return the article headers of ID."
4334   (car (gnus-id-to-thread id)))
4335
4336 (defun gnus-article-displayed-root-p (article)
4337   "Say whether ARTICLE is a root(ish) article."
4338   (let ((level (gnus-summary-thread-level article))
4339         (refs (mail-header-references  (gnus-summary-article-header article)))
4340         particle)
4341     (cond
4342      ((null level) nil)
4343      ((zerop level) t)
4344      ((null refs) t)
4345      ((null (gnus-parent-id refs)) t)
4346      ((and (= 1 level)
4347            (null (setq particle (gnus-id-to-article
4348                                  (gnus-parent-id refs))))
4349            (null (gnus-summary-thread-level particle)))))))
4350
4351 (defun gnus-root-id (id)
4352   "Return the id of the root of the thread where ID appears."
4353   (let (last-id prev)
4354     (while (and id (setq prev (car (gnus-id-to-thread id))))
4355       (setq last-id id
4356             id (gnus-parent-id (mail-header-references prev))))
4357     last-id))
4358
4359 (defun gnus-articles-in-thread (thread)
4360   "Return the list of articles in THREAD."
4361   (cons (mail-header-number (car thread))
4362         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4363
4364 (defun gnus-remove-thread (id &optional dont-remove)
4365   "Remove the thread that has ID in it."
4366   (let (headers thread last-id)
4367     ;; First go up in this thread until we find the root.
4368     (setq last-id (gnus-root-id id)
4369           headers (message-flatten-list (gnus-id-to-thread last-id)))
4370     ;; We have now found the real root of this thread.  It might have
4371     ;; been gathered into some loose thread, so we have to search
4372     ;; through the threads to find the thread we wanted.
4373     (let ((threads gnus-newsgroup-threads)
4374           sub)
4375       (while threads
4376         (setq sub (car threads))
4377         (if (stringp (car sub))
4378             ;; This is a gathered thread, so we look at the roots
4379             ;; below it to find whether this article is in this
4380             ;; gathered root.
4381             (progn
4382               (setq sub (cdr sub))
4383               (while sub
4384                 (when (member (caar sub) headers)
4385                   (setq thread (car threads)
4386                         threads nil
4387                         sub nil))
4388                 (setq sub (cdr sub))))
4389           ;; It's an ordinary thread, so we check it.
4390           (when (eq (car sub) (car headers))
4391             (setq thread sub
4392                   threads nil)))
4393         (setq threads (cdr threads)))
4394       ;; If this article is in no thread, then it's a root.
4395       (if thread
4396           (unless dont-remove
4397             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4398         (setq thread (gnus-id-to-thread last-id)))
4399       (when thread
4400         (prog1
4401             thread                      ; We return this thread.
4402           (unless dont-remove
4403             (if (stringp (car thread))
4404                 (progn
4405                   ;; If we use dummy roots, then we have to remove the
4406                   ;; dummy root as well.
4407                   (when (eq gnus-summary-make-false-root 'dummy)
4408                     ;; We go to the dummy root by going to
4409                     ;; the first sub-"thread", and then one line up.
4410                     (gnus-summary-goto-article
4411                      (mail-header-number (caadr thread)))
4412                     (forward-line -1)
4413                     (gnus-delete-line)
4414                     (gnus-data-compute-positions))
4415                   (setq thread (cdr thread))
4416                   (while thread
4417                     (gnus-remove-thread-1 (car thread))
4418                     (setq thread (cdr thread))))
4419               (gnus-remove-thread-1 thread))))))))
4420
4421 (defun gnus-remove-thread-1 (thread)
4422   "Remove the thread THREAD recursively."
4423   (let ((number (mail-header-number (pop thread)))
4424         d)
4425     (setq thread (reverse thread))
4426     (while thread
4427       (gnus-remove-thread-1 (pop thread)))
4428     (when (setq d (gnus-data-find number))
4429       (goto-char (gnus-data-pos d))
4430       (gnus-summary-show-thread)
4431       (gnus-data-remove
4432        number
4433        (- (point-at-bol)
4434           (prog1
4435               (1+ (point-at-eol))
4436             (gnus-delete-line)))))))
4437
4438 (defun gnus-sort-threads-1 (threads func)
4439   (sort (mapcar (lambda (thread)
4440                   (cons (car thread)
4441                         (and (cdr thread)
4442                              (gnus-sort-threads-1 (cdr thread) func))))
4443                 threads) func))
4444
4445 (defun gnus-sort-threads (threads)
4446   "Sort THREADS."
4447   (if (not gnus-thread-sort-functions)
4448       threads
4449     (gnus-message 8 "Sorting threads...")
4450     (let ((max-lisp-eval-depth 5000))
4451       (prog1 (gnus-sort-threads-1
4452          threads
4453          (gnus-make-sort-function gnus-thread-sort-functions))
4454         (gnus-message 8 "Sorting threads...done")))))
4455
4456 (defun gnus-sort-articles (articles)
4457   "Sort ARTICLES."
4458   (when gnus-article-sort-functions
4459     (gnus-message 7 "Sorting articles...")
4460     (prog1
4461         (setq gnus-newsgroup-headers
4462               (sort articles (gnus-make-sort-function
4463                               gnus-article-sort-functions)))
4464       (gnus-message 7 "Sorting articles...done"))))
4465
4466 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4467 (defmacro gnus-thread-header (thread)
4468   "Return header of first article in THREAD.
4469 Note that THREAD must never, ever be anything else than a variable -
4470 using some other form will lead to serious barfage."
4471   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4472   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4473   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4474         (vector thread) 2))
4475
4476 (defsubst gnus-article-sort-by-number (h1 h2)
4477   "Sort articles by article number."
4478   (< (mail-header-number h1)
4479      (mail-header-number h2)))
4480
4481 (defun gnus-thread-sort-by-number (h1 h2)
4482   "Sort threads by root article number."
4483   (gnus-article-sort-by-number
4484    (gnus-thread-header h1) (gnus-thread-header h2)))
4485
4486 (defsubst gnus-article-sort-by-random (h1 h2)
4487   "Sort articles by article number."
4488   (zerop (random 2)))
4489
4490 (defun gnus-thread-sort-by-random (h1 h2)
4491   "Sort threads by root article number."
4492   (gnus-article-sort-by-random
4493    (gnus-thread-header h1) (gnus-thread-header h2)))
4494
4495 (defsubst gnus-article-sort-by-lines (h1 h2)
4496   "Sort articles by article Lines header."
4497   (< (mail-header-lines h1)
4498      (mail-header-lines h2)))
4499
4500 (defun gnus-thread-sort-by-lines (h1 h2)
4501   "Sort threads by root article Lines header."
4502   (gnus-article-sort-by-lines
4503    (gnus-thread-header h1) (gnus-thread-header h2)))
4504
4505 (defsubst gnus-article-sort-by-chars (h1 h2)
4506   "Sort articles by octet length."
4507   (< (mail-header-chars h1)
4508      (mail-header-chars h2)))
4509
4510 (defun gnus-thread-sort-by-chars (h1 h2)
4511   "Sort threads by root article octet length."
4512   (gnus-article-sort-by-chars
4513    (gnus-thread-header h1) (gnus-thread-header h2)))
4514
4515 (defsubst gnus-article-sort-by-author (h1 h2)
4516   "Sort articles by root author."
4517   (string-lessp
4518    (let ((addr (car (mime-entity-read-field h1 'From))))
4519      (or (std11-full-name-string addr)
4520          (std11-address-string addr)
4521          ""))
4522    (let ((addr (car (mime-entity-read-field h2 'From))))
4523      (or (std11-full-name-string addr)
4524          (std11-address-string addr)
4525          ""))
4526    ))
4527
4528 (defun gnus-thread-sort-by-author (h1 h2)
4529   "Sort threads by root author."
4530   (gnus-article-sort-by-author
4531    (gnus-thread-header h1)  (gnus-thread-header h2)))
4532
4533 (defsubst gnus-article-sort-by-subject (h1 h2)
4534   "Sort articles by root subject."
4535   (string-lessp
4536    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4537    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4538
4539 (defun gnus-thread-sort-by-subject (h1 h2)
4540   "Sort threads by root subject."
4541   (gnus-article-sort-by-subject
4542    (gnus-thread-header h1) (gnus-thread-header h2)))
4543
4544 (defsubst gnus-article-sort-by-date (h1 h2)
4545   "Sort articles by root article date."
4546   (time-less-p
4547    (gnus-date-get-time (mail-header-date h1))
4548    (gnus-date-get-time (mail-header-date h2))))
4549
4550 (defun gnus-thread-sort-by-date (h1 h2)
4551   "Sort threads by root article date."
4552   (gnus-article-sort-by-date
4553    (gnus-thread-header h1) (gnus-thread-header h2)))
4554
4555 (defsubst gnus-article-sort-by-score (h1 h2)
4556   "Sort articles by root article score.
4557 Unscored articles will be counted as having a score of zero."
4558   (> (or (cdr (assq (mail-header-number h1)
4559                     gnus-newsgroup-scored))
4560          gnus-summary-default-score 0)
4561      (or (cdr (assq (mail-header-number h2)
4562                     gnus-newsgroup-scored))
4563          gnus-summary-default-score 0)))
4564
4565 (defun gnus-thread-sort-by-score (h1 h2)
4566   "Sort threads by root article score."
4567   (gnus-article-sort-by-score
4568    (gnus-thread-header h1) (gnus-thread-header h2)))
4569
4570 (defun gnus-thread-sort-by-total-score (h1 h2)
4571   "Sort threads by the sum of all scores in the thread.
4572 Unscored articles will be counted as having a score of zero."
4573   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4574
4575 (defun gnus-thread-total-score (thread)
4576   ;; This function find the total score of THREAD.
4577   (cond
4578    ((null thread)
4579     0)
4580    ((consp thread)
4581     (if (stringp (car thread))
4582         (apply gnus-thread-score-function 0
4583                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4584       (gnus-thread-total-score-1 thread)))
4585    (t
4586     (gnus-thread-total-score-1 (list thread)))))
4587
4588 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4589   "Sort threads such that the thread with the most recently arrived article comes first."
4590   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4591
4592 (defun gnus-thread-highest-number (thread)
4593   "Return the highest article number in THREAD."
4594   (apply 'max (mapcar (lambda (header)
4595                         (mail-header-number header))
4596                       (message-flatten-list thread))))
4597
4598 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4599   "Sort threads such that the thread with the most recently dated article comes first."
4600   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4601
4602 (defun gnus-thread-latest-date (thread)
4603   "Return the highest article date in THREAD."
4604   (let ((previous-time 0))
4605     (apply 'max
4606            (mapcar
4607             (lambda (header)
4608               (setq previous-time
4609                     (condition-case ()
4610                         (time-to-seconds (mail-header-parse-date
4611                                           (mail-header-date header)))
4612                       (error previous-time))))
4613             (sort
4614              (message-flatten-list thread)
4615              (lambda (h1 h2)
4616                (< (mail-header-number h1)
4617                   (mail-header-number h2))))))))
4618
4619 (defun gnus-thread-total-score-1 (root)
4620   ;; This function find the total score of the thread below ROOT.
4621   (setq root (car root))
4622   (apply gnus-thread-score-function
4623          (or (append
4624               (mapcar 'gnus-thread-total-score
4625                       (cdr (gnus-id-to-thread (mail-header-id root))))
4626               (when (> (mail-header-number root) 0)
4627                 (list (or (cdr (assq (mail-header-number root)
4628                                      gnus-newsgroup-scored))
4629                           gnus-summary-default-score 0))))
4630              (list gnus-summary-default-score)
4631              '(0))))
4632
4633 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4634 (defvar gnus-tmp-prev-subject nil)
4635 (defvar gnus-tmp-false-parent nil)
4636 (defvar gnus-tmp-root-expunged nil)
4637 (defvar gnus-tmp-dummy-line nil)
4638
4639 (eval-when-compile (defvar gnus-tmp-header))
4640 (defun gnus-extra-header (type &optional header)
4641   "Return the extra header of TYPE."
4642   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4643       ""))
4644
4645 (defvar gnus-tmp-thread-tree-header-string "")
4646
4647 (defcustom gnus-sum-thread-tree-root "> "
4648   "With %B spec, used for the root of a thread.
4649 If nil, use subject instead."
4650   :type '(radio (const :format "%v  " nil) (string :size 0))
4651   :group 'gnus-thread)
4652 (defcustom gnus-sum-thread-tree-false-root "> "
4653   "With %B spec, used for a false root of a thread.
4654 If nil, use subject instead."
4655   :type '(radio (const :format "%v  " nil) (string :size 0))
4656   :group 'gnus-thread)
4657 (defcustom gnus-sum-thread-tree-single-indent ""
4658   "With %B spec, used for a thread with just one message.
4659 If nil, use subject instead."
4660   :type '(radio (const :format "%v  " nil) (string :size 0))
4661   :group 'gnus-thread)
4662 (defcustom gnus-sum-thread-tree-vertical "| "
4663   "With %B spec, used for drawing a vertical line."
4664   :type 'string
4665   :group 'gnus-thread)
4666 (defcustom gnus-sum-thread-tree-indent "  "
4667   "With %B spec, used for indenting."
4668   :type 'string
4669   :group 'gnus-thread)
4670 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4671   "With %B spec, used for a leaf with brothers."
4672   :type 'string
4673   :group 'gnus-thread)
4674 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4675   "With %B spec, used for a leaf without brothers."
4676   :type 'string
4677   :group 'gnus-thread)
4678
4679 (defun gnus-summary-prepare-threads (threads)
4680   "Prepare summary buffer from THREADS and indentation LEVEL.
4681 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4682 or a straight list of headers."
4683   (gnus-message 7 "Generating summary...")
4684
4685   (setq gnus-newsgroup-threads threads)
4686   (beginning-of-line)
4687
4688   (let ((gnus-tmp-level 0)
4689         (default-score (or gnus-summary-default-score 0))
4690         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4691         (building-line-count gnus-summary-display-while-building)
4692         (building-count (integerp gnus-summary-display-while-building))
4693         thread number subject stack state gnus-tmp-gathered beg-match
4694         new-roots gnus-tmp-new-adopts thread-end simp-subject
4695         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4696         gnus-tmp-replied gnus-tmp-subject-or-nil
4697         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4698         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4699         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4700         tree-stack)
4701
4702     (setq gnus-tmp-prev-subject nil
4703           gnus-tmp-thread-tree-header-string "")
4704
4705     (if (vectorp (car threads))
4706         ;; If this is a straight (sic) list of headers, then a
4707         ;; threaded summary display isn't required, so we just create
4708         ;; an unthreaded one.
4709         (gnus-summary-prepare-unthreaded threads)
4710
4711       ;; Do the threaded display.
4712
4713       (if gnus-summary-display-while-building
4714           (switch-to-buffer (buffer-name)))
4715       (while (or threads stack gnus-tmp-new-adopts new-roots)
4716
4717         (if (and (= gnus-tmp-level 0)
4718                  (or (not stack)
4719                      (= (caar stack) 0))
4720                  (not gnus-tmp-false-parent)
4721                  (or gnus-tmp-new-adopts new-roots))
4722             (if gnus-tmp-new-adopts
4723                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4724                       thread (list (car gnus-tmp-new-adopts))
4725                       gnus-tmp-header (caar thread)
4726                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4727               (when new-roots
4728                 (setq thread (list (car new-roots))
4729                       gnus-tmp-header (caar thread)
4730                       new-roots (cdr new-roots))))
4731
4732           (if threads
4733               ;; If there are some threads, we do them before the
4734               ;; threads on the stack.
4735               (setq thread threads
4736                     gnus-tmp-header (caar thread))
4737             ;; There were no current threads, so we pop something off
4738             ;; the stack.
4739             (setq state (car stack)
4740                   gnus-tmp-level (car state)
4741                   tree-stack (cadr state)
4742                   thread (caddr state)
4743                   stack (cdr stack)
4744                   gnus-tmp-header (caar thread))))
4745
4746         (setq gnus-tmp-false-parent nil)
4747         (setq gnus-tmp-root-expunged nil)
4748         (setq thread-end nil)
4749
4750         (if (stringp gnus-tmp-header)
4751             ;; The header is a dummy root.
4752             (cond
4753              ((eq gnus-summary-make-false-root 'adopt)
4754               ;; We let the first article adopt the rest.
4755               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4756                                                (cddar thread)))
4757               (setq gnus-tmp-gathered
4758                     (nconc (mapcar
4759                             (lambda (h) (mail-header-number (car h)))
4760                             (cddar thread))
4761                            gnus-tmp-gathered))
4762               (setq thread (cons (list (caar thread)
4763                                        (cadar thread))
4764                                  (cdr thread)))
4765               (setq gnus-tmp-level -1
4766                     gnus-tmp-false-parent t))
4767              ((eq gnus-summary-make-false-root 'empty)
4768               ;; We print adopted articles with empty subject fields.
4769               (setq gnus-tmp-gathered
4770                     (nconc (mapcar
4771                             (lambda (h) (mail-header-number (car h)))
4772                             (cddar thread))
4773                            gnus-tmp-gathered))
4774               (setq gnus-tmp-level -1))
4775              ((eq gnus-summary-make-false-root 'dummy)
4776               ;; We remember that we probably want to output a dummy
4777               ;; root.
4778               (setq gnus-tmp-dummy-line gnus-tmp-header)
4779               (setq gnus-tmp-prev-subject gnus-tmp-header))
4780              (t
4781               ;; We do not make a root for the gathered
4782               ;; sub-threads at all.
4783               (setq gnus-tmp-level -1)))
4784
4785           (setq number (mail-header-number gnus-tmp-header)
4786                 subject (mail-header-subject gnus-tmp-header)
4787                 simp-subject (gnus-simplify-subject-fully subject))
4788
4789           (cond
4790            ;; If the thread has changed subject, we might want to make
4791            ;; this subthread into a root.
4792            ((and (null gnus-thread-ignore-subject)
4793                  (not (zerop gnus-tmp-level))
4794                  gnus-tmp-prev-subject
4795                  (not (string= gnus-tmp-prev-subject simp-subject)))
4796             (setq new-roots (nconc new-roots (list (car thread)))
4797                   thread-end t
4798                   gnus-tmp-header nil))
4799            ;; If the article lies outside the current limit,
4800            ;; then we do not display it.
4801            ((not (memq number gnus-newsgroup-limit))
4802             (setq gnus-tmp-gathered
4803                   (nconc (mapcar
4804                           (lambda (h) (mail-header-number (car h)))
4805                           (cdar thread))
4806                          gnus-tmp-gathered))
4807             (setq gnus-tmp-new-adopts (if (cdar thread)
4808                                           (append gnus-tmp-new-adopts
4809                                                   (cdar thread))
4810                                         gnus-tmp-new-adopts)
4811                   thread-end t
4812                   gnus-tmp-header nil)
4813             (when (zerop gnus-tmp-level)
4814               (setq gnus-tmp-root-expunged t)))
4815            ;; Perhaps this article is to be marked as read?
4816            ((and gnus-summary-mark-below
4817                  (< (or (cdr (assq number gnus-newsgroup-scored))
4818                         default-score)
4819                     gnus-summary-mark-below)
4820                  ;; Don't touch sparse articles.
4821                  (not (gnus-summary-article-sparse-p number))
4822                  (not (gnus-summary-article-ancient-p number)))
4823             (setq gnus-newsgroup-unreads
4824                   (delq number gnus-newsgroup-unreads))
4825             (if gnus-newsgroup-auto-expire
4826                 (setq gnus-newsgroup-expirable
4827                       (gnus-add-to-sorted-list
4828                        gnus-newsgroup-expirable number))
4829               (push (cons number gnus-low-score-mark)
4830                     gnus-newsgroup-reads))))
4831
4832           (when gnus-tmp-header
4833             ;; We may have an old dummy line to output before this
4834             ;; article.
4835             (when (and gnus-tmp-dummy-line
4836                        (gnus-subject-equal
4837                         gnus-tmp-dummy-line
4838                         (mail-header-subject gnus-tmp-header)))
4839               (gnus-summary-insert-dummy-line
4840                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4841               (setq gnus-tmp-dummy-line nil))
4842
4843             ;; Compute the mark.
4844             (setq gnus-tmp-unread (gnus-article-mark number))
4845
4846             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4847                                   gnus-tmp-header gnus-tmp-level)
4848                   gnus-newsgroup-data)
4849
4850             ;; Actually insert the line.
4851             (setq
4852              gnus-tmp-subject-or-nil
4853              (cond
4854               ((and gnus-thread-ignore-subject
4855                     gnus-tmp-prev-subject
4856                     (not (string= gnus-tmp-prev-subject simp-subject)))
4857                subject)
4858               ((zerop gnus-tmp-level)
4859                (if (and (eq gnus-summary-make-false-root 'empty)
4860                         (memq number gnus-tmp-gathered)
4861                         gnus-tmp-prev-subject
4862                         (string= gnus-tmp-prev-subject simp-subject))
4863                    gnus-summary-same-subject
4864                  subject))
4865               (t gnus-summary-same-subject)))
4866             (if (and (eq gnus-summary-make-false-root 'adopt)
4867                      (= gnus-tmp-level 1)
4868                      (memq number gnus-tmp-gathered))
4869                 (setq gnus-tmp-opening-bracket ?\<
4870                       gnus-tmp-closing-bracket ?\>)
4871               (setq gnus-tmp-opening-bracket ?\[
4872                     gnus-tmp-closing-bracket ?\]))
4873             (setq
4874              gnus-tmp-indentation
4875              (aref gnus-thread-indent-array gnus-tmp-level)
4876              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4877              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4878                                 gnus-summary-default-score 0)
4879              gnus-tmp-score-char
4880              (if (or (null gnus-summary-default-score)
4881                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4882                          gnus-summary-zcore-fuzz))
4883                  ?\ ;;;Whitespace
4884                (if (< gnus-tmp-score gnus-summary-default-score)
4885                    gnus-score-below-mark gnus-score-over-mark))
4886              gnus-tmp-replied
4887              (cond ((memq number gnus-newsgroup-processable)
4888                     gnus-process-mark)
4889                    ((memq number gnus-newsgroup-cached)
4890                     gnus-cached-mark)
4891                    ((memq number gnus-newsgroup-replied)
4892                     gnus-replied-mark)
4893                    ((memq number gnus-newsgroup-forwarded)
4894                     gnus-forwarded-mark)
4895                    ((memq number gnus-newsgroup-saved)
4896                     gnus-saved-mark)
4897                    ((memq number gnus-newsgroup-recent)
4898                     gnus-recent-mark)
4899                    ((memq number gnus-newsgroup-unseen)
4900                     gnus-unseen-mark)
4901                    (t gnus-no-mark))
4902              gnus-tmp-downloaded
4903              (cond ((memq number gnus-newsgroup-undownloaded)
4904                     gnus-undownloaded-mark)
4905                    (gnus-newsgroup-agentized
4906                     gnus-downloaded-mark)
4907                    (t
4908                     gnus-no-mark))
4909              gnus-tmp-from (mail-header-from gnus-tmp-header)
4910              gnus-tmp-name
4911              (cond
4912               ((string-match "<[^>]+> *$" gnus-tmp-from)
4913                (setq beg-match (match-beginning 0))
4914                (or (and (string-match "^\".+\"" gnus-tmp-from)
4915                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4916                    (substring gnus-tmp-from 0 beg-match)))
4917               ((string-match "(.+)" gnus-tmp-from)
4918                (substring gnus-tmp-from
4919                           (1+ (match-beginning 0)) (1- (match-end 0))))
4920               (t gnus-tmp-from))
4921
4922              ;; Do the %B string
4923              gnus-tmp-thread-tree-header-string
4924              (cond
4925               ((not gnus-show-threads) "")
4926               ((zerop gnus-tmp-level)
4927                (cond ((cdar thread)
4928                       (or gnus-sum-thread-tree-root subject))
4929                      (gnus-tmp-new-adopts
4930                       (or gnus-sum-thread-tree-false-root subject))
4931                      (t
4932                       (or gnus-sum-thread-tree-single-indent subject))))
4933               (t
4934                (concat (apply 'concat
4935                               (mapcar (lambda (item)
4936                                         (if (= item 1)
4937                                             gnus-sum-thread-tree-vertical
4938                                           gnus-sum-thread-tree-indent))
4939                                       (cdr (reverse tree-stack))))
4940                        (if (nth 1 thread)
4941                            gnus-sum-thread-tree-leaf-with-other
4942                          gnus-sum-thread-tree-single-leaf)))))
4943             (when (string= gnus-tmp-name "")
4944               (setq gnus-tmp-name gnus-tmp-from))
4945             (unless (numberp gnus-tmp-lines)
4946               (setq gnus-tmp-lines -1))
4947             (if (= gnus-tmp-lines -1)
4948                 (setq gnus-tmp-lines "?")
4949               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4950               (gnus-put-text-property
4951              (point)
4952              (progn (eval gnus-summary-line-format-spec) (point))
4953                'gnus-number number)
4954             (when gnus-visual-p
4955               (forward-line -1)
4956               (gnus-run-hooks 'gnus-summary-update-hook)
4957               (forward-line 1))
4958
4959             (setq gnus-tmp-prev-subject simp-subject)))
4960
4961         (when (nth 1 thread)
4962           (push (list (max 0 gnus-tmp-level)
4963                       (copy-sequence tree-stack)
4964                       (nthcdr 1 thread))
4965                 stack))
4966         (push (if (nth 1 thread) 1 0) tree-stack)
4967         (incf gnus-tmp-level)
4968         (setq threads (if thread-end nil (cdar thread)))
4969         (if gnus-summary-display-while-building
4970             (if building-count
4971                 (progn
4972                   ;; use a set frequency
4973                   (setq building-line-count (1- building-line-count))
4974                   (when (= building-line-count 0)
4975                     (sit-for 0)
4976                     (setq building-line-count
4977                           gnus-summary-display-while-building)))
4978               ;; always
4979               (sit-for 0)))
4980         (unless threads
4981           (setq gnus-tmp-level 0)))))
4982   (gnus-message 7 "Generating summary...done"))
4983
4984 (defun gnus-summary-prepare-unthreaded (headers)
4985   "Generate an unthreaded summary buffer based on HEADERS."
4986   (let (header number mark)
4987
4988     (beginning-of-line)
4989
4990     (while headers
4991       ;; We may have to root out some bad articles...
4992       (when (memq (setq number (mail-header-number
4993                                 (setq header (pop headers))))
4994                   gnus-newsgroup-limit)
4995         ;; Mark article as read when it has a low score.
4996         (when (and gnus-summary-mark-below
4997                    (< (or (cdr (assq number gnus-newsgroup-scored))
4998                           gnus-summary-default-score 0)
4999                       gnus-summary-mark-below)
5000                    (not (gnus-summary-article-ancient-p number)))
5001           (setq gnus-newsgroup-unreads
5002                 (delq number gnus-newsgroup-unreads))
5003           (if gnus-newsgroup-auto-expire
5004               (push number gnus-newsgroup-expirable)
5005             (push (cons number gnus-low-score-mark)
5006                   gnus-newsgroup-reads)))
5007
5008         (setq mark (gnus-article-mark number))
5009         (push (gnus-data-make number mark (1+ (point)) header 0)
5010               gnus-newsgroup-data)
5011         (gnus-summary-insert-line
5012          header 0 number
5013          (memq number gnus-newsgroup-undownloaded)
5014          mark (memq number gnus-newsgroup-replied)
5015          (memq number gnus-newsgroup-expirable)
5016          (mail-header-subject header) nil
5017          (cdr (assq number gnus-newsgroup-scored))
5018          (memq number gnus-newsgroup-processable))))))
5019
5020 (defun gnus-summary-remove-list-identifiers ()
5021   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5022   (let ((regexp (if (consp gnus-list-identifiers)
5023                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5024                   gnus-list-identifiers))
5025         changed subject)
5026     (when regexp
5027       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5028       (dolist (header gnus-newsgroup-headers)
5029         (setq subject (mail-header-subject header)
5030               changed nil)
5031         (while (string-match regexp subject)
5032           (setq subject
5033                 (concat (substring subject 0 (match-beginning 1))
5034                         (substring subject (match-end 0)))
5035                 changed t))
5036         (when changed
5037           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5038             (setq subject
5039                   (concat (substring subject 0 (match-beginning 1))
5040                           (substring subject (match-end 1)))))
5041           (mail-header-set-subject header subject))))))
5042
5043 (defun gnus-fetch-headers (articles)
5044   "Fetch headers of ARTICLES."
5045   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5046     (gnus-message 5 "Fetching headers for %s..." name)
5047     (prog1
5048         (if (eq 'nov
5049                 (setq gnus-headers-retrieved-by
5050                       (gnus-retrieve-headers
5051                        articles gnus-newsgroup-name
5052                        ;; We might want to fetch old headers, but
5053                        ;; not if there is only 1 article.
5054                        (and (or (and
5055                                  (not (eq gnus-fetch-old-headers 'some))
5056                                  (not (numberp gnus-fetch-old-headers)))
5057                                 (> (length articles) 1))
5058                             gnus-fetch-old-headers))))
5059             (gnus-get-newsgroup-headers-xover
5060              articles nil nil gnus-newsgroup-name t)
5061           (gnus-get-newsgroup-headers))
5062       (gnus-message 5 "Fetching headers for %s...done" name))))
5063
5064 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5065   "Select newsgroup GROUP.
5066 If READ-ALL is non-nil, all articles in the group are selected.
5067 If SELECT-ARTICLES, only select those articles from GROUP."
5068   (let* ((entry (gnus-group-entry group))
5069          ;;!!! Dirty hack; should be removed.
5070          (gnus-summary-ignore-duplicates
5071           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5072               t
5073             gnus-summary-ignore-duplicates))
5074          (info (nth 2 entry))
5075          articles fetched-articles cached)
5076
5077     (unless (gnus-check-server
5078              (set (make-local-variable 'gnus-current-select-method)
5079                   (gnus-find-method-for-group group)))
5080       (error "Couldn't open server"))
5081
5082     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5083         (gnus-activate-group group)     ; Or we can activate it...
5084         (progn                          ; Or we bug out.
5085           (when (equal major-mode 'gnus-summary-mode)
5086             (gnus-kill-buffer (current-buffer)))
5087           (error "Couldn't activate group %s: %s"
5088                  group (gnus-status-message group))))
5089
5090     (unless (gnus-request-group group t)
5091       (when (equal major-mode 'gnus-summary-mode)
5092         (gnus-kill-buffer (current-buffer)))
5093       (error "Couldn't request group %s: %s"
5094              group (gnus-status-message group)))
5095
5096     (when gnus-agent
5097       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5098       
5099       (setq gnus-summary-use-undownloaded-faces
5100             (gnus-agent-find-parameter
5101              group
5102              'agent-enable-undownloaded-faces)))
5103
5104     (setq gnus-newsgroup-name group
5105           gnus-newsgroup-unselected nil
5106           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5107
5108     (let ((display (gnus-group-find-parameter group 'display)))
5109       (setq gnus-newsgroup-display
5110             (cond
5111              ((not (zerop (or (car-safe read-all) 0)))
5112               ;; The user entered the group with C-u SPC/RET, let's show
5113               ;; all articles.
5114               'gnus-not-ignore)
5115              ((eq display 'all)
5116               'gnus-not-ignore)
5117              ((arrayp display)
5118               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5119              ((numberp display)
5120               ;; The following is probably the "correct" solution, but
5121               ;; it makes Gnus fetch all headers and then limit the
5122               ;; articles (which is slow), so instead we hack the
5123               ;; select-articles parameter instead. -- Simon Josefsson
5124               ;; <jas@kth.se>
5125               ;;
5126               ;; (gnus-byte-compile
5127               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5128               ;;                         display)))))
5129               (setq select-articles
5130                     (gnus-uncompress-range
5131                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5132                              (if (> tmp 0)
5133                                  tmp
5134                                1))
5135                            (cdr (gnus-active group)))))
5136               nil)
5137              (t
5138               nil))))
5139
5140     (gnus-summary-setup-default-charset)
5141
5142     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5143     (when (gnus-virtual-group-p group)
5144       (setq cached gnus-newsgroup-cached))
5145
5146     (setq gnus-newsgroup-unreads
5147           (gnus-sorted-ndifference
5148            (gnus-sorted-ndifference gnus-newsgroup-unreads
5149                                     gnus-newsgroup-marked)
5150            gnus-newsgroup-dormant))
5151
5152     (setq gnus-newsgroup-processable nil)
5153
5154     (gnus-update-read-articles group gnus-newsgroup-unreads)
5155
5156     ;; Adjust and set lists of article marks.
5157     (when info
5158       (gnus-adjust-marked-articles info))
5159     (if (setq articles select-articles)
5160         (setq gnus-newsgroup-unselected
5161               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5162       (setq articles (gnus-articles-to-read group read-all)))
5163
5164     (cond
5165      ((null articles)
5166       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5167       'quit)
5168      ((eq articles 0) nil)
5169      (t
5170       ;; Init the dependencies hash table.
5171       (setq gnus-newsgroup-dependencies
5172             (gnus-make-hashtable (length articles)))
5173       (gnus-set-global-variables)
5174       ;; Retrieve the headers and read them in.
5175
5176       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5177
5178       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5179       (when cached
5180         (setq gnus-newsgroup-cached cached))
5181
5182       ;; Suppress duplicates?
5183       (when gnus-suppress-duplicates
5184         (gnus-dup-suppress-articles))
5185
5186       ;; Set the initial limit.
5187       (setq gnus-newsgroup-limit (copy-sequence articles))
5188       ;; Remove canceled articles from the list of unread articles.
5189       (setq fetched-articles
5190             (mapcar (lambda (headers) (mail-header-number headers))
5191                     gnus-newsgroup-headers))
5192       (setq gnus-newsgroup-articles fetched-articles)
5193       (setq gnus-newsgroup-unreads
5194             (gnus-sorted-nintersection
5195              gnus-newsgroup-unreads fetched-articles))
5196       (gnus-compute-unseen-list)
5197
5198       ;; Removed marked articles that do not exist.
5199       (gnus-update-missing-marks
5200        (gnus-sorted-difference articles fetched-articles))
5201       ;; We might want to build some more threads first.
5202       (when (and gnus-fetch-old-headers
5203                  (eq gnus-headers-retrieved-by 'nov))
5204         (if (eq gnus-fetch-old-headers 'invisible)
5205             (gnus-build-all-threads)
5206           (gnus-build-old-threads)))
5207       ;; Let the Gnus agent mark articles as read.
5208       (when gnus-agent
5209         (gnus-agent-get-undownloaded-list))
5210       ;; Remove list identifiers from subject
5211       (when gnus-list-identifiers
5212         (gnus-summary-remove-list-identifiers))
5213       ;; Check whether auto-expire is to be done in this group.
5214       (setq gnus-newsgroup-auto-expire
5215             (gnus-group-auto-expirable-p group))
5216       ;; Set up the article buffer now, if necessary.
5217       (unless gnus-single-article-buffer
5218         (gnus-article-setup-buffer))
5219       ;; First and last article in this newsgroup.
5220       (when gnus-newsgroup-headers
5221         (setq gnus-newsgroup-begin
5222               (mail-header-number (car gnus-newsgroup-headers))
5223               gnus-newsgroup-end
5224               (mail-header-number
5225                (gnus-last-element gnus-newsgroup-headers))))
5226       ;; GROUP is successfully selected.
5227       (or gnus-newsgroup-headers t)))))
5228
5229 (defun gnus-compute-unseen-list ()
5230   ;; The `seen' marks are treated specially.
5231   (if (not gnus-newsgroup-seen)
5232       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5233     (setq gnus-newsgroup-unseen
5234           (gnus-inverse-list-range-intersection
5235            gnus-newsgroup-articles gnus-newsgroup-seen))))
5236
5237 (defun gnus-summary-display-make-predicate (display)
5238   (require 'gnus-agent)
5239   (when (= (length display) 1)
5240     (setq display (car display)))
5241   (unless gnus-summary-display-cache
5242     (dolist (elem (append '((unread . unread)
5243                             (read . read)
5244                             (unseen . unseen))
5245                           gnus-article-mark-lists))
5246       (push (cons (cdr elem)
5247                   (gnus-byte-compile
5248                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5249             gnus-summary-display-cache)))
5250   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5251         (gnus-category-predicate-cache gnus-summary-display-cache))
5252     (gnus-get-predicate display)))
5253
5254 ;; Uses the dynamically bound `number' variable.
5255 (eval-when-compile
5256   (defvar number))
5257 (defun gnus-article-marked-p (type &optional article)
5258   (let ((article (or article number)))
5259     (cond
5260      ((eq type 'tick)
5261       (memq article gnus-newsgroup-marked))
5262      ((eq type 'spam)
5263       (memq article gnus-newsgroup-spam-marked))
5264      ((eq type 'unsend)
5265       (memq article gnus-newsgroup-unsendable))
5266      ((eq type 'undownload)
5267       (memq article gnus-newsgroup-undownloaded))
5268      ((eq type 'download)
5269       (memq article gnus-newsgroup-downloadable))
5270      ((eq type 'unread)
5271       (memq article gnus-newsgroup-unreads))
5272      ((eq type 'read)
5273       (memq article gnus-newsgroup-reads))
5274      ((eq type 'dormant)
5275       (memq article gnus-newsgroup-dormant) )
5276      ((eq type 'expire)
5277       (memq article gnus-newsgroup-expirable))
5278      ((eq type 'reply)
5279       (memq article gnus-newsgroup-replied))
5280      ((eq type 'killed)
5281       (memq article gnus-newsgroup-killed))
5282      ((eq type 'bookmark)
5283       (assq article gnus-newsgroup-bookmarks))
5284      ((eq type 'score)
5285       (assq article gnus-newsgroup-scored))
5286      ((eq type 'save)
5287       (memq article gnus-newsgroup-saved))
5288      ((eq type 'cache)
5289       (memq article gnus-newsgroup-cached))
5290      ((eq type 'forward)
5291       (memq article gnus-newsgroup-forwarded))
5292      ((eq type 'seen)
5293       (not (memq article gnus-newsgroup-unseen)))
5294      ((eq type 'recent)
5295       (memq article gnus-newsgroup-recent))
5296      (t t))))
5297
5298 (defun gnus-articles-to-read (group &optional read-all)
5299   "Find out what articles the user wants to read."
5300   (let* ((display (gnus-group-find-parameter group 'display))
5301          (articles
5302           ;; Select all articles if `read-all' is non-nil, or if there
5303           ;; are no unread articles.
5304           (if (or read-all
5305                   (and (zerop (length gnus-newsgroup-marked))
5306                        (zerop (length gnus-newsgroup-unreads)))
5307                   ;; Fetch all if the predicate is non-nil.
5308                   gnus-newsgroup-display)
5309               ;; We want to select the headers for all the articles in
5310               ;; the group, so we select either all the active
5311               ;; articles in the group, or (if that's nil), the
5312               ;; articles in the cache.
5313               (or
5314                (gnus-uncompress-range (gnus-active group))
5315                (gnus-cache-articles-in-group group))
5316             ;; Select only the "normal" subset of articles.
5317             (gnus-sorted-nunion
5318              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5319              gnus-newsgroup-unreads)))
5320          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5321          (scored (length scored-list))
5322          (number (length articles))
5323          (marked (+ (length gnus-newsgroup-marked)
5324                     (length gnus-newsgroup-dormant)))
5325          (select
5326           (cond
5327            ((numberp read-all)
5328             read-all)
5329            ((numberp gnus-newsgroup-display)
5330             gnus-newsgroup-display)
5331            (t
5332             (condition-case ()
5333                 (cond
5334                  ((and (or (<= scored marked) (= scored number))
5335                        (numberp gnus-large-newsgroup)
5336                        (> number gnus-large-newsgroup))
5337                   (let* ((cursor-in-echo-area nil)
5338                          (initial (gnus-parameter-large-newsgroup-initial
5339                                    gnus-newsgroup-name))
5340                          (input
5341                           (read-string
5342                            (format
5343                             "How many articles from %s (%s %d): "
5344                             (gnus-limit-string
5345                              (gnus-group-decoded-name gnus-newsgroup-name)
5346                              35)
5347                             (if initial "max" "default")
5348                             number)
5349                            (if initial
5350                                (cons (number-to-string initial)
5351                                      0)))))
5352                     (if (string-match "^[ \t]*$" input) number input)))
5353                  ((and (> scored marked) (< scored number)
5354                        (> (- scored number) 20))
5355                   (let ((input
5356                          (read-string
5357                           (format "%s %s (%d scored, %d total): "
5358                                   "How many articles from"
5359                                   (gnus-group-decoded-name group)
5360                                   scored number))))
5361                     (if (string-match "^[ \t]*$" input)
5362                         number input)))
5363                  (t number))
5364               (quit
5365                (message "Quit getting the articles to read")
5366                nil))))))
5367     (setq select (if (stringp select) (string-to-number select) select))
5368     (if (or (null select) (zerop select))
5369         select
5370       (if (and (not (zerop scored)) (<= (abs select) scored))
5371           (progn
5372             (setq articles (sort scored-list '<))
5373             (setq number (length articles)))
5374         (setq articles (copy-sequence articles)))
5375
5376       (when (< (abs select) number)
5377         (if (< select 0)
5378             ;; Select the N oldest articles.
5379             (setcdr (nthcdr (1- (abs select)) articles) nil)
5380           ;; Select the N most recent articles.
5381           (setq articles (nthcdr (- number select) articles))))
5382       (setq gnus-newsgroup-unselected
5383             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5384       (when gnus-alter-articles-to-read-function
5385         (setq articles
5386               (sort
5387                (funcall gnus-alter-articles-to-read-function
5388                         gnus-newsgroup-name articles)
5389                '<)))
5390       articles)))
5391
5392 (defun gnus-killed-articles (killed articles)
5393   (let (out)
5394     (while articles
5395       (when (inline (gnus-member-of-range (car articles) killed))
5396         (push (car articles) out))
5397       (setq articles (cdr articles)))
5398     out))
5399
5400 (defun gnus-uncompress-marks (marks)
5401   "Uncompress the mark ranges in MARKS."
5402   (let ((uncompressed '(score bookmark))
5403         out)
5404     (while marks
5405       (if (memq (caar marks) uncompressed)
5406           (push (car marks) out)
5407         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5408       (setq marks (cdr marks)))
5409     out))
5410
5411 (defun gnus-article-mark-to-type (mark)
5412   "Return the type of MARK."
5413   (or (cadr (assq mark gnus-article-special-mark-lists))
5414       'list))
5415
5416 (defun gnus-article-unpropagatable-p (mark)
5417   "Return whether MARK should be propagated to back end."
5418   (memq mark gnus-article-unpropagated-mark-lists))
5419
5420 (defun gnus-adjust-marked-articles (info)
5421   "Set all article lists and remove all marks that are no longer valid."
5422   (let* ((marked-lists (gnus-info-marks info))
5423          (active (gnus-active (gnus-info-group info)))
5424          (min (car active))
5425          (max (cdr active))
5426          (types gnus-article-mark-lists)
5427          marks var articles article mark mark-type
5428          bgn end)
5429
5430     (dolist (marks marked-lists)
5431       (setq mark (car marks)
5432             mark-type (gnus-article-mark-to-type mark)
5433             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5434
5435       ;; We set the variable according to the type of the marks list,
5436       ;; and then adjust the marks to a subset of the active articles.
5437       (cond
5438        ;; Adjust "simple" lists - compressed yet unsorted
5439        ((eq mark-type 'list)
5440         ;; Simultaneously uncompress and clip to active range
5441         ;; See gnus-uncompress-range for a description of possible marks
5442         (let (l lh)
5443           (if (not (cadr marks))
5444               (set var nil)
5445             (setq articles (if (numberp (cddr marks))
5446                                (list (cdr marks))
5447                              (cdr marks))
5448                   lh (cons nil nil)
5449                   l lh)
5450
5451             (while (setq article (pop articles))
5452               (cond ((consp article)
5453                      (setq bgn (max (car article) min)
5454                            end (min (cdr article) max))
5455                      (while (<= bgn end)
5456                        (setq l (setcdr l (cons bgn nil))
5457                              bgn (1+ bgn))))
5458                     ((and (<= min article)
5459                           (>= max article))
5460                      (setq l (setcdr l (cons article nil))))))
5461             (set var (cdr lh)))))
5462        ;; Adjust assocs.
5463        ((eq mark-type 'tuple)
5464         (set var (setq articles (cdr marks)))
5465         (when (not (listp (cdr (symbol-value var))))
5466           (set var (list (symbol-value var))))
5467         (when (not (listp (cdr articles)))
5468           (setq articles (list articles)))
5469         (while articles
5470           (when (or (not (consp (setq article (pop articles))))
5471                     (< (car article) min)
5472                     (> (car article) max))
5473             (set var (delq article (symbol-value var))))))
5474        ;; Adjust ranges (sloppily).
5475        ((eq mark-type 'range)
5476         (cond
5477          ((eq mark 'seen)
5478           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5479           ;; It should be (seen (NUM1 . NUM2)).
5480           (when (numberp (cddr marks))
5481             (setcdr marks (list (cdr marks))))
5482           (setq articles (cdr marks))
5483           (while (and articles
5484                       (or (and (consp (car articles))
5485                                (> min (cdar articles)))
5486                           (and (numberp (car articles))
5487                                (> min (car articles)))))
5488             (pop articles))
5489           (set var articles))))))))
5490
5491 (defun gnus-update-missing-marks (missing)
5492   "Go through the list of MISSING articles and remove them from the mark lists."
5493   (when missing
5494     (let (var m)
5495       ;; Go through all types.
5496       (dolist (elem gnus-article-mark-lists)
5497         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5498           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5499           (when (symbol-value var)
5500             ;; This list has articles.  So we delete all missing
5501             ;; articles from it.
5502             (setq m missing)
5503             (while m
5504               (set var (delq (pop m) (symbol-value var))))))))))
5505
5506 (defun gnus-update-marks ()
5507   "Enter the various lists of marked articles into the newsgroup info list."
5508   (let ((types gnus-article-mark-lists)
5509         (info (gnus-get-info gnus-newsgroup-name))
5510         type list newmarked symbol delta-marks)
5511     (when info
5512       ;; Add all marks lists to the list of marks lists.
5513       (while (setq type (pop types))
5514         (setq list (symbol-value
5515                     (setq symbol
5516                           (intern (format "gnus-newsgroup-%s" (car type))))))
5517
5518         (when list
5519           ;; Get rid of the entries of the articles that have the
5520           ;; default score.
5521           (when (and (eq (cdr type) 'score)
5522                      gnus-save-score
5523                      list)
5524             (let* ((arts list)
5525                    (prev (cons nil list))
5526                    (all prev))
5527               (while arts
5528                 (if (or (not (consp (car arts)))
5529                         (= (cdar arts) gnus-summary-default-score))
5530                     (setcdr prev (cdr arts))
5531                   (setq prev arts))
5532                 (setq arts (cdr arts)))
5533               (setq list (cdr all)))))
5534
5535         (when (eq (cdr type) 'seen)
5536           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5537
5538         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5539           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5540
5541         (when (and (gnus-check-backend-function
5542                     'request-set-mark gnus-newsgroup-name)
5543                    (not (gnus-article-unpropagatable-p (cdr type))))
5544           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5545                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5546                  (add (gnus-remove-from-range
5547                        (gnus-copy-sequence list) old)))
5548             (when add
5549               (push (list add 'add (list (cdr type))) delta-marks))
5550             (when del
5551               (push (list del 'del (list (cdr type))) delta-marks))))
5552
5553         (when list
5554           (push (cons (cdr type) list) newmarked)))
5555
5556       (when delta-marks
5557         (unless (gnus-check-group gnus-newsgroup-name)
5558           (error "Can't open server for %s" gnus-newsgroup-name))
5559         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5560
5561       ;; Enter these new marks into the info of the group.
5562       (if (nthcdr 3 info)
5563           (setcar (nthcdr 3 info) newmarked)
5564         ;; Add the marks lists to the end of the info.
5565         (when newmarked
5566           (setcdr (nthcdr 2 info) (list newmarked))))
5567
5568       ;; Cut off the end of the info if there's nothing else there.
5569       (let ((i 5))
5570         (while (and (> i 2)
5571                     (not (nth i info)))
5572           (when (nthcdr (decf i) info)
5573             (setcdr (nthcdr i info) nil)))))))
5574
5575 (defun gnus-set-mode-line (where)
5576   "Set the mode line of the article or summary buffers.
5577 If WHERE is `summary', the summary mode line format will be used."
5578   ;; Is this mode line one we keep updated?
5579   (when (and (memq where gnus-updated-mode-lines)
5580              (symbol-value
5581               (intern (format "gnus-%s-mode-line-format-spec" where))))
5582     (let (mode-string)
5583       (save-excursion
5584         ;; We evaluate this in the summary buffer since these
5585         ;; variables are buffer-local to that buffer.
5586         (set-buffer gnus-summary-buffer)
5587         ;; We bind all these variables that are used in the `eval' form
5588         ;; below.
5589         (let* ((mformat (symbol-value
5590                          (intern
5591                           (format "gnus-%s-mode-line-format-spec" where))))
5592                (gnus-tmp-group-name (gnus-group-decoded-name
5593                                      gnus-newsgroup-name))
5594                (gnus-tmp-article-number (or gnus-current-article 0))
5595                (gnus-tmp-unread gnus-newsgroup-unreads)
5596                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5597                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5598                (gnus-tmp-unread-and-unselected
5599                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5600                             (zerop gnus-tmp-unselected))
5601                        "")
5602                       ((zerop gnus-tmp-unselected)
5603                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5604                       (t (format "{%d(+%d) more}"
5605                                  gnus-tmp-unread-and-unticked
5606                                  gnus-tmp-unselected))))
5607                (gnus-tmp-subject
5608                 (if (and gnus-current-headers
5609                          (vectorp gnus-current-headers))
5610                     (gnus-mode-string-quote
5611                      (mail-header-subject gnus-current-headers))
5612                   ""))
5613                bufname-length max-len
5614                gnus-tmp-header);; passed as argument to any user-format-funcs
5615           (setq mode-string (eval mformat))
5616           (setq bufname-length (if (string-match "%b" mode-string)
5617                                    (- (length
5618                                        (buffer-name
5619                                         (if (eq where 'summary)
5620                                             nil
5621                                           (get-buffer gnus-article-buffer))))
5622                                       2)
5623                                  0))
5624           (setq max-len (max 4 (if gnus-mode-non-string-length
5625                                    (- (window-width)
5626                                       gnus-mode-non-string-length
5627                                       bufname-length)
5628                                  (length mode-string))))
5629           ;; We might have to chop a bit of the string off...
5630           (when (> (length mode-string) max-len)
5631             (setq mode-string
5632                   (concat (gnus-truncate-string mode-string (- max-len 3))
5633                           "...")))
5634           ;; Pad the mode string a bit.
5635           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5636       ;; Update the mode line.
5637       (setq mode-line-buffer-identification
5638             (gnus-mode-line-buffer-identification (list mode-string)))
5639       (set-buffer-modified-p t))))
5640
5641 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5642   "Go through the HEADERS list and add all Xrefs to a hash table.
5643 The resulting hash table is returned, or nil if no Xrefs were found."
5644   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5645          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5646          (xref-hashtb (gnus-make-hashtable))
5647          start group entry number xrefs header)
5648     (while headers
5649       (setq header (pop headers))
5650       (when (and (setq xrefs (mail-header-xref header))
5651                  (not (memq (setq number (mail-header-number header))
5652                             unreads)))
5653         (setq start 0)
5654         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5655           (setq start (match-end 0))
5656           (setq group (if prefix
5657                           (concat prefix (substring xrefs (match-beginning 1)
5658                                                     (match-end 1)))
5659                         (substring xrefs (match-beginning 1) (match-end 1))))
5660           (setq number
5661                 (string-to-int (substring xrefs (match-beginning 2)
5662                                           (match-end 2))))
5663           (if (setq entry (gnus-gethash group xref-hashtb))
5664               (setcdr entry (cons number (cdr entry)))
5665             (gnus-sethash group (cons number nil) xref-hashtb)))))
5666     (and start xref-hashtb)))
5667
5668 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5669   "Look through all the headers and mark the Xrefs as read."
5670   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5671         name info xref-hashtb idlist method nth4)
5672     (save-excursion
5673       (set-buffer gnus-group-buffer)
5674       (when (setq xref-hashtb
5675                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5676         (mapatoms
5677          (lambda (group)
5678            (unless (string= from-newsgroup (setq name (symbol-name group)))
5679              (setq idlist (symbol-value group))
5680              ;; Dead groups are not updated.
5681              (and (prog1
5682                       (setq info (gnus-get-info name))
5683                     (when (stringp (setq nth4 (gnus-info-method info)))
5684                       (setq nth4 (gnus-server-to-method nth4))))
5685                   ;; Only do the xrefs if the group has the same
5686                   ;; select method as the group we have just read.
5687                   (or (gnus-methods-equal-p
5688                        nth4 (gnus-find-method-for-group from-newsgroup))
5689                       virtual
5690                       (equal nth4 (setq method (gnus-find-method-for-group
5691                                                 from-newsgroup)))
5692                       (and (equal (car nth4) (car method))
5693                            (equal (nth 1 nth4) (nth 1 method))))
5694                   gnus-use-cross-reference
5695                   (or (not (eq gnus-use-cross-reference t))
5696                       virtual
5697                       ;; Only do cross-references on subscribed
5698                       ;; groups, if that is what is wanted.
5699                       (<= (gnus-info-level info) gnus-level-subscribed))
5700                   (gnus-group-make-articles-read name idlist))))
5701          xref-hashtb)))))
5702
5703 (defun gnus-compute-read-articles (group articles)
5704   (let* ((entry (gnus-group-entry group))
5705          (info (nth 2 entry))
5706          (active (gnus-active group))
5707          ninfo)
5708     (when entry
5709       ;; First peel off all invalid article numbers.
5710       (when active
5711         (let ((ids articles)
5712               id first)
5713           (while (setq id (pop ids))
5714             (when (and first (> id (cdr active)))
5715               ;; We'll end up in this situation in one particular
5716               ;; obscure situation.  If you re-scan a group and get
5717               ;; a new article that is cross-posted to a different
5718               ;; group that has not been re-scanned, you might get
5719               ;; crossposted article that has a higher number than
5720               ;; Gnus believes possible.  So we re-activate this
5721               ;; group as well.  This might mean doing the
5722               ;; crossposting thingy will *increase* the number
5723               ;; of articles in some groups.  Tsk, tsk.
5724               (setq active (or (gnus-activate-group group) active)))
5725             (when (or (> id (cdr active))
5726                       (< id (car active)))
5727               (setq articles (delq id articles))))))
5728       ;; If the read list is nil, we init it.
5729       (if (and active
5730                (null (gnus-info-read info))
5731                (> (car active) 1))
5732           (setq ninfo (cons 1 (1- (car active))))
5733         (setq ninfo (gnus-info-read info)))
5734       ;; Then we add the read articles to the range.
5735       (gnus-add-to-range
5736        ninfo (setq articles (sort articles '<))))))
5737
5738 (defun gnus-group-make-articles-read (group articles)
5739   "Update the info of GROUP to say that ARTICLES are read."
5740   (let* ((num 0)
5741          (entry (gnus-group-entry group))
5742          (info (nth 2 entry))
5743          (active (gnus-active group))
5744          range)
5745     (when entry
5746       (setq range (gnus-compute-read-articles group articles))
5747       (with-current-buffer gnus-group-buffer
5748         (gnus-undo-register
5749           `(progn
5750              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5751              (gnus-info-set-read ',info ',(gnus-info-read info))
5752              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5753              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5754              (gnus-group-update-group ,group t))))
5755       ;; Add the read articles to the range.
5756       (gnus-info-set-read info range)
5757       (gnus-request-set-mark group (list (list range 'add '(read))))
5758       ;; Then we have to re-compute how many unread
5759       ;; articles there are in this group.
5760       (when active
5761         (cond
5762          ((not range)
5763           (setq num (- (1+ (cdr active)) (car active))))
5764          ((not (listp (cdr range)))
5765           (setq num (- (cdr active) (- (1+ (cdr range))
5766                                        (car range)))))
5767          (t
5768           (while range
5769             (if (numberp (car range))
5770                 (setq num (1+ num))
5771               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5772             (setq range (cdr range)))
5773           (setq num (- (cdr active) num))))
5774         ;; Update the number of unread articles.
5775         (setcar entry num)
5776         ;; Update the group buffer.
5777         (unless (gnus-ephemeral-group-p group)
5778           (gnus-group-update-group group t))))))
5779
5780 (defvar gnus-newsgroup-none-id 0)
5781
5782 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5783   (let ((cur nntp-server-buffer)
5784         (dependencies
5785          (or dependencies
5786              (with-current-buffer gnus-summary-buffer
5787                gnus-newsgroup-dependencies)))
5788         headers id end ref
5789         (mail-parse-charset gnus-newsgroup-charset)
5790         (mail-parse-ignored-charsets
5791          (save-excursion (condition-case nil
5792                              (set-buffer gnus-summary-buffer)
5793                            (error))
5794                          gnus-newsgroup-ignored-charsets)))
5795     (save-excursion
5796       (set-buffer nntp-server-buffer)
5797       ;; Translate all TAB characters into SPACE characters.
5798       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5799       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5800       (ietf-drums-unfold-fws)
5801       (gnus-run-hooks 'gnus-parse-headers-hook)
5802       (let ((case-fold-search t)
5803             in-reply-to header p lines chars ctype)
5804         (goto-char (point-min))
5805         ;; Search to the beginning of the next header.  Error messages
5806         ;; do not begin with 2 or 3.
5807         (while (re-search-forward "^[23][0-9]+ " nil t)
5808           (setq id nil
5809                 ref nil)
5810           ;; This implementation of this function, with nine
5811           ;; search-forwards instead of the one re-search-forward and
5812           ;; a case (which basically was the old function) is actually
5813           ;; about twice as fast, even though it looks messier.  You
5814           ;; can't have everything, I guess.  Speed and elegance
5815           ;; doesn't always go hand in hand.
5816           (setq
5817            header
5818            (make-full-mail-header
5819             ;; Number.
5820             (prog1
5821                 (read cur)
5822               (end-of-line)
5823               (setq p (point))
5824               (narrow-to-region (point)
5825                                 (or (and (search-forward "\n.\n" nil t)
5826                                          (- (point) 2))
5827                                     (point))))
5828             ;; Subject.
5829             (progn
5830               (goto-char p)
5831               (if (search-forward "\nsubject:" nil t)
5832                   (nnheader-header-value)
5833                 "(none)"))
5834             ;; From.
5835             (progn
5836               (goto-char p)
5837               (if (search-forward "\nfrom:" nil t)
5838                   (nnheader-header-value)
5839                 "(nobody)"))
5840             ;; Date.
5841             (progn
5842               (goto-char p)
5843               (if (search-forward "\ndate:" nil t)
5844                   (nnheader-header-value) ""))
5845             ;; Message-ID.
5846             (progn
5847               (goto-char p)
5848               (setq id (if (re-search-forward
5849                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5850                            ;; We do it this way to make sure the Message-ID
5851                            ;; is (somewhat) syntactically valid.
5852                            (buffer-substring (match-beginning 1)
5853                                              (match-end 1))
5854                          ;; If there was no message-id, we just fake one
5855                          ;; to make subsequent routines simpler.
5856                          (nnheader-generate-fake-message-id))))
5857             ;; References.
5858             (progn
5859               (goto-char p)
5860               (if (search-forward "\nreferences:" nil t)
5861                   (progn
5862                     (setq end (point))
5863                     (prog1
5864                         (nnheader-header-value)
5865                       (setq ref
5866                             (buffer-substring
5867                              (progn
5868                                ;; (end-of-line)
5869                                (search-backward ">" end t)
5870                                (1+ (point)))
5871                              (progn
5872                                (search-backward "<" end t)
5873                                (point))))))
5874                 ;; Get the references from the in-reply-to header if there
5875                 ;; were no references and the in-reply-to header looks
5876                 ;; promising.
5877                 (if (and (search-forward "\nin-reply-to:" nil t)
5878                          (setq in-reply-to (nnheader-header-value))
5879                          (string-match "<[^>]+>" in-reply-to))
5880                     (let (ref2)
5881                       (setq ref (substring in-reply-to (match-beginning 0)
5882                                            (match-end 0)))
5883                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5884                         (setq ref2 (substring in-reply-to (match-beginning 0)
5885                                               (match-end 0)))
5886                         (when (> (length ref2) (length ref))
5887                           (setq ref ref2)))
5888                       ref)
5889                   (setq ref nil))))
5890             ;; Chars.
5891             (progn
5892               (goto-char p)
5893               (if (search-forward "\nchars: " nil t)
5894                   (if (numberp (setq chars (ignore-errors (read cur))))
5895                       chars -1)
5896                 -1))
5897             ;; Lines.
5898             (progn
5899               (goto-char p)
5900               (if (search-forward "\nlines: " nil t)
5901                   (if (numberp (setq lines (ignore-errors (read cur))))
5902                       lines -1)
5903                 -1))
5904             ;; Xref.
5905             (progn
5906               (goto-char p)
5907               (and (search-forward "\nxref:" nil t)
5908                    (nnheader-header-value)))
5909             ;; Extra.
5910             (when gnus-extra-headers
5911               (let ((extra gnus-extra-headers)
5912                     out)
5913                 (while extra
5914                   (goto-char p)
5915                   (when (search-forward
5916                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5917                     (push (cons (car extra) (nnheader-header-value)) out))
5918                   (pop extra))
5919                 out))))
5920           (goto-char p)
5921           (if (and (search-forward "\ncontent-type: " nil t)
5922                    (setq ctype (nnheader-header-value)))
5923               (mime-entity-set-content-type-internal
5924                header (mime-parse-Content-Type ctype)))
5925           (when (equal id ref)
5926             (setq ref nil))
5927
5928           (when gnus-alter-header-function
5929             (funcall gnus-alter-header-function header)
5930             (setq id (mail-header-id header)
5931                   ref (gnus-parent-id (mail-header-references header))))
5932
5933           (when (setq header
5934                       (gnus-dependencies-add-header
5935                        header dependencies force-new))
5936             (push header headers))
5937           (goto-char (point-max))
5938           (widen))
5939         (nreverse headers)))))
5940
5941 ;; Goes through the xover lines and returns a list of vectors
5942 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5943                                                   force-new dependencies
5944                                                   group also-fetch-heads)
5945   "Parse the news overview data in the server buffer.
5946 Return a list of headers that match SEQUENCE (see
5947 `nntp-retrieve-headers')."
5948   ;; Get the Xref when the users reads the articles since most/some
5949   ;; NNTP servers do not include Xrefs when using XOVER.
5950   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5951   (let ((mail-parse-charset gnus-newsgroup-charset)
5952         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5953         (cur nntp-server-buffer)
5954         (dependencies (or dependencies gnus-newsgroup-dependencies))
5955         (allp (cond
5956                ((eq gnus-read-all-available-headers t)
5957                 t)
5958                ((stringp gnus-read-all-available-headers)
5959                 (string-match gnus-read-all-available-headers group))
5960                (t
5961                 nil)))
5962         number headers header)
5963     (save-excursion
5964       (set-buffer nntp-server-buffer)
5965       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5966       ;; Allow the user to mangle the headers before parsing them.
5967       (gnus-run-hooks 'gnus-parse-headers-hook)
5968       (goto-char (point-min))
5969       (gnus-parse-without-error
5970         (while (and (or sequence allp)
5971                     (not (eobp)))
5972           (setq number (read cur))
5973           (when (not allp)
5974             (while (and sequence
5975                         (< (car sequence) number))
5976               (setq sequence (cdr sequence))))
5977           (when (and (or allp
5978                          (and sequence
5979                               (eq number (car sequence))))
5980                      (progn
5981                        (setq sequence (cdr sequence))
5982                        (setq header (inline
5983                                       (gnus-nov-parse-line
5984                                        number dependencies force-new)))))
5985             (push header headers))
5986           (forward-line 1)))
5987       ;; A common bug in inn is that if you have posted an article and
5988       ;; then retrieves the active file, it will answer correctly --
5989       ;; the new article is included.  However, a NOV entry for the
5990       ;; article may not have been generated yet, so this may fail.
5991       ;; We work around this problem by retrieving the last few
5992       ;; headers using HEAD.
5993       (if (or (not also-fetch-heads)
5994               (not sequence))
5995           ;; We (probably) got all the headers.
5996           (nreverse headers)
5997         (let ((gnus-nov-is-evil t))
5998           (nconc
5999            (nreverse headers)
6000            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6001              (gnus-get-newsgroup-headers))))))))
6002
6003 (defun gnus-article-get-xrefs ()
6004   "Fill in the Xref value in `gnus-current-headers', if necessary.
6005 This is meant to be called in `gnus-article-internal-prepare-hook'."
6006   (let ((headers (with-current-buffer gnus-summary-buffer
6007                    gnus-current-headers)))
6008     (or (not gnus-use-cross-reference)
6009         (not headers)
6010         (and (mail-header-xref headers)
6011              (not (string= (mail-header-xref headers) "")))
6012         (let ((case-fold-search t)
6013               xref)
6014           (save-restriction
6015             (nnheader-narrow-to-headers)
6016             (goto-char (point-min))
6017             (when (or (and (not (eobp))
6018                            (eq (downcase (char-after)) ?x)
6019                            (looking-at "Xref:"))
6020                       (search-forward "\nXref:" nil t))
6021               (goto-char (1+ (match-end 0)))
6022               (setq xref (buffer-substring (point) (point-at-eol)))
6023               (mail-header-set-xref headers xref)))))))
6024
6025 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6026   "Find article ID and insert the summary line for that article.
6027 OLD-HEADER can either be a header or a line number to insert
6028 the subject line on."
6029   (let* ((line (and (numberp old-header) old-header))
6030          (old-header (and (vectorp old-header) old-header))
6031          (header (cond ((and old-header use-old-header)
6032                         old-header)
6033                        ((and (numberp id)
6034                              (gnus-number-to-header id))
6035                         (gnus-number-to-header id))
6036                        (t
6037                         (gnus-read-header id))))
6038          (number (and (numberp id) id))
6039          d)
6040     (when header
6041       ;; Rebuild the thread that this article is part of and go to the
6042       ;; article we have fetched.
6043       (when (and (not gnus-show-threads)
6044                  old-header)
6045         (when (and number
6046                    (setq d (gnus-data-find (mail-header-number old-header))))
6047           (goto-char (gnus-data-pos d))
6048           (gnus-data-remove
6049            number
6050            (- (point-at-bol)
6051               (prog1
6052                   (1+ (point-at-eol))
6053                 (gnus-delete-line))))))
6054       (when old-header
6055         (mail-header-set-number header (mail-header-number old-header)))
6056       (setq gnus-newsgroup-sparse
6057             (delq (setq number (mail-header-number header))
6058                   gnus-newsgroup-sparse))
6059       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6060       (push number gnus-newsgroup-limit)
6061       (gnus-rebuild-thread (mail-header-id header) line)
6062       (gnus-summary-goto-subject number nil t))
6063     (when (and (numberp number)
6064                (> number 0))
6065       ;; We have to update the boundaries even if we can't fetch the
6066       ;; article if ID is a number -- so that the next `P' or `N'
6067       ;; command will fetch the previous (or next) article even
6068       ;; if the one we tried to fetch this time has been canceled.
6069       (when (> number gnus-newsgroup-end)
6070         (setq gnus-newsgroup-end number))
6071       (when (< number gnus-newsgroup-begin)
6072         (setq gnus-newsgroup-begin number))
6073       (setq gnus-newsgroup-unselected
6074             (delq number gnus-newsgroup-unselected)))
6075     ;; Report back a success?
6076     (and header (mail-header-number header))))
6077
6078 ;;; Process/prefix in the summary buffer
6079
6080 (defun gnus-summary-work-articles (n)
6081   "Return a list of articles to be worked upon.
6082 The prefix argument, the list of process marked articles, and the
6083 current article will be taken into consideration."
6084   (save-excursion
6085     (set-buffer gnus-summary-buffer)
6086     (cond
6087      (n
6088       ;; A numerical prefix has been given.
6089       (setq n (prefix-numeric-value n))
6090       (let ((backward (< n 0))
6091             (n (abs (prefix-numeric-value n)))
6092             articles article)
6093         (save-excursion
6094           (while
6095               (and (> n 0)
6096                    (push (setq article (gnus-summary-article-number))
6097                          articles)
6098                    (if backward
6099                        (gnus-summary-find-prev nil article)
6100                      (gnus-summary-find-next nil article)))
6101             (decf n)))
6102         (nreverse articles)))
6103      ((and (gnus-region-active-p) (mark))
6104       (message "region active")
6105       ;; Work on the region between point and mark.
6106       (let ((max (max (point) (mark)))
6107             articles article)
6108         (save-excursion
6109           (goto-char (min (point) (mark)))
6110           (while
6111               (and
6112                (push (setq article (gnus-summary-article-number)) articles)
6113                (gnus-summary-find-next nil article)
6114                (< (point) max)))
6115           (nreverse articles))))
6116      (gnus-newsgroup-processable
6117       ;; There are process-marked articles present.
6118       ;; Save current state.
6119       (gnus-summary-save-process-mark)
6120       ;; Return the list.
6121       (reverse gnus-newsgroup-processable))
6122      (t
6123       ;; Just return the current article.
6124       (list (gnus-summary-article-number))))))
6125
6126 (defmacro gnus-summary-iterate (arg &rest forms)
6127   "Iterate over the process/prefixed articles and do FORMS.
6128 ARG is the interactive prefix given to the command.  FORMS will be
6129 executed with point over the summary line of the articles."
6130   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6131     `(let ((,articles (gnus-summary-work-articles ,arg)))
6132        (while ,articles
6133          (gnus-summary-goto-subject (car ,articles))
6134          ,@forms
6135          (pop ,articles)))))
6136
6137 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6138 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6139
6140 (defun gnus-summary-save-process-mark ()
6141   "Push the current set of process marked articles on the stack."
6142   (interactive)
6143   (push (copy-sequence gnus-newsgroup-processable)
6144         gnus-newsgroup-process-stack))
6145
6146 (defun gnus-summary-kill-process-mark ()
6147   "Push the current set of process marked articles on the stack and unmark."
6148   (interactive)
6149   (gnus-summary-save-process-mark)
6150   (gnus-summary-unmark-all-processable))
6151
6152 (defun gnus-summary-yank-process-mark ()
6153   "Pop the last process mark state off the stack and restore it."
6154   (interactive)
6155   (unless gnus-newsgroup-process-stack
6156     (error "Empty mark stack"))
6157   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6158
6159 (defun gnus-summary-process-mark-set (set)
6160   "Make SET into the current process marked articles."
6161   (gnus-summary-unmark-all-processable)
6162   (while set
6163     (gnus-summary-set-process-mark (pop set))))
6164
6165 ;;; Searching and stuff
6166
6167 (defun gnus-summary-search-group (&optional backward use-level)
6168   "Search for next unread newsgroup.
6169 If optional argument BACKWARD is non-nil, search backward instead."
6170   (save-excursion
6171     (set-buffer gnus-group-buffer)
6172     (when (gnus-group-search-forward
6173            backward nil (if use-level (gnus-group-group-level) nil))
6174       (gnus-group-group-name))))
6175
6176 (defun gnus-summary-best-group (&optional exclude-group)
6177   "Find the name of the best unread group.
6178 If EXCLUDE-GROUP, do not go to this group."
6179   (with-current-buffer gnus-group-buffer
6180     (save-excursion
6181       (gnus-group-best-unread-group exclude-group))))
6182
6183 (defun gnus-summary-find-next (&optional unread article backward)
6184   (if backward
6185       (gnus-summary-find-prev unread article)
6186     (let* ((dummy (gnus-summary-article-intangible-p))
6187            (article (or article (gnus-summary-article-number)))
6188            (data (gnus-data-find-list article))
6189            result)
6190       (when (and (not dummy)
6191                  (or (not gnus-summary-check-current)
6192                      (not unread)
6193                      (not (gnus-data-unread-p (car data)))))
6194         (setq data (cdr data)))
6195       (when (setq result
6196                   (if unread
6197                       (progn
6198                         (while data
6199                           (unless (memq (gnus-data-number (car data))
6200                                         (cond
6201                                          ((eq gnus-auto-goto-ignores
6202                                               'always-undownloaded)
6203                                           gnus-newsgroup-undownloaded)
6204                                          (gnus-plugged
6205                                           nil)
6206                                          ((eq gnus-auto-goto-ignores
6207                                               'unfetched)
6208                                           gnus-newsgroup-unfetched)
6209                                          ((eq gnus-auto-goto-ignores
6210                                               'undownloaded)
6211                                           gnus-newsgroup-undownloaded)))
6212                             (when (gnus-data-unread-p (car data))
6213                               (setq result (car data)
6214                                     data nil)))
6215                           (setq data (cdr data)))
6216                         result)
6217                     (car data)))
6218         (goto-char (gnus-data-pos result))
6219         (gnus-data-number result)))))
6220
6221 (defun gnus-summary-find-prev (&optional unread article)
6222   (let* ((eobp (eobp))
6223          (article (or article (gnus-summary-article-number)))
6224          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6225          result)
6226     (when (and (not eobp)
6227                (or (not gnus-summary-check-current)
6228                    (not unread)
6229                    (not (gnus-data-unread-p (car data)))))
6230       (setq data (cdr data)))
6231     (when (setq result
6232                 (if unread
6233                     (progn
6234                       (while data
6235                         (unless (memq (gnus-data-number (car data))
6236                                       (cond
6237                                        ((eq gnus-auto-goto-ignores
6238                                             'always-undownloaded)
6239                                         gnus-newsgroup-undownloaded)
6240                                        (gnus-plugged
6241                                         nil)
6242                                        ((eq gnus-auto-goto-ignores
6243                                             'unfetched)
6244                                         gnus-newsgroup-unfetched)
6245                                        ((eq gnus-auto-goto-ignores
6246                                             'undownloaded)
6247                                         gnus-newsgroup-undownloaded)))
6248                           (when (gnus-data-unread-p (car data))
6249                             (setq result (car data)
6250                                   data nil)))
6251                         (setq data (cdr data)))
6252                       result)
6253                   (car data)))
6254       (goto-char (gnus-data-pos result))
6255       (gnus-data-number result))))
6256
6257 (defun gnus-summary-find-subject (subject &optional unread backward article)
6258   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6259          (article (or article (gnus-summary-article-number)))
6260          (articles (gnus-data-list backward))
6261          (arts (gnus-data-find-list article articles))
6262          result)
6263     (when (or (not gnus-summary-check-current)
6264               (not unread)
6265               (not (gnus-data-unread-p (car arts))))
6266       (setq arts (cdr arts)))
6267     (while arts
6268       (and (or (not unread)
6269                (gnus-data-unread-p (car arts)))
6270            (vectorp (gnus-data-header (car arts)))
6271            (gnus-subject-equal
6272             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6273            (setq result (car arts)
6274                  arts nil))
6275       (setq arts (cdr arts)))
6276     (and result
6277          (goto-char (gnus-data-pos result))
6278          (gnus-data-number result))))
6279
6280 (defun gnus-summary-search-forward (&optional unread subject backward)
6281   "Search forward for an article.
6282 If UNREAD, look for unread articles.  If SUBJECT, look for
6283 articles with that subject.  If BACKWARD, search backward instead."
6284   (cond (subject (gnus-summary-find-subject subject unread backward))
6285         (backward (gnus-summary-find-prev unread))
6286         (t (gnus-summary-find-next unread))))
6287
6288 (defun gnus-recenter (&optional n)
6289   "Center point in window and redisplay frame.
6290 Also do horizontal recentering."
6291   (interactive "P")
6292   (when (and gnus-auto-center-summary
6293              (not (eq gnus-auto-center-summary 'vertical)))
6294     (gnus-horizontal-recenter))
6295   (recenter n))
6296
6297 (defun gnus-summary-recenter ()
6298   "Center point in the summary window.
6299 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6300 displayed, no centering will be performed."
6301   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6302   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6303   (interactive)
6304   ;; The user has to want it.
6305   (when gnus-auto-center-summary
6306     (let* ((top (cond ((< (window-height) 4) 0)
6307                       ((< (window-height) 7) 1)
6308                       (t (if (numberp gnus-auto-center-summary)
6309                              gnus-auto-center-summary
6310                            (/ (1- (window-height)) 2)))))
6311            (height (1- (window-height)))
6312            (bottom (save-excursion (goto-char (point-max))
6313                                    (forward-line (- height))
6314                                    (point)))
6315            (window (get-buffer-window (current-buffer))))
6316       (when (get-buffer-window gnus-article-buffer)
6317         ;; Only do recentering when the article buffer is displayed,
6318         ;; Set the window start to either `bottom', which is the biggest
6319         ;; possible valid number, or the second line from the top,
6320         ;; whichever is the least.
6321         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6322           (if (> bottom top-pos)
6323               ;; Keep the second line from the top visible
6324               (set-window-start window top-pos t)
6325             ;; Try to keep the bottom line visible; if it's partially
6326             ;; obscured, either scroll one more line to make it fully
6327             ;; visible, or revert to using TOP-POS.
6328             (save-excursion
6329               (goto-char (point-max))
6330               (forward-line -1)
6331               (let ((last-line-start (point)))
6332                 (goto-char bottom)
6333                 (set-window-start window (point) t)
6334                 (when (not (pos-visible-in-window-p last-line-start window))
6335                   (forward-line 1)
6336                   (set-window-start window (min (point) top-pos) t)))))))
6337       ;; Do horizontal recentering while we're at it.
6338       (when (and (get-buffer-window (current-buffer) t)
6339                  (not (eq gnus-auto-center-summary 'vertical)))
6340         (let ((selected (selected-window)))
6341           (select-window (get-buffer-window (current-buffer) t))
6342           (gnus-summary-position-point)
6343           (gnus-horizontal-recenter)
6344           (select-window selected))))))
6345
6346 (defun gnus-summary-jump-to-group (newsgroup)
6347   "Move point to NEWSGROUP in group mode buffer."
6348   ;; Keep update point of group mode buffer if visible.
6349   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6350       (save-window-excursion
6351         ;; Take care of tree window mode.
6352         (when (get-buffer-window gnus-group-buffer)
6353           (pop-to-buffer gnus-group-buffer))
6354         (gnus-group-jump-to-group newsgroup))
6355     (save-excursion
6356       ;; Take care of tree window mode.
6357       (if (get-buffer-window gnus-group-buffer)
6358           (pop-to-buffer gnus-group-buffer)
6359         (set-buffer gnus-group-buffer))
6360       (gnus-group-jump-to-group newsgroup))))
6361
6362 ;; This function returns a list of article numbers based on the
6363 ;; difference between the ranges of read articles in this group and
6364 ;; the range of active articles.
6365 (defun gnus-list-of-unread-articles (group)
6366   (let* ((read (gnus-info-read (gnus-get-info group)))
6367          (active (or (gnus-active group) (gnus-activate-group group)))
6368          (last (cdr active))
6369          first nlast unread)
6370     ;; If none are read, then all are unread.
6371     (if (not read)
6372         (setq first (car active))
6373       ;; If the range of read articles is a single range, then the
6374       ;; first unread article is the article after the last read
6375       ;; article.  Sounds logical, doesn't it?
6376       (if (and (not (listp (cdr read)))
6377                (or (< (car read) (car active))
6378                    (progn (setq read (list read))
6379                           nil)))
6380           (setq first (max (car active) (1+ (cdr read))))
6381         ;; `read' is a list of ranges.
6382         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6383                                   (caar read)))
6384                   1)
6385           (setq first (car active)))
6386         (while read
6387           (when first
6388             (while (< first nlast)
6389               (setq unread (cons first unread)
6390                     first (1+ first))))
6391           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6392           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6393           (setq read (cdr read)))))
6394     ;; And add the last unread articles.
6395     (while (<= first last)
6396       (setq unread (cons first unread)
6397             first (1+ first)))
6398     ;; Return the list of unread articles.
6399     (delq 0 (nreverse unread))))
6400
6401 (defun gnus-list-of-read-articles (group)
6402   "Return a list of unread, unticked and non-dormant articles."
6403   (let* ((info (gnus-get-info group))
6404          (marked (gnus-info-marks info))
6405          (active (gnus-active group)))
6406     (and info active
6407          (gnus-list-range-difference
6408           (gnus-list-range-difference
6409            (gnus-sorted-complement
6410             (gnus-uncompress-range active)
6411             (gnus-list-of-unread-articles group))
6412            (cdr (assq 'dormant marked)))
6413           (cdr (assq 'tick marked))))))
6414
6415 ;; This function returns a sequence of article numbers based on the
6416 ;; difference between the ranges of read articles in this group and
6417 ;; the range of active articles.
6418 (defun gnus-sequence-of-unread-articles (group)
6419   (let* ((read (gnus-info-read (gnus-get-info group)))
6420          (active (or (gnus-active group) (gnus-activate-group group)))
6421          (last (cdr active))
6422          first nlast unread)
6423     ;; If none are read, then all are unread.
6424     (if (not read)
6425         (setq first (car active))
6426       ;; If the range of read articles is a single range, then the
6427       ;; first unread article is the article after the last read
6428       ;; article.  Sounds logical, doesn't it?
6429       (if (and (not (listp (cdr read)))
6430                (or (< (car read) (car active))
6431                    (progn (setq read (list read))
6432                           nil)))
6433           (setq first (max (car active) (1+ (cdr read))))
6434         ;; `read' is a list of ranges.
6435         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6436                                   (caar read)))
6437                   1)
6438           (setq first (car active)))
6439         (while read
6440           (when first
6441             (push (cons first nlast) unread))
6442           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6443           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6444           (setq read (cdr read)))))
6445     ;; And add the last unread articles.
6446     (cond ((< first last)
6447            (push (cons first last) unread))
6448           ((= first last)
6449            (push first unread)))
6450     ;; Return the sequence of unread articles.
6451     (delq 0 (nreverse unread))))
6452
6453 ;; Various summary commands
6454
6455 (defun gnus-summary-select-article-buffer ()
6456   "Reconfigure windows to show article buffer."
6457   (interactive)
6458   (if (not (gnus-buffer-live-p gnus-article-buffer))
6459       (error "There is no article buffer for this summary buffer")
6460     (gnus-configure-windows 'article)
6461     (select-window (get-buffer-window gnus-article-buffer))))
6462
6463 (defun gnus-summary-universal-argument (arg)
6464   "Perform any operation on all articles that are process/prefixed."
6465   (interactive "P")
6466   (let ((articles (gnus-summary-work-articles arg))
6467         func article)
6468     (if (eq
6469          (setq
6470           func
6471           (key-binding
6472            (read-key-sequence
6473             (substitute-command-keys
6474              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6475          'undefined)
6476         (gnus-error 1 "Undefined key")
6477       (save-excursion
6478         (while articles
6479           (gnus-summary-goto-subject (setq article (pop articles)))
6480           (let (gnus-newsgroup-processable)
6481             (command-execute func))
6482           (gnus-summary-remove-process-mark article)))))
6483   (gnus-summary-position-point))
6484
6485 (defun gnus-summary-toggle-truncation (&optional arg)
6486   "Toggle truncation of summary lines.
6487 With ARG, turn line truncation on if ARG is positive."
6488   (interactive "P")
6489   (setq truncate-lines
6490         (if (null arg) (not truncate-lines)
6491           (> (prefix-numeric-value arg) 0)))
6492   (redraw-display))
6493
6494 (defun gnus-summary-find-for-reselect ()
6495   "Return the number of an article to stay on across a reselect.
6496 The current article is considered, then following articles, then previous
6497 articles.  An article is sought which is not cancelled and isn't a temporary
6498 insertion from another group.  If there's no such then return a dummy 0."
6499   (let (found)
6500     (dolist (rev '(nil t))
6501       (unless found      ; don't demand the reverse list if we don't need it
6502         (let ((data (gnus-data-find-list
6503                      (gnus-summary-article-number) (gnus-data-list rev))))
6504           (while (and data (not found))
6505             (if (and (< 0 (gnus-data-number (car data)))
6506                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6507                 (setq found (gnus-data-number (car data))))
6508             (setq data (cdr data))))))
6509     (or found 0)))
6510
6511 (defun gnus-summary-reselect-current-group (&optional all rescan)
6512   "Exit and then reselect the current newsgroup.
6513 The prefix argument ALL means to select all articles."
6514   (interactive "P")
6515   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6516     (error "Ephemeral groups can't be reselected"))
6517   (let ((current-subject (gnus-summary-find-for-reselect))
6518         (group gnus-newsgroup-name))
6519     (setq gnus-newsgroup-begin nil)
6520     (gnus-summary-exit nil 'leave-hidden)
6521     ;; We have to adjust the point of group mode buffer because
6522     ;; point was moved to the next unread newsgroup by exiting.
6523     (gnus-summary-jump-to-group group)
6524     (when rescan
6525       (save-excursion
6526         (save-window-excursion
6527           ;; Don't show group contents.
6528           (set-window-start (selected-window) (point-max))
6529           (gnus-group-get-new-news-this-group 1))))
6530     (gnus-group-read-group all t)
6531     (gnus-summary-goto-subject current-subject nil t)))
6532
6533 (defun gnus-summary-rescan-group (&optional all)
6534   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6535   (interactive "P")
6536   (gnus-summary-reselect-current-group all t))
6537
6538 (defun gnus-summary-update-info (&optional non-destructive)
6539   (save-excursion
6540     (let ((group gnus-newsgroup-name))
6541       (when group
6542         (when gnus-newsgroup-kill-headers
6543           (setq gnus-newsgroup-killed
6544                 (gnus-compress-sequence
6545                  (gnus-sorted-union
6546                   (gnus-list-range-intersection
6547                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6548                   gnus-newsgroup-unreads)
6549                  t)))
6550         (unless (listp (cdr gnus-newsgroup-killed))
6551           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6552         (let ((headers gnus-newsgroup-headers))
6553           ;; Set the new ranges of read articles.
6554           (with-current-buffer gnus-group-buffer
6555             (gnus-undo-force-boundary))
6556           (gnus-update-read-articles
6557            group (gnus-sorted-union
6558                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6559           ;; Set the current article marks.
6560           (let ((gnus-newsgroup-scored
6561                  (if (and (not gnus-save-score)
6562                           (not non-destructive))
6563                      nil
6564                    gnus-newsgroup-scored)))
6565             (save-excursion
6566               (gnus-update-marks)))
6567           ;; Do the cross-ref thing.
6568           (when gnus-use-cross-reference
6569             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6570           ;; Do not switch windows but change the buffer to work.
6571           (set-buffer gnus-group-buffer)
6572           (unless (gnus-ephemeral-group-p group)
6573             (gnus-group-update-group group)))))))
6574
6575 (defun gnus-summary-save-newsrc (&optional force)
6576   "Save the current number of read/marked articles in the dribble buffer.
6577 The dribble buffer will then be saved.
6578 If FORCE (the prefix), also save the .newsrc file(s)."
6579   (interactive "P")
6580   (gnus-summary-update-info t)
6581   (if force
6582       (gnus-save-newsrc-file)
6583     (gnus-dribble-save)))
6584
6585 (defun gnus-summary-exit (&optional temporary leave-hidden)
6586   "Exit reading current newsgroup, and then return to group selection mode.
6587 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6588   (interactive)
6589   (gnus-set-global-variables)
6590   (gnus-kill-save-kill-buffer)
6591   (gnus-async-halt-prefetch)
6592   (let* ((group gnus-newsgroup-name)
6593          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6594          (gnus-group-is-exiting-p t)
6595          (mode major-mode)
6596          (group-point nil)
6597          (buf (current-buffer)))
6598     (unless quit-config
6599       ;; Do adaptive scoring, and possibly save score files.
6600       (when gnus-newsgroup-adaptive
6601         (gnus-score-adaptive))
6602       (when gnus-use-scoring
6603         (gnus-score-save)))
6604     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6605     ;; If we have several article buffers, we kill them at exit.
6606     (unless gnus-single-article-buffer
6607       (gnus-kill-buffer gnus-original-article-buffer)
6608       (setq gnus-article-current nil))
6609     (when gnus-use-cache
6610       (gnus-cache-possibly-remove-articles)
6611       (gnus-cache-save-buffers))
6612     (gnus-async-prefetch-remove-group group)
6613     (when gnus-suppress-duplicates
6614       (gnus-dup-enter-articles))
6615     (when gnus-use-trees
6616       (gnus-tree-close group))
6617     (when gnus-use-cache
6618       (gnus-cache-write-active))
6619     ;; Remove entries for this group.
6620     (nnmail-purge-split-history (gnus-group-real-name group))
6621     ;; Make all changes in this group permanent.
6622     (unless quit-config
6623       (gnus-run-hooks 'gnus-exit-group-hook)
6624       (gnus-summary-update-info))
6625     (gnus-close-group group)
6626     ;; Make sure where we were, and go to next newsgroup.
6627     (set-buffer gnus-group-buffer)
6628     (unless quit-config
6629       (gnus-group-jump-to-group group))
6630     (gnus-run-hooks 'gnus-summary-exit-hook)
6631     (unless (or quit-config
6632                 ;; If this group has disappeared from the summary
6633                 ;; buffer, don't skip forwards.
6634                 (not (string= group (gnus-group-group-name))))
6635       (gnus-group-next-unread-group 1))
6636     (setq group-point (point))
6637     (if temporary
6638         nil                             ;Nothing to do.
6639       ;; If we have several article buffers, we kill them at exit.
6640       (unless gnus-single-article-buffer
6641         (gnus-kill-buffer gnus-article-buffer)
6642         (gnus-kill-buffer gnus-original-article-buffer)
6643         (setq gnus-article-current nil))
6644       (set-buffer buf)
6645       (if (not gnus-kill-summary-on-exit)
6646           (progn
6647             (gnus-deaden-summary)
6648             (setq mode nil))
6649         ;; We set all buffer-local variables to nil.  It is unclear why
6650         ;; this is needed, but if we don't, buffer-local variables are
6651         ;; not garbage-collected, it seems.  This would the lead to en
6652         ;; ever-growing Emacs.
6653         (gnus-summary-clear-local-variables)
6654         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6655           (gnus-summary-clear-local-variables))
6656         (when (get-buffer gnus-article-buffer)
6657           (bury-buffer gnus-article-buffer))
6658         ;; We clear the global counterparts of the buffer-local
6659         ;; variables as well, just to be on the safe side.
6660         (set-buffer gnus-group-buffer)
6661         (gnus-summary-clear-local-variables)
6662         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6663           (gnus-summary-clear-local-variables))
6664         ;; Return to group mode buffer.
6665         (when (eq mode 'gnus-summary-mode)
6666           (gnus-kill-buffer buf)))
6667       (setq gnus-current-select-method gnus-select-method)
6668       (if leave-hidden
6669           (set-buffer gnus-group-buffer)
6670         (pop-to-buffer gnus-group-buffer))
6671       (if (not quit-config)
6672           (progn
6673             (goto-char group-point)
6674             (unless leave-hidden
6675               (gnus-configure-windows 'group 'force))
6676             (unless (pos-visible-in-window-p)
6677               (forward-line (/ (static-if (featurep 'xemacs)
6678                                    (window-displayed-height)
6679                                  (1- (window-height)))
6680                                -2))
6681               (set-window-start (selected-window) (point))
6682               (goto-char group-point)))
6683         (gnus-handle-ephemeral-exit quit-config))
6684       ;; Clear the current group name.
6685       (unless quit-config
6686         (setq gnus-newsgroup-name nil)))))
6687
6688 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6689 (defun gnus-summary-exit-no-update (&optional no-questions)
6690   "Quit reading current newsgroup without updating read article info."
6691   (interactive)
6692   (let* ((group gnus-newsgroup-name)
6693          (gnus-group-is-exiting-p t)
6694          (gnus-group-is-exiting-without-update-p t)
6695          (quit-config (gnus-group-quit-config group)))
6696     (when (or no-questions
6697               gnus-expert-user
6698               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6699       (gnus-async-halt-prefetch)
6700       (run-hooks 'gnus-summary-prepare-exit-hook)
6701       ;; If we have several article buffers, we kill them at exit.
6702       (unless gnus-single-article-buffer
6703         (gnus-kill-buffer gnus-article-buffer)
6704         (gnus-kill-buffer gnus-original-article-buffer)
6705         (setq gnus-article-current nil))
6706       (if (not gnus-kill-summary-on-exit)
6707           (gnus-deaden-summary)
6708         (gnus-close-group group)
6709         (gnus-summary-clear-local-variables)
6710         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6711           (gnus-summary-clear-local-variables))
6712         (set-buffer gnus-group-buffer)
6713         (gnus-summary-clear-local-variables)
6714         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6715           (gnus-summary-clear-local-variables))
6716         (gnus-kill-buffer gnus-summary-buffer))
6717       (unless gnus-single-article-buffer
6718         (setq gnus-article-current nil))
6719       (when gnus-use-trees
6720         (gnus-tree-close group))
6721       (gnus-async-prefetch-remove-group group)
6722       (when (get-buffer gnus-article-buffer)
6723         (bury-buffer gnus-article-buffer))
6724       ;; Return to the group buffer.
6725       (gnus-configure-windows 'group 'force)
6726       ;; Clear the current group name.
6727       (setq gnus-newsgroup-name nil)
6728       (unless (gnus-ephemeral-group-p group)
6729         (gnus-group-update-group group))
6730       (when (equal (gnus-group-group-name) group)
6731         (gnus-group-next-unread-group 1))
6732       (when quit-config
6733         (gnus-handle-ephemeral-exit quit-config)))))
6734
6735 (defun gnus-handle-ephemeral-exit (quit-config)
6736   "Handle movement when leaving an ephemeral group.
6737 The state which existed when entering the ephemeral is reset."
6738   (if (not (buffer-name (car quit-config)))
6739       (gnus-configure-windows 'group 'force)
6740     (set-buffer (car quit-config))
6741     (cond ((eq major-mode 'gnus-summary-mode)
6742            (gnus-set-global-variables))
6743           ((eq major-mode 'gnus-article-mode)
6744            (save-excursion
6745              ;; The `gnus-summary-buffer' variable may point
6746              ;; to the old summary buffer when using a single
6747              ;; article buffer.
6748              (unless (gnus-buffer-live-p gnus-summary-buffer)
6749                (set-buffer gnus-group-buffer))
6750              (set-buffer gnus-summary-buffer)
6751              (gnus-set-global-variables))))
6752     (if (or (eq (cdr quit-config) 'article)
6753             (eq (cdr quit-config) 'pick))
6754         (progn
6755           ;; The current article may be from the ephemeral group
6756           ;; thus it is best that we reload this article
6757           ;;
6758           ;; If we're exiting from a large digest, this can be
6759           ;; extremely slow.  So, it's better not to reload it. -- jh.
6760           ;;(gnus-summary-show-article)
6761           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6762               (gnus-configure-windows 'pick 'force)
6763             (gnus-configure-windows (cdr quit-config) 'force)))
6764       (gnus-configure-windows (cdr quit-config) 'force))
6765     (when (eq major-mode 'gnus-summary-mode)
6766       (gnus-summary-next-subject 1 nil t)
6767       (gnus-summary-recenter)
6768       (gnus-summary-position-point))))
6769
6770 (defun gnus-summary-preview-mime-message ()
6771   "MIME decode and play this message."
6772   (interactive)
6773   (let ((gnus-break-pages nil)
6774         (gnus-show-mime t))
6775     (gnus-summary-select-article gnus-show-all-headers t))
6776   (let ((w (get-buffer-window gnus-article-buffer)))
6777     (when w
6778       (select-window (get-buffer-window gnus-article-buffer)))))
6779
6780 ;;; Dead summaries.
6781
6782 (defvar gnus-dead-summary-mode-map nil)
6783
6784 (unless gnus-dead-summary-mode-map
6785   (setq gnus-dead-summary-mode-map (make-keymap))
6786   (suppress-keymap gnus-dead-summary-mode-map)
6787   (substitute-key-definition
6788    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6789   (dolist (key '("\C-d" "\r" "\177" [delete]))
6790     (define-key gnus-dead-summary-mode-map
6791       key 'gnus-summary-wake-up-the-dead))
6792   (dolist (key '("q" "Q"))
6793     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6794
6795 (defvar gnus-dead-summary-mode nil
6796   "Minor mode for Gnus summary buffers.")
6797
6798 (defun gnus-dead-summary-mode (&optional arg)
6799   "Minor mode for Gnus summary buffers."
6800   (interactive "P")
6801   (when (eq major-mode 'gnus-summary-mode)
6802     (make-local-variable 'gnus-dead-summary-mode)
6803     (setq gnus-dead-summary-mode
6804           (if (null arg) (not gnus-dead-summary-mode)
6805             (> (prefix-numeric-value arg) 0)))
6806     (when gnus-dead-summary-mode
6807       (add-minor-mode
6808        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6809
6810 (defun gnus-deaden-summary ()
6811   "Make the current summary buffer into a dead summary buffer."
6812   ;; Kill any previous dead summary buffer.
6813   (when (and gnus-dead-summary
6814              (buffer-name gnus-dead-summary))
6815     (with-current-buffer gnus-dead-summary
6816       (when gnus-dead-summary-mode
6817         (kill-buffer (current-buffer)))))
6818   ;; Make this the current dead summary.
6819   (setq gnus-dead-summary (current-buffer))
6820   (gnus-dead-summary-mode 1)
6821   (let ((name (buffer-name)))
6822     (when (string-match "Summary" name)
6823       (rename-buffer
6824        (concat (substring name 0 (match-beginning 0)) "Dead "
6825                (substring name (match-beginning 0)))
6826        t)
6827       (bury-buffer))))
6828
6829 (defun gnus-kill-or-deaden-summary (buffer)
6830   "Kill or deaden the summary BUFFER."
6831   (save-excursion
6832     (when (and (buffer-name buffer)
6833                (not gnus-single-article-buffer))
6834       (with-current-buffer buffer
6835         (gnus-kill-buffer gnus-article-buffer)
6836         (gnus-kill-buffer gnus-original-article-buffer)))
6837     (cond
6838      ;; Kill the buffer.
6839      (gnus-kill-summary-on-exit
6840       (when (and gnus-use-trees
6841                  (gnus-buffer-exists-p buffer))
6842         (save-excursion
6843           (set-buffer buffer)
6844           (gnus-tree-close gnus-newsgroup-name)))
6845       (gnus-kill-buffer buffer))
6846      ;; Deaden the buffer.
6847      ((gnus-buffer-exists-p buffer)
6848       (save-excursion
6849         (set-buffer buffer)
6850         (gnus-deaden-summary))))))
6851
6852 (defun gnus-summary-wake-up-the-dead (&rest args)
6853   "Wake up the dead summary buffer."
6854   (interactive)
6855   (gnus-dead-summary-mode -1)
6856   (let ((name (buffer-name)))
6857     (when (string-match "Dead " name)
6858       (rename-buffer
6859        (concat (substring name 0 (match-beginning 0))
6860                (substring name (match-end 0)))
6861        t)))
6862   (gnus-message 3 "This dead summary is now alive again"))
6863
6864 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6865 (defun gnus-summary-fetch-faq (&optional faq-dir)
6866   "Fetch the FAQ for the current group.
6867 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6868 in."
6869   (interactive
6870    (list
6871     (when current-prefix-arg
6872       (completing-read
6873        "FAQ dir: " (and (listp gnus-group-faq-directory)
6874                         (mapcar 'list
6875                                 gnus-group-faq-directory))))))
6876   (let (gnus-faq-buffer)
6877     (when (setq gnus-faq-buffer
6878                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6879       (gnus-configure-windows 'summary-faq))))
6880
6881 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6882 (defun gnus-summary-describe-group (&optional force)
6883   "Describe the current newsgroup."
6884   (interactive "P")
6885   (gnus-group-describe-group force gnus-newsgroup-name))
6886
6887 (defun gnus-summary-describe-briefly ()
6888   "Describe summary mode commands briefly."
6889   (interactive)
6890   (gnus-message 6 (substitute-command-keys "\\<gnus-summary-mode-map>\\[gnus-summary-next-page]:Select  \\[gnus-summary-next-unread-article]:Forward  \\[gnus-summary-prev-unread-article]:Backward  \\[gnus-summary-exit]:Exit  \\[gnus-info-find-node]:Run Info        \\[gnus-summary-describe-briefly]:This help")))
6891
6892 ;; Walking around group mode buffer from summary mode.
6893
6894 (defun gnus-summary-next-group (&optional no-article target-group backward)
6895   "Exit current newsgroup and then select next unread newsgroup.
6896 If prefix argument NO-ARTICLE is non-nil, no article is selected
6897 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6898 previous group instead."
6899   (interactive "P")
6900   ;; Stop pre-fetching.
6901   (gnus-async-halt-prefetch)
6902   (let ((current-group gnus-newsgroup-name)
6903         (current-buffer (current-buffer))
6904         entered)
6905     ;; First we semi-exit this group to update Xrefs and all variables.
6906     ;; We can't do a real exit, because the window conf must remain
6907     ;; the same in case the user is prompted for info, and we don't
6908     ;; want the window conf to change before that...
6909     (gnus-summary-exit t)
6910     (while (not entered)
6911       ;; Then we find what group we are supposed to enter.
6912       (set-buffer gnus-group-buffer)
6913       (gnus-group-jump-to-group current-group)
6914       (setq target-group
6915             (or target-group
6916                 (if (eq gnus-keep-same-level 'best)
6917                     (gnus-summary-best-group gnus-newsgroup-name)
6918                   (gnus-summary-search-group backward gnus-keep-same-level))))
6919       (if (not target-group)
6920           ;; There are no further groups, so we return to the group
6921           ;; buffer.
6922           (progn
6923             (gnus-message 5 "Returning to the group buffer")
6924             (setq entered t)
6925             (when (gnus-buffer-live-p current-buffer)
6926               (set-buffer current-buffer)
6927               (gnus-summary-exit))
6928             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6929         ;; We try to enter the target group.
6930         (gnus-group-jump-to-group target-group)
6931         (let ((unreads (gnus-group-group-unread)))
6932           (if (and (or (eq t unreads)
6933                        (and unreads (not (zerop unreads))))
6934                    (gnus-summary-read-group
6935                     target-group nil no-article
6936                     (and (buffer-name current-buffer) current-buffer)
6937                     nil backward))
6938               (setq entered t)
6939             (setq current-group target-group
6940                   target-group nil)))))))
6941
6942 (defun gnus-summary-prev-group (&optional no-article)
6943   "Exit current newsgroup and then select previous unread newsgroup.
6944 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6945   (interactive "P")
6946   (gnus-summary-next-group no-article nil t))
6947
6948 ;; Walking around summary lines.
6949
6950 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6951   "Go to the first subject satisfying any non-nil constraint.
6952 If UNREAD is non-nil, the article should be unread.
6953 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6954 If UNSEEN is non-nil, the article should be unseen.
6955 Returns the article selected or nil if there are no matching articles."
6956   (interactive "P")
6957   (cond
6958    ;; Empty summary.
6959    ((null gnus-newsgroup-data)
6960     (gnus-message 3 "No articles in the group")
6961     nil)
6962    ;; Pick the first article.
6963    ((not (or unread undownloaded unseen))
6964     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6965     (gnus-data-number (car gnus-newsgroup-data)))
6966    ;; Find the first unread article.
6967    (t
6968     (let ((data gnus-newsgroup-data))
6969       (while (and data
6970                   (let ((num (gnus-data-number (car data))))
6971                     (or (memq num gnus-newsgroup-unfetched)
6972                         (not (or (and unread
6973                                       (memq num gnus-newsgroup-unreads))
6974                                  (and undownloaded
6975                                       (memq num gnus-newsgroup-undownloaded))
6976                                  (and unseen
6977                                       (memq num gnus-newsgroup-unseen)))))))
6978         (setq data (cdr data)))
6979       (prog1
6980           (if data
6981               (progn
6982                 (goto-char (gnus-data-pos (car data)))
6983                 (gnus-data-number (car data)))
6984             (gnus-message 3 "No more%s articles"
6985                           (let* ((r (when unread " unread"))
6986                                  (d (when undownloaded " undownloaded"))
6987                                  (s (when unseen " unseen"))
6988                                  (l (delq nil (list r d s))))
6989                             (cond ((= 3 (length l))
6990                                    (concat r "," d ", or" s))
6991                                   ((= 2 (length l))
6992                                    (concat (car l) ", or" (cadr l)))
6993                                   ((= 1 (length l))
6994                                    (car l))
6995                                   (t
6996                                    ""))))
6997             nil
6998             )
6999         (gnus-summary-position-point))))))
7000
7001 (defun gnus-summary-next-subject (n &optional unread dont-display)
7002   "Go to next N'th summary line.
7003 If N is negative, go to the previous N'th subject line.
7004 If UNREAD is non-nil, only unread articles are selected.
7005 The difference between N and the actual number of steps taken is
7006 returned."
7007   (interactive "p")
7008   (let ((backward (< n 0))
7009         (n (abs n)))
7010     (while (and (> n 0)
7011                 (if backward
7012                     (gnus-summary-find-prev unread)
7013                   (gnus-summary-find-next unread)))
7014       (unless (zerop (setq n (1- n)))
7015         (gnus-summary-show-thread)))
7016     (when (/= 0 n)
7017       (gnus-message 7 "No more%s articles"
7018                     (if unread " unread" "")))
7019     (unless dont-display
7020       (gnus-summary-recenter)
7021       (gnus-summary-position-point))
7022     n))
7023
7024 (defun gnus-summary-next-unread-subject (n)
7025   "Go to next N'th unread summary line."
7026   (interactive "p")
7027   (gnus-summary-next-subject n t))
7028
7029 (defun gnus-summary-prev-subject (n &optional unread)
7030   "Go to previous N'th summary line.
7031 If optional argument UNREAD is non-nil, only unread article is selected."
7032   (interactive "p")
7033   (gnus-summary-next-subject (- n) unread))
7034
7035 (defun gnus-summary-prev-unread-subject (n)
7036   "Go to previous N'th unread summary line."
7037   (interactive "p")
7038   (gnus-summary-next-subject (- n) t))
7039
7040 (defun gnus-summary-goto-subjects (articles)
7041   "Insert the subject header for ARTICLES in the current buffer."
7042   (save-excursion
7043     (dolist (article articles)
7044       (gnus-summary-goto-subject article t)))
7045   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7046   (gnus-summary-position-point))
7047  
7048 (defun gnus-summary-goto-subject (article &optional force silent)
7049   "Go the subject line of ARTICLE.
7050 If FORCE, also allow jumping to articles not currently shown."
7051   (interactive "nArticle number: ")
7052   (unless (numberp article)
7053     (error "Article %s is not a number" article))
7054   (let ((b (point))
7055         (data (gnus-data-find article)))
7056     ;; We read in the article if we have to.
7057     (and (not data)
7058          force
7059          (gnus-summary-insert-subject
7060           article
7061           (if (or (numberp force) (vectorp force)) force)
7062           t)
7063          (setq data (gnus-data-find article)))
7064     (goto-char b)
7065     (if (not data)
7066         (progn
7067           (unless silent
7068             (gnus-message 3 "Can't find article %d" article))
7069           nil)
7070       (let ((pt (gnus-data-pos data)))
7071         (goto-char pt)
7072         (gnus-summary-set-article-display-arrow pt))
7073       (gnus-summary-position-point)
7074       article)))
7075
7076 ;; Walking around summary lines with displaying articles.
7077
7078 (defun gnus-summary-expand-window (&optional arg)
7079   "Make the summary buffer take up the entire Emacs frame.
7080 Given a prefix, will force an `article' buffer configuration."
7081   (interactive "P")
7082   (if arg
7083       (gnus-configure-windows 'article 'force)
7084     (gnus-configure-windows 'summary 'force)))
7085
7086 (defun gnus-summary-display-article (article &optional all-header)
7087   "Display ARTICLE in article buffer."
7088   (when (gnus-buffer-live-p gnus-article-buffer)
7089     (with-current-buffer gnus-article-buffer
7090       (set-buffer-multibyte t)))
7091   (gnus-set-global-variables)
7092   (when (gnus-buffer-live-p gnus-article-buffer)
7093     (with-current-buffer gnus-article-buffer
7094       (setq gnus-article-charset gnus-newsgroup-charset)
7095       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7096       (set-buffer-multibyte t)))
7097   (if (null article)
7098       nil
7099     (prog1
7100         (if gnus-summary-display-article-function
7101             (funcall gnus-summary-display-article-function article all-header)
7102           (gnus-article-prepare article all-header))
7103       (with-current-buffer gnus-article-buffer
7104         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7105              nil))
7106       (gnus-run-hooks 'gnus-select-article-hook)
7107       (when (and gnus-current-article
7108                  (not (zerop gnus-current-article)))
7109         (gnus-summary-goto-subject gnus-current-article))
7110       (gnus-summary-recenter)
7111       (when (and gnus-use-trees gnus-show-threads)
7112         (gnus-possibly-generate-tree article)
7113         (gnus-highlight-selected-tree article))
7114       ;; Successfully display article.
7115       (gnus-article-set-window-start
7116        (cdr (assq article gnus-newsgroup-bookmarks))))))
7117
7118 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7119   "Select the current article.
7120 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7121 non-nil, the article will be re-fetched even if it already present in
7122 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7123 be displayed."
7124   ;; Make sure we are in the summary buffer to work around bbdb bug.
7125   (unless (eq major-mode 'gnus-summary-mode)
7126     (set-buffer gnus-summary-buffer))
7127   (let ((article (or article (gnus-summary-article-number)))
7128         (all-headers (not (not all-headers))) ;Must be T or NIL.
7129         gnus-summary-display-article-function)
7130     (and (not pseudo)
7131          (gnus-summary-article-pseudo-p article)
7132          (error "This is a pseudo-article"))
7133     (save-excursion
7134       (set-buffer gnus-summary-buffer)
7135       (if (or (and gnus-single-article-buffer
7136                    (or (null gnus-current-article)
7137                        (null gnus-article-current)
7138                        (null (get-buffer gnus-article-buffer))
7139                        (not (eq article (cdr gnus-article-current)))
7140                        (not (equal (car gnus-article-current)
7141                                    gnus-newsgroup-name))))
7142               (and (not gnus-single-article-buffer)
7143                    (or (null gnus-current-article)
7144                        (not (eq gnus-current-article article))))
7145               force)
7146           ;; The requested article is different from the current article.
7147           (progn
7148             (gnus-summary-display-article article all-headers)
7149             (gnus-article-set-window-start
7150              (cdr (assq article gnus-newsgroup-bookmarks)))
7151             article)
7152         'old))))
7153
7154 (defun gnus-summary-force-verify-and-decrypt ()
7155   "Display buttons for signed/encrypted parts and verify/decrypt them."
7156   (interactive)
7157   (let ((mm-verify-option 'known)
7158         (mm-decrypt-option 'known)
7159         (gnus-article-emulate-mime t)
7160         (gnus-buttonized-mime-types (append (list "multipart/signed"
7161                                                   "multipart/encrypted")
7162                                             gnus-buttonized-mime-types)))
7163     (gnus-summary-select-article nil 'force)))
7164
7165 (defun gnus-summary-set-current-mark (&optional current-mark)
7166   "Obsolete function."
7167   nil)
7168
7169 (defun gnus-summary-next-article (&optional unread subject backward push)
7170   "Select the next article.
7171 If UNREAD, only unread articles are selected.
7172 If SUBJECT, only articles with SUBJECT are selected.
7173 If BACKWARD, the previous article is selected instead of the next."
7174   (interactive "P")
7175   (cond
7176    ;; Is there such an article?
7177    ((and (gnus-summary-search-forward unread subject backward)
7178          (or (gnus-summary-display-article (gnus-summary-article-number))
7179              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7180     (gnus-summary-position-point))
7181    ;; If not, we try the first unread, if that is wanted.
7182    ((and subject
7183          gnus-auto-select-same
7184          (gnus-summary-first-unread-article))
7185     (gnus-summary-position-point)
7186     (gnus-message 6 "Wrapped"))
7187    ;; Try to get next/previous article not displayed in this group.
7188    ((and gnus-auto-extend-newsgroup
7189          (not unread) (not subject))
7190     (gnus-summary-goto-article
7191      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7192      nil (count-lines (point-min) (point))))
7193    ;; Go to next/previous group.
7194    (t
7195     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7196       (gnus-summary-jump-to-group gnus-newsgroup-name))
7197     (let ((cmd last-command-char)
7198           (point
7199            (with-current-buffer gnus-group-buffer
7200              (point)))
7201           (group
7202            (if (eq gnus-keep-same-level 'best)
7203                (gnus-summary-best-group gnus-newsgroup-name)
7204              (gnus-summary-search-group backward gnus-keep-same-level))))
7205       ;; For some reason, the group window gets selected.  We change
7206       ;; it back.
7207       (select-window (get-buffer-window (current-buffer)))
7208       ;; Select next unread newsgroup automagically.
7209       (cond
7210        ((or (not gnus-auto-select-next)
7211             (not cmd))
7212         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7213        ((or (eq gnus-auto-select-next 'quietly)
7214             (and (eq gnus-auto-select-next 'slightly-quietly)
7215                  push)
7216             (and (eq gnus-auto-select-next 'almost-quietly)
7217                  (gnus-summary-last-article-p)))
7218         ;; Select quietly.
7219         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7220             (gnus-summary-exit)
7221           (gnus-message 7 "No more%s articles (%s)..."
7222                         (if unread " unread" "")
7223                         (if group (concat "selecting " group)
7224                           "exiting"))
7225           (gnus-summary-next-group nil group backward)))
7226        (t
7227         (when (gnus-key-press-event-p last-input-event)
7228           (gnus-summary-walk-group-buffer
7229            gnus-newsgroup-name cmd unread backward point))))))))
7230
7231 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7232   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7233                       (?\C-p (gnus-group-prev-unread-group 1))))
7234         (cursor-in-echo-area t)
7235         keve key group ended prompt)
7236     (save-excursion
7237       (set-buffer gnus-group-buffer)
7238       (goto-char start)
7239       (setq group
7240             (if (eq gnus-keep-same-level 'best)
7241                 (gnus-summary-best-group gnus-newsgroup-name)
7242               (gnus-summary-search-group backward gnus-keep-same-level))))
7243     (while (not ended)
7244       (setq prompt
7245             (format
7246              "No more%s articles%s " (if unread " unread" "")
7247              (if (and group
7248                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7249                  (format " (Type %s for %s [%s])"
7250                          (single-key-description cmd) group
7251                          (gnus-group-unread group))
7252                (format " (Type %s to exit %s)"
7253                        (single-key-description cmd)
7254                        gnus-newsgroup-name))))
7255       ;; Confirm auto selection.
7256       (setq key (car (setq keve (gnus-read-event-char prompt)))
7257             ended t)
7258       (cond
7259        ((assq key keystrokes)
7260         (let ((obuf (current-buffer)))
7261           (switch-to-buffer gnus-group-buffer)
7262           (when group
7263             (gnus-group-jump-to-group group))
7264           (eval (cadr (assq key keystrokes)))
7265           (setq group (gnus-group-group-name))
7266           (switch-to-buffer obuf))
7267         (setq ended nil))
7268        ((equal key cmd)
7269         (if (or (not group)
7270                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7271             (gnus-summary-exit)
7272           (gnus-summary-next-group nil group backward)))
7273        (t
7274         (push (cdr keve) unread-command-events))))))
7275
7276 (defun gnus-summary-next-unread-article ()
7277   "Select unread article after current one."
7278   (interactive)
7279   (gnus-summary-next-article
7280    (or (not (eq gnus-summary-goto-unread 'never))
7281        (gnus-summary-last-article-p (gnus-summary-article-number)))
7282    (and gnus-auto-select-same
7283         (gnus-summary-article-subject))))
7284
7285 (defun gnus-summary-prev-article (&optional unread subject)
7286   "Select the article after the current one.
7287 If UNREAD is non-nil, only unread articles are selected."
7288   (interactive "P")
7289   (gnus-summary-next-article unread subject t))
7290
7291 (defun gnus-summary-prev-unread-article ()
7292   "Select unread article before current one."
7293   (interactive)
7294   (gnus-summary-prev-article
7295    (or (not (eq gnus-summary-goto-unread 'never))
7296        (gnus-summary-first-article-p (gnus-summary-article-number)))
7297    (and gnus-auto-select-same
7298         (gnus-summary-article-subject))))
7299
7300 (defun gnus-summary-next-page (&optional lines circular stop)
7301   "Show next page of the selected article.
7302 If at the end of the current article, select the next article.
7303 LINES says how many lines should be scrolled up.
7304
7305 If CIRCULAR is non-nil, go to the start of the article instead of
7306 selecting the next article when reaching the end of the current
7307 article.
7308
7309 If STOP is non-nil, just stop when reaching the end of the message.
7310
7311 Also see the variable `gnus-article-skip-boring'."
7312   (interactive "P")
7313   (setq gnus-summary-buffer (current-buffer))
7314   (gnus-set-global-variables)
7315   (let ((article (gnus-summary-article-number))
7316         (article-window (get-buffer-window gnus-article-buffer t))
7317         endp)
7318     ;; If the buffer is empty, we have no article.
7319     (unless article
7320       (error "No article to select"))
7321     (gnus-configure-windows 'article)
7322     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7323         (if (and (eq gnus-summary-goto-unread 'never)
7324                  (not (gnus-summary-last-article-p article)))
7325             (gnus-summary-next-article)
7326           (gnus-summary-next-unread-article))
7327       (if (or (null gnus-current-article)
7328               (null gnus-article-current)
7329               (/= article (cdr gnus-article-current))
7330               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7331           ;; Selected subject is different from current article's.
7332           (gnus-summary-display-article article)
7333         (when article-window
7334           (gnus-eval-in-buffer-window gnus-article-buffer
7335             (setq endp (or (gnus-article-next-page lines)
7336                            (gnus-article-only-boring-p))))
7337           (when endp
7338             (cond (stop
7339                    (gnus-message 3 "End of message"))
7340                   (circular
7341                    (gnus-summary-beginning-of-article))
7342                   (lines
7343                    (gnus-message 3 "End of message"))
7344                   ((null lines)
7345                    (if (and (eq gnus-summary-goto-unread 'never)
7346                             (not (gnus-summary-last-article-p article)))
7347                        (gnus-summary-next-article)
7348                      (gnus-summary-next-unread-article))))))))
7349     (gnus-summary-recenter)
7350     (gnus-summary-position-point)))
7351
7352 (defun gnus-summary-prev-page (&optional lines move)
7353   "Show previous page of selected article.
7354 Argument LINES specifies lines to be scrolled down.
7355 If MOVE, move to the previous unread article if point is at
7356 the beginning of the buffer."
7357   (interactive "P")
7358   (let ((article (gnus-summary-article-number))
7359         (article-window (get-buffer-window gnus-article-buffer t))
7360         endp)
7361     (gnus-configure-windows 'article)
7362     (if (or (null gnus-current-article)
7363             (null gnus-article-current)
7364             (/= article (cdr gnus-article-current))
7365             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7366         ;; Selected subject is different from current article's.
7367         (gnus-summary-display-article article)
7368       (gnus-summary-recenter)
7369       (when article-window
7370         (gnus-eval-in-buffer-window gnus-article-buffer
7371           (setq endp (gnus-article-prev-page lines)))
7372         (when (and move endp)
7373           (cond (lines
7374                  (gnus-message 3 "Beginning of message"))
7375                 ((null lines)
7376                  (if (and (eq gnus-summary-goto-unread 'never)
7377                           (not (gnus-summary-first-article-p article)))
7378                      (gnus-summary-prev-article)
7379                    (gnus-summary-prev-unread-article))))))))
7380   (gnus-summary-position-point))
7381
7382 (defun gnus-summary-prev-page-or-article (&optional lines)
7383   "Show previous page of selected article.
7384 Argument LINES specifies lines to be scrolled down.
7385 If at the beginning of the article, go to the next article."
7386   (interactive "P")
7387   (gnus-summary-prev-page lines t))
7388
7389 (defun gnus-summary-scroll-up (lines)
7390   "Scroll up (or down) one line current article.
7391 Argument LINES specifies lines to be scrolled up (or down if negative)."
7392   (interactive "p")
7393   (gnus-configure-windows 'article)
7394   (gnus-summary-show-thread)
7395   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7396     (gnus-eval-in-buffer-window gnus-article-buffer
7397       (cond ((> lines 0)
7398              (when (gnus-article-next-page lines)
7399                (gnus-message 3 "End of message")))
7400             ((< lines 0)
7401              (gnus-article-prev-page (- lines))))))
7402   (gnus-summary-recenter)
7403   (gnus-summary-position-point))
7404
7405 (defun gnus-summary-scroll-down (lines)
7406   "Scroll down (or up) one line current article.
7407 Argument LINES specifies lines to be scrolled down (or up if negative)."
7408   (interactive "p")
7409   (gnus-summary-scroll-up (- lines)))
7410
7411 (defun gnus-summary-next-same-subject ()
7412   "Select next article which has the same subject as current one."
7413   (interactive)
7414   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7415
7416 (defun gnus-summary-prev-same-subject ()
7417   "Select previous article which has the same subject as current one."
7418   (interactive)
7419   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7420
7421 (defun gnus-summary-next-unread-same-subject ()
7422   "Select next unread article which has the same subject as current one."
7423   (interactive)
7424   (gnus-summary-next-article t (gnus-summary-article-subject)))
7425
7426 (defun gnus-summary-prev-unread-same-subject ()
7427   "Select previous unread article which has the same subject as current one."
7428   (interactive)
7429   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7430
7431 (defun gnus-summary-first-unread-article ()
7432   "Select the first unread article.
7433 Return nil if there are no unread articles."
7434   (interactive)
7435   (prog1
7436       (when (gnus-summary-first-subject t)
7437         (gnus-summary-show-thread)
7438         (gnus-summary-first-subject t)
7439         (gnus-summary-display-article (gnus-summary-article-number)))
7440     (gnus-summary-position-point)))
7441
7442 (defun gnus-summary-first-unread-subject ()
7443   "Place the point on the subject line of the first unread article.
7444 Return nil if there are no unread articles."
7445   (interactive)
7446   (prog1
7447       (when (gnus-summary-first-subject t)
7448         (gnus-summary-show-thread)
7449         (gnus-summary-first-subject t))
7450     (gnus-summary-position-point)))
7451
7452 (defun gnus-summary-first-unseen-subject ()
7453   "Place the point on the subject line of the first unseen article.
7454 Return nil if there are no unseen articles."
7455   (interactive)
7456   (prog1
7457       (when (gnus-summary-first-subject nil nil t)
7458         (gnus-summary-show-thread)
7459         (gnus-summary-first-subject nil nil t))
7460     (gnus-summary-position-point)))
7461
7462 (defun gnus-summary-first-unseen-or-unread-subject ()
7463   "Place the point on the subject line of the first unseen article or,
7464 if all article have been seen, on the subject line of the first unread
7465 article."
7466   (interactive)
7467   (prog1
7468       (unless (when (gnus-summary-first-subject nil nil t)
7469                 (gnus-summary-show-thread)
7470                 (gnus-summary-first-subject nil nil t))
7471         (when (gnus-summary-first-subject t)
7472           (gnus-summary-show-thread)
7473           (gnus-summary-first-subject t)))
7474     (gnus-summary-position-point)))
7475
7476 (defun gnus-summary-first-article ()
7477   "Select the first article.
7478 Return nil if there are no articles."
7479   (interactive)
7480   (prog1
7481       (when (gnus-summary-first-subject)
7482         (gnus-summary-show-thread)
7483         (gnus-summary-first-subject)
7484         (gnus-summary-display-article (gnus-summary-article-number)))
7485     (gnus-summary-position-point)))
7486
7487 (defun gnus-summary-best-unread-article (&optional arg)
7488   "Select the unread article with the highest score.
7489 If given a prefix argument, select the next unread article that has a
7490 score higher than the default score."
7491   (interactive "P")
7492   (let ((article (if arg
7493                      (gnus-summary-better-unread-subject)
7494                    (gnus-summary-best-unread-subject))))
7495     (if article
7496         (gnus-summary-goto-article article)
7497       (error "No unread articles"))))
7498
7499 (defun gnus-summary-best-unread-subject ()
7500   "Select the unread subject with the highest score."
7501   (interactive)
7502   (let ((best -1000000)
7503         (data gnus-newsgroup-data)
7504         article score)
7505     (while data
7506       (and (gnus-data-unread-p (car data))
7507            (> (setq score
7508                     (gnus-summary-article-score (gnus-data-number (car data))))
7509               best)
7510            (setq best score
7511                  article (gnus-data-number (car data))))
7512       (setq data (cdr data)))
7513     (when article
7514       (gnus-summary-goto-subject article))
7515     (gnus-summary-position-point)
7516     article))
7517
7518 (defun gnus-summary-better-unread-subject ()
7519   "Select the first unread subject that has a score over the default score."
7520   (interactive)
7521   (let ((data gnus-newsgroup-data)
7522         article score)
7523     (while (and (setq article (gnus-data-number (car data)))
7524                 (or (gnus-data-read-p (car data))
7525                     (not (> (gnus-summary-article-score article)
7526                             gnus-summary-default-score))))
7527       (setq data (cdr data)))
7528     (when article
7529       (gnus-summary-goto-subject article))
7530     (gnus-summary-position-point)
7531     article))
7532
7533 (defun gnus-summary-last-subject ()
7534   "Go to the last displayed subject line in the group."
7535   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7536     (when article
7537       (gnus-summary-goto-subject article))))
7538
7539 (defun gnus-summary-goto-article (article &optional all-headers force)
7540   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7541 If ALL-HEADERS is non-nil, no header lines are hidden.
7542 If FORCE, go to the article even if it isn't displayed.  If FORCE
7543 is a number, it is the line the article is to be displayed on."
7544   (interactive
7545    (list
7546     (completing-read
7547      "Article number or Message-ID: "
7548      (mapcar (lambda (number) (list (int-to-string number)))
7549              gnus-newsgroup-limit))
7550     current-prefix-arg
7551     t))
7552   (prog1
7553       (if (and (stringp article)
7554                (string-match "@\\|%40" article))
7555           (gnus-summary-refer-article article)
7556         (when (stringp article)
7557           (setq article (string-to-number article)))
7558         (if (gnus-summary-goto-subject article force)
7559             (gnus-summary-display-article article all-headers)
7560           (gnus-message 4 "Couldn't go to article %s" article) nil))
7561     (gnus-summary-position-point)))
7562
7563 (defun gnus-summary-goto-last-article ()
7564   "Go to the previously read article."
7565   (interactive)
7566   (prog1
7567       (when gnus-last-article
7568         (gnus-summary-goto-article gnus-last-article nil t))
7569     (gnus-summary-position-point)))
7570
7571 (defun gnus-summary-pop-article (number)
7572   "Pop one article off the history and go to the previous.
7573 NUMBER articles will be popped off."
7574   (interactive "p")
7575   (let (to)
7576     (setq gnus-newsgroup-history
7577           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7578     (if to
7579         (gnus-summary-goto-article (car to) nil t)
7580       (error "Article history empty")))
7581   (gnus-summary-position-point))
7582
7583 ;; Summary commands and functions for limiting the summary buffer.
7584
7585 (defun gnus-summary-limit-to-articles (n)
7586   "Limit the summary buffer to the next N articles.
7587 If not given a prefix, use the process marked articles instead."
7588   (interactive "P")
7589   (prog1
7590       (let ((articles (gnus-summary-work-articles n)))
7591         (setq gnus-newsgroup-processable nil)
7592         (gnus-summary-limit articles))
7593     (gnus-summary-position-point)))
7594
7595 (defun gnus-summary-pop-limit (&optional total)
7596   "Restore the previous limit.
7597 If given a prefix, remove all limits."
7598   (interactive "P")
7599   (when total
7600     (setq gnus-newsgroup-limits
7601           (list (mapcar (lambda (h) (mail-header-number h))
7602                         gnus-newsgroup-headers))))
7603   (unless gnus-newsgroup-limits
7604     (error "No limit to pop"))
7605   (prog1
7606       (gnus-summary-limit nil 'pop)
7607     (gnus-summary-position-point)))
7608
7609 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7610   "Limit the summary buffer to articles that have subjects that match a regexp.
7611 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7612   (interactive
7613    (list (read-string (if current-prefix-arg
7614                           "Exclude subject (regexp): "
7615                         "Limit to subject (regexp): "))
7616          nil current-prefix-arg))
7617   (unless header
7618     (setq header "subject"))
7619   (when (not (equal "" subject))
7620     (prog1
7621         (let ((articles (gnus-summary-find-matching
7622                          (or header "subject") subject 'all nil nil
7623                          not-matching)))
7624           (unless articles
7625             (error "Found no matches for \"%s\"" subject))
7626           (gnus-summary-limit articles))
7627       (gnus-summary-position-point))))
7628
7629 (defun gnus-summary-limit-to-author (from &optional not-matching)
7630   "Limit the summary buffer to articles that have authors that match a regexp.
7631 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7632   (interactive
7633    (list (read-string (if current-prefix-arg
7634                           "Exclude author (regexp): "
7635                         "Limit to author (regexp): "))
7636          current-prefix-arg))
7637   (gnus-summary-limit-to-subject from "from" not-matching))
7638
7639 (defun gnus-summary-limit-to-age (age &optional younger-p)
7640   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7641 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7642 articles that are younger than AGE days."
7643   (interactive
7644    (let ((younger current-prefix-arg)
7645          (days-got nil)
7646          days)
7647      (while (not days-got)
7648        (setq days (if younger
7649                       (read-string "Limit to articles younger than (in days, older when negative): ")
7650                     (read-string
7651                      "Limit to articles older than (in days, younger when negative): ")))
7652        (when (> (length days) 0)
7653          (setq days (read days)))
7654        (if (numberp days)
7655            (progn
7656              (setq days-got t)
7657              (when (< days 0)
7658                (setq younger (not younger))
7659                (setq days (* days -1))))
7660          (message "Please enter a number.")
7661          (sleep-for 1)))
7662      (list days younger)))
7663   (prog1
7664       (let ((data gnus-newsgroup-data)
7665             (cutoff (days-to-time age))
7666             articles d date is-younger)
7667         (while (setq d (pop data))
7668           (when (and (vectorp (gnus-data-header d))
7669                      (setq date (mail-header-date (gnus-data-header d))))
7670             (setq is-younger (time-less-p
7671                               (time-since (condition-case ()
7672                                               (date-to-time date)
7673                                             (error '(0 0))))
7674                               cutoff))
7675             (when (if younger-p
7676                       is-younger
7677                     (not is-younger))
7678               (push (gnus-data-number d) articles))))
7679         (gnus-summary-limit (nreverse articles)))
7680     (gnus-summary-position-point)))
7681
7682 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7683   "Limit the summary buffer to articles that match an 'extra' header."
7684   (interactive
7685    (let ((header
7686           (intern
7687            (gnus-completing-read-with-default
7688             (symbol-name (car gnus-extra-headers))
7689             (if current-prefix-arg
7690                 "Exclude extra header:"
7691               "Limit extra header:")
7692             (mapcar (lambda (x)
7693                       (cons (symbol-name x) x))
7694                     gnus-extra-headers)
7695             nil
7696             t))))
7697      (list header
7698            (read-string (format "%s header %s (regexp): "
7699                                 (if current-prefix-arg "Exclude" "Limit to")
7700                                 header))
7701            current-prefix-arg)))
7702   (when (not (equal "" regexp))
7703     (prog1
7704         (let ((articles (gnus-summary-find-matching
7705                          (cons 'extra header) regexp 'all nil nil
7706                          not-matching)))
7707           (unless articles
7708             (error "Found no matches for \"%s\"" regexp))
7709           (gnus-summary-limit articles))
7710       (gnus-summary-position-point))))
7711
7712 (defun gnus-summary-limit-to-display-predicate ()
7713   "Limit the summary buffer to the predicated in the `display' group parameter."
7714   (interactive)
7715   (unless gnus-newsgroup-display
7716     (error "There is no `display' group parameter"))
7717   (let (articles)
7718     (dolist (number gnus-newsgroup-articles)
7719       (when (funcall gnus-newsgroup-display)
7720         (push number articles)))
7721     (gnus-summary-limit articles))
7722   (gnus-summary-position-point))
7723
7724 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7725 (make-obsolete
7726  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7727
7728 (defun gnus-summary-limit-to-unread (&optional all)
7729   "Limit the summary buffer to articles that are not marked as read.
7730 If ALL is non-nil, limit strictly to unread articles."
7731   (interactive "P")
7732   (if all
7733       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7734     (gnus-summary-limit-to-marks
7735      ;; Concat all the marks that say that an article is read and have
7736      ;; those removed.
7737      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7738            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7739            gnus-low-score-mark gnus-expirable-mark
7740            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7741            gnus-duplicate-mark gnus-souped-mark)
7742      'reverse)))
7743
7744 (defun gnus-summary-limit-to-replied (&optional unreplied)
7745   "Limit the summary buffer to replied articles.
7746 If UNREPLIED (the prefix), limit to unreplied articles."
7747   (interactive "P")
7748   (if unreplied
7749       (gnus-summary-limit
7750        (gnus-set-difference gnus-newsgroup-articles
7751         gnus-newsgroup-replied))
7752     (gnus-summary-limit gnus-newsgroup-replied))
7753   (gnus-summary-position-point))
7754
7755 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7756 (make-obsolete 'gnus-summary-delete-marked-with
7757                'gnus-summary-limit-exclude-marks)
7758
7759 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7760   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7761 If REVERSE, limit the summary buffer to articles that are marked
7762 with MARKS.  MARKS can either be a string of marks or a list of marks.
7763 Returns how many articles were removed."
7764   (interactive "sMarks: ")
7765   (gnus-summary-limit-to-marks marks t))
7766
7767 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7768   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7769 If REVERSE (the prefix), limit the summary buffer to articles that are
7770 not marked with MARKS.  MARKS can either be a string of marks or a
7771 list of marks.
7772 Returns how many articles were removed."
7773   (interactive "sMarks: \nP")
7774   (prog1
7775       (let ((data gnus-newsgroup-data)
7776             (marks (if (listp marks) marks
7777                      (append marks nil))) ; Transform to list.
7778             articles)
7779         (while data
7780           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7781                   (memq (gnus-data-mark (car data)) marks))
7782             (push (gnus-data-number (car data)) articles))
7783           (setq data (cdr data)))
7784         (gnus-summary-limit articles))
7785     (gnus-summary-position-point)))
7786
7787 (defun gnus-summary-limit-to-score (score)
7788   "Limit to articles with score at or above SCORE."
7789   (interactive "NLimit to articles with score of at least: ")
7790   (let ((data gnus-newsgroup-data)
7791         articles)
7792     (while data
7793       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7794                 score)
7795         (push (gnus-data-number (car data)) articles))
7796       (setq data (cdr data)))
7797     (prog1
7798         (gnus-summary-limit articles)
7799       (gnus-summary-position-point))))
7800
7801 (defun gnus-summary-limit-to-unseen ()
7802   "Limit to unseen articles."
7803   (interactive)
7804   (prog1
7805       (gnus-summary-limit gnus-newsgroup-unseen)
7806     (gnus-summary-position-point)))
7807
7808 (defun gnus-summary-limit-include-thread (id)
7809   "Display all the hidden articles that is in the thread with ID in it.
7810 When called interactively, ID is the Message-ID of the current
7811 article."
7812   (interactive (list (mail-header-id (gnus-summary-article-header))))
7813   (let ((articles (gnus-articles-in-thread
7814                    (gnus-id-to-thread (gnus-root-id id)))))
7815     (prog1
7816         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7817       (gnus-summary-limit-include-matching-articles
7818        "subject"
7819        (regexp-quote (gnus-simplify-subject-re
7820                       (mail-header-subject (gnus-id-to-header id)))))
7821       (gnus-summary-position-point))))
7822
7823 (defun gnus-summary-limit-include-matching-articles (header regexp)
7824   "Display all the hidden articles that have HEADERs that match REGEXP."
7825   (interactive (list (read-string "Match on header: ")
7826                      (read-string "Regexp: ")))
7827   (let ((articles (gnus-find-matching-articles header regexp)))
7828     (prog1
7829         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7830       (gnus-summary-position-point))))
7831
7832 (defun gnus-summary-insert-dormant-articles ()
7833   "Insert all the dormant articles for this group into the current buffer."
7834   (interactive)
7835   (let ((gnus-verbose (max 6 gnus-verbose)))
7836     (if (not gnus-newsgroup-dormant)
7837         (gnus-message 3 "No cached articles for this group")
7838       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7839
7840 (defun gnus-summary-limit-include-dormant ()
7841   "Display all the hidden articles that are marked as dormant.
7842 Note that this command only works on a subset of the articles currently
7843 fetched for this group."
7844   (interactive)
7845   (unless gnus-newsgroup-dormant
7846     (error "There are no dormant articles in this group"))
7847   (prog1
7848       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7849     (gnus-summary-position-point)))
7850
7851 (defun gnus-summary-limit-exclude-dormant ()
7852   "Hide all dormant articles."
7853   (interactive)
7854   (prog1
7855       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7856     (gnus-summary-position-point)))
7857
7858 (defun gnus-summary-limit-exclude-childless-dormant ()
7859   "Hide all dormant articles that have no children."
7860   (interactive)
7861   (let ((data (gnus-data-list t))
7862         articles d children)
7863     ;; Find all articles that are either not dormant or have
7864     ;; children.
7865     (while (setq d (pop data))
7866       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7867                 (and (setq children
7868                            (gnus-article-children (gnus-data-number d)))
7869                      (let (found)
7870                        (while children
7871                          (when (memq (car children) articles)
7872                            (setq children nil
7873                                  found t))
7874                          (pop children))
7875                        found)))
7876         (push (gnus-data-number d) articles)))
7877     ;; Do the limiting.
7878     (prog1
7879         (gnus-summary-limit articles)
7880       (gnus-summary-position-point))))
7881
7882 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7883   "Mark all unread excluded articles as read.
7884 If ALL, mark even excluded ticked and dormants as read."
7885   (interactive "P")
7886   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7887   (let ((articles (gnus-sorted-ndifference
7888                    (sort
7889                     (mapcar (lambda (h) (mail-header-number h))
7890                             gnus-newsgroup-headers)
7891                     '<)
7892                    gnus-newsgroup-limit))
7893         article)
7894     (setq gnus-newsgroup-unreads
7895           (gnus-sorted-intersection gnus-newsgroup-unreads
7896                                     gnus-newsgroup-limit))
7897     (if all
7898         (setq gnus-newsgroup-dormant nil
7899               gnus-newsgroup-marked nil
7900               gnus-newsgroup-reads
7901               (nconc
7902                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7903                gnus-newsgroup-reads))
7904       (while (setq article (pop articles))
7905         (unless (or (memq article gnus-newsgroup-dormant)
7906                     (memq article gnus-newsgroup-marked))
7907           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7908
7909 (defun gnus-summary-limit (articles &optional pop)
7910   (if pop
7911       ;; We pop the previous limit off the stack and use that.
7912       (setq articles (car gnus-newsgroup-limits)
7913             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7914     ;; We use the new limit, so we push the old limit on the stack.
7915     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7916   ;; Set the limit.
7917   (setq gnus-newsgroup-limit articles)
7918   (let ((total (length gnus-newsgroup-data))
7919         (data (gnus-data-find-list (gnus-summary-article-number)))
7920         (gnus-summary-mark-below nil)   ; Inhibit this.
7921         found)
7922     ;; This will do all the work of generating the new summary buffer
7923     ;; according to the new limit.
7924     (gnus-summary-prepare)
7925     ;; Hide any threads, possibly.
7926     (gnus-summary-maybe-hide-threads)
7927     ;; Try to return to the article you were at, or one in the
7928     ;; neighborhood.
7929     (when data
7930       ;; We try to find some article after the current one.
7931       (while data
7932         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7933           (setq data nil
7934                 found t))
7935         (setq data (cdr data))))
7936     (unless found
7937       ;; If there is no data, that means that we were after the last
7938       ;; article.  The same goes when we can't find any articles
7939       ;; after the current one.
7940       (goto-char (point-max))
7941       (gnus-summary-find-prev))
7942     (gnus-set-mode-line 'summary)
7943     ;; We return how many articles were removed from the summary
7944     ;; buffer as a result of the new limit.
7945     (- total (length gnus-newsgroup-data))))
7946
7947 (defsubst gnus-invisible-cut-children (threads)
7948   (let ((num 0))
7949     (while threads
7950       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7951         (incf num))
7952       (pop threads))
7953     (< num 2)))
7954
7955 (defsubst gnus-cut-thread (thread)
7956   "Go forwards in the thread until we find an article that we want to display."
7957   (when (or (eq gnus-fetch-old-headers 'some)
7958             (eq gnus-fetch-old-headers 'invisible)
7959             (numberp gnus-fetch-old-headers)
7960             (eq gnus-build-sparse-threads 'some)
7961             (eq gnus-build-sparse-threads 'more))
7962     ;; Deal with old-fetched headers and sparse threads.
7963     (while (and
7964             thread
7965             (or
7966              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7967              (gnus-summary-article-ancient-p
7968               (mail-header-number (car thread))))
7969             (if (or (<= (length (cdr thread)) 1)
7970                     (eq gnus-fetch-old-headers 'invisible))
7971                 (setq gnus-newsgroup-limit
7972                       (delq (mail-header-number (car thread))
7973                             gnus-newsgroup-limit)
7974                       thread (cadr thread))
7975               (when (gnus-invisible-cut-children (cdr thread))
7976                 (let ((th (cdr thread)))
7977                   (while th
7978                     (if (memq (mail-header-number (caar th))
7979                               gnus-newsgroup-limit)
7980                         (setq thread (car th)
7981                               th nil)
7982                       (setq th (cdr th))))))))))
7983   thread)
7984
7985 (defun gnus-cut-threads (threads)
7986   "Cut off all uninteresting articles from the beginning of THREADS."
7987   (when (or (eq gnus-fetch-old-headers 'some)
7988             (eq gnus-fetch-old-headers 'invisible)
7989             (numberp gnus-fetch-old-headers)
7990             (eq gnus-build-sparse-threads 'some)
7991             (eq gnus-build-sparse-threads 'more))
7992     (let ((th threads))
7993       (while th
7994         (setcar th (gnus-cut-thread (car th)))
7995         (setq th (cdr th)))))
7996   ;; Remove nixed out threads.
7997   (delq nil threads))
7998
7999 (defun gnus-summary-initial-limit (&optional show-if-empty)
8000   "Figure out what the initial limit is supposed to be on group entry.
8001 This entails weeding out unwanted dormants, low-scored articles,
8002 fetch-old-headers verbiage, and so on."
8003   ;; Most groups have nothing to remove.
8004   (if (or gnus-inhibit-limiting
8005           (and (null gnus-newsgroup-dormant)
8006                (eq gnus-newsgroup-display 'gnus-not-ignore)
8007                (not (eq gnus-fetch-old-headers 'some))
8008                (not (numberp gnus-fetch-old-headers))
8009                (not (eq gnus-fetch-old-headers 'invisible))
8010                (null gnus-summary-expunge-below)
8011                (not (eq gnus-build-sparse-threads 'some))
8012                (not (eq gnus-build-sparse-threads 'more))
8013                (null gnus-thread-expunge-below)
8014                (not gnus-use-nocem)))
8015       ()                                ; Do nothing.
8016     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8017     (setq gnus-newsgroup-limit nil)
8018     (mapatoms
8019      (lambda (node)
8020        (unless (car (symbol-value node))
8021          ;; These threads have no parents -- they are roots.
8022          (let ((nodes (cdr (symbol-value node)))
8023                thread)
8024            (while nodes
8025              (if (and gnus-thread-expunge-below
8026                       (< (gnus-thread-total-score (car nodes))
8027                          gnus-thread-expunge-below))
8028                  (gnus-expunge-thread (pop nodes))
8029                (setq thread (pop nodes))
8030                (gnus-summary-limit-children thread))))))
8031      gnus-newsgroup-dependencies)
8032     ;; If this limitation resulted in an empty group, we might
8033     ;; pop the previous limit and use it instead.
8034     (when (and (not gnus-newsgroup-limit)
8035                show-if-empty)
8036       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8037     gnus-newsgroup-limit))
8038
8039 (defun gnus-summary-limit-children (thread)
8040   "Return 1 if this subthread is visible and 0 if it is not."
8041   ;; First we get the number of visible children to this thread.  This
8042   ;; is done by recursing down the thread using this function, so this
8043   ;; will really go down to a leaf article first, before slowly
8044   ;; working its way up towards the root.
8045   (when thread
8046     (let* ((max-lisp-eval-depth 5000)
8047            (children
8048            (if (cdr thread)
8049                (apply '+ (mapcar 'gnus-summary-limit-children
8050                                  (cdr thread)))
8051              0))
8052           (number (mail-header-number (car thread)))
8053           score)
8054       (if (and
8055            (not (memq number gnus-newsgroup-marked))
8056            (or
8057             ;; If this article is dormant and has absolutely no visible
8058             ;; children, then this article isn't visible.
8059             (and (memq number gnus-newsgroup-dormant)
8060                  (zerop children))
8061             ;; If this is "fetch-old-headered" and there is no
8062             ;; visible children, then we don't want this article.
8063             (and (or (eq gnus-fetch-old-headers 'some)
8064                      (numberp gnus-fetch-old-headers))
8065                  (gnus-summary-article-ancient-p number)
8066                  (zerop children))
8067             ;; If this is "fetch-old-headered" and `invisible', then
8068             ;; we don't want this article.
8069             (and (eq gnus-fetch-old-headers 'invisible)
8070                  (gnus-summary-article-ancient-p number))
8071             ;; If this is a sparsely inserted article with no children,
8072             ;; we don't want it.
8073             (and (eq gnus-build-sparse-threads 'some)
8074                  (gnus-summary-article-sparse-p number)
8075                  (zerop children))
8076             ;; If we use expunging, and this article is really
8077             ;; low-scored, then we don't want this article.
8078             (when (and gnus-summary-expunge-below
8079                        (< (setq score
8080                                 (or (cdr (assq number gnus-newsgroup-scored))
8081                                     gnus-summary-default-score))
8082                           gnus-summary-expunge-below))
8083               ;; We increase the expunge-tally here, but that has
8084               ;; nothing to do with the limits, really.
8085               (incf gnus-newsgroup-expunged-tally)
8086               ;; We also mark as read here, if that's wanted.
8087               (when (and gnus-summary-mark-below
8088                          (< score gnus-summary-mark-below))
8089                 (setq gnus-newsgroup-unreads
8090                       (delq number gnus-newsgroup-unreads))
8091                 (if gnus-newsgroup-auto-expire
8092                     (push number gnus-newsgroup-expirable)
8093                   (push (cons number gnus-low-score-mark)
8094                         gnus-newsgroup-reads)))
8095               t)
8096             ;; Do the `display' group parameter.
8097             (and gnus-newsgroup-display
8098                  (not (funcall gnus-newsgroup-display)))
8099             ;; Check NoCeM things.
8100             (when (and gnus-use-nocem
8101                        (gnus-nocem-unwanted-article-p
8102                         (mail-header-id (car thread))))
8103               (setq gnus-newsgroup-unreads
8104                     (delq number gnus-newsgroup-unreads))
8105               t)))
8106           ;; Nope, invisible article.
8107           0
8108         ;; Ok, this article is to be visible, so we add it to the limit
8109         ;; and return 1.
8110         (push number gnus-newsgroup-limit)
8111         1))))
8112
8113 (defun gnus-expunge-thread (thread)
8114   "Mark all articles in THREAD as read."
8115   (let* ((number (mail-header-number (car thread))))
8116     (incf gnus-newsgroup-expunged-tally)
8117     ;; We also mark as read here, if that's wanted.
8118     (setq gnus-newsgroup-unreads
8119           (delq number gnus-newsgroup-unreads))
8120     (if gnus-newsgroup-auto-expire
8121         (push number gnus-newsgroup-expirable)
8122       (push (cons number gnus-low-score-mark)
8123             gnus-newsgroup-reads)))
8124   ;; Go recursively through all subthreads.
8125   (mapcar 'gnus-expunge-thread (cdr thread)))
8126
8127 ;; Summary article oriented commands
8128
8129 (defun gnus-summary-refer-parent-article (n)
8130   "Refer parent article N times.
8131 If N is negative, go to ancestor -N instead.
8132 The difference between N and the number of articles fetched is returned."
8133   (interactive "p")
8134   (let ((skip 1)
8135         error header ref)
8136     (when (not (natnump n))
8137       (setq skip (abs n)
8138             n 1))
8139     (while (and (> n 0)
8140                 (not error))
8141       (setq header (gnus-summary-article-header))
8142       (if (and (eq (mail-header-number header)
8143                    (cdr gnus-article-current))
8144                (equal gnus-newsgroup-name
8145                       (car gnus-article-current)))
8146           ;; If we try to find the parent of the currently
8147           ;; displayed article, then we take a look at the actual
8148           ;; References header, since this is slightly more
8149           ;; reliable than the References field we got from the
8150           ;; server.
8151           (save-excursion
8152             (set-buffer gnus-original-article-buffer)
8153             (nnheader-narrow-to-headers)
8154             (unless (setq ref (message-fetch-field "references"))
8155               (when (setq ref (message-fetch-field "in-reply-to"))
8156                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8157             (widen))
8158         (setq ref
8159               ;; It's not the current article, so we take a bet on
8160               ;; the value we got from the server.
8161               (mail-header-references header)))
8162       (if (and ref
8163                (not (equal ref "")))
8164           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8165             (gnus-message 1 "Couldn't find parent"))
8166         (gnus-message 1 "No references in article %d"
8167                       (gnus-summary-article-number))
8168         (setq error t))
8169       (decf n))
8170     (gnus-summary-position-point)
8171     n))
8172
8173 (defun gnus-summary-refer-references ()
8174   "Fetch all articles mentioned in the References header.
8175 Return the number of articles fetched."
8176   (interactive)
8177   (let ((ref (mail-header-references (gnus-summary-article-header)))
8178         (current (gnus-summary-article-number))
8179         (n 0))
8180     (if (or (not ref)
8181             (equal ref ""))
8182         (error "No References in the current article")
8183       ;; For each Message-ID in the References header...
8184       (while (string-match "<[^>]*>" ref)
8185         (incf n)
8186         ;; ... fetch that article.
8187         (gnus-summary-refer-article
8188          (prog1 (match-string 0 ref)
8189            (setq ref (substring ref (match-end 0))))))
8190       (gnus-summary-goto-subject current)
8191       (gnus-summary-position-point)
8192       n)))
8193
8194 (defun gnus-summary-refer-thread (&optional limit)
8195   "Fetch all articles in the current thread.
8196 If LIMIT (the numerical prefix), fetch that many old headers instead
8197 of what's specified by the `gnus-refer-thread-limit' variable."
8198   (interactive "P")
8199   (let ((id (mail-header-id (gnus-summary-article-header)))
8200         (limit (if limit (prefix-numeric-value limit)
8201                  gnus-refer-thread-limit)))
8202     (unless (eq gnus-fetch-old-headers 'invisible)
8203       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8204       ;; Retrieve the headers and read them in.
8205       (if (eq (if (numberp limit)
8206                   (gnus-retrieve-headers
8207                    (list (min
8208                           (+ (mail-header-number
8209                               (gnus-summary-article-header))
8210                              limit)
8211                           gnus-newsgroup-end))
8212                    gnus-newsgroup-name (* limit 2))
8213                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8214                 ;; headers.
8215                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8216                                        gnus-newsgroup-name limit))
8217               'nov)
8218           (gnus-build-all-threads)
8219         (error "Can't fetch thread from back ends that don't support NOV"))
8220       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8221     (gnus-summary-limit-include-thread id)))
8222
8223 (defun gnus-summary-refer-article (message-id)
8224   "Fetch an article specified by MESSAGE-ID."
8225   (interactive "sMessage-ID: ")
8226   (when (and (stringp message-id)
8227              (not (zerop (length message-id))))
8228     (setq message-id (gnus-replace-in-string message-id " " ""))
8229     ;; Construct the correct Message-ID if necessary.
8230     ;; Suggested by tale@pawl.rpi.edu.
8231     (unless (string-match "^<" message-id)
8232       (setq message-id (concat "<" message-id)))
8233     (unless (string-match ">$" message-id)
8234       (setq message-id (concat message-id ">")))
8235     ;; People often post MIDs from URLs, so unhex it:
8236     (unless (string-match "@" message-id)
8237       (setq message-id (gnus-url-unhex-string message-id)))
8238     (let* ((header (gnus-id-to-header message-id))
8239            (sparse (and header
8240                         (gnus-summary-article-sparse-p
8241                          (mail-header-number header))
8242                         (memq (mail-header-number header)
8243                               gnus-newsgroup-limit)))
8244            number)
8245       (cond
8246        ;; If the article is present in the buffer we just go to it.
8247        ((and header
8248              (or (not (gnus-summary-article-sparse-p
8249                        (mail-header-number header)))
8250                  sparse))
8251         (prog1
8252             (gnus-summary-goto-article
8253              (mail-header-number header) nil t)
8254           (when sparse
8255             (gnus-summary-update-article (mail-header-number header)))))
8256        (t
8257         ;; We fetch the article.
8258         (catch 'found
8259           (dolist (gnus-override-method (gnus-refer-article-methods))
8260             (when (and (gnus-check-server gnus-override-method)
8261                        ;; Fetch the header,
8262                        (setq number (gnus-summary-insert-subject message-id)))
8263               ;; and display the article.
8264               (gnus-summary-select-article nil nil nil number)
8265               (throw 'found t)))
8266           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8267
8268 (defun gnus-refer-article-methods ()
8269   "Return a list of referable methods."
8270   (cond
8271    ;; No method, so we default to current and native.
8272    ((null gnus-refer-article-method)
8273     (list gnus-current-select-method gnus-select-method))
8274    ;; Current.
8275    ((eq 'current gnus-refer-article-method)
8276     (list gnus-current-select-method))
8277    ;; List of select methods.
8278    ((not (and (symbolp (car gnus-refer-article-method))
8279               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8280     (let (out)
8281       (dolist (method gnus-refer-article-method)
8282         (push (if (eq 'current method)
8283                   gnus-current-select-method
8284                 method)
8285               out))
8286       (nreverse out)))
8287    ;; One single select method.
8288    (t
8289     (list gnus-refer-article-method))))
8290
8291 (defun gnus-summary-edit-parameters ()
8292   "Edit the group parameters of the current group."
8293   (interactive)
8294   (gnus-group-edit-group gnus-newsgroup-name 'params))
8295
8296 (defun gnus-summary-customize-parameters ()
8297   "Customize the group parameters of the current group."
8298   (interactive)
8299   (gnus-group-customize gnus-newsgroup-name))
8300
8301 (defun gnus-summary-enter-digest-group (&optional force)
8302   "Enter an nndoc group based on the current article.
8303 If FORCE, force a digest interpretation.  If not, try
8304 to guess what the document format is."
8305   (interactive "P")
8306   (let ((conf gnus-current-window-configuration))
8307     (save-window-excursion
8308       (save-excursion
8309         (let (gnus-article-prepare-hook
8310               gnus-display-mime-function
8311               gnus-break-pages)
8312           (gnus-summary-select-article))))
8313     (setq gnus-current-window-configuration conf)
8314     (let* ((name (format "%s-%d"
8315                          (gnus-group-prefixed-name
8316                           gnus-newsgroup-name (list 'nndoc ""))
8317                          (with-current-buffer gnus-summary-buffer
8318                            gnus-current-article)))
8319            (ogroup gnus-newsgroup-name)
8320            (params (append (gnus-info-params (gnus-get-info ogroup))
8321                            (list (cons 'to-group ogroup))
8322                            (list (cons 'parent-group ogroup))
8323                            (list (cons 'save-article-group ogroup))))
8324            (case-fold-search t)
8325            (buf (current-buffer))
8326            dig to-address)
8327       (save-excursion
8328         (set-buffer gnus-original-article-buffer)
8329         ;; Have the digest group inherit the main mail address of
8330         ;; the parent article.
8331         (when (setq to-address (or (gnus-fetch-field "reply-to")
8332                                    (gnus-fetch-field "from")))
8333           (setq params (append
8334                         (list (cons 'to-address
8335                                     (funcall gnus-decode-encoded-word-function
8336                                              to-address))))))
8337         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8338         (insert-buffer-substring gnus-original-article-buffer)
8339         ;; Remove lines that may lead nndoc to misinterpret the
8340         ;; document type.
8341         (narrow-to-region
8342          (goto-char (point-min))
8343          (or (search-forward "\n\n" nil t) (point)))
8344         (goto-char (point-min))
8345         (delete-matching-lines "^Path:\\|^From ")
8346         (widen))
8347       (unwind-protect
8348           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8349                     (gnus-newsgroup-ephemeral-ignored-charsets
8350                      gnus-newsgroup-ignored-charsets))
8351                 (gnus-group-read-ephemeral-group
8352                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8353                               (nndoc-article-type
8354                                ,(if force 'mbox 'guess)))
8355                  t nil nil nil
8356                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8357                                                         "ADAPT")))))
8358               ;; Make all postings to this group go to the parent group.
8359               (nconc (gnus-info-params (gnus-get-info name))
8360                      params)
8361             ;; Couldn't select this doc group.
8362             (switch-to-buffer buf)
8363             (gnus-set-global-variables)
8364             (gnus-configure-windows 'summary)
8365             (gnus-message 3 "Article couldn't be entered?"))
8366         (kill-buffer dig)))))
8367
8368 (defun gnus-summary-read-document (n)
8369   "Open a new group based on the current article(s).
8370 This will allow you to read digests and other similar
8371 documents as newsgroups.
8372 Obeys the standard process/prefix convention."
8373   (interactive "P")
8374   (let* ((articles (gnus-summary-work-articles n))
8375          (ogroup gnus-newsgroup-name)
8376          (params (append (gnus-info-params (gnus-get-info ogroup))
8377                          (list (cons 'to-group ogroup))))
8378          article group egroup groups vgroup)
8379     (while (setq article (pop articles))
8380       (setq group (format "%s-%d" gnus-newsgroup-name article))
8381       (gnus-summary-remove-process-mark article)
8382       (when (gnus-summary-display-article article)
8383         (save-excursion
8384           (with-temp-buffer
8385             (insert-buffer-substring gnus-original-article-buffer)
8386             ;; Remove some headers that may lead nndoc to make
8387             ;; the wrong guess.
8388             (message-narrow-to-head)
8389             (goto-char (point-min))
8390             (delete-matching-lines "^Path:\\|^From ")
8391             (widen)
8392             (if (setq egroup
8393                       (gnus-group-read-ephemeral-group
8394                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8395                                      (nndoc-article-type guess))
8396                        t nil t))
8397                 (progn
8398                   ;; Make all postings to this group go to the parent group.
8399                   (nconc (gnus-info-params (gnus-get-info egroup))
8400                          params)
8401                   (push egroup groups))
8402               ;; Couldn't select this doc group.
8403               (gnus-error 3 "Article couldn't be entered"))))))
8404     ;; Now we have selected all the documents.
8405     (cond
8406      ((not groups)
8407       (error "None of the articles could be interpreted as documents"))
8408      ((gnus-group-read-ephemeral-group
8409        (setq vgroup (format
8410                      "nnvirtual:%s-%s" gnus-newsgroup-name
8411                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8412        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8413        t
8414        (cons (current-buffer) 'summary)))
8415      (t
8416       (error "Couldn't select virtual nndoc group")))))
8417
8418 (defun gnus-summary-isearch-article (&optional regexp-p)
8419   "Do incremental search forward on the current article.
8420 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8421   (interactive "P")
8422   (let* ((gnus-inhibit-treatment t)
8423          (old (gnus-summary-select-article)))
8424     (gnus-configure-windows 'article)
8425     (gnus-eval-in-buffer-window gnus-article-buffer
8426       (save-restriction
8427         (widen)
8428         (when (eq 'old old)
8429           (gnus-article-show-all-headers))
8430         (goto-char (point-min))
8431         (isearch-forward regexp-p)))))
8432
8433 (defun gnus-summary-search-article-forward (regexp &optional backward)
8434   "Search for an article containing REGEXP forward.
8435 If BACKWARD, search backward instead."
8436   (interactive
8437    (list (read-string
8438           (format "Search article %s (regexp%s): "
8439                   (if current-prefix-arg "backward" "forward")
8440                   (if gnus-last-search-regexp
8441                       (concat ", default " gnus-last-search-regexp)
8442                     "")))
8443          current-prefix-arg))
8444   (if (string-equal regexp "")
8445       (setq regexp (or gnus-last-search-regexp ""))
8446     (setq gnus-last-search-regexp regexp)
8447     (setq gnus-article-before-search gnus-current-article))
8448   ;; Intentionally set gnus-last-article.
8449   (setq gnus-last-article gnus-article-before-search)
8450   (let ((gnus-last-article gnus-last-article))
8451     (if (gnus-summary-search-article regexp backward)
8452         (gnus-summary-show-thread)
8453       (error "Search failed: \"%s\"" regexp))))
8454
8455 (defun gnus-summary-search-article-backward (regexp)
8456   "Search for an article containing REGEXP backward."
8457   (interactive
8458    (list (read-string
8459           (format "Search article backward (regexp%s): "
8460                   (if gnus-last-search-regexp
8461                       (concat ", default " gnus-last-search-regexp)
8462                     "")))))
8463   (gnus-summary-search-article-forward regexp 'backward))
8464
8465 (eval-when-compile
8466   (defmacro gnus-summary-search-article-position-point (regexp backward)
8467     "Dehighlight the last matched text and goto the beginning position."
8468     (` (if (and gnus-summary-search-article-matched-data
8469                 (let ((text (caddr gnus-summary-search-article-matched-data))
8470                       (inhibit-read-only t)
8471                       buffer-read-only)
8472                   (delete-region
8473                    (goto-char (car gnus-summary-search-article-matched-data))
8474                    (cadr gnus-summary-search-article-matched-data))
8475                   (insert text)
8476                   (string-match (, regexp) text)))
8477            (if (, backward) (beginning-of-line) (end-of-line))
8478          (goto-char (if (, backward) (point-max) (point-min))))))
8479
8480   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8481     "Place point where X-Face image is displayed."
8482     (if (featurep 'xemacs)
8483         (` (let ((end (if (search-forward "\n\n" nil t)
8484                           (goto-char (1- (point)))
8485                         (point-min)))
8486                  extent)
8487              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8488              (unless (and (re-search-forward "^From:" end t)
8489                           (setq extent (extent-at (point)))
8490                           (extent-begin-glyph extent))
8491                (goto-char (, opoint)))))
8492       (` (let ((end (if (search-forward "\n\n" nil t)
8493                         (goto-char (1- (point)))
8494                       (point-min)))
8495                (start (or (search-backward "\n\n" nil t) (point-min))))
8496            (goto-char
8497             (or (text-property-any start end 'x-face-image t);; x-face-e21
8498                 (text-property-any start end 'x-face-mule-bitmap-image t)
8499                 (, opoint)))))))
8500
8501   (defmacro gnus-summary-search-article-highlight-matched-text
8502     (backward treated x-face)
8503     "Highlight matched text in the function `gnus-summary-search-article'."
8504     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8505              (end (set-marker (make-marker) (match-end 0)))
8506              (inhibit-read-only t)
8507              buffer-read-only)
8508          (unless treated
8509            (let ((,@
8510                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8511                     (mapcar
8512                      (lambda (item) (setq items (delq item items)))
8513                      '(gnus-treat-buttonize
8514                        gnus-treat-fill-article
8515                        gnus-treat-fill-long-lines
8516                        gnus-treat-emphasize
8517                        gnus-treat-highlight-headers
8518                        gnus-treat-highlight-citation
8519                        gnus-treat-highlight-signature
8520                        gnus-treat-overstrike
8521                        gnus-treat-display-x-face
8522                        gnus-treat-buttonize-head
8523                        gnus-treat-decode-article-as-default-mime-charset))
8524                     (static-if (featurep 'xemacs)
8525                         items
8526                       (cons '(x-face-mule-delete-x-face-field
8527                               (quote never))
8528                             items))))
8529                  (gnus-treat-display-x-face
8530                   (when (, x-face) gnus-treat-display-x-face)))
8531              (gnus-article-prepare-mime-display)))
8532          (goto-char (if (, backward) start end))
8533          (when (, x-face)
8534            (gnus-summary-search-article-highlight-goto-x-face (point)))
8535          (setq gnus-summary-search-article-matched-data
8536                (list start end (buffer-substring start end)))
8537          (unless (eq start end);; matched text has been deleted. :-<
8538            (put-text-property start end 'face
8539                               (or (find-face 'isearch)
8540                                   'secondary-selection))))))
8541   )
8542
8543 (defun gnus-summary-search-article (regexp &optional backward)
8544   "Search for an article containing REGEXP.
8545 Optional argument BACKWARD means do search for backward.
8546 `gnus-select-article-hook' is not called during the search."
8547   ;; We have to require this here to make sure that the following
8548   ;; dynamic binding isn't shadowed by autoloading.
8549   (require 'gnus-async)
8550   (require 'gnus-art)
8551   (let ((gnus-select-article-hook nil)  ;Disable hook.
8552         (gnus-article-prepare-hook nil)
8553         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8554         (gnus-use-article-prefetch nil)
8555         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8556         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8557         (gnus-visual nil)
8558         (gnus-keep-backlog nil)
8559         (gnus-break-pages nil)
8560         (gnus-summary-display-arrow nil)
8561         (gnus-updated-mode-lines nil)
8562         (gnus-auto-center-summary nil)
8563         (sum (current-buffer))
8564         (found nil)
8565         point treated)
8566     (gnus-save-hidden-threads
8567       (static-if (featurep 'xemacs)
8568           (let ((gnus-inhibit-treatment t))
8569             (setq treated (eq 'old (gnus-summary-select-article)))
8570             (when (and treated
8571                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8572                                  (window-live-p (get-buffer-window
8573                                                  gnus-article-buffer t)))))
8574               (gnus-summary-select-article nil t)
8575               (setq treated nil)))
8576         (let ((gnus-inhibit-treatment t)
8577               (x-face-mule-delete-x-face-field 'never))
8578           (setq treated (eq 'old (gnus-summary-select-article)))
8579           (when (and treated
8580                      (not
8581                       (and (gnus-buffer-live-p gnus-article-buffer)
8582                            (window-live-p (get-buffer-window
8583                                            gnus-article-buffer t))
8584                            (or (not (string-match "^\\^X-Face:" regexp))
8585                                (with-current-buffer gnus-article-buffer
8586                                  gnus-summary-search-article-matched-data)))))
8587             (gnus-summary-select-article nil t)
8588             (setq treated nil))))
8589       (set-buffer gnus-article-buffer)
8590       (widen)
8591       (if treated
8592           (progn
8593             (gnus-article-show-all-headers)
8594             (gnus-summary-search-article-position-point regexp backward))
8595         (goto-char (if backward (point-max) (point-min))))
8596       (while (not found)
8597         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8598         (if (if backward
8599                 (re-search-backward regexp nil t)
8600               (re-search-forward regexp nil t))
8601             ;; We found the regexp.
8602             (progn
8603               (gnus-summary-search-article-highlight-matched-text
8604                backward treated (string-match "^\\^X-Face:" regexp))
8605               (setq found 'found)
8606               (forward-line
8607                (/ (- 2 (window-height
8608                         (get-buffer-window gnus-article-buffer t)))
8609                   2))
8610               (set-window-start
8611                (get-buffer-window (current-buffer))
8612                (point))
8613               (set-buffer sum)
8614               (setq point (point)))
8615           ;; We didn't find it, so we go to the next article.
8616           (set-buffer sum)
8617           (setq found 'not)
8618           (while (eq found 'not)
8619             (if (not (if backward (gnus-summary-find-prev)
8620                        (gnus-summary-find-next)))
8621                 ;; No more articles.
8622                 (setq found t)
8623               ;; Select the next article and adjust point.
8624               (unless (gnus-summary-article-sparse-p
8625                        (gnus-summary-article-number))
8626                 (setq found nil)
8627                 (let ((gnus-inhibit-treatment t))
8628                   (gnus-summary-select-article))
8629                 (setq treated nil)
8630                 (set-buffer gnus-article-buffer)
8631                 (widen)
8632                 (goto-char (if backward (point-max) (point-min))))))))
8633       (gnus-message 7 ""))
8634     ;; Return whether we found the regexp.
8635     (when (eq found 'found)
8636       (goto-char point)
8637       (gnus-summary-show-thread)
8638       (gnus-summary-goto-subject gnus-current-article)
8639       (gnus-summary-position-point)
8640       t)))
8641
8642 (defun gnus-find-matching-articles (header regexp)
8643   "Return a list of all articles that match REGEXP on HEADER.
8644 This search includes all articles in the current group that Gnus has
8645 fetched headers for, whether they are displayed or not."
8646   (let ((articles nil)
8647         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8648         (case-fold-search t))
8649     (dolist (header gnus-newsgroup-headers)
8650       (when (string-match regexp (funcall func header))
8651         (push (mail-header-number header) articles)))
8652     (nreverse articles)))
8653
8654 (defun gnus-summary-find-matching (header regexp &optional backward unread
8655                                           not-case-fold not-matching)
8656   "Return a list of all articles that match REGEXP on HEADER.
8657 The search stars on the current article and goes forwards unless
8658 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8659 If UNREAD is non-nil, only unread articles will
8660 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8661 in the comparisons. If NOT-MATCHING, return a list of all articles that
8662 not match REGEXP on HEADER."
8663   (let ((case-fold-search (not not-case-fold))
8664         articles d func)
8665     (if (consp header)
8666         (if (eq (car header) 'extra)
8667             (setq func
8668                   `(lambda (h)
8669                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8670                          "")))
8671           (error "%s is an invalid header" header))
8672       (unless (fboundp (intern (concat "mail-header-" header)))
8673         (error "%s is not a valid header" header))
8674       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8675     (dolist (d (if (eq backward 'all)
8676                    gnus-newsgroup-data
8677                  (gnus-data-find-list
8678                   (gnus-summary-article-number)
8679                   (gnus-data-list backward))))
8680       (when (and (or (not unread)       ; We want all articles...
8681                      (gnus-data-unread-p d)) ; Or just unreads.
8682                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8683                  (if not-matching
8684                      (not (string-match
8685                            regexp
8686                            (funcall func (gnus-data-header d))))
8687                    (string-match regexp
8688                                  (funcall func (gnus-data-header d)))))
8689         (push (gnus-data-number d) articles))) ; Success!
8690     (nreverse articles)))
8691
8692 (defun gnus-summary-execute-command (header regexp command &optional backward)
8693   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8694 If HEADER is an empty string (or nil), the match is done on the entire
8695 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8696   (interactive
8697    (list (let ((completion-ignore-case t))
8698            (completing-read
8699             "Header name: "
8700             (mapcar (lambda (header) (list (format "%s" header)))
8701                     (append
8702                      '("Number" "Subject" "From" "Lines" "Date"
8703                        "Message-ID" "Xref" "References" "Body")
8704                      gnus-extra-headers))
8705             nil 'require-match))
8706          (read-string "Regexp: ")
8707          (read-key-sequence "Command: ")
8708          current-prefix-arg))
8709   (when (equal header "Body")
8710     (setq header ""))
8711   ;; Hidden thread subtrees must be searched as well.
8712   (gnus-summary-show-all-threads)
8713   ;; We don't want to change current point nor window configuration.
8714   (save-excursion
8715     (save-window-excursion
8716       (let (gnus-visual
8717             gnus-treat-strip-trailing-blank-lines
8718             gnus-treat-strip-leading-blank-lines
8719             gnus-treat-strip-multiple-blank-lines
8720             gnus-treat-hide-boring-headers
8721             gnus-treat-fold-newsgroups
8722             gnus-article-prepare-hook)
8723         (gnus-message 6 "Executing %s..." (key-description command))
8724         ;; We'd like to execute COMMAND interactively so as to give arguments.
8725         (gnus-execute header regexp
8726                       `(call-interactively ',(key-binding command))
8727                       backward)
8728         (gnus-message 6 "Executing %s...done" (key-description command))))))
8729
8730 (defun gnus-summary-beginning-of-article ()
8731   "Scroll the article back to the beginning."
8732   (interactive)
8733   (gnus-summary-select-article)
8734   (gnus-configure-windows 'article)
8735   (gnus-eval-in-buffer-window gnus-article-buffer
8736     (widen)
8737     (goto-char (point-min))
8738     (when gnus-break-pages
8739       (gnus-narrow-to-page))))
8740
8741 (defun gnus-summary-end-of-article ()
8742   "Scroll to the end of the article."
8743   (interactive)
8744   (gnus-summary-select-article)
8745   (gnus-configure-windows 'article)
8746   (gnus-eval-in-buffer-window gnus-article-buffer
8747     (widen)
8748     (goto-char (point-max))
8749     (recenter -3)
8750     (when gnus-break-pages
8751       (when (re-search-backward page-delimiter nil t)
8752         (narrow-to-region (match-end 0) (point-max)))
8753       (gnus-narrow-to-page))))
8754
8755 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8756   "Truncate to LEN and quote all \"(\"'s in STRING."
8757   (gnus-replace-in-string (if (and len (> (length string) len))
8758                               (substring string 0 len)
8759                             string)
8760                           "[()]" "\\\\\\&"))
8761
8762 (defun gnus-summary-print-article (&optional filename n)
8763   "Generate and print a PostScript image of the process-marked (mail) articles.
8764
8765 If used interactively, print the current article if none are
8766 process-marked.  With prefix arg, prompt the user for the name of the
8767 file to save in.
8768
8769 When used from Lisp, accept two optional args FILENAME and N.  N means
8770 to print the next N articles.  If N is negative, print the N previous
8771 articles.  If N is nil and articles have been marked with the process
8772 mark, print these instead.
8773
8774 If the optional first argument FILENAME is nil, send the image to the
8775 printer.  If FILENAME is a string, save the PostScript image in a file with
8776 that name.  If FILENAME is a number, prompt the user for the name of the file
8777 to save in."
8778   (interactive (list (ps-print-preprint current-prefix-arg)))
8779   (dolist (article (gnus-summary-work-articles n))
8780     (gnus-summary-select-article nil nil 'pseudo article)
8781     (gnus-eval-in-buffer-window gnus-article-buffer
8782       (gnus-print-buffer))
8783     (gnus-summary-remove-process-mark article))
8784   (ps-despool filename))
8785
8786 (defun gnus-print-buffer ()
8787   (let ((buffer (generate-new-buffer " *print*")))
8788     (unwind-protect
8789         (progn
8790           (copy-to-buffer buffer (point-min) (point-max))
8791           (set-buffer buffer)
8792           (gnus-remove-text-with-property 'gnus-decoration)
8793           (when (gnus-visual-p 'article-highlight 'highlight)
8794             ;; Copy-to-buffer doesn't copy overlay.  So redo
8795             ;; highlight.
8796             (let ((gnus-article-buffer buffer))
8797               (gnus-article-highlight-citation t)
8798               (gnus-article-highlight-signature)
8799               (gnus-article-emphasize)
8800               (gnus-article-delete-invisible-text)))
8801           (let ((ps-left-header
8802                  (list
8803                   (concat "("
8804                           (gnus-summary-print-truncate-and-quote
8805                            (mail-header-subject gnus-current-headers)
8806                            66) ")")
8807                   (concat "("
8808                           (gnus-summary-print-truncate-and-quote
8809                            (mail-header-from gnus-current-headers)
8810                            45) ")")))
8811                 (ps-right-header
8812                  (list
8813                   "/pagenumberstring load"
8814                   (concat "("
8815                           (mail-header-date gnus-current-headers) ")"))))
8816             (gnus-run-hooks 'gnus-ps-print-hook)
8817             (save-excursion
8818               (if window-system
8819                   (ps-spool-buffer-with-faces)
8820                 (ps-spool-buffer)))))
8821       (kill-buffer buffer))))
8822
8823 (defun gnus-summary-show-article (&optional arg)
8824   "Force redisplaying of the current article.
8825 If ARG (the prefix) is a number, show the article with the charset
8826 defined in `gnus-summary-show-article-charset-alist', or the charset
8827 input.
8828 If ARG (the prefix) is non-nil and not a number, show the raw article
8829 without any article massaging functions being run.  Normally, the key
8830 strokes are `C-u g'."
8831   (interactive "P")
8832   (cond
8833    ((numberp arg)
8834     (gnus-summary-show-article t)
8835     (let* ((gnus-newsgroup-charset
8836             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8837                 (mm-read-coding-system
8838                  "View as charset: " ;; actually it is coding system.
8839                  (save-excursion
8840                    (set-buffer gnus-article-buffer)
8841                    (mm-detect-coding-region (point) (point-max))))))
8842            (default-mime-charset gnus-newsgroup-charset)
8843            (gnus-newsgroup-ignored-charsets 'gnus-all))
8844       (gnus-summary-select-article nil 'force)
8845       (let ((deps gnus-newsgroup-dependencies)
8846             head header lines)
8847         (save-excursion
8848           (set-buffer gnus-original-article-buffer)
8849           (save-restriction
8850             (message-narrow-to-head)
8851             (setq head (buffer-string))
8852             (goto-char (point-min))
8853             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8854               (goto-char (point-max))
8855               (widen)
8856               (setq lines (1- (count-lines (point) (point-max))))))
8857           (with-temp-buffer
8858             (insert (format "211 %d Article retrieved.\n"
8859                             (cdr gnus-article-current)))
8860             (insert head)
8861             (if lines (insert (format "Lines: %d\n" lines)))
8862             (insert ".\n")
8863             (let ((nntp-server-buffer (current-buffer)))
8864               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8865         (gnus-data-set-header
8866          (gnus-data-find (cdr gnus-article-current))
8867          header)
8868         (gnus-summary-update-article-line
8869          (cdr gnus-article-current) header)
8870         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8871           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8872    ((not arg)
8873     ;; Select the article the normal way.
8874     (gnus-summary-select-article nil 'force))
8875    (t
8876     ;; We have to require this here to make sure that the following
8877     ;; dynamic binding isn't shadowed by autoloading.
8878     (require 'gnus-async)
8879     (require 'gnus-art)
8880     ;; Bind the article treatment functions to nil.
8881     (let ((gnus-have-all-headers t)
8882           gnus-article-prepare-hook
8883           gnus-article-decode-hook
8884           gnus-break-pages
8885           gnus-show-mime
8886           (gnus-inhibit-treatment t))
8887       (gnus-summary-select-article nil 'force))))
8888   (gnus-summary-goto-subject gnus-current-article)
8889   (gnus-summary-position-point))
8890
8891 (defun gnus-summary-show-raw-article ()
8892   "Show the raw article without any article massaging functions being run."
8893   (interactive)
8894   (gnus-summary-show-article t))
8895
8896 (defun gnus-summary-verbose-headers (&optional arg)
8897   "Toggle permanent full header display.
8898 If ARG is a positive number, turn header display on.
8899 If ARG is a negative number, turn header display off."
8900   (interactive "P")
8901   (setq gnus-show-all-headers
8902         (cond ((or (not (numberp arg))
8903                    (zerop arg))
8904                (not gnus-show-all-headers))
8905               ((natnump arg)
8906                t)))
8907   (gnus-summary-show-article))
8908
8909 (defun gnus-summary-toggle-header (&optional arg)
8910   "Show the headers if they are hidden, or hide them if they are shown.
8911 If ARG is a positive number, show the entire header.
8912 If ARG is a negative number, hide the unwanted header lines."
8913   (interactive "P")
8914   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8915                      (get-buffer-window gnus-article-buffer t))))
8916     (with-current-buffer gnus-article-buffer
8917       (widen)
8918       (article-narrow-to-head)
8919       (let* ((buffer-read-only nil)
8920              (inhibit-point-motion-hooks t)
8921              (hidden (if (numberp arg)
8922                          (>= arg 0)
8923                        (gnus-article-hidden-text-p 'headers)))
8924              s e)
8925         (delete-region (point-min) (point-max))
8926         (with-current-buffer gnus-original-article-buffer
8927           (goto-char (setq s (point-min)))
8928           (setq e (if (search-forward "\n\n" nil t)
8929                       (1- (point))
8930                     (point-max))))
8931         (insert-buffer-substring gnus-original-article-buffer s e)
8932         ;; In T-gnus, gnus-article-decode-hook doesn't contain
8933         ;; article-decode-encoded-words by default.
8934         (article-decode-encoded-words)
8935         (run-hooks 'gnus-article-decode-hook)
8936         (if hidden
8937             (let ((gnus-treat-hide-headers nil)
8938                   (gnus-treat-hide-boring-headers nil))
8939               (gnus-delete-wash-type 'headers)
8940               (gnus-treat-article 'head))
8941           (gnus-treat-article 'head))
8942         (widen)
8943         (if window
8944             (set-window-start window (goto-char (point-min))))
8945         (if gnus-break-pages
8946             (gnus-narrow-to-page)
8947           (when (gnus-visual-p 'page-marker)
8948             (let ((buffer-read-only nil))
8949               (gnus-remove-text-with-property 'gnus-prev)
8950               (gnus-remove-text-with-property 'gnus-next))))
8951         (gnus-set-mode-line 'article)))))
8952
8953 (defun gnus-summary-show-all-headers ()
8954   "Make all header lines visible."
8955   (interactive)
8956   (gnus-summary-toggle-header 1))
8957
8958 (defun gnus-summary-toggle-mime (&optional arg)
8959   "Toggle MIME processing.
8960 If ARG is a positive number, turn MIME processing on."
8961   (interactive "P")
8962   (setq gnus-show-mime
8963         (if (null arg)
8964             (not gnus-show-mime)
8965           (> (prefix-numeric-value arg) 0)))
8966   (gnus-summary-select-article t 'force))
8967
8968 (defun gnus-summary-caesar-message (&optional arg)
8969   "Caesar rotate the current article by 13.
8970 The numerical prefix specifies how many places to rotate each letter
8971 forward."
8972   (interactive "P")
8973   (gnus-summary-select-article)
8974   (let ((mail-header-separator ""))
8975     (gnus-eval-in-buffer-window gnus-article-buffer
8976       (save-restriction
8977         (widen)
8978         (let ((start (window-start))
8979               buffer-read-only)
8980           (message-caesar-buffer-body arg)
8981           (set-window-start (get-buffer-window (current-buffer)) start))))))
8982
8983 (autoload 'unmorse-region "morse"
8984   "Convert morse coded text in region to ordinary ASCII text."
8985   t)
8986
8987 (defun gnus-summary-morse-message (&optional arg)
8988   "Morse decode the current article."
8989   (interactive "P")
8990   (gnus-summary-select-article)
8991   (let ((mail-header-separator ""))
8992     (gnus-eval-in-buffer-window gnus-article-buffer
8993       (save-excursion
8994         (save-restriction
8995           (widen)
8996           (let ((pos (window-start))
8997                 buffer-read-only)
8998             (goto-char (point-min))
8999             (when (message-goto-body)
9000               (gnus-narrow-to-body))
9001             (goto-char (point-min))
9002             (while (re-search-forward "·" (point-max) t)
9003               (replace-match "."))
9004             (unmorse-region (point-min) (point-max))
9005             (widen)
9006             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9007
9008 (defun gnus-summary-stop-page-breaking ()
9009   "Stop page breaking in the current article."
9010   (interactive)
9011   (gnus-summary-select-article)
9012   (gnus-eval-in-buffer-window gnus-article-buffer
9013     (widen)
9014     (when (gnus-visual-p 'page-marker)
9015       (let ((buffer-read-only nil))
9016         (gnus-remove-text-with-property 'gnus-prev)
9017         (gnus-remove-text-with-property 'gnus-next))
9018       (setq gnus-page-broken nil))))
9019
9020 (defun gnus-summary-move-article (&optional n to-newsgroup
9021                                             select-method action)
9022   "Move the current article to a different newsgroup.
9023 If N is a positive number, move the N next articles.
9024 If N is a negative number, move the N previous articles.
9025 If N is nil and any articles have been marked with the process mark,
9026 move those articles instead.
9027 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9028 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9029 re-spool using this method.
9030
9031 When called interactively with TO-NEWSGROUP being nil, the value of
9032 the variable `gnus-move-split-methods' is used for finding a default
9033 for the target newsgroup.
9034
9035 For this function to work, both the current newsgroup and the
9036 newsgroup that you want to move to have to support the `request-move'
9037 and `request-accept' functions.
9038
9039 ACTION can be either `move' (the default), `crosspost' or `copy'."
9040   (interactive "P")
9041   (unless action
9042     (setq action 'move))
9043   ;; Check whether the source group supports the required functions.
9044   (cond ((and (eq action 'move)
9045               (not (gnus-check-backend-function
9046                     'request-move-article gnus-newsgroup-name)))
9047          (error "The current group does not support article moving"))
9048         ((and (eq action 'crosspost)
9049               (not (gnus-check-backend-function
9050                     'request-replace-article gnus-newsgroup-name)))
9051          (error "The current group does not support article editing")))
9052   (let ((articles (gnus-summary-work-articles n))
9053         (prefix (if (gnus-check-backend-function
9054                      'request-move-article gnus-newsgroup-name)
9055                     (funcall gnus-move-group-prefix-function
9056                              gnus-newsgroup-name)
9057                   ""))
9058         (names '((move "Move" "Moving")
9059                  (copy "Copy" "Copying")
9060                  (crosspost "Crosspost" "Crossposting")))
9061         (copy-buf (save-excursion
9062                     (nnheader-set-temp-buffer " *copy article*")))
9063         art-group to-method new-xref article to-groups)
9064     (unless (assq action names)
9065       (error "Unknown action %s" action))
9066     ;; Read the newsgroup name.
9067     (when (and (not to-newsgroup)
9068                (not select-method))
9069       (if (and gnus-move-split-methods
9070                (not
9071                 (and (memq gnus-current-article articles)
9072                      (gnus-buffer-live-p gnus-original-article-buffer))))
9073           ;; When `gnus-move-split-methods' is non-nil, we have to
9074           ;; select an article to give `gnus-read-move-group-name' an
9075           ;; opportunity to suggest an appropriate default.  However,
9076           ;; we needn't render or mark the article.
9077           (let ((gnus-display-mime-function nil)
9078                 (gnus-article-prepare-hook nil)
9079                 (gnus-mark-article-hook nil))
9080             (gnus-summary-select-article nil nil nil (car articles))))
9081       (setq to-newsgroup
9082             (gnus-read-move-group-name
9083              (cadr (assq action names))
9084              (symbol-value (intern (format "gnus-current-%s-group" action)))
9085              articles prefix))
9086       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9087     (setq to-method (or select-method
9088                         (gnus-server-to-method
9089                          (gnus-group-method to-newsgroup))))
9090     ;; Check the method we are to move this article to...
9091     (unless (gnus-check-backend-function
9092              'request-accept-article (car to-method))
9093       (error "%s does not support article copying" (car to-method)))
9094     (unless (gnus-check-server to-method)
9095       (error "Can't open server %s" (car to-method)))
9096     (gnus-message 6 "%s to %s: %s..."
9097                   (caddr (assq action names))
9098                   (or (car select-method) to-newsgroup) articles)
9099     (while articles
9100       (setq article (pop articles))
9101       (setq
9102        art-group
9103        (cond
9104         ;; Move the article.
9105         ((eq action 'move)
9106          ;; Remove this article from future suppression.
9107          (gnus-dup-unsuppress-article article)
9108          (gnus-request-move-article
9109           article                       ; Article to move
9110           gnus-newsgroup-name           ; From newsgroup
9111           (nth 1 (gnus-find-method-for-group
9112                   gnus-newsgroup-name)) ; Server
9113           (list 'gnus-request-accept-article
9114                 to-newsgroup (list 'quote select-method)
9115                 (not articles) t)       ; Accept form
9116           (not articles)))              ; Only save nov last time
9117         ;; Copy the article.
9118         ((eq action 'copy)
9119          (save-excursion
9120            (set-buffer copy-buf)
9121            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9122              (gnus-request-accept-article
9123               to-newsgroup select-method (not articles) t))))
9124         ;; Crosspost the article.
9125         ((eq action 'crosspost)
9126          (let ((xref (message-tokenize-header
9127                       (mail-header-xref (gnus-summary-article-header article))
9128                       " ")))
9129            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9130                                   ":" (number-to-string article)))
9131            (unless xref
9132              (setq xref (list (system-name))))
9133            (setq new-xref
9134                  (concat
9135                   (mapconcat 'identity
9136                              (delete "Xref:" (delete new-xref xref))
9137                              " ")
9138                   " " new-xref))
9139            (save-excursion
9140              (set-buffer copy-buf)
9141              ;; First put the article in the destination group.
9142              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9143              (when (consp (setq art-group
9144                                 (gnus-request-accept-article
9145                                  to-newsgroup select-method (not articles))))
9146                (setq new-xref (concat new-xref " " (car art-group)
9147                                       ":"
9148                                       (number-to-string (cdr art-group))))
9149                ;; Now we have the new Xrefs header, so we insert
9150                ;; it and replace the new article.
9151                (nnheader-replace-header "Xref" new-xref)
9152                (gnus-request-replace-article
9153                 (cdr art-group) to-newsgroup (current-buffer))
9154                art-group))))))
9155       (cond
9156        ((not art-group)
9157         (gnus-message 1 "Couldn't %s article %s: %s"
9158                       (cadr (assq action names)) article
9159                       (nnheader-get-report (car to-method))))
9160        ((eq art-group 'junk)
9161         (when (eq action 'move)
9162           (gnus-summary-mark-article article gnus-canceled-mark)
9163           (gnus-message 4 "Deleted article %s" article)
9164           ;; run the delete hook
9165           (run-hook-with-args 'gnus-summary-article-delete-hook
9166                               action
9167                               (gnus-data-header
9168                                (assoc article (gnus-data-list nil)))
9169                               gnus-newsgroup-name nil
9170                               select-method)))
9171        (t
9172         (let* ((pto-group (gnus-group-prefixed-name
9173                            (car art-group) to-method))
9174                (info (gnus-get-info pto-group))
9175                (to-group (gnus-info-group info))
9176                to-marks)
9177           ;; Update the group that has been moved to.
9178           (when (and info
9179                      (memq action '(move copy)))
9180             (unless (member to-group to-groups)
9181               (push to-group to-groups))
9182
9183             (unless (memq article gnus-newsgroup-unreads)
9184               (push 'read to-marks)
9185               (gnus-info-set-read
9186                info (gnus-add-to-range (gnus-info-read info)
9187                                        (list (cdr art-group)))))
9188
9189             ;; See whether the article is to be put in the cache.
9190             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9191                              gnus-article-mark-lists
9192                            (delete '(expirable . expire)
9193                                    (copy-sequence gnus-article-mark-lists))))
9194                   (to-article (cdr art-group)))
9195
9196               ;; Enter the article into the cache in the new group,
9197               ;; if that is required.
9198               (when gnus-use-cache
9199                 (gnus-cache-possibly-enter-article
9200                  to-group to-article
9201                  (let ((header (copy-sequence
9202                                 (gnus-summary-article-header article))))
9203                    (mail-header-set-number header to-article)
9204                    header)
9205                  (memq article gnus-newsgroup-marked)
9206                  (memq article gnus-newsgroup-dormant)
9207                  (memq article gnus-newsgroup-unreads)))
9208
9209               (when gnus-preserve-marks
9210                 ;; Copy any marks over to the new group.
9211                 (when (and (equal to-group gnus-newsgroup-name)
9212                            (not (memq article gnus-newsgroup-unreads)))
9213                   ;; Mark this article as read in this group.
9214                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9215                   (setcdr (gnus-active to-group) to-article)
9216                   (setcdr gnus-newsgroup-active to-article))
9217
9218                 (while marks
9219                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9220                     (when (memq article (symbol-value
9221                                          (intern (format "gnus-newsgroup-%s"
9222                                                          (caar marks)))))
9223                       (push (cdar marks) to-marks)
9224                       ;; If the other group is the same as this group,
9225                       ;; then we have to add the mark to the list.
9226                       (when (equal to-group gnus-newsgroup-name)
9227                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9228                              (cons to-article
9229                                    (symbol-value
9230                                     (intern (format "gnus-newsgroup-%s"
9231                                                     (caar marks)))))))
9232                       ;; Copy the marks to other group.
9233                       (gnus-add-marked-articles
9234                        to-group (cdar marks) (list to-article) info)))
9235                   (setq marks (cdr marks)))
9236
9237                 (gnus-request-set-mark
9238                  to-group (list (list (list to-article) 'add to-marks))))
9239
9240               (gnus-dribble-enter
9241                (concat "(gnus-group-set-info '"
9242                        (gnus-prin1-to-string (gnus-get-info to-group))
9243                        ")"))))
9244
9245           ;; Update the Xref header in this article to point to
9246           ;; the new crossposted article we have just created.
9247           (when (eq action 'crosspost)
9248             (save-excursion
9249               (set-buffer copy-buf)
9250               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9251               (nnheader-replace-header "Xref" new-xref)
9252               (gnus-request-replace-article
9253                article gnus-newsgroup-name (current-buffer))))
9254
9255           ;; run the move/copy/crosspost/respool hook
9256           (run-hook-with-args 'gnus-summary-article-move-hook
9257                               action
9258                               (gnus-data-header
9259                                (assoc article (gnus-data-list nil)))
9260                               gnus-newsgroup-name
9261                               to-newsgroup
9262                               select-method))
9263
9264         ;;;!!!Why is this necessary?
9265         (set-buffer gnus-summary-buffer)
9266         
9267         (gnus-summary-goto-subject article)
9268         (when (eq action 'move)
9269           (gnus-summary-mark-article article gnus-canceled-mark))))
9270       (gnus-summary-remove-process-mark article))
9271     ;; Re-activate all groups that have been moved to.
9272     (save-excursion
9273       (set-buffer gnus-group-buffer)
9274       (let ((gnus-group-marked to-groups))
9275         (gnus-group-get-new-news-this-group nil t)))
9276
9277     (gnus-kill-buffer copy-buf)
9278     (gnus-summary-position-point)
9279     (gnus-set-mode-line 'summary)))
9280
9281 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9282   "Move the current article to a different newsgroup.
9283 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9284 When called interactively, if TO-NEWSGROUP is nil, use the value of
9285 the variable `gnus-move-split-methods' for finding a default target
9286 newsgroup.
9287 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9288 re-spool using this method."
9289   (interactive "P")
9290   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9291
9292 (defun gnus-summary-crosspost-article (&optional n)
9293   "Crosspost the current article to some other group."
9294   (interactive "P")
9295   (gnus-summary-move-article n nil nil 'crosspost))
9296
9297 (defcustom gnus-summary-respool-default-method nil
9298   "Default method type for respooling an article.
9299 If nil, use to the current newsgroup method."
9300   :type 'symbol
9301   :group 'gnus-summary-mail)
9302
9303 (defcustom gnus-summary-display-while-building nil
9304   "If non-nil, show and update the summary buffer as it's being built.
9305 If the value is t, update the buffer after every line is inserted.  If
9306 the value is an integer (N), update the display every N lines."
9307   :group 'gnus-thread
9308   :type '(choice (const :tag "off" nil)
9309                  number
9310                  (const :tag "frequently" t)))
9311
9312 (defun gnus-summary-respool-article (&optional n method)
9313   "Respool the current article.
9314 The article will be squeezed through the mail spooling process again,
9315 which means that it will be put in some mail newsgroup or other
9316 depending on `nnmail-split-methods'.
9317 If N is a positive number, respool the N next articles.
9318 If N is a negative number, respool the N previous articles.
9319 If N is nil and any articles have been marked with the process mark,
9320 respool those articles instead.
9321
9322 Respooling can be done both from mail groups and \"real\" newsgroups.
9323 In the former case, the articles in question will be moved from the
9324 current group into whatever groups they are destined to.  In the
9325 latter case, they will be copied into the relevant groups."
9326   (interactive
9327    (list current-prefix-arg
9328          (let* ((methods (gnus-methods-using 'respool))
9329                 (methname
9330                  (symbol-name (or gnus-summary-respool-default-method
9331                                   (car (gnus-find-method-for-group
9332                                         gnus-newsgroup-name)))))
9333                 (method
9334                  (gnus-completing-read-with-default
9335                   methname "What backend do you want to use when respooling?"
9336                   methods nil t nil 'gnus-mail-method-history))
9337                 ms)
9338            (cond
9339             ((zerop (length (setq ms (gnus-servers-using-backend
9340                                       (intern method)))))
9341              (list (intern method) ""))
9342             ((= 1 (length ms))
9343              (car ms))
9344             (t
9345              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9346                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9347                            ms-alist))))))))
9348   (unless method
9349     (error "No method given for respooling"))
9350   (if (assoc (symbol-name
9351               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9352              (gnus-methods-using 'respool))
9353       (gnus-summary-move-article n nil method)
9354     (gnus-summary-copy-article n nil method)))
9355
9356 (defun gnus-summary-import-article (file &optional edit)
9357   "Import an arbitrary file into a mail newsgroup."
9358   (interactive "fImport file: \nP")
9359   (let ((group gnus-newsgroup-name)
9360         (now (current-time))
9361         atts lines group-art)
9362     (unless (gnus-check-backend-function 'request-accept-article group)
9363       (error "%s does not support article importing" group))
9364     (or (file-readable-p file)
9365         (not (file-regular-p file))
9366         (error "Can't read %s" file))
9367     (save-excursion
9368       (set-buffer (gnus-get-buffer-create " *import file*"))
9369       (erase-buffer)
9370       (nnheader-insert-file-contents file)
9371       (goto-char (point-min))
9372       (if (nnheader-article-p)
9373           (save-restriction
9374             (goto-char (point-min))
9375             (search-forward "\n\n" nil t)
9376             (narrow-to-region (point-min) (1- (point)))
9377             (goto-char (point-min))
9378             (unless (re-search-forward "^date:" nil t)
9379               (goto-char (point-max))
9380               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9381         ;; This doesn't look like an article, so we fudge some headers.
9382         (setq atts (file-attributes file)
9383               lines (count-lines (point-min) (point-max)))
9384         (insert "From: " (read-string "From: ") "\n"
9385                 "Subject: " (read-string "Subject: ") "\n"
9386                 "Date: " (message-make-date (nth 5 atts)) "\n"
9387                 "Message-ID: " (message-make-message-id) "\n"
9388                 "Lines: " (int-to-string lines) "\n"
9389                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9390       (setq group-art (gnus-request-accept-article group nil t))
9391       (kill-buffer (current-buffer)))
9392     (setq gnus-newsgroup-active (gnus-activate-group group))
9393     (forward-line 1)
9394     (gnus-summary-goto-article (cdr group-art) nil t)
9395     (when edit
9396       (gnus-summary-edit-article))))
9397
9398 (defun gnus-summary-create-article ()
9399   "Create an article in a mail newsgroup."
9400   (interactive)
9401   (let ((group gnus-newsgroup-name)
9402         (now (current-time))
9403         group-art)
9404     (unless (gnus-check-backend-function 'request-accept-article group)
9405       (error "%s does not support article importing" group))
9406     (save-excursion
9407       (set-buffer (gnus-get-buffer-create " *import file*"))
9408       (erase-buffer)
9409       (goto-char (point-min))
9410       ;; This doesn't look like an article, so we fudge some headers.
9411       (insert "From: " (read-string "From: ") "\n"
9412               "Subject: " (read-string "Subject: ") "\n"
9413               "Date: " (message-make-date now) "\n"
9414               "Message-ID: " (message-make-message-id) "\n")
9415       (setq group-art (gnus-request-accept-article group nil t))
9416       (kill-buffer (current-buffer)))
9417     (setq gnus-newsgroup-active (gnus-activate-group group))
9418     (forward-line 1)
9419     (gnus-summary-goto-article (cdr group-art) nil t)
9420     (gnus-summary-edit-article)))
9421
9422 (defun gnus-summary-article-posted-p ()
9423   "Say whether the current (mail) article is available from news as well.
9424 This will be the case if the article has both been mailed and posted."
9425   (interactive)
9426   (let ((id (mail-header-references (gnus-summary-article-header)))
9427         (gnus-override-method (car (gnus-refer-article-methods))))
9428     (if (gnus-request-head id "")
9429         (gnus-message 2 "The current message was found on %s"
9430                       gnus-override-method)
9431       (gnus-message 2 "The current message couldn't be found on %s"
9432                     gnus-override-method)
9433       nil)))
9434
9435 (defun gnus-summary-expire-articles (&optional now)
9436   "Expire all articles that are marked as expirable in the current group."
9437   (interactive)
9438   (when (and (not gnus-group-is-exiting-without-update-p)
9439              (gnus-check-backend-function
9440               'request-expire-articles gnus-newsgroup-name))
9441     ;; This backend supports expiry.
9442     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9443            (expirable (if total
9444                           (progn
9445                             ;; We need to update the info for
9446                             ;; this group for `gnus-list-of-read-articles'
9447                             ;; to give us the right answer.
9448                             (gnus-run-hooks 'gnus-exit-group-hook)
9449                             (gnus-summary-update-info)
9450                             (gnus-list-of-read-articles gnus-newsgroup-name))
9451                         (setq gnus-newsgroup-expirable
9452                               (sort gnus-newsgroup-expirable '<))))
9453            (expiry-wait (if now 'immediate
9454                           (gnus-group-find-parameter
9455                            gnus-newsgroup-name 'expiry-wait)))
9456            (nnmail-expiry-target
9457             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9458                 nnmail-expiry-target))
9459            es)
9460       (when expirable
9461         ;; There are expirable articles in this group, so we run them
9462         ;; through the expiry process.
9463         (gnus-message 6 "Expiring articles...")
9464         (unless (gnus-check-group gnus-newsgroup-name)
9465           (error "Can't open server for %s" gnus-newsgroup-name))
9466         ;; The list of articles that weren't expired is returned.
9467         (save-excursion
9468           (if expiry-wait
9469               (let ((nnmail-expiry-wait-function nil)
9470                     (nnmail-expiry-wait expiry-wait))
9471                 (setq es (gnus-request-expire-articles
9472                           expirable gnus-newsgroup-name)))
9473             (setq es (gnus-request-expire-articles
9474                       expirable gnus-newsgroup-name)))
9475           (unless total
9476             (setq gnus-newsgroup-expirable es))
9477           ;; We go through the old list of expirable, and mark all
9478           ;; really expired articles as nonexistent.
9479           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9480             (let ((gnus-use-cache nil))
9481               (dolist (article expirable)
9482                 (when (and (not (memq article es))
9483                            (gnus-data-find article))
9484                   (gnus-summary-mark-article article gnus-canceled-mark)
9485                   (run-hook-with-args 'gnus-summary-article-expire-hook
9486                                       'delete
9487                                       (gnus-data-header
9488                                        (assoc article (gnus-data-list nil)))
9489                                       gnus-newsgroup-name
9490                                       nil
9491                                       nil))))))
9492         (gnus-message 6 "Expiring articles...done")))))
9493
9494 (defun gnus-summary-expire-articles-now ()
9495   "Expunge all expirable articles in the current group.
9496 This means that *all* articles that are marked as expirable will be
9497 deleted forever, right now."
9498   (interactive)
9499   (or gnus-expert-user
9500       (gnus-yes-or-no-p
9501        "Are you really, really, really sure you want to delete all these messages? ")
9502       (error "Phew!"))
9503   (gnus-summary-expire-articles t))
9504
9505 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9506 (defun gnus-summary-delete-article (&optional n)
9507   "Delete the N next (mail) articles.
9508 This command actually deletes articles.  This is not a marking
9509 command.  The article will disappear forever from your life, never to
9510 return.
9511
9512 If N is negative, delete backwards.
9513 If N is nil and articles have been marked with the process mark,
9514 delete these instead.
9515
9516 If `gnus-novice-user' is non-nil you will be asked for
9517 confirmation before the articles are deleted."
9518   (interactive "P")
9519   (unless (gnus-check-backend-function 'request-expire-articles
9520                                        gnus-newsgroup-name)
9521     (error "The current newsgroup does not support article deletion"))
9522   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9523     (error "Couldn't open server"))
9524   ;; Compute the list of articles to delete.
9525   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9526         (nnmail-expiry-target 'delete)
9527         not-deleted)
9528     (if (and gnus-novice-user
9529              (not (gnus-yes-or-no-p
9530                    (format "Do you really want to delete %s forever? "
9531                            (if (> (length articles) 1)
9532                                (format "these %s articles" (length articles))
9533                              "this article")))))
9534         ()
9535       ;; Delete the articles.
9536       (setq not-deleted (gnus-request-expire-articles
9537                          articles gnus-newsgroup-name 'force))
9538       (while articles
9539         (gnus-summary-remove-process-mark (car articles))
9540         ;; The backend might not have been able to delete the article
9541         ;; after all.
9542         (unless (memq (car articles) not-deleted)
9543           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9544         (let* ((article (car articles))
9545                (id (mail-header-id (gnus-data-header
9546                                     (assoc article (gnus-data-list nil))))))
9547           (run-hook-with-args 'gnus-summary-article-delete-hook
9548                               'delete id gnus-newsgroup-name nil
9549                               nil))
9550         (setq articles (cdr articles)))
9551       (when not-deleted
9552         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9553     (gnus-summary-position-point)
9554     (gnus-set-mode-line 'summary)
9555     not-deleted))
9556
9557 (defun gnus-summary-edit-article (&optional force)
9558   "Edit the current article.
9559 This will have permanent effect only in mail groups.
9560 If FORCE is non-nil, allow editing of articles even in read-only
9561 groups."
9562   (interactive "P")
9563   (save-excursion
9564     (set-buffer gnus-summary-buffer)
9565     (let ((mail-parse-charset gnus-newsgroup-charset)
9566           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9567       (gnus-set-global-variables)
9568       (when (and (not force)
9569                  (gnus-group-read-only-p))
9570         (error "The current newsgroup does not support article editing"))
9571       (gnus-summary-show-article t)
9572       (gnus-article-edit-article
9573        'ignore
9574        `(lambda (no-highlight)
9575           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9576                 (message-options message-options)
9577                 (message-options-set-recipient)
9578                 (mail-parse-ignored-charsets
9579                  ',gnus-newsgroup-ignored-charsets))
9580             (gnus-summary-edit-article-done
9581              ,(or (mail-header-references gnus-current-headers) "")
9582              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9583
9584 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9585
9586 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9587                                                  no-highlight)
9588   "Make edits to the current article permanent."
9589   (interactive)
9590   (save-excursion
9591     ;; The buffer restriction contains the entire article if it exists.
9592     (when (article-goto-body)
9593       (let ((lines (count-lines (point) (point-max)))
9594             (length (- (point-max) (point)))
9595             (case-fold-search t)
9596             (body (copy-marker (point))))
9597         (goto-char (point-min))
9598         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9599           (delete-region (match-beginning 1) (match-end 1))
9600           (insert (number-to-string length)))
9601         (goto-char (point-min))
9602         (when (re-search-forward
9603                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9604           (delete-region (match-beginning 1) (match-end 1))
9605           (insert (number-to-string length)))
9606         (goto-char (point-min))
9607         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9608           (delete-region (match-beginning 1) (match-end 1))
9609           (insert (number-to-string lines))))))
9610   ;; Replace the article.
9611   (let ((buf (current-buffer)))
9612     (with-temp-buffer
9613       (insert-buffer-substring buf)
9614
9615       (if (and (not read-only)
9616                (not (gnus-request-replace-article
9617                      (cdr gnus-article-current) (car gnus-article-current)
9618                      (current-buffer) t)))
9619           (error "Couldn't replace article")
9620         ;; Update the summary buffer.
9621         (if (and references
9622                  (equal (message-tokenize-header references " ")
9623                         (message-tokenize-header
9624                          (or (message-fetch-field "references") "") " ")))
9625             ;; We only have to update this line.
9626             (save-excursion
9627               (save-restriction
9628                 (message-narrow-to-head)
9629                 (let ((head (buffer-string))
9630                       header)
9631                   (with-temp-buffer
9632                     (insert (format "211 %d Article retrieved.\n"
9633                                     (cdr gnus-article-current)))
9634                     (insert head)
9635                     (insert ".\n")
9636                     (let ((nntp-server-buffer (current-buffer)))
9637                       (setq header (car (gnus-get-newsgroup-headers
9638                                          nil t))))
9639                     (save-excursion
9640                       (set-buffer gnus-summary-buffer)
9641                       (gnus-data-set-header
9642                        (gnus-data-find (cdr gnus-article-current))
9643                        header)
9644                       (gnus-summary-update-article-line
9645                        (cdr gnus-article-current) header)
9646                       (if (gnus-summary-goto-subject
9647                            (cdr gnus-article-current) nil t)
9648                           (gnus-summary-update-secondary-mark
9649                            (cdr gnus-article-current))))))))
9650           ;; Update threads.
9651           (set-buffer (or buffer gnus-summary-buffer))
9652           (gnus-summary-update-article (cdr gnus-article-current))
9653           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9654               (gnus-summary-update-secondary-mark
9655                (cdr gnus-article-current))))
9656         ;; Prettify the article buffer again.
9657         (unless no-highlight
9658           (save-excursion
9659             (set-buffer gnus-article-buffer)
9660             ;;;!!! Fix this -- article should be rehighlighted.
9661             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9662             (set-buffer gnus-original-article-buffer)
9663             (gnus-request-article
9664              (cdr gnus-article-current)
9665              (car gnus-article-current) (current-buffer))))
9666         ;; Prettify the summary buffer line.
9667         (when (gnus-visual-p 'summary-highlight 'highlight)
9668           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9669
9670 (defun gnus-summary-edit-wash (key)
9671   "Perform editing command KEY in the article buffer."
9672   (interactive
9673    (list
9674     (progn
9675       (message "%s" (concat (this-command-keys) "- "))
9676       (read-char))))
9677   (message "")
9678   (gnus-summary-edit-article)
9679   (execute-kbd-macro (concat (this-command-keys) key))
9680   (gnus-article-edit-done))
9681
9682 ;;; Respooling
9683
9684 (defun gnus-summary-respool-query (&optional silent trace)
9685   "Query where the respool algorithm would put this article."
9686   (interactive)
9687   (let (gnus-mark-article-hook)
9688     (gnus-summary-select-article)
9689     (save-excursion
9690       (set-buffer gnus-original-article-buffer)
9691       (let ((groups (nnmail-article-group 'identity trace)))
9692         (unless silent
9693           (if groups
9694               (message "This message would go to %s"
9695                        (mapconcat 'car groups ", "))
9696             (message "This message would go to no groups"))
9697           groups)))))
9698
9699 (defun gnus-summary-respool-trace ()
9700   "Trace where the respool algorithm would put this article.
9701 Display a buffer showing all fancy splitting patterns which matched."
9702   (interactive)
9703   (gnus-summary-respool-query nil t))
9704
9705 ;; Summary marking commands.
9706
9707 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9708   "Mark articles which has the same subject as read, and then select the next.
9709 If UNMARK is positive, remove any kind of mark.
9710 If UNMARK is negative, tick articles."
9711   (interactive "P")
9712   (when unmark
9713     (setq unmark (prefix-numeric-value unmark)))
9714   (let ((count
9715          (gnus-summary-mark-same-subject
9716           (gnus-summary-article-subject) unmark)))
9717     ;; Select next unread article.  If auto-select-same mode, should
9718     ;; select the first unread article.
9719     (gnus-summary-next-article t (and gnus-auto-select-same
9720                                       (gnus-summary-article-subject)))
9721     (gnus-message 7 "%d article%s marked as %s"
9722                   count (if (= count 1) " is" "s are")
9723                   (if unmark "unread" "read"))))
9724
9725 (defun gnus-summary-kill-same-subject (&optional unmark)
9726   "Mark articles which has the same subject as read.
9727 If UNMARK is positive, remove any kind of mark.
9728 If UNMARK is negative, tick articles."
9729   (interactive "P")
9730   (when unmark
9731     (setq unmark (prefix-numeric-value unmark)))
9732   (let ((count
9733          (gnus-summary-mark-same-subject
9734           (gnus-summary-article-subject) unmark)))
9735     ;; If marked as read, go to next unread subject.
9736     (when (null unmark)
9737       ;; Go to next unread subject.
9738       (gnus-summary-next-subject 1 t))
9739     (gnus-message 7 "%d articles are marked as %s"
9740                   count (if unmark "unread" "read"))))
9741
9742 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9743   "Mark articles with same SUBJECT as read, and return marked number.
9744 If optional argument UNMARK is positive, remove any kinds of marks.
9745 If optional argument UNMARK is negative, mark articles as unread instead."
9746   (let ((count 1))
9747     (save-excursion
9748       (cond
9749        ((null unmark)                   ; Mark as read.
9750         (while (and
9751                 (progn
9752                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9753                   (gnus-summary-show-thread) t)
9754                 (gnus-summary-find-subject subject))
9755           (setq count (1+ count))))
9756        ((> unmark 0)                    ; Tick.
9757         (while (and
9758                 (progn
9759                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9760                   (gnus-summary-show-thread) t)
9761                 (gnus-summary-find-subject subject))
9762           (setq count (1+ count))))
9763        (t                               ; Mark as unread.
9764         (while (and
9765                 (progn
9766                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9767                   (gnus-summary-show-thread) t)
9768                 (gnus-summary-find-subject subject))
9769           (setq count (1+ count)))))
9770       (gnus-set-mode-line 'summary)
9771       ;; Return the number of marked articles.
9772       count)))
9773
9774 (defun gnus-summary-mark-as-processable (n &optional unmark)
9775   "Set the process mark on the next N articles.
9776 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9777 the process mark instead.  The difference between N and the actual
9778 number of articles marked is returned."
9779   (interactive "P")
9780   (if (and (null n) (gnus-region-active-p))
9781       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9782     (setq n (prefix-numeric-value n))
9783     (let ((backward (< n 0))
9784           (n (abs n)))
9785       (while (and
9786               (> n 0)
9787               (if unmark
9788                   (gnus-summary-remove-process-mark
9789                    (gnus-summary-article-number))
9790                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9791               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9792         (setq n (1- n)))
9793       (when (/= 0 n)
9794         (gnus-message 7 "No more articles"))
9795       (gnus-summary-recenter)
9796       (gnus-summary-position-point)
9797       n)))
9798
9799 (defun gnus-summary-unmark-as-processable (n)
9800   "Remove the process mark from the next N articles.
9801 If N is negative, unmark backward instead.  The difference between N and
9802 the actual number of articles unmarked is returned."
9803   (interactive "P")
9804   (gnus-summary-mark-as-processable n t))
9805
9806 (defun gnus-summary-unmark-all-processable ()
9807   "Remove the process mark from all articles."
9808   (interactive)
9809   (save-excursion
9810     (while gnus-newsgroup-processable
9811       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9812   (gnus-summary-position-point))
9813
9814 (defun gnus-summary-add-mark (article type)
9815   "Mark ARTICLE with a mark of TYPE."
9816   (let ((vtype (car (assq type gnus-article-mark-lists)))
9817         var)
9818     (if (not vtype)
9819         (error "No such mark type: %s" type)
9820       (setq var (intern (format "gnus-newsgroup-%s" type)))
9821       (set var (cons article (symbol-value var)))
9822       (if (memq type '(processable cached replied forwarded recent saved))
9823           (gnus-summary-update-secondary-mark article)
9824         ;;; !!! This is bogus.  We should find out what primary
9825         ;;; !!! mark we want to set.
9826         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9827
9828 (defun gnus-summary-mark-as-expirable (n)
9829   "Mark N articles forward as expirable.
9830 If N is negative, mark backward instead.  The difference between N and
9831 the actual number of articles marked is returned."
9832   (interactive "p")
9833   (gnus-summary-mark-forward n gnus-expirable-mark))
9834
9835 (defun gnus-summary-mark-as-spam (n)
9836   "Mark N articles forward as spam.
9837 If N is negative, mark backward instead.  The difference between N and
9838 the actual number of articles marked is returned."
9839   (interactive "p")
9840   (gnus-summary-mark-forward n gnus-spam-mark))
9841
9842 (defun gnus-summary-mark-article-as-replied (article)
9843   "Mark ARTICLE as replied to and update the summary line.
9844 ARTICLE can also be a list of articles."
9845   (interactive (list (gnus-summary-article-number)))
9846   (let ((articles (if (listp article) article (list article))))
9847     (dolist (article articles)
9848       (unless (numberp article)
9849         (error "%s is not a number" article))
9850       (push article gnus-newsgroup-replied)
9851       (let ((buffer-read-only nil))
9852         (when (gnus-summary-goto-subject article nil t)
9853           (gnus-summary-update-secondary-mark article))))))
9854
9855 (defun gnus-summary-mark-article-as-forwarded (article)
9856   "Mark ARTICLE as forwarded and update the summary line.
9857 ARTICLE can also be a list of articles."
9858   (let ((articles (if (listp article) article (list article))))
9859     (dolist (article articles)
9860       (push article gnus-newsgroup-forwarded)
9861       (let ((buffer-read-only nil))
9862         (when (gnus-summary-goto-subject article nil t)
9863           (gnus-summary-update-secondary-mark article))))))
9864
9865 (defun gnus-summary-set-bookmark (article)
9866   "Set a bookmark in current article."
9867   (interactive (list (gnus-summary-article-number)))
9868   (when (or (not (get-buffer gnus-article-buffer))
9869             (not gnus-current-article)
9870             (not gnus-article-current)
9871             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9872     (error "No current article selected"))
9873   ;; Remove old bookmark, if one exists.
9874   (gnus-pull article gnus-newsgroup-bookmarks)
9875   ;; Set the new bookmark, which is on the form
9876   ;; (article-number . line-number-in-body).
9877   (push
9878    (cons article
9879          (with-current-buffer gnus-article-buffer
9880            (count-lines
9881             (min (point)
9882                  (save-excursion
9883                    (article-goto-body)
9884                    (point)))
9885             (point))))
9886    gnus-newsgroup-bookmarks)
9887   (gnus-message 6 "A bookmark has been added to the current article."))
9888
9889 (defun gnus-summary-remove-bookmark (article)
9890   "Remove the bookmark from the current article."
9891   (interactive (list (gnus-summary-article-number)))
9892   ;; Remove old bookmark, if one exists.
9893   (if (not (assq article gnus-newsgroup-bookmarks))
9894       (gnus-message 6 "No bookmark in current article.")
9895     (gnus-pull article gnus-newsgroup-bookmarks)
9896     (gnus-message 6 "Removed bookmark.")))
9897
9898 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9899 (defun gnus-summary-mark-as-dormant (n)
9900   "Mark N articles forward as dormant.
9901 If N is negative, mark backward instead.  The difference between N and
9902 the actual number of articles marked is returned."
9903   (interactive "p")
9904   (gnus-summary-mark-forward n gnus-dormant-mark))
9905
9906 (defun gnus-summary-set-process-mark (article)
9907   "Set the process mark on ARTICLE and update the summary line."
9908   (setq gnus-newsgroup-processable
9909         (cons article
9910               (delq article gnus-newsgroup-processable)))
9911   (when (gnus-summary-goto-subject article)
9912     (gnus-summary-show-thread)
9913     (gnus-summary-goto-subject article)
9914     (gnus-summary-update-secondary-mark article)))
9915
9916 (defun gnus-summary-remove-process-mark (article)
9917   "Remove the process mark from ARTICLE and update the summary line."
9918   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9919   (when (gnus-summary-goto-subject article)
9920     (gnus-summary-show-thread)
9921     (gnus-summary-goto-subject article)
9922     (gnus-summary-update-secondary-mark article)))
9923
9924 (defun gnus-summary-set-saved-mark (article)
9925   "Set the process mark on ARTICLE and update the summary line."
9926   (push article gnus-newsgroup-saved)
9927   (when (gnus-summary-goto-subject article)
9928     (gnus-summary-update-secondary-mark article)))
9929
9930 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9931   "Mark N articles as read forwards.
9932 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9933 The difference between N and the actual number of articles marked is
9934 returned.
9935 If NO-EXPIRE, auto-expiry will be inhibited."
9936   (interactive "p")
9937   (gnus-summary-show-thread)
9938   (let ((backward (< n 0))
9939         (gnus-summary-goto-unread
9940          (and gnus-summary-goto-unread
9941               (not (eq gnus-summary-goto-unread 'never))
9942               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9943                                     gnus-ticked-mark gnus-dormant-mark)))))
9944         (n (abs n))
9945         (mark (or mark gnus-del-mark)))
9946     (while (and (> n 0)
9947                 (gnus-summary-mark-article nil mark no-expire)
9948                 (zerop (gnus-summary-next-subject
9949                         (if backward -1 1)
9950                         (and gnus-summary-goto-unread
9951                              (not (eq gnus-summary-goto-unread 'never)))
9952                         t)))
9953       (setq n (1- n)))
9954     (when (/= 0 n)
9955       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9956     (gnus-summary-recenter)
9957     (gnus-summary-position-point)
9958     (gnus-set-mode-line 'summary)
9959     n))
9960
9961 (defun gnus-summary-mark-article-as-read (mark)
9962   "Mark the current article quickly as read with MARK."
9963   (let ((article (gnus-summary-article-number)))
9964     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9965     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9966     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9967     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9968     (push (cons article mark) gnus-newsgroup-reads)
9969     ;; Possibly remove from cache, if that is used.
9970     (when gnus-use-cache
9971       (gnus-cache-enter-remove-article article))
9972     ;; Allow the backend to change the mark.
9973     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9974     ;; Check for auto-expiry.
9975     (when (and gnus-newsgroup-auto-expire
9976                (memq mark gnus-auto-expirable-marks))
9977       (setq mark gnus-expirable-mark)
9978       ;; Let the backend know about the mark change.
9979       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9980       (push article gnus-newsgroup-expirable))
9981     ;; Set the mark in the buffer.
9982     (gnus-summary-update-mark mark 'unread)
9983     t))
9984
9985 (defun gnus-summary-mark-article-as-unread (mark)
9986   "Mark the current article quickly as unread with MARK."
9987   (let* ((article (gnus-summary-article-number))
9988          (old-mark (gnus-summary-article-mark article)))
9989     ;; Allow the backend to change the mark.
9990     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9991     (if (eq mark old-mark)
9992         t
9993       (if (<= article 0)
9994           (progn
9995             (gnus-error 1 "Can't mark negative article numbers")
9996             nil)
9997         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9998         (setq gnus-newsgroup-spam-marked
9999               (delq article gnus-newsgroup-spam-marked))
10000         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10001         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10002         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10003         (cond ((= mark gnus-ticked-mark)
10004                (setq gnus-newsgroup-marked
10005                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10006                                               article)))
10007               ((= mark gnus-spam-mark)
10008                (setq gnus-newsgroup-spam-marked
10009                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10010                                               article)))
10011               ((= mark gnus-dormant-mark)
10012                (setq gnus-newsgroup-dormant
10013                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10014                                               article)))
10015               (t
10016                (setq gnus-newsgroup-unreads
10017                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10018                                               article))))
10019         (gnus-pull article gnus-newsgroup-reads)
10020
10021         ;; See whether the article is to be put in the cache.
10022         (and gnus-use-cache
10023              (vectorp (gnus-summary-article-header article))
10024              (save-excursion
10025                (gnus-cache-possibly-enter-article
10026                 gnus-newsgroup-name article
10027                 (gnus-summary-article-header article)
10028                 (= mark gnus-ticked-mark)
10029                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10030
10031         ;; Fix the mark.
10032         (gnus-summary-update-mark mark 'unread)
10033         t))))
10034
10035 (defun gnus-summary-mark-article (&optional article mark no-expire)
10036   "Mark ARTICLE with MARK.  MARK can be any character.
10037 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10038 `??' (dormant) and `?E' (expirable).
10039 If MARK is nil, then the default character `?r' is used.
10040 If ARTICLE is nil, then the article on the current line will be
10041 marked.
10042 If NO-EXPIRE, auto-expiry will be inhibited."
10043   ;; The mark might be a string.
10044   (when (stringp mark)
10045     (setq mark (aref mark 0)))
10046   ;; If no mark is given, then we check auto-expiring.
10047   (when (null mark)
10048     (setq mark gnus-del-mark))
10049   (when (and (not no-expire)
10050              gnus-newsgroup-auto-expire
10051              (memq mark gnus-auto-expirable-marks))
10052     (setq mark gnus-expirable-mark))
10053   (let ((article (or article (gnus-summary-article-number)))
10054         (old-mark (gnus-summary-article-mark article)))
10055     ;; Allow the backend to change the mark.
10056     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10057     (if (eq mark old-mark)
10058         t
10059       (unless article
10060         (error "No article on current line"))
10061       (if (not (if (or (= mark gnus-unread-mark)
10062                        (= mark gnus-ticked-mark)
10063                        (= mark gnus-spam-mark)
10064                        (= mark gnus-dormant-mark))
10065                    (gnus-mark-article-as-unread article mark)
10066                  (gnus-mark-article-as-read article mark)))
10067           t
10068         ;; See whether the article is to be put in the cache.
10069         (and gnus-use-cache
10070              (not (= mark gnus-canceled-mark))
10071              (vectorp (gnus-summary-article-header article))
10072              (save-excursion
10073                (gnus-cache-possibly-enter-article
10074                 gnus-newsgroup-name article
10075                 (gnus-summary-article-header article)
10076                 (= mark gnus-ticked-mark)
10077                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10078
10079         (when (gnus-summary-goto-subject article nil t)
10080           (let ((buffer-read-only nil))
10081             (gnus-summary-show-thread)
10082             ;; Fix the mark.
10083             (gnus-summary-update-mark mark 'unread)
10084             t))))))
10085
10086 (defun gnus-summary-update-secondary-mark (article)
10087   "Update the secondary (read, process, cache) mark."
10088   (gnus-summary-update-mark
10089    (cond ((memq article gnus-newsgroup-processable)
10090           gnus-process-mark)
10091          ((memq article gnus-newsgroup-cached)
10092           gnus-cached-mark)
10093          ((memq article gnus-newsgroup-replied)
10094           gnus-replied-mark)
10095          ((memq article gnus-newsgroup-forwarded)
10096           gnus-forwarded-mark)
10097          ((memq article gnus-newsgroup-saved)
10098           gnus-saved-mark)
10099          ((memq article gnus-newsgroup-recent)
10100           gnus-recent-mark)
10101          ((memq article gnus-newsgroup-unseen)
10102           gnus-unseen-mark)
10103          (t gnus-no-mark))
10104    'replied)
10105   (when (gnus-visual-p 'summary-highlight 'highlight)
10106     (gnus-run-hooks 'gnus-summary-update-hook))
10107   t)
10108
10109 (defun gnus-summary-update-download-mark (article)
10110   "Update the download mark."
10111   (gnus-summary-update-mark
10112    (cond ((memq article gnus-newsgroup-undownloaded)
10113           gnus-undownloaded-mark)
10114          (gnus-newsgroup-agentized
10115           gnus-downloaded-mark)
10116          (t
10117           gnus-no-mark))
10118    'download)
10119   (gnus-summary-update-line t)
10120   t)
10121
10122 (defun gnus-summary-update-mark (mark type)
10123   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10124         (buffer-read-only nil))
10125     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10126     (when forward
10127       (when (looking-at "\r")
10128         (incf forward))
10129       (when (<= (+ forward (point)) (point-max))
10130         ;; Go to the right position on the line.
10131         (goto-char (+ forward (point)))
10132         ;; Replace the old mark with the new mark.
10133         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10134         ;; Optionally update the marks by some user rule.
10135         (when (eq type 'unread)
10136           (gnus-data-set-mark
10137            (gnus-data-find (gnus-summary-article-number)) mark)
10138           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10139
10140 (defun gnus-mark-article-as-read (article &optional mark)
10141   "Enter ARTICLE in the pertinent lists and remove it from others."
10142   ;; Make the article expirable.
10143   (let ((mark (or mark gnus-del-mark)))
10144     (setq gnus-newsgroup-expirable
10145           (if (= mark gnus-expirable-mark)
10146               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10147             (delq article gnus-newsgroup-expirable)))
10148     ;; Remove from unread and marked lists.
10149     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10150     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10151     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10152     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10153     (push (cons article mark) gnus-newsgroup-reads)
10154     ;; Possibly remove from cache, if that is used.
10155     (when gnus-use-cache
10156       (gnus-cache-enter-remove-article article))
10157     t))
10158
10159 (defun gnus-mark-article-as-unread (article &optional mark)
10160   "Enter ARTICLE in the pertinent lists and remove it from others."
10161   (let ((mark (or mark gnus-ticked-mark)))
10162     (if (<= article 0)
10163         (progn
10164           (gnus-error 1 "Can't mark negative article numbers")
10165           nil)
10166       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10167             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10168             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10169             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10170             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10171
10172       ;; Unsuppress duplicates?
10173       (when gnus-suppress-duplicates
10174         (gnus-dup-unsuppress-article article))
10175
10176       (cond ((= mark gnus-ticked-mark)
10177              (setq gnus-newsgroup-marked
10178                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10179             ((= mark gnus-spam-mark)
10180              (setq gnus-newsgroup-spam-marked
10181                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10182                                             article)))
10183             ((= mark gnus-dormant-mark)
10184              (setq gnus-newsgroup-dormant
10185                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10186             (t
10187              (setq gnus-newsgroup-unreads
10188                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10189       (gnus-pull article gnus-newsgroup-reads)
10190       t)))
10191
10192 (defalias 'gnus-summary-mark-as-unread-forward
10193   'gnus-summary-tick-article-forward)
10194 (make-obsolete 'gnus-summary-mark-as-unread-forward
10195                'gnus-summary-tick-article-forward)
10196 (defun gnus-summary-tick-article-forward (n)
10197   "Tick N articles forwards.
10198 If N is negative, tick backwards instead.
10199 The difference between N and the number of articles ticked is returned."
10200   (interactive "p")
10201   (gnus-summary-mark-forward n gnus-ticked-mark))
10202
10203 (defalias 'gnus-summary-mark-as-unread-backward
10204   'gnus-summary-tick-article-backward)
10205 (make-obsolete 'gnus-summary-mark-as-unread-backward
10206                'gnus-summary-tick-article-backward)
10207 (defun gnus-summary-tick-article-backward (n)
10208   "Tick N articles backwards.
10209 The difference between N and the number of articles ticked is returned."
10210   (interactive "p")
10211   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10212
10213 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10214 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10215 (defun gnus-summary-tick-article (&optional article clear-mark)
10216   "Mark current article as unread.
10217 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10218 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10219   (interactive)
10220   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10221                                        gnus-ticked-mark)))
10222
10223 (defun gnus-summary-mark-as-read-forward (n)
10224   "Mark N articles as read forwards.
10225 If N is negative, mark backwards instead.
10226 The difference between N and the actual number of articles marked is
10227 returned."
10228   (interactive "p")
10229   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10230
10231 (defun gnus-summary-mark-as-read-backward (n)
10232   "Mark the N articles as read backwards.
10233 The difference between N and the actual number of articles marked is
10234 returned."
10235   (interactive "p")
10236   (gnus-summary-mark-forward
10237    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10238
10239 (defun gnus-summary-mark-as-read (&optional article mark)
10240   "Mark current article as read.
10241 ARTICLE specifies the article to be marked as read.
10242 MARK specifies a string to be inserted at the beginning of the line."
10243   (gnus-summary-mark-article article mark))
10244
10245 (defun gnus-summary-clear-mark-forward (n)
10246   "Clear marks from N articles forward.
10247 If N is negative, clear backward instead.
10248 The difference between N and the number of marks cleared is returned."
10249   (interactive "p")
10250   (gnus-summary-mark-forward n gnus-unread-mark))
10251
10252 (defun gnus-summary-clear-mark-backward (n)
10253   "Clear marks from N articles backward.
10254 The difference between N and the number of marks cleared is returned."
10255   (interactive "p")
10256   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10257
10258 (defun gnus-summary-mark-unread-as-read ()
10259   "Intended to be used by `gnus-summary-mark-article-hook'."
10260   (when (memq gnus-current-article gnus-newsgroup-unreads)
10261     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10262
10263 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10264   "Intended to be used by `gnus-summary-mark-article-hook'."
10265   (let ((mark (gnus-summary-article-mark)))
10266     (when (or (gnus-unread-mark-p mark)
10267               (gnus-read-mark-p mark))
10268       (gnus-summary-mark-article gnus-current-article
10269                                  (or new-mark gnus-read-mark)))))
10270
10271 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10272   "Intended to be used by `gnus-summary-mark-article-hook'."
10273   (let ((mark (gnus-summary-article-mark)))
10274     (when (or (gnus-unread-mark-p mark)
10275               (gnus-read-mark-p mark))
10276       (gnus-summary-mark-article (gnus-summary-article-number)
10277                                  (or new-mark gnus-read-mark)))))
10278
10279 (defun gnus-summary-mark-unread-as-ticked ()
10280   "Intended to be used by `gnus-summary-mark-article-hook'."
10281   (when (memq gnus-current-article gnus-newsgroup-unreads)
10282     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10283
10284 (defun gnus-summary-mark-region-as-read (point mark all)
10285   "Mark all unread articles between point and mark as read.
10286 If given a prefix, mark all articles between point and mark as read,
10287 even ticked and dormant ones."
10288   (interactive "r\nP")
10289   (save-excursion
10290     (let (article)
10291       (goto-char point)
10292       (beginning-of-line)
10293       (while (and
10294               (< (point) mark)
10295               (progn
10296                 (when (or all
10297                           (memq (setq article (gnus-summary-article-number))
10298                                 gnus-newsgroup-unreads))
10299                   (gnus-summary-mark-article article gnus-del-mark))
10300                 t)
10301               (gnus-summary-find-next))))))
10302
10303 (defun gnus-summary-mark-below (score mark)
10304   "Mark articles with score less than SCORE with MARK."
10305   (interactive "P\ncMark: ")
10306   (setq score (if score
10307                   (prefix-numeric-value score)
10308                 (or gnus-summary-default-score 0)))
10309   (save-excursion
10310     (set-buffer gnus-summary-buffer)
10311     (goto-char (point-min))
10312     (while
10313         (progn
10314           (and (< (gnus-summary-article-score) score)
10315                (gnus-summary-mark-article nil mark))
10316           (gnus-summary-find-next)))))
10317
10318 (defun gnus-summary-kill-below (&optional score)
10319   "Mark articles with score below SCORE as read."
10320   (interactive "P")
10321   (gnus-summary-mark-below score gnus-killed-mark))
10322
10323 (defun gnus-summary-clear-above (&optional score)
10324   "Clear all marks from articles with score above SCORE."
10325   (interactive "P")
10326   (gnus-summary-mark-above score gnus-unread-mark))
10327
10328 (defun gnus-summary-tick-above (&optional score)
10329   "Tick all articles with score above SCORE."
10330   (interactive "P")
10331   (gnus-summary-mark-above score gnus-ticked-mark))
10332
10333 (defun gnus-summary-mark-above (score mark)
10334   "Mark articles with score over SCORE with MARK."
10335   (interactive "P\ncMark: ")
10336   (setq score (if score
10337                   (prefix-numeric-value score)
10338                 (or gnus-summary-default-score 0)))
10339   (save-excursion
10340     (set-buffer gnus-summary-buffer)
10341     (goto-char (point-min))
10342     (while (and (progn
10343                   (when (> (gnus-summary-article-score) score)
10344                     (gnus-summary-mark-article nil mark))
10345                   t)
10346                 (gnus-summary-find-next)))))
10347
10348 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10349 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10350 (defun gnus-summary-limit-include-expunged (&optional no-error)
10351   "Display all the hidden articles that were expunged for low scores."
10352   (interactive)
10353   (let ((buffer-read-only nil))
10354     (let ((scored gnus-newsgroup-scored)
10355           headers h)
10356       (while scored
10357         (unless (gnus-summary-article-header (caar scored))
10358           (and (setq h (gnus-number-to-header (caar scored)))
10359                (< (cdar scored) gnus-summary-expunge-below)
10360                (push h headers)))
10361         (setq scored (cdr scored)))
10362       (if (not headers)
10363           (when (not no-error)
10364             (error "No expunged articles hidden"))
10365         (goto-char (point-min))
10366         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10367         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10368         (mapcar (lambda (x) (push (mail-header-number x)
10369                                   gnus-newsgroup-limit))
10370                 headers)
10371         (gnus-summary-prepare-unthreaded (nreverse headers))
10372         (goto-char (point-min))
10373         (gnus-summary-position-point)
10374         t))))
10375
10376 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10377   "Mark all unread articles in this newsgroup as read.
10378 If prefix argument ALL is non-nil, ticked and dormant articles will
10379 also be marked as read.
10380 If QUIETLY is non-nil, no questions will be asked.
10381
10382 If TO-HERE is non-nil, it should be a point in the buffer.  All
10383 articles before (after, if REVERSE is set) this point will be marked
10384 as read.
10385
10386 Note that this function will only catch up the unread article
10387 in the current summary buffer limitation.
10388
10389 The number of articles marked as read is returned."
10390   (interactive "P")
10391   (prog1
10392       (save-excursion
10393         (when (or quietly
10394                   (not gnus-interactive-catchup) ;Without confirmation?
10395                   gnus-expert-user
10396                   (gnus-y-or-n-p
10397                    (if all
10398                        "Mark absolutely all articles as read? "
10399                      "Mark all unread articles as read? ")))
10400           (if (and not-mark
10401                    (not gnus-newsgroup-adaptive)
10402                    (not gnus-newsgroup-auto-expire)
10403                    (not gnus-suppress-duplicates)
10404                    (or (not gnus-use-cache)
10405                        (eq gnus-use-cache 'passive)))
10406               (progn
10407                 (when all
10408                   (setq gnus-newsgroup-marked nil
10409                         gnus-newsgroup-spam-marked nil
10410                         gnus-newsgroup-dormant nil))
10411                 (setq gnus-newsgroup-unreads
10412                       (gnus-sorted-nunion
10413                        (gnus-intersection gnus-newsgroup-unreads
10414                                           gnus-newsgroup-downloadable)
10415                        gnus-newsgroup-unfetched)))
10416             ;; We actually mark all articles as canceled, which we
10417             ;; have to do when using auto-expiry or adaptive scoring.
10418             (gnus-summary-show-all-threads)
10419             (if (and to-here reverse)
10420                 (progn
10421                   (goto-char to-here)
10422                   (gnus-summary-mark-current-read-and-unread-as-read
10423                    gnus-catchup-mark)
10424                   (while (gnus-summary-find-next (not all))
10425                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10426               (when (gnus-summary-first-subject (not all))
10427                 (while (and
10428                         (if to-here (< (point) to-here) t)
10429                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10430                         (gnus-summary-find-next (not all))))))
10431             (gnus-set-mode-line 'summary))
10432           t))
10433     (gnus-summary-position-point)))
10434
10435 (defun gnus-summary-catchup-to-here (&optional all)
10436   "Mark all unticked articles before the current one as read.
10437 If ALL is non-nil, also mark ticked and dormant articles as read."
10438   (interactive "P")
10439   (save-excursion
10440     (gnus-save-hidden-threads
10441       (let ((beg (point)))
10442         ;; We check that there are unread articles.
10443         (when (or all (gnus-summary-find-prev))
10444           (gnus-summary-catchup all t beg)))))
10445   (gnus-summary-position-point))
10446
10447 (defun gnus-summary-catchup-from-here (&optional all)
10448   "Mark all unticked articles after (and including) the current one as read.
10449 If ALL is non-nil, also mark ticked and dormant articles as read."
10450   (interactive "P")
10451   (save-excursion
10452     (gnus-save-hidden-threads
10453       (let ((beg (point)))
10454         ;; We check that there are unread articles.
10455         (when (or all (gnus-summary-find-next))
10456           (gnus-summary-catchup all t beg nil t)))))
10457   (gnus-summary-position-point))
10458
10459 (defun gnus-summary-catchup-all (&optional quietly)
10460   "Mark all articles in this newsgroup as read.
10461 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10462 instead, which marks only unread articles as read."
10463   (interactive "P")
10464   (gnus-summary-catchup t quietly))
10465
10466 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10467   "Mark all unread articles in this group as read, then exit.
10468 If prefix argument ALL is non-nil, all articles are marked as read.
10469 If QUIETLY is non-nil, no questions will be asked."
10470   (interactive "P")
10471   (when (gnus-summary-catchup all quietly nil 'fast)
10472     ;; Select next newsgroup or exit.
10473     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10474              (eq gnus-auto-select-next 'quietly))
10475         (gnus-summary-next-group nil)
10476       (gnus-summary-exit))))
10477
10478 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10479   "Mark all articles in this newsgroup as read, and then exit.
10480 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10481 instead, which marks only unread articles as read."
10482   (interactive "P")
10483   (gnus-summary-catchup-and-exit t quietly))
10484
10485 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10486   "Mark all articles in this group as read and select the next group.
10487 If given a prefix, mark all articles, unread as well as ticked, as
10488 read."
10489   (interactive "P")
10490   (save-excursion
10491     (gnus-summary-catchup all))
10492   (gnus-summary-next-group))
10493
10494 ;;;
10495 ;;; with article
10496 ;;;
10497
10498 (defmacro gnus-with-article (article &rest forms)
10499   "Select ARTICLE and perform FORMS in the original article buffer.
10500 Then replace the article with the result."
10501   `(progn
10502      ;; We don't want the article to be marked as read.
10503      (let (gnus-mark-article-hook)
10504        (gnus-summary-select-article t t nil ,article))
10505      (set-buffer gnus-original-article-buffer)
10506      ,@forms
10507      (if (not (gnus-check-backend-function
10508                'request-replace-article (car gnus-article-current)))
10509          (gnus-message 5 "Read-only group; not replacing")
10510        (unless (gnus-request-replace-article
10511                 ,article (car gnus-article-current)
10512                 (current-buffer) t)
10513          (error "Couldn't replace article")))
10514      ;; The cache and backlog have to be flushed somewhat.
10515      (when gnus-keep-backlog
10516        (gnus-backlog-remove-article
10517         (car gnus-article-current) (cdr gnus-article-current)))
10518      (when gnus-use-cache
10519        (gnus-cache-update-article
10520         (car gnus-article-current) (cdr gnus-article-current)))))
10521
10522 (put 'gnus-with-article 'lisp-indent-function 1)
10523 (put 'gnus-with-article 'edebug-form-spec '(form body))
10524
10525 ;; Thread-based commands.
10526
10527 (defun gnus-summary-articles-in-thread (&optional article)
10528   "Return a list of all articles in the current thread.
10529 If ARTICLE is non-nil, return all articles in the thread that starts
10530 with that article."
10531   (let* ((article (or article (gnus-summary-article-number)))
10532          (data (gnus-data-find-list article))
10533          (top-level (gnus-data-level (car data)))
10534          (top-subject
10535           (cond ((null gnus-thread-operation-ignore-subject)
10536                  (gnus-simplify-subject-re
10537                   (mail-header-subject (gnus-data-header (car data)))))
10538                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10539                  (gnus-simplify-subject-fuzzy
10540                   (mail-header-subject (gnus-data-header (car data)))))
10541                 (t nil)))
10542          (end-point (save-excursion
10543                       (if (gnus-summary-go-to-next-thread)
10544                           (point) (point-max))))
10545          articles)
10546     (while (and data
10547                 (< (gnus-data-pos (car data)) end-point))
10548       (when (or (not top-subject)
10549                 (string= top-subject
10550                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10551                              (gnus-simplify-subject-fuzzy
10552                               (mail-header-subject
10553                                (gnus-data-header (car data))))
10554                            (gnus-simplify-subject-re
10555                             (mail-header-subject
10556                              (gnus-data-header (car data)))))))
10557         (push (gnus-data-number (car data)) articles))
10558       (unless (and (setq data (cdr data))
10559                    (> (gnus-data-level (car data)) top-level))
10560         (setq data nil)))
10561     ;; Return the list of articles.
10562     (nreverse articles)))
10563
10564 (defun gnus-summary-rethread-current ()
10565   "Rethread the thread the current article is part of."
10566   (interactive)
10567   (let* ((gnus-show-threads t)
10568          (article (gnus-summary-article-number))
10569          (id (mail-header-id (gnus-summary-article-header)))
10570          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10571     (unless id
10572       (error "No article on the current line"))
10573     (gnus-rebuild-thread id)
10574     (gnus-summary-goto-subject article)))
10575
10576 (defun gnus-summary-reparent-thread ()
10577   "Make the current article child of the marked (or previous) article.
10578
10579 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10580 is non-nil or the Subject: of both articles are the same."
10581   (interactive)
10582   (unless (not (gnus-group-read-only-p))
10583     (error "The current newsgroup does not support article editing"))
10584   (unless (<= (length gnus-newsgroup-processable) 1)
10585     (error "No more than one article may be marked"))
10586   (save-window-excursion
10587     (let ((gnus-article-buffer " *reparent*")
10588           (current-article (gnus-summary-article-number))
10589           ;; First grab the marked article, otherwise one line up.
10590           (parent-article (if (not (null gnus-newsgroup-processable))
10591                               (car gnus-newsgroup-processable)
10592                             (save-excursion
10593                               (if (eq (forward-line -1) 0)
10594                                   (gnus-summary-article-number)
10595                                 (error "Beginning of summary buffer"))))))
10596       (unless (not (eq current-article parent-article))
10597         (error "An article may not be self-referential"))
10598       (let ((message-id (mail-header-id
10599                          (gnus-summary-article-header parent-article))))
10600         (unless (and message-id (not (equal message-id "")))
10601           (error "No message-id in desired parent"))
10602         (gnus-with-article current-article
10603           (save-restriction
10604             (goto-char (point-min))
10605             (message-narrow-to-head)
10606             (if (re-search-forward "^References: " nil t)
10607                 (progn
10608                   (re-search-forward "^[^ \t]" nil t)
10609                   (forward-line -1)
10610                   (end-of-line)
10611                   (insert " " message-id))
10612               (insert "References: " message-id "\n"))))
10613         (set-buffer gnus-summary-buffer)
10614         (gnus-summary-unmark-all-processable)
10615         (gnus-summary-update-article current-article)
10616         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10617             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10618         (gnus-summary-rethread-current)
10619         (gnus-message 3 "Article %d is now the child of article %d"
10620                       current-article parent-article)))))
10621
10622 (defun gnus-summary-toggle-threads (&optional arg)
10623   "Toggle showing conversation threads.
10624 If ARG is positive number, turn showing conversation threads on."
10625   (interactive "P")
10626   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10627     (setq gnus-show-threads
10628           (if (null arg) (not gnus-show-threads)
10629             (> (prefix-numeric-value arg) 0)))
10630     (gnus-summary-prepare)
10631     (gnus-summary-goto-subject current)
10632     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10633     (gnus-summary-position-point)))
10634
10635 (defun gnus-summary-show-all-threads ()
10636   "Show all threads."
10637   (interactive)
10638   (save-excursion
10639     (let ((buffer-read-only nil))
10640       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10641   (gnus-summary-position-point))
10642
10643 (defun gnus-summary-show-thread ()
10644   "Show thread subtrees.
10645 Returns nil if no thread was there to be shown."
10646   (interactive)
10647   (let ((buffer-read-only nil)
10648         (orig (point))
10649         (end (point-at-eol))
10650         ;; Leave point at bol
10651         (beg (progn (beginning-of-line) (point))))
10652     (prog1
10653         ;; Any hidden lines here?
10654         (search-forward "\r" end t)
10655       (subst-char-in-region beg end ?\^M ?\n t)
10656       (goto-char orig)
10657       (gnus-summary-position-point))))
10658
10659 (defun gnus-summary-maybe-hide-threads ()
10660   "If requested, hide the threads that should be hidden."
10661   (when (and gnus-show-threads
10662              gnus-thread-hide-subtree)
10663     (gnus-summary-hide-all-threads
10664      (if (or (consp gnus-thread-hide-subtree)
10665              (functionp gnus-thread-hide-subtree))
10666          (gnus-make-predicate gnus-thread-hide-subtree)
10667        nil))))
10668
10669 ;;; Hiding predicates.
10670
10671 (defun gnus-article-unread-p (header)
10672   (memq (mail-header-number header) gnus-newsgroup-unreads))
10673
10674 (defun gnus-article-unseen-p (header)
10675   (memq (mail-header-number header) gnus-newsgroup-unseen))
10676
10677 (defun gnus-map-articles (predicate articles)
10678   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10679   (apply 'gnus-or (mapcar predicate
10680                           (mapcar 'gnus-summary-article-header articles))))
10681
10682 (defun gnus-summary-hide-all-threads (&optional predicate)
10683   "Hide all thread subtrees.
10684 If PREDICATE is supplied, threads that satisfy this predicate
10685 will not be hidden."
10686   (interactive)
10687   (save-excursion
10688     (goto-char (point-min))
10689     (let ((end nil))
10690       (while (not end)
10691         (when (or (not predicate)
10692                   (gnus-map-articles
10693                    predicate (gnus-summary-article-children)))
10694             (gnus-summary-hide-thread))
10695         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10696   (gnus-summary-position-point))
10697
10698 (defun gnus-summary-hide-thread ()
10699   "Hide thread subtrees.
10700 If PREDICATE is supplied, threads that satisfy this predicate
10701 will not be hidden.
10702 Returns nil if no threads were there to be hidden."
10703   (interactive)
10704   (let ((buffer-read-only nil)
10705         (start (point))
10706         (article (gnus-summary-article-number)))
10707     (goto-char start)
10708     ;; Go forward until either the buffer ends or the subthread
10709     ;; ends.
10710     (when (and (not (eobp))
10711                (or (zerop (gnus-summary-next-thread 1 t))
10712                    (goto-char (point-max))))
10713       (prog1
10714           (if (and (> (point) start)
10715                    (search-backward "\n" start t))
10716               (progn
10717                 (subst-char-in-region start (point) ?\n ?\^M)
10718                 (gnus-summary-goto-subject article))
10719             (goto-char start)
10720             nil)))))
10721
10722 (defun gnus-summary-go-to-next-thread (&optional previous)
10723   "Go to the same level (or less) next thread.
10724 If PREVIOUS is non-nil, go to previous thread instead.
10725 Return the article number moved to, or nil if moving was impossible."
10726   (let ((level (gnus-summary-thread-level))
10727         (way (if previous -1 1))
10728         (beg (point)))
10729     (forward-line way)
10730     (while (and (not (eobp))
10731                 (< level (gnus-summary-thread-level)))
10732       (forward-line way))
10733     (if (eobp)
10734         (progn
10735           (goto-char beg)
10736           nil)
10737       (setq beg (point))
10738       (prog1
10739           (gnus-summary-article-number)
10740         (goto-char beg)))))
10741
10742 (defun gnus-summary-next-thread (n &optional silent)
10743   "Go to the same level next N'th thread.
10744 If N is negative, search backward instead.
10745 Returns the difference between N and the number of skips actually
10746 done.
10747
10748 If SILENT, don't output messages."
10749   (interactive "p")
10750   (let ((backward (< n 0))
10751         (n (abs n)))
10752     (while (and (> n 0)
10753                 (gnus-summary-go-to-next-thread backward))
10754       (decf n))
10755     (unless silent
10756       (gnus-summary-position-point))
10757     (when (and (not silent) (/= 0 n))
10758       (gnus-message 7 "No more threads"))
10759     n))
10760
10761 (defun gnus-summary-prev-thread (n)
10762   "Go to the same level previous N'th thread.
10763 Returns the difference between N and the number of skips actually
10764 done."
10765   (interactive "p")
10766   (gnus-summary-next-thread (- n)))
10767
10768 (defun gnus-summary-go-down-thread ()
10769   "Go down one level in the current thread."
10770   (let ((children (gnus-summary-article-children)))
10771     (when children
10772       (gnus-summary-goto-subject (car children)))))
10773
10774 (defun gnus-summary-go-up-thread ()
10775   "Go up one level in the current thread."
10776   (let ((parent (gnus-summary-article-parent)))
10777     (when parent
10778       (gnus-summary-goto-subject parent))))
10779
10780 (defun gnus-summary-down-thread (n)
10781   "Go down thread N steps.
10782 If N is negative, go up instead.
10783 Returns the difference between N and how many steps down that were
10784 taken."
10785   (interactive "p")
10786   (let ((up (< n 0))
10787         (n (abs n)))
10788     (while (and (> n 0)
10789                 (if up (gnus-summary-go-up-thread)
10790                   (gnus-summary-go-down-thread)))
10791       (setq n (1- n)))
10792     (gnus-summary-position-point)
10793     (when (/= 0 n)
10794       (gnus-message 7 "Can't go further"))
10795     n))
10796
10797 (defun gnus-summary-up-thread (n)
10798   "Go up thread N steps.
10799 If N is negative, go down instead.
10800 Returns the difference between N and how many steps down that were
10801 taken."
10802   (interactive "p")
10803   (gnus-summary-down-thread (- n)))
10804
10805 (defun gnus-summary-top-thread ()
10806   "Go to the top of the thread."
10807   (interactive)
10808   (while (gnus-summary-go-up-thread))
10809   (gnus-summary-article-number))
10810
10811 (defun gnus-summary-kill-thread (&optional unmark)
10812   "Mark articles under current thread as read.
10813 If the prefix argument is positive, remove any kinds of marks.
10814 If the prefix argument is negative, tick articles instead."
10815   (interactive "P")
10816   (when unmark
10817     (setq unmark (prefix-numeric-value unmark)))
10818   (let ((articles (gnus-summary-articles-in-thread)))
10819     (save-excursion
10820       ;; Expand the thread.
10821       (gnus-summary-show-thread)
10822       ;; Mark all the articles.
10823       (while articles
10824         (gnus-summary-goto-subject (car articles))
10825         (cond ((null unmark)
10826                (gnus-summary-mark-article-as-read gnus-killed-mark))
10827               ((> unmark 0)
10828                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10829               (t
10830                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10831         (setq articles (cdr articles))))
10832     ;; Hide killed subtrees.
10833     (and (null unmark)
10834          gnus-thread-hide-killed
10835          (gnus-summary-hide-thread))
10836     ;; If marked as read, go to next unread subject.
10837     (when (null unmark)
10838       ;; Go to next unread subject.
10839       (gnus-summary-next-subject 1 t)))
10840   (gnus-set-mode-line 'summary))
10841
10842 ;; Summary sorting commands
10843
10844 (defun gnus-summary-sort-by-number (&optional reverse)
10845   "Sort the summary buffer by article number.
10846 Argument REVERSE means reverse order."
10847   (interactive "P")
10848   (gnus-summary-sort 'number reverse))
10849
10850 (defun gnus-summary-sort-by-random (&optional reverse)
10851   "Randomize the order in the summary buffer.
10852 Argument REVERSE means to randomize in reverse order."
10853   (interactive "P")
10854   (gnus-summary-sort 'random reverse))
10855
10856 (defun gnus-summary-sort-by-author (&optional reverse)
10857   "Sort the summary buffer by author name alphabetically.
10858 If `case-fold-search' is non-nil, case of letters is ignored.
10859 Argument REVERSE means reverse order."
10860   (interactive "P")
10861   (gnus-summary-sort 'author reverse))
10862
10863 (defun gnus-summary-sort-by-subject (&optional reverse)
10864   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10865 If `case-fold-search' is non-nil, case of letters is ignored.
10866 Argument REVERSE means reverse order."
10867   (interactive "P")
10868   (gnus-summary-sort 'subject reverse))
10869
10870 (defun gnus-summary-sort-by-date (&optional reverse)
10871   "Sort the summary buffer by date.
10872 Argument REVERSE means reverse order."
10873   (interactive "P")
10874   (gnus-summary-sort 'date reverse))
10875
10876 (defun gnus-summary-sort-by-score (&optional reverse)
10877   "Sort the summary buffer by score.
10878 Argument REVERSE means reverse order."
10879   (interactive "P")
10880   (gnus-summary-sort 'score reverse))
10881
10882 (defun gnus-summary-sort-by-lines (&optional reverse)
10883   "Sort the summary buffer by the number of lines.
10884 Argument REVERSE means reverse order."
10885   (interactive "P")
10886   (gnus-summary-sort 'lines reverse))
10887
10888 (defun gnus-summary-sort-by-chars (&optional reverse)
10889   "Sort the summary buffer by article length.
10890 Argument REVERSE means reverse order."
10891   (interactive "P")
10892   (gnus-summary-sort 'chars reverse))
10893
10894 (defun gnus-summary-sort-by-original (&optional reverse)
10895   "Sort the summary buffer using the default sorting method.
10896 Argument REVERSE means reverse order."
10897   (interactive "P")
10898   (let* ((buffer-read-only)
10899          (gnus-summary-prepare-hook nil))
10900     ;; We do the sorting by regenerating the threads.
10901     (gnus-summary-prepare)
10902     ;; Hide subthreads if needed.
10903     (gnus-summary-maybe-hide-threads)))
10904
10905 (defun gnus-summary-sort (predicate reverse)
10906   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10907   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10908          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10909          (gnus-thread-sort-functions
10910           (if (not reverse)
10911               thread
10912             `(lambda (t1 t2)
10913                (,thread t2 t1))))
10914          (gnus-sort-gathered-threads-function
10915           gnus-thread-sort-functions)
10916          (gnus-article-sort-functions
10917           (if (not reverse)
10918               article
10919             `(lambda (t1 t2)
10920                (,article t2 t1))))
10921          (buffer-read-only)
10922          (gnus-summary-prepare-hook nil))
10923     ;; We do the sorting by regenerating the threads.
10924     (gnus-summary-prepare)
10925     ;; Hide subthreads if needed.
10926     (gnus-summary-maybe-hide-threads)))
10927
10928 ;; Summary saving commands.
10929
10930 (defun gnus-summary-save-article (&optional n not-saved)
10931   "Save the current article using the default saver function.
10932 If N is a positive number, save the N next articles.
10933 If N is a negative number, save the N previous articles.
10934 If N is nil and any articles have been marked with the process mark,
10935 save those articles instead.
10936 The variable `gnus-default-article-saver' specifies the saver function."
10937   (interactive "P")
10938   (let* ((articles (gnus-summary-work-articles n))
10939          (save-buffer (save-excursion
10940                         (nnheader-set-temp-buffer " *Gnus Save*")))
10941          (num (length articles))
10942          header file)
10943     (dolist (article articles)
10944       (setq header (gnus-summary-article-header article))
10945       (if (not (vectorp header))
10946           ;; This is a pseudo-article.
10947           (if (assq 'name header)
10948               (gnus-copy-file (cdr (assq 'name header)))
10949             (gnus-message 1 "Article %d is unsaveable" article))
10950         ;; This is a real article.
10951         (save-window-excursion
10952           (let ((gnus-display-mime-function nil)
10953                 (gnus-article-prepare-hook nil))
10954             (gnus-summary-select-article t nil nil article)))
10955         (save-excursion
10956           (set-buffer save-buffer)
10957           (erase-buffer)
10958           (insert-buffer-substring gnus-original-article-buffer))
10959         (setq file (gnus-article-save save-buffer file num))
10960         (gnus-summary-remove-process-mark article)
10961         (unless not-saved
10962           (gnus-summary-set-saved-mark article))))
10963     (gnus-kill-buffer save-buffer)
10964     (gnus-summary-position-point)
10965     (gnus-set-mode-line 'summary)
10966     n))
10967
10968 (defun gnus-summary-pipe-output (&optional arg headers)
10969   "Pipe the current article to a subprocess.
10970 If N is a positive number, pipe the N next articles.
10971 If N is a negative number, pipe the N previous articles.
10972 If N is nil and any articles have been marked with the process mark,
10973 pipe those articles instead.
10974 If HEADERS (the symbolic prefix), include the headers, too."
10975   (interactive (gnus-interactive "P\ny"))
10976   (require 'gnus-art)
10977   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10978         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10979     (gnus-summary-save-article arg t))
10980   (let ((buffer (get-buffer "*Shell Command Output*")))
10981     (when (and buffer
10982                (not (zerop (buffer-size buffer))))
10983       (gnus-configure-windows 'pipe))))
10984
10985 (defun gnus-summary-save-article-mail (&optional arg)
10986   "Append the current article to an mail file.
10987 If N is a positive number, save the N next articles.
10988 If N is a negative number, save the N previous articles.
10989 If N is nil and any articles have been marked with the process mark,
10990 save those articles instead."
10991   (interactive "P")
10992   (require 'gnus-art)
10993   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10994     (gnus-summary-save-article arg)))
10995
10996 (defun gnus-summary-save-article-rmail (&optional arg)
10997   "Append the current article to an rmail file.
10998 If N is a positive number, save the N next articles.
10999 If N is a negative number, save the N previous articles.
11000 If N is nil and any articles have been marked with the process mark,
11001 save those articles instead."
11002   (interactive "P")
11003   (require 'gnus-art)
11004   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11005     (gnus-summary-save-article arg)))
11006
11007 (defun gnus-summary-save-article-file (&optional arg)
11008   "Append the current article to a file.
11009 If N is a positive number, save the N next articles.
11010 If N is a negative number, save the N previous articles.
11011 If N is nil and any articles have been marked with the process mark,
11012 save those articles instead."
11013   (interactive "P")
11014   (require 'gnus-art)
11015   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11016     (gnus-summary-save-article arg)))
11017
11018 (defun gnus-summary-write-article-file (&optional arg)
11019   "Write the current article to a file, deleting the previous file.
11020 If N is a positive number, save the N next articles.
11021 If N is a negative number, save the N previous articles.
11022 If N is nil and any articles have been marked with the process mark,
11023 save those articles instead."
11024   (interactive "P")
11025   (require 'gnus-art)
11026   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11027     (gnus-summary-save-article arg)))
11028
11029 (defun gnus-summary-save-article-body-file (&optional arg)
11030   "Append the current article body to a file.
11031 If N is a positive number, save the N next articles.
11032 If N is a negative number, save the N previous articles.
11033 If N is nil and any articles have been marked with the process mark,
11034 save those articles instead."
11035   (interactive "P")
11036   (require 'gnus-art)
11037   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11038     (gnus-summary-save-article arg)))
11039
11040 (defun gnus-summary-muttprint (&optional arg)
11041   "Print the current article using Muttprint.
11042 If N is a positive number, save the N next articles.
11043 If N is a negative number, save the N previous articles.
11044 If N is nil and any articles have been marked with the process mark,
11045 save those articles instead."
11046   (interactive "P")
11047   (require 'gnus-art)
11048   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11049     (gnus-summary-save-article arg t)))
11050
11051 (defun gnus-summary-pipe-message (program)
11052   "Pipe the current article through PROGRAM."
11053   (interactive "sProgram: ")
11054   (gnus-summary-select-article)
11055   (let ((mail-header-separator ""))
11056     (gnus-eval-in-buffer-window gnus-article-buffer
11057       (save-restriction
11058         (widen)
11059         (let ((start (window-start))
11060               buffer-read-only)
11061           (message-pipe-buffer-body program)
11062           (set-window-start (get-buffer-window (current-buffer)) start))))))
11063
11064 (defun gnus-get-split-value (methods)
11065   "Return a value based on the split METHODS."
11066   (let (split-name method result match)
11067     (when methods
11068       (save-excursion
11069         (set-buffer gnus-original-article-buffer)
11070         (save-restriction
11071           (nnheader-narrow-to-headers)
11072           (while (and methods (not split-name))
11073             (goto-char (point-min))
11074             (setq method (pop methods))
11075             (setq match (car method))
11076             (when (cond
11077                    ((stringp match)
11078                     ;; Regular expression.
11079                     (ignore-errors
11080                       (re-search-forward match nil t)))
11081                    ((functionp match)
11082                     ;; Function.
11083                     (save-restriction
11084                       (widen)
11085                       (setq result (funcall match gnus-newsgroup-name))))
11086                    ((consp match)
11087                     ;; Form.
11088                     (save-restriction
11089                       (widen)
11090                       (setq result (eval match)))))
11091               (setq split-name (cdr method))
11092               (cond ((stringp result)
11093                      (push (expand-file-name
11094                             result gnus-article-save-directory)
11095                            split-name))
11096                     ((consp result)
11097                      (setq split-name (append result split-name)))))))))
11098     (nreverse split-name)))
11099
11100 (defun gnus-valid-move-group-p (group)
11101   (and (boundp group)
11102        (symbol-name group)
11103        (symbol-value group)
11104        (gnus-get-function (gnus-find-method-for-group
11105                            (symbol-name group)) 'request-accept-article t)))
11106
11107 (defun gnus-read-move-group-name (prompt default articles prefix)
11108   "Read a group name."
11109   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11110          (minibuffer-confirm-incomplete nil) ; XEmacs
11111          (prom
11112           (format "%s %s to:"
11113                   prompt
11114                   (if (> (length articles) 1)
11115                       (format "these %d articles" (length articles))
11116                     "this article")))
11117          (to-newsgroup
11118           (cond
11119            ((null split-name)
11120             (gnus-completing-read-with-default
11121              default prom
11122              gnus-active-hashtb
11123              'gnus-valid-move-group-p
11124              nil prefix
11125              'gnus-group-history))
11126            ((= 1 (length split-name))
11127             (gnus-completing-read-with-default
11128              (car split-name) prom
11129              gnus-active-hashtb
11130              'gnus-valid-move-group-p
11131              nil nil
11132              'gnus-group-history))
11133            (t
11134             (gnus-completing-read-with-default
11135              nil prom
11136              (mapcar 'list (nreverse split-name))
11137              nil nil nil
11138              'gnus-group-history))))
11139          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11140     (when to-newsgroup
11141       (if (or (string= to-newsgroup "")
11142               (string= to-newsgroup prefix))
11143           (setq to-newsgroup default))
11144       (unless to-newsgroup
11145         (error "No group name entered"))
11146       (or (gnus-active to-newsgroup)
11147           (gnus-activate-group to-newsgroup nil nil to-method)
11148           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11149                                      to-newsgroup))
11150               (or (and (gnus-request-create-group to-newsgroup to-method)
11151                        (gnus-activate-group
11152                         to-newsgroup nil nil to-method)
11153                        (gnus-subscribe-group to-newsgroup))
11154                   (error "Couldn't create group %s" to-newsgroup)))
11155           (error "No such group: %s" to-newsgroup)))
11156     to-newsgroup))
11157
11158 (defun gnus-summary-save-parts (type dir n &optional reverse)
11159   "Save parts matching TYPE to DIR.
11160 If REVERSE, save parts that do not match TYPE."
11161   (interactive
11162    (list (read-string "Save parts of type: "
11163                       (or (car gnus-summary-save-parts-type-history)
11164                           gnus-summary-save-parts-default-mime)
11165                       'gnus-summary-save-parts-type-history)
11166          (setq gnus-summary-save-parts-last-directory
11167                (read-file-name "Save to directory: "
11168                                gnus-summary-save-parts-last-directory
11169                                nil t))
11170          current-prefix-arg))
11171   (gnus-summary-iterate n
11172     (let ((gnus-display-mime-function nil)
11173           (gnus-inhibit-treatment t))
11174       (gnus-summary-select-article))
11175     (save-excursion
11176       (set-buffer gnus-article-buffer)
11177       (let ((handles (or gnus-article-mime-handles
11178                          (mm-dissect-buffer nil gnus-article-loose-mime)
11179                          (and gnus-article-emulate-mime
11180                               (mm-uu-dissect)))))
11181         (when handles
11182           (gnus-summary-save-parts-1 type dir handles reverse)
11183           (unless gnus-article-mime-handles ;; Don't destroy this case.
11184             (mm-destroy-parts handles)))))))
11185
11186 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11187   (if (stringp (car handle))
11188       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11189               (cdr handle))
11190     (when (if reverse
11191               (not (string-match type (mm-handle-media-type handle)))
11192             (string-match type (mm-handle-media-type handle)))
11193       (let ((file (expand-file-name
11194                    (gnus-map-function
11195                     mm-file-name-rewrite-functions
11196                     (file-name-nondirectory
11197                      (or
11198                       (mail-content-type-get
11199                        (mm-handle-disposition handle) 'filename)
11200                       (mail-content-type-get
11201                        (mm-handle-type handle) 'name)
11202                       (concat gnus-newsgroup-name
11203                               "." (number-to-string
11204                                    (cdr gnus-article-current))))))
11205                    dir)))
11206         (unless (file-exists-p file)
11207           (mm-save-part-to-file handle file))))))
11208
11209 ;; Summary extract commands
11210
11211 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11212   (let ((buffer-read-only nil)
11213         (article (gnus-summary-article-number))
11214         after-article b e)
11215     (unless (gnus-summary-goto-subject article)
11216       (error "No such article: %d" article))
11217     (gnus-summary-position-point)
11218     ;; If all commands are to be bunched up on one line, we collect
11219     ;; them here.
11220     (unless gnus-view-pseudos-separately
11221       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11222             files action)
11223         (while ps
11224           (setq action (cdr (assq 'action (car ps))))
11225           (setq files (list (cdr (assq 'name (car ps)))))
11226           (while (and ps (cdr ps)
11227                       (string= (or action "1")
11228                                (or (cdr (assq 'action (cadr ps))) "2")))
11229             (push (cdr (assq 'name (cadr ps))) files)
11230             (setcdr ps (cddr ps)))
11231           (when files
11232             (when (not (string-match "%s" action))
11233               (push " " files))
11234             (push " " files)
11235             (when (assq 'execute (car ps))
11236               (setcdr (assq 'execute (car ps))
11237                       (funcall (if (string-match "%s" action)
11238                                    'format 'concat)
11239                                action
11240                                (mapconcat
11241                                 (lambda (f)
11242                                   (if (equal f " ")
11243                                       f
11244                                     (shell-quote-argument f)))
11245                                 files " ")))))
11246           (setq ps (cdr ps)))))
11247     (if (and gnus-view-pseudos (not not-view))
11248         (while pslist
11249           (when (assq 'execute (car pslist))
11250             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11251                                   (eq gnus-view-pseudos 'not-confirm)))
11252           (setq pslist (cdr pslist)))
11253       (save-excursion
11254         (while pslist
11255           (setq after-article (or (cdr (assq 'article (car pslist)))
11256                                   (gnus-summary-article-number)))
11257           (gnus-summary-goto-subject after-article)
11258           (forward-line 1)
11259           (setq b (point))
11260           (insert "    " (file-name-nondirectory
11261                           (cdr (assq 'name (car pslist))))
11262                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11263           (setq e (point))
11264           (forward-line -1)             ; back to `b'
11265           (gnus-add-text-properties
11266            b (1- e) (list 'gnus-number gnus-reffed-article-number
11267                           gnus-mouse-face-prop gnus-mouse-face))
11268           (gnus-data-enter
11269            after-article gnus-reffed-article-number
11270            gnus-unread-mark b (car pslist) 0 (- e b))
11271           (setq gnus-newsgroup-unreads
11272                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11273                                          gnus-reffed-article-number))
11274           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11275           (setq pslist (cdr pslist)))))))
11276
11277 (defun gnus-pseudos< (p1 p2)
11278   (let ((c1 (cdr (assq 'action p1)))
11279         (c2 (cdr (assq 'action p2))))
11280     (and c1 c2 (string< c1 c2))))
11281
11282 (defun gnus-request-pseudo-article (props)
11283   (cond ((assq 'execute props)
11284          (gnus-execute-command (cdr (assq 'execute props)))))
11285   (let ((gnus-current-article (gnus-summary-article-number)))
11286     (gnus-run-hooks 'gnus-mark-article-hook)))
11287
11288 (defun gnus-execute-command (command &optional automatic)
11289   (save-excursion
11290     (gnus-article-setup-buffer)
11291     (set-buffer gnus-article-buffer)
11292     (setq buffer-read-only nil)
11293     (let ((command (if automatic command
11294                      (read-string "Command: " (cons command 0)))))
11295       (erase-buffer)
11296       (insert "$ " command "\n\n")
11297       (if gnus-view-pseudo-asynchronously
11298           (start-process "gnus-execute" (current-buffer) shell-file-name
11299                          shell-command-switch command)
11300         (call-process shell-file-name nil t nil
11301                       shell-command-switch command)))))
11302
11303 ;; Summary kill commands.
11304
11305 (defun gnus-summary-edit-global-kill (article)
11306   "Edit the \"global\" kill file."
11307   (interactive (list (gnus-summary-article-number)))
11308   (gnus-group-edit-global-kill article))
11309
11310 (defun gnus-summary-edit-local-kill ()
11311   "Edit a local kill file applied to the current newsgroup."
11312   (interactive)
11313   (setq gnus-current-headers (gnus-summary-article-header))
11314   (gnus-group-edit-local-kill
11315    (gnus-summary-article-number) gnus-newsgroup-name))
11316
11317 ;;; Header reading.
11318
11319 (defun gnus-read-header (id &optional header)
11320   "Read the headers of article ID and enter them into the Gnus system."
11321   (let ((group gnus-newsgroup-name)
11322         (gnus-override-method
11323          (or
11324           gnus-override-method
11325           (and (gnus-news-group-p gnus-newsgroup-name)
11326                (car (gnus-refer-article-methods)))))
11327         where)
11328     ;; First we check to see whether the header in question is already
11329     ;; fetched.
11330     (if (stringp id)
11331         ;; This is a Message-ID.
11332         (setq header (or header (gnus-id-to-header id)))
11333       ;; This is an article number.
11334       (setq header (or header (gnus-summary-article-header id))))
11335     (if (and header
11336              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11337         ;; We have found the header.
11338         header
11339       ;; We have to really fetch the header to this article.
11340       (save-excursion
11341         (set-buffer nntp-server-buffer)
11342         (when (setq where (gnus-request-head id group))
11343           (nnheader-fold-continuation-lines)
11344           (goto-char (point-max))
11345           (insert ".\n")
11346           (goto-char (point-min))
11347           (insert "211 ")
11348           (princ (cond
11349                   ((numberp id) id)
11350                   ((cdr where) (cdr where))
11351                   (header (mail-header-number header))
11352                   (t gnus-reffed-article-number))
11353                  (current-buffer))
11354           (insert " Article retrieved.\n"))
11355         (if (or (not where)
11356                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11357             ()                          ; Malformed head.
11358           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11359             (when (and (stringp id)
11360                        (not (string= (gnus-group-real-name group)
11361                                      (car where))))
11362               ;; If we fetched by Message-ID and the article came
11363               ;; from a different group, we fudge some bogus article
11364               ;; numbers for this article.
11365               (mail-header-set-number header gnus-reffed-article-number))
11366             (save-excursion
11367               (set-buffer gnus-summary-buffer)
11368               (decf gnus-reffed-article-number)
11369               (gnus-remove-header (mail-header-number header))
11370               (push header gnus-newsgroup-headers)
11371               (setq gnus-current-headers header)
11372               (push (mail-header-number header) gnus-newsgroup-limit)))
11373           header)))))
11374
11375 (defun gnus-remove-header (number)
11376   "Remove header NUMBER from `gnus-newsgroup-headers'."
11377   (if (and gnus-newsgroup-headers
11378            (= number (mail-header-number (car gnus-newsgroup-headers))))
11379       (pop gnus-newsgroup-headers)
11380     (let ((headers gnus-newsgroup-headers))
11381       (while (and (cdr headers)
11382                   (not (= number (mail-header-number (cadr headers)))))
11383         (pop headers))
11384       (when (cdr headers)
11385         (setcdr headers (cddr headers))))))
11386
11387 ;;;
11388 ;;; summary highlights
11389 ;;;
11390
11391 (defun gnus-highlight-selected-summary ()
11392   "Highlight selected article in summary buffer."
11393   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11394   (when gnus-summary-selected-face
11395     (save-excursion
11396       (let* ((beg (point-at-bol))
11397              (end (point-at-eol))
11398              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11399              (from (if (get-text-property beg gnus-mouse-face-prop)
11400                        beg
11401                      (or (next-single-property-change
11402                           beg gnus-mouse-face-prop nil end)
11403                          beg)))
11404              (to
11405               (if (= from end)
11406                   (- from 2)
11407                 (or (next-single-property-change
11408                      from gnus-mouse-face-prop nil end)
11409                     end))))
11410         ;; If no mouse-face prop on line we will have to = from = end,
11411         ;; so we highlight the entire line instead.
11412         (when (= (+ to 2) from)
11413           (setq from beg)
11414           (setq to end))
11415         (if gnus-newsgroup-selected-overlay
11416             ;; Move old overlay.
11417             (gnus-move-overlay
11418              gnus-newsgroup-selected-overlay from to (current-buffer))
11419           ;; Create new overlay.
11420           (gnus-overlay-put
11421            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11422            'face gnus-summary-selected-face))))))
11423
11424 (defvar gnus-summary-highlight-line-cached nil)
11425 (defvar gnus-summary-highlight-line-trigger nil)
11426
11427 (defun gnus-summary-highlight-line-0 ()
11428   (if (and (eq gnus-summary-highlight-line-trigger
11429                gnus-summary-highlight)
11430            gnus-summary-highlight-line-cached)
11431       gnus-summary-highlight-line-cached
11432     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11433           gnus-summary-highlight-line-cached
11434           (let* ((cond (list 'cond))
11435                  (c cond)
11436                  (list gnus-summary-highlight))
11437             (while list
11438               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11439                               nil))
11440               (setq c (cdr c)
11441                     list (cdr list)))
11442             (gnus-byte-compile (list 'lambda nil cond))))))
11443
11444 (defun gnus-summary-highlight-line ()
11445   "Highlight current line according to `gnus-summary-highlight'."
11446   (let* ((beg (point-at-bol))
11447          (article (or (gnus-summary-article-number) gnus-current-article))
11448          (score (or (cdr (assq article
11449                                gnus-newsgroup-scored))
11450                     gnus-summary-default-score 0))
11451          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11452          (inhibit-read-only t)
11453          (default gnus-summary-default-score)
11454          (default-high gnus-summary-default-high-score)
11455          (default-low gnus-summary-default-low-score)
11456          (uncached (and gnus-summary-use-undownloaded-faces
11457                         (memq article gnus-newsgroup-undownloaded)
11458                         (not (memq article gnus-newsgroup-cached)))))
11459     (let ((face (funcall (gnus-summary-highlight-line-0))))
11460       (unless (eq face (get-text-property beg 'face))
11461         (gnus-put-text-property-excluding-characters-with-faces
11462          beg (point-at-eol) 'face
11463          (setq face (if (boundp face) (symbol-value face) face)))
11464         (when gnus-summary-highlight-line-function
11465           (funcall gnus-summary-highlight-line-function article face))))))
11466
11467 (defun gnus-update-read-articles (group unread &optional compute)
11468   "Update the list of read articles in GROUP.
11469 UNREAD is a sorted list."
11470   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11471         (info (gnus-get-info group))
11472         (prev 1)
11473         read)
11474     (if (or (not info) (not active))
11475         ;; There is no info on this group if it was, in fact,
11476         ;; killed.  Gnus stores no information on killed groups, so
11477         ;; there's nothing to be done.
11478         ;; One could store the information somewhere temporarily,
11479         ;; perhaps...  Hmmm...
11480         ()
11481       ;; Remove any negative articles numbers.
11482       (while (and unread (< (car unread) 0))
11483         (setq unread (cdr unread)))
11484       ;; Remove any expired article numbers
11485       (while (and unread (< (car unread) (car active)))
11486         (setq unread (cdr unread)))
11487       ;; Compute the ranges of read articles by looking at the list of
11488       ;; unread articles.
11489       (while unread
11490         (when (/= (car unread) prev)
11491           (push (if (= prev (1- (car unread))) prev
11492                   (cons prev (1- (car unread))))
11493                 read))
11494         (setq prev (1+ (car unread)))
11495         (setq unread (cdr unread)))
11496       (when (<= prev (cdr active))
11497         (push (cons prev (cdr active)) read))
11498       (setq read (if (> (length read) 1) (nreverse read) read))
11499       (if compute
11500           read
11501         (save-excursion
11502           (let (setmarkundo)
11503             ;; Propagate the read marks to the backend.
11504             (when (gnus-check-backend-function 'request-set-mark group)
11505               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11506                     (add (gnus-remove-from-range read (gnus-info-read info))))
11507                 (when (or add del)
11508                   (unless (gnus-check-group group)
11509                     (error "Can't open server for %s" group))
11510                   (gnus-request-set-mark
11511                    group (delq nil (list (if add (list add 'add '(read)))
11512                                          (if del (list del 'del '(read))))))
11513                   (setq setmarkundo
11514                         `(gnus-request-set-mark
11515                           ,group
11516                           ',(delq nil (list
11517                                        (if del (list del 'add '(read)))
11518                                        (if add (list add 'del '(read))))))))))
11519             (set-buffer gnus-group-buffer)
11520             (gnus-undo-register
11521               `(progn
11522                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11523                  (gnus-info-set-read ',info ',(gnus-info-read info))
11524                  (gnus-get-unread-articles-in-group ',info
11525                                                     (gnus-active ,group))
11526                  (gnus-group-update-group ,group t)
11527                  ,setmarkundo))))
11528         ;; Enter this list into the group info.
11529         (gnus-info-set-read info read)
11530         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11531         (gnus-get-unread-articles-in-group info (gnus-active group))
11532         t))))
11533
11534 (defun gnus-offer-save-summaries ()
11535   "Offer to save all active summary buffers."
11536   (let (buffers)
11537     ;; Go through all buffers and find all summaries.
11538     (dolist (buffer (buffer-list))
11539       (when (and (setq buffer (buffer-name buffer))
11540                  (string-match "Summary" buffer)
11541                  (with-current-buffer buffer
11542                    ;; We check that this is, indeed, a summary buffer.
11543                    (and (eq major-mode 'gnus-summary-mode)
11544                         ;; Also make sure this isn't bogus.
11545                         gnus-newsgroup-prepared
11546                         ;; Also make sure that this isn't a
11547                         ;; dead summary buffer.
11548                         (not gnus-dead-summary-mode))))
11549         (push buffer buffers)))
11550     ;; Go through all these summary buffers and offer to save them.
11551     (when buffers
11552       (save-excursion
11553         (map-y-or-n-p
11554          "Update summary buffer %s? "
11555          (lambda (buf)
11556            (switch-to-buffer buf)
11557            (gnus-summary-exit))
11558          buffers)))))
11559
11560
11561 ;;; @ for mime-partial
11562 ;;;
11563
11564 (defun gnus-request-partial-message ()
11565   (save-excursion
11566     (let ((number (gnus-summary-article-number))
11567           (group gnus-newsgroup-name)
11568           (mother gnus-article-buffer))
11569       (set-buffer (get-buffer-create " *Partial Article*"))
11570       (erase-buffer)
11571       (setq mime-preview-buffer mother)
11572       (gnus-request-article-this-buffer number group)
11573       (mime-parse-buffer)
11574       )))
11575
11576 (autoload 'mime-combine-message/partial-pieces-automatically
11577   "mime-partial"
11578   "Internal method to combine message/partial messages automatically.")
11579
11580 (mime-add-condition
11581  'action '((type . message)(subtype . partial)
11582            (major-mode . gnus-original-article-mode)
11583            (method . mime-combine-message/partial-pieces-automatically)
11584            (summary-buffer-exp . gnus-summary-buffer)
11585            (request-partial-message-method . gnus-request-partial-message)
11586            ))
11587
11588
11589 ;;; @ for message/rfc822
11590 ;;;
11591
11592 (defun gnus-mime-extract-message/rfc822 (entity situation)
11593   "Burst a forwarded article."
11594   (save-excursion
11595     (set-buffer gnus-summary-buffer)
11596     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11597                                    gnus-newsgroup-name 'gnus-group-history))
11598            (gnus-group-marked (list group))
11599            article info)
11600       (with-temp-buffer
11601         (mime-insert-entity-content entity)
11602         (setq article (gnus-request-accept-article group)))
11603       (when (and (consp article)
11604                  (numberp (setq article (cdr article))))
11605         (setq info (gnus-get-info group))
11606         (gnus-info-set-read info
11607                             (gnus-remove-from-range (gnus-info-read info)
11608                                                     (list article)))
11609         (when (string-equal group gnus-newsgroup-name)
11610           (forward-line 1)
11611           (let (gnus-show-threads)
11612             (gnus-summary-goto-subject article t))
11613           (gnus-summary-clear-mark-forward 1))
11614         (set-buffer gnus-group-buffer)
11615         (gnus-group-get-new-news-this-group nil t)))))
11616
11617 (mime-add-condition
11618  'action '((type . message)(subtype . rfc822)
11619            (major-mode . gnus-original-article-mode)
11620            (method . gnus-mime-extract-message/rfc822)
11621            (mode . "extract")
11622            ))
11623
11624 (mime-add-condition
11625  'action '((type . message)(subtype . news)
11626            (major-mode . gnus-original-article-mode)
11627            (method . gnus-mime-extract-message/rfc822)
11628            (mode . "extract")
11629            ))
11630
11631 (defun gnus-mime-extract-multipart (entity situation)
11632   (let ((children (mime-entity-children entity))
11633         mime-acting-situation-to-override
11634         f)
11635     (while children
11636       (mime-play-entity (car children)
11637                         (cons (assq 'mode situation)
11638                               mime-acting-situation-to-override))
11639       (setq children (cdr children)))
11640     (if (setq f (cdr (assq 'after-method
11641                            mime-acting-situation-to-override)))
11642         (eval f)
11643       )))
11644
11645 (mime-add-condition
11646  'action '((type . multipart)
11647            (method . gnus-mime-extract-multipart)
11648            (mode . "extract")
11649            )
11650  'with-default)
11651
11652
11653 ;;; @ end
11654 ;;;
11655
11656 (defun gnus-summary-inherit-default-charset ()
11657   "Import `default-mime-charset' from summary buffer.
11658 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11659 of FLIM is used."
11660   (if (buffer-live-p gnus-summary-buffer)
11661       (let (d-m-c d-m-c-u)
11662         (with-current-buffer gnus-summary-buffer
11663           (setq d-m-c (if (local-variable-p 'default-mime-charset
11664                                             gnus-summary-buffer)
11665                           default-mime-charset
11666                         t)
11667                 ;; LIMIT
11668                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11669                                               gnus-summary-buffer)
11670                             (symbol-value 'default-mime-charset-unlimited)
11671                           t)))
11672         (if (eq t d-m-c)
11673             (kill-local-variable 'default-mime-charset)
11674           (set (make-local-variable 'default-mime-charset) d-m-c))
11675         (if (eq t d-m-c-u)
11676             (kill-local-variable 'default-mime-charset-unlimited)
11677           (set (make-local-variable 'default-mime-charset-unlimited)
11678                d-m-c-u)))))
11679
11680 (defun gnus-summary-setup-default-charset ()
11681   "Setup newsgroup default charset."
11682   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11683       (progn
11684         (setq gnus-newsgroup-charset nil)
11685         (set (make-local-variable 'default-mime-charset) nil)
11686         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11687           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11688     (let ((ignored-charsets
11689            (or gnus-newsgroup-ephemeral-ignored-charsets
11690                (append
11691                 (and gnus-newsgroup-name
11692                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11693                 gnus-newsgroup-ignored-charsets)))
11694           charset)
11695       (setq gnus-newsgroup-charset
11696             (or gnus-newsgroup-ephemeral-charset
11697                 (when (and gnus-newsgroup-name
11698                            (setq charset (gnus-parameter-charset
11699                                           gnus-newsgroup-name)))
11700                   (make-local-variable 'default-mime-charset)
11701                   (setq default-mime-charset charset))
11702                 gnus-default-charset))
11703       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11704            ignored-charsets))))
11705
11706 ;;;
11707 ;;; Mime Commands
11708 ;;;
11709
11710 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11711   "Display the current article buffer fully MIME-buttonized.
11712 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11713 treated as multipart/mixed."
11714   (interactive "P")
11715   (require 'gnus-art)
11716   (let ((gnus-unbuttonized-mime-types nil)
11717         (gnus-mime-display-multipart-as-mixed show-all-parts))
11718     (gnus-summary-show-article)))
11719
11720 (defun gnus-summary-repair-multipart (article)
11721   "Add a Content-Type header to a multipart article without one."
11722   (interactive (list (gnus-summary-article-number)))
11723   (gnus-with-article article
11724     (message-narrow-to-head)
11725     (message-remove-header "Mime-Version")
11726     (goto-char (point-max))
11727     (insert "Mime-Version: 1.0\n")
11728     (widen)
11729     (when (search-forward "\n--" nil t)
11730       (let ((separator (buffer-substring (point) (point-at-eol))))
11731         (message-narrow-to-head)
11732         (message-remove-header "Content-Type")
11733         (goto-char (point-max))
11734         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11735                         separator))
11736         (widen))))
11737   (let (gnus-mark-article-hook)
11738     (gnus-summary-select-article t t nil article)))
11739
11740 (defun gnus-summary-toggle-display-buttonized ()
11741   "Toggle the buttonizing of the article buffer."
11742   (interactive)
11743   (require 'gnus-art)
11744   (if (setq gnus-inhibit-mime-unbuttonizing
11745             (not gnus-inhibit-mime-unbuttonizing))
11746       (let ((gnus-unbuttonized-mime-types nil))
11747         (gnus-summary-show-article))
11748     (gnus-summary-show-article)))
11749
11750 ;;;
11751 ;;; Intelli-mouse commmands
11752 ;;;
11753
11754 (defun gnus-wheel-summary-scroll (event)
11755   (interactive "e")
11756   (let ((amount (if (memq 'shift (event-modifiers event))
11757                     (car gnus-wheel-scroll-amount)
11758                   (cdr gnus-wheel-scroll-amount)))
11759         (direction (- (* (static-if (featurep 'xemacs)
11760                              (event-button event)
11761                            (cond ((eq 'mouse-4 (event-basic-type event))
11762                                   4)
11763                                  ((eq 'mouse-5 (event-basic-type event))
11764                                   5)))
11765                          2) 9))
11766         edge)
11767     (gnus-summary-scroll-up (* amount direction))
11768     (when (gnus-eval-in-buffer-window gnus-article-buffer
11769             (save-restriction
11770               (widen)
11771               (and (if (< 0 direction)
11772                        (gnus-article-next-page 0)
11773                      (gnus-article-prev-page 0)
11774                      (bobp))
11775                    (if (setq edge (get-text-property
11776                                    (point-min) 'gnus-wheel-edge))
11777                        (setq edge (* edge direction))
11778                      (setq edge -1))
11779                    (or (plusp edge)
11780                        (let ((buffer-read-only nil)
11781                              (inhibit-read-only t))
11782                          (put-text-property (point-min) (point-max)
11783                                             'gnus-wheel-edge direction)
11784                          nil))
11785                    (or (> edge gnus-wheel-edge-resistance)
11786                        (let ((buffer-read-only nil)
11787                              (inhibit-read-only t))
11788                          (put-text-property (point-min) (point-max)
11789                                             'gnus-wheel-edge
11790                                             (* (1+ edge) direction))
11791                          nil))
11792                    (eq last-command 'gnus-wheel-summary-scroll))))
11793       (gnus-summary-next-article nil nil (minusp direction)))))
11794
11795 (defun gnus-wheel-install ()
11796   "Enable mouse wheel support on summary window."
11797   (when gnus-use-wheel
11798     (let ((keys
11799            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11800       (dolist (key keys)
11801         (define-key gnus-summary-mode-map key
11802           'gnus-wheel-summary-scroll)))))
11803
11804 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11805
11806 ;;;
11807 ;;; Traditional PGP commmands
11808 ;;;
11809
11810 (defun gnus-summary-decrypt-article (&optional force)
11811   "Decrypt the current article in traditional PGP way.
11812 This will have permanent effect only in mail groups.
11813 If FORCE is non-nil, allow editing of articles even in read-only
11814 groups."
11815   (interactive "P")
11816   (gnus-summary-select-article t)
11817   (gnus-eval-in-buffer-window gnus-article-buffer
11818     (save-excursion
11819       (save-restriction
11820         (widen)
11821         (goto-char (point-min))
11822         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11823           (error "Not a traditional PGP message!"))
11824         (let ((armor-start (match-beginning 0)))
11825           (if (and (pgg-decrypt-region armor-start (point-max))
11826                    (or force (not (gnus-group-read-only-p))))
11827               (let ((inhibit-read-only t)
11828                     buffer-read-only)
11829                 (delete-region armor-start
11830                                (progn
11831                                  (re-search-forward "^-+END PGP" nil t)
11832                                  (beginning-of-line 2)
11833                                  (point)))
11834                 (insert-buffer-substring pgg-output-buffer))))))))
11835
11836 (defun gnus-summary-verify-article ()
11837   "Verify the current article in traditional PGP way."
11838   (interactive)
11839   (save-excursion
11840     (set-buffer gnus-original-article-buffer)
11841     (goto-char (point-min))
11842     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11843       (error "Not a traditional PGP message!"))
11844     (re-search-forward "^-+END PGP" nil t)
11845     (beginning-of-line 2)
11846     (call-interactively (function pgg-verify-region))))
11847
11848 ;;;
11849 ;;; Generic summary marking commands
11850 ;;;
11851
11852 (defvar gnus-summary-marking-alist
11853   '((read gnus-del-mark "d")
11854     (unread gnus-unread-mark "u")
11855     (ticked gnus-ticked-mark "!")
11856     (dormant gnus-dormant-mark "?")
11857     (expirable gnus-expirable-mark "e"))
11858   "An alist of names/marks/keystrokes.")
11859
11860 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11861 (defvar gnus-summary-mark-map)
11862
11863 (defun gnus-summary-make-all-marking-commands ()
11864   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11865   (dolist (elem gnus-summary-marking-alist)
11866     (apply 'gnus-summary-make-marking-command elem)))
11867
11868 (defun gnus-summary-make-marking-command (name mark keystroke)
11869   (let ((map (make-sparse-keymap)))
11870     (define-key gnus-summary-generic-mark-map keystroke map)
11871     (dolist (lway `((next "next" next nil "n")
11872                     (next-unread "next unread" next t "N")
11873                     (prev "previous" prev nil "p")
11874                     (prev-unread "previous unread" prev t "P")
11875                     (nomove "" nil nil ,keystroke)))
11876       (let ((func (gnus-summary-make-marking-command-1
11877                    mark (car lway) lway name)))
11878         (setq func (eval func))
11879         (define-key map (nth 4 lway) func)))))
11880
11881 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11882   `(defun ,(intern
11883             (format "gnus-summary-put-mark-as-%s%s"
11884                     name (if (eq way 'nomove)
11885                              ""
11886                            (concat "-" (symbol-name way)))))
11887      (n)
11888      ,(format
11889        "Mark the current article as %s%s.
11890 If N, the prefix, then repeat N times.
11891 If N is negative, move in reverse order.
11892 The difference between N and the actual number of articles marked is
11893 returned."
11894        name (car (cdr lway)))
11895      (interactive "p")
11896      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11897
11898 (defun gnus-summary-generic-mark (n mark move unread)
11899   "Mark N articles with MARK."
11900   (unless (eq major-mode 'gnus-summary-mode)
11901     (error "This command can only be used in the summary buffer"))
11902   (gnus-summary-show-thread)
11903   (let ((nummove
11904          (cond
11905           ((eq move 'next) 1)
11906           ((eq move 'prev) -1)
11907           (t 0))))
11908     (if (zerop nummove)
11909         (setq n 1)
11910       (when (< n 0)
11911         (setq n (abs n)
11912               nummove (* -1 nummove))))
11913     (while (and (> n 0)
11914                 (gnus-summary-mark-article nil mark)
11915                 (zerop (gnus-summary-next-subject nummove unread t)))
11916       (setq n (1- n)))
11917     (when (/= 0 n)
11918       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11919     (gnus-summary-recenter)
11920     (gnus-summary-position-point)
11921     (gnus-set-mode-line 'summary)
11922     n))
11923
11924 (defun gnus-summary-insert-articles (articles)
11925   (when (setq articles
11926               (gnus-sorted-difference articles
11927                                       (mapcar (lambda (h)
11928                                                 (mail-header-number h))
11929                                               gnus-newsgroup-headers)))
11930     (setq gnus-newsgroup-headers
11931           (gnus-merge 'list
11932                       gnus-newsgroup-headers
11933                       (gnus-fetch-headers articles)
11934                       'gnus-article-sort-by-number))
11935     ;; Suppress duplicates?
11936     (when gnus-suppress-duplicates
11937       (gnus-dup-suppress-articles))
11938
11939     ;; We might want to build some more threads first.
11940     (when (and gnus-fetch-old-headers
11941                (eq gnus-headers-retrieved-by 'nov))
11942       (if (eq gnus-fetch-old-headers 'invisible)
11943           (gnus-build-all-threads)
11944         (gnus-build-old-threads)))
11945     ;; Let the Gnus agent mark articles as read.
11946     (when gnus-agent
11947       (gnus-agent-get-undownloaded-list))
11948     ;; Remove list identifiers from subject
11949     (when gnus-list-identifiers
11950       (gnus-summary-remove-list-identifiers))
11951     ;; First and last article in this newsgroup.
11952     (when gnus-newsgroup-headers
11953       (setq gnus-newsgroup-begin
11954             (mail-header-number (car gnus-newsgroup-headers))
11955             gnus-newsgroup-end
11956             (mail-header-number
11957              (gnus-last-element gnus-newsgroup-headers))))
11958     (when gnus-use-scoring
11959       (gnus-possibly-score-headers))))
11960
11961 (defun gnus-summary-insert-old-articles (&optional all)
11962   "Insert all old articles in this group.
11963 If ALL is non-nil, already read articles become readable.
11964 If ALL is a number, fetch this number of articles."
11965   (interactive "P")
11966   (prog1
11967       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11968             older len)
11969         (setq older
11970               ;; Some nntp servers lie about their active range.  When
11971               ;; this happens, the active range can be in the millions.
11972               ;; Use a compressed range to avoid creating a huge list.
11973               (gnus-range-difference (list gnus-newsgroup-active) old))
11974         (setq len (gnus-range-length older))
11975         (cond
11976          ((null older) nil)
11977          ((numberp all)
11978           (if (< all len)
11979               (let ((older-range (nreverse older)))
11980                 (setq older nil)
11981
11982                 (while (> all 0)
11983                   (let* ((r (pop older-range))
11984                          (min (if (numberp r) r (car r)))
11985                          (max (if (numberp r) r (cdr r))))
11986                     (while (and (<= min max)
11987                                 (> all 0))
11988                       (push max older)
11989                       (setq all (1- all)
11990                             max (1- max))))))
11991             (setq older (gnus-uncompress-range older))))
11992          (all
11993           (setq older (gnus-uncompress-range older)))
11994          (t
11995           (when (and (numberp gnus-large-newsgroup)
11996                    (> len gnus-large-newsgroup))
11997               (let* ((cursor-in-echo-area nil)
11998                      (initial (gnus-parameter-large-newsgroup-initial
11999                                gnus-newsgroup-name))
12000                      (input
12001                       (read-string
12002                        (format
12003                         "How many articles from %s (%s %d): "
12004                         (gnus-limit-string
12005                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12006                         (if initial "max" "default")
12007                         len)
12008                        (if initial
12009                            (cons (number-to-string initial)
12010                                  0)))))
12011                 (unless (string-match "^[ \t]*$" input)
12012                   (setq all (string-to-number input))
12013                   (if (< all len)
12014                       (let ((older-range (nreverse older)))
12015                         (setq older nil)
12016
12017                         (while (> all 0)
12018                           (let* ((r (pop older-range))
12019                                  (min (if (numberp r) r (car r)))
12020                                  (max (if (numberp r) r (cdr r))))
12021                             (while (and (<= min max)
12022                                         (> all 0))
12023                               (push max older)
12024                               (setq all (1- all)
12025                                     max (1- max))))))))))
12026           (setq older (gnus-uncompress-range older))))
12027         (if (not older)
12028             (message "No old news.")
12029           (gnus-summary-insert-articles older)
12030           (gnus-summary-limit (gnus-sorted-nunion old older))))
12031     (gnus-summary-position-point)))
12032
12033 (defun gnus-summary-insert-new-articles ()
12034   "Insert all new articles in this group."
12035   (interactive)
12036   (prog1
12037       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12038             (old-active gnus-newsgroup-active)
12039             (nnmail-fetched-sources (list t))
12040             i new)
12041         (setq gnus-newsgroup-active
12042               (gnus-activate-group gnus-newsgroup-name 'scan))
12043         (setq i (cdr gnus-newsgroup-active))
12044         (while (> i (cdr old-active))
12045           (push i new)
12046           (decf i))
12047         (if (not new)
12048             (message "No gnus is bad news")
12049           (gnus-summary-insert-articles new)
12050           (setq gnus-newsgroup-unreads
12051                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12052           (gnus-summary-limit (gnus-sorted-nunion old new))))
12053     (gnus-summary-position-point)))
12054
12055 (gnus-summary-make-all-marking-commands)
12056
12057 (gnus-ems-redefine)
12058
12059 (provide 'gnus-sum)
12060
12061 (run-hooks 'gnus-sum-load-hook)
12062
12063 ;; Local Variables:
12064 ;; coding: iso-8859-1
12065 ;; End:
12066
12067 ;;; gnus-sum.el ends here