file uu-decode.pbm was added on branch t-gnus-6_17 on 2005-05-01 23:25:48 +0000
[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-summary-catchup "catchup" gnus-summary-mode-map)
2596               (tool-bar-add-item-from-menu
2597                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2598               (tool-bar-add-item-from-menu
2599                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2600               tool-bar-map)))
2601   (if gnus-summary-tool-bar-map
2602       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2603
2604 (defun gnus-score-set-default (var value)
2605   "A version of set that updates the GNU Emacs menu-bar."
2606   (set var value)
2607   ;; It is the message that forces the active status to be updated.
2608   (message ""))
2609
2610 (defun gnus-make-score-map (type)
2611   "Make a summary score map of type TYPE."
2612   (if t
2613       nil
2614     (let ((headers '(("author" "from" string)
2615                      ("subject" "subject" string)
2616                      ("article body" "body" string)
2617                      ("article head" "head" string)
2618                      ("xref" "xref" string)
2619                      ("extra header" "extra" string)
2620                      ("lines" "lines" number)
2621                      ("followups to author" "followup" string)))
2622           (types '((number ("less than" <)
2623                            ("greater than" >)
2624                            ("equal" =))
2625                    (string ("substring" s)
2626                            ("exact string" e)
2627                            ("fuzzy string" f)
2628                            ("regexp" r))))
2629           (perms '(("temporary" (current-time-string))
2630                    ("permanent" nil)
2631                    ("immediate" now)))
2632           header)
2633       (list
2634        (apply
2635         'nconc
2636         (list
2637          (if (eq type 'lower)
2638              "Lower score"
2639            "Increase score"))
2640         (let (outh)
2641           (while headers
2642             (setq header (car headers))
2643             (setq outh
2644                   (cons
2645                    (apply
2646                     'nconc
2647                     (list (car header))
2648                     (let ((ts (cdr (assoc (nth 2 header) types)))
2649                           outt)
2650                       (while ts
2651                         (setq outt
2652                               (cons
2653                                (apply
2654                                 'nconc
2655                                 (list (caar ts))
2656                                 (let ((ps perms)
2657                                       outp)
2658                                   (while ps
2659                                     (setq outp
2660                                           (cons
2661                                            (vector
2662                                             (caar ps)
2663                                             (list
2664                                              'gnus-summary-score-entry
2665                                              (nth 1 header)
2666                                              (if (or (string= (nth 1 header)
2667                                                               "head")
2668                                                      (string= (nth 1 header)
2669                                                               "body"))
2670                                                  ""
2671                                                (list 'gnus-summary-header
2672                                                      (nth 1 header)))
2673                                              (list 'quote (nth 1 (car ts)))
2674                                              (list 'gnus-score-delta-default
2675                                                    nil)
2676                                              (nth 1 (car ps))
2677                                              t)
2678                                             t)
2679                                            outp))
2680                                     (setq ps (cdr ps)))
2681                                   (list (nreverse outp))))
2682                                outt))
2683                         (setq ts (cdr ts)))
2684                       (list (nreverse outt))))
2685                    outh))
2686             (setq headers (cdr headers)))
2687           (list (nreverse outh))))))))
2688
2689 \f
2690
2691 (defun gnus-summary-mode (&optional group)
2692   "Major mode for reading articles.
2693
2694 All normal editing commands are switched off.
2695 \\<gnus-summary-mode-map>
2696 Each line in this buffer represents one article.  To read an
2697 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2698 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2699 respectively.
2700
2701 You can also post articles and send mail from this buffer.  To
2702 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2703 of an article, type `\\[gnus-summary-reply]'.
2704
2705 There are approx. one gazillion commands you can execute in this
2706 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2707
2708 The following commands are available:
2709
2710 \\{gnus-summary-mode-map}"
2711   (interactive)
2712   (kill-all-local-variables)
2713   (when (gnus-visual-p 'summary-menu 'menu)
2714     (gnus-summary-make-menu-bar)
2715     (gnus-summary-make-tool-bar))
2716   (gnus-summary-make-local-variables)
2717   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2718     (gnus-summary-make-local-variables))
2719   (gnus-make-thread-indent-array)
2720   (gnus-simplify-mode-line)
2721   (setq major-mode 'gnus-summary-mode)
2722   (setq mode-name "Summary")
2723   (make-local-variable 'minor-mode-alist)
2724   (use-local-map gnus-summary-mode-map)
2725   (buffer-disable-undo)
2726   (setq buffer-read-only t)             ;Disable modification
2727   (setq truncate-lines t)
2728   (setq selective-display t)
2729   (setq selective-display-ellipses t)   ;Display `...'
2730   (gnus-summary-set-display-table)
2731   (gnus-set-default-directory)
2732   (setq gnus-newsgroup-name group)
2733   (unless (gnus-news-group-p group)
2734     (setq gnus-newsgroup-incorporated
2735           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2736   (make-local-variable 'gnus-summary-line-format)
2737   (make-local-variable 'gnus-summary-line-format-spec)
2738   (make-local-variable 'gnus-summary-dummy-line-format)
2739   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2740   (make-local-variable 'gnus-summary-mark-positions)
2741   (gnus-make-local-hook 'pre-command-hook)
2742   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2743   (gnus-run-hooks 'gnus-summary-mode-hook)
2744   (turn-on-gnus-mailing-list-mode)
2745   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2746   (gnus-update-summary-mark-positions))
2747
2748 (defun gnus-summary-make-local-variables ()
2749   "Make all the local summary buffer variables."
2750   (let (global)
2751     (dolist (local gnus-summary-local-variables)
2752       (if (consp local)
2753           (progn
2754             (if (eq (cdr local) 'global)
2755                 ;; Copy the global value of the variable.
2756                 (setq global (symbol-value (car local)))
2757               ;; Use the value from the list.
2758               (setq global (eval (cdr local))))
2759             (set (make-local-variable (car local)) global))
2760         ;; Simple nil-valued local variable.
2761         (set (make-local-variable local) nil)))))
2762
2763 (defun gnus-summary-clear-local-variables ()
2764   (let ((locals gnus-summary-local-variables))
2765     (while locals
2766       (if (consp (car locals))
2767           (and (vectorp (caar locals))
2768                (set (caar locals) nil))
2769         (and (vectorp (car locals))
2770              (set (car locals) nil)))
2771       (setq locals (cdr locals)))))
2772
2773 ;; Summary data functions.
2774
2775 (defmacro gnus-data-number (data)
2776   `(car ,data))
2777
2778 (defmacro gnus-data-set-number (data number)
2779   `(setcar ,data ,number))
2780
2781 (defmacro gnus-data-mark (data)
2782   `(nth 1 ,data))
2783
2784 (defmacro gnus-data-set-mark (data mark)
2785   `(setcar (nthcdr 1 ,data) ,mark))
2786
2787 (defmacro gnus-data-pos (data)
2788   `(nth 2 ,data))
2789
2790 (defmacro gnus-data-set-pos (data pos)
2791   `(setcar (nthcdr 2 ,data) ,pos))
2792
2793 (defmacro gnus-data-header (data)
2794   `(nth 3 ,data))
2795
2796 (defmacro gnus-data-set-header (data header)
2797   `(setcar (nthcdr 3 ,data) ,header))
2798
2799 (defmacro gnus-data-level (data)
2800   `(nth 4 ,data))
2801
2802 (defmacro gnus-data-unread-p (data)
2803   `(= (nth 1 ,data) gnus-unread-mark))
2804
2805 (defmacro gnus-data-read-p (data)
2806   `(/= (nth 1 ,data) gnus-unread-mark))
2807
2808 (defmacro gnus-data-pseudo-p (data)
2809   `(consp (nth 3 ,data)))
2810
2811 (defmacro gnus-data-find (number)
2812   `(assq ,number gnus-newsgroup-data))
2813
2814 (defmacro gnus-data-find-list (number &optional data)
2815   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2816      (memq (assq ,number bdata)
2817            bdata)))
2818
2819 (defmacro gnus-data-make (number mark pos header level)
2820   `(list ,number ,mark ,pos ,header ,level))
2821
2822 (defun gnus-data-enter (after-article number mark pos header level offset)
2823   (let ((data (gnus-data-find-list after-article)))
2824     (unless data
2825       (error "No such article: %d" after-article))
2826     (setcdr data (cons (gnus-data-make number mark pos header level)
2827                        (cdr data)))
2828     (setq gnus-newsgroup-data-reverse nil)
2829     (gnus-data-update-list (cddr data) offset)))
2830
2831 (defun gnus-data-enter-list (after-article list &optional offset)
2832   (when list
2833     (let ((data (and after-article (gnus-data-find-list after-article)))
2834           (ilist list))
2835       (if (not (or data
2836                    after-article))
2837           (let ((odata gnus-newsgroup-data))
2838             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2839             (when offset
2840               (gnus-data-update-list odata offset)))
2841         ;; Find the last element in the list to be spliced into the main
2842         ;; list.
2843         (while (cdr list)
2844           (setq list (cdr list)))
2845         (if (not data)
2846             (progn
2847               (setcdr list gnus-newsgroup-data)
2848               (setq gnus-newsgroup-data ilist)
2849               (when offset
2850                 (gnus-data-update-list (cdr list) offset)))
2851           (setcdr list (cdr data))
2852           (setcdr data ilist)
2853           (when offset
2854             (gnus-data-update-list (cdr list) offset))))
2855       (setq gnus-newsgroup-data-reverse nil))))
2856
2857 (defun gnus-data-remove (article &optional offset)
2858   (let ((data gnus-newsgroup-data))
2859     (if (= (gnus-data-number (car data)) article)
2860         (progn
2861           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2862                 gnus-newsgroup-data-reverse nil)
2863           (when offset
2864             (gnus-data-update-list gnus-newsgroup-data offset)))
2865       (while (cdr data)
2866         (when (= (gnus-data-number (cadr data)) article)
2867           (setcdr data (cddr data))
2868           (when offset
2869             (gnus-data-update-list (cdr data) offset))
2870           (setq data nil
2871                 gnus-newsgroup-data-reverse nil))
2872         (setq data (cdr data))))))
2873
2874 (defmacro gnus-data-list (backward)
2875   `(if ,backward
2876        (or gnus-newsgroup-data-reverse
2877            (setq gnus-newsgroup-data-reverse
2878                  (reverse gnus-newsgroup-data)))
2879      gnus-newsgroup-data))
2880
2881 (defun gnus-data-update-list (data offset)
2882   "Add OFFSET to the POS of all data entries in DATA."
2883   (setq gnus-newsgroup-data-reverse nil)
2884   (while data
2885     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2886     (setq data (cdr data))))
2887
2888 (defun gnus-summary-article-pseudo-p (article)
2889   "Say whether this article is a pseudo article or not."
2890   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2891
2892 (defmacro gnus-summary-article-sparse-p (article)
2893   "Say whether this article is a sparse article or not."
2894   `(memq ,article gnus-newsgroup-sparse))
2895
2896 (defmacro gnus-summary-article-ancient-p (article)
2897   "Say whether this article is a sparse article or not."
2898   `(memq ,article gnus-newsgroup-ancient))
2899
2900 (defun gnus-article-parent-p (number)
2901   "Say whether this article is a parent or not."
2902   (let ((data (gnus-data-find-list number)))
2903     (and (cdr data)                     ; There has to be an article after...
2904          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2905             (gnus-data-level (nth 1 data))))))
2906
2907 (defun gnus-article-children (number)
2908   "Return a list of all children to NUMBER."
2909   (let* ((data (gnus-data-find-list number))
2910          (level (gnus-data-level (car data)))
2911          children)
2912     (setq data (cdr data))
2913     (while (and data
2914                 (= (gnus-data-level (car data)) (1+ level)))
2915       (push (gnus-data-number (car data)) children)
2916       (setq data (cdr data)))
2917     children))
2918
2919 (defmacro gnus-summary-skip-intangible ()
2920   "If the current article is intangible, then jump to a different article."
2921   '(let ((to (get-text-property (point) 'gnus-intangible)))
2922      (and to (gnus-summary-goto-subject to))))
2923
2924 (defmacro gnus-summary-article-intangible-p ()
2925   "Say whether this article is intangible or not."
2926   '(get-text-property (point) 'gnus-intangible))
2927
2928 (defun gnus-article-read-p (article)
2929   "Say whether ARTICLE is read or not."
2930   (not (or (memq article gnus-newsgroup-marked)
2931            (memq article gnus-newsgroup-spam-marked)
2932            (memq article gnus-newsgroup-unreads)
2933            (memq article gnus-newsgroup-unselected)
2934            (memq article gnus-newsgroup-dormant))))
2935
2936 ;; Some summary mode macros.
2937
2938 (defmacro gnus-summary-article-number ()
2939   "The article number of the article on the current line.
2940 If there isn't an article number here, then we return the current
2941 article number."
2942   '(progn
2943      (gnus-summary-skip-intangible)
2944      (or (get-text-property (point) 'gnus-number)
2945          (gnus-summary-last-subject))))
2946
2947 (defmacro gnus-summary-article-header (&optional number)
2948   "Return the header of article NUMBER."
2949   `(gnus-data-header (gnus-data-find
2950                       ,(or number '(gnus-summary-article-number)))))
2951
2952 (defmacro gnus-summary-thread-level (&optional number)
2953   "Return the level of thread that starts with article NUMBER."
2954   `(if (and (eq gnus-summary-make-false-root 'dummy)
2955             (get-text-property (point) 'gnus-intangible))
2956        0
2957      (gnus-data-level (gnus-data-find
2958                        ,(or number '(gnus-summary-article-number))))))
2959
2960 (defmacro gnus-summary-article-mark (&optional number)
2961   "Return the mark of article NUMBER."
2962   `(gnus-data-mark (gnus-data-find
2963                     ,(or number '(gnus-summary-article-number)))))
2964
2965 (defmacro gnus-summary-article-pos (&optional number)
2966   "Return the position of the line of article NUMBER."
2967   `(gnus-data-pos (gnus-data-find
2968                    ,(or number '(gnus-summary-article-number)))))
2969
2970 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2971 (defmacro gnus-summary-article-subject (&optional number)
2972   "Return current subject string or nil if nothing."
2973   `(let ((headers
2974           ,(if number
2975                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2976              '(gnus-data-header (assq (gnus-summary-article-number)
2977                                       gnus-newsgroup-data)))))
2978      (and headers
2979           (vectorp headers)
2980           (mail-header-subject headers))))
2981
2982 (defmacro gnus-summary-article-score (&optional number)
2983   "Return current article score."
2984   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2985                   gnus-newsgroup-scored))
2986        gnus-summary-default-score 0))
2987
2988 (defun gnus-summary-article-children (&optional number)
2989   "Return a list of article numbers that are children of article NUMBER."
2990   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2991          (level (gnus-data-level (car data)))
2992          l children)
2993     (while (and (setq data (cdr data))
2994                 (> (setq l (gnus-data-level (car data))) level))
2995       (and (= (1+ level) l)
2996            (push (gnus-data-number (car data))
2997                  children)))
2998     (nreverse children)))
2999
3000 (defun gnus-summary-article-parent (&optional number)
3001   "Return the article number of the parent of article NUMBER."
3002   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3003                                     (gnus-data-list t)))
3004          (level (gnus-data-level (car data))))
3005     (if (zerop level)
3006         ()                              ; This is a root.
3007       ;; We search until we find an article with a level less than
3008       ;; this one.  That function has to be the parent.
3009       (while (and (setq data (cdr data))
3010                   (not (< (gnus-data-level (car data)) level))))
3011       (and data (gnus-data-number (car data))))))
3012
3013 (defun gnus-unread-mark-p (mark)
3014   "Say whether MARK is the unread mark."
3015   (= mark gnus-unread-mark))
3016
3017 (defun gnus-read-mark-p (mark)
3018   "Say whether MARK is one of the marks that mark as read.
3019 This is all marks except unread, ticked, dormant, and expirable."
3020   (not (or (= mark gnus-unread-mark)
3021            (= mark gnus-ticked-mark)
3022            (= mark gnus-spam-mark)
3023            (= mark gnus-dormant-mark)
3024            (= mark gnus-expirable-mark))))
3025
3026 (defmacro gnus-article-mark (number)
3027   "Return the MARK of article NUMBER.
3028 This macro should only be used when computing the mark the \"first\"
3029 time; i.e., when generating the summary lines.  After that,
3030 `gnus-summary-article-mark' should be used to examine the
3031 marks of articles."
3032   `(cond
3033     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3034     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3035     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3036     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3037     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3038     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3039     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3040     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3041            gnus-ancient-mark))))
3042
3043 ;; Saving hidden threads.
3044
3045 (defmacro gnus-save-hidden-threads (&rest forms)
3046   "Save hidden threads, eval FORMS, and restore the hidden threads."
3047   (let ((config (make-symbol "config")))
3048     `(let ((,config (gnus-hidden-threads-configuration)))
3049        (unwind-protect
3050            (save-excursion
3051              ,@forms)
3052          (gnus-restore-hidden-threads-configuration ,config)))))
3053 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3054 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3055
3056 (defun gnus-data-compute-positions ()
3057   "Compute the positions of all articles."
3058   (setq gnus-newsgroup-data-reverse nil)
3059   (let ((data gnus-newsgroup-data))
3060     (save-excursion
3061       (gnus-save-hidden-threads
3062         (gnus-summary-show-all-threads)
3063         (goto-char (point-min))
3064         (while data
3065           (while (get-text-property (point) 'gnus-intangible)
3066             (forward-line 1))
3067           (gnus-data-set-pos (car data) (+ (point) 3))
3068           (setq data (cdr data))
3069           (forward-line 1))))))
3070
3071 (defun gnus-hidden-threads-configuration ()
3072   "Return the current hidden threads configuration."
3073   (save-excursion
3074     (let (config)
3075       (goto-char (point-min))
3076       (while (search-forward "\r" nil t)
3077         (push (1- (point)) config))
3078       config)))
3079
3080 (defun gnus-restore-hidden-threads-configuration (config)
3081   "Restore hidden threads configuration from CONFIG."
3082   (save-excursion
3083     (let (point buffer-read-only)
3084       (while (setq point (pop config))
3085         (when (and (< point (point-max))
3086                    (goto-char point)
3087                    (eq (char-after) ?\n))
3088           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3089
3090 ;; Various summary mode internalish functions.
3091
3092 (defun gnus-mouse-pick-article (e)
3093   (interactive "e")
3094   (mouse-set-point e)
3095   (gnus-summary-next-page nil t))
3096
3097 (defun gnus-summary-set-display-table ()
3098   "Change the display table.
3099 Odd characters have a tendency to mess
3100 up nicely formatted displays - we make all possible glyphs
3101 display only a single character."
3102
3103   ;; We start from the standard display table, if any.
3104   (let ((table (or (copy-sequence standard-display-table)
3105                    (make-display-table)))
3106         (i 32))
3107     ;; Nix out all the control chars...
3108     (while (>= (setq i (1- i)) 0)
3109       (aset table i [??]))
3110     ;; ... but not newline and cr, of course.  (cr is necessary for the
3111     ;; selective display).
3112     (aset table ?\n nil)
3113     (aset table ?\r nil)
3114     ;; We keep TAB as well.
3115     (aset table ?\t nil)
3116     ;; We nix out any glyphs over 126 that are not set already.
3117     (let ((i 256))
3118       (while (>= (setq i (1- i)) 127)
3119         ;; Only modify if the entry is nil.
3120         (unless (aref table i)
3121           (aset table i [??]))))
3122     (setq buffer-display-table table)))
3123
3124 (defun gnus-summary-set-article-display-arrow (pos)
3125   "Update the overlay arrow to point to line at position POS."
3126   (when (and gnus-summary-display-arrow
3127              (boundp 'overlay-arrow-position)
3128              (boundp 'overlay-arrow-string))
3129     (save-excursion
3130       (goto-char pos)
3131       (beginning-of-line)
3132       (unless overlay-arrow-position
3133         (setq overlay-arrow-position (make-marker)))
3134       (setq overlay-arrow-string "=>"
3135             overlay-arrow-position (set-marker overlay-arrow-position
3136                                                (point)
3137                                                (current-buffer))))))
3138
3139 (defun gnus-summary-setup-buffer (group)
3140   "Initialize summary buffer."
3141   (let ((buffer (gnus-summary-buffer-name group))
3142         (dead-name (concat "*Dead Summary "
3143                            (gnus-group-decoded-name group) "*")))
3144     ;; If a dead summary buffer exists, we kill it.
3145     (when (gnus-buffer-live-p dead-name)
3146       (gnus-kill-buffer dead-name))
3147     (if (get-buffer buffer)
3148         (progn
3149           (set-buffer buffer)
3150           (setq gnus-summary-buffer (current-buffer))
3151           (not gnus-newsgroup-prepared))
3152       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3153       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3154       (gnus-summary-mode group)
3155       (when gnus-carpal
3156         (gnus-carpal-setup-buffer 'summary))
3157       (unless gnus-single-article-buffer
3158         (make-local-variable 'gnus-article-buffer)
3159         (make-local-variable 'gnus-article-current)
3160         (make-local-variable 'gnus-original-article-buffer))
3161       (setq gnus-newsgroup-name group)
3162       ;; Set any local variables in the group parameters.
3163       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3164       t)))
3165
3166 (defun gnus-set-global-variables ()
3167   "Set the global equivalents of the buffer-local variables.
3168 They are set to the latest values they had.  These reflect the summary
3169 buffer that was in action when the last article was fetched."
3170   (when (eq major-mode 'gnus-summary-mode)
3171     (setq gnus-summary-buffer (current-buffer))
3172     (let ((name gnus-newsgroup-name)
3173           (marked gnus-newsgroup-marked)
3174           (spam gnus-newsgroup-spam-marked)
3175           (unread gnus-newsgroup-unreads)
3176           (headers gnus-current-headers)
3177           (data gnus-newsgroup-data)
3178           (summary gnus-summary-buffer)
3179           (article-buffer gnus-article-buffer)
3180           (original gnus-original-article-buffer)
3181           (gac gnus-article-current)
3182           (reffed gnus-reffed-article-number)
3183           (score-file gnus-current-score-file)
3184           (default-charset gnus-newsgroup-charset)
3185           vlist)
3186       (let ((locals gnus-newsgroup-variables))
3187         (while locals
3188           (if (consp (car locals))
3189               (push (eval (caar locals)) vlist)
3190             (push (eval (car locals)) vlist))
3191           (setq locals (cdr locals)))
3192         (setq vlist (nreverse vlist)))
3193       (with-current-buffer gnus-group-buffer
3194         (setq gnus-newsgroup-name name
3195               gnus-newsgroup-marked marked
3196               gnus-newsgroup-spam-marked spam
3197               gnus-newsgroup-unreads unread
3198               gnus-current-headers headers
3199               gnus-newsgroup-data data
3200               gnus-article-current gac
3201               gnus-summary-buffer summary
3202               gnus-article-buffer article-buffer
3203               gnus-original-article-buffer original
3204               gnus-reffed-article-number reffed
3205               gnus-current-score-file score-file
3206               gnus-newsgroup-charset default-charset)
3207         (let ((locals gnus-newsgroup-variables))
3208           (while locals
3209             (if (consp (car locals))
3210                 (set (caar locals) (pop vlist))
3211               (set (car locals) (pop vlist)))
3212             (setq locals (cdr locals))))
3213         ;; The article buffer also has local variables.
3214         (when (gnus-buffer-live-p gnus-article-buffer)
3215           (set-buffer gnus-article-buffer)
3216           (setq gnus-summary-buffer summary))))))
3217
3218 (defun gnus-summary-article-unread-p (article)
3219   "Say whether ARTICLE is unread or not."
3220   (memq article gnus-newsgroup-unreads))
3221
3222 (defun gnus-summary-first-article-p (&optional article)
3223   "Return whether ARTICLE is the first article in the buffer."
3224   (if (not (setq article (or article (gnus-summary-article-number))))
3225       nil
3226     (eq article (caar gnus-newsgroup-data))))
3227
3228 (defun gnus-summary-last-article-p (&optional article)
3229   "Return whether ARTICLE is the last article in the buffer."
3230   (if (not (setq article (or article (gnus-summary-article-number))))
3231       ;; All non-existent numbers are the last article.  :-)
3232       t
3233     (not (cdr (gnus-data-find-list article)))))
3234
3235 (defun gnus-make-thread-indent-array ()
3236   (let ((n 200))
3237     (unless (and gnus-thread-indent-array
3238                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3239       (setq gnus-thread-indent-array (make-vector 201 "")
3240             gnus-thread-indent-array-level gnus-thread-indent-level)
3241       (while (>= n 0)
3242         (aset gnus-thread-indent-array n
3243               (make-string (* n gnus-thread-indent-level) ? ))
3244         (setq n (1- n))))))
3245
3246 (defun gnus-update-summary-mark-positions ()
3247   "Compute where the summary marks are to go."
3248   (save-excursion
3249     (when (gnus-buffer-exists-p gnus-summary-buffer)
3250       (set-buffer gnus-summary-buffer))
3251     (let ((gnus-replied-mark 129)
3252           (gnus-score-below-mark 130)
3253           (gnus-score-over-mark 130)
3254           (gnus-undownloaded-mark 131)
3255           (spec gnus-summary-line-format-spec)
3256           gnus-visual pos)
3257       (save-excursion
3258         (gnus-set-work-buffer)
3259         (let ((gnus-summary-line-format-spec spec)
3260               (gnus-newsgroup-downloadable '(0)))
3261           (gnus-summary-insert-line
3262            (make-full-mail-header 0 "" "nobody"
3263                                   "05 Apr 2001 23:33:09 +0400"
3264                                   "" "" 0 0 "" nil)
3265            0 nil t 128 t nil "" nil 1)
3266           (goto-char (point-min))
3267           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3268                                              (- (point) (point-min) 1)))))
3269           (goto-char (point-min))
3270           (push (cons 'replied (and (search-forward "\201" nil t)
3271                                     (- (point) (point-min) 1)))
3272                 pos)
3273           (goto-char (point-min))
3274           (push (cons 'score (and (search-forward "\202" nil t)
3275                                   (- (point) (point-min) 1)))
3276                 pos)
3277           (goto-char (point-min))
3278           (push (cons 'download
3279                       (and (search-forward "\203" nil t)
3280                            (- (point) (point-min) 1)))
3281                 pos)))
3282       (setq gnus-summary-mark-positions pos))))
3283
3284 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3285   "Insert a dummy root in the summary buffer."
3286   (beginning-of-line)
3287   (gnus-add-text-properties
3288    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3289    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3290
3291 (defun gnus-summary-extract-address-component (from)
3292   (or (car (funcall gnus-extract-address-components from))
3293       from))
3294
3295 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3296   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3297                                 default-mime-charset)))
3298     ;; Is it really necessary to do this next part for each summary line?
3299     ;; Luckily, doesn't seem to slow things down much.
3300     (or
3301      (and gnus-ignored-from-addresses
3302           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3303           (let ((extra-headers (mail-header-extra header))
3304                 to
3305                 newsgroups)
3306             (cond
3307              ((setq to (cdr (assq 'To extra-headers)))
3308               (concat "-> "
3309                       (inline
3310                         (gnus-summary-extract-address-component
3311                          (funcall gnus-decode-encoded-word-function to)))))
3312              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3313               (concat "=> " newsgroups)))))
3314      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3315
3316 (defun gnus-summary-insert-line (gnus-tmp-header
3317                                  gnus-tmp-level gnus-tmp-current
3318                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3319                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3320                                  &optional gnus-tmp-dummy gnus-tmp-score
3321                                  gnus-tmp-process)
3322   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3323          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3324          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3325          (gnus-tmp-score-char
3326           (if (or (null gnus-summary-default-score)
3327                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3328                       gnus-summary-zcore-fuzz))
3329               ?\ ;;;Whitespace
3330             (if (< gnus-tmp-score gnus-summary-default-score)
3331                 gnus-score-below-mark gnus-score-over-mark)))
3332          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3333          (gnus-tmp-replied
3334           (cond (gnus-tmp-process gnus-process-mark)
3335                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3336                  gnus-cached-mark)
3337                 (gnus-tmp-replied gnus-replied-mark)
3338                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3339                  gnus-forwarded-mark)
3340                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3341                  gnus-saved-mark)
3342                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3343                  gnus-recent-mark)
3344                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3345                  gnus-unseen-mark)
3346                 (t gnus-no-mark)))
3347          (gnus-tmp-downloaded
3348           (cond (undownloaded
3349                  gnus-undownloaded-mark)
3350                 (gnus-newsgroup-agentized
3351                  gnus-downloaded-mark)
3352                 (t
3353                  gnus-no-mark)))
3354          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3355          (gnus-tmp-name
3356           (cond
3357            ((string-match "<[^>]+> *$" gnus-tmp-from)
3358             (let ((beg (match-beginning 0)))
3359               (or (and (string-match "^\".+\"" gnus-tmp-from)
3360                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3361                   (substring gnus-tmp-from 0 beg))))
3362            ((string-match "(.+)" gnus-tmp-from)
3363             (substring gnus-tmp-from
3364                        (1+ (match-beginning 0)) (1- (match-end 0))))
3365            (t gnus-tmp-from)))
3366          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3367          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3368          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3369          (buffer-read-only nil))
3370     (when (string= gnus-tmp-name "")
3371       (setq gnus-tmp-name gnus-tmp-from))
3372     (unless (numberp gnus-tmp-lines)
3373       (setq gnus-tmp-lines -1))
3374     (if (= gnus-tmp-lines -1)
3375         (setq gnus-tmp-lines "?")
3376       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3377     (gnus-put-text-property-excluding-characters-with-faces
3378      (point)
3379      (progn (eval gnus-summary-line-format-spec) (point))
3380      'gnus-number gnus-tmp-number)
3381     (when (gnus-visual-p 'summary-highlight 'highlight)
3382       (forward-line -1)
3383       (gnus-run-hooks 'gnus-summary-update-hook)
3384       (forward-line 1))))
3385
3386 (defun gnus-summary-update-line (&optional dont-update)
3387   "Update summary line after change."
3388   (when (and gnus-summary-default-score
3389              (not gnus-summary-inhibit-highlight))
3390     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3391            (article (gnus-summary-article-number))
3392            (score (gnus-summary-article-score article)))
3393       (unless dont-update
3394         (if (and gnus-summary-mark-below
3395                  (< (gnus-summary-article-score)
3396                     gnus-summary-mark-below))
3397             ;; This article has a low score, so we mark it as read.
3398             (when (memq article gnus-newsgroup-unreads)
3399               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3400           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3401             ;; This article was previously marked as read on account
3402             ;; of a low score, but now it has risen, so we mark it as
3403             ;; unread.
3404             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3405         (gnus-summary-update-mark
3406          (if (or (null gnus-summary-default-score)
3407                  (<= (abs (- score gnus-summary-default-score))
3408                      gnus-summary-zcore-fuzz))
3409              ?\ ;;;Whitespace
3410            (if (< score gnus-summary-default-score)
3411                gnus-score-below-mark gnus-score-over-mark))
3412          'score))
3413       ;; Do visual highlighting.
3414       (when (gnus-visual-p 'summary-highlight 'highlight)
3415         (gnus-run-hooks 'gnus-summary-update-hook)))))
3416
3417 (defvar gnus-tmp-new-adopts nil)
3418
3419 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3420   "Return the number of articles in THREAD.
3421 This may be 0 in some cases -- if none of the articles in
3422 the thread are to be displayed."
3423   (let* ((number
3424           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3425           (cond
3426            ((not (listp thread))
3427             1)
3428            ((and (consp thread) (cdr thread))
3429             (apply
3430              '+ 1 (mapcar
3431                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3432            ((null thread)
3433             1)
3434            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3435             1)
3436            (t 0))))
3437     (when (and level (zerop level) gnus-tmp-new-adopts)
3438       (incf number
3439             (apply '+ (mapcar
3440                        'gnus-summary-number-of-articles-in-thread
3441                        gnus-tmp-new-adopts))))
3442     (if char
3443         (if (> number 1) gnus-not-empty-thread-mark
3444           gnus-empty-thread-mark)
3445       number)))
3446
3447 (defsubst gnus-summary-line-message-size (head)
3448   "Return pretty-printed version of message size.
3449 This function is intended to be used in
3450 `gnus-summary-line-format-alist'."
3451   (let ((c (or (mail-header-chars head) -1)))
3452     (cond ((< c 0) "n/a")               ; chars not available
3453           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3454           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3455           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3456           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3457
3458
3459 (defun gnus-summary-set-local-parameters (group)
3460   "Go through the local params of GROUP and set all variable specs in that list."
3461   (let ((params (gnus-group-find-parameter group))
3462         (vars '(quit-config))           ; Ignore quit-config.
3463         elem)
3464     (while params
3465       (setq elem (car params)
3466             params (cdr params))
3467       (and (consp elem)                 ; Has to be a cons.
3468            (consp (cdr elem))           ; The cdr has to be a list.
3469            (symbolp (car elem))         ; Has to be a symbol in there.
3470            (not (memq (car elem) vars))
3471            (ignore-errors               ; So we set it.
3472              (push (car elem) vars)
3473              (make-local-variable (car elem))
3474              (set (car elem) (eval (nth 1 elem))))))))
3475
3476 (defun gnus-summary-read-group (group &optional show-all no-article
3477                                       kill-buffer no-display backward
3478                                       select-articles)
3479   "Start reading news in newsgroup GROUP.
3480 If SHOW-ALL is non-nil, already read articles are also listed.
3481 If NO-ARTICLE is non-nil, no article is selected initially.
3482 If NO-DISPLAY, don't generate a summary buffer."
3483   (let (result)
3484     (while (and group
3485                 (null (setq result
3486                             (let ((gnus-auto-select-next nil))
3487                               (or (gnus-summary-read-group-1
3488                                    group show-all no-article
3489                                    kill-buffer no-display
3490                                    select-articles)
3491                                   (setq show-all nil
3492                                         select-articles nil)))))
3493                 (eq gnus-auto-select-next 'quietly))
3494       (set-buffer gnus-group-buffer)
3495       ;; The entry function called above goes to the next
3496       ;; group automatically, so we go two groups back
3497       ;; if we are searching for the previous group.
3498       (when backward
3499         (gnus-group-prev-unread-group 2))
3500       (if (not (equal group (gnus-group-group-name)))
3501           (setq group (gnus-group-group-name))
3502         (setq group nil)))
3503     result))
3504
3505 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3506   "Directly jump to the other GROUP from summary buffer.
3507 If SHOW-ALL is non-nil, already read articles are also listed."
3508   (interactive
3509    (if (eq gnus-summary-buffer (current-buffer))
3510        (list (completing-read
3511               "Group: " gnus-active-hashtb nil t
3512               (when (and gnus-newsgroup-name
3513                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3514                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3515               'gnus-group-history)
3516              current-prefix-arg)
3517      (error "%s must be invoked from a gnus summary buffer." this-command)))
3518   (unless (or (zerop (length group))
3519               (and gnus-newsgroup-name
3520                    (string-equal gnus-newsgroup-name group)))
3521     (gnus-summary-exit)
3522     (gnus-summary-read-group group show-all
3523                              gnus-dont-select-after-jump-to-other-group)))
3524
3525 (defun gnus-summary-read-group-1 (group show-all no-article
3526                                         kill-buffer no-display
3527                                         &optional select-articles)
3528   ;; Killed foreign groups can't be entered.
3529   ;;  (when (and (not (gnus-group-native-p group))
3530   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3531   ;;    (error "Dead non-native groups can't be entered"))
3532   (gnus-message 5 "Retrieving newsgroup: %s..."
3533                 (gnus-group-decoded-name group))
3534   (let* ((new-group (gnus-summary-setup-buffer group))
3535          (quit-config (gnus-group-quit-config group))
3536          (did-select (and new-group (gnus-select-newsgroup
3537                                      group show-all select-articles))))
3538     (cond
3539      ;; This summary buffer exists already, so we just select it.
3540      ((not new-group)
3541       (gnus-set-global-variables)
3542       (when kill-buffer
3543         (gnus-kill-or-deaden-summary kill-buffer))
3544       (gnus-configure-windows 'summary 'force)
3545       (gnus-set-mode-line 'summary)
3546       (gnus-summary-position-point)
3547       (message "")
3548       t)
3549      ;; We couldn't select this group.
3550      ((null did-select)
3551       (when (and (eq major-mode 'gnus-summary-mode)
3552                  (not (equal (current-buffer) kill-buffer)))
3553         (kill-buffer (current-buffer))
3554         (if (not quit-config)
3555             (progn
3556               ;; Update the info -- marks might need to be removed,
3557               ;; for instance.
3558               (gnus-summary-update-info)
3559               (set-buffer gnus-group-buffer)
3560               (gnus-group-jump-to-group group)
3561               (gnus-group-next-unread-group 1))
3562           (gnus-handle-ephemeral-exit quit-config)))
3563       (let ((grpinfo (gnus-get-info group)))
3564         (if (null (gnus-info-read grpinfo))
3565             (gnus-message 3 "Group %s contains no messages"
3566                           (gnus-group-decoded-name group))
3567           (gnus-message 3 "Can't select group")))
3568       nil)
3569      ;; The user did a `C-g' while prompting for number of articles,
3570      ;; so we exit this group.
3571      ((eq did-select 'quit)
3572       (and (eq major-mode 'gnus-summary-mode)
3573            (not (equal (current-buffer) kill-buffer))
3574            (kill-buffer (current-buffer)))
3575       (when kill-buffer
3576         (gnus-kill-or-deaden-summary kill-buffer))
3577       (if (not quit-config)
3578           (progn
3579             (set-buffer gnus-group-buffer)
3580             (gnus-group-jump-to-group group)
3581             (gnus-group-next-unread-group 1)
3582             (gnus-configure-windows 'group 'force))
3583         (gnus-handle-ephemeral-exit quit-config))
3584       ;; Finally signal the quit.
3585       (signal 'quit nil))
3586      ;; The group was successfully selected.
3587      (t
3588       (gnus-set-global-variables)
3589       ;; Save the active value in effect when the group was entered.
3590       (setq gnus-newsgroup-active
3591             (gnus-copy-sequence
3592              (gnus-active gnus-newsgroup-name)))
3593       ;; You can change the summary buffer in some way with this hook.
3594       (gnus-run-hooks 'gnus-select-group-hook)
3595       (gnus-update-format-specifications
3596        nil 'summary 'summary-mode 'summary-dummy)
3597       (gnus-update-summary-mark-positions)
3598       ;; Do score processing.
3599       (when gnus-use-scoring
3600         (gnus-possibly-score-headers))
3601       ;; Check whether to fill in the gaps in the threads.
3602       (when gnus-build-sparse-threads
3603         (gnus-build-sparse-threads))
3604       ;; Find the initial limit.
3605       (if gnus-show-threads
3606           (if show-all
3607               (let ((gnus-newsgroup-dormant nil))
3608                 (gnus-summary-initial-limit show-all))
3609             (gnus-summary-initial-limit show-all))
3610         ;; When unthreaded, all articles are always shown.
3611         (setq gnus-newsgroup-limit
3612               (mapcar
3613                (lambda (header) (mail-header-number header))
3614                gnus-newsgroup-headers)))
3615       ;; Generate the summary buffer.
3616       (unless no-display
3617         (gnus-summary-prepare))
3618       (when gnus-use-trees
3619         (gnus-tree-open group)
3620         (setq gnus-summary-highlight-line-function
3621               'gnus-tree-highlight-article))
3622       ;; If the summary buffer is empty, but there are some low-scored
3623       ;; articles or some excluded dormants, we include these in the
3624       ;; buffer.
3625       (when (and (zerop (buffer-size))
3626                  (not no-display))
3627         (cond (gnus-newsgroup-dormant
3628                (gnus-summary-limit-include-dormant))
3629               ((and gnus-newsgroup-scored show-all)
3630                (gnus-summary-limit-include-expunged t))))
3631       ;; Function `gnus-apply-kill-file' must be called in this hook.
3632       (gnus-run-hooks 'gnus-apply-kill-hook)
3633       (if (and (zerop (buffer-size))
3634                (not no-display))
3635           (progn
3636             ;; This newsgroup is empty.
3637             (gnus-summary-catchup-and-exit nil t)
3638             (gnus-message 6 "No unread news")
3639             (when kill-buffer
3640               (gnus-kill-or-deaden-summary kill-buffer))
3641             ;; Return nil from this function.
3642             nil)
3643         ;; Hide conversation thread subtrees.  We cannot do this in
3644         ;; gnus-summary-prepare-hook since kill processing may not
3645         ;; work with hidden articles.
3646         (gnus-summary-maybe-hide-threads)
3647         (when kill-buffer
3648           (gnus-kill-or-deaden-summary kill-buffer))
3649         (gnus-summary-auto-select-subject)
3650         ;; Show first unread article if requested.
3651         (if (and (not no-article)
3652                  (not no-display)
3653                  gnus-newsgroup-unreads
3654                  gnus-auto-select-first)
3655             (progn
3656               (gnus-configure-windows 'summary)
3657               (let ((art (gnus-summary-article-number)))
3658                 (unless (and (not gnus-plugged)
3659                              (or (memq art gnus-newsgroup-undownloaded)
3660                                  (memq art gnus-newsgroup-downloadable)))
3661                   (gnus-summary-goto-article art))))
3662           ;; Don't select any articles.
3663           (gnus-summary-position-point)
3664           (gnus-configure-windows 'summary 'force)
3665           (gnus-set-mode-line 'summary))
3666         (when (and gnus-auto-center-group
3667                    (get-buffer-window gnus-group-buffer t))
3668           ;; Gotta use windows, because recenter does weird stuff if
3669           ;; the current buffer ain't the displayed window.
3670           (let ((owin (selected-window)))
3671             (select-window (get-buffer-window gnus-group-buffer t))
3672             (when (gnus-group-goto-group group)
3673               (recenter))
3674             (select-window owin)))
3675         ;; Mark this buffer as "prepared".
3676         (setq gnus-newsgroup-prepared t)
3677         (gnus-run-hooks 'gnus-summary-prepared-hook)
3678         (unless (gnus-ephemeral-group-p group)
3679           (gnus-group-update-group group))
3680         t)))))
3681
3682 (defun gnus-summary-auto-select-subject ()
3683   "Select the subject line on initial group entry."
3684   (goto-char (point-min))
3685   (cond
3686    ((eq gnus-auto-select-subject 'best)
3687     (gnus-summary-best-unread-subject))
3688    ((eq gnus-auto-select-subject 'unread)
3689     (gnus-summary-first-unread-subject))
3690    ((eq gnus-auto-select-subject 'unseen)
3691     (gnus-summary-first-unseen-subject))
3692    ((eq gnus-auto-select-subject 'unseen-or-unread)
3693     (gnus-summary-first-unseen-or-unread-subject))
3694    ((eq gnus-auto-select-subject 'first)
3695     ;; Do nothing.
3696     )
3697    ((functionp gnus-auto-select-subject)
3698     (funcall gnus-auto-select-subject))))
3699
3700 (defun gnus-summary-prepare ()
3701   "Generate the summary buffer."
3702   (interactive)
3703   (let ((buffer-read-only nil))
3704     (erase-buffer)
3705     (setq gnus-newsgroup-data nil
3706           gnus-newsgroup-data-reverse nil)
3707     (gnus-run-hooks 'gnus-summary-generate-hook)
3708     ;; Generate the buffer, either with threads or without.
3709     (when gnus-newsgroup-headers
3710       (gnus-summary-prepare-threads
3711        (if gnus-show-threads
3712            (gnus-sort-gathered-threads
3713             (funcall gnus-summary-thread-gathering-function
3714                      (gnus-sort-threads
3715                       (gnus-cut-threads (gnus-make-threads)))))
3716          ;; Unthreaded display.
3717          (gnus-sort-articles gnus-newsgroup-headers))))
3718     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3719     ;; Call hooks for modifying summary buffer.
3720     (goto-char (point-min))
3721     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3722
3723 (defsubst gnus-general-simplify-subject (subject)
3724   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3725   (setq subject
3726         (cond
3727          ;; Truncate the subject.
3728          (gnus-simplify-subject-functions
3729           (gnus-map-function gnus-simplify-subject-functions subject))
3730          ((numberp gnus-summary-gather-subject-limit)
3731           (setq subject (gnus-simplify-subject-re subject))
3732           (if (> (length subject) gnus-summary-gather-subject-limit)
3733               (substring subject 0 gnus-summary-gather-subject-limit)
3734             subject))
3735          ;; Fuzzily simplify it.
3736          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3737           (gnus-simplify-subject-fuzzy subject))
3738          ;; Just remove the leading "Re:".
3739          (t
3740           (gnus-simplify-subject-re subject))))
3741
3742   (if (and gnus-summary-gather-exclude-subject
3743            (string-match gnus-summary-gather-exclude-subject subject))
3744       nil                               ; This article shouldn't be gathered
3745     subject))
3746
3747 (defun gnus-summary-simplify-subject-query ()
3748   "Query where the respool algorithm would put this article."
3749   (interactive)
3750   (gnus-summary-select-article)
3751   (message "%s"
3752            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3753
3754 (defun gnus-gather-threads-by-subject (threads)
3755   "Gather threads by looking at Subject headers."
3756   (if (not gnus-summary-make-false-root)
3757       threads
3758     (let ((hashtb (gnus-make-hashtable 1024))
3759           (prev threads)
3760           (result threads)
3761           subject hthread whole-subject)
3762       (while threads
3763         (setq subject (gnus-general-simplify-subject
3764                        (setq whole-subject (mail-header-subject
3765                                             (caar threads)))))
3766         (when subject
3767           (if (setq hthread (gnus-gethash subject hashtb))
3768               (progn
3769                 ;; We enter a dummy root into the thread, if we
3770                 ;; haven't done that already.
3771                 (unless (stringp (caar hthread))
3772                   (setcar hthread (list whole-subject (car hthread))))
3773                 ;; We add this new gathered thread to this gathered
3774                 ;; thread.
3775                 (setcdr (car hthread)
3776                         (nconc (cdar hthread) (list (car threads))))
3777                 ;; Remove it from the list of threads.
3778                 (setcdr prev (cdr threads))
3779                 (setq threads prev))
3780             ;; Enter this thread into the hash table.
3781             (gnus-sethash subject
3782                           (if gnus-summary-make-false-root-always
3783                               (progn
3784                                 ;; If you want a dummy root above all
3785                                 ;; threads...
3786                                 (setcar threads (list whole-subject
3787                                                       (car threads)))
3788                                 threads)
3789                             threads)
3790                           hashtb)))
3791         (setq prev threads)
3792         (setq threads (cdr threads)))
3793       result)))
3794
3795 (defun gnus-gather-threads-by-references (threads)
3796   "Gather threads by looking at References headers."
3797   (let ((idhashtb (gnus-make-hashtable 1024))
3798         (thhashtb (gnus-make-hashtable 1024))
3799         (prev threads)
3800         (result threads)
3801         ids references id gthread gid entered ref)
3802     (while threads
3803       (when (setq references (mail-header-references (caar threads)))
3804         (setq id (mail-header-id (caar threads))
3805               ids (inline (gnus-split-references references))
3806               entered nil)
3807         (while (setq ref (pop ids))
3808           (setq ids (delete ref ids))
3809           (if (not (setq gid (gnus-gethash ref idhashtb)))
3810               (progn
3811                 (gnus-sethash ref id idhashtb)
3812                 (gnus-sethash id threads thhashtb))
3813             (setq gthread (gnus-gethash gid thhashtb))
3814             (unless entered
3815               ;; We enter a dummy root into the thread, if we
3816               ;; haven't done that already.
3817               (unless (stringp (caar gthread))
3818                 (setcar gthread (list (mail-header-subject (caar gthread))
3819                                       (car gthread))))
3820               ;; We add this new gathered thread to this gathered
3821               ;; thread.
3822               (setcdr (car gthread)
3823                       (nconc (cdar gthread) (list (car threads)))))
3824             ;; Add it into the thread hash table.
3825             (gnus-sethash id gthread thhashtb)
3826             (setq entered t)
3827             ;; Remove it from the list of threads.
3828             (setcdr prev (cdr threads))
3829             (setq threads prev))))
3830       (setq prev threads)
3831       (setq threads (cdr threads)))
3832     result))
3833
3834 (defun gnus-sort-gathered-threads (threads)
3835   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3836   (let ((result threads))
3837     (while threads
3838       (when (stringp (caar threads))
3839         (setcdr (car threads)
3840                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3841       (setq threads (cdr threads)))
3842     result))
3843
3844 (defun gnus-thread-loop-p (root thread)
3845   "Say whether ROOT is in THREAD."
3846   (let ((stack (list thread))
3847         (infloop 0)
3848         th)
3849     (while (setq thread (pop stack))
3850       (setq th (cdr thread))
3851       (while (and th
3852                   (not (eq (caar th) root)))
3853         (pop th))
3854       (if th
3855           ;; We have found a loop.
3856           (let (ref-dep)
3857             (setcdr thread (delq (car th) (cdr thread)))
3858             (if (boundp (setq ref-dep (intern "none"
3859                                               gnus-newsgroup-dependencies)))
3860                 (setcdr (symbol-value ref-dep)
3861                         (nconc (cdr (symbol-value ref-dep))
3862                                (list (car th))))
3863               (set ref-dep (list nil (car th))))
3864             (setq infloop 1
3865                   stack nil))
3866         ;; Push all the subthreads onto the stack.
3867         (push (cdr thread) stack)))
3868     infloop))
3869
3870 (defun gnus-make-threads ()
3871   "Go through the dependency hashtb and find the roots.  Return all threads."
3872   (let (threads)
3873     (while (catch 'infloop
3874              (mapatoms
3875               (lambda (refs)
3876                 ;; Deal with self-referencing References loops.
3877                 (when (and (car (symbol-value refs))
3878                            (not (zerop
3879                                  (apply
3880                                   '+
3881                                   (mapcar
3882                                    (lambda (thread)
3883                                      (gnus-thread-loop-p
3884                                       (car (symbol-value refs)) thread))
3885                                    (cdr (symbol-value refs)))))))
3886                   (setq threads nil)
3887                   (throw 'infloop t))
3888                 (unless (car (symbol-value refs))
3889                   ;; These threads do not refer back to any other articles,
3890                   ;; so they're roots.
3891                   (setq threads (append (cdr (symbol-value refs)) threads))))
3892               gnus-newsgroup-dependencies)))
3893     threads))
3894
3895 ;; Build the thread tree.
3896 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3897   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3898
3899 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3900 if it was already present.
3901
3902 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3903 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3904 Message-IDs will be renamed to a unique Message-ID before being
3905 entered.
3906
3907 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3908   (let* ((id (mail-header-id header))
3909          (id-dep (and id (intern id dependencies)))
3910          parent-id ref ref-dep ref-header replaced)
3911     ;; Enter this `header' in the `dependencies' table.
3912     (cond
3913      ((not id-dep)
3914       (setq header nil))
3915      ;; The first two cases do the normal part: enter a new `header'
3916      ;; in the `dependencies' table.
3917      ((not (boundp id-dep))
3918       (set id-dep (list header)))
3919      ((null (car (symbol-value id-dep)))
3920       (setcar (symbol-value id-dep) header))
3921
3922      ;; From here the `header' was already present in the
3923      ;; `dependencies' table.
3924      (force-new
3925       ;; Overrides an existing entry;
3926       ;; just set the header part of the entry.
3927       (setcar (symbol-value id-dep) header)
3928       (setq replaced t))
3929
3930      ;; Renames the existing `header' to a unique Message-ID.
3931      ((not gnus-summary-ignore-duplicates)
3932       ;; An article with this Message-ID has already been seen.
3933       ;; We rename the Message-ID.
3934       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3935            (list header))
3936       (mail-header-set-id header id))
3937
3938      ;; The last case ignores an existing entry, except it adds any
3939      ;; additional Xrefs (in case the two articles came from different
3940      ;; servers.
3941      ;; Also sets `header' to `nil' meaning that the `dependencies'
3942      ;; table was *not* modified.
3943      (t
3944       (mail-header-set-xref
3945        (car (symbol-value id-dep))
3946        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3947                    "")
3948                (or (mail-header-xref header) "")))
3949       (setq header nil)))
3950
3951     (when (and header (not replaced))
3952       ;; First check that we are not creating a References loop.
3953       (setq parent-id (gnus-parent-id (mail-header-references header)))
3954       (setq ref parent-id)
3955       (while (and ref
3956                   (setq ref-dep (intern-soft ref dependencies))
3957                   (boundp ref-dep)
3958                   (setq ref-header (car (symbol-value ref-dep))))
3959         (if (string= id ref)
3960             ;; Yuk!  This is a reference loop.  Make the article be a
3961             ;; root article.
3962             (progn
3963               (mail-header-set-references (car (symbol-value id-dep)) "none")
3964               (setq ref nil)
3965               (setq parent-id nil))
3966           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3967       (setq ref-dep (intern (or parent-id "none") dependencies))
3968       (if (boundp ref-dep)
3969           (setcdr (symbol-value ref-dep)
3970                   (nconc (cdr (symbol-value ref-dep))
3971                          (list (symbol-value id-dep))))
3972         (set ref-dep (list nil (symbol-value id-dep)))))
3973     header))
3974
3975 (defun gnus-extract-message-id-from-in-reply-to (string)
3976   (if (string-match "<[^>]+>" string)
3977       (substring string (match-beginning 0) (match-end 0))
3978     nil))
3979
3980 (defun gnus-build-sparse-threads ()
3981   (let ((headers gnus-newsgroup-headers)
3982         (mail-parse-charset gnus-newsgroup-charset)
3983         (gnus-summary-ignore-duplicates t)
3984         header references generation relations
3985         subject child end new-child date)
3986     ;; First we create an alist of generations/relations, where
3987     ;; generations is how much we trust the relation, and the relation
3988     ;; is parent/child.
3989     (gnus-message 7 "Making sparse threads...")
3990     (save-excursion
3991       (nnheader-set-temp-buffer " *gnus sparse threads*")
3992       (while (setq header (pop headers))
3993         (when (and (setq references (mail-header-references header))
3994                    (not (string= references "")))
3995           (insert references)
3996           (setq child (mail-header-id header)
3997                 subject (mail-header-subject header)
3998                 date (mail-header-date header)
3999                 generation 0)
4000           (while (search-backward ">" nil t)
4001             (setq end (1+ (point)))
4002             (when (search-backward "<" nil t)
4003               (setq new-child (buffer-substring (point) end))
4004               (push (list (incf generation)
4005                           child (setq child new-child)
4006                           subject date)
4007                     relations)))
4008           (when child
4009             (push (list (1+ generation) child nil subject) relations))
4010           (erase-buffer)))
4011       (kill-buffer (current-buffer)))
4012     ;; Sort over trustworthiness.
4013     (mapcar
4014      (lambda (relation)
4015        (when (gnus-dependencies-add-header
4016               (make-full-mail-header-from-decoded-header
4017                gnus-reffed-article-number
4018                (nth 3 relation) "" (or (nth 4 relation) "")
4019                (nth 1 relation)
4020                (or (nth 2 relation) "") 0 0 "")
4021               gnus-newsgroup-dependencies nil)
4022          (push gnus-reffed-article-number gnus-newsgroup-limit)
4023          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4024          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4025                gnus-newsgroup-reads)
4026          (decf gnus-reffed-article-number)))
4027      (sort relations 'car-less-than-car))
4028     (gnus-message 7 "Making sparse threads...done")))
4029
4030 (defun gnus-build-old-threads ()
4031   ;; Look at all the articles that refer back to old articles, and
4032   ;; fetch the headers for the articles that aren't there.  This will
4033   ;; build complete threads - if the roots haven't been expired by the
4034   ;; server, that is.
4035   (let ((mail-parse-charset gnus-newsgroup-charset)
4036         id heads)
4037     (mapatoms
4038      (lambda (refs)
4039        (when (not (car (symbol-value refs)))
4040          (setq heads (cdr (symbol-value refs)))
4041          (while heads
4042            (if (memq (mail-header-number (caar heads))
4043                      gnus-newsgroup-dormant)
4044                (setq heads (cdr heads))
4045              (setq id (symbol-name refs))
4046              (while (and (setq id (gnus-build-get-header id))
4047                          (not (car (gnus-id-to-thread id)))))
4048              (setq heads nil)))))
4049      gnus-newsgroup-dependencies)))
4050
4051 (defsubst gnus-remove-odd-characters (string)
4052   "Translate STRING into something that doesn't contain weird characters."
4053   (mm-subst-char-in-string
4054    ?\r ?\-
4055    (mm-subst-char-in-string ?\n ?\- string t) t))
4056
4057 ;; This function has to be called with point after the article number
4058 ;; on the beginning of the line.
4059 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4060   (let ((eol (point-at-eol))
4061         (buffer (current-buffer))
4062         header references in-reply-to)
4063
4064     ;; overview: [num subject from date id refs chars lines misc]
4065     (unwind-protect
4066         (progn
4067           (narrow-to-region (point) eol)
4068           (unless (eobp)
4069             (forward-char))
4070
4071           (setq header
4072                 (make-full-mail-header
4073                  number                         ; number
4074                  (nnheader-nov-field)           ; subject
4075                  (nnheader-nov-field)           ; from
4076                  (nnheader-nov-field)           ; date
4077                  (nnheader-nov-read-message-id) ; id
4078                  (nnheader-nov-field)           ; refs
4079                  (nnheader-nov-read-integer)    ; chars
4080                  (nnheader-nov-read-integer)    ; lines
4081                  (unless (eobp)
4082                    (if (looking-at "Xref: ")
4083                        (goto-char (match-end 0)))
4084                    (nnheader-nov-field))        ; Xref
4085                  (nnheader-nov-parse-extra))))  ; extra
4086
4087       (widen))
4088
4089     (when (and (string= references "")
4090                (setq in-reply-to (mail-header-extra header))
4091                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4092       (mail-header-set-references
4093        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4094
4095     (when gnus-alter-header-function
4096       (funcall gnus-alter-header-function header))
4097     (gnus-dependencies-add-header header dependencies force-new)))
4098
4099 (defun gnus-build-get-header (id)
4100   "Look through the buffer of NOV lines and find the header to ID.
4101 Enter this line into the dependencies hash table, and return
4102 the id of the parent article (if any)."
4103   (let ((deps gnus-newsgroup-dependencies)
4104         found header)
4105     (prog1
4106         (save-excursion
4107           (set-buffer nntp-server-buffer)
4108           (let ((case-fold-search nil))
4109             (goto-char (point-min))
4110             (while (and (not found)
4111                         (search-forward id nil t))
4112               (beginning-of-line)
4113               (setq found (looking-at
4114                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4115                                    (regexp-quote id))))
4116               (or found (beginning-of-line 2)))
4117             (when found
4118               (beginning-of-line)
4119               (and
4120                (setq header (gnus-nov-parse-line
4121                              (read (current-buffer)) deps))
4122                (gnus-parent-id (mail-header-references header))))))
4123       (when header
4124         (let ((number (mail-header-number header)))
4125           (push number gnus-newsgroup-limit)
4126           (push header gnus-newsgroup-headers)
4127           (if (memq number gnus-newsgroup-unselected)
4128               (progn
4129                 (setq gnus-newsgroup-unreads
4130                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4131                                                number))
4132                 (setq gnus-newsgroup-unselected
4133                       (delq number gnus-newsgroup-unselected)))
4134             (push number gnus-newsgroup-ancient)))))))
4135
4136 (defun gnus-build-all-threads ()
4137   "Read all the headers."
4138   (let ((gnus-summary-ignore-duplicates t)
4139         (mail-parse-charset gnus-newsgroup-charset)
4140         (dependencies gnus-newsgroup-dependencies)
4141         header article)
4142     (save-excursion
4143       (set-buffer nntp-server-buffer)
4144       (let ((case-fold-search nil))
4145         (goto-char (point-min))
4146         (while (not (eobp))
4147           (ignore-errors
4148             (setq article (read (current-buffer))
4149                   header (gnus-nov-parse-line article dependencies)))
4150           (when header
4151             (with-current-buffer gnus-summary-buffer
4152               (push header gnus-newsgroup-headers)
4153               (if (memq (setq article (mail-header-number header))
4154                         gnus-newsgroup-unselected)
4155                   (progn
4156                     (setq gnus-newsgroup-unreads
4157                           (gnus-add-to-sorted-list
4158                            gnus-newsgroup-unreads article))
4159                     (setq gnus-newsgroup-unselected
4160                           (delq article gnus-newsgroup-unselected)))
4161                 (push article gnus-newsgroup-ancient)))
4162             (forward-line 1)))))))
4163
4164 (defun gnus-summary-update-article-line (article header)
4165   "Update the line for ARTICLE using HEADER."
4166   (let* ((id (mail-header-id header))
4167          (thread (gnus-id-to-thread id)))
4168     (unless thread
4169       (error "Article in no thread"))
4170     ;; Update the thread.
4171     (setcar thread header)
4172     (gnus-summary-goto-subject article)
4173     (let* ((datal (gnus-data-find-list article))
4174            (data (car datal))
4175            (buffer-read-only nil)
4176            (level (gnus-summary-thread-level)))
4177       (gnus-delete-line)
4178       (let ((inserted (- (point)
4179                          (progn
4180                            (gnus-summary-insert-line
4181                             header level nil
4182                             (memq article gnus-newsgroup-undownloaded)
4183                             (gnus-article-mark article)
4184                             (memq article gnus-newsgroup-replied)
4185                             (memq article gnus-newsgroup-expirable)
4186                             ;; Only insert the Subject string when it's different
4187                             ;; from the previous Subject string.
4188                             (if (and
4189                                  gnus-show-threads
4190                                  (gnus-subject-equal
4191                                   (condition-case ()
4192                                       (mail-header-subject
4193                                        (gnus-data-header
4194                                         (cadr
4195                                          (gnus-data-find-list
4196                                           article
4197                                           (gnus-data-list t)))))
4198                                     ;; Error on the side of excessive subjects.
4199                                     (error ""))
4200                                   (mail-header-subject header)))
4201                                 ""
4202                               (mail-header-subject header))
4203                             nil (cdr (assq article gnus-newsgroup-scored))
4204                             (memq article gnus-newsgroup-processable))
4205                            (point)))))
4206         (when (cdr datal)
4207           (gnus-data-update-list
4208            (cdr datal)
4209            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4210
4211 (defun gnus-summary-update-article (article &optional iheader)
4212   "Update ARTICLE in the summary buffer."
4213   (set-buffer gnus-summary-buffer)
4214   (let* ((header (gnus-summary-article-header article))
4215          (id (mail-header-id header))
4216          (data (gnus-data-find article))
4217          (thread (gnus-id-to-thread id))
4218          (references (mail-header-references header))
4219          (parent
4220           (gnus-id-to-thread
4221            (or (gnus-parent-id
4222                 (when (and references
4223                            (not (equal "" references)))
4224                   references))
4225                "none")))
4226          (buffer-read-only nil)
4227          (old (car thread)))
4228     (when thread
4229       (unless iheader
4230         (setcar thread nil)
4231         (when parent
4232           (delq thread parent)))
4233       (if (gnus-summary-insert-subject id header)
4234           ;; Set the (possibly) new article number in the data structure.
4235           (gnus-data-set-number data (gnus-id-to-article id))
4236         (setcar thread old)
4237         nil))))
4238
4239 (defun gnus-rebuild-thread (id &optional line)
4240   "Rebuild the thread containing ID.
4241 If LINE, insert the rebuilt thread starting on line LINE."
4242   (let ((buffer-read-only nil)
4243         old-pos current thread data)
4244     (if (not gnus-show-threads)
4245         (setq thread (list (car (gnus-id-to-thread id))))
4246       ;; Get the thread this article is part of.
4247       (setq thread (gnus-remove-thread id)))
4248     (setq old-pos (point-at-bol))
4249     (setq current (save-excursion
4250                     (and (re-search-backward "[\r\n]" nil t)
4251                          (gnus-summary-article-number))))
4252     ;; If this is a gathered thread, we have to go some re-gathering.
4253     (when (stringp (car thread))
4254       (let ((subject (car thread))
4255             roots thr)
4256         (setq thread (cdr thread))
4257         (while thread
4258           (unless (memq (setq thr (gnus-id-to-thread
4259                                    (gnus-root-id
4260                                     (mail-header-id (caar thread)))))
4261                         roots)
4262             (push thr roots))
4263           (setq thread (cdr thread)))
4264         ;; We now have all (unique) roots.
4265         (if (= (length roots) 1)
4266             ;; All the loose roots are now one solid root.
4267             (setq thread (car roots))
4268           (setq thread (cons subject (gnus-sort-threads roots))))))
4269     (let (threads)
4270       ;; We then insert this thread into the summary buffer.
4271       (when line
4272         (goto-char (point-min))
4273         (forward-line (1- line)))
4274       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4275         (if gnus-show-threads
4276             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4277           (gnus-summary-prepare-unthreaded thread))
4278         (setq data (nreverse gnus-newsgroup-data))
4279         (setq threads gnus-newsgroup-threads))
4280       ;; We splice the new data into the data structure.
4281       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4282       ;;!!! then we want to insert at the beginning of the buffer.
4283       ;;!!! That happens to be true with Gnus now, but that may
4284       ;;!!! change in the future.  Perhaps.
4285       (gnus-data-enter-list
4286        (if line nil current) data (- (point) old-pos))
4287       (setq gnus-newsgroup-threads
4288             (nconc threads gnus-newsgroup-threads))
4289       (gnus-data-compute-positions))))
4290
4291 (defun gnus-number-to-header (number)
4292   "Return the header for article NUMBER."
4293   (let ((headers gnus-newsgroup-headers))
4294     (while (and headers
4295                 (not (= number (mail-header-number (car headers)))))
4296       (pop headers))
4297     (when headers
4298       (car headers))))
4299
4300 (defun gnus-parent-headers (in-headers &optional generation)
4301   "Return the headers of the GENERATIONeth parent of HEADERS."
4302   (unless generation
4303     (setq generation 1))
4304   (let ((parent t)
4305         (headers in-headers)
4306         references)
4307     (while (and parent
4308                 (not (zerop generation))
4309                 (setq references (mail-header-references headers)))
4310       (setq headers (if (and references
4311                              (setq parent (gnus-parent-id references)))
4312                         (car (gnus-id-to-thread parent))
4313                       nil))
4314       (decf generation))
4315     (and (not (eq headers in-headers))
4316          headers)))
4317
4318 (defun gnus-id-to-thread (id)
4319   "Return the (sub-)thread where ID appears."
4320   (gnus-gethash id gnus-newsgroup-dependencies))
4321
4322 (defun gnus-id-to-article (id)
4323   "Return the article number of ID."
4324   (let ((thread (gnus-id-to-thread id)))
4325     (when (and thread
4326                (car thread))
4327       (mail-header-number (car thread)))))
4328
4329 (defun gnus-id-to-header (id)
4330   "Return the article headers of ID."
4331   (car (gnus-id-to-thread id)))
4332
4333 (defun gnus-article-displayed-root-p (article)
4334   "Say whether ARTICLE is a root(ish) article."
4335   (let ((level (gnus-summary-thread-level article))
4336         (refs (mail-header-references  (gnus-summary-article-header article)))
4337         particle)
4338     (cond
4339      ((null level) nil)
4340      ((zerop level) t)
4341      ((null refs) t)
4342      ((null (gnus-parent-id refs)) t)
4343      ((and (= 1 level)
4344            (null (setq particle (gnus-id-to-article
4345                                  (gnus-parent-id refs))))
4346            (null (gnus-summary-thread-level particle)))))))
4347
4348 (defun gnus-root-id (id)
4349   "Return the id of the root of the thread where ID appears."
4350   (let (last-id prev)
4351     (while (and id (setq prev (car (gnus-id-to-thread id))))
4352       (setq last-id id
4353             id (gnus-parent-id (mail-header-references prev))))
4354     last-id))
4355
4356 (defun gnus-articles-in-thread (thread)
4357   "Return the list of articles in THREAD."
4358   (cons (mail-header-number (car thread))
4359         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4360
4361 (defun gnus-remove-thread (id &optional dont-remove)
4362   "Remove the thread that has ID in it."
4363   (let (headers thread last-id)
4364     ;; First go up in this thread until we find the root.
4365     (setq last-id (gnus-root-id id)
4366           headers (message-flatten-list (gnus-id-to-thread last-id)))
4367     ;; We have now found the real root of this thread.  It might have
4368     ;; been gathered into some loose thread, so we have to search
4369     ;; through the threads to find the thread we wanted.
4370     (let ((threads gnus-newsgroup-threads)
4371           sub)
4372       (while threads
4373         (setq sub (car threads))
4374         (if (stringp (car sub))
4375             ;; This is a gathered thread, so we look at the roots
4376             ;; below it to find whether this article is in this
4377             ;; gathered root.
4378             (progn
4379               (setq sub (cdr sub))
4380               (while sub
4381                 (when (member (caar sub) headers)
4382                   (setq thread (car threads)
4383                         threads nil
4384                         sub nil))
4385                 (setq sub (cdr sub))))
4386           ;; It's an ordinary thread, so we check it.
4387           (when (eq (car sub) (car headers))
4388             (setq thread sub
4389                   threads nil)))
4390         (setq threads (cdr threads)))
4391       ;; If this article is in no thread, then it's a root.
4392       (if thread
4393           (unless dont-remove
4394             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4395         (setq thread (gnus-id-to-thread last-id)))
4396       (when thread
4397         (prog1
4398             thread                      ; We return this thread.
4399           (unless dont-remove
4400             (if (stringp (car thread))
4401                 (progn
4402                   ;; If we use dummy roots, then we have to remove the
4403                   ;; dummy root as well.
4404                   (when (eq gnus-summary-make-false-root 'dummy)
4405                     ;; We go to the dummy root by going to
4406                     ;; the first sub-"thread", and then one line up.
4407                     (gnus-summary-goto-article
4408                      (mail-header-number (caadr thread)))
4409                     (forward-line -1)
4410                     (gnus-delete-line)
4411                     (gnus-data-compute-positions))
4412                   (setq thread (cdr thread))
4413                   (while thread
4414                     (gnus-remove-thread-1 (car thread))
4415                     (setq thread (cdr thread))))
4416               (gnus-remove-thread-1 thread))))))))
4417
4418 (defun gnus-remove-thread-1 (thread)
4419   "Remove the thread THREAD recursively."
4420   (let ((number (mail-header-number (pop thread)))
4421         d)
4422     (setq thread (reverse thread))
4423     (while thread
4424       (gnus-remove-thread-1 (pop thread)))
4425     (when (setq d (gnus-data-find number))
4426       (goto-char (gnus-data-pos d))
4427       (gnus-summary-show-thread)
4428       (gnus-data-remove
4429        number
4430        (- (point-at-bol)
4431           (prog1
4432               (1+ (point-at-eol))
4433             (gnus-delete-line)))))))
4434
4435 (defun gnus-sort-threads-1 (threads func)
4436   (sort (mapcar (lambda (thread)
4437                   (cons (car thread)
4438                         (and (cdr thread)
4439                              (gnus-sort-threads-1 (cdr thread) func))))
4440                 threads) func))
4441
4442 (defun gnus-sort-threads (threads)
4443   "Sort THREADS."
4444   (if (not gnus-thread-sort-functions)
4445       threads
4446     (gnus-message 8 "Sorting threads...")
4447     (let ((max-lisp-eval-depth 5000))
4448       (prog1 (gnus-sort-threads-1
4449          threads
4450          (gnus-make-sort-function gnus-thread-sort-functions))
4451         (gnus-message 8 "Sorting threads...done")))))
4452
4453 (defun gnus-sort-articles (articles)
4454   "Sort ARTICLES."
4455   (when gnus-article-sort-functions
4456     (gnus-message 7 "Sorting articles...")
4457     (prog1
4458         (setq gnus-newsgroup-headers
4459               (sort articles (gnus-make-sort-function
4460                               gnus-article-sort-functions)))
4461       (gnus-message 7 "Sorting articles...done"))))
4462
4463 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4464 (defmacro gnus-thread-header (thread)
4465   "Return header of first article in THREAD.
4466 Note that THREAD must never, ever be anything else than a variable -
4467 using some other form will lead to serious barfage."
4468   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4469   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4470   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4471         (vector thread) 2))
4472
4473 (defsubst gnus-article-sort-by-number (h1 h2)
4474   "Sort articles by article number."
4475   (< (mail-header-number h1)
4476      (mail-header-number h2)))
4477
4478 (defun gnus-thread-sort-by-number (h1 h2)
4479   "Sort threads by root article number."
4480   (gnus-article-sort-by-number
4481    (gnus-thread-header h1) (gnus-thread-header h2)))
4482
4483 (defsubst gnus-article-sort-by-random (h1 h2)
4484   "Sort articles by article number."
4485   (zerop (random 2)))
4486
4487 (defun gnus-thread-sort-by-random (h1 h2)
4488   "Sort threads by root article number."
4489   (gnus-article-sort-by-random
4490    (gnus-thread-header h1) (gnus-thread-header h2)))
4491
4492 (defsubst gnus-article-sort-by-lines (h1 h2)
4493   "Sort articles by article Lines header."
4494   (< (mail-header-lines h1)
4495      (mail-header-lines h2)))
4496
4497 (defun gnus-thread-sort-by-lines (h1 h2)
4498   "Sort threads by root article Lines header."
4499   (gnus-article-sort-by-lines
4500    (gnus-thread-header h1) (gnus-thread-header h2)))
4501
4502 (defsubst gnus-article-sort-by-chars (h1 h2)
4503   "Sort articles by octet length."
4504   (< (mail-header-chars h1)
4505      (mail-header-chars h2)))
4506
4507 (defun gnus-thread-sort-by-chars (h1 h2)
4508   "Sort threads by root article octet length."
4509   (gnus-article-sort-by-chars
4510    (gnus-thread-header h1) (gnus-thread-header h2)))
4511
4512 (defsubst gnus-article-sort-by-author (h1 h2)
4513   "Sort articles by root author."
4514   (string-lessp
4515    (let ((addr (car (mime-entity-read-field h1 'From))))
4516      (or (std11-full-name-string addr)
4517          (std11-address-string addr)
4518          ""))
4519    (let ((addr (car (mime-entity-read-field h2 'From))))
4520      (or (std11-full-name-string addr)
4521          (std11-address-string addr)
4522          ""))
4523    ))
4524
4525 (defun gnus-thread-sort-by-author (h1 h2)
4526   "Sort threads by root author."
4527   (gnus-article-sort-by-author
4528    (gnus-thread-header h1)  (gnus-thread-header h2)))
4529
4530 (defsubst gnus-article-sort-by-subject (h1 h2)
4531   "Sort articles by root subject."
4532   (string-lessp
4533    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4534    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4535
4536 (defun gnus-thread-sort-by-subject (h1 h2)
4537   "Sort threads by root subject."
4538   (gnus-article-sort-by-subject
4539    (gnus-thread-header h1) (gnus-thread-header h2)))
4540
4541 (defsubst gnus-article-sort-by-date (h1 h2)
4542   "Sort articles by root article date."
4543   (time-less-p
4544    (gnus-date-get-time (mail-header-date h1))
4545    (gnus-date-get-time (mail-header-date h2))))
4546
4547 (defun gnus-thread-sort-by-date (h1 h2)
4548   "Sort threads by root article date."
4549   (gnus-article-sort-by-date
4550    (gnus-thread-header h1) (gnus-thread-header h2)))
4551
4552 (defsubst gnus-article-sort-by-score (h1 h2)
4553   "Sort articles by root article score.
4554 Unscored articles will be counted as having a score of zero."
4555   (> (or (cdr (assq (mail-header-number h1)
4556                     gnus-newsgroup-scored))
4557          gnus-summary-default-score 0)
4558      (or (cdr (assq (mail-header-number h2)
4559                     gnus-newsgroup-scored))
4560          gnus-summary-default-score 0)))
4561
4562 (defun gnus-thread-sort-by-score (h1 h2)
4563   "Sort threads by root article score."
4564   (gnus-article-sort-by-score
4565    (gnus-thread-header h1) (gnus-thread-header h2)))
4566
4567 (defun gnus-thread-sort-by-total-score (h1 h2)
4568   "Sort threads by the sum of all scores in the thread.
4569 Unscored articles will be counted as having a score of zero."
4570   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4571
4572 (defun gnus-thread-total-score (thread)
4573   ;; This function find the total score of THREAD.
4574   (cond
4575    ((null thread)
4576     0)
4577    ((consp thread)
4578     (if (stringp (car thread))
4579         (apply gnus-thread-score-function 0
4580                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4581       (gnus-thread-total-score-1 thread)))
4582    (t
4583     (gnus-thread-total-score-1 (list thread)))))
4584
4585 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4586   "Sort threads such that the thread with the most recently arrived article comes first."
4587   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4588
4589 (defun gnus-thread-highest-number (thread)
4590   "Return the highest article number in THREAD."
4591   (apply 'max (mapcar (lambda (header)
4592                         (mail-header-number header))
4593                       (message-flatten-list thread))))
4594
4595 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4596   "Sort threads such that the thread with the most recently dated article comes first."
4597   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4598
4599 (defun gnus-thread-latest-date (thread)
4600   "Return the highest article date in THREAD."
4601   (let ((previous-time 0))
4602     (apply 'max
4603            (mapcar
4604             (lambda (header)
4605               (setq previous-time
4606                     (condition-case ()
4607                         (time-to-seconds (mail-header-parse-date
4608                                           (mail-header-date header)))
4609                       (error previous-time))))
4610             (sort
4611              (message-flatten-list thread)
4612              (lambda (h1 h2)
4613                (< (mail-header-number h1)
4614                   (mail-header-number h2))))))))
4615
4616 (defun gnus-thread-total-score-1 (root)
4617   ;; This function find the total score of the thread below ROOT.
4618   (setq root (car root))
4619   (apply gnus-thread-score-function
4620          (or (append
4621               (mapcar 'gnus-thread-total-score
4622                       (cdr (gnus-id-to-thread (mail-header-id root))))
4623               (when (> (mail-header-number root) 0)
4624                 (list (or (cdr (assq (mail-header-number root)
4625                                      gnus-newsgroup-scored))
4626                           gnus-summary-default-score 0))))
4627              (list gnus-summary-default-score)
4628              '(0))))
4629
4630 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4631 (defvar gnus-tmp-prev-subject nil)
4632 (defvar gnus-tmp-false-parent nil)
4633 (defvar gnus-tmp-root-expunged nil)
4634 (defvar gnus-tmp-dummy-line nil)
4635
4636 (eval-when-compile (defvar gnus-tmp-header))
4637 (defun gnus-extra-header (type &optional header)
4638   "Return the extra header of TYPE."
4639   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4640       ""))
4641
4642 (defvar gnus-tmp-thread-tree-header-string "")
4643
4644 (defcustom gnus-sum-thread-tree-root "> "
4645   "With %B spec, used for the root of a thread.
4646 If nil, use subject instead."
4647   :type '(radio (const :format "%v  " nil) (string :size 0))
4648   :group 'gnus-thread)
4649 (defcustom gnus-sum-thread-tree-false-root "> "
4650   "With %B spec, used for a false root of a thread.
4651 If nil, use subject instead."
4652   :type '(radio (const :format "%v  " nil) (string :size 0))
4653   :group 'gnus-thread)
4654 (defcustom gnus-sum-thread-tree-single-indent ""
4655   "With %B spec, used for a thread with just one message.
4656 If nil, use subject instead."
4657   :type '(radio (const :format "%v  " nil) (string :size 0))
4658   :group 'gnus-thread)
4659 (defcustom gnus-sum-thread-tree-vertical "| "
4660   "With %B spec, used for drawing a vertical line."
4661   :type 'string
4662   :group 'gnus-thread)
4663 (defcustom gnus-sum-thread-tree-indent "  "
4664   "With %B spec, used for indenting."
4665   :type 'string
4666   :group 'gnus-thread)
4667 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4668   "With %B spec, used for a leaf with brothers."
4669   :type 'string
4670   :group 'gnus-thread)
4671 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4672   "With %B spec, used for a leaf without brothers."
4673   :type 'string
4674   :group 'gnus-thread)
4675
4676 (defun gnus-summary-prepare-threads (threads)
4677   "Prepare summary buffer from THREADS and indentation LEVEL.
4678 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4679 or a straight list of headers."
4680   (gnus-message 7 "Generating summary...")
4681
4682   (setq gnus-newsgroup-threads threads)
4683   (beginning-of-line)
4684
4685   (let ((gnus-tmp-level 0)
4686         (default-score (or gnus-summary-default-score 0))
4687         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4688         (building-line-count gnus-summary-display-while-building)
4689         (building-count (integerp gnus-summary-display-while-building))
4690         thread number subject stack state gnus-tmp-gathered beg-match
4691         new-roots gnus-tmp-new-adopts thread-end simp-subject
4692         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4693         gnus-tmp-replied gnus-tmp-subject-or-nil
4694         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4695         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4696         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4697         tree-stack)
4698
4699     (setq gnus-tmp-prev-subject nil
4700           gnus-tmp-thread-tree-header-string "")
4701
4702     (if (vectorp (car threads))
4703         ;; If this is a straight (sic) list of headers, then a
4704         ;; threaded summary display isn't required, so we just create
4705         ;; an unthreaded one.
4706         (gnus-summary-prepare-unthreaded threads)
4707
4708       ;; Do the threaded display.
4709
4710       (if gnus-summary-display-while-building
4711           (switch-to-buffer (buffer-name)))
4712       (while (or threads stack gnus-tmp-new-adopts new-roots)
4713
4714         (if (and (= gnus-tmp-level 0)
4715                  (or (not stack)
4716                      (= (caar stack) 0))
4717                  (not gnus-tmp-false-parent)
4718                  (or gnus-tmp-new-adopts new-roots))
4719             (if gnus-tmp-new-adopts
4720                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4721                       thread (list (car gnus-tmp-new-adopts))
4722                       gnus-tmp-header (caar thread)
4723                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4724               (when new-roots
4725                 (setq thread (list (car new-roots))
4726                       gnus-tmp-header (caar thread)
4727                       new-roots (cdr new-roots))))
4728
4729           (if threads
4730               ;; If there are some threads, we do them before the
4731               ;; threads on the stack.
4732               (setq thread threads
4733                     gnus-tmp-header (caar thread))
4734             ;; There were no current threads, so we pop something off
4735             ;; the stack.
4736             (setq state (car stack)
4737                   gnus-tmp-level (car state)
4738                   tree-stack (cadr state)
4739                   thread (caddr state)
4740                   stack (cdr stack)
4741                   gnus-tmp-header (caar thread))))
4742
4743         (setq gnus-tmp-false-parent nil)
4744         (setq gnus-tmp-root-expunged nil)
4745         (setq thread-end nil)
4746
4747         (if (stringp gnus-tmp-header)
4748             ;; The header is a dummy root.
4749             (cond
4750              ((eq gnus-summary-make-false-root 'adopt)
4751               ;; We let the first article adopt the rest.
4752               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4753                                                (cddar thread)))
4754               (setq gnus-tmp-gathered
4755                     (nconc (mapcar
4756                             (lambda (h) (mail-header-number (car h)))
4757                             (cddar thread))
4758                            gnus-tmp-gathered))
4759               (setq thread (cons (list (caar thread)
4760                                        (cadar thread))
4761                                  (cdr thread)))
4762               (setq gnus-tmp-level -1
4763                     gnus-tmp-false-parent t))
4764              ((eq gnus-summary-make-false-root 'empty)
4765               ;; We print adopted articles with empty subject fields.
4766               (setq gnus-tmp-gathered
4767                     (nconc (mapcar
4768                             (lambda (h) (mail-header-number (car h)))
4769                             (cddar thread))
4770                            gnus-tmp-gathered))
4771               (setq gnus-tmp-level -1))
4772              ((eq gnus-summary-make-false-root 'dummy)
4773               ;; We remember that we probably want to output a dummy
4774               ;; root.
4775               (setq gnus-tmp-dummy-line gnus-tmp-header)
4776               (setq gnus-tmp-prev-subject gnus-tmp-header))
4777              (t
4778               ;; We do not make a root for the gathered
4779               ;; sub-threads at all.
4780               (setq gnus-tmp-level -1)))
4781
4782           (setq number (mail-header-number gnus-tmp-header)
4783                 subject (mail-header-subject gnus-tmp-header)
4784                 simp-subject (gnus-simplify-subject-fully subject))
4785
4786           (cond
4787            ;; If the thread has changed subject, we might want to make
4788            ;; this subthread into a root.
4789            ((and (null gnus-thread-ignore-subject)
4790                  (not (zerop gnus-tmp-level))
4791                  gnus-tmp-prev-subject
4792                  (not (string= gnus-tmp-prev-subject simp-subject)))
4793             (setq new-roots (nconc new-roots (list (car thread)))
4794                   thread-end t
4795                   gnus-tmp-header nil))
4796            ;; If the article lies outside the current limit,
4797            ;; then we do not display it.
4798            ((not (memq number gnus-newsgroup-limit))
4799             (setq gnus-tmp-gathered
4800                   (nconc (mapcar
4801                           (lambda (h) (mail-header-number (car h)))
4802                           (cdar thread))
4803                          gnus-tmp-gathered))
4804             (setq gnus-tmp-new-adopts (if (cdar thread)
4805                                           (append gnus-tmp-new-adopts
4806                                                   (cdar thread))
4807                                         gnus-tmp-new-adopts)
4808                   thread-end t
4809                   gnus-tmp-header nil)
4810             (when (zerop gnus-tmp-level)
4811               (setq gnus-tmp-root-expunged t)))
4812            ;; Perhaps this article is to be marked as read?
4813            ((and gnus-summary-mark-below
4814                  (< (or (cdr (assq number gnus-newsgroup-scored))
4815                         default-score)
4816                     gnus-summary-mark-below)
4817                  ;; Don't touch sparse articles.
4818                  (not (gnus-summary-article-sparse-p number))
4819                  (not (gnus-summary-article-ancient-p number)))
4820             (setq gnus-newsgroup-unreads
4821                   (delq number gnus-newsgroup-unreads))
4822             (if gnus-newsgroup-auto-expire
4823                 (setq gnus-newsgroup-expirable
4824                       (gnus-add-to-sorted-list
4825                        gnus-newsgroup-expirable number))
4826               (push (cons number gnus-low-score-mark)
4827                     gnus-newsgroup-reads))))
4828
4829           (when gnus-tmp-header
4830             ;; We may have an old dummy line to output before this
4831             ;; article.
4832             (when (and gnus-tmp-dummy-line
4833                        (gnus-subject-equal
4834                         gnus-tmp-dummy-line
4835                         (mail-header-subject gnus-tmp-header)))
4836               (gnus-summary-insert-dummy-line
4837                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4838               (setq gnus-tmp-dummy-line nil))
4839
4840             ;; Compute the mark.
4841             (setq gnus-tmp-unread (gnus-article-mark number))
4842
4843             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4844                                   gnus-tmp-header gnus-tmp-level)
4845                   gnus-newsgroup-data)
4846
4847             ;; Actually insert the line.
4848             (setq
4849              gnus-tmp-subject-or-nil
4850              (cond
4851               ((and gnus-thread-ignore-subject
4852                     gnus-tmp-prev-subject
4853                     (not (string= gnus-tmp-prev-subject simp-subject)))
4854                subject)
4855               ((zerop gnus-tmp-level)
4856                (if (and (eq gnus-summary-make-false-root 'empty)
4857                         (memq number gnus-tmp-gathered)
4858                         gnus-tmp-prev-subject
4859                         (string= gnus-tmp-prev-subject simp-subject))
4860                    gnus-summary-same-subject
4861                  subject))
4862               (t gnus-summary-same-subject)))
4863             (if (and (eq gnus-summary-make-false-root 'adopt)
4864                      (= gnus-tmp-level 1)
4865                      (memq number gnus-tmp-gathered))
4866                 (setq gnus-tmp-opening-bracket ?\<
4867                       gnus-tmp-closing-bracket ?\>)
4868               (setq gnus-tmp-opening-bracket ?\[
4869                     gnus-tmp-closing-bracket ?\]))
4870             (setq
4871              gnus-tmp-indentation
4872              (aref gnus-thread-indent-array gnus-tmp-level)
4873              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4874              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4875                                 gnus-summary-default-score 0)
4876              gnus-tmp-score-char
4877              (if (or (null gnus-summary-default-score)
4878                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4879                          gnus-summary-zcore-fuzz))
4880                  ?\ ;;;Whitespace
4881                (if (< gnus-tmp-score gnus-summary-default-score)
4882                    gnus-score-below-mark gnus-score-over-mark))
4883              gnus-tmp-replied
4884              (cond ((memq number gnus-newsgroup-processable)
4885                     gnus-process-mark)
4886                    ((memq number gnus-newsgroup-cached)
4887                     gnus-cached-mark)
4888                    ((memq number gnus-newsgroup-replied)
4889                     gnus-replied-mark)
4890                    ((memq number gnus-newsgroup-forwarded)
4891                     gnus-forwarded-mark)
4892                    ((memq number gnus-newsgroup-saved)
4893                     gnus-saved-mark)
4894                    ((memq number gnus-newsgroup-recent)
4895                     gnus-recent-mark)
4896                    ((memq number gnus-newsgroup-unseen)
4897                     gnus-unseen-mark)
4898                    (t gnus-no-mark))
4899              gnus-tmp-downloaded
4900              (cond ((memq number gnus-newsgroup-undownloaded)
4901                     gnus-undownloaded-mark)
4902                    (gnus-newsgroup-agentized
4903                     gnus-downloaded-mark)
4904                    (t
4905                     gnus-no-mark))
4906              gnus-tmp-from (mail-header-from gnus-tmp-header)
4907              gnus-tmp-name
4908              (cond
4909               ((string-match "<[^>]+> *$" gnus-tmp-from)
4910                (setq beg-match (match-beginning 0))
4911                (or (and (string-match "^\".+\"" gnus-tmp-from)
4912                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4913                    (substring gnus-tmp-from 0 beg-match)))
4914               ((string-match "(.+)" gnus-tmp-from)
4915                (substring gnus-tmp-from
4916                           (1+ (match-beginning 0)) (1- (match-end 0))))
4917               (t gnus-tmp-from))
4918
4919              ;; Do the %B string
4920              gnus-tmp-thread-tree-header-string
4921              (cond
4922               ((not gnus-show-threads) "")
4923               ((zerop gnus-tmp-level)
4924                (cond ((cdar thread)
4925                       (or gnus-sum-thread-tree-root subject))
4926                      (gnus-tmp-new-adopts
4927                       (or gnus-sum-thread-tree-false-root subject))
4928                      (t
4929                       (or gnus-sum-thread-tree-single-indent subject))))
4930               (t
4931                (concat (apply 'concat
4932                               (mapcar (lambda (item)
4933                                         (if (= item 1)
4934                                             gnus-sum-thread-tree-vertical
4935                                           gnus-sum-thread-tree-indent))
4936                                       (cdr (reverse tree-stack))))
4937                        (if (nth 1 thread)
4938                            gnus-sum-thread-tree-leaf-with-other
4939                          gnus-sum-thread-tree-single-leaf)))))
4940             (when (string= gnus-tmp-name "")
4941               (setq gnus-tmp-name gnus-tmp-from))
4942             (unless (numberp gnus-tmp-lines)
4943               (setq gnus-tmp-lines -1))
4944             (if (= gnus-tmp-lines -1)
4945                 (setq gnus-tmp-lines "?")
4946               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4947               (gnus-put-text-property
4948              (point)
4949              (progn (eval gnus-summary-line-format-spec) (point))
4950                'gnus-number number)
4951             (when gnus-visual-p
4952               (forward-line -1)
4953               (gnus-run-hooks 'gnus-summary-update-hook)
4954               (forward-line 1))
4955
4956             (setq gnus-tmp-prev-subject simp-subject)))
4957
4958         (when (nth 1 thread)
4959           (push (list (max 0 gnus-tmp-level)
4960                       (copy-sequence tree-stack)
4961                       (nthcdr 1 thread))
4962                 stack))
4963         (push (if (nth 1 thread) 1 0) tree-stack)
4964         (incf gnus-tmp-level)
4965         (setq threads (if thread-end nil (cdar thread)))
4966         (if gnus-summary-display-while-building
4967             (if building-count
4968                 (progn
4969                   ;; use a set frequency
4970                   (setq building-line-count (1- building-line-count))
4971                   (when (= building-line-count 0)
4972                     (sit-for 0)
4973                     (setq building-line-count
4974                           gnus-summary-display-while-building)))
4975               ;; always
4976               (sit-for 0)))
4977         (unless threads
4978           (setq gnus-tmp-level 0)))))
4979   (gnus-message 7 "Generating summary...done"))
4980
4981 (defun gnus-summary-prepare-unthreaded (headers)
4982   "Generate an unthreaded summary buffer based on HEADERS."
4983   (let (header number mark)
4984
4985     (beginning-of-line)
4986
4987     (while headers
4988       ;; We may have to root out some bad articles...
4989       (when (memq (setq number (mail-header-number
4990                                 (setq header (pop headers))))
4991                   gnus-newsgroup-limit)
4992         ;; Mark article as read when it has a low score.
4993         (when (and gnus-summary-mark-below
4994                    (< (or (cdr (assq number gnus-newsgroup-scored))
4995                           gnus-summary-default-score 0)
4996                       gnus-summary-mark-below)
4997                    (not (gnus-summary-article-ancient-p number)))
4998           (setq gnus-newsgroup-unreads
4999                 (delq number gnus-newsgroup-unreads))
5000           (if gnus-newsgroup-auto-expire
5001               (push number gnus-newsgroup-expirable)
5002             (push (cons number gnus-low-score-mark)
5003                   gnus-newsgroup-reads)))
5004
5005         (setq mark (gnus-article-mark number))
5006         (push (gnus-data-make number mark (1+ (point)) header 0)
5007               gnus-newsgroup-data)
5008         (gnus-summary-insert-line
5009          header 0 number
5010          (memq number gnus-newsgroup-undownloaded)
5011          mark (memq number gnus-newsgroup-replied)
5012          (memq number gnus-newsgroup-expirable)
5013          (mail-header-subject header) nil
5014          (cdr (assq number gnus-newsgroup-scored))
5015          (memq number gnus-newsgroup-processable))))))
5016
5017 (defun gnus-summary-remove-list-identifiers ()
5018   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5019   (let ((regexp (if (consp gnus-list-identifiers)
5020                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5021                   gnus-list-identifiers))
5022         changed subject)
5023     (when regexp
5024       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5025       (dolist (header gnus-newsgroup-headers)
5026         (setq subject (mail-header-subject header)
5027               changed nil)
5028         (while (string-match regexp subject)
5029           (setq subject
5030                 (concat (substring subject 0 (match-beginning 1))
5031                         (substring subject (match-end 0)))
5032                 changed t))
5033         (when changed
5034           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5035             (setq subject
5036                   (concat (substring subject 0 (match-beginning 1))
5037                           (substring subject (match-end 1)))))
5038           (mail-header-set-subject header subject))))))
5039
5040 (defun gnus-fetch-headers (articles)
5041   "Fetch headers of ARTICLES."
5042   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5043     (gnus-message 5 "Fetching headers for %s..." name)
5044     (prog1
5045         (if (eq 'nov
5046                 (setq gnus-headers-retrieved-by
5047                       (gnus-retrieve-headers
5048                        articles gnus-newsgroup-name
5049                        ;; We might want to fetch old headers, but
5050                        ;; not if there is only 1 article.
5051                        (and (or (and
5052                                  (not (eq gnus-fetch-old-headers 'some))
5053                                  (not (numberp gnus-fetch-old-headers)))
5054                                 (> (length articles) 1))
5055                             gnus-fetch-old-headers))))
5056             (gnus-get-newsgroup-headers-xover
5057              articles nil nil gnus-newsgroup-name t)
5058           (gnus-get-newsgroup-headers))
5059       (gnus-message 5 "Fetching headers for %s...done" name))))
5060
5061 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5062   "Select newsgroup GROUP.
5063 If READ-ALL is non-nil, all articles in the group are selected.
5064 If SELECT-ARTICLES, only select those articles from GROUP."
5065   (let* ((entry (gnus-group-entry group))
5066          ;;!!! Dirty hack; should be removed.
5067          (gnus-summary-ignore-duplicates
5068           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5069               t
5070             gnus-summary-ignore-duplicates))
5071          (info (nth 2 entry))
5072          articles fetched-articles cached)
5073
5074     (unless (gnus-check-server
5075              (set (make-local-variable 'gnus-current-select-method)
5076                   (gnus-find-method-for-group group)))
5077       (error "Couldn't open server"))
5078
5079     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5080         (gnus-activate-group group)     ; Or we can activate it...
5081         (progn                          ; Or we bug out.
5082           (when (equal major-mode 'gnus-summary-mode)
5083             (gnus-kill-buffer (current-buffer)))
5084           (error "Couldn't activate group %s: %s"
5085                  group (gnus-status-message group))))
5086
5087     (unless (gnus-request-group group t)
5088       (when (equal major-mode 'gnus-summary-mode)
5089         (gnus-kill-buffer (current-buffer)))
5090       (error "Couldn't request group %s: %s"
5091              group (gnus-status-message group)))
5092
5093     (when gnus-agent
5094       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5095       
5096       (setq gnus-summary-use-undownloaded-faces
5097             (gnus-agent-find-parameter
5098              group
5099              'agent-enable-undownloaded-faces)))
5100
5101     (setq gnus-newsgroup-name group
5102           gnus-newsgroup-unselected nil
5103           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5104
5105     (let ((display (gnus-group-find-parameter group 'display)))
5106       (setq gnus-newsgroup-display
5107             (cond
5108              ((not (zerop (or (car-safe read-all) 0)))
5109               ;; The user entered the group with C-u SPC/RET, let's show
5110               ;; all articles.
5111               'gnus-not-ignore)
5112              ((eq display 'all)
5113               'gnus-not-ignore)
5114              ((arrayp display)
5115               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5116              ((numberp display)
5117               ;; The following is probably the "correct" solution, but
5118               ;; it makes Gnus fetch all headers and then limit the
5119               ;; articles (which is slow), so instead we hack the
5120               ;; select-articles parameter instead. -- Simon Josefsson
5121               ;; <jas@kth.se>
5122               ;;
5123               ;; (gnus-byte-compile
5124               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5125               ;;                         display)))))
5126               (setq select-articles
5127                     (gnus-uncompress-range
5128                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5129                              (if (> tmp 0)
5130                                  tmp
5131                                1))
5132                            (cdr (gnus-active group)))))
5133               nil)
5134              (t
5135               nil))))
5136
5137     (gnus-summary-setup-default-charset)
5138
5139     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5140     (when (gnus-virtual-group-p group)
5141       (setq cached gnus-newsgroup-cached))
5142
5143     (setq gnus-newsgroup-unreads
5144           (gnus-sorted-ndifference
5145            (gnus-sorted-ndifference gnus-newsgroup-unreads
5146                                     gnus-newsgroup-marked)
5147            gnus-newsgroup-dormant))
5148
5149     (setq gnus-newsgroup-processable nil)
5150
5151     (gnus-update-read-articles group gnus-newsgroup-unreads)
5152
5153     ;; Adjust and set lists of article marks.
5154     (when info
5155       (gnus-adjust-marked-articles info))
5156     (if (setq articles select-articles)
5157         (setq gnus-newsgroup-unselected
5158               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5159       (setq articles (gnus-articles-to-read group read-all)))
5160
5161     (cond
5162      ((null articles)
5163       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5164       'quit)
5165      ((eq articles 0) nil)
5166      (t
5167       ;; Init the dependencies hash table.
5168       (setq gnus-newsgroup-dependencies
5169             (gnus-make-hashtable (length articles)))
5170       (gnus-set-global-variables)
5171       ;; Retrieve the headers and read them in.
5172
5173       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5174
5175       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5176       (when cached
5177         (setq gnus-newsgroup-cached cached))
5178
5179       ;; Suppress duplicates?
5180       (when gnus-suppress-duplicates
5181         (gnus-dup-suppress-articles))
5182
5183       ;; Set the initial limit.
5184       (setq gnus-newsgroup-limit (copy-sequence articles))
5185       ;; Remove canceled articles from the list of unread articles.
5186       (setq fetched-articles
5187             (mapcar (lambda (headers) (mail-header-number headers))
5188                     gnus-newsgroup-headers))
5189       (setq gnus-newsgroup-articles fetched-articles)
5190       (setq gnus-newsgroup-unreads
5191             (gnus-sorted-nintersection
5192              gnus-newsgroup-unreads fetched-articles))
5193       (gnus-compute-unseen-list)
5194
5195       ;; Removed marked articles that do not exist.
5196       (gnus-update-missing-marks
5197        (gnus-sorted-difference articles fetched-articles))
5198       ;; We might want to build some more threads first.
5199       (when (and gnus-fetch-old-headers
5200                  (eq gnus-headers-retrieved-by 'nov))
5201         (if (eq gnus-fetch-old-headers 'invisible)
5202             (gnus-build-all-threads)
5203           (gnus-build-old-threads)))
5204       ;; Let the Gnus agent mark articles as read.
5205       (when gnus-agent
5206         (gnus-agent-get-undownloaded-list))
5207       ;; Remove list identifiers from subject
5208       (when gnus-list-identifiers
5209         (gnus-summary-remove-list-identifiers))
5210       ;; Check whether auto-expire is to be done in this group.
5211       (setq gnus-newsgroup-auto-expire
5212             (gnus-group-auto-expirable-p group))
5213       ;; Set up the article buffer now, if necessary.
5214       (unless gnus-single-article-buffer
5215         (gnus-article-setup-buffer))
5216       ;; First and last article in this newsgroup.
5217       (when gnus-newsgroup-headers
5218         (setq gnus-newsgroup-begin
5219               (mail-header-number (car gnus-newsgroup-headers))
5220               gnus-newsgroup-end
5221               (mail-header-number
5222                (gnus-last-element gnus-newsgroup-headers))))
5223       ;; GROUP is successfully selected.
5224       (or gnus-newsgroup-headers t)))))
5225
5226 (defun gnus-compute-unseen-list ()
5227   ;; The `seen' marks are treated specially.
5228   (if (not gnus-newsgroup-seen)
5229       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5230     (setq gnus-newsgroup-unseen
5231           (gnus-inverse-list-range-intersection
5232            gnus-newsgroup-articles gnus-newsgroup-seen))))
5233
5234 (defun gnus-summary-display-make-predicate (display)
5235   (require 'gnus-agent)
5236   (when (= (length display) 1)
5237     (setq display (car display)))
5238   (unless gnus-summary-display-cache
5239     (dolist (elem (append '((unread . unread)
5240                             (read . read)
5241                             (unseen . unseen))
5242                           gnus-article-mark-lists))
5243       (push (cons (cdr elem)
5244                   (gnus-byte-compile
5245                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5246             gnus-summary-display-cache)))
5247   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5248         (gnus-category-predicate-cache gnus-summary-display-cache))
5249     (gnus-get-predicate display)))
5250
5251 ;; Uses the dynamically bound `number' variable.
5252 (eval-when-compile
5253   (defvar number))
5254 (defun gnus-article-marked-p (type &optional article)
5255   (let ((article (or article number)))
5256     (cond
5257      ((eq type 'tick)
5258       (memq article gnus-newsgroup-marked))
5259      ((eq type 'spam)
5260       (memq article gnus-newsgroup-spam-marked))
5261      ((eq type 'unsend)
5262       (memq article gnus-newsgroup-unsendable))
5263      ((eq type 'undownload)
5264       (memq article gnus-newsgroup-undownloaded))
5265      ((eq type 'download)
5266       (memq article gnus-newsgroup-downloadable))
5267      ((eq type 'unread)
5268       (memq article gnus-newsgroup-unreads))
5269      ((eq type 'read)
5270       (memq article gnus-newsgroup-reads))
5271      ((eq type 'dormant)
5272       (memq article gnus-newsgroup-dormant) )
5273      ((eq type 'expire)
5274       (memq article gnus-newsgroup-expirable))
5275      ((eq type 'reply)
5276       (memq article gnus-newsgroup-replied))
5277      ((eq type 'killed)
5278       (memq article gnus-newsgroup-killed))
5279      ((eq type 'bookmark)
5280       (assq article gnus-newsgroup-bookmarks))
5281      ((eq type 'score)
5282       (assq article gnus-newsgroup-scored))
5283      ((eq type 'save)
5284       (memq article gnus-newsgroup-saved))
5285      ((eq type 'cache)
5286       (memq article gnus-newsgroup-cached))
5287      ((eq type 'forward)
5288       (memq article gnus-newsgroup-forwarded))
5289      ((eq type 'seen)
5290       (not (memq article gnus-newsgroup-unseen)))
5291      ((eq type 'recent)
5292       (memq article gnus-newsgroup-recent))
5293      (t t))))
5294
5295 (defun gnus-articles-to-read (group &optional read-all)
5296   "Find out what articles the user wants to read."
5297   (let* ((display (gnus-group-find-parameter group 'display))
5298          (articles
5299           ;; Select all articles if `read-all' is non-nil, or if there
5300           ;; are no unread articles.
5301           (if (or read-all
5302                   (and (zerop (length gnus-newsgroup-marked))
5303                        (zerop (length gnus-newsgroup-unreads)))
5304                   ;; Fetch all if the predicate is non-nil.
5305                   gnus-newsgroup-display)
5306               ;; We want to select the headers for all the articles in
5307               ;; the group, so we select either all the active
5308               ;; articles in the group, or (if that's nil), the
5309               ;; articles in the cache.
5310               (or
5311                (gnus-uncompress-range (gnus-active group))
5312                (gnus-cache-articles-in-group group))
5313             ;; Select only the "normal" subset of articles.
5314             (gnus-sorted-nunion
5315              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5316              gnus-newsgroup-unreads)))
5317          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5318          (scored (length scored-list))
5319          (number (length articles))
5320          (marked (+ (length gnus-newsgroup-marked)
5321                     (length gnus-newsgroup-dormant)))
5322          (select
5323           (cond
5324            ((numberp read-all)
5325             read-all)
5326            ((numberp gnus-newsgroup-display)
5327             gnus-newsgroup-display)
5328            (t
5329             (condition-case ()
5330                 (cond
5331                  ((and (or (<= scored marked) (= scored number))
5332                        (numberp gnus-large-newsgroup)
5333                        (> number gnus-large-newsgroup))
5334                   (let* ((cursor-in-echo-area nil)
5335                          (initial (gnus-parameter-large-newsgroup-initial
5336                                    gnus-newsgroup-name))
5337                          (input
5338                           (read-string
5339                            (format
5340                             "How many articles from %s (%s %d): "
5341                             (gnus-limit-string
5342                              (gnus-group-decoded-name gnus-newsgroup-name)
5343                              35)
5344                             (if initial "max" "default")
5345                             number)
5346                            (if initial
5347                                (cons (number-to-string initial)
5348                                      0)))))
5349                     (if (string-match "^[ \t]*$" input) number input)))
5350                  ((and (> scored marked) (< scored number)
5351                        (> (- scored number) 20))
5352                   (let ((input
5353                          (read-string
5354                           (format "%s %s (%d scored, %d total): "
5355                                   "How many articles from"
5356                                   (gnus-group-decoded-name group)
5357                                   scored number))))
5358                     (if (string-match "^[ \t]*$" input)
5359                         number input)))
5360                  (t number))
5361               (quit
5362                (message "Quit getting the articles to read")
5363                nil))))))
5364     (setq select (if (stringp select) (string-to-number select) select))
5365     (if (or (null select) (zerop select))
5366         select
5367       (if (and (not (zerop scored)) (<= (abs select) scored))
5368           (progn
5369             (setq articles (sort scored-list '<))
5370             (setq number (length articles)))
5371         (setq articles (copy-sequence articles)))
5372
5373       (when (< (abs select) number)
5374         (if (< select 0)
5375             ;; Select the N oldest articles.
5376             (setcdr (nthcdr (1- (abs select)) articles) nil)
5377           ;; Select the N most recent articles.
5378           (setq articles (nthcdr (- number select) articles))))
5379       (setq gnus-newsgroup-unselected
5380             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5381       (when gnus-alter-articles-to-read-function
5382         (setq articles
5383               (sort
5384                (funcall gnus-alter-articles-to-read-function
5385                         gnus-newsgroup-name articles)
5386                '<)))
5387       articles)))
5388
5389 (defun gnus-killed-articles (killed articles)
5390   (let (out)
5391     (while articles
5392       (when (inline (gnus-member-of-range (car articles) killed))
5393         (push (car articles) out))
5394       (setq articles (cdr articles)))
5395     out))
5396
5397 (defun gnus-uncompress-marks (marks)
5398   "Uncompress the mark ranges in MARKS."
5399   (let ((uncompressed '(score bookmark))
5400         out)
5401     (while marks
5402       (if (memq (caar marks) uncompressed)
5403           (push (car marks) out)
5404         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5405       (setq marks (cdr marks)))
5406     out))
5407
5408 (defun gnus-article-mark-to-type (mark)
5409   "Return the type of MARK."
5410   (or (cadr (assq mark gnus-article-special-mark-lists))
5411       'list))
5412
5413 (defun gnus-article-unpropagatable-p (mark)
5414   "Return whether MARK should be propagated to back end."
5415   (memq mark gnus-article-unpropagated-mark-lists))
5416
5417 (defun gnus-adjust-marked-articles (info)
5418   "Set all article lists and remove all marks that are no longer valid."
5419   (let* ((marked-lists (gnus-info-marks info))
5420          (active (gnus-active (gnus-info-group info)))
5421          (min (car active))
5422          (max (cdr active))
5423          (types gnus-article-mark-lists)
5424          marks var articles article mark mark-type
5425          bgn end)
5426
5427     (dolist (marks marked-lists)
5428       (setq mark (car marks)
5429             mark-type (gnus-article-mark-to-type mark)
5430             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5431
5432       ;; We set the variable according to the type of the marks list,
5433       ;; and then adjust the marks to a subset of the active articles.
5434       (cond
5435        ;; Adjust "simple" lists - compressed yet unsorted
5436        ((eq mark-type 'list)
5437         ;; Simultaneously uncompress and clip to active range
5438         ;; See gnus-uncompress-range for a description of possible marks
5439         (let (l lh)
5440           (if (not (cadr marks))
5441               (set var nil)
5442             (setq articles (if (numberp (cddr marks))
5443                                (list (cdr marks))
5444                              (cdr marks))
5445                   lh (cons nil nil)
5446                   l lh)
5447
5448             (while (setq article (pop articles))
5449               (cond ((consp article)
5450                      (setq bgn (max (car article) min)
5451                            end (min (cdr article) max))
5452                      (while (<= bgn end)
5453                        (setq l (setcdr l (cons bgn nil))
5454                              bgn (1+ bgn))))
5455                     ((and (<= min article)
5456                           (>= max article))
5457                      (setq l (setcdr l (cons article nil))))))
5458             (set var (cdr lh)))))
5459        ;; Adjust assocs.
5460        ((eq mark-type 'tuple)
5461         (set var (setq articles (cdr marks)))
5462         (when (not (listp (cdr (symbol-value var))))
5463           (set var (list (symbol-value var))))
5464         (when (not (listp (cdr articles)))
5465           (setq articles (list articles)))
5466         (while articles
5467           (when (or (not (consp (setq article (pop articles))))
5468                     (< (car article) min)
5469                     (> (car article) max))
5470             (set var (delq article (symbol-value var))))))
5471        ;; Adjust ranges (sloppily).
5472        ((eq mark-type 'range)
5473         (cond
5474          ((eq mark 'seen)
5475           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5476           ;; It should be (seen (NUM1 . NUM2)).
5477           (when (numberp (cddr marks))
5478             (setcdr marks (list (cdr marks))))
5479           (setq articles (cdr marks))
5480           (while (and articles
5481                       (or (and (consp (car articles))
5482                                (> min (cdar articles)))
5483                           (and (numberp (car articles))
5484                                (> min (car articles)))))
5485             (pop articles))
5486           (set var articles))))))))
5487
5488 (defun gnus-update-missing-marks (missing)
5489   "Go through the list of MISSING articles and remove them from the mark lists."
5490   (when missing
5491     (let (var m)
5492       ;; Go through all types.
5493       (dolist (elem gnus-article-mark-lists)
5494         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5495           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5496           (when (symbol-value var)
5497             ;; This list has articles.  So we delete all missing
5498             ;; articles from it.
5499             (setq m missing)
5500             (while m
5501               (set var (delq (pop m) (symbol-value var))))))))))
5502
5503 (defun gnus-update-marks ()
5504   "Enter the various lists of marked articles into the newsgroup info list."
5505   (let ((types gnus-article-mark-lists)
5506         (info (gnus-get-info gnus-newsgroup-name))
5507         type list newmarked symbol delta-marks)
5508     (when info
5509       ;; Add all marks lists to the list of marks lists.
5510       (while (setq type (pop types))
5511         (setq list (symbol-value
5512                     (setq symbol
5513                           (intern (format "gnus-newsgroup-%s" (car type))))))
5514
5515         (when list
5516           ;; Get rid of the entries of the articles that have the
5517           ;; default score.
5518           (when (and (eq (cdr type) 'score)
5519                      gnus-save-score
5520                      list)
5521             (let* ((arts list)
5522                    (prev (cons nil list))
5523                    (all prev))
5524               (while arts
5525                 (if (or (not (consp (car arts)))
5526                         (= (cdar arts) gnus-summary-default-score))
5527                     (setcdr prev (cdr arts))
5528                   (setq prev arts))
5529                 (setq arts (cdr arts)))
5530               (setq list (cdr all)))))
5531
5532         (when (eq (cdr type) 'seen)
5533           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5534
5535         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5536           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5537
5538         (when (and (gnus-check-backend-function
5539                     'request-set-mark gnus-newsgroup-name)
5540                    (not (gnus-article-unpropagatable-p (cdr type))))
5541           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5542                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5543                  (add (gnus-remove-from-range
5544                        (gnus-copy-sequence list) old)))
5545             (when add
5546               (push (list add 'add (list (cdr type))) delta-marks))
5547             (when del
5548               (push (list del 'del (list (cdr type))) delta-marks))))
5549
5550         (when list
5551           (push (cons (cdr type) list) newmarked)))
5552
5553       (when delta-marks
5554         (unless (gnus-check-group gnus-newsgroup-name)
5555           (error "Can't open server for %s" gnus-newsgroup-name))
5556         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5557
5558       ;; Enter these new marks into the info of the group.
5559       (if (nthcdr 3 info)
5560           (setcar (nthcdr 3 info) newmarked)
5561         ;; Add the marks lists to the end of the info.
5562         (when newmarked
5563           (setcdr (nthcdr 2 info) (list newmarked))))
5564
5565       ;; Cut off the end of the info if there's nothing else there.
5566       (let ((i 5))
5567         (while (and (> i 2)
5568                     (not (nth i info)))
5569           (when (nthcdr (decf i) info)
5570             (setcdr (nthcdr i info) nil)))))))
5571
5572 (defun gnus-set-mode-line (where)
5573   "Set the mode line of the article or summary buffers.
5574 If WHERE is `summary', the summary mode line format will be used."
5575   ;; Is this mode line one we keep updated?
5576   (when (and (memq where gnus-updated-mode-lines)
5577              (symbol-value
5578               (intern (format "gnus-%s-mode-line-format-spec" where))))
5579     (let (mode-string)
5580       (save-excursion
5581         ;; We evaluate this in the summary buffer since these
5582         ;; variables are buffer-local to that buffer.
5583         (set-buffer gnus-summary-buffer)
5584         ;; We bind all these variables that are used in the `eval' form
5585         ;; below.
5586         (let* ((mformat (symbol-value
5587                          (intern
5588                           (format "gnus-%s-mode-line-format-spec" where))))
5589                (gnus-tmp-group-name (gnus-group-decoded-name
5590                                      gnus-newsgroup-name))
5591                (gnus-tmp-article-number (or gnus-current-article 0))
5592                (gnus-tmp-unread gnus-newsgroup-unreads)
5593                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5594                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5595                (gnus-tmp-unread-and-unselected
5596                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5597                             (zerop gnus-tmp-unselected))
5598                        "")
5599                       ((zerop gnus-tmp-unselected)
5600                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5601                       (t (format "{%d(+%d) more}"
5602                                  gnus-tmp-unread-and-unticked
5603                                  gnus-tmp-unselected))))
5604                (gnus-tmp-subject
5605                 (if (and gnus-current-headers
5606                          (vectorp gnus-current-headers))
5607                     (gnus-mode-string-quote
5608                      (mail-header-subject gnus-current-headers))
5609                   ""))
5610                bufname-length max-len
5611                gnus-tmp-header);; passed as argument to any user-format-funcs
5612           (setq mode-string (eval mformat))
5613           (setq bufname-length (if (string-match "%b" mode-string)
5614                                    (- (length
5615                                        (buffer-name
5616                                         (if (eq where 'summary)
5617                                             nil
5618                                           (get-buffer gnus-article-buffer))))
5619                                       2)
5620                                  0))
5621           (setq max-len (max 4 (if gnus-mode-non-string-length
5622                                    (- (window-width)
5623                                       gnus-mode-non-string-length
5624                                       bufname-length)
5625                                  (length mode-string))))
5626           ;; We might have to chop a bit of the string off...
5627           (when (> (length mode-string) max-len)
5628             (setq mode-string
5629                   (concat (gnus-truncate-string mode-string (- max-len 3))
5630                           "...")))
5631           ;; Pad the mode string a bit.
5632           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5633       ;; Update the mode line.
5634       (setq mode-line-buffer-identification
5635             (gnus-mode-line-buffer-identification (list mode-string)))
5636       (set-buffer-modified-p t))))
5637
5638 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5639   "Go through the HEADERS list and add all Xrefs to a hash table.
5640 The resulting hash table is returned, or nil if no Xrefs were found."
5641   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5642          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5643          (xref-hashtb (gnus-make-hashtable))
5644          start group entry number xrefs header)
5645     (while headers
5646       (setq header (pop headers))
5647       (when (and (setq xrefs (mail-header-xref header))
5648                  (not (memq (setq number (mail-header-number header))
5649                             unreads)))
5650         (setq start 0)
5651         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5652           (setq start (match-end 0))
5653           (setq group (if prefix
5654                           (concat prefix (substring xrefs (match-beginning 1)
5655                                                     (match-end 1)))
5656                         (substring xrefs (match-beginning 1) (match-end 1))))
5657           (setq number
5658                 (string-to-int (substring xrefs (match-beginning 2)
5659                                           (match-end 2))))
5660           (if (setq entry (gnus-gethash group xref-hashtb))
5661               (setcdr entry (cons number (cdr entry)))
5662             (gnus-sethash group (cons number nil) xref-hashtb)))))
5663     (and start xref-hashtb)))
5664
5665 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5666   "Look through all the headers and mark the Xrefs as read."
5667   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5668         name info xref-hashtb idlist method nth4)
5669     (save-excursion
5670       (set-buffer gnus-group-buffer)
5671       (when (setq xref-hashtb
5672                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5673         (mapatoms
5674          (lambda (group)
5675            (unless (string= from-newsgroup (setq name (symbol-name group)))
5676              (setq idlist (symbol-value group))
5677              ;; Dead groups are not updated.
5678              (and (prog1
5679                       (setq info (gnus-get-info name))
5680                     (when (stringp (setq nth4 (gnus-info-method info)))
5681                       (setq nth4 (gnus-server-to-method nth4))))
5682                   ;; Only do the xrefs if the group has the same
5683                   ;; select method as the group we have just read.
5684                   (or (gnus-methods-equal-p
5685                        nth4 (gnus-find-method-for-group from-newsgroup))
5686                       virtual
5687                       (equal nth4 (setq method (gnus-find-method-for-group
5688                                                 from-newsgroup)))
5689                       (and (equal (car nth4) (car method))
5690                            (equal (nth 1 nth4) (nth 1 method))))
5691                   gnus-use-cross-reference
5692                   (or (not (eq gnus-use-cross-reference t))
5693                       virtual
5694                       ;; Only do cross-references on subscribed
5695                       ;; groups, if that is what is wanted.
5696                       (<= (gnus-info-level info) gnus-level-subscribed))
5697                   (gnus-group-make-articles-read name idlist))))
5698          xref-hashtb)))))
5699
5700 (defun gnus-compute-read-articles (group articles)
5701   (let* ((entry (gnus-group-entry group))
5702          (info (nth 2 entry))
5703          (active (gnus-active group))
5704          ninfo)
5705     (when entry
5706       ;; First peel off all invalid article numbers.
5707       (when active
5708         (let ((ids articles)
5709               id first)
5710           (while (setq id (pop ids))
5711             (when (and first (> id (cdr active)))
5712               ;; We'll end up in this situation in one particular
5713               ;; obscure situation.  If you re-scan a group and get
5714               ;; a new article that is cross-posted to a different
5715               ;; group that has not been re-scanned, you might get
5716               ;; crossposted article that has a higher number than
5717               ;; Gnus believes possible.  So we re-activate this
5718               ;; group as well.  This might mean doing the
5719               ;; crossposting thingy will *increase* the number
5720               ;; of articles in some groups.  Tsk, tsk.
5721               (setq active (or (gnus-activate-group group) active)))
5722             (when (or (> id (cdr active))
5723                       (< id (car active)))
5724               (setq articles (delq id articles))))))
5725       ;; If the read list is nil, we init it.
5726       (if (and active
5727                (null (gnus-info-read info))
5728                (> (car active) 1))
5729           (setq ninfo (cons 1 (1- (car active))))
5730         (setq ninfo (gnus-info-read info)))
5731       ;; Then we add the read articles to the range.
5732       (gnus-add-to-range
5733        ninfo (setq articles (sort articles '<))))))
5734
5735 (defun gnus-group-make-articles-read (group articles)
5736   "Update the info of GROUP to say that ARTICLES are read."
5737   (let* ((num 0)
5738          (entry (gnus-group-entry group))
5739          (info (nth 2 entry))
5740          (active (gnus-active group))
5741          range)
5742     (when entry
5743       (setq range (gnus-compute-read-articles group articles))
5744       (with-current-buffer gnus-group-buffer
5745         (gnus-undo-register
5746           `(progn
5747              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5748              (gnus-info-set-read ',info ',(gnus-info-read info))
5749              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5750              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5751              (gnus-group-update-group ,group t))))
5752       ;; Add the read articles to the range.
5753       (gnus-info-set-read info range)
5754       (gnus-request-set-mark group (list (list range 'add '(read))))
5755       ;; Then we have to re-compute how many unread
5756       ;; articles there are in this group.
5757       (when active
5758         (cond
5759          ((not range)
5760           (setq num (- (1+ (cdr active)) (car active))))
5761          ((not (listp (cdr range)))
5762           (setq num (- (cdr active) (- (1+ (cdr range))
5763                                        (car range)))))
5764          (t
5765           (while range
5766             (if (numberp (car range))
5767                 (setq num (1+ num))
5768               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5769             (setq range (cdr range)))
5770           (setq num (- (cdr active) num))))
5771         ;; Update the number of unread articles.
5772         (setcar entry num)
5773         ;; Update the group buffer.
5774         (unless (gnus-ephemeral-group-p group)
5775           (gnus-group-update-group group t))))))
5776
5777 (defvar gnus-newsgroup-none-id 0)
5778
5779 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5780   (let ((cur nntp-server-buffer)
5781         (dependencies
5782          (or dependencies
5783              (with-current-buffer gnus-summary-buffer
5784                gnus-newsgroup-dependencies)))
5785         headers id end ref
5786         (mail-parse-charset gnus-newsgroup-charset)
5787         (mail-parse-ignored-charsets
5788          (save-excursion (condition-case nil
5789                              (set-buffer gnus-summary-buffer)
5790                            (error))
5791                          gnus-newsgroup-ignored-charsets)))
5792     (save-excursion
5793       (set-buffer nntp-server-buffer)
5794       ;; Translate all TAB characters into SPACE characters.
5795       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5796       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5797       (ietf-drums-unfold-fws)
5798       (gnus-run-hooks 'gnus-parse-headers-hook)
5799       (let ((case-fold-search t)
5800             in-reply-to header p lines chars ctype)
5801         (goto-char (point-min))
5802         ;; Search to the beginning of the next header.  Error messages
5803         ;; do not begin with 2 or 3.
5804         (while (re-search-forward "^[23][0-9]+ " nil t)
5805           (setq id nil
5806                 ref nil)
5807           ;; This implementation of this function, with nine
5808           ;; search-forwards instead of the one re-search-forward and
5809           ;; a case (which basically was the old function) is actually
5810           ;; about twice as fast, even though it looks messier.  You
5811           ;; can't have everything, I guess.  Speed and elegance
5812           ;; doesn't always go hand in hand.
5813           (setq
5814            header
5815            (make-full-mail-header
5816             ;; Number.
5817             (prog1
5818                 (read cur)
5819               (end-of-line)
5820               (setq p (point))
5821               (narrow-to-region (point)
5822                                 (or (and (search-forward "\n.\n" nil t)
5823                                          (- (point) 2))
5824                                     (point))))
5825             ;; Subject.
5826             (progn
5827               (goto-char p)
5828               (if (search-forward "\nsubject:" nil t)
5829                   (nnheader-header-value)
5830                 "(none)"))
5831             ;; From.
5832             (progn
5833               (goto-char p)
5834               (if (search-forward "\nfrom:" nil t)
5835                   (nnheader-header-value)
5836                 "(nobody)"))
5837             ;; Date.
5838             (progn
5839               (goto-char p)
5840               (if (search-forward "\ndate:" nil t)
5841                   (nnheader-header-value) ""))
5842             ;; Message-ID.
5843             (progn
5844               (goto-char p)
5845               (setq id (if (re-search-forward
5846                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5847                            ;; We do it this way to make sure the Message-ID
5848                            ;; is (somewhat) syntactically valid.
5849                            (buffer-substring (match-beginning 1)
5850                                              (match-end 1))
5851                          ;; If there was no message-id, we just fake one
5852                          ;; to make subsequent routines simpler.
5853                          (nnheader-generate-fake-message-id))))
5854             ;; References.
5855             (progn
5856               (goto-char p)
5857               (if (search-forward "\nreferences:" nil t)
5858                   (progn
5859                     (setq end (point))
5860                     (prog1
5861                         (nnheader-header-value)
5862                       (setq ref
5863                             (buffer-substring
5864                              (progn
5865                                ;; (end-of-line)
5866                                (search-backward ">" end t)
5867                                (1+ (point)))
5868                              (progn
5869                                (search-backward "<" end t)
5870                                (point))))))
5871                 ;; Get the references from the in-reply-to header if there
5872                 ;; were no references and the in-reply-to header looks
5873                 ;; promising.
5874                 (if (and (search-forward "\nin-reply-to:" nil t)
5875                          (setq in-reply-to (nnheader-header-value))
5876                          (string-match "<[^>]+>" in-reply-to))
5877                     (let (ref2)
5878                       (setq ref (substring in-reply-to (match-beginning 0)
5879                                            (match-end 0)))
5880                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5881                         (setq ref2 (substring in-reply-to (match-beginning 0)
5882                                               (match-end 0)))
5883                         (when (> (length ref2) (length ref))
5884                           (setq ref ref2)))
5885                       ref)
5886                   (setq ref nil))))
5887             ;; Chars.
5888             (progn
5889               (goto-char p)
5890               (if (search-forward "\nchars: " nil t)
5891                   (if (numberp (setq chars (ignore-errors (read cur))))
5892                       chars -1)
5893                 -1))
5894             ;; Lines.
5895             (progn
5896               (goto-char p)
5897               (if (search-forward "\nlines: " nil t)
5898                   (if (numberp (setq lines (ignore-errors (read cur))))
5899                       lines -1)
5900                 -1))
5901             ;; Xref.
5902             (progn
5903               (goto-char p)
5904               (and (search-forward "\nxref:" nil t)
5905                    (nnheader-header-value)))
5906             ;; Extra.
5907             (when gnus-extra-headers
5908               (let ((extra gnus-extra-headers)
5909                     out)
5910                 (while extra
5911                   (goto-char p)
5912                   (when (search-forward
5913                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5914                     (push (cons (car extra) (nnheader-header-value)) out))
5915                   (pop extra))
5916                 out))))
5917           (goto-char p)
5918           (if (and (search-forward "\ncontent-type: " nil t)
5919                    (setq ctype (nnheader-header-value)))
5920               (mime-entity-set-content-type-internal
5921                header (mime-parse-Content-Type ctype)))
5922           (when (equal id ref)
5923             (setq ref nil))
5924
5925           (when gnus-alter-header-function
5926             (funcall gnus-alter-header-function header)
5927             (setq id (mail-header-id header)
5928                   ref (gnus-parent-id (mail-header-references header))))
5929
5930           (when (setq header
5931                       (gnus-dependencies-add-header
5932                        header dependencies force-new))
5933             (push header headers))
5934           (goto-char (point-max))
5935           (widen))
5936         (nreverse headers)))))
5937
5938 ;; Goes through the xover lines and returns a list of vectors
5939 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5940                                                   force-new dependencies
5941                                                   group also-fetch-heads)
5942   "Parse the news overview data in the server buffer.
5943 Return a list of headers that match SEQUENCE (see
5944 `nntp-retrieve-headers')."
5945   ;; Get the Xref when the users reads the articles since most/some
5946   ;; NNTP servers do not include Xrefs when using XOVER.
5947   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5948   (let ((mail-parse-charset gnus-newsgroup-charset)
5949         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5950         (cur nntp-server-buffer)
5951         (dependencies (or dependencies gnus-newsgroup-dependencies))
5952         (allp (cond
5953                ((eq gnus-read-all-available-headers t)
5954                 t)
5955                ((stringp gnus-read-all-available-headers)
5956                 (string-match gnus-read-all-available-headers group))
5957                (t
5958                 nil)))
5959         number headers header)
5960     (save-excursion
5961       (set-buffer nntp-server-buffer)
5962       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5963       ;; Allow the user to mangle the headers before parsing them.
5964       (gnus-run-hooks 'gnus-parse-headers-hook)
5965       (goto-char (point-min))
5966       (gnus-parse-without-error
5967         (while (and (or sequence allp)
5968                     (not (eobp)))
5969           (setq number (read cur))
5970           (when (not allp)
5971             (while (and sequence
5972                         (< (car sequence) number))
5973               (setq sequence (cdr sequence))))
5974           (when (and (or allp
5975                          (and sequence
5976                               (eq number (car sequence))))
5977                      (progn
5978                        (setq sequence (cdr sequence))
5979                        (setq header (inline
5980                                       (gnus-nov-parse-line
5981                                        number dependencies force-new)))))
5982             (push header headers))
5983           (forward-line 1)))
5984       ;; A common bug in inn is that if you have posted an article and
5985       ;; then retrieves the active file, it will answer correctly --
5986       ;; the new article is included.  However, a NOV entry for the
5987       ;; article may not have been generated yet, so this may fail.
5988       ;; We work around this problem by retrieving the last few
5989       ;; headers using HEAD.
5990       (if (or (not also-fetch-heads)
5991               (not sequence))
5992           ;; We (probably) got all the headers.
5993           (nreverse headers)
5994         (let ((gnus-nov-is-evil t))
5995           (nconc
5996            (nreverse headers)
5997            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5998              (gnus-get-newsgroup-headers))))))))
5999
6000 (defun gnus-article-get-xrefs ()
6001   "Fill in the Xref value in `gnus-current-headers', if necessary.
6002 This is meant to be called in `gnus-article-internal-prepare-hook'."
6003   (let ((headers (with-current-buffer gnus-summary-buffer
6004                    gnus-current-headers)))
6005     (or (not gnus-use-cross-reference)
6006         (not headers)
6007         (and (mail-header-xref headers)
6008              (not (string= (mail-header-xref headers) "")))
6009         (let ((case-fold-search t)
6010               xref)
6011           (save-restriction
6012             (nnheader-narrow-to-headers)
6013             (goto-char (point-min))
6014             (when (or (and (not (eobp))
6015                            (eq (downcase (char-after)) ?x)
6016                            (looking-at "Xref:"))
6017                       (search-forward "\nXref:" nil t))
6018               (goto-char (1+ (match-end 0)))
6019               (setq xref (buffer-substring (point) (point-at-eol)))
6020               (mail-header-set-xref headers xref)))))))
6021
6022 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6023   "Find article ID and insert the summary line for that article.
6024 OLD-HEADER can either be a header or a line number to insert
6025 the subject line on."
6026   (let* ((line (and (numberp old-header) old-header))
6027          (old-header (and (vectorp old-header) old-header))
6028          (header (cond ((and old-header use-old-header)
6029                         old-header)
6030                        ((and (numberp id)
6031                              (gnus-number-to-header id))
6032                         (gnus-number-to-header id))
6033                        (t
6034                         (gnus-read-header id))))
6035          (number (and (numberp id) id))
6036          d)
6037     (when header
6038       ;; Rebuild the thread that this article is part of and go to the
6039       ;; article we have fetched.
6040       (when (and (not gnus-show-threads)
6041                  old-header)
6042         (when (and number
6043                    (setq d (gnus-data-find (mail-header-number old-header))))
6044           (goto-char (gnus-data-pos d))
6045           (gnus-data-remove
6046            number
6047            (- (point-at-bol)
6048               (prog1
6049                   (1+ (point-at-eol))
6050                 (gnus-delete-line))))))
6051       (when old-header
6052         (mail-header-set-number header (mail-header-number old-header)))
6053       (setq gnus-newsgroup-sparse
6054             (delq (setq number (mail-header-number header))
6055                   gnus-newsgroup-sparse))
6056       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6057       (push number gnus-newsgroup-limit)
6058       (gnus-rebuild-thread (mail-header-id header) line)
6059       (gnus-summary-goto-subject number nil t))
6060     (when (and (numberp number)
6061                (> number 0))
6062       ;; We have to update the boundaries even if we can't fetch the
6063       ;; article if ID is a number -- so that the next `P' or `N'
6064       ;; command will fetch the previous (or next) article even
6065       ;; if the one we tried to fetch this time has been canceled.
6066       (when (> number gnus-newsgroup-end)
6067         (setq gnus-newsgroup-end number))
6068       (when (< number gnus-newsgroup-begin)
6069         (setq gnus-newsgroup-begin number))
6070       (setq gnus-newsgroup-unselected
6071             (delq number gnus-newsgroup-unselected)))
6072     ;; Report back a success?
6073     (and header (mail-header-number header))))
6074
6075 ;;; Process/prefix in the summary buffer
6076
6077 (defun gnus-summary-work-articles (n)
6078   "Return a list of articles to be worked upon.
6079 The prefix argument, the list of process marked articles, and the
6080 current article will be taken into consideration."
6081   (save-excursion
6082     (set-buffer gnus-summary-buffer)
6083     (cond
6084      (n
6085       ;; A numerical prefix has been given.
6086       (setq n (prefix-numeric-value n))
6087       (let ((backward (< n 0))
6088             (n (abs (prefix-numeric-value n)))
6089             articles article)
6090         (save-excursion
6091           (while
6092               (and (> n 0)
6093                    (push (setq article (gnus-summary-article-number))
6094                          articles)
6095                    (if backward
6096                        (gnus-summary-find-prev nil article)
6097                      (gnus-summary-find-next nil article)))
6098             (decf n)))
6099         (nreverse articles)))
6100      ((and (gnus-region-active-p) (mark))
6101       (message "region active")
6102       ;; Work on the region between point and mark.
6103       (let ((max (max (point) (mark)))
6104             articles article)
6105         (save-excursion
6106           (goto-char (min (point) (mark)))
6107           (while
6108               (and
6109                (push (setq article (gnus-summary-article-number)) articles)
6110                (gnus-summary-find-next nil article)
6111                (< (point) max)))
6112           (nreverse articles))))
6113      (gnus-newsgroup-processable
6114       ;; There are process-marked articles present.
6115       ;; Save current state.
6116       (gnus-summary-save-process-mark)
6117       ;; Return the list.
6118       (reverse gnus-newsgroup-processable))
6119      (t
6120       ;; Just return the current article.
6121       (list (gnus-summary-article-number))))))
6122
6123 (defmacro gnus-summary-iterate (arg &rest forms)
6124   "Iterate over the process/prefixed articles and do FORMS.
6125 ARG is the interactive prefix given to the command.  FORMS will be
6126 executed with point over the summary line of the articles."
6127   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6128     `(let ((,articles (gnus-summary-work-articles ,arg)))
6129        (while ,articles
6130          (gnus-summary-goto-subject (car ,articles))
6131          ,@forms
6132          (pop ,articles)))))
6133
6134 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6135 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6136
6137 (defun gnus-summary-save-process-mark ()
6138   "Push the current set of process marked articles on the stack."
6139   (interactive)
6140   (push (copy-sequence gnus-newsgroup-processable)
6141         gnus-newsgroup-process-stack))
6142
6143 (defun gnus-summary-kill-process-mark ()
6144   "Push the current set of process marked articles on the stack and unmark."
6145   (interactive)
6146   (gnus-summary-save-process-mark)
6147   (gnus-summary-unmark-all-processable))
6148
6149 (defun gnus-summary-yank-process-mark ()
6150   "Pop the last process mark state off the stack and restore it."
6151   (interactive)
6152   (unless gnus-newsgroup-process-stack
6153     (error "Empty mark stack"))
6154   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6155
6156 (defun gnus-summary-process-mark-set (set)
6157   "Make SET into the current process marked articles."
6158   (gnus-summary-unmark-all-processable)
6159   (while set
6160     (gnus-summary-set-process-mark (pop set))))
6161
6162 ;;; Searching and stuff
6163
6164 (defun gnus-summary-search-group (&optional backward use-level)
6165   "Search for next unread newsgroup.
6166 If optional argument BACKWARD is non-nil, search backward instead."
6167   (save-excursion
6168     (set-buffer gnus-group-buffer)
6169     (when (gnus-group-search-forward
6170            backward nil (if use-level (gnus-group-group-level) nil))
6171       (gnus-group-group-name))))
6172
6173 (defun gnus-summary-best-group (&optional exclude-group)
6174   "Find the name of the best unread group.
6175 If EXCLUDE-GROUP, do not go to this group."
6176   (with-current-buffer gnus-group-buffer
6177     (save-excursion
6178       (gnus-group-best-unread-group exclude-group))))
6179
6180 (defun gnus-summary-find-next (&optional unread article backward)
6181   (if backward
6182       (gnus-summary-find-prev unread article)
6183     (let* ((dummy (gnus-summary-article-intangible-p))
6184            (article (or article (gnus-summary-article-number)))
6185            (data (gnus-data-find-list article))
6186            result)
6187       (when (and (not dummy)
6188                  (or (not gnus-summary-check-current)
6189                      (not unread)
6190                      (not (gnus-data-unread-p (car data)))))
6191         (setq data (cdr data)))
6192       (when (setq result
6193                   (if unread
6194                       (progn
6195                         (while data
6196                           (unless (memq (gnus-data-number (car data))
6197                                         (cond
6198                                          ((eq gnus-auto-goto-ignores
6199                                               'always-undownloaded)
6200                                           gnus-newsgroup-undownloaded)
6201                                          (gnus-plugged
6202                                           nil)
6203                                          ((eq gnus-auto-goto-ignores
6204                                               'unfetched)
6205                                           gnus-newsgroup-unfetched)
6206                                          ((eq gnus-auto-goto-ignores
6207                                               'undownloaded)
6208                                           gnus-newsgroup-undownloaded)))
6209                             (when (gnus-data-unread-p (car data))
6210                               (setq result (car data)
6211                                     data nil)))
6212                           (setq data (cdr data)))
6213                         result)
6214                     (car data)))
6215         (goto-char (gnus-data-pos result))
6216         (gnus-data-number result)))))
6217
6218 (defun gnus-summary-find-prev (&optional unread article)
6219   (let* ((eobp (eobp))
6220          (article (or article (gnus-summary-article-number)))
6221          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6222          result)
6223     (when (and (not eobp)
6224                (or (not gnus-summary-check-current)
6225                    (not unread)
6226                    (not (gnus-data-unread-p (car data)))))
6227       (setq data (cdr data)))
6228     (when (setq result
6229                 (if unread
6230                     (progn
6231                       (while data
6232                         (unless (memq (gnus-data-number (car data))
6233                                       (cond
6234                                        ((eq gnus-auto-goto-ignores
6235                                             'always-undownloaded)
6236                                         gnus-newsgroup-undownloaded)
6237                                        (gnus-plugged
6238                                         nil)
6239                                        ((eq gnus-auto-goto-ignores
6240                                             'unfetched)
6241                                         gnus-newsgroup-unfetched)
6242                                        ((eq gnus-auto-goto-ignores
6243                                             'undownloaded)
6244                                         gnus-newsgroup-undownloaded)))
6245                           (when (gnus-data-unread-p (car data))
6246                             (setq result (car data)
6247                                   data nil)))
6248                         (setq data (cdr data)))
6249                       result)
6250                   (car data)))
6251       (goto-char (gnus-data-pos result))
6252       (gnus-data-number result))))
6253
6254 (defun gnus-summary-find-subject (subject &optional unread backward article)
6255   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6256          (article (or article (gnus-summary-article-number)))
6257          (articles (gnus-data-list backward))
6258          (arts (gnus-data-find-list article articles))
6259          result)
6260     (when (or (not gnus-summary-check-current)
6261               (not unread)
6262               (not (gnus-data-unread-p (car arts))))
6263       (setq arts (cdr arts)))
6264     (while arts
6265       (and (or (not unread)
6266                (gnus-data-unread-p (car arts)))
6267            (vectorp (gnus-data-header (car arts)))
6268            (gnus-subject-equal
6269             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6270            (setq result (car arts)
6271                  arts nil))
6272       (setq arts (cdr arts)))
6273     (and result
6274          (goto-char (gnus-data-pos result))
6275          (gnus-data-number result))))
6276
6277 (defun gnus-summary-search-forward (&optional unread subject backward)
6278   "Search forward for an article.
6279 If UNREAD, look for unread articles.  If SUBJECT, look for
6280 articles with that subject.  If BACKWARD, search backward instead."
6281   (cond (subject (gnus-summary-find-subject subject unread backward))
6282         (backward (gnus-summary-find-prev unread))
6283         (t (gnus-summary-find-next unread))))
6284
6285 (defun gnus-recenter (&optional n)
6286   "Center point in window and redisplay frame.
6287 Also do horizontal recentering."
6288   (interactive "P")
6289   (when (and gnus-auto-center-summary
6290              (not (eq gnus-auto-center-summary 'vertical)))
6291     (gnus-horizontal-recenter))
6292   (recenter n))
6293
6294 (defun gnus-summary-recenter ()
6295   "Center point in the summary window.
6296 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6297 displayed, no centering will be performed."
6298   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6299   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6300   (interactive)
6301   ;; The user has to want it.
6302   (when gnus-auto-center-summary
6303     (let* ((top (cond ((< (window-height) 4) 0)
6304                       ((< (window-height) 7) 1)
6305                       (t (if (numberp gnus-auto-center-summary)
6306                              gnus-auto-center-summary
6307                            2))))
6308            (height (1- (window-height)))
6309            (bottom (save-excursion (goto-char (point-max))
6310                                    (forward-line (- height))
6311                                    (point)))
6312            (window (get-buffer-window (current-buffer))))
6313       (when (get-buffer-window gnus-article-buffer)
6314         ;; Only do recentering when the article buffer is displayed,
6315         ;; Set the window start to either `bottom', which is the biggest
6316         ;; possible valid number, or the second line from the top,
6317         ;; whichever is the least.
6318         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6319           (if (> bottom top-pos)
6320               ;; Keep the second line from the top visible
6321               (set-window-start window top-pos t)
6322             ;; Try to keep the bottom line visible; if it's partially
6323             ;; obscured, either scroll one more line to make it fully
6324             ;; visible, or revert to using TOP-POS.
6325             (save-excursion
6326               (goto-char (point-max))
6327               (forward-line -1)
6328               (let ((last-line-start (point)))
6329                 (goto-char bottom)
6330                 (set-window-start window (point) t)
6331                 (when (not (pos-visible-in-window-p last-line-start window))
6332                   (forward-line 1)
6333                   (set-window-start window (min (point) top-pos) t)))))))
6334       ;; Do horizontal recentering while we're at it.
6335       (when (and (get-buffer-window (current-buffer) t)
6336                  (not (eq gnus-auto-center-summary 'vertical)))
6337         (let ((selected (selected-window)))
6338           (select-window (get-buffer-window (current-buffer) t))
6339           (gnus-summary-position-point)
6340           (gnus-horizontal-recenter)
6341           (select-window selected))))))
6342
6343 (defun gnus-summary-jump-to-group (newsgroup)
6344   "Move point to NEWSGROUP in group mode buffer."
6345   ;; Keep update point of group mode buffer if visible.
6346   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6347       (save-window-excursion
6348         ;; Take care of tree window mode.
6349         (when (get-buffer-window gnus-group-buffer)
6350           (pop-to-buffer gnus-group-buffer))
6351         (gnus-group-jump-to-group newsgroup))
6352     (save-excursion
6353       ;; Take care of tree window mode.
6354       (if (get-buffer-window gnus-group-buffer)
6355           (pop-to-buffer gnus-group-buffer)
6356         (set-buffer gnus-group-buffer))
6357       (gnus-group-jump-to-group newsgroup))))
6358
6359 ;; This function returns a list of article numbers based on the
6360 ;; difference between the ranges of read articles in this group and
6361 ;; the range of active articles.
6362 (defun gnus-list-of-unread-articles (group)
6363   (let* ((read (gnus-info-read (gnus-get-info group)))
6364          (active (or (gnus-active group) (gnus-activate-group group)))
6365          (last (cdr active))
6366          first nlast unread)
6367     ;; If none are read, then all are unread.
6368     (if (not read)
6369         (setq first (car active))
6370       ;; If the range of read articles is a single range, then the
6371       ;; first unread article is the article after the last read
6372       ;; article.  Sounds logical, doesn't it?
6373       (if (and (not (listp (cdr read)))
6374                (or (< (car read) (car active))
6375                    (progn (setq read (list read))
6376                           nil)))
6377           (setq first (max (car active) (1+ (cdr read))))
6378         ;; `read' is a list of ranges.
6379         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6380                                   (caar read)))
6381                   1)
6382           (setq first (car active)))
6383         (while read
6384           (when first
6385             (while (< first nlast)
6386               (setq unread (cons first unread)
6387                     first (1+ first))))
6388           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6389           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6390           (setq read (cdr read)))))
6391     ;; And add the last unread articles.
6392     (while (<= first last)
6393       (setq unread (cons first unread)
6394             first (1+ first)))
6395     ;; Return the list of unread articles.
6396     (delq 0 (nreverse unread))))
6397
6398 (defun gnus-list-of-read-articles (group)
6399   "Return a list of unread, unticked and non-dormant articles."
6400   (let* ((info (gnus-get-info group))
6401          (marked (gnus-info-marks info))
6402          (active (gnus-active group)))
6403     (and info active
6404          (gnus-list-range-difference
6405           (gnus-list-range-difference
6406            (gnus-sorted-complement
6407             (gnus-uncompress-range active)
6408             (gnus-list-of-unread-articles group))
6409            (cdr (assq 'dormant marked)))
6410           (cdr (assq 'tick marked))))))
6411
6412 ;; This function returns a sequence of article numbers based on the
6413 ;; difference between the ranges of read articles in this group and
6414 ;; the range of active articles.
6415 (defun gnus-sequence-of-unread-articles (group)
6416   (let* ((read (gnus-info-read (gnus-get-info group)))
6417          (active (or (gnus-active group) (gnus-activate-group group)))
6418          (last (cdr active))
6419          first nlast unread)
6420     ;; If none are read, then all are unread.
6421     (if (not read)
6422         (setq first (car active))
6423       ;; If the range of read articles is a single range, then the
6424       ;; first unread article is the article after the last read
6425       ;; article.  Sounds logical, doesn't it?
6426       (if (and (not (listp (cdr read)))
6427                (or (< (car read) (car active))
6428                    (progn (setq read (list read))
6429                           nil)))
6430           (setq first (max (car active) (1+ (cdr read))))
6431         ;; `read' is a list of ranges.
6432         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6433                                   (caar read)))
6434                   1)
6435           (setq first (car active)))
6436         (while read
6437           (when first
6438             (push (cons first nlast) unread))
6439           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6440           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6441           (setq read (cdr read)))))
6442     ;; And add the last unread articles.
6443     (cond ((< first last)
6444            (push (cons first last) unread))
6445           ((= first last)
6446            (push first unread)))
6447     ;; Return the sequence of unread articles.
6448     (delq 0 (nreverse unread))))
6449
6450 ;; Various summary commands
6451
6452 (defun gnus-summary-select-article-buffer ()
6453   "Reconfigure windows to show article buffer."
6454   (interactive)
6455   (if (not (gnus-buffer-live-p gnus-article-buffer))
6456       (error "There is no article buffer for this summary buffer")
6457     (gnus-configure-windows 'article)
6458     (select-window (get-buffer-window gnus-article-buffer))))
6459
6460 (defun gnus-summary-universal-argument (arg)
6461   "Perform any operation on all articles that are process/prefixed."
6462   (interactive "P")
6463   (let ((articles (gnus-summary-work-articles arg))
6464         func article)
6465     (if (eq
6466          (setq
6467           func
6468           (key-binding
6469            (read-key-sequence
6470             (substitute-command-keys
6471              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6472          'undefined)
6473         (gnus-error 1 "Undefined key")
6474       (save-excursion
6475         (while articles
6476           (gnus-summary-goto-subject (setq article (pop articles)))
6477           (let (gnus-newsgroup-processable)
6478             (command-execute func))
6479           (gnus-summary-remove-process-mark article)))))
6480   (gnus-summary-position-point))
6481
6482 (defun gnus-summary-toggle-truncation (&optional arg)
6483   "Toggle truncation of summary lines.
6484 With ARG, turn line truncation on if ARG is positive."
6485   (interactive "P")
6486   (setq truncate-lines
6487         (if (null arg) (not truncate-lines)
6488           (> (prefix-numeric-value arg) 0)))
6489   (redraw-display))
6490
6491 (defun gnus-summary-find-for-reselect ()
6492   "Return the number of an article to stay on across a reselect.
6493 The current article is considered, then following articles, then previous
6494 articles.  An article is sought which is not cancelled and isn't a temporary
6495 insertion from another group.  If there's no such then return a dummy 0."
6496   (let (found)
6497     (dolist (rev '(nil t))
6498       (unless found      ; don't demand the reverse list if we don't need it
6499         (let ((data (gnus-data-find-list
6500                      (gnus-summary-article-number) (gnus-data-list rev))))
6501           (while (and data (not found))
6502             (if (and (< 0 (gnus-data-number (car data)))
6503                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6504                 (setq found (gnus-data-number (car data))))
6505             (setq data (cdr data))))))
6506     (or found 0)))
6507
6508 (defun gnus-summary-reselect-current-group (&optional all rescan)
6509   "Exit and then reselect the current newsgroup.
6510 The prefix argument ALL means to select all articles."
6511   (interactive "P")
6512   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6513     (error "Ephemeral groups can't be reselected"))
6514   (let ((current-subject (gnus-summary-find-for-reselect))
6515         (group gnus-newsgroup-name))
6516     (setq gnus-newsgroup-begin nil)
6517     (gnus-summary-exit nil 'leave-hidden)
6518     ;; We have to adjust the point of group mode buffer because
6519     ;; point was moved to the next unread newsgroup by exiting.
6520     (gnus-summary-jump-to-group group)
6521     (when rescan
6522       (save-excursion
6523         (save-window-excursion
6524           ;; Don't show group contents.
6525           (set-window-start (selected-window) (point-max))
6526           (gnus-group-get-new-news-this-group 1))))
6527     (gnus-group-read-group all t)
6528     (gnus-summary-goto-subject current-subject nil t)))
6529
6530 (defun gnus-summary-rescan-group (&optional all)
6531   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6532   (interactive "P")
6533   (gnus-summary-reselect-current-group all t))
6534
6535 (defun gnus-summary-update-info (&optional non-destructive)
6536   (save-excursion
6537     (let ((group gnus-newsgroup-name))
6538       (when group
6539         (when gnus-newsgroup-kill-headers
6540           (setq gnus-newsgroup-killed
6541                 (gnus-compress-sequence
6542                  (gnus-sorted-union
6543                   (gnus-list-range-intersection
6544                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6545                   gnus-newsgroup-unreads)
6546                  t)))
6547         (unless (listp (cdr gnus-newsgroup-killed))
6548           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6549         (let ((headers gnus-newsgroup-headers))
6550           ;; Set the new ranges of read articles.
6551           (with-current-buffer gnus-group-buffer
6552             (gnus-undo-force-boundary))
6553           (gnus-update-read-articles
6554            group (gnus-sorted-union
6555                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6556           ;; Set the current article marks.
6557           (let ((gnus-newsgroup-scored
6558                  (if (and (not gnus-save-score)
6559                           (not non-destructive))
6560                      nil
6561                    gnus-newsgroup-scored)))
6562             (save-excursion
6563               (gnus-update-marks)))
6564           ;; Do the cross-ref thing.
6565           (when gnus-use-cross-reference
6566             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6567           ;; Do not switch windows but change the buffer to work.
6568           (set-buffer gnus-group-buffer)
6569           (unless (gnus-ephemeral-group-p group)
6570             (gnus-group-update-group group)))))))
6571
6572 (defun gnus-summary-save-newsrc (&optional force)
6573   "Save the current number of read/marked articles in the dribble buffer.
6574 The dribble buffer will then be saved.
6575 If FORCE (the prefix), also save the .newsrc file(s)."
6576   (interactive "P")
6577   (gnus-summary-update-info t)
6578   (if force
6579       (gnus-save-newsrc-file)
6580     (gnus-dribble-save)))
6581
6582 (defun gnus-summary-exit (&optional temporary leave-hidden)
6583   "Exit reading current newsgroup, and then return to group selection mode.
6584 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6585   (interactive)
6586   (gnus-set-global-variables)
6587   (gnus-kill-save-kill-buffer)
6588   (gnus-async-halt-prefetch)
6589   (let* ((group gnus-newsgroup-name)
6590          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6591          (gnus-group-is-exiting-p t)
6592          (mode major-mode)
6593          (group-point nil)
6594          (buf (current-buffer)))
6595     (unless quit-config
6596       ;; Do adaptive scoring, and possibly save score files.
6597       (when gnus-newsgroup-adaptive
6598         (gnus-score-adaptive))
6599       (when gnus-use-scoring
6600         (gnus-score-save)))
6601     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6602     ;; If we have several article buffers, we kill them at exit.
6603     (unless gnus-single-article-buffer
6604       (gnus-kill-buffer gnus-original-article-buffer)
6605       (setq gnus-article-current nil))
6606     (when gnus-use-cache
6607       (gnus-cache-possibly-remove-articles)
6608       (gnus-cache-save-buffers))
6609     (gnus-async-prefetch-remove-group group)
6610     (when gnus-suppress-duplicates
6611       (gnus-dup-enter-articles))
6612     (when gnus-use-trees
6613       (gnus-tree-close group))
6614     (when gnus-use-cache
6615       (gnus-cache-write-active))
6616     ;; Remove entries for this group.
6617     (nnmail-purge-split-history (gnus-group-real-name group))
6618     ;; Make all changes in this group permanent.
6619     (unless quit-config
6620       (gnus-run-hooks 'gnus-exit-group-hook)
6621       (gnus-summary-update-info))
6622     (gnus-close-group group)
6623     ;; Make sure where we were, and go to next newsgroup.
6624     (set-buffer gnus-group-buffer)
6625     (unless quit-config
6626       (gnus-group-jump-to-group group))
6627     (gnus-run-hooks 'gnus-summary-exit-hook)
6628     (unless (or quit-config
6629                 ;; If this group has disappeared from the summary
6630                 ;; buffer, don't skip forwards.
6631                 (not (string= group (gnus-group-group-name))))
6632       (gnus-group-next-unread-group 1))
6633     (setq group-point (point))
6634     (if temporary
6635         nil                             ;Nothing to do.
6636       ;; If we have several article buffers, we kill them at exit.
6637       (unless gnus-single-article-buffer
6638         (gnus-kill-buffer gnus-article-buffer)
6639         (gnus-kill-buffer gnus-original-article-buffer)
6640         (setq gnus-article-current nil))
6641       (set-buffer buf)
6642       (if (not gnus-kill-summary-on-exit)
6643           (progn
6644             (gnus-deaden-summary)
6645             (setq mode nil))
6646         ;; We set all buffer-local variables to nil.  It is unclear why
6647         ;; this is needed, but if we don't, buffer-local variables are
6648         ;; not garbage-collected, it seems.  This would the lead to en
6649         ;; ever-growing Emacs.
6650         (gnus-summary-clear-local-variables)
6651         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6652           (gnus-summary-clear-local-variables))
6653         (when (get-buffer gnus-article-buffer)
6654           (bury-buffer gnus-article-buffer))
6655         ;; We clear the global counterparts of the buffer-local
6656         ;; variables as well, just to be on the safe side.
6657         (set-buffer gnus-group-buffer)
6658         (gnus-summary-clear-local-variables)
6659         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6660           (gnus-summary-clear-local-variables))
6661         ;; Return to group mode buffer.
6662         (when (eq mode 'gnus-summary-mode)
6663           (gnus-kill-buffer buf)))
6664       (setq gnus-current-select-method gnus-select-method)
6665       (if leave-hidden
6666           (set-buffer gnus-group-buffer)
6667         (pop-to-buffer gnus-group-buffer))
6668       (if (not quit-config)
6669           (progn
6670             (goto-char group-point)
6671             (unless leave-hidden
6672               (gnus-configure-windows 'group 'force))
6673             (unless (pos-visible-in-window-p)
6674               (forward-line (/ (static-if (featurep 'xemacs)
6675                                    (window-displayed-height)
6676                                  (1- (window-height)))
6677                                -2))
6678               (set-window-start (selected-window) (point))
6679               (goto-char group-point)))
6680         (gnus-handle-ephemeral-exit quit-config))
6681       ;; Clear the current group name.
6682       (unless quit-config
6683         (setq gnus-newsgroup-name nil)))))
6684
6685 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6686 (defun gnus-summary-exit-no-update (&optional no-questions)
6687   "Quit reading current newsgroup without updating read article info."
6688   (interactive)
6689   (let* ((group gnus-newsgroup-name)
6690          (gnus-group-is-exiting-p t)
6691          (gnus-group-is-exiting-without-update-p t)
6692          (quit-config (gnus-group-quit-config group)))
6693     (when (or no-questions
6694               gnus-expert-user
6695               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6696       (gnus-async-halt-prefetch)
6697       (run-hooks 'gnus-summary-prepare-exit-hook)
6698       ;; If we have several article buffers, we kill them at exit.
6699       (unless gnus-single-article-buffer
6700         (gnus-kill-buffer gnus-article-buffer)
6701         (gnus-kill-buffer gnus-original-article-buffer)
6702         (setq gnus-article-current nil))
6703       (if (not gnus-kill-summary-on-exit)
6704           (gnus-deaden-summary)
6705         (gnus-close-group group)
6706         (gnus-summary-clear-local-variables)
6707         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6708           (gnus-summary-clear-local-variables))
6709         (set-buffer gnus-group-buffer)
6710         (gnus-summary-clear-local-variables)
6711         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6712           (gnus-summary-clear-local-variables))
6713         (gnus-kill-buffer gnus-summary-buffer))
6714       (unless gnus-single-article-buffer
6715         (setq gnus-article-current nil))
6716       (when gnus-use-trees
6717         (gnus-tree-close group))
6718       (gnus-async-prefetch-remove-group group)
6719       (when (get-buffer gnus-article-buffer)
6720         (bury-buffer gnus-article-buffer))
6721       ;; Return to the group buffer.
6722       (gnus-configure-windows 'group 'force)
6723       ;; Clear the current group name.
6724       (setq gnus-newsgroup-name nil)
6725       (unless (gnus-ephemeral-group-p group)
6726         (gnus-group-update-group group))
6727       (when (equal (gnus-group-group-name) group)
6728         (gnus-group-next-unread-group 1))
6729       (when quit-config
6730         (gnus-handle-ephemeral-exit quit-config)))))
6731
6732 (defun gnus-handle-ephemeral-exit (quit-config)
6733   "Handle movement when leaving an ephemeral group.
6734 The state which existed when entering the ephemeral is reset."
6735   (if (not (buffer-name (car quit-config)))
6736       (gnus-configure-windows 'group 'force)
6737     (set-buffer (car quit-config))
6738     (cond ((eq major-mode 'gnus-summary-mode)
6739            (gnus-set-global-variables))
6740           ((eq major-mode 'gnus-article-mode)
6741            (save-excursion
6742              ;; The `gnus-summary-buffer' variable may point
6743              ;; to the old summary buffer when using a single
6744              ;; article buffer.
6745              (unless (gnus-buffer-live-p gnus-summary-buffer)
6746                (set-buffer gnus-group-buffer))
6747              (set-buffer gnus-summary-buffer)
6748              (gnus-set-global-variables))))
6749     (if (or (eq (cdr quit-config) 'article)
6750             (eq (cdr quit-config) 'pick))
6751         (progn
6752           ;; The current article may be from the ephemeral group
6753           ;; thus it is best that we reload this article
6754           ;;
6755           ;; If we're exiting from a large digest, this can be
6756           ;; extremely slow.  So, it's better not to reload it. -- jh.
6757           ;;(gnus-summary-show-article)
6758           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6759               (gnus-configure-windows 'pick 'force)
6760             (gnus-configure-windows (cdr quit-config) 'force)))
6761       (gnus-configure-windows (cdr quit-config) 'force))
6762     (when (eq major-mode 'gnus-summary-mode)
6763       (gnus-summary-next-subject 1 nil t)
6764       (gnus-summary-recenter)
6765       (gnus-summary-position-point))))
6766
6767 (defun gnus-summary-preview-mime-message ()
6768   "MIME decode and play this message."
6769   (interactive)
6770   (let ((gnus-break-pages nil)
6771         (gnus-show-mime t))
6772     (gnus-summary-select-article gnus-show-all-headers t))
6773   (let ((w (get-buffer-window gnus-article-buffer)))
6774     (when w
6775       (select-window (get-buffer-window gnus-article-buffer)))))
6776
6777 ;;; Dead summaries.
6778
6779 (defvar gnus-dead-summary-mode-map nil)
6780
6781 (unless gnus-dead-summary-mode-map
6782   (setq gnus-dead-summary-mode-map (make-keymap))
6783   (suppress-keymap gnus-dead-summary-mode-map)
6784   (substitute-key-definition
6785    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6786   (dolist (key '("\C-d" "\r" "\177" [delete]))
6787     (define-key gnus-dead-summary-mode-map
6788       key 'gnus-summary-wake-up-the-dead))
6789   (dolist (key '("q" "Q"))
6790     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6791
6792 (defvar gnus-dead-summary-mode nil
6793   "Minor mode for Gnus summary buffers.")
6794
6795 (defun gnus-dead-summary-mode (&optional arg)
6796   "Minor mode for Gnus summary buffers."
6797   (interactive "P")
6798   (when (eq major-mode 'gnus-summary-mode)
6799     (make-local-variable 'gnus-dead-summary-mode)
6800     (setq gnus-dead-summary-mode
6801           (if (null arg) (not gnus-dead-summary-mode)
6802             (> (prefix-numeric-value arg) 0)))
6803     (when gnus-dead-summary-mode
6804       (add-minor-mode
6805        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6806
6807 (defun gnus-deaden-summary ()
6808   "Make the current summary buffer into a dead summary buffer."
6809   ;; Kill any previous dead summary buffer.
6810   (when (and gnus-dead-summary
6811              (buffer-name gnus-dead-summary))
6812     (with-current-buffer gnus-dead-summary
6813       (when gnus-dead-summary-mode
6814         (kill-buffer (current-buffer)))))
6815   ;; Make this the current dead summary.
6816   (setq gnus-dead-summary (current-buffer))
6817   (gnus-dead-summary-mode 1)
6818   (let ((name (buffer-name)))
6819     (when (string-match "Summary" name)
6820       (rename-buffer
6821        (concat (substring name 0 (match-beginning 0)) "Dead "
6822                (substring name (match-beginning 0)))
6823        t)
6824       (bury-buffer))))
6825
6826 (defun gnus-kill-or-deaden-summary (buffer)
6827   "Kill or deaden the summary BUFFER."
6828   (save-excursion
6829     (when (and (buffer-name buffer)
6830                (not gnus-single-article-buffer))
6831       (with-current-buffer buffer
6832         (gnus-kill-buffer gnus-article-buffer)
6833         (gnus-kill-buffer gnus-original-article-buffer)))
6834     (cond
6835      ;; Kill the buffer.
6836      (gnus-kill-summary-on-exit
6837       (when (and gnus-use-trees
6838                  (gnus-buffer-exists-p buffer))
6839         (save-excursion
6840           (set-buffer buffer)
6841           (gnus-tree-close gnus-newsgroup-name)))
6842       (gnus-kill-buffer buffer))
6843      ;; Deaden the buffer.
6844      ((gnus-buffer-exists-p buffer)
6845       (save-excursion
6846         (set-buffer buffer)
6847         (gnus-deaden-summary))))))
6848
6849 (defun gnus-summary-wake-up-the-dead (&rest args)
6850   "Wake up the dead summary buffer."
6851   (interactive)
6852   (gnus-dead-summary-mode -1)
6853   (let ((name (buffer-name)))
6854     (when (string-match "Dead " name)
6855       (rename-buffer
6856        (concat (substring name 0 (match-beginning 0))
6857                (substring name (match-end 0)))
6858        t)))
6859   (gnus-message 3 "This dead summary is now alive again"))
6860
6861 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6862 (defun gnus-summary-fetch-faq (&optional faq-dir)
6863   "Fetch the FAQ for the current group.
6864 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6865 in."
6866   (interactive
6867    (list
6868     (when current-prefix-arg
6869       (completing-read
6870        "FAQ dir: " (and (listp gnus-group-faq-directory)
6871                         (mapcar 'list
6872                                 gnus-group-faq-directory))))))
6873   (let (gnus-faq-buffer)
6874     (when (setq gnus-faq-buffer
6875                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6876       (gnus-configure-windows 'summary-faq))))
6877
6878 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6879 (defun gnus-summary-describe-group (&optional force)
6880   "Describe the current newsgroup."
6881   (interactive "P")
6882   (gnus-group-describe-group force gnus-newsgroup-name))
6883
6884 (defun gnus-summary-describe-briefly ()
6885   "Describe summary mode commands briefly."
6886   (interactive)
6887   (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")))
6888
6889 ;; Walking around group mode buffer from summary mode.
6890
6891 (defun gnus-summary-next-group (&optional no-article target-group backward)
6892   "Exit current newsgroup and then select next unread newsgroup.
6893 If prefix argument NO-ARTICLE is non-nil, no article is selected
6894 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6895 previous group instead."
6896   (interactive "P")
6897   ;; Stop pre-fetching.
6898   (gnus-async-halt-prefetch)
6899   (let ((current-group gnus-newsgroup-name)
6900         (current-buffer (current-buffer))
6901         entered)
6902     ;; First we semi-exit this group to update Xrefs and all variables.
6903     ;; We can't do a real exit, because the window conf must remain
6904     ;; the same in case the user is prompted for info, and we don't
6905     ;; want the window conf to change before that...
6906     (gnus-summary-exit t)
6907     (while (not entered)
6908       ;; Then we find what group we are supposed to enter.
6909       (set-buffer gnus-group-buffer)
6910       (gnus-group-jump-to-group current-group)
6911       (setq target-group
6912             (or target-group
6913                 (if (eq gnus-keep-same-level 'best)
6914                     (gnus-summary-best-group gnus-newsgroup-name)
6915                   (gnus-summary-search-group backward gnus-keep-same-level))))
6916       (if (not target-group)
6917           ;; There are no further groups, so we return to the group
6918           ;; buffer.
6919           (progn
6920             (gnus-message 5 "Returning to the group buffer")
6921             (setq entered t)
6922             (when (gnus-buffer-live-p current-buffer)
6923               (set-buffer current-buffer)
6924               (gnus-summary-exit))
6925             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6926         ;; We try to enter the target group.
6927         (gnus-group-jump-to-group target-group)
6928         (let ((unreads (gnus-group-group-unread)))
6929           (if (and (or (eq t unreads)
6930                        (and unreads (not (zerop unreads))))
6931                    (gnus-summary-read-group
6932                     target-group nil no-article
6933                     (and (buffer-name current-buffer) current-buffer)
6934                     nil backward))
6935               (setq entered t)
6936             (setq current-group target-group
6937                   target-group nil)))))))
6938
6939 (defun gnus-summary-prev-group (&optional no-article)
6940   "Exit current newsgroup and then select previous unread newsgroup.
6941 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6942   (interactive "P")
6943   (gnus-summary-next-group no-article nil t))
6944
6945 ;; Walking around summary lines.
6946
6947 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6948   "Go to the first subject satisfying any non-nil constraint.
6949 If UNREAD is non-nil, the article should be unread.
6950 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6951 If UNSEEN is non-nil, the article should be unseen.
6952 Returns the article selected or nil if there are no matching articles."
6953   (interactive "P")
6954   (cond
6955    ;; Empty summary.
6956    ((null gnus-newsgroup-data)
6957     (gnus-message 3 "No articles in the group")
6958     nil)
6959    ;; Pick the first article.
6960    ((not (or unread undownloaded unseen))
6961     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6962     (gnus-data-number (car gnus-newsgroup-data)))
6963    ;; Find the first unread article.
6964    (t
6965     (let ((data gnus-newsgroup-data))
6966       (while (and data
6967                   (let ((num (gnus-data-number (car data))))
6968                     (or (memq num gnus-newsgroup-unfetched)
6969                         (not (or (and unread
6970                                       (memq num gnus-newsgroup-unreads))
6971                                  (and undownloaded
6972                                       (memq num gnus-newsgroup-undownloaded))
6973                                  (and unseen
6974                                       (memq num gnus-newsgroup-unseen)))))))
6975         (setq data (cdr data)))
6976       (prog1
6977           (if data
6978               (progn
6979                 (goto-char (gnus-data-pos (car data)))
6980                 (gnus-data-number (car data)))
6981             (gnus-message 3 "No more%s articles"
6982                           (let* ((r (when unread " unread"))
6983                                  (d (when undownloaded " undownloaded"))
6984                                  (s (when unseen " unseen"))
6985                                  (l (delq nil (list r d s))))
6986                             (cond ((= 3 (length l))
6987                                    (concat r "," d ", or" s))
6988                                   ((= 2 (length l))
6989                                    (concat (car l) ", or" (cadr l)))
6990                                   ((= 1 (length l))
6991                                    (car l))
6992                                   (t
6993                                    ""))))
6994             nil
6995             )
6996         (gnus-summary-position-point))))))
6997
6998 (defun gnus-summary-next-subject (n &optional unread dont-display)
6999   "Go to next N'th summary line.
7000 If N is negative, go to the previous N'th subject line.
7001 If UNREAD is non-nil, only unread articles are selected.
7002 The difference between N and the actual number of steps taken is
7003 returned."
7004   (interactive "p")
7005   (let ((backward (< n 0))
7006         (n (abs n)))
7007     (while (and (> n 0)
7008                 (if backward
7009                     (gnus-summary-find-prev unread)
7010                   (gnus-summary-find-next unread)))
7011       (unless (zerop (setq n (1- n)))
7012         (gnus-summary-show-thread)))
7013     (when (/= 0 n)
7014       (gnus-message 7 "No more%s articles"
7015                     (if unread " unread" "")))
7016     (unless dont-display
7017       (gnus-summary-recenter)
7018       (gnus-summary-position-point))
7019     n))
7020
7021 (defun gnus-summary-next-unread-subject (n)
7022   "Go to next N'th unread summary line."
7023   (interactive "p")
7024   (gnus-summary-next-subject n t))
7025
7026 (defun gnus-summary-prev-subject (n &optional unread)
7027   "Go to previous N'th summary line.
7028 If optional argument UNREAD is non-nil, only unread article is selected."
7029   (interactive "p")
7030   (gnus-summary-next-subject (- n) unread))
7031
7032 (defun gnus-summary-prev-unread-subject (n)
7033   "Go to previous N'th unread summary line."
7034   (interactive "p")
7035   (gnus-summary-next-subject (- n) t))
7036
7037 (defun gnus-summary-goto-subjects (articles)
7038   "Insert the subject header for ARTICLES in the current buffer."
7039   (save-excursion
7040     (dolist (article articles)
7041       (gnus-summary-goto-subject article t)))
7042   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7043   (gnus-summary-position-point))
7044  
7045 (defun gnus-summary-goto-subject (article &optional force silent)
7046   "Go the subject line of ARTICLE.
7047 If FORCE, also allow jumping to articles not currently shown."
7048   (interactive "nArticle number: ")
7049   (unless (numberp article)
7050     (error "Article %s is not a number" article))
7051   (let ((b (point))
7052         (data (gnus-data-find article)))
7053     ;; We read in the article if we have to.
7054     (and (not data)
7055          force
7056          (gnus-summary-insert-subject
7057           article
7058           (if (or (numberp force) (vectorp force)) force)
7059           t)
7060          (setq data (gnus-data-find article)))
7061     (goto-char b)
7062     (if (not data)
7063         (progn
7064           (unless silent
7065             (gnus-message 3 "Can't find article %d" article))
7066           nil)
7067       (let ((pt (gnus-data-pos data)))
7068         (goto-char pt)
7069         (gnus-summary-set-article-display-arrow pt))
7070       (gnus-summary-position-point)
7071       article)))
7072
7073 ;; Walking around summary lines with displaying articles.
7074
7075 (defun gnus-summary-expand-window (&optional arg)
7076   "Make the summary buffer take up the entire Emacs frame.
7077 Given a prefix, will force an `article' buffer configuration."
7078   (interactive "P")
7079   (if arg
7080       (gnus-configure-windows 'article 'force)
7081     (gnus-configure-windows 'summary 'force)))
7082
7083 (defun gnus-summary-display-article (article &optional all-header)
7084   "Display ARTICLE in article buffer."
7085   (when (gnus-buffer-live-p gnus-article-buffer)
7086     (with-current-buffer gnus-article-buffer
7087       (set-buffer-multibyte t)))
7088   (gnus-set-global-variables)
7089   (when (gnus-buffer-live-p gnus-article-buffer)
7090     (with-current-buffer gnus-article-buffer
7091       (setq gnus-article-charset gnus-newsgroup-charset)
7092       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7093       (set-buffer-multibyte t)))
7094   (if (null article)
7095       nil
7096     (prog1
7097         (if gnus-summary-display-article-function
7098             (funcall gnus-summary-display-article-function article all-header)
7099           (gnus-article-prepare article all-header))
7100       (with-current-buffer gnus-article-buffer
7101         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7102              nil))
7103       (gnus-run-hooks 'gnus-select-article-hook)
7104       (when (and gnus-current-article
7105                  (not (zerop gnus-current-article)))
7106         (gnus-summary-goto-subject gnus-current-article))
7107       (gnus-summary-recenter)
7108       (when (and gnus-use-trees gnus-show-threads)
7109         (gnus-possibly-generate-tree article)
7110         (gnus-highlight-selected-tree article))
7111       ;; Successfully display article.
7112       (gnus-article-set-window-start
7113        (cdr (assq article gnus-newsgroup-bookmarks))))))
7114
7115 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7116   "Select the current article.
7117 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7118 non-nil, the article will be re-fetched even if it already present in
7119 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7120 be displayed."
7121   ;; Make sure we are in the summary buffer to work around bbdb bug.
7122   (unless (eq major-mode 'gnus-summary-mode)
7123     (set-buffer gnus-summary-buffer))
7124   (let ((article (or article (gnus-summary-article-number)))
7125         (all-headers (not (not all-headers))) ;Must be T or NIL.
7126         gnus-summary-display-article-function)
7127     (and (not pseudo)
7128          (gnus-summary-article-pseudo-p article)
7129          (error "This is a pseudo-article"))
7130     (save-excursion
7131       (set-buffer gnus-summary-buffer)
7132       (if (or (and gnus-single-article-buffer
7133                    (or (null gnus-current-article)
7134                        (null gnus-article-current)
7135                        (null (get-buffer gnus-article-buffer))
7136                        (not (eq article (cdr gnus-article-current)))
7137                        (not (equal (car gnus-article-current)
7138                                    gnus-newsgroup-name))))
7139               (and (not gnus-single-article-buffer)
7140                    (or (null gnus-current-article)
7141                        (not (eq gnus-current-article article))))
7142               force)
7143           ;; The requested article is different from the current article.
7144           (progn
7145             (gnus-summary-display-article article all-headers)
7146             (gnus-article-set-window-start
7147              (cdr (assq article gnus-newsgroup-bookmarks)))
7148             article)
7149         'old))))
7150
7151 (defun gnus-summary-force-verify-and-decrypt ()
7152   "Display buttons for signed/encrypted parts and verify/decrypt them."
7153   (interactive)
7154   (let ((mm-verify-option 'known)
7155         (mm-decrypt-option 'known)
7156         (gnus-article-emulate-mime t)
7157         (gnus-buttonized-mime-types (append (list "multipart/signed"
7158                                                   "multipart/encrypted")
7159                                             gnus-buttonized-mime-types)))
7160     (gnus-summary-select-article nil 'force)))
7161
7162 (defun gnus-summary-set-current-mark (&optional current-mark)
7163   "Obsolete function."
7164   nil)
7165
7166 (defun gnus-summary-next-article (&optional unread subject backward push)
7167   "Select the next article.
7168 If UNREAD, only unread articles are selected.
7169 If SUBJECT, only articles with SUBJECT are selected.
7170 If BACKWARD, the previous article is selected instead of the next."
7171   (interactive "P")
7172   (cond
7173    ;; Is there such an article?
7174    ((and (gnus-summary-search-forward unread subject backward)
7175          (or (gnus-summary-display-article (gnus-summary-article-number))
7176              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7177     (gnus-summary-position-point))
7178    ;; If not, we try the first unread, if that is wanted.
7179    ((and subject
7180          gnus-auto-select-same
7181          (gnus-summary-first-unread-article))
7182     (gnus-summary-position-point)
7183     (gnus-message 6 "Wrapped"))
7184    ;; Try to get next/previous article not displayed in this group.
7185    ((and gnus-auto-extend-newsgroup
7186          (not unread) (not subject))
7187     (gnus-summary-goto-article
7188      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7189      nil (count-lines (point-min) (point))))
7190    ;; Go to next/previous group.
7191    (t
7192     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7193       (gnus-summary-jump-to-group gnus-newsgroup-name))
7194     (let ((cmd last-command-char)
7195           (point
7196            (with-current-buffer gnus-group-buffer
7197              (point)))
7198           (group
7199            (if (eq gnus-keep-same-level 'best)
7200                (gnus-summary-best-group gnus-newsgroup-name)
7201              (gnus-summary-search-group backward gnus-keep-same-level))))
7202       ;; For some reason, the group window gets selected.  We change
7203       ;; it back.
7204       (select-window (get-buffer-window (current-buffer)))
7205       ;; Select next unread newsgroup automagically.
7206       (cond
7207        ((or (not gnus-auto-select-next)
7208             (not cmd))
7209         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7210        ((or (eq gnus-auto-select-next 'quietly)
7211             (and (eq gnus-auto-select-next 'slightly-quietly)
7212                  push)
7213             (and (eq gnus-auto-select-next 'almost-quietly)
7214                  (gnus-summary-last-article-p)))
7215         ;; Select quietly.
7216         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7217             (gnus-summary-exit)
7218           (gnus-message 7 "No more%s articles (%s)..."
7219                         (if unread " unread" "")
7220                         (if group (concat "selecting " group)
7221                           "exiting"))
7222           (gnus-summary-next-group nil group backward)))
7223        (t
7224         (when (gnus-key-press-event-p last-input-event)
7225           (gnus-summary-walk-group-buffer
7226            gnus-newsgroup-name cmd unread backward point))))))))
7227
7228 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7229   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7230                       (?\C-p (gnus-group-prev-unread-group 1))))
7231         (cursor-in-echo-area t)
7232         keve key group ended prompt)
7233     (save-excursion
7234       (set-buffer gnus-group-buffer)
7235       (goto-char start)
7236       (setq group
7237             (if (eq gnus-keep-same-level 'best)
7238                 (gnus-summary-best-group gnus-newsgroup-name)
7239               (gnus-summary-search-group backward gnus-keep-same-level))))
7240     (while (not ended)
7241       (setq prompt
7242             (format
7243              "No more%s articles%s " (if unread " unread" "")
7244              (if (and group
7245                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7246                  (format " (Type %s for %s [%s])"
7247                          (single-key-description cmd) group
7248                          (gnus-group-unread group))
7249                (format " (Type %s to exit %s)"
7250                        (single-key-description cmd)
7251                        gnus-newsgroup-name))))
7252       ;; Confirm auto selection.
7253       (setq key (car (setq keve (gnus-read-event-char prompt)))
7254             ended t)
7255       (cond
7256        ((assq key keystrokes)
7257         (let ((obuf (current-buffer)))
7258           (switch-to-buffer gnus-group-buffer)
7259           (when group
7260             (gnus-group-jump-to-group group))
7261           (eval (cadr (assq key keystrokes)))
7262           (setq group (gnus-group-group-name))
7263           (switch-to-buffer obuf))
7264         (setq ended nil))
7265        ((equal key cmd)
7266         (if (or (not group)
7267                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7268             (gnus-summary-exit)
7269           (gnus-summary-next-group nil group backward)))
7270        (t
7271         (push (cdr keve) unread-command-events))))))
7272
7273 (defun gnus-summary-next-unread-article ()
7274   "Select unread article after current one."
7275   (interactive)
7276   (gnus-summary-next-article
7277    (or (not (eq gnus-summary-goto-unread 'never))
7278        (gnus-summary-last-article-p (gnus-summary-article-number)))
7279    (and gnus-auto-select-same
7280         (gnus-summary-article-subject))))
7281
7282 (defun gnus-summary-prev-article (&optional unread subject)
7283   "Select the article after the current one.
7284 If UNREAD is non-nil, only unread articles are selected."
7285   (interactive "P")
7286   (gnus-summary-next-article unread subject t))
7287
7288 (defun gnus-summary-prev-unread-article ()
7289   "Select unread article before current one."
7290   (interactive)
7291   (gnus-summary-prev-article
7292    (or (not (eq gnus-summary-goto-unread 'never))
7293        (gnus-summary-first-article-p (gnus-summary-article-number)))
7294    (and gnus-auto-select-same
7295         (gnus-summary-article-subject))))
7296
7297 (defun gnus-summary-next-page (&optional lines circular stop)
7298   "Show next page of the selected article.
7299 If at the end of the current article, select the next article.
7300 LINES says how many lines should be scrolled up.
7301
7302 If CIRCULAR is non-nil, go to the start of the article instead of
7303 selecting the next article when reaching the end of the current
7304 article.
7305
7306 If STOP is non-nil, just stop when reaching the end of the message.
7307
7308 Also see the variable `gnus-article-skip-boring'."
7309   (interactive "P")
7310   (setq gnus-summary-buffer (current-buffer))
7311   (gnus-set-global-variables)
7312   (let ((article (gnus-summary-article-number))
7313         (article-window (get-buffer-window gnus-article-buffer t))
7314         endp)
7315     ;; If the buffer is empty, we have no article.
7316     (unless article
7317       (error "No article to select"))
7318     (gnus-configure-windows 'article)
7319     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7320         (if (and (eq gnus-summary-goto-unread 'never)
7321                  (not (gnus-summary-last-article-p article)))
7322             (gnus-summary-next-article)
7323           (gnus-summary-next-unread-article))
7324       (if (or (null gnus-current-article)
7325               (null gnus-article-current)
7326               (/= article (cdr gnus-article-current))
7327               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7328           ;; Selected subject is different from current article's.
7329           (gnus-summary-display-article article)
7330         (when article-window
7331           (gnus-eval-in-buffer-window gnus-article-buffer
7332             (setq endp (or (gnus-article-next-page lines)
7333                            (gnus-article-only-boring-p))))
7334           (when endp
7335             (cond (stop
7336                    (gnus-message 3 "End of message"))
7337                   (circular
7338                    (gnus-summary-beginning-of-article))
7339                   (lines
7340                    (gnus-message 3 "End of message"))
7341                   ((null lines)
7342                    (if (and (eq gnus-summary-goto-unread 'never)
7343                             (not (gnus-summary-last-article-p article)))
7344                        (gnus-summary-next-article)
7345                      (gnus-summary-next-unread-article))))))))
7346     (gnus-summary-recenter)
7347     (gnus-summary-position-point)))
7348
7349 (defun gnus-summary-prev-page (&optional lines move)
7350   "Show previous page of selected article.
7351 Argument LINES specifies lines to be scrolled down.
7352 If MOVE, move to the previous unread article if point is at
7353 the beginning of the buffer."
7354   (interactive "P")
7355   (let ((article (gnus-summary-article-number))
7356         (article-window (get-buffer-window gnus-article-buffer t))
7357         endp)
7358     (gnus-configure-windows 'article)
7359     (if (or (null gnus-current-article)
7360             (null gnus-article-current)
7361             (/= article (cdr gnus-article-current))
7362             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7363         ;; Selected subject is different from current article's.
7364         (gnus-summary-display-article article)
7365       (gnus-summary-recenter)
7366       (when article-window
7367         (gnus-eval-in-buffer-window gnus-article-buffer
7368           (setq endp (gnus-article-prev-page lines)))
7369         (when (and move endp)
7370           (cond (lines
7371                  (gnus-message 3 "Beginning of message"))
7372                 ((null lines)
7373                  (if (and (eq gnus-summary-goto-unread 'never)
7374                           (not (gnus-summary-first-article-p article)))
7375                      (gnus-summary-prev-article)
7376                    (gnus-summary-prev-unread-article))))))))
7377   (gnus-summary-position-point))
7378
7379 (defun gnus-summary-prev-page-or-article (&optional lines)
7380   "Show previous page of selected article.
7381 Argument LINES specifies lines to be scrolled down.
7382 If at the beginning of the article, go to the next article."
7383   (interactive "P")
7384   (gnus-summary-prev-page lines t))
7385
7386 (defun gnus-summary-scroll-up (lines)
7387   "Scroll up (or down) one line current article.
7388 Argument LINES specifies lines to be scrolled up (or down if negative)."
7389   (interactive "p")
7390   (gnus-configure-windows 'article)
7391   (gnus-summary-show-thread)
7392   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7393     (gnus-eval-in-buffer-window gnus-article-buffer
7394       (cond ((> lines 0)
7395              (when (gnus-article-next-page lines)
7396                (gnus-message 3 "End of message")))
7397             ((< lines 0)
7398              (gnus-article-prev-page (- lines))))))
7399   (gnus-summary-recenter)
7400   (gnus-summary-position-point))
7401
7402 (defun gnus-summary-scroll-down (lines)
7403   "Scroll down (or up) one line current article.
7404 Argument LINES specifies lines to be scrolled down (or up if negative)."
7405   (interactive "p")
7406   (gnus-summary-scroll-up (- lines)))
7407
7408 (defun gnus-summary-next-same-subject ()
7409   "Select next article which has the same subject as current one."
7410   (interactive)
7411   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7412
7413 (defun gnus-summary-prev-same-subject ()
7414   "Select previous article which has the same subject as current one."
7415   (interactive)
7416   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7417
7418 (defun gnus-summary-next-unread-same-subject ()
7419   "Select next unread article which has the same subject as current one."
7420   (interactive)
7421   (gnus-summary-next-article t (gnus-summary-article-subject)))
7422
7423 (defun gnus-summary-prev-unread-same-subject ()
7424   "Select previous unread article which has the same subject as current one."
7425   (interactive)
7426   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7427
7428 (defun gnus-summary-first-unread-article ()
7429   "Select the first unread article.
7430 Return nil if there are no unread articles."
7431   (interactive)
7432   (prog1
7433       (when (gnus-summary-first-subject t)
7434         (gnus-summary-show-thread)
7435         (gnus-summary-first-subject t)
7436         (gnus-summary-display-article (gnus-summary-article-number)))
7437     (gnus-summary-position-point)))
7438
7439 (defun gnus-summary-first-unread-subject ()
7440   "Place the point on the subject line of the first unread article.
7441 Return nil if there are no unread articles."
7442   (interactive)
7443   (prog1
7444       (when (gnus-summary-first-subject t)
7445         (gnus-summary-show-thread)
7446         (gnus-summary-first-subject t))
7447     (gnus-summary-position-point)))
7448
7449 (defun gnus-summary-first-unseen-subject ()
7450   "Place the point on the subject line of the first unseen article.
7451 Return nil if there are no unseen articles."
7452   (interactive)
7453   (prog1
7454       (when (gnus-summary-first-subject nil nil t)
7455         (gnus-summary-show-thread)
7456         (gnus-summary-first-subject nil nil t))
7457     (gnus-summary-position-point)))
7458
7459 (defun gnus-summary-first-unseen-or-unread-subject ()
7460   "Place the point on the subject line of the first unseen article or,
7461 if all article have been seen, on the subject line of the first unread
7462 article."
7463   (interactive)
7464   (prog1
7465       (unless (when (gnus-summary-first-subject nil nil t)
7466                 (gnus-summary-show-thread)
7467                 (gnus-summary-first-subject nil nil t))
7468         (when (gnus-summary-first-subject t)
7469           (gnus-summary-show-thread)
7470           (gnus-summary-first-subject t)))
7471     (gnus-summary-position-point)))
7472
7473 (defun gnus-summary-first-article ()
7474   "Select the first article.
7475 Return nil if there are no articles."
7476   (interactive)
7477   (prog1
7478       (when (gnus-summary-first-subject)
7479         (gnus-summary-show-thread)
7480         (gnus-summary-first-subject)
7481         (gnus-summary-display-article (gnus-summary-article-number)))
7482     (gnus-summary-position-point)))
7483
7484 (defun gnus-summary-best-unread-article (&optional arg)
7485   "Select the unread article with the highest score.
7486 If given a prefix argument, select the next unread article that has a
7487 score higher than the default score."
7488   (interactive "P")
7489   (let ((article (if arg
7490                      (gnus-summary-better-unread-subject)
7491                    (gnus-summary-best-unread-subject))))
7492     (if article
7493         (gnus-summary-goto-article article)
7494       (error "No unread articles"))))
7495
7496 (defun gnus-summary-best-unread-subject ()
7497   "Select the unread subject with the highest score."
7498   (interactive)
7499   (let ((best -1000000)
7500         (data gnus-newsgroup-data)
7501         article score)
7502     (while data
7503       (and (gnus-data-unread-p (car data))
7504            (> (setq score
7505                     (gnus-summary-article-score (gnus-data-number (car data))))
7506               best)
7507            (setq best score
7508                  article (gnus-data-number (car data))))
7509       (setq data (cdr data)))
7510     (when article
7511       (gnus-summary-goto-subject article))
7512     (gnus-summary-position-point)
7513     article))
7514
7515 (defun gnus-summary-better-unread-subject ()
7516   "Select the first unread subject that has a score over the default score."
7517   (interactive)
7518   (let ((data gnus-newsgroup-data)
7519         article score)
7520     (while (and (setq article (gnus-data-number (car data)))
7521                 (or (gnus-data-read-p (car data))
7522                     (not (> (gnus-summary-article-score article)
7523                             gnus-summary-default-score))))
7524       (setq data (cdr data)))
7525     (when article
7526       (gnus-summary-goto-subject article))
7527     (gnus-summary-position-point)
7528     article))
7529
7530 (defun gnus-summary-last-subject ()
7531   "Go to the last displayed subject line in the group."
7532   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7533     (when article
7534       (gnus-summary-goto-subject article))))
7535
7536 (defun gnus-summary-goto-article (article &optional all-headers force)
7537   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7538 If ALL-HEADERS is non-nil, no header lines are hidden.
7539 If FORCE, go to the article even if it isn't displayed.  If FORCE
7540 is a number, it is the line the article is to be displayed on."
7541   (interactive
7542    (list
7543     (completing-read
7544      "Article number or Message-ID: "
7545      (mapcar (lambda (number) (list (int-to-string number)))
7546              gnus-newsgroup-limit))
7547     current-prefix-arg
7548     t))
7549   (prog1
7550       (if (and (stringp article)
7551                (string-match "@\\|%40" article))
7552           (gnus-summary-refer-article article)
7553         (when (stringp article)
7554           (setq article (string-to-number article)))
7555         (if (gnus-summary-goto-subject article force)
7556             (gnus-summary-display-article article all-headers)
7557           (gnus-message 4 "Couldn't go to article %s" article) nil))
7558     (gnus-summary-position-point)))
7559
7560 (defun gnus-summary-goto-last-article ()
7561   "Go to the previously read article."
7562   (interactive)
7563   (prog1
7564       (when gnus-last-article
7565         (gnus-summary-goto-article gnus-last-article nil t))
7566     (gnus-summary-position-point)))
7567
7568 (defun gnus-summary-pop-article (number)
7569   "Pop one article off the history and go to the previous.
7570 NUMBER articles will be popped off."
7571   (interactive "p")
7572   (let (to)
7573     (setq gnus-newsgroup-history
7574           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7575     (if to
7576         (gnus-summary-goto-article (car to) nil t)
7577       (error "Article history empty")))
7578   (gnus-summary-position-point))
7579
7580 ;; Summary commands and functions for limiting the summary buffer.
7581
7582 (defun gnus-summary-limit-to-articles (n)
7583   "Limit the summary buffer to the next N articles.
7584 If not given a prefix, use the process marked articles instead."
7585   (interactive "P")
7586   (prog1
7587       (let ((articles (gnus-summary-work-articles n)))
7588         (setq gnus-newsgroup-processable nil)
7589         (gnus-summary-limit articles))
7590     (gnus-summary-position-point)))
7591
7592 (defun gnus-summary-pop-limit (&optional total)
7593   "Restore the previous limit.
7594 If given a prefix, remove all limits."
7595   (interactive "P")
7596   (when total
7597     (setq gnus-newsgroup-limits
7598           (list (mapcar (lambda (h) (mail-header-number h))
7599                         gnus-newsgroup-headers))))
7600   (unless gnus-newsgroup-limits
7601     (error "No limit to pop"))
7602   (prog1
7603       (gnus-summary-limit nil 'pop)
7604     (gnus-summary-position-point)))
7605
7606 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7607   "Limit the summary buffer to articles that have subjects that match a regexp.
7608 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7609   (interactive
7610    (list (read-string (if current-prefix-arg
7611                           "Exclude subject (regexp): "
7612                         "Limit to subject (regexp): "))
7613          nil current-prefix-arg))
7614   (unless header
7615     (setq header "subject"))
7616   (when (not (equal "" subject))
7617     (prog1
7618         (let ((articles (gnus-summary-find-matching
7619                          (or header "subject") subject 'all nil nil
7620                          not-matching)))
7621           (unless articles
7622             (error "Found no matches for \"%s\"" subject))
7623           (gnus-summary-limit articles))
7624       (gnus-summary-position-point))))
7625
7626 (defun gnus-summary-limit-to-author (from &optional not-matching)
7627   "Limit the summary buffer to articles that have authors that match a regexp.
7628 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7629   (interactive
7630    (list (read-string (if current-prefix-arg
7631                           "Exclude author (regexp): "
7632                         "Limit to author (regexp): "))
7633          current-prefix-arg))
7634   (gnus-summary-limit-to-subject from "from" not-matching))
7635
7636 (defun gnus-summary-limit-to-age (age &optional younger-p)
7637   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7638 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7639 articles that are younger than AGE days."
7640   (interactive
7641    (let ((younger current-prefix-arg)
7642          (days-got nil)
7643          days)
7644      (while (not days-got)
7645        (setq days (if younger
7646                       (read-string "Limit to articles younger than (in days, older when negative): ")
7647                     (read-string
7648                      "Limit to articles older than (in days, younger when negative): ")))
7649        (when (> (length days) 0)
7650          (setq days (read days)))
7651        (if (numberp days)
7652            (progn
7653              (setq days-got t)
7654              (when (< days 0)
7655                (setq younger (not younger))
7656                (setq days (* days -1))))
7657          (message "Please enter a number.")
7658          (sleep-for 1)))
7659      (list days younger)))
7660   (prog1
7661       (let ((data gnus-newsgroup-data)
7662             (cutoff (days-to-time age))
7663             articles d date is-younger)
7664         (while (setq d (pop data))
7665           (when (and (vectorp (gnus-data-header d))
7666                      (setq date (mail-header-date (gnus-data-header d))))
7667             (setq is-younger (time-less-p
7668                               (time-since (condition-case ()
7669                                               (date-to-time date)
7670                                             (error '(0 0))))
7671                               cutoff))
7672             (when (if younger-p
7673                       is-younger
7674                     (not is-younger))
7675               (push (gnus-data-number d) articles))))
7676         (gnus-summary-limit (nreverse articles)))
7677     (gnus-summary-position-point)))
7678
7679 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7680   "Limit the summary buffer to articles that match an 'extra' header."
7681   (interactive
7682    (let ((header
7683           (intern
7684            (gnus-completing-read-with-default
7685             (symbol-name (car gnus-extra-headers))
7686             (if current-prefix-arg
7687                 "Exclude extra header:"
7688               "Limit extra header:")
7689             (mapcar (lambda (x)
7690                       (cons (symbol-name x) x))
7691                     gnus-extra-headers)
7692             nil
7693             t))))
7694      (list header
7695            (read-string (format "%s header %s (regexp): "
7696                                 (if current-prefix-arg "Exclude" "Limit to")
7697                                 header))
7698            current-prefix-arg)))
7699   (when (not (equal "" regexp))
7700     (prog1
7701         (let ((articles (gnus-summary-find-matching
7702                          (cons 'extra header) regexp 'all nil nil
7703                          not-matching)))
7704           (unless articles
7705             (error "Found no matches for \"%s\"" regexp))
7706           (gnus-summary-limit articles))
7707       (gnus-summary-position-point))))
7708
7709 (defun gnus-summary-limit-to-display-predicate ()
7710   "Limit the summary buffer to the predicated in the `display' group parameter."
7711   (interactive)
7712   (unless gnus-newsgroup-display
7713     (error "There is no `display' group parameter"))
7714   (let (articles)
7715     (dolist (number gnus-newsgroup-articles)
7716       (when (funcall gnus-newsgroup-display)
7717         (push number articles)))
7718     (gnus-summary-limit articles))
7719   (gnus-summary-position-point))
7720
7721 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7722 (make-obsolete
7723  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7724
7725 (defun gnus-summary-limit-to-unread (&optional all)
7726   "Limit the summary buffer to articles that are not marked as read.
7727 If ALL is non-nil, limit strictly to unread articles."
7728   (interactive "P")
7729   (if all
7730       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7731     (gnus-summary-limit-to-marks
7732      ;; Concat all the marks that say that an article is read and have
7733      ;; those removed.
7734      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7735            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7736            gnus-low-score-mark gnus-expirable-mark
7737            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7738            gnus-duplicate-mark gnus-souped-mark)
7739      'reverse)))
7740
7741 (defun gnus-summary-limit-to-replied (&optional unreplied)
7742   "Limit the summary buffer to replied articles.
7743 If UNREPLIED (the prefix), limit to unreplied articles."
7744   (interactive "P")
7745   (if unreplied
7746       (gnus-summary-limit
7747        (gnus-set-difference gnus-newsgroup-articles
7748         gnus-newsgroup-replied))
7749     (gnus-summary-limit gnus-newsgroup-replied))
7750   (gnus-summary-position-point))
7751
7752 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7753 (make-obsolete 'gnus-summary-delete-marked-with
7754                'gnus-summary-limit-exclude-marks)
7755
7756 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7757   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7758 If REVERSE, limit the summary buffer to articles that are marked
7759 with MARKS.  MARKS can either be a string of marks or a list of marks.
7760 Returns how many articles were removed."
7761   (interactive "sMarks: ")
7762   (gnus-summary-limit-to-marks marks t))
7763
7764 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7765   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7766 If REVERSE (the prefix), limit the summary buffer to articles that are
7767 not marked with MARKS.  MARKS can either be a string of marks or a
7768 list of marks.
7769 Returns how many articles were removed."
7770   (interactive "sMarks: \nP")
7771   (prog1
7772       (let ((data gnus-newsgroup-data)
7773             (marks (if (listp marks) marks
7774                      (append marks nil))) ; Transform to list.
7775             articles)
7776         (while data
7777           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7778                   (memq (gnus-data-mark (car data)) marks))
7779             (push (gnus-data-number (car data)) articles))
7780           (setq data (cdr data)))
7781         (gnus-summary-limit articles))
7782     (gnus-summary-position-point)))
7783
7784 (defun gnus-summary-limit-to-score (score)
7785   "Limit to articles with score at or above SCORE."
7786   (interactive "NLimit to articles with score of at least: ")
7787   (let ((data gnus-newsgroup-data)
7788         articles)
7789     (while data
7790       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7791                 score)
7792         (push (gnus-data-number (car data)) articles))
7793       (setq data (cdr data)))
7794     (prog1
7795         (gnus-summary-limit articles)
7796       (gnus-summary-position-point))))
7797
7798 (defun gnus-summary-limit-to-unseen ()
7799   "Limit to unseen articles."
7800   (interactive)
7801   (prog1
7802       (gnus-summary-limit gnus-newsgroup-unseen)
7803     (gnus-summary-position-point)))
7804
7805 (defun gnus-summary-limit-include-thread (id)
7806   "Display all the hidden articles that is in the thread with ID in it.
7807 When called interactively, ID is the Message-ID of the current
7808 article."
7809   (interactive (list (mail-header-id (gnus-summary-article-header))))
7810   (let ((articles (gnus-articles-in-thread
7811                    (gnus-id-to-thread (gnus-root-id id)))))
7812     (prog1
7813         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7814       (gnus-summary-limit-include-matching-articles
7815        "subject"
7816        (regexp-quote (gnus-simplify-subject-re
7817                       (mail-header-subject (gnus-id-to-header id)))))
7818       (gnus-summary-position-point))))
7819
7820 (defun gnus-summary-limit-include-matching-articles (header regexp)
7821   "Display all the hidden articles that have HEADERs that match REGEXP."
7822   (interactive (list (read-string "Match on header: ")
7823                      (read-string "Regexp: ")))
7824   (let ((articles (gnus-find-matching-articles header regexp)))
7825     (prog1
7826         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7827       (gnus-summary-position-point))))
7828
7829 (defun gnus-summary-insert-dormant-articles ()
7830   "Insert all the dormant articles for this group into the current buffer."
7831   (interactive)
7832   (let ((gnus-verbose (max 6 gnus-verbose)))
7833     (if (not gnus-newsgroup-dormant)
7834         (gnus-message 3 "No cached articles for this group")
7835       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7836
7837 (defun gnus-summary-limit-include-dormant ()
7838   "Display all the hidden articles that are marked as dormant.
7839 Note that this command only works on a subset of the articles currently
7840 fetched for this group."
7841   (interactive)
7842   (unless gnus-newsgroup-dormant
7843     (error "There are no dormant articles in this group"))
7844   (prog1
7845       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7846     (gnus-summary-position-point)))
7847
7848 (defun gnus-summary-limit-exclude-dormant ()
7849   "Hide all dormant articles."
7850   (interactive)
7851   (prog1
7852       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7853     (gnus-summary-position-point)))
7854
7855 (defun gnus-summary-limit-exclude-childless-dormant ()
7856   "Hide all dormant articles that have no children."
7857   (interactive)
7858   (let ((data (gnus-data-list t))
7859         articles d children)
7860     ;; Find all articles that are either not dormant or have
7861     ;; children.
7862     (while (setq d (pop data))
7863       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7864                 (and (setq children
7865                            (gnus-article-children (gnus-data-number d)))
7866                      (let (found)
7867                        (while children
7868                          (when (memq (car children) articles)
7869                            (setq children nil
7870                                  found t))
7871                          (pop children))
7872                        found)))
7873         (push (gnus-data-number d) articles)))
7874     ;; Do the limiting.
7875     (prog1
7876         (gnus-summary-limit articles)
7877       (gnus-summary-position-point))))
7878
7879 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7880   "Mark all unread excluded articles as read.
7881 If ALL, mark even excluded ticked and dormants as read."
7882   (interactive "P")
7883   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7884   (let ((articles (gnus-sorted-ndifference
7885                    (sort
7886                     (mapcar (lambda (h) (mail-header-number h))
7887                             gnus-newsgroup-headers)
7888                     '<)
7889                    gnus-newsgroup-limit))
7890         article)
7891     (setq gnus-newsgroup-unreads
7892           (gnus-sorted-intersection gnus-newsgroup-unreads
7893                                     gnus-newsgroup-limit))
7894     (if all
7895         (setq gnus-newsgroup-dormant nil
7896               gnus-newsgroup-marked nil
7897               gnus-newsgroup-reads
7898               (nconc
7899                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7900                gnus-newsgroup-reads))
7901       (while (setq article (pop articles))
7902         (unless (or (memq article gnus-newsgroup-dormant)
7903                     (memq article gnus-newsgroup-marked))
7904           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7905
7906 (defun gnus-summary-limit (articles &optional pop)
7907   (if pop
7908       ;; We pop the previous limit off the stack and use that.
7909       (setq articles (car gnus-newsgroup-limits)
7910             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7911     ;; We use the new limit, so we push the old limit on the stack.
7912     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7913   ;; Set the limit.
7914   (setq gnus-newsgroup-limit articles)
7915   (let ((total (length gnus-newsgroup-data))
7916         (data (gnus-data-find-list (gnus-summary-article-number)))
7917         (gnus-summary-mark-below nil)   ; Inhibit this.
7918         found)
7919     ;; This will do all the work of generating the new summary buffer
7920     ;; according to the new limit.
7921     (gnus-summary-prepare)
7922     ;; Hide any threads, possibly.
7923     (gnus-summary-maybe-hide-threads)
7924     ;; Try to return to the article you were at, or one in the
7925     ;; neighborhood.
7926     (when data
7927       ;; We try to find some article after the current one.
7928       (while data
7929         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7930           (setq data nil
7931                 found t))
7932         (setq data (cdr data))))
7933     (unless found
7934       ;; If there is no data, that means that we were after the last
7935       ;; article.  The same goes when we can't find any articles
7936       ;; after the current one.
7937       (goto-char (point-max))
7938       (gnus-summary-find-prev))
7939     (gnus-set-mode-line 'summary)
7940     ;; We return how many articles were removed from the summary
7941     ;; buffer as a result of the new limit.
7942     (- total (length gnus-newsgroup-data))))
7943
7944 (defsubst gnus-invisible-cut-children (threads)
7945   (let ((num 0))
7946     (while threads
7947       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7948         (incf num))
7949       (pop threads))
7950     (< num 2)))
7951
7952 (defsubst gnus-cut-thread (thread)
7953   "Go forwards in the thread until we find an article that we want to display."
7954   (when (or (eq gnus-fetch-old-headers 'some)
7955             (eq gnus-fetch-old-headers 'invisible)
7956             (numberp gnus-fetch-old-headers)
7957             (eq gnus-build-sparse-threads 'some)
7958             (eq gnus-build-sparse-threads 'more))
7959     ;; Deal with old-fetched headers and sparse threads.
7960     (while (and
7961             thread
7962             (or
7963              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7964              (gnus-summary-article-ancient-p
7965               (mail-header-number (car thread))))
7966             (if (or (<= (length (cdr thread)) 1)
7967                     (eq gnus-fetch-old-headers 'invisible))
7968                 (setq gnus-newsgroup-limit
7969                       (delq (mail-header-number (car thread))
7970                             gnus-newsgroup-limit)
7971                       thread (cadr thread))
7972               (when (gnus-invisible-cut-children (cdr thread))
7973                 (let ((th (cdr thread)))
7974                   (while th
7975                     (if (memq (mail-header-number (caar th))
7976                               gnus-newsgroup-limit)
7977                         (setq thread (car th)
7978                               th nil)
7979                       (setq th (cdr th))))))))))
7980   thread)
7981
7982 (defun gnus-cut-threads (threads)
7983   "Cut off all uninteresting articles from the beginning of THREADS."
7984   (when (or (eq gnus-fetch-old-headers 'some)
7985             (eq gnus-fetch-old-headers 'invisible)
7986             (numberp gnus-fetch-old-headers)
7987             (eq gnus-build-sparse-threads 'some)
7988             (eq gnus-build-sparse-threads 'more))
7989     (let ((th threads))
7990       (while th
7991         (setcar th (gnus-cut-thread (car th)))
7992         (setq th (cdr th)))))
7993   ;; Remove nixed out threads.
7994   (delq nil threads))
7995
7996 (defun gnus-summary-initial-limit (&optional show-if-empty)
7997   "Figure out what the initial limit is supposed to be on group entry.
7998 This entails weeding out unwanted dormants, low-scored articles,
7999 fetch-old-headers verbiage, and so on."
8000   ;; Most groups have nothing to remove.
8001   (if (or gnus-inhibit-limiting
8002           (and (null gnus-newsgroup-dormant)
8003                (eq gnus-newsgroup-display 'gnus-not-ignore)
8004                (not (eq gnus-fetch-old-headers 'some))
8005                (not (numberp gnus-fetch-old-headers))
8006                (not (eq gnus-fetch-old-headers 'invisible))
8007                (null gnus-summary-expunge-below)
8008                (not (eq gnus-build-sparse-threads 'some))
8009                (not (eq gnus-build-sparse-threads 'more))
8010                (null gnus-thread-expunge-below)
8011                (not gnus-use-nocem)))
8012       ()                                ; Do nothing.
8013     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8014     (setq gnus-newsgroup-limit nil)
8015     (mapatoms
8016      (lambda (node)
8017        (unless (car (symbol-value node))
8018          ;; These threads have no parents -- they are roots.
8019          (let ((nodes (cdr (symbol-value node)))
8020                thread)
8021            (while nodes
8022              (if (and gnus-thread-expunge-below
8023                       (< (gnus-thread-total-score (car nodes))
8024                          gnus-thread-expunge-below))
8025                  (gnus-expunge-thread (pop nodes))
8026                (setq thread (pop nodes))
8027                (gnus-summary-limit-children thread))))))
8028      gnus-newsgroup-dependencies)
8029     ;; If this limitation resulted in an empty group, we might
8030     ;; pop the previous limit and use it instead.
8031     (when (and (not gnus-newsgroup-limit)
8032                show-if-empty)
8033       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8034     gnus-newsgroup-limit))
8035
8036 (defun gnus-summary-limit-children (thread)
8037   "Return 1 if this subthread is visible and 0 if it is not."
8038   ;; First we get the number of visible children to this thread.  This
8039   ;; is done by recursing down the thread using this function, so this
8040   ;; will really go down to a leaf article first, before slowly
8041   ;; working its way up towards the root.
8042   (when thread
8043     (let* ((max-lisp-eval-depth 5000)
8044            (children
8045            (if (cdr thread)
8046                (apply '+ (mapcar 'gnus-summary-limit-children
8047                                  (cdr thread)))
8048              0))
8049           (number (mail-header-number (car thread)))
8050           score)
8051       (if (and
8052            (not (memq number gnus-newsgroup-marked))
8053            (or
8054             ;; If this article is dormant and has absolutely no visible
8055             ;; children, then this article isn't visible.
8056             (and (memq number gnus-newsgroup-dormant)
8057                  (zerop children))
8058             ;; If this is "fetch-old-headered" and there is no
8059             ;; visible children, then we don't want this article.
8060             (and (or (eq gnus-fetch-old-headers 'some)
8061                      (numberp gnus-fetch-old-headers))
8062                  (gnus-summary-article-ancient-p number)
8063                  (zerop children))
8064             ;; If this is "fetch-old-headered" and `invisible', then
8065             ;; we don't want this article.
8066             (and (eq gnus-fetch-old-headers 'invisible)
8067                  (gnus-summary-article-ancient-p number))
8068             ;; If this is a sparsely inserted article with no children,
8069             ;; we don't want it.
8070             (and (eq gnus-build-sparse-threads 'some)
8071                  (gnus-summary-article-sparse-p number)
8072                  (zerop children))
8073             ;; If we use expunging, and this article is really
8074             ;; low-scored, then we don't want this article.
8075             (when (and gnus-summary-expunge-below
8076                        (< (setq score
8077                                 (or (cdr (assq number gnus-newsgroup-scored))
8078                                     gnus-summary-default-score))
8079                           gnus-summary-expunge-below))
8080               ;; We increase the expunge-tally here, but that has
8081               ;; nothing to do with the limits, really.
8082               (incf gnus-newsgroup-expunged-tally)
8083               ;; We also mark as read here, if that's wanted.
8084               (when (and gnus-summary-mark-below
8085                          (< score gnus-summary-mark-below))
8086                 (setq gnus-newsgroup-unreads
8087                       (delq number gnus-newsgroup-unreads))
8088                 (if gnus-newsgroup-auto-expire
8089                     (push number gnus-newsgroup-expirable)
8090                   (push (cons number gnus-low-score-mark)
8091                         gnus-newsgroup-reads)))
8092               t)
8093             ;; Do the `display' group parameter.
8094             (and gnus-newsgroup-display
8095                  (not (funcall gnus-newsgroup-display)))
8096             ;; Check NoCeM things.
8097             (when (and gnus-use-nocem
8098                        (gnus-nocem-unwanted-article-p
8099                         (mail-header-id (car thread))))
8100               (setq gnus-newsgroup-unreads
8101                     (delq number gnus-newsgroup-unreads))
8102               t)))
8103           ;; Nope, invisible article.
8104           0
8105         ;; Ok, this article is to be visible, so we add it to the limit
8106         ;; and return 1.
8107         (push number gnus-newsgroup-limit)
8108         1))))
8109
8110 (defun gnus-expunge-thread (thread)
8111   "Mark all articles in THREAD as read."
8112   (let* ((number (mail-header-number (car thread))))
8113     (incf gnus-newsgroup-expunged-tally)
8114     ;; We also mark as read here, if that's wanted.
8115     (setq gnus-newsgroup-unreads
8116           (delq number gnus-newsgroup-unreads))
8117     (if gnus-newsgroup-auto-expire
8118         (push number gnus-newsgroup-expirable)
8119       (push (cons number gnus-low-score-mark)
8120             gnus-newsgroup-reads)))
8121   ;; Go recursively through all subthreads.
8122   (mapcar 'gnus-expunge-thread (cdr thread)))
8123
8124 ;; Summary article oriented commands
8125
8126 (defun gnus-summary-refer-parent-article (n)
8127   "Refer parent article N times.
8128 If N is negative, go to ancestor -N instead.
8129 The difference between N and the number of articles fetched is returned."
8130   (interactive "p")
8131   (let ((skip 1)
8132         error header ref)
8133     (when (not (natnump n))
8134       (setq skip (abs n)
8135             n 1))
8136     (while (and (> n 0)
8137                 (not error))
8138       (setq header (gnus-summary-article-header))
8139       (if (and (eq (mail-header-number header)
8140                    (cdr gnus-article-current))
8141                (equal gnus-newsgroup-name
8142                       (car gnus-article-current)))
8143           ;; If we try to find the parent of the currently
8144           ;; displayed article, then we take a look at the actual
8145           ;; References header, since this is slightly more
8146           ;; reliable than the References field we got from the
8147           ;; server.
8148           (save-excursion
8149             (set-buffer gnus-original-article-buffer)
8150             (nnheader-narrow-to-headers)
8151             (unless (setq ref (message-fetch-field "references"))
8152               (when (setq ref (message-fetch-field "in-reply-to"))
8153                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8154             (widen))
8155         (setq ref
8156               ;; It's not the current article, so we take a bet on
8157               ;; the value we got from the server.
8158               (mail-header-references header)))
8159       (if (and ref
8160                (not (equal ref "")))
8161           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8162             (gnus-message 1 "Couldn't find parent"))
8163         (gnus-message 1 "No references in article %d"
8164                       (gnus-summary-article-number))
8165         (setq error t))
8166       (decf n))
8167     (gnus-summary-position-point)
8168     n))
8169
8170 (defun gnus-summary-refer-references ()
8171   "Fetch all articles mentioned in the References header.
8172 Return the number of articles fetched."
8173   (interactive)
8174   (let ((ref (mail-header-references (gnus-summary-article-header)))
8175         (current (gnus-summary-article-number))
8176         (n 0))
8177     (if (or (not ref)
8178             (equal ref ""))
8179         (error "No References in the current article")
8180       ;; For each Message-ID in the References header...
8181       (while (string-match "<[^>]*>" ref)
8182         (incf n)
8183         ;; ... fetch that article.
8184         (gnus-summary-refer-article
8185          (prog1 (match-string 0 ref)
8186            (setq ref (substring ref (match-end 0))))))
8187       (gnus-summary-goto-subject current)
8188       (gnus-summary-position-point)
8189       n)))
8190
8191 (defun gnus-summary-refer-thread (&optional limit)
8192   "Fetch all articles in the current thread.
8193 If LIMIT (the numerical prefix), fetch that many old headers instead
8194 of what's specified by the `gnus-refer-thread-limit' variable."
8195   (interactive "P")
8196   (let ((id (mail-header-id (gnus-summary-article-header)))
8197         (limit (if limit (prefix-numeric-value limit)
8198                  gnus-refer-thread-limit)))
8199     (unless (eq gnus-fetch-old-headers 'invisible)
8200       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8201       ;; Retrieve the headers and read them in.
8202       (if (eq (if (numberp limit)
8203                   (gnus-retrieve-headers
8204                    (list (min
8205                           (+ (mail-header-number
8206                               (gnus-summary-article-header))
8207                              limit)
8208                           gnus-newsgroup-end))
8209                    gnus-newsgroup-name (* limit 2))
8210                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8211                 ;; headers.
8212                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8213                                        gnus-newsgroup-name limit))
8214               'nov)
8215           (gnus-build-all-threads)
8216         (error "Can't fetch thread from back ends that don't support NOV"))
8217       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8218     (gnus-summary-limit-include-thread id)))
8219
8220 (defun gnus-summary-refer-article (message-id)
8221   "Fetch an article specified by MESSAGE-ID."
8222   (interactive "sMessage-ID: ")
8223   (when (and (stringp message-id)
8224              (not (zerop (length message-id))))
8225     (setq message-id (gnus-replace-in-string message-id " " ""))
8226     ;; Construct the correct Message-ID if necessary.
8227     ;; Suggested by tale@pawl.rpi.edu.
8228     (unless (string-match "^<" message-id)
8229       (setq message-id (concat "<" message-id)))
8230     (unless (string-match ">$" message-id)
8231       (setq message-id (concat message-id ">")))
8232     ;; People often post MIDs from URLs, so unhex it:
8233     (unless (string-match "@" message-id)
8234       (setq message-id (gnus-url-unhex-string message-id)))
8235     (let* ((header (gnus-id-to-header message-id))
8236            (sparse (and header
8237                         (gnus-summary-article-sparse-p
8238                          (mail-header-number header))
8239                         (memq (mail-header-number header)
8240                               gnus-newsgroup-limit)))
8241            number)
8242       (cond
8243        ;; If the article is present in the buffer we just go to it.
8244        ((and header
8245              (or (not (gnus-summary-article-sparse-p
8246                        (mail-header-number header)))
8247                  sparse))
8248         (prog1
8249             (gnus-summary-goto-article
8250              (mail-header-number header) nil t)
8251           (when sparse
8252             (gnus-summary-update-article (mail-header-number header)))))
8253        (t
8254         ;; We fetch the article.
8255         (catch 'found
8256           (dolist (gnus-override-method (gnus-refer-article-methods))
8257             (when (and (gnus-check-server gnus-override-method)
8258                        ;; Fetch the header,
8259                        (setq number (gnus-summary-insert-subject message-id)))
8260               ;; and display the article.
8261               (gnus-summary-select-article nil nil nil number)
8262               (throw 'found t)))
8263           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8264
8265 (defun gnus-refer-article-methods ()
8266   "Return a list of referable methods."
8267   (cond
8268    ;; No method, so we default to current and native.
8269    ((null gnus-refer-article-method)
8270     (list gnus-current-select-method gnus-select-method))
8271    ;; Current.
8272    ((eq 'current gnus-refer-article-method)
8273     (list gnus-current-select-method))
8274    ;; List of select methods.
8275    ((not (and (symbolp (car gnus-refer-article-method))
8276               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8277     (let (out)
8278       (dolist (method gnus-refer-article-method)
8279         (push (if (eq 'current method)
8280                   gnus-current-select-method
8281                 method)
8282               out))
8283       (nreverse out)))
8284    ;; One single select method.
8285    (t
8286     (list gnus-refer-article-method))))
8287
8288 (defun gnus-summary-edit-parameters ()
8289   "Edit the group parameters of the current group."
8290   (interactive)
8291   (gnus-group-edit-group gnus-newsgroup-name 'params))
8292
8293 (defun gnus-summary-customize-parameters ()
8294   "Customize the group parameters of the current group."
8295   (interactive)
8296   (gnus-group-customize gnus-newsgroup-name))
8297
8298 (defun gnus-summary-enter-digest-group (&optional force)
8299   "Enter an nndoc group based on the current article.
8300 If FORCE, force a digest interpretation.  If not, try
8301 to guess what the document format is."
8302   (interactive "P")
8303   (let ((conf gnus-current-window-configuration))
8304     (save-window-excursion
8305       (save-excursion
8306         (let (gnus-article-prepare-hook
8307               gnus-display-mime-function
8308               gnus-break-pages)
8309           (gnus-summary-select-article))))
8310     (setq gnus-current-window-configuration conf)
8311     (let* ((name (format "%s-%d"
8312                          (gnus-group-prefixed-name
8313                           gnus-newsgroup-name (list 'nndoc ""))
8314                          (with-current-buffer gnus-summary-buffer
8315                            gnus-current-article)))
8316            (ogroup gnus-newsgroup-name)
8317            (params (append (gnus-info-params (gnus-get-info ogroup))
8318                            (list (cons 'to-group ogroup))
8319                            (list (cons 'parent-group ogroup))
8320                            (list (cons 'save-article-group ogroup))))
8321            (case-fold-search t)
8322            (buf (current-buffer))
8323            dig to-address)
8324       (save-excursion
8325         (set-buffer gnus-original-article-buffer)
8326         ;; Have the digest group inherit the main mail address of
8327         ;; the parent article.
8328         (when (setq to-address (or (gnus-fetch-field "reply-to")
8329                                    (gnus-fetch-field "from")))
8330           (setq params (append
8331                         (list (cons 'to-address
8332                                     (funcall gnus-decode-encoded-word-function
8333                                              to-address))))))
8334         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8335         (insert-buffer-substring gnus-original-article-buffer)
8336         ;; Remove lines that may lead nndoc to misinterpret the
8337         ;; document type.
8338         (narrow-to-region
8339          (goto-char (point-min))
8340          (or (search-forward "\n\n" nil t) (point)))
8341         (goto-char (point-min))
8342         (delete-matching-lines "^Path:\\|^From ")
8343         (widen))
8344       (unwind-protect
8345           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8346                     (gnus-newsgroup-ephemeral-ignored-charsets
8347                      gnus-newsgroup-ignored-charsets))
8348                 (gnus-group-read-ephemeral-group
8349                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8350                               (nndoc-article-type
8351                                ,(if force 'mbox 'guess)))
8352                  t nil nil nil
8353                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8354                                                         "ADAPT")))))
8355               ;; Make all postings to this group go to the parent group.
8356               (nconc (gnus-info-params (gnus-get-info name))
8357                      params)
8358             ;; Couldn't select this doc group.
8359             (switch-to-buffer buf)
8360             (gnus-set-global-variables)
8361             (gnus-configure-windows 'summary)
8362             (gnus-message 3 "Article couldn't be entered?"))
8363         (kill-buffer dig)))))
8364
8365 (defun gnus-summary-read-document (n)
8366   "Open a new group based on the current article(s).
8367 This will allow you to read digests and other similar
8368 documents as newsgroups.
8369 Obeys the standard process/prefix convention."
8370   (interactive "P")
8371   (let* ((articles (gnus-summary-work-articles n))
8372          (ogroup gnus-newsgroup-name)
8373          (params (append (gnus-info-params (gnus-get-info ogroup))
8374                          (list (cons 'to-group ogroup))))
8375          article group egroup groups vgroup)
8376     (while (setq article (pop articles))
8377       (setq group (format "%s-%d" gnus-newsgroup-name article))
8378       (gnus-summary-remove-process-mark article)
8379       (when (gnus-summary-display-article article)
8380         (save-excursion
8381           (with-temp-buffer
8382             (insert-buffer-substring gnus-original-article-buffer)
8383             ;; Remove some headers that may lead nndoc to make
8384             ;; the wrong guess.
8385             (message-narrow-to-head)
8386             (goto-char (point-min))
8387             (delete-matching-lines "^Path:\\|^From ")
8388             (widen)
8389             (if (setq egroup
8390                       (gnus-group-read-ephemeral-group
8391                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8392                                      (nndoc-article-type guess))
8393                        t nil t))
8394                 (progn
8395                   ;; Make all postings to this group go to the parent group.
8396                   (nconc (gnus-info-params (gnus-get-info egroup))
8397                          params)
8398                   (push egroup groups))
8399               ;; Couldn't select this doc group.
8400               (gnus-error 3 "Article couldn't be entered"))))))
8401     ;; Now we have selected all the documents.
8402     (cond
8403      ((not groups)
8404       (error "None of the articles could be interpreted as documents"))
8405      ((gnus-group-read-ephemeral-group
8406        (setq vgroup (format
8407                      "nnvirtual:%s-%s" gnus-newsgroup-name
8408                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8409        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8410        t
8411        (cons (current-buffer) 'summary)))
8412      (t
8413       (error "Couldn't select virtual nndoc group")))))
8414
8415 (defun gnus-summary-isearch-article (&optional regexp-p)
8416   "Do incremental search forward on the current article.
8417 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8418   (interactive "P")
8419   (let* ((gnus-inhibit-treatment t)
8420          (old (gnus-summary-select-article)))
8421     (gnus-configure-windows 'article)
8422     (gnus-eval-in-buffer-window gnus-article-buffer
8423       (save-restriction
8424         (widen)
8425         (when (eq 'old old)
8426           (gnus-article-show-all-headers))
8427         (goto-char (point-min))
8428         (isearch-forward regexp-p)))))
8429
8430 (defun gnus-summary-search-article-forward (regexp &optional backward)
8431   "Search for an article containing REGEXP forward.
8432 If BACKWARD, search backward instead."
8433   (interactive
8434    (list (read-string
8435           (format "Search article %s (regexp%s): "
8436                   (if current-prefix-arg "backward" "forward")
8437                   (if gnus-last-search-regexp
8438                       (concat ", default " gnus-last-search-regexp)
8439                     "")))
8440          current-prefix-arg))
8441   (if (string-equal regexp "")
8442       (setq regexp (or gnus-last-search-regexp ""))
8443     (setq gnus-last-search-regexp regexp)
8444     (setq gnus-article-before-search gnus-current-article))
8445   ;; Intentionally set gnus-last-article.
8446   (setq gnus-last-article gnus-article-before-search)
8447   (let ((gnus-last-article gnus-last-article))
8448     (if (gnus-summary-search-article regexp backward)
8449         (gnus-summary-show-thread)
8450       (error "Search failed: \"%s\"" regexp))))
8451
8452 (defun gnus-summary-search-article-backward (regexp)
8453   "Search for an article containing REGEXP backward."
8454   (interactive
8455    (list (read-string
8456           (format "Search article backward (regexp%s): "
8457                   (if gnus-last-search-regexp
8458                       (concat ", default " gnus-last-search-regexp)
8459                     "")))))
8460   (gnus-summary-search-article-forward regexp 'backward))
8461
8462 (eval-when-compile
8463   (defmacro gnus-summary-search-article-position-point (regexp backward)
8464     "Dehighlight the last matched text and goto the beginning position."
8465     (` (if (and gnus-summary-search-article-matched-data
8466                 (let ((text (caddr gnus-summary-search-article-matched-data))
8467                       (inhibit-read-only t)
8468                       buffer-read-only)
8469                   (delete-region
8470                    (goto-char (car gnus-summary-search-article-matched-data))
8471                    (cadr gnus-summary-search-article-matched-data))
8472                   (insert text)
8473                   (string-match (, regexp) text)))
8474            (if (, backward) (beginning-of-line) (end-of-line))
8475          (goto-char (if (, backward) (point-max) (point-min))))))
8476
8477   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8478     "Place point where X-Face image is displayed."
8479     (if (featurep 'xemacs)
8480         (` (let ((end (if (search-forward "\n\n" nil t)
8481                           (goto-char (1- (point)))
8482                         (point-min)))
8483                  extent)
8484              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8485              (unless (and (re-search-forward "^From:" end t)
8486                           (setq extent (extent-at (point)))
8487                           (extent-begin-glyph extent))
8488                (goto-char (, opoint)))))
8489       (` (let ((end (if (search-forward "\n\n" nil t)
8490                         (goto-char (1- (point)))
8491                       (point-min)))
8492                (start (or (search-backward "\n\n" nil t) (point-min))))
8493            (goto-char
8494             (or (text-property-any start end 'x-face-image t);; x-face-e21
8495                 (text-property-any start end 'x-face-mule-bitmap-image t)
8496                 (, opoint)))))))
8497
8498   (defmacro gnus-summary-search-article-highlight-matched-text
8499     (backward treated x-face)
8500     "Highlight matched text in the function `gnus-summary-search-article'."
8501     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8502              (end (set-marker (make-marker) (match-end 0)))
8503              (inhibit-read-only t)
8504              buffer-read-only)
8505          (unless treated
8506            (let ((,@
8507                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8508                     (mapcar
8509                      (lambda (item) (setq items (delq item items)))
8510                      '(gnus-treat-buttonize
8511                        gnus-treat-fill-article
8512                        gnus-treat-fill-long-lines
8513                        gnus-treat-emphasize
8514                        gnus-treat-highlight-headers
8515                        gnus-treat-highlight-citation
8516                        gnus-treat-highlight-signature
8517                        gnus-treat-overstrike
8518                        gnus-treat-display-x-face
8519                        gnus-treat-buttonize-head
8520                        gnus-treat-decode-article-as-default-mime-charset))
8521                     (static-if (featurep 'xemacs)
8522                         items
8523                       (cons '(x-face-mule-delete-x-face-field
8524                               (quote never))
8525                             items))))
8526                  (gnus-treat-display-x-face
8527                   (when (, x-face) gnus-treat-display-x-face)))
8528              (gnus-article-prepare-mime-display)))
8529          (goto-char (if (, backward) start end))
8530          (when (, x-face)
8531            (gnus-summary-search-article-highlight-goto-x-face (point)))
8532          (setq gnus-summary-search-article-matched-data
8533                (list start end (buffer-substring start end)))
8534          (unless (eq start end);; matched text has been deleted. :-<
8535            (put-text-property start end 'face
8536                               (or (find-face 'isearch)
8537                                   'secondary-selection))))))
8538   )
8539
8540 (defun gnus-summary-search-article (regexp &optional backward)
8541   "Search for an article containing REGEXP.
8542 Optional argument BACKWARD means do search for backward.
8543 `gnus-select-article-hook' is not called during the search."
8544   ;; We have to require this here to make sure that the following
8545   ;; dynamic binding isn't shadowed by autoloading.
8546   (require 'gnus-async)
8547   (require 'gnus-art)
8548   (let ((gnus-select-article-hook nil)  ;Disable hook.
8549         (gnus-article-prepare-hook nil)
8550         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8551         (gnus-use-article-prefetch nil)
8552         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8553         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8554         (gnus-visual nil)
8555         (gnus-keep-backlog nil)
8556         (gnus-break-pages nil)
8557         (gnus-summary-display-arrow nil)
8558         (gnus-updated-mode-lines nil)
8559         (gnus-auto-center-summary nil)
8560         (sum (current-buffer))
8561         (found nil)
8562         point treated)
8563     (gnus-save-hidden-threads
8564       (static-if (featurep 'xemacs)
8565           (let ((gnus-inhibit-treatment t))
8566             (setq treated (eq 'old (gnus-summary-select-article)))
8567             (when (and treated
8568                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8569                                  (window-live-p (get-buffer-window
8570                                                  gnus-article-buffer t)))))
8571               (gnus-summary-select-article nil t)
8572               (setq treated nil)))
8573         (let ((gnus-inhibit-treatment t)
8574               (x-face-mule-delete-x-face-field 'never))
8575           (setq treated (eq 'old (gnus-summary-select-article)))
8576           (when (and treated
8577                      (not
8578                       (and (gnus-buffer-live-p gnus-article-buffer)
8579                            (window-live-p (get-buffer-window
8580                                            gnus-article-buffer t))
8581                            (or (not (string-match "^\\^X-Face:" regexp))
8582                                (with-current-buffer gnus-article-buffer
8583                                  gnus-summary-search-article-matched-data)))))
8584             (gnus-summary-select-article nil t)
8585             (setq treated nil))))
8586       (set-buffer gnus-article-buffer)
8587       (widen)
8588       (if treated
8589           (progn
8590             (gnus-article-show-all-headers)
8591             (gnus-summary-search-article-position-point regexp backward))
8592         (goto-char (if backward (point-max) (point-min))))
8593       (while (not found)
8594         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8595         (if (if backward
8596                 (re-search-backward regexp nil t)
8597               (re-search-forward regexp nil t))
8598             ;; We found the regexp.
8599             (progn
8600               (gnus-summary-search-article-highlight-matched-text
8601                backward treated (string-match "^\\^X-Face:" regexp))
8602               (setq found 'found)
8603               (forward-line
8604                (/ (- 2 (window-height
8605                         (get-buffer-window gnus-article-buffer t)))
8606                   2))
8607               (set-window-start
8608                (get-buffer-window (current-buffer))
8609                (point))
8610               (set-buffer sum)
8611               (setq point (point)))
8612           ;; We didn't find it, so we go to the next article.
8613           (set-buffer sum)
8614           (setq found 'not)
8615           (while (eq found 'not)
8616             (if (not (if backward (gnus-summary-find-prev)
8617                        (gnus-summary-find-next)))
8618                 ;; No more articles.
8619                 (setq found t)
8620               ;; Select the next article and adjust point.
8621               (unless (gnus-summary-article-sparse-p
8622                        (gnus-summary-article-number))
8623                 (setq found nil)
8624                 (let ((gnus-inhibit-treatment t))
8625                   (gnus-summary-select-article))
8626                 (setq treated nil)
8627                 (set-buffer gnus-article-buffer)
8628                 (widen)
8629                 (goto-char (if backward (point-max) (point-min))))))))
8630       (gnus-message 7 ""))
8631     ;; Return whether we found the regexp.
8632     (when (eq found 'found)
8633       (goto-char point)
8634       (gnus-summary-show-thread)
8635       (gnus-summary-goto-subject gnus-current-article)
8636       (gnus-summary-position-point)
8637       t)))
8638
8639 (defun gnus-find-matching-articles (header regexp)
8640   "Return a list of all articles that match REGEXP on HEADER.
8641 This search includes all articles in the current group that Gnus has
8642 fetched headers for, whether they are displayed or not."
8643   (let ((articles nil)
8644         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8645         (case-fold-search t))
8646     (dolist (header gnus-newsgroup-headers)
8647       (when (string-match regexp (funcall func header))
8648         (push (mail-header-number header) articles)))
8649     (nreverse articles)))
8650
8651 (defun gnus-summary-find-matching (header regexp &optional backward unread
8652                                           not-case-fold not-matching)
8653   "Return a list of all articles that match REGEXP on HEADER.
8654 The search stars on the current article and goes forwards unless
8655 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8656 If UNREAD is non-nil, only unread articles will
8657 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8658 in the comparisons. If NOT-MATCHING, return a list of all articles that
8659 not match REGEXP on HEADER."
8660   (let ((case-fold-search (not not-case-fold))
8661         articles d func)
8662     (if (consp header)
8663         (if (eq (car header) 'extra)
8664             (setq func
8665                   `(lambda (h)
8666                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8667                          "")))
8668           (error "%s is an invalid header" header))
8669       (unless (fboundp (intern (concat "mail-header-" header)))
8670         (error "%s is not a valid header" header))
8671       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8672     (dolist (d (if (eq backward 'all)
8673                    gnus-newsgroup-data
8674                  (gnus-data-find-list
8675                   (gnus-summary-article-number)
8676                   (gnus-data-list backward))))
8677       (when (and (or (not unread)       ; We want all articles...
8678                      (gnus-data-unread-p d)) ; Or just unreads.
8679                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8680                  (if not-matching
8681                      (not (string-match
8682                            regexp
8683                            (funcall func (gnus-data-header d))))
8684                    (string-match regexp
8685                                  (funcall func (gnus-data-header d)))))
8686         (push (gnus-data-number d) articles))) ; Success!
8687     (nreverse articles)))
8688
8689 (defun gnus-summary-execute-command (header regexp command &optional backward)
8690   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8691 If HEADER is an empty string (or nil), the match is done on the entire
8692 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8693   (interactive
8694    (list (let ((completion-ignore-case t))
8695            (completing-read
8696             "Header name: "
8697             (mapcar (lambda (header) (list (format "%s" header)))
8698                     (append
8699                      '("Number" "Subject" "From" "Lines" "Date"
8700                        "Message-ID" "Xref" "References" "Body")
8701                      gnus-extra-headers))
8702             nil 'require-match))
8703          (read-string "Regexp: ")
8704          (read-key-sequence "Command: ")
8705          current-prefix-arg))
8706   (when (equal header "Body")
8707     (setq header ""))
8708   ;; Hidden thread subtrees must be searched as well.
8709   (gnus-summary-show-all-threads)
8710   ;; We don't want to change current point nor window configuration.
8711   (save-excursion
8712     (save-window-excursion
8713       (let (gnus-visual
8714             gnus-treat-strip-trailing-blank-lines
8715             gnus-treat-strip-leading-blank-lines
8716             gnus-treat-strip-multiple-blank-lines
8717             gnus-treat-hide-boring-headers
8718             gnus-treat-fold-newsgroups
8719             gnus-article-prepare-hook)
8720         (gnus-message 6 "Executing %s..." (key-description command))
8721         ;; We'd like to execute COMMAND interactively so as to give arguments.
8722         (gnus-execute header regexp
8723                       `(call-interactively ',(key-binding command))
8724                       backward)
8725         (gnus-message 6 "Executing %s...done" (key-description command))))))
8726
8727 (defun gnus-summary-beginning-of-article ()
8728   "Scroll the article back to the beginning."
8729   (interactive)
8730   (gnus-summary-select-article)
8731   (gnus-configure-windows 'article)
8732   (gnus-eval-in-buffer-window gnus-article-buffer
8733     (widen)
8734     (goto-char (point-min))
8735     (when gnus-break-pages
8736       (gnus-narrow-to-page))))
8737
8738 (defun gnus-summary-end-of-article ()
8739   "Scroll to the end of the article."
8740   (interactive)
8741   (gnus-summary-select-article)
8742   (gnus-configure-windows 'article)
8743   (gnus-eval-in-buffer-window gnus-article-buffer
8744     (widen)
8745     (goto-char (point-max))
8746     (recenter -3)
8747     (when gnus-break-pages
8748       (when (re-search-backward page-delimiter nil t)
8749         (narrow-to-region (match-end 0) (point-max)))
8750       (gnus-narrow-to-page))))
8751
8752 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8753   "Truncate to LEN and quote all \"(\"'s in STRING."
8754   (gnus-replace-in-string (if (and len (> (length string) len))
8755                               (substring string 0 len)
8756                             string)
8757                           "[()]" "\\\\\\&"))
8758
8759 (defun gnus-summary-print-article (&optional filename n)
8760   "Generate and print a PostScript image of the process-marked (mail) articles.
8761
8762 If used interactively, print the current article if none are
8763 process-marked.  With prefix arg, prompt the user for the name of the
8764 file to save in.
8765
8766 When used from Lisp, accept two optional args FILENAME and N.  N means
8767 to print the next N articles.  If N is negative, print the N previous
8768 articles.  If N is nil and articles have been marked with the process
8769 mark, print these instead.
8770
8771 If the optional first argument FILENAME is nil, send the image to the
8772 printer.  If FILENAME is a string, save the PostScript image in a file with
8773 that name.  If FILENAME is a number, prompt the user for the name of the file
8774 to save in."
8775   (interactive (list (ps-print-preprint current-prefix-arg)))
8776   (dolist (article (gnus-summary-work-articles n))
8777     (gnus-summary-select-article nil nil 'pseudo article)
8778     (gnus-eval-in-buffer-window gnus-article-buffer
8779       (gnus-print-buffer))
8780     (gnus-summary-remove-process-mark article))
8781   (ps-despool filename))
8782
8783 (defun gnus-print-buffer ()
8784   (let ((buffer (generate-new-buffer " *print*")))
8785     (unwind-protect
8786         (progn
8787           (copy-to-buffer buffer (point-min) (point-max))
8788           (set-buffer buffer)
8789           (gnus-remove-text-with-property 'gnus-decoration)
8790           (when (gnus-visual-p 'article-highlight 'highlight)
8791             ;; Copy-to-buffer doesn't copy overlay.  So redo
8792             ;; highlight.
8793             (let ((gnus-article-buffer buffer))
8794               (gnus-article-highlight-citation t)
8795               (gnus-article-highlight-signature)
8796               (gnus-article-emphasize)
8797               (gnus-article-delete-invisible-text)))
8798           (let ((ps-left-header
8799                  (list
8800                   (concat "("
8801                           (gnus-summary-print-truncate-and-quote
8802                            (mail-header-subject gnus-current-headers)
8803                            66) ")")
8804                   (concat "("
8805                           (gnus-summary-print-truncate-and-quote
8806                            (mail-header-from gnus-current-headers)
8807                            45) ")")))
8808                 (ps-right-header
8809                  (list
8810                   "/pagenumberstring load"
8811                   (concat "("
8812                           (mail-header-date gnus-current-headers) ")"))))
8813             (gnus-run-hooks 'gnus-ps-print-hook)
8814             (save-excursion
8815               (if window-system
8816                   (ps-spool-buffer-with-faces)
8817                 (ps-spool-buffer)))))
8818       (kill-buffer buffer))))
8819
8820 (defun gnus-summary-show-article (&optional arg)
8821   "Force redisplaying of the current article.
8822 If ARG (the prefix) is a number, show the article with the charset
8823 defined in `gnus-summary-show-article-charset-alist', or the charset
8824 input.
8825 If ARG (the prefix) is non-nil and not a number, show the raw article
8826 without any article massaging functions being run.  Normally, the key
8827 strokes are `C-u g'."
8828   (interactive "P")
8829   (cond
8830    ((numberp arg)
8831     (gnus-summary-show-article t)
8832     (let* ((gnus-newsgroup-charset
8833             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8834                 (mm-read-coding-system
8835                  "View as charset: " ;; actually it is coding system.
8836                  (save-excursion
8837                    (set-buffer gnus-article-buffer)
8838                    (mm-detect-coding-region (point) (point-max))))))
8839            (default-mime-charset gnus-newsgroup-charset)
8840            (gnus-newsgroup-ignored-charsets 'gnus-all))
8841       (gnus-summary-select-article nil 'force)
8842       (let ((deps gnus-newsgroup-dependencies)
8843             head header lines)
8844         (save-excursion
8845           (set-buffer gnus-original-article-buffer)
8846           (save-restriction
8847             (message-narrow-to-head)
8848             (setq head (buffer-string))
8849             (goto-char (point-min))
8850             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8851               (goto-char (point-max))
8852               (widen)
8853               (setq lines (1- (count-lines (point) (point-max))))))
8854           (with-temp-buffer
8855             (insert (format "211 %d Article retrieved.\n"
8856                             (cdr gnus-article-current)))
8857             (insert head)
8858             (if lines (insert (format "Lines: %d\n" lines)))
8859             (insert ".\n")
8860             (let ((nntp-server-buffer (current-buffer)))
8861               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8862         (gnus-data-set-header
8863          (gnus-data-find (cdr gnus-article-current))
8864          header)
8865         (gnus-summary-update-article-line
8866          (cdr gnus-article-current) header)
8867         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8868           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8869    ((not arg)
8870     ;; Select the article the normal way.
8871     (gnus-summary-select-article nil 'force))
8872    (t
8873     ;; We have to require this here to make sure that the following
8874     ;; dynamic binding isn't shadowed by autoloading.
8875     (require 'gnus-async)
8876     (require 'gnus-art)
8877     ;; Bind the article treatment functions to nil.
8878     (let ((gnus-have-all-headers t)
8879           gnus-article-prepare-hook
8880           gnus-article-decode-hook
8881           gnus-break-pages
8882           gnus-show-mime
8883           (gnus-inhibit-treatment t))
8884       (gnus-summary-select-article nil 'force))))
8885   (gnus-summary-goto-subject gnus-current-article)
8886   (gnus-summary-position-point))
8887
8888 (defun gnus-summary-show-raw-article ()
8889   "Show the raw article without any article massaging functions being run."
8890   (interactive)
8891   (gnus-summary-show-article t))
8892
8893 (defun gnus-summary-verbose-headers (&optional arg)
8894   "Toggle permanent full header display.
8895 If ARG is a positive number, turn header display on.
8896 If ARG is a negative number, turn header display off."
8897   (interactive "P")
8898   (setq gnus-show-all-headers
8899         (cond ((or (not (numberp arg))
8900                    (zerop arg))
8901                (not gnus-show-all-headers))
8902               ((natnump arg)
8903                t)))
8904   (gnus-summary-show-article))
8905
8906 (defun gnus-summary-toggle-header (&optional arg)
8907   "Show the headers if they are hidden, or hide them if they are shown.
8908 If ARG is a positive number, show the entire header.
8909 If ARG is a negative number, hide the unwanted header lines."
8910   (interactive "P")
8911   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8912                      (get-buffer-window gnus-article-buffer t))))
8913     (with-current-buffer gnus-article-buffer
8914       (widen)
8915       (article-narrow-to-head)
8916       (let* ((buffer-read-only nil)
8917              (inhibit-point-motion-hooks t)
8918              (hidden (if (numberp arg)
8919                          (>= arg 0)
8920                        (gnus-article-hidden-text-p 'headers)))
8921              s e)
8922         (delete-region (point-min) (point-max))
8923         (with-current-buffer gnus-original-article-buffer
8924           (goto-char (setq s (point-min)))
8925           (setq e (if (search-forward "\n\n" nil t)
8926                       (1- (point))
8927                     (point-max))))
8928         (insert-buffer-substring gnus-original-article-buffer s e)
8929         ;; In T-gnus, gnus-article-decode-hook doesn't contain
8930         ;; article-decode-encoded-words by default.
8931         (article-decode-encoded-words)
8932         (run-hooks 'gnus-article-decode-hook)
8933         (if hidden
8934             (let ((gnus-treat-hide-headers nil)
8935                   (gnus-treat-hide-boring-headers nil))
8936               (gnus-delete-wash-type 'headers)
8937               (gnus-treat-article 'head))
8938           (gnus-treat-article 'head))
8939         (widen)
8940         (if window
8941             (set-window-start window (goto-char (point-min))))
8942         (if gnus-break-pages
8943             (gnus-narrow-to-page)
8944           (when (gnus-visual-p 'page-marker)
8945             (let ((buffer-read-only nil))
8946               (gnus-remove-text-with-property 'gnus-prev)
8947               (gnus-remove-text-with-property 'gnus-next))))
8948         (gnus-set-mode-line 'article)))))
8949
8950 (defun gnus-summary-show-all-headers ()
8951   "Make all header lines visible."
8952   (interactive)
8953   (gnus-summary-toggle-header 1))
8954
8955 (defun gnus-summary-toggle-mime (&optional arg)
8956   "Toggle MIME processing.
8957 If ARG is a positive number, turn MIME processing on."
8958   (interactive "P")
8959   (setq gnus-show-mime
8960         (if (null arg)
8961             (not gnus-show-mime)
8962           (> (prefix-numeric-value arg) 0)))
8963   (gnus-summary-select-article t 'force))
8964
8965 (defun gnus-summary-caesar-message (&optional arg)
8966   "Caesar rotate the current article by 13.
8967 The numerical prefix specifies how many places to rotate each letter
8968 forward."
8969   (interactive "P")
8970   (gnus-summary-select-article)
8971   (let ((mail-header-separator ""))
8972     (gnus-eval-in-buffer-window gnus-article-buffer
8973       (save-restriction
8974         (widen)
8975         (let ((start (window-start))
8976               buffer-read-only)
8977           (message-caesar-buffer-body arg)
8978           (set-window-start (get-buffer-window (current-buffer)) start))))))
8979
8980 (autoload 'unmorse-region "morse"
8981   "Convert morse coded text in region to ordinary ASCII text."
8982   t)
8983
8984 (defun gnus-summary-morse-message (&optional arg)
8985   "Morse decode the current article."
8986   (interactive "P")
8987   (gnus-summary-select-article)
8988   (let ((mail-header-separator ""))
8989     (gnus-eval-in-buffer-window gnus-article-buffer
8990       (save-excursion
8991         (save-restriction
8992           (widen)
8993           (let ((pos (window-start))
8994                 buffer-read-only)
8995             (goto-char (point-min))
8996             (when (message-goto-body)
8997               (gnus-narrow-to-body))
8998             (goto-char (point-min))
8999             (while (re-search-forward "·" (point-max) t)
9000               (replace-match "."))
9001             (unmorse-region (point-min) (point-max))
9002             (widen)
9003             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9004
9005 (defun gnus-summary-stop-page-breaking ()
9006   "Stop page breaking in the current article."
9007   (interactive)
9008   (gnus-summary-select-article)
9009   (gnus-eval-in-buffer-window gnus-article-buffer
9010     (widen)
9011     (when (gnus-visual-p 'page-marker)
9012       (let ((buffer-read-only nil))
9013         (gnus-remove-text-with-property 'gnus-prev)
9014         (gnus-remove-text-with-property 'gnus-next))
9015       (setq gnus-page-broken nil))))
9016
9017 (defun gnus-summary-move-article (&optional n to-newsgroup
9018                                             select-method action)
9019   "Move the current article to a different newsgroup.
9020 If N is a positive number, move the N next articles.
9021 If N is a negative number, move the N previous articles.
9022 If N is nil and any articles have been marked with the process mark,
9023 move those articles instead.
9024 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9025 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9026 re-spool using this method.
9027
9028 When called interactively with TO-NEWSGROUP being nil, the value of
9029 the variable `gnus-move-split-methods' is used for finding a default
9030 for the target newsgroup.
9031
9032 For this function to work, both the current newsgroup and the
9033 newsgroup that you want to move to have to support the `request-move'
9034 and `request-accept' functions.
9035
9036 ACTION can be either `move' (the default), `crosspost' or `copy'."
9037   (interactive "P")
9038   (unless action
9039     (setq action 'move))
9040   ;; Check whether the source group supports the required functions.
9041   (cond ((and (eq action 'move)
9042               (not (gnus-check-backend-function
9043                     'request-move-article gnus-newsgroup-name)))
9044          (error "The current group does not support article moving"))
9045         ((and (eq action 'crosspost)
9046               (not (gnus-check-backend-function
9047                     'request-replace-article gnus-newsgroup-name)))
9048          (error "The current group does not support article editing")))
9049   (let ((articles (gnus-summary-work-articles n))
9050         (prefix (if (gnus-check-backend-function
9051                      'request-move-article gnus-newsgroup-name)
9052                     (funcall gnus-move-group-prefix-function
9053                              gnus-newsgroup-name)
9054                   ""))
9055         (names '((move "Move" "Moving")
9056                  (copy "Copy" "Copying")
9057                  (crosspost "Crosspost" "Crossposting")))
9058         (copy-buf (save-excursion
9059                     (nnheader-set-temp-buffer " *copy article*")))
9060         art-group to-method new-xref article to-groups)
9061     (unless (assq action names)
9062       (error "Unknown action %s" action))
9063     ;; Read the newsgroup name.
9064     (when (and (not to-newsgroup)
9065                (not select-method))
9066       (if (and gnus-move-split-methods
9067                (not
9068                 (and (memq gnus-current-article articles)
9069                      (gnus-buffer-live-p gnus-original-article-buffer))))
9070           ;; When `gnus-move-split-methods' is non-nil, we have to
9071           ;; select an article to give `gnus-read-move-group-name' an
9072           ;; opportunity to suggest an appropriate default.  However,
9073           ;; we needn't render or mark the article.
9074           (let ((gnus-display-mime-function nil)
9075                 (gnus-article-prepare-hook nil)
9076                 (gnus-mark-article-hook nil))
9077             (gnus-summary-select-article nil nil nil (car articles))))
9078       (setq to-newsgroup
9079             (gnus-read-move-group-name
9080              (cadr (assq action names))
9081              (symbol-value (intern (format "gnus-current-%s-group" action)))
9082              articles prefix))
9083       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9084     (setq to-method (or select-method
9085                         (gnus-server-to-method
9086                          (gnus-group-method to-newsgroup))))
9087     ;; Check the method we are to move this article to...
9088     (unless (gnus-check-backend-function
9089              'request-accept-article (car to-method))
9090       (error "%s does not support article copying" (car to-method)))
9091     (unless (gnus-check-server to-method)
9092       (error "Can't open server %s" (car to-method)))
9093     (gnus-message 6 "%s to %s: %s..."
9094                   (caddr (assq action names))
9095                   (or (car select-method) to-newsgroup) articles)
9096     (while articles
9097       (setq article (pop articles))
9098       (setq
9099        art-group
9100        (cond
9101         ;; Move the article.
9102         ((eq action 'move)
9103          ;; Remove this article from future suppression.
9104          (gnus-dup-unsuppress-article article)
9105          (gnus-request-move-article
9106           article                       ; Article to move
9107           gnus-newsgroup-name           ; From newsgroup
9108           (nth 1 (gnus-find-method-for-group
9109                   gnus-newsgroup-name)) ; Server
9110           (list 'gnus-request-accept-article
9111                 to-newsgroup (list 'quote select-method)
9112                 (not articles) t)       ; Accept form
9113           (not articles)))              ; Only save nov last time
9114         ;; Copy the article.
9115         ((eq action 'copy)
9116          (save-excursion
9117            (set-buffer copy-buf)
9118            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9119              (gnus-request-accept-article
9120               to-newsgroup select-method (not articles) t))))
9121         ;; Crosspost the article.
9122         ((eq action 'crosspost)
9123          (let ((xref (message-tokenize-header
9124                       (mail-header-xref (gnus-summary-article-header article))
9125                       " ")))
9126            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9127                                   ":" (number-to-string article)))
9128            (unless xref
9129              (setq xref (list (system-name))))
9130            (setq new-xref
9131                  (concat
9132                   (mapconcat 'identity
9133                              (delete "Xref:" (delete new-xref xref))
9134                              " ")
9135                   " " new-xref))
9136            (save-excursion
9137              (set-buffer copy-buf)
9138              ;; First put the article in the destination group.
9139              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9140              (when (consp (setq art-group
9141                                 (gnus-request-accept-article
9142                                  to-newsgroup select-method (not articles))))
9143                (setq new-xref (concat new-xref " " (car art-group)
9144                                       ":"
9145                                       (number-to-string (cdr art-group))))
9146                ;; Now we have the new Xrefs header, so we insert
9147                ;; it and replace the new article.
9148                (nnheader-replace-header "Xref" new-xref)
9149                (gnus-request-replace-article
9150                 (cdr art-group) to-newsgroup (current-buffer))
9151                art-group))))))
9152       (cond
9153        ((not art-group)
9154         (gnus-message 1 "Couldn't %s article %s: %s"
9155                       (cadr (assq action names)) article
9156                       (nnheader-get-report (car to-method))))
9157        ((eq art-group 'junk)
9158         (when (eq action 'move)
9159           (gnus-summary-mark-article article gnus-canceled-mark)
9160           (gnus-message 4 "Deleted article %s" article)
9161           ;; run the delete hook
9162           (run-hook-with-args 'gnus-summary-article-delete-hook
9163                               action
9164                               (gnus-data-header
9165                                (assoc article (gnus-data-list nil)))
9166                               gnus-newsgroup-name nil
9167                               select-method)))
9168        (t
9169         (let* ((pto-group (gnus-group-prefixed-name
9170                            (car art-group) to-method))
9171                (info (gnus-get-info pto-group))
9172                (to-group (gnus-info-group info))
9173                to-marks)
9174           ;; Update the group that has been moved to.
9175           (when (and info
9176                      (memq action '(move copy)))
9177             (unless (member to-group to-groups)
9178               (push to-group to-groups))
9179
9180             (unless (memq article gnus-newsgroup-unreads)
9181               (push 'read to-marks)
9182               (gnus-info-set-read
9183                info (gnus-add-to-range (gnus-info-read info)
9184                                        (list (cdr art-group)))))
9185
9186             ;; See whether the article is to be put in the cache.
9187             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9188                              gnus-article-mark-lists
9189                            (delete '(expirable . expire)
9190                                    (copy-sequence gnus-article-mark-lists))))
9191                   (to-article (cdr art-group)))
9192
9193               ;; Enter the article into the cache in the new group,
9194               ;; if that is required.
9195               (when gnus-use-cache
9196                 (gnus-cache-possibly-enter-article
9197                  to-group to-article
9198                  (let ((header (copy-sequence
9199                                 (gnus-summary-article-header article))))
9200                    (mail-header-set-number header to-article)
9201                    header)
9202                  (memq article gnus-newsgroup-marked)
9203                  (memq article gnus-newsgroup-dormant)
9204                  (memq article gnus-newsgroup-unreads)))
9205
9206               (when gnus-preserve-marks
9207                 ;; Copy any marks over to the new group.
9208                 (when (and (equal to-group gnus-newsgroup-name)
9209                            (not (memq article gnus-newsgroup-unreads)))
9210                   ;; Mark this article as read in this group.
9211                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9212                   (setcdr (gnus-active to-group) to-article)
9213                   (setcdr gnus-newsgroup-active to-article))
9214
9215                 (while marks
9216                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9217                     (when (memq article (symbol-value
9218                                          (intern (format "gnus-newsgroup-%s"
9219                                                          (caar marks)))))
9220                       (push (cdar marks) to-marks)
9221                       ;; If the other group is the same as this group,
9222                       ;; then we have to add the mark to the list.
9223                       (when (equal to-group gnus-newsgroup-name)
9224                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9225                              (cons to-article
9226                                    (symbol-value
9227                                     (intern (format "gnus-newsgroup-%s"
9228                                                     (caar marks)))))))
9229                       ;; Copy the marks to other group.
9230                       (gnus-add-marked-articles
9231                        to-group (cdar marks) (list to-article) info)))
9232                   (setq marks (cdr marks)))
9233
9234                 (gnus-request-set-mark
9235                  to-group (list (list (list to-article) 'add to-marks))))
9236
9237               (gnus-dribble-enter
9238                (concat "(gnus-group-set-info '"
9239                        (gnus-prin1-to-string (gnus-get-info to-group))
9240                        ")"))))
9241
9242           ;; Update the Xref header in this article to point to
9243           ;; the new crossposted article we have just created.
9244           (when (eq action 'crosspost)
9245             (save-excursion
9246               (set-buffer copy-buf)
9247               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9248               (nnheader-replace-header "Xref" new-xref)
9249               (gnus-request-replace-article
9250                article gnus-newsgroup-name (current-buffer))))
9251
9252           ;; run the move/copy/crosspost/respool hook
9253           (run-hook-with-args 'gnus-summary-article-move-hook
9254                               action
9255                               (gnus-data-header
9256                                (assoc article (gnus-data-list nil)))
9257                               gnus-newsgroup-name
9258                               to-newsgroup
9259                               select-method))
9260
9261         ;;;!!!Why is this necessary?
9262         (set-buffer gnus-summary-buffer)
9263         
9264         (gnus-summary-goto-subject article)
9265         (when (eq action 'move)
9266           (gnus-summary-mark-article article gnus-canceled-mark))))
9267       (gnus-summary-remove-process-mark article))
9268     ;; Re-activate all groups that have been moved to.
9269     (save-excursion
9270       (set-buffer gnus-group-buffer)
9271       (let ((gnus-group-marked to-groups))
9272         (gnus-group-get-new-news-this-group nil t)))
9273
9274     (gnus-kill-buffer copy-buf)
9275     (gnus-summary-position-point)
9276     (gnus-set-mode-line 'summary)))
9277
9278 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9279   "Move the current article to a different newsgroup.
9280 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9281 When called interactively, if TO-NEWSGROUP is nil, use the value of
9282 the variable `gnus-move-split-methods' for finding a default target
9283 newsgroup.
9284 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9285 re-spool using this method."
9286   (interactive "P")
9287   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9288
9289 (defun gnus-summary-crosspost-article (&optional n)
9290   "Crosspost the current article to some other group."
9291   (interactive "P")
9292   (gnus-summary-move-article n nil nil 'crosspost))
9293
9294 (defcustom gnus-summary-respool-default-method nil
9295   "Default method type for respooling an article.
9296 If nil, use to the current newsgroup method."
9297   :type 'symbol
9298   :group 'gnus-summary-mail)
9299
9300 (defcustom gnus-summary-display-while-building nil
9301   "If non-nil, show and update the summary buffer as it's being built.
9302 If the value is t, update the buffer after every line is inserted.  If
9303 the value is an integer (N), update the display every N lines."
9304   :group 'gnus-thread
9305   :type '(choice (const :tag "off" nil)
9306                  number
9307                  (const :tag "frequently" t)))
9308
9309 (defun gnus-summary-respool-article (&optional n method)
9310   "Respool the current article.
9311 The article will be squeezed through the mail spooling process again,
9312 which means that it will be put in some mail newsgroup or other
9313 depending on `nnmail-split-methods'.
9314 If N is a positive number, respool the N next articles.
9315 If N is a negative number, respool the N previous articles.
9316 If N is nil and any articles have been marked with the process mark,
9317 respool those articles instead.
9318
9319 Respooling can be done both from mail groups and \"real\" newsgroups.
9320 In the former case, the articles in question will be moved from the
9321 current group into whatever groups they are destined to.  In the
9322 latter case, they will be copied into the relevant groups."
9323   (interactive
9324    (list current-prefix-arg
9325          (let* ((methods (gnus-methods-using 'respool))
9326                 (methname
9327                  (symbol-name (or gnus-summary-respool-default-method
9328                                   (car (gnus-find-method-for-group
9329                                         gnus-newsgroup-name)))))
9330                 (method
9331                  (gnus-completing-read-with-default
9332                   methname "What backend do you want to use when respooling?"
9333                   methods nil t nil 'gnus-mail-method-history))
9334                 ms)
9335            (cond
9336             ((zerop (length (setq ms (gnus-servers-using-backend
9337                                       (intern method)))))
9338              (list (intern method) ""))
9339             ((= 1 (length ms))
9340              (car ms))
9341             (t
9342              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9343                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9344                            ms-alist))))))))
9345   (unless method
9346     (error "No method given for respooling"))
9347   (if (assoc (symbol-name
9348               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9349              (gnus-methods-using 'respool))
9350       (gnus-summary-move-article n nil method)
9351     (gnus-summary-copy-article n nil method)))
9352
9353 (defun gnus-summary-import-article (file &optional edit)
9354   "Import an arbitrary file into a mail newsgroup."
9355   (interactive "fImport file: \nP")
9356   (let ((group gnus-newsgroup-name)
9357         (now (current-time))
9358         atts lines group-art)
9359     (unless (gnus-check-backend-function 'request-accept-article group)
9360       (error "%s does not support article importing" group))
9361     (or (file-readable-p file)
9362         (not (file-regular-p file))
9363         (error "Can't read %s" file))
9364     (save-excursion
9365       (set-buffer (gnus-get-buffer-create " *import file*"))
9366       (erase-buffer)
9367       (nnheader-insert-file-contents file)
9368       (goto-char (point-min))
9369       (if (nnheader-article-p)
9370           (save-restriction
9371             (goto-char (point-min))
9372             (search-forward "\n\n" nil t)
9373             (narrow-to-region (point-min) (1- (point)))
9374             (goto-char (point-min))
9375             (unless (re-search-forward "^date:" nil t)
9376               (goto-char (point-max))
9377               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9378         ;; This doesn't look like an article, so we fudge some headers.
9379         (setq atts (file-attributes file)
9380               lines (count-lines (point-min) (point-max)))
9381         (insert "From: " (read-string "From: ") "\n"
9382                 "Subject: " (read-string "Subject: ") "\n"
9383                 "Date: " (message-make-date (nth 5 atts)) "\n"
9384                 "Message-ID: " (message-make-message-id) "\n"
9385                 "Lines: " (int-to-string lines) "\n"
9386                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9387       (setq group-art (gnus-request-accept-article group nil t))
9388       (kill-buffer (current-buffer)))
9389     (setq gnus-newsgroup-active (gnus-activate-group group))
9390     (forward-line 1)
9391     (gnus-summary-goto-article (cdr group-art) nil t)
9392     (when edit
9393       (gnus-summary-edit-article))))
9394
9395 (defun gnus-summary-create-article ()
9396   "Create an article in a mail newsgroup."
9397   (interactive)
9398   (let ((group gnus-newsgroup-name)
9399         (now (current-time))
9400         group-art)
9401     (unless (gnus-check-backend-function 'request-accept-article group)
9402       (error "%s does not support article importing" group))
9403     (save-excursion
9404       (set-buffer (gnus-get-buffer-create " *import file*"))
9405       (erase-buffer)
9406       (goto-char (point-min))
9407       ;; This doesn't look like an article, so we fudge some headers.
9408       (insert "From: " (read-string "From: ") "\n"
9409               "Subject: " (read-string "Subject: ") "\n"
9410               "Date: " (message-make-date now) "\n"
9411               "Message-ID: " (message-make-message-id) "\n")
9412       (setq group-art (gnus-request-accept-article group nil t))
9413       (kill-buffer (current-buffer)))
9414     (setq gnus-newsgroup-active (gnus-activate-group group))
9415     (forward-line 1)
9416     (gnus-summary-goto-article (cdr group-art) nil t)
9417     (gnus-summary-edit-article)))
9418
9419 (defun gnus-summary-article-posted-p ()
9420   "Say whether the current (mail) article is available from news as well.
9421 This will be the case if the article has both been mailed and posted."
9422   (interactive)
9423   (let ((id (mail-header-references (gnus-summary-article-header)))
9424         (gnus-override-method (car (gnus-refer-article-methods))))
9425     (if (gnus-request-head id "")
9426         (gnus-message 2 "The current message was found on %s"
9427                       gnus-override-method)
9428       (gnus-message 2 "The current message couldn't be found on %s"
9429                     gnus-override-method)
9430       nil)))
9431
9432 (defun gnus-summary-expire-articles (&optional now)
9433   "Expire all articles that are marked as expirable in the current group."
9434   (interactive)
9435   (when (and (not gnus-group-is-exiting-without-update-p)
9436              (gnus-check-backend-function
9437               'request-expire-articles gnus-newsgroup-name))
9438     ;; This backend supports expiry.
9439     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9440            (expirable (if total
9441                           (progn
9442                             ;; We need to update the info for
9443                             ;; this group for `gnus-list-of-read-articles'
9444                             ;; to give us the right answer.
9445                             (gnus-run-hooks 'gnus-exit-group-hook)
9446                             (gnus-summary-update-info)
9447                             (gnus-list-of-read-articles gnus-newsgroup-name))
9448                         (setq gnus-newsgroup-expirable
9449                               (sort gnus-newsgroup-expirable '<))))
9450            (expiry-wait (if now 'immediate
9451                           (gnus-group-find-parameter
9452                            gnus-newsgroup-name 'expiry-wait)))
9453            (nnmail-expiry-target
9454             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9455                 nnmail-expiry-target))
9456            es)
9457       (when expirable
9458         ;; There are expirable articles in this group, so we run them
9459         ;; through the expiry process.
9460         (gnus-message 6 "Expiring articles...")
9461         (unless (gnus-check-group gnus-newsgroup-name)
9462           (error "Can't open server for %s" gnus-newsgroup-name))
9463         ;; The list of articles that weren't expired is returned.
9464         (save-excursion
9465           (if expiry-wait
9466               (let ((nnmail-expiry-wait-function nil)
9467                     (nnmail-expiry-wait expiry-wait))
9468                 (setq es (gnus-request-expire-articles
9469                           expirable gnus-newsgroup-name)))
9470             (setq es (gnus-request-expire-articles
9471                       expirable gnus-newsgroup-name)))
9472           (unless total
9473             (setq gnus-newsgroup-expirable es))
9474           ;; We go through the old list of expirable, and mark all
9475           ;; really expired articles as nonexistent.
9476           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9477             (let ((gnus-use-cache nil))
9478               (dolist (article expirable)
9479                 (when (and (not (memq article es))
9480                            (gnus-data-find article))
9481                   (gnus-summary-mark-article article gnus-canceled-mark)
9482                   (run-hook-with-args 'gnus-summary-article-expire-hook
9483                                       'delete
9484                                       (gnus-data-header
9485                                        (assoc article (gnus-data-list nil)))
9486                                       gnus-newsgroup-name
9487                                       nil
9488                                       nil))))))
9489         (gnus-message 6 "Expiring articles...done")))))
9490
9491 (defun gnus-summary-expire-articles-now ()
9492   "Expunge all expirable articles in the current group.
9493 This means that *all* articles that are marked as expirable will be
9494 deleted forever, right now."
9495   (interactive)
9496   (or gnus-expert-user
9497       (gnus-yes-or-no-p
9498        "Are you really, really, really sure you want to delete all these messages? ")
9499       (error "Phew!"))
9500   (gnus-summary-expire-articles t))
9501
9502 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9503 (defun gnus-summary-delete-article (&optional n)
9504   "Delete the N next (mail) articles.
9505 This command actually deletes articles.  This is not a marking
9506 command.  The article will disappear forever from your life, never to
9507 return.
9508
9509 If N is negative, delete backwards.
9510 If N is nil and articles have been marked with the process mark,
9511 delete these instead.
9512
9513 If `gnus-novice-user' is non-nil you will be asked for
9514 confirmation before the articles are deleted."
9515   (interactive "P")
9516   (unless (gnus-check-backend-function 'request-expire-articles
9517                                        gnus-newsgroup-name)
9518     (error "The current newsgroup does not support article deletion"))
9519   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9520     (error "Couldn't open server"))
9521   ;; Compute the list of articles to delete.
9522   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9523         (nnmail-expiry-target 'delete)
9524         not-deleted)
9525     (if (and gnus-novice-user
9526              (not (gnus-yes-or-no-p
9527                    (format "Do you really want to delete %s forever? "
9528                            (if (> (length articles) 1)
9529                                (format "these %s articles" (length articles))
9530                              "this article")))))
9531         ()
9532       ;; Delete the articles.
9533       (setq not-deleted (gnus-request-expire-articles
9534                          articles gnus-newsgroup-name 'force))
9535       (while articles
9536         (gnus-summary-remove-process-mark (car articles))
9537         ;; The backend might not have been able to delete the article
9538         ;; after all.
9539         (unless (memq (car articles) not-deleted)
9540           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9541         (let* ((article (car articles))
9542                (id (mail-header-id (gnus-data-header
9543                                     (assoc article (gnus-data-list nil))))))
9544           (run-hook-with-args 'gnus-summary-article-delete-hook
9545                               'delete id gnus-newsgroup-name nil
9546                               nil))
9547         (setq articles (cdr articles)))
9548       (when not-deleted
9549         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9550     (gnus-summary-position-point)
9551     (gnus-set-mode-line 'summary)
9552     not-deleted))
9553
9554 (defun gnus-summary-edit-article (&optional force)
9555   "Edit the current article.
9556 This will have permanent effect only in mail groups.
9557 If FORCE is non-nil, allow editing of articles even in read-only
9558 groups."
9559   (interactive "P")
9560   (save-excursion
9561     (set-buffer gnus-summary-buffer)
9562     (let ((mail-parse-charset gnus-newsgroup-charset)
9563           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9564       (gnus-set-global-variables)
9565       (when (and (not force)
9566                  (gnus-group-read-only-p))
9567         (error "The current newsgroup does not support article editing"))
9568       (gnus-summary-show-article t)
9569       (gnus-article-edit-article
9570        'ignore
9571        `(lambda (no-highlight)
9572           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9573                 (message-options message-options)
9574                 (message-options-set-recipient)
9575                 (mail-parse-ignored-charsets
9576                  ',gnus-newsgroup-ignored-charsets))
9577             (gnus-summary-edit-article-done
9578              ,(or (mail-header-references gnus-current-headers) "")
9579              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9580
9581 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9582
9583 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9584                                                  no-highlight)
9585   "Make edits to the current article permanent."
9586   (interactive)
9587   (save-excursion
9588     ;; The buffer restriction contains the entire article if it exists.
9589     (when (article-goto-body)
9590       (let ((lines (count-lines (point) (point-max)))
9591             (length (- (point-max) (point)))
9592             (case-fold-search t)
9593             (body (copy-marker (point))))
9594         (goto-char (point-min))
9595         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9596           (delete-region (match-beginning 1) (match-end 1))
9597           (insert (number-to-string length)))
9598         (goto-char (point-min))
9599         (when (re-search-forward
9600                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9601           (delete-region (match-beginning 1) (match-end 1))
9602           (insert (number-to-string length)))
9603         (goto-char (point-min))
9604         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9605           (delete-region (match-beginning 1) (match-end 1))
9606           (insert (number-to-string lines))))))
9607   ;; Replace the article.
9608   (let ((buf (current-buffer)))
9609     (with-temp-buffer
9610       (insert-buffer-substring buf)
9611
9612       (if (and (not read-only)
9613                (not (gnus-request-replace-article
9614                      (cdr gnus-article-current) (car gnus-article-current)
9615                      (current-buffer) t)))
9616           (error "Couldn't replace article")
9617         ;; Update the summary buffer.
9618         (if (and references
9619                  (equal (message-tokenize-header references " ")
9620                         (message-tokenize-header
9621                          (or (message-fetch-field "references") "") " ")))
9622             ;; We only have to update this line.
9623             (save-excursion
9624               (save-restriction
9625                 (message-narrow-to-head)
9626                 (let ((head (buffer-string))
9627                       header)
9628                   (with-temp-buffer
9629                     (insert (format "211 %d Article retrieved.\n"
9630                                     (cdr gnus-article-current)))
9631                     (insert head)
9632                     (insert ".\n")
9633                     (let ((nntp-server-buffer (current-buffer)))
9634                       (setq header (car (gnus-get-newsgroup-headers
9635                                          nil t))))
9636                     (save-excursion
9637                       (set-buffer gnus-summary-buffer)
9638                       (gnus-data-set-header
9639                        (gnus-data-find (cdr gnus-article-current))
9640                        header)
9641                       (gnus-summary-update-article-line
9642                        (cdr gnus-article-current) header)
9643                       (if (gnus-summary-goto-subject
9644                            (cdr gnus-article-current) nil t)
9645                           (gnus-summary-update-secondary-mark
9646                            (cdr gnus-article-current))))))))
9647           ;; Update threads.
9648           (set-buffer (or buffer gnus-summary-buffer))
9649           (gnus-summary-update-article (cdr gnus-article-current))
9650           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9651               (gnus-summary-update-secondary-mark
9652                (cdr gnus-article-current))))
9653         ;; Prettify the article buffer again.
9654         (unless no-highlight
9655           (save-excursion
9656             (set-buffer gnus-article-buffer)
9657             ;;;!!! Fix this -- article should be rehighlighted.
9658             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9659             (set-buffer gnus-original-article-buffer)
9660             (gnus-request-article
9661              (cdr gnus-article-current)
9662              (car gnus-article-current) (current-buffer))))
9663         ;; Prettify the summary buffer line.
9664         (when (gnus-visual-p 'summary-highlight 'highlight)
9665           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9666
9667 (defun gnus-summary-edit-wash (key)
9668   "Perform editing command KEY in the article buffer."
9669   (interactive
9670    (list
9671     (progn
9672       (message "%s" (concat (this-command-keys) "- "))
9673       (read-char))))
9674   (message "")
9675   (gnus-summary-edit-article)
9676   (execute-kbd-macro (concat (this-command-keys) key))
9677   (gnus-article-edit-done))
9678
9679 ;;; Respooling
9680
9681 (defun gnus-summary-respool-query (&optional silent trace)
9682   "Query where the respool algorithm would put this article."
9683   (interactive)
9684   (let (gnus-mark-article-hook)
9685     (gnus-summary-select-article)
9686     (save-excursion
9687       (set-buffer gnus-original-article-buffer)
9688       (let ((groups (nnmail-article-group 'identity trace)))
9689         (unless silent
9690           (if groups
9691               (message "This message would go to %s"
9692                        (mapconcat 'car groups ", "))
9693             (message "This message would go to no groups"))
9694           groups)))))
9695
9696 (defun gnus-summary-respool-trace ()
9697   "Trace where the respool algorithm would put this article.
9698 Display a buffer showing all fancy splitting patterns which matched."
9699   (interactive)
9700   (gnus-summary-respool-query nil t))
9701
9702 ;; Summary marking commands.
9703
9704 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9705   "Mark articles which has the same subject as read, and then select the next.
9706 If UNMARK is positive, remove any kind of mark.
9707 If UNMARK is negative, tick articles."
9708   (interactive "P")
9709   (when unmark
9710     (setq unmark (prefix-numeric-value unmark)))
9711   (let ((count
9712          (gnus-summary-mark-same-subject
9713           (gnus-summary-article-subject) unmark)))
9714     ;; Select next unread article.  If auto-select-same mode, should
9715     ;; select the first unread article.
9716     (gnus-summary-next-article t (and gnus-auto-select-same
9717                                       (gnus-summary-article-subject)))
9718     (gnus-message 7 "%d article%s marked as %s"
9719                   count (if (= count 1) " is" "s are")
9720                   (if unmark "unread" "read"))))
9721
9722 (defun gnus-summary-kill-same-subject (&optional unmark)
9723   "Mark articles which has the same subject as read.
9724 If UNMARK is positive, remove any kind of mark.
9725 If UNMARK is negative, tick articles."
9726   (interactive "P")
9727   (when unmark
9728     (setq unmark (prefix-numeric-value unmark)))
9729   (let ((count
9730          (gnus-summary-mark-same-subject
9731           (gnus-summary-article-subject) unmark)))
9732     ;; If marked as read, go to next unread subject.
9733     (when (null unmark)
9734       ;; Go to next unread subject.
9735       (gnus-summary-next-subject 1 t))
9736     (gnus-message 7 "%d articles are marked as %s"
9737                   count (if unmark "unread" "read"))))
9738
9739 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9740   "Mark articles with same SUBJECT as read, and return marked number.
9741 If optional argument UNMARK is positive, remove any kinds of marks.
9742 If optional argument UNMARK is negative, mark articles as unread instead."
9743   (let ((count 1))
9744     (save-excursion
9745       (cond
9746        ((null unmark)                   ; Mark as read.
9747         (while (and
9748                 (progn
9749                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9750                   (gnus-summary-show-thread) t)
9751                 (gnus-summary-find-subject subject))
9752           (setq count (1+ count))))
9753        ((> unmark 0)                    ; Tick.
9754         (while (and
9755                 (progn
9756                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9757                   (gnus-summary-show-thread) t)
9758                 (gnus-summary-find-subject subject))
9759           (setq count (1+ count))))
9760        (t                               ; Mark as unread.
9761         (while (and
9762                 (progn
9763                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9764                   (gnus-summary-show-thread) t)
9765                 (gnus-summary-find-subject subject))
9766           (setq count (1+ count)))))
9767       (gnus-set-mode-line 'summary)
9768       ;; Return the number of marked articles.
9769       count)))
9770
9771 (defun gnus-summary-mark-as-processable (n &optional unmark)
9772   "Set the process mark on the next N articles.
9773 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9774 the process mark instead.  The difference between N and the actual
9775 number of articles marked is returned."
9776   (interactive "P")
9777   (if (and (null n) (gnus-region-active-p))
9778       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9779     (setq n (prefix-numeric-value n))
9780     (let ((backward (< n 0))
9781           (n (abs n)))
9782       (while (and
9783               (> n 0)
9784               (if unmark
9785                   (gnus-summary-remove-process-mark
9786                    (gnus-summary-article-number))
9787                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9788               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9789         (setq n (1- n)))
9790       (when (/= 0 n)
9791         (gnus-message 7 "No more articles"))
9792       (gnus-summary-recenter)
9793       (gnus-summary-position-point)
9794       n)))
9795
9796 (defun gnus-summary-unmark-as-processable (n)
9797   "Remove the process mark from the next N articles.
9798 If N is negative, unmark backward instead.  The difference between N and
9799 the actual number of articles unmarked is returned."
9800   (interactive "P")
9801   (gnus-summary-mark-as-processable n t))
9802
9803 (defun gnus-summary-unmark-all-processable ()
9804   "Remove the process mark from all articles."
9805   (interactive)
9806   (save-excursion
9807     (while gnus-newsgroup-processable
9808       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9809   (gnus-summary-position-point))
9810
9811 (defun gnus-summary-add-mark (article type)
9812   "Mark ARTICLE with a mark of TYPE."
9813   (let ((vtype (car (assq type gnus-article-mark-lists)))
9814         var)
9815     (if (not vtype)
9816         (error "No such mark type: %s" type)
9817       (setq var (intern (format "gnus-newsgroup-%s" type)))
9818       (set var (cons article (symbol-value var)))
9819       (if (memq type '(processable cached replied forwarded recent saved))
9820           (gnus-summary-update-secondary-mark article)
9821         ;;; !!! This is bogus.  We should find out what primary
9822         ;;; !!! mark we want to set.
9823         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9824
9825 (defun gnus-summary-mark-as-expirable (n)
9826   "Mark N articles forward as expirable.
9827 If N is negative, mark backward instead.  The difference between N and
9828 the actual number of articles marked is returned."
9829   (interactive "p")
9830   (gnus-summary-mark-forward n gnus-expirable-mark))
9831
9832 (defun gnus-summary-mark-as-spam (n)
9833   "Mark N articles forward as spam.
9834 If N is negative, mark backward instead.  The difference between N and
9835 the actual number of articles marked is returned."
9836   (interactive "p")
9837   (gnus-summary-mark-forward n gnus-spam-mark))
9838
9839 (defun gnus-summary-mark-article-as-replied (article)
9840   "Mark ARTICLE as replied to and update the summary line.
9841 ARTICLE can also be a list of articles."
9842   (interactive (list (gnus-summary-article-number)))
9843   (let ((articles (if (listp article) article (list article))))
9844     (dolist (article articles)
9845       (unless (numberp article)
9846         (error "%s is not a number" article))
9847       (push article gnus-newsgroup-replied)
9848       (let ((buffer-read-only nil))
9849         (when (gnus-summary-goto-subject article nil t)
9850           (gnus-summary-update-secondary-mark article))))))
9851
9852 (defun gnus-summary-mark-article-as-forwarded (article)
9853   "Mark ARTICLE as forwarded and update the summary line.
9854 ARTICLE can also be a list of articles."
9855   (let ((articles (if (listp article) article (list article))))
9856     (dolist (article articles)
9857       (push article gnus-newsgroup-forwarded)
9858       (let ((buffer-read-only nil))
9859         (when (gnus-summary-goto-subject article nil t)
9860           (gnus-summary-update-secondary-mark article))))))
9861
9862 (defun gnus-summary-set-bookmark (article)
9863   "Set a bookmark in current article."
9864   (interactive (list (gnus-summary-article-number)))
9865   (when (or (not (get-buffer gnus-article-buffer))
9866             (not gnus-current-article)
9867             (not gnus-article-current)
9868             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9869     (error "No current article selected"))
9870   ;; Remove old bookmark, if one exists.
9871   (gnus-pull article gnus-newsgroup-bookmarks)
9872   ;; Set the new bookmark, which is on the form
9873   ;; (article-number . line-number-in-body).
9874   (push
9875    (cons article
9876          (with-current-buffer gnus-article-buffer
9877            (count-lines
9878             (min (point)
9879                  (save-excursion
9880                    (article-goto-body)
9881                    (point)))
9882             (point))))
9883    gnus-newsgroup-bookmarks)
9884   (gnus-message 6 "A bookmark has been added to the current article."))
9885
9886 (defun gnus-summary-remove-bookmark (article)
9887   "Remove the bookmark from the current article."
9888   (interactive (list (gnus-summary-article-number)))
9889   ;; Remove old bookmark, if one exists.
9890   (if (not (assq article gnus-newsgroup-bookmarks))
9891       (gnus-message 6 "No bookmark in current article.")
9892     (gnus-pull article gnus-newsgroup-bookmarks)
9893     (gnus-message 6 "Removed bookmark.")))
9894
9895 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9896 (defun gnus-summary-mark-as-dormant (n)
9897   "Mark N articles forward as dormant.
9898 If N is negative, mark backward instead.  The difference between N and
9899 the actual number of articles marked is returned."
9900   (interactive "p")
9901   (gnus-summary-mark-forward n gnus-dormant-mark))
9902
9903 (defun gnus-summary-set-process-mark (article)
9904   "Set the process mark on ARTICLE and update the summary line."
9905   (setq gnus-newsgroup-processable
9906         (cons article
9907               (delq article gnus-newsgroup-processable)))
9908   (when (gnus-summary-goto-subject article)
9909     (gnus-summary-show-thread)
9910     (gnus-summary-goto-subject article)
9911     (gnus-summary-update-secondary-mark article)))
9912
9913 (defun gnus-summary-remove-process-mark (article)
9914   "Remove the process mark from ARTICLE and update the summary line."
9915   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9916   (when (gnus-summary-goto-subject article)
9917     (gnus-summary-show-thread)
9918     (gnus-summary-goto-subject article)
9919     (gnus-summary-update-secondary-mark article)))
9920
9921 (defun gnus-summary-set-saved-mark (article)
9922   "Set the process mark on ARTICLE and update the summary line."
9923   (push article gnus-newsgroup-saved)
9924   (when (gnus-summary-goto-subject article)
9925     (gnus-summary-update-secondary-mark article)))
9926
9927 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9928   "Mark N articles as read forwards.
9929 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9930 The difference between N and the actual number of articles marked is
9931 returned.
9932 If NO-EXPIRE, auto-expiry will be inhibited."
9933   (interactive "p")
9934   (gnus-summary-show-thread)
9935   (let ((backward (< n 0))
9936         (gnus-summary-goto-unread
9937          (and gnus-summary-goto-unread
9938               (not (eq gnus-summary-goto-unread 'never))
9939               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9940                                     gnus-ticked-mark gnus-dormant-mark)))))
9941         (n (abs n))
9942         (mark (or mark gnus-del-mark)))
9943     (while (and (> n 0)
9944                 (gnus-summary-mark-article nil mark no-expire)
9945                 (zerop (gnus-summary-next-subject
9946                         (if backward -1 1)
9947                         (and gnus-summary-goto-unread
9948                              (not (eq gnus-summary-goto-unread 'never)))
9949                         t)))
9950       (setq n (1- n)))
9951     (when (/= 0 n)
9952       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9953     (gnus-summary-recenter)
9954     (gnus-summary-position-point)
9955     (gnus-set-mode-line 'summary)
9956     n))
9957
9958 (defun gnus-summary-mark-article-as-read (mark)
9959   "Mark the current article quickly as read with MARK."
9960   (let ((article (gnus-summary-article-number)))
9961     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9962     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9963     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9964     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9965     (push (cons article mark) gnus-newsgroup-reads)
9966     ;; Possibly remove from cache, if that is used.
9967     (when gnus-use-cache
9968       (gnus-cache-enter-remove-article article))
9969     ;; Allow the backend to change the mark.
9970     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9971     ;; Check for auto-expiry.
9972     (when (and gnus-newsgroup-auto-expire
9973                (memq mark gnus-auto-expirable-marks))
9974       (setq mark gnus-expirable-mark)
9975       ;; Let the backend know about the mark change.
9976       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9977       (push article gnus-newsgroup-expirable))
9978     ;; Set the mark in the buffer.
9979     (gnus-summary-update-mark mark 'unread)
9980     t))
9981
9982 (defun gnus-summary-mark-article-as-unread (mark)
9983   "Mark the current article quickly as unread with MARK."
9984   (let* ((article (gnus-summary-article-number))
9985          (old-mark (gnus-summary-article-mark article)))
9986     ;; Allow the backend to change the mark.
9987     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9988     (if (eq mark old-mark)
9989         t
9990       (if (<= article 0)
9991           (progn
9992             (gnus-error 1 "Can't mark negative article numbers")
9993             nil)
9994         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9995         (setq gnus-newsgroup-spam-marked
9996               (delq article gnus-newsgroup-spam-marked))
9997         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9998         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9999         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10000         (cond ((= mark gnus-ticked-mark)
10001                (setq gnus-newsgroup-marked
10002                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10003                                               article)))
10004               ((= mark gnus-spam-mark)
10005                (setq gnus-newsgroup-spam-marked
10006                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10007                                               article)))
10008               ((= mark gnus-dormant-mark)
10009                (setq gnus-newsgroup-dormant
10010                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10011                                               article)))
10012               (t
10013                (setq gnus-newsgroup-unreads
10014                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10015                                               article))))
10016         (gnus-pull article gnus-newsgroup-reads)
10017
10018         ;; See whether the article is to be put in the cache.
10019         (and gnus-use-cache
10020              (vectorp (gnus-summary-article-header article))
10021              (save-excursion
10022                (gnus-cache-possibly-enter-article
10023                 gnus-newsgroup-name article
10024                 (gnus-summary-article-header article)
10025                 (= mark gnus-ticked-mark)
10026                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10027
10028         ;; Fix the mark.
10029         (gnus-summary-update-mark mark 'unread)
10030         t))))
10031
10032 (defun gnus-summary-mark-article (&optional article mark no-expire)
10033   "Mark ARTICLE with MARK.  MARK can be any character.
10034 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10035 `??' (dormant) and `?E' (expirable).
10036 If MARK is nil, then the default character `?r' is used.
10037 If ARTICLE is nil, then the article on the current line will be
10038 marked.
10039 If NO-EXPIRE, auto-expiry will be inhibited."
10040   ;; The mark might be a string.
10041   (when (stringp mark)
10042     (setq mark (aref mark 0)))
10043   ;; If no mark is given, then we check auto-expiring.
10044   (when (null mark)
10045     (setq mark gnus-del-mark))
10046   (when (and (not no-expire)
10047              gnus-newsgroup-auto-expire
10048              (memq mark gnus-auto-expirable-marks))
10049     (setq mark gnus-expirable-mark))
10050   (let ((article (or article (gnus-summary-article-number)))
10051         (old-mark (gnus-summary-article-mark article)))
10052     ;; Allow the backend to change the mark.
10053     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10054     (if (eq mark old-mark)
10055         t
10056       (unless article
10057         (error "No article on current line"))
10058       (if (not (if (or (= mark gnus-unread-mark)
10059                        (= mark gnus-ticked-mark)
10060                        (= mark gnus-spam-mark)
10061                        (= mark gnus-dormant-mark))
10062                    (gnus-mark-article-as-unread article mark)
10063                  (gnus-mark-article-as-read article mark)))
10064           t
10065         ;; See whether the article is to be put in the cache.
10066         (and gnus-use-cache
10067              (not (= mark gnus-canceled-mark))
10068              (vectorp (gnus-summary-article-header article))
10069              (save-excursion
10070                (gnus-cache-possibly-enter-article
10071                 gnus-newsgroup-name article
10072                 (gnus-summary-article-header article)
10073                 (= mark gnus-ticked-mark)
10074                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10075
10076         (when (gnus-summary-goto-subject article nil t)
10077           (let ((buffer-read-only nil))
10078             (gnus-summary-show-thread)
10079             ;; Fix the mark.
10080             (gnus-summary-update-mark mark 'unread)
10081             t))))))
10082
10083 (defun gnus-summary-update-secondary-mark (article)
10084   "Update the secondary (read, process, cache) mark."
10085   (gnus-summary-update-mark
10086    (cond ((memq article gnus-newsgroup-processable)
10087           gnus-process-mark)
10088          ((memq article gnus-newsgroup-cached)
10089           gnus-cached-mark)
10090          ((memq article gnus-newsgroup-replied)
10091           gnus-replied-mark)
10092          ((memq article gnus-newsgroup-forwarded)
10093           gnus-forwarded-mark)
10094          ((memq article gnus-newsgroup-saved)
10095           gnus-saved-mark)
10096          ((memq article gnus-newsgroup-recent)
10097           gnus-recent-mark)
10098          ((memq article gnus-newsgroup-unseen)
10099           gnus-unseen-mark)
10100          (t gnus-no-mark))
10101    'replied)
10102   (when (gnus-visual-p 'summary-highlight 'highlight)
10103     (gnus-run-hooks 'gnus-summary-update-hook))
10104   t)
10105
10106 (defun gnus-summary-update-download-mark (article)
10107   "Update the download mark."
10108   (gnus-summary-update-mark
10109    (cond ((memq article gnus-newsgroup-undownloaded)
10110           gnus-undownloaded-mark)
10111          (gnus-newsgroup-agentized
10112           gnus-downloaded-mark)
10113          (t
10114           gnus-no-mark))
10115    'download)
10116   (gnus-summary-update-line t)
10117   t)
10118
10119 (defun gnus-summary-update-mark (mark type)
10120   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10121         (buffer-read-only nil))
10122     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10123     (when forward
10124       (when (looking-at "\r")
10125         (incf forward))
10126       (when (<= (+ forward (point)) (point-max))
10127         ;; Go to the right position on the line.
10128         (goto-char (+ forward (point)))
10129         ;; Replace the old mark with the new mark.
10130         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10131         ;; Optionally update the marks by some user rule.
10132         (when (eq type 'unread)
10133           (gnus-data-set-mark
10134            (gnus-data-find (gnus-summary-article-number)) mark)
10135           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10136
10137 (defun gnus-mark-article-as-read (article &optional mark)
10138   "Enter ARTICLE in the pertinent lists and remove it from others."
10139   ;; Make the article expirable.
10140   (let ((mark (or mark gnus-del-mark)))
10141     (setq gnus-newsgroup-expirable
10142           (if (= mark gnus-expirable-mark)
10143               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10144             (delq article gnus-newsgroup-expirable)))
10145     ;; Remove from unread and marked lists.
10146     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10147     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10148     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10149     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10150     (push (cons article mark) gnus-newsgroup-reads)
10151     ;; Possibly remove from cache, if that is used.
10152     (when gnus-use-cache
10153       (gnus-cache-enter-remove-article article))
10154     t))
10155
10156 (defun gnus-mark-article-as-unread (article &optional mark)
10157   "Enter ARTICLE in the pertinent lists and remove it from others."
10158   (let ((mark (or mark gnus-ticked-mark)))
10159     (if (<= article 0)
10160         (progn
10161           (gnus-error 1 "Can't mark negative article numbers")
10162           nil)
10163       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10164             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10165             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10166             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10167             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10168
10169       ;; Unsuppress duplicates?
10170       (when gnus-suppress-duplicates
10171         (gnus-dup-unsuppress-article article))
10172
10173       (cond ((= mark gnus-ticked-mark)
10174              (setq gnus-newsgroup-marked
10175                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10176             ((= mark gnus-spam-mark)
10177              (setq gnus-newsgroup-spam-marked
10178                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10179                                             article)))
10180             ((= mark gnus-dormant-mark)
10181              (setq gnus-newsgroup-dormant
10182                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10183             (t
10184              (setq gnus-newsgroup-unreads
10185                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10186       (gnus-pull article gnus-newsgroup-reads)
10187       t)))
10188
10189 (defalias 'gnus-summary-mark-as-unread-forward
10190   'gnus-summary-tick-article-forward)
10191 (make-obsolete 'gnus-summary-mark-as-unread-forward
10192                'gnus-summary-tick-article-forward)
10193 (defun gnus-summary-tick-article-forward (n)
10194   "Tick N articles forwards.
10195 If N is negative, tick backwards instead.
10196 The difference between N and the number of articles ticked is returned."
10197   (interactive "p")
10198   (gnus-summary-mark-forward n gnus-ticked-mark))
10199
10200 (defalias 'gnus-summary-mark-as-unread-backward
10201   'gnus-summary-tick-article-backward)
10202 (make-obsolete 'gnus-summary-mark-as-unread-backward
10203                'gnus-summary-tick-article-backward)
10204 (defun gnus-summary-tick-article-backward (n)
10205   "Tick N articles backwards.
10206 The difference between N and the number of articles ticked is returned."
10207   (interactive "p")
10208   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10209
10210 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10211 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10212 (defun gnus-summary-tick-article (&optional article clear-mark)
10213   "Mark current article as unread.
10214 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10215 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10216   (interactive)
10217   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10218                                        gnus-ticked-mark)))
10219
10220 (defun gnus-summary-mark-as-read-forward (n)
10221   "Mark N articles as read forwards.
10222 If N is negative, mark backwards instead.
10223 The difference between N and the actual number of articles marked is
10224 returned."
10225   (interactive "p")
10226   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10227
10228 (defun gnus-summary-mark-as-read-backward (n)
10229   "Mark the N articles as read backwards.
10230 The difference between N and the actual number of articles marked is
10231 returned."
10232   (interactive "p")
10233   (gnus-summary-mark-forward
10234    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10235
10236 (defun gnus-summary-mark-as-read (&optional article mark)
10237   "Mark current article as read.
10238 ARTICLE specifies the article to be marked as read.
10239 MARK specifies a string to be inserted at the beginning of the line."
10240   (gnus-summary-mark-article article mark))
10241
10242 (defun gnus-summary-clear-mark-forward (n)
10243   "Clear marks from N articles forward.
10244 If N is negative, clear backward instead.
10245 The difference between N and the number of marks cleared is returned."
10246   (interactive "p")
10247   (gnus-summary-mark-forward n gnus-unread-mark))
10248
10249 (defun gnus-summary-clear-mark-backward (n)
10250   "Clear marks from N articles backward.
10251 The difference between N and the number of marks cleared is returned."
10252   (interactive "p")
10253   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10254
10255 (defun gnus-summary-mark-unread-as-read ()
10256   "Intended to be used by `gnus-summary-mark-article-hook'."
10257   (when (memq gnus-current-article gnus-newsgroup-unreads)
10258     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10259
10260 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10261   "Intended to be used by `gnus-summary-mark-article-hook'."
10262   (let ((mark (gnus-summary-article-mark)))
10263     (when (or (gnus-unread-mark-p mark)
10264               (gnus-read-mark-p mark))
10265       (gnus-summary-mark-article gnus-current-article
10266                                  (or new-mark gnus-read-mark)))))
10267
10268 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10269   "Intended to be used by `gnus-summary-mark-article-hook'."
10270   (let ((mark (gnus-summary-article-mark)))
10271     (when (or (gnus-unread-mark-p mark)
10272               (gnus-read-mark-p mark))
10273       (gnus-summary-mark-article (gnus-summary-article-number)
10274                                  (or new-mark gnus-read-mark)))))
10275
10276 (defun gnus-summary-mark-unread-as-ticked ()
10277   "Intended to be used by `gnus-summary-mark-article-hook'."
10278   (when (memq gnus-current-article gnus-newsgroup-unreads)
10279     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10280
10281 (defun gnus-summary-mark-region-as-read (point mark all)
10282   "Mark all unread articles between point and mark as read.
10283 If given a prefix, mark all articles between point and mark as read,
10284 even ticked and dormant ones."
10285   (interactive "r\nP")
10286   (save-excursion
10287     (let (article)
10288       (goto-char point)
10289       (beginning-of-line)
10290       (while (and
10291               (< (point) mark)
10292               (progn
10293                 (when (or all
10294                           (memq (setq article (gnus-summary-article-number))
10295                                 gnus-newsgroup-unreads))
10296                   (gnus-summary-mark-article article gnus-del-mark))
10297                 t)
10298               (gnus-summary-find-next))))))
10299
10300 (defun gnus-summary-mark-below (score mark)
10301   "Mark articles with score less than SCORE with MARK."
10302   (interactive "P\ncMark: ")
10303   (setq score (if score
10304                   (prefix-numeric-value score)
10305                 (or gnus-summary-default-score 0)))
10306   (save-excursion
10307     (set-buffer gnus-summary-buffer)
10308     (goto-char (point-min))
10309     (while
10310         (progn
10311           (and (< (gnus-summary-article-score) score)
10312                (gnus-summary-mark-article nil mark))
10313           (gnus-summary-find-next)))))
10314
10315 (defun gnus-summary-kill-below (&optional score)
10316   "Mark articles with score below SCORE as read."
10317   (interactive "P")
10318   (gnus-summary-mark-below score gnus-killed-mark))
10319
10320 (defun gnus-summary-clear-above (&optional score)
10321   "Clear all marks from articles with score above SCORE."
10322   (interactive "P")
10323   (gnus-summary-mark-above score gnus-unread-mark))
10324
10325 (defun gnus-summary-tick-above (&optional score)
10326   "Tick all articles with score above SCORE."
10327   (interactive "P")
10328   (gnus-summary-mark-above score gnus-ticked-mark))
10329
10330 (defun gnus-summary-mark-above (score mark)
10331   "Mark articles with score over SCORE with MARK."
10332   (interactive "P\ncMark: ")
10333   (setq score (if score
10334                   (prefix-numeric-value score)
10335                 (or gnus-summary-default-score 0)))
10336   (save-excursion
10337     (set-buffer gnus-summary-buffer)
10338     (goto-char (point-min))
10339     (while (and (progn
10340                   (when (> (gnus-summary-article-score) score)
10341                     (gnus-summary-mark-article nil mark))
10342                   t)
10343                 (gnus-summary-find-next)))))
10344
10345 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10346 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10347 (defun gnus-summary-limit-include-expunged (&optional no-error)
10348   "Display all the hidden articles that were expunged for low scores."
10349   (interactive)
10350   (let ((buffer-read-only nil))
10351     (let ((scored gnus-newsgroup-scored)
10352           headers h)
10353       (while scored
10354         (unless (gnus-summary-article-header (caar scored))
10355           (and (setq h (gnus-number-to-header (caar scored)))
10356                (< (cdar scored) gnus-summary-expunge-below)
10357                (push h headers)))
10358         (setq scored (cdr scored)))
10359       (if (not headers)
10360           (when (not no-error)
10361             (error "No expunged articles hidden"))
10362         (goto-char (point-min))
10363         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10364         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10365         (mapcar (lambda (x) (push (mail-header-number x)
10366                                   gnus-newsgroup-limit))
10367                 headers)
10368         (gnus-summary-prepare-unthreaded (nreverse headers))
10369         (goto-char (point-min))
10370         (gnus-summary-position-point)
10371         t))))
10372
10373 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10374   "Mark all unread articles in this newsgroup as read.
10375 If prefix argument ALL is non-nil, ticked and dormant articles will
10376 also be marked as read.
10377 If QUIETLY is non-nil, no questions will be asked.
10378
10379 If TO-HERE is non-nil, it should be a point in the buffer.  All
10380 articles before (after, if REVERSE is set) this point will be marked
10381 as read.
10382
10383 Note that this function will only catch up the unread article
10384 in the current summary buffer limitation.
10385
10386 The number of articles marked as read is returned."
10387   (interactive "P")
10388   (prog1
10389       (save-excursion
10390         (when (or quietly
10391                   (not gnus-interactive-catchup) ;Without confirmation?
10392                   gnus-expert-user
10393                   (gnus-y-or-n-p
10394                    (if all
10395                        "Mark absolutely all articles as read? "
10396                      "Mark all unread articles as read? ")))
10397           (if (and not-mark
10398                    (not gnus-newsgroup-adaptive)
10399                    (not gnus-newsgroup-auto-expire)
10400                    (not gnus-suppress-duplicates)
10401                    (or (not gnus-use-cache)
10402                        (eq gnus-use-cache 'passive)))
10403               (progn
10404                 (when all
10405                   (setq gnus-newsgroup-marked nil
10406                         gnus-newsgroup-spam-marked nil
10407                         gnus-newsgroup-dormant nil))
10408                 (setq gnus-newsgroup-unreads
10409                       (gnus-sorted-nunion
10410                        (gnus-intersection gnus-newsgroup-unreads
10411                                           gnus-newsgroup-downloadable)
10412                        gnus-newsgroup-unfetched)))
10413             ;; We actually mark all articles as canceled, which we
10414             ;; have to do when using auto-expiry or adaptive scoring.
10415             (gnus-summary-show-all-threads)
10416             (if (and to-here reverse)
10417                 (progn
10418                   (goto-char to-here)
10419                   (gnus-summary-mark-current-read-and-unread-as-read
10420                    gnus-catchup-mark)
10421                   (while (gnus-summary-find-next (not all))
10422                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10423               (when (gnus-summary-first-subject (not all))
10424                 (while (and
10425                         (if to-here (< (point) to-here) t)
10426                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10427                         (gnus-summary-find-next (not all))))))
10428             (gnus-set-mode-line 'summary))
10429           t))
10430     (gnus-summary-position-point)))
10431
10432 (defun gnus-summary-catchup-to-here (&optional all)
10433   "Mark all unticked articles before the current one as read.
10434 If ALL is non-nil, also mark ticked and dormant articles as read."
10435   (interactive "P")
10436   (save-excursion
10437     (gnus-save-hidden-threads
10438       (let ((beg (point)))
10439         ;; We check that there are unread articles.
10440         (when (or all (gnus-summary-find-prev))
10441           (gnus-summary-catchup all t beg)))))
10442   (gnus-summary-position-point))
10443
10444 (defun gnus-summary-catchup-from-here (&optional all)
10445   "Mark all unticked articles after (and including) the current one as read.
10446 If ALL is non-nil, also mark ticked and dormant articles as read."
10447   (interactive "P")
10448   (save-excursion
10449     (gnus-save-hidden-threads
10450       (let ((beg (point)))
10451         ;; We check that there are unread articles.
10452         (when (or all (gnus-summary-find-next))
10453           (gnus-summary-catchup all t beg nil t)))))
10454   (gnus-summary-position-point))
10455
10456 (defun gnus-summary-catchup-all (&optional quietly)
10457   "Mark all articles in this newsgroup as read.
10458 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10459 instead, which marks only unread articles as read."
10460   (interactive "P")
10461   (gnus-summary-catchup t quietly))
10462
10463 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10464   "Mark all unread articles in this group as read, then exit.
10465 If prefix argument ALL is non-nil, all articles are marked as read.
10466 If QUIETLY is non-nil, no questions will be asked."
10467   (interactive "P")
10468   (when (gnus-summary-catchup all quietly nil 'fast)
10469     ;; Select next newsgroup or exit.
10470     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10471              (eq gnus-auto-select-next 'quietly))
10472         (gnus-summary-next-group nil)
10473       (gnus-summary-exit))))
10474
10475 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10476   "Mark all articles in this newsgroup as read, and then exit.
10477 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10478 instead, which marks only unread articles as read."
10479   (interactive "P")
10480   (gnus-summary-catchup-and-exit t quietly))
10481
10482 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10483   "Mark all articles in this group as read and select the next group.
10484 If given a prefix, mark all articles, unread as well as ticked, as
10485 read."
10486   (interactive "P")
10487   (save-excursion
10488     (gnus-summary-catchup all))
10489   (gnus-summary-next-group))
10490
10491 ;;;
10492 ;;; with article
10493 ;;;
10494
10495 (defmacro gnus-with-article (article &rest forms)
10496   "Select ARTICLE and perform FORMS in the original article buffer.
10497 Then replace the article with the result."
10498   `(progn
10499      ;; We don't want the article to be marked as read.
10500      (let (gnus-mark-article-hook)
10501        (gnus-summary-select-article t t nil ,article))
10502      (set-buffer gnus-original-article-buffer)
10503      ,@forms
10504      (if (not (gnus-check-backend-function
10505                'request-replace-article (car gnus-article-current)))
10506          (gnus-message 5 "Read-only group; not replacing")
10507        (unless (gnus-request-replace-article
10508                 ,article (car gnus-article-current)
10509                 (current-buffer) t)
10510          (error "Couldn't replace article")))
10511      ;; The cache and backlog have to be flushed somewhat.
10512      (when gnus-keep-backlog
10513        (gnus-backlog-remove-article
10514         (car gnus-article-current) (cdr gnus-article-current)))
10515      (when gnus-use-cache
10516        (gnus-cache-update-article
10517         (car gnus-article-current) (cdr gnus-article-current)))))
10518
10519 (put 'gnus-with-article 'lisp-indent-function 1)
10520 (put 'gnus-with-article 'edebug-form-spec '(form body))
10521
10522 ;; Thread-based commands.
10523
10524 (defun gnus-summary-articles-in-thread (&optional article)
10525   "Return a list of all articles in the current thread.
10526 If ARTICLE is non-nil, return all articles in the thread that starts
10527 with that article."
10528   (let* ((article (or article (gnus-summary-article-number)))
10529          (data (gnus-data-find-list article))
10530          (top-level (gnus-data-level (car data)))
10531          (top-subject
10532           (cond ((null gnus-thread-operation-ignore-subject)
10533                  (gnus-simplify-subject-re
10534                   (mail-header-subject (gnus-data-header (car data)))))
10535                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10536                  (gnus-simplify-subject-fuzzy
10537                   (mail-header-subject (gnus-data-header (car data)))))
10538                 (t nil)))
10539          (end-point (save-excursion
10540                       (if (gnus-summary-go-to-next-thread)
10541                           (point) (point-max))))
10542          articles)
10543     (while (and data
10544                 (< (gnus-data-pos (car data)) end-point))
10545       (when (or (not top-subject)
10546                 (string= top-subject
10547                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10548                              (gnus-simplify-subject-fuzzy
10549                               (mail-header-subject
10550                                (gnus-data-header (car data))))
10551                            (gnus-simplify-subject-re
10552                             (mail-header-subject
10553                              (gnus-data-header (car data)))))))
10554         (push (gnus-data-number (car data)) articles))
10555       (unless (and (setq data (cdr data))
10556                    (> (gnus-data-level (car data)) top-level))
10557         (setq data nil)))
10558     ;; Return the list of articles.
10559     (nreverse articles)))
10560
10561 (defun gnus-summary-rethread-current ()
10562   "Rethread the thread the current article is part of."
10563   (interactive)
10564   (let* ((gnus-show-threads t)
10565          (article (gnus-summary-article-number))
10566          (id (mail-header-id (gnus-summary-article-header)))
10567          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10568     (unless id
10569       (error "No article on the current line"))
10570     (gnus-rebuild-thread id)
10571     (gnus-summary-goto-subject article)))
10572
10573 (defun gnus-summary-reparent-thread ()
10574   "Make the current article child of the marked (or previous) article.
10575
10576 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10577 is non-nil or the Subject: of both articles are the same."
10578   (interactive)
10579   (unless (not (gnus-group-read-only-p))
10580     (error "The current newsgroup does not support article editing"))
10581   (unless (<= (length gnus-newsgroup-processable) 1)
10582     (error "No more than one article may be marked"))
10583   (save-window-excursion
10584     (let ((gnus-article-buffer " *reparent*")
10585           (current-article (gnus-summary-article-number))
10586           ;; First grab the marked article, otherwise one line up.
10587           (parent-article (if (not (null gnus-newsgroup-processable))
10588                               (car gnus-newsgroup-processable)
10589                             (save-excursion
10590                               (if (eq (forward-line -1) 0)
10591                                   (gnus-summary-article-number)
10592                                 (error "Beginning of summary buffer"))))))
10593       (unless (not (eq current-article parent-article))
10594         (error "An article may not be self-referential"))
10595       (let ((message-id (mail-header-id
10596                          (gnus-summary-article-header parent-article))))
10597         (unless (and message-id (not (equal message-id "")))
10598           (error "No message-id in desired parent"))
10599         (gnus-with-article current-article
10600           (save-restriction
10601             (goto-char (point-min))
10602             (message-narrow-to-head)
10603             (if (re-search-forward "^References: " nil t)
10604                 (progn
10605                   (re-search-forward "^[^ \t]" nil t)
10606                   (forward-line -1)
10607                   (end-of-line)
10608                   (insert " " message-id))
10609               (insert "References: " message-id "\n"))))
10610         (set-buffer gnus-summary-buffer)
10611         (gnus-summary-unmark-all-processable)
10612         (gnus-summary-update-article current-article)
10613         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10614             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10615         (gnus-summary-rethread-current)
10616         (gnus-message 3 "Article %d is now the child of article %d"
10617                       current-article parent-article)))))
10618
10619 (defun gnus-summary-toggle-threads (&optional arg)
10620   "Toggle showing conversation threads.
10621 If ARG is positive number, turn showing conversation threads on."
10622   (interactive "P")
10623   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10624     (setq gnus-show-threads
10625           (if (null arg) (not gnus-show-threads)
10626             (> (prefix-numeric-value arg) 0)))
10627     (gnus-summary-prepare)
10628     (gnus-summary-goto-subject current)
10629     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10630     (gnus-summary-position-point)))
10631
10632 (defun gnus-summary-show-all-threads ()
10633   "Show all threads."
10634   (interactive)
10635   (save-excursion
10636     (let ((buffer-read-only nil))
10637       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10638   (gnus-summary-position-point))
10639
10640 (defun gnus-summary-show-thread ()
10641   "Show thread subtrees.
10642 Returns nil if no thread was there to be shown."
10643   (interactive)
10644   (let ((buffer-read-only nil)
10645         (orig (point))
10646         (end (point-at-eol))
10647         ;; Leave point at bol
10648         (beg (progn (beginning-of-line) (point))))
10649     (prog1
10650         ;; Any hidden lines here?
10651         (search-forward "\r" end t)
10652       (subst-char-in-region beg end ?\^M ?\n t)
10653       (goto-char orig)
10654       (gnus-summary-position-point))))
10655
10656 (defun gnus-summary-maybe-hide-threads ()
10657   "If requested, hide the threads that should be hidden."
10658   (when (and gnus-show-threads
10659              gnus-thread-hide-subtree)
10660     (gnus-summary-hide-all-threads
10661      (if (or (consp gnus-thread-hide-subtree)
10662              (functionp gnus-thread-hide-subtree))
10663          (gnus-make-predicate gnus-thread-hide-subtree)
10664        nil))))
10665
10666 ;;; Hiding predicates.
10667
10668 (defun gnus-article-unread-p (header)
10669   (memq (mail-header-number header) gnus-newsgroup-unreads))
10670
10671 (defun gnus-article-unseen-p (header)
10672   (memq (mail-header-number header) gnus-newsgroup-unseen))
10673
10674 (defun gnus-map-articles (predicate articles)
10675   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10676   (apply 'gnus-or (mapcar predicate
10677                           (mapcar 'gnus-summary-article-header articles))))
10678
10679 (defun gnus-summary-hide-all-threads (&optional predicate)
10680   "Hide all thread subtrees.
10681 If PREDICATE is supplied, threads that satisfy this predicate
10682 will not be hidden."
10683   (interactive)
10684   (save-excursion
10685     (goto-char (point-min))
10686     (let ((end nil))
10687       (while (not end)
10688         (when (or (not predicate)
10689                   (gnus-map-articles
10690                    predicate (gnus-summary-article-children)))
10691             (gnus-summary-hide-thread))
10692         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10693   (gnus-summary-position-point))
10694
10695 (defun gnus-summary-hide-thread ()
10696   "Hide thread subtrees.
10697 If PREDICATE is supplied, threads that satisfy this predicate
10698 will not be hidden.
10699 Returns nil if no threads were there to be hidden."
10700   (interactive)
10701   (let ((buffer-read-only nil)
10702         (start (point))
10703         (article (gnus-summary-article-number)))
10704     (goto-char start)
10705     ;; Go forward until either the buffer ends or the subthread
10706     ;; ends.
10707     (when (and (not (eobp))
10708                (or (zerop (gnus-summary-next-thread 1 t))
10709                    (goto-char (point-max))))
10710       (prog1
10711           (if (and (> (point) start)
10712                    (search-backward "\n" start t))
10713               (progn
10714                 (subst-char-in-region start (point) ?\n ?\^M)
10715                 (gnus-summary-goto-subject article))
10716             (goto-char start)
10717             nil)))))
10718
10719 (defun gnus-summary-go-to-next-thread (&optional previous)
10720   "Go to the same level (or less) next thread.
10721 If PREVIOUS is non-nil, go to previous thread instead.
10722 Return the article number moved to, or nil if moving was impossible."
10723   (let ((level (gnus-summary-thread-level))
10724         (way (if previous -1 1))
10725         (beg (point)))
10726     (forward-line way)
10727     (while (and (not (eobp))
10728                 (< level (gnus-summary-thread-level)))
10729       (forward-line way))
10730     (if (eobp)
10731         (progn
10732           (goto-char beg)
10733           nil)
10734       (setq beg (point))
10735       (prog1
10736           (gnus-summary-article-number)
10737         (goto-char beg)))))
10738
10739 (defun gnus-summary-next-thread (n &optional silent)
10740   "Go to the same level next N'th thread.
10741 If N is negative, search backward instead.
10742 Returns the difference between N and the number of skips actually
10743 done.
10744
10745 If SILENT, don't output messages."
10746   (interactive "p")
10747   (let ((backward (< n 0))
10748         (n (abs n)))
10749     (while (and (> n 0)
10750                 (gnus-summary-go-to-next-thread backward))
10751       (decf n))
10752     (unless silent
10753       (gnus-summary-position-point))
10754     (when (and (not silent) (/= 0 n))
10755       (gnus-message 7 "No more threads"))
10756     n))
10757
10758 (defun gnus-summary-prev-thread (n)
10759   "Go to the same level previous N'th thread.
10760 Returns the difference between N and the number of skips actually
10761 done."
10762   (interactive "p")
10763   (gnus-summary-next-thread (- n)))
10764
10765 (defun gnus-summary-go-down-thread ()
10766   "Go down one level in the current thread."
10767   (let ((children (gnus-summary-article-children)))
10768     (when children
10769       (gnus-summary-goto-subject (car children)))))
10770
10771 (defun gnus-summary-go-up-thread ()
10772   "Go up one level in the current thread."
10773   (let ((parent (gnus-summary-article-parent)))
10774     (when parent
10775       (gnus-summary-goto-subject parent))))
10776
10777 (defun gnus-summary-down-thread (n)
10778   "Go down thread N steps.
10779 If N is negative, go up instead.
10780 Returns the difference between N and how many steps down that were
10781 taken."
10782   (interactive "p")
10783   (let ((up (< n 0))
10784         (n (abs n)))
10785     (while (and (> n 0)
10786                 (if up (gnus-summary-go-up-thread)
10787                   (gnus-summary-go-down-thread)))
10788       (setq n (1- n)))
10789     (gnus-summary-position-point)
10790     (when (/= 0 n)
10791       (gnus-message 7 "Can't go further"))
10792     n))
10793
10794 (defun gnus-summary-up-thread (n)
10795   "Go up thread N steps.
10796 If N is negative, go down instead.
10797 Returns the difference between N and how many steps down that were
10798 taken."
10799   (interactive "p")
10800   (gnus-summary-down-thread (- n)))
10801
10802 (defun gnus-summary-top-thread ()
10803   "Go to the top of the thread."
10804   (interactive)
10805   (while (gnus-summary-go-up-thread))
10806   (gnus-summary-article-number))
10807
10808 (defun gnus-summary-kill-thread (&optional unmark)
10809   "Mark articles under current thread as read.
10810 If the prefix argument is positive, remove any kinds of marks.
10811 If the prefix argument is negative, tick articles instead."
10812   (interactive "P")
10813   (when unmark
10814     (setq unmark (prefix-numeric-value unmark)))
10815   (let ((articles (gnus-summary-articles-in-thread)))
10816     (save-excursion
10817       ;; Expand the thread.
10818       (gnus-summary-show-thread)
10819       ;; Mark all the articles.
10820       (while articles
10821         (gnus-summary-goto-subject (car articles))
10822         (cond ((null unmark)
10823                (gnus-summary-mark-article-as-read gnus-killed-mark))
10824               ((> unmark 0)
10825                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10826               (t
10827                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10828         (setq articles (cdr articles))))
10829     ;; Hide killed subtrees.
10830     (and (null unmark)
10831          gnus-thread-hide-killed
10832          (gnus-summary-hide-thread))
10833     ;; If marked as read, go to next unread subject.
10834     (when (null unmark)
10835       ;; Go to next unread subject.
10836       (gnus-summary-next-subject 1 t)))
10837   (gnus-set-mode-line 'summary))
10838
10839 ;; Summary sorting commands
10840
10841 (defun gnus-summary-sort-by-number (&optional reverse)
10842   "Sort the summary buffer by article number.
10843 Argument REVERSE means reverse order."
10844   (interactive "P")
10845   (gnus-summary-sort 'number reverse))
10846
10847 (defun gnus-summary-sort-by-random (&optional reverse)
10848   "Randomize the order in the summary buffer.
10849 Argument REVERSE means to randomize in reverse order."
10850   (interactive "P")
10851   (gnus-summary-sort 'random reverse))
10852
10853 (defun gnus-summary-sort-by-author (&optional reverse)
10854   "Sort the summary buffer by author name alphabetically.
10855 If `case-fold-search' is non-nil, case of letters is ignored.
10856 Argument REVERSE means reverse order."
10857   (interactive "P")
10858   (gnus-summary-sort 'author reverse))
10859
10860 (defun gnus-summary-sort-by-subject (&optional reverse)
10861   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10862 If `case-fold-search' is non-nil, case of letters is ignored.
10863 Argument REVERSE means reverse order."
10864   (interactive "P")
10865   (gnus-summary-sort 'subject reverse))
10866
10867 (defun gnus-summary-sort-by-date (&optional reverse)
10868   "Sort the summary buffer by date.
10869 Argument REVERSE means reverse order."
10870   (interactive "P")
10871   (gnus-summary-sort 'date reverse))
10872
10873 (defun gnus-summary-sort-by-score (&optional reverse)
10874   "Sort the summary buffer by score.
10875 Argument REVERSE means reverse order."
10876   (interactive "P")
10877   (gnus-summary-sort 'score reverse))
10878
10879 (defun gnus-summary-sort-by-lines (&optional reverse)
10880   "Sort the summary buffer by the number of lines.
10881 Argument REVERSE means reverse order."
10882   (interactive "P")
10883   (gnus-summary-sort 'lines reverse))
10884
10885 (defun gnus-summary-sort-by-chars (&optional reverse)
10886   "Sort the summary buffer by article length.
10887 Argument REVERSE means reverse order."
10888   (interactive "P")
10889   (gnus-summary-sort 'chars reverse))
10890
10891 (defun gnus-summary-sort-by-original (&optional reverse)
10892   "Sort the summary buffer using the default sorting method.
10893 Argument REVERSE means reverse order."
10894   (interactive "P")
10895   (let* ((buffer-read-only)
10896          (gnus-summary-prepare-hook nil))
10897     ;; We do the sorting by regenerating the threads.
10898     (gnus-summary-prepare)
10899     ;; Hide subthreads if needed.
10900     (gnus-summary-maybe-hide-threads)))
10901
10902 (defun gnus-summary-sort (predicate reverse)
10903   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10904   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10905          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10906          (gnus-thread-sort-functions
10907           (if (not reverse)
10908               thread
10909             `(lambda (t1 t2)
10910                (,thread t2 t1))))
10911          (gnus-sort-gathered-threads-function
10912           gnus-thread-sort-functions)
10913          (gnus-article-sort-functions
10914           (if (not reverse)
10915               article
10916             `(lambda (t1 t2)
10917                (,article t2 t1))))
10918          (buffer-read-only)
10919          (gnus-summary-prepare-hook nil))
10920     ;; We do the sorting by regenerating the threads.
10921     (gnus-summary-prepare)
10922     ;; Hide subthreads if needed.
10923     (gnus-summary-maybe-hide-threads)))
10924
10925 ;; Summary saving commands.
10926
10927 (defun gnus-summary-save-article (&optional n not-saved)
10928   "Save the current article using the default saver function.
10929 If N is a positive number, save the N next articles.
10930 If N is a negative number, save the N previous articles.
10931 If N is nil and any articles have been marked with the process mark,
10932 save those articles instead.
10933 The variable `gnus-default-article-saver' specifies the saver function."
10934   (interactive "P")
10935   (let* ((articles (gnus-summary-work-articles n))
10936          (save-buffer (save-excursion
10937                         (nnheader-set-temp-buffer " *Gnus Save*")))
10938          (num (length articles))
10939          header file)
10940     (dolist (article articles)
10941       (setq header (gnus-summary-article-header article))
10942       (if (not (vectorp header))
10943           ;; This is a pseudo-article.
10944           (if (assq 'name header)
10945               (gnus-copy-file (cdr (assq 'name header)))
10946             (gnus-message 1 "Article %d is unsaveable" article))
10947         ;; This is a real article.
10948         (save-window-excursion
10949           (let ((gnus-display-mime-function nil)
10950                 (gnus-article-prepare-hook nil))
10951             (gnus-summary-select-article t nil nil article)))
10952         (save-excursion
10953           (set-buffer save-buffer)
10954           (erase-buffer)
10955           (insert-buffer-substring gnus-original-article-buffer))
10956         (setq file (gnus-article-save save-buffer file num))
10957         (gnus-summary-remove-process-mark article)
10958         (unless not-saved
10959           (gnus-summary-set-saved-mark article))))
10960     (gnus-kill-buffer save-buffer)
10961     (gnus-summary-position-point)
10962     (gnus-set-mode-line 'summary)
10963     n))
10964
10965 (defun gnus-summary-pipe-output (&optional arg headers)
10966   "Pipe the current article to a subprocess.
10967 If N is a positive number, pipe the N next articles.
10968 If N is a negative number, pipe the N previous articles.
10969 If N is nil and any articles have been marked with the process mark,
10970 pipe those articles instead.
10971 If HEADERS (the symbolic prefix), include the headers, too."
10972   (interactive (gnus-interactive "P\ny"))
10973   (require 'gnus-art)
10974   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10975         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10976     (gnus-summary-save-article arg t))
10977   (let ((buffer (get-buffer "*Shell Command Output*")))
10978     (when (and buffer
10979                (not (zerop (buffer-size buffer))))
10980       (gnus-configure-windows 'pipe))))
10981
10982 (defun gnus-summary-save-article-mail (&optional arg)
10983   "Append the current article to an mail file.
10984 If N is a positive number, save the N next articles.
10985 If N is a negative number, save the N previous articles.
10986 If N is nil and any articles have been marked with the process mark,
10987 save those articles instead."
10988   (interactive "P")
10989   (require 'gnus-art)
10990   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10991     (gnus-summary-save-article arg)))
10992
10993 (defun gnus-summary-save-article-rmail (&optional arg)
10994   "Append the current article to an rmail file.
10995 If N is a positive number, save the N next articles.
10996 If N is a negative number, save the N previous articles.
10997 If N is nil and any articles have been marked with the process mark,
10998 save those articles instead."
10999   (interactive "P")
11000   (require 'gnus-art)
11001   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11002     (gnus-summary-save-article arg)))
11003
11004 (defun gnus-summary-save-article-file (&optional arg)
11005   "Append the current article to a file.
11006 If N is a positive number, save the N next articles.
11007 If N is a negative number, save the N previous articles.
11008 If N is nil and any articles have been marked with the process mark,
11009 save those articles instead."
11010   (interactive "P")
11011   (require 'gnus-art)
11012   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11013     (gnus-summary-save-article arg)))
11014
11015 (defun gnus-summary-write-article-file (&optional arg)
11016   "Write the current article to a file, deleting the previous file.
11017 If N is a positive number, save the N next articles.
11018 If N is a negative number, save the N previous articles.
11019 If N is nil and any articles have been marked with the process mark,
11020 save those articles instead."
11021   (interactive "P")
11022   (require 'gnus-art)
11023   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11024     (gnus-summary-save-article arg)))
11025
11026 (defun gnus-summary-save-article-body-file (&optional arg)
11027   "Append the current article body to a file.
11028 If N is a positive number, save the N next articles.
11029 If N is a negative number, save the N previous articles.
11030 If N is nil and any articles have been marked with the process mark,
11031 save those articles instead."
11032   (interactive "P")
11033   (require 'gnus-art)
11034   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11035     (gnus-summary-save-article arg)))
11036
11037 (defun gnus-summary-muttprint (&optional arg)
11038   "Print the current article using Muttprint.
11039 If N is a positive number, save the N next articles.
11040 If N is a negative number, save the N previous articles.
11041 If N is nil and any articles have been marked with the process mark,
11042 save those articles instead."
11043   (interactive "P")
11044   (require 'gnus-art)
11045   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11046     (gnus-summary-save-article arg t)))
11047
11048 (defun gnus-summary-pipe-message (program)
11049   "Pipe the current article through PROGRAM."
11050   (interactive "sProgram: ")
11051   (gnus-summary-select-article)
11052   (let ((mail-header-separator ""))
11053     (gnus-eval-in-buffer-window gnus-article-buffer
11054       (save-restriction
11055         (widen)
11056         (let ((start (window-start))
11057               buffer-read-only)
11058           (message-pipe-buffer-body program)
11059           (set-window-start (get-buffer-window (current-buffer)) start))))))
11060
11061 (defun gnus-get-split-value (methods)
11062   "Return a value based on the split METHODS."
11063   (let (split-name method result match)
11064     (when methods
11065       (save-excursion
11066         (set-buffer gnus-original-article-buffer)
11067         (save-restriction
11068           (nnheader-narrow-to-headers)
11069           (while (and methods (not split-name))
11070             (goto-char (point-min))
11071             (setq method (pop methods))
11072             (setq match (car method))
11073             (when (cond
11074                    ((stringp match)
11075                     ;; Regular expression.
11076                     (ignore-errors
11077                       (re-search-forward match nil t)))
11078                    ((functionp match)
11079                     ;; Function.
11080                     (save-restriction
11081                       (widen)
11082                       (setq result (funcall match gnus-newsgroup-name))))
11083                    ((consp match)
11084                     ;; Form.
11085                     (save-restriction
11086                       (widen)
11087                       (setq result (eval match)))))
11088               (setq split-name (cdr method))
11089               (cond ((stringp result)
11090                      (push (expand-file-name
11091                             result gnus-article-save-directory)
11092                            split-name))
11093                     ((consp result)
11094                      (setq split-name (append result split-name)))))))))
11095     (nreverse split-name)))
11096
11097 (defun gnus-valid-move-group-p (group)
11098   (and (boundp group)
11099        (symbol-name group)
11100        (symbol-value group)
11101        (gnus-get-function (gnus-find-method-for-group
11102                            (symbol-name group)) 'request-accept-article t)))
11103
11104 (defun gnus-read-move-group-name (prompt default articles prefix)
11105   "Read a group name."
11106   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11107          (minibuffer-confirm-incomplete nil) ; XEmacs
11108          (prom
11109           (format "%s %s to:"
11110                   prompt
11111                   (if (> (length articles) 1)
11112                       (format "these %d articles" (length articles))
11113                     "this article")))
11114          (to-newsgroup
11115           (cond
11116            ((null split-name)
11117             (gnus-completing-read-with-default
11118              default prom
11119              gnus-active-hashtb
11120              'gnus-valid-move-group-p
11121              nil prefix
11122              'gnus-group-history))
11123            ((= 1 (length split-name))
11124             (gnus-completing-read-with-default
11125              (car split-name) prom
11126              gnus-active-hashtb
11127              'gnus-valid-move-group-p
11128              nil nil
11129              'gnus-group-history))
11130            (t
11131             (gnus-completing-read-with-default
11132              nil prom
11133              (mapcar 'list (nreverse split-name))
11134              nil nil nil
11135              'gnus-group-history))))
11136          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11137     (when to-newsgroup
11138       (if (or (string= to-newsgroup "")
11139               (string= to-newsgroup prefix))
11140           (setq to-newsgroup default))
11141       (unless to-newsgroup
11142         (error "No group name entered"))
11143       (or (gnus-active to-newsgroup)
11144           (gnus-activate-group to-newsgroup nil nil to-method)
11145           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11146                                      to-newsgroup))
11147               (or (and (gnus-request-create-group to-newsgroup to-method)
11148                        (gnus-activate-group
11149                         to-newsgroup nil nil to-method)
11150                        (gnus-subscribe-group to-newsgroup))
11151                   (error "Couldn't create group %s" to-newsgroup)))
11152           (error "No such group: %s" to-newsgroup)))
11153     to-newsgroup))
11154
11155 (defun gnus-summary-save-parts (type dir n &optional reverse)
11156   "Save parts matching TYPE to DIR.
11157 If REVERSE, save parts that do not match TYPE."
11158   (interactive
11159    (list (read-string "Save parts of type: "
11160                       (or (car gnus-summary-save-parts-type-history)
11161                           gnus-summary-save-parts-default-mime)
11162                       'gnus-summary-save-parts-type-history)
11163          (setq gnus-summary-save-parts-last-directory
11164                (read-file-name "Save to directory: "
11165                                gnus-summary-save-parts-last-directory
11166                                nil t))
11167          current-prefix-arg))
11168   (gnus-summary-iterate n
11169     (let ((gnus-display-mime-function nil)
11170           (gnus-inhibit-treatment t))
11171       (gnus-summary-select-article))
11172     (save-excursion
11173       (set-buffer gnus-article-buffer)
11174       (let ((handles (or gnus-article-mime-handles
11175                          (mm-dissect-buffer nil gnus-article-loose-mime)
11176                          (and gnus-article-emulate-mime
11177                               (mm-uu-dissect)))))
11178         (when handles
11179           (gnus-summary-save-parts-1 type dir handles reverse)
11180           (unless gnus-article-mime-handles ;; Don't destroy this case.
11181             (mm-destroy-parts handles)))))))
11182
11183 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11184   (if (stringp (car handle))
11185       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11186               (cdr handle))
11187     (when (if reverse
11188               (not (string-match type (mm-handle-media-type handle)))
11189             (string-match type (mm-handle-media-type handle)))
11190       (let ((file (expand-file-name
11191                    (gnus-map-function
11192                     mm-file-name-rewrite-functions
11193                     (file-name-nondirectory
11194                      (or
11195                       (mail-content-type-get
11196                        (mm-handle-disposition handle) 'filename)
11197                       (mail-content-type-get
11198                        (mm-handle-type handle) 'name)
11199                       (concat gnus-newsgroup-name
11200                               "." (number-to-string
11201                                    (cdr gnus-article-current))))))
11202                    dir)))
11203         (unless (file-exists-p file)
11204           (mm-save-part-to-file handle file))))))
11205
11206 ;; Summary extract commands
11207
11208 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11209   (let ((buffer-read-only nil)
11210         (article (gnus-summary-article-number))
11211         after-article b e)
11212     (unless (gnus-summary-goto-subject article)
11213       (error "No such article: %d" article))
11214     (gnus-summary-position-point)
11215     ;; If all commands are to be bunched up on one line, we collect
11216     ;; them here.
11217     (unless gnus-view-pseudos-separately
11218       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11219             files action)
11220         (while ps
11221           (setq action (cdr (assq 'action (car ps))))
11222           (setq files (list (cdr (assq 'name (car ps)))))
11223           (while (and ps (cdr ps)
11224                       (string= (or action "1")
11225                                (or (cdr (assq 'action (cadr ps))) "2")))
11226             (push (cdr (assq 'name (cadr ps))) files)
11227             (setcdr ps (cddr ps)))
11228           (when files
11229             (when (not (string-match "%s" action))
11230               (push " " files))
11231             (push " " files)
11232             (when (assq 'execute (car ps))
11233               (setcdr (assq 'execute (car ps))
11234                       (funcall (if (string-match "%s" action)
11235                                    'format 'concat)
11236                                action
11237                                (mapconcat
11238                                 (lambda (f)
11239                                   (if (equal f " ")
11240                                       f
11241                                     (shell-quote-argument f)))
11242                                 files " ")))))
11243           (setq ps (cdr ps)))))
11244     (if (and gnus-view-pseudos (not not-view))
11245         (while pslist
11246           (when (assq 'execute (car pslist))
11247             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11248                                   (eq gnus-view-pseudos 'not-confirm)))
11249           (setq pslist (cdr pslist)))
11250       (save-excursion
11251         (while pslist
11252           (setq after-article (or (cdr (assq 'article (car pslist)))
11253                                   (gnus-summary-article-number)))
11254           (gnus-summary-goto-subject after-article)
11255           (forward-line 1)
11256           (setq b (point))
11257           (insert "    " (file-name-nondirectory
11258                           (cdr (assq 'name (car pslist))))
11259                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11260           (setq e (point))
11261           (forward-line -1)             ; back to `b'
11262           (gnus-add-text-properties
11263            b (1- e) (list 'gnus-number gnus-reffed-article-number
11264                           gnus-mouse-face-prop gnus-mouse-face))
11265           (gnus-data-enter
11266            after-article gnus-reffed-article-number
11267            gnus-unread-mark b (car pslist) 0 (- e b))
11268           (setq gnus-newsgroup-unreads
11269                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11270                                          gnus-reffed-article-number))
11271           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11272           (setq pslist (cdr pslist)))))))
11273
11274 (defun gnus-pseudos< (p1 p2)
11275   (let ((c1 (cdr (assq 'action p1)))
11276         (c2 (cdr (assq 'action p2))))
11277     (and c1 c2 (string< c1 c2))))
11278
11279 (defun gnus-request-pseudo-article (props)
11280   (cond ((assq 'execute props)
11281          (gnus-execute-command (cdr (assq 'execute props)))))
11282   (let ((gnus-current-article (gnus-summary-article-number)))
11283     (gnus-run-hooks 'gnus-mark-article-hook)))
11284
11285 (defun gnus-execute-command (command &optional automatic)
11286   (save-excursion
11287     (gnus-article-setup-buffer)
11288     (set-buffer gnus-article-buffer)
11289     (setq buffer-read-only nil)
11290     (let ((command (if automatic command
11291                      (read-string "Command: " (cons command 0)))))
11292       (erase-buffer)
11293       (insert "$ " command "\n\n")
11294       (if gnus-view-pseudo-asynchronously
11295           (start-process "gnus-execute" (current-buffer) shell-file-name
11296                          shell-command-switch command)
11297         (call-process shell-file-name nil t nil
11298                       shell-command-switch command)))))
11299
11300 ;; Summary kill commands.
11301
11302 (defun gnus-summary-edit-global-kill (article)
11303   "Edit the \"global\" kill file."
11304   (interactive (list (gnus-summary-article-number)))
11305   (gnus-group-edit-global-kill article))
11306
11307 (defun gnus-summary-edit-local-kill ()
11308   "Edit a local kill file applied to the current newsgroup."
11309   (interactive)
11310   (setq gnus-current-headers (gnus-summary-article-header))
11311   (gnus-group-edit-local-kill
11312    (gnus-summary-article-number) gnus-newsgroup-name))
11313
11314 ;;; Header reading.
11315
11316 (defun gnus-read-header (id &optional header)
11317   "Read the headers of article ID and enter them into the Gnus system."
11318   (let ((group gnus-newsgroup-name)
11319         (gnus-override-method
11320          (or
11321           gnus-override-method
11322           (and (gnus-news-group-p gnus-newsgroup-name)
11323                (car (gnus-refer-article-methods)))))
11324         where)
11325     ;; First we check to see whether the header in question is already
11326     ;; fetched.
11327     (if (stringp id)
11328         ;; This is a Message-ID.
11329         (setq header (or header (gnus-id-to-header id)))
11330       ;; This is an article number.
11331       (setq header (or header (gnus-summary-article-header id))))
11332     (if (and header
11333              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11334         ;; We have found the header.
11335         header
11336       ;; We have to really fetch the header to this article.
11337       (save-excursion
11338         (set-buffer nntp-server-buffer)
11339         (when (setq where (gnus-request-head id group))
11340           (nnheader-fold-continuation-lines)
11341           (goto-char (point-max))
11342           (insert ".\n")
11343           (goto-char (point-min))
11344           (insert "211 ")
11345           (princ (cond
11346                   ((numberp id) id)
11347                   ((cdr where) (cdr where))
11348                   (header (mail-header-number header))
11349                   (t gnus-reffed-article-number))
11350                  (current-buffer))
11351           (insert " Article retrieved.\n"))
11352         (if (or (not where)
11353                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11354             ()                          ; Malformed head.
11355           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11356             (when (and (stringp id)
11357                        (not (string= (gnus-group-real-name group)
11358                                      (car where))))
11359               ;; If we fetched by Message-ID and the article came
11360               ;; from a different group, we fudge some bogus article
11361               ;; numbers for this article.
11362               (mail-header-set-number header gnus-reffed-article-number))
11363             (save-excursion
11364               (set-buffer gnus-summary-buffer)
11365               (decf gnus-reffed-article-number)
11366               (gnus-remove-header (mail-header-number header))
11367               (push header gnus-newsgroup-headers)
11368               (setq gnus-current-headers header)
11369               (push (mail-header-number header) gnus-newsgroup-limit)))
11370           header)))))
11371
11372 (defun gnus-remove-header (number)
11373   "Remove header NUMBER from `gnus-newsgroup-headers'."
11374   (if (and gnus-newsgroup-headers
11375            (= number (mail-header-number (car gnus-newsgroup-headers))))
11376       (pop gnus-newsgroup-headers)
11377     (let ((headers gnus-newsgroup-headers))
11378       (while (and (cdr headers)
11379                   (not (= number (mail-header-number (cadr headers)))))
11380         (pop headers))
11381       (when (cdr headers)
11382         (setcdr headers (cddr headers))))))
11383
11384 ;;;
11385 ;;; summary highlights
11386 ;;;
11387
11388 (defun gnus-highlight-selected-summary ()
11389   "Highlight selected article in summary buffer."
11390   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11391   (when gnus-summary-selected-face
11392     (save-excursion
11393       (let* ((beg (point-at-bol))
11394              (end (point-at-eol))
11395              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11396              (from (if (get-text-property beg gnus-mouse-face-prop)
11397                        beg
11398                      (or (next-single-property-change
11399                           beg gnus-mouse-face-prop nil end)
11400                          beg)))
11401              (to
11402               (if (= from end)
11403                   (- from 2)
11404                 (or (next-single-property-change
11405                      from gnus-mouse-face-prop nil end)
11406                     end))))
11407         ;; If no mouse-face prop on line we will have to = from = end,
11408         ;; so we highlight the entire line instead.
11409         (when (= (+ to 2) from)
11410           (setq from beg)
11411           (setq to end))
11412         (if gnus-newsgroup-selected-overlay
11413             ;; Move old overlay.
11414             (gnus-move-overlay
11415              gnus-newsgroup-selected-overlay from to (current-buffer))
11416           ;; Create new overlay.
11417           (gnus-overlay-put
11418            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11419            'face gnus-summary-selected-face))))))
11420
11421 (defvar gnus-summary-highlight-line-cached nil)
11422 (defvar gnus-summary-highlight-line-trigger nil)
11423
11424 (defun gnus-summary-highlight-line-0 ()
11425   (if (and (eq gnus-summary-highlight-line-trigger
11426                gnus-summary-highlight)
11427            gnus-summary-highlight-line-cached)
11428       gnus-summary-highlight-line-cached
11429     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11430           gnus-summary-highlight-line-cached
11431           (let* ((cond (list 'cond))
11432                  (c cond)
11433                  (list gnus-summary-highlight))
11434             (while list
11435               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11436                               nil))
11437               (setq c (cdr c)
11438                     list (cdr list)))
11439             (gnus-byte-compile (list 'lambda nil cond))))))
11440
11441 (defun gnus-summary-highlight-line ()
11442   "Highlight current line according to `gnus-summary-highlight'."
11443   (let* ((beg (point-at-bol))
11444          (article (or (gnus-summary-article-number) gnus-current-article))
11445          (score (or (cdr (assq article
11446                                gnus-newsgroup-scored))
11447                     gnus-summary-default-score 0))
11448          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11449          (inhibit-read-only t)
11450          (default gnus-summary-default-score)
11451          (default-high gnus-summary-default-high-score)
11452          (default-low gnus-summary-default-low-score)
11453          (uncached (and gnus-summary-use-undownloaded-faces
11454                         (memq article gnus-newsgroup-undownloaded)
11455                         (not (memq article gnus-newsgroup-cached)))))
11456     (let ((face (funcall (gnus-summary-highlight-line-0))))
11457       (unless (eq face (get-text-property beg 'face))
11458         (gnus-put-text-property-excluding-characters-with-faces
11459          beg (point-at-eol) 'face
11460          (setq face (if (boundp face) (symbol-value face) face)))
11461         (when gnus-summary-highlight-line-function
11462           (funcall gnus-summary-highlight-line-function article face))))))
11463
11464 (defun gnus-update-read-articles (group unread &optional compute)
11465   "Update the list of read articles in GROUP.
11466 UNREAD is a sorted list."
11467   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11468         (info (gnus-get-info group))
11469         (prev 1)
11470         read)
11471     (if (or (not info) (not active))
11472         ;; There is no info on this group if it was, in fact,
11473         ;; killed.  Gnus stores no information on killed groups, so
11474         ;; there's nothing to be done.
11475         ;; One could store the information somewhere temporarily,
11476         ;; perhaps...  Hmmm...
11477         ()
11478       ;; Remove any negative articles numbers.
11479       (while (and unread (< (car unread) 0))
11480         (setq unread (cdr unread)))
11481       ;; Remove any expired article numbers
11482       (while (and unread (< (car unread) (car active)))
11483         (setq unread (cdr unread)))
11484       ;; Compute the ranges of read articles by looking at the list of
11485       ;; unread articles.
11486       (while unread
11487         (when (/= (car unread) prev)
11488           (push (if (= prev (1- (car unread))) prev
11489                   (cons prev (1- (car unread))))
11490                 read))
11491         (setq prev (1+ (car unread)))
11492         (setq unread (cdr unread)))
11493       (when (<= prev (cdr active))
11494         (push (cons prev (cdr active)) read))
11495       (setq read (if (> (length read) 1) (nreverse read) read))
11496       (if compute
11497           read
11498         (save-excursion
11499           (let (setmarkundo)
11500             ;; Propagate the read marks to the backend.
11501             (when (gnus-check-backend-function 'request-set-mark group)
11502               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11503                     (add (gnus-remove-from-range read (gnus-info-read info))))
11504                 (when (or add del)
11505                   (unless (gnus-check-group group)
11506                     (error "Can't open server for %s" group))
11507                   (gnus-request-set-mark
11508                    group (delq nil (list (if add (list add 'add '(read)))
11509                                          (if del (list del 'del '(read))))))
11510                   (setq setmarkundo
11511                         `(gnus-request-set-mark
11512                           ,group
11513                           ',(delq nil (list
11514                                        (if del (list del 'add '(read)))
11515                                        (if add (list add 'del '(read))))))))))
11516             (set-buffer gnus-group-buffer)
11517             (gnus-undo-register
11518               `(progn
11519                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11520                  (gnus-info-set-read ',info ',(gnus-info-read info))
11521                  (gnus-get-unread-articles-in-group ',info
11522                                                     (gnus-active ,group))
11523                  (gnus-group-update-group ,group t)
11524                  ,setmarkundo))))
11525         ;; Enter this list into the group info.
11526         (gnus-info-set-read info read)
11527         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11528         (gnus-get-unread-articles-in-group info (gnus-active group))
11529         t))))
11530
11531 (defun gnus-offer-save-summaries ()
11532   "Offer to save all active summary buffers."
11533   (let (buffers)
11534     ;; Go through all buffers and find all summaries.
11535     (dolist (buffer (buffer-list))
11536       (when (and (setq buffer (buffer-name buffer))
11537                  (string-match "Summary" buffer)
11538                  (with-current-buffer buffer
11539                    ;; We check that this is, indeed, a summary buffer.
11540                    (and (eq major-mode 'gnus-summary-mode)
11541                         ;; Also make sure this isn't bogus.
11542                         gnus-newsgroup-prepared
11543                         ;; Also make sure that this isn't a
11544                         ;; dead summary buffer.
11545                         (not gnus-dead-summary-mode))))
11546         (push buffer buffers)))
11547     ;; Go through all these summary buffers and offer to save them.
11548     (when buffers
11549       (save-excursion
11550         (map-y-or-n-p
11551          "Update summary buffer %s? "
11552          (lambda (buf)
11553            (switch-to-buffer buf)
11554            (gnus-summary-exit))
11555          buffers)))))
11556
11557
11558 ;;; @ for mime-partial
11559 ;;;
11560
11561 (defun gnus-request-partial-message ()
11562   (save-excursion
11563     (let ((number (gnus-summary-article-number))
11564           (group gnus-newsgroup-name)
11565           (mother gnus-article-buffer))
11566       (set-buffer (get-buffer-create " *Partial Article*"))
11567       (erase-buffer)
11568       (setq mime-preview-buffer mother)
11569       (gnus-request-article-this-buffer number group)
11570       (mime-parse-buffer)
11571       )))
11572
11573 (autoload 'mime-combine-message/partial-pieces-automatically
11574   "mime-partial"
11575   "Internal method to combine message/partial messages automatically.")
11576
11577 (mime-add-condition
11578  'action '((type . message)(subtype . partial)
11579            (major-mode . gnus-original-article-mode)
11580            (method . mime-combine-message/partial-pieces-automatically)
11581            (summary-buffer-exp . gnus-summary-buffer)
11582            (request-partial-message-method . gnus-request-partial-message)
11583            ))
11584
11585
11586 ;;; @ for message/rfc822
11587 ;;;
11588
11589 (defun gnus-mime-extract-message/rfc822 (entity situation)
11590   "Burst a forwarded article."
11591   (save-excursion
11592     (set-buffer gnus-summary-buffer)
11593     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11594                                    gnus-newsgroup-name 'gnus-group-history))
11595            (gnus-group-marked (list group))
11596            article info)
11597       (with-temp-buffer
11598         (mime-insert-entity-content entity)
11599         (setq article (gnus-request-accept-article group)))
11600       (when (and (consp article)
11601                  (numberp (setq article (cdr article))))
11602         (setq info (gnus-get-info group))
11603         (gnus-info-set-read info
11604                             (gnus-remove-from-range (gnus-info-read info)
11605                                                     (list article)))
11606         (when (string-equal group gnus-newsgroup-name)
11607           (forward-line 1)
11608           (let (gnus-show-threads)
11609             (gnus-summary-goto-subject article t))
11610           (gnus-summary-clear-mark-forward 1))
11611         (set-buffer gnus-group-buffer)
11612         (gnus-group-get-new-news-this-group nil t)))))
11613
11614 (mime-add-condition
11615  'action '((type . message)(subtype . rfc822)
11616            (major-mode . gnus-original-article-mode)
11617            (method . gnus-mime-extract-message/rfc822)
11618            (mode . "extract")
11619            ))
11620
11621 (mime-add-condition
11622  'action '((type . message)(subtype . news)
11623            (major-mode . gnus-original-article-mode)
11624            (method . gnus-mime-extract-message/rfc822)
11625            (mode . "extract")
11626            ))
11627
11628 (defun gnus-mime-extract-multipart (entity situation)
11629   (let ((children (mime-entity-children entity))
11630         mime-acting-situation-to-override
11631         f)
11632     (while children
11633       (mime-play-entity (car children)
11634                         (cons (assq 'mode situation)
11635                               mime-acting-situation-to-override))
11636       (setq children (cdr children)))
11637     (if (setq f (cdr (assq 'after-method
11638                            mime-acting-situation-to-override)))
11639         (eval f)
11640       )))
11641
11642 (mime-add-condition
11643  'action '((type . multipart)
11644            (method . gnus-mime-extract-multipart)
11645            (mode . "extract")
11646            )
11647  'with-default)
11648
11649
11650 ;;; @ end
11651 ;;;
11652
11653 (defun gnus-summary-inherit-default-charset ()
11654   "Import `default-mime-charset' from summary buffer.
11655 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11656 of FLIM is used."
11657   (if (buffer-live-p gnus-summary-buffer)
11658       (let (d-m-c d-m-c-u)
11659         (with-current-buffer gnus-summary-buffer
11660           (setq d-m-c (if (local-variable-p 'default-mime-charset
11661                                             gnus-summary-buffer)
11662                           default-mime-charset
11663                         t)
11664                 ;; LIMIT
11665                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11666                                               gnus-summary-buffer)
11667                             (symbol-value 'default-mime-charset-unlimited)
11668                           t)))
11669         (if (eq t d-m-c)
11670             (kill-local-variable 'default-mime-charset)
11671           (set (make-local-variable 'default-mime-charset) d-m-c))
11672         (if (eq t d-m-c-u)
11673             (kill-local-variable 'default-mime-charset-unlimited)
11674           (set (make-local-variable 'default-mime-charset-unlimited)
11675                d-m-c-u)))))
11676
11677 (defun gnus-summary-setup-default-charset ()
11678   "Setup newsgroup default charset."
11679   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11680       (progn
11681         (setq gnus-newsgroup-charset nil)
11682         (set (make-local-variable 'default-mime-charset) nil)
11683         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11684           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11685     (let ((ignored-charsets
11686            (or gnus-newsgroup-ephemeral-ignored-charsets
11687                (append
11688                 (and gnus-newsgroup-name
11689                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11690                 gnus-newsgroup-ignored-charsets)))
11691           charset)
11692       (setq gnus-newsgroup-charset
11693             (or gnus-newsgroup-ephemeral-charset
11694                 (when (and gnus-newsgroup-name
11695                            (setq charset (gnus-parameter-charset
11696                                           gnus-newsgroup-name)))
11697                   (make-local-variable 'default-mime-charset)
11698                   (setq default-mime-charset charset))
11699                 gnus-default-charset))
11700       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11701            ignored-charsets))))
11702
11703 ;;;
11704 ;;; Mime Commands
11705 ;;;
11706
11707 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11708   "Display the current article buffer fully MIME-buttonized.
11709 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11710 treated as multipart/mixed."
11711   (interactive "P")
11712   (require 'gnus-art)
11713   (let ((gnus-unbuttonized-mime-types nil)
11714         (gnus-mime-display-multipart-as-mixed show-all-parts))
11715     (gnus-summary-show-article)))
11716
11717 (defun gnus-summary-repair-multipart (article)
11718   "Add a Content-Type header to a multipart article without one."
11719   (interactive (list (gnus-summary-article-number)))
11720   (gnus-with-article article
11721     (message-narrow-to-head)
11722     (message-remove-header "Mime-Version")
11723     (goto-char (point-max))
11724     (insert "Mime-Version: 1.0\n")
11725     (widen)
11726     (when (search-forward "\n--" nil t)
11727       (let ((separator (buffer-substring (point) (point-at-eol))))
11728         (message-narrow-to-head)
11729         (message-remove-header "Content-Type")
11730         (goto-char (point-max))
11731         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11732                         separator))
11733         (widen))))
11734   (let (gnus-mark-article-hook)
11735     (gnus-summary-select-article t t nil article)))
11736
11737 (defun gnus-summary-toggle-display-buttonized ()
11738   "Toggle the buttonizing of the article buffer."
11739   (interactive)
11740   (require 'gnus-art)
11741   (if (setq gnus-inhibit-mime-unbuttonizing
11742             (not gnus-inhibit-mime-unbuttonizing))
11743       (let ((gnus-unbuttonized-mime-types nil))
11744         (gnus-summary-show-article))
11745     (gnus-summary-show-article)))
11746
11747 ;;;
11748 ;;; Intelli-mouse commmands
11749 ;;;
11750
11751 (defun gnus-wheel-summary-scroll (event)
11752   (interactive "e")
11753   (let ((amount (if (memq 'shift (event-modifiers event))
11754                     (car gnus-wheel-scroll-amount)
11755                   (cdr gnus-wheel-scroll-amount)))
11756         (direction (- (* (static-if (featurep 'xemacs)
11757                              (event-button event)
11758                            (cond ((eq 'mouse-4 (event-basic-type event))
11759                                   4)
11760                                  ((eq 'mouse-5 (event-basic-type event))
11761                                   5)))
11762                          2) 9))
11763         edge)
11764     (gnus-summary-scroll-up (* amount direction))
11765     (when (gnus-eval-in-buffer-window gnus-article-buffer
11766             (save-restriction
11767               (widen)
11768               (and (if (< 0 direction)
11769                        (gnus-article-next-page 0)
11770                      (gnus-article-prev-page 0)
11771                      (bobp))
11772                    (if (setq edge (get-text-property
11773                                    (point-min) 'gnus-wheel-edge))
11774                        (setq edge (* edge direction))
11775                      (setq edge -1))
11776                    (or (plusp edge)
11777                        (let ((buffer-read-only nil)
11778                              (inhibit-read-only t))
11779                          (put-text-property (point-min) (point-max)
11780                                             'gnus-wheel-edge direction)
11781                          nil))
11782                    (or (> edge gnus-wheel-edge-resistance)
11783                        (let ((buffer-read-only nil)
11784                              (inhibit-read-only t))
11785                          (put-text-property (point-min) (point-max)
11786                                             'gnus-wheel-edge
11787                                             (* (1+ edge) direction))
11788                          nil))
11789                    (eq last-command 'gnus-wheel-summary-scroll))))
11790       (gnus-summary-next-article nil nil (minusp direction)))))
11791
11792 (defun gnus-wheel-install ()
11793   "Enable mouse wheel support on summary window."
11794   (when gnus-use-wheel
11795     (let ((keys
11796            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11797       (dolist (key keys)
11798         (define-key gnus-summary-mode-map key
11799           'gnus-wheel-summary-scroll)))))
11800
11801 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11802
11803 ;;;
11804 ;;; Traditional PGP commmands
11805 ;;;
11806
11807 (defun gnus-summary-decrypt-article (&optional force)
11808   "Decrypt the current article in traditional PGP way.
11809 This will have permanent effect only in mail groups.
11810 If FORCE is non-nil, allow editing of articles even in read-only
11811 groups."
11812   (interactive "P")
11813   (gnus-summary-select-article t)
11814   (gnus-eval-in-buffer-window gnus-article-buffer
11815     (save-excursion
11816       (save-restriction
11817         (widen)
11818         (goto-char (point-min))
11819         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11820           (error "Not a traditional PGP message!"))
11821         (let ((armor-start (match-beginning 0)))
11822           (if (and (pgg-decrypt-region armor-start (point-max))
11823                    (or force (not (gnus-group-read-only-p))))
11824               (let ((inhibit-read-only t)
11825                     buffer-read-only)
11826                 (delete-region armor-start
11827                                (progn
11828                                  (re-search-forward "^-+END PGP" nil t)
11829                                  (beginning-of-line 2)
11830                                  (point)))
11831                 (insert-buffer-substring pgg-output-buffer))))))))
11832
11833 (defun gnus-summary-verify-article ()
11834   "Verify the current article in traditional PGP way."
11835   (interactive)
11836   (save-excursion
11837     (set-buffer gnus-original-article-buffer)
11838     (goto-char (point-min))
11839     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11840       (error "Not a traditional PGP message!"))
11841     (re-search-forward "^-+END PGP" nil t)
11842     (beginning-of-line 2)
11843     (call-interactively (function pgg-verify-region))))
11844
11845 ;;;
11846 ;;; Generic summary marking commands
11847 ;;;
11848
11849 (defvar gnus-summary-marking-alist
11850   '((read gnus-del-mark "d")
11851     (unread gnus-unread-mark "u")
11852     (ticked gnus-ticked-mark "!")
11853     (dormant gnus-dormant-mark "?")
11854     (expirable gnus-expirable-mark "e"))
11855   "An alist of names/marks/keystrokes.")
11856
11857 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11858 (defvar gnus-summary-mark-map)
11859
11860 (defun gnus-summary-make-all-marking-commands ()
11861   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11862   (dolist (elem gnus-summary-marking-alist)
11863     (apply 'gnus-summary-make-marking-command elem)))
11864
11865 (defun gnus-summary-make-marking-command (name mark keystroke)
11866   (let ((map (make-sparse-keymap)))
11867     (define-key gnus-summary-generic-mark-map keystroke map)
11868     (dolist (lway `((next "next" next nil "n")
11869                     (next-unread "next unread" next t "N")
11870                     (prev "previous" prev nil "p")
11871                     (prev-unread "previous unread" prev t "P")
11872                     (nomove "" nil nil ,keystroke)))
11873       (let ((func (gnus-summary-make-marking-command-1
11874                    mark (car lway) lway name)))
11875         (setq func (eval func))
11876         (define-key map (nth 4 lway) func)))))
11877
11878 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11879   `(defun ,(intern
11880             (format "gnus-summary-put-mark-as-%s%s"
11881                     name (if (eq way 'nomove)
11882                              ""
11883                            (concat "-" (symbol-name way)))))
11884      (n)
11885      ,(format
11886        "Mark the current article as %s%s.
11887 If N, the prefix, then repeat N times.
11888 If N is negative, move in reverse order.
11889 The difference between N and the actual number of articles marked is
11890 returned."
11891        name (car (cdr lway)))
11892      (interactive "p")
11893      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11894
11895 (defun gnus-summary-generic-mark (n mark move unread)
11896   "Mark N articles with MARK."
11897   (unless (eq major-mode 'gnus-summary-mode)
11898     (error "This command can only be used in the summary buffer"))
11899   (gnus-summary-show-thread)
11900   (let ((nummove
11901          (cond
11902           ((eq move 'next) 1)
11903           ((eq move 'prev) -1)
11904           (t 0))))
11905     (if (zerop nummove)
11906         (setq n 1)
11907       (when (< n 0)
11908         (setq n (abs n)
11909               nummove (* -1 nummove))))
11910     (while (and (> n 0)
11911                 (gnus-summary-mark-article nil mark)
11912                 (zerop (gnus-summary-next-subject nummove unread t)))
11913       (setq n (1- n)))
11914     (when (/= 0 n)
11915       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11916     (gnus-summary-recenter)
11917     (gnus-summary-position-point)
11918     (gnus-set-mode-line 'summary)
11919     n))
11920
11921 (defun gnus-summary-insert-articles (articles)
11922   (when (setq articles
11923               (gnus-sorted-difference articles
11924                                       (mapcar (lambda (h)
11925                                                 (mail-header-number h))
11926                                               gnus-newsgroup-headers)))
11927     (setq gnus-newsgroup-headers
11928           (gnus-merge 'list
11929                       gnus-newsgroup-headers
11930                       (gnus-fetch-headers articles)
11931                       'gnus-article-sort-by-number))
11932     ;; Suppress duplicates?
11933     (when gnus-suppress-duplicates
11934       (gnus-dup-suppress-articles))
11935
11936     ;; We might want to build some more threads first.
11937     (when (and gnus-fetch-old-headers
11938                (eq gnus-headers-retrieved-by 'nov))
11939       (if (eq gnus-fetch-old-headers 'invisible)
11940           (gnus-build-all-threads)
11941         (gnus-build-old-threads)))
11942     ;; Let the Gnus agent mark articles as read.
11943     (when gnus-agent
11944       (gnus-agent-get-undownloaded-list))
11945     ;; Remove list identifiers from subject
11946     (when gnus-list-identifiers
11947       (gnus-summary-remove-list-identifiers))
11948     ;; First and last article in this newsgroup.
11949     (when gnus-newsgroup-headers
11950       (setq gnus-newsgroup-begin
11951             (mail-header-number (car gnus-newsgroup-headers))
11952             gnus-newsgroup-end
11953             (mail-header-number
11954              (gnus-last-element gnus-newsgroup-headers))))
11955     (when gnus-use-scoring
11956       (gnus-possibly-score-headers))))
11957
11958 (defun gnus-summary-insert-old-articles (&optional all)
11959   "Insert all old articles in this group.
11960 If ALL is non-nil, already read articles become readable.
11961 If ALL is a number, fetch this number of articles."
11962   (interactive "P")
11963   (prog1
11964       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11965             older len)
11966         (setq older
11967               ;; Some nntp servers lie about their active range.  When
11968               ;; this happens, the active range can be in the millions.
11969               ;; Use a compressed range to avoid creating a huge list.
11970               (gnus-range-difference (list gnus-newsgroup-active) old))
11971         (setq len (gnus-range-length older))
11972         (cond
11973          ((null older) nil)
11974          ((numberp all)
11975           (if (< all len)
11976               (let ((older-range (nreverse older)))
11977                 (setq older nil)
11978
11979                 (while (> all 0)
11980                   (let* ((r (pop older-range))
11981                          (min (if (numberp r) r (car r)))
11982                          (max (if (numberp r) r (cdr r))))
11983                     (while (and (<= min max)
11984                                 (> all 0))
11985                       (push max older)
11986                       (setq all (1- all)
11987                             max (1- max))))))
11988             (setq older (gnus-uncompress-range older))))
11989          (all
11990           (setq older (gnus-uncompress-range older)))
11991          (t
11992           (when (and (numberp gnus-large-newsgroup)
11993                    (> len gnus-large-newsgroup))
11994               (let* ((cursor-in-echo-area nil)
11995                      (initial (gnus-parameter-large-newsgroup-initial
11996                                gnus-newsgroup-name))
11997                      (input
11998                       (read-string
11999                        (format
12000                         "How many articles from %s (%s %d): "
12001                         (gnus-limit-string
12002                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12003                         (if initial "max" "default")
12004                         len)
12005                        (if initial
12006                            (cons (number-to-string initial)
12007                                  0)))))
12008                 (unless (string-match "^[ \t]*$" input)
12009                   (setq all (string-to-number input))
12010                   (if (< all len)
12011                       (let ((older-range (nreverse older)))
12012                         (setq older nil)
12013
12014                         (while (> all 0)
12015                           (let* ((r (pop older-range))
12016                                  (min (if (numberp r) r (car r)))
12017                                  (max (if (numberp r) r (cdr r))))
12018                             (while (and (<= min max)
12019                                         (> all 0))
12020                               (push max older)
12021                               (setq all (1- all)
12022                                     max (1- max))))))))))
12023           (setq older (gnus-uncompress-range older))))
12024         (if (not older)
12025             (message "No old news.")
12026           (gnus-summary-insert-articles older)
12027           (gnus-summary-limit (gnus-sorted-nunion old older))))
12028     (gnus-summary-position-point)))
12029
12030 (defun gnus-summary-insert-new-articles ()
12031   "Insert all new articles in this group."
12032   (interactive)
12033   (prog1
12034       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12035             (old-active gnus-newsgroup-active)
12036             (nnmail-fetched-sources (list t))
12037             i new)
12038         (setq gnus-newsgroup-active
12039               (gnus-activate-group gnus-newsgroup-name 'scan))
12040         (setq i (cdr gnus-newsgroup-active))
12041         (while (> i (cdr old-active))
12042           (push i new)
12043           (decf i))
12044         (if (not new)
12045             (message "No gnus is bad news")
12046           (gnus-summary-insert-articles new)
12047           (setq gnus-newsgroup-unreads
12048                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12049           (gnus-summary-limit (gnus-sorted-nunion old new))))
12050     (gnus-summary-position-point)))
12051
12052 (gnus-summary-make-all-marking-commands)
12053
12054 (gnus-ems-redefine)
12055
12056 (provide 'gnus-sum)
12057
12058 (run-hooks 'gnus-sum-load-hook)
12059
12060 ;; Local Variables:
12061 ;; coding: iso-8859-1
12062 ;; End:
12063
12064 ;;; gnus-sum.el ends here