4ac59fbca374ec1cab93fef33c16c9a7bb10d3ec
[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 2
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 t
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 If non-nil (the default), Gnus will treat some articles as MIME
1189 even if the MIME-Version header is missing."
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         ["Invert marks" gnus-uu-invert-processable t]
2459         ["Mark above" gnus-uu-mark-over t]
2460         ["Mark series" gnus-uu-mark-series t]
2461         ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2462         ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2463         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2464         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2465         ["Mark all" gnus-uu-mark-all t]
2466         ["Mark buffer" gnus-uu-mark-buffer t]
2467         ["Mark sparse" gnus-uu-mark-sparse t]
2468         ["Mark thread" gnus-uu-mark-thread t]
2469         ["Unmark thread" gnus-uu-unmark-thread t]
2470         ("Process Mark Sets"
2471          ["Kill" gnus-summary-kill-process-mark t]
2472          ["Yank" gnus-summary-yank-process-mark
2473           gnus-newsgroup-process-stack]
2474          ["Save" gnus-summary-save-process-mark t]
2475          ["Run command on marked..." gnus-summary-universal-argument t]))
2476        ("Scroll article"
2477         ["Page forward" gnus-summary-next-page
2478          ,@(if (featurep 'xemacs) '(t)
2479              '(:help "Show next page of article"))]
2480         ["Page backward" gnus-summary-prev-page
2481          ,@(if (featurep 'xemacs) '(t)
2482              '(:help "Show previous page of article"))]
2483         ["Line forward" gnus-summary-scroll-up t])
2484        ("Move"
2485         ["Next unread article" gnus-summary-next-unread-article t]
2486         ["Previous unread article" gnus-summary-prev-unread-article t]
2487         ["Next article" gnus-summary-next-article t]
2488         ["Previous article" gnus-summary-prev-article t]
2489         ["Next unread subject" gnus-summary-next-unread-subject t]
2490         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2491         ["Next article same subject" gnus-summary-next-same-subject t]
2492         ["Previous article same subject" gnus-summary-prev-same-subject t]
2493         ["First unread article" gnus-summary-first-unread-article t]
2494         ["Best unread article" gnus-summary-best-unread-article t]
2495         ["Go to subject number..." gnus-summary-goto-subject t]
2496         ["Go to article number..." gnus-summary-goto-article t]
2497         ["Go to the last article" gnus-summary-goto-last-article t]
2498         ["Pop article off history" gnus-summary-pop-article t])
2499        ("Sort"
2500         ["Sort by number" gnus-summary-sort-by-number t]
2501         ["Sort by author" gnus-summary-sort-by-author t]
2502         ["Sort by subject" gnus-summary-sort-by-subject t]
2503         ["Sort by date" gnus-summary-sort-by-date t]
2504         ["Sort by score" gnus-summary-sort-by-score t]
2505         ["Sort by lines" gnus-summary-sort-by-lines t]
2506         ["Sort by characters" gnus-summary-sort-by-chars t]
2507         ["Randomize" gnus-summary-sort-by-random t]
2508         ["Original sort" gnus-summary-sort-by-original t])
2509        ("Help"
2510         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2511         ["Describe group" gnus-summary-describe-group t]
2512         ["Fetch charter" gnus-group-fetch-charter
2513          ,@(if (featurep 'xemacs) nil
2514              '(:help "Display the charter of the current group"))]
2515         ["Fetch control message" gnus-group-fetch-control
2516          ,@(if (featurep 'xemacs) nil
2517              '(:help "Display the archived control message for the current group"))]
2518         ["Read manual" gnus-info-find-node t])
2519        ("Modes"
2520         ["Pick and read" gnus-pick-mode t]
2521         ["Binary" gnus-binary-mode t])
2522        ("Regeneration"
2523         ["Regenerate" gnus-summary-prepare t]
2524         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2525         ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2526         ["Toggle threading" gnus-summary-toggle-threads t])
2527        ["See old articles" gnus-summary-insert-old-articles t]
2528        ["See new articles" gnus-summary-insert-new-articles t]
2529        ["Filter articles..." gnus-summary-execute-command t]
2530        ["Run command on articles..." gnus-summary-universal-argument t]
2531        ["Search articles forward..." gnus-summary-search-article-forward t]
2532        ["Search articles backward..." gnus-summary-search-article-backward t]
2533        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2534        ["Expand window" gnus-summary-expand-window t]
2535        ["Expire expirable articles" gnus-summary-expire-articles
2536         (gnus-check-backend-function
2537          'request-expire-articles gnus-newsgroup-name)]
2538        ["Edit local kill file" gnus-summary-edit-local-kill t]
2539        ["Edit main kill file" gnus-summary-edit-global-kill t]
2540        ["Edit group parameters" gnus-summary-edit-parameters t]
2541        ["Customize group parameters" gnus-summary-customize-parameters t]
2542        ["Send a bug report" gnus-bug t]
2543        ("Exit"
2544         ["Catchup and exit" gnus-summary-catchup-and-exit
2545          ,@(if (featurep 'xemacs) '(t)
2546              '(:help "Mark unread articles in this group as read, then exit"))]
2547         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2548         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2549         ["Exit group" gnus-summary-exit
2550          ,@(if (featurep 'xemacs) '(t)
2551              '(:help "Exit current group, return to group selection mode"))]
2552         ["Exit group without updating" gnus-summary-exit-no-update t]
2553         ["Exit and goto next group" gnus-summary-next-group t]
2554         ["Exit and goto prev group" gnus-summary-prev-group t]
2555         ["Reselect group" gnus-summary-reselect-current-group t]
2556         ["Rescan group" gnus-summary-rescan-group t]
2557         ["Update dribble" gnus-summary-save-newsrc t])))
2558
2559     (gnus-run-hooks 'gnus-summary-menu-hook)))
2560
2561 (defvar gnus-summary-tool-bar-map nil)
2562
2563 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2564 (defun gnus-summary-make-tool-bar ()
2565   (if (and (fboundp 'tool-bar-add-item-from-menu)
2566            (default-value 'tool-bar-mode)
2567            (not gnus-summary-tool-bar-map))
2568       (setq gnus-summary-tool-bar-map
2569             (let ((tool-bar-map (make-sparse-keymap))
2570                   (load-path (mm-image-load-path)))
2571               (tool-bar-add-item-from-menu
2572                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2573               (tool-bar-add-item-from-menu
2574                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2575               (tool-bar-add-item-from-menu
2576                'gnus-summary-post-news "post" gnus-summary-mode-map)
2577               (tool-bar-add-item-from-menu
2578                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2579               (tool-bar-add-item-from-menu
2580                'gnus-summary-followup "followup" gnus-summary-mode-map)
2581               (tool-bar-add-item-from-menu
2582                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2583               (tool-bar-add-item-from-menu
2584                'gnus-summary-reply "reply" gnus-summary-mode-map)
2585               (tool-bar-add-item-from-menu
2586                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2587               (tool-bar-add-item-from-menu
2588                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2589               (tool-bar-add-item-from-menu
2590                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2591               (tool-bar-add-item-from-menu
2592                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2593               (tool-bar-add-item-from-menu
2594                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2595               (tool-bar-add-item-from-menu
2596                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2597               (tool-bar-add-item-from-menu
2598                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2599               (tool-bar-add-item-from-menu
2600                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2601               (tool-bar-add-item-from-menu
2602                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2603               tool-bar-map)))
2604   (if gnus-summary-tool-bar-map
2605       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2606
2607 (defun gnus-score-set-default (var value)
2608   "A version of set that updates the GNU Emacs menu-bar."
2609   (set var value)
2610   ;; It is the message that forces the active status to be updated.
2611   (message ""))
2612
2613 (defun gnus-make-score-map (type)
2614   "Make a summary score map of type TYPE."
2615   (if t
2616       nil
2617     (let ((headers '(("author" "from" string)
2618                      ("subject" "subject" string)
2619                      ("article body" "body" string)
2620                      ("article head" "head" string)
2621                      ("xref" "xref" string)
2622                      ("extra header" "extra" string)
2623                      ("lines" "lines" number)
2624                      ("followups to author" "followup" string)))
2625           (types '((number ("less than" <)
2626                            ("greater than" >)
2627                            ("equal" =))
2628                    (string ("substring" s)
2629                            ("exact string" e)
2630                            ("fuzzy string" f)
2631                            ("regexp" r))))
2632           (perms '(("temporary" (current-time-string))
2633                    ("permanent" nil)
2634                    ("immediate" now)))
2635           header)
2636       (list
2637        (apply
2638         'nconc
2639         (list
2640          (if (eq type 'lower)
2641              "Lower score"
2642            "Increase score"))
2643         (let (outh)
2644           (while headers
2645             (setq header (car headers))
2646             (setq outh
2647                   (cons
2648                    (apply
2649                     'nconc
2650                     (list (car header))
2651                     (let ((ts (cdr (assoc (nth 2 header) types)))
2652                           outt)
2653                       (while ts
2654                         (setq outt
2655                               (cons
2656                                (apply
2657                                 'nconc
2658                                 (list (caar ts))
2659                                 (let ((ps perms)
2660                                       outp)
2661                                   (while ps
2662                                     (setq outp
2663                                           (cons
2664                                            (vector
2665                                             (caar ps)
2666                                             (list
2667                                              'gnus-summary-score-entry
2668                                              (nth 1 header)
2669                                              (if (or (string= (nth 1 header)
2670                                                               "head")
2671                                                      (string= (nth 1 header)
2672                                                               "body"))
2673                                                  ""
2674                                                (list 'gnus-summary-header
2675                                                      (nth 1 header)))
2676                                              (list 'quote (nth 1 (car ts)))
2677                                              (list 'gnus-score-delta-default
2678                                                    nil)
2679                                              (nth 1 (car ps))
2680                                              t)
2681                                             t)
2682                                            outp))
2683                                     (setq ps (cdr ps)))
2684                                   (list (nreverse outp))))
2685                                outt))
2686                         (setq ts (cdr ts)))
2687                       (list (nreverse outt))))
2688                    outh))
2689             (setq headers (cdr headers)))
2690           (list (nreverse outh))))))))
2691
2692 \f
2693
2694 (defun gnus-summary-mode (&optional group)
2695   "Major mode for reading articles.
2696
2697 All normal editing commands are switched off.
2698 \\<gnus-summary-mode-map>
2699 Each line in this buffer represents one article.  To read an
2700 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2701 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2702 respectively.
2703
2704 You can also post articles and send mail from this buffer.  To
2705 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2706 of an article, type `\\[gnus-summary-reply]'.
2707
2708 There are approx. one gazillion commands you can execute in this
2709 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2710
2711 The following commands are available:
2712
2713 \\{gnus-summary-mode-map}"
2714   (interactive)
2715   (kill-all-local-variables)
2716   (when (gnus-visual-p 'summary-menu 'menu)
2717     (gnus-summary-make-menu-bar)
2718     (gnus-summary-make-tool-bar))
2719   (gnus-summary-make-local-variables)
2720   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2721     (gnus-summary-make-local-variables))
2722   (gnus-make-thread-indent-array)
2723   (gnus-simplify-mode-line)
2724   (setq major-mode 'gnus-summary-mode)
2725   (setq mode-name "Summary")
2726   (make-local-variable 'minor-mode-alist)
2727   (use-local-map gnus-summary-mode-map)
2728   (buffer-disable-undo)
2729   (setq buffer-read-only t              ;Disable modification
2730         show-trailing-whitespace nil)
2731   (setq truncate-lines t)
2732   (setq selective-display t)
2733   (setq selective-display-ellipses t)   ;Display `...'
2734   (gnus-summary-set-display-table)
2735   (gnus-set-default-directory)
2736   (setq gnus-newsgroup-name group)
2737   (unless (gnus-news-group-p group)
2738     (setq gnus-newsgroup-incorporated
2739           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2740   (make-local-variable 'gnus-summary-line-format)
2741   (make-local-variable 'gnus-summary-line-format-spec)
2742   (make-local-variable 'gnus-summary-dummy-line-format)
2743   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2744   (make-local-variable 'gnus-summary-mark-positions)
2745   (gnus-make-local-hook 'pre-command-hook)
2746   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2747   (gnus-run-hooks 'gnus-summary-mode-hook)
2748   (turn-on-gnus-mailing-list-mode)
2749   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2750   (gnus-update-summary-mark-positions))
2751
2752 (defun gnus-summary-make-local-variables ()
2753   "Make all the local summary buffer variables."
2754   (let (global)
2755     (dolist (local gnus-summary-local-variables)
2756       (if (consp local)
2757           (progn
2758             (if (eq (cdr local) 'global)
2759                 ;; Copy the global value of the variable.
2760                 (setq global (symbol-value (car local)))
2761               ;; Use the value from the list.
2762               (setq global (eval (cdr local))))
2763             (set (make-local-variable (car local)) global))
2764         ;; Simple nil-valued local variable.
2765         (set (make-local-variable local) nil)))))
2766
2767 (defun gnus-summary-clear-local-variables ()
2768   (let ((locals gnus-summary-local-variables))
2769     (while locals
2770       (if (consp (car locals))
2771           (and (vectorp (caar locals))
2772                (set (caar locals) nil))
2773         (and (vectorp (car locals))
2774              (set (car locals) nil)))
2775       (setq locals (cdr locals)))))
2776
2777 ;; Summary data functions.
2778
2779 (defmacro gnus-data-number (data)
2780   `(car ,data))
2781
2782 (defmacro gnus-data-set-number (data number)
2783   `(setcar ,data ,number))
2784
2785 (defmacro gnus-data-mark (data)
2786   `(nth 1 ,data))
2787
2788 (defmacro gnus-data-set-mark (data mark)
2789   `(setcar (nthcdr 1 ,data) ,mark))
2790
2791 (defmacro gnus-data-pos (data)
2792   `(nth 2 ,data))
2793
2794 (defmacro gnus-data-set-pos (data pos)
2795   `(setcar (nthcdr 2 ,data) ,pos))
2796
2797 (defmacro gnus-data-header (data)
2798   `(nth 3 ,data))
2799
2800 (defmacro gnus-data-set-header (data header)
2801   `(setcar (nthcdr 3 ,data) ,header))
2802
2803 (defmacro gnus-data-level (data)
2804   `(nth 4 ,data))
2805
2806 (defmacro gnus-data-unread-p (data)
2807   `(= (nth 1 ,data) gnus-unread-mark))
2808
2809 (defmacro gnus-data-read-p (data)
2810   `(/= (nth 1 ,data) gnus-unread-mark))
2811
2812 (defmacro gnus-data-pseudo-p (data)
2813   `(consp (nth 3 ,data)))
2814
2815 (defmacro gnus-data-find (number)
2816   `(assq ,number gnus-newsgroup-data))
2817
2818 (defmacro gnus-data-find-list (number &optional data)
2819   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2820      (memq (assq ,number bdata)
2821            bdata)))
2822
2823 (defmacro gnus-data-make (number mark pos header level)
2824   `(list ,number ,mark ,pos ,header ,level))
2825
2826 (defun gnus-data-enter (after-article number mark pos header level offset)
2827   (let ((data (gnus-data-find-list after-article)))
2828     (unless data
2829       (error "No such article: %d" after-article))
2830     (setcdr data (cons (gnus-data-make number mark pos header level)
2831                        (cdr data)))
2832     (setq gnus-newsgroup-data-reverse nil)
2833     (gnus-data-update-list (cddr data) offset)))
2834
2835 (defun gnus-data-enter-list (after-article list &optional offset)
2836   (when list
2837     (let ((data (and after-article (gnus-data-find-list after-article)))
2838           (ilist list))
2839       (if (not (or data
2840                    after-article))
2841           (let ((odata gnus-newsgroup-data))
2842             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2843             (when offset
2844               (gnus-data-update-list odata offset)))
2845         ;; Find the last element in the list to be spliced into the main
2846         ;; list.
2847         (while (cdr list)
2848           (setq list (cdr list)))
2849         (if (not data)
2850             (progn
2851               (setcdr list gnus-newsgroup-data)
2852               (setq gnus-newsgroup-data ilist)
2853               (when offset
2854                 (gnus-data-update-list (cdr list) offset)))
2855           (setcdr list (cdr data))
2856           (setcdr data ilist)
2857           (when offset
2858             (gnus-data-update-list (cdr list) offset))))
2859       (setq gnus-newsgroup-data-reverse nil))))
2860
2861 (defun gnus-data-remove (article &optional offset)
2862   (let ((data gnus-newsgroup-data))
2863     (if (= (gnus-data-number (car data)) article)
2864         (progn
2865           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2866                 gnus-newsgroup-data-reverse nil)
2867           (when offset
2868             (gnus-data-update-list gnus-newsgroup-data offset)))
2869       (while (cdr data)
2870         (when (= (gnus-data-number (cadr data)) article)
2871           (setcdr data (cddr data))
2872           (when offset
2873             (gnus-data-update-list (cdr data) offset))
2874           (setq data nil
2875                 gnus-newsgroup-data-reverse nil))
2876         (setq data (cdr data))))))
2877
2878 (defmacro gnus-data-list (backward)
2879   `(if ,backward
2880        (or gnus-newsgroup-data-reverse
2881            (setq gnus-newsgroup-data-reverse
2882                  (reverse gnus-newsgroup-data)))
2883      gnus-newsgroup-data))
2884
2885 (defun gnus-data-update-list (data offset)
2886   "Add OFFSET to the POS of all data entries in DATA."
2887   (setq gnus-newsgroup-data-reverse nil)
2888   (while data
2889     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2890     (setq data (cdr data))))
2891
2892 (defun gnus-summary-article-pseudo-p (article)
2893   "Say whether this article is a pseudo article or not."
2894   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2895
2896 (defmacro gnus-summary-article-sparse-p (article)
2897   "Say whether this article is a sparse article or not."
2898   `(memq ,article gnus-newsgroup-sparse))
2899
2900 (defmacro gnus-summary-article-ancient-p (article)
2901   "Say whether this article is a sparse article or not."
2902   `(memq ,article gnus-newsgroup-ancient))
2903
2904 (defun gnus-article-parent-p (number)
2905   "Say whether this article is a parent or not."
2906   (let ((data (gnus-data-find-list number)))
2907     (and (cdr data)                     ; There has to be an article after...
2908          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2909             (gnus-data-level (nth 1 data))))))
2910
2911 (defun gnus-article-children (number)
2912   "Return a list of all children to NUMBER."
2913   (let* ((data (gnus-data-find-list number))
2914          (level (gnus-data-level (car data)))
2915          children)
2916     (setq data (cdr data))
2917     (while (and data
2918                 (= (gnus-data-level (car data)) (1+ level)))
2919       (push (gnus-data-number (car data)) children)
2920       (setq data (cdr data)))
2921     children))
2922
2923 (defmacro gnus-summary-skip-intangible ()
2924   "If the current article is intangible, then jump to a different article."
2925   '(let ((to (get-text-property (point) 'gnus-intangible)))
2926      (and to (gnus-summary-goto-subject to))))
2927
2928 (defmacro gnus-summary-article-intangible-p ()
2929   "Say whether this article is intangible or not."
2930   '(get-text-property (point) 'gnus-intangible))
2931
2932 (defun gnus-article-read-p (article)
2933   "Say whether ARTICLE is read or not."
2934   (not (or (memq article gnus-newsgroup-marked)
2935            (memq article gnus-newsgroup-spam-marked)
2936            (memq article gnus-newsgroup-unreads)
2937            (memq article gnus-newsgroup-unselected)
2938            (memq article gnus-newsgroup-dormant))))
2939
2940 ;; Some summary mode macros.
2941
2942 (defmacro gnus-summary-article-number ()
2943   "The article number of the article on the current line.
2944 If there isn't an article number here, then we return the current
2945 article number."
2946   '(progn
2947      (gnus-summary-skip-intangible)
2948      (or (get-text-property (point) 'gnus-number)
2949          (gnus-summary-last-subject))))
2950
2951 (defmacro gnus-summary-article-header (&optional number)
2952   "Return the header of article NUMBER."
2953   `(gnus-data-header (gnus-data-find
2954                       ,(or number '(gnus-summary-article-number)))))
2955
2956 (defmacro gnus-summary-thread-level (&optional number)
2957   "Return the level of thread that starts with article NUMBER."
2958   `(if (and (eq gnus-summary-make-false-root 'dummy)
2959             (get-text-property (point) 'gnus-intangible))
2960        0
2961      (gnus-data-level (gnus-data-find
2962                        ,(or number '(gnus-summary-article-number))))))
2963
2964 (defmacro gnus-summary-article-mark (&optional number)
2965   "Return the mark of article NUMBER."
2966   `(gnus-data-mark (gnus-data-find
2967                     ,(or number '(gnus-summary-article-number)))))
2968
2969 (defmacro gnus-summary-article-pos (&optional number)
2970   "Return the position of the line of article NUMBER."
2971   `(gnus-data-pos (gnus-data-find
2972                    ,(or number '(gnus-summary-article-number)))))
2973
2974 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2975 (defmacro gnus-summary-article-subject (&optional number)
2976   "Return current subject string or nil if nothing."
2977   `(let ((headers
2978           ,(if number
2979                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2980              '(gnus-data-header (assq (gnus-summary-article-number)
2981                                       gnus-newsgroup-data)))))
2982      (and headers
2983           (vectorp headers)
2984           (mail-header-subject headers))))
2985
2986 (defmacro gnus-summary-article-score (&optional number)
2987   "Return current article score."
2988   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2989                   gnus-newsgroup-scored))
2990        gnus-summary-default-score 0))
2991
2992 (defun gnus-summary-article-children (&optional number)
2993   "Return a list of article numbers that are children of article NUMBER."
2994   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2995          (level (gnus-data-level (car data)))
2996          l children)
2997     (while (and (setq data (cdr data))
2998                 (> (setq l (gnus-data-level (car data))) level))
2999       (and (= (1+ level) l)
3000            (push (gnus-data-number (car data))
3001                  children)))
3002     (nreverse children)))
3003
3004 (defun gnus-summary-article-parent (&optional number)
3005   "Return the article number of the parent of article NUMBER."
3006   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3007                                     (gnus-data-list t)))
3008          (level (gnus-data-level (car data))))
3009     (if (zerop level)
3010         ()                              ; This is a root.
3011       ;; We search until we find an article with a level less than
3012       ;; this one.  That function has to be the parent.
3013       (while (and (setq data (cdr data))
3014                   (not (< (gnus-data-level (car data)) level))))
3015       (and data (gnus-data-number (car data))))))
3016
3017 (defun gnus-unread-mark-p (mark)
3018   "Say whether MARK is the unread mark."
3019   (= mark gnus-unread-mark))
3020
3021 (defun gnus-read-mark-p (mark)
3022   "Say whether MARK is one of the marks that mark as read.
3023 This is all marks except unread, ticked, dormant, and expirable."
3024   (not (or (= mark gnus-unread-mark)
3025            (= mark gnus-ticked-mark)
3026            (= mark gnus-spam-mark)
3027            (= mark gnus-dormant-mark)
3028            (= mark gnus-expirable-mark))))
3029
3030 (defmacro gnus-article-mark (number)
3031   "Return the MARK of article NUMBER.
3032 This macro should only be used when computing the mark the \"first\"
3033 time; i.e., when generating the summary lines.  After that,
3034 `gnus-summary-article-mark' should be used to examine the
3035 marks of articles."
3036   `(cond
3037     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3038     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3039     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3040     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3041     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3042     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3043     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3044     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3045            gnus-ancient-mark))))
3046
3047 ;; Saving hidden threads.
3048
3049 (defmacro gnus-save-hidden-threads (&rest forms)
3050   "Save hidden threads, eval FORMS, and restore the hidden threads."
3051   (let ((config (make-symbol "config")))
3052     `(let ((,config (gnus-hidden-threads-configuration)))
3053        (unwind-protect
3054            (save-excursion
3055              ,@forms)
3056          (gnus-restore-hidden-threads-configuration ,config)))))
3057 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3058 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3059
3060 (defun gnus-data-compute-positions ()
3061   "Compute the positions of all articles."
3062   (setq gnus-newsgroup-data-reverse nil)
3063   (let ((data gnus-newsgroup-data))
3064     (save-excursion
3065       (gnus-save-hidden-threads
3066         (gnus-summary-show-all-threads)
3067         (goto-char (point-min))
3068         (while data
3069           (while (get-text-property (point) 'gnus-intangible)
3070             (forward-line 1))
3071           (gnus-data-set-pos (car data) (+ (point) 3))
3072           (setq data (cdr data))
3073           (forward-line 1))))))
3074
3075 (defun gnus-hidden-threads-configuration ()
3076   "Return the current hidden threads configuration."
3077   (save-excursion
3078     (let (config)
3079       (goto-char (point-min))
3080       (while (search-forward "\r" nil t)
3081         (push (1- (point)) config))
3082       config)))
3083
3084 (defun gnus-restore-hidden-threads-configuration (config)
3085   "Restore hidden threads configuration from CONFIG."
3086   (save-excursion
3087     (let (point buffer-read-only)
3088       (while (setq point (pop config))
3089         (when (and (< point (point-max))
3090                    (goto-char point)
3091                    (eq (char-after) ?\n))
3092           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3093
3094 ;; Various summary mode internalish functions.
3095
3096 (defun gnus-mouse-pick-article (e)
3097   (interactive "e")
3098   (mouse-set-point e)
3099   (gnus-summary-next-page nil t))
3100
3101 (defun gnus-summary-set-display-table ()
3102   "Change the display table.
3103 Odd characters have a tendency to mess
3104 up nicely formatted displays - we make all possible glyphs
3105 display only a single character."
3106
3107   ;; We start from the standard display table, if any.
3108   (let ((table (or (copy-sequence standard-display-table)
3109                    (make-display-table)))
3110         (i 32))
3111     ;; Nix out all the control chars...
3112     (while (>= (setq i (1- i)) 0)
3113       (aset table i [??]))
3114     ;; ... but not newline and cr, of course.  (cr is necessary for the
3115     ;; selective display).
3116     (aset table ?\n nil)
3117     (aset table ?\r nil)
3118     ;; We keep TAB as well.
3119     (aset table ?\t nil)
3120     ;; We nix out any glyphs over 126 that are not set already.
3121     (let ((i 256))
3122       (while (>= (setq i (1- i)) 127)
3123         ;; Only modify if the entry is nil.
3124         (unless (aref table i)
3125           (aset table i [??]))))
3126     (setq buffer-display-table table)))
3127
3128 (defun gnus-summary-set-article-display-arrow (pos)
3129   "Update the overlay arrow to point to line at position POS."
3130   (when (and gnus-summary-display-arrow
3131              (boundp 'overlay-arrow-position)
3132              (boundp 'overlay-arrow-string))
3133     (save-excursion
3134       (goto-char pos)
3135       (beginning-of-line)
3136       (unless overlay-arrow-position
3137         (setq overlay-arrow-position (make-marker)))
3138       (setq overlay-arrow-string "=>"
3139             overlay-arrow-position (set-marker overlay-arrow-position
3140                                                (point)
3141                                                (current-buffer))))))
3142
3143 (defun gnus-summary-setup-buffer (group)
3144   "Initialize summary buffer."
3145   (let ((buffer (gnus-summary-buffer-name group))
3146         (dead-name (concat "*Dead Summary "
3147                            (gnus-group-decoded-name group) "*")))
3148     ;; If a dead summary buffer exists, we kill it.
3149     (when (gnus-buffer-live-p dead-name)
3150       (gnus-kill-buffer dead-name))
3151     (if (get-buffer buffer)
3152         (progn
3153           (set-buffer buffer)
3154           (setq gnus-summary-buffer (current-buffer))
3155           (not gnus-newsgroup-prepared))
3156       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3157       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3158       (gnus-summary-mode group)
3159       (when gnus-carpal
3160         (gnus-carpal-setup-buffer 'summary))
3161       (unless gnus-single-article-buffer
3162         (make-local-variable 'gnus-article-buffer)
3163         (make-local-variable 'gnus-article-current)
3164         (make-local-variable 'gnus-original-article-buffer))
3165       (setq gnus-newsgroup-name group)
3166       ;; Set any local variables in the group parameters.
3167       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3168       t)))
3169
3170 (defun gnus-set-global-variables ()
3171   "Set the global equivalents of the buffer-local variables.
3172 They are set to the latest values they had.  These reflect the summary
3173 buffer that was in action when the last article was fetched."
3174   (when (eq major-mode 'gnus-summary-mode)
3175     (setq gnus-summary-buffer (current-buffer))
3176     (let ((name gnus-newsgroup-name)
3177           (marked gnus-newsgroup-marked)
3178           (spam gnus-newsgroup-spam-marked)
3179           (unread gnus-newsgroup-unreads)
3180           (headers gnus-current-headers)
3181           (data gnus-newsgroup-data)
3182           (summary gnus-summary-buffer)
3183           (article-buffer gnus-article-buffer)
3184           (original gnus-original-article-buffer)
3185           (gac gnus-article-current)
3186           (reffed gnus-reffed-article-number)
3187           (score-file gnus-current-score-file)
3188           (default-charset gnus-newsgroup-charset)
3189           vlist)
3190       (let ((locals gnus-newsgroup-variables))
3191         (while locals
3192           (if (consp (car locals))
3193               (push (eval (caar locals)) vlist)
3194             (push (eval (car locals)) vlist))
3195           (setq locals (cdr locals)))
3196         (setq vlist (nreverse vlist)))
3197       (with-current-buffer gnus-group-buffer
3198         (setq gnus-newsgroup-name name
3199               gnus-newsgroup-marked marked
3200               gnus-newsgroup-spam-marked spam
3201               gnus-newsgroup-unreads unread
3202               gnus-current-headers headers
3203               gnus-newsgroup-data data
3204               gnus-article-current gac
3205               gnus-summary-buffer summary
3206               gnus-article-buffer article-buffer
3207               gnus-original-article-buffer original
3208               gnus-reffed-article-number reffed
3209               gnus-current-score-file score-file
3210               gnus-newsgroup-charset default-charset)
3211         (let ((locals gnus-newsgroup-variables))
3212           (while locals
3213             (if (consp (car locals))
3214                 (set (caar locals) (pop vlist))
3215               (set (car locals) (pop vlist)))
3216             (setq locals (cdr locals))))
3217         ;; The article buffer also has local variables.
3218         (when (gnus-buffer-live-p gnus-article-buffer)
3219           (set-buffer gnus-article-buffer)
3220           (setq gnus-summary-buffer summary))))))
3221
3222 (defun gnus-summary-article-unread-p (article)
3223   "Say whether ARTICLE is unread or not."
3224   (memq article gnus-newsgroup-unreads))
3225
3226 (defun gnus-summary-first-article-p (&optional article)
3227   "Return whether ARTICLE is the first article in the buffer."
3228   (if (not (setq article (or article (gnus-summary-article-number))))
3229       nil
3230     (eq article (caar gnus-newsgroup-data))))
3231
3232 (defun gnus-summary-last-article-p (&optional article)
3233   "Return whether ARTICLE is the last article in the buffer."
3234   (if (not (setq article (or article (gnus-summary-article-number))))
3235       ;; All non-existent numbers are the last article.  :-)
3236       t
3237     (not (cdr (gnus-data-find-list article)))))
3238
3239 (defun gnus-make-thread-indent-array ()
3240   (let ((n 200))
3241     (unless (and gnus-thread-indent-array
3242                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3243       (setq gnus-thread-indent-array (make-vector 201 "")
3244             gnus-thread-indent-array-level gnus-thread-indent-level)
3245       (while (>= n 0)
3246         (aset gnus-thread-indent-array n
3247               (make-string (* n gnus-thread-indent-level) ? ))
3248         (setq n (1- n))))))
3249
3250 (defun gnus-update-summary-mark-positions ()
3251   "Compute where the summary marks are to go."
3252   (save-excursion
3253     (when (gnus-buffer-exists-p gnus-summary-buffer)
3254       (set-buffer gnus-summary-buffer))
3255     (let ((gnus-replied-mark 129)
3256           (gnus-score-below-mark 130)
3257           (gnus-score-over-mark 130)
3258           (gnus-undownloaded-mark 131)
3259           (spec gnus-summary-line-format-spec)
3260           gnus-visual pos)
3261       (save-excursion
3262         (gnus-set-work-buffer)
3263         (let ((gnus-summary-line-format-spec spec)
3264               (gnus-newsgroup-downloadable '(0)))
3265           (gnus-summary-insert-line
3266            (make-full-mail-header 0 "" "nobody"
3267                                   "05 Apr 2001 23:33:09 +0400"
3268                                   "" "" 0 0 "" nil)
3269            0 nil t 128 t nil "" nil 1)
3270           (goto-char (point-min))
3271           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3272                                              (- (point) (point-min) 1)))))
3273           (goto-char (point-min))
3274           (push (cons 'replied (and (search-forward "\201" nil t)
3275                                     (- (point) (point-min) 1)))
3276                 pos)
3277           (goto-char (point-min))
3278           (push (cons 'score (and (search-forward "\202" nil t)
3279                                   (- (point) (point-min) 1)))
3280                 pos)
3281           (goto-char (point-min))
3282           (push (cons 'download
3283                       (and (search-forward "\203" nil t)
3284                            (- (point) (point-min) 1)))
3285                 pos)))
3286       (setq gnus-summary-mark-positions pos))))
3287
3288 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3289   "Insert a dummy root in the summary buffer."
3290   (beginning-of-line)
3291   (gnus-add-text-properties
3292    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3293    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3294
3295 (defun gnus-summary-extract-address-component (from)
3296   (or (car (funcall gnus-extract-address-components from))
3297       from))
3298
3299 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3300   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3301                                 default-mime-charset)))
3302     ;; Is it really necessary to do this next part for each summary line?
3303     ;; Luckily, doesn't seem to slow things down much.
3304     (or
3305      (and gnus-ignored-from-addresses
3306           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3307           (let ((extra-headers (mail-header-extra header))
3308                 to
3309                 newsgroups)
3310             (cond
3311              ((setq to (cdr (assq 'To extra-headers)))
3312               (concat "-> "
3313                       (inline
3314                         (gnus-summary-extract-address-component
3315                          (funcall gnus-decode-encoded-word-function to)))))
3316              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3317               (concat "=> " newsgroups)))))
3318      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3319
3320 (defun gnus-summary-insert-line (gnus-tmp-header
3321                                  gnus-tmp-level gnus-tmp-current
3322                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3323                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3324                                  &optional gnus-tmp-dummy gnus-tmp-score
3325                                  gnus-tmp-process)
3326   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3327          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3328          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3329          (gnus-tmp-score-char
3330           (if (or (null gnus-summary-default-score)
3331                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3332                       gnus-summary-zcore-fuzz))
3333               ?\ ;;;Whitespace
3334             (if (< gnus-tmp-score gnus-summary-default-score)
3335                 gnus-score-below-mark gnus-score-over-mark)))
3336          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3337          (gnus-tmp-replied
3338           (cond (gnus-tmp-process gnus-process-mark)
3339                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3340                  gnus-cached-mark)
3341                 (gnus-tmp-replied gnus-replied-mark)
3342                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3343                  gnus-forwarded-mark)
3344                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3345                  gnus-saved-mark)
3346                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3347                  gnus-recent-mark)
3348                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3349                  gnus-unseen-mark)
3350                 (t gnus-no-mark)))
3351          (gnus-tmp-downloaded
3352           (cond (undownloaded
3353                  gnus-undownloaded-mark)
3354                 (gnus-newsgroup-agentized
3355                  gnus-downloaded-mark)
3356                 (t
3357                  gnus-no-mark)))
3358          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3359          (gnus-tmp-name
3360           (cond
3361            ((string-match "<[^>]+> *$" gnus-tmp-from)
3362             (let ((beg (match-beginning 0)))
3363               (or (and (string-match "^\".+\"" gnus-tmp-from)
3364                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3365                   (substring gnus-tmp-from 0 beg))))
3366            ((string-match "(.+)" gnus-tmp-from)
3367             (substring gnus-tmp-from
3368                        (1+ (match-beginning 0)) (1- (match-end 0))))
3369            (t gnus-tmp-from)))
3370          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3371          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3372          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3373          (buffer-read-only nil))
3374     (when (string= gnus-tmp-name "")
3375       (setq gnus-tmp-name gnus-tmp-from))
3376     (unless (numberp gnus-tmp-lines)
3377       (setq gnus-tmp-lines -1))
3378     (if (= gnus-tmp-lines -1)
3379         (setq gnus-tmp-lines "?")
3380       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3381     (gnus-put-text-property-excluding-characters-with-faces
3382      (point)
3383      (progn (eval gnus-summary-line-format-spec) (point))
3384      'gnus-number gnus-tmp-number)
3385     (when (gnus-visual-p 'summary-highlight 'highlight)
3386       (forward-line -1)
3387       (gnus-run-hooks 'gnus-summary-update-hook)
3388       (forward-line 1))))
3389
3390 (defun gnus-summary-update-line (&optional dont-update)
3391   "Update summary line after change."
3392   (when (and gnus-summary-default-score
3393              (not gnus-summary-inhibit-highlight))
3394     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3395            (article (gnus-summary-article-number))
3396            (score (gnus-summary-article-score article)))
3397       (unless dont-update
3398         (if (and gnus-summary-mark-below
3399                  (< (gnus-summary-article-score)
3400                     gnus-summary-mark-below))
3401             ;; This article has a low score, so we mark it as read.
3402             (when (memq article gnus-newsgroup-unreads)
3403               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3404           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3405             ;; This article was previously marked as read on account
3406             ;; of a low score, but now it has risen, so we mark it as
3407             ;; unread.
3408             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3409         (gnus-summary-update-mark
3410          (if (or (null gnus-summary-default-score)
3411                  (<= (abs (- score gnus-summary-default-score))
3412                      gnus-summary-zcore-fuzz))
3413              ?\ ;;;Whitespace
3414            (if (< score gnus-summary-default-score)
3415                gnus-score-below-mark gnus-score-over-mark))
3416          'score))
3417       ;; Do visual highlighting.
3418       (when (gnus-visual-p 'summary-highlight 'highlight)
3419         (gnus-run-hooks 'gnus-summary-update-hook)))))
3420
3421 (defvar gnus-tmp-new-adopts nil)
3422
3423 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3424   "Return the number of articles in THREAD.
3425 This may be 0 in some cases -- if none of the articles in
3426 the thread are to be displayed."
3427   (let* ((number
3428           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3429           (cond
3430            ((not (listp thread))
3431             1)
3432            ((and (consp thread) (cdr thread))
3433             (apply
3434              '+ 1 (mapcar
3435                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3436            ((null thread)
3437             1)
3438            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3439             1)
3440            (t 0))))
3441     (when (and level (zerop level) gnus-tmp-new-adopts)
3442       (incf number
3443             (apply '+ (mapcar
3444                        'gnus-summary-number-of-articles-in-thread
3445                        gnus-tmp-new-adopts))))
3446     (if char
3447         (if (> number 1) gnus-not-empty-thread-mark
3448           gnus-empty-thread-mark)
3449       number)))
3450
3451 (defsubst gnus-summary-line-message-size (head)
3452   "Return pretty-printed version of message size.
3453 This function is intended to be used in
3454 `gnus-summary-line-format-alist'."
3455   (let ((c (or (mail-header-chars head) -1)))
3456     (cond ((< c 0) "n/a")               ; chars not available
3457           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3458           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3459           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3460           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3461
3462
3463 (defun gnus-summary-set-local-parameters (group)
3464   "Go through the local params of GROUP and set all variable specs in that list."
3465   (let ((params (gnus-group-find-parameter group))
3466         (vars '(quit-config))           ; Ignore quit-config.
3467         elem)
3468     (while params
3469       (setq elem (car params)
3470             params (cdr params))
3471       (and (consp elem)                 ; Has to be a cons.
3472            (consp (cdr elem))           ; The cdr has to be a list.
3473            (symbolp (car elem))         ; Has to be a symbol in there.
3474            (not (memq (car elem) vars))
3475            (ignore-errors               ; So we set it.
3476              (push (car elem) vars)
3477              (make-local-variable (car elem))
3478              (set (car elem) (eval (nth 1 elem))))))))
3479
3480 (defun gnus-summary-read-group (group &optional show-all no-article
3481                                       kill-buffer no-display backward
3482                                       select-articles)
3483   "Start reading news in newsgroup GROUP.
3484 If SHOW-ALL is non-nil, already read articles are also listed.
3485 If NO-ARTICLE is non-nil, no article is selected initially.
3486 If NO-DISPLAY, don't generate a summary buffer."
3487   (let (result)
3488     (while (and group
3489                 (null (setq result
3490                             (let ((gnus-auto-select-next nil))
3491                               (or (gnus-summary-read-group-1
3492                                    group show-all no-article
3493                                    kill-buffer no-display
3494                                    select-articles)
3495                                   (setq show-all nil
3496                                         select-articles nil)))))
3497                 (eq gnus-auto-select-next 'quietly))
3498       (set-buffer gnus-group-buffer)
3499       ;; The entry function called above goes to the next
3500       ;; group automatically, so we go two groups back
3501       ;; if we are searching for the previous group.
3502       (when backward
3503         (gnus-group-prev-unread-group 2))
3504       (if (not (equal group (gnus-group-group-name)))
3505           (setq group (gnus-group-group-name))
3506         (setq group nil)))
3507     result))
3508
3509 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3510   "Directly jump to the other GROUP from summary buffer.
3511 If SHOW-ALL is non-nil, already read articles are also listed."
3512   (interactive
3513    (if (eq gnus-summary-buffer (current-buffer))
3514        (list (completing-read
3515               "Group: " gnus-active-hashtb nil t
3516               (when (and gnus-newsgroup-name
3517                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3518                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3519               'gnus-group-history)
3520              current-prefix-arg)
3521      (error "%s must be invoked from a gnus summary buffer." this-command)))
3522   (unless (or (zerop (length group))
3523               (and gnus-newsgroup-name
3524                    (string-equal gnus-newsgroup-name group)))
3525     (gnus-summary-exit)
3526     (gnus-summary-read-group group show-all
3527                              gnus-dont-select-after-jump-to-other-group)))
3528
3529 (defun gnus-summary-read-group-1 (group show-all no-article
3530                                         kill-buffer no-display
3531                                         &optional select-articles)
3532   ;; Killed foreign groups can't be entered.
3533   ;;  (when (and (not (gnus-group-native-p group))
3534   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3535   ;;    (error "Dead non-native groups can't be entered"))
3536   (gnus-message 5 "Retrieving newsgroup: %s..."
3537                 (gnus-group-decoded-name group))
3538   (let* ((new-group (gnus-summary-setup-buffer group))
3539          (quit-config (gnus-group-quit-config group))
3540          (did-select (and new-group (gnus-select-newsgroup
3541                                      group show-all select-articles))))
3542     (cond
3543      ;; This summary buffer exists already, so we just select it.
3544      ((not new-group)
3545       (gnus-set-global-variables)
3546       (when kill-buffer
3547         (gnus-kill-or-deaden-summary kill-buffer))
3548       (gnus-configure-windows 'summary 'force)
3549       (gnus-set-mode-line 'summary)
3550       (gnus-summary-position-point)
3551       (message "")
3552       t)
3553      ;; We couldn't select this group.
3554      ((null did-select)
3555       (when (and (eq major-mode 'gnus-summary-mode)
3556                  (not (equal (current-buffer) kill-buffer)))
3557         (kill-buffer (current-buffer))
3558         (if (not quit-config)
3559             (progn
3560               ;; Update the info -- marks might need to be removed,
3561               ;; for instance.
3562               (gnus-summary-update-info)
3563               (set-buffer gnus-group-buffer)
3564               (gnus-group-jump-to-group group)
3565               (gnus-group-next-unread-group 1))
3566           (gnus-handle-ephemeral-exit quit-config)))
3567       (let ((grpinfo (gnus-get-info group)))
3568         (if (null (gnus-info-read grpinfo))
3569             (gnus-message 3 "Group %s contains no messages"
3570                           (gnus-group-decoded-name group))
3571           (gnus-message 3 "Can't select group")))
3572       nil)
3573      ;; The user did a `C-g' while prompting for number of articles,
3574      ;; so we exit this group.
3575      ((eq did-select 'quit)
3576       (and (eq major-mode 'gnus-summary-mode)
3577            (not (equal (current-buffer) kill-buffer))
3578            (kill-buffer (current-buffer)))
3579       (when kill-buffer
3580         (gnus-kill-or-deaden-summary kill-buffer))
3581       (if (not quit-config)
3582           (progn
3583             (set-buffer gnus-group-buffer)
3584             (gnus-group-jump-to-group group)
3585             (gnus-group-next-unread-group 1)
3586             (gnus-configure-windows 'group 'force))
3587         (gnus-handle-ephemeral-exit quit-config))
3588       ;; Finally signal the quit.
3589       (signal 'quit nil))
3590      ;; The group was successfully selected.
3591      (t
3592       (gnus-set-global-variables)
3593       ;; Save the active value in effect when the group was entered.
3594       (setq gnus-newsgroup-active
3595             (gnus-copy-sequence
3596              (gnus-active gnus-newsgroup-name)))
3597       ;; You can change the summary buffer in some way with this hook.
3598       (gnus-run-hooks 'gnus-select-group-hook)
3599       (gnus-update-format-specifications
3600        nil 'summary 'summary-mode 'summary-dummy)
3601       (gnus-update-summary-mark-positions)
3602       ;; Do score processing.
3603       (when gnus-use-scoring
3604         (gnus-possibly-score-headers))
3605       ;; Check whether to fill in the gaps in the threads.
3606       (when gnus-build-sparse-threads
3607         (gnus-build-sparse-threads))
3608       ;; Find the initial limit.
3609       (if show-all
3610           (let ((gnus-newsgroup-dormant nil))
3611             (gnus-summary-initial-limit show-all))
3612         (gnus-summary-initial-limit show-all))
3613       ;; Generate the summary buffer.
3614       (unless no-display
3615         (gnus-summary-prepare))
3616       (when gnus-use-trees
3617         (gnus-tree-open group)
3618         (setq gnus-summary-highlight-line-function
3619               'gnus-tree-highlight-article))
3620       ;; If the summary buffer is empty, but there are some low-scored
3621       ;; articles or some excluded dormants, we include these in the
3622       ;; buffer.
3623       (when (and (zerop (buffer-size))
3624                  (not no-display))
3625         (cond (gnus-newsgroup-dormant
3626                (gnus-summary-limit-include-dormant))
3627               ((and gnus-newsgroup-scored show-all)
3628                (gnus-summary-limit-include-expunged t))))
3629       ;; Function `gnus-apply-kill-file' must be called in this hook.
3630       (gnus-run-hooks 'gnus-apply-kill-hook)
3631       (if (and (zerop (buffer-size))
3632                (not no-display))
3633           (progn
3634             ;; This newsgroup is empty.
3635             (gnus-summary-catchup-and-exit nil t)
3636             (gnus-message 6 "No unread news")
3637             (when kill-buffer
3638               (gnus-kill-or-deaden-summary kill-buffer))
3639             ;; Return nil from this function.
3640             nil)
3641         ;; Hide conversation thread subtrees.  We cannot do this in
3642         ;; gnus-summary-prepare-hook since kill processing may not
3643         ;; work with hidden articles.
3644         (gnus-summary-maybe-hide-threads)
3645         (when kill-buffer
3646           (gnus-kill-or-deaden-summary kill-buffer))
3647         (gnus-summary-auto-select-subject)
3648         ;; Show first unread article if requested.
3649         (if (and (not no-article)
3650                  (not no-display)
3651                  gnus-newsgroup-unreads
3652                  gnus-auto-select-first)
3653             (progn
3654               (gnus-configure-windows 'summary)
3655               (let ((art (gnus-summary-article-number)))
3656                 (unless (and (not gnus-plugged)
3657                              (or (memq art gnus-newsgroup-undownloaded)
3658                                  (memq art gnus-newsgroup-downloadable)))
3659                   (gnus-summary-goto-article art))))
3660           ;; Don't select any articles.
3661           (gnus-summary-position-point)
3662           (gnus-configure-windows 'summary 'force)
3663           (gnus-set-mode-line 'summary))
3664         (when (and gnus-auto-center-group
3665                    (get-buffer-window gnus-group-buffer t))
3666           ;; Gotta use windows, because recenter does weird stuff if
3667           ;; the current buffer ain't the displayed window.
3668           (let ((owin (selected-window)))
3669             (select-window (get-buffer-window gnus-group-buffer t))
3670             (when (gnus-group-goto-group group)
3671               (recenter))
3672             (select-window owin)))
3673         ;; Mark this buffer as "prepared".
3674         (setq gnus-newsgroup-prepared t)
3675         (gnus-run-hooks 'gnus-summary-prepared-hook)
3676         (unless (gnus-ephemeral-group-p group)
3677           (gnus-group-update-group group))
3678         t)))))
3679
3680 (defun gnus-summary-auto-select-subject ()
3681   "Select the subject line on initial group entry."
3682   (goto-char (point-min))
3683   (cond
3684    ((eq gnus-auto-select-subject 'best)
3685     (gnus-summary-best-unread-subject))
3686    ((eq gnus-auto-select-subject 'unread)
3687     (gnus-summary-first-unread-subject))
3688    ((eq gnus-auto-select-subject 'unseen)
3689     (gnus-summary-first-unseen-subject))
3690    ((eq gnus-auto-select-subject 'unseen-or-unread)
3691     (gnus-summary-first-unseen-or-unread-subject))
3692    ((eq gnus-auto-select-subject 'first)
3693     ;; Do nothing.
3694     )
3695    ((functionp gnus-auto-select-subject)
3696     (funcall gnus-auto-select-subject))))
3697
3698 (defun gnus-summary-prepare ()
3699   "Generate the summary buffer."
3700   (interactive)
3701   (let ((buffer-read-only nil))
3702     (erase-buffer)
3703     (setq gnus-newsgroup-data nil
3704           gnus-newsgroup-data-reverse nil)
3705     (gnus-run-hooks 'gnus-summary-generate-hook)
3706     ;; Generate the buffer, either with threads or without.
3707     (when gnus-newsgroup-headers
3708       (gnus-summary-prepare-threads
3709        (if gnus-show-threads
3710            (gnus-sort-gathered-threads
3711             (funcall gnus-summary-thread-gathering-function
3712                      (gnus-sort-threads
3713                       (gnus-cut-threads (gnus-make-threads)))))
3714          ;; Unthreaded display.
3715          (gnus-sort-articles gnus-newsgroup-headers))))
3716     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3717     ;; Call hooks for modifying summary buffer.
3718     (goto-char (point-min))
3719     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3720
3721 (defsubst gnus-general-simplify-subject (subject)
3722   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3723   (setq subject
3724         (cond
3725          ;; Truncate the subject.
3726          (gnus-simplify-subject-functions
3727           (gnus-map-function gnus-simplify-subject-functions subject))
3728          ((numberp gnus-summary-gather-subject-limit)
3729           (setq subject (gnus-simplify-subject-re subject))
3730           (if (> (length subject) gnus-summary-gather-subject-limit)
3731               (substring subject 0 gnus-summary-gather-subject-limit)
3732             subject))
3733          ;; Fuzzily simplify it.
3734          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3735           (gnus-simplify-subject-fuzzy subject))
3736          ;; Just remove the leading "Re:".
3737          (t
3738           (gnus-simplify-subject-re subject))))
3739
3740   (if (and gnus-summary-gather-exclude-subject
3741            (string-match gnus-summary-gather-exclude-subject subject))
3742       nil                               ; This article shouldn't be gathered
3743     subject))
3744
3745 (defun gnus-summary-simplify-subject-query ()
3746   "Query where the respool algorithm would put this article."
3747   (interactive)
3748   (gnus-summary-select-article)
3749   (message "%s"
3750            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3751
3752 (defun gnus-gather-threads-by-subject (threads)
3753   "Gather threads by looking at Subject headers."
3754   (if (not gnus-summary-make-false-root)
3755       threads
3756     (let ((hashtb (gnus-make-hashtable 1024))
3757           (prev threads)
3758           (result threads)
3759           subject hthread whole-subject)
3760       (while threads
3761         (setq subject (gnus-general-simplify-subject
3762                        (setq whole-subject (mail-header-subject
3763                                             (caar threads)))))
3764         (when subject
3765           (if (setq hthread (gnus-gethash subject hashtb))
3766               (progn
3767                 ;; We enter a dummy root into the thread, if we
3768                 ;; haven't done that already.
3769                 (unless (stringp (caar hthread))
3770                   (setcar hthread (list whole-subject (car hthread))))
3771                 ;; We add this new gathered thread to this gathered
3772                 ;; thread.
3773                 (setcdr (car hthread)
3774                         (nconc (cdar hthread) (list (car threads))))
3775                 ;; Remove it from the list of threads.
3776                 (setcdr prev (cdr threads))
3777                 (setq threads prev))
3778             ;; Enter this thread into the hash table.
3779             (gnus-sethash subject
3780                           (if gnus-summary-make-false-root-always
3781                               (progn
3782                                 ;; If you want a dummy root above all
3783                                 ;; threads...
3784                                 (setcar threads (list whole-subject
3785                                                       (car threads)))
3786                                 threads)
3787                             threads)
3788                           hashtb)))
3789         (setq prev threads)
3790         (setq threads (cdr threads)))
3791       result)))
3792
3793 (defun gnus-gather-threads-by-references (threads)
3794   "Gather threads by looking at References headers."
3795   (let ((idhashtb (gnus-make-hashtable 1024))
3796         (thhashtb (gnus-make-hashtable 1024))
3797         (prev threads)
3798         (result threads)
3799         ids references id gthread gid entered ref)
3800     (while threads
3801       (when (setq references (mail-header-references (caar threads)))
3802         (setq id (mail-header-id (caar threads))
3803               ids (inline (gnus-split-references references))
3804               entered nil)
3805         (while (setq ref (pop ids))
3806           (setq ids (delete ref ids))
3807           (if (not (setq gid (gnus-gethash ref idhashtb)))
3808               (progn
3809                 (gnus-sethash ref id idhashtb)
3810                 (gnus-sethash id threads thhashtb))
3811             (setq gthread (gnus-gethash gid thhashtb))
3812             (unless entered
3813               ;; We enter a dummy root into the thread, if we
3814               ;; haven't done that already.
3815               (unless (stringp (caar gthread))
3816                 (setcar gthread (list (mail-header-subject (caar gthread))
3817                                       (car gthread))))
3818               ;; We add this new gathered thread to this gathered
3819               ;; thread.
3820               (setcdr (car gthread)
3821                       (nconc (cdar gthread) (list (car threads)))))
3822             ;; Add it into the thread hash table.
3823             (gnus-sethash id gthread thhashtb)
3824             (setq entered t)
3825             ;; Remove it from the list of threads.
3826             (setcdr prev (cdr threads))
3827             (setq threads prev))))
3828       (setq prev threads)
3829       (setq threads (cdr threads)))
3830     result))
3831
3832 (defun gnus-sort-gathered-threads (threads)
3833   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3834   (let ((result threads))
3835     (while threads
3836       (when (stringp (caar threads))
3837         (setcdr (car threads)
3838                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3839       (setq threads (cdr threads)))
3840     result))
3841
3842 (defun gnus-thread-loop-p (root thread)
3843   "Say whether ROOT is in THREAD."
3844   (let ((stack (list thread))
3845         (infloop 0)
3846         th)
3847     (while (setq thread (pop stack))
3848       (setq th (cdr thread))
3849       (while (and th
3850                   (not (eq (caar th) root)))
3851         (pop th))
3852       (if th
3853           ;; We have found a loop.
3854           (let (ref-dep)
3855             (setcdr thread (delq (car th) (cdr thread)))
3856             (if (boundp (setq ref-dep (intern "none"
3857                                               gnus-newsgroup-dependencies)))
3858                 (setcdr (symbol-value ref-dep)
3859                         (nconc (cdr (symbol-value ref-dep))
3860                                (list (car th))))
3861               (set ref-dep (list nil (car th))))
3862             (setq infloop 1
3863                   stack nil))
3864         ;; Push all the subthreads onto the stack.
3865         (push (cdr thread) stack)))
3866     infloop))
3867
3868 (defun gnus-make-threads ()
3869   "Go through the dependency hashtb and find the roots.  Return all threads."
3870   (let (threads)
3871     (while (catch 'infloop
3872              (mapatoms
3873               (lambda (refs)
3874                 ;; Deal with self-referencing References loops.
3875                 (when (and (car (symbol-value refs))
3876                            (not (zerop
3877                                  (apply
3878                                   '+
3879                                   (mapcar
3880                                    (lambda (thread)
3881                                      (gnus-thread-loop-p
3882                                       (car (symbol-value refs)) thread))
3883                                    (cdr (symbol-value refs)))))))
3884                   (setq threads nil)
3885                   (throw 'infloop t))
3886                 (unless (car (symbol-value refs))
3887                   ;; These threads do not refer back to any other articles,
3888                   ;; so they're roots.
3889                   (setq threads (append (cdr (symbol-value refs)) threads))))
3890               gnus-newsgroup-dependencies)))
3891     threads))
3892
3893 ;; Build the thread tree.
3894 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3895   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3896
3897 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3898 if it was already present.
3899
3900 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3901 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3902 Message-IDs will be renamed to a unique Message-ID before being
3903 entered.
3904
3905 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3906   (let* ((id (mail-header-id header))
3907          (id-dep (and id (intern id dependencies)))
3908          parent-id ref ref-dep ref-header replaced)
3909     ;; Enter this `header' in the `dependencies' table.
3910     (cond
3911      ((not id-dep)
3912       (setq header nil))
3913      ;; The first two cases do the normal part: enter a new `header'
3914      ;; in the `dependencies' table.
3915      ((not (boundp id-dep))
3916       (set id-dep (list header)))
3917      ((null (car (symbol-value id-dep)))
3918       (setcar (symbol-value id-dep) header))
3919
3920      ;; From here the `header' was already present in the
3921      ;; `dependencies' table.
3922      (force-new
3923       ;; Overrides an existing entry;
3924       ;; just set the header part of the entry.
3925       (setcar (symbol-value id-dep) header)
3926       (setq replaced t))
3927
3928      ;; Renames the existing `header' to a unique Message-ID.
3929      ((not gnus-summary-ignore-duplicates)
3930       ;; An article with this Message-ID has already been seen.
3931       ;; We rename the Message-ID.
3932       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3933            (list header))
3934       (mail-header-set-id header id))
3935
3936      ;; The last case ignores an existing entry, except it adds any
3937      ;; additional Xrefs (in case the two articles came from different
3938      ;; servers.
3939      ;; Also sets `header' to `nil' meaning that the `dependencies'
3940      ;; table was *not* modified.
3941      (t
3942       (mail-header-set-xref
3943        (car (symbol-value id-dep))
3944        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3945                    "")
3946                (or (mail-header-xref header) "")))
3947       (setq header nil)))
3948
3949     (when (and header (not replaced))
3950       ;; First check that we are not creating a References loop.
3951       (setq parent-id (gnus-parent-id (mail-header-references header)))
3952       (setq ref parent-id)
3953       (while (and ref
3954                   (setq ref-dep (intern-soft ref dependencies))
3955                   (boundp ref-dep)
3956                   (setq ref-header (car (symbol-value ref-dep))))
3957         (if (string= id ref)
3958             ;; Yuk!  This is a reference loop.  Make the article be a
3959             ;; root article.
3960             (progn
3961               (mail-header-set-references (car (symbol-value id-dep)) "none")
3962               (setq ref nil)
3963               (setq parent-id nil))
3964           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3965       (setq ref-dep (intern (or parent-id "none") dependencies))
3966       (if (boundp ref-dep)
3967           (setcdr (symbol-value ref-dep)
3968                   (nconc (cdr (symbol-value ref-dep))
3969                          (list (symbol-value id-dep))))
3970         (set ref-dep (list nil (symbol-value id-dep)))))
3971     header))
3972
3973 (defun gnus-extract-message-id-from-in-reply-to (string)
3974   (if (string-match "<[^>]+>" string)
3975       (substring string (match-beginning 0) (match-end 0))
3976     nil))
3977
3978 (defun gnus-build-sparse-threads ()
3979   (let ((headers gnus-newsgroup-headers)
3980         (mail-parse-charset gnus-newsgroup-charset)
3981         (gnus-summary-ignore-duplicates t)
3982         header references generation relations
3983         subject child end new-child date)
3984     ;; First we create an alist of generations/relations, where
3985     ;; generations is how much we trust the relation, and the relation
3986     ;; is parent/child.
3987     (gnus-message 7 "Making sparse threads...")
3988     (save-excursion
3989       (nnheader-set-temp-buffer " *gnus sparse threads*")
3990       (while (setq header (pop headers))
3991         (when (and (setq references (mail-header-references header))
3992                    (not (string= references "")))
3993           (insert references)
3994           (setq child (mail-header-id header)
3995                 subject (mail-header-subject header)
3996                 date (mail-header-date header)
3997                 generation 0)
3998           (while (search-backward ">" nil t)
3999             (setq end (1+ (point)))
4000             (when (search-backward "<" nil t)
4001               (setq new-child (buffer-substring (point) end))
4002               (push (list (incf generation)
4003                           child (setq child new-child)
4004                           subject date)
4005                     relations)))
4006           (when child
4007             (push (list (1+ generation) child nil subject) relations))
4008           (erase-buffer)))
4009       (kill-buffer (current-buffer)))
4010     ;; Sort over trustworthiness.
4011     (mapcar
4012      (lambda (relation)
4013        (when (gnus-dependencies-add-header
4014               (make-full-mail-header-from-decoded-header
4015                gnus-reffed-article-number
4016                (nth 3 relation) "" (or (nth 4 relation) "")
4017                (nth 1 relation)
4018                (or (nth 2 relation) "") 0 0 "")
4019               gnus-newsgroup-dependencies nil)
4020          (push gnus-reffed-article-number gnus-newsgroup-limit)
4021          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4022          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4023                gnus-newsgroup-reads)
4024          (decf gnus-reffed-article-number)))
4025      (sort relations 'car-less-than-car))
4026     (gnus-message 7 "Making sparse threads...done")))
4027
4028 (defun gnus-build-old-threads ()
4029   ;; Look at all the articles that refer back to old articles, and
4030   ;; fetch the headers for the articles that aren't there.  This will
4031   ;; build complete threads - if the roots haven't been expired by the
4032   ;; server, that is.
4033   (let ((mail-parse-charset gnus-newsgroup-charset)
4034         id heads)
4035     (mapatoms
4036      (lambda (refs)
4037        (when (not (car (symbol-value refs)))
4038          (setq heads (cdr (symbol-value refs)))
4039          (while heads
4040            (if (memq (mail-header-number (caar heads))
4041                      gnus-newsgroup-dormant)
4042                (setq heads (cdr heads))
4043              (setq id (symbol-name refs))
4044              (while (and (setq id (gnus-build-get-header id))
4045                          (not (car (gnus-id-to-thread id)))))
4046              (setq heads nil)))))
4047      gnus-newsgroup-dependencies)))
4048
4049 (defsubst gnus-remove-odd-characters (string)
4050   "Translate STRING into something that doesn't contain weird characters."
4051   (mm-subst-char-in-string
4052    ?\r ?\-
4053    (mm-subst-char-in-string ?\n ?\- string t) t))
4054
4055 ;; This function has to be called with point after the article number
4056 ;; on the beginning of the line.
4057 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4058   (let ((eol (point-at-eol))
4059         (buffer (current-buffer))
4060         header references in-reply-to)
4061
4062     ;; overview: [num subject from date id refs chars lines misc]
4063     (unwind-protect
4064         (progn
4065           (narrow-to-region (point) eol)
4066           (unless (eobp)
4067             (forward-char))
4068
4069           (setq header
4070                 (make-full-mail-header
4071                  number                         ; number
4072                  (nnheader-nov-field)           ; subject
4073                  (nnheader-nov-field)           ; from
4074                  (nnheader-nov-field)           ; date
4075                  (nnheader-nov-read-message-id number)  ; id
4076                  (setq references (nnheader-nov-field)) ; refs
4077                  (nnheader-nov-read-integer)    ; chars
4078                  (nnheader-nov-read-integer)    ; lines
4079                  (unless (eobp)
4080                    (if (looking-at "Xref: ")
4081                        (goto-char (match-end 0)))
4082                    (nnheader-nov-field))        ; Xref
4083                  (nnheader-nov-parse-extra))))  ; extra
4084
4085       (widen))
4086
4087     (when (and (string= references "")
4088                (setq in-reply-to (mail-header-extra header))
4089                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4090       (mail-header-set-references
4091        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4092
4093     (when gnus-alter-header-function
4094       (funcall gnus-alter-header-function header))
4095     (gnus-dependencies-add-header header dependencies force-new)))
4096
4097 (defun gnus-build-get-header (id)
4098   "Look through the buffer of NOV lines and find the header to ID.
4099 Enter this line into the dependencies hash table, and return
4100 the id of the parent article (if any)."
4101   (let ((deps gnus-newsgroup-dependencies)
4102         found header)
4103     (prog1
4104         (save-excursion
4105           (set-buffer nntp-server-buffer)
4106           (let ((case-fold-search nil))
4107             (goto-char (point-min))
4108             (while (and (not found)
4109                         (search-forward id nil t))
4110               (beginning-of-line)
4111               (setq found (looking-at
4112                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4113                                    (regexp-quote id))))
4114               (or found (beginning-of-line 2)))
4115             (when found
4116               (beginning-of-line)
4117               (and
4118                (setq header (gnus-nov-parse-line
4119                              (read (current-buffer)) deps))
4120                (gnus-parent-id (mail-header-references header))))))
4121       (when header
4122         (let ((number (mail-header-number header)))
4123           (push number gnus-newsgroup-limit)
4124           (push header gnus-newsgroup-headers)
4125           (if (memq number gnus-newsgroup-unselected)
4126               (progn
4127                 (setq gnus-newsgroup-unreads
4128                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4129                                                number))
4130                 (setq gnus-newsgroup-unselected
4131                       (delq number gnus-newsgroup-unselected)))
4132             (push number gnus-newsgroup-ancient)))))))
4133
4134 (defun gnus-build-all-threads ()
4135   "Read all the headers."
4136   (let ((gnus-summary-ignore-duplicates t)
4137         (mail-parse-charset gnus-newsgroup-charset)
4138         (dependencies gnus-newsgroup-dependencies)
4139         header article)
4140     (save-excursion
4141       (set-buffer nntp-server-buffer)
4142       (let ((case-fold-search nil))
4143         (goto-char (point-min))
4144         (while (not (eobp))
4145           (ignore-errors
4146             (setq article (read (current-buffer))
4147                   header (gnus-nov-parse-line article dependencies)))
4148           (when header
4149             (with-current-buffer gnus-summary-buffer
4150               (push header gnus-newsgroup-headers)
4151               (if (memq (setq article (mail-header-number header))
4152                         gnus-newsgroup-unselected)
4153                   (progn
4154                     (setq gnus-newsgroup-unreads
4155                           (gnus-add-to-sorted-list
4156                            gnus-newsgroup-unreads article))
4157                     (setq gnus-newsgroup-unselected
4158                           (delq article gnus-newsgroup-unselected)))
4159                 (push article gnus-newsgroup-ancient)))
4160             (forward-line 1)))))))
4161
4162 (defun gnus-summary-update-article-line (article header)
4163   "Update the line for ARTICLE using HEADER."
4164   (let* ((id (mail-header-id header))
4165          (thread (gnus-id-to-thread id)))
4166     (unless thread
4167       (error "Article in no thread"))
4168     ;; Update the thread.
4169     (setcar thread header)
4170     (gnus-summary-goto-subject article)
4171     (let* ((datal (gnus-data-find-list article))
4172            (data (car datal))
4173            (buffer-read-only nil)
4174            (level (gnus-summary-thread-level)))
4175       (gnus-delete-line)
4176       (let ((inserted (- (point)
4177                          (progn
4178                            (gnus-summary-insert-line
4179                             header level nil
4180                             (memq article gnus-newsgroup-undownloaded)
4181                             (gnus-article-mark article)
4182                             (memq article gnus-newsgroup-replied)
4183                             (memq article gnus-newsgroup-expirable)
4184                             ;; Only insert the Subject string when it's different
4185                             ;; from the previous Subject string.
4186                             (if (and
4187                                  gnus-show-threads
4188                                  (gnus-subject-equal
4189                                   (condition-case ()
4190                                       (mail-header-subject
4191                                        (gnus-data-header
4192                                         (cadr
4193                                          (gnus-data-find-list
4194                                           article
4195                                           (gnus-data-list t)))))
4196                                     ;; Error on the side of excessive subjects.
4197                                     (error ""))
4198                                   (mail-header-subject header)))
4199                                 ""
4200                               (mail-header-subject header))
4201                             nil (cdr (assq article gnus-newsgroup-scored))
4202                             (memq article gnus-newsgroup-processable))
4203                            (point)))))
4204         (when (cdr datal)
4205           (gnus-data-update-list
4206            (cdr datal)
4207            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4208
4209 (defun gnus-summary-update-article (article &optional iheader)
4210   "Update ARTICLE in the summary buffer."
4211   (set-buffer gnus-summary-buffer)
4212   (let* ((header (gnus-summary-article-header article))
4213          (id (mail-header-id header))
4214          (data (gnus-data-find article))
4215          (thread (gnus-id-to-thread id))
4216          (references (mail-header-references header))
4217          (parent
4218           (gnus-id-to-thread
4219            (or (gnus-parent-id
4220                 (when (and references
4221                            (not (equal "" references)))
4222                   references))
4223                "none")))
4224          (buffer-read-only nil)
4225          (old (car thread)))
4226     (when thread
4227       (unless iheader
4228         (setcar thread nil)
4229         (when parent
4230           (delq thread parent)))
4231       (if (gnus-summary-insert-subject id header)
4232           ;; Set the (possibly) new article number in the data structure.
4233           (gnus-data-set-number data (gnus-id-to-article id))
4234         (setcar thread old)
4235         nil))))
4236
4237 (defun gnus-rebuild-thread (id &optional line)
4238   "Rebuild the thread containing ID.
4239 If LINE, insert the rebuilt thread starting on line LINE."
4240   (let ((buffer-read-only nil)
4241         old-pos current thread data)
4242     (if (not gnus-show-threads)
4243         (setq thread (list (car (gnus-id-to-thread id))))
4244       ;; Get the thread this article is part of.
4245       (setq thread (gnus-remove-thread id)))
4246     (setq old-pos (point-at-bol))
4247     (setq current (save-excursion
4248                     (and (re-search-backward "[\r\n]" nil t)
4249                          (gnus-summary-article-number))))
4250     ;; If this is a gathered thread, we have to go some re-gathering.
4251     (when (stringp (car thread))
4252       (let ((subject (car thread))
4253             roots thr)
4254         (setq thread (cdr thread))
4255         (while thread
4256           (unless (memq (setq thr (gnus-id-to-thread
4257                                    (gnus-root-id
4258                                     (mail-header-id (caar thread)))))
4259                         roots)
4260             (push thr roots))
4261           (setq thread (cdr thread)))
4262         ;; We now have all (unique) roots.
4263         (if (= (length roots) 1)
4264             ;; All the loose roots are now one solid root.
4265             (setq thread (car roots))
4266           (setq thread (cons subject (gnus-sort-threads roots))))))
4267     (let (threads)
4268       ;; We then insert this thread into the summary buffer.
4269       (when line
4270         (goto-char (point-min))
4271         (forward-line (1- line)))
4272       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4273         (if gnus-show-threads
4274             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4275           (gnus-summary-prepare-unthreaded thread))
4276         (setq data (nreverse gnus-newsgroup-data))
4277         (setq threads gnus-newsgroup-threads))
4278       ;; We splice the new data into the data structure.
4279       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4280       ;;!!! then we want to insert at the beginning of the buffer.
4281       ;;!!! That happens to be true with Gnus now, but that may
4282       ;;!!! change in the future.  Perhaps.
4283       (gnus-data-enter-list
4284        (if line nil current) data (- (point) old-pos))
4285       (setq gnus-newsgroup-threads
4286             (nconc threads gnus-newsgroup-threads))
4287       (gnus-data-compute-positions))))
4288
4289 (defun gnus-number-to-header (number)
4290   "Return the header for article NUMBER."
4291   (let ((headers gnus-newsgroup-headers))
4292     (while (and headers
4293                 (not (= number (mail-header-number (car headers)))))
4294       (pop headers))
4295     (when headers
4296       (car headers))))
4297
4298 (defun gnus-parent-headers (in-headers &optional generation)
4299   "Return the headers of the GENERATIONeth parent of HEADERS."
4300   (unless generation
4301     (setq generation 1))
4302   (let ((parent t)
4303         (headers in-headers)
4304         references)
4305     (while (and parent
4306                 (not (zerop generation))
4307                 (setq references (mail-header-references headers)))
4308       (setq headers (if (and references
4309                              (setq parent (gnus-parent-id references)))
4310                         (car (gnus-id-to-thread parent))
4311                       nil))
4312       (decf generation))
4313     (and (not (eq headers in-headers))
4314          headers)))
4315
4316 (defun gnus-id-to-thread (id)
4317   "Return the (sub-)thread where ID appears."
4318   (gnus-gethash id gnus-newsgroup-dependencies))
4319
4320 (defun gnus-id-to-article (id)
4321   "Return the article number of ID."
4322   (let ((thread (gnus-id-to-thread id)))
4323     (when (and thread
4324                (car thread))
4325       (mail-header-number (car thread)))))
4326
4327 (defun gnus-id-to-header (id)
4328   "Return the article headers of ID."
4329   (car (gnus-id-to-thread id)))
4330
4331 (defun gnus-article-displayed-root-p (article)
4332   "Say whether ARTICLE is a root(ish) article."
4333   (let ((level (gnus-summary-thread-level article))
4334         (refs (mail-header-references  (gnus-summary-article-header article)))
4335         particle)
4336     (cond
4337      ((null level) nil)
4338      ((zerop level) t)
4339      ((null refs) t)
4340      ((null (gnus-parent-id refs)) t)
4341      ((and (= 1 level)
4342            (null (setq particle (gnus-id-to-article
4343                                  (gnus-parent-id refs))))
4344            (null (gnus-summary-thread-level particle)))))))
4345
4346 (defun gnus-root-id (id)
4347   "Return the id of the root of the thread where ID appears."
4348   (let (last-id prev)
4349     (while (and id (setq prev (car (gnus-id-to-thread id))))
4350       (setq last-id id
4351             id (gnus-parent-id (mail-header-references prev))))
4352     last-id))
4353
4354 (defun gnus-articles-in-thread (thread)
4355   "Return the list of articles in THREAD."
4356   (cons (mail-header-number (car thread))
4357         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4358
4359 (defun gnus-remove-thread (id &optional dont-remove)
4360   "Remove the thread that has ID in it."
4361   (let (headers thread last-id)
4362     ;; First go up in this thread until we find the root.
4363     (setq last-id (gnus-root-id id)
4364           headers (message-flatten-list (gnus-id-to-thread last-id)))
4365     ;; We have now found the real root of this thread.  It might have
4366     ;; been gathered into some loose thread, so we have to search
4367     ;; through the threads to find the thread we wanted.
4368     (let ((threads gnus-newsgroup-threads)
4369           sub)
4370       (while threads
4371         (setq sub (car threads))
4372         (if (stringp (car sub))
4373             ;; This is a gathered thread, so we look at the roots
4374             ;; below it to find whether this article is in this
4375             ;; gathered root.
4376             (progn
4377               (setq sub (cdr sub))
4378               (while sub
4379                 (when (member (caar sub) headers)
4380                   (setq thread (car threads)
4381                         threads nil
4382                         sub nil))
4383                 (setq sub (cdr sub))))
4384           ;; It's an ordinary thread, so we check it.
4385           (when (eq (car sub) (car headers))
4386             (setq thread sub
4387                   threads nil)))
4388         (setq threads (cdr threads)))
4389       ;; If this article is in no thread, then it's a root.
4390       (if thread
4391           (unless dont-remove
4392             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4393         (setq thread (gnus-id-to-thread last-id)))
4394       (when thread
4395         (prog1
4396             thread                      ; We return this thread.
4397           (unless dont-remove
4398             (if (stringp (car thread))
4399                 (progn
4400                   ;; If we use dummy roots, then we have to remove the
4401                   ;; dummy root as well.
4402                   (when (eq gnus-summary-make-false-root 'dummy)
4403                     ;; We go to the dummy root by going to
4404                     ;; the first sub-"thread", and then one line up.
4405                     (gnus-summary-goto-article
4406                      (mail-header-number (caadr thread)))
4407                     (forward-line -1)
4408                     (gnus-delete-line)
4409                     (gnus-data-compute-positions))
4410                   (setq thread (cdr thread))
4411                   (while thread
4412                     (gnus-remove-thread-1 (car thread))
4413                     (setq thread (cdr thread))))
4414               (gnus-remove-thread-1 thread))))))))
4415
4416 (defun gnus-remove-thread-1 (thread)
4417   "Remove the thread THREAD recursively."
4418   (let ((number (mail-header-number (pop thread)))
4419         d)
4420     (setq thread (reverse thread))
4421     (while thread
4422       (gnus-remove-thread-1 (pop thread)))
4423     (when (setq d (gnus-data-find number))
4424       (goto-char (gnus-data-pos d))
4425       (gnus-summary-show-thread)
4426       (gnus-data-remove
4427        number
4428        (- (point-at-bol)
4429           (prog1
4430               (1+ (point-at-eol))
4431             (gnus-delete-line)))))))
4432
4433 (defun gnus-sort-threads-1 (threads func)
4434   (sort (mapcar (lambda (thread)
4435                   (cons (car thread)
4436                         (and (cdr thread)
4437                              (gnus-sort-threads-1 (cdr thread) func))))
4438                 threads) func))
4439
4440 (defun gnus-sort-threads (threads)
4441   "Sort THREADS."
4442   (if (not gnus-thread-sort-functions)
4443       threads
4444     (gnus-message 8 "Sorting threads...")
4445     (let ((max-lisp-eval-depth 5000))
4446       (prog1 (gnus-sort-threads-1
4447          threads
4448          (gnus-make-sort-function gnus-thread-sort-functions))
4449         (gnus-message 8 "Sorting threads...done")))))
4450
4451 (defun gnus-sort-articles (articles)
4452   "Sort ARTICLES."
4453   (when gnus-article-sort-functions
4454     (gnus-message 7 "Sorting articles...")
4455     (prog1
4456         (setq gnus-newsgroup-headers
4457               (sort articles (gnus-make-sort-function
4458                               gnus-article-sort-functions)))
4459       (gnus-message 7 "Sorting articles...done"))))
4460
4461 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4462 (defmacro gnus-thread-header (thread)
4463   "Return header of first article in THREAD.
4464 Note that THREAD must never, ever be anything else than a variable -
4465 using some other form will lead to serious barfage."
4466   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4467   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4468   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4469         (vector thread) 2))
4470
4471 (defsubst gnus-article-sort-by-number (h1 h2)
4472   "Sort articles by article number."
4473   (< (mail-header-number h1)
4474      (mail-header-number h2)))
4475
4476 (defun gnus-thread-sort-by-number (h1 h2)
4477   "Sort threads by root article number."
4478   (gnus-article-sort-by-number
4479    (gnus-thread-header h1) (gnus-thread-header h2)))
4480
4481 (defsubst gnus-article-sort-by-random (h1 h2)
4482   "Sort articles by article number."
4483   (zerop (random 2)))
4484
4485 (defun gnus-thread-sort-by-random (h1 h2)
4486   "Sort threads by root article number."
4487   (gnus-article-sort-by-random
4488    (gnus-thread-header h1) (gnus-thread-header h2)))
4489
4490 (defsubst gnus-article-sort-by-lines (h1 h2)
4491   "Sort articles by article Lines header."
4492   (< (mail-header-lines h1)
4493      (mail-header-lines h2)))
4494
4495 (defun gnus-thread-sort-by-lines (h1 h2)
4496   "Sort threads by root article Lines header."
4497   (gnus-article-sort-by-lines
4498    (gnus-thread-header h1) (gnus-thread-header h2)))
4499
4500 (defsubst gnus-article-sort-by-chars (h1 h2)
4501   "Sort articles by octet length."
4502   (< (mail-header-chars h1)
4503      (mail-header-chars h2)))
4504
4505 (defun gnus-thread-sort-by-chars (h1 h2)
4506   "Sort threads by root article octet length."
4507   (gnus-article-sort-by-chars
4508    (gnus-thread-header h1) (gnus-thread-header h2)))
4509
4510 (defsubst gnus-article-sort-by-author (h1 h2)
4511   "Sort articles by root author."
4512   (string-lessp
4513    (let ((addr (car (mime-entity-read-field h1 'From))))
4514      (or (std11-full-name-string addr)
4515          (std11-address-string addr)
4516          ""))
4517    (let ((addr (car (mime-entity-read-field h2 'From))))
4518      (or (std11-full-name-string addr)
4519          (std11-address-string addr)
4520          ""))
4521    ))
4522
4523 (defun gnus-thread-sort-by-author (h1 h2)
4524   "Sort threads by root author."
4525   (gnus-article-sort-by-author
4526    (gnus-thread-header h1)  (gnus-thread-header h2)))
4527
4528 (defsubst gnus-article-sort-by-subject (h1 h2)
4529   "Sort articles by root subject."
4530   (string-lessp
4531    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4532    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4533
4534 (defun gnus-thread-sort-by-subject (h1 h2)
4535   "Sort threads by root subject."
4536   (gnus-article-sort-by-subject
4537    (gnus-thread-header h1) (gnus-thread-header h2)))
4538
4539 (defsubst gnus-article-sort-by-date (h1 h2)
4540   "Sort articles by root article date."
4541   (time-less-p
4542    (gnus-date-get-time (mail-header-date h1))
4543    (gnus-date-get-time (mail-header-date h2))))
4544
4545 (defun gnus-thread-sort-by-date (h1 h2)
4546   "Sort threads by root article date."
4547   (gnus-article-sort-by-date
4548    (gnus-thread-header h1) (gnus-thread-header h2)))
4549
4550 (defsubst gnus-article-sort-by-score (h1 h2)
4551   "Sort articles by root article score.
4552 Unscored articles will be counted as having a score of zero."
4553   (> (or (cdr (assq (mail-header-number h1)
4554                     gnus-newsgroup-scored))
4555          gnus-summary-default-score 0)
4556      (or (cdr (assq (mail-header-number h2)
4557                     gnus-newsgroup-scored))
4558          gnus-summary-default-score 0)))
4559
4560 (defun gnus-thread-sort-by-score (h1 h2)
4561   "Sort threads by root article score."
4562   (gnus-article-sort-by-score
4563    (gnus-thread-header h1) (gnus-thread-header h2)))
4564
4565 (defun gnus-thread-sort-by-total-score (h1 h2)
4566   "Sort threads by the sum of all scores in the thread.
4567 Unscored articles will be counted as having a score of zero."
4568   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4569
4570 (defun gnus-thread-total-score (thread)
4571   ;; This function find the total score of THREAD.
4572   (cond
4573    ((null thread)
4574     0)
4575    ((consp thread)
4576     (if (stringp (car thread))
4577         (apply gnus-thread-score-function 0
4578                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4579       (gnus-thread-total-score-1 thread)))
4580    (t
4581     (gnus-thread-total-score-1 (list thread)))))
4582
4583 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4584   "Sort threads such that the thread with the most recently arrived article comes first."
4585   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4586
4587 (defun gnus-thread-highest-number (thread)
4588   "Return the highest article number in THREAD."
4589   (apply 'max (mapcar (lambda (header)
4590                         (mail-header-number header))
4591                       (message-flatten-list thread))))
4592
4593 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4594   "Sort threads such that the thread with the most recently dated article comes first."
4595   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4596
4597 (defun gnus-thread-latest-date (thread)
4598   "Return the highest article date in THREAD."
4599   (let ((previous-time 0))
4600     (apply 'max
4601            (mapcar
4602             (lambda (header)
4603               (setq previous-time
4604                     (condition-case ()
4605                         (time-to-seconds (mail-header-parse-date
4606                                           (mail-header-date header)))
4607                       (error previous-time))))
4608             (sort
4609              (message-flatten-list thread)
4610              (lambda (h1 h2)
4611                (< (mail-header-number h1)
4612                   (mail-header-number h2))))))))
4613
4614 (defun gnus-thread-total-score-1 (root)
4615   ;; This function find the total score of the thread below ROOT.
4616   (setq root (car root))
4617   (apply gnus-thread-score-function
4618          (or (append
4619               (mapcar 'gnus-thread-total-score
4620                       (cdr (gnus-id-to-thread (mail-header-id root))))
4621               (when (> (mail-header-number root) 0)
4622                 (list (or (cdr (assq (mail-header-number root)
4623                                      gnus-newsgroup-scored))
4624                           gnus-summary-default-score 0))))
4625              (list gnus-summary-default-score)
4626              '(0))))
4627
4628 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4629 (defvar gnus-tmp-prev-subject nil)
4630 (defvar gnus-tmp-false-parent nil)
4631 (defvar gnus-tmp-root-expunged nil)
4632 (defvar gnus-tmp-dummy-line nil)
4633
4634 (eval-when-compile (defvar gnus-tmp-header))
4635 (defun gnus-extra-header (type &optional header)
4636   "Return the extra header of TYPE."
4637   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4638       ""))
4639
4640 (defvar gnus-tmp-thread-tree-header-string "")
4641
4642 (defcustom gnus-sum-thread-tree-root "> "
4643   "With %B spec, used for the root of a thread.
4644 If nil, use subject instead."
4645   :type '(radio (const :format "%v  " nil) (string :size 0))
4646   :group 'gnus-thread)
4647 (defcustom gnus-sum-thread-tree-false-root "> "
4648   "With %B spec, used for a false root of a thread.
4649 If nil, use subject instead."
4650   :type '(radio (const :format "%v  " nil) (string :size 0))
4651   :group 'gnus-thread)
4652 (defcustom gnus-sum-thread-tree-single-indent ""
4653   "With %B spec, used for a thread with just one message.
4654 If nil, use subject instead."
4655   :type '(radio (const :format "%v  " nil) (string :size 0))
4656   :group 'gnus-thread)
4657 (defcustom gnus-sum-thread-tree-vertical "| "
4658   "With %B spec, used for drawing a vertical line."
4659   :type 'string
4660   :group 'gnus-thread)
4661 (defcustom gnus-sum-thread-tree-indent "  "
4662   "With %B spec, used for indenting."
4663   :type 'string
4664   :group 'gnus-thread)
4665 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4666   "With %B spec, used for a leaf with brothers."
4667   :type 'string
4668   :group 'gnus-thread)
4669 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4670   "With %B spec, used for a leaf without brothers."
4671   :type 'string
4672   :group 'gnus-thread)
4673
4674 (defun gnus-summary-prepare-threads (threads)
4675   "Prepare summary buffer from THREADS and indentation LEVEL.
4676 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4677 or a straight list of headers."
4678   (gnus-message 7 "Generating summary...")
4679
4680   (setq gnus-newsgroup-threads threads)
4681   (beginning-of-line)
4682
4683   (let ((gnus-tmp-level 0)
4684         (default-score (or gnus-summary-default-score 0))
4685         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4686         (building-line-count gnus-summary-display-while-building)
4687         (building-count (integerp gnus-summary-display-while-building))
4688         thread number subject stack state gnus-tmp-gathered beg-match
4689         new-roots gnus-tmp-new-adopts thread-end simp-subject
4690         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4691         gnus-tmp-replied gnus-tmp-subject-or-nil
4692         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4693         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4694         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4695         tree-stack)
4696
4697     (setq gnus-tmp-prev-subject nil
4698           gnus-tmp-thread-tree-header-string "")
4699
4700     (if (vectorp (car threads))
4701         ;; If this is a straight (sic) list of headers, then a
4702         ;; threaded summary display isn't required, so we just create
4703         ;; an unthreaded one.
4704         (gnus-summary-prepare-unthreaded threads)
4705
4706       ;; Do the threaded display.
4707
4708       (if gnus-summary-display-while-building
4709           (switch-to-buffer (buffer-name)))
4710       (while (or threads stack gnus-tmp-new-adopts new-roots)
4711
4712         (if (and (= gnus-tmp-level 0)
4713                  (or (not stack)
4714                      (= (caar stack) 0))
4715                  (not gnus-tmp-false-parent)
4716                  (or gnus-tmp-new-adopts new-roots))
4717             (if gnus-tmp-new-adopts
4718                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4719                       thread (list (car gnus-tmp-new-adopts))
4720                       gnus-tmp-header (caar thread)
4721                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4722               (when new-roots
4723                 (setq thread (list (car new-roots))
4724                       gnus-tmp-header (caar thread)
4725                       new-roots (cdr new-roots))))
4726
4727           (if threads
4728               ;; If there are some threads, we do them before the
4729               ;; threads on the stack.
4730               (setq thread threads
4731                     gnus-tmp-header (caar thread))
4732             ;; There were no current threads, so we pop something off
4733             ;; the stack.
4734             (setq state (car stack)
4735                   gnus-tmp-level (car state)
4736                   tree-stack (cadr state)
4737                   thread (caddr state)
4738                   stack (cdr stack)
4739                   gnus-tmp-header (caar thread))))
4740
4741         (setq gnus-tmp-false-parent nil)
4742         (setq gnus-tmp-root-expunged nil)
4743         (setq thread-end nil)
4744
4745         (if (stringp gnus-tmp-header)
4746             ;; The header is a dummy root.
4747             (cond
4748              ((eq gnus-summary-make-false-root 'adopt)
4749               ;; We let the first article adopt the rest.
4750               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4751                                                (cddar thread)))
4752               (setq gnus-tmp-gathered
4753                     (nconc (mapcar
4754                             (lambda (h) (mail-header-number (car h)))
4755                             (cddar thread))
4756                            gnus-tmp-gathered))
4757               (setq thread (cons (list (caar thread)
4758                                        (cadar thread))
4759                                  (cdr thread)))
4760               (setq gnus-tmp-level -1
4761                     gnus-tmp-false-parent t))
4762              ((eq gnus-summary-make-false-root 'empty)
4763               ;; We print adopted articles with empty subject fields.
4764               (setq gnus-tmp-gathered
4765                     (nconc (mapcar
4766                             (lambda (h) (mail-header-number (car h)))
4767                             (cddar thread))
4768                            gnus-tmp-gathered))
4769               (setq gnus-tmp-level -1))
4770              ((eq gnus-summary-make-false-root 'dummy)
4771               ;; We remember that we probably want to output a dummy
4772               ;; root.
4773               (setq gnus-tmp-dummy-line gnus-tmp-header)
4774               (setq gnus-tmp-prev-subject gnus-tmp-header))
4775              (t
4776               ;; We do not make a root for the gathered
4777               ;; sub-threads at all.
4778               (setq gnus-tmp-level -1)))
4779
4780           (setq number (mail-header-number gnus-tmp-header)
4781                 subject (mail-header-subject gnus-tmp-header)
4782                 simp-subject (gnus-simplify-subject-fully subject))
4783
4784           (cond
4785            ;; If the thread has changed subject, we might want to make
4786            ;; this subthread into a root.
4787            ((and (null gnus-thread-ignore-subject)
4788                  (not (zerop gnus-tmp-level))
4789                  gnus-tmp-prev-subject
4790                  (not (string= gnus-tmp-prev-subject simp-subject)))
4791             (setq new-roots (nconc new-roots (list (car thread)))
4792                   thread-end t
4793                   gnus-tmp-header nil))
4794            ;; If the article lies outside the current limit,
4795            ;; then we do not display it.
4796            ((not (memq number gnus-newsgroup-limit))
4797             (setq gnus-tmp-gathered
4798                   (nconc (mapcar
4799                           (lambda (h) (mail-header-number (car h)))
4800                           (cdar thread))
4801                          gnus-tmp-gathered))
4802             (setq gnus-tmp-new-adopts (if (cdar thread)
4803                                           (append gnus-tmp-new-adopts
4804                                                   (cdar thread))
4805                                         gnus-tmp-new-adopts)
4806                   thread-end t
4807                   gnus-tmp-header nil)
4808             (when (zerop gnus-tmp-level)
4809               (setq gnus-tmp-root-expunged t)))
4810            ;; Perhaps this article is to be marked as read?
4811            ((and gnus-summary-mark-below
4812                  (< (or (cdr (assq number gnus-newsgroup-scored))
4813                         default-score)
4814                     gnus-summary-mark-below)
4815                  ;; Don't touch sparse articles.
4816                  (not (gnus-summary-article-sparse-p number))
4817                  (not (gnus-summary-article-ancient-p number)))
4818             (setq gnus-newsgroup-unreads
4819                   (delq number gnus-newsgroup-unreads))
4820             (if gnus-newsgroup-auto-expire
4821                 (setq gnus-newsgroup-expirable
4822                       (gnus-add-to-sorted-list
4823                        gnus-newsgroup-expirable number))
4824               (push (cons number gnus-low-score-mark)
4825                     gnus-newsgroup-reads))))
4826
4827           (when gnus-tmp-header
4828             ;; We may have an old dummy line to output before this
4829             ;; article.
4830             (when (and gnus-tmp-dummy-line
4831                        (gnus-subject-equal
4832                         gnus-tmp-dummy-line
4833                         (mail-header-subject gnus-tmp-header)))
4834               (gnus-summary-insert-dummy-line
4835                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4836               (setq gnus-tmp-dummy-line nil))
4837
4838             ;; Compute the mark.
4839             (setq gnus-tmp-unread (gnus-article-mark number))
4840
4841             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4842                                   gnus-tmp-header gnus-tmp-level)
4843                   gnus-newsgroup-data)
4844
4845             ;; Actually insert the line.
4846             (setq
4847              gnus-tmp-subject-or-nil
4848              (cond
4849               ((and gnus-thread-ignore-subject
4850                     gnus-tmp-prev-subject
4851                     (not (string= gnus-tmp-prev-subject simp-subject)))
4852                subject)
4853               ((zerop gnus-tmp-level)
4854                (if (and (eq gnus-summary-make-false-root 'empty)
4855                         (memq number gnus-tmp-gathered)
4856                         gnus-tmp-prev-subject
4857                         (string= gnus-tmp-prev-subject simp-subject))
4858                    gnus-summary-same-subject
4859                  subject))
4860               (t gnus-summary-same-subject)))
4861             (if (and (eq gnus-summary-make-false-root 'adopt)
4862                      (= gnus-tmp-level 1)
4863                      (memq number gnus-tmp-gathered))
4864                 (setq gnus-tmp-opening-bracket ?\<
4865                       gnus-tmp-closing-bracket ?\>)
4866               (setq gnus-tmp-opening-bracket ?\[
4867                     gnus-tmp-closing-bracket ?\]))
4868             (setq
4869              gnus-tmp-indentation
4870              (aref gnus-thread-indent-array gnus-tmp-level)
4871              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4872              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4873                                 gnus-summary-default-score 0)
4874              gnus-tmp-score-char
4875              (if (or (null gnus-summary-default-score)
4876                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4877                          gnus-summary-zcore-fuzz))
4878                  ?\ ;;;Whitespace
4879                (if (< gnus-tmp-score gnus-summary-default-score)
4880                    gnus-score-below-mark gnus-score-over-mark))
4881              gnus-tmp-replied
4882              (cond ((memq number gnus-newsgroup-processable)
4883                     gnus-process-mark)
4884                    ((memq number gnus-newsgroup-cached)
4885                     gnus-cached-mark)
4886                    ((memq number gnus-newsgroup-replied)
4887                     gnus-replied-mark)
4888                    ((memq number gnus-newsgroup-forwarded)
4889                     gnus-forwarded-mark)
4890                    ((memq number gnus-newsgroup-saved)
4891                     gnus-saved-mark)
4892                    ((memq number gnus-newsgroup-recent)
4893                     gnus-recent-mark)
4894                    ((memq number gnus-newsgroup-unseen)
4895                     gnus-unseen-mark)
4896                    (t gnus-no-mark))
4897              gnus-tmp-downloaded
4898              (cond ((memq number gnus-newsgroup-undownloaded)
4899                     gnus-undownloaded-mark)
4900                    (gnus-newsgroup-agentized
4901                     gnus-downloaded-mark)
4902                    (t
4903                     gnus-no-mark))
4904              gnus-tmp-from (mail-header-from gnus-tmp-header)
4905              gnus-tmp-name
4906              (cond
4907               ((string-match "<[^>]+> *$" gnus-tmp-from)
4908                (setq beg-match (match-beginning 0))
4909                (or (and (string-match "^\".+\"" gnus-tmp-from)
4910                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4911                    (substring gnus-tmp-from 0 beg-match)))
4912               ((string-match "(.+)" gnus-tmp-from)
4913                (substring gnus-tmp-from
4914                           (1+ (match-beginning 0)) (1- (match-end 0))))
4915               (t gnus-tmp-from))
4916
4917              ;; Do the %B string
4918              gnus-tmp-thread-tree-header-string
4919              (cond
4920               ((not gnus-show-threads) "")
4921               ((zerop gnus-tmp-level)
4922                (cond ((cdar thread)
4923                       (or gnus-sum-thread-tree-root subject))
4924                      (gnus-tmp-new-adopts
4925                       (or gnus-sum-thread-tree-false-root subject))
4926                      (t
4927                       (or gnus-sum-thread-tree-single-indent subject))))
4928               (t
4929                (concat (apply 'concat
4930                               (mapcar (lambda (item)
4931                                         (if (= item 1)
4932                                             gnus-sum-thread-tree-vertical
4933                                           gnus-sum-thread-tree-indent))
4934                                       (cdr (reverse tree-stack))))
4935                        (if (nth 1 thread)
4936                            gnus-sum-thread-tree-leaf-with-other
4937                          gnus-sum-thread-tree-single-leaf)))))
4938             (when (string= gnus-tmp-name "")
4939               (setq gnus-tmp-name gnus-tmp-from))
4940             (unless (numberp gnus-tmp-lines)
4941               (setq gnus-tmp-lines -1))
4942             (if (= gnus-tmp-lines -1)
4943                 (setq gnus-tmp-lines "?")
4944               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4945               (gnus-put-text-property
4946              (point)
4947              (progn (eval gnus-summary-line-format-spec) (point))
4948                'gnus-number number)
4949             (when gnus-visual-p
4950               (forward-line -1)
4951               (gnus-run-hooks 'gnus-summary-update-hook)
4952               (forward-line 1))
4953
4954             (setq gnus-tmp-prev-subject simp-subject)))
4955
4956         (when (nth 1 thread)
4957           (push (list (max 0 gnus-tmp-level)
4958                       (copy-sequence tree-stack)
4959                       (nthcdr 1 thread))
4960                 stack))
4961         (push (if (nth 1 thread) 1 0) tree-stack)
4962         (incf gnus-tmp-level)
4963         (setq threads (if thread-end nil (cdar thread)))
4964         (if gnus-summary-display-while-building
4965             (if building-count
4966                 (progn
4967                   ;; use a set frequency
4968                   (setq building-line-count (1- building-line-count))
4969                   (when (= building-line-count 0)
4970                     (sit-for 0)
4971                     (setq building-line-count
4972                           gnus-summary-display-while-building)))
4973               ;; always
4974               (sit-for 0)))
4975         (unless threads
4976           (setq gnus-tmp-level 0)))))
4977   (gnus-message 7 "Generating summary...done"))
4978
4979 (defun gnus-summary-prepare-unthreaded (headers)
4980   "Generate an unthreaded summary buffer based on HEADERS."
4981   (let (header number mark)
4982
4983     (beginning-of-line)
4984
4985     (while headers
4986       ;; We may have to root out some bad articles...
4987       (when (memq (setq number (mail-header-number
4988                                 (setq header (pop headers))))
4989                   gnus-newsgroup-limit)
4990         ;; Mark article as read when it has a low score.
4991         (when (and gnus-summary-mark-below
4992                    (< (or (cdr (assq number gnus-newsgroup-scored))
4993                           gnus-summary-default-score 0)
4994                       gnus-summary-mark-below)
4995                    (not (gnus-summary-article-ancient-p number)))
4996           (setq gnus-newsgroup-unreads
4997                 (delq number gnus-newsgroup-unreads))
4998           (if gnus-newsgroup-auto-expire
4999               (push number gnus-newsgroup-expirable)
5000             (push (cons number gnus-low-score-mark)
5001                   gnus-newsgroup-reads)))
5002
5003         (setq mark (gnus-article-mark number))
5004         (push (gnus-data-make number mark (1+ (point)) header 0)
5005               gnus-newsgroup-data)
5006         (gnus-summary-insert-line
5007          header 0 number
5008          (memq number gnus-newsgroup-undownloaded)
5009          mark (memq number gnus-newsgroup-replied)
5010          (memq number gnus-newsgroup-expirable)
5011          (mail-header-subject header) nil
5012          (cdr (assq number gnus-newsgroup-scored))
5013          (memq number gnus-newsgroup-processable))))))
5014
5015 (defun gnus-summary-remove-list-identifiers ()
5016   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5017   (let ((regexp (if (consp gnus-list-identifiers)
5018                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5019                   gnus-list-identifiers))
5020         changed subject)
5021     (when regexp
5022       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5023       (dolist (header gnus-newsgroup-headers)
5024         (setq subject (mail-header-subject header)
5025               changed nil)
5026         (while (string-match regexp subject)
5027           (setq subject
5028                 (concat (substring subject 0 (match-beginning 1))
5029                         (substring subject (match-end 0)))
5030                 changed t))
5031         (when changed
5032           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5033             (setq subject
5034                   (concat (substring subject 0 (match-beginning 1))
5035                           (substring subject (match-end 1)))))
5036           (mail-header-set-subject header subject))))))
5037
5038 (defun gnus-fetch-headers (articles)
5039   "Fetch headers of ARTICLES."
5040   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5041     (gnus-message 5 "Fetching headers for %s..." name)
5042     (prog1
5043         (if (eq 'nov
5044                 (setq gnus-headers-retrieved-by
5045                       (gnus-retrieve-headers
5046                        articles gnus-newsgroup-name
5047                        ;; We might want to fetch old headers, but
5048                        ;; not if there is only 1 article.
5049                        (and (or (and
5050                                  (not (eq gnus-fetch-old-headers 'some))
5051                                  (not (numberp gnus-fetch-old-headers)))
5052                                 (> (length articles) 1))
5053                             gnus-fetch-old-headers))))
5054             (gnus-get-newsgroup-headers-xover
5055              articles nil nil gnus-newsgroup-name t)
5056           (gnus-get-newsgroup-headers))
5057       (gnus-message 5 "Fetching headers for %s...done" name))))
5058
5059 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5060   "Select newsgroup GROUP.
5061 If READ-ALL is non-nil, all articles in the group are selected.
5062 If SELECT-ARTICLES, only select those articles from GROUP."
5063   (let* ((entry (gnus-group-entry group))
5064          ;;!!! Dirty hack; should be removed.
5065          (gnus-summary-ignore-duplicates
5066           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5067               t
5068             gnus-summary-ignore-duplicates))
5069          (info (nth 2 entry))
5070          articles fetched-articles cached)
5071
5072     (unless (gnus-check-server
5073              (set (make-local-variable 'gnus-current-select-method)
5074                   (gnus-find-method-for-group group)))
5075       (error "Couldn't open server"))
5076
5077     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5078         (gnus-activate-group group)     ; Or we can activate it...
5079         (progn                          ; Or we bug out.
5080           (when (equal major-mode 'gnus-summary-mode)
5081             (gnus-kill-buffer (current-buffer)))
5082           (error "Couldn't activate group %s: %s"
5083                  group (gnus-status-message group))))
5084
5085     (unless (gnus-request-group group t)
5086       (when (equal major-mode 'gnus-summary-mode)
5087         (gnus-kill-buffer (current-buffer)))
5088       (error "Couldn't request group %s: %s"
5089              group (gnus-status-message group)))
5090
5091     (when gnus-agent
5092       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5093       
5094       (setq gnus-summary-use-undownloaded-faces
5095             (gnus-agent-find-parameter
5096              group
5097              'agent-enable-undownloaded-faces)))
5098
5099     (setq gnus-newsgroup-name group
5100           gnus-newsgroup-unselected nil
5101           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5102
5103     (let ((display (gnus-group-find-parameter group 'display)))
5104       (setq gnus-newsgroup-display
5105             (cond
5106              ((not (zerop (or (car-safe read-all) 0)))
5107               ;; The user entered the group with C-u SPC/RET, let's show
5108               ;; all articles.
5109               'gnus-not-ignore)
5110              ((eq display 'all)
5111               'gnus-not-ignore)
5112              ((arrayp display)
5113               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5114              ((numberp display)
5115               ;; The following is probably the "correct" solution, but
5116               ;; it makes Gnus fetch all headers and then limit the
5117               ;; articles (which is slow), so instead we hack the
5118               ;; select-articles parameter instead. -- Simon Josefsson
5119               ;; <jas@kth.se>
5120               ;;
5121               ;; (gnus-byte-compile
5122               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5123               ;;                         display)))))
5124               (setq select-articles
5125                     (gnus-uncompress-range
5126                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5127                              (if (> tmp 0)
5128                                  tmp
5129                                1))
5130                            (cdr (gnus-active group)))))
5131               nil)
5132              (t
5133               nil))))
5134
5135     (gnus-summary-setup-default-charset)
5136
5137     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5138     (when (gnus-virtual-group-p group)
5139       (setq cached gnus-newsgroup-cached))
5140
5141     (setq gnus-newsgroup-unreads
5142           (gnus-sorted-ndifference
5143            (gnus-sorted-ndifference gnus-newsgroup-unreads
5144                                     gnus-newsgroup-marked)
5145            gnus-newsgroup-dormant))
5146
5147     (setq gnus-newsgroup-processable nil)
5148
5149     (gnus-update-read-articles group gnus-newsgroup-unreads)
5150
5151     ;; Adjust and set lists of article marks.
5152     (when info
5153       (gnus-adjust-marked-articles info))
5154     (if (setq articles select-articles)
5155         (setq gnus-newsgroup-unselected
5156               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5157       (setq articles (gnus-articles-to-read group read-all)))
5158
5159     (cond
5160      ((null articles)
5161       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5162       'quit)
5163      ((eq articles 0) nil)
5164      (t
5165       ;; Init the dependencies hash table.
5166       (setq gnus-newsgroup-dependencies
5167             (gnus-make-hashtable (length articles)))
5168       (gnus-set-global-variables)
5169       ;; Retrieve the headers and read them in.
5170
5171       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5172
5173       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5174       (when cached
5175         (setq gnus-newsgroup-cached cached))
5176
5177       ;; Suppress duplicates?
5178       (when gnus-suppress-duplicates
5179         (gnus-dup-suppress-articles))
5180
5181       ;; Set the initial limit.
5182       (setq gnus-newsgroup-limit (copy-sequence articles))
5183       ;; Remove canceled articles from the list of unread articles.
5184       (setq fetched-articles
5185             (mapcar (lambda (headers) (mail-header-number headers))
5186                     gnus-newsgroup-headers))
5187       (setq gnus-newsgroup-articles fetched-articles)
5188       (setq gnus-newsgroup-unreads
5189             (gnus-sorted-nintersection
5190              gnus-newsgroup-unreads fetched-articles))
5191       (gnus-compute-unseen-list)
5192
5193       ;; Removed marked articles that do not exist.
5194       (gnus-update-missing-marks
5195        (gnus-sorted-difference articles fetched-articles))
5196       ;; We might want to build some more threads first.
5197       (when (and gnus-fetch-old-headers
5198                  (eq gnus-headers-retrieved-by 'nov))
5199         (if (eq gnus-fetch-old-headers 'invisible)
5200             (gnus-build-all-threads)
5201           (gnus-build-old-threads)))
5202       ;; Let the Gnus agent mark articles as read.
5203       (when gnus-agent
5204         (gnus-agent-get-undownloaded-list))
5205       ;; Remove list identifiers from subject
5206       (when gnus-list-identifiers
5207         (gnus-summary-remove-list-identifiers))
5208       ;; Check whether auto-expire is to be done in this group.
5209       (setq gnus-newsgroup-auto-expire
5210             (gnus-group-auto-expirable-p group))
5211       ;; Set up the article buffer now, if necessary.
5212       (unless gnus-single-article-buffer
5213         (gnus-article-setup-buffer))
5214       ;; First and last article in this newsgroup.
5215       (when gnus-newsgroup-headers
5216         (setq gnus-newsgroup-begin
5217               (mail-header-number (car gnus-newsgroup-headers))
5218               gnus-newsgroup-end
5219               (mail-header-number
5220                (gnus-last-element gnus-newsgroup-headers))))
5221       ;; GROUP is successfully selected.
5222       (or gnus-newsgroup-headers t)))))
5223
5224 (defun gnus-compute-unseen-list ()
5225   ;; The `seen' marks are treated specially.
5226   (if (not gnus-newsgroup-seen)
5227       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5228     (setq gnus-newsgroup-unseen
5229           (gnus-inverse-list-range-intersection
5230            gnus-newsgroup-articles gnus-newsgroup-seen))))
5231
5232 (defun gnus-summary-display-make-predicate (display)
5233   (require 'gnus-agent)
5234   (when (= (length display) 1)
5235     (setq display (car display)))
5236   (unless gnus-summary-display-cache
5237     (dolist (elem (append '((unread . unread)
5238                             (read . read)
5239                             (unseen . unseen))
5240                           gnus-article-mark-lists))
5241       (push (cons (cdr elem)
5242                   (gnus-byte-compile
5243                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5244             gnus-summary-display-cache)))
5245   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5246         (gnus-category-predicate-cache gnus-summary-display-cache))
5247     (gnus-get-predicate display)))
5248
5249 ;; Uses the dynamically bound `number' variable.
5250 (eval-when-compile
5251   (defvar number))
5252 (defun gnus-article-marked-p (type &optional article)
5253   (let ((article (or article number)))
5254     (cond
5255      ((eq type 'tick)
5256       (memq article gnus-newsgroup-marked))
5257      ((eq type 'spam)
5258       (memq article gnus-newsgroup-spam-marked))
5259      ((eq type 'unsend)
5260       (memq article gnus-newsgroup-unsendable))
5261      ((eq type 'undownload)
5262       (memq article gnus-newsgroup-undownloaded))
5263      ((eq type 'download)
5264       (memq article gnus-newsgroup-downloadable))
5265      ((eq type 'unread)
5266       (memq article gnus-newsgroup-unreads))
5267      ((eq type 'read)
5268       (memq article gnus-newsgroup-reads))
5269      ((eq type 'dormant)
5270       (memq article gnus-newsgroup-dormant) )
5271      ((eq type 'expire)
5272       (memq article gnus-newsgroup-expirable))
5273      ((eq type 'reply)
5274       (memq article gnus-newsgroup-replied))
5275      ((eq type 'killed)
5276       (memq article gnus-newsgroup-killed))
5277      ((eq type 'bookmark)
5278       (assq article gnus-newsgroup-bookmarks))
5279      ((eq type 'score)
5280       (assq article gnus-newsgroup-scored))
5281      ((eq type 'save)
5282       (memq article gnus-newsgroup-saved))
5283      ((eq type 'cache)
5284       (memq article gnus-newsgroup-cached))
5285      ((eq type 'forward)
5286       (memq article gnus-newsgroup-forwarded))
5287      ((eq type 'seen)
5288       (not (memq article gnus-newsgroup-unseen)))
5289      ((eq type 'recent)
5290       (memq article gnus-newsgroup-recent))
5291      (t t))))
5292
5293 (defun gnus-articles-to-read (group &optional read-all)
5294   "Find out what articles the user wants to read."
5295   (let* ((articles
5296           ;; Select all articles if `read-all' is non-nil, or if there
5297           ;; are no unread articles.
5298           (if (or read-all
5299                   (and (zerop (length gnus-newsgroup-marked))
5300                        (zerop (length gnus-newsgroup-unreads)))
5301                   ;; Fetch all if the predicate is non-nil.
5302                   gnus-newsgroup-display)
5303               ;; We want to select the headers for all the articles in
5304               ;; the group, so we select either all the active
5305               ;; articles in the group, or (if that's nil), the
5306               ;; articles in the cache.
5307               (or
5308                (gnus-uncompress-range (gnus-active group))
5309                (gnus-cache-articles-in-group group))
5310             ;; Select only the "normal" subset of articles.
5311             (gnus-sorted-nunion
5312              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5313              gnus-newsgroup-unreads)))
5314          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5315          (scored (length scored-list))
5316          (number (length articles))
5317          (marked (+ (length gnus-newsgroup-marked)
5318                     (length gnus-newsgroup-dormant)))
5319          (select
5320           (cond
5321            ((numberp read-all)
5322             read-all)
5323            ((numberp gnus-newsgroup-display)
5324             gnus-newsgroup-display)
5325            (t
5326             (condition-case ()
5327                 (cond
5328                  ((and (or (<= scored marked) (= scored number))
5329                        (numberp gnus-large-newsgroup)
5330                        (> number gnus-large-newsgroup))
5331                   (let* ((cursor-in-echo-area nil)
5332                          (initial (gnus-parameter-large-newsgroup-initial
5333                                    gnus-newsgroup-name))
5334                          (input
5335                           (read-string
5336                            (format
5337                             "How many articles from %s (%s %d): "
5338                             (gnus-limit-string
5339                              (gnus-group-decoded-name gnus-newsgroup-name)
5340                              35)
5341                             (if initial "max" "default")
5342                             number)
5343                            (if initial
5344                                (cons (number-to-string initial)
5345                                      0)))))
5346                     (if (string-match "^[ \t]*$" input) number input)))
5347                  ((and (> scored marked) (< scored number)
5348                        (> (- scored number) 20))
5349                   (let ((input
5350                          (read-string
5351                           (format "%s %s (%d scored, %d total): "
5352                                   "How many articles from"
5353                                   (gnus-group-decoded-name group)
5354                                   scored number))))
5355                     (if (string-match "^[ \t]*$" input)
5356                         number input)))
5357                  (t number))
5358               (quit
5359                (message "Quit getting the articles to read")
5360                nil))))))
5361     (setq select (if (stringp select) (string-to-number select) select))
5362     (if (or (null select) (zerop select))
5363         select
5364       (if (and (not (zerop scored)) (<= (abs select) scored))
5365           (progn
5366             (setq articles (sort scored-list '<))
5367             (setq number (length articles)))
5368         (setq articles (copy-sequence articles)))
5369
5370       (when (< (abs select) number)
5371         (if (< select 0)
5372             ;; Select the N oldest articles.
5373             (setcdr (nthcdr (1- (abs select)) articles) nil)
5374           ;; Select the N most recent articles.
5375           (setq articles (nthcdr (- number select) articles))))
5376       (setq gnus-newsgroup-unselected
5377             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5378       (when gnus-alter-articles-to-read-function
5379         (setq articles
5380               (sort
5381                (funcall gnus-alter-articles-to-read-function
5382                         gnus-newsgroup-name articles)
5383                '<)))
5384       articles)))
5385
5386 (defun gnus-killed-articles (killed articles)
5387   (let (out)
5388     (while articles
5389       (when (inline (gnus-member-of-range (car articles) killed))
5390         (push (car articles) out))
5391       (setq articles (cdr articles)))
5392     out))
5393
5394 (defun gnus-uncompress-marks (marks)
5395   "Uncompress the mark ranges in MARKS."
5396   (let ((uncompressed '(score bookmark))
5397         out)
5398     (while marks
5399       (if (memq (caar marks) uncompressed)
5400           (push (car marks) out)
5401         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5402       (setq marks (cdr marks)))
5403     out))
5404
5405 (defun gnus-article-mark-to-type (mark)
5406   "Return the type of MARK."
5407   (or (cadr (assq mark gnus-article-special-mark-lists))
5408       'list))
5409
5410 (defun gnus-article-unpropagatable-p (mark)
5411   "Return whether MARK should be propagated to back end."
5412   (memq mark gnus-article-unpropagated-mark-lists))
5413
5414 (defun gnus-adjust-marked-articles (info)
5415   "Set all article lists and remove all marks that are no longer valid."
5416   (let* ((marked-lists (gnus-info-marks info))
5417          (active (gnus-active (gnus-info-group info)))
5418          (min (car active))
5419          (max (cdr active))
5420          (types gnus-article-mark-lists)
5421          marks var articles article mark mark-type
5422          bgn end)
5423
5424     (dolist (marks marked-lists)
5425       (setq mark (car marks)
5426             mark-type (gnus-article-mark-to-type mark)
5427             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5428
5429       ;; We set the variable according to the type of the marks list,
5430       ;; and then adjust the marks to a subset of the active articles.
5431       (cond
5432        ;; Adjust "simple" lists - compressed yet unsorted
5433        ((eq mark-type 'list)
5434         ;; Simultaneously uncompress and clip to active range
5435         ;; See gnus-uncompress-range for a description of possible marks
5436         (let (l lh)
5437           (if (not (cadr marks))
5438               (set var nil)
5439             (setq articles (if (numberp (cddr marks))
5440                                (list (cdr marks))
5441                              (cdr marks))
5442                   lh (cons nil nil)
5443                   l lh)
5444
5445             (while (setq article (pop articles))
5446               (cond ((consp article)
5447                      (setq bgn (max (car article) min)
5448                            end (min (cdr article) max))
5449                      (while (<= bgn end)
5450                        (setq l (setcdr l (cons bgn nil))
5451                              bgn (1+ bgn))))
5452                     ((and (<= min article)
5453                           (>= max article))
5454                      (setq l (setcdr l (cons article nil))))))
5455             (set var (cdr lh)))))
5456        ;; Adjust assocs.
5457        ((eq mark-type 'tuple)
5458         (set var (setq articles (cdr marks)))
5459         (when (not (listp (cdr (symbol-value var))))
5460           (set var (list (symbol-value var))))
5461         (when (not (listp (cdr articles)))
5462           (setq articles (list articles)))
5463         (while articles
5464           (when (or (not (consp (setq article (pop articles))))
5465                     (< (car article) min)
5466                     (> (car article) max))
5467             (set var (delq article (symbol-value var))))))
5468        ;; Adjust ranges (sloppily).
5469        ((eq mark-type 'range)
5470         (cond
5471          ((eq mark 'seen)
5472           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5473           ;; It should be (seen (NUM1 . NUM2)).
5474           (when (numberp (cddr marks))
5475             (setcdr marks (list (cdr marks))))
5476           (setq articles (cdr marks))
5477           (while (and articles
5478                       (or (and (consp (car articles))
5479                                (> min (cdar articles)))
5480                           (and (numberp (car articles))
5481                                (> min (car articles)))))
5482             (pop articles))
5483           (set var articles))))))))
5484
5485 (defun gnus-update-missing-marks (missing)
5486   "Go through the list of MISSING articles and remove them from the mark lists."
5487   (when missing
5488     (let (var m)
5489       ;; Go through all types.
5490       (dolist (elem gnus-article-mark-lists)
5491         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5492           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5493           (when (symbol-value var)
5494             ;; This list has articles.  So we delete all missing
5495             ;; articles from it.
5496             (setq m missing)
5497             (while m
5498               (set var (delq (pop m) (symbol-value var))))))))))
5499
5500 (defun gnus-update-marks ()
5501   "Enter the various lists of marked articles into the newsgroup info list."
5502   (let ((types gnus-article-mark-lists)
5503         (info (gnus-get-info gnus-newsgroup-name))
5504         type list newmarked symbol delta-marks)
5505     (when info
5506       ;; Add all marks lists to the list of marks lists.
5507       (while (setq type (pop types))
5508         (setq list (symbol-value
5509                     (setq symbol
5510                           (intern (format "gnus-newsgroup-%s" (car type))))))
5511
5512         (when list
5513           ;; Get rid of the entries of the articles that have the
5514           ;; default score.
5515           (when (and (eq (cdr type) 'score)
5516                      gnus-save-score
5517                      list)
5518             (let* ((arts list)
5519                    (prev (cons nil list))
5520                    (all prev))
5521               (while arts
5522                 (if (or (not (consp (car arts)))
5523                         (= (cdar arts) gnus-summary-default-score))
5524                     (setcdr prev (cdr arts))
5525                   (setq prev arts))
5526                 (setq arts (cdr arts)))
5527               (setq list (cdr all)))))
5528
5529         (when (eq (cdr type) 'seen)
5530           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5531
5532         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5533           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5534
5535         (when (and (gnus-check-backend-function
5536                     'request-set-mark gnus-newsgroup-name)
5537                    (not (gnus-article-unpropagatable-p (cdr type))))
5538           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5539                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5540                  (add (gnus-remove-from-range
5541                        (gnus-copy-sequence list) old)))
5542             (when add
5543               (push (list add 'add (list (cdr type))) delta-marks))
5544             (when del
5545               (push (list del 'del (list (cdr type))) delta-marks))))
5546
5547         (when list
5548           (push (cons (cdr type) list) newmarked)))
5549
5550       (when delta-marks
5551         (unless (gnus-check-group gnus-newsgroup-name)
5552           (error "Can't open server for %s" gnus-newsgroup-name))
5553         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5554
5555       ;; Enter these new marks into the info of the group.
5556       (if (nthcdr 3 info)
5557           (setcar (nthcdr 3 info) newmarked)
5558         ;; Add the marks lists to the end of the info.
5559         (when newmarked
5560           (setcdr (nthcdr 2 info) (list newmarked))))
5561
5562       ;; Cut off the end of the info if there's nothing else there.
5563       (let ((i 5))
5564         (while (and (> i 2)
5565                     (not (nth i info)))
5566           (when (nthcdr (decf i) info)
5567             (setcdr (nthcdr i info) nil)))))))
5568
5569 (defun gnus-set-mode-line (where)
5570   "Set the mode line of the article or summary buffers.
5571 If WHERE is `summary', the summary mode line format will be used."
5572   ;; Is this mode line one we keep updated?
5573   (when (and (memq where gnus-updated-mode-lines)
5574              (symbol-value
5575               (intern (format "gnus-%s-mode-line-format-spec" where))))
5576     (let (mode-string)
5577       (save-excursion
5578         ;; We evaluate this in the summary buffer since these
5579         ;; variables are buffer-local to that buffer.
5580         (set-buffer gnus-summary-buffer)
5581         ;; We bind all these variables that are used in the `eval' form
5582         ;; below.
5583         (let* ((mformat (symbol-value
5584                          (intern
5585                           (format "gnus-%s-mode-line-format-spec" where))))
5586                (gnus-tmp-group-name (gnus-group-decoded-name
5587                                      gnus-newsgroup-name))
5588                (gnus-tmp-article-number (or gnus-current-article 0))
5589                (gnus-tmp-unread gnus-newsgroup-unreads)
5590                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5591                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5592                (gnus-tmp-unread-and-unselected
5593                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5594                             (zerop gnus-tmp-unselected))
5595                        "")
5596                       ((zerop gnus-tmp-unselected)
5597                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5598                       (t (format "{%d(+%d) more}"
5599                                  gnus-tmp-unread-and-unticked
5600                                  gnus-tmp-unselected))))
5601                (gnus-tmp-subject
5602                 (if (and gnus-current-headers
5603                          (vectorp gnus-current-headers))
5604                     (gnus-mode-string-quote
5605                      (mail-header-subject gnus-current-headers))
5606                   ""))
5607                bufname-length max-len
5608                gnus-tmp-header);; passed as argument to any user-format-funcs
5609           (setq mode-string (eval mformat))
5610           (setq bufname-length (if (string-match "%b" mode-string)
5611                                    (- (length
5612                                        (buffer-name
5613                                         (if (eq where 'summary)
5614                                             nil
5615                                           (get-buffer gnus-article-buffer))))
5616                                       2)
5617                                  0))
5618           (setq max-len (max 4 (if gnus-mode-non-string-length
5619                                    (- (window-width)
5620                                       gnus-mode-non-string-length
5621                                       bufname-length)
5622                                  (length mode-string))))
5623           ;; We might have to chop a bit of the string off...
5624           (when (> (length mode-string) max-len)
5625             (setq mode-string
5626                   (concat (gnus-truncate-string mode-string (- max-len 3))
5627                           "...")))
5628           ;; Pad the mode string a bit.
5629           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5630       ;; Update the mode line.
5631       (setq mode-line-buffer-identification
5632             (gnus-mode-line-buffer-identification (list mode-string)))
5633       (set-buffer-modified-p t))))
5634
5635 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5636   "Go through the HEADERS list and add all Xrefs to a hash table.
5637 The resulting hash table is returned, or nil if no Xrefs were found."
5638   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5639          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5640          (xref-hashtb (gnus-make-hashtable))
5641          start group entry number xrefs header)
5642     (while headers
5643       (setq header (pop headers))
5644       (when (and (setq xrefs (mail-header-xref header))
5645                  (not (memq (setq number (mail-header-number header))
5646                             unreads)))
5647         (setq start 0)
5648         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5649           (setq start (match-end 0))
5650           (setq group (if prefix
5651                           (concat prefix (substring xrefs (match-beginning 1)
5652                                                     (match-end 1)))
5653                         (substring xrefs (match-beginning 1) (match-end 1))))
5654           (setq number
5655                 (string-to-int (substring xrefs (match-beginning 2)
5656                                           (match-end 2))))
5657           (if (setq entry (gnus-gethash group xref-hashtb))
5658               (setcdr entry (cons number (cdr entry)))
5659             (gnus-sethash group (cons number nil) xref-hashtb)))))
5660     (and start xref-hashtb)))
5661
5662 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5663   "Look through all the headers and mark the Xrefs as read."
5664   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5665         name info xref-hashtb idlist method nth4)
5666     (save-excursion
5667       (set-buffer gnus-group-buffer)
5668       (when (setq xref-hashtb
5669                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5670         (mapatoms
5671          (lambda (group)
5672            (unless (string= from-newsgroup (setq name (symbol-name group)))
5673              (setq idlist (symbol-value group))
5674              ;; Dead groups are not updated.
5675              (and (prog1
5676                       (setq info (gnus-get-info name))
5677                     (when (stringp (setq nth4 (gnus-info-method info)))
5678                       (setq nth4 (gnus-server-to-method nth4))))
5679                   ;; Only do the xrefs if the group has the same
5680                   ;; select method as the group we have just read.
5681                   (or (gnus-methods-equal-p
5682                        nth4 (gnus-find-method-for-group from-newsgroup))
5683                       virtual
5684                       (equal nth4 (setq method (gnus-find-method-for-group
5685                                                 from-newsgroup)))
5686                       (and (equal (car nth4) (car method))
5687                            (equal (nth 1 nth4) (nth 1 method))))
5688                   gnus-use-cross-reference
5689                   (or (not (eq gnus-use-cross-reference t))
5690                       virtual
5691                       ;; Only do cross-references on subscribed
5692                       ;; groups, if that is what is wanted.
5693                       (<= (gnus-info-level info) gnus-level-subscribed))
5694                   (gnus-group-make-articles-read name idlist))))
5695          xref-hashtb)))))
5696
5697 (defun gnus-compute-read-articles (group articles)
5698   (let* ((entry (gnus-group-entry group))
5699          (info (nth 2 entry))
5700          (active (gnus-active group))
5701          ninfo)
5702     (when entry
5703       ;; First peel off all invalid article numbers.
5704       (when active
5705         (let ((ids articles)
5706               id first)
5707           (while (setq id (pop ids))
5708             (when (and first (> id (cdr active)))
5709               ;; We'll end up in this situation in one particular
5710               ;; obscure situation.  If you re-scan a group and get
5711               ;; a new article that is cross-posted to a different
5712               ;; group that has not been re-scanned, you might get
5713               ;; crossposted article that has a higher number than
5714               ;; Gnus believes possible.  So we re-activate this
5715               ;; group as well.  This might mean doing the
5716               ;; crossposting thingy will *increase* the number
5717               ;; of articles in some groups.  Tsk, tsk.
5718               (setq active (or (gnus-activate-group group) active)))
5719             (when (or (> id (cdr active))
5720                       (< id (car active)))
5721               (setq articles (delq id articles))))))
5722       ;; If the read list is nil, we init it.
5723       (if (and active
5724                (null (gnus-info-read info))
5725                (> (car active) 1))
5726           (setq ninfo (cons 1 (1- (car active))))
5727         (setq ninfo (gnus-info-read info)))
5728       ;; Then we add the read articles to the range.
5729       (gnus-add-to-range
5730        ninfo (setq articles (sort articles '<))))))
5731
5732 (defun gnus-group-make-articles-read (group articles)
5733   "Update the info of GROUP to say that ARTICLES are read."
5734   (let* ((num 0)
5735          (entry (gnus-group-entry group))
5736          (info (nth 2 entry))
5737          (active (gnus-active group))
5738          range)
5739     (when entry
5740       (setq range (gnus-compute-read-articles group articles))
5741       (with-current-buffer gnus-group-buffer
5742         (gnus-undo-register
5743           `(progn
5744              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5745              (gnus-info-set-read ',info ',(gnus-info-read info))
5746              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5747              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5748              (gnus-group-update-group ,group t))))
5749       ;; Add the read articles to the range.
5750       (gnus-info-set-read info range)
5751       (gnus-request-set-mark group (list (list range 'add '(read))))
5752       ;; Then we have to re-compute how many unread
5753       ;; articles there are in this group.
5754       (when active
5755         (cond
5756          ((not range)
5757           (setq num (- (1+ (cdr active)) (car active))))
5758          ((not (listp (cdr range)))
5759           (setq num (- (cdr active) (- (1+ (cdr range))
5760                                        (car range)))))
5761          (t
5762           (while range
5763             (if (numberp (car range))
5764                 (setq num (1+ num))
5765               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5766             (setq range (cdr range)))
5767           (setq num (- (cdr active) num))))
5768         ;; Update the number of unread articles.
5769         (setcar entry num)
5770         ;; Update the group buffer.
5771         (unless (gnus-ephemeral-group-p group)
5772           (gnus-group-update-group group t))))))
5773
5774 (defvar gnus-newsgroup-none-id 0)
5775
5776 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5777   (let ((cur nntp-server-buffer)
5778         (dependencies
5779          (or dependencies
5780              (with-current-buffer gnus-summary-buffer
5781                gnus-newsgroup-dependencies)))
5782         headers id end ref number
5783         (mail-parse-charset gnus-newsgroup-charset)
5784         (mail-parse-ignored-charsets
5785          (save-excursion (condition-case nil
5786                              (set-buffer gnus-summary-buffer)
5787                            (error))
5788                          gnus-newsgroup-ignored-charsets)))
5789     (save-excursion
5790       (set-buffer nntp-server-buffer)
5791       ;; Translate all TAB characters into SPACE characters.
5792       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5793       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5794       (ietf-drums-unfold-fws)
5795       (gnus-run-hooks 'gnus-parse-headers-hook)
5796       (let ((case-fold-search t)
5797             in-reply-to header p lines chars ctype)
5798         (goto-char (point-min))
5799         ;; Search to the beginning of the next header.  Error messages
5800         ;; do not begin with 2 or 3.
5801         (while (re-search-forward "^[23][0-9]+ " nil t)
5802           (setq id nil
5803                 ref nil)
5804           ;; This implementation of this function, with nine
5805           ;; search-forwards instead of the one re-search-forward and
5806           ;; a case (which basically was the old function) is actually
5807           ;; about twice as fast, even though it looks messier.  You
5808           ;; can't have everything, I guess.  Speed and elegance
5809           ;; doesn't always go hand in hand.
5810           (setq
5811            header
5812            (make-full-mail-header
5813             ;; Number.
5814             (prog1
5815                 (setq number (read cur))
5816               (end-of-line)
5817               (setq p (point))
5818               (narrow-to-region (point)
5819                                 (or (and (search-forward "\n.\n" nil t)
5820                                          (- (point) 2))
5821                                     (point))))
5822             ;; Subject.
5823             (progn
5824               (goto-char p)
5825               (if (search-forward "\nsubject:" nil t)
5826                   (nnheader-header-value)
5827                 "(none)"))
5828             ;; From.
5829             (progn
5830               (goto-char p)
5831               (if (search-forward "\nfrom:" nil t)
5832                   (nnheader-header-value)
5833                 "(nobody)"))
5834             ;; Date.
5835             (progn
5836               (goto-char p)
5837               (if (search-forward "\ndate:" nil t)
5838                   (nnheader-header-value) ""))
5839             ;; Message-ID.
5840             (progn
5841               (goto-char p)
5842               (setq id (if (re-search-forward
5843                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5844                            ;; We do it this way to make sure the Message-ID
5845                            ;; is (somewhat) syntactically valid.
5846                            (buffer-substring (match-beginning 1)
5847                                              (match-end 1))
5848                          ;; If there was no message-id, we just fake one
5849                          ;; to make subsequent routines simpler.
5850                          (nnheader-generate-fake-message-id number))))
5851             ;; References.
5852             (progn
5853               (goto-char p)
5854               (if (search-forward "\nreferences:" nil t)
5855                   (progn
5856                     (setq end (point))
5857                     (prog1
5858                         (nnheader-header-value)
5859                       (setq ref
5860                             (buffer-substring
5861                              (progn
5862                                ;; (end-of-line)
5863                                (search-backward ">" end t)
5864                                (1+ (point)))
5865                              (progn
5866                                (search-backward "<" end t)
5867                                (point))))))
5868                 ;; Get the references from the in-reply-to header if there
5869                 ;; were no references and the in-reply-to header looks
5870                 ;; promising.
5871                 (if (and (search-forward "\nin-reply-to:" nil t)
5872                          (setq in-reply-to (nnheader-header-value))
5873                          (string-match "<[^>]+>" in-reply-to))
5874                     (let (ref2)
5875                       (setq ref (substring in-reply-to (match-beginning 0)
5876                                            (match-end 0)))
5877                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5878                         (setq ref2 (substring in-reply-to (match-beginning 0)
5879                                               (match-end 0)))
5880                         (when (> (length ref2) (length ref))
5881                           (setq ref ref2)))
5882                       ref)
5883                   (setq ref nil))))
5884             ;; Chars.
5885             (progn
5886               (goto-char p)
5887               (if (search-forward "\nchars: " nil t)
5888                   (if (numberp (setq chars (ignore-errors (read cur))))
5889                       chars -1)
5890                 -1))
5891             ;; Lines.
5892             (progn
5893               (goto-char p)
5894               (if (search-forward "\nlines: " nil t)
5895                   (if (numberp (setq lines (ignore-errors (read cur))))
5896                       lines -1)
5897                 -1))
5898             ;; Xref.
5899             (progn
5900               (goto-char p)
5901               (and (search-forward "\nxref:" nil t)
5902                    (nnheader-header-value)))
5903             ;; Extra.
5904             (when gnus-extra-headers
5905               (let ((extra gnus-extra-headers)
5906                     out)
5907                 (while extra
5908                   (goto-char p)
5909                   (when (search-forward
5910                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5911                     (push (cons (car extra) (nnheader-header-value)) out))
5912                   (pop extra))
5913                 out))))
5914           (goto-char p)
5915           (if (and (search-forward "\ncontent-type: " nil t)
5916                    (setq ctype (nnheader-header-value)))
5917               (mime-entity-set-content-type-internal
5918                header (mime-parse-Content-Type ctype)))
5919           (when (equal id ref)
5920             (setq ref nil))
5921
5922           (when gnus-alter-header-function
5923             (funcall gnus-alter-header-function header)
5924             (setq id (mail-header-id header)
5925                   ref (gnus-parent-id (mail-header-references header))))
5926
5927           (when (setq header
5928                       (gnus-dependencies-add-header
5929                        header dependencies force-new))
5930             (push header headers))
5931           (goto-char (point-max))
5932           (widen))
5933         (nreverse headers)))))
5934
5935 ;; Goes through the xover lines and returns a list of vectors
5936 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5937                                                   force-new dependencies
5938                                                   group also-fetch-heads)
5939   "Parse the news overview data in the server buffer.
5940 Return a list of headers that match SEQUENCE (see
5941 `nntp-retrieve-headers')."
5942   ;; Get the Xref when the users reads the articles since most/some
5943   ;; NNTP servers do not include Xrefs when using XOVER.
5944   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5945   (let ((mail-parse-charset gnus-newsgroup-charset)
5946         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5947         (cur nntp-server-buffer)
5948         (dependencies (or dependencies gnus-newsgroup-dependencies))
5949         (allp (cond
5950                ((eq gnus-read-all-available-headers t)
5951                 t)
5952                ((stringp gnus-read-all-available-headers)
5953                 (string-match gnus-read-all-available-headers group))
5954                (t
5955                 nil)))
5956         number headers header)
5957     (save-excursion
5958       (set-buffer nntp-server-buffer)
5959       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5960       ;; Allow the user to mangle the headers before parsing them.
5961       (gnus-run-hooks 'gnus-parse-headers-hook)
5962       (goto-char (point-min))
5963       (gnus-parse-without-error
5964         (while (and (or sequence allp)
5965                     (not (eobp)))
5966           (setq number (read cur))
5967           (when (not allp)
5968             (while (and sequence
5969                         (< (car sequence) number))
5970               (setq sequence (cdr sequence))))
5971           (when (and (or allp
5972                          (and sequence
5973                               (eq number (car sequence))))
5974                      (progn
5975                        (setq sequence (cdr sequence))
5976                        (setq header (inline
5977                                       (gnus-nov-parse-line
5978                                        number dependencies force-new)))))
5979             (push header headers))
5980           (forward-line 1)))
5981       ;; A common bug in inn is that if you have posted an article and
5982       ;; then retrieves the active file, it will answer correctly --
5983       ;; the new article is included.  However, a NOV entry for the
5984       ;; article may not have been generated yet, so this may fail.
5985       ;; We work around this problem by retrieving the last few
5986       ;; headers using HEAD.
5987       (if (or (not also-fetch-heads)
5988               (not sequence))
5989           ;; We (probably) got all the headers.
5990           (nreverse headers)
5991         (let ((gnus-nov-is-evil t))
5992           (nconc
5993            (nreverse headers)
5994            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5995              (gnus-get-newsgroup-headers))))))))
5996
5997 (defun gnus-article-get-xrefs ()
5998   "Fill in the Xref value in `gnus-current-headers', if necessary.
5999 This is meant to be called in `gnus-article-internal-prepare-hook'."
6000   (let ((headers (with-current-buffer gnus-summary-buffer
6001                    gnus-current-headers)))
6002     (or (not gnus-use-cross-reference)
6003         (not headers)
6004         (and (mail-header-xref headers)
6005              (not (string= (mail-header-xref headers) "")))
6006         (let ((case-fold-search t)
6007               xref)
6008           (save-restriction
6009             (nnheader-narrow-to-headers)
6010             (goto-char (point-min))
6011             (when (or (and (not (eobp))
6012                            (eq (downcase (char-after)) ?x)
6013                            (looking-at "Xref:"))
6014                       (search-forward "\nXref:" nil t))
6015               (goto-char (1+ (match-end 0)))
6016               (setq xref (buffer-substring (point) (point-at-eol)))
6017               (mail-header-set-xref headers xref)))))))
6018
6019 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6020   "Find article ID and insert the summary line for that article.
6021 OLD-HEADER can either be a header or a line number to insert
6022 the subject line on."
6023   (let* ((line (and (numberp old-header) old-header))
6024          (old-header (and (vectorp old-header) old-header))
6025          (header (cond ((and old-header use-old-header)
6026                         old-header)
6027                        ((and (numberp id)
6028                              (gnus-number-to-header id))
6029                         (gnus-number-to-header id))
6030                        (t
6031                         (gnus-read-header id))))
6032          (number (and (numberp id) id))
6033          d)
6034     (when header
6035       ;; Rebuild the thread that this article is part of and go to the
6036       ;; article we have fetched.
6037       (when (and (not gnus-show-threads)
6038                  old-header)
6039         (when (and number
6040                    (setq d (gnus-data-find (mail-header-number old-header))))
6041           (goto-char (gnus-data-pos d))
6042           (gnus-data-remove
6043            number
6044            (- (point-at-bol)
6045               (prog1
6046                   (1+ (point-at-eol))
6047                 (gnus-delete-line))))))
6048       (when old-header
6049         (mail-header-set-number header (mail-header-number old-header)))
6050       (setq gnus-newsgroup-sparse
6051             (delq (setq number (mail-header-number header))
6052                   gnus-newsgroup-sparse))
6053       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6054       (push number gnus-newsgroup-limit)
6055       (gnus-rebuild-thread (mail-header-id header) line)
6056       (gnus-summary-goto-subject number nil t))
6057     (when (and (numberp number)
6058                (> number 0))
6059       ;; We have to update the boundaries even if we can't fetch the
6060       ;; article if ID is a number -- so that the next `P' or `N'
6061       ;; command will fetch the previous (or next) article even
6062       ;; if the one we tried to fetch this time has been canceled.
6063       (when (> number gnus-newsgroup-end)
6064         (setq gnus-newsgroup-end number))
6065       (when (< number gnus-newsgroup-begin)
6066         (setq gnus-newsgroup-begin number))
6067       (setq gnus-newsgroup-unselected
6068             (delq number gnus-newsgroup-unselected)))
6069     ;; Report back a success?
6070     (and header (mail-header-number header))))
6071
6072 ;;; Process/prefix in the summary buffer
6073
6074 (defun gnus-summary-work-articles (n)
6075   "Return a list of articles to be worked upon.
6076 The prefix argument, the list of process marked articles, and the
6077 current article will be taken into consideration."
6078   (save-excursion
6079     (set-buffer gnus-summary-buffer)
6080     (cond
6081      (n
6082       ;; A numerical prefix has been given.
6083       (setq n (prefix-numeric-value n))
6084       (let ((backward (< n 0))
6085             (n (abs (prefix-numeric-value n)))
6086             articles article)
6087         (save-excursion
6088           (while
6089               (and (> n 0)
6090                    (push (setq article (gnus-summary-article-number))
6091                          articles)
6092                    (if backward
6093                        (gnus-summary-find-prev nil article)
6094                      (gnus-summary-find-next nil article)))
6095             (decf n)))
6096         (nreverse articles)))
6097      ((and (gnus-region-active-p) (mark))
6098       (message "region active")
6099       ;; Work on the region between point and mark.
6100       (let ((max (max (point) (mark)))
6101             articles article)
6102         (save-excursion
6103           (goto-char (min (point) (mark)))
6104           (while
6105               (and
6106                (push (setq article (gnus-summary-article-number)) articles)
6107                (gnus-summary-find-next nil article)
6108                (< (point) max)))
6109           (nreverse articles))))
6110      (gnus-newsgroup-processable
6111       ;; There are process-marked articles present.
6112       ;; Save current state.
6113       (gnus-summary-save-process-mark)
6114       ;; Return the list.
6115       (reverse gnus-newsgroup-processable))
6116      (t
6117       ;; Just return the current article.
6118       (list (gnus-summary-article-number))))))
6119
6120 (defmacro gnus-summary-iterate (arg &rest forms)
6121   "Iterate over the process/prefixed articles and do FORMS.
6122 ARG is the interactive prefix given to the command.  FORMS will be
6123 executed with point over the summary line of the articles."
6124   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6125     `(let ((,articles (gnus-summary-work-articles ,arg)))
6126        (while ,articles
6127          (gnus-summary-goto-subject (car ,articles))
6128          ,@forms
6129          (pop ,articles)))))
6130
6131 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6132 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6133
6134 (defun gnus-summary-save-process-mark ()
6135   "Push the current set of process marked articles on the stack."
6136   (interactive)
6137   (push (copy-sequence gnus-newsgroup-processable)
6138         gnus-newsgroup-process-stack))
6139
6140 (defun gnus-summary-kill-process-mark ()
6141   "Push the current set of process marked articles on the stack and unmark."
6142   (interactive)
6143   (gnus-summary-save-process-mark)
6144   (gnus-summary-unmark-all-processable))
6145
6146 (defun gnus-summary-yank-process-mark ()
6147   "Pop the last process mark state off the stack and restore it."
6148   (interactive)
6149   (unless gnus-newsgroup-process-stack
6150     (error "Empty mark stack"))
6151   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6152
6153 (defun gnus-summary-process-mark-set (set)
6154   "Make SET into the current process marked articles."
6155   (gnus-summary-unmark-all-processable)
6156   (while set
6157     (gnus-summary-set-process-mark (pop set))))
6158
6159 ;;; Searching and stuff
6160
6161 (defun gnus-summary-search-group (&optional backward use-level)
6162   "Search for next unread newsgroup.
6163 If optional argument BACKWARD is non-nil, search backward instead."
6164   (save-excursion
6165     (set-buffer gnus-group-buffer)
6166     (when (gnus-group-search-forward
6167            backward nil (if use-level (gnus-group-group-level) nil))
6168       (gnus-group-group-name))))
6169
6170 (defun gnus-summary-best-group (&optional exclude-group)
6171   "Find the name of the best unread group.
6172 If EXCLUDE-GROUP, do not go to this group."
6173   (with-current-buffer gnus-group-buffer
6174     (save-excursion
6175       (gnus-group-best-unread-group exclude-group))))
6176
6177 (defun gnus-summary-find-next (&optional unread article backward)
6178   (if backward
6179       (gnus-summary-find-prev unread article)
6180     (let* ((dummy (gnus-summary-article-intangible-p))
6181            (article (or article (gnus-summary-article-number)))
6182            (data (gnus-data-find-list article))
6183            result)
6184       (when (and (not dummy)
6185                  (or (not gnus-summary-check-current)
6186                      (not unread)
6187                      (not (gnus-data-unread-p (car data)))))
6188         (setq data (cdr data)))
6189       (when (setq result
6190                   (if unread
6191                       (progn
6192                         (while data
6193                           (unless (memq (gnus-data-number (car data))
6194                                         (cond
6195                                          ((eq gnus-auto-goto-ignores
6196                                               'always-undownloaded)
6197                                           gnus-newsgroup-undownloaded)
6198                                          (gnus-plugged
6199                                           nil)
6200                                          ((eq gnus-auto-goto-ignores
6201                                               'unfetched)
6202                                           gnus-newsgroup-unfetched)
6203                                          ((eq gnus-auto-goto-ignores
6204                                               'undownloaded)
6205                                           gnus-newsgroup-undownloaded)))
6206                             (when (gnus-data-unread-p (car data))
6207                               (setq result (car data)
6208                                     data nil)))
6209                           (setq data (cdr data)))
6210                         result)
6211                     (car data)))
6212         (goto-char (gnus-data-pos result))
6213         (gnus-data-number result)))))
6214
6215 (defun gnus-summary-find-prev (&optional unread article)
6216   (let* ((eobp (eobp))
6217          (article (or article (gnus-summary-article-number)))
6218          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6219          result)
6220     (when (and (not eobp)
6221                (or (not gnus-summary-check-current)
6222                    (not unread)
6223                    (not (gnus-data-unread-p (car data)))))
6224       (setq data (cdr data)))
6225     (when (setq result
6226                 (if unread
6227                     (progn
6228                       (while data
6229                         (unless (memq (gnus-data-number (car data))
6230                                       (cond
6231                                        ((eq gnus-auto-goto-ignores
6232                                             'always-undownloaded)
6233                                         gnus-newsgroup-undownloaded)
6234                                        (gnus-plugged
6235                                         nil)
6236                                        ((eq gnus-auto-goto-ignores
6237                                             'unfetched)
6238                                         gnus-newsgroup-unfetched)
6239                                        ((eq gnus-auto-goto-ignores
6240                                             'undownloaded)
6241                                         gnus-newsgroup-undownloaded)))
6242                           (when (gnus-data-unread-p (car data))
6243                             (setq result (car data)
6244                                   data nil)))
6245                         (setq data (cdr data)))
6246                       result)
6247                   (car data)))
6248       (goto-char (gnus-data-pos result))
6249       (gnus-data-number result))))
6250
6251 (defun gnus-summary-find-subject (subject &optional unread backward article)
6252   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6253          (article (or article (gnus-summary-article-number)))
6254          (articles (gnus-data-list backward))
6255          (arts (gnus-data-find-list article articles))
6256          result)
6257     (when (or (not gnus-summary-check-current)
6258               (not unread)
6259               (not (gnus-data-unread-p (car arts))))
6260       (setq arts (cdr arts)))
6261     (while arts
6262       (and (or (not unread)
6263                (gnus-data-unread-p (car arts)))
6264            (vectorp (gnus-data-header (car arts)))
6265            (gnus-subject-equal
6266             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6267            (setq result (car arts)
6268                  arts nil))
6269       (setq arts (cdr arts)))
6270     (and result
6271          (goto-char (gnus-data-pos result))
6272          (gnus-data-number result))))
6273
6274 (defun gnus-summary-search-forward (&optional unread subject backward)
6275   "Search forward for an article.
6276 If UNREAD, look for unread articles.  If SUBJECT, look for
6277 articles with that subject.  If BACKWARD, search backward instead."
6278   (cond (subject (gnus-summary-find-subject subject unread backward))
6279         (backward (gnus-summary-find-prev unread))
6280         (t (gnus-summary-find-next unread))))
6281
6282 (defun gnus-recenter (&optional n)
6283   "Center point in window and redisplay frame.
6284 Also do horizontal recentering."
6285   (interactive "P")
6286   (when (and gnus-auto-center-summary
6287              (not (eq gnus-auto-center-summary 'vertical)))
6288     (gnus-horizontal-recenter))
6289   (recenter n))
6290
6291 (defun gnus-summary-recenter ()
6292   "Center point in the summary window.
6293 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6294 displayed, no centering will be performed."
6295   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6296   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6297   (interactive)
6298   ;; The user has to want it.
6299   (when gnus-auto-center-summary
6300     (let* ((top (cond ((< (window-height) 4) 0)
6301                       ((< (window-height) 7) 1)
6302                       (t (if (numberp gnus-auto-center-summary)
6303                              gnus-auto-center-summary
6304                            (/ (1- (window-height)) 2)))))
6305            (height (1- (window-height)))
6306            (bottom (save-excursion (goto-char (point-max))
6307                                    (forward-line (- height))
6308                                    (point)))
6309            (window (get-buffer-window (current-buffer))))
6310       (when (get-buffer-window gnus-article-buffer)
6311         ;; Only do recentering when the article buffer is displayed,
6312         ;; Set the window start to either `bottom', which is the biggest
6313         ;; possible valid number, or the second line from the top,
6314         ;; whichever is the least.
6315         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6316           (if (> bottom top-pos)
6317               ;; Keep the second line from the top visible
6318               (set-window-start window top-pos t)
6319             ;; Try to keep the bottom line visible; if it's partially
6320             ;; obscured, either scroll one more line to make it fully
6321             ;; visible, or revert to using TOP-POS.
6322             (save-excursion
6323               (goto-char (point-max))
6324               (forward-line -1)
6325               (let ((last-line-start (point)))
6326                 (goto-char bottom)
6327                 (set-window-start window (point) t)
6328                 (when (not (pos-visible-in-window-p last-line-start window))
6329                   (forward-line 1)
6330                   (set-window-start window (min (point) top-pos) t)))))))
6331       ;; Do horizontal recentering while we're at it.
6332       (when (and (get-buffer-window (current-buffer) t)
6333                  (not (eq gnus-auto-center-summary 'vertical)))
6334         (let ((selected (selected-window)))
6335           (select-window (get-buffer-window (current-buffer) t))
6336           (gnus-summary-position-point)
6337           (gnus-horizontal-recenter)
6338           (select-window selected))))))
6339
6340 (defun gnus-summary-jump-to-group (newsgroup)
6341   "Move point to NEWSGROUP in group mode buffer."
6342   ;; Keep update point of group mode buffer if visible.
6343   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6344       (save-window-excursion
6345         ;; Take care of tree window mode.
6346         (when (get-buffer-window gnus-group-buffer)
6347           (pop-to-buffer gnus-group-buffer))
6348         (gnus-group-jump-to-group newsgroup))
6349     (save-excursion
6350       ;; Take care of tree window mode.
6351       (if (get-buffer-window gnus-group-buffer)
6352           (pop-to-buffer gnus-group-buffer)
6353         (set-buffer gnus-group-buffer))
6354       (gnus-group-jump-to-group newsgroup))))
6355
6356 ;; This function returns a list of article numbers based on the
6357 ;; difference between the ranges of read articles in this group and
6358 ;; the range of active articles.
6359 (defun gnus-list-of-unread-articles (group)
6360   (let* ((read (gnus-info-read (gnus-get-info group)))
6361          (active (or (gnus-active group) (gnus-activate-group group)))
6362          (last (cdr active))
6363          first nlast unread)
6364     ;; If none are read, then all are unread.
6365     (if (not read)
6366         (setq first (car active))
6367       ;; If the range of read articles is a single range, then the
6368       ;; first unread article is the article after the last read
6369       ;; article.  Sounds logical, doesn't it?
6370       (if (and (not (listp (cdr read)))
6371                (or (< (car read) (car active))
6372                    (progn (setq read (list read))
6373                           nil)))
6374           (setq first (max (car active) (1+ (cdr read))))
6375         ;; `read' is a list of ranges.
6376         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6377                                   (caar read)))
6378                   1)
6379           (setq first (car active)))
6380         (while read
6381           (when first
6382             (while (< first nlast)
6383               (setq unread (cons first unread)
6384                     first (1+ first))))
6385           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6386           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6387           (setq read (cdr read)))))
6388     ;; And add the last unread articles.
6389     (while (<= first last)
6390       (setq unread (cons first unread)
6391             first (1+ first)))
6392     ;; Return the list of unread articles.
6393     (delq 0 (nreverse unread))))
6394
6395 (defun gnus-list-of-read-articles (group)
6396   "Return a list of unread, unticked and non-dormant articles."
6397   (let* ((info (gnus-get-info group))
6398          (marked (gnus-info-marks info))
6399          (active (gnus-active group)))
6400     (and info active
6401          (gnus-list-range-difference
6402           (gnus-list-range-difference
6403            (gnus-sorted-complement
6404             (gnus-uncompress-range active)
6405             (gnus-list-of-unread-articles group))
6406            (cdr (assq 'dormant marked)))
6407           (cdr (assq 'tick marked))))))
6408
6409 ;; This function returns a sequence of article numbers based on the
6410 ;; difference between the ranges of read articles in this group and
6411 ;; the range of active articles.
6412 (defun gnus-sequence-of-unread-articles (group)
6413   (let* ((read (gnus-info-read (gnus-get-info group)))
6414          (active (or (gnus-active group) (gnus-activate-group group)))
6415          (last (cdr active))
6416          first nlast unread)
6417     ;; If none are read, then all are unread.
6418     (if (not read)
6419         (setq first (car active))
6420       ;; If the range of read articles is a single range, then the
6421       ;; first unread article is the article after the last read
6422       ;; article.  Sounds logical, doesn't it?
6423       (if (and (not (listp (cdr read)))
6424                (or (< (car read) (car active))
6425                    (progn (setq read (list read))
6426                           nil)))
6427           (setq first (max (car active) (1+ (cdr read))))
6428         ;; `read' is a list of ranges.
6429         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6430                                   (caar read)))
6431                   1)
6432           (setq first (car active)))
6433         (while read
6434           (when first
6435             (push (cons first nlast) unread))
6436           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6437           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6438           (setq read (cdr read)))))
6439     ;; And add the last unread articles.
6440     (cond ((< first last)
6441            (push (cons first last) unread))
6442           ((= first last)
6443            (push first unread)))
6444     ;; Return the sequence of unread articles.
6445     (delq 0 (nreverse unread))))
6446
6447 ;; Various summary commands
6448
6449 (defun gnus-summary-select-article-buffer ()
6450   "Reconfigure windows to show article buffer."
6451   (interactive)
6452   (if (not (gnus-buffer-live-p gnus-article-buffer))
6453       (error "There is no article buffer for this summary buffer")
6454     (gnus-configure-windows 'article)
6455     (select-window (get-buffer-window gnus-article-buffer))))
6456
6457 (defun gnus-summary-universal-argument (arg)
6458   "Perform any operation on all articles that are process/prefixed."
6459   (interactive "P")
6460   (let ((articles (gnus-summary-work-articles arg))
6461         func article)
6462     (if (eq
6463          (setq
6464           func
6465           (key-binding
6466            (read-key-sequence
6467             (substitute-command-keys
6468              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6469          'undefined)
6470         (gnus-error 1 "Undefined key")
6471       (save-excursion
6472         (while articles
6473           (gnus-summary-goto-subject (setq article (pop articles)))
6474           (let (gnus-newsgroup-processable)
6475             (command-execute func))
6476           (gnus-summary-remove-process-mark article)))))
6477   (gnus-summary-position-point))
6478
6479 (defun gnus-summary-toggle-truncation (&optional arg)
6480   "Toggle truncation of summary lines.
6481 With ARG, turn line truncation on if ARG is positive."
6482   (interactive "P")
6483   (setq truncate-lines
6484         (if (null arg) (not truncate-lines)
6485           (> (prefix-numeric-value arg) 0)))
6486   (redraw-display))
6487
6488 (defun gnus-summary-find-for-reselect ()
6489   "Return the number of an article to stay on across a reselect.
6490 The current article is considered, then following articles, then previous
6491 articles.  An article is sought which is not cancelled and isn't a temporary
6492 insertion from another group.  If there's no such then return a dummy 0."
6493   (let (found)
6494     (dolist (rev '(nil t))
6495       (unless found      ; don't demand the reverse list if we don't need it
6496         (let ((data (gnus-data-find-list
6497                      (gnus-summary-article-number) (gnus-data-list rev))))
6498           (while (and data (not found))
6499             (if (and (< 0 (gnus-data-number (car data)))
6500                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6501                 (setq found (gnus-data-number (car data))))
6502             (setq data (cdr data))))))
6503     (or found 0)))
6504
6505 (defun gnus-summary-reselect-current-group (&optional all rescan)
6506   "Exit and then reselect the current newsgroup.
6507 The prefix argument ALL means to select all articles."
6508   (interactive "P")
6509   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6510     (error "Ephemeral groups can't be reselected"))
6511   (let ((current-subject (gnus-summary-find-for-reselect))
6512         (group gnus-newsgroup-name))
6513     (setq gnus-newsgroup-begin nil)
6514     (gnus-summary-exit nil 'leave-hidden)
6515     ;; We have to adjust the point of group mode buffer because
6516     ;; point was moved to the next unread newsgroup by exiting.
6517     (gnus-summary-jump-to-group group)
6518     (when rescan
6519       (save-excursion
6520         (save-window-excursion
6521           ;; Don't show group contents.
6522           (set-window-start (selected-window) (point-max))
6523           (gnus-group-get-new-news-this-group 1))))
6524     (gnus-group-read-group all t)
6525     (gnus-summary-goto-subject current-subject nil t)))
6526
6527 (defun gnus-summary-rescan-group (&optional all)
6528   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6529   (interactive "P")
6530   (gnus-summary-reselect-current-group all t))
6531
6532 (defun gnus-summary-update-info (&optional non-destructive)
6533   (save-excursion
6534     (let ((group gnus-newsgroup-name))
6535       (when group
6536         (when gnus-newsgroup-kill-headers
6537           (setq gnus-newsgroup-killed
6538                 (gnus-compress-sequence
6539                  (gnus-sorted-union
6540                   (gnus-list-range-intersection
6541                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6542                   gnus-newsgroup-unreads)
6543                  t)))
6544         (unless (listp (cdr gnus-newsgroup-killed))
6545           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6546         (let ((headers gnus-newsgroup-headers))
6547           ;; Set the new ranges of read articles.
6548           (with-current-buffer gnus-group-buffer
6549             (gnus-undo-force-boundary))
6550           (gnus-update-read-articles
6551            group (gnus-sorted-union
6552                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6553           ;; Set the current article marks.
6554           (let ((gnus-newsgroup-scored
6555                  (if (and (not gnus-save-score)
6556                           (not non-destructive))
6557                      nil
6558                    gnus-newsgroup-scored)))
6559             (save-excursion
6560               (gnus-update-marks)))
6561           ;; Do the cross-ref thing.
6562           (when gnus-use-cross-reference
6563             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6564           ;; Do not switch windows but change the buffer to work.
6565           (set-buffer gnus-group-buffer)
6566           (unless (gnus-ephemeral-group-p group)
6567             (gnus-group-update-group group)))))))
6568
6569 (defun gnus-summary-save-newsrc (&optional force)
6570   "Save the current number of read/marked articles in the dribble buffer.
6571 The dribble buffer will then be saved.
6572 If FORCE (the prefix), also save the .newsrc file(s)."
6573   (interactive "P")
6574   (gnus-summary-update-info t)
6575   (if force
6576       (gnus-save-newsrc-file)
6577     (gnus-dribble-save)))
6578
6579 (defun gnus-summary-exit (&optional temporary leave-hidden)
6580   "Exit reading current newsgroup, and then return to group selection mode.
6581 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6582   (interactive)
6583   (gnus-set-global-variables)
6584   (gnus-kill-save-kill-buffer)
6585   (gnus-async-halt-prefetch)
6586   (let* ((group gnus-newsgroup-name)
6587          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6588          (gnus-group-is-exiting-p t)
6589          (mode major-mode)
6590          (group-point nil)
6591          (buf (current-buffer)))
6592     (unless quit-config
6593       ;; Do adaptive scoring, and possibly save score files.
6594       (when gnus-newsgroup-adaptive
6595         (gnus-score-adaptive))
6596       (when gnus-use-scoring
6597         (gnus-score-save)))
6598     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6599     ;; If we have several article buffers, we kill them at exit.
6600     (unless gnus-single-article-buffer
6601       (gnus-kill-buffer gnus-original-article-buffer)
6602       (setq gnus-article-current nil))
6603     (when gnus-use-cache
6604       (gnus-cache-possibly-remove-articles)
6605       (gnus-cache-save-buffers))
6606     (gnus-async-prefetch-remove-group group)
6607     (when gnus-suppress-duplicates
6608       (gnus-dup-enter-articles))
6609     (when gnus-use-trees
6610       (gnus-tree-close group))
6611     (when gnus-use-cache
6612       (gnus-cache-write-active))
6613     ;; Remove entries for this group.
6614     (nnmail-purge-split-history (gnus-group-real-name group))
6615     ;; Make all changes in this group permanent.
6616     (unless quit-config
6617       (gnus-run-hooks 'gnus-exit-group-hook)
6618       (gnus-summary-update-info))
6619     (gnus-close-group group)
6620     ;; Make sure where we were, and go to next newsgroup.
6621     (set-buffer gnus-group-buffer)
6622     (unless quit-config
6623       (gnus-group-jump-to-group group))
6624     (gnus-run-hooks 'gnus-summary-exit-hook)
6625     (unless (or quit-config
6626                 ;; If this group has disappeared from the summary
6627                 ;; buffer, don't skip forwards.
6628                 (not (string= group (gnus-group-group-name))))
6629       (gnus-group-next-unread-group 1))
6630     (setq group-point (point))
6631     (if temporary
6632         nil                             ;Nothing to do.
6633       ;; If we have several article buffers, we kill them at exit.
6634       (unless gnus-single-article-buffer
6635         (gnus-kill-buffer gnus-article-buffer)
6636         (gnus-kill-buffer gnus-original-article-buffer)
6637         (setq gnus-article-current nil))
6638       (set-buffer buf)
6639       (if (not gnus-kill-summary-on-exit)
6640           (progn
6641             (gnus-deaden-summary)
6642             (setq mode nil))
6643         ;; We set all buffer-local variables to nil.  It is unclear why
6644         ;; this is needed, but if we don't, buffer-local variables are
6645         ;; not garbage-collected, it seems.  This would the lead to en
6646         ;; ever-growing Emacs.
6647         (gnus-summary-clear-local-variables)
6648         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6649           (gnus-summary-clear-local-variables))
6650         (when (get-buffer gnus-article-buffer)
6651           (bury-buffer gnus-article-buffer))
6652         ;; We clear the global counterparts of the buffer-local
6653         ;; variables as well, just to be on the safe side.
6654         (set-buffer gnus-group-buffer)
6655         (gnus-summary-clear-local-variables)
6656         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6657           (gnus-summary-clear-local-variables))
6658         ;; Return to group mode buffer.
6659         (when (eq mode 'gnus-summary-mode)
6660           (gnus-kill-buffer buf)))
6661       (setq gnus-current-select-method gnus-select-method)
6662       (if leave-hidden
6663           (set-buffer gnus-group-buffer)
6664         (pop-to-buffer gnus-group-buffer))
6665       (if (not quit-config)
6666           (progn
6667             (goto-char group-point)
6668             (unless leave-hidden
6669               (gnus-configure-windows 'group 'force))
6670             (unless (pos-visible-in-window-p)
6671               (forward-line (/ (static-if (featurep 'xemacs)
6672                                    (window-displayed-height)
6673                                  (1- (window-height)))
6674                                -2))
6675               (set-window-start (selected-window) (point))
6676               (goto-char group-point)))
6677         (gnus-handle-ephemeral-exit quit-config))
6678       ;; Clear the current group name.
6679       (unless quit-config
6680         (setq gnus-newsgroup-name nil)))))
6681
6682 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6683 (defun gnus-summary-exit-no-update (&optional no-questions)
6684   "Quit reading current newsgroup without updating read article info."
6685   (interactive)
6686   (let* ((group gnus-newsgroup-name)
6687          (gnus-group-is-exiting-p t)
6688          (gnus-group-is-exiting-without-update-p t)
6689          (quit-config (gnus-group-quit-config group)))
6690     (when (or no-questions
6691               gnus-expert-user
6692               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6693       (gnus-async-halt-prefetch)
6694       (run-hooks 'gnus-summary-prepare-exit-hook)
6695       ;; If we have several article buffers, we kill them at exit.
6696       (unless gnus-single-article-buffer
6697         (gnus-kill-buffer gnus-article-buffer)
6698         (gnus-kill-buffer gnus-original-article-buffer)
6699         (setq gnus-article-current nil))
6700       (if (not gnus-kill-summary-on-exit)
6701           (gnus-deaden-summary)
6702         (gnus-close-group group)
6703         (gnus-summary-clear-local-variables)
6704         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6705           (gnus-summary-clear-local-variables))
6706         (set-buffer gnus-group-buffer)
6707         (gnus-summary-clear-local-variables)
6708         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6709           (gnus-summary-clear-local-variables))
6710         (gnus-kill-buffer gnus-summary-buffer))
6711       (unless gnus-single-article-buffer
6712         (setq gnus-article-current nil))
6713       (when gnus-use-trees
6714         (gnus-tree-close group))
6715       (gnus-async-prefetch-remove-group group)
6716       (when (get-buffer gnus-article-buffer)
6717         (bury-buffer gnus-article-buffer))
6718       ;; Return to the group buffer.
6719       (gnus-configure-windows 'group 'force)
6720       ;; Clear the current group name.
6721       (setq gnus-newsgroup-name nil)
6722       (unless (gnus-ephemeral-group-p group)
6723         (gnus-group-update-group group))
6724       (when (equal (gnus-group-group-name) group)
6725         (gnus-group-next-unread-group 1))
6726       (when quit-config
6727         (gnus-handle-ephemeral-exit quit-config)))))
6728
6729 (defun gnus-handle-ephemeral-exit (quit-config)
6730   "Handle movement when leaving an ephemeral group.
6731 The state which existed when entering the ephemeral is reset."
6732   (if (not (buffer-name (car quit-config)))
6733       (gnus-configure-windows 'group 'force)
6734     (set-buffer (car quit-config))
6735     (cond ((eq major-mode 'gnus-summary-mode)
6736            (gnus-set-global-variables))
6737           ((eq major-mode 'gnus-article-mode)
6738            (save-excursion
6739              ;; The `gnus-summary-buffer' variable may point
6740              ;; to the old summary buffer when using a single
6741              ;; article buffer.
6742              (unless (gnus-buffer-live-p gnus-summary-buffer)
6743                (set-buffer gnus-group-buffer))
6744              (set-buffer gnus-summary-buffer)
6745              (gnus-set-global-variables))))
6746     (if (or (eq (cdr quit-config) 'article)
6747             (eq (cdr quit-config) 'pick))
6748         (progn
6749           ;; The current article may be from the ephemeral group
6750           ;; thus it is best that we reload this article
6751           ;;
6752           ;; If we're exiting from a large digest, this can be
6753           ;; extremely slow.  So, it's better not to reload it. -- jh.
6754           ;;(gnus-summary-show-article)
6755           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6756               (gnus-configure-windows 'pick 'force)
6757             (gnus-configure-windows (cdr quit-config) 'force)))
6758       (gnus-configure-windows (cdr quit-config) 'force))
6759     (when (eq major-mode 'gnus-summary-mode)
6760       (gnus-summary-next-subject 1 nil t)
6761       (gnus-summary-recenter)
6762       (gnus-summary-position-point))))
6763
6764 (defun gnus-summary-preview-mime-message ()
6765   "MIME decode and play this message."
6766   (interactive)
6767   (let ((gnus-break-pages nil)
6768         (gnus-show-mime t))
6769     (gnus-summary-select-article gnus-show-all-headers t))
6770   (let ((w (get-buffer-window gnus-article-buffer)))
6771     (when w
6772       (select-window (get-buffer-window gnus-article-buffer)))))
6773
6774 ;;; Dead summaries.
6775
6776 (defvar gnus-dead-summary-mode-map nil)
6777
6778 (unless gnus-dead-summary-mode-map
6779   (setq gnus-dead-summary-mode-map (make-keymap))
6780   (suppress-keymap gnus-dead-summary-mode-map)
6781   (substitute-key-definition
6782    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6783   (dolist (key '("\C-d" "\r" "\177" [delete]))
6784     (define-key gnus-dead-summary-mode-map
6785       key 'gnus-summary-wake-up-the-dead))
6786   (dolist (key '("q" "Q"))
6787     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6788
6789 (defvar gnus-dead-summary-mode nil
6790   "Minor mode for Gnus summary buffers.")
6791
6792 (defun gnus-dead-summary-mode (&optional arg)
6793   "Minor mode for Gnus summary buffers."
6794   (interactive "P")
6795   (when (eq major-mode 'gnus-summary-mode)
6796     (make-local-variable 'gnus-dead-summary-mode)
6797     (setq gnus-dead-summary-mode
6798           (if (null arg) (not gnus-dead-summary-mode)
6799             (> (prefix-numeric-value arg) 0)))
6800     (when gnus-dead-summary-mode
6801       (add-minor-mode
6802        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6803
6804 (defun gnus-deaden-summary ()
6805   "Make the current summary buffer into a dead summary buffer."
6806   ;; Kill any previous dead summary buffer.
6807   (when (and gnus-dead-summary
6808              (buffer-name gnus-dead-summary))
6809     (with-current-buffer gnus-dead-summary
6810       (when gnus-dead-summary-mode
6811         (kill-buffer (current-buffer)))))
6812   ;; Make this the current dead summary.
6813   (setq gnus-dead-summary (current-buffer))
6814   (gnus-dead-summary-mode 1)
6815   (let ((name (buffer-name)))
6816     (when (string-match "Summary" name)
6817       (rename-buffer
6818        (concat (substring name 0 (match-beginning 0)) "Dead "
6819                (substring name (match-beginning 0)))
6820        t)
6821       (bury-buffer))))
6822
6823 (defun gnus-kill-or-deaden-summary (buffer)
6824   "Kill or deaden the summary BUFFER."
6825   (save-excursion
6826     (when (and (buffer-name buffer)
6827                (not gnus-single-article-buffer))
6828       (with-current-buffer buffer
6829         (gnus-kill-buffer gnus-article-buffer)
6830         (gnus-kill-buffer gnus-original-article-buffer)))
6831     (cond
6832      ;; Kill the buffer.
6833      (gnus-kill-summary-on-exit
6834       (when (and gnus-use-trees
6835                  (gnus-buffer-exists-p buffer))
6836         (save-excursion
6837           (set-buffer buffer)
6838           (gnus-tree-close gnus-newsgroup-name)))
6839       (gnus-kill-buffer buffer))
6840      ;; Deaden the buffer.
6841      ((gnus-buffer-exists-p buffer)
6842       (save-excursion
6843         (set-buffer buffer)
6844         (gnus-deaden-summary))))))
6845
6846 (defun gnus-summary-wake-up-the-dead (&rest args)
6847   "Wake up the dead summary buffer."
6848   (interactive)
6849   (gnus-dead-summary-mode -1)
6850   (let ((name (buffer-name)))
6851     (when (string-match "Dead " name)
6852       (rename-buffer
6853        (concat (substring name 0 (match-beginning 0))
6854                (substring name (match-end 0)))
6855        t)))
6856   (gnus-message 3 "This dead summary is now alive again"))
6857
6858 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6859 (defun gnus-summary-fetch-faq (&optional faq-dir)
6860   "Fetch the FAQ for the current group.
6861 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6862 in."
6863   (interactive
6864    (list
6865     (when current-prefix-arg
6866       (completing-read
6867        "FAQ dir: " (and (listp gnus-group-faq-directory)
6868                         (mapcar 'list
6869                                 gnus-group-faq-directory))))))
6870   (let (gnus-faq-buffer)
6871     (when (setq gnus-faq-buffer
6872                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6873       (gnus-configure-windows 'summary-faq))))
6874
6875 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6876 (defun gnus-summary-describe-group (&optional force)
6877   "Describe the current newsgroup."
6878   (interactive "P")
6879   (gnus-group-describe-group force gnus-newsgroup-name))
6880
6881 (defun gnus-summary-describe-briefly ()
6882   "Describe summary mode commands briefly."
6883   (interactive)
6884   (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")))
6885
6886 ;; Walking around group mode buffer from summary mode.
6887
6888 (defun gnus-summary-next-group (&optional no-article target-group backward)
6889   "Exit current newsgroup and then select next unread newsgroup.
6890 If prefix argument NO-ARTICLE is non-nil, no article is selected
6891 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6892 previous group instead."
6893   (interactive "P")
6894   ;; Stop pre-fetching.
6895   (gnus-async-halt-prefetch)
6896   (let ((current-group gnus-newsgroup-name)
6897         (current-buffer (current-buffer))
6898         entered)
6899     ;; First we semi-exit this group to update Xrefs and all variables.
6900     ;; We can't do a real exit, because the window conf must remain
6901     ;; the same in case the user is prompted for info, and we don't
6902     ;; want the window conf to change before that...
6903     (gnus-summary-exit t)
6904     (while (not entered)
6905       ;; Then we find what group we are supposed to enter.
6906       (set-buffer gnus-group-buffer)
6907       (gnus-group-jump-to-group current-group)
6908       (setq target-group
6909             (or target-group
6910                 (if (eq gnus-keep-same-level 'best)
6911                     (gnus-summary-best-group gnus-newsgroup-name)
6912                   (gnus-summary-search-group backward gnus-keep-same-level))))
6913       (if (not target-group)
6914           ;; There are no further groups, so we return to the group
6915           ;; buffer.
6916           (progn
6917             (gnus-message 5 "Returning to the group buffer")
6918             (setq entered t)
6919             (when (gnus-buffer-live-p current-buffer)
6920               (set-buffer current-buffer)
6921               (gnus-summary-exit))
6922             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6923         ;; We try to enter the target group.
6924         (gnus-group-jump-to-group target-group)
6925         (let ((unreads (gnus-group-group-unread)))
6926           (if (and (or (eq t unreads)
6927                        (and unreads (not (zerop unreads))))
6928                    (gnus-summary-read-group
6929                     target-group nil no-article
6930                     (and (buffer-name current-buffer) current-buffer)
6931                     nil backward))
6932               (setq entered t)
6933             (setq current-group target-group
6934                   target-group nil)))))))
6935
6936 (defun gnus-summary-prev-group (&optional no-article)
6937   "Exit current newsgroup and then select previous unread newsgroup.
6938 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6939   (interactive "P")
6940   (gnus-summary-next-group no-article nil t))
6941
6942 ;; Walking around summary lines.
6943
6944 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6945   "Go to the first subject satisfying any non-nil constraint.
6946 If UNREAD is non-nil, the article should be unread.
6947 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6948 If UNSEEN is non-nil, the article should be unseen.
6949 Returns the article selected or nil if there are no matching articles."
6950   (interactive "P")
6951   (cond
6952    ;; Empty summary.
6953    ((null gnus-newsgroup-data)
6954     (gnus-message 3 "No articles in the group")
6955     nil)
6956    ;; Pick the first article.
6957    ((not (or unread undownloaded unseen))
6958     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6959     (gnus-data-number (car gnus-newsgroup-data)))
6960    ;; Find the first unread article.
6961    (t
6962     (let ((data gnus-newsgroup-data))
6963       (while (and data
6964                   (let ((num (gnus-data-number (car data))))
6965                     (or (memq num gnus-newsgroup-unfetched)
6966                         (not (or (and unread
6967                                       (memq num gnus-newsgroup-unreads))
6968                                  (and undownloaded
6969                                       (memq num gnus-newsgroup-undownloaded))
6970                                  (and unseen
6971                                       (memq num gnus-newsgroup-unseen)))))))
6972         (setq data (cdr data)))
6973       (prog1
6974           (if data
6975               (progn
6976                 (goto-char (gnus-data-pos (car data)))
6977                 (gnus-data-number (car data)))
6978             (gnus-message 3 "No more%s articles"
6979                           (let* ((r (when unread " unread"))
6980                                  (d (when undownloaded " undownloaded"))
6981                                  (s (when unseen " unseen"))
6982                                  (l (delq nil (list r d s))))
6983                             (cond ((= 3 (length l))
6984                                    (concat r "," d ", or" s))
6985                                   ((= 2 (length l))
6986                                    (concat (car l) ", or" (cadr l)))
6987                                   ((= 1 (length l))
6988                                    (car l))
6989                                   (t
6990                                    ""))))
6991             nil
6992             )
6993         (gnus-summary-position-point))))))
6994
6995 (defun gnus-summary-next-subject (n &optional unread dont-display)
6996   "Go to next N'th summary line.
6997 If N is negative, go to the previous N'th subject line.
6998 If UNREAD is non-nil, only unread articles are selected.
6999 The difference between N and the actual number of steps taken is
7000 returned."
7001   (interactive "p")
7002   (let ((backward (< n 0))
7003         (n (abs n)))
7004     (while (and (> n 0)
7005                 (if backward
7006                     (gnus-summary-find-prev unread)
7007                   (gnus-summary-find-next unread)))
7008       (unless (zerop (setq n (1- n)))
7009         (gnus-summary-show-thread)))
7010     (when (/= 0 n)
7011       (gnus-message 7 "No more%s articles"
7012                     (if unread " unread" "")))
7013     (unless dont-display
7014       (gnus-summary-recenter)
7015       (gnus-summary-position-point))
7016     n))
7017
7018 (defun gnus-summary-next-unread-subject (n)
7019   "Go to next N'th unread summary line."
7020   (interactive "p")
7021   (gnus-summary-next-subject n t))
7022
7023 (defun gnus-summary-prev-subject (n &optional unread)
7024   "Go to previous N'th summary line.
7025 If optional argument UNREAD is non-nil, only unread article is selected."
7026   (interactive "p")
7027   (gnus-summary-next-subject (- n) unread))
7028
7029 (defun gnus-summary-prev-unread-subject (n)
7030   "Go to previous N'th unread summary line."
7031   (interactive "p")
7032   (gnus-summary-next-subject (- n) t))
7033
7034 (defun gnus-summary-goto-subjects (articles)
7035   "Insert the subject header for ARTICLES in the current buffer."
7036   (save-excursion
7037     (dolist (article articles)
7038       (gnus-summary-goto-subject article t)))
7039   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7040   (gnus-summary-position-point))
7041  
7042 (defun gnus-summary-goto-subject (article &optional force silent)
7043   "Go the subject line of ARTICLE.
7044 If FORCE, also allow jumping to articles not currently shown."
7045   (interactive "nArticle number: ")
7046   (unless (numberp article)
7047     (error "Article %s is not a number" article))
7048   (let ((b (point))
7049         (data (gnus-data-find article)))
7050     ;; We read in the article if we have to.
7051     (and (not data)
7052          force
7053          (gnus-summary-insert-subject
7054           article
7055           (if (or (numberp force) (vectorp force)) force)
7056           t)
7057          (setq data (gnus-data-find article)))
7058     (goto-char b)
7059     (if (not data)
7060         (progn
7061           (unless silent
7062             (gnus-message 3 "Can't find article %d" article))
7063           nil)
7064       (let ((pt (gnus-data-pos data)))
7065         (goto-char pt)
7066         (gnus-summary-set-article-display-arrow pt))
7067       (gnus-summary-position-point)
7068       article)))
7069
7070 ;; Walking around summary lines with displaying articles.
7071
7072 (defun gnus-summary-expand-window (&optional arg)
7073   "Make the summary buffer take up the entire Emacs frame.
7074 Given a prefix, will force an `article' buffer configuration."
7075   (interactive "P")
7076   (if arg
7077       (gnus-configure-windows 'article 'force)
7078     (gnus-configure-windows 'summary 'force)))
7079
7080 (defun gnus-summary-display-article (article &optional all-header)
7081   "Display ARTICLE in article buffer."
7082   (when (gnus-buffer-live-p gnus-article-buffer)
7083     (with-current-buffer gnus-article-buffer
7084       (set-buffer-multibyte t)))
7085   (gnus-set-global-variables)
7086   (when (gnus-buffer-live-p gnus-article-buffer)
7087     (with-current-buffer gnus-article-buffer
7088       (setq gnus-article-charset gnus-newsgroup-charset)
7089       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7090       (set-buffer-multibyte t)))
7091   (if (null article)
7092       nil
7093     (prog1
7094         (if gnus-summary-display-article-function
7095             (funcall gnus-summary-display-article-function article all-header)
7096           (gnus-article-prepare article all-header))
7097       (with-current-buffer gnus-article-buffer
7098         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7099              nil))
7100       (gnus-run-hooks 'gnus-select-article-hook)
7101       (when (and gnus-current-article
7102                  (not (zerop gnus-current-article)))
7103         (gnus-summary-goto-subject gnus-current-article))
7104       (gnus-summary-recenter)
7105       (when (and gnus-use-trees gnus-show-threads)
7106         (gnus-possibly-generate-tree article)
7107         (gnus-highlight-selected-tree article))
7108       ;; Successfully display article.
7109       (gnus-article-set-window-start
7110        (cdr (assq article gnus-newsgroup-bookmarks))))))
7111
7112 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7113   "Select the current article.
7114 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7115 non-nil, the article will be re-fetched even if it already present in
7116 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7117 be displayed."
7118   ;; Make sure we are in the summary buffer to work around bbdb bug.
7119   (unless (eq major-mode 'gnus-summary-mode)
7120     (set-buffer gnus-summary-buffer))
7121   (let ((article (or article (gnus-summary-article-number)))
7122         (all-headers (not (not all-headers))) ;Must be T or NIL.
7123         gnus-summary-display-article-function)
7124     (and (not pseudo)
7125          (gnus-summary-article-pseudo-p article)
7126          (error "This is a pseudo-article"))
7127     (save-excursion
7128       (set-buffer gnus-summary-buffer)
7129       (if (or (and gnus-single-article-buffer
7130                    (or (null gnus-current-article)
7131                        (null gnus-article-current)
7132                        (null (get-buffer gnus-article-buffer))
7133                        (not (eq article (cdr gnus-article-current)))
7134                        (not (equal (car gnus-article-current)
7135                                    gnus-newsgroup-name))))
7136               (and (not gnus-single-article-buffer)
7137                    (or (null gnus-current-article)
7138                        (not (eq gnus-current-article article))))
7139               force)
7140           ;; The requested article is different from the current article.
7141           (progn
7142             (gnus-summary-display-article article all-headers)
7143             (gnus-article-set-window-start
7144              (cdr (assq article gnus-newsgroup-bookmarks)))
7145             article)
7146         'old))))
7147
7148 (defun gnus-summary-force-verify-and-decrypt ()
7149   "Display buttons for signed/encrypted parts and verify/decrypt them."
7150   (interactive)
7151   (let ((mm-verify-option 'known)
7152         (mm-decrypt-option 'known)
7153         (gnus-article-emulate-mime t)
7154         (mm-fill-flowed nil)
7155         (gnus-buttonized-mime-types (append (list "multipart/signed"
7156                                                   "multipart/encrypted")
7157                                             gnus-buttonized-mime-types)))
7158     (gnus-summary-select-article nil 'force)))
7159
7160 (defun gnus-summary-set-current-mark (&optional current-mark)
7161   "Obsolete function."
7162   nil)
7163
7164 (defun gnus-summary-next-article (&optional unread subject backward push)
7165   "Select the next article.
7166 If UNREAD, only unread articles are selected.
7167 If SUBJECT, only articles with SUBJECT are selected.
7168 If BACKWARD, the previous article is selected instead of the next."
7169   (interactive "P")
7170   (cond
7171    ;; Is there such an article?
7172    ((and (gnus-summary-search-forward unread subject backward)
7173          (or (gnus-summary-display-article (gnus-summary-article-number))
7174              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7175     (gnus-summary-position-point))
7176    ;; If not, we try the first unread, if that is wanted.
7177    ((and subject
7178          gnus-auto-select-same
7179          (gnus-summary-first-unread-article))
7180     (gnus-summary-position-point)
7181     (gnus-message 6 "Wrapped"))
7182    ;; Try to get next/previous article not displayed in this group.
7183    ((and gnus-auto-extend-newsgroup
7184          (not unread) (not subject))
7185     (gnus-summary-goto-article
7186      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7187      nil (count-lines (point-min) (point))))
7188    ;; Go to next/previous group.
7189    (t
7190     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7191       (gnus-summary-jump-to-group gnus-newsgroup-name))
7192     (let ((cmd last-command-char)
7193           (point
7194            (with-current-buffer gnus-group-buffer
7195              (point)))
7196           (group
7197            (if (eq gnus-keep-same-level 'best)
7198                (gnus-summary-best-group gnus-newsgroup-name)
7199              (gnus-summary-search-group backward gnus-keep-same-level))))
7200       ;; For some reason, the group window gets selected.  We change
7201       ;; it back.
7202       (select-window (get-buffer-window (current-buffer)))
7203       ;; Select next unread newsgroup automagically.
7204       (cond
7205        ((or (not gnus-auto-select-next)
7206             (not cmd))
7207         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7208        ((or (eq gnus-auto-select-next 'quietly)
7209             (and (eq gnus-auto-select-next 'slightly-quietly)
7210                  push)
7211             (and (eq gnus-auto-select-next 'almost-quietly)
7212                  (gnus-summary-last-article-p)))
7213         ;; Select quietly.
7214         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7215             (gnus-summary-exit)
7216           (gnus-message 7 "No more%s articles (%s)..."
7217                         (if unread " unread" "")
7218                         (if group (concat "selecting " group)
7219                           "exiting"))
7220           (gnus-summary-next-group nil group backward)))
7221        (t
7222         (when (gnus-key-press-event-p last-input-event)
7223           (gnus-summary-walk-group-buffer
7224            gnus-newsgroup-name cmd unread backward point))))))))
7225
7226 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7227   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7228                       (?\C-p (gnus-group-prev-unread-group 1))))
7229         (cursor-in-echo-area t)
7230         keve key group ended prompt)
7231     (save-excursion
7232       (set-buffer gnus-group-buffer)
7233       (goto-char start)
7234       (setq group
7235             (if (eq gnus-keep-same-level 'best)
7236                 (gnus-summary-best-group gnus-newsgroup-name)
7237               (gnus-summary-search-group backward gnus-keep-same-level))))
7238     (while (not ended)
7239       (setq prompt
7240             (format
7241              "No more%s articles%s " (if unread " unread" "")
7242              (if (and group
7243                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7244                  (format " (Type %s for %s [%s])"
7245                          (single-key-description cmd) group
7246                          (gnus-group-unread group))
7247                (format " (Type %s to exit %s)"
7248                        (single-key-description cmd)
7249                        gnus-newsgroup-name))))
7250       ;; Confirm auto selection.
7251       (setq key (car (setq keve (gnus-read-event-char prompt)))
7252             ended t)
7253       (cond
7254        ((assq key keystrokes)
7255         (let ((obuf (current-buffer)))
7256           (switch-to-buffer gnus-group-buffer)
7257           (when group
7258             (gnus-group-jump-to-group group))
7259           (eval (cadr (assq key keystrokes)))
7260           (setq group (gnus-group-group-name))
7261           (switch-to-buffer obuf))
7262         (setq ended nil))
7263        ((equal key cmd)
7264         (if (or (not group)
7265                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7266             (gnus-summary-exit)
7267           (gnus-summary-next-group nil group backward)))
7268        (t
7269         (push (cdr keve) unread-command-events))))))
7270
7271 (defun gnus-summary-next-unread-article ()
7272   "Select unread article after current one."
7273   (interactive)
7274   (gnus-summary-next-article
7275    (or (not (eq gnus-summary-goto-unread 'never))
7276        (gnus-summary-last-article-p (gnus-summary-article-number)))
7277    (and gnus-auto-select-same
7278         (gnus-summary-article-subject))))
7279
7280 (defun gnus-summary-prev-article (&optional unread subject)
7281   "Select the article after the current one.
7282 If UNREAD is non-nil, only unread articles are selected."
7283   (interactive "P")
7284   (gnus-summary-next-article unread subject t))
7285
7286 (defun gnus-summary-prev-unread-article ()
7287   "Select unread article before current one."
7288   (interactive)
7289   (gnus-summary-prev-article
7290    (or (not (eq gnus-summary-goto-unread 'never))
7291        (gnus-summary-first-article-p (gnus-summary-article-number)))
7292    (and gnus-auto-select-same
7293         (gnus-summary-article-subject))))
7294
7295 (defun gnus-summary-next-page (&optional lines circular stop)
7296   "Show next page of the selected article.
7297 If at the end of the current article, select the next article.
7298 LINES says how many lines should be scrolled up.
7299
7300 If CIRCULAR is non-nil, go to the start of the article instead of
7301 selecting the next article when reaching the end of the current
7302 article.
7303
7304 If STOP is non-nil, just stop when reaching the end of the message.
7305
7306 Also see the variable `gnus-article-skip-boring'."
7307   (interactive "P")
7308   (setq gnus-summary-buffer (current-buffer))
7309   (gnus-set-global-variables)
7310   (let ((article (gnus-summary-article-number))
7311         (article-window (get-buffer-window gnus-article-buffer t))
7312         endp)
7313     ;; If the buffer is empty, we have no article.
7314     (unless article
7315       (error "No article to select"))
7316     (gnus-configure-windows 'article)
7317     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7318         (if (and (eq gnus-summary-goto-unread 'never)
7319                  (not (gnus-summary-last-article-p article)))
7320             (gnus-summary-next-article)
7321           (gnus-summary-next-unread-article))
7322       (if (or (null gnus-current-article)
7323               (null gnus-article-current)
7324               (/= article (cdr gnus-article-current))
7325               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7326           ;; Selected subject is different from current article's.
7327           (gnus-summary-display-article article)
7328         (when article-window
7329           (gnus-eval-in-buffer-window gnus-article-buffer
7330             (setq endp (or (gnus-article-next-page lines)
7331                            (gnus-article-only-boring-p))))
7332           (when endp
7333             (cond (stop
7334                    (gnus-message 3 "End of message"))
7335                   (circular
7336                    (gnus-summary-beginning-of-article))
7337                   (lines
7338                    (gnus-message 3 "End of message"))
7339                   ((null lines)
7340                    (if (and (eq gnus-summary-goto-unread 'never)
7341                             (not (gnus-summary-last-article-p article)))
7342                        (gnus-summary-next-article)
7343                      (gnus-summary-next-unread-article))))))))
7344     (gnus-summary-recenter)
7345     (gnus-summary-position-point)))
7346
7347 (defun gnus-summary-prev-page (&optional lines move)
7348   "Show previous page of selected article.
7349 Argument LINES specifies lines to be scrolled down.
7350 If MOVE, move to the previous unread article if point is at
7351 the beginning of the buffer."
7352   (interactive "P")
7353   (let ((article (gnus-summary-article-number))
7354         (article-window (get-buffer-window gnus-article-buffer t))
7355         endp)
7356     (gnus-configure-windows 'article)
7357     (if (or (null gnus-current-article)
7358             (null gnus-article-current)
7359             (/= article (cdr gnus-article-current))
7360             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7361         ;; Selected subject is different from current article's.
7362         (gnus-summary-display-article article)
7363       (gnus-summary-recenter)
7364       (when article-window
7365         (gnus-eval-in-buffer-window gnus-article-buffer
7366           (setq endp (gnus-article-prev-page lines)))
7367         (when (and move endp)
7368           (cond (lines
7369                  (gnus-message 3 "Beginning of message"))
7370                 ((null lines)
7371                  (if (and (eq gnus-summary-goto-unread 'never)
7372                           (not (gnus-summary-first-article-p article)))
7373                      (gnus-summary-prev-article)
7374                    (gnus-summary-prev-unread-article))))))))
7375   (gnus-summary-position-point))
7376
7377 (defun gnus-summary-prev-page-or-article (&optional lines)
7378   "Show previous page of selected article.
7379 Argument LINES specifies lines to be scrolled down.
7380 If at the beginning of the article, go to the next article."
7381   (interactive "P")
7382   (gnus-summary-prev-page lines t))
7383
7384 (defun gnus-summary-scroll-up (lines)
7385   "Scroll up (or down) one line current article.
7386 Argument LINES specifies lines to be scrolled up (or down if negative)."
7387   (interactive "p")
7388   (gnus-configure-windows 'article)
7389   (gnus-summary-show-thread)
7390   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7391     (gnus-eval-in-buffer-window gnus-article-buffer
7392       (cond ((> lines 0)
7393              (when (gnus-article-next-page lines)
7394                (gnus-message 3 "End of message")))
7395             ((< lines 0)
7396              (gnus-article-prev-page (- lines))))))
7397   (gnus-summary-recenter)
7398   (gnus-summary-position-point))
7399
7400 (defun gnus-summary-scroll-down (lines)
7401   "Scroll down (or up) one line current article.
7402 Argument LINES specifies lines to be scrolled down (or up if negative)."
7403   (interactive "p")
7404   (gnus-summary-scroll-up (- lines)))
7405
7406 (defun gnus-summary-next-same-subject ()
7407   "Select next article which has the same subject as current one."
7408   (interactive)
7409   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7410
7411 (defun gnus-summary-prev-same-subject ()
7412   "Select previous article which has the same subject as current one."
7413   (interactive)
7414   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7415
7416 (defun gnus-summary-next-unread-same-subject ()
7417   "Select next unread article which has the same subject as current one."
7418   (interactive)
7419   (gnus-summary-next-article t (gnus-summary-article-subject)))
7420
7421 (defun gnus-summary-prev-unread-same-subject ()
7422   "Select previous unread article which has the same subject as current one."
7423   (interactive)
7424   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7425
7426 (defun gnus-summary-first-unread-article ()
7427   "Select the first unread article.
7428 Return nil if there are no unread articles."
7429   (interactive)
7430   (prog1
7431       (when (gnus-summary-first-subject t)
7432         (gnus-summary-show-thread)
7433         (gnus-summary-first-subject t)
7434         (gnus-summary-display-article (gnus-summary-article-number)))
7435     (gnus-summary-position-point)))
7436
7437 (defun gnus-summary-first-unread-subject ()
7438   "Place the point on the subject line of the first unread article.
7439 Return nil if there are no unread articles."
7440   (interactive)
7441   (prog1
7442       (when (gnus-summary-first-subject t)
7443         (gnus-summary-show-thread)
7444         (gnus-summary-first-subject t))
7445     (gnus-summary-position-point)))
7446
7447 (defun gnus-summary-first-unseen-subject ()
7448   "Place the point on the subject line of the first unseen article.
7449 Return nil if there are no unseen articles."
7450   (interactive)
7451   (prog1
7452       (when (gnus-summary-first-subject nil nil t)
7453         (gnus-summary-show-thread)
7454         (gnus-summary-first-subject nil nil t))
7455     (gnus-summary-position-point)))
7456
7457 (defun gnus-summary-first-unseen-or-unread-subject ()
7458   "Place the point on the subject line of the first unseen article or,
7459 if all article have been seen, on the subject line of the first unread
7460 article."
7461   (interactive)
7462   (prog1
7463       (unless (when (gnus-summary-first-subject nil nil t)
7464                 (gnus-summary-show-thread)
7465                 (gnus-summary-first-subject nil nil t))
7466         (when (gnus-summary-first-subject t)
7467           (gnus-summary-show-thread)
7468           (gnus-summary-first-subject t)))
7469     (gnus-summary-position-point)))
7470
7471 (defun gnus-summary-first-article ()
7472   "Select the first article.
7473 Return nil if there are no articles."
7474   (interactive)
7475   (prog1
7476       (when (gnus-summary-first-subject)
7477         (gnus-summary-show-thread)
7478         (gnus-summary-first-subject)
7479         (gnus-summary-display-article (gnus-summary-article-number)))
7480     (gnus-summary-position-point)))
7481
7482 (defun gnus-summary-best-unread-article (&optional arg)
7483   "Select the unread article with the highest score.
7484 If given a prefix argument, select the next unread article that has a
7485 score higher than the default score."
7486   (interactive "P")
7487   (let ((article (if arg
7488                      (gnus-summary-better-unread-subject)
7489                    (gnus-summary-best-unread-subject))))
7490     (if article
7491         (gnus-summary-goto-article article)
7492       (error "No unread articles"))))
7493
7494 (defun gnus-summary-best-unread-subject ()
7495   "Select the unread subject with the highest score."
7496   (interactive)
7497   (let ((best -1000000)
7498         (data gnus-newsgroup-data)
7499         article score)
7500     (while data
7501       (and (gnus-data-unread-p (car data))
7502            (> (setq score
7503                     (gnus-summary-article-score (gnus-data-number (car data))))
7504               best)
7505            (setq best score
7506                  article (gnus-data-number (car data))))
7507       (setq data (cdr data)))
7508     (when article
7509       (gnus-summary-goto-subject article))
7510     (gnus-summary-position-point)
7511     article))
7512
7513 (defun gnus-summary-better-unread-subject ()
7514   "Select the first unread subject that has a score over the default score."
7515   (interactive)
7516   (let ((data gnus-newsgroup-data)
7517         article score)
7518     (while (and (setq article (gnus-data-number (car data)))
7519                 (or (gnus-data-read-p (car data))
7520                     (not (> (gnus-summary-article-score article)
7521                             gnus-summary-default-score))))
7522       (setq data (cdr data)))
7523     (when article
7524       (gnus-summary-goto-subject article))
7525     (gnus-summary-position-point)
7526     article))
7527
7528 (defun gnus-summary-last-subject ()
7529   "Go to the last displayed subject line in the group."
7530   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7531     (when article
7532       (gnus-summary-goto-subject article))))
7533
7534 (defun gnus-summary-goto-article (article &optional all-headers force)
7535   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7536 If ALL-HEADERS is non-nil, no header lines are hidden.
7537 If FORCE, go to the article even if it isn't displayed.  If FORCE
7538 is a number, it is the line the article is to be displayed on."
7539   (interactive
7540    (list
7541     (completing-read
7542      "Article number or Message-ID: "
7543      (mapcar (lambda (number) (list (int-to-string number)))
7544              gnus-newsgroup-limit))
7545     current-prefix-arg
7546     t))
7547   (prog1
7548       (if (and (stringp article)
7549                (string-match "@\\|%40" article))
7550           (gnus-summary-refer-article article)
7551         (when (stringp article)
7552           (setq article (string-to-number article)))
7553         (if (gnus-summary-goto-subject article force)
7554             (gnus-summary-display-article article all-headers)
7555           (gnus-message 4 "Couldn't go to article %s" article) nil))
7556     (gnus-summary-position-point)))
7557
7558 (defun gnus-summary-goto-last-article ()
7559   "Go to the previously read article."
7560   (interactive)
7561   (prog1
7562       (when gnus-last-article
7563         (gnus-summary-goto-article gnus-last-article nil t))
7564     (gnus-summary-position-point)))
7565
7566 (defun gnus-summary-pop-article (number)
7567   "Pop one article off the history and go to the previous.
7568 NUMBER articles will be popped off."
7569   (interactive "p")
7570   (let (to)
7571     (setq gnus-newsgroup-history
7572           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7573     (if to
7574         (gnus-summary-goto-article (car to) nil t)
7575       (error "Article history empty")))
7576   (gnus-summary-position-point))
7577
7578 ;; Summary commands and functions for limiting the summary buffer.
7579
7580 (defun gnus-summary-limit-to-articles (n)
7581   "Limit the summary buffer to the next N articles.
7582 If not given a prefix, use the process marked articles instead."
7583   (interactive "P")
7584   (prog1
7585       (let ((articles (gnus-summary-work-articles n)))
7586         (setq gnus-newsgroup-processable nil)
7587         (gnus-summary-limit articles))
7588     (gnus-summary-position-point)))
7589
7590 (defun gnus-summary-pop-limit (&optional total)
7591   "Restore the previous limit.
7592 If given a prefix, remove all limits."
7593   (interactive "P")
7594   (when total
7595     (setq gnus-newsgroup-limits
7596           (list (mapcar (lambda (h) (mail-header-number h))
7597                         gnus-newsgroup-headers))))
7598   (unless gnus-newsgroup-limits
7599     (error "No limit to pop"))
7600   (prog1
7601       (gnus-summary-limit nil 'pop)
7602     (gnus-summary-position-point)))
7603
7604 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7605   "Limit the summary buffer to articles that have subjects that match a regexp.
7606 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7607   (interactive
7608    (list (read-string (if current-prefix-arg
7609                           "Exclude subject (regexp): "
7610                         "Limit to subject (regexp): "))
7611          nil current-prefix-arg))
7612   (unless header
7613     (setq header "subject"))
7614   (when (not (equal "" subject))
7615     (prog1
7616         (let ((articles (gnus-summary-find-matching
7617                          (or header "subject") subject 'all nil nil
7618                          not-matching)))
7619           (unless articles
7620             (error "Found no matches for \"%s\"" subject))
7621           (gnus-summary-limit articles))
7622       (gnus-summary-position-point))))
7623
7624 (defun gnus-summary-limit-to-author (from &optional not-matching)
7625   "Limit the summary buffer to articles that have authors that match a regexp.
7626 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7627   (interactive
7628    (list (read-string (if current-prefix-arg
7629                           "Exclude author (regexp): "
7630                         "Limit to author (regexp): "))
7631          current-prefix-arg))
7632   (gnus-summary-limit-to-subject from "from" not-matching))
7633
7634 (defun gnus-summary-limit-to-age (age &optional younger-p)
7635   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7636 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7637 articles that are younger than AGE days."
7638   (interactive
7639    (let ((younger current-prefix-arg)
7640          (days-got nil)
7641          days)
7642      (while (not days-got)
7643        (setq days (if younger
7644                       (read-string "Limit to articles younger than (in days, older when negative): ")
7645                     (read-string
7646                      "Limit to articles older than (in days, younger when negative): ")))
7647        (when (> (length days) 0)
7648          (setq days (read days)))
7649        (if (numberp days)
7650            (progn
7651              (setq days-got t)
7652              (when (< days 0)
7653                (setq younger (not younger))
7654                (setq days (* days -1))))
7655          (message "Please enter a number.")
7656          (sleep-for 1)))
7657      (list days younger)))
7658   (prog1
7659       (let ((data gnus-newsgroup-data)
7660             (cutoff (days-to-time age))
7661             articles d date is-younger)
7662         (while (setq d (pop data))
7663           (when (and (vectorp (gnus-data-header d))
7664                      (setq date (mail-header-date (gnus-data-header d))))
7665             (setq is-younger (time-less-p
7666                               (time-since (condition-case ()
7667                                               (date-to-time date)
7668                                             (error '(0 0))))
7669                               cutoff))
7670             (when (if younger-p
7671                       is-younger
7672                     (not is-younger))
7673               (push (gnus-data-number d) articles))))
7674         (gnus-summary-limit (nreverse articles)))
7675     (gnus-summary-position-point)))
7676
7677 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7678   "Limit the summary buffer to articles that match an 'extra' header."
7679   (interactive
7680    (let ((header
7681           (intern
7682            (gnus-completing-read-with-default
7683             (symbol-name (car gnus-extra-headers))
7684             (if current-prefix-arg
7685                 "Exclude extra header:"
7686               "Limit extra header:")
7687             (mapcar (lambda (x)
7688                       (cons (symbol-name x) x))
7689                     gnus-extra-headers)
7690             nil
7691             t))))
7692      (list header
7693            (read-string (format "%s header %s (regexp): "
7694                                 (if current-prefix-arg "Exclude" "Limit to")
7695                                 header))
7696            current-prefix-arg)))
7697   (when (not (equal "" regexp))
7698     (prog1
7699         (let ((articles (gnus-summary-find-matching
7700                          (cons 'extra header) regexp 'all nil nil
7701                          not-matching)))
7702           (unless articles
7703             (error "Found no matches for \"%s\"" regexp))
7704           (gnus-summary-limit articles))
7705       (gnus-summary-position-point))))
7706
7707 (defun gnus-summary-limit-to-display-predicate ()
7708   "Limit the summary buffer to the predicated in the `display' group parameter."
7709   (interactive)
7710   (unless gnus-newsgroup-display
7711     (error "There is no `display' group parameter"))
7712   (let (articles)
7713     (dolist (number gnus-newsgroup-articles)
7714       (when (funcall gnus-newsgroup-display)
7715         (push number articles)))
7716     (gnus-summary-limit articles))
7717   (gnus-summary-position-point))
7718
7719 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7720 (make-obsolete
7721  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7722
7723 (defun gnus-summary-limit-to-unread (&optional all)
7724   "Limit the summary buffer to articles that are not marked as read.
7725 If ALL is non-nil, limit strictly to unread articles."
7726   (interactive "P")
7727   (if all
7728       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7729     (gnus-summary-limit-to-marks
7730      ;; Concat all the marks that say that an article is read and have
7731      ;; those removed.
7732      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7733            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7734            gnus-low-score-mark gnus-expirable-mark
7735            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7736            gnus-duplicate-mark gnus-souped-mark)
7737      'reverse)))
7738
7739 (defun gnus-summary-limit-to-replied (&optional unreplied)
7740   "Limit the summary buffer to replied articles.
7741 If UNREPLIED (the prefix), limit to unreplied articles."
7742   (interactive "P")
7743   (if unreplied
7744       (gnus-summary-limit
7745        (gnus-set-difference gnus-newsgroup-articles
7746         gnus-newsgroup-replied))
7747     (gnus-summary-limit gnus-newsgroup-replied))
7748   (gnus-summary-position-point))
7749
7750 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7751 (make-obsolete 'gnus-summary-delete-marked-with
7752                'gnus-summary-limit-exclude-marks)
7753
7754 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7755   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7756 If REVERSE, limit the summary buffer to articles that are marked
7757 with MARKS.  MARKS can either be a string of marks or a list of marks.
7758 Returns how many articles were removed."
7759   (interactive "sMarks: ")
7760   (gnus-summary-limit-to-marks marks t))
7761
7762 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7763   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7764 If REVERSE (the prefix), limit the summary buffer to articles that are
7765 not marked with MARKS.  MARKS can either be a string of marks or a
7766 list of marks.
7767 Returns how many articles were removed."
7768   (interactive "sMarks: \nP")
7769   (prog1
7770       (let ((data gnus-newsgroup-data)
7771             (marks (if (listp marks) marks
7772                      (append marks nil))) ; Transform to list.
7773             articles)
7774         (while data
7775           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7776                   (memq (gnus-data-mark (car data)) marks))
7777             (push (gnus-data-number (car data)) articles))
7778           (setq data (cdr data)))
7779         (gnus-summary-limit articles))
7780     (gnus-summary-position-point)))
7781
7782 (defun gnus-summary-limit-to-score (score)
7783   "Limit to articles with score at or above SCORE."
7784   (interactive "NLimit to articles with score of at least: ")
7785   (let ((data gnus-newsgroup-data)
7786         articles)
7787     (while data
7788       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7789                 score)
7790         (push (gnus-data-number (car data)) articles))
7791       (setq data (cdr data)))
7792     (prog1
7793         (gnus-summary-limit articles)
7794       (gnus-summary-position-point))))
7795
7796 (defun gnus-summary-limit-to-unseen ()
7797   "Limit to unseen articles."
7798   (interactive)
7799   (prog1
7800       (gnus-summary-limit gnus-newsgroup-unseen)
7801     (gnus-summary-position-point)))
7802
7803 (defun gnus-summary-limit-include-thread (id)
7804   "Display all the hidden articles that is in the thread with ID in it.
7805 When called interactively, ID is the Message-ID of the current
7806 article."
7807   (interactive (list (mail-header-id (gnus-summary-article-header))))
7808   (let ((articles (gnus-articles-in-thread
7809                    (gnus-id-to-thread (gnus-root-id id)))))
7810     (prog1
7811         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7812       (gnus-summary-limit-include-matching-articles
7813        "subject"
7814        (regexp-quote (gnus-simplify-subject-re
7815                       (mail-header-subject (gnus-id-to-header id)))))
7816       (gnus-summary-position-point))))
7817
7818 (defun gnus-summary-limit-include-matching-articles (header regexp)
7819   "Display all the hidden articles that have HEADERs that match REGEXP."
7820   (interactive (list (read-string "Match on header: ")
7821                      (read-string "Regexp: ")))
7822   (let ((articles (gnus-find-matching-articles header regexp)))
7823     (prog1
7824         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7825       (gnus-summary-position-point))))
7826
7827 (defun gnus-summary-insert-dormant-articles ()
7828   "Insert all the dormant articles for this group into the current buffer."
7829   (interactive)
7830   (let ((gnus-verbose (max 6 gnus-verbose)))
7831     (if (not gnus-newsgroup-dormant)
7832         (gnus-message 3 "No cached articles for this group")
7833       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7834
7835 (defun gnus-summary-limit-include-dormant ()
7836   "Display all the hidden articles that are marked as dormant.
7837 Note that this command only works on a subset of the articles currently
7838 fetched for this group."
7839   (interactive)
7840   (unless gnus-newsgroup-dormant
7841     (error "There are no dormant articles in this group"))
7842   (prog1
7843       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7844     (gnus-summary-position-point)))
7845
7846 (defun gnus-summary-limit-exclude-dormant ()
7847   "Hide all dormant articles."
7848   (interactive)
7849   (prog1
7850       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7851     (gnus-summary-position-point)))
7852
7853 (defun gnus-summary-limit-exclude-childless-dormant ()
7854   "Hide all dormant articles that have no children."
7855   (interactive)
7856   (let ((data (gnus-data-list t))
7857         articles d children)
7858     ;; Find all articles that are either not dormant or have
7859     ;; children.
7860     (while (setq d (pop data))
7861       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7862                 (and (setq children
7863                            (gnus-article-children (gnus-data-number d)))
7864                      (let (found)
7865                        (while children
7866                          (when (memq (car children) articles)
7867                            (setq children nil
7868                                  found t))
7869                          (pop children))
7870                        found)))
7871         (push (gnus-data-number d) articles)))
7872     ;; Do the limiting.
7873     (prog1
7874         (gnus-summary-limit articles)
7875       (gnus-summary-position-point))))
7876
7877 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7878   "Mark all unread excluded articles as read.
7879 If ALL, mark even excluded ticked and dormants as read."
7880   (interactive "P")
7881   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7882   (let ((articles (gnus-sorted-ndifference
7883                    (sort
7884                     (mapcar (lambda (h) (mail-header-number h))
7885                             gnus-newsgroup-headers)
7886                     '<)
7887                    gnus-newsgroup-limit))
7888         article)
7889     (setq gnus-newsgroup-unreads
7890           (gnus-sorted-intersection gnus-newsgroup-unreads
7891                                     gnus-newsgroup-limit))
7892     (if all
7893         (setq gnus-newsgroup-dormant nil
7894               gnus-newsgroup-marked nil
7895               gnus-newsgroup-reads
7896               (nconc
7897                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7898                gnus-newsgroup-reads))
7899       (while (setq article (pop articles))
7900         (unless (or (memq article gnus-newsgroup-dormant)
7901                     (memq article gnus-newsgroup-marked))
7902           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7903
7904 (defun gnus-summary-limit (articles &optional pop)
7905   (if pop
7906       ;; We pop the previous limit off the stack and use that.
7907       (setq articles (car gnus-newsgroup-limits)
7908             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7909     ;; We use the new limit, so we push the old limit on the stack.
7910     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7911   ;; Set the limit.
7912   (setq gnus-newsgroup-limit articles)
7913   (let ((total (length gnus-newsgroup-data))
7914         (data (gnus-data-find-list (gnus-summary-article-number)))
7915         (gnus-summary-mark-below nil)   ; Inhibit this.
7916         found)
7917     ;; This will do all the work of generating the new summary buffer
7918     ;; according to the new limit.
7919     (gnus-summary-prepare)
7920     ;; Hide any threads, possibly.
7921     (gnus-summary-maybe-hide-threads)
7922     ;; Try to return to the article you were at, or one in the
7923     ;; neighborhood.
7924     (when data
7925       ;; We try to find some article after the current one.
7926       (while data
7927         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7928           (setq data nil
7929                 found t))
7930         (setq data (cdr data))))
7931     (unless found
7932       ;; If there is no data, that means that we were after the last
7933       ;; article.  The same goes when we can't find any articles
7934       ;; after the current one.
7935       (goto-char (point-max))
7936       (gnus-summary-find-prev))
7937     (gnus-set-mode-line 'summary)
7938     ;; We return how many articles were removed from the summary
7939     ;; buffer as a result of the new limit.
7940     (- total (length gnus-newsgroup-data))))
7941
7942 (defsubst gnus-invisible-cut-children (threads)
7943   (let ((num 0))
7944     (while threads
7945       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7946         (incf num))
7947       (pop threads))
7948     (< num 2)))
7949
7950 (defsubst gnus-cut-thread (thread)
7951   "Go forwards in the thread until we find an article that we want to display."
7952   (when (or (eq gnus-fetch-old-headers 'some)
7953             (eq gnus-fetch-old-headers 'invisible)
7954             (numberp gnus-fetch-old-headers)
7955             (eq gnus-build-sparse-threads 'some)
7956             (eq gnus-build-sparse-threads 'more))
7957     ;; Deal with old-fetched headers and sparse threads.
7958     (while (and
7959             thread
7960             (or
7961              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7962              (gnus-summary-article-ancient-p
7963               (mail-header-number (car thread))))
7964             (if (or (<= (length (cdr thread)) 1)
7965                     (eq gnus-fetch-old-headers 'invisible))
7966                 (setq gnus-newsgroup-limit
7967                       (delq (mail-header-number (car thread))
7968                             gnus-newsgroup-limit)
7969                       thread (cadr thread))
7970               (when (gnus-invisible-cut-children (cdr thread))
7971                 (let ((th (cdr thread)))
7972                   (while th
7973                     (if (memq (mail-header-number (caar th))
7974                               gnus-newsgroup-limit)
7975                         (setq thread (car th)
7976                               th nil)
7977                       (setq th (cdr th))))))))))
7978   thread)
7979
7980 (defun gnus-cut-threads (threads)
7981   "Cut off all uninteresting articles from the beginning of THREADS."
7982   (when (or (eq gnus-fetch-old-headers 'some)
7983             (eq gnus-fetch-old-headers 'invisible)
7984             (numberp gnus-fetch-old-headers)
7985             (eq gnus-build-sparse-threads 'some)
7986             (eq gnus-build-sparse-threads 'more))
7987     (let ((th threads))
7988       (while th
7989         (setcar th (gnus-cut-thread (car th)))
7990         (setq th (cdr th)))))
7991   ;; Remove nixed out threads.
7992   (delq nil threads))
7993
7994 (defun gnus-summary-initial-limit (&optional show-if-empty)
7995   "Figure out what the initial limit is supposed to be on group entry.
7996 This entails weeding out unwanted dormants, low-scored articles,
7997 fetch-old-headers verbiage, and so on."
7998   ;; Most groups have nothing to remove.
7999   (if (or gnus-inhibit-limiting
8000           (and (null gnus-newsgroup-dormant)
8001                (eq gnus-newsgroup-display 'gnus-not-ignore)
8002                (not (eq gnus-fetch-old-headers 'some))
8003                (not (numberp gnus-fetch-old-headers))
8004                (not (eq gnus-fetch-old-headers 'invisible))
8005                (null gnus-summary-expunge-below)
8006                (not (eq gnus-build-sparse-threads 'some))
8007                (not (eq gnus-build-sparse-threads 'more))
8008                (null gnus-thread-expunge-below)
8009                (not gnus-use-nocem)))
8010       ()                                ; Do nothing.
8011     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8012     (setq gnus-newsgroup-limit nil)
8013     (mapatoms
8014      (lambda (node)
8015        (unless (car (symbol-value node))
8016          ;; These threads have no parents -- they are roots.
8017          (let ((nodes (cdr (symbol-value node)))
8018                thread)
8019            (while nodes
8020              (if (and gnus-thread-expunge-below
8021                       (< (gnus-thread-total-score (car nodes))
8022                          gnus-thread-expunge-below))
8023                  (gnus-expunge-thread (pop nodes))
8024                (setq thread (pop nodes))
8025                (gnus-summary-limit-children thread))))))
8026      gnus-newsgroup-dependencies)
8027     ;; If this limitation resulted in an empty group, we might
8028     ;; pop the previous limit and use it instead.
8029     (when (and (not gnus-newsgroup-limit)
8030                show-if-empty)
8031       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8032     gnus-newsgroup-limit))
8033
8034 (defun gnus-summary-limit-children (thread)
8035   "Return 1 if this subthread is visible and 0 if it is not."
8036   ;; First we get the number of visible children to this thread.  This
8037   ;; is done by recursing down the thread using this function, so this
8038   ;; will really go down to a leaf article first, before slowly
8039   ;; working its way up towards the root.
8040   (when thread
8041     (let* ((max-lisp-eval-depth 5000)
8042            (children
8043            (if (cdr thread)
8044                (apply '+ (mapcar 'gnus-summary-limit-children
8045                                  (cdr thread)))
8046              0))
8047           (number (mail-header-number (car thread)))
8048           score)
8049       (if (and
8050            (not (memq number gnus-newsgroup-marked))
8051            (or
8052             ;; If this article is dormant and has absolutely no visible
8053             ;; children, then this article isn't visible.
8054             (and (memq number gnus-newsgroup-dormant)
8055                  (zerop children))
8056             ;; If this is "fetch-old-headered" and there is no
8057             ;; visible children, then we don't want this article.
8058             (and (or (eq gnus-fetch-old-headers 'some)
8059                      (numberp gnus-fetch-old-headers))
8060                  (gnus-summary-article-ancient-p number)
8061                  (zerop children))
8062             ;; If this is "fetch-old-headered" and `invisible', then
8063             ;; we don't want this article.
8064             (and (eq gnus-fetch-old-headers 'invisible)
8065                  (gnus-summary-article-ancient-p number))
8066             ;; If this is a sparsely inserted article with no children,
8067             ;; we don't want it.
8068             (and (eq gnus-build-sparse-threads 'some)
8069                  (gnus-summary-article-sparse-p number)
8070                  (zerop children))
8071             ;; If we use expunging, and this article is really
8072             ;; low-scored, then we don't want this article.
8073             (when (and gnus-summary-expunge-below
8074                        (< (setq score
8075                                 (or (cdr (assq number gnus-newsgroup-scored))
8076                                     gnus-summary-default-score))
8077                           gnus-summary-expunge-below))
8078               ;; We increase the expunge-tally here, but that has
8079               ;; nothing to do with the limits, really.
8080               (incf gnus-newsgroup-expunged-tally)
8081               ;; We also mark as read here, if that's wanted.
8082               (when (and gnus-summary-mark-below
8083                          (< score gnus-summary-mark-below))
8084                 (setq gnus-newsgroup-unreads
8085                       (delq number gnus-newsgroup-unreads))
8086                 (if gnus-newsgroup-auto-expire
8087                     (push number gnus-newsgroup-expirable)
8088                   (push (cons number gnus-low-score-mark)
8089                         gnus-newsgroup-reads)))
8090               t)
8091             ;; Do the `display' group parameter.
8092             (and gnus-newsgroup-display
8093                  (not (funcall gnus-newsgroup-display)))
8094             ;; Check NoCeM things.
8095             (when (and gnus-use-nocem
8096                        (gnus-nocem-unwanted-article-p
8097                         (mail-header-id (car thread))))
8098               (setq gnus-newsgroup-unreads
8099                     (delq number gnus-newsgroup-unreads))
8100               t)))
8101           ;; Nope, invisible article.
8102           0
8103         ;; Ok, this article is to be visible, so we add it to the limit
8104         ;; and return 1.
8105         (push number gnus-newsgroup-limit)
8106         1))))
8107
8108 (defun gnus-expunge-thread (thread)
8109   "Mark all articles in THREAD as read."
8110   (let* ((number (mail-header-number (car thread))))
8111     (incf gnus-newsgroup-expunged-tally)
8112     ;; We also mark as read here, if that's wanted.
8113     (setq gnus-newsgroup-unreads
8114           (delq number gnus-newsgroup-unreads))
8115     (if gnus-newsgroup-auto-expire
8116         (push number gnus-newsgroup-expirable)
8117       (push (cons number gnus-low-score-mark)
8118             gnus-newsgroup-reads)))
8119   ;; Go recursively through all subthreads.
8120   (mapcar 'gnus-expunge-thread (cdr thread)))
8121
8122 ;; Summary article oriented commands
8123
8124 (defun gnus-summary-refer-parent-article (n)
8125   "Refer parent article N times.
8126 If N is negative, go to ancestor -N instead.
8127 The difference between N and the number of articles fetched is returned."
8128   (interactive "p")
8129   (let ((skip 1)
8130         error header ref)
8131     (when (not (natnump n))
8132       (setq skip (abs n)
8133             n 1))
8134     (while (and (> n 0)
8135                 (not error))
8136       (setq header (gnus-summary-article-header))
8137       (if (and (eq (mail-header-number header)
8138                    (cdr gnus-article-current))
8139                (equal gnus-newsgroup-name
8140                       (car gnus-article-current)))
8141           ;; If we try to find the parent of the currently
8142           ;; displayed article, then we take a look at the actual
8143           ;; References header, since this is slightly more
8144           ;; reliable than the References field we got from the
8145           ;; server.
8146           (save-excursion
8147             (set-buffer gnus-original-article-buffer)
8148             (nnheader-narrow-to-headers)
8149             (unless (setq ref (message-fetch-field "references"))
8150               (when (setq ref (message-fetch-field "in-reply-to"))
8151                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8152             (widen))
8153         (setq ref
8154               ;; It's not the current article, so we take a bet on
8155               ;; the value we got from the server.
8156               (mail-header-references header)))
8157       (if (and ref
8158                (not (equal ref "")))
8159           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8160             (gnus-message 1 "Couldn't find parent"))
8161         (gnus-message 1 "No references in article %d"
8162                       (gnus-summary-article-number))
8163         (setq error t))
8164       (decf n))
8165     (gnus-summary-position-point)
8166     n))
8167
8168 (defun gnus-summary-refer-references ()
8169   "Fetch all articles mentioned in the References header.
8170 Return the number of articles fetched."
8171   (interactive)
8172   (let ((ref (mail-header-references (gnus-summary-article-header)))
8173         (current (gnus-summary-article-number))
8174         (n 0))
8175     (if (or (not ref)
8176             (equal ref ""))
8177         (error "No References in the current article")
8178       ;; For each Message-ID in the References header...
8179       (while (string-match "<[^>]*>" ref)
8180         (incf n)
8181         ;; ... fetch that article.
8182         (gnus-summary-refer-article
8183          (prog1 (match-string 0 ref)
8184            (setq ref (substring ref (match-end 0))))))
8185       (gnus-summary-goto-subject current)
8186       (gnus-summary-position-point)
8187       n)))
8188
8189 (defun gnus-summary-refer-thread (&optional limit)
8190   "Fetch all articles in the current thread.
8191 If LIMIT (the numerical prefix), fetch that many old headers instead
8192 of what's specified by the `gnus-refer-thread-limit' variable."
8193   (interactive "P")
8194   (let ((id (mail-header-id (gnus-summary-article-header)))
8195         (limit (if limit (prefix-numeric-value limit)
8196                  gnus-refer-thread-limit)))
8197     (unless (eq gnus-fetch-old-headers 'invisible)
8198       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8199       ;; Retrieve the headers and read them in.
8200       (if (eq (if (numberp limit)
8201                   (gnus-retrieve-headers
8202                    (list (min
8203                           (+ (mail-header-number
8204                               (gnus-summary-article-header))
8205                              limit)
8206                           gnus-newsgroup-end))
8207                    gnus-newsgroup-name (* limit 2))
8208                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8209                 ;; headers.
8210                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8211                                        gnus-newsgroup-name limit))
8212               'nov)
8213           (gnus-build-all-threads)
8214         (error "Can't fetch thread from back ends that don't support NOV"))
8215       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8216     (gnus-summary-limit-include-thread id)))
8217
8218 (defun gnus-summary-refer-article (message-id)
8219   "Fetch an article specified by MESSAGE-ID."
8220   (interactive "sMessage-ID: ")
8221   (when (and (stringp message-id)
8222              (not (zerop (length message-id))))
8223     (setq message-id (gnus-replace-in-string message-id " " ""))
8224     ;; Construct the correct Message-ID if necessary.
8225     ;; Suggested by tale@pawl.rpi.edu.
8226     (unless (string-match "^<" message-id)
8227       (setq message-id (concat "<" message-id)))
8228     (unless (string-match ">$" message-id)
8229       (setq message-id (concat message-id ">")))
8230     ;; People often post MIDs from URLs, so unhex it:
8231     (unless (string-match "@" message-id)
8232       (setq message-id (gnus-url-unhex-string message-id)))
8233     (let* ((header (gnus-id-to-header message-id))
8234            (sparse (and header
8235                         (gnus-summary-article-sparse-p
8236                          (mail-header-number header))
8237                         (memq (mail-header-number header)
8238                               gnus-newsgroup-limit)))
8239            number)
8240       (cond
8241        ;; If the article is present in the buffer we just go to it.
8242        ((and header
8243              (or (not (gnus-summary-article-sparse-p
8244                        (mail-header-number header)))
8245                  sparse))
8246         (prog1
8247             (gnus-summary-goto-article
8248              (mail-header-number header) nil t)
8249           (when sparse
8250             (gnus-summary-update-article (mail-header-number header)))))
8251        (t
8252         ;; We fetch the article.
8253         (catch 'found
8254           (dolist (gnus-override-method (gnus-refer-article-methods))
8255             (when (and (gnus-check-server gnus-override-method)
8256                        ;; Fetch the header,
8257                        (setq number (gnus-summary-insert-subject message-id)))
8258               ;; and display the article.
8259               (gnus-summary-select-article nil nil nil number)
8260               (throw 'found t)))
8261           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8262
8263 (defun gnus-refer-article-methods ()
8264   "Return a list of referable methods."
8265   (cond
8266    ;; No method, so we default to current and native.
8267    ((null gnus-refer-article-method)
8268     (list gnus-current-select-method gnus-select-method))
8269    ;; Current.
8270    ((eq 'current gnus-refer-article-method)
8271     (list gnus-current-select-method))
8272    ;; List of select methods.
8273    ((not (and (symbolp (car gnus-refer-article-method))
8274               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8275     (let (out)
8276       (dolist (method gnus-refer-article-method)
8277         (push (if (eq 'current method)
8278                   gnus-current-select-method
8279                 method)
8280               out))
8281       (nreverse out)))
8282    ;; One single select method.
8283    (t
8284     (list gnus-refer-article-method))))
8285
8286 (defun gnus-summary-edit-parameters ()
8287   "Edit the group parameters of the current group."
8288   (interactive)
8289   (gnus-group-edit-group gnus-newsgroup-name 'params))
8290
8291 (defun gnus-summary-customize-parameters ()
8292   "Customize the group parameters of the current group."
8293   (interactive)
8294   (gnus-group-customize gnus-newsgroup-name))
8295
8296 (defun gnus-summary-enter-digest-group (&optional force)
8297   "Enter an nndoc group based on the current article.
8298 If FORCE, force a digest interpretation.  If not, try
8299 to guess what the document format is."
8300   (interactive "P")
8301   (let ((conf gnus-current-window-configuration))
8302     (save-window-excursion
8303       (save-excursion
8304         (let (gnus-article-prepare-hook
8305               gnus-display-mime-function
8306               gnus-break-pages)
8307           (gnus-summary-select-article))))
8308     (setq gnus-current-window-configuration conf)
8309     (let* ((name (format "%s-%d"
8310                          (gnus-group-prefixed-name
8311                           gnus-newsgroup-name (list 'nndoc ""))
8312                          (with-current-buffer gnus-summary-buffer
8313                            gnus-current-article)))
8314            (ogroup gnus-newsgroup-name)
8315            (params (append (gnus-info-params (gnus-get-info ogroup))
8316                            (list (cons 'to-group ogroup))
8317                            (list (cons 'parent-group ogroup))
8318                            (list (cons 'save-article-group ogroup))))
8319            (case-fold-search t)
8320            (buf (current-buffer))
8321            dig to-address)
8322       (save-excursion
8323         (set-buffer gnus-original-article-buffer)
8324         ;; Have the digest group inherit the main mail address of
8325         ;; the parent article.
8326         (when (setq to-address (or (gnus-fetch-field "reply-to")
8327                                    (gnus-fetch-field "from")))
8328           (setq params (append
8329                         (list (cons 'to-address
8330                                     (funcall gnus-decode-encoded-word-function
8331                                              to-address))))))
8332         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8333         (insert-buffer-substring gnus-original-article-buffer)
8334         ;; Remove lines that may lead nndoc to misinterpret the
8335         ;; document type.
8336         (narrow-to-region
8337          (goto-char (point-min))
8338          (or (search-forward "\n\n" nil t) (point)))
8339         (goto-char (point-min))
8340         (delete-matching-lines "^Path:\\|^From ")
8341         (widen))
8342       (unwind-protect
8343           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8344                     (gnus-newsgroup-ephemeral-ignored-charsets
8345                      gnus-newsgroup-ignored-charsets))
8346                 (gnus-group-read-ephemeral-group
8347                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8348                               (nndoc-article-type
8349                                ,(if force 'mbox 'guess)))
8350                  t nil nil nil
8351                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8352                                                         "ADAPT")))))
8353               ;; Make all postings to this group go to the parent group.
8354               (nconc (gnus-info-params (gnus-get-info name))
8355                      params)
8356             ;; Couldn't select this doc group.
8357             (switch-to-buffer buf)
8358             (gnus-set-global-variables)
8359             (gnus-configure-windows 'summary)
8360             (gnus-message 3 "Article couldn't be entered?"))
8361         (kill-buffer dig)))))
8362
8363 (defun gnus-summary-read-document (n)
8364   "Open a new group based on the current article(s).
8365 This will allow you to read digests and other similar
8366 documents as newsgroups.
8367 Obeys the standard process/prefix convention."
8368   (interactive "P")
8369   (let* ((articles (gnus-summary-work-articles n))
8370          (ogroup gnus-newsgroup-name)
8371          (params (append (gnus-info-params (gnus-get-info ogroup))
8372                          (list (cons 'to-group ogroup))))
8373          article group egroup groups vgroup)
8374     (while (setq article (pop articles))
8375       (setq group (format "%s-%d" gnus-newsgroup-name article))
8376       (gnus-summary-remove-process-mark article)
8377       (when (gnus-summary-display-article article)
8378         (save-excursion
8379           (with-temp-buffer
8380             (insert-buffer-substring gnus-original-article-buffer)
8381             ;; Remove some headers that may lead nndoc to make
8382             ;; the wrong guess.
8383             (message-narrow-to-head)
8384             (goto-char (point-min))
8385             (delete-matching-lines "^Path:\\|^From ")
8386             (widen)
8387             (if (setq egroup
8388                       (gnus-group-read-ephemeral-group
8389                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8390                                      (nndoc-article-type guess))
8391                        t nil t))
8392                 (progn
8393                   ;; Make all postings to this group go to the parent group.
8394                   (nconc (gnus-info-params (gnus-get-info egroup))
8395                          params)
8396                   (push egroup groups))
8397               ;; Couldn't select this doc group.
8398               (gnus-error 3 "Article couldn't be entered"))))))
8399     ;; Now we have selected all the documents.
8400     (cond
8401      ((not groups)
8402       (error "None of the articles could be interpreted as documents"))
8403      ((gnus-group-read-ephemeral-group
8404        (setq vgroup (format
8405                      "nnvirtual:%s-%s" gnus-newsgroup-name
8406                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8407        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8408        t
8409        (cons (current-buffer) 'summary)))
8410      (t
8411       (error "Couldn't select virtual nndoc group")))))
8412
8413 (defun gnus-summary-isearch-article (&optional regexp-p)
8414   "Do incremental search forward on the current article.
8415 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8416   (interactive "P")
8417   (let* ((gnus-inhibit-treatment t)
8418          (old (gnus-summary-select-article)))
8419     (gnus-configure-windows 'article)
8420     (gnus-eval-in-buffer-window gnus-article-buffer
8421       (save-restriction
8422         (widen)
8423         (when (eq 'old old)
8424           (gnus-article-show-all-headers))
8425         (goto-char (point-min))
8426         (isearch-forward regexp-p)))))
8427
8428 (defun gnus-summary-search-article-forward (regexp &optional backward)
8429   "Search for an article containing REGEXP forward.
8430 If BACKWARD, search backward instead."
8431   (interactive
8432    (list (read-string
8433           (format "Search article %s (regexp%s): "
8434                   (if current-prefix-arg "backward" "forward")
8435                   (if gnus-last-search-regexp
8436                       (concat ", default " gnus-last-search-regexp)
8437                     "")))
8438          current-prefix-arg))
8439   (if (string-equal regexp "")
8440       (setq regexp (or gnus-last-search-regexp ""))
8441     (setq gnus-last-search-regexp regexp)
8442     (setq gnus-article-before-search gnus-current-article))
8443   ;; Intentionally set gnus-last-article.
8444   (setq gnus-last-article gnus-article-before-search)
8445   (let ((gnus-last-article gnus-last-article))
8446     (if (gnus-summary-search-article regexp backward)
8447         (gnus-summary-show-thread)
8448       (error "Search failed: \"%s\"" regexp))))
8449
8450 (defun gnus-summary-search-article-backward (regexp)
8451   "Search for an article containing REGEXP backward."
8452   (interactive
8453    (list (read-string
8454           (format "Search article backward (regexp%s): "
8455                   (if gnus-last-search-regexp
8456                       (concat ", default " gnus-last-search-regexp)
8457                     "")))))
8458   (gnus-summary-search-article-forward regexp 'backward))
8459
8460 (eval-when-compile
8461   (defmacro gnus-summary-search-article-position-point (regexp backward)
8462     "Dehighlight the last matched text and goto the beginning position."
8463     (` (if (and gnus-summary-search-article-matched-data
8464                 (let ((text (caddr gnus-summary-search-article-matched-data))
8465                       (inhibit-read-only t)
8466                       buffer-read-only)
8467                   (delete-region
8468                    (goto-char (car gnus-summary-search-article-matched-data))
8469                    (cadr gnus-summary-search-article-matched-data))
8470                   (insert text)
8471                   (string-match (, regexp) text)))
8472            (if (, backward) (beginning-of-line) (end-of-line))
8473          (goto-char (if (, backward) (point-max) (point-min))))))
8474
8475   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8476     "Place point where X-Face image is displayed."
8477     (if (featurep 'xemacs)
8478         (` (let ((end (if (search-forward "\n\n" nil t)
8479                           (goto-char (1- (point)))
8480                         (point-min)))
8481                  extent)
8482              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8483              (unless (and (re-search-forward "^From:" end t)
8484                           (setq extent (extent-at (point)))
8485                           (extent-begin-glyph extent))
8486                (goto-char (, opoint)))))
8487       (` (let ((end (if (search-forward "\n\n" nil t)
8488                         (goto-char (1- (point)))
8489                       (point-min)))
8490                (start (or (search-backward "\n\n" nil t) (point-min))))
8491            (goto-char
8492             (or (text-property-any start end 'x-face-image t);; x-face-e21
8493                 (text-property-any start end 'x-face-mule-bitmap-image t)
8494                 (, opoint)))))))
8495
8496   (defmacro gnus-summary-search-article-highlight-matched-text
8497     (backward treated x-face)
8498     "Highlight matched text in the function `gnus-summary-search-article'."
8499     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8500              (end (set-marker (make-marker) (match-end 0)))
8501              (inhibit-read-only t)
8502              buffer-read-only)
8503          (unless treated
8504            (let ((,@
8505                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8506                     (mapcar
8507                      (lambda (item) (setq items (delq item items)))
8508                      '(gnus-treat-buttonize
8509                        gnus-treat-fill-article
8510                        gnus-treat-fill-long-lines
8511                        gnus-treat-emphasize
8512                        gnus-treat-highlight-headers
8513                        gnus-treat-highlight-citation
8514                        gnus-treat-highlight-signature
8515                        gnus-treat-overstrike
8516                        gnus-treat-display-x-face
8517                        gnus-treat-buttonize-head
8518                        gnus-treat-decode-article-as-default-mime-charset))
8519                     (static-if (featurep 'xemacs)
8520                         items
8521                       (cons '(x-face-mule-delete-x-face-field
8522                               (quote never))
8523                             items))))
8524                  (gnus-treat-display-x-face
8525                   (when (, x-face) gnus-treat-display-x-face)))
8526              (gnus-article-prepare-mime-display)))
8527          (goto-char (if (, backward) start end))
8528          (when (, x-face)
8529            (gnus-summary-search-article-highlight-goto-x-face (point)))
8530          (setq gnus-summary-search-article-matched-data
8531                (list start end (buffer-substring start end)))
8532          (unless (eq start end);; matched text has been deleted. :-<
8533            (put-text-property start end 'face
8534                               (or (find-face 'isearch)
8535                                   'secondary-selection))))))
8536   )
8537
8538 (defun gnus-summary-search-article (regexp &optional backward)
8539   "Search for an article containing REGEXP.
8540 Optional argument BACKWARD means do search for backward.
8541 `gnus-select-article-hook' is not called during the search."
8542   ;; We have to require this here to make sure that the following
8543   ;; dynamic binding isn't shadowed by autoloading.
8544   (require 'gnus-async)
8545   (require 'gnus-art)
8546   (let ((gnus-select-article-hook nil)  ;Disable hook.
8547         (gnus-article-prepare-hook nil)
8548         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8549         (gnus-use-article-prefetch nil)
8550         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8551         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8552         (gnus-visual nil)
8553         (gnus-keep-backlog nil)
8554         (gnus-break-pages nil)
8555         (gnus-summary-display-arrow nil)
8556         (gnus-updated-mode-lines nil)
8557         (gnus-auto-center-summary nil)
8558         (sum (current-buffer))
8559         (found nil)
8560         point treated)
8561     (gnus-save-hidden-threads
8562       (static-if (featurep 'xemacs)
8563           (let ((gnus-inhibit-treatment t))
8564             (setq treated (eq 'old (gnus-summary-select-article)))
8565             (when (and treated
8566                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8567                                  (window-live-p (get-buffer-window
8568                                                  gnus-article-buffer t)))))
8569               (gnus-summary-select-article nil t)
8570               (setq treated nil)))
8571         (let ((gnus-inhibit-treatment t)
8572               (x-face-mule-delete-x-face-field 'never))
8573           (setq treated (eq 'old (gnus-summary-select-article)))
8574           (when (and treated
8575                      (not
8576                       (and (gnus-buffer-live-p gnus-article-buffer)
8577                            (window-live-p (get-buffer-window
8578                                            gnus-article-buffer t))
8579                            (or (not (string-match "^\\^X-Face:" regexp))
8580                                (with-current-buffer gnus-article-buffer
8581                                  gnus-summary-search-article-matched-data)))))
8582             (gnus-summary-select-article nil t)
8583             (setq treated nil))))
8584       (set-buffer gnus-article-buffer)
8585       (widen)
8586       (if treated
8587           (progn
8588             (gnus-article-show-all-headers)
8589             (gnus-summary-search-article-position-point regexp backward))
8590         (goto-char (if backward (point-max) (point-min))))
8591       (while (not found)
8592         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8593         (if (if backward
8594                 (re-search-backward regexp nil t)
8595               (re-search-forward regexp nil t))
8596             ;; We found the regexp.
8597             (progn
8598               (gnus-summary-search-article-highlight-matched-text
8599                backward treated (string-match "^\\^X-Face:" regexp))
8600               (setq found 'found)
8601               (forward-line
8602                (/ (- 2 (window-height
8603                         (get-buffer-window gnus-article-buffer t)))
8604                   2))
8605               (set-window-start
8606                (get-buffer-window (current-buffer))
8607                (point))
8608               (set-buffer sum)
8609               (setq point (point)))
8610           ;; We didn't find it, so we go to the next article.
8611           (set-buffer sum)
8612           (setq found 'not)
8613           (while (eq found 'not)
8614             (if (not (if backward (gnus-summary-find-prev)
8615                        (gnus-summary-find-next)))
8616                 ;; No more articles.
8617                 (setq found t)
8618               ;; Select the next article and adjust point.
8619               (unless (gnus-summary-article-sparse-p
8620                        (gnus-summary-article-number))
8621                 (setq found nil)
8622                 (let ((gnus-inhibit-treatment t))
8623                   (gnus-summary-select-article))
8624                 (setq treated nil)
8625                 (set-buffer gnus-article-buffer)
8626                 (widen)
8627                 (goto-char (if backward (point-max) (point-min))))))))
8628       (gnus-message 7 ""))
8629     ;; Return whether we found the regexp.
8630     (when (eq found 'found)
8631       (goto-char point)
8632       (gnus-summary-show-thread)
8633       (gnus-summary-goto-subject gnus-current-article)
8634       (gnus-summary-position-point)
8635       t)))
8636
8637 (defun gnus-find-matching-articles (header regexp)
8638   "Return a list of all articles that match REGEXP on HEADER.
8639 This search includes all articles in the current group that Gnus has
8640 fetched headers for, whether they are displayed or not."
8641   (let ((articles nil)
8642         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8643         (case-fold-search t))
8644     (dolist (header gnus-newsgroup-headers)
8645       (when (string-match regexp (funcall func header))
8646         (push (mail-header-number header) articles)))
8647     (nreverse articles)))
8648
8649 (defun gnus-summary-find-matching (header regexp &optional backward unread
8650                                           not-case-fold not-matching)
8651   "Return a list of all articles that match REGEXP on HEADER.
8652 The search stars on the current article and goes forwards unless
8653 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8654 If UNREAD is non-nil, only unread articles will
8655 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8656 in the comparisons. If NOT-MATCHING, return a list of all articles that
8657 not match REGEXP on HEADER."
8658   (let ((case-fold-search (not not-case-fold))
8659         articles d func)
8660     (if (consp header)
8661         (if (eq (car header) 'extra)
8662             (setq func
8663                   `(lambda (h)
8664                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8665                          "")))
8666           (error "%s is an invalid header" header))
8667       (unless (fboundp (intern (concat "mail-header-" header)))
8668         (error "%s is not a valid header" header))
8669       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8670     (dolist (d (if (eq backward 'all)
8671                    gnus-newsgroup-data
8672                  (gnus-data-find-list
8673                   (gnus-summary-article-number)
8674                   (gnus-data-list backward))))
8675       (when (and (or (not unread)       ; We want all articles...
8676                      (gnus-data-unread-p d)) ; Or just unreads.
8677                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8678                  (if not-matching
8679                      (not (string-match
8680                            regexp
8681                            (funcall func (gnus-data-header d))))
8682                    (string-match regexp
8683                                  (funcall func (gnus-data-header d)))))
8684         (push (gnus-data-number d) articles))) ; Success!
8685     (nreverse articles)))
8686
8687 (defun gnus-summary-execute-command (header regexp command &optional backward)
8688   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8689 If HEADER is an empty string (or nil), the match is done on the entire
8690 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8691   (interactive
8692    (list (let ((completion-ignore-case t))
8693            (completing-read
8694             "Header name: "
8695             (mapcar (lambda (header) (list (format "%s" header)))
8696                     (append
8697                      '("Number" "Subject" "From" "Lines" "Date"
8698                        "Message-ID" "Xref" "References" "Body")
8699                      gnus-extra-headers))
8700             nil 'require-match))
8701          (read-string "Regexp: ")
8702          (read-key-sequence "Command: ")
8703          current-prefix-arg))
8704   (when (equal header "Body")
8705     (setq header ""))
8706   ;; Hidden thread subtrees must be searched as well.
8707   (gnus-summary-show-all-threads)
8708   ;; We don't want to change current point nor window configuration.
8709   (save-excursion
8710     (save-window-excursion
8711       (let (gnus-visual
8712             gnus-treat-strip-trailing-blank-lines
8713             gnus-treat-strip-leading-blank-lines
8714             gnus-treat-strip-multiple-blank-lines
8715             gnus-treat-hide-boring-headers
8716             gnus-treat-fold-newsgroups
8717             gnus-article-prepare-hook)
8718         (gnus-message 6 "Executing %s..." (key-description command))
8719         ;; We'd like to execute COMMAND interactively so as to give arguments.
8720         (gnus-execute header regexp
8721                       `(call-interactively ',(key-binding command))
8722                       backward)
8723         (gnus-message 6 "Executing %s...done" (key-description command))))))
8724
8725 (defun gnus-summary-beginning-of-article ()
8726   "Scroll the article back to the beginning."
8727   (interactive)
8728   (gnus-summary-select-article)
8729   (gnus-configure-windows 'article)
8730   (gnus-eval-in-buffer-window gnus-article-buffer
8731     (widen)
8732     (goto-char (point-min))
8733     (when gnus-break-pages
8734       (gnus-narrow-to-page))))
8735
8736 (defun gnus-summary-end-of-article ()
8737   "Scroll to the end of the article."
8738   (interactive)
8739   (gnus-summary-select-article)
8740   (gnus-configure-windows 'article)
8741   (gnus-eval-in-buffer-window gnus-article-buffer
8742     (widen)
8743     (goto-char (point-max))
8744     (recenter -3)
8745     (when gnus-break-pages
8746       (when (re-search-backward page-delimiter nil t)
8747         (narrow-to-region (match-end 0) (point-max)))
8748       (gnus-narrow-to-page))))
8749
8750 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8751   "Truncate to LEN and quote all \"(\"'s in STRING."
8752   (gnus-replace-in-string (if (and len (> (length string) len))
8753                               (substring string 0 len)
8754                             string)
8755                           "[()]" "\\\\\\&"))
8756
8757 (defun gnus-summary-print-article (&optional filename n)
8758   "Generate and print a PostScript image of the process-marked (mail) articles.
8759
8760 If used interactively, print the current article if none are
8761 process-marked.  With prefix arg, prompt the user for the name of the
8762 file to save in.
8763
8764 When used from Lisp, accept two optional args FILENAME and N.  N means
8765 to print the next N articles.  If N is negative, print the N previous
8766 articles.  If N is nil and articles have been marked with the process
8767 mark, print these instead.
8768
8769 If the optional first argument FILENAME is nil, send the image to the
8770 printer.  If FILENAME is a string, save the PostScript image in a file with
8771 that name.  If FILENAME is a number, prompt the user for the name of the file
8772 to save in."
8773   (interactive (list (ps-print-preprint current-prefix-arg)))
8774   (dolist (article (gnus-summary-work-articles n))
8775     (gnus-summary-select-article nil nil 'pseudo article)
8776     (gnus-eval-in-buffer-window gnus-article-buffer
8777       (gnus-print-buffer))
8778     (gnus-summary-remove-process-mark article))
8779   (ps-despool filename))
8780
8781 (defun gnus-print-buffer ()
8782   (let ((buffer (generate-new-buffer " *print*")))
8783     (unwind-protect
8784         (progn
8785           (copy-to-buffer buffer (point-min) (point-max))
8786           (set-buffer buffer)
8787           (gnus-remove-text-with-property 'gnus-decoration)
8788           (when (gnus-visual-p 'article-highlight 'highlight)
8789             ;; Copy-to-buffer doesn't copy overlay.  So redo
8790             ;; highlight.
8791             (let ((gnus-article-buffer buffer))
8792               (gnus-article-highlight-citation t)
8793               (gnus-article-highlight-signature)
8794               (gnus-article-emphasize)
8795               (gnus-article-delete-invisible-text)))
8796           (let ((ps-left-header
8797                  (list
8798                   (concat "("
8799                           (gnus-summary-print-truncate-and-quote
8800                            (mail-header-subject gnus-current-headers)
8801                            66) ")")
8802                   (concat "("
8803                           (gnus-summary-print-truncate-and-quote
8804                            (mail-header-from gnus-current-headers)
8805                            45) ")")))
8806                 (ps-right-header
8807                  (list
8808                   "/pagenumberstring load"
8809                   (concat "("
8810                           (mail-header-date gnus-current-headers) ")"))))
8811             (gnus-run-hooks 'gnus-ps-print-hook)
8812             (save-excursion
8813               (if window-system
8814                   (ps-spool-buffer-with-faces)
8815                 (ps-spool-buffer)))))
8816       (kill-buffer buffer))))
8817
8818 (defun gnus-summary-show-article (&optional arg)
8819   "Force redisplaying of the current article.
8820 If ARG (the prefix) is a number, show the article with the charset
8821 defined in `gnus-summary-show-article-charset-alist', or the charset
8822 input.
8823 If ARG (the prefix) is non-nil and not a number, show the raw article
8824 without any article massaging functions being run.  Normally, the key
8825 strokes are `C-u g'."
8826   (interactive "P")
8827   (cond
8828    ((numberp arg)
8829     (gnus-summary-show-article t)
8830     (let* ((gnus-newsgroup-charset
8831             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8832                 (mm-read-coding-system
8833                  "View as charset: " ;; actually it is coding system.
8834                  (save-excursion
8835                    (set-buffer gnus-article-buffer)
8836                    (mm-detect-coding-region (point) (point-max))))))
8837            (default-mime-charset gnus-newsgroup-charset)
8838            (gnus-newsgroup-ignored-charsets 'gnus-all))
8839       (gnus-summary-select-article nil 'force)
8840       (let ((deps gnus-newsgroup-dependencies)
8841             head header lines)
8842         (save-excursion
8843           (set-buffer gnus-original-article-buffer)
8844           (save-restriction
8845             (message-narrow-to-head)
8846             (setq head (buffer-string))
8847             (goto-char (point-min))
8848             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8849               (goto-char (point-max))
8850               (widen)
8851               (setq lines (1- (count-lines (point) (point-max))))))
8852           (with-temp-buffer
8853             (insert (format "211 %d Article retrieved.\n"
8854                             (cdr gnus-article-current)))
8855             (insert head)
8856             (if lines (insert (format "Lines: %d\n" lines)))
8857             (insert ".\n")
8858             (let ((nntp-server-buffer (current-buffer)))
8859               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8860         (gnus-data-set-header
8861          (gnus-data-find (cdr gnus-article-current))
8862          header)
8863         (gnus-summary-update-article-line
8864          (cdr gnus-article-current) header)
8865         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8866           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8867    ((not arg)
8868     ;; Select the article the normal way.
8869     (gnus-summary-select-article nil 'force))
8870    (t
8871     ;; We have to require this here to make sure that the following
8872     ;; dynamic binding isn't shadowed by autoloading.
8873     (require 'gnus-async)
8874     (require 'gnus-art)
8875     ;; Bind the article treatment functions to nil.
8876     (let ((gnus-have-all-headers t)
8877           gnus-article-prepare-hook
8878           gnus-article-decode-hook
8879           gnus-break-pages
8880           gnus-show-mime
8881           (gnus-inhibit-treatment t))
8882       (gnus-summary-select-article nil 'force))))
8883   (gnus-summary-goto-subject gnus-current-article)
8884   (gnus-summary-position-point))
8885
8886 (defun gnus-summary-show-raw-article ()
8887   "Show the raw article without any article massaging functions being run."
8888   (interactive)
8889   (gnus-summary-show-article t))
8890
8891 (defun gnus-summary-verbose-headers (&optional arg)
8892   "Toggle permanent full header display.
8893 If ARG is a positive number, turn header display on.
8894 If ARG is a negative number, turn header display off."
8895   (interactive "P")
8896   (setq gnus-show-all-headers
8897         (cond ((or (not (numberp arg))
8898                    (zerop arg))
8899                (not gnus-show-all-headers))
8900               ((natnump arg)
8901                t)))
8902   (gnus-summary-show-article))
8903
8904 (defun gnus-summary-toggle-header (&optional arg)
8905   "Show the headers if they are hidden, or hide them if they are shown.
8906 If ARG is a positive number, show the entire header.
8907 If ARG is a negative number, hide the unwanted header lines."
8908   (interactive "P")
8909   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8910                      (get-buffer-window gnus-article-buffer t))))
8911     (with-current-buffer gnus-article-buffer
8912       (widen)
8913       (article-narrow-to-head)
8914       (let* ((buffer-read-only nil)
8915              (inhibit-point-motion-hooks t)
8916              (hidden (if (numberp arg)
8917                          (>= arg 0)
8918                        (gnus-article-hidden-text-p 'headers)))
8919              s e)
8920         (delete-region (point-min) (point-max))
8921         (with-current-buffer gnus-original-article-buffer
8922           (goto-char (setq s (point-min)))
8923           (setq e (if (search-forward "\n\n" nil t)
8924                       (1- (point))
8925                     (point-max))))
8926         (insert-buffer-substring gnus-original-article-buffer s e)
8927         ;; In T-gnus, gnus-article-decode-hook doesn't contain
8928         ;; article-decode-encoded-words by default.
8929         (article-decode-encoded-words)
8930         (run-hooks 'gnus-article-decode-hook)
8931         (if hidden
8932             (let ((gnus-treat-hide-headers nil)
8933                   (gnus-treat-hide-boring-headers nil))
8934               (gnus-delete-wash-type 'headers)
8935               (gnus-treat-article 'head))
8936           (gnus-treat-article 'head))
8937         (widen)
8938         (if window
8939             (set-window-start window (goto-char (point-min))))
8940         (if gnus-break-pages
8941             (gnus-narrow-to-page)
8942           (when (gnus-visual-p 'page-marker)
8943             (let ((buffer-read-only nil))
8944               (gnus-remove-text-with-property 'gnus-prev)
8945               (gnus-remove-text-with-property 'gnus-next))))
8946         (gnus-set-mode-line 'article)))))
8947
8948 (defun gnus-summary-show-all-headers ()
8949   "Make all header lines visible."
8950   (interactive)
8951   (gnus-summary-toggle-header 1))
8952
8953 (defun gnus-summary-toggle-mime (&optional arg)
8954   "Toggle MIME processing.
8955 If ARG is a positive number, turn MIME processing on."
8956   (interactive "P")
8957   (setq gnus-show-mime
8958         (if (null arg)
8959             (not gnus-show-mime)
8960           (> (prefix-numeric-value arg) 0)))
8961   (gnus-summary-select-article t 'force))
8962
8963 (defun gnus-summary-caesar-message (&optional arg)
8964   "Caesar rotate the current article by 13.
8965 The numerical prefix specifies how many places to rotate each letter
8966 forward."
8967   (interactive "P")
8968   (gnus-summary-select-article)
8969   (let ((mail-header-separator ""))
8970     (gnus-eval-in-buffer-window gnus-article-buffer
8971       (save-restriction
8972         (widen)
8973         (let ((start (window-start))
8974               buffer-read-only)
8975           (message-caesar-buffer-body arg)
8976           (set-window-start (get-buffer-window (current-buffer)) start))))))
8977
8978 (autoload 'unmorse-region "morse"
8979   "Convert morse coded text in region to ordinary ASCII text."
8980   t)
8981
8982 (defun gnus-summary-morse-message (&optional arg)
8983   "Morse decode the current article."
8984   (interactive "P")
8985   (gnus-summary-select-article)
8986   (let ((mail-header-separator ""))
8987     (gnus-eval-in-buffer-window gnus-article-buffer
8988       (save-excursion
8989         (save-restriction
8990           (widen)
8991           (let ((pos (window-start))
8992                 buffer-read-only)
8993             (goto-char (point-min))
8994             (when (message-goto-body)
8995               (gnus-narrow-to-body))
8996             (goto-char (point-min))
8997             (while (re-search-forward "·" (point-max) t)
8998               (replace-match "."))
8999             (unmorse-region (point-min) (point-max))
9000             (widen)
9001             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9002
9003 (defun gnus-summary-stop-page-breaking ()
9004   "Stop page breaking in the current article."
9005   (interactive)
9006   (gnus-summary-select-article)
9007   (gnus-eval-in-buffer-window gnus-article-buffer
9008     (widen)
9009     (when (gnus-visual-p 'page-marker)
9010       (let ((buffer-read-only nil))
9011         (gnus-remove-text-with-property 'gnus-prev)
9012         (gnus-remove-text-with-property 'gnus-next))
9013       (setq gnus-page-broken nil))))
9014
9015 (defun gnus-summary-move-article (&optional n to-newsgroup
9016                                             select-method action)
9017   "Move the current article to a different newsgroup.
9018 If N is a positive number, move the N next articles.
9019 If N is a negative number, move the N previous articles.
9020 If N is nil and any articles have been marked with the process mark,
9021 move those articles instead.
9022 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9023 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9024 re-spool using this method.
9025
9026 When called interactively with TO-NEWSGROUP being nil, the value of
9027 the variable `gnus-move-split-methods' is used for finding a default
9028 for the target newsgroup.
9029
9030 For this function to work, both the current newsgroup and the
9031 newsgroup that you want to move to have to support the `request-move'
9032 and `request-accept' functions.
9033
9034 ACTION can be either `move' (the default), `crosspost' or `copy'."
9035   (interactive "P")
9036   (unless action
9037     (setq action 'move))
9038   ;; Check whether the source group supports the required functions.
9039   (cond ((and (eq action 'move)
9040               (not (gnus-check-backend-function
9041                     'request-move-article gnus-newsgroup-name)))
9042          (error "The current group does not support article moving"))
9043         ((and (eq action 'crosspost)
9044               (not (gnus-check-backend-function
9045                     'request-replace-article gnus-newsgroup-name)))
9046          (error "The current group does not support article editing")))
9047   (let ((articles (gnus-summary-work-articles n))
9048         (prefix (if (gnus-check-backend-function
9049                      'request-move-article gnus-newsgroup-name)
9050                     (funcall gnus-move-group-prefix-function
9051                              gnus-newsgroup-name)
9052                   ""))
9053         (names '((move "Move" "Moving")
9054                  (copy "Copy" "Copying")
9055                  (crosspost "Crosspost" "Crossposting")))
9056         (copy-buf (save-excursion
9057                     (nnheader-set-temp-buffer " *copy article*")))
9058         art-group to-method new-xref article to-groups)
9059     (unless (assq action names)
9060       (error "Unknown action %s" action))
9061     ;; Read the newsgroup name.
9062     (when (and (not to-newsgroup)
9063                (not select-method))
9064       (if (and gnus-move-split-methods
9065                (not
9066                 (and (memq gnus-current-article articles)
9067                      (gnus-buffer-live-p gnus-original-article-buffer))))
9068           ;; When `gnus-move-split-methods' is non-nil, we have to
9069           ;; select an article to give `gnus-read-move-group-name' an
9070           ;; opportunity to suggest an appropriate default.  However,
9071           ;; we needn't render or mark the article.
9072           (let ((gnus-display-mime-function nil)
9073                 (gnus-article-prepare-hook nil)
9074                 (gnus-mark-article-hook nil))
9075             (gnus-summary-select-article nil nil nil (car articles))))
9076       (setq to-newsgroup
9077             (gnus-read-move-group-name
9078              (cadr (assq action names))
9079              (symbol-value (intern (format "gnus-current-%s-group" action)))
9080              articles prefix))
9081       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9082     (setq to-method (or select-method
9083                         (gnus-server-to-method
9084                          (gnus-group-method to-newsgroup))))
9085     ;; Check the method we are to move this article to...
9086     (unless (gnus-check-backend-function
9087              'request-accept-article (car to-method))
9088       (error "%s does not support article copying" (car to-method)))
9089     (unless (gnus-check-server to-method)
9090       (error "Can't open server %s" (car to-method)))
9091     (gnus-message 6 "%s to %s: %s..."
9092                   (caddr (assq action names))
9093                   (or (car select-method) to-newsgroup) articles)
9094     (while articles
9095       (setq article (pop articles))
9096       (setq
9097        art-group
9098        (cond
9099         ;; Move the article.
9100         ((eq action 'move)
9101          ;; Remove this article from future suppression.
9102          (gnus-dup-unsuppress-article article)
9103          (gnus-request-move-article
9104           article                       ; Article to move
9105           gnus-newsgroup-name           ; From newsgroup
9106           (nth 1 (gnus-find-method-for-group
9107                   gnus-newsgroup-name)) ; Server
9108           (list 'gnus-request-accept-article
9109                 to-newsgroup (list 'quote select-method)
9110                 (not articles) t)       ; Accept form
9111           (not articles)))              ; Only save nov last time
9112         ;; Copy the article.
9113         ((eq action 'copy)
9114          (save-excursion
9115            (set-buffer copy-buf)
9116            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9117              (gnus-request-accept-article
9118               to-newsgroup select-method (not articles) t))))
9119         ;; Crosspost the article.
9120         ((eq action 'crosspost)
9121          (let ((xref (message-tokenize-header
9122                       (mail-header-xref (gnus-summary-article-header article))
9123                       " ")))
9124            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9125                                   ":" (number-to-string article)))
9126            (unless xref
9127              (setq xref (list (system-name))))
9128            (setq new-xref
9129                  (concat
9130                   (mapconcat 'identity
9131                              (delete "Xref:" (delete new-xref xref))
9132                              " ")
9133                   " " new-xref))
9134            (save-excursion
9135              (set-buffer copy-buf)
9136              ;; First put the article in the destination group.
9137              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9138              (when (consp (setq art-group
9139                                 (gnus-request-accept-article
9140                                  to-newsgroup select-method (not articles))))
9141                (setq new-xref (concat new-xref " " (car art-group)
9142                                       ":"
9143                                       (number-to-string (cdr art-group))))
9144                ;; Now we have the new Xrefs header, so we insert
9145                ;; it and replace the new article.
9146                (nnheader-replace-header "Xref" new-xref)
9147                (gnus-request-replace-article
9148                 (cdr art-group) to-newsgroup (current-buffer))
9149                art-group))))))
9150       (cond
9151        ((not art-group)
9152         (gnus-message 1 "Couldn't %s article %s: %s"
9153                       (cadr (assq action names)) article
9154                       (nnheader-get-report (car to-method))))
9155        ((eq art-group 'junk)
9156         (when (eq action 'move)
9157           (gnus-summary-mark-article article gnus-canceled-mark)
9158           (gnus-message 4 "Deleted article %s" article)
9159           ;; run the delete hook
9160           (run-hook-with-args 'gnus-summary-article-delete-hook
9161                               action
9162                               (gnus-data-header
9163                                (assoc article (gnus-data-list nil)))
9164                               gnus-newsgroup-name nil
9165                               select-method)))
9166        (t
9167         (let* ((pto-group (gnus-group-prefixed-name
9168                            (car art-group) to-method))
9169                (info (gnus-get-info pto-group))
9170                (to-group (gnus-info-group info))
9171                to-marks)
9172           ;; Update the group that has been moved to.
9173           (when (and info
9174                      (memq action '(move copy)))
9175             (unless (member to-group to-groups)
9176               (push to-group to-groups))
9177
9178             (unless (memq article gnus-newsgroup-unreads)
9179               (push 'read to-marks)
9180               (gnus-info-set-read
9181                info (gnus-add-to-range (gnus-info-read info)
9182                                        (list (cdr art-group)))))
9183
9184             ;; See whether the article is to be put in the cache.
9185             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9186                              gnus-article-mark-lists
9187                            (delete '(expirable . expire)
9188                                    (copy-sequence gnus-article-mark-lists))))
9189                   (to-article (cdr art-group)))
9190
9191               ;; Enter the article into the cache in the new group,
9192               ;; if that is required.
9193               (when gnus-use-cache
9194                 (gnus-cache-possibly-enter-article
9195                  to-group to-article
9196                  (let ((header (copy-sequence
9197                                 (gnus-summary-article-header article))))
9198                    (mail-header-set-number header to-article)
9199                    header)
9200                  (memq article gnus-newsgroup-marked)
9201                  (memq article gnus-newsgroup-dormant)
9202                  (memq article gnus-newsgroup-unreads)))
9203
9204               (when gnus-preserve-marks
9205                 ;; Copy any marks over to the new group.
9206                 (when (and (equal to-group gnus-newsgroup-name)
9207                            (not (memq article gnus-newsgroup-unreads)))
9208                   ;; Mark this article as read in this group.
9209                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9210                   (setcdr (gnus-active to-group) to-article)
9211                   (setcdr gnus-newsgroup-active to-article))
9212
9213                 (while marks
9214                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9215                     (when (memq article (symbol-value
9216                                          (intern (format "gnus-newsgroup-%s"
9217                                                          (caar marks)))))
9218                       (push (cdar marks) to-marks)
9219                       ;; If the other group is the same as this group,
9220                       ;; then we have to add the mark to the list.
9221                       (when (equal to-group gnus-newsgroup-name)
9222                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9223                              (cons to-article
9224                                    (symbol-value
9225                                     (intern (format "gnus-newsgroup-%s"
9226                                                     (caar marks)))))))
9227                       ;; Copy the marks to other group.
9228                       (gnus-add-marked-articles
9229                        to-group (cdar marks) (list to-article) info)))
9230                   (setq marks (cdr marks)))
9231
9232                 (gnus-request-set-mark
9233                  to-group (list (list (list to-article) 'add to-marks))))
9234
9235               (gnus-dribble-enter
9236                (concat "(gnus-group-set-info '"
9237                        (gnus-prin1-to-string (gnus-get-info to-group))
9238                        ")"))))
9239
9240           ;; Update the Xref header in this article to point to
9241           ;; the new crossposted article we have just created.
9242           (when (eq action 'crosspost)
9243             (save-excursion
9244               (set-buffer copy-buf)
9245               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9246               (nnheader-replace-header "Xref" new-xref)
9247               (gnus-request-replace-article
9248                article gnus-newsgroup-name (current-buffer))))
9249
9250           ;; run the move/copy/crosspost/respool hook
9251           (run-hook-with-args 'gnus-summary-article-move-hook
9252                               action
9253                               (gnus-data-header
9254                                (assoc article (gnus-data-list nil)))
9255                               gnus-newsgroup-name
9256                               to-newsgroup
9257                               select-method))
9258
9259         ;;;!!!Why is this necessary?
9260         (set-buffer gnus-summary-buffer)
9261         
9262         (gnus-summary-goto-subject article)
9263         (when (eq action 'move)
9264           (gnus-summary-mark-article article gnus-canceled-mark))))
9265       (gnus-summary-remove-process-mark article))
9266     ;; Re-activate all groups that have been moved to.
9267     (save-excursion
9268       (set-buffer gnus-group-buffer)
9269       (let ((gnus-group-marked to-groups))
9270         (gnus-group-get-new-news-this-group nil t)))
9271
9272     (gnus-kill-buffer copy-buf)
9273     (gnus-summary-position-point)
9274     (gnus-set-mode-line 'summary)))
9275
9276 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9277   "Move the current article to a different newsgroup.
9278 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9279 When called interactively, if TO-NEWSGROUP is nil, use the value of
9280 the variable `gnus-move-split-methods' for finding a default target
9281 newsgroup.
9282 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9283 re-spool using this method."
9284   (interactive "P")
9285   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9286
9287 (defun gnus-summary-crosspost-article (&optional n)
9288   "Crosspost the current article to some other group."
9289   (interactive "P")
9290   (gnus-summary-move-article n nil nil 'crosspost))
9291
9292 (defcustom gnus-summary-respool-default-method nil
9293   "Default method type for respooling an article.
9294 If nil, use to the current newsgroup method."
9295   :type 'symbol
9296   :group 'gnus-summary-mail)
9297
9298 (defcustom gnus-summary-display-while-building nil
9299   "If non-nil, show and update the summary buffer as it's being built.
9300 If the value is t, update the buffer after every line is inserted.  If
9301 the value is an integer (N), update the display every N lines."
9302   :group 'gnus-thread
9303   :type '(choice (const :tag "off" nil)
9304                  number
9305                  (const :tag "frequently" t)))
9306
9307 (defun gnus-summary-respool-article (&optional n method)
9308   "Respool the current article.
9309 The article will be squeezed through the mail spooling process again,
9310 which means that it will be put in some mail newsgroup or other
9311 depending on `nnmail-split-methods'.
9312 If N is a positive number, respool the N next articles.
9313 If N is a negative number, respool the N previous articles.
9314 If N is nil and any articles have been marked with the process mark,
9315 respool those articles instead.
9316
9317 Respooling can be done both from mail groups and \"real\" newsgroups.
9318 In the former case, the articles in question will be moved from the
9319 current group into whatever groups they are destined to.  In the
9320 latter case, they will be copied into the relevant groups."
9321   (interactive
9322    (list current-prefix-arg
9323          (let* ((methods (gnus-methods-using 'respool))
9324                 (methname
9325                  (symbol-name (or gnus-summary-respool-default-method
9326                                   (car (gnus-find-method-for-group
9327                                         gnus-newsgroup-name)))))
9328                 (method
9329                  (gnus-completing-read-with-default
9330                   methname "What backend do you want to use when respooling?"
9331                   methods nil t nil 'gnus-mail-method-history))
9332                 ms)
9333            (cond
9334             ((zerop (length (setq ms (gnus-servers-using-backend
9335                                       (intern method)))))
9336              (list (intern method) ""))
9337             ((= 1 (length ms))
9338              (car ms))
9339             (t
9340              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9341                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9342                            ms-alist))))))))
9343   (unless method
9344     (error "No method given for respooling"))
9345   (if (assoc (symbol-name
9346               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9347              (gnus-methods-using 'respool))
9348       (gnus-summary-move-article n nil method)
9349     (gnus-summary-copy-article n nil method)))
9350
9351 (defun gnus-summary-import-article (file &optional edit)
9352   "Import an arbitrary file into a mail newsgroup."
9353   (interactive "fImport file: \nP")
9354   (let ((group gnus-newsgroup-name)
9355         (now (current-time))
9356         atts lines group-art)
9357     (unless (gnus-check-backend-function 'request-accept-article group)
9358       (error "%s does not support article importing" group))
9359     (or (file-readable-p file)
9360         (not (file-regular-p file))
9361         (error "Can't read %s" file))
9362     (save-excursion
9363       (set-buffer (gnus-get-buffer-create " *import file*"))
9364       (erase-buffer)
9365       (nnheader-insert-file-contents file)
9366       (goto-char (point-min))
9367       (if (nnheader-article-p)
9368           (save-restriction
9369             (goto-char (point-min))
9370             (search-forward "\n\n" nil t)
9371             (narrow-to-region (point-min) (1- (point)))
9372             (goto-char (point-min))
9373             (unless (re-search-forward "^date:" nil t)
9374               (goto-char (point-max))
9375               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9376         ;; This doesn't look like an article, so we fudge some headers.
9377         (setq atts (file-attributes file)
9378               lines (count-lines (point-min) (point-max)))
9379         (insert "From: " (read-string "From: ") "\n"
9380                 "Subject: " (read-string "Subject: ") "\n"
9381                 "Date: " (message-make-date (nth 5 atts)) "\n"
9382                 "Message-ID: " (message-make-message-id) "\n"
9383                 "Lines: " (int-to-string lines) "\n"
9384                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9385       (setq group-art (gnus-request-accept-article group nil t))
9386       (kill-buffer (current-buffer)))
9387     (setq gnus-newsgroup-active (gnus-activate-group group))
9388     (forward-line 1)
9389     (gnus-summary-goto-article (cdr group-art) nil t)
9390     (when edit
9391       (gnus-summary-edit-article))))
9392
9393 (defun gnus-summary-create-article ()
9394   "Create an article in a mail newsgroup."
9395   (interactive)
9396   (let ((group gnus-newsgroup-name)
9397         (now (current-time))
9398         group-art)
9399     (unless (gnus-check-backend-function 'request-accept-article group)
9400       (error "%s does not support article importing" group))
9401     (save-excursion
9402       (set-buffer (gnus-get-buffer-create " *import file*"))
9403       (erase-buffer)
9404       (goto-char (point-min))
9405       ;; This doesn't look like an article, so we fudge some headers.
9406       (insert "From: " (read-string "From: ") "\n"
9407               "Subject: " (read-string "Subject: ") "\n"
9408               "Date: " (message-make-date now) "\n"
9409               "Message-ID: " (message-make-message-id) "\n")
9410       (setq group-art (gnus-request-accept-article group nil t))
9411       (kill-buffer (current-buffer)))
9412     (setq gnus-newsgroup-active (gnus-activate-group group))
9413     (forward-line 1)
9414     (gnus-summary-goto-article (cdr group-art) nil t)
9415     (gnus-summary-edit-article)))
9416
9417 (defun gnus-summary-article-posted-p ()
9418   "Say whether the current (mail) article is available from news as well.
9419 This will be the case if the article has both been mailed and posted."
9420   (interactive)
9421   (let ((id (mail-header-references (gnus-summary-article-header)))
9422         (gnus-override-method (car (gnus-refer-article-methods))))
9423     (if (gnus-request-head id "")
9424         (gnus-message 2 "The current message was found on %s"
9425                       gnus-override-method)
9426       (gnus-message 2 "The current message couldn't be found on %s"
9427                     gnus-override-method)
9428       nil)))
9429
9430 (defun gnus-summary-expire-articles (&optional now)
9431   "Expire all articles that are marked as expirable in the current group."
9432   (interactive)
9433   (when (and (not gnus-group-is-exiting-without-update-p)
9434              (gnus-check-backend-function
9435               'request-expire-articles gnus-newsgroup-name))
9436     ;; This backend supports expiry.
9437     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9438            (expirable (if total
9439                           (progn
9440                             ;; We need to update the info for
9441                             ;; this group for `gnus-list-of-read-articles'
9442                             ;; to give us the right answer.
9443                             (gnus-run-hooks 'gnus-exit-group-hook)
9444                             (gnus-summary-update-info)
9445                             (gnus-list-of-read-articles gnus-newsgroup-name))
9446                         (setq gnus-newsgroup-expirable
9447                               (sort gnus-newsgroup-expirable '<))))
9448            (expiry-wait (if now 'immediate
9449                           (gnus-group-find-parameter
9450                            gnus-newsgroup-name 'expiry-wait)))
9451            (nnmail-expiry-target
9452             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9453                 nnmail-expiry-target))
9454            es)
9455       (when expirable
9456         ;; There are expirable articles in this group, so we run them
9457         ;; through the expiry process.
9458         (gnus-message 6 "Expiring articles...")
9459         (unless (gnus-check-group gnus-newsgroup-name)
9460           (error "Can't open server for %s" gnus-newsgroup-name))
9461         ;; The list of articles that weren't expired is returned.
9462         (save-excursion
9463           (if expiry-wait
9464               (let ((nnmail-expiry-wait-function nil)
9465                     (nnmail-expiry-wait expiry-wait))
9466                 (setq es (gnus-request-expire-articles
9467                           expirable gnus-newsgroup-name)))
9468             (setq es (gnus-request-expire-articles
9469                       expirable gnus-newsgroup-name)))
9470           (unless total
9471             (setq gnus-newsgroup-expirable es))
9472           ;; We go through the old list of expirable, and mark all
9473           ;; really expired articles as nonexistent.
9474           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9475             (let ((gnus-use-cache nil))
9476               (dolist (article expirable)
9477                 (when (and (not (memq article es))
9478                            (gnus-data-find article))
9479                   (gnus-summary-mark-article article gnus-canceled-mark)
9480                   (run-hook-with-args 'gnus-summary-article-expire-hook
9481                                       'delete
9482                                       (gnus-data-header
9483                                        (assoc article (gnus-data-list nil)))
9484                                       gnus-newsgroup-name
9485                                       nil
9486                                       nil))))))
9487         (gnus-message 6 "Expiring articles...done")))))
9488
9489 (defun gnus-summary-expire-articles-now ()
9490   "Expunge all expirable articles in the current group.
9491 This means that *all* articles that are marked as expirable will be
9492 deleted forever, right now."
9493   (interactive)
9494   (or gnus-expert-user
9495       (gnus-yes-or-no-p
9496        "Are you really, really, really sure you want to delete all these messages? ")
9497       (error "Phew!"))
9498   (gnus-summary-expire-articles t))
9499
9500 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9501 (defun gnus-summary-delete-article (&optional n)
9502   "Delete the N next (mail) articles.
9503 This command actually deletes articles.  This is not a marking
9504 command.  The article will disappear forever from your life, never to
9505 return.
9506
9507 If N is negative, delete backwards.
9508 If N is nil and articles have been marked with the process mark,
9509 delete these instead.
9510
9511 If `gnus-novice-user' is non-nil you will be asked for
9512 confirmation before the articles are deleted."
9513   (interactive "P")
9514   (unless (gnus-check-backend-function 'request-expire-articles
9515                                        gnus-newsgroup-name)
9516     (error "The current newsgroup does not support article deletion"))
9517   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9518     (error "Couldn't open server"))
9519   ;; Compute the list of articles to delete.
9520   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9521         (nnmail-expiry-target 'delete)
9522         not-deleted)
9523     (if (and gnus-novice-user
9524              (not (gnus-yes-or-no-p
9525                    (format "Do you really want to delete %s forever? "
9526                            (if (> (length articles) 1)
9527                                (format "these %s articles" (length articles))
9528                              "this article")))))
9529         ()
9530       ;; Delete the articles.
9531       (setq not-deleted (gnus-request-expire-articles
9532                          articles gnus-newsgroup-name 'force))
9533       (while articles
9534         (gnus-summary-remove-process-mark (car articles))
9535         ;; The backend might not have been able to delete the article
9536         ;; after all.
9537         (unless (memq (car articles) not-deleted)
9538           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9539         (let* ((article (car articles))
9540                (ghead  (gnus-data-header
9541                                     (assoc article (gnus-data-list nil)))))
9542           (run-hook-with-args 'gnus-summary-article-delete-hook
9543                               'delete ghead gnus-newsgroup-name nil
9544                               nil))
9545         (setq articles (cdr articles)))
9546       (when not-deleted
9547         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9548     (gnus-summary-position-point)
9549     (gnus-set-mode-line 'summary)
9550     not-deleted))
9551
9552 (defun gnus-summary-edit-article (&optional force)
9553   "Edit the current article.
9554 This will have permanent effect only in mail groups.
9555 If FORCE is non-nil, allow editing of articles even in read-only
9556 groups."
9557   (interactive "P")
9558   (save-excursion
9559     (set-buffer gnus-summary-buffer)
9560     (let ((mail-parse-charset gnus-newsgroup-charset)
9561           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9562       (gnus-set-global-variables)
9563       (when (and (not force)
9564                  (gnus-group-read-only-p))
9565         (error "The current newsgroup does not support article editing"))
9566       (gnus-summary-show-article t)
9567       (gnus-article-edit-article
9568        'ignore
9569        `(lambda (no-highlight)
9570           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9571                 (message-options message-options)
9572                 (message-options-set-recipient)
9573                 (mail-parse-ignored-charsets
9574                  ',gnus-newsgroup-ignored-charsets))
9575             (gnus-summary-edit-article-done
9576              ,(or (mail-header-references gnus-current-headers) "")
9577              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9578
9579 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9580
9581 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9582                                                  no-highlight)
9583   "Make edits to the current article permanent."
9584   (interactive)
9585   (save-excursion
9586     ;; The buffer restriction contains the entire article if it exists.
9587     (when (article-goto-body)
9588       (let ((lines (count-lines (point) (point-max)))
9589             (length (- (point-max) (point)))
9590             (case-fold-search t)
9591             (body (copy-marker (point))))
9592         (goto-char (point-min))
9593         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9594           (delete-region (match-beginning 1) (match-end 1))
9595           (insert (number-to-string length)))
9596         (goto-char (point-min))
9597         (when (re-search-forward
9598                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9599           (delete-region (match-beginning 1) (match-end 1))
9600           (insert (number-to-string length)))
9601         (goto-char (point-min))
9602         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9603           (delete-region (match-beginning 1) (match-end 1))
9604           (insert (number-to-string lines))))))
9605   ;; Replace the article.
9606   (let ((buf (current-buffer)))
9607     (with-temp-buffer
9608       (insert-buffer-substring buf)
9609
9610       (if (and (not read-only)
9611                (not (gnus-request-replace-article
9612                      (cdr gnus-article-current) (car gnus-article-current)
9613                      (current-buffer) t)))
9614           (error "Couldn't replace article")
9615         ;; Update the summary buffer.
9616         (if (and references
9617                  (equal (message-tokenize-header references " ")
9618                         (message-tokenize-header
9619                          (or (message-fetch-field "references") "") " ")))
9620             ;; We only have to update this line.
9621             (save-excursion
9622               (save-restriction
9623                 (message-narrow-to-head)
9624                 (let ((head (buffer-string))
9625                       header)
9626                   (with-temp-buffer
9627                     (insert (format "211 %d Article retrieved.\n"
9628                                     (cdr gnus-article-current)))
9629                     (insert head)
9630                     (insert ".\n")
9631                     (let ((nntp-server-buffer (current-buffer)))
9632                       (setq header (car (gnus-get-newsgroup-headers
9633                                          nil t))))
9634                     (save-excursion
9635                       (set-buffer gnus-summary-buffer)
9636                       (gnus-data-set-header
9637                        (gnus-data-find (cdr gnus-article-current))
9638                        header)
9639                       (gnus-summary-update-article-line
9640                        (cdr gnus-article-current) header)
9641                       (if (gnus-summary-goto-subject
9642                            (cdr gnus-article-current) nil t)
9643                           (gnus-summary-update-secondary-mark
9644                            (cdr gnus-article-current))))))))
9645           ;; Update threads.
9646           (set-buffer (or buffer gnus-summary-buffer))
9647           (gnus-summary-update-article (cdr gnus-article-current))
9648           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9649               (gnus-summary-update-secondary-mark
9650                (cdr gnus-article-current))))
9651         ;; Prettify the article buffer again.
9652         (unless no-highlight
9653           (save-excursion
9654             (set-buffer gnus-article-buffer)
9655             ;;;!!! Fix this -- article should be rehighlighted.
9656             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9657             (set-buffer gnus-original-article-buffer)
9658             (gnus-request-article
9659              (cdr gnus-article-current)
9660              (car gnus-article-current) (current-buffer))))
9661         ;; Prettify the summary buffer line.
9662         (when (gnus-visual-p 'summary-highlight 'highlight)
9663           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9664
9665 (defun gnus-summary-edit-wash (key)
9666   "Perform editing command KEY in the article buffer."
9667   (interactive
9668    (list
9669     (progn
9670       (message "%s" (concat (this-command-keys) "- "))
9671       (read-char))))
9672   (message "")
9673   (gnus-summary-edit-article)
9674   (execute-kbd-macro (concat (this-command-keys) key))
9675   (gnus-article-edit-done))
9676
9677 ;;; Respooling
9678
9679 (defun gnus-summary-respool-query (&optional silent trace)
9680   "Query where the respool algorithm would put this article."
9681   (interactive)
9682   (let (gnus-mark-article-hook)
9683     (gnus-summary-select-article)
9684     (save-excursion
9685       (set-buffer gnus-original-article-buffer)
9686       (let ((groups (nnmail-article-group 'identity trace)))
9687         (unless silent
9688           (if groups
9689               (message "This message would go to %s"
9690                        (mapconcat 'car groups ", "))
9691             (message "This message would go to no groups"))
9692           groups)))))
9693
9694 (defun gnus-summary-respool-trace ()
9695   "Trace where the respool algorithm would put this article.
9696 Display a buffer showing all fancy splitting patterns which matched."
9697   (interactive)
9698   (gnus-summary-respool-query nil t))
9699
9700 ;; Summary marking commands.
9701
9702 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9703   "Mark articles which has the same subject as read, and then select the next.
9704 If UNMARK is positive, remove any kind of mark.
9705 If UNMARK is negative, tick articles."
9706   (interactive "P")
9707   (when unmark
9708     (setq unmark (prefix-numeric-value unmark)))
9709   (let ((count
9710          (gnus-summary-mark-same-subject
9711           (gnus-summary-article-subject) unmark)))
9712     ;; Select next unread article.  If auto-select-same mode, should
9713     ;; select the first unread article.
9714     (gnus-summary-next-article t (and gnus-auto-select-same
9715                                       (gnus-summary-article-subject)))
9716     (gnus-message 7 "%d article%s marked as %s"
9717                   count (if (= count 1) " is" "s are")
9718                   (if unmark "unread" "read"))))
9719
9720 (defun gnus-summary-kill-same-subject (&optional unmark)
9721   "Mark articles which has the same subject as read.
9722 If UNMARK is positive, remove any kind of mark.
9723 If UNMARK is negative, tick articles."
9724   (interactive "P")
9725   (when unmark
9726     (setq unmark (prefix-numeric-value unmark)))
9727   (let ((count
9728          (gnus-summary-mark-same-subject
9729           (gnus-summary-article-subject) unmark)))
9730     ;; If marked as read, go to next unread subject.
9731     (when (null unmark)
9732       ;; Go to next unread subject.
9733       (gnus-summary-next-subject 1 t))
9734     (gnus-message 7 "%d articles are marked as %s"
9735                   count (if unmark "unread" "read"))))
9736
9737 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9738   "Mark articles with same SUBJECT as read, and return marked number.
9739 If optional argument UNMARK is positive, remove any kinds of marks.
9740 If optional argument UNMARK is negative, mark articles as unread instead."
9741   (let ((count 1))
9742     (save-excursion
9743       (cond
9744        ((null unmark)                   ; Mark as read.
9745         (while (and
9746                 (progn
9747                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9748                   (gnus-summary-show-thread) t)
9749                 (gnus-summary-find-subject subject))
9750           (setq count (1+ count))))
9751        ((> unmark 0)                    ; Tick.
9752         (while (and
9753                 (progn
9754                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9755                   (gnus-summary-show-thread) t)
9756                 (gnus-summary-find-subject subject))
9757           (setq count (1+ count))))
9758        (t                               ; Mark as unread.
9759         (while (and
9760                 (progn
9761                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9762                   (gnus-summary-show-thread) t)
9763                 (gnus-summary-find-subject subject))
9764           (setq count (1+ count)))))
9765       (gnus-set-mode-line 'summary)
9766       ;; Return the number of marked articles.
9767       count)))
9768
9769 (defun gnus-summary-mark-as-processable (n &optional unmark)
9770   "Set the process mark on the next N articles.
9771 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9772 the process mark instead.  The difference between N and the actual
9773 number of articles marked is returned."
9774   (interactive "P")
9775   (if (and (null n) (gnus-region-active-p))
9776       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9777     (setq n (prefix-numeric-value n))
9778     (let ((backward (< n 0))
9779           (n (abs n)))
9780       (while (and
9781               (> n 0)
9782               (if unmark
9783                   (gnus-summary-remove-process-mark
9784                    (gnus-summary-article-number))
9785                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9786               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9787         (setq n (1- n)))
9788       (when (/= 0 n)
9789         (gnus-message 7 "No more articles"))
9790       (gnus-summary-recenter)
9791       (gnus-summary-position-point)
9792       n)))
9793
9794 (defun gnus-summary-unmark-as-processable (n)
9795   "Remove the process mark from the next N articles.
9796 If N is negative, unmark backward instead.  The difference between N and
9797 the actual number of articles unmarked is returned."
9798   (interactive "P")
9799   (gnus-summary-mark-as-processable n t))
9800
9801 (defun gnus-summary-unmark-all-processable ()
9802   "Remove the process mark from all articles."
9803   (interactive)
9804   (save-excursion
9805     (while gnus-newsgroup-processable
9806       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9807   (gnus-summary-position-point))
9808
9809 (defun gnus-summary-add-mark (article type)
9810   "Mark ARTICLE with a mark of TYPE."
9811   (let ((vtype (car (assq type gnus-article-mark-lists)))
9812         var)
9813     (if (not vtype)
9814         (error "No such mark type: %s" type)
9815       (setq var (intern (format "gnus-newsgroup-%s" type)))
9816       (set var (cons article (symbol-value var)))
9817       (if (memq type '(processable cached replied forwarded recent saved))
9818           (gnus-summary-update-secondary-mark article)
9819         ;;; !!! This is bogus.  We should find out what primary
9820         ;;; !!! mark we want to set.
9821         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9822
9823 (defun gnus-summary-mark-as-expirable (n)
9824   "Mark N articles forward as expirable.
9825 If N is negative, mark backward instead.  The difference between N and
9826 the actual number of articles marked is returned."
9827   (interactive "p")
9828   (gnus-summary-mark-forward n gnus-expirable-mark))
9829
9830 (defun gnus-summary-mark-as-spam (n)
9831   "Mark N articles forward as spam.
9832 If N is negative, mark backward instead.  The difference between N and
9833 the actual number of articles marked is returned."
9834   (interactive "p")
9835   (gnus-summary-mark-forward n gnus-spam-mark))
9836
9837 (defun gnus-summary-mark-article-as-replied (article)
9838   "Mark ARTICLE as replied to and update the summary line.
9839 ARTICLE can also be a list of articles."
9840   (interactive (list (gnus-summary-article-number)))
9841   (let ((articles (if (listp article) article (list article))))
9842     (dolist (article articles)
9843       (unless (numberp article)
9844         (error "%s is not a number" article))
9845       (push article gnus-newsgroup-replied)
9846       (let ((buffer-read-only nil))
9847         (when (gnus-summary-goto-subject article nil t)
9848           (gnus-summary-update-secondary-mark article))))))
9849
9850 (defun gnus-summary-mark-article-as-forwarded (article)
9851   "Mark ARTICLE as forwarded and update the summary line.
9852 ARTICLE can also be a list of articles."
9853   (let ((articles (if (listp article) article (list article))))
9854     (dolist (article articles)
9855       (push article gnus-newsgroup-forwarded)
9856       (let ((buffer-read-only nil))
9857         (when (gnus-summary-goto-subject article nil t)
9858           (gnus-summary-update-secondary-mark article))))))
9859
9860 (defun gnus-summary-set-bookmark (article)
9861   "Set a bookmark in current article."
9862   (interactive (list (gnus-summary-article-number)))
9863   (when (or (not (get-buffer gnus-article-buffer))
9864             (not gnus-current-article)
9865             (not gnus-article-current)
9866             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9867     (error "No current article selected"))
9868   ;; Remove old bookmark, if one exists.
9869   (gnus-pull article gnus-newsgroup-bookmarks)
9870   ;; Set the new bookmark, which is on the form
9871   ;; (article-number . line-number-in-body).
9872   (push
9873    (cons article
9874          (with-current-buffer gnus-article-buffer
9875            (count-lines
9876             (min (point)
9877                  (save-excursion
9878                    (article-goto-body)
9879                    (point)))
9880             (point))))
9881    gnus-newsgroup-bookmarks)
9882   (gnus-message 6 "A bookmark has been added to the current article."))
9883
9884 (defun gnus-summary-remove-bookmark (article)
9885   "Remove the bookmark from the current article."
9886   (interactive (list (gnus-summary-article-number)))
9887   ;; Remove old bookmark, if one exists.
9888   (if (not (assq article gnus-newsgroup-bookmarks))
9889       (gnus-message 6 "No bookmark in current article.")
9890     (gnus-pull article gnus-newsgroup-bookmarks)
9891     (gnus-message 6 "Removed bookmark.")))
9892
9893 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9894 (defun gnus-summary-mark-as-dormant (n)
9895   "Mark N articles forward as dormant.
9896 If N is negative, mark backward instead.  The difference between N and
9897 the actual number of articles marked is returned."
9898   (interactive "p")
9899   (gnus-summary-mark-forward n gnus-dormant-mark))
9900
9901 (defun gnus-summary-set-process-mark (article)
9902   "Set the process mark on ARTICLE and update the summary line."
9903   (setq gnus-newsgroup-processable
9904         (cons article
9905               (delq article gnus-newsgroup-processable)))
9906   (when (gnus-summary-goto-subject article)
9907     (gnus-summary-show-thread)
9908     (gnus-summary-goto-subject article)
9909     (gnus-summary-update-secondary-mark article)))
9910
9911 (defun gnus-summary-remove-process-mark (article)
9912   "Remove the process mark from ARTICLE and update the summary line."
9913   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9914   (when (gnus-summary-goto-subject article)
9915     (gnus-summary-show-thread)
9916     (gnus-summary-goto-subject article)
9917     (gnus-summary-update-secondary-mark article)))
9918
9919 (defun gnus-summary-set-saved-mark (article)
9920   "Set the process mark on ARTICLE and update the summary line."
9921   (push article gnus-newsgroup-saved)
9922   (when (gnus-summary-goto-subject article)
9923     (gnus-summary-update-secondary-mark article)))
9924
9925 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9926   "Mark N articles as read forwards.
9927 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9928 The difference between N and the actual number of articles marked is
9929 returned.
9930 If NO-EXPIRE, auto-expiry will be inhibited."
9931   (interactive "p")
9932   (gnus-summary-show-thread)
9933   (let ((backward (< n 0))
9934         (gnus-summary-goto-unread
9935          (and gnus-summary-goto-unread
9936               (not (eq gnus-summary-goto-unread 'never))
9937               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9938                                     gnus-ticked-mark gnus-dormant-mark)))))
9939         (n (abs n))
9940         (mark (or mark gnus-del-mark)))
9941     (while (and (> n 0)
9942                 (gnus-summary-mark-article nil mark no-expire)
9943                 (zerop (gnus-summary-next-subject
9944                         (if backward -1 1)
9945                         (and gnus-summary-goto-unread
9946                              (not (eq gnus-summary-goto-unread 'never)))
9947                         t)))
9948       (setq n (1- n)))
9949     (when (/= 0 n)
9950       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9951     (gnus-summary-recenter)
9952     (gnus-summary-position-point)
9953     (gnus-set-mode-line 'summary)
9954     n))
9955
9956 (defun gnus-summary-mark-article-as-read (mark)
9957   "Mark the current article quickly as read with MARK."
9958   (let ((article (gnus-summary-article-number)))
9959     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9960     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9961     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9962     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9963     (push (cons article mark) gnus-newsgroup-reads)
9964     ;; Possibly remove from cache, if that is used.
9965     (when gnus-use-cache
9966       (gnus-cache-enter-remove-article article))
9967     ;; Allow the backend to change the mark.
9968     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9969     ;; Check for auto-expiry.
9970     (when (and gnus-newsgroup-auto-expire
9971                (memq mark gnus-auto-expirable-marks))
9972       (setq mark gnus-expirable-mark)
9973       ;; Let the backend know about the mark change.
9974       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9975       (push article gnus-newsgroup-expirable))
9976     ;; Set the mark in the buffer.
9977     (gnus-summary-update-mark mark 'unread)
9978     t))
9979
9980 (defun gnus-summary-mark-article-as-unread (mark)
9981   "Mark the current article quickly as unread with MARK."
9982   (let* ((article (gnus-summary-article-number))
9983          (old-mark (gnus-summary-article-mark article)))
9984     ;; Allow the backend to change the mark.
9985     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9986     (if (eq mark old-mark)
9987         t
9988       (if (<= article 0)
9989           (progn
9990             (gnus-error 1 "Can't mark negative article numbers")
9991             nil)
9992         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9993         (setq gnus-newsgroup-spam-marked
9994               (delq article gnus-newsgroup-spam-marked))
9995         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9996         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9997         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9998         (cond ((= mark gnus-ticked-mark)
9999                (setq gnus-newsgroup-marked
10000                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10001                                               article)))
10002               ((= mark gnus-spam-mark)
10003                (setq gnus-newsgroup-spam-marked
10004                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10005                                               article)))
10006               ((= mark gnus-dormant-mark)
10007                (setq gnus-newsgroup-dormant
10008                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10009                                               article)))
10010               (t
10011                (setq gnus-newsgroup-unreads
10012                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10013                                               article))))
10014         (gnus-pull article gnus-newsgroup-reads)
10015
10016         ;; See whether the article is to be put in the cache.
10017         (and gnus-use-cache
10018              (vectorp (gnus-summary-article-header article))
10019              (save-excursion
10020                (gnus-cache-possibly-enter-article
10021                 gnus-newsgroup-name article
10022                 (gnus-summary-article-header article)
10023                 (= mark gnus-ticked-mark)
10024                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10025
10026         ;; Fix the mark.
10027         (gnus-summary-update-mark mark 'unread)
10028         t))))
10029
10030 (defun gnus-summary-mark-article (&optional article mark no-expire)
10031   "Mark ARTICLE with MARK.  MARK can be any character.
10032 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10033 `??' (dormant) and `?E' (expirable).
10034 If MARK is nil, then the default character `?r' is used.
10035 If ARTICLE is nil, then the article on the current line will be
10036 marked.
10037 If NO-EXPIRE, auto-expiry will be inhibited."
10038   ;; The mark might be a string.
10039   (when (stringp mark)
10040     (setq mark (aref mark 0)))
10041   ;; If no mark is given, then we check auto-expiring.
10042   (when (null mark)
10043     (setq mark gnus-del-mark))
10044   (when (and (not no-expire)
10045              gnus-newsgroup-auto-expire
10046              (memq mark gnus-auto-expirable-marks))
10047     (setq mark gnus-expirable-mark))
10048   (let ((article (or article (gnus-summary-article-number)))
10049         (old-mark (gnus-summary-article-mark article)))
10050     ;; Allow the backend to change the mark.
10051     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10052     (if (eq mark old-mark)
10053         t
10054       (unless article
10055         (error "No article on current line"))
10056       (if (not (if (or (= mark gnus-unread-mark)
10057                        (= mark gnus-ticked-mark)
10058                        (= mark gnus-spam-mark)
10059                        (= mark gnus-dormant-mark))
10060                    (gnus-mark-article-as-unread article mark)
10061                  (gnus-mark-article-as-read article mark)))
10062           t
10063         ;; See whether the article is to be put in the cache.
10064         (and gnus-use-cache
10065              (not (= mark gnus-canceled-mark))
10066              (vectorp (gnus-summary-article-header article))
10067              (save-excursion
10068                (gnus-cache-possibly-enter-article
10069                 gnus-newsgroup-name article
10070                 (gnus-summary-article-header article)
10071                 (= mark gnus-ticked-mark)
10072                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10073
10074         (when (gnus-summary-goto-subject article nil t)
10075           (let ((buffer-read-only nil))
10076             (gnus-summary-show-thread)
10077             ;; Fix the mark.
10078             (gnus-summary-update-mark mark 'unread)
10079             t))))))
10080
10081 (defun gnus-summary-update-secondary-mark (article)
10082   "Update the secondary (read, process, cache) mark."
10083   (gnus-summary-update-mark
10084    (cond ((memq article gnus-newsgroup-processable)
10085           gnus-process-mark)
10086          ((memq article gnus-newsgroup-cached)
10087           gnus-cached-mark)
10088          ((memq article gnus-newsgroup-replied)
10089           gnus-replied-mark)
10090          ((memq article gnus-newsgroup-forwarded)
10091           gnus-forwarded-mark)
10092          ((memq article gnus-newsgroup-saved)
10093           gnus-saved-mark)
10094          ((memq article gnus-newsgroup-recent)
10095           gnus-recent-mark)
10096          ((memq article gnus-newsgroup-unseen)
10097           gnus-unseen-mark)
10098          (t gnus-no-mark))
10099    'replied)
10100   (when (gnus-visual-p 'summary-highlight 'highlight)
10101     (gnus-run-hooks 'gnus-summary-update-hook))
10102   t)
10103
10104 (defun gnus-summary-update-download-mark (article)
10105   "Update the download mark."
10106   (gnus-summary-update-mark
10107    (cond ((memq article gnus-newsgroup-undownloaded)
10108           gnus-undownloaded-mark)
10109          (gnus-newsgroup-agentized
10110           gnus-downloaded-mark)
10111          (t
10112           gnus-no-mark))
10113    'download)
10114   (gnus-summary-update-line t)
10115   t)
10116
10117 (defun gnus-summary-update-mark (mark type)
10118   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10119         (buffer-read-only nil))
10120     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10121     (when forward
10122       (when (looking-at "\r")
10123         (incf forward))
10124       (when (<= (+ forward (point)) (point-max))
10125         ;; Go to the right position on the line.
10126         (goto-char (+ forward (point)))
10127         ;; Replace the old mark with the new mark.
10128         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10129         ;; Optionally update the marks by some user rule.
10130         (when (eq type 'unread)
10131           (gnus-data-set-mark
10132            (gnus-data-find (gnus-summary-article-number)) mark)
10133           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10134
10135 (defun gnus-mark-article-as-read (article &optional mark)
10136   "Enter ARTICLE in the pertinent lists and remove it from others."
10137   ;; Make the article expirable.
10138   (let ((mark (or mark gnus-del-mark)))
10139     (setq gnus-newsgroup-expirable
10140           (if (= mark gnus-expirable-mark)
10141               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10142             (delq article gnus-newsgroup-expirable)))
10143     ;; Remove from unread and marked lists.
10144     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10145     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10146     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10147     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10148     (push (cons article mark) gnus-newsgroup-reads)
10149     ;; Possibly remove from cache, if that is used.
10150     (when gnus-use-cache
10151       (gnus-cache-enter-remove-article article))
10152     t))
10153
10154 (defun gnus-mark-article-as-unread (article &optional mark)
10155   "Enter ARTICLE in the pertinent lists and remove it from others."
10156   (let ((mark (or mark gnus-ticked-mark)))
10157     (if (<= article 0)
10158         (progn
10159           (gnus-error 1 "Can't mark negative article numbers")
10160           nil)
10161       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10162             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10163             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10164             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10165             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10166
10167       ;; Unsuppress duplicates?
10168       (when gnus-suppress-duplicates
10169         (gnus-dup-unsuppress-article article))
10170
10171       (cond ((= mark gnus-ticked-mark)
10172              (setq gnus-newsgroup-marked
10173                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10174             ((= mark gnus-spam-mark)
10175              (setq gnus-newsgroup-spam-marked
10176                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10177                                             article)))
10178             ((= mark gnus-dormant-mark)
10179              (setq gnus-newsgroup-dormant
10180                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10181             (t
10182              (setq gnus-newsgroup-unreads
10183                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10184       (gnus-pull article gnus-newsgroup-reads)
10185       t)))
10186
10187 (defalias 'gnus-summary-mark-as-unread-forward
10188   'gnus-summary-tick-article-forward)
10189 (make-obsolete 'gnus-summary-mark-as-unread-forward
10190                'gnus-summary-tick-article-forward)
10191 (defun gnus-summary-tick-article-forward (n)
10192   "Tick N articles forwards.
10193 If N is negative, tick backwards instead.
10194 The difference between N and the number of articles ticked is returned."
10195   (interactive "p")
10196   (gnus-summary-mark-forward n gnus-ticked-mark))
10197
10198 (defalias 'gnus-summary-mark-as-unread-backward
10199   'gnus-summary-tick-article-backward)
10200 (make-obsolete 'gnus-summary-mark-as-unread-backward
10201                'gnus-summary-tick-article-backward)
10202 (defun gnus-summary-tick-article-backward (n)
10203   "Tick N articles backwards.
10204 The difference between N and the number of articles ticked is returned."
10205   (interactive "p")
10206   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10207
10208 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10209 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10210 (defun gnus-summary-tick-article (&optional article clear-mark)
10211   "Mark current article as unread.
10212 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10213 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10214   (interactive)
10215   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10216                                        gnus-ticked-mark)))
10217
10218 (defun gnus-summary-mark-as-read-forward (n)
10219   "Mark N articles as read forwards.
10220 If N is negative, mark backwards instead.
10221 The difference between N and the actual number of articles marked is
10222 returned."
10223   (interactive "p")
10224   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10225
10226 (defun gnus-summary-mark-as-read-backward (n)
10227   "Mark the N articles as read backwards.
10228 The difference between N and the actual number of articles marked is
10229 returned."
10230   (interactive "p")
10231   (gnus-summary-mark-forward
10232    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10233
10234 (defun gnus-summary-mark-as-read (&optional article mark)
10235   "Mark current article as read.
10236 ARTICLE specifies the article to be marked as read.
10237 MARK specifies a string to be inserted at the beginning of the line."
10238   (gnus-summary-mark-article article mark))
10239
10240 (defun gnus-summary-clear-mark-forward (n)
10241   "Clear marks from N articles forward.
10242 If N is negative, clear backward instead.
10243 The difference between N and the number of marks cleared is returned."
10244   (interactive "p")
10245   (gnus-summary-mark-forward n gnus-unread-mark))
10246
10247 (defun gnus-summary-clear-mark-backward (n)
10248   "Clear marks from N articles backward.
10249 The difference between N and the number of marks cleared is returned."
10250   (interactive "p")
10251   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10252
10253 (defun gnus-summary-mark-unread-as-read ()
10254   "Intended to be used by `gnus-summary-mark-article-hook'."
10255   (when (memq gnus-current-article gnus-newsgroup-unreads)
10256     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10257
10258 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10259   "Intended to be used by `gnus-summary-mark-article-hook'."
10260   (let ((mark (gnus-summary-article-mark)))
10261     (when (or (gnus-unread-mark-p mark)
10262               (gnus-read-mark-p mark))
10263       (gnus-summary-mark-article gnus-current-article
10264                                  (or new-mark gnus-read-mark)))))
10265
10266 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10267   "Intended to be used by `gnus-summary-mark-article-hook'."
10268   (let ((mark (gnus-summary-article-mark)))
10269     (when (or (gnus-unread-mark-p mark)
10270               (gnus-read-mark-p mark))
10271       (gnus-summary-mark-article (gnus-summary-article-number)
10272                                  (or new-mark gnus-read-mark)))))
10273
10274 (defun gnus-summary-mark-unread-as-ticked ()
10275   "Intended to be used by `gnus-summary-mark-article-hook'."
10276   (when (memq gnus-current-article gnus-newsgroup-unreads)
10277     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10278
10279 (defun gnus-summary-mark-region-as-read (point mark all)
10280   "Mark all unread articles between point and mark as read.
10281 If given a prefix, mark all articles between point and mark as read,
10282 even ticked and dormant ones."
10283   (interactive "r\nP")
10284   (save-excursion
10285     (let (article)
10286       (goto-char point)
10287       (beginning-of-line)
10288       (while (and
10289               (< (point) mark)
10290               (progn
10291                 (when (or all
10292                           (memq (setq article (gnus-summary-article-number))
10293                                 gnus-newsgroup-unreads))
10294                   (gnus-summary-mark-article article gnus-del-mark))
10295                 t)
10296               (gnus-summary-find-next))))))
10297
10298 (defun gnus-summary-mark-below (score mark)
10299   "Mark articles with score less than SCORE with MARK."
10300   (interactive "P\ncMark: ")
10301   (setq score (if score
10302                   (prefix-numeric-value score)
10303                 (or gnus-summary-default-score 0)))
10304   (save-excursion
10305     (set-buffer gnus-summary-buffer)
10306     (goto-char (point-min))
10307     (while
10308         (progn
10309           (and (< (gnus-summary-article-score) score)
10310                (gnus-summary-mark-article nil mark))
10311           (gnus-summary-find-next)))))
10312
10313 (defun gnus-summary-kill-below (&optional score)
10314   "Mark articles with score below SCORE as read."
10315   (interactive "P")
10316   (gnus-summary-mark-below score gnus-killed-mark))
10317
10318 (defun gnus-summary-clear-above (&optional score)
10319   "Clear all marks from articles with score above SCORE."
10320   (interactive "P")
10321   (gnus-summary-mark-above score gnus-unread-mark))
10322
10323 (defun gnus-summary-tick-above (&optional score)
10324   "Tick all articles with score above SCORE."
10325   (interactive "P")
10326   (gnus-summary-mark-above score gnus-ticked-mark))
10327
10328 (defun gnus-summary-mark-above (score mark)
10329   "Mark articles with score over SCORE with MARK."
10330   (interactive "P\ncMark: ")
10331   (setq score (if score
10332                   (prefix-numeric-value score)
10333                 (or gnus-summary-default-score 0)))
10334   (save-excursion
10335     (set-buffer gnus-summary-buffer)
10336     (goto-char (point-min))
10337     (while (and (progn
10338                   (when (> (gnus-summary-article-score) score)
10339                     (gnus-summary-mark-article nil mark))
10340                   t)
10341                 (gnus-summary-find-next)))))
10342
10343 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10344 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10345 (defun gnus-summary-limit-include-expunged (&optional no-error)
10346   "Display all the hidden articles that were expunged for low scores."
10347   (interactive)
10348   (let ((buffer-read-only nil))
10349     (let ((scored gnus-newsgroup-scored)
10350           headers h)
10351       (while scored
10352         (unless (gnus-summary-article-header (caar scored))
10353           (and (setq h (gnus-number-to-header (caar scored)))
10354                (< (cdar scored) gnus-summary-expunge-below)
10355                (push h headers)))
10356         (setq scored (cdr scored)))
10357       (if (not headers)
10358           (when (not no-error)
10359             (error "No expunged articles hidden"))
10360         (goto-char (point-min))
10361         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10362         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10363         (mapcar (lambda (x) (push (mail-header-number x)
10364                                   gnus-newsgroup-limit))
10365                 headers)
10366         (gnus-summary-prepare-unthreaded (nreverse headers))
10367         (goto-char (point-min))
10368         (gnus-summary-position-point)
10369         t))))
10370
10371 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10372   "Mark all unread articles in this newsgroup as read.
10373 If prefix argument ALL is non-nil, ticked and dormant articles will
10374 also be marked as read.
10375 If QUIETLY is non-nil, no questions will be asked.
10376
10377 If TO-HERE is non-nil, it should be a point in the buffer.  All
10378 articles before (after, if REVERSE is set) this point will be marked
10379 as read.
10380
10381 Note that this function will only catch up the unread article
10382 in the current summary buffer limitation.
10383
10384 The number of articles marked as read is returned."
10385   (interactive "P")
10386   (prog1
10387       (save-excursion
10388         (when (or quietly
10389                   (not gnus-interactive-catchup) ;Without confirmation?
10390                   gnus-expert-user
10391                   (gnus-y-or-n-p
10392                    (if all
10393                        "Mark absolutely all articles as read? "
10394                      "Mark all unread articles as read? ")))
10395           (if (and not-mark
10396                    (not gnus-newsgroup-adaptive)
10397                    (not gnus-newsgroup-auto-expire)
10398                    (not gnus-suppress-duplicates)
10399                    (or (not gnus-use-cache)
10400                        (eq gnus-use-cache 'passive)))
10401               (progn
10402                 (when all
10403                   (setq gnus-newsgroup-marked nil
10404                         gnus-newsgroup-spam-marked nil
10405                         gnus-newsgroup-dormant nil))
10406                 (setq gnus-newsgroup-unreads
10407                       (gnus-sorted-nunion
10408                        (gnus-intersection gnus-newsgroup-unreads
10409                                           gnus-newsgroup-downloadable)
10410                        gnus-newsgroup-unfetched)))
10411             ;; We actually mark all articles as canceled, which we
10412             ;; have to do when using auto-expiry or adaptive scoring.
10413             (gnus-summary-show-all-threads)
10414             (if (and to-here reverse)
10415                 (progn
10416                   (goto-char to-here)
10417                   (gnus-summary-mark-current-read-and-unread-as-read
10418                    gnus-catchup-mark)
10419                   (while (gnus-summary-find-next (not all))
10420                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10421               (when (gnus-summary-first-subject (not all))
10422                 (while (and
10423                         (if to-here (< (point) to-here) t)
10424                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10425                         (gnus-summary-find-next (not all))))))
10426             (gnus-set-mode-line 'summary))
10427           t))
10428     (gnus-summary-position-point)))
10429
10430 (defun gnus-summary-catchup-to-here (&optional all)
10431   "Mark all unticked articles before the current one as read.
10432 If ALL is non-nil, also mark ticked and dormant articles as read."
10433   (interactive "P")
10434   (save-excursion
10435     (gnus-save-hidden-threads
10436       (let ((beg (point)))
10437         ;; We check that there are unread articles.
10438         (when (or all (gnus-summary-find-prev))
10439           (gnus-summary-catchup all t beg)))))
10440   (gnus-summary-position-point))
10441
10442 (defun gnus-summary-catchup-from-here (&optional all)
10443   "Mark all unticked articles after (and including) the current one as read.
10444 If ALL is non-nil, also mark ticked and dormant articles as read."
10445   (interactive "P")
10446   (save-excursion
10447     (gnus-save-hidden-threads
10448       (let ((beg (point)))
10449         ;; We check that there are unread articles.
10450         (when (or all (gnus-summary-find-next))
10451           (gnus-summary-catchup all t beg nil t)))))
10452   (gnus-summary-position-point))
10453
10454 (defun gnus-summary-catchup-all (&optional quietly)
10455   "Mark all articles in this newsgroup as read.
10456 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10457 instead, which marks only unread articles as read."
10458   (interactive "P")
10459   (gnus-summary-catchup t quietly))
10460
10461 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10462   "Mark all unread articles in this group as read, then exit.
10463 If prefix argument ALL is non-nil, all articles are marked as read.
10464 If QUIETLY is non-nil, no questions will be asked."
10465   (interactive "P")
10466   (when (gnus-summary-catchup all quietly nil 'fast)
10467     ;; Select next newsgroup or exit.
10468     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10469              (eq gnus-auto-select-next 'quietly))
10470         (gnus-summary-next-group nil)
10471       (gnus-summary-exit))))
10472
10473 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10474   "Mark all articles in this newsgroup as read, and then exit.
10475 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10476 instead, which marks only unread articles as read."
10477   (interactive "P")
10478   (gnus-summary-catchup-and-exit t quietly))
10479
10480 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10481   "Mark all articles in this group as read and select the next group.
10482 If given a prefix, mark all articles, unread as well as ticked, as
10483 read."
10484   (interactive "P")
10485   (save-excursion
10486     (gnus-summary-catchup all))
10487   (gnus-summary-next-group))
10488
10489 ;;;
10490 ;;; with article
10491 ;;;
10492
10493 (defmacro gnus-with-article (article &rest forms)
10494   "Select ARTICLE and perform FORMS in the original article buffer.
10495 Then replace the article with the result."
10496   `(progn
10497      ;; We don't want the article to be marked as read.
10498      (let (gnus-mark-article-hook)
10499        (gnus-summary-select-article t t nil ,article))
10500      (set-buffer gnus-original-article-buffer)
10501      ,@forms
10502      (if (not (gnus-check-backend-function
10503                'request-replace-article (car gnus-article-current)))
10504          (gnus-message 5 "Read-only group; not replacing")
10505        (unless (gnus-request-replace-article
10506                 ,article (car gnus-article-current)
10507                 (current-buffer) t)
10508          (error "Couldn't replace article")))
10509      ;; The cache and backlog have to be flushed somewhat.
10510      (when gnus-keep-backlog
10511        (gnus-backlog-remove-article
10512         (car gnus-article-current) (cdr gnus-article-current)))
10513      (when gnus-use-cache
10514        (gnus-cache-update-article
10515         (car gnus-article-current) (cdr gnus-article-current)))))
10516
10517 (put 'gnus-with-article 'lisp-indent-function 1)
10518 (put 'gnus-with-article 'edebug-form-spec '(form body))
10519
10520 ;; Thread-based commands.
10521
10522 (defun gnus-summary-articles-in-thread (&optional article)
10523   "Return a list of all articles in the current thread.
10524 If ARTICLE is non-nil, return all articles in the thread that starts
10525 with that article."
10526   (let* ((article (or article (gnus-summary-article-number)))
10527          (data (gnus-data-find-list article))
10528          (top-level (gnus-data-level (car data)))
10529          (top-subject
10530           (cond ((null gnus-thread-operation-ignore-subject)
10531                  (gnus-simplify-subject-re
10532                   (mail-header-subject (gnus-data-header (car data)))))
10533                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10534                  (gnus-simplify-subject-fuzzy
10535                   (mail-header-subject (gnus-data-header (car data)))))
10536                 (t nil)))
10537          (end-point (save-excursion
10538                       (if (gnus-summary-go-to-next-thread)
10539                           (point) (point-max))))
10540          articles)
10541     (while (and data
10542                 (< (gnus-data-pos (car data)) end-point))
10543       (when (or (not top-subject)
10544                 (string= top-subject
10545                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10546                              (gnus-simplify-subject-fuzzy
10547                               (mail-header-subject
10548                                (gnus-data-header (car data))))
10549                            (gnus-simplify-subject-re
10550                             (mail-header-subject
10551                              (gnus-data-header (car data)))))))
10552         (push (gnus-data-number (car data)) articles))
10553       (unless (and (setq data (cdr data))
10554                    (> (gnus-data-level (car data)) top-level))
10555         (setq data nil)))
10556     ;; Return the list of articles.
10557     (nreverse articles)))
10558
10559 (defun gnus-summary-rethread-current ()
10560   "Rethread the thread the current article is part of."
10561   (interactive)
10562   (let* ((gnus-show-threads t)
10563          (article (gnus-summary-article-number))
10564          (id (mail-header-id (gnus-summary-article-header)))
10565          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10566     (unless id
10567       (error "No article on the current line"))
10568     (gnus-rebuild-thread id)
10569     (gnus-summary-goto-subject article)))
10570
10571 (defun gnus-summary-reparent-thread ()
10572   "Make the current article child of the marked (or previous) article.
10573
10574 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10575 is non-nil or the Subject: of both articles are the same."
10576   (interactive)
10577   (unless (not (gnus-group-read-only-p))
10578     (error "The current newsgroup does not support article editing"))
10579   (unless (<= (length gnus-newsgroup-processable) 1)
10580     (error "No more than one article may be marked"))
10581   (save-window-excursion
10582     (let ((gnus-article-buffer " *reparent*")
10583           (current-article (gnus-summary-article-number))
10584           ;; First grab the marked article, otherwise one line up.
10585           (parent-article (if (not (null gnus-newsgroup-processable))
10586                               (car gnus-newsgroup-processable)
10587                             (save-excursion
10588                               (if (eq (forward-line -1) 0)
10589                                   (gnus-summary-article-number)
10590                                 (error "Beginning of summary buffer"))))))
10591       (unless (not (eq current-article parent-article))
10592         (error "An article may not be self-referential"))
10593       (let ((message-id (mail-header-id
10594                          (gnus-summary-article-header parent-article))))
10595         (unless (and message-id (not (equal message-id "")))
10596           (error "No message-id in desired parent"))
10597         (gnus-with-article current-article
10598           (save-restriction
10599             (goto-char (point-min))
10600             (message-narrow-to-head)
10601             (if (re-search-forward "^References: " nil t)
10602                 (progn
10603                   (re-search-forward "^[^ \t]" nil t)
10604                   (forward-line -1)
10605                   (end-of-line)
10606                   (insert " " message-id))
10607               (insert "References: " message-id "\n"))))
10608         (set-buffer gnus-summary-buffer)
10609         (gnus-summary-unmark-all-processable)
10610         (gnus-summary-update-article current-article)
10611         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10612             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10613         (gnus-summary-rethread-current)
10614         (gnus-message 3 "Article %d is now the child of article %d"
10615                       current-article parent-article)))))
10616
10617 (defun gnus-summary-toggle-threads (&optional arg)
10618   "Toggle showing conversation threads.
10619 If ARG is positive number, turn showing conversation threads on."
10620   (interactive "P")
10621   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10622     (setq gnus-show-threads
10623           (if (null arg) (not gnus-show-threads)
10624             (> (prefix-numeric-value arg) 0)))
10625     (gnus-summary-prepare)
10626     (gnus-summary-goto-subject current)
10627     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10628     (gnus-summary-position-point)))
10629
10630 (defun gnus-summary-show-all-threads ()
10631   "Show all threads."
10632   (interactive)
10633   (save-excursion
10634     (let ((buffer-read-only nil))
10635       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10636   (gnus-summary-position-point))
10637
10638 (defun gnus-summary-show-thread ()
10639   "Show thread subtrees.
10640 Returns nil if no thread was there to be shown."
10641   (interactive)
10642   (let ((buffer-read-only nil)
10643         (orig (point))
10644         (end (point-at-eol))
10645         ;; Leave point at bol
10646         (beg (progn (beginning-of-line) (point))))
10647     (prog1
10648         ;; Any hidden lines here?
10649         (search-forward "\r" end t)
10650       (subst-char-in-region beg end ?\^M ?\n t)
10651       (goto-char orig)
10652       (gnus-summary-position-point))))
10653
10654 (defun gnus-summary-maybe-hide-threads ()
10655   "If requested, hide the threads that should be hidden."
10656   (when (and gnus-show-threads
10657              gnus-thread-hide-subtree)
10658     (gnus-summary-hide-all-threads
10659      (if (or (consp gnus-thread-hide-subtree)
10660              (functionp gnus-thread-hide-subtree))
10661          (gnus-make-predicate gnus-thread-hide-subtree)
10662        nil))))
10663
10664 ;;; Hiding predicates.
10665
10666 (defun gnus-article-unread-p (header)
10667   (memq (mail-header-number header) gnus-newsgroup-unreads))
10668
10669 (defun gnus-article-unseen-p (header)
10670   (memq (mail-header-number header) gnus-newsgroup-unseen))
10671
10672 (defun gnus-map-articles (predicate articles)
10673   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10674   (apply 'gnus-or (mapcar predicate
10675                           (mapcar 'gnus-summary-article-header articles))))
10676
10677 (defun gnus-summary-hide-all-threads (&optional predicate)
10678   "Hide all thread subtrees.
10679 If PREDICATE is supplied, threads that satisfy this predicate
10680 will not be hidden."
10681   (interactive)
10682   (save-excursion
10683     (goto-char (point-min))
10684     (let ((end nil))
10685       (while (not end)
10686         (when (or (not predicate)
10687                   (gnus-map-articles
10688                    predicate (gnus-summary-article-children)))
10689             (gnus-summary-hide-thread))
10690         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10691   (gnus-summary-position-point))
10692
10693 (defun gnus-summary-hide-thread ()
10694   "Hide thread subtrees.
10695 If PREDICATE is supplied, threads that satisfy this predicate
10696 will not be hidden.
10697 Returns nil if no threads were there to be hidden."
10698   (interactive)
10699   (let ((buffer-read-only nil)
10700         (start (point))
10701         (article (gnus-summary-article-number)))
10702     (goto-char start)
10703     ;; Go forward until either the buffer ends or the subthread
10704     ;; ends.
10705     (when (and (not (eobp))
10706                (or (zerop (gnus-summary-next-thread 1 t))
10707                    (goto-char (point-max))))
10708       (prog1
10709           (if (and (> (point) start)
10710                    (search-backward "\n" start t))
10711               (progn
10712                 (subst-char-in-region start (point) ?\n ?\^M)
10713                 (gnus-summary-goto-subject article))
10714             (goto-char start)
10715             nil)))))
10716
10717 (defun gnus-summary-go-to-next-thread (&optional previous)
10718   "Go to the same level (or less) next thread.
10719 If PREVIOUS is non-nil, go to previous thread instead.
10720 Return the article number moved to, or nil if moving was impossible."
10721   (let ((level (gnus-summary-thread-level))
10722         (way (if previous -1 1))
10723         (beg (point)))
10724     (forward-line way)
10725     (while (and (not (eobp))
10726                 (< level (gnus-summary-thread-level)))
10727       (forward-line way))
10728     (if (eobp)
10729         (progn
10730           (goto-char beg)
10731           nil)
10732       (setq beg (point))
10733       (prog1
10734           (gnus-summary-article-number)
10735         (goto-char beg)))))
10736
10737 (defun gnus-summary-next-thread (n &optional silent)
10738   "Go to the same level next N'th thread.
10739 If N is negative, search backward instead.
10740 Returns the difference between N and the number of skips actually
10741 done.
10742
10743 If SILENT, don't output messages."
10744   (interactive "p")
10745   (let ((backward (< n 0))
10746         (n (abs n)))
10747     (while (and (> n 0)
10748                 (gnus-summary-go-to-next-thread backward))
10749       (decf n))
10750     (unless silent
10751       (gnus-summary-position-point))
10752     (when (and (not silent) (/= 0 n))
10753       (gnus-message 7 "No more threads"))
10754     n))
10755
10756 (defun gnus-summary-prev-thread (n)
10757   "Go to the same level previous N'th thread.
10758 Returns the difference between N and the number of skips actually
10759 done."
10760   (interactive "p")
10761   (gnus-summary-next-thread (- n)))
10762
10763 (defun gnus-summary-go-down-thread ()
10764   "Go down one level in the current thread."
10765   (let ((children (gnus-summary-article-children)))
10766     (when children
10767       (gnus-summary-goto-subject (car children)))))
10768
10769 (defun gnus-summary-go-up-thread ()
10770   "Go up one level in the current thread."
10771   (let ((parent (gnus-summary-article-parent)))
10772     (when parent
10773       (gnus-summary-goto-subject parent))))
10774
10775 (defun gnus-summary-down-thread (n)
10776   "Go down thread N steps.
10777 If N is negative, go up instead.
10778 Returns the difference between N and how many steps down that were
10779 taken."
10780   (interactive "p")
10781   (let ((up (< n 0))
10782         (n (abs n)))
10783     (while (and (> n 0)
10784                 (if up (gnus-summary-go-up-thread)
10785                   (gnus-summary-go-down-thread)))
10786       (setq n (1- n)))
10787     (gnus-summary-position-point)
10788     (when (/= 0 n)
10789       (gnus-message 7 "Can't go further"))
10790     n))
10791
10792 (defun gnus-summary-up-thread (n)
10793   "Go up thread N steps.
10794 If N is negative, go down instead.
10795 Returns the difference between N and how many steps down that were
10796 taken."
10797   (interactive "p")
10798   (gnus-summary-down-thread (- n)))
10799
10800 (defun gnus-summary-top-thread ()
10801   "Go to the top of the thread."
10802   (interactive)
10803   (while (gnus-summary-go-up-thread))
10804   (gnus-summary-article-number))
10805
10806 (defun gnus-summary-kill-thread (&optional unmark)
10807   "Mark articles under current thread as read.
10808 If the prefix argument is positive, remove any kinds of marks.
10809 If the prefix argument is negative, tick articles instead."
10810   (interactive "P")
10811   (when unmark
10812     (setq unmark (prefix-numeric-value unmark)))
10813   (let ((articles (gnus-summary-articles-in-thread)))
10814     (save-excursion
10815       ;; Expand the thread.
10816       (gnus-summary-show-thread)
10817       ;; Mark all the articles.
10818       (while articles
10819         (gnus-summary-goto-subject (car articles))
10820         (cond ((null unmark)
10821                (gnus-summary-mark-article-as-read gnus-killed-mark))
10822               ((> unmark 0)
10823                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10824               (t
10825                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10826         (setq articles (cdr articles))))
10827     ;; Hide killed subtrees.
10828     (and (null unmark)
10829          gnus-thread-hide-killed
10830          (gnus-summary-hide-thread))
10831     ;; If marked as read, go to next unread subject.
10832     (when (null unmark)
10833       ;; Go to next unread subject.
10834       (gnus-summary-next-subject 1 t)))
10835   (gnus-set-mode-line 'summary))
10836
10837 ;; Summary sorting commands
10838
10839 (defun gnus-summary-sort-by-number (&optional reverse)
10840   "Sort the summary buffer by article number.
10841 Argument REVERSE means reverse order."
10842   (interactive "P")
10843   (gnus-summary-sort 'number reverse))
10844
10845 (defun gnus-summary-sort-by-random (&optional reverse)
10846   "Randomize the order in the summary buffer.
10847 Argument REVERSE means to randomize in reverse order."
10848   (interactive "P")
10849   (gnus-summary-sort 'random reverse))
10850
10851 (defun gnus-summary-sort-by-author (&optional reverse)
10852   "Sort the summary buffer by author name alphabetically.
10853 If `case-fold-search' is non-nil, case of letters is ignored.
10854 Argument REVERSE means reverse order."
10855   (interactive "P")
10856   (gnus-summary-sort 'author reverse))
10857
10858 (defun gnus-summary-sort-by-subject (&optional reverse)
10859   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10860 If `case-fold-search' is non-nil, case of letters is ignored.
10861 Argument REVERSE means reverse order."
10862   (interactive "P")
10863   (gnus-summary-sort 'subject reverse))
10864
10865 (defun gnus-summary-sort-by-date (&optional reverse)
10866   "Sort the summary buffer by date.
10867 Argument REVERSE means reverse order."
10868   (interactive "P")
10869   (gnus-summary-sort 'date reverse))
10870
10871 (defun gnus-summary-sort-by-score (&optional reverse)
10872   "Sort the summary buffer by score.
10873 Argument REVERSE means reverse order."
10874   (interactive "P")
10875   (gnus-summary-sort 'score reverse))
10876
10877 (defun gnus-summary-sort-by-lines (&optional reverse)
10878   "Sort the summary buffer by the number of lines.
10879 Argument REVERSE means reverse order."
10880   (interactive "P")
10881   (gnus-summary-sort 'lines reverse))
10882
10883 (defun gnus-summary-sort-by-chars (&optional reverse)
10884   "Sort the summary buffer by article length.
10885 Argument REVERSE means reverse order."
10886   (interactive "P")
10887   (gnus-summary-sort 'chars reverse))
10888
10889 (defun gnus-summary-sort-by-original (&optional reverse)
10890   "Sort the summary buffer using the default sorting method.
10891 Argument REVERSE means reverse order."
10892   (interactive "P")
10893   (let* ((buffer-read-only)
10894          (gnus-summary-prepare-hook nil))
10895     ;; We do the sorting by regenerating the threads.
10896     (gnus-summary-prepare)
10897     ;; Hide subthreads if needed.
10898     (gnus-summary-maybe-hide-threads)))
10899
10900 (defun gnus-summary-sort (predicate reverse)
10901   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10902   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10903          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10904          (gnus-thread-sort-functions
10905           (if (not reverse)
10906               thread
10907             `(lambda (t1 t2)
10908                (,thread t2 t1))))
10909          (gnus-sort-gathered-threads-function
10910           gnus-thread-sort-functions)
10911          (gnus-article-sort-functions
10912           (if (not reverse)
10913               article
10914             `(lambda (t1 t2)
10915                (,article t2 t1))))
10916          (buffer-read-only)
10917          (gnus-summary-prepare-hook nil))
10918     ;; We do the sorting by regenerating the threads.
10919     (gnus-summary-prepare)
10920     ;; Hide subthreads if needed.
10921     (gnus-summary-maybe-hide-threads)))
10922
10923 ;; Summary saving commands.
10924
10925 (defun gnus-summary-save-article (&optional n not-saved)
10926   "Save the current article using the default saver function.
10927 If N is a positive number, save the N next articles.
10928 If N is a negative number, save the N previous articles.
10929 If N is nil and any articles have been marked with the process mark,
10930 save those articles instead.
10931 The variable `gnus-default-article-saver' specifies the saver function."
10932   (interactive "P")
10933   (let* ((articles (gnus-summary-work-articles n))
10934          (save-buffer (save-excursion
10935                         (nnheader-set-temp-buffer " *Gnus Save*")))
10936          (num (length articles))
10937          header file)
10938     (dolist (article articles)
10939       (setq header (gnus-summary-article-header article))
10940       (if (not (vectorp header))
10941           ;; This is a pseudo-article.
10942           (if (assq 'name header)
10943               (gnus-copy-file (cdr (assq 'name header)))
10944             (gnus-message 1 "Article %d is unsaveable" article))
10945         ;; This is a real article.
10946         (save-window-excursion
10947           (let ((gnus-display-mime-function nil)
10948                 (gnus-article-prepare-hook nil))
10949             (gnus-summary-select-article t nil nil article)))
10950         (save-excursion
10951           (set-buffer save-buffer)
10952           (erase-buffer)
10953           (insert-buffer-substring gnus-original-article-buffer))
10954         (setq file (gnus-article-save save-buffer file num))
10955         (gnus-summary-remove-process-mark article)
10956         (unless not-saved
10957           (gnus-summary-set-saved-mark article))))
10958     (gnus-kill-buffer save-buffer)
10959     (gnus-summary-position-point)
10960     (gnus-set-mode-line 'summary)
10961     n))
10962
10963 (defun gnus-summary-pipe-output (&optional arg headers)
10964   "Pipe the current article to a subprocess.
10965 If N is a positive number, pipe the N next articles.
10966 If N is a negative number, pipe the N previous articles.
10967 If N is nil and any articles have been marked with the process mark,
10968 pipe those articles instead.
10969 If HEADERS (the symbolic prefix), include the headers, too."
10970   (interactive (gnus-interactive "P\ny"))
10971   (require 'gnus-art)
10972   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10973         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10974     (gnus-summary-save-article arg t))
10975   (let ((buffer (get-buffer "*Shell Command Output*")))
10976     (when (and buffer
10977                (not (zerop (buffer-size buffer))))
10978       (gnus-configure-windows 'pipe))))
10979
10980 (defun gnus-summary-save-article-mail (&optional arg)
10981   "Append the current article to an mail file.
10982 If N is a positive number, save the N next articles.
10983 If N is a negative number, save the N previous articles.
10984 If N is nil and any articles have been marked with the process mark,
10985 save those articles instead."
10986   (interactive "P")
10987   (require 'gnus-art)
10988   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10989     (gnus-summary-save-article arg)))
10990
10991 (defun gnus-summary-save-article-rmail (&optional arg)
10992   "Append the current article to an rmail file.
10993 If N is a positive number, save the N next articles.
10994 If N is a negative number, save the N previous articles.
10995 If N is nil and any articles have been marked with the process mark,
10996 save those articles instead."
10997   (interactive "P")
10998   (require 'gnus-art)
10999   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11000     (gnus-summary-save-article arg)))
11001
11002 (defun gnus-summary-save-article-file (&optional arg)
11003   "Append the current article to a file.
11004 If N is a positive number, save the N next articles.
11005 If N is a negative number, save the N previous articles.
11006 If N is nil and any articles have been marked with the process mark,
11007 save those articles instead."
11008   (interactive "P")
11009   (require 'gnus-art)
11010   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11011     (gnus-summary-save-article arg)))
11012
11013 (defun gnus-summary-write-article-file (&optional arg)
11014   "Write the current article to a file, deleting the previous file.
11015 If N is a positive number, save the N next articles.
11016 If N is a negative number, save the N previous articles.
11017 If N is nil and any articles have been marked with the process mark,
11018 save those articles instead."
11019   (interactive "P")
11020   (require 'gnus-art)
11021   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11022     (gnus-summary-save-article arg)))
11023
11024 (defun gnus-summary-save-article-body-file (&optional arg)
11025   "Append the current article body to a file.
11026 If N is a positive number, save the N next articles.
11027 If N is a negative number, save the N previous articles.
11028 If N is nil and any articles have been marked with the process mark,
11029 save those articles instead."
11030   (interactive "P")
11031   (require 'gnus-art)
11032   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11033     (gnus-summary-save-article arg)))
11034
11035 (defun gnus-summary-muttprint (&optional arg)
11036   "Print the current article using Muttprint.
11037 If N is a positive number, save the N next articles.
11038 If N is a negative number, save the N previous articles.
11039 If N is nil and any articles have been marked with the process mark,
11040 save those articles instead."
11041   (interactive "P")
11042   (require 'gnus-art)
11043   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11044     (gnus-summary-save-article arg t)))
11045
11046 (defun gnus-summary-pipe-message (program)
11047   "Pipe the current article through PROGRAM."
11048   (interactive "sProgram: ")
11049   (gnus-summary-select-article)
11050   (let ((mail-header-separator ""))
11051     (gnus-eval-in-buffer-window gnus-article-buffer
11052       (save-restriction
11053         (widen)
11054         (let ((start (window-start))
11055               buffer-read-only)
11056           (message-pipe-buffer-body program)
11057           (set-window-start (get-buffer-window (current-buffer)) start))))))
11058
11059 (defun gnus-get-split-value (methods)
11060   "Return a value based on the split METHODS."
11061   (let (split-name method result match)
11062     (when methods
11063       (save-excursion
11064         (set-buffer gnus-original-article-buffer)
11065         (save-restriction
11066           (nnheader-narrow-to-headers)
11067           (while (and methods (not split-name))
11068             (goto-char (point-min))
11069             (setq method (pop methods))
11070             (setq match (car method))
11071             (when (cond
11072                    ((stringp match)
11073                     ;; Regular expression.
11074                     (ignore-errors
11075                       (re-search-forward match nil t)))
11076                    ((functionp match)
11077                     ;; Function.
11078                     (save-restriction
11079                       (widen)
11080                       (setq result (funcall match gnus-newsgroup-name))))
11081                    ((consp match)
11082                     ;; Form.
11083                     (save-restriction
11084                       (widen)
11085                       (setq result (eval match)))))
11086               (setq split-name (cdr method))
11087               (cond ((stringp result)
11088                      (push (expand-file-name
11089                             result gnus-article-save-directory)
11090                            split-name))
11091                     ((consp result)
11092                      (setq split-name (append result split-name)))))))))
11093     (nreverse split-name)))
11094
11095 (defun gnus-valid-move-group-p (group)
11096   (and (boundp group)
11097        (symbol-name group)
11098        (symbol-value group)
11099        (gnus-get-function (gnus-find-method-for-group
11100                            (symbol-name group)) 'request-accept-article t)))
11101
11102 (defun gnus-read-move-group-name (prompt default articles prefix)
11103   "Read a group name."
11104   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11105          (minibuffer-confirm-incomplete nil) ; XEmacs
11106          (prom
11107           (format "%s %s to:"
11108                   prompt
11109                   (if (> (length articles) 1)
11110                       (format "these %d articles" (length articles))
11111                     "this article")))
11112          (to-newsgroup
11113           (cond
11114            ((null split-name)
11115             (gnus-completing-read-with-default
11116              default prom
11117              gnus-active-hashtb
11118              'gnus-valid-move-group-p
11119              nil prefix
11120              'gnus-group-history))
11121            ((= 1 (length split-name))
11122             (gnus-completing-read-with-default
11123              (car split-name) prom
11124              gnus-active-hashtb
11125              'gnus-valid-move-group-p
11126              nil nil
11127              'gnus-group-history))
11128            (t
11129             (gnus-completing-read-with-default
11130              nil prom
11131              (mapcar 'list (nreverse split-name))
11132              nil nil nil
11133              'gnus-group-history))))
11134          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11135     (when to-newsgroup
11136       (if (or (string= to-newsgroup "")
11137               (string= to-newsgroup prefix))
11138           (setq to-newsgroup default))
11139       (unless to-newsgroup
11140         (error "No group name entered"))
11141       (or (gnus-active to-newsgroup)
11142           (gnus-activate-group to-newsgroup nil nil to-method)
11143           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11144                                      to-newsgroup))
11145               (or (and (gnus-request-create-group to-newsgroup to-method)
11146                        (gnus-activate-group
11147                         to-newsgroup nil nil to-method)
11148                        (gnus-subscribe-group to-newsgroup))
11149                   (error "Couldn't create group %s" to-newsgroup)))
11150           (error "No such group: %s" to-newsgroup)))
11151     to-newsgroup))
11152
11153 (defun gnus-summary-save-parts (type dir n &optional reverse)
11154   "Save parts matching TYPE to DIR.
11155 If REVERSE, save parts that do not match TYPE."
11156   (interactive
11157    (list (read-string "Save parts of type: "
11158                       (or (car gnus-summary-save-parts-type-history)
11159                           gnus-summary-save-parts-default-mime)
11160                       'gnus-summary-save-parts-type-history)
11161          (setq gnus-summary-save-parts-last-directory
11162                (read-file-name "Save to directory: "
11163                                gnus-summary-save-parts-last-directory
11164                                nil t))
11165          current-prefix-arg))
11166   (gnus-summary-iterate n
11167     (let ((gnus-display-mime-function nil)
11168           (gnus-inhibit-treatment t))
11169       (gnus-summary-select-article))
11170     (save-excursion
11171       (set-buffer gnus-article-buffer)
11172       (let ((handles (or gnus-article-mime-handles
11173                          (mm-dissect-buffer nil gnus-article-loose-mime)
11174                          (and gnus-article-emulate-mime
11175                               (mm-uu-dissect)))))
11176         (when handles
11177           (gnus-summary-save-parts-1 type dir handles reverse)
11178           (unless gnus-article-mime-handles ;; Don't destroy this case.
11179             (mm-destroy-parts handles)))))))
11180
11181 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11182   (if (stringp (car handle))
11183       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11184               (cdr handle))
11185     (when (if reverse
11186               (not (string-match type (mm-handle-media-type handle)))
11187             (string-match type (mm-handle-media-type handle)))
11188       (let ((file (expand-file-name
11189                    (gnus-map-function
11190                     mm-file-name-rewrite-functions
11191                     (file-name-nondirectory
11192                      (or
11193                       (mail-content-type-get
11194                        (mm-handle-disposition handle) 'filename)
11195                       (mail-content-type-get
11196                        (mm-handle-type handle) 'name)
11197                       (concat gnus-newsgroup-name
11198                               "." (number-to-string
11199                                    (cdr gnus-article-current))))))
11200                    dir)))
11201         (unless (file-exists-p file)
11202           (mm-save-part-to-file handle file))))))
11203
11204 ;; Summary extract commands
11205
11206 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11207   (let ((buffer-read-only nil)
11208         (article (gnus-summary-article-number))
11209         after-article b e)
11210     (unless (gnus-summary-goto-subject article)
11211       (error "No such article: %d" article))
11212     (gnus-summary-position-point)
11213     ;; If all commands are to be bunched up on one line, we collect
11214     ;; them here.
11215     (unless gnus-view-pseudos-separately
11216       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11217             files action)
11218         (while ps
11219           (setq action (cdr (assq 'action (car ps))))
11220           (setq files (list (cdr (assq 'name (car ps)))))
11221           (while (and ps (cdr ps)
11222                       (string= (or action "1")
11223                                (or (cdr (assq 'action (cadr ps))) "2")))
11224             (push (cdr (assq 'name (cadr ps))) files)
11225             (setcdr ps (cddr ps)))
11226           (when files
11227             (when (not (string-match "%s" action))
11228               (push " " files))
11229             (push " " files)
11230             (when (assq 'execute (car ps))
11231               (setcdr (assq 'execute (car ps))
11232                       (funcall (if (string-match "%s" action)
11233                                    'format 'concat)
11234                                action
11235                                (mapconcat
11236                                 (lambda (f)
11237                                   (if (equal f " ")
11238                                       f
11239                                     (shell-quote-argument f)))
11240                                 files " ")))))
11241           (setq ps (cdr ps)))))
11242     (if (and gnus-view-pseudos (not not-view))
11243         (while pslist
11244           (when (assq 'execute (car pslist))
11245             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11246                                   (eq gnus-view-pseudos 'not-confirm)))
11247           (setq pslist (cdr pslist)))
11248       (save-excursion
11249         (while pslist
11250           (setq after-article (or (cdr (assq 'article (car pslist)))
11251                                   (gnus-summary-article-number)))
11252           (gnus-summary-goto-subject after-article)
11253           (forward-line 1)
11254           (setq b (point))
11255           (insert "    " (file-name-nondirectory
11256                           (cdr (assq 'name (car pslist))))
11257                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11258           (setq e (point))
11259           (forward-line -1)             ; back to `b'
11260           (gnus-add-text-properties
11261            b (1- e) (list 'gnus-number gnus-reffed-article-number
11262                           gnus-mouse-face-prop gnus-mouse-face))
11263           (gnus-data-enter
11264            after-article gnus-reffed-article-number
11265            gnus-unread-mark b (car pslist) 0 (- e b))
11266           (setq gnus-newsgroup-unreads
11267                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11268                                          gnus-reffed-article-number))
11269           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11270           (setq pslist (cdr pslist)))))))
11271
11272 (defun gnus-pseudos< (p1 p2)
11273   (let ((c1 (cdr (assq 'action p1)))
11274         (c2 (cdr (assq 'action p2))))
11275     (and c1 c2 (string< c1 c2))))
11276
11277 (defun gnus-request-pseudo-article (props)
11278   (cond ((assq 'execute props)
11279          (gnus-execute-command (cdr (assq 'execute props)))))
11280   (let ((gnus-current-article (gnus-summary-article-number)))
11281     (gnus-run-hooks 'gnus-mark-article-hook)))
11282
11283 (defun gnus-execute-command (command &optional automatic)
11284   (save-excursion
11285     (gnus-article-setup-buffer)
11286     (set-buffer gnus-article-buffer)
11287     (setq buffer-read-only nil)
11288     (let ((command (if automatic command
11289                      (read-string "Command: " (cons command 0)))))
11290       (erase-buffer)
11291       (insert "$ " command "\n\n")
11292       (if gnus-view-pseudo-asynchronously
11293           (start-process "gnus-execute" (current-buffer) shell-file-name
11294                          shell-command-switch command)
11295         (call-process shell-file-name nil t nil
11296                       shell-command-switch command)))))
11297
11298 ;; Summary kill commands.
11299
11300 (defun gnus-summary-edit-global-kill (article)
11301   "Edit the \"global\" kill file."
11302   (interactive (list (gnus-summary-article-number)))
11303   (gnus-group-edit-global-kill article))
11304
11305 (defun gnus-summary-edit-local-kill ()
11306   "Edit a local kill file applied to the current newsgroup."
11307   (interactive)
11308   (setq gnus-current-headers (gnus-summary-article-header))
11309   (gnus-group-edit-local-kill
11310    (gnus-summary-article-number) gnus-newsgroup-name))
11311
11312 ;;; Header reading.
11313
11314 (defun gnus-read-header (id &optional header)
11315   "Read the headers of article ID and enter them into the Gnus system."
11316   (let ((group gnus-newsgroup-name)
11317         (gnus-override-method
11318          (or
11319           gnus-override-method
11320           (and (gnus-news-group-p gnus-newsgroup-name)
11321                (car (gnus-refer-article-methods)))))
11322         where)
11323     ;; First we check to see whether the header in question is already
11324     ;; fetched.
11325     (if (stringp id)
11326         ;; This is a Message-ID.
11327         (setq header (or header (gnus-id-to-header id)))
11328       ;; This is an article number.
11329       (setq header (or header (gnus-summary-article-header id))))
11330     (if (and header
11331              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11332         ;; We have found the header.
11333         header
11334       ;; We have to really fetch the header to this article.
11335       (save-excursion
11336         (set-buffer nntp-server-buffer)
11337         (when (setq where (gnus-request-head id group))
11338           (nnheader-fold-continuation-lines)
11339           (goto-char (point-max))
11340           (insert ".\n")
11341           (goto-char (point-min))
11342           (insert "211 ")
11343           (princ (cond
11344                   ((numberp id) id)
11345                   ((cdr where) (cdr where))
11346                   (header (mail-header-number header))
11347                   (t gnus-reffed-article-number))
11348                  (current-buffer))
11349           (insert " Article retrieved.\n"))
11350         (if (or (not where)
11351                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11352             ()                          ; Malformed head.
11353           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11354             (when (and (stringp id)
11355                        (not (string= (gnus-group-real-name group)
11356                                      (car where))))
11357               ;; If we fetched by Message-ID and the article came
11358               ;; from a different group, we fudge some bogus article
11359               ;; numbers for this article.
11360               (mail-header-set-number header gnus-reffed-article-number))
11361             (save-excursion
11362               (set-buffer gnus-summary-buffer)
11363               (decf gnus-reffed-article-number)
11364               (gnus-remove-header (mail-header-number header))
11365               (push header gnus-newsgroup-headers)
11366               (setq gnus-current-headers header)
11367               (push (mail-header-number header) gnus-newsgroup-limit)))
11368           header)))))
11369
11370 (defun gnus-remove-header (number)
11371   "Remove header NUMBER from `gnus-newsgroup-headers'."
11372   (if (and gnus-newsgroup-headers
11373            (= number (mail-header-number (car gnus-newsgroup-headers))))
11374       (pop gnus-newsgroup-headers)
11375     (let ((headers gnus-newsgroup-headers))
11376       (while (and (cdr headers)
11377                   (not (= number (mail-header-number (cadr headers)))))
11378         (pop headers))
11379       (when (cdr headers)
11380         (setcdr headers (cddr headers))))))
11381
11382 ;;;
11383 ;;; summary highlights
11384 ;;;
11385
11386 (defun gnus-highlight-selected-summary ()
11387   "Highlight selected article in summary buffer."
11388   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11389   (when gnus-summary-selected-face
11390     (save-excursion
11391       (let* ((beg (point-at-bol))
11392              (end (point-at-eol))
11393              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11394              (from (if (get-text-property beg gnus-mouse-face-prop)
11395                        beg
11396                      (or (next-single-property-change
11397                           beg gnus-mouse-face-prop nil end)
11398                          beg)))
11399              (to
11400               (if (= from end)
11401                   (- from 2)
11402                 (or (next-single-property-change
11403                      from gnus-mouse-face-prop nil end)
11404                     end))))
11405         ;; If no mouse-face prop on line we will have to = from = end,
11406         ;; so we highlight the entire line instead.
11407         (when (= (+ to 2) from)
11408           (setq from beg)
11409           (setq to end))
11410         (if gnus-newsgroup-selected-overlay
11411             ;; Move old overlay.
11412             (gnus-move-overlay
11413              gnus-newsgroup-selected-overlay from to (current-buffer))
11414           ;; Create new overlay.
11415           (gnus-overlay-put
11416            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11417            'face gnus-summary-selected-face))))))
11418
11419 (defvar gnus-summary-highlight-line-cached nil)
11420 (defvar gnus-summary-highlight-line-trigger nil)
11421
11422 (defun gnus-summary-highlight-line-0 ()
11423   (if (and (eq gnus-summary-highlight-line-trigger
11424                gnus-summary-highlight)
11425            gnus-summary-highlight-line-cached)
11426       gnus-summary-highlight-line-cached
11427     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11428           gnus-summary-highlight-line-cached
11429           (let* ((cond (list 'cond))
11430                  (c cond)
11431                  (list gnus-summary-highlight))
11432             (while list
11433               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11434                               nil))
11435               (setq c (cdr c)
11436                     list (cdr list)))
11437             (gnus-byte-compile (list 'lambda nil cond))))))
11438
11439 (defun gnus-summary-highlight-line ()
11440   "Highlight current line according to `gnus-summary-highlight'."
11441   (let* ((beg (point-at-bol))
11442          (article (or (gnus-summary-article-number) gnus-current-article))
11443          (score (or (cdr (assq article
11444                                gnus-newsgroup-scored))
11445                     gnus-summary-default-score 0))
11446          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11447          (inhibit-read-only t)
11448          (default gnus-summary-default-score)
11449          (default-high gnus-summary-default-high-score)
11450          (default-low gnus-summary-default-low-score)
11451          (uncached (and gnus-summary-use-undownloaded-faces
11452                         (memq article gnus-newsgroup-undownloaded)
11453                         (not (memq article gnus-newsgroup-cached)))))
11454     (let ((face (funcall (gnus-summary-highlight-line-0))))
11455       (unless (eq face (get-text-property beg 'face))
11456         (gnus-put-text-property-excluding-characters-with-faces
11457          beg (point-at-eol) 'face
11458          (setq face (if (boundp face) (symbol-value face) face)))
11459         (when gnus-summary-highlight-line-function
11460           (funcall gnus-summary-highlight-line-function article face))))))
11461
11462 (defun gnus-update-read-articles (group unread &optional compute)
11463   "Update the list of read articles in GROUP.
11464 UNREAD is a sorted list."
11465   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11466         (info (gnus-get-info group))
11467         (prev 1)
11468         read)
11469     (if (or (not info) (not active))
11470         ;; There is no info on this group if it was, in fact,
11471         ;; killed.  Gnus stores no information on killed groups, so
11472         ;; there's nothing to be done.
11473         ;; One could store the information somewhere temporarily,
11474         ;; perhaps...  Hmmm...
11475         ()
11476       ;; Remove any negative articles numbers.
11477       (while (and unread (< (car unread) 0))
11478         (setq unread (cdr unread)))
11479       ;; Remove any expired article numbers
11480       (while (and unread (< (car unread) (car active)))
11481         (setq unread (cdr unread)))
11482       ;; Compute the ranges of read articles by looking at the list of
11483       ;; unread articles.
11484       (while unread
11485         (when (/= (car unread) prev)
11486           (push (if (= prev (1- (car unread))) prev
11487                   (cons prev (1- (car unread))))
11488                 read))
11489         (setq prev (1+ (car unread)))
11490         (setq unread (cdr unread)))
11491       (when (<= prev (cdr active))
11492         (push (cons prev (cdr active)) read))
11493       (setq read (if (> (length read) 1) (nreverse read) read))
11494       (if compute
11495           read
11496         (save-excursion
11497           (let (setmarkundo)
11498             ;; Propagate the read marks to the backend.
11499             (when (gnus-check-backend-function 'request-set-mark group)
11500               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11501                     (add (gnus-remove-from-range read (gnus-info-read info))))
11502                 (when (or add del)
11503                   (unless (gnus-check-group group)
11504                     (error "Can't open server for %s" group))
11505                   (gnus-request-set-mark
11506                    group (delq nil (list (if add (list add 'add '(read)))
11507                                          (if del (list del 'del '(read))))))
11508                   (setq setmarkundo
11509                         `(gnus-request-set-mark
11510                           ,group
11511                           ',(delq nil (list
11512                                        (if del (list del 'add '(read)))
11513                                        (if add (list add 'del '(read))))))))))
11514             (set-buffer gnus-group-buffer)
11515             (gnus-undo-register
11516               `(progn
11517                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11518                  (gnus-info-set-read ',info ',(gnus-info-read info))
11519                  (gnus-get-unread-articles-in-group ',info
11520                                                     (gnus-active ,group))
11521                  (gnus-group-update-group ,group t)
11522                  ,setmarkundo))))
11523         ;; Enter this list into the group info.
11524         (gnus-info-set-read info read)
11525         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11526         (gnus-get-unread-articles-in-group info (gnus-active group))
11527         t))))
11528
11529 (defun gnus-offer-save-summaries ()
11530   "Offer to save all active summary buffers."
11531   (let (buffers)
11532     ;; Go through all buffers and find all summaries.
11533     (dolist (buffer (buffer-list))
11534       (when (and (setq buffer (buffer-name buffer))
11535                  (string-match "Summary" buffer)
11536                  (with-current-buffer buffer
11537                    ;; We check that this is, indeed, a summary buffer.
11538                    (and (eq major-mode 'gnus-summary-mode)
11539                         ;; Also make sure this isn't bogus.
11540                         gnus-newsgroup-prepared
11541                         ;; Also make sure that this isn't a
11542                         ;; dead summary buffer.
11543                         (not gnus-dead-summary-mode))))
11544         (push buffer buffers)))
11545     ;; Go through all these summary buffers and offer to save them.
11546     (when buffers
11547       (save-excursion
11548         (map-y-or-n-p
11549          "Update summary buffer %s? "
11550          (lambda (buf)
11551            (switch-to-buffer buf)
11552            (gnus-summary-exit))
11553          buffers)))))
11554
11555
11556 ;;; @ for mime-partial
11557 ;;;
11558
11559 (defun gnus-request-partial-message ()
11560   (save-excursion
11561     (let ((number (gnus-summary-article-number))
11562           (group gnus-newsgroup-name)
11563           (mother gnus-article-buffer))
11564       (set-buffer (get-buffer-create " *Partial Article*"))
11565       (erase-buffer)
11566       (setq mime-preview-buffer mother)
11567       (gnus-request-article-this-buffer number group)
11568       (mime-parse-buffer)
11569       )))
11570
11571 (autoload 'mime-combine-message/partial-pieces-automatically
11572   "mime-partial"
11573   "Internal method to combine message/partial messages automatically.")
11574
11575 (mime-add-condition
11576  'action '((type . message)(subtype . partial)
11577            (major-mode . gnus-original-article-mode)
11578            (method . mime-combine-message/partial-pieces-automatically)
11579            (summary-buffer-exp . gnus-summary-buffer)
11580            (request-partial-message-method . gnus-request-partial-message)
11581            ))
11582
11583
11584 ;;; @ for message/rfc822
11585 ;;;
11586
11587 (defun gnus-mime-extract-message/rfc822 (entity situation)
11588   "Burst a forwarded article."
11589   (save-excursion
11590     (set-buffer gnus-summary-buffer)
11591     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11592                                    gnus-newsgroup-name 'gnus-group-history))
11593            (gnus-group-marked (list group))
11594            article info)
11595       (with-temp-buffer
11596         (mime-insert-entity-content entity)
11597         (setq article (gnus-request-accept-article group)))
11598       (when (and (consp article)
11599                  (numberp (setq article (cdr article))))
11600         (setq info (gnus-get-info group))
11601         (gnus-info-set-read info
11602                             (gnus-remove-from-range (gnus-info-read info)
11603                                                     (list article)))
11604         (when (string-equal group gnus-newsgroup-name)
11605           (forward-line 1)
11606           (let (gnus-show-threads)
11607             (gnus-summary-goto-subject article t))
11608           (gnus-summary-clear-mark-forward 1))
11609         (set-buffer gnus-group-buffer)
11610         (gnus-group-get-new-news-this-group nil t)))))
11611
11612 (mime-add-condition
11613  'action '((type . message)(subtype . rfc822)
11614            (major-mode . gnus-original-article-mode)
11615            (method . gnus-mime-extract-message/rfc822)
11616            (mode . "extract")
11617            ))
11618
11619 (mime-add-condition
11620  'action '((type . message)(subtype . news)
11621            (major-mode . gnus-original-article-mode)
11622            (method . gnus-mime-extract-message/rfc822)
11623            (mode . "extract")
11624            ))
11625
11626 (defun gnus-mime-extract-multipart (entity situation)
11627   (let ((children (mime-entity-children entity))
11628         mime-acting-situation-to-override
11629         f)
11630     (while children
11631       (mime-play-entity (car children)
11632                         (cons (assq 'mode situation)
11633                               mime-acting-situation-to-override))
11634       (setq children (cdr children)))
11635     (if (setq f (cdr (assq 'after-method
11636                            mime-acting-situation-to-override)))
11637         (eval f)
11638       )))
11639
11640 (mime-add-condition
11641  'action '((type . multipart)
11642            (method . gnus-mime-extract-multipart)
11643            (mode . "extract")
11644            )
11645  'with-default)
11646
11647
11648 ;;; @ end
11649 ;;;
11650
11651 (defun gnus-summary-inherit-default-charset ()
11652   "Import `default-mime-charset' from summary buffer.
11653 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11654 of FLIM is used."
11655   (if (buffer-live-p gnus-summary-buffer)
11656       (let (d-m-c d-m-c-u)
11657         (with-current-buffer gnus-summary-buffer
11658           (setq d-m-c (if (local-variable-p 'default-mime-charset
11659                                             gnus-summary-buffer)
11660                           default-mime-charset
11661                         t)
11662                 ;; LIMIT
11663                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11664                                               gnus-summary-buffer)
11665                             (symbol-value 'default-mime-charset-unlimited)
11666                           t)))
11667         (if (eq t d-m-c)
11668             (kill-local-variable 'default-mime-charset)
11669           (set (make-local-variable 'default-mime-charset) d-m-c))
11670         (if (eq t d-m-c-u)
11671             (kill-local-variable 'default-mime-charset-unlimited)
11672           (set (make-local-variable 'default-mime-charset-unlimited)
11673                d-m-c-u)))))
11674
11675 (defun gnus-summary-setup-default-charset ()
11676   "Setup newsgroup default charset."
11677   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11678       (progn
11679         (setq gnus-newsgroup-charset nil)
11680         (set (make-local-variable 'default-mime-charset) nil)
11681         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11682           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11683     (let ((ignored-charsets
11684            (or gnus-newsgroup-ephemeral-ignored-charsets
11685                (append
11686                 (and gnus-newsgroup-name
11687                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11688                 gnus-newsgroup-ignored-charsets)))
11689           charset)
11690       (setq gnus-newsgroup-charset
11691             (or gnus-newsgroup-ephemeral-charset
11692                 (when (and gnus-newsgroup-name
11693                            (setq charset (gnus-parameter-charset
11694                                           gnus-newsgroup-name)))
11695                   (make-local-variable 'default-mime-charset)
11696                   (setq default-mime-charset charset))
11697                 gnus-default-charset))
11698       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11699            ignored-charsets))))
11700
11701 ;;;
11702 ;;; Mime Commands
11703 ;;;
11704
11705 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11706   "Display the current article buffer fully MIME-buttonized.
11707 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11708 treated as multipart/mixed."
11709   (interactive "P")
11710   (require 'gnus-art)
11711   (let ((gnus-unbuttonized-mime-types nil)
11712         (gnus-mime-display-multipart-as-mixed show-all-parts))
11713     (gnus-summary-show-article)))
11714
11715 (defun gnus-summary-repair-multipart (article)
11716   "Add a Content-Type header to a multipart article without one."
11717   (interactive (list (gnus-summary-article-number)))
11718   (gnus-with-article article
11719     (message-narrow-to-head)
11720     (message-remove-header "Mime-Version")
11721     (goto-char (point-max))
11722     (insert "Mime-Version: 1.0\n")
11723     (widen)
11724     (when (search-forward "\n--" nil t)
11725       (let ((separator (buffer-substring (point) (point-at-eol))))
11726         (message-narrow-to-head)
11727         (message-remove-header "Content-Type")
11728         (goto-char (point-max))
11729         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11730                         separator))
11731         (widen))))
11732   (let (gnus-mark-article-hook)
11733     (gnus-summary-select-article t t nil article)))
11734
11735 (defun gnus-summary-toggle-display-buttonized ()
11736   "Toggle the buttonizing of the article buffer."
11737   (interactive)
11738   (require 'gnus-art)
11739   (if (setq gnus-inhibit-mime-unbuttonizing
11740             (not gnus-inhibit-mime-unbuttonizing))
11741       (let ((gnus-unbuttonized-mime-types nil))
11742         (gnus-summary-show-article))
11743     (gnus-summary-show-article)))
11744
11745 ;;;
11746 ;;; Intelli-mouse commmands
11747 ;;;
11748
11749 (defun gnus-wheel-summary-scroll (event)
11750   (interactive "e")
11751   (let ((amount (if (memq 'shift (event-modifiers event))
11752                     (car gnus-wheel-scroll-amount)
11753                   (cdr gnus-wheel-scroll-amount)))
11754         (direction (- (* (static-if (featurep 'xemacs)
11755                              (event-button event)
11756                            (cond ((eq 'mouse-4 (event-basic-type event))
11757                                   4)
11758                                  ((eq 'mouse-5 (event-basic-type event))
11759                                   5)))
11760                          2) 9))
11761         edge)
11762     (gnus-summary-scroll-up (* amount direction))
11763     (when (gnus-eval-in-buffer-window gnus-article-buffer
11764             (save-restriction
11765               (widen)
11766               (and (if (< 0 direction)
11767                        (gnus-article-next-page 0)
11768                      (gnus-article-prev-page 0)
11769                      (bobp))
11770                    (if (setq edge (get-text-property
11771                                    (point-min) 'gnus-wheel-edge))
11772                        (setq edge (* edge direction))
11773                      (setq edge -1))
11774                    (or (plusp edge)
11775                        (let ((buffer-read-only nil)
11776                              (inhibit-read-only t))
11777                          (put-text-property (point-min) (point-max)
11778                                             'gnus-wheel-edge direction)
11779                          nil))
11780                    (or (> edge gnus-wheel-edge-resistance)
11781                        (let ((buffer-read-only nil)
11782                              (inhibit-read-only t))
11783                          (put-text-property (point-min) (point-max)
11784                                             'gnus-wheel-edge
11785                                             (* (1+ edge) direction))
11786                          nil))
11787                    (eq last-command 'gnus-wheel-summary-scroll))))
11788       (gnus-summary-next-article nil nil (minusp direction)))))
11789
11790 (defun gnus-wheel-install ()
11791   "Enable mouse wheel support on summary window."
11792   (when gnus-use-wheel
11793     (let ((keys
11794            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11795       (dolist (key keys)
11796         (define-key gnus-summary-mode-map key
11797           'gnus-wheel-summary-scroll)))))
11798
11799 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11800
11801 ;;;
11802 ;;; Traditional PGP commmands
11803 ;;;
11804
11805 (defun gnus-summary-decrypt-article (&optional force)
11806   "Decrypt the current article in traditional PGP way.
11807 This will have permanent effect only in mail groups.
11808 If FORCE is non-nil, allow editing of articles even in read-only
11809 groups."
11810   (interactive "P")
11811   (gnus-summary-select-article t)
11812   (gnus-eval-in-buffer-window gnus-article-buffer
11813     (save-excursion
11814       (save-restriction
11815         (widen)
11816         (goto-char (point-min))
11817         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11818           (error "Not a traditional PGP message!"))
11819         (let ((armor-start (match-beginning 0)))
11820           (if (and (pgg-decrypt-region armor-start (point-max))
11821                    (or force (not (gnus-group-read-only-p))))
11822               (let ((inhibit-read-only t)
11823                     buffer-read-only)
11824                 (delete-region armor-start
11825                                (progn
11826                                  (re-search-forward "^-+END PGP" nil t)
11827                                  (beginning-of-line 2)
11828                                  (point)))
11829                 (insert-buffer-substring pgg-output-buffer))))))))
11830
11831 (defun gnus-summary-verify-article ()
11832   "Verify the current article in traditional PGP way."
11833   (interactive)
11834   (save-excursion
11835     (set-buffer gnus-original-article-buffer)
11836     (goto-char (point-min))
11837     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11838       (error "Not a traditional PGP message!"))
11839     (re-search-forward "^-+END PGP" nil t)
11840     (beginning-of-line 2)
11841     (call-interactively (function pgg-verify-region))))
11842
11843 ;;;
11844 ;;; Generic summary marking commands
11845 ;;;
11846
11847 (defvar gnus-summary-marking-alist
11848   '((read gnus-del-mark "d")
11849     (unread gnus-unread-mark "u")
11850     (ticked gnus-ticked-mark "!")
11851     (dormant gnus-dormant-mark "?")
11852     (expirable gnus-expirable-mark "e"))
11853   "An alist of names/marks/keystrokes.")
11854
11855 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11856 (defvar gnus-summary-mark-map)
11857
11858 (defun gnus-summary-make-all-marking-commands ()
11859   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11860   (dolist (elem gnus-summary-marking-alist)
11861     (apply 'gnus-summary-make-marking-command elem)))
11862
11863 (defun gnus-summary-make-marking-command (name mark keystroke)
11864   (let ((map (make-sparse-keymap)))
11865     (define-key gnus-summary-generic-mark-map keystroke map)
11866     (dolist (lway `((next "next" next nil "n")
11867                     (next-unread "next unread" next t "N")
11868                     (prev "previous" prev nil "p")
11869                     (prev-unread "previous unread" prev t "P")
11870                     (nomove "" nil nil ,keystroke)))
11871       (let ((func (gnus-summary-make-marking-command-1
11872                    mark (car lway) lway name)))
11873         (setq func (eval func))
11874         (define-key map (nth 4 lway) func)))))
11875
11876 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11877   `(defun ,(intern
11878             (format "gnus-summary-put-mark-as-%s%s"
11879                     name (if (eq way 'nomove)
11880                              ""
11881                            (concat "-" (symbol-name way)))))
11882      (n)
11883      ,(format
11884        "Mark the current article as %s%s.
11885 If N, the prefix, then repeat N times.
11886 If N is negative, move in reverse order.
11887 The difference between N and the actual number of articles marked is
11888 returned."
11889        name (car (cdr lway)))
11890      (interactive "p")
11891      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11892
11893 (defun gnus-summary-generic-mark (n mark move unread)
11894   "Mark N articles with MARK."
11895   (unless (eq major-mode 'gnus-summary-mode)
11896     (error "This command can only be used in the summary buffer"))
11897   (gnus-summary-show-thread)
11898   (let ((nummove
11899          (cond
11900           ((eq move 'next) 1)
11901           ((eq move 'prev) -1)
11902           (t 0))))
11903     (if (zerop nummove)
11904         (setq n 1)
11905       (when (< n 0)
11906         (setq n (abs n)
11907               nummove (* -1 nummove))))
11908     (while (and (> n 0)
11909                 (gnus-summary-mark-article nil mark)
11910                 (zerop (gnus-summary-next-subject nummove unread t)))
11911       (setq n (1- n)))
11912     (when (/= 0 n)
11913       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11914     (gnus-summary-recenter)
11915     (gnus-summary-position-point)
11916     (gnus-set-mode-line 'summary)
11917     n))
11918
11919 (defun gnus-summary-insert-articles (articles)
11920   (when (setq articles
11921               (gnus-sorted-difference articles
11922                                       (mapcar (lambda (h)
11923                                                 (mail-header-number h))
11924                                               gnus-newsgroup-headers)))
11925     (setq gnus-newsgroup-headers
11926           (gnus-merge 'list
11927                       gnus-newsgroup-headers
11928                       (gnus-fetch-headers articles)
11929                       'gnus-article-sort-by-number))
11930     ;; Suppress duplicates?
11931     (when gnus-suppress-duplicates
11932       (gnus-dup-suppress-articles))
11933
11934     ;; We might want to build some more threads first.
11935     (when (and gnus-fetch-old-headers
11936                (eq gnus-headers-retrieved-by 'nov))
11937       (if (eq gnus-fetch-old-headers 'invisible)
11938           (gnus-build-all-threads)
11939         (gnus-build-old-threads)))
11940     ;; Let the Gnus agent mark articles as read.
11941     (when gnus-agent
11942       (gnus-agent-get-undownloaded-list))
11943     ;; Remove list identifiers from subject
11944     (when gnus-list-identifiers
11945       (gnus-summary-remove-list-identifiers))
11946     ;; First and last article in this newsgroup.
11947     (when gnus-newsgroup-headers
11948       (setq gnus-newsgroup-begin
11949             (mail-header-number (car gnus-newsgroup-headers))
11950             gnus-newsgroup-end
11951             (mail-header-number
11952              (gnus-last-element gnus-newsgroup-headers))))
11953     (when gnus-use-scoring
11954       (gnus-possibly-score-headers))))
11955
11956 (defun gnus-summary-insert-old-articles (&optional all)
11957   "Insert all old articles in this group.
11958 If ALL is non-nil, already read articles become readable.
11959 If ALL is a number, fetch this number of articles."
11960   (interactive "P")
11961   (prog1
11962       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11963             older len)
11964         (setq older
11965               ;; Some nntp servers lie about their active range.  When
11966               ;; this happens, the active range can be in the millions.
11967               ;; Use a compressed range to avoid creating a huge list.
11968               (gnus-range-difference (list gnus-newsgroup-active) old))
11969         (setq len (gnus-range-length older))
11970         (cond
11971          ((null older) nil)
11972          ((numberp all)
11973           (if (< all len)
11974               (let ((older-range (nreverse older)))
11975                 (setq older nil)
11976
11977                 (while (> all 0)
11978                   (let* ((r (pop older-range))
11979                          (min (if (numberp r) r (car r)))
11980                          (max (if (numberp r) r (cdr r))))
11981                     (while (and (<= min max)
11982                                 (> all 0))
11983                       (push max older)
11984                       (setq all (1- all)
11985                             max (1- max))))))
11986             (setq older (gnus-uncompress-range older))))
11987          (all
11988           (setq older (gnus-uncompress-range older)))
11989          (t
11990           (when (and (numberp gnus-large-newsgroup)
11991                    (> len gnus-large-newsgroup))
11992               (let* ((cursor-in-echo-area nil)
11993                      (initial (gnus-parameter-large-newsgroup-initial
11994                                gnus-newsgroup-name))
11995                      (input
11996                       (read-string
11997                        (format
11998                         "How many articles from %s (%s %d): "
11999                         (gnus-limit-string
12000                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12001                         (if initial "max" "default")
12002                         len)
12003                        (if initial
12004                            (cons (number-to-string initial)
12005                                  0)))))
12006                 (unless (string-match "^[ \t]*$" input)
12007                   (setq all (string-to-number input))
12008                   (if (< all len)
12009                       (let ((older-range (nreverse older)))
12010                         (setq older nil)
12011
12012                         (while (> all 0)
12013                           (let* ((r (pop older-range))
12014                                  (min (if (numberp r) r (car r)))
12015                                  (max (if (numberp r) r (cdr r))))
12016                             (while (and (<= min max)
12017                                         (> all 0))
12018                               (push max older)
12019                               (setq all (1- all)
12020                                     max (1- max))))))))))
12021           (setq older (gnus-uncompress-range older))))
12022         (if (not older)
12023             (message "No old news.")
12024           (gnus-summary-insert-articles older)
12025           (gnus-summary-limit (gnus-sorted-nunion old older))))
12026     (gnus-summary-position-point)))
12027
12028 (defun gnus-summary-insert-new-articles ()
12029   "Insert all new articles in this group."
12030   (interactive)
12031   (prog1
12032       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12033             (old-active gnus-newsgroup-active)
12034             (nnmail-fetched-sources (list t))
12035             i new)
12036         (setq gnus-newsgroup-active
12037               (gnus-activate-group gnus-newsgroup-name 'scan))
12038         (setq i (cdr gnus-newsgroup-active))
12039         (while (> i (cdr old-active))
12040           (push i new)
12041           (decf i))
12042         (if (not new)
12043             (message "No gnus is bad news")
12044           (gnus-summary-insert-articles new)
12045           (setq gnus-newsgroup-unreads
12046                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12047           (gnus-summary-limit (gnus-sorted-nunion old new))))
12048     (gnus-summary-position-point)))
12049
12050 (gnus-summary-make-all-marking-commands)
12051
12052 (gnus-ems-redefine)
12053
12054 (provide 'gnus-sum)
12055
12056 (run-hooks 'gnus-sum-load-hook)
12057
12058 ;; Local Variables:
12059 ;; coding: iso-8859-1
12060 ;; End:
12061
12062 ;;; gnus-sum.el ends here