Synch to Gnus 200305110209.
[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
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   (require 'gnus-clfns)
34   (defvar tool-bar-map))
35
36 (require 'gnus)
37 (require 'gnus-group)
38 (require 'gnus-spec)
39 (require 'gnus-range)
40 (require 'gnus-int)
41 (require 'gnus-undo)
42 (require 'gnus-util)
43 (require 'nnoo)
44 (require 'mime-view)
45
46 (eval-when-compile
47   (require 'mime-play)
48   (require 'static))
49
50 (eval-and-compile
51   (autoload 'pgg-decrypt-region "pgg" nil t)
52   (autoload 'pgg-verify-region "pgg" nil t))
53
54 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
55 (autoload 'gnus-cache-write-active "gnus-cache")
56 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
57 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
58 (autoload 'mm-uu-dissect "mm-uu")
59 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
60   "Deuglify broken Outlook (Express) articles and redisplay."
61   t)
62 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
63 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
64 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
65
66 (defcustom gnus-kill-summary-on-exit t
67   "*If non-nil, kill the summary buffer when you exit from it.
68 If nil, the summary will become a \"*Dead Summary*\" buffer, and
69 it will be killed sometime later."
70   :group 'gnus-summary-exit
71   :type 'boolean)
72
73 (defcustom gnus-fetch-old-headers nil
74   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
75 If an unread article in the group refers to an older, already read (or
76 just marked as read) article, the old article will not normally be
77 displayed in the Summary buffer.  If this variable is non-nil, Gnus
78 will attempt to grab the headers to the old articles, and thereby
79 build complete threads.  If it has the value `some', only enough
80 headers to connect otherwise loose threads will be displayed.  This
81 variable can also be a number.  In that case, no more than that number
82 of old headers will be fetched.  If it has the value `invisible', all
83 old headers will be fetched, but none will be displayed.
84
85 The server has to support NOV for any of this to work."
86   :group 'gnus-thread
87   :type '(choice (const :tag "off" nil)
88                  (const some)
89                  number
90                  (sexp :menu-tag "other" t)))
91
92 (defcustom gnus-refer-thread-limit 200
93   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
94 If t, fetch all the available old headers."
95   :group 'gnus-thread
96   :type '(choice number
97                  (sexp :menu-tag "other" t)))
98
99 (defcustom gnus-summary-make-false-root 'adopt
100   "*nil means that Gnus won't gather loose threads.
101 If the root of a thread has expired or been read in a previous
102 session, the information necessary to build a complete thread has been
103 lost.  Instead of having many small sub-threads from this original thread
104 scattered all over the summary buffer, Gnus can gather them.
105
106 If non-nil, Gnus will try to gather all loose sub-threads from an
107 original thread into one large thread.
108
109 If this variable is non-nil, it should be one of `none', `adopt',
110 `dummy' or `empty'.
111
112 If this variable is `none', Gnus will not make a false root, but just
113 present the sub-threads after another.
114 If this variable is `dummy', Gnus will create a dummy root that will
115 have all the sub-threads as children.
116 If this variable is `adopt', Gnus will make one of the \"children\"
117 the parent and mark all the step-children as such.
118 If this variable is `empty', the \"children\" are printed with empty
119 subject fields.  (Or rather, they will be printed with a string
120 given by the `gnus-summary-same-subject' variable.)"
121   :group 'gnus-thread
122   :type '(choice (const :tag "off" nil)
123                  (const none)
124                  (const dummy)
125                  (const adopt)
126                  (const empty)))
127
128 (defcustom gnus-summary-make-false-root-always nil
129   "Always make a false dummy root."
130   :group 'gnus-thread
131   :type 'boolean)
132
133 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
134   "*A regexp to match subjects to be excluded from loose thread gathering.
135 As loose thread gathering is done on subjects only, that means that
136 there can be many false gatherings performed.  By rooting out certain
137 common subjects, gathering might become saner."
138   :group 'gnus-thread
139   :type 'regexp)
140
141 (defcustom gnus-summary-gather-subject-limit nil
142   "*Maximum length of subject comparisons when gathering loose threads.
143 Use nil to compare full subjects.  Setting this variable to a low
144 number will help gather threads that have been corrupted by
145 newsreaders chopping off subject lines, but it might also mean that
146 unrelated articles that have subject that happen to begin with the
147 same few characters will be incorrectly gathered.
148
149 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
150 comparing subjects."
151   :group 'gnus-thread
152   :type '(choice (const :tag "off" nil)
153                  (const fuzzy)
154                  (sexp :menu-tag "on" t)))
155
156 (defcustom gnus-simplify-subject-functions nil
157   "List of functions taking a string argument that simplify subjects.
158 The functions are applied recursively.
159
160 Useful functions to put in this list include:
161 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
162 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
163   :group 'gnus-thread
164   :type '(repeat function))
165
166 (defcustom gnus-simplify-ignored-prefixes nil
167   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
168   :group 'gnus-thread
169   :type '(choice (const :tag "off" nil)
170                  regexp))
171
172 (defcustom gnus-build-sparse-threads nil
173   "*If non-nil, fill in the gaps in threads.
174 If `some', only fill in the gaps that are needed to tie loose threads
175 together.  If `more', fill in all leaf nodes that Gnus can find.  If
176 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
177   :group 'gnus-thread
178   :type '(choice (const :tag "off" nil)
179                  (const some)
180                  (const more)
181                  (sexp :menu-tag "all" t)))
182
183 (defcustom gnus-summary-thread-gathering-function
184   'gnus-gather-threads-by-subject
185   "*Function used for gathering loose threads.
186 There are two pre-defined functions: `gnus-gather-threads-by-subject',
187 which only takes Subjects into consideration; and
188 `gnus-gather-threads-by-references', which compared the References
189 headers of the articles to find matches."
190   :group 'gnus-thread
191   :type '(radio (function-item gnus-gather-threads-by-subject)
192                 (function-item gnus-gather-threads-by-references)
193                 (function :tag "other")))
194
195 (defcustom gnus-summary-same-subject ""
196   "*String indicating that the current article has the same subject as the previous.
197 This variable will only be used if the value of
198 `gnus-summary-make-false-root' is `empty'."
199   :group 'gnus-summary-format
200   :type 'string)
201
202 (defcustom gnus-summary-goto-unread t
203   "*If t, many commands will go to the next unread article.
204 This applies to marking commands as well as other commands that
205 \"naturally\" select the next article, like, for instance, `SPC' at
206 the end of an article.
207
208 If nil, the marking commands do NOT go to the next unread article
209 \(they go to the next article instead).  If `never', commands that
210 usually go to the next unread article, will go to the next article,
211 whether it is read or not."
212   :group 'gnus-summary-marks
213   :link '(custom-manual "(gnus)Setting Marks")
214   :type '(choice (const :tag "off" nil)
215                  (const never)
216                  (sexp :menu-tag "on" t)))
217
218 (defcustom gnus-summary-default-score 0
219   "*Default article score level.
220 All scores generated by the score files will be added to this score.
221 If this variable is nil, scoring will be disabled."
222   :group 'gnus-score-default
223   :type '(choice (const :tag "disable")
224                  integer))
225
226 (defcustom gnus-summary-default-high-score 0
227   "*Default threshold for a high scored article.
228 An article will be highlighted as high scored if its score is greater
229 than this score."
230   :group 'gnus-score-default
231   :type 'integer)
232
233 (defcustom gnus-summary-default-low-score 0
234   "*Default threshold for a low scored article.
235 An article will be highlighted as low scored if its score is smaller
236 than this score."
237   :group 'gnus-score-default
238   :type 'integer)
239
240 (defcustom gnus-summary-zcore-fuzz 0
241   "*Fuzziness factor for the zcore in the summary buffer.
242 Articles with scores closer than this to `gnus-summary-default-score'
243 will not be marked."
244   :group 'gnus-summary-format
245   :type 'integer)
246
247 (defcustom gnus-simplify-subject-fuzzy-regexp nil
248   "*Strings to be removed when doing fuzzy matches.
249 This can either be a regular expression or list of regular expressions
250 that will be removed from subject strings if fuzzy subject
251 simplification is selected."
252   :group 'gnus-thread
253   :type '(repeat regexp))
254
255 (defcustom gnus-show-threads t
256   "*If non-nil, display threads in summary mode."
257   :group 'gnus-thread
258   :type 'boolean)
259
260 (defcustom gnus-thread-hide-subtree nil
261   "*If non-nil, hide all threads initially.
262 This can be a predicate specifier which says which threads to hide.
263 If threads are hidden, you have to run the command
264 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
265 to expose hidden threads."
266   :group 'gnus-thread
267   :type 'boolean)
268
269 (defcustom gnus-thread-hide-killed t
270   "*If non-nil, hide killed threads automatically."
271   :group 'gnus-thread
272   :type 'boolean)
273
274 (defcustom gnus-thread-ignore-subject t
275   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
276 If nil, articles that have different subjects from their parents will
277 start separate threads."
278   :group 'gnus-thread
279   :type 'boolean)
280
281 (defcustom gnus-thread-operation-ignore-subject t
282   "*If non-nil, subjects will be ignored when doing thread commands.
283 This affects commands like `gnus-summary-kill-thread' and
284 `gnus-summary-lower-thread'.
285
286 If this variable is nil, articles in the same thread with different
287 subjects will not be included in the operation in question.  If this
288 variable is `fuzzy', only articles that have subjects that are fuzzily
289 equal will be included."
290   :group 'gnus-thread
291   :type '(choice (const :tag "off" nil)
292                  (const fuzzy)
293                  (sexp :tag "on" t)))
294
295 (defcustom gnus-thread-indent-level 4
296   "*Number that says how much each sub-thread should be indented."
297   :group 'gnus-thread
298   :type 'integer)
299
300 (defcustom gnus-auto-extend-newsgroup t
301   "*If non-nil, extend newsgroup forward and backward when requested."
302   :group 'gnus-summary-choose
303   :type 'boolean)
304
305 (defcustom gnus-auto-select-first t
306   "*If non-nil, select the article under point.
307 Which article this is is controlled by the `gnus-auto-select-subject'
308 variable.
309
310 If you want to prevent automatic selection of articles in some
311 newsgroups, set the variable to nil in `gnus-select-group-hook'."
312   :group 'gnus-group-select
313   :type '(choice (const :tag "none" nil)
314                  (sexp :menu-tag "first" t)))
315
316 (defcustom gnus-auto-select-subject 'unread
317   "*Says what subject to place under point when entering a group.
318
319 This variable can either be the symbols `first' (place point on the
320 first subject), `unread' (place point on the subject line of the first
321 unread article), `best' (place point on the subject line of the
322 higest-scored article), `unseen' (place point on the subject line of
323 the first unseen article), 'unseen-or-unread' (place point on the subject
324 line of the first unseen article or, if all article have been seen, on the
325 subject line of the first unread article), or a function to be called to
326 place point on some subject line."
327   :group 'gnus-group-select
328   :type '(choice (const best)
329                  (const unread)
330                  (const first)
331                  (const unseen)
332                  (const unseen-or-unread)))
333
334 (defcustom gnus-dont-select-after-jump-to-other-group nil
335   "If non-nil, don't select the first unread article after entering the
336 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
337 it is depend on the value of `gnus-auto-select-first' whether to select
338 or not."
339   :group 'gnus-group-select
340   :type 'boolean)
341
342 (defcustom gnus-auto-select-next t
343   "*If non-nil, offer to go to the next group from the end of the previous.
344 If the value is t and the next newsgroup is empty, Gnus will exit
345 summary mode and go back to group mode.  If the value is neither nil
346 nor t, Gnus will select the following unread newsgroup.  In
347 particular, if the value is the symbol `quietly', the next unread
348 newsgroup will be selected without any confirmation, and if it is
349 `almost-quietly', the next group will be selected without any
350 confirmation if you are located on the last article in the group.
351 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
352 will go to the next group without confirmation."
353   :group 'gnus-summary-maneuvering
354   :type '(choice (const :tag "off" nil)
355                  (const quietly)
356                  (const almost-quietly)
357                  (const slightly-quietly)
358                  (sexp :menu-tag "on" t)))
359
360 (defcustom gnus-auto-select-same nil
361   "*If non-nil, select the next article with the same subject.
362 If there are no more articles with the same subject, go to
363 the first unread article."
364   :group 'gnus-summary-maneuvering
365   :type 'boolean)
366
367 (defcustom gnus-auto-goto-ignores 'unfetched
368   "*Says how to handle unfetched articles when maneuvering.
369
370 This variable can either be the symbols nil (maneuver to any
371 article), `undownloaded' (maneuvering while unplugged ignores articles
372 that have not been fetched), `always-undownloaded' (maneuvering always
373 ignores articles that have not been fetched), `unfetched' (maneuvering
374 ignores articles whose headers have not been fetched).
375
376 NOTE: The list of unfetched articles will always be nil when plugged
377 and, when unplugged, a subset of the undownloaded article list."
378   :group 'gnus-summary-maneuvering
379   :type '(choice (const :tag "None" nil)
380                  (const :tag "Undownloaded when unplugged" undownloaded)
381                  (const :tag "Undownloaded" always-undownloaded)
382                  (const :tag "Unfetched" unfetched)))
383
384 (defcustom gnus-summary-check-current nil
385   "*If non-nil, consider the current article when moving.
386 The \"unread\" movement commands will stay on the same line if the
387 current article is unread."
388   :group 'gnus-summary-maneuvering
389   :type 'boolean)
390
391 (defcustom gnus-auto-center-summary t
392   "*If non-nil, always center the current summary buffer.
393 In particular, if `vertical' do only vertical recentering.  If non-nil
394 and non-`vertical', do both horizontal and vertical recentering."
395   :group 'gnus-summary-maneuvering
396   :type '(choice (const :tag "none" nil)
397                  (const vertical)
398                  (integer :tag "height")
399                  (sexp :menu-tag "both" t)))
400
401 (defvar gnus-auto-center-group t
402   "*If non-nil, always center the group buffer.")
403
404 (defcustom gnus-show-all-headers nil
405   "*If non-nil, don't hide any headers."
406   :group 'gnus-article-hiding
407   :group 'gnus-article-headers
408   :type 'boolean)
409
410 (defcustom gnus-summary-ignore-duplicates nil
411   "*If non-nil, ignore articles with identical Message-ID headers."
412   :group 'gnus-summary
413   :type 'boolean)
414
415 (defcustom gnus-single-article-buffer t
416   "*If non-nil, display all articles in the same buffer.
417 If nil, each group will get its own article buffer."
418   :group 'gnus-article-various
419   :type 'boolean)
420
421 (defcustom gnus-break-pages t
422   "*If non-nil, do page breaking on articles.
423 The page delimiter is specified by the `gnus-page-delimiter'
424 variable."
425   :group 'gnus-article-various
426   :type 'boolean)
427
428 (defcustom gnus-show-mime t
429   "*If non-nil, do mime processing of articles.
430 The articles will simply be fed to the function given by
431 `gnus-article-display-method-for-mime'."
432   :group 'gnus-article-mime
433   :type 'boolean)
434
435 (defcustom gnus-move-split-methods nil
436   "*Variable used to suggest where articles are to be moved to.
437 It uses the same syntax as the `gnus-split-methods' variable.
438 However, whereas `gnus-split-methods' specifies file names as targets,
439 this variable specifies group names."
440   :group 'gnus-summary-mail
441   :type '(repeat (choice (list :value (fun) function)
442                          (cons :value ("" "") regexp (repeat string))
443                          (sexp :value nil))))
444
445 (defcustom gnus-unread-mark ?\ ;;;Whitespace
446   "*Mark used for unread articles."
447   :group 'gnus-summary-marks
448   :type 'character)
449
450 (defcustom gnus-ticked-mark ?!
451   "*Mark used for ticked articles."
452   :group 'gnus-summary-marks
453   :type 'character)
454
455 (defcustom gnus-dormant-mark ??
456   "*Mark used for dormant articles."
457   :group 'gnus-summary-marks
458   :type 'character)
459
460 (defcustom gnus-del-mark ?r
461   "*Mark used for del'd articles."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-read-mark ?R
466   "*Mark used for read articles."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-expirable-mark ?E
471   "*Mark used for expirable articles."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-killed-mark ?K
476   "*Mark used for killed articles."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-spam-mark ?$
481   "*Mark used for spam articles."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-souped-mark ?F
486   "*Mark used for souped articles."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-kill-file-mark ?X
491   "*Mark used for articles killed by kill files."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-low-score-mark ?Y
496   "*Mark used for articles with a low score."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-catchup-mark ?C
501   "*Mark used for articles that are caught up."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-replied-mark ?A
506   "*Mark used for articles that have been replied to."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-forwarded-mark ?F
511   "*Mark used for articles that have been forwarded."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-recent-mark ?N
516   "*Mark used for articles that are recent."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-cached-mark ?*
521   "*Mark used for articles that are in the cache."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-saved-mark ?S
526   "*Mark used for articles that have been saved."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-unseen-mark ?.
531   "*Mark used for articles that haven't been seen."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-no-mark ?\ ;;;Whitespace
536   "*Mark used for articles that have no other secondary mark."
537   :group 'gnus-summary-marks
538   :type 'character)
539
540 (defcustom gnus-ancient-mark ?O
541   "*Mark used for ancient articles."
542   :group 'gnus-summary-marks
543   :type 'character)
544
545 (defcustom gnus-sparse-mark ?Q
546   "*Mark used for sparsely reffed articles."
547   :group 'gnus-summary-marks
548   :type 'character)
549
550 (defcustom gnus-canceled-mark ?G
551   "*Mark used for canceled articles."
552   :group 'gnus-summary-marks
553   :type 'character)
554
555 (defcustom gnus-duplicate-mark ?M
556   "*Mark used for duplicate articles."
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-undownloaded-mark ?-
561   "*Mark used for articles that weren't downloaded."
562   :group 'gnus-summary-marks
563   :type 'character)
564
565 (defcustom gnus-downloaded-mark ?+
566   "*Mark used for articles that were downloaded."
567   :group 'gnus-summary-marks
568   :type 'character)
569
570 (defcustom gnus-downloadable-mark ?%
571   "*Mark used for articles that are to be downloaded."
572   :group 'gnus-summary-marks
573   :type 'character)
574
575 (defcustom gnus-unsendable-mark ?=
576   "*Mark used for articles that won't be sent."
577   :group 'gnus-summary-marks
578   :type 'character)
579
580 (defcustom gnus-score-over-mark ?+
581   "*Score mark used for articles with high scores."
582   :group 'gnus-summary-marks
583   :type 'character)
584
585 (defcustom gnus-score-below-mark ?-
586   "*Score mark used for articles with low scores."
587   :group 'gnus-summary-marks
588   :type 'character)
589
590 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
591   "*There is no thread under the article."
592   :group 'gnus-summary-marks
593   :type 'character)
594
595 (defcustom gnus-not-empty-thread-mark ?=
596   "*There is a thread under the article."
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-view-pseudo-asynchronously nil
601   "*If non-nil, Gnus will view pseudo-articles asynchronously."
602   :group 'gnus-extract-view
603   :type 'boolean)
604
605 (defcustom gnus-auto-expirable-marks
606   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
607         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
608         gnus-souped-mark gnus-duplicate-mark)
609   "*The list of marks converted into expiration if a group is auto-expirable."
610   :version "21.1"
611   :group 'gnus-summary
612   :type '(repeat character))
613
614 (defcustom gnus-inhibit-user-auto-expire t
615   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
616   :version "21.1"
617   :group 'gnus-summary
618   :type 'boolean)
619
620 (defcustom gnus-view-pseudos nil
621   "*If `automatic', pseudo-articles will be viewed automatically.
622 If `not-confirm', pseudos will be viewed automatically, and the user
623 will not be asked to confirm the command."
624   :group 'gnus-extract-view
625   :type '(choice (const :tag "off" nil)
626                  (const automatic)
627                  (const not-confirm)))
628
629 (defcustom gnus-view-pseudos-separately t
630   "*If non-nil, one pseudo-article will be created for each file to be viewed.
631 If nil, all files that use the same viewing command will be given as a
632 list of parameters to that command."
633   :group 'gnus-extract-view
634   :type 'boolean)
635
636 (defcustom gnus-insert-pseudo-articles t
637   "*If non-nil, insert pseudo-articles when decoding articles."
638   :group 'gnus-extract-view
639   :type 'boolean)
640
641 (defcustom gnus-summary-dummy-line-format
642   "   %(:                             :%) %S\n"
643   "*The format specification for the dummy roots in the summary buffer.
644 It works along the same lines as a normal formatting string,
645 with some simple extensions.
646
647 %S  The subject
648
649 General format specifiers can also be used.
650 See `(gnus)Formatting Variables'."
651   :link '(custom-manual "(gnus)Formatting Variables")
652   :group 'gnus-threading
653   :type 'string)
654
655 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
656   "*The format specification for the summary mode line.
657 It works along the same lines as a normal formatting string,
658 with some simple extensions:
659
660 %G  Group name
661 %p  Unprefixed group name
662 %A  Current article number
663 %z  Current article score
664 %V  Gnus version
665 %U  Number of unread articles in the group
666 %e  Number of unselected articles in the group
667 %Z  A string with unread/unselected article counts
668 %g  Shortish group name
669 %S  Subject of the current article
670 %u  User-defined spec
671 %s  Current score file name
672 %d  Number of dormant articles
673 %r  Number of articles that have been marked as read in this session
674 %E  Number of articles expunged by the score files"
675   :group 'gnus-summary-format
676   :type 'string)
677
678 (defcustom gnus-list-identifiers nil
679   "Regexp that matches list identifiers to be removed from subject.
680 This can also be a list of regexps."
681   :version "21.1"
682   :group 'gnus-summary-format
683   :group 'gnus-article-hiding
684   :type '(choice (const :tag "none" nil)
685                  (regexp :value ".*")
686                  (repeat :value (".*") regexp)))
687
688 (defcustom gnus-summary-mark-below 0
689   "*Mark all articles with a score below this variable as read.
690 This variable is local to each summary buffer and usually set by the
691 score file."
692   :group 'gnus-score-default
693   :type 'integer)
694
695 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
696   "*List of functions used for sorting articles in the summary buffer.
697
698 Each function takes two articles and returns non-nil if the first
699 article should be sorted before the other.  If you use more than one
700 function, the primary sort function should be the last.  You should
701 probably always include `gnus-article-sort-by-number' in the list of
702 sorting functions -- preferably first.  Also note that sorting by date
703 is often much slower than sorting by number, and the sorting order is
704 very similar.  (Sorting by date means sorting by the time the message
705 was sent, sorting by number means sorting by arrival time.)
706
707 Ready-made functions include `gnus-article-sort-by-number',
708 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
709 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
710 and `gnus-article-sort-by-score'.
711
712 When threading is turned on, the variable `gnus-thread-sort-functions'
713 controls how articles are sorted."
714   :group 'gnus-summary-sort
715   :type '(repeat (choice (function-item gnus-article-sort-by-number)
716                          (function-item gnus-article-sort-by-author)
717                          (function-item gnus-article-sort-by-subject)
718                          (function-item gnus-article-sort-by-date)
719                          (function-item gnus-article-sort-by-score)
720                          (function-item gnus-article-sort-by-random)
721                          (function :tag "other"))))
722
723 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
724   "*List of functions used for sorting threads in the summary buffer.
725 By default, threads are sorted by article number.
726
727 Each function takes two threads and returns non-nil if the first
728 thread should be sorted before the other.  If you use more than one
729 function, the primary sort function should be the last.  You should
730 probably always include `gnus-thread-sort-by-number' in the list of
731 sorting functions -- preferably first.  Also note that sorting by date
732 is often much slower than sorting by number, and the sorting order is
733 very similar.  (Sorting by date means sorting by the time the message
734 was sent, sorting by number means sorting by arrival time.)
735
736 Ready-made functions include `gnus-thread-sort-by-number',
737 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
738 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
739 `gnus-thread-sort-by-most-recent-number',
740 `gnus-thread-sort-by-most-recent-date',
741 `gnus-thread-sort-by-random', and
742 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
743
744 When threading is turned off, the variable
745 `gnus-article-sort-functions' controls how articles are sorted."
746   :group 'gnus-summary-sort
747   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
748                          (function-item gnus-thread-sort-by-author)
749                          (function-item gnus-thread-sort-by-subject)
750                          (function-item gnus-thread-sort-by-date)
751                          (function-item gnus-thread-sort-by-score)
752                          (function-item gnus-thread-sort-by-total-score)
753                          (function-item gnus-thread-sort-by-random)
754                          (function :tag "other"))))
755
756 (defcustom gnus-thread-score-function '+
757   "*Function used for calculating the total score of a thread.
758
759 The function is called with the scores of the article and each
760 subthread and should then return the score of the thread.
761
762 Some functions you can use are `+', `max', or `min'."
763   :group 'gnus-summary-sort
764   :type 'function)
765
766 (defcustom gnus-summary-expunge-below nil
767   "All articles that have a score less than this variable will be expunged.
768 This variable is local to the summary buffers."
769   :group 'gnus-score-default
770   :type '(choice (const :tag "off" nil)
771                  integer))
772
773 (defcustom gnus-thread-expunge-below nil
774   "All threads that have a total score less than this variable will be expunged.
775 See `gnus-thread-score-function' for en explanation of what a
776 \"thread score\" is.
777
778 This variable is local to the summary buffers."
779   :group 'gnus-threading
780   :group 'gnus-score-default
781   :type '(choice (const :tag "off" nil)
782                  integer))
783
784 (defcustom gnus-summary-mode-hook nil
785   "*A hook for Gnus summary mode.
786 This hook is run before any variables are set in the summary buffer."
787   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
788   :group 'gnus-summary-various
789   :type 'hook)
790
791 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
792 (when (featurep 'xemacs)
793   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
794   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
795   (add-hook 'gnus-summary-mode-hook
796             'gnus-xmas-switch-horizontal-scrollbar-off))
797
798 (defcustom gnus-summary-menu-hook nil
799   "*Hook run after the creation of the summary mode menu."
800   :group 'gnus-summary-visual
801   :type 'hook)
802
803 (defcustom gnus-summary-exit-hook nil
804   "*A hook called on exit from the summary buffer.
805 It will be called with point in the group buffer."
806   :group 'gnus-summary-exit
807   :type 'hook)
808
809 (defcustom gnus-summary-prepare-hook nil
810   "*A hook called after the summary buffer has been generated.
811 If you want to modify the summary buffer, you can use this hook."
812   :group 'gnus-summary-various
813   :type 'hook)
814
815 (defcustom gnus-summary-prepared-hook nil
816   "*A hook called as the last thing after the summary buffer has been generated."
817   :group 'gnus-summary-various
818   :type 'hook)
819
820 (defcustom gnus-summary-generate-hook nil
821   "*A hook run just before generating the summary buffer.
822 This hook is commonly used to customize threading variables and the
823 like."
824   :group 'gnus-summary-various
825   :type 'hook)
826
827 (defcustom gnus-select-group-hook nil
828   "*A hook called when a newsgroup is selected.
829
830 If you'd like to simplify subjects like the
831 `gnus-summary-next-same-subject' command does, you can use the
832 following hook:
833
834  (add-hook gnus-select-group-hook
835            (lambda ()
836              (mapcar (lambda (header)
837                        (mail-header-set-subject
838                         header
839                         (gnus-simplify-subject
840                          (mail-header-subject header) 're-only)))
841                      gnus-newsgroup-headers)))"
842   :group 'gnus-group-select
843   :type 'hook)
844
845 (defcustom gnus-select-article-hook nil
846   "*A hook called when an article is selected."
847   :group 'gnus-summary-choose
848   :options '(gnus-agent-fetch-selected-article)
849   :type 'hook)
850
851 (defcustom gnus-visual-mark-article-hook
852   (list 'gnus-highlight-selected-summary)
853   "*Hook run after selecting an article in the summary buffer.
854 It is meant to be used for highlighting the article in some way.  It
855 is not run if `gnus-visual' is nil."
856   :group 'gnus-summary-visual
857   :type 'hook)
858
859 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
860   "*A hook called before parsing the headers."
861   :group 'gnus-various
862   :type 'hook)
863
864 (defcustom gnus-exit-group-hook nil
865   "*A hook called when exiting summary mode.
866 This hook is not called from the non-updating exit commands like `Q'."
867   :group 'gnus-various
868   :type 'hook)
869
870 (defcustom gnus-summary-update-hook
871   (list 'gnus-summary-highlight-line)
872   "*A hook called when a summary line is changed.
873 The hook will not be called if `gnus-visual' is nil.
874
875 The default function `gnus-summary-highlight-line' will
876 highlight the line according to the `gnus-summary-highlight'
877 variable."
878   :group 'gnus-summary-visual
879   :type 'hook)
880
881 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
882   "*A hook called when an article is selected for the first time.
883 The hook is intended to mark an article as read (or unread)
884 automatically when it is selected."
885   :group 'gnus-summary-choose
886   :type 'hook)
887
888 (defcustom gnus-group-no-more-groups-hook nil
889   "*A hook run when returning to group mode having no more (unread) groups."
890   :group 'gnus-group-select
891   :type 'hook)
892
893 (defcustom gnus-ps-print-hook nil
894   "*A hook run before ps-printing something from Gnus."
895   :group 'gnus-summary
896   :type 'hook)
897
898 (defcustom gnus-summary-article-move-hook nil
899   "*A hook called after an article is moved, copied, respooled, or crossposted."
900   :group 'gnus-summary
901   :type 'hook)
902
903 (defcustom gnus-summary-article-delete-hook nil
904   "*A hook called after an article is deleted."
905   :group 'gnus-summary
906   :type 'hook)
907
908 (defcustom gnus-summary-article-expire-hook nil
909   "*A hook called after an article is expired."
910   :group 'gnus-summary
911   :type 'hook)
912
913 (defcustom gnus-summary-display-arrow
914   (and (fboundp 'display-graphic-p)
915        (display-graphic-p))
916   "*If non-nil, display an arrow highlighting the current article."
917   :version "21.1"
918   :group 'gnus-summary
919   :type 'boolean)
920
921 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
922   "Face used for highlighting the current article in the summary buffer."
923   :group 'gnus-summary-visual
924   :type 'face)
925
926 (defvar gnus-tmp-downloaded nil)
927
928 (defcustom gnus-summary-highlight
929   '(((eq mark gnus-canceled-mark)
930      . gnus-summary-cancelled-face)
931     ((and uncached (> score default-high))
932      . gnus-summary-high-undownloaded-face)
933     ((and uncached (< score default-low))
934      . gnus-summary-low-undownloaded-face)
935     (uncached
936      . gnus-summary-normal-undownloaded-face)
937     ((and (> score default-high)
938           (or (eq mark gnus-dormant-mark)
939               (eq mark gnus-ticked-mark)))
940      . gnus-summary-high-ticked-face)
941     ((and (< score default-low)
942           (or (eq mark gnus-dormant-mark)
943               (eq mark gnus-ticked-mark)))
944      . gnus-summary-low-ticked-face)
945     ((or (eq mark gnus-dormant-mark)
946          (eq mark gnus-ticked-mark))
947      . gnus-summary-normal-ticked-face)
948     ((and (> score default-high) (eq mark gnus-ancient-mark))
949      . gnus-summary-high-ancient-face)
950     ((and (< score default-low) (eq mark gnus-ancient-mark))
951      . gnus-summary-low-ancient-face)
952     ((eq mark gnus-ancient-mark)
953      . gnus-summary-normal-ancient-face)
954     ((and (> score default-high) (eq mark gnus-unread-mark))
955      . gnus-summary-high-unread-face)
956     ((and (< score default-low) (eq mark gnus-unread-mark))
957      . gnus-summary-low-unread-face)
958     ((eq mark gnus-unread-mark)
959      . gnus-summary-normal-unread-face)
960     ((> score default-high)
961      . gnus-summary-high-read-face)
962     ((< score default-low)
963      . gnus-summary-low-read-face)
964     (t
965      . gnus-summary-normal-read-face))
966   "*Controls the highlighting of summary buffer lines.
967
968 A list of (FORM . FACE) pairs.  When deciding how a a particular
969 summary line should be displayed, each form is evaluated.  The content
970 of the face field after the first true form is used.  You can change
971 how those summary lines are displayed, by editing the face field.
972
973 You can use the following variables in the FORM field.
974
975 score:        The article's score
976 default:      The default article score.
977 default-high: The default score for high scored articles.
978 default-low:  The default score for low scored articles.
979 below:        The score below which articles are automatically marked as read.
980 mark:         The articles mark."
981   :group 'gnus-summary-visual
982   :type '(repeat (cons (sexp :tag "Form" nil)
983                        face)))
984
985 (defcustom gnus-alter-header-function nil
986   "Function called to allow alteration of article header structures.
987 The function is called with one parameter, the article header vector,
988 which it may alter in any way."
989   :type '(choice (const :tag "None" nil)
990                  function)
991   :group 'gnus-summary)
992
993 (defvar gnus-decode-encoded-word-function
994   (mime-find-field-decoder 'From 'nov)
995   "Variable that says which function should be used to decode a string with encoded words.")
996
997 (defcustom gnus-extra-headers '(To Newsgroups)
998   "*Extra headers to parse."
999   :version "21.1"
1000   :group 'gnus-summary
1001   :type '(repeat symbol))
1002
1003 (defcustom gnus-ignored-from-addresses
1004   (and user-mail-address (regexp-quote user-mail-address))
1005   "*Regexp of From headers that may be suppressed in favor of To headers."
1006   :version "21.1"
1007   :group 'gnus-summary
1008   :type 'regexp)
1009
1010 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1011   "List of charsets that should be ignored.
1012 When these charsets are used in the \"charset\" parameter, the
1013 default charset will be used instead."
1014   :version "21.1"
1015   :type '(repeat symbol)
1016   :group 'gnus-charset)
1017
1018 (gnus-define-group-parameter
1019  ignored-charsets
1020  :type list
1021  :function-document
1022  "Return the ignored charsets of GROUP."
1023  :variable gnus-group-ignored-charsets-alist
1024  :variable-default
1025  '(("alt\\.chinese\\.text" iso-8859-1))
1026  :variable-document
1027  "Alist of regexps (to match group names) and charsets that should be ignored.
1028 When these charsets are used in the \"charset\" parameter, the
1029 default charset will be used instead."
1030  :variable-group gnus-charset
1031  :variable-type '(repeat (cons (regexp :tag "Group")
1032                                (repeat symbol)))
1033  :parameter-type '(choice :tag "Ignored charsets"
1034                           :value nil
1035                           (repeat (symbol)))
1036  :parameter-document       "\
1037 List of charsets that should be ignored.
1038
1039 When these charsets are used in the \"charset\" parameter, the
1040 default charset will be used instead.")
1041
1042 (defcustom gnus-group-highlight-words-alist nil
1043   "Alist of group regexps and highlight regexps.
1044 This variable uses the same syntax as `gnus-emphasis-alist'."
1045   :version "21.1"
1046   :type '(repeat (cons (regexp :tag "Group")
1047                        (repeat (list (regexp :tag "Highlight regexp")
1048                                      (number :tag "Group for entire word" 0)
1049                                      (number :tag "Group for displayed part" 0)
1050                                      (symbol :tag "Face"
1051                                              gnus-emphasis-highlight-words)))))
1052   :group 'gnus-summary-visual)
1053
1054 (defcustom gnus-use-wheel nil
1055   "Use Intelli-mouse on summary movement"
1056   :type 'boolean
1057   :group 'gnus-summary-maneuvering)
1058
1059 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1060   "Amount to scroll messages by spinning the mouse wheel.
1061 This is actually a cons cell, where the first item is the amount to scroll
1062 on a normal wheel event, and the second is the amount to scroll when the
1063 wheel is moved with the shift key depressed."
1064   :type '(cons (integer :tag "Shift") integer)
1065   :group 'gnus-summary-maneuvering)
1066
1067 (defcustom gnus-wheel-edge-resistance 2
1068   "How hard it should be to change the current article
1069 by moving the mouse over the edge of the article window."
1070   :type 'integer
1071   :group 'gnus-summary-maneuvering)
1072
1073 (defcustom gnus-summary-show-article-charset-alist
1074   nil
1075   "Alist of number and charset.
1076 The article will be shown with the charset corresponding to the
1077 numbered argument.
1078 For example: ((1 . cn-gb-2312) (2 . big5))."
1079   :version "21.1"
1080   :type '(repeat (cons (number :tag "Argument" 1)
1081                        (symbol :tag "Charset")))
1082   :group 'gnus-charset)
1083
1084 (defcustom gnus-preserve-marks t
1085   "Whether marks are preserved when moving, copying and respooling messages."
1086   :version "21.1"
1087   :type 'boolean
1088   :group 'gnus-summary-marks)
1089
1090 (defcustom gnus-alter-articles-to-read-function nil
1091   "Function to be called to alter the list of articles to be selected."
1092   :type '(choice (const nil) function)
1093   :group 'gnus-summary)
1094
1095 (defcustom gnus-orphan-score nil
1096   "*All orphans get this score added.  Set in the score file."
1097   :group 'gnus-score-default
1098   :type '(choice (const nil)
1099                  integer))
1100
1101 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1102   "*A regexp to match MIME parts when saving multiple parts of a
1103 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1104 This regexp will be used by default when prompting the user for which
1105 type of files to save."
1106   :group 'gnus-summary
1107   :type 'regexp)
1108
1109 (defcustom gnus-read-all-available-headers nil
1110   "Whether Gnus should parse all headers made available to it.
1111 This is mostly relevant for slow backends where the user may
1112 wish to widen the summary buffer to include all headers
1113 that were fetched.  Say, for nnultimate groups."
1114   :group 'gnus-summary
1115   :type '(choice boolean regexp))
1116
1117 (defcustom gnus-summary-muttprint-program "muttprint"
1118   "Command (and optional arguments) used to run Muttprint."
1119   :version "21.3"
1120   :group 'gnus-summary
1121   :type 'string)
1122
1123 (defcustom gnus-article-loose-mime nil
1124   "If non-nil, don't require MIME-Version header.
1125 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1126 supply the MIME-Version header or deliberately strip it From the mail.
1127 Set it to non-nil, Gnus will treat some articles as MIME even if
1128 the MIME-Version header is missed."
1129   :version "21.3"
1130   :type 'boolean
1131   :group 'gnus-article-mime)
1132
1133 (defcustom gnus-article-emulate-mime t
1134   "If non-nil, use MIME emulation for uuencode and the like.
1135 This means that Gnus will search message bodies for text that look
1136 like uuencoded bits, yEncoded bits, and so on, and present that using
1137 the normal Gnus MIME machinery."
1138   :type 'boolean
1139   :group 'gnus-article-mime)
1140
1141 ;;; Internal variables
1142
1143 (defvar gnus-summary-display-cache nil)
1144 (defvar gnus-article-mime-handles nil)
1145 (defvar gnus-article-decoded-p nil)
1146 (defvar gnus-article-charset nil)
1147 (defvar gnus-article-ignored-charsets nil)
1148 (defvar gnus-scores-exclude-files nil)
1149 (defvar gnus-page-broken nil)
1150
1151 (defvar gnus-original-article nil)
1152 (defvar gnus-article-internal-prepare-hook nil)
1153 (defvar gnus-newsgroup-process-stack nil)
1154
1155 (defvar gnus-thread-indent-array nil)
1156 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1157 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1158   "Function called to sort the articles within a thread after it has been gathered together.")
1159
1160 (defvar gnus-summary-save-parts-type-history nil)
1161 (defvar gnus-summary-save-parts-last-directory nil)
1162
1163 ;; Avoid highlighting in kill files.
1164 (defvar gnus-summary-inhibit-highlight nil)
1165 (defvar gnus-newsgroup-selected-overlay nil)
1166 (defvar gnus-inhibit-limiting nil)
1167 (defvar gnus-newsgroup-adaptive-score-file nil)
1168 (defvar gnus-current-score-file nil)
1169 (defvar gnus-current-move-group nil)
1170 (defvar gnus-current-copy-group nil)
1171 (defvar gnus-current-crosspost-group nil)
1172 (defvar gnus-newsgroup-display nil)
1173
1174 (defvar gnus-newsgroup-dependencies nil)
1175 (defvar gnus-newsgroup-adaptive nil)
1176 (defvar gnus-summary-display-article-function nil)
1177 (defvar gnus-summary-highlight-line-function nil
1178   "Function called after highlighting a summary line.")
1179
1180 (defvar gnus-summary-line-format-alist
1181   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1182     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1183     (?s gnus-tmp-subject-or-nil ?s)
1184     (?n gnus-tmp-name ?s)
1185     (?A (std11-address-string
1186          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1187     (?a (or (std11-full-name-string
1188              (car (mime-entity-read-field gnus-tmp-header 'From)))
1189             gnus-tmp-from) ?s)
1190     (?F gnus-tmp-from ?s)
1191     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1192     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1193     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1194     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1195     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1196     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1197     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1198     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1199     (?L gnus-tmp-lines ?s)
1200     (?O gnus-tmp-downloaded ?c)
1201     (?I gnus-tmp-indentation ?s)
1202     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1203     (?R gnus-tmp-replied ?c)
1204     (?\[ gnus-tmp-opening-bracket ?c)
1205     (?\] gnus-tmp-closing-bracket ?c)
1206     (?\> (make-string gnus-tmp-level ? ) ?s)
1207     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1208     (?i gnus-tmp-score ?d)
1209     (?z gnus-tmp-score-char ?c)
1210     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1211     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1212     (?U gnus-tmp-unread ?c)
1213     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1214         ?s)
1215     (?t (gnus-summary-number-of-articles-in-thread
1216          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1217         ?d)
1218     (?e (gnus-summary-number-of-articles-in-thread
1219          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1220         ?c)
1221     (?u gnus-tmp-user-defined ?s)
1222     (?P (gnus-pick-line-number) ?d)
1223     (?B gnus-tmp-thread-tree-header-string ?s)
1224     (user-date (gnus-user-date
1225                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1226   "An alist of format specifications that can appear in summary lines.
1227 These are paired with what variables they correspond with, along with
1228 the type of the variable (string, integer, character, etc).")
1229
1230 (defvar gnus-summary-dummy-line-format-alist
1231   `((?S gnus-tmp-subject ?s)
1232     (?N gnus-tmp-number ?d)
1233     (?u gnus-tmp-user-defined ?s)))
1234
1235 (defvar gnus-summary-mode-line-format-alist
1236   `((?G gnus-tmp-group-name ?s)
1237     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1238     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1239     (?A gnus-tmp-article-number ?d)
1240     (?Z gnus-tmp-unread-and-unselected ?s)
1241     (?V gnus-version ?s)
1242     (?U gnus-tmp-unread-and-unticked ?d)
1243     (?S gnus-tmp-subject ?s)
1244     (?e gnus-tmp-unselected ?d)
1245     (?u gnus-tmp-user-defined ?s)
1246     (?d (length gnus-newsgroup-dormant) ?d)
1247     (?t (length gnus-newsgroup-marked) ?d)
1248     (?h (length gnus-newsgroup-spam-marked) ?d)
1249     (?r (length gnus-newsgroup-reads) ?d)
1250     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1251     (?E gnus-newsgroup-expunged-tally ?d)
1252     (?s (gnus-current-score-file-nondirectory) ?s)))
1253
1254 (defvar gnus-last-search-regexp nil
1255   "Default regexp for article search command.")
1256
1257 (defvar gnus-summary-search-article-matched-data nil
1258   "Last matched data of article search command.  It is the local variable
1259 in `gnus-article-buffer' which consists of the list of start position,
1260 end position and text.")
1261
1262 (defvar gnus-last-shell-command nil
1263   "Default shell command on article.")
1264
1265 (defvar gnus-newsgroup-agentized nil
1266   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1267 (defvar gnus-newsgroup-begin nil)
1268 (defvar gnus-newsgroup-end nil)
1269 (defvar gnus-newsgroup-last-rmail nil)
1270 (defvar gnus-newsgroup-last-mail nil)
1271 (defvar gnus-newsgroup-last-folder nil)
1272 (defvar gnus-newsgroup-last-file nil)
1273 (defvar gnus-newsgroup-auto-expire nil)
1274 (defvar gnus-newsgroup-active nil)
1275
1276 (defvar gnus-newsgroup-data nil)
1277 (defvar gnus-newsgroup-data-reverse nil)
1278 (defvar gnus-newsgroup-limit nil)
1279 (defvar gnus-newsgroup-limits nil)
1280
1281 (defvar gnus-newsgroup-unreads nil
1282   "Sorted list of unread articles in the current newsgroup.")
1283
1284 (defvar gnus-newsgroup-unselected nil
1285   "Sorted list of unselected unread articles in the current newsgroup.")
1286
1287 (defvar gnus-newsgroup-reads nil
1288   "Alist of read articles and article marks in the current newsgroup.")
1289
1290 (defvar gnus-newsgroup-expunged-tally nil)
1291
1292 (defvar gnus-newsgroup-marked nil
1293   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1294
1295 (defvar gnus-newsgroup-spam-marked nil
1296   "List of ranges of articles that have been marked as spam.")
1297
1298 (defvar gnus-newsgroup-killed nil
1299   "List of ranges of articles that have been through the scoring process.")
1300
1301 (defvar gnus-newsgroup-cached nil
1302   "Sorted list of articles that come from the article cache.")
1303
1304 (defvar gnus-newsgroup-saved nil
1305   "List of articles that have been saved.")
1306
1307 (defvar gnus-newsgroup-kill-headers nil)
1308
1309 (defvar gnus-newsgroup-replied nil
1310   "List of articles that have been replied to in the current newsgroup.")
1311
1312 (defvar gnus-newsgroup-forwarded nil
1313   "List of articles that have been forwarded in the current newsgroup.")
1314
1315 (defvar gnus-newsgroup-recent nil
1316   "List of articles that have are recent in the current newsgroup.")
1317
1318 (defvar gnus-newsgroup-expirable nil
1319   "Sorted list of articles in the current newsgroup that can be expired.")
1320
1321 (defvar gnus-newsgroup-processable nil
1322   "List of articles in the current newsgroup that can be processed.")
1323
1324 (defvar gnus-newsgroup-downloadable nil
1325   "Sorted list of articles in the current newsgroup that can be processed.")
1326
1327 (defvar gnus-newsgroup-unfetched nil
1328   "Sorted list of articles in the current newsgroup whose headers have
1329 not been fetched into the agent.
1330
1331 This list will always be a subset of gnus-newsgroup-undownloaded.")
1332
1333 (defvar gnus-newsgroup-undownloaded nil
1334   "List of articles in the current newsgroup that haven't been downloaded.")
1335
1336 (defvar gnus-newsgroup-unsendable nil
1337   "List of articles in the current newsgroup that won't be sent.")
1338
1339 (defvar gnus-newsgroup-bookmarks nil
1340   "List of articles in the current newsgroup that have bookmarks.")
1341
1342 (defvar gnus-newsgroup-dormant nil
1343   "Sorted list of dormant articles in the current newsgroup.")
1344
1345 (defvar gnus-newsgroup-unseen nil
1346   "List of unseen articles in the current newsgroup.")
1347
1348 (defvar gnus-newsgroup-seen nil
1349   "Range of seen articles in the current newsgroup.")
1350
1351 (defvar gnus-newsgroup-articles nil
1352   "List of articles in the current newsgroup.")
1353
1354 (defvar gnus-newsgroup-scored nil
1355   "List of scored articles in the current newsgroup.")
1356
1357 (defvar gnus-newsgroup-incorporated nil
1358   "List of incorporated articles in the current newsgroup.")
1359
1360 (defvar gnus-newsgroup-headers nil
1361   "List of article headers in the current newsgroup.")
1362
1363 (defvar gnus-newsgroup-threads nil)
1364
1365 (defvar gnus-newsgroup-prepared nil
1366   "Whether the current group has been prepared properly.")
1367
1368 (defvar gnus-newsgroup-ancient nil
1369   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1370
1371 (defvar gnus-newsgroup-sparse nil)
1372
1373 (defvar gnus-current-article nil)
1374 (defvar gnus-article-current nil)
1375 (defvar gnus-current-headers nil)
1376 (defvar gnus-have-all-headers nil)
1377 (defvar gnus-last-article nil)
1378 (defvar gnus-newsgroup-history nil)
1379 (defvar gnus-newsgroup-charset nil)
1380 (defvar gnus-newsgroup-ephemeral-charset nil)
1381 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1382
1383 (defvar gnus-article-before-search nil)
1384
1385 (defvar gnus-summary-local-variables
1386   '(gnus-newsgroup-name
1387     gnus-newsgroup-begin gnus-newsgroup-end
1388     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1389     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1390     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1391     gnus-newsgroup-unselected gnus-newsgroup-marked
1392     gnus-newsgroup-spam-marked
1393     gnus-newsgroup-reads gnus-newsgroup-saved
1394     gnus-newsgroup-replied gnus-newsgroup-forwarded
1395     gnus-newsgroup-recent
1396     gnus-newsgroup-expirable
1397     gnus-newsgroup-processable gnus-newsgroup-killed
1398     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1399     gnus-newsgroup-unfetched
1400     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1401     gnus-newsgroup-seen gnus-newsgroup-articles
1402     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1403     gnus-newsgroup-headers gnus-newsgroup-threads
1404     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1405     gnus-current-article gnus-current-headers gnus-have-all-headers
1406     gnus-last-article gnus-article-internal-prepare-hook
1407     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1408     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1409     gnus-thread-expunge-below
1410     gnus-score-alist gnus-current-score-file
1411     (gnus-summary-expunge-below . global)
1412     (gnus-summary-mark-below . global)
1413     (gnus-orphan-score . global)
1414     gnus-newsgroup-active gnus-scores-exclude-files
1415     gnus-newsgroup-history gnus-newsgroup-ancient
1416     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1417     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1418     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1419     (gnus-newsgroup-expunged-tally . 0)
1420     gnus-cache-removable-articles gnus-newsgroup-cached
1421     gnus-newsgroup-data gnus-newsgroup-data-reverse
1422     gnus-newsgroup-limit gnus-newsgroup-limits
1423     gnus-newsgroup-charset gnus-newsgroup-display
1424     gnus-newsgroup-incorporated)
1425   "Variables that are buffer-local to the summary buffers.")
1426
1427 (defvar gnus-newsgroup-variables nil
1428   "A list of variables that have separate values in different newsgroups.
1429 A list of newsgroup (summary buffer) local variables, or cons of
1430 variables and their default values (when the default values are not
1431 nil), that should be made global while the summary buffer is active.
1432 These variables can be used to set variables in the group parameters
1433 while still allowing them to affect operations done in other
1434 buffers. For example:
1435
1436 \(setq gnus-newsgroup-variables
1437      '(message-use-followup-to
1438        (gnus-visible-headers .
1439          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1440 ")
1441
1442 ;; Byte-compiler warning.
1443 (eval-when-compile
1444   ;; Bind features so that require will believe that gnus-sum has
1445   ;; already been loaded (avoids infinite recursion)
1446   (let ((features (cons 'gnus-sum features)))
1447     ;; Several of the declarations in gnus-sum are needed to load the
1448     ;; following files. Right now, these definitions have been
1449     ;; compiled but not defined (evaluated).  We could either do a
1450     ;; eval-and-compile about all of the declarations or evaluate the
1451     ;; source file.
1452     (if (boundp 'gnus-newsgroup-variables)
1453         nil
1454       (load "gnus-sum.el" t t t))
1455     (require 'gnus)
1456     (require 'gnus-agent)
1457     (require 'gnus-art)))
1458
1459 ;; Subject simplification.
1460
1461 (defun gnus-simplify-whitespace (str)
1462   "Remove excessive whitespace from STR."
1463   ;; Multiple spaces.
1464   (while (string-match "[ \t][ \t]+" str)
1465     (setq str (concat (substring str 0 (match-beginning 0))
1466                         " "
1467                         (substring str (match-end 0)))))
1468   ;; Leading spaces.
1469   (when (string-match "^[ \t]+" str)
1470     (setq str (substring str (match-end 0))))
1471   ;; Trailing spaces.
1472   (when (string-match "[ \t]+$" str)
1473     (setq str (substring str 0 (match-beginning 0))))
1474   str)
1475
1476 (defun gnus-simplify-all-whitespace (str)
1477   "Remove all whitespace from STR."
1478   (while (string-match "[ \t\n]+" str)
1479     (setq str (replace-match "" nil nil str)))
1480   str)
1481
1482 (defsubst gnus-simplify-subject-re (subject)
1483   "Remove \"Re:\" from subject lines."
1484   (if (string-match message-subject-re-regexp subject)
1485       (substring subject (match-end 0))
1486     subject))
1487
1488 (defun gnus-simplify-subject (subject &optional re-only)
1489   "Remove `Re:' and words in parentheses.
1490 If RE-ONLY is non-nil, strip leading `Re:'s only."
1491   (let ((case-fold-search t))           ;Ignore case.
1492     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1493     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1494       (setq subject (substring subject (match-end 0))))
1495     ;; Remove uninteresting prefixes.
1496     (when (and (not re-only)
1497                gnus-simplify-ignored-prefixes
1498                (string-match gnus-simplify-ignored-prefixes subject))
1499       (setq subject (substring subject (match-end 0))))
1500     ;; Remove words in parentheses from end.
1501     (unless re-only
1502       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1503         (setq subject (substring subject 0 (match-beginning 0)))))
1504     ;; Return subject string.
1505     subject))
1506
1507 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1508 ;; all whitespace.
1509 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1510   (goto-char (point-min))
1511   (while (re-search-forward regexp nil t)
1512     (replace-match (or newtext ""))))
1513
1514 (defun gnus-simplify-buffer-fuzzy ()
1515   "Simplify string in the buffer fuzzily.
1516 The string in the accessible portion of the current buffer is simplified.
1517 It is assumed to be a single-line subject.
1518 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1519 matter is removed.  Additional things can be deleted by setting
1520 `gnus-simplify-subject-fuzzy-regexp'."
1521   (let ((case-fold-search t)
1522         (modified-tick))
1523     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1524
1525     (while (not (eq modified-tick (buffer-modified-tick)))
1526       (setq modified-tick (buffer-modified-tick))
1527       (cond
1528        ((listp gnus-simplify-subject-fuzzy-regexp)
1529         (mapcar 'gnus-simplify-buffer-fuzzy-step
1530                 gnus-simplify-subject-fuzzy-regexp))
1531        (gnus-simplify-subject-fuzzy-regexp
1532         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1533       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1534       (gnus-simplify-buffer-fuzzy-step
1535        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1536       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1537
1538     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1539     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1540     (gnus-simplify-buffer-fuzzy-step " $")
1541     (gnus-simplify-buffer-fuzzy-step "^ +")))
1542
1543 (defun gnus-simplify-subject-fuzzy (subject)
1544   "Simplify a subject string fuzzily.
1545 See `gnus-simplify-buffer-fuzzy' for details."
1546   (save-excursion
1547     (gnus-set-work-buffer)
1548     (let ((case-fold-search t))
1549       ;; Remove uninteresting prefixes.
1550       (when (and gnus-simplify-ignored-prefixes
1551                  (string-match gnus-simplify-ignored-prefixes subject))
1552         (setq subject (substring subject (match-end 0))))
1553       (insert subject)
1554       (inline (gnus-simplify-buffer-fuzzy))
1555       (buffer-string))))
1556
1557 (defsubst gnus-simplify-subject-fully (subject)
1558   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1559   (cond
1560    (gnus-simplify-subject-functions
1561     (gnus-map-function gnus-simplify-subject-functions subject))
1562    ((null gnus-summary-gather-subject-limit)
1563     (gnus-simplify-subject-re subject))
1564    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1565     (gnus-simplify-subject-fuzzy subject))
1566    ((numberp gnus-summary-gather-subject-limit)
1567     (gnus-limit-string (gnus-simplify-subject-re subject)
1568                        gnus-summary-gather-subject-limit))
1569    (t
1570     subject)))
1571
1572 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1573   "Check whether two subjects are equal.
1574 If optional argument SIMPLE-FIRST is t, first argument is already
1575 simplified."
1576   (cond
1577    ((null simple-first)
1578     (equal (gnus-simplify-subject-fully s1)
1579            (gnus-simplify-subject-fully s2)))
1580    (t
1581     (equal s1
1582            (gnus-simplify-subject-fully s2)))))
1583
1584 (defun gnus-summary-bubble-group ()
1585   "Increase the score of the current group.
1586 This is a handy function to add to `gnus-summary-exit-hook' to
1587 increase the score of each group you read."
1588   (gnus-group-add-score gnus-newsgroup-name))
1589
1590 \f
1591 ;;;
1592 ;;; Gnus summary mode
1593 ;;;
1594
1595 (put 'gnus-summary-mode 'mode-class 'special)
1596
1597 (defvar gnus-article-commands-menu)
1598
1599 ;; Non-orthogonal keys
1600
1601 (gnus-define-keys gnus-summary-mode-map
1602   " " gnus-summary-next-page
1603   "\177" gnus-summary-prev-page
1604   [delete] gnus-summary-prev-page
1605   [backspace] gnus-summary-prev-page
1606   "\r" gnus-summary-scroll-up
1607   "\M-\r" gnus-summary-scroll-down
1608   "n" gnus-summary-next-unread-article
1609   "p" gnus-summary-prev-unread-article
1610   "N" gnus-summary-next-article
1611   "P" gnus-summary-prev-article
1612   "\M-\C-n" gnus-summary-next-same-subject
1613   "\M-\C-p" gnus-summary-prev-same-subject
1614   "\M-n" gnus-summary-next-unread-subject
1615   "\M-p" gnus-summary-prev-unread-subject
1616   "." gnus-summary-first-unread-article
1617   "," gnus-summary-best-unread-article
1618   "\M-s" gnus-summary-search-article-forward
1619   "\M-r" gnus-summary-search-article-backward
1620   "<" gnus-summary-beginning-of-article
1621   ">" gnus-summary-end-of-article
1622   "j" gnus-summary-goto-article
1623   "^" gnus-summary-refer-parent-article
1624   "\M-^" gnus-summary-refer-article
1625   "u" gnus-summary-tick-article-forward
1626   "!" gnus-summary-tick-article-forward
1627   "U" gnus-summary-tick-article-backward
1628   "d" gnus-summary-mark-as-read-forward
1629   "D" gnus-summary-mark-as-read-backward
1630   "E" gnus-summary-mark-as-expirable
1631   "\M-u" gnus-summary-clear-mark-forward
1632   "\M-U" gnus-summary-clear-mark-backward
1633   "k" gnus-summary-kill-same-subject-and-select
1634   "\C-k" gnus-summary-kill-same-subject
1635   "\M-\C-k" gnus-summary-kill-thread
1636   "\M-\C-l" gnus-summary-lower-thread
1637   "e" gnus-summary-edit-article
1638   "#" gnus-summary-mark-as-processable
1639   "\M-#" gnus-summary-unmark-as-processable
1640   "\M-\C-t" gnus-summary-toggle-threads
1641   "\M-\C-s" gnus-summary-show-thread
1642   "\M-\C-h" gnus-summary-hide-thread
1643   "\M-\C-f" gnus-summary-next-thread
1644   "\M-\C-b" gnus-summary-prev-thread
1645   [(meta down)] gnus-summary-next-thread
1646   [(meta up)] gnus-summary-prev-thread
1647   "\M-\C-u" gnus-summary-up-thread
1648   "\M-\C-d" gnus-summary-down-thread
1649   "&" gnus-summary-execute-command
1650   "c" gnus-summary-catchup-and-exit
1651   "\C-w" gnus-summary-mark-region-as-read
1652   "\C-t" gnus-summary-toggle-truncation
1653   "?" gnus-summary-mark-as-dormant
1654   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1655   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1656   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1657   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1658   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1659   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1660   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1661   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1662   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1663   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1664   "=" gnus-summary-expand-window
1665   "\C-x\C-s" gnus-summary-reselect-current-group
1666   "\M-g" gnus-summary-rescan-group
1667   "w" gnus-summary-stop-page-breaking
1668   "\C-c\C-r" gnus-summary-caesar-message
1669   "\M-t" gnus-summary-toggle-mime
1670   "f" gnus-summary-followup
1671   "F" gnus-summary-followup-with-original
1672   "C" gnus-summary-cancel-article
1673   "r" gnus-summary-reply
1674   "R" gnus-summary-reply-with-original
1675   "\C-c\C-f" gnus-summary-mail-forward
1676   "o" gnus-summary-save-article
1677   "\C-o" gnus-summary-save-article-mail
1678   "|" gnus-summary-pipe-output
1679   "\M-k" gnus-summary-edit-local-kill
1680   "\M-K" gnus-summary-edit-global-kill
1681   ;; "V" gnus-version
1682   "\C-c\C-d" gnus-summary-describe-group
1683   "q" gnus-summary-exit
1684   "Q" gnus-summary-exit-no-update
1685   "\C-c\C-i" gnus-info-find-node
1686   gnus-mouse-2 gnus-mouse-pick-article
1687   "m" gnus-summary-mail-other-window
1688   "a" gnus-summary-post-news
1689   "i" gnus-summary-news-other-window
1690   "x" gnus-summary-limit-to-unread
1691   "s" gnus-summary-isearch-article
1692   "t" gnus-summary-toggle-header
1693   "g" gnus-summary-show-article
1694   "l" gnus-summary-goto-last-article
1695   "v" gnus-summary-preview-mime-message
1696   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1697   "\C-d" gnus-summary-enter-digest-group
1698   "\M-\C-d" gnus-summary-read-document
1699   "\M-\C-e" gnus-summary-edit-parameters
1700   "\M-\C-a" gnus-summary-customize-parameters
1701   "\C-c\C-b" gnus-bug
1702   "\C-c\C-n" gnus-namazu-search
1703   "*" gnus-cache-enter-article
1704   "\M-*" gnus-cache-remove-article
1705   "\M-&" gnus-summary-universal-argument
1706   "\C-l" gnus-recenter
1707   "I" gnus-summary-increase-score
1708   "L" gnus-summary-lower-score
1709   "\M-i" gnus-symbolic-argument
1710   "h" gnus-summary-select-article-buffer
1711
1712   "V" gnus-summary-score-map
1713   "X" gnus-uu-extract-map
1714   "S" gnus-summary-send-map)
1715
1716   ;; Sort of orthogonal keymap
1717 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1718   "t" gnus-summary-tick-article-forward
1719   "!" gnus-summary-tick-article-forward
1720   "d" gnus-summary-mark-as-read-forward
1721   "r" gnus-summary-mark-as-read-forward
1722   "c" gnus-summary-clear-mark-forward
1723   " " gnus-summary-clear-mark-forward
1724   "e" gnus-summary-mark-as-expirable
1725   "x" gnus-summary-mark-as-expirable
1726   "?" gnus-summary-mark-as-dormant
1727   "b" gnus-summary-set-bookmark
1728   "B" gnus-summary-remove-bookmark
1729   "#" gnus-summary-mark-as-processable
1730   "\M-#" gnus-summary-unmark-as-processable
1731   "S" gnus-summary-limit-include-expunged
1732   "C" gnus-summary-catchup
1733   "H" gnus-summary-catchup-to-here
1734   "h" gnus-summary-catchup-from-here
1735   "\C-c" gnus-summary-catchup-all
1736   "k" gnus-summary-kill-same-subject-and-select
1737   "K" gnus-summary-kill-same-subject
1738   "P" gnus-uu-mark-map)
1739
1740 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1741   "c" gnus-summary-clear-above
1742   "u" gnus-summary-tick-above
1743   "m" gnus-summary-mark-above
1744   "k" gnus-summary-kill-below)
1745
1746 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1747   "/" gnus-summary-limit-to-subject
1748   "n" gnus-summary-limit-to-articles
1749   "w" gnus-summary-pop-limit
1750   "s" gnus-summary-limit-to-subject
1751   "a" gnus-summary-limit-to-author
1752   "u" gnus-summary-limit-to-unread
1753   "m" gnus-summary-limit-to-marks
1754   "M" gnus-summary-limit-exclude-marks
1755   "v" gnus-summary-limit-to-score
1756   "*" gnus-summary-limit-include-cached
1757   "D" gnus-summary-limit-include-dormant
1758   "T" gnus-summary-limit-include-thread
1759   "d" gnus-summary-limit-exclude-dormant
1760   "t" gnus-summary-limit-to-age
1761   "." gnus-summary-limit-to-unseen
1762   "x" gnus-summary-limit-to-extra
1763   "p" gnus-summary-limit-to-display-predicate
1764   "E" gnus-summary-limit-include-expunged
1765   "c" gnus-summary-limit-exclude-childless-dormant
1766   "C" gnus-summary-limit-mark-excluded-as-read
1767   "o" gnus-summary-insert-old-articles
1768   "N" gnus-summary-insert-new-articles)
1769
1770 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1771   "n" gnus-summary-next-unread-article
1772   "p" gnus-summary-prev-unread-article
1773   "N" gnus-summary-next-article
1774   "P" gnus-summary-prev-article
1775   "\C-n" gnus-summary-next-same-subject
1776   "\C-p" gnus-summary-prev-same-subject
1777   "\M-n" gnus-summary-next-unread-subject
1778   "\M-p" gnus-summary-prev-unread-subject
1779   "f" gnus-summary-first-unread-article
1780   "b" gnus-summary-best-unread-article
1781   "j" gnus-summary-goto-article
1782   "g" gnus-summary-goto-subject
1783   "l" gnus-summary-goto-last-article
1784   "o" gnus-summary-pop-article)
1785
1786 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1787   "k" gnus-summary-kill-thread
1788   "l" gnus-summary-lower-thread
1789   "i" gnus-summary-raise-thread
1790   "T" gnus-summary-toggle-threads
1791   "t" gnus-summary-rethread-current
1792   "^" gnus-summary-reparent-thread
1793   "s" gnus-summary-show-thread
1794   "S" gnus-summary-show-all-threads
1795   "h" gnus-summary-hide-thread
1796   "H" gnus-summary-hide-all-threads
1797   "n" gnus-summary-next-thread
1798   "p" gnus-summary-prev-thread
1799   "u" gnus-summary-up-thread
1800   "o" gnus-summary-top-thread
1801   "d" gnus-summary-down-thread
1802   "#" gnus-uu-mark-thread
1803   "\M-#" gnus-uu-unmark-thread)
1804
1805 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1806   "g" gnus-summary-prepare
1807   "c" gnus-summary-insert-cached-articles
1808   "d" gnus-summary-insert-dormant-articles)
1809
1810 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1811   "c" gnus-summary-catchup-and-exit
1812   "C" gnus-summary-catchup-all-and-exit
1813   "E" gnus-summary-exit-no-update
1814   "J" gnus-summary-jump-to-other-group
1815   "Q" gnus-summary-exit
1816   "Z" gnus-summary-exit
1817   "n" gnus-summary-catchup-and-goto-next-group
1818   "R" gnus-summary-reselect-current-group
1819   "G" gnus-summary-rescan-group
1820   "N" gnus-summary-next-group
1821   "s" gnus-summary-save-newsrc
1822   "P" gnus-summary-prev-group)
1823
1824 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1825   " " gnus-summary-next-page
1826   "n" gnus-summary-next-page
1827   "\177" gnus-summary-prev-page
1828   [delete] gnus-summary-prev-page
1829   "p" gnus-summary-prev-page
1830   "\r" gnus-summary-scroll-up
1831   "\M-\r" gnus-summary-scroll-down
1832   "<" gnus-summary-beginning-of-article
1833   ">" gnus-summary-end-of-article
1834   "b" gnus-summary-beginning-of-article
1835   "e" gnus-summary-end-of-article
1836   "^" gnus-summary-refer-parent-article
1837   "r" gnus-summary-refer-parent-article
1838   "D" gnus-summary-enter-digest-group
1839   "R" gnus-summary-refer-references
1840   "T" gnus-summary-refer-thread
1841   "g" gnus-summary-show-article
1842   "s" gnus-summary-isearch-article
1843   "P" gnus-summary-print-article
1844   "M" gnus-mailing-list-insinuate
1845   "t" gnus-article-babel)
1846
1847 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1848   "b" gnus-article-add-buttons
1849   "B" gnus-article-add-buttons-to-head
1850   "o" gnus-article-treat-overstrike
1851   "e" gnus-article-emphasize
1852   "w" gnus-article-fill-cited-article
1853   "Q" gnus-article-fill-long-lines
1854   "C" gnus-article-capitalize-sentences
1855   "c" gnus-article-remove-cr
1856   "Z" gnus-article-decode-HZ
1857   "h" gnus-article-wash-html
1858   "u" gnus-article-unsplit-urls
1859   "f" gnus-article-display-x-face
1860   "l" gnus-summary-stop-page-breaking
1861   "r" gnus-summary-caesar-message
1862   "m" gnus-summary-morse-message
1863   "t" gnus-summary-toggle-header
1864   "g" gnus-treat-smiley
1865   "v" gnus-summary-verbose-headers
1866   "m" gnus-summary-toggle-mime
1867   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1868   "p" gnus-article-verify-x-pgp-sig
1869   "d" gnus-article-treat-dumbquotes)
1870
1871 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1872   ;; mnemonic: deuglif*Y*
1873   "u" gnus-article-outlook-unwrap-lines
1874   "a" gnus-article-outlook-repair-attribution
1875   "c" gnus-article-outlook-rearrange-citation
1876   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1877
1878 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1879   "a" gnus-article-hide
1880   "h" gnus-article-hide-headers
1881   "b" gnus-article-hide-boring-headers
1882   "s" gnus-article-hide-signature
1883   "c" gnus-article-hide-citation
1884   "C" gnus-article-hide-citation-in-followups
1885   "l" gnus-article-hide-list-identifiers
1886   "B" gnus-article-strip-banner
1887   "P" gnus-article-hide-pem
1888   "\C-c" gnus-article-hide-citation-maybe)
1889
1890 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1891   "a" gnus-article-highlight
1892   "h" gnus-article-highlight-headers
1893   "c" gnus-article-highlight-citation
1894   "s" gnus-article-highlight-signature)
1895
1896 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1897   "f" gnus-article-treat-fold-headers
1898   "u" gnus-article-treat-unfold-headers
1899   "n" gnus-article-treat-fold-newsgroups)
1900
1901 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1902   "x" gnus-article-display-x-face
1903   "d" gnus-article-display-face
1904   "s" gnus-treat-smiley
1905   "D" gnus-article-remove-images
1906   "f" gnus-treat-from-picon
1907   "m" gnus-treat-mail-picon
1908   "n" gnus-treat-newsgroups-picon)
1909
1910 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1911   "z" gnus-article-date-ut
1912   "u" gnus-article-date-ut
1913   "l" gnus-article-date-local
1914   "p" gnus-article-date-english
1915   "e" gnus-article-date-lapsed
1916   "o" gnus-article-date-original
1917   "i" gnus-article-date-iso8601
1918   "s" gnus-article-date-user)
1919
1920 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1921   "t" gnus-article-remove-trailing-blank-lines
1922   "l" gnus-article-strip-leading-blank-lines
1923   "m" gnus-article-strip-multiple-blank-lines
1924   "a" gnus-article-strip-blank-lines
1925   "A" gnus-article-strip-all-blank-lines
1926   "s" gnus-article-strip-leading-space
1927   "e" gnus-article-strip-trailing-space
1928   "w" gnus-article-remove-leading-whitespace)
1929
1930 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1931   "v" gnus-version
1932   "f" gnus-summary-fetch-faq
1933   "d" gnus-summary-describe-group
1934   "h" gnus-summary-describe-briefly
1935   "i" gnus-info-find-node
1936   "c" gnus-group-fetch-charter
1937   "C" gnus-group-fetch-control)
1938
1939 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1940   "e" gnus-summary-expire-articles
1941   "\M-\C-e" gnus-summary-expire-articles-now
1942   "\177" gnus-summary-delete-article
1943   [delete] gnus-summary-delete-article
1944   [backspace] gnus-summary-delete-article
1945   "m" gnus-summary-move-article
1946   "r" gnus-summary-respool-article
1947   "w" gnus-summary-edit-article
1948   "c" gnus-summary-copy-article
1949   "B" gnus-summary-crosspost-article
1950   "q" gnus-summary-respool-query
1951   "t" gnus-summary-respool-trace
1952   "i" gnus-summary-import-article
1953   "I" gnus-summary-create-article
1954   "p" gnus-summary-article-posted-p)
1955
1956 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1957   "o" gnus-summary-save-article
1958   "m" gnus-summary-save-article-mail
1959   "F" gnus-summary-write-article-file
1960   "r" gnus-summary-save-article-rmail
1961   "f" gnus-summary-save-article-file
1962   "b" gnus-summary-save-article-body-file
1963   "h" gnus-summary-save-article-folder
1964   "v" gnus-summary-save-article-vm
1965   "p" gnus-summary-pipe-output
1966   "P" gnus-summary-muttprint
1967   "s" gnus-soup-add-article)
1968
1969 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1970   "b" gnus-summary-display-buttonized
1971   "m" gnus-summary-repair-multipart
1972   "v" gnus-article-view-part
1973   "o" gnus-article-save-part
1974   "c" gnus-article-copy-part
1975   "C" gnus-article-view-part-as-charset
1976   "e" gnus-article-view-part-externally
1977   "E" gnus-article-encrypt-body
1978   "i" gnus-article-inline-part
1979   "|" gnus-article-pipe-part)
1980
1981 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1982   "p" gnus-summary-mark-as-processable
1983   "u" gnus-summary-unmark-as-processable
1984   "U" gnus-summary-unmark-all-processable
1985   "v" gnus-uu-mark-over
1986   "s" gnus-uu-mark-series
1987   "r" gnus-uu-mark-region
1988   "g" gnus-uu-unmark-region
1989   "R" gnus-uu-mark-by-regexp
1990   "G" gnus-uu-unmark-by-regexp
1991   "t" gnus-uu-mark-thread
1992   "T" gnus-uu-unmark-thread
1993   "a" gnus-uu-mark-all
1994   "b" gnus-uu-mark-buffer
1995   "S" gnus-uu-mark-sparse
1996   "k" gnus-summary-kill-process-mark
1997   "y" gnus-summary-yank-process-mark
1998   "w" gnus-summary-save-process-mark
1999   "i" gnus-uu-invert-processable)
2000
2001 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2002   ;;"x" gnus-uu-extract-any
2003   "m" gnus-summary-save-parts
2004   "u" gnus-uu-decode-uu
2005   "U" gnus-uu-decode-uu-and-save
2006   "s" gnus-uu-decode-unshar
2007   "S" gnus-uu-decode-unshar-and-save
2008   "o" gnus-uu-decode-save
2009   "O" gnus-uu-decode-save
2010   "b" gnus-uu-decode-binhex
2011   "B" gnus-uu-decode-binhex
2012   "p" gnus-uu-decode-postscript
2013   "P" gnus-uu-decode-postscript-and-save)
2014
2015 (gnus-define-keys
2016     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2017   "u" gnus-uu-decode-uu-view
2018   "U" gnus-uu-decode-uu-and-save-view
2019   "s" gnus-uu-decode-unshar-view
2020   "S" gnus-uu-decode-unshar-and-save-view
2021   "o" gnus-uu-decode-save-view
2022   "O" gnus-uu-decode-save-view
2023   "b" gnus-uu-decode-binhex-view
2024   "B" gnus-uu-decode-binhex-view
2025   "p" gnus-uu-decode-postscript-view
2026   "P" gnus-uu-decode-postscript-and-save-view)
2027
2028 (defvar gnus-article-post-menu nil)
2029
2030 (defconst gnus-summary-menu-maxlen 20)
2031
2032 (defun gnus-summary-menu-split (menu)
2033   ;; If we have lots of elements, divide them into groups of 20
2034   ;; and make a pane (or submenu) for each one.
2035   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2036       (let ((menu menu) sublists next
2037             (i 1))
2038         (while menu
2039           ;; Pull off the next gnus-summary-menu-maxlen elements
2040           ;; and make them the next element of sublist.
2041           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2042           (if next
2043               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2044                       nil))
2045           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2046                                              (aref (car (last menu)) 0)) menu)
2047                                sublists))
2048           (setq i (1+ i))
2049           (setq menu next))
2050         (nreverse sublists))
2051     ;; Few elements--put them all in one pane.
2052     menu))
2053
2054 (defun gnus-summary-make-menu-bar ()
2055   (gnus-turn-off-edit-menu 'summary)
2056
2057   (unless (boundp 'gnus-summary-misc-menu)
2058
2059     (easy-menu-define
2060      gnus-summary-kill-menu gnus-summary-mode-map ""
2061      (cons
2062       "Score"
2063       (nconc
2064        (list
2065         ["Customize" gnus-score-customize t])
2066        (gnus-make-score-map 'increase)
2067        (gnus-make-score-map 'lower)
2068        '(("Mark"
2069           ["Kill below" gnus-summary-kill-below t]
2070           ["Mark above" gnus-summary-mark-above t]
2071           ["Tick above" gnus-summary-tick-above t]
2072           ["Clear above" gnus-summary-clear-above t])
2073          ["Current score" gnus-summary-current-score t]
2074          ["Set score" gnus-summary-set-score t]
2075          ["Switch current score file..." gnus-score-change-score-file t]
2076          ["Set mark below..." gnus-score-set-mark-below t]
2077          ["Set expunge below..." gnus-score-set-expunge-below t]
2078          ["Edit current score file" gnus-score-edit-current-scores t]
2079          ["Edit score file" gnus-score-edit-file t]
2080          ["Trace score" gnus-score-find-trace t]
2081          ["Find words" gnus-score-find-favourite-words t]
2082          ["Rescore buffer" gnus-summary-rescore t]
2083          ["Increase score..." gnus-summary-increase-score t]
2084          ["Lower score..." gnus-summary-lower-score t]))))
2085
2086     ;; Define both the Article menu in the summary buffer and the
2087     ;; equivalent Commands menu in the article buffer here for
2088     ;; consistency.
2089     (let ((innards
2090            `(("Hide"
2091               ["All" gnus-article-hide t]
2092               ["Headers" gnus-article-hide-headers t]
2093               ["Signature" gnus-article-hide-signature t]
2094               ["Citation" gnus-article-hide-citation t]
2095               ["List identifiers" gnus-article-hide-list-identifiers t]
2096               ["Banner" gnus-article-strip-banner t]
2097               ["Boring headers" gnus-article-hide-boring-headers t])
2098              ("Highlight"
2099               ["All" gnus-article-highlight t]
2100               ["Headers" gnus-article-highlight-headers t]
2101               ["Signature" gnus-article-highlight-signature t]
2102               ["Citation" gnus-article-highlight-citation t])
2103              ("Date"
2104               ["Local" gnus-article-date-local t]
2105               ["ISO8601" gnus-article-date-iso8601 t]
2106               ["UT" gnus-article-date-ut t]
2107               ["Original" gnus-article-date-original t]
2108               ["Lapsed" gnus-article-date-lapsed t]
2109               ["User-defined" gnus-article-date-user t])
2110              ("Display"
2111               ["Remove images" gnus-article-remove-images t]
2112               ["Toggle smiley" gnus-treat-smiley t]
2113               ["Show X-Face" gnus-article-display-x-face t]
2114               ["Show picons in From" gnus-treat-from-picon t]
2115               ["Show picons in mail headers" gnus-treat-mail-picon t]
2116               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2117               ("View as different encoding"
2118                ,@(gnus-summary-menu-split
2119                   (mapcar
2120                    (lambda (cs)
2121                      ;; Since easymenu under Emacs doesn't allow
2122                      ;; lambda forms for menu commands, we should
2123                      ;; provide intern'ed function symbols.
2124                      (let ((command (intern (format "\
2125 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2126                        (fset command
2127                              `(lambda ()
2128                                 (interactive)
2129                                 (let ((gnus-summary-show-article-charset-alist
2130                                        '((1 . ,cs))))
2131                                   (gnus-summary-show-article 1))))
2132                        `[,(symbol-name cs) ,command t]))
2133                    (sort (if (fboundp 'coding-system-list)
2134                              (coding-system-list)
2135                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2136                            )
2137                          'string<)))))
2138              ("Washing"
2139               ("Remove Blanks"
2140                ["Leading" gnus-article-strip-leading-blank-lines t]
2141                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2142                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2143                ["All of the above" gnus-article-strip-blank-lines t]
2144                ["All" gnus-article-strip-all-blank-lines t]
2145                ["Leading space" gnus-article-strip-leading-space t]
2146                ["Trailing space" gnus-article-strip-trailing-space t]
2147                ["Leading space in headers"
2148                 gnus-article-remove-leading-whitespace t])
2149               ["Overstrike" gnus-article-treat-overstrike t]
2150               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2151               ["Emphasis" gnus-article-emphasize t]
2152               ["Word wrap" gnus-article-fill-cited-article t]
2153               ["Fill long lines" gnus-article-fill-long-lines t]
2154               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2155               ["CR" gnus-article-remove-cr t]
2156               ["Rot 13" gnus-summary-caesar-message
2157                ,@(if (featurep 'xemacs) '(t)
2158                    '(:help "\"Caesar rotate\" article by 13"))]
2159               ["Morse decode" gnus-summary-morse-message t]
2160               ["Unix pipe..." gnus-summary-pipe-message t]
2161               ["Add buttons" gnus-article-add-buttons t]
2162               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2163               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2164               ["Toggle MIME" gnus-summary-toggle-mime t]
2165               ["Verbose header" gnus-summary-verbose-headers t]
2166               ["Toggle header" gnus-summary-toggle-header t]
2167               ["Unfold headers" gnus-article-treat-unfold-headers t]
2168               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2169               ["Html" gnus-article-wash-html t]
2170               ["URLs" gnus-article-unsplit-urls t]
2171               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2172               ["HZ" gnus-article-decode-HZ t]
2173               ("(Outlook) Deuglify"
2174                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2175                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2176                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2177                ["Full (Outlook) deuglify"
2178                 gnus-article-outlook-deuglify-article t])
2179               )
2180              ("Output"
2181               ["Save in default format" gnus-summary-save-article
2182                ,@(if (featurep 'xemacs) '(t)
2183                    '(:help "Save article using default method"))]
2184               ["Save in file" gnus-summary-save-article-file
2185                ,@(if (featurep 'xemacs) '(t)
2186                    '(:help "Save article in file"))]
2187               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2188               ["Save in MH folder" gnus-summary-save-article-folder t]
2189               ["Save in VM folder" gnus-summary-save-article-vm t]
2190               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2191               ["Save body in file" gnus-summary-save-article-body-file t]
2192               ["Pipe through a filter" gnus-summary-pipe-output t]
2193               ["Add to SOUP packet" gnus-soup-add-article t]
2194               ["Print with Muttprint" gnus-summary-muttprint t]
2195               ["Print" gnus-summary-print-article t])
2196              ("Backend"
2197               ["Respool article..." gnus-summary-respool-article t]
2198               ["Move article..." gnus-summary-move-article
2199                (gnus-check-backend-function
2200                 'request-move-article gnus-newsgroup-name)]
2201               ["Copy article..." gnus-summary-copy-article t]
2202               ["Crosspost article..." gnus-summary-crosspost-article
2203                (gnus-check-backend-function
2204                 'request-replace-article gnus-newsgroup-name)]
2205               ["Import file..." gnus-summary-import-article
2206                (gnus-check-backend-function
2207                 'request-accept-article gnus-newsgroup-name)]
2208               ["Create article..." gnus-summary-create-article
2209                (gnus-check-backend-function
2210                 'request-accept-article gnus-newsgroup-name)]
2211               ["Check if posted" gnus-summary-article-posted-p t]
2212               ["Edit article" gnus-summary-edit-article
2213                (not (gnus-group-read-only-p))]
2214               ["Delete article" gnus-summary-delete-article
2215                (gnus-check-backend-function
2216                 'request-expire-articles gnus-newsgroup-name)]
2217               ["Query respool" gnus-summary-respool-query t]
2218               ["Trace respool" gnus-summary-respool-trace t]
2219               ["Delete expirable articles" gnus-summary-expire-articles-now
2220                (gnus-check-backend-function
2221                 'request-expire-articles gnus-newsgroup-name)])
2222              ("Extract"
2223               ["Uudecode" gnus-uu-decode-uu
2224                ,@(if (featurep 'xemacs) '(t)
2225                    '(:help "Decode uuencoded article(s)"))]
2226               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2227               ["Unshar" gnus-uu-decode-unshar t]
2228               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2229               ["Save" gnus-uu-decode-save t]
2230               ["Binhex" gnus-uu-decode-binhex t]
2231               ["Postscript" gnus-uu-decode-postscript t])
2232              ("Cache"
2233               ["Enter article" gnus-cache-enter-article t]
2234               ["Remove article" gnus-cache-remove-article t])
2235              ["Translate" gnus-article-babel t]
2236              ["Select article buffer" gnus-summary-select-article-buffer t]
2237              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2238              ["Isearch article..." gnus-summary-isearch-article t]
2239              ["Beginning of the article" gnus-summary-beginning-of-article t]
2240              ["End of the article" gnus-summary-end-of-article t]
2241              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2242              ["Fetch referenced articles" gnus-summary-refer-references t]
2243              ["Fetch current thread" gnus-summary-refer-thread t]
2244              ["Fetch article with id..." gnus-summary-refer-article t]
2245              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2246              ["Redisplay" gnus-summary-show-article t]
2247              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2248       (easy-menu-define
2249        gnus-summary-article-menu gnus-summary-mode-map ""
2250        (cons "Article" innards))
2251
2252       (if (not (keymapp gnus-summary-article-menu))
2253           (easy-menu-define
2254            gnus-article-commands-menu gnus-article-mode-map ""
2255            (cons "Commands" innards))
2256         ;; in Emacs, don't share menu.
2257         (setq gnus-article-commands-menu
2258               (copy-keymap gnus-summary-article-menu))
2259         (define-key gnus-article-mode-map [menu-bar commands]
2260           (cons "Commands" gnus-article-commands-menu))))
2261
2262     (easy-menu-define
2263      gnus-summary-thread-menu gnus-summary-mode-map ""
2264      '("Threads"
2265        ["Find all messages in thread" gnus-summary-refer-thread t]
2266        ["Toggle threading" gnus-summary-toggle-threads t]
2267        ["Hide threads" gnus-summary-hide-all-threads t]
2268        ["Show threads" gnus-summary-show-all-threads t]
2269        ["Hide thread" gnus-summary-hide-thread t]
2270        ["Show thread" gnus-summary-show-thread t]
2271        ["Go to next thread" gnus-summary-next-thread t]
2272        ["Go to previous thread" gnus-summary-prev-thread t]
2273        ["Go down thread" gnus-summary-down-thread t]
2274        ["Go up thread" gnus-summary-up-thread t]
2275        ["Top of thread" gnus-summary-top-thread t]
2276        ["Mark thread as read" gnus-summary-kill-thread t]
2277        ["Lower thread score" gnus-summary-lower-thread t]
2278        ["Raise thread score" gnus-summary-raise-thread t]
2279        ["Rethread current" gnus-summary-rethread-current t]))
2280
2281     (easy-menu-define
2282      gnus-summary-post-menu gnus-summary-mode-map ""
2283      `("Post"
2284        ["Send a message (mail or news)" gnus-summary-post-news
2285         ,@(if (featurep 'xemacs) '(t)
2286             '(:help "Post an article"))]
2287        ["Followup" gnus-summary-followup
2288         ,@(if (featurep 'xemacs) '(t)
2289             '(:help "Post followup to this article"))]
2290        ["Followup and yank" gnus-summary-followup-with-original
2291         ,@(if (featurep 'xemacs) '(t)
2292             '(:help "Post followup to this article, quoting its contents"))]
2293        ["Supersede article" gnus-summary-supersede-article t]
2294        ["Cancel article" gnus-summary-cancel-article
2295         ,@(if (featurep 'xemacs) '(t)
2296             '(:help "Cancel an article you posted"))]
2297        ["Reply" gnus-summary-reply t]
2298        ["Reply and yank" gnus-summary-reply-with-original t]
2299        ["Wide reply" gnus-summary-wide-reply t]
2300        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2301         ,@(if (featurep 'xemacs) '(t)
2302             '(:help "Mail a reply, quoting this article"))]
2303        ["Very wide reply" gnus-summary-very-wide-reply t]
2304        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2305         ,@(if (featurep 'xemacs) '(t)
2306             '(:help "Mail a very wide reply, quoting this article"))]
2307        ["Mail forward" gnus-summary-mail-forward t]
2308        ["Post forward" gnus-summary-post-forward t]
2309        ["Digest and mail" gnus-summary-digest-mail-forward t]
2310        ["Digest and post" gnus-summary-digest-post-forward t]
2311        ["Resend message" gnus-summary-resend-message t]
2312        ["Resend message edit" gnus-summary-resend-message-edit t]
2313        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2314        ["Send a mail" gnus-summary-mail-other-window t]
2315        ["Create a local message" gnus-summary-news-other-window t]
2316        ["Uuencode and post" gnus-uu-post-news
2317         ,@(if (featurep 'xemacs) '(t)
2318             '(:help "Post a uuencoded article"))]
2319        ["Followup via news" gnus-summary-followup-to-mail t]
2320        ["Followup via news and yank"
2321         gnus-summary-followup-to-mail-with-original t]
2322        ;;("Draft"
2323        ;;["Send" gnus-summary-send-draft t]
2324        ;;["Send bounced" gnus-resend-bounced-mail t])
2325        ))
2326
2327     (cond
2328      ((not (keymapp gnus-summary-post-menu))
2329       (setq gnus-article-post-menu gnus-summary-post-menu))
2330      ((not gnus-article-post-menu)
2331       ;; Don't share post menu.
2332       (setq gnus-article-post-menu
2333             (copy-keymap gnus-summary-post-menu))))
2334     (define-key gnus-article-mode-map [menu-bar post]
2335       (cons "Post" gnus-article-post-menu))
2336
2337     (easy-menu-define
2338      gnus-summary-misc-menu gnus-summary-mode-map ""
2339      `("Gnus"
2340        ("Mark Read"
2341         ["Mark as read" gnus-summary-mark-as-read-forward t]
2342         ["Mark same subject and select"
2343          gnus-summary-kill-same-subject-and-select t]
2344         ["Mark same subject" gnus-summary-kill-same-subject t]
2345         ["Catchup" gnus-summary-catchup
2346          ,@(if (featurep 'xemacs) '(t)
2347              '(:help "Mark unread articles in this group as read"))]
2348         ["Catchup all" gnus-summary-catchup-all t]
2349         ["Catchup to here" gnus-summary-catchup-to-here t]
2350         ["Catchup from here" gnus-summary-catchup-from-here t]
2351         ["Catchup region" gnus-summary-mark-region-as-read
2352          (gnus-mark-active-p)]
2353         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2354        ("Mark Various"
2355         ["Tick" gnus-summary-tick-article-forward t]
2356         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2357         ["Remove marks" gnus-summary-clear-mark-forward t]
2358         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2359         ["Set bookmark" gnus-summary-set-bookmark t]
2360         ["Remove bookmark" gnus-summary-remove-bookmark t])
2361        ("Limit to"
2362         ["Marks..." gnus-summary-limit-to-marks t]
2363         ["Subject..." gnus-summary-limit-to-subject t]
2364         ["Author..." gnus-summary-limit-to-author t]
2365         ["Age..." gnus-summary-limit-to-age t]
2366         ["Extra..." gnus-summary-limit-to-extra t]
2367         ["Score..." gnus-summary-limit-to-score t]
2368         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2369         ["Unread" gnus-summary-limit-to-unread t]
2370         ["Unseen" gnus-summary-limit-to-unseen t]
2371         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2372         ["Next articles" gnus-summary-limit-to-articles t]
2373         ["Pop limit" gnus-summary-pop-limit t]
2374         ["Show dormant" gnus-summary-limit-include-dormant t]
2375         ["Hide childless dormant"
2376          gnus-summary-limit-exclude-childless-dormant t]
2377         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2378         ["Hide marked" gnus-summary-limit-exclude-marks t]
2379         ["Show expunged" gnus-summary-limit-include-expunged t])
2380        ("Process Mark"
2381         ["Set mark" gnus-summary-mark-as-processable t]
2382         ["Remove mark" gnus-summary-unmark-as-processable t]
2383         ["Remove all marks" gnus-summary-unmark-all-processable t]
2384         ["Mark above" gnus-uu-mark-over t]
2385         ["Mark series" gnus-uu-mark-series t]
2386         ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2387         ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2388         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2389         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2390         ["Mark all" gnus-uu-mark-all t]
2391         ["Mark buffer" gnus-uu-mark-buffer t]
2392         ["Mark sparse" gnus-uu-mark-sparse t]
2393         ["Mark thread" gnus-uu-mark-thread t]
2394         ["Unmark thread" gnus-uu-unmark-thread t]
2395         ("Process Mark Sets"
2396          ["Kill" gnus-summary-kill-process-mark t]
2397          ["Yank" gnus-summary-yank-process-mark
2398           gnus-newsgroup-process-stack]
2399          ["Save" gnus-summary-save-process-mark t]
2400          ["Run command on marked..." gnus-summary-universal-argument t]))
2401        ("Scroll article"
2402         ["Page forward" gnus-summary-next-page
2403          ,@(if (featurep 'xemacs) '(t)
2404              '(:help "Show next page of article"))]
2405         ["Page backward" gnus-summary-prev-page
2406          ,@(if (featurep 'xemacs) '(t)
2407              '(:help "Show previous page of article"))]
2408         ["Line forward" gnus-summary-scroll-up t])
2409        ("Move"
2410         ["Next unread article" gnus-summary-next-unread-article t]
2411         ["Previous unread article" gnus-summary-prev-unread-article t]
2412         ["Next article" gnus-summary-next-article t]
2413         ["Previous article" gnus-summary-prev-article t]
2414         ["Next unread subject" gnus-summary-next-unread-subject t]
2415         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2416         ["Next article same subject" gnus-summary-next-same-subject t]
2417         ["Previous article same subject" gnus-summary-prev-same-subject t]
2418         ["First unread article" gnus-summary-first-unread-article t]
2419         ["Best unread article" gnus-summary-best-unread-article t]
2420         ["Go to subject number..." gnus-summary-goto-subject t]
2421         ["Go to article number..." gnus-summary-goto-article t]
2422         ["Go to the last article" gnus-summary-goto-last-article t]
2423         ["Pop article off history" gnus-summary-pop-article t])
2424        ("Sort"
2425         ["Sort by number" gnus-summary-sort-by-number t]
2426         ["Sort by author" gnus-summary-sort-by-author t]
2427         ["Sort by subject" gnus-summary-sort-by-subject t]
2428         ["Sort by date" gnus-summary-sort-by-date t]
2429         ["Sort by score" gnus-summary-sort-by-score t]
2430         ["Sort by lines" gnus-summary-sort-by-lines t]
2431         ["Sort by characters" gnus-summary-sort-by-chars t]
2432         ["Randomize" gnus-summary-sort-by-random t]
2433         ["Original sort" gnus-summary-sort-by-original t])
2434        ("Help"
2435         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2436         ["Describe group" gnus-summary-describe-group t]
2437         ["Fetch charter" gnus-group-fetch-charter
2438          ,@(if (featurep 'xemacs) nil
2439              '(:help "Display the charter of the current group"))]
2440         ["Fetch control message" gnus-group-fetch-control
2441          ,@(if (featurep 'xemacs) nil
2442              '(:help "Display the archived control message for the current group"))]
2443         ["Read manual" gnus-info-find-node t])
2444        ("Modes"
2445         ["Pick and read" gnus-pick-mode t]
2446         ["Binary" gnus-binary-mode t])
2447        ("Regeneration"
2448         ["Regenerate" gnus-summary-prepare t]
2449         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2450         ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2451         ["Toggle threading" gnus-summary-toggle-threads t])
2452        ["See old articles" gnus-summary-insert-old-articles t]
2453        ["See new articles" gnus-summary-insert-new-articles t]
2454        ["Filter articles..." gnus-summary-execute-command t]
2455        ["Run command on articles..." gnus-summary-universal-argument t]
2456        ["Search articles forward..." gnus-summary-search-article-forward t]
2457        ["Search articles backward..." gnus-summary-search-article-backward t]
2458        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2459        ["Expand window" gnus-summary-expand-window t]
2460        ["Expire expirable articles" gnus-summary-expire-articles
2461         (gnus-check-backend-function
2462          'request-expire-articles gnus-newsgroup-name)]
2463        ["Edit local kill file" gnus-summary-edit-local-kill t]
2464        ["Edit main kill file" gnus-summary-edit-global-kill t]
2465        ["Edit group parameters" gnus-summary-edit-parameters t]
2466        ["Customize group parameters" gnus-summary-customize-parameters t]
2467        ["Send a bug report" gnus-bug t]
2468        ("Exit"
2469         ["Catchup and exit" gnus-summary-catchup-and-exit
2470          ,@(if (featurep 'xemacs) '(t)
2471              '(:help "Mark unread articles in this group as read, then exit"))]
2472         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2473         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2474         ["Exit group" gnus-summary-exit
2475          ,@(if (featurep 'xemacs) '(t)
2476              '(:help "Exit current group, return to group selection mode"))]
2477         ["Exit group without updating" gnus-summary-exit-no-update t]
2478         ["Exit and goto next group" gnus-summary-next-group t]
2479         ["Exit and goto prev group" gnus-summary-prev-group t]
2480         ["Reselect group" gnus-summary-reselect-current-group t]
2481         ["Rescan group" gnus-summary-rescan-group t]
2482         ["Update dribble" gnus-summary-save-newsrc t])))
2483
2484     (gnus-run-hooks 'gnus-summary-menu-hook)))
2485
2486 (defvar gnus-summary-tool-bar-map nil)
2487
2488 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2489 (defun gnus-summary-make-tool-bar ()
2490   (if (and (fboundp 'tool-bar-add-item-from-menu)
2491            (default-value 'tool-bar-mode)
2492            (not gnus-summary-tool-bar-map))
2493       (setq gnus-summary-tool-bar-map
2494             (let ((tool-bar-map (make-sparse-keymap))
2495                   (load-path (mm-image-load-path)))
2496               (tool-bar-add-item-from-menu
2497                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2498               (tool-bar-add-item-from-menu
2499                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2500               (tool-bar-add-item-from-menu
2501                'gnus-summary-post-news "post" gnus-summary-mode-map)
2502               (tool-bar-add-item-from-menu
2503                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2504               (tool-bar-add-item-from-menu
2505                'gnus-summary-followup "followup" gnus-summary-mode-map)
2506               (tool-bar-add-item-from-menu
2507                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2508               (tool-bar-add-item-from-menu
2509                'gnus-summary-reply "reply" gnus-summary-mode-map)
2510               (tool-bar-add-item-from-menu
2511                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2512               (tool-bar-add-item-from-menu
2513                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2514               (tool-bar-add-item-from-menu
2515                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2516               (tool-bar-add-item-from-menu
2517                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2518               (tool-bar-add-item-from-menu
2519                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2520               (tool-bar-add-item-from-menu
2521                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2522               (tool-bar-add-item-from-menu
2523                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2524               (tool-bar-add-item-from-menu
2525                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2526               tool-bar-map)))
2527   (if gnus-summary-tool-bar-map
2528       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2529
2530 (defun gnus-score-set-default (var value)
2531   "A version of set that updates the GNU Emacs menu-bar."
2532   (set var value)
2533   ;; It is the message that forces the active status to be updated.
2534   (message ""))
2535
2536 (defun gnus-make-score-map (type)
2537   "Make a summary score map of type TYPE."
2538   (if t
2539       nil
2540     (let ((headers '(("author" "from" string)
2541                      ("subject" "subject" string)
2542                      ("article body" "body" string)
2543                      ("article head" "head" string)
2544                      ("xref" "xref" string)
2545                      ("extra header" "extra" string)
2546                      ("lines" "lines" number)
2547                      ("followups to author" "followup" string)))
2548           (types '((number ("less than" <)
2549                            ("greater than" >)
2550                            ("equal" =))
2551                    (string ("substring" s)
2552                            ("exact string" e)
2553                            ("fuzzy string" f)
2554                            ("regexp" r))))
2555           (perms '(("temporary" (current-time-string))
2556                    ("permanent" nil)
2557                    ("immediate" now)))
2558           header)
2559       (list
2560        (apply
2561         'nconc
2562         (list
2563          (if (eq type 'lower)
2564              "Lower score"
2565            "Increase score"))
2566         (let (outh)
2567           (while headers
2568             (setq header (car headers))
2569             (setq outh
2570                   (cons
2571                    (apply
2572                     'nconc
2573                     (list (car header))
2574                     (let ((ts (cdr (assoc (nth 2 header) types)))
2575                           outt)
2576                       (while ts
2577                         (setq outt
2578                               (cons
2579                                (apply
2580                                 'nconc
2581                                 (list (caar ts))
2582                                 (let ((ps perms)
2583                                       outp)
2584                                   (while ps
2585                                     (setq outp
2586                                           (cons
2587                                            (vector
2588                                             (caar ps)
2589                                             (list
2590                                              'gnus-summary-score-entry
2591                                              (nth 1 header)
2592                                              (if (or (string= (nth 1 header)
2593                                                               "head")
2594                                                      (string= (nth 1 header)
2595                                                               "body"))
2596                                                  ""
2597                                                (list 'gnus-summary-header
2598                                                      (nth 1 header)))
2599                                              (list 'quote (nth 1 (car ts)))
2600                                              (list 'gnus-score-delta-default
2601                                                    nil)
2602                                              (nth 1 (car ps))
2603                                              t)
2604                                             t)
2605                                            outp))
2606                                     (setq ps (cdr ps)))
2607                                   (list (nreverse outp))))
2608                                outt))
2609                         (setq ts (cdr ts)))
2610                       (list (nreverse outt))))
2611                    outh))
2612             (setq headers (cdr headers)))
2613           (list (nreverse outh))))))))
2614
2615 \f
2616
2617 (defun gnus-summary-mode (&optional group)
2618   "Major mode for reading articles.
2619
2620 All normal editing commands are switched off.
2621 \\<gnus-summary-mode-map>
2622 Each line in this buffer represents one article.  To read an
2623 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2624 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2625 respectively.
2626
2627 You can also post articles and send mail from this buffer.  To
2628 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2629 of an article, type `\\[gnus-summary-reply]'.
2630
2631 There are approx. one gazillion commands you can execute in this
2632 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2633
2634 The following commands are available:
2635
2636 \\{gnus-summary-mode-map}"
2637   (interactive)
2638   (kill-all-local-variables)
2639   (when (gnus-visual-p 'summary-menu 'menu)
2640     (gnus-summary-make-menu-bar)
2641     (gnus-summary-make-tool-bar))
2642   (gnus-summary-make-local-variables)
2643   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2644     (gnus-summary-make-local-variables))
2645   (gnus-make-thread-indent-array)
2646   (gnus-simplify-mode-line)
2647   (setq major-mode 'gnus-summary-mode)
2648   (setq mode-name "Summary")
2649   (make-local-variable 'minor-mode-alist)
2650   (use-local-map gnus-summary-mode-map)
2651   (buffer-disable-undo)
2652   (setq buffer-read-only t)             ;Disable modification
2653   (setq truncate-lines t)
2654   (setq selective-display t)
2655   (setq selective-display-ellipses t)   ;Display `...'
2656   (gnus-summary-set-display-table)
2657   (gnus-set-default-directory)
2658   (setq gnus-newsgroup-name group)
2659   (unless (gnus-news-group-p group)
2660     (setq gnus-newsgroup-incorporated
2661           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2662   (make-local-variable 'gnus-summary-line-format)
2663   (make-local-variable 'gnus-summary-line-format-spec)
2664   (make-local-variable 'gnus-summary-dummy-line-format)
2665   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2666   (make-local-variable 'gnus-summary-mark-positions)
2667   (gnus-make-local-hook 'pre-command-hook)
2668   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2669   (gnus-run-hooks 'gnus-summary-mode-hook)
2670   (turn-on-gnus-mailing-list-mode)
2671   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2672   (gnus-update-summary-mark-positions))
2673
2674 (defun gnus-summary-make-local-variables ()
2675   "Make all the local summary buffer variables."
2676   (let (global)
2677     (dolist (local gnus-summary-local-variables)
2678       (if (consp local)
2679           (progn
2680             (if (eq (cdr local) 'global)
2681                 ;; Copy the global value of the variable.
2682                 (setq global (symbol-value (car local)))
2683               ;; Use the value from the list.
2684               (setq global (eval (cdr local))))
2685             (set (make-local-variable (car local)) global))
2686         ;; Simple nil-valued local variable.
2687         (set (make-local-variable local) nil)))))
2688
2689 (defun gnus-summary-clear-local-variables ()
2690   (let ((locals gnus-summary-local-variables))
2691     (while locals
2692       (if (consp (car locals))
2693           (and (vectorp (caar locals))
2694                (set (caar locals) nil))
2695         (and (vectorp (car locals))
2696              (set (car locals) nil)))
2697       (setq locals (cdr locals)))))
2698
2699 ;; Summary data functions.
2700
2701 (defmacro gnus-data-number (data)
2702   `(car ,data))
2703
2704 (defmacro gnus-data-set-number (data number)
2705   `(setcar ,data ,number))
2706
2707 (defmacro gnus-data-mark (data)
2708   `(nth 1 ,data))
2709
2710 (defmacro gnus-data-set-mark (data mark)
2711   `(setcar (nthcdr 1 ,data) ,mark))
2712
2713 (defmacro gnus-data-pos (data)
2714   `(nth 2 ,data))
2715
2716 (defmacro gnus-data-set-pos (data pos)
2717   `(setcar (nthcdr 2 ,data) ,pos))
2718
2719 (defmacro gnus-data-header (data)
2720   `(nth 3 ,data))
2721
2722 (defmacro gnus-data-set-header (data header)
2723   `(setcar (nthcdr 3 ,data) ,header))
2724
2725 (defmacro gnus-data-level (data)
2726   `(nth 4 ,data))
2727
2728 (defmacro gnus-data-unread-p (data)
2729   `(= (nth 1 ,data) gnus-unread-mark))
2730
2731 (defmacro gnus-data-read-p (data)
2732   `(/= (nth 1 ,data) gnus-unread-mark))
2733
2734 (defmacro gnus-data-pseudo-p (data)
2735   `(consp (nth 3 ,data)))
2736
2737 (defmacro gnus-data-find (number)
2738   `(assq ,number gnus-newsgroup-data))
2739
2740 (defmacro gnus-data-find-list (number &optional data)
2741   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2742      (memq (assq ,number bdata)
2743            bdata)))
2744
2745 (defmacro gnus-data-make (number mark pos header level)
2746   `(list ,number ,mark ,pos ,header ,level))
2747
2748 (defun gnus-data-enter (after-article number mark pos header level offset)
2749   (let ((data (gnus-data-find-list after-article)))
2750     (unless data
2751       (error "No such article: %d" after-article))
2752     (setcdr data (cons (gnus-data-make number mark pos header level)
2753                        (cdr data)))
2754     (setq gnus-newsgroup-data-reverse nil)
2755     (gnus-data-update-list (cddr data) offset)))
2756
2757 (defun gnus-data-enter-list (after-article list &optional offset)
2758   (when list
2759     (let ((data (and after-article (gnus-data-find-list after-article)))
2760           (ilist list))
2761       (if (not (or data
2762                    after-article))
2763           (let ((odata gnus-newsgroup-data))
2764             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2765             (when offset
2766               (gnus-data-update-list odata offset)))
2767         ;; Find the last element in the list to be spliced into the main
2768         ;; list.
2769         (while (cdr list)
2770           (setq list (cdr list)))
2771         (if (not data)
2772             (progn
2773               (setcdr list gnus-newsgroup-data)
2774               (setq gnus-newsgroup-data ilist)
2775               (when offset
2776                 (gnus-data-update-list (cdr list) offset)))
2777           (setcdr list (cdr data))
2778           (setcdr data ilist)
2779           (when offset
2780             (gnus-data-update-list (cdr list) offset))))
2781       (setq gnus-newsgroup-data-reverse nil))))
2782
2783 (defun gnus-data-remove (article &optional offset)
2784   (let ((data gnus-newsgroup-data))
2785     (if (= (gnus-data-number (car data)) article)
2786         (progn
2787           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2788                 gnus-newsgroup-data-reverse nil)
2789           (when offset
2790             (gnus-data-update-list gnus-newsgroup-data offset)))
2791       (while (cdr data)
2792         (when (= (gnus-data-number (cadr data)) article)
2793           (setcdr data (cddr data))
2794           (when offset
2795             (gnus-data-update-list (cdr data) offset))
2796           (setq data nil
2797                 gnus-newsgroup-data-reverse nil))
2798         (setq data (cdr data))))))
2799
2800 (defmacro gnus-data-list (backward)
2801   `(if ,backward
2802        (or gnus-newsgroup-data-reverse
2803            (setq gnus-newsgroup-data-reverse
2804                  (reverse gnus-newsgroup-data)))
2805      gnus-newsgroup-data))
2806
2807 (defun gnus-data-update-list (data offset)
2808   "Add OFFSET to the POS of all data entries in DATA."
2809   (setq gnus-newsgroup-data-reverse nil)
2810   (while data
2811     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2812     (setq data (cdr data))))
2813
2814 (defun gnus-summary-article-pseudo-p (article)
2815   "Say whether this article is a pseudo article or not."
2816   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2817
2818 (defmacro gnus-summary-article-sparse-p (article)
2819   "Say whether this article is a sparse article or not."
2820   `(memq ,article gnus-newsgroup-sparse))
2821
2822 (defmacro gnus-summary-article-ancient-p (article)
2823   "Say whether this article is a sparse article or not."
2824   `(memq ,article gnus-newsgroup-ancient))
2825
2826 (defun gnus-article-parent-p (number)
2827   "Say whether this article is a parent or not."
2828   (let ((data (gnus-data-find-list number)))
2829     (and (cdr data)                     ; There has to be an article after...
2830          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2831             (gnus-data-level (nth 1 data))))))
2832
2833 (defun gnus-article-children (number)
2834   "Return a list of all children to NUMBER."
2835   (let* ((data (gnus-data-find-list number))
2836          (level (gnus-data-level (car data)))
2837          children)
2838     (setq data (cdr data))
2839     (while (and data
2840                 (= (gnus-data-level (car data)) (1+ level)))
2841       (push (gnus-data-number (car data)) children)
2842       (setq data (cdr data)))
2843     children))
2844
2845 (defmacro gnus-summary-skip-intangible ()
2846   "If the current article is intangible, then jump to a different article."
2847   '(let ((to (get-text-property (point) 'gnus-intangible)))
2848      (and to (gnus-summary-goto-subject to))))
2849
2850 (defmacro gnus-summary-article-intangible-p ()
2851   "Say whether this article is intangible or not."
2852   '(get-text-property (point) 'gnus-intangible))
2853
2854 (defun gnus-article-read-p (article)
2855   "Say whether ARTICLE is read or not."
2856   (not (or (memq article gnus-newsgroup-marked)
2857            (memq article gnus-newsgroup-spam-marked)
2858            (memq article gnus-newsgroup-unreads)
2859            (memq article gnus-newsgroup-unselected)
2860            (memq article gnus-newsgroup-dormant))))
2861
2862 ;; Some summary mode macros.
2863
2864 (defmacro gnus-summary-article-number ()
2865   "The article number of the article on the current line.
2866 If there isn't an article number here, then we return the current
2867 article number."
2868   '(progn
2869      (gnus-summary-skip-intangible)
2870      (or (get-text-property (point) 'gnus-number)
2871          (gnus-summary-last-subject))))
2872
2873 (defmacro gnus-summary-article-header (&optional number)
2874   "Return the header of article NUMBER."
2875   `(gnus-data-header (gnus-data-find
2876                       ,(or number '(gnus-summary-article-number)))))
2877
2878 (defmacro gnus-summary-thread-level (&optional number)
2879   "Return the level of thread that starts with article NUMBER."
2880   `(if (and (eq gnus-summary-make-false-root 'dummy)
2881             (get-text-property (point) 'gnus-intangible))
2882        0
2883      (gnus-data-level (gnus-data-find
2884                        ,(or number '(gnus-summary-article-number))))))
2885
2886 (defmacro gnus-summary-article-mark (&optional number)
2887   "Return the mark of article NUMBER."
2888   `(gnus-data-mark (gnus-data-find
2889                     ,(or number '(gnus-summary-article-number)))))
2890
2891 (defmacro gnus-summary-article-pos (&optional number)
2892   "Return the position of the line of article NUMBER."
2893   `(gnus-data-pos (gnus-data-find
2894                    ,(or number '(gnus-summary-article-number)))))
2895
2896 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2897 (defmacro gnus-summary-article-subject (&optional number)
2898   "Return current subject string or nil if nothing."
2899   `(let ((headers
2900           ,(if number
2901                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2902              '(gnus-data-header (assq (gnus-summary-article-number)
2903                                       gnus-newsgroup-data)))))
2904      (and headers
2905           (vectorp headers)
2906           (mail-header-subject headers))))
2907
2908 (defmacro gnus-summary-article-score (&optional number)
2909   "Return current article score."
2910   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2911                   gnus-newsgroup-scored))
2912        gnus-summary-default-score 0))
2913
2914 (defun gnus-summary-article-children (&optional number)
2915   "Return a list of article numbers that are children of article NUMBER."
2916   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2917          (level (gnus-data-level (car data)))
2918          l children)
2919     (while (and (setq data (cdr data))
2920                 (> (setq l (gnus-data-level (car data))) level))
2921       (and (= (1+ level) l)
2922            (push (gnus-data-number (car data))
2923                  children)))
2924     (nreverse children)))
2925
2926 (defun gnus-summary-article-parent (&optional number)
2927   "Return the article number of the parent of article NUMBER."
2928   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2929                                     (gnus-data-list t)))
2930          (level (gnus-data-level (car data))))
2931     (if (zerop level)
2932         ()                              ; This is a root.
2933       ;; We search until we find an article with a level less than
2934       ;; this one.  That function has to be the parent.
2935       (while (and (setq data (cdr data))
2936                   (not (< (gnus-data-level (car data)) level))))
2937       (and data (gnus-data-number (car data))))))
2938
2939 (defun gnus-unread-mark-p (mark)
2940   "Say whether MARK is the unread mark."
2941   (= mark gnus-unread-mark))
2942
2943 (defun gnus-read-mark-p (mark)
2944   "Say whether MARK is one of the marks that mark as read.
2945 This is all marks except unread, ticked, dormant, and expirable."
2946   (not (or (= mark gnus-unread-mark)
2947            (= mark gnus-ticked-mark)
2948            (= mark gnus-spam-mark)
2949            (= mark gnus-dormant-mark)
2950            (= mark gnus-expirable-mark))))
2951
2952 (defmacro gnus-article-mark (number)
2953   "Return the MARK of article NUMBER.
2954 This macro should only be used when computing the mark the \"first\"
2955 time; i.e., when generating the summary lines.  After that,
2956 `gnus-summary-article-mark' should be used to examine the
2957 marks of articles."
2958   `(cond
2959     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2960     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2961     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2962     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2963     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2964     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2965     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2966     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2967            gnus-ancient-mark))))
2968
2969 ;; Saving hidden threads.
2970
2971 (defmacro gnus-save-hidden-threads (&rest forms)
2972   "Save hidden threads, eval FORMS, and restore the hidden threads."
2973   (let ((config (make-symbol "config")))
2974     `(let ((,config (gnus-hidden-threads-configuration)))
2975        (unwind-protect
2976            (save-excursion
2977              ,@forms)
2978          (gnus-restore-hidden-threads-configuration ,config)))))
2979 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2980 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2981
2982 (defun gnus-data-compute-positions ()
2983   "Compute the positions of all articles."
2984   (setq gnus-newsgroup-data-reverse nil)
2985   (let ((data gnus-newsgroup-data))
2986     (save-excursion
2987       (gnus-save-hidden-threads
2988         (gnus-summary-show-all-threads)
2989         (goto-char (point-min))
2990         (while data
2991           (while (get-text-property (point) 'gnus-intangible)
2992             (forward-line 1))
2993           (gnus-data-set-pos (car data) (+ (point) 3))
2994           (setq data (cdr data))
2995           (forward-line 1))))))
2996
2997 (defun gnus-hidden-threads-configuration ()
2998   "Return the current hidden threads configuration."
2999   (save-excursion
3000     (let (config)
3001       (goto-char (point-min))
3002       (while (search-forward "\r" nil t)
3003         (push (1- (point)) config))
3004       config)))
3005
3006 (defun gnus-restore-hidden-threads-configuration (config)
3007   "Restore hidden threads configuration from CONFIG."
3008   (save-excursion
3009     (let (point buffer-read-only)
3010       (while (setq point (pop config))
3011         (when (and (< point (point-max))
3012                    (goto-char point)
3013                    (eq (char-after) ?\n))
3014           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3015
3016 ;; Various summary mode internalish functions.
3017
3018 (defun gnus-mouse-pick-article (e)
3019   (interactive "e")
3020   (mouse-set-point e)
3021   (gnus-summary-next-page nil t))
3022
3023 (defun gnus-summary-set-display-table ()
3024   "Change the display table.
3025 Odd characters have a tendency to mess
3026 up nicely formatted displays - we make all possible glyphs
3027 display only a single character."
3028
3029   ;; We start from the standard display table, if any.
3030   (let ((table (or (copy-sequence standard-display-table)
3031                    (make-display-table)))
3032         (i 32))
3033     ;; Nix out all the control chars...
3034     (while (>= (setq i (1- i)) 0)
3035       (aset table i [??]))
3036     ;; ... but not newline and cr, of course.  (cr is necessary for the
3037     ;; selective display).
3038     (aset table ?\n nil)
3039     (aset table ?\r nil)
3040     ;; We keep TAB as well.
3041     (aset table ?\t nil)
3042     ;; We nix out any glyphs over 126 that are not set already.
3043     (let ((i 256))
3044       (while (>= (setq i (1- i)) 127)
3045         ;; Only modify if the entry is nil.
3046         (unless (aref table i)
3047           (aset table i [??]))))
3048     (setq buffer-display-table table)))
3049
3050 (defun gnus-summary-set-article-display-arrow (pos)
3051   "Update the overlay arrow to point to line at position POS."
3052   (when (and gnus-summary-display-arrow
3053              (boundp 'overlay-arrow-position)
3054              (boundp 'overlay-arrow-string))
3055     (save-excursion
3056       (goto-char pos)
3057       (beginning-of-line)
3058       (unless overlay-arrow-position
3059         (setq overlay-arrow-position (make-marker)))
3060       (setq overlay-arrow-string "=>"
3061             overlay-arrow-position (set-marker overlay-arrow-position
3062                                                (point)
3063                                                (current-buffer))))))
3064
3065 (defun gnus-summary-setup-buffer (group)
3066   "Initialize summary buffer."
3067   (let ((buffer (gnus-summary-buffer-name group))
3068         (dead-name (concat "*Dead Summary "
3069                            (gnus-group-decoded-name group) "*")))
3070     ;; If a dead summary buffer exists, we kill it.
3071     (when (gnus-buffer-live-p dead-name)
3072       (gnus-kill-buffer dead-name))
3073     (if (get-buffer buffer)
3074         (progn
3075           (set-buffer buffer)
3076           (setq gnus-summary-buffer (current-buffer))
3077           (not gnus-newsgroup-prepared))
3078       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3079       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3080       (gnus-summary-mode group)
3081       (when gnus-carpal
3082         (gnus-carpal-setup-buffer 'summary))
3083       (unless gnus-single-article-buffer
3084         (make-local-variable 'gnus-article-buffer)
3085         (make-local-variable 'gnus-article-current)
3086         (make-local-variable 'gnus-original-article-buffer))
3087       (setq gnus-newsgroup-name group)
3088       ;; Set any local variables in the group parameters.
3089       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3090       t)))
3091
3092 (defun gnus-set-global-variables ()
3093   "Set the global equivalents of the buffer-local variables.
3094 They are set to the latest values they had.  These reflect the summary
3095 buffer that was in action when the last article was fetched."
3096   (when (eq major-mode 'gnus-summary-mode)
3097     (setq gnus-summary-buffer (current-buffer))
3098     (let ((name gnus-newsgroup-name)
3099           (marked gnus-newsgroup-marked)
3100           (spam gnus-newsgroup-spam-marked)
3101           (unread gnus-newsgroup-unreads)
3102           (headers gnus-current-headers)
3103           (data gnus-newsgroup-data)
3104           (summary gnus-summary-buffer)
3105           (article-buffer gnus-article-buffer)
3106           (original gnus-original-article-buffer)
3107           (gac gnus-article-current)
3108           (reffed gnus-reffed-article-number)
3109           (score-file gnus-current-score-file)
3110           (default-charset gnus-newsgroup-charset)
3111           vlist)
3112       (let ((locals gnus-newsgroup-variables))
3113         (while locals
3114           (if (consp (car locals))
3115               (push (eval (caar locals)) vlist)
3116             (push (eval (car locals)) vlist))
3117           (setq locals (cdr locals)))
3118         (setq vlist (nreverse vlist)))
3119       (save-excursion
3120         (set-buffer gnus-group-buffer)
3121         (setq gnus-newsgroup-name name
3122               gnus-newsgroup-marked marked
3123               gnus-newsgroup-spam-marked spam
3124               gnus-newsgroup-unreads unread
3125               gnus-current-headers headers
3126               gnus-newsgroup-data data
3127               gnus-article-current gac
3128               gnus-summary-buffer summary
3129               gnus-article-buffer article-buffer
3130               gnus-original-article-buffer original
3131               gnus-reffed-article-number reffed
3132               gnus-current-score-file score-file
3133               gnus-newsgroup-charset default-charset)
3134         (let ((locals gnus-newsgroup-variables))
3135           (while locals
3136             (if (consp (car locals))
3137                 (set (caar locals) (pop vlist))
3138               (set (car locals) (pop vlist)))
3139             (setq locals (cdr locals))))
3140         ;; The article buffer also has local variables.
3141         (when (gnus-buffer-live-p gnus-article-buffer)
3142           (set-buffer gnus-article-buffer)
3143           (setq gnus-summary-buffer summary))))))
3144
3145 (defun gnus-summary-article-unread-p (article)
3146   "Say whether ARTICLE is unread or not."
3147   (memq article gnus-newsgroup-unreads))
3148
3149 (defun gnus-summary-first-article-p (&optional article)
3150   "Return whether ARTICLE is the first article in the buffer."
3151   (if (not (setq article (or article (gnus-summary-article-number))))
3152       nil
3153     (eq article (caar gnus-newsgroup-data))))
3154
3155 (defun gnus-summary-last-article-p (&optional article)
3156   "Return whether ARTICLE is the last article in the buffer."
3157   (if (not (setq article (or article (gnus-summary-article-number))))
3158       ;; All non-existent numbers are the last article.  :-)
3159       t
3160     (not (cdr (gnus-data-find-list article)))))
3161
3162 (defun gnus-make-thread-indent-array ()
3163   (let ((n 200))
3164     (unless (and gnus-thread-indent-array
3165                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3166       (setq gnus-thread-indent-array (make-vector 201 "")
3167             gnus-thread-indent-array-level gnus-thread-indent-level)
3168       (while (>= n 0)
3169         (aset gnus-thread-indent-array n
3170               (make-string (* n gnus-thread-indent-level) ? ))
3171         (setq n (1- n))))))
3172
3173 (defun gnus-update-summary-mark-positions ()
3174   "Compute where the summary marks are to go."
3175   (save-excursion
3176     (when (gnus-buffer-exists-p gnus-summary-buffer)
3177       (set-buffer gnus-summary-buffer))
3178     (let ((gnus-replied-mark 129)
3179           (gnus-score-below-mark 130)
3180           (gnus-score-over-mark 130)
3181           (gnus-undownloaded-mark 131)
3182           (spec gnus-summary-line-format-spec)
3183           gnus-visual pos)
3184       (save-excursion
3185         (gnus-set-work-buffer)
3186         (let ((gnus-summary-line-format-spec spec)
3187               (gnus-newsgroup-downloadable '(0)))
3188           (gnus-summary-insert-line
3189            (make-full-mail-header 0 "" "nobody"
3190                                   "05 Apr 2001 23:33:09 +0400"
3191                                   "" "" 0 0 "" nil)
3192            0 nil t 128 t nil "" nil 1)
3193           (goto-char (point-min))
3194           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3195                                              (- (point) (point-min) 1)))))
3196           (goto-char (point-min))
3197           (push (cons 'replied (and (search-forward "\201" nil t)
3198                                     (- (point) (point-min) 1)))
3199                 pos)
3200           (goto-char (point-min))
3201           (push (cons 'score (and (search-forward "\202" nil t)
3202                                   (- (point) (point-min) 1)))
3203                 pos)
3204           (goto-char (point-min))
3205           (push (cons 'download
3206                       (and (search-forward "\203" nil t)
3207                            (- (point) (point-min) 1)))
3208                 pos)))
3209       (setq gnus-summary-mark-positions pos))))
3210
3211 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3212   "Insert a dummy root in the summary buffer."
3213   (beginning-of-line)
3214   (gnus-add-text-properties
3215    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3216    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3217
3218 (defun gnus-summary-extract-address-component (from)
3219   (or (car (funcall gnus-extract-address-components from))
3220       from))
3221
3222 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3223   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3224                                 default-mime-charset)))
3225     ;; Is it really necessary to do this next part for each summary line?
3226     ;; Luckily, doesn't seem to slow things down much.
3227     (or
3228      (and gnus-ignored-from-addresses
3229           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3230           (let ((extra-headers (mail-header-extra header))
3231                 to
3232                 newsgroups)
3233             (cond
3234              ((setq to (cdr (assq 'To extra-headers)))
3235               (concat "-> "
3236                       (inline
3237                         (gnus-summary-extract-address-component
3238                          (funcall gnus-decode-encoded-word-function to)))))
3239              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3240               (concat "=> " newsgroups)))))
3241      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3242
3243 (defun gnus-summary-insert-line (gnus-tmp-header
3244                                  gnus-tmp-level gnus-tmp-current
3245                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3246                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3247                                  &optional gnus-tmp-dummy gnus-tmp-score
3248                                  gnus-tmp-process)
3249   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3250          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3251          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3252          (gnus-tmp-score-char
3253           (if (or (null gnus-summary-default-score)
3254                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3255                       gnus-summary-zcore-fuzz))
3256               ?\ ;;;Whitespace
3257             (if (< gnus-tmp-score gnus-summary-default-score)
3258                 gnus-score-below-mark gnus-score-over-mark)))
3259          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3260          (gnus-tmp-replied
3261           (cond (gnus-tmp-process gnus-process-mark)
3262                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3263                  gnus-cached-mark)
3264                 (gnus-tmp-replied gnus-replied-mark)
3265                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3266                  gnus-forwarded-mark)
3267                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3268                  gnus-saved-mark)
3269                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3270                  gnus-recent-mark)
3271                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3272                  gnus-unseen-mark)
3273                 (t gnus-no-mark)))
3274          (gnus-tmp-downloaded
3275           (cond (undownloaded 
3276                  gnus-undownloaded-mark)
3277                 (gnus-newsgroup-agentized
3278                  gnus-downloaded-mark)
3279                 (t
3280                  gnus-no-mark)))
3281          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3282          (gnus-tmp-name
3283           (cond
3284            ((string-match "<[^>]+> *$" gnus-tmp-from)
3285             (let ((beg (match-beginning 0)))
3286               (or (and (string-match "^\".+\"" gnus-tmp-from)
3287                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3288                   (substring gnus-tmp-from 0 beg))))
3289            ((string-match "(.+)" gnus-tmp-from)
3290             (substring gnus-tmp-from
3291                        (1+ (match-beginning 0)) (1- (match-end 0))))
3292            (t gnus-tmp-from)))
3293          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3294          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3295          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3296          (buffer-read-only nil))
3297     (when (string= gnus-tmp-name "")
3298       (setq gnus-tmp-name gnus-tmp-from))
3299     (unless (numberp gnus-tmp-lines)
3300       (setq gnus-tmp-lines -1))
3301     (if (= gnus-tmp-lines -1)
3302         (setq gnus-tmp-lines "?")
3303       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3304     (gnus-put-text-property-excluding-characters-with-faces
3305      (point)
3306      (progn (eval gnus-summary-line-format-spec) (point))
3307      'gnus-number gnus-tmp-number)
3308     (when (gnus-visual-p 'summary-highlight 'highlight)
3309       (forward-line -1)
3310       (gnus-run-hooks 'gnus-summary-update-hook)
3311       (forward-line 1))))
3312
3313 (defun gnus-summary-update-line (&optional dont-update)
3314   "Update summary line after change."
3315   (when (and gnus-summary-default-score
3316              (not gnus-summary-inhibit-highlight))
3317     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3318            (article (gnus-summary-article-number))
3319            (score (gnus-summary-article-score article)))
3320       (unless dont-update
3321         (if (and gnus-summary-mark-below
3322                  (< (gnus-summary-article-score)
3323                     gnus-summary-mark-below))
3324             ;; This article has a low score, so we mark it as read.
3325             (when (memq article gnus-newsgroup-unreads)
3326               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3327           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3328             ;; This article was previously marked as read on account
3329             ;; of a low score, but now it has risen, so we mark it as
3330             ;; unread.
3331             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3332         (gnus-summary-update-mark
3333          (if (or (null gnus-summary-default-score)
3334                  (<= (abs (- score gnus-summary-default-score))
3335                      gnus-summary-zcore-fuzz))
3336              ?\ ;;;Whitespace
3337            (if (< score gnus-summary-default-score)
3338                gnus-score-below-mark gnus-score-over-mark))
3339          'score))
3340       ;; Do visual highlighting.
3341       (when (gnus-visual-p 'summary-highlight 'highlight)
3342         (gnus-run-hooks 'gnus-summary-update-hook)))))
3343
3344 (defvar gnus-tmp-new-adopts nil)
3345
3346 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3347   "Return the number of articles in THREAD.
3348 This may be 0 in some cases -- if none of the articles in
3349 the thread are to be displayed."
3350   (let* ((number
3351           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3352           (cond
3353            ((not (listp thread))
3354             1)
3355            ((and (consp thread) (cdr thread))
3356             (apply
3357              '+ 1 (mapcar
3358                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3359            ((null thread)
3360             1)
3361            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3362             1)
3363            (t 0))))
3364     (when (and level (zerop level) gnus-tmp-new-adopts)
3365       (incf number
3366             (apply '+ (mapcar
3367                        'gnus-summary-number-of-articles-in-thread
3368                        gnus-tmp-new-adopts))))
3369     (if char
3370         (if (> number 1) gnus-not-empty-thread-mark
3371           gnus-empty-thread-mark)
3372       number)))
3373
3374 (defsubst gnus-summary-line-message-size (head)
3375   "Return pretty-printed version of message size.
3376 This function is intended to be used in
3377 `gnus-summary-line-format-alist'."
3378   (let ((c (or (mail-header-chars head) -1)))
3379     (cond ((< c 0) "n/a")               ; chars not available
3380           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3381           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3382           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3383           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3384
3385
3386 (defun gnus-summary-set-local-parameters (group)
3387   "Go through the local params of GROUP and set all variable specs in that list."
3388   (let ((params (gnus-group-find-parameter group))
3389         (vars '(quit-config))           ; Ignore quit-config.
3390         elem)
3391     (while params
3392       (setq elem (car params)
3393             params (cdr params))
3394       (and (consp elem)                 ; Has to be a cons.
3395            (consp (cdr elem))           ; The cdr has to be a list.
3396            (symbolp (car elem))         ; Has to be a symbol in there.
3397            (not (memq (car elem) vars))
3398            (ignore-errors               ; So we set it.
3399              (push (car elem) vars)
3400              (make-local-variable (car elem))
3401              (set (car elem) (eval (nth 1 elem))))))))
3402
3403 (defun gnus-summary-read-group (group &optional show-all no-article
3404                                       kill-buffer no-display backward
3405                                       select-articles)
3406   "Start reading news in newsgroup GROUP.
3407 If SHOW-ALL is non-nil, already read articles are also listed.
3408 If NO-ARTICLE is non-nil, no article is selected initially.
3409 If NO-DISPLAY, don't generate a summary buffer."
3410   (let (result)
3411     (while (and group
3412                 (null (setq result
3413                             (let ((gnus-auto-select-next nil))
3414                               (or (gnus-summary-read-group-1
3415                                    group show-all no-article
3416                                    kill-buffer no-display
3417                                    select-articles)
3418                                   (setq show-all nil
3419                                         select-articles nil)))))
3420                 (eq gnus-auto-select-next 'quietly))
3421       (set-buffer gnus-group-buffer)
3422       ;; The entry function called above goes to the next
3423       ;; group automatically, so we go two groups back
3424       ;; if we are searching for the previous group.
3425       (when backward
3426         (gnus-group-prev-unread-group 2))
3427       (if (not (equal group (gnus-group-group-name)))
3428           (setq group (gnus-group-group-name))
3429         (setq group nil)))
3430     result))
3431
3432 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3433   "Directly jump to the other GROUP from summary buffer.
3434 If SHOW-ALL is non-nil, already read articles are also listed."
3435   (interactive
3436    (if (eq gnus-summary-buffer (current-buffer))
3437        (list (completing-read
3438               "Group: " gnus-active-hashtb nil t
3439               (when (and gnus-newsgroup-name
3440                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3441                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3442               'gnus-group-history)
3443              current-prefix-arg)
3444      (error "%s must be invoked from a gnus summary buffer." this-command)))
3445   (unless (or (zerop (length group))
3446               (and gnus-newsgroup-name
3447                    (string-equal gnus-newsgroup-name group)))
3448     (gnus-summary-exit)
3449     (gnus-summary-read-group group show-all
3450                              gnus-dont-select-after-jump-to-other-group)))
3451
3452 (defun gnus-summary-read-group-1 (group show-all no-article
3453                                         kill-buffer no-display
3454                                         &optional select-articles)
3455   ;; Killed foreign groups can't be entered.
3456   ;;  (when (and (not (gnus-group-native-p group))
3457   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3458   ;;    (error "Dead non-native groups can't be entered"))
3459   (gnus-message 5 "Retrieving newsgroup: %s..."
3460                 (gnus-group-decoded-name group))
3461   (let* ((new-group (gnus-summary-setup-buffer group))
3462          (quit-config (gnus-group-quit-config group))
3463          (did-select (and new-group (gnus-select-newsgroup
3464                                      group show-all select-articles))))
3465     (cond
3466      ;; This summary buffer exists already, so we just select it.
3467      ((not new-group)
3468       (gnus-set-global-variables)
3469       (when kill-buffer
3470         (gnus-kill-or-deaden-summary kill-buffer))
3471       (gnus-configure-windows 'summary 'force)
3472       (gnus-set-mode-line 'summary)
3473       (gnus-summary-position-point)
3474       (message "")
3475       t)
3476      ;; We couldn't select this group.
3477      ((null did-select)
3478       (when (and (eq major-mode 'gnus-summary-mode)
3479                  (not (equal (current-buffer) kill-buffer)))
3480         (kill-buffer (current-buffer))
3481         (if (not quit-config)
3482             (progn
3483               ;; Update the info -- marks might need to be removed,
3484               ;; for instance.
3485               (gnus-summary-update-info)
3486               (set-buffer gnus-group-buffer)
3487               (gnus-group-jump-to-group group)
3488               (gnus-group-next-unread-group 1))
3489           (gnus-handle-ephemeral-exit quit-config)))
3490       (let ((grpinfo (gnus-get-info group)))
3491         (if (null (gnus-info-read grpinfo))
3492             (gnus-message 3 "Group %s contains no messages"
3493                           (gnus-group-decoded-name group))
3494           (gnus-message 3 "Can't select group")))
3495       nil)
3496      ;; The user did a `C-g' while prompting for number of articles,
3497      ;; so we exit this group.
3498      ((eq did-select 'quit)
3499       (and (eq major-mode 'gnus-summary-mode)
3500            (not (equal (current-buffer) kill-buffer))
3501            (kill-buffer (current-buffer)))
3502       (when kill-buffer
3503         (gnus-kill-or-deaden-summary kill-buffer))
3504       (if (not quit-config)
3505           (progn
3506             (set-buffer gnus-group-buffer)
3507             (gnus-group-jump-to-group group)
3508             (gnus-group-next-unread-group 1)
3509             (gnus-configure-windows 'group 'force))
3510         (gnus-handle-ephemeral-exit quit-config))
3511       ;; Finally signal the quit.
3512       (signal 'quit nil))
3513      ;; The group was successfully selected.
3514      (t
3515       (gnus-set-global-variables)
3516       ;; Save the active value in effect when the group was entered.
3517       (setq gnus-newsgroup-active
3518             (gnus-copy-sequence
3519              (gnus-active gnus-newsgroup-name)))
3520       ;; You can change the summary buffer in some way with this hook.
3521       (gnus-run-hooks 'gnus-select-group-hook)
3522       (gnus-update-format-specifications
3523        nil 'summary 'summary-mode 'summary-dummy)
3524       (gnus-update-summary-mark-positions)
3525       ;; Do score processing.
3526       (when gnus-use-scoring
3527         (gnus-possibly-score-headers))
3528       ;; Check whether to fill in the gaps in the threads.
3529       (when gnus-build-sparse-threads
3530         (gnus-build-sparse-threads))
3531       ;; Find the initial limit.
3532       (if gnus-show-threads
3533           (if show-all
3534               (let ((gnus-newsgroup-dormant nil))
3535                 (gnus-summary-initial-limit show-all))
3536             (gnus-summary-initial-limit show-all))
3537         ;; When unthreaded, all articles are always shown.
3538         (setq gnus-newsgroup-limit
3539               (mapcar
3540                (lambda (header) (mail-header-number header))
3541                gnus-newsgroup-headers)))
3542       ;; Generate the summary buffer.
3543       (unless no-display
3544         (gnus-summary-prepare))
3545       (when gnus-use-trees
3546         (gnus-tree-open group)
3547         (setq gnus-summary-highlight-line-function
3548               'gnus-tree-highlight-article))
3549       ;; If the summary buffer is empty, but there are some low-scored
3550       ;; articles or some excluded dormants, we include these in the
3551       ;; buffer.
3552       (when (and (zerop (buffer-size))
3553                  (not no-display))
3554         (cond (gnus-newsgroup-dormant
3555                (gnus-summary-limit-include-dormant))
3556               ((and gnus-newsgroup-scored show-all)
3557                (gnus-summary-limit-include-expunged t))))
3558       ;; Function `gnus-apply-kill-file' must be called in this hook.
3559       (gnus-run-hooks 'gnus-apply-kill-hook)
3560       (if (and (zerop (buffer-size))
3561                (not no-display))
3562           (progn
3563             ;; This newsgroup is empty.
3564             (gnus-summary-catchup-and-exit nil t)
3565             (gnus-message 6 "No unread news")
3566             (when kill-buffer
3567               (gnus-kill-or-deaden-summary kill-buffer))
3568             ;; Return nil from this function.
3569             nil)
3570         ;; Hide conversation thread subtrees.  We cannot do this in
3571         ;; gnus-summary-prepare-hook since kill processing may not
3572         ;; work with hidden articles.
3573         (gnus-summary-maybe-hide-threads)
3574         (when kill-buffer
3575           (gnus-kill-or-deaden-summary kill-buffer))
3576         (gnus-summary-auto-select-subject)
3577         ;; Show first unread article if requested.
3578         (if (and (not no-article)
3579                  (not no-display)
3580                  gnus-newsgroup-unreads
3581                  gnus-auto-select-first)
3582             (progn
3583               (gnus-configure-windows 'summary)
3584               (let ((art (gnus-summary-article-number)))
3585                 (unless (and (not gnus-plugged)
3586                              (or (memq art gnus-newsgroup-undownloaded)
3587                                  (memq art gnus-newsgroup-downloadable)))
3588                   (gnus-summary-goto-article art))))
3589           ;; Don't select any articles.
3590           (gnus-summary-position-point)
3591           (gnus-configure-windows 'summary 'force)
3592           (gnus-set-mode-line 'summary))
3593         (when (and gnus-auto-center-group
3594                    (get-buffer-window gnus-group-buffer t))
3595           ;; Gotta use windows, because recenter does weird stuff if
3596           ;; the current buffer ain't the displayed window.
3597           (let ((owin (selected-window)))
3598             (select-window (get-buffer-window gnus-group-buffer t))
3599             (when (gnus-group-goto-group group)
3600               (recenter))
3601             (select-window owin)))
3602         ;; Mark this buffer as "prepared".
3603         (setq gnus-newsgroup-prepared t)
3604         (gnus-run-hooks 'gnus-summary-prepared-hook)
3605         (unless (gnus-ephemeral-group-p group)
3606           (gnus-group-update-group group))
3607         t)))))
3608
3609 (defun gnus-summary-auto-select-subject ()
3610   "Select the subject line on initial group entry."
3611   (goto-char (point-min))
3612   (cond
3613    ((eq gnus-auto-select-subject 'best)
3614     (gnus-summary-best-unread-subject))
3615    ((eq gnus-auto-select-subject 'unread)
3616     (gnus-summary-first-unread-subject))
3617    ((eq gnus-auto-select-subject 'unseen)
3618     (gnus-summary-first-unseen-subject))
3619    ((eq gnus-auto-select-subject 'unseen-or-unread)
3620     (gnus-summary-first-unseen-or-unread-subject))
3621    ((eq gnus-auto-select-subject 'first)
3622     ;; Do nothing.
3623     )
3624    ((functionp gnus-auto-select-subject)
3625     (funcall gnus-auto-select-subject))))
3626
3627 (defun gnus-summary-prepare ()
3628   "Generate the summary buffer."
3629   (interactive)
3630   (let ((buffer-read-only nil))
3631     (erase-buffer)
3632     (setq gnus-newsgroup-data nil
3633           gnus-newsgroup-data-reverse nil)
3634     (gnus-run-hooks 'gnus-summary-generate-hook)
3635     ;; Generate the buffer, either with threads or without.
3636     (when gnus-newsgroup-headers
3637       (gnus-summary-prepare-threads
3638        (if gnus-show-threads
3639            (gnus-sort-gathered-threads
3640             (funcall gnus-summary-thread-gathering-function
3641                      (gnus-sort-threads
3642                       (gnus-cut-threads (gnus-make-threads)))))
3643          ;; Unthreaded display.
3644          (gnus-sort-articles gnus-newsgroup-headers))))
3645     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3646     ;; Call hooks for modifying summary buffer.
3647     (goto-char (point-min))
3648     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3649
3650 (defsubst gnus-general-simplify-subject (subject)
3651   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3652   (setq subject
3653         (cond
3654          ;; Truncate the subject.
3655          (gnus-simplify-subject-functions
3656           (gnus-map-function gnus-simplify-subject-functions subject))
3657          ((numberp gnus-summary-gather-subject-limit)
3658           (setq subject (gnus-simplify-subject-re subject))
3659           (if (> (length subject) gnus-summary-gather-subject-limit)
3660               (substring subject 0 gnus-summary-gather-subject-limit)
3661             subject))
3662          ;; Fuzzily simplify it.
3663          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3664           (gnus-simplify-subject-fuzzy subject))
3665          ;; Just remove the leading "Re:".
3666          (t
3667           (gnus-simplify-subject-re subject))))
3668
3669   (if (and gnus-summary-gather-exclude-subject
3670            (string-match gnus-summary-gather-exclude-subject subject))
3671       nil                               ; This article shouldn't be gathered
3672     subject))
3673
3674 (defun gnus-summary-simplify-subject-query ()
3675   "Query where the respool algorithm would put this article."
3676   (interactive)
3677   (gnus-summary-select-article)
3678   (message "%s"
3679            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3680
3681 (defun gnus-gather-threads-by-subject (threads)
3682   "Gather threads by looking at Subject headers."
3683   (if (not gnus-summary-make-false-root)
3684       threads
3685     (let ((hashtb (gnus-make-hashtable 1024))
3686           (prev threads)
3687           (result threads)
3688           subject hthread whole-subject)
3689       (while threads
3690         (setq subject (gnus-general-simplify-subject
3691                        (setq whole-subject (mail-header-subject
3692                                             (caar threads)))))
3693         (when subject
3694           (if (setq hthread (gnus-gethash subject hashtb))
3695               (progn
3696                 ;; We enter a dummy root into the thread, if we
3697                 ;; haven't done that already.
3698                 (unless (stringp (caar hthread))
3699                   (setcar hthread (list whole-subject (car hthread))))
3700                 ;; We add this new gathered thread to this gathered
3701                 ;; thread.
3702                 (setcdr (car hthread)
3703                         (nconc (cdar hthread) (list (car threads))))
3704                 ;; Remove it from the list of threads.
3705                 (setcdr prev (cdr threads))
3706                 (setq threads prev))
3707             ;; Enter this thread into the hash table.
3708             (gnus-sethash subject
3709                           (if gnus-summary-make-false-root-always
3710                               (progn
3711                                 ;; If you want a dummy root above all
3712                                 ;; threads...
3713                                 (setcar threads (list whole-subject
3714                                                       (car threads)))
3715                                 threads)
3716                             threads)
3717                           hashtb)))
3718         (setq prev threads)
3719         (setq threads (cdr threads)))
3720       result)))
3721
3722 (defun gnus-gather-threads-by-references (threads)
3723   "Gather threads by looking at References headers."
3724   (let ((idhashtb (gnus-make-hashtable 1024))
3725         (thhashtb (gnus-make-hashtable 1024))
3726         (prev threads)
3727         (result threads)
3728         ids references id gthread gid entered ref)
3729     (while threads
3730       (when (setq references (mail-header-references (caar threads)))
3731         (setq id (mail-header-id (caar threads))
3732               ids (inline (gnus-split-references references))
3733               entered nil)
3734         (while (setq ref (pop ids))
3735           (setq ids (delete ref ids))
3736           (if (not (setq gid (gnus-gethash ref idhashtb)))
3737               (progn
3738                 (gnus-sethash ref id idhashtb)
3739                 (gnus-sethash id threads thhashtb))
3740             (setq gthread (gnus-gethash gid thhashtb))
3741             (unless entered
3742               ;; We enter a dummy root into the thread, if we
3743               ;; haven't done that already.
3744               (unless (stringp (caar gthread))
3745                 (setcar gthread (list (mail-header-subject (caar gthread))
3746                                       (car gthread))))
3747               ;; We add this new gathered thread to this gathered
3748               ;; thread.
3749               (setcdr (car gthread)
3750                       (nconc (cdar gthread) (list (car threads)))))
3751             ;; Add it into the thread hash table.
3752             (gnus-sethash id gthread thhashtb)
3753             (setq entered t)
3754             ;; Remove it from the list of threads.
3755             (setcdr prev (cdr threads))
3756             (setq threads prev))))
3757       (setq prev threads)
3758       (setq threads (cdr threads)))
3759     result))
3760
3761 (defun gnus-sort-gathered-threads (threads)
3762   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3763   (let ((result threads))
3764     (while threads
3765       (when (stringp (caar threads))
3766         (setcdr (car threads)
3767                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3768       (setq threads (cdr threads)))
3769     result))
3770
3771 (defun gnus-thread-loop-p (root thread)
3772   "Say whether ROOT is in THREAD."
3773   (let ((stack (list thread))
3774         (infloop 0)
3775         th)
3776     (while (setq thread (pop stack))
3777       (setq th (cdr thread))
3778       (while (and th
3779                   (not (eq (caar th) root)))
3780         (pop th))
3781       (if th
3782           ;; We have found a loop.
3783           (let (ref-dep)
3784             (setcdr thread (delq (car th) (cdr thread)))
3785             (if (boundp (setq ref-dep (intern "none"
3786                                               gnus-newsgroup-dependencies)))
3787                 (setcdr (symbol-value ref-dep)
3788                         (nconc (cdr (symbol-value ref-dep))
3789                                (list (car th))))
3790               (set ref-dep (list nil (car th))))
3791             (setq infloop 1
3792                   stack nil))
3793         ;; Push all the subthreads onto the stack.
3794         (push (cdr thread) stack)))
3795     infloop))
3796
3797 (defun gnus-make-threads ()
3798   "Go through the dependency hashtb and find the roots.  Return all threads."
3799   (let (threads)
3800     (while (catch 'infloop
3801              (mapatoms
3802               (lambda (refs)
3803                 ;; Deal with self-referencing References loops.
3804                 (when (and (car (symbol-value refs))
3805                            (not (zerop
3806                                  (apply
3807                                   '+
3808                                   (mapcar
3809                                    (lambda (thread)
3810                                      (gnus-thread-loop-p
3811                                       (car (symbol-value refs)) thread))
3812                                    (cdr (symbol-value refs)))))))
3813                   (setq threads nil)
3814                   (throw 'infloop t))
3815                 (unless (car (symbol-value refs))
3816                   ;; These threads do not refer back to any other articles,
3817                   ;; so they're roots.
3818                   (setq threads (append (cdr (symbol-value refs)) threads))))
3819               gnus-newsgroup-dependencies)))
3820     threads))
3821
3822 ;; Build the thread tree.
3823 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3824   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3825
3826 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3827 if it was already present.
3828
3829 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3830 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3831 Message-IDs will be renamed to a unique Message-ID before being
3832 entered.
3833
3834 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3835   (let* ((id (mail-header-id header))
3836          (id-dep (and id (intern id dependencies)))
3837          parent-id ref ref-dep ref-header replaced)
3838     ;; Enter this `header' in the `dependencies' table.
3839     (cond
3840      ((not id-dep)
3841       (setq header nil))
3842      ;; The first two cases do the normal part: enter a new `header'
3843      ;; in the `dependencies' table.
3844      ((not (boundp id-dep))
3845       (set id-dep (list header)))
3846      ((null (car (symbol-value id-dep)))
3847       (setcar (symbol-value id-dep) header))
3848
3849      ;; From here the `header' was already present in the
3850      ;; `dependencies' table.
3851      (force-new
3852       ;; Overrides an existing entry;
3853       ;; just set the header part of the entry.
3854       (setcar (symbol-value id-dep) header)
3855       (setq replaced t))
3856
3857      ;; Renames the existing `header' to a unique Message-ID.
3858      ((not gnus-summary-ignore-duplicates)
3859       ;; An article with this Message-ID has already been seen.
3860       ;; We rename the Message-ID.
3861       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3862            (list header))
3863       (mail-header-set-id header id))
3864
3865      ;; The last case ignores an existing entry, except it adds any
3866      ;; additional Xrefs (in case the two articles came from different
3867      ;; servers.
3868      ;; Also sets `header' to `nil' meaning that the `dependencies'
3869      ;; table was *not* modified.
3870      (t
3871       (mail-header-set-xref
3872        (car (symbol-value id-dep))
3873        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3874                    "")
3875                (or (mail-header-xref header) "")))
3876       (setq header nil)))
3877
3878     (when (and header (not replaced))
3879       ;; First check that we are not creating a References loop.
3880       (setq parent-id (gnus-parent-id (mail-header-references header)))
3881       (setq ref parent-id)
3882       (while (and ref
3883                   (setq ref-dep (intern-soft ref dependencies))
3884                   (boundp ref-dep)
3885                   (setq ref-header (car (symbol-value ref-dep))))
3886         (if (string= id ref)
3887             ;; Yuk!  This is a reference loop.  Make the article be a
3888             ;; root article.
3889             (progn
3890               (mail-header-set-references (car (symbol-value id-dep)) "none")
3891               (setq ref nil)
3892               (setq parent-id nil))
3893           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3894       (setq ref-dep (intern (or parent-id "none") dependencies))
3895       (if (boundp ref-dep)
3896           (setcdr (symbol-value ref-dep)
3897                   (nconc (cdr (symbol-value ref-dep))
3898                          (list (symbol-value id-dep))))
3899         (set ref-dep (list nil (symbol-value id-dep)))))
3900     header))
3901
3902 (defun gnus-extract-message-id-from-in-reply-to (string)
3903   (if (string-match "<[^>]+>" string)
3904       (substring string (match-beginning 0) (match-end 0))
3905     nil))
3906
3907 (defun gnus-build-sparse-threads ()
3908   (let ((headers gnus-newsgroup-headers)
3909         (mail-parse-charset gnus-newsgroup-charset)
3910         (gnus-summary-ignore-duplicates t)
3911         header references generation relations
3912         subject child end new-child date)
3913     ;; First we create an alist of generations/relations, where
3914     ;; generations is how much we trust the relation, and the relation
3915     ;; is parent/child.
3916     (gnus-message 7 "Making sparse threads...")
3917     (save-excursion
3918       (nnheader-set-temp-buffer " *gnus sparse threads*")
3919       (while (setq header (pop headers))
3920         (when (and (setq references (mail-header-references header))
3921                    (not (string= references "")))
3922           (insert references)
3923           (setq child (mail-header-id header)
3924                 subject (mail-header-subject header)
3925                 date (mail-header-date header)
3926                 generation 0)
3927           (while (search-backward ">" nil t)
3928             (setq end (1+ (point)))
3929             (when (search-backward "<" nil t)
3930               (setq new-child (buffer-substring (point) end))
3931               (push (list (incf generation)
3932                           child (setq child new-child)
3933                           subject date)
3934                     relations)))
3935           (when child
3936             (push (list (1+ generation) child nil subject) relations))
3937           (erase-buffer)))
3938       (kill-buffer (current-buffer)))
3939     ;; Sort over trustworthiness.
3940     (mapcar
3941      (lambda (relation)
3942        (when (gnus-dependencies-add-header
3943               (make-full-mail-header-from-decoded-header
3944                gnus-reffed-article-number
3945                (nth 3 relation) "" (or (nth 4 relation) "")
3946                (nth 1 relation)
3947                (or (nth 2 relation) "") 0 0 "")
3948               gnus-newsgroup-dependencies nil)
3949          (push gnus-reffed-article-number gnus-newsgroup-limit)
3950          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3951          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3952                gnus-newsgroup-reads)
3953          (decf gnus-reffed-article-number)))
3954      (sort relations 'car-less-than-car))
3955     (gnus-message 7 "Making sparse threads...done")))
3956
3957 (defun gnus-build-old-threads ()
3958   ;; Look at all the articles that refer back to old articles, and
3959   ;; fetch the headers for the articles that aren't there.  This will
3960   ;; build complete threads - if the roots haven't been expired by the
3961   ;; server, that is.
3962   (let ((mail-parse-charset gnus-newsgroup-charset)
3963         id heads)
3964     (mapatoms
3965      (lambda (refs)
3966        (when (not (car (symbol-value refs)))
3967          (setq heads (cdr (symbol-value refs)))
3968          (while heads
3969            (if (memq (mail-header-number (caar heads))
3970                      gnus-newsgroup-dormant)
3971                (setq heads (cdr heads))
3972              (setq id (symbol-name refs))
3973              (while (and (setq id (gnus-build-get-header id))
3974                          (not (car (gnus-id-to-thread id)))))
3975              (setq heads nil)))))
3976      gnus-newsgroup-dependencies)))
3977
3978 ;; This function has to be called with point after the article number
3979 ;; on the beginning of the line.
3980 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3981   (let ((eol (gnus-point-at-eol))
3982         (buffer (current-buffer))
3983         header references in-reply-to)
3984
3985     ;; overview: [num subject from date id refs chars lines misc]
3986     (unwind-protect
3987         (progn
3988           (narrow-to-region (point) eol)
3989           (unless (eobp)
3990             (forward-char))
3991
3992           (setq header
3993                 (make-full-mail-header
3994                  number                         ; number
3995                  (nnheader-nov-field)           ; subject
3996                  (nnheader-nov-field)           ; from
3997                  (nnheader-nov-field)           ; date
3998                  (nnheader-nov-read-message-id) ; id
3999                  (nnheader-nov-field)           ; refs
4000                  (nnheader-nov-read-integer)    ; chars
4001                  (nnheader-nov-read-integer)    ; lines
4002                  (unless (eobp)
4003                    (if (looking-at "Xref: ")
4004                        (goto-char (match-end 0)))
4005                    (nnheader-nov-field))        ; Xref
4006                  (nnheader-nov-parse-extra))))  ; extra
4007
4008       (widen))
4009
4010     (when (and (string= references "")
4011                (setq in-reply-to (mail-header-extra header))
4012                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4013       (mail-header-set-references
4014        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4015
4016     (when gnus-alter-header-function
4017       (funcall gnus-alter-header-function header))
4018     (gnus-dependencies-add-header header dependencies force-new)))
4019
4020 (defun gnus-build-get-header (id)
4021   "Look through the buffer of NOV lines and find the header to ID.
4022 Enter this line into the dependencies hash table, and return
4023 the id of the parent article (if any)."
4024   (let ((deps gnus-newsgroup-dependencies)
4025         found header)
4026     (prog1
4027         (save-excursion
4028           (set-buffer nntp-server-buffer)
4029           (let ((case-fold-search nil))
4030             (goto-char (point-min))
4031             (while (and (not found)
4032                         (search-forward id nil t))
4033               (beginning-of-line)
4034               (setq found (looking-at
4035                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4036                                    (regexp-quote id))))
4037               (or found (beginning-of-line 2)))
4038             (when found
4039               (beginning-of-line)
4040               (and
4041                (setq header (gnus-nov-parse-line
4042                              (read (current-buffer)) deps))
4043                (gnus-parent-id (mail-header-references header))))))
4044       (when header
4045         (let ((number (mail-header-number header)))
4046           (push number gnus-newsgroup-limit)
4047           (push header gnus-newsgroup-headers)
4048           (if (memq number gnus-newsgroup-unselected)
4049               (progn
4050                 (setq gnus-newsgroup-unreads
4051                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4052                                                number))
4053                 (setq gnus-newsgroup-unselected
4054                       (delq number gnus-newsgroup-unselected)))
4055             (push number gnus-newsgroup-ancient)))))))
4056
4057 (defun gnus-build-all-threads ()
4058   "Read all the headers."
4059   (let ((gnus-summary-ignore-duplicates t)
4060         (mail-parse-charset gnus-newsgroup-charset)
4061         (dependencies gnus-newsgroup-dependencies)
4062         header article)
4063     (save-excursion
4064       (set-buffer nntp-server-buffer)
4065       (let ((case-fold-search nil))
4066         (goto-char (point-min))
4067         (while (not (eobp))
4068           (ignore-errors
4069             (setq article (read (current-buffer))
4070                   header (gnus-nov-parse-line article dependencies)))
4071           (when header
4072             (save-excursion
4073               (set-buffer gnus-summary-buffer)
4074               (push header gnus-newsgroup-headers)
4075               (if (memq (setq article (mail-header-number header))
4076                         gnus-newsgroup-unselected)
4077                   (progn
4078                     (setq gnus-newsgroup-unreads
4079                           (gnus-add-to-sorted-list
4080                            gnus-newsgroup-unreads article))
4081                     (setq gnus-newsgroup-unselected
4082                           (delq article gnus-newsgroup-unselected)))
4083                 (push article gnus-newsgroup-ancient)))
4084             (forward-line 1)))))))
4085
4086 (defun gnus-summary-update-article-line (article header)
4087   "Update the line for ARTICLE using HEADERS."
4088   (let* ((id (mail-header-id header))
4089          (thread (gnus-id-to-thread id)))
4090     (unless thread
4091       (error "Article in no thread"))
4092     ;; Update the thread.
4093     (setcar thread header)
4094     (gnus-summary-goto-subject article)
4095     (let* ((datal (gnus-data-find-list article))
4096            (data (car datal))
4097            (buffer-read-only nil)
4098            (level (gnus-summary-thread-level)))
4099       (gnus-delete-line)
4100       (let ((inserted (- (point)
4101                          (progn
4102                            (gnus-summary-insert-line
4103                             header level nil 
4104                             (memq article gnus-newsgroup-undownloaded)
4105                             (gnus-article-mark article)
4106                             (memq article gnus-newsgroup-replied)
4107                             (memq article gnus-newsgroup-expirable)
4108                             ;; Only insert the Subject string when it's different
4109                             ;; from the previous Subject string.
4110                             (if (and
4111                                  gnus-show-threads
4112                                  (gnus-subject-equal
4113                                   (condition-case ()
4114                                       (mail-header-subject
4115                                        (gnus-data-header
4116                                         (cadr
4117                                          (gnus-data-find-list
4118                                           article
4119                                           (gnus-data-list t)))))
4120                                     ;; Error on the side of excessive subjects.
4121                                     (error ""))
4122                                   (mail-header-subject header)))
4123                                 ""
4124                               (mail-header-subject header))
4125                             nil (cdr (assq article gnus-newsgroup-scored))
4126                             (memq article gnus-newsgroup-processable))
4127                            (point)))))
4128         (when (cdr datal)
4129           (gnus-data-update-list
4130            (cdr datal) 
4131            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4132
4133 (defun gnus-summary-update-article (article &optional iheader)
4134   "Update ARTICLE in the summary buffer."
4135   (set-buffer gnus-summary-buffer)
4136   (let* ((header (gnus-summary-article-header article))
4137          (id (mail-header-id header))
4138          (data (gnus-data-find article))
4139          (thread (gnus-id-to-thread id))
4140          (references (mail-header-references header))
4141          (parent
4142           (gnus-id-to-thread
4143            (or (gnus-parent-id
4144                 (when (and references
4145                            (not (equal "" references)))
4146                   references))
4147                "none")))
4148          (buffer-read-only nil)
4149          (old (car thread)))
4150     (when thread
4151       (unless iheader
4152         (setcar thread nil)
4153         (when parent
4154           (delq thread parent)))
4155       (if (gnus-summary-insert-subject id header)
4156           ;; Set the (possibly) new article number in the data structure.
4157           (gnus-data-set-number data (gnus-id-to-article id))
4158         (setcar thread old)
4159         nil))))
4160
4161 (defun gnus-rebuild-thread (id &optional line)
4162   "Rebuild the thread containing ID.
4163 If LINE, insert the rebuilt thread starting on line LINE."
4164   (let ((buffer-read-only nil)
4165         old-pos current thread data)
4166     (if (not gnus-show-threads)
4167         (setq thread (list (car (gnus-id-to-thread id))))
4168       ;; Get the thread this article is part of.
4169       (setq thread (gnus-remove-thread id)))
4170     (setq old-pos (gnus-point-at-bol))
4171     (setq current (save-excursion
4172                     (and (re-search-backward "[\r\n]" nil t)
4173                          (gnus-summary-article-number))))
4174     ;; If this is a gathered thread, we have to go some re-gathering.
4175     (when (stringp (car thread))
4176       (let ((subject (car thread))
4177             roots thr)
4178         (setq thread (cdr thread))
4179         (while thread
4180           (unless (memq (setq thr (gnus-id-to-thread
4181                                    (gnus-root-id
4182                                     (mail-header-id (caar thread)))))
4183                         roots)
4184             (push thr roots))
4185           (setq thread (cdr thread)))
4186         ;; We now have all (unique) roots.
4187         (if (= (length roots) 1)
4188             ;; All the loose roots are now one solid root.
4189             (setq thread (car roots))
4190           (setq thread (cons subject (gnus-sort-threads roots))))))
4191     (let (threads)
4192       ;; We then insert this thread into the summary buffer.
4193       (when line
4194         (goto-char (point-min))
4195         (forward-line (1- line)))
4196       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4197         (if gnus-show-threads
4198             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4199           (gnus-summary-prepare-unthreaded thread))
4200         (setq data (nreverse gnus-newsgroup-data))
4201         (setq threads gnus-newsgroup-threads))
4202       ;; We splice the new data into the data structure.
4203       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4204       ;;!!! then we want to insert at the beginning of the buffer.
4205       ;;!!! That happens to be true with Gnus now, but that may
4206       ;;!!! change in the future.  Perhaps.
4207       (gnus-data-enter-list
4208        (if line nil current) data (- (point) old-pos))
4209       (setq gnus-newsgroup-threads
4210             (nconc threads gnus-newsgroup-threads))
4211       (gnus-data-compute-positions))))
4212
4213 (defun gnus-number-to-header (number)
4214   "Return the header for article NUMBER."
4215   (let ((headers gnus-newsgroup-headers))
4216     (while (and headers
4217                 (not (= number (mail-header-number (car headers)))))
4218       (pop headers))
4219     (when headers
4220       (car headers))))
4221
4222 (defun gnus-parent-headers (in-headers &optional generation)
4223   "Return the headers of the GENERATIONeth parent of HEADERS."
4224   (unless generation
4225     (setq generation 1))
4226   (let ((parent t)
4227         (headers in-headers)
4228         references)
4229     (while (and parent
4230                 (not (zerop generation))
4231                 (setq references (mail-header-references headers)))
4232       (setq headers (if (and references
4233                              (setq parent (gnus-parent-id references)))
4234                         (car (gnus-id-to-thread parent))
4235                       nil))
4236       (decf generation))
4237     (and (not (eq headers in-headers))
4238          headers)))
4239
4240 (defun gnus-id-to-thread (id)
4241   "Return the (sub-)thread where ID appears."
4242   (gnus-gethash id gnus-newsgroup-dependencies))
4243
4244 (defun gnus-id-to-article (id)
4245   "Return the article number of ID."
4246   (let ((thread (gnus-id-to-thread id)))
4247     (when (and thread
4248                (car thread))
4249       (mail-header-number (car thread)))))
4250
4251 (defun gnus-id-to-header (id)
4252   "Return the article headers of ID."
4253   (car (gnus-id-to-thread id)))
4254
4255 (defun gnus-article-displayed-root-p (article)
4256   "Say whether ARTICLE is a root(ish) article."
4257   (let ((level (gnus-summary-thread-level article))
4258         (refs (mail-header-references  (gnus-summary-article-header article)))
4259         particle)
4260     (cond
4261      ((null level) nil)
4262      ((zerop level) t)
4263      ((null refs) t)
4264      ((null (gnus-parent-id refs)) t)
4265      ((and (= 1 level)
4266            (null (setq particle (gnus-id-to-article
4267                                  (gnus-parent-id refs))))
4268            (null (gnus-summary-thread-level particle)))))))
4269
4270 (defun gnus-root-id (id)
4271   "Return the id of the root of the thread where ID appears."
4272   (let (last-id prev)
4273     (while (and id (setq prev (car (gnus-id-to-thread id))))
4274       (setq last-id id
4275             id (gnus-parent-id (mail-header-references prev))))
4276     last-id))
4277
4278 (defun gnus-articles-in-thread (thread)
4279   "Return the list of articles in THREAD."
4280   (cons (mail-header-number (car thread))
4281         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4282
4283 (defun gnus-remove-thread (id &optional dont-remove)
4284   "Remove the thread that has ID in it."
4285   (let (headers thread last-id)
4286     ;; First go up in this thread until we find the root.
4287     (setq last-id (gnus-root-id id)
4288           headers (message-flatten-list (gnus-id-to-thread last-id)))
4289     ;; We have now found the real root of this thread.  It might have
4290     ;; been gathered into some loose thread, so we have to search
4291     ;; through the threads to find the thread we wanted.
4292     (let ((threads gnus-newsgroup-threads)
4293           sub)
4294       (while threads
4295         (setq sub (car threads))
4296         (if (stringp (car sub))
4297             ;; This is a gathered thread, so we look at the roots
4298             ;; below it to find whether this article is in this
4299             ;; gathered root.
4300             (progn
4301               (setq sub (cdr sub))
4302               (while sub
4303                 (when (member (caar sub) headers)
4304                   (setq thread (car threads)
4305                         threads nil
4306                         sub nil))
4307                 (setq sub (cdr sub))))
4308           ;; It's an ordinary thread, so we check it.
4309           (when (eq (car sub) (car headers))
4310             (setq thread sub
4311                   threads nil)))
4312         (setq threads (cdr threads)))
4313       ;; If this article is in no thread, then it's a root.
4314       (if thread
4315           (unless dont-remove
4316             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4317         (setq thread (gnus-id-to-thread last-id)))
4318       (when thread
4319         (prog1
4320             thread                      ; We return this thread.
4321           (unless dont-remove
4322             (if (stringp (car thread))
4323                 (progn
4324                   ;; If we use dummy roots, then we have to remove the
4325                   ;; dummy root as well.
4326                   (when (eq gnus-summary-make-false-root 'dummy)
4327                     ;; We go to the dummy root by going to
4328                     ;; the first sub-"thread", and then one line up.
4329                     (gnus-summary-goto-article
4330                      (mail-header-number (caadr thread)))
4331                     (forward-line -1)
4332                     (gnus-delete-line)
4333                     (gnus-data-compute-positions))
4334                   (setq thread (cdr thread))
4335                   (while thread
4336                     (gnus-remove-thread-1 (car thread))
4337                     (setq thread (cdr thread))))
4338               (gnus-remove-thread-1 thread))))))))
4339
4340 (defun gnus-remove-thread-1 (thread)
4341   "Remove the thread THREAD recursively."
4342   (let ((number (mail-header-number (pop thread)))
4343         d)
4344     (setq thread (reverse thread))
4345     (while thread
4346       (gnus-remove-thread-1 (pop thread)))
4347     (when (setq d (gnus-data-find number))
4348       (goto-char (gnus-data-pos d))
4349       (gnus-summary-show-thread)
4350       (gnus-data-remove
4351        number
4352        (- (gnus-point-at-bol)
4353           (prog1
4354               (1+ (gnus-point-at-eol))
4355             (gnus-delete-line)))))))
4356
4357 (defun gnus-sort-threads-1 (threads func)
4358   (sort (mapcar (lambda (thread)
4359                   (cons (car thread)
4360                         (and (cdr thread)
4361                              (gnus-sort-threads-1 (cdr thread) func))))
4362                 threads) func))
4363
4364 (defun gnus-sort-threads (threads)
4365   "Sort THREADS."
4366   (if (not gnus-thread-sort-functions)
4367       threads
4368     (gnus-message 8 "Sorting threads...")
4369     (let ((max-lisp-eval-depth 5000))
4370       (prog1 (gnus-sort-threads-1
4371          threads
4372          (gnus-make-sort-function gnus-thread-sort-functions))
4373         (gnus-message 8 "Sorting threads...done")))))
4374
4375 (defun gnus-sort-articles (articles)
4376   "Sort ARTICLES."
4377   (when gnus-article-sort-functions
4378     (gnus-message 7 "Sorting articles...")
4379     (prog1
4380         (setq gnus-newsgroup-headers
4381               (sort articles (gnus-make-sort-function
4382                               gnus-article-sort-functions)))
4383       (gnus-message 7 "Sorting articles...done"))))
4384
4385 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4386 (defmacro gnus-thread-header (thread)
4387   "Return header of first article in THREAD.
4388 Note that THREAD must never, ever be anything else than a variable -
4389 using some other form will lead to serious barfage."
4390   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4391   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4392   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4393         (vector thread) 2))
4394
4395 (defsubst gnus-article-sort-by-number (h1 h2)
4396   "Sort articles by article number."
4397   (< (mail-header-number h1)
4398      (mail-header-number h2)))
4399
4400 (defun gnus-thread-sort-by-number (h1 h2)
4401   "Sort threads by root article number."
4402   (gnus-article-sort-by-number
4403    (gnus-thread-header h1) (gnus-thread-header h2)))
4404
4405 (defsubst gnus-article-sort-by-random (h1 h2)
4406   "Sort articles by article number."
4407   (zerop (random 2)))
4408
4409 (defun gnus-thread-sort-by-random (h1 h2)
4410   "Sort threads by root article number."
4411   (gnus-article-sort-by-random
4412    (gnus-thread-header h1) (gnus-thread-header h2)))
4413
4414 (defsubst gnus-article-sort-by-lines (h1 h2)
4415   "Sort articles by article Lines header."
4416   (< (mail-header-lines h1)
4417      (mail-header-lines h2)))
4418
4419 (defun gnus-thread-sort-by-lines (h1 h2)
4420   "Sort threads by root article Lines header."
4421   (gnus-article-sort-by-lines
4422    (gnus-thread-header h1) (gnus-thread-header h2)))
4423
4424 (defsubst gnus-article-sort-by-chars (h1 h2)
4425   "Sort articles by octet length."
4426   (< (mail-header-chars h1)
4427      (mail-header-chars h2)))
4428
4429 (defun gnus-thread-sort-by-chars (h1 h2)
4430   "Sort threads by root article octet length."
4431   (gnus-article-sort-by-chars
4432    (gnus-thread-header h1) (gnus-thread-header h2)))
4433
4434 (defsubst gnus-article-sort-by-author (h1 h2)
4435   "Sort articles by root author."
4436   (string-lessp
4437    (let ((addr (car (mime-entity-read-field h1 'From))))
4438      (or (std11-full-name-string addr)
4439          (std11-address-string addr)
4440          ""))
4441    (let ((addr (car (mime-entity-read-field h2 'From))))
4442      (or (std11-full-name-string addr)
4443          (std11-address-string addr)
4444          ""))
4445    ))
4446
4447 (defun gnus-thread-sort-by-author (h1 h2)
4448   "Sort threads by root author."
4449   (gnus-article-sort-by-author
4450    (gnus-thread-header h1)  (gnus-thread-header h2)))
4451
4452 (defsubst gnus-article-sort-by-subject (h1 h2)
4453   "Sort articles by root subject."
4454   (string-lessp
4455    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4456    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4457
4458 (defun gnus-thread-sort-by-subject (h1 h2)
4459   "Sort threads by root subject."
4460   (gnus-article-sort-by-subject
4461    (gnus-thread-header h1) (gnus-thread-header h2)))
4462
4463 (defsubst gnus-article-sort-by-date (h1 h2)
4464   "Sort articles by root article date."
4465   (time-less-p
4466    (gnus-date-get-time (mail-header-date h1))
4467    (gnus-date-get-time (mail-header-date h2))))
4468
4469 (defun gnus-thread-sort-by-date (h1 h2)
4470   "Sort threads by root article date."
4471   (gnus-article-sort-by-date
4472    (gnus-thread-header h1) (gnus-thread-header h2)))
4473
4474 (defsubst gnus-article-sort-by-score (h1 h2)
4475   "Sort articles by root article score.
4476 Unscored articles will be counted as having a score of zero."
4477   (> (or (cdr (assq (mail-header-number h1)
4478                     gnus-newsgroup-scored))
4479          gnus-summary-default-score 0)
4480      (or (cdr (assq (mail-header-number h2)
4481                     gnus-newsgroup-scored))
4482          gnus-summary-default-score 0)))
4483
4484 (defun gnus-thread-sort-by-score (h1 h2)
4485   "Sort threads by root article score."
4486   (gnus-article-sort-by-score
4487    (gnus-thread-header h1) (gnus-thread-header h2)))
4488
4489 (defun gnus-thread-sort-by-total-score (h1 h2)
4490   "Sort threads by the sum of all scores in the thread.
4491 Unscored articles will be counted as having a score of zero."
4492   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4493
4494 (defun gnus-thread-total-score (thread)
4495   ;; This function find the total score of THREAD.
4496   (cond
4497    ((null thread)
4498     0)
4499    ((consp thread)
4500     (if (stringp (car thread))
4501         (apply gnus-thread-score-function 0
4502                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4503       (gnus-thread-total-score-1 thread)))
4504    (t
4505     (gnus-thread-total-score-1 (list thread)))))
4506
4507 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4508   "Sort threads such that the thread with the most recently arrived article comes first."
4509   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4510
4511 (defun gnus-thread-highest-number (thread)
4512   "Return the highest article number in THREAD."
4513   (apply 'max (mapcar (lambda (header)
4514                         (mail-header-number header))
4515                       (message-flatten-list thread))))
4516
4517 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4518   "Sort threads such that the thread with the most recently dated article comes first."
4519   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4520
4521 (defun gnus-thread-latest-date (thread)
4522   "Return the highest article date in THREAD."
4523   (let ((previous-time 0))
4524     (apply 'max
4525            (mapcar
4526             (lambda (header)
4527               (setq previous-time
4528                     (time-to-seconds
4529                      (condition-case ()
4530                          (mail-header-parse-date (mail-header-date header))
4531                        (error previous-time)))))
4532             (sort
4533              (message-flatten-list thread)
4534              (lambda (h1 h2)
4535                (< (mail-header-number h1)
4536                   (mail-header-number h2))))))))
4537
4538 (defun gnus-thread-total-score-1 (root)
4539   ;; This function find the total score of the thread below ROOT.
4540   (setq root (car root))
4541   (apply gnus-thread-score-function
4542          (or (append
4543               (mapcar 'gnus-thread-total-score
4544                       (cdr (gnus-id-to-thread (mail-header-id root))))
4545               (when (> (mail-header-number root) 0)
4546                 (list (or (cdr (assq (mail-header-number root)
4547                                      gnus-newsgroup-scored))
4548                           gnus-summary-default-score 0))))
4549              (list gnus-summary-default-score)
4550              '(0))))
4551
4552 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4553 (defvar gnus-tmp-prev-subject nil)
4554 (defvar gnus-tmp-false-parent nil)
4555 (defvar gnus-tmp-root-expunged nil)
4556 (defvar gnus-tmp-dummy-line nil)
4557
4558 (eval-when-compile (defvar gnus-tmp-header))
4559 (defun gnus-extra-header (type &optional header)
4560   "Return the extra header of TYPE."
4561   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4562       ""))
4563
4564 (defvar gnus-tmp-thread-tree-header-string "")
4565
4566 (defcustom gnus-sum-thread-tree-root "> "
4567   "With %B spec, used for the root of a thread.
4568 If nil, use subject instead."
4569   :type 'string
4570   :group 'gnus-thread)
4571 (defcustom gnus-sum-thread-tree-false-root "> "
4572   "With %B spec, used for a false root of a thread.
4573 If nil, use subject instead."
4574   :type 'string
4575   :group 'gnus-thread)
4576 (defcustom gnus-sum-thread-tree-single-indent ""
4577   "With %B spec, used for a thread with just one message.
4578 If nil, use subject instead."
4579   :type 'string
4580   :group 'gnus-thread)
4581 (defcustom gnus-sum-thread-tree-vertical "| "
4582   "With %B spec, used for drawing a vertical line."
4583   :type 'string
4584   :group 'gnus-thread)
4585 (defcustom gnus-sum-thread-tree-indent "  "
4586   "With %B spec, used for indenting."
4587   :type 'string
4588   :group 'gnus-thread)
4589 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4590   "With %B spec, used for a leaf with brothers."
4591   :type 'string
4592   :group 'gnus-thread)
4593 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4594   "With %B spec, used for a leaf without brothers."
4595   :type 'string
4596   :group 'gnus-thread)
4597
4598 (defun gnus-summary-prepare-threads (threads)
4599   "Prepare summary buffer from THREADS and indentation LEVEL.
4600 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4601 or a straight list of headers."
4602   (gnus-message 7 "Generating summary...")
4603
4604   (setq gnus-newsgroup-threads threads)
4605   (beginning-of-line)
4606
4607   (let ((gnus-tmp-level 0)
4608         (default-score (or gnus-summary-default-score 0))
4609         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4610         (building-line-count gnus-summary-display-while-building)
4611         (building-count (integerp gnus-summary-display-while-building))
4612         thread number subject stack state gnus-tmp-gathered beg-match
4613         new-roots gnus-tmp-new-adopts thread-end simp-subject
4614         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4615         gnus-tmp-replied gnus-tmp-subject-or-nil
4616         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4617         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4618         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4619         tree-stack)
4620
4621     (setq gnus-tmp-prev-subject nil
4622           gnus-tmp-thread-tree-header-string "")
4623
4624     (if (vectorp (car threads))
4625         ;; If this is a straight (sic) list of headers, then a
4626         ;; threaded summary display isn't required, so we just create
4627         ;; an unthreaded one.
4628         (gnus-summary-prepare-unthreaded threads)
4629
4630       ;; Do the threaded display.
4631
4632       (if gnus-summary-display-while-building
4633           (switch-to-buffer (buffer-name)))
4634       (while (or threads stack gnus-tmp-new-adopts new-roots)
4635
4636         (if (and (= gnus-tmp-level 0)
4637                  (or (not stack)
4638                      (= (caar stack) 0))
4639                  (not gnus-tmp-false-parent)
4640                  (or gnus-tmp-new-adopts new-roots))
4641             (if gnus-tmp-new-adopts
4642                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4643                       thread (list (car gnus-tmp-new-adopts))
4644                       gnus-tmp-header (caar thread)
4645                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4646               (when new-roots
4647                 (setq thread (list (car new-roots))
4648                       gnus-tmp-header (caar thread)
4649                       new-roots (cdr new-roots))))
4650
4651           (if threads
4652               ;; If there are some threads, we do them before the
4653               ;; threads on the stack.
4654               (setq thread threads
4655                     gnus-tmp-header (caar thread))
4656             ;; There were no current threads, so we pop something off
4657             ;; the stack.
4658             (setq state (car stack)
4659                   gnus-tmp-level (car state)
4660                   tree-stack (cadr state)
4661                   thread (caddr state)
4662                   stack (cdr stack)
4663                   gnus-tmp-header (caar thread))))
4664
4665         (setq gnus-tmp-false-parent nil)
4666         (setq gnus-tmp-root-expunged nil)
4667         (setq thread-end nil)
4668
4669         (if (stringp gnus-tmp-header)
4670             ;; The header is a dummy root.
4671             (cond
4672              ((eq gnus-summary-make-false-root 'adopt)
4673               ;; We let the first article adopt the rest.
4674               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4675                                                (cddar thread)))
4676               (setq gnus-tmp-gathered
4677                     (nconc (mapcar
4678                             (lambda (h) (mail-header-number (car h)))
4679                             (cddar thread))
4680                            gnus-tmp-gathered))
4681               (setq thread (cons (list (caar thread)
4682                                        (cadar thread))
4683                                  (cdr thread)))
4684               (setq gnus-tmp-level -1
4685                     gnus-tmp-false-parent t))
4686              ((eq gnus-summary-make-false-root 'empty)
4687               ;; We print adopted articles with empty subject fields.
4688               (setq gnus-tmp-gathered
4689                     (nconc (mapcar
4690                             (lambda (h) (mail-header-number (car h)))
4691                             (cddar thread))
4692                            gnus-tmp-gathered))
4693               (setq gnus-tmp-level -1))
4694              ((eq gnus-summary-make-false-root 'dummy)
4695               ;; We remember that we probably want to output a dummy
4696               ;; root.
4697               (setq gnus-tmp-dummy-line gnus-tmp-header)
4698               (setq gnus-tmp-prev-subject gnus-tmp-header))
4699              (t
4700               ;; We do not make a root for the gathered
4701               ;; sub-threads at all.
4702               (setq gnus-tmp-level -1)))
4703
4704           (setq number (mail-header-number gnus-tmp-header)
4705                 subject (mail-header-subject gnus-tmp-header)
4706                 simp-subject (gnus-simplify-subject-fully subject))
4707
4708           (cond
4709            ;; If the thread has changed subject, we might want to make
4710            ;; this subthread into a root.
4711            ((and (null gnus-thread-ignore-subject)
4712                  (not (zerop gnus-tmp-level))
4713                  gnus-tmp-prev-subject
4714                  (not (string= gnus-tmp-prev-subject simp-subject)))
4715             (setq new-roots (nconc new-roots (list (car thread)))
4716                   thread-end t
4717                   gnus-tmp-header nil))
4718            ;; If the article lies outside the current limit,
4719            ;; then we do not display it.
4720            ((not (memq number gnus-newsgroup-limit))
4721             (setq gnus-tmp-gathered
4722                   (nconc (mapcar
4723                           (lambda (h) (mail-header-number (car h)))
4724                           (cdar thread))
4725                          gnus-tmp-gathered))
4726             (setq gnus-tmp-new-adopts (if (cdar thread)
4727                                           (append gnus-tmp-new-adopts
4728                                                   (cdar thread))
4729                                         gnus-tmp-new-adopts)
4730                   thread-end t
4731                   gnus-tmp-header nil)
4732             (when (zerop gnus-tmp-level)
4733               (setq gnus-tmp-root-expunged t)))
4734            ;; Perhaps this article is to be marked as read?
4735            ((and gnus-summary-mark-below
4736                  (< (or (cdr (assq number gnus-newsgroup-scored))
4737                         default-score)
4738                     gnus-summary-mark-below)
4739                  ;; Don't touch sparse articles.
4740                  (not (gnus-summary-article-sparse-p number))
4741                  (not (gnus-summary-article-ancient-p number)))
4742             (setq gnus-newsgroup-unreads
4743                   (delq number gnus-newsgroup-unreads))
4744             (if gnus-newsgroup-auto-expire
4745                 (setq gnus-newsgroup-expirable
4746                       (gnus-add-to-sorted-list
4747                        gnus-newsgroup-expirable number))
4748               (push (cons number gnus-low-score-mark)
4749                     gnus-newsgroup-reads))))
4750
4751           (when gnus-tmp-header
4752             ;; We may have an old dummy line to output before this
4753             ;; article.
4754             (when (and gnus-tmp-dummy-line
4755                        (gnus-subject-equal
4756                         gnus-tmp-dummy-line
4757                         (mail-header-subject gnus-tmp-header)))
4758               (gnus-summary-insert-dummy-line
4759                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4760               (setq gnus-tmp-dummy-line nil))
4761
4762             ;; Compute the mark.
4763             (setq gnus-tmp-unread (gnus-article-mark number))
4764
4765             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4766                                   gnus-tmp-header gnus-tmp-level)
4767                   gnus-newsgroup-data)
4768
4769             ;; Actually insert the line.
4770             (setq
4771              gnus-tmp-subject-or-nil
4772              (cond
4773               ((and gnus-thread-ignore-subject
4774                     gnus-tmp-prev-subject
4775                     (not (string= gnus-tmp-prev-subject simp-subject)))
4776                subject)
4777               ((zerop gnus-tmp-level)
4778                (if (and (eq gnus-summary-make-false-root 'empty)
4779                         (memq number gnus-tmp-gathered)
4780                         gnus-tmp-prev-subject
4781                         (string= gnus-tmp-prev-subject simp-subject))
4782                    gnus-summary-same-subject
4783                  subject))
4784               (t gnus-summary-same-subject)))
4785             (if (and (eq gnus-summary-make-false-root 'adopt)
4786                      (= gnus-tmp-level 1)
4787                      (memq number gnus-tmp-gathered))
4788                 (setq gnus-tmp-opening-bracket ?\<
4789                       gnus-tmp-closing-bracket ?\>)
4790               (setq gnus-tmp-opening-bracket ?\[
4791                     gnus-tmp-closing-bracket ?\]))
4792             (setq
4793              gnus-tmp-indentation
4794              (aref gnus-thread-indent-array gnus-tmp-level)
4795              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4796              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4797                                 gnus-summary-default-score 0)
4798              gnus-tmp-score-char
4799              (if (or (null gnus-summary-default-score)
4800                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4801                          gnus-summary-zcore-fuzz))
4802                  ?\ ;;;Whitespace
4803                (if (< gnus-tmp-score gnus-summary-default-score)
4804                    gnus-score-below-mark gnus-score-over-mark))
4805              gnus-tmp-replied
4806              (cond ((memq number gnus-newsgroup-processable)
4807                     gnus-process-mark)
4808                    ((memq number gnus-newsgroup-cached)
4809                     gnus-cached-mark)
4810                    ((memq number gnus-newsgroup-replied)
4811                     gnus-replied-mark)
4812                    ((memq number gnus-newsgroup-forwarded)
4813                     gnus-forwarded-mark)
4814                    ((memq number gnus-newsgroup-saved)
4815                     gnus-saved-mark)
4816                    ((memq number gnus-newsgroup-recent)
4817                     gnus-recent-mark)
4818                    ((memq number gnus-newsgroup-unseen)
4819                     gnus-unseen-mark)
4820                    (t gnus-no-mark))
4821              gnus-tmp-downloaded
4822              (cond ((memq number gnus-newsgroup-undownloaded) 
4823                     gnus-undownloaded-mark)
4824                    (gnus-newsgroup-agentized
4825                     gnus-downloaded-mark)
4826                    (t
4827                     gnus-no-mark))
4828              gnus-tmp-from (mail-header-from gnus-tmp-header)
4829              gnus-tmp-name
4830              (cond
4831               ((string-match "<[^>]+> *$" gnus-tmp-from)
4832                (setq beg-match (match-beginning 0))
4833                (or (and (string-match "^\".+\"" gnus-tmp-from)
4834                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4835                    (substring gnus-tmp-from 0 beg-match)))
4836               ((string-match "(.+)" gnus-tmp-from)
4837                (substring gnus-tmp-from
4838                           (1+ (match-beginning 0)) (1- (match-end 0))))
4839               (t gnus-tmp-from))
4840
4841              ;; Do the %B string
4842              gnus-tmp-thread-tree-header-string
4843              (cond
4844               ((not gnus-show-threads) "")
4845               ((zerop gnus-tmp-level)
4846                (cond ((cdar thread)
4847                       (or gnus-sum-thread-tree-root subject))
4848                      (gnus-tmp-new-adopts
4849                       (or gnus-sum-thread-tree-false-root subject))
4850                      (t
4851                       (or gnus-sum-thread-tree-single-indent subject))))
4852               (t
4853                (concat (apply 'concat
4854                               (mapcar (lambda (item)
4855                                         (if (= item 1)
4856                                             gnus-sum-thread-tree-vertical
4857                                           gnus-sum-thread-tree-indent))
4858                                       (cdr (reverse tree-stack))))
4859                        (if (nth 1 thread)
4860                            gnus-sum-thread-tree-leaf-with-other
4861                          gnus-sum-thread-tree-single-leaf)))))
4862             (when (string= gnus-tmp-name "")
4863               (setq gnus-tmp-name gnus-tmp-from))
4864             (unless (numberp gnus-tmp-lines)
4865               (setq gnus-tmp-lines -1))
4866             (if (= gnus-tmp-lines -1)
4867                 (setq gnus-tmp-lines "?")
4868               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4869               (gnus-put-text-property
4870              (point)
4871              (progn (eval gnus-summary-line-format-spec) (point))
4872                'gnus-number number)
4873             (when gnus-visual-p
4874               (forward-line -1)
4875               (gnus-run-hooks 'gnus-summary-update-hook)
4876               (forward-line 1))
4877
4878             (setq gnus-tmp-prev-subject simp-subject)))
4879
4880         (when (nth 1 thread)
4881           (push (list (max 0 gnus-tmp-level)
4882                       (copy-sequence tree-stack)
4883                       (nthcdr 1 thread))
4884                 stack))
4885         (push (if (nth 1 thread) 1 0) tree-stack)
4886         (incf gnus-tmp-level)
4887         (setq threads (if thread-end nil (cdar thread)))
4888         (if gnus-summary-display-while-building
4889             (if building-count
4890                 (progn
4891                   ;; use a set frequency
4892                   (setq building-line-count (1- building-line-count))
4893                   (when (= building-line-count 0)
4894                     (sit-for 0)
4895                     (setq building-line-count
4896                           gnus-summary-display-while-building)))
4897               ;; always
4898               (sit-for 0)))
4899         (unless threads
4900           (setq gnus-tmp-level 0)))))
4901   (gnus-message 7 "Generating summary...done"))
4902
4903 (defun gnus-summary-prepare-unthreaded (headers)
4904   "Generate an unthreaded summary buffer based on HEADERS."
4905   (let (header number mark)
4906
4907     (beginning-of-line)
4908
4909     (while headers
4910       ;; We may have to root out some bad articles...
4911       (when (memq (setq number (mail-header-number
4912                                 (setq header (pop headers))))
4913                   gnus-newsgroup-limit)
4914         ;; Mark article as read when it has a low score.
4915         (when (and gnus-summary-mark-below
4916                    (< (or (cdr (assq number gnus-newsgroup-scored))
4917                           gnus-summary-default-score 0)
4918                       gnus-summary-mark-below)
4919                    (not (gnus-summary-article-ancient-p number)))
4920           (setq gnus-newsgroup-unreads
4921                 (delq number gnus-newsgroup-unreads))
4922           (if gnus-newsgroup-auto-expire
4923               (push number gnus-newsgroup-expirable)
4924             (push (cons number gnus-low-score-mark)
4925                   gnus-newsgroup-reads)))
4926
4927         (setq mark (gnus-article-mark number))
4928         (push (gnus-data-make number mark (1+ (point)) header 0)
4929               gnus-newsgroup-data)
4930         (gnus-summary-insert-line
4931          header 0 number
4932          (memq number gnus-newsgroup-undownloaded)
4933          mark (memq number gnus-newsgroup-replied)
4934          (memq number gnus-newsgroup-expirable)
4935          (mail-header-subject header) nil
4936          (cdr (assq number gnus-newsgroup-scored))
4937          (memq number gnus-newsgroup-processable))))))
4938
4939 (defun gnus-summary-remove-list-identifiers ()
4940   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4941   (let ((regexp (if (consp gnus-list-identifiers)
4942                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4943                   gnus-list-identifiers))
4944         changed subject)
4945     (when regexp
4946       (dolist (header gnus-newsgroup-headers)
4947         (setq subject (mail-header-subject header)
4948               changed nil)
4949         (while (string-match
4950                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4951                 subject)
4952           (setq subject
4953                 (concat (substring subject 0 (match-beginning 2))
4954                         (substring subject (match-end 0)))
4955                 changed t))
4956         (when (and changed
4957                    (string-match
4958                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4959           (setq subject
4960                 (concat (substring subject 0 (match-beginning 1))
4961                         (substring subject (match-end 1)))))
4962         (when changed
4963           (mail-header-set-subject header subject))))))
4964
4965 (defun gnus-fetch-headers (articles)
4966   "Fetch headers of ARTICLES."
4967   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4968     (gnus-message 5 "Fetching headers for %s..." name)
4969     (prog1
4970         (if (eq 'nov
4971                 (setq gnus-headers-retrieved-by
4972                       (gnus-retrieve-headers
4973                        articles gnus-newsgroup-name
4974                        ;; We might want to fetch old headers, but
4975                        ;; not if there is only 1 article.
4976                        (and (or (and
4977                                  (not (eq gnus-fetch-old-headers 'some))
4978                                  (not (numberp gnus-fetch-old-headers)))
4979                                 (> (length articles) 1))
4980                             gnus-fetch-old-headers))))
4981             (gnus-get-newsgroup-headers-xover
4982              articles nil nil gnus-newsgroup-name t)
4983           (gnus-get-newsgroup-headers))
4984       (gnus-message 5 "Fetching headers for %s...done" name))))
4985
4986 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4987   "Select newsgroup GROUP.
4988 If READ-ALL is non-nil, all articles in the group are selected.
4989 If SELECT-ARTICLES, only select those articles from GROUP."
4990   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4991          ;;!!! Dirty hack; should be removed.
4992          (gnus-summary-ignore-duplicates
4993           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4994               t
4995             gnus-summary-ignore-duplicates))
4996          (info (nth 2 entry))
4997          articles fetched-articles cached)
4998
4999     (unless (gnus-check-server
5000              (set (make-local-variable 'gnus-current-select-method)
5001                   (gnus-find-method-for-group group)))
5002       (error "Couldn't open server"))
5003
5004     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5005         (gnus-activate-group group)     ; Or we can activate it...
5006         (progn                          ; Or we bug out.
5007           (when (equal major-mode 'gnus-summary-mode)
5008             (gnus-kill-buffer (current-buffer)))
5009           (error "Couldn't activate group %s: %s"
5010                  group (gnus-status-message group))))
5011
5012     (unless (gnus-request-group group t)
5013       (when (equal major-mode 'gnus-summary-mode)
5014         (gnus-kill-buffer (current-buffer)))
5015       (error "Couldn't request group %s: %s"
5016              group (gnus-status-message group)))
5017
5018     (when gnus-agent
5019       ;; The agent may be storing articles that are no longer in the
5020       ;; server's active range.  If that is the case, the active range
5021       ;; needs to be expanded such that the agent's articles can be
5022       ;; included in the summary.
5023       (let* ((gnus-command-method (gnus-find-method-for-group group))
5024              (alist (gnus-agent-load-alist group))
5025              (active (gnus-active group)))
5026         (if (and (car alist)
5027                  (< (caar alist) (car active)))
5028             (gnus-set-active group (cons (caar alist) (cdr active))))))
5029
5030     (setq gnus-newsgroup-name group
5031           gnus-newsgroup-unselected nil
5032           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5033
5034     (let ((display (gnus-group-find-parameter group 'display)))
5035       (setq gnus-newsgroup-display
5036             (cond
5037              ((not (zerop (or (car-safe read-all) 0)))
5038               ;; The user entered the group with C-u SPC/RET, let's show
5039               ;; all articles.
5040               'gnus-not-ignore)
5041              ((eq display 'all)
5042               'gnus-not-ignore)
5043              ((arrayp display)
5044               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5045              ((numberp display)
5046               ;; The following is probably the "correct" solution, but
5047               ;; it makes Gnus fetch all headers and then limit the
5048               ;; articles (which is slow), so instead we hack the
5049               ;; select-articles parameter instead. -- Simon Josefsson
5050               ;; <jas@kth.se>
5051               ;;
5052               ;; (gnus-byte-compile
5053               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5054               ;;                         display)))))
5055               (setq select-articles
5056                     (gnus-uncompress-range
5057                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5058                              (if (> tmp 0)
5059                                  tmp
5060                                1))
5061                            (cdr (gnus-active group)))))
5062               nil)
5063              (t
5064               nil))))
5065
5066     (gnus-summary-setup-default-charset)
5067
5068     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5069     (when (gnus-virtual-group-p group)
5070       (setq cached gnus-newsgroup-cached))
5071
5072     (setq gnus-newsgroup-unreads
5073           (gnus-sorted-ndifference
5074            (gnus-sorted-ndifference gnus-newsgroup-unreads
5075                                     gnus-newsgroup-marked)
5076            gnus-newsgroup-dormant))
5077
5078     (setq gnus-newsgroup-processable nil)
5079
5080     (gnus-update-read-articles group gnus-newsgroup-unreads)
5081
5082     ;; Adjust and set lists of article marks.
5083     (when info
5084       (gnus-adjust-marked-articles info))
5085     (if (setq articles select-articles)
5086         (setq gnus-newsgroup-unselected
5087               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5088       (setq articles (gnus-articles-to-read group read-all)))
5089
5090     (cond
5091      ((null articles)
5092       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5093       'quit)
5094      ((eq articles 0) nil)
5095      (t
5096       ;; Init the dependencies hash table.
5097       (setq gnus-newsgroup-dependencies
5098             (gnus-make-hashtable (length articles)))
5099       (gnus-set-global-variables)
5100       ;; Retrieve the headers and read them in.
5101
5102       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5103
5104       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5105       (when cached
5106         (setq gnus-newsgroup-cached cached))
5107
5108       ;; Suppress duplicates?
5109       (when gnus-suppress-duplicates
5110         (gnus-dup-suppress-articles))
5111
5112       ;; Set the initial limit.
5113       (setq gnus-newsgroup-limit (copy-sequence articles))
5114       ;; Remove canceled articles from the list of unread articles.
5115       (setq fetched-articles
5116             (mapcar (lambda (headers) (mail-header-number headers))
5117                     gnus-newsgroup-headers))
5118       (setq gnus-newsgroup-articles fetched-articles)
5119       (setq gnus-newsgroup-unreads
5120             (gnus-sorted-nintersection
5121              gnus-newsgroup-unreads fetched-articles))
5122       (gnus-compute-unseen-list)
5123
5124       ;; Removed marked articles that do not exist.
5125       (gnus-update-missing-marks
5126        (gnus-sorted-difference articles fetched-articles))
5127       ;; We might want to build some more threads first.
5128       (when (and gnus-fetch-old-headers
5129                  (eq gnus-headers-retrieved-by 'nov))
5130         (if (eq gnus-fetch-old-headers 'invisible)
5131             (gnus-build-all-threads)
5132           (gnus-build-old-threads)))
5133       ;; Let the Gnus agent mark articles as read.
5134       (when gnus-agent
5135         (gnus-agent-get-undownloaded-list))
5136       ;; Remove list identifiers from subject
5137       (when gnus-list-identifiers
5138         (gnus-summary-remove-list-identifiers))
5139       ;; Check whether auto-expire is to be done in this group.
5140       (setq gnus-newsgroup-auto-expire
5141             (gnus-group-auto-expirable-p group))
5142       ;; Set up the article buffer now, if necessary.
5143       (unless gnus-single-article-buffer
5144         (gnus-article-setup-buffer))
5145       ;; First and last article in this newsgroup.
5146       (when gnus-newsgroup-headers
5147         (setq gnus-newsgroup-begin
5148               (mail-header-number (car gnus-newsgroup-headers))
5149               gnus-newsgroup-end
5150               (mail-header-number
5151                (gnus-last-element gnus-newsgroup-headers))))
5152       ;; GROUP is successfully selected.
5153       (or gnus-newsgroup-headers t)))))
5154
5155 (defun gnus-compute-unseen-list ()
5156   ;; The `seen' marks are treated specially.
5157   (if (not gnus-newsgroup-seen)
5158       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5159     (setq gnus-newsgroup-unseen
5160           (gnus-inverse-list-range-intersection
5161            gnus-newsgroup-articles gnus-newsgroup-seen))))
5162
5163 (defun gnus-summary-display-make-predicate (display)
5164   (require 'gnus-agent)
5165   (when (= (length display) 1)
5166     (setq display (car display)))
5167   (unless gnus-summary-display-cache
5168     (dolist (elem (append '((unread . unread)
5169                             (read . read)
5170                             (unseen . unseen))
5171                           gnus-article-mark-lists))
5172       (push (cons (cdr elem)
5173                   (gnus-byte-compile
5174                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5175             gnus-summary-display-cache)))
5176   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5177         (gnus-category-predicate-cache gnus-summary-display-cache))
5178     (gnus-get-predicate display)))
5179
5180 ;; Uses the dynamically bound `number' variable.
5181 (eval-when-compile
5182   (defvar number))
5183 (defun gnus-article-marked-p (type &optional article)
5184   (let ((article (or article number)))
5185     (cond
5186      ((eq type 'tick)
5187       (memq article gnus-newsgroup-marked))
5188      ((eq type 'spam)
5189       (memq article gnus-newsgroup-spam-marked))
5190      ((eq type 'unsend)
5191       (memq article gnus-newsgroup-unsendable))
5192      ((eq type 'undownload)
5193       (memq article gnus-newsgroup-undownloaded))
5194      ((eq type 'download)
5195       (memq article gnus-newsgroup-downloadable))
5196      ((eq type 'unread)
5197       (memq article gnus-newsgroup-unreads))
5198      ((eq type 'read)
5199       (memq article gnus-newsgroup-reads))
5200      ((eq type 'dormant)
5201       (memq article gnus-newsgroup-dormant) )
5202      ((eq type 'expire)
5203       (memq article gnus-newsgroup-expirable))
5204      ((eq type 'reply)
5205       (memq article gnus-newsgroup-replied))
5206      ((eq type 'killed)
5207       (memq article gnus-newsgroup-killed))
5208      ((eq type 'bookmark)
5209       (assq article gnus-newsgroup-bookmarks))
5210      ((eq type 'score)
5211       (assq article gnus-newsgroup-scored))
5212      ((eq type 'save)
5213       (memq article gnus-newsgroup-saved))
5214      ((eq type 'cache)
5215       (memq article gnus-newsgroup-cached))
5216      ((eq type 'forward)
5217       (memq article gnus-newsgroup-forwarded))
5218      ((eq type 'seen)
5219       (not (memq article gnus-newsgroup-unseen)))
5220      ((eq type 'recent)
5221       (memq article gnus-newsgroup-recent))
5222      (t t))))
5223
5224 (defun gnus-articles-to-read (group &optional read-all)
5225   "Find out what articles the user wants to read."
5226   (let* ((display (gnus-group-find-parameter group 'display))
5227          (articles
5228           ;; Select all articles if `read-all' is non-nil, or if there
5229           ;; are no unread articles.
5230           (if (or read-all
5231                   (and (zerop (length gnus-newsgroup-marked))
5232                        (zerop (length gnus-newsgroup-unreads)))
5233                   ;; Fetch all if the predicate is non-nil.
5234                   gnus-newsgroup-display)
5235               ;; We want to select the headers for all the articles in
5236               ;; the group, so we select either all the active
5237               ;; articles in the group, or (if that's nil), the
5238               ;; articles in the cache.
5239               (or
5240                (gnus-uncompress-range (gnus-active group))
5241                (gnus-cache-articles-in-group group))
5242             ;; Select only the "normal" subset of articles.
5243             (gnus-sorted-nunion
5244              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5245              gnus-newsgroup-unreads)))
5246          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5247          (scored (length scored-list))
5248          (number (length articles))
5249          (marked (+ (length gnus-newsgroup-marked)
5250                     (length gnus-newsgroup-dormant)))
5251          (select
5252           (cond
5253            ((numberp read-all)
5254             read-all)
5255            ((numberp gnus-newsgroup-display)
5256             gnus-newsgroup-display)
5257            (t
5258             (condition-case ()
5259                 (cond
5260                  ((and (or (<= scored marked) (= scored number))
5261                        (numberp gnus-large-newsgroup)
5262                        (> number gnus-large-newsgroup))
5263                   (let* ((cursor-in-echo-area nil)
5264                          (initial (gnus-parameter-large-newsgroup-initial
5265                                    gnus-newsgroup-name))
5266                          (input
5267                           (read-string
5268                            (format
5269                             "How many articles from %s (%s %d): "
5270                             (gnus-limit-string
5271                              (gnus-group-decoded-name gnus-newsgroup-name)
5272                              35)
5273                             (if initial "max" "default")
5274                             number)
5275                            (if initial
5276                                (cons (number-to-string initial)
5277                                      0)))))
5278                     (if (string-match "^[ \t]*$" input) number input)))
5279                  ((and (> scored marked) (< scored number)
5280                        (> (- scored number) 20))
5281                   (let ((input
5282                          (read-string
5283                           (format "%s %s (%d scored, %d total): "
5284                                   "How many articles from"
5285                                   (gnus-group-decoded-name group)
5286                                   scored number))))
5287                     (if (string-match "^[ \t]*$" input)
5288                         number input)))
5289                  (t number))
5290               (quit
5291                (message "Quit getting the articles to read")
5292                nil))))))
5293     (setq select (if (stringp select) (string-to-number select) select))
5294     (if (or (null select) (zerop select))
5295         select
5296       (if (and (not (zerop scored)) (<= (abs select) scored))
5297           (progn
5298             (setq articles (sort scored-list '<))
5299             (setq number (length articles)))
5300         (setq articles (copy-sequence articles)))
5301
5302       (when (< (abs select) number)
5303         (if (< select 0)
5304             ;; Select the N oldest articles.
5305             (setcdr (nthcdr (1- (abs select)) articles) nil)
5306           ;; Select the N most recent articles.
5307           (setq articles (nthcdr (- number select) articles))))
5308       (setq gnus-newsgroup-unselected
5309             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5310       (when gnus-alter-articles-to-read-function
5311         (setq articles
5312               (sort
5313                (funcall gnus-alter-articles-to-read-function
5314                         gnus-newsgroup-name articles)
5315                '<)))
5316       articles)))
5317
5318 (defun gnus-killed-articles (killed articles)
5319   (let (out)
5320     (while articles
5321       (when (inline (gnus-member-of-range (car articles) killed))
5322         (push (car articles) out))
5323       (setq articles (cdr articles)))
5324     out))
5325
5326 (defun gnus-uncompress-marks (marks)
5327   "Uncompress the mark ranges in MARKS."
5328   (let ((uncompressed '(score bookmark))
5329         out)
5330     (while marks
5331       (if (memq (caar marks) uncompressed)
5332           (push (car marks) out)
5333         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5334       (setq marks (cdr marks)))
5335     out))
5336
5337 (defun gnus-article-mark-to-type (mark)
5338   "Return the type of MARK."
5339   (or (cadr (assq mark gnus-article-special-mark-lists))
5340       'list))
5341
5342 (defun gnus-article-unpropagatable-p (mark)
5343   "Return whether MARK should be propagated to backend."
5344   (memq mark gnus-article-unpropagated-mark-lists))
5345
5346 (defun gnus-adjust-marked-articles (info)
5347   "Set all article lists and remove all marks that are no longer valid."
5348   (let* ((marked-lists (gnus-info-marks info))
5349          (active (gnus-active (gnus-info-group info)))
5350          (min (car active))
5351          (max (cdr active))
5352          (types gnus-article-mark-lists)
5353          marks var articles article mark mark-type)
5354
5355     (dolist (marks marked-lists)
5356       (setq mark (car marks)
5357             mark-type (gnus-article-mark-to-type mark)
5358             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5359
5360       ;; We set the variable according to the type of the marks list,
5361       ;; and then adjust the marks to a subset of the active articles.
5362       (cond
5363        ;; Adjust "simple" lists.
5364        ((eq mark-type 'list)
5365         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5366         (when (memq mark '(tick dormant expire reply save))
5367           (while articles
5368             (when (or (< (setq article (pop articles)) min) (> article max))
5369               (set var (delq article (symbol-value var)))))))
5370        ;; Adjust assocs.
5371        ((eq mark-type 'tuple)
5372         (set var (setq articles (cdr marks)))
5373         (when (not (listp (cdr (symbol-value var))))
5374           (set var (list (symbol-value var))))
5375         (when (not (listp (cdr articles)))
5376           (setq articles (list articles)))
5377         (while articles
5378           (when (or (not (consp (setq article (pop articles))))
5379                     (< (car article) min)
5380                     (> (car article) max))
5381             (set var (delq article (symbol-value var))))))
5382        ;; Adjust ranges (sloppily).
5383        ((eq mark-type 'range)
5384         (cond
5385          ((eq mark 'seen)
5386           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5387           ;; It should be (seen (NUM1 . NUM2)).
5388           (when (numberp (cddr marks))
5389             (setcdr marks (list (cdr marks))))
5390           (setq articles (cdr marks))
5391           (while (and articles
5392                       (or (and (consp (car articles))
5393                                (> min (cdar articles)))
5394                           (and (numberp (car articles))
5395                                (> min (car articles)))))
5396             (pop articles))
5397           (set var articles))))))))
5398
5399 (defun gnus-update-missing-marks (missing)
5400   "Go through the list of MISSING articles and remove them from the mark lists."
5401   (when missing
5402     (let (var m)
5403       ;; Go through all types.
5404       (dolist (elem gnus-article-mark-lists)
5405         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5406           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5407           (when (symbol-value var)
5408             ;; This list has articles.  So we delete all missing
5409             ;; articles from it.
5410             (setq m missing)
5411             (while m
5412               (set var (delq (pop m) (symbol-value var))))))))))
5413
5414 (defun gnus-update-marks ()
5415   "Enter the various lists of marked articles into the newsgroup info list."
5416   (let ((types gnus-article-mark-lists)
5417         (info (gnus-get-info gnus-newsgroup-name))
5418         type list newmarked symbol delta-marks)
5419     (when info
5420       ;; Add all marks lists to the list of marks lists.
5421       (while (setq type (pop types))
5422         (setq list (symbol-value
5423                     (setq symbol
5424                           (intern (format "gnus-newsgroup-%s" (car type))))))
5425
5426         (when list
5427           ;; Get rid of the entries of the articles that have the
5428           ;; default score.
5429           (when (and (eq (cdr type) 'score)
5430                      gnus-save-score
5431                      list)
5432             (let* ((arts list)
5433                    (prev (cons nil list))
5434                    (all prev))
5435               (while arts
5436                 (if (or (not (consp (car arts)))
5437                         (= (cdar arts) gnus-summary-default-score))
5438                     (setcdr prev (cdr arts))
5439                   (setq prev arts))
5440                 (setq arts (cdr arts)))
5441               (setq list (cdr all)))))
5442
5443         (when (eq (cdr type) 'seen)
5444           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5445
5446         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5447           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5448
5449         (when (and (gnus-check-backend-function
5450                     'request-set-mark gnus-newsgroup-name)
5451                    (not (gnus-article-unpropagatable-p (cdr type))))
5452           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5453                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5454                  (add (gnus-remove-from-range
5455                        (gnus-copy-sequence list) old)))
5456             (when add
5457               (push (list add 'add (list (cdr type))) delta-marks))
5458             (when del
5459               (push (list del 'del (list (cdr type))) delta-marks))))
5460
5461         (when list
5462           (push (cons (cdr type) list) newmarked)))
5463
5464       (when delta-marks
5465         (unless (gnus-check-group gnus-newsgroup-name)
5466           (error "Can't open server for %s" gnus-newsgroup-name))
5467         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5468
5469       ;; Enter these new marks into the info of the group.
5470       (if (nthcdr 3 info)
5471           (setcar (nthcdr 3 info) newmarked)
5472         ;; Add the marks lists to the end of the info.
5473         (when newmarked
5474           (setcdr (nthcdr 2 info) (list newmarked))))
5475
5476       ;; Cut off the end of the info if there's nothing else there.
5477       (let ((i 5))
5478         (while (and (> i 2)
5479                     (not (nth i info)))
5480           (when (nthcdr (decf i) info)
5481             (setcdr (nthcdr i info) nil)))))))
5482
5483 (defun gnus-set-mode-line (where)
5484   "Set the mode line of the article or summary buffers.
5485 If WHERE is `summary', the summary mode line format will be used."
5486   ;; Is this mode line one we keep updated?
5487   (when (and (memq where gnus-updated-mode-lines)
5488              (symbol-value
5489               (intern (format "gnus-%s-mode-line-format-spec" where))))
5490     (let (mode-string)
5491       (save-excursion
5492         ;; We evaluate this in the summary buffer since these
5493         ;; variables are buffer-local to that buffer.
5494         (set-buffer gnus-summary-buffer)
5495         ;; We bind all these variables that are used in the `eval' form
5496         ;; below.
5497         (let* ((mformat (symbol-value
5498                          (intern
5499                           (format "gnus-%s-mode-line-format-spec" where))))
5500                (gnus-tmp-group-name (gnus-group-decoded-name
5501                                      gnus-newsgroup-name))
5502                (gnus-tmp-article-number (or gnus-current-article 0))
5503                (gnus-tmp-unread gnus-newsgroup-unreads)
5504                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5505                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5506                (gnus-tmp-unread-and-unselected
5507                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5508                             (zerop gnus-tmp-unselected))
5509                        "")
5510                       ((zerop gnus-tmp-unselected)
5511                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5512                       (t (format "{%d(+%d) more}"
5513                                  gnus-tmp-unread-and-unticked
5514                                  gnus-tmp-unselected))))
5515                (gnus-tmp-subject
5516                 (if (and gnus-current-headers
5517                          (vectorp gnus-current-headers))
5518                     (gnus-mode-string-quote
5519                      (mail-header-subject gnus-current-headers))
5520                   ""))
5521                bufname-length max-len
5522                gnus-tmp-header);; passed as argument to any user-format-funcs
5523           (setq mode-string (eval mformat))
5524           (setq bufname-length (if (string-match "%b" mode-string)
5525                                    (- (length
5526                                        (buffer-name
5527                                         (if (eq where 'summary)
5528                                             nil
5529                                           (get-buffer gnus-article-buffer))))
5530                                       2)
5531                                  0))
5532           (setq max-len (max 4 (if gnus-mode-non-string-length
5533                                    (- (window-width)
5534                                       gnus-mode-non-string-length
5535                                       bufname-length)
5536                                  (length mode-string))))
5537           ;; We might have to chop a bit of the string off...
5538           (when (> (length mode-string) max-len)
5539             (setq mode-string
5540                   (concat (gnus-truncate-string mode-string (- max-len 3))
5541                           "...")))
5542           ;; Pad the mode string a bit.
5543           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5544       ;; Update the mode line.
5545       (setq mode-line-buffer-identification
5546             (gnus-mode-line-buffer-identification (list mode-string)))
5547       (set-buffer-modified-p t))))
5548
5549 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5550   "Go through the HEADERS list and add all Xrefs to a hash table.
5551 The resulting hash table is returned, or nil if no Xrefs were found."
5552   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5553          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5554          (xref-hashtb (gnus-make-hashtable))
5555          start group entry number xrefs header)
5556     (while headers
5557       (setq header (pop headers))
5558       (when (and (setq xrefs (mail-header-xref header))
5559                  (not (memq (setq number (mail-header-number header))
5560                             unreads)))
5561         (setq start 0)
5562         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5563           (setq start (match-end 0))
5564           (setq group (if prefix
5565                           (concat prefix (substring xrefs (match-beginning 1)
5566                                                     (match-end 1)))
5567                         (substring xrefs (match-beginning 1) (match-end 1))))
5568           (setq number
5569                 (string-to-int (substring xrefs (match-beginning 2)
5570                                           (match-end 2))))
5571           (if (setq entry (gnus-gethash group xref-hashtb))
5572               (setcdr entry (cons number (cdr entry)))
5573             (gnus-sethash group (cons number nil) xref-hashtb)))))
5574     (and start xref-hashtb)))
5575
5576 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5577   "Look through all the headers and mark the Xrefs as read."
5578   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5579         name entry info xref-hashtb idlist method nth4)
5580     (save-excursion
5581       (set-buffer gnus-group-buffer)
5582       (when (setq xref-hashtb
5583                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5584         (mapatoms
5585          (lambda (group)
5586            (unless (string= from-newsgroup (setq name (symbol-name group)))
5587              (setq idlist (symbol-value group))
5588              ;; Dead groups are not updated.
5589              (and (prog1
5590                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5591                             info (nth 2 entry))
5592                     (when (stringp (setq nth4 (gnus-info-method info)))
5593                       (setq nth4 (gnus-server-to-method nth4))))
5594                   ;; Only do the xrefs if the group has the same
5595                   ;; select method as the group we have just read.
5596                   (or (gnus-methods-equal-p
5597                        nth4 (gnus-find-method-for-group from-newsgroup))
5598                       virtual
5599                       (equal nth4 (setq method (gnus-find-method-for-group
5600                                                 from-newsgroup)))
5601                       (and (equal (car nth4) (car method))
5602                            (equal (nth 1 nth4) (nth 1 method))))
5603                   gnus-use-cross-reference
5604                   (or (not (eq gnus-use-cross-reference t))
5605                       virtual
5606                       ;; Only do cross-references on subscribed
5607                       ;; groups, if that is what is wanted.
5608                       (<= (gnus-info-level info) gnus-level-subscribed))
5609                   (gnus-group-make-articles-read name idlist))))
5610          xref-hashtb)))))
5611
5612 (defun gnus-compute-read-articles (group articles)
5613   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5614          (info (nth 2 entry))
5615          (active (gnus-active group))
5616          ninfo)
5617     (when entry
5618       ;; First peel off all invalid article numbers.
5619       (when active
5620         (let ((ids articles)
5621               id first)
5622           (while (setq id (pop ids))
5623             (when (and first (> id (cdr active)))
5624               ;; We'll end up in this situation in one particular
5625               ;; obscure situation.  If you re-scan a group and get
5626               ;; a new article that is cross-posted to a different
5627               ;; group that has not been re-scanned, you might get
5628               ;; crossposted article that has a higher number than
5629               ;; Gnus believes possible.  So we re-activate this
5630               ;; group as well.  This might mean doing the
5631               ;; crossposting thingy will *increase* the number
5632               ;; of articles in some groups.  Tsk, tsk.
5633               (setq active (or (gnus-activate-group group) active)))
5634             (when (or (> id (cdr active))
5635                       (< id (car active)))
5636               (setq articles (delq id articles))))))
5637       ;; If the read list is nil, we init it.
5638       (if (and active
5639                (null (gnus-info-read info))
5640                (> (car active) 1))
5641           (setq ninfo (cons 1 (1- (car active))))
5642         (setq ninfo (gnus-info-read info)))
5643       ;; Then we add the read articles to the range.
5644       (gnus-add-to-range
5645        ninfo (setq articles (sort articles '<))))))
5646
5647 (defun gnus-group-make-articles-read (group articles)
5648   "Update the info of GROUP to say that ARTICLES are read."
5649   (let* ((num 0)
5650          (entry (gnus-gethash group gnus-newsrc-hashtb))
5651          (info (nth 2 entry))
5652          (active (gnus-active group))
5653          range)
5654     (when entry
5655       (setq range (gnus-compute-read-articles group articles))
5656       (save-excursion
5657         (set-buffer gnus-group-buffer)
5658         (gnus-undo-register
5659           `(progn
5660              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5661              (gnus-info-set-read ',info ',(gnus-info-read info))
5662              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5663              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5664              (gnus-group-update-group ,group t))))
5665       ;; Add the read articles to the range.
5666       (gnus-info-set-read info range)
5667       (gnus-request-set-mark group (list (list range 'add '(read))))
5668       ;; Then we have to re-compute how many unread
5669       ;; articles there are in this group.
5670       (when active
5671         (cond
5672          ((not range)
5673           (setq num (- (1+ (cdr active)) (car active))))
5674          ((not (listp (cdr range)))
5675           (setq num (- (cdr active) (- (1+ (cdr range))
5676                                        (car range)))))
5677          (t
5678           (while range
5679             (if (numberp (car range))
5680                 (setq num (1+ num))
5681               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5682             (setq range (cdr range)))
5683           (setq num (- (cdr active) num))))
5684         ;; Update the number of unread articles.
5685         (setcar entry num)
5686         ;; Update the group buffer.
5687         (unless (gnus-ephemeral-group-p group)
5688           (gnus-group-update-group group t))))))
5689
5690 (defvar gnus-newsgroup-none-id 0)
5691
5692 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5693   (let ((cur nntp-server-buffer)
5694         (dependencies
5695          (or dependencies
5696              (save-excursion (set-buffer gnus-summary-buffer)
5697                              gnus-newsgroup-dependencies)))
5698         headers id end ref
5699         (mail-parse-charset gnus-newsgroup-charset)
5700         (mail-parse-ignored-charsets
5701          (save-excursion (condition-case nil
5702                              (set-buffer gnus-summary-buffer)
5703                            (error))
5704                          gnus-newsgroup-ignored-charsets)))
5705     (save-excursion
5706       (set-buffer nntp-server-buffer)
5707       ;; Translate all TAB characters into SPACE characters.
5708       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5709       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5710       (gnus-run-hooks 'gnus-parse-headers-hook)
5711       (let ((case-fold-search t)
5712             in-reply-to header p lines chars ctype)
5713         (goto-char (point-min))
5714         ;; Search to the beginning of the next header.  Error messages
5715         ;; do not begin with 2 or 3.
5716         (while (re-search-forward "^[23][0-9]+ " nil t)
5717           (setq id nil
5718                 ref nil)
5719           ;; This implementation of this function, with nine
5720           ;; search-forwards instead of the one re-search-forward and
5721           ;; a case (which basically was the old function) is actually
5722           ;; about twice as fast, even though it looks messier.  You
5723           ;; can't have everything, I guess.  Speed and elegance
5724           ;; doesn't always go hand in hand.
5725           (setq
5726            header
5727            (make-full-mail-header
5728             ;; Number.
5729             (prog1
5730                 (read cur)
5731               (end-of-line)
5732               (setq p (point))
5733               (narrow-to-region (point)
5734                                 (or (and (search-forward "\n.\n" nil t)
5735                                          (- (point) 2))
5736                                     (point))))
5737             ;; Subject.
5738             (progn
5739               (goto-char p)
5740               (if (search-forward "\nsubject:" nil t)
5741                   (nnheader-header-value)
5742                 "(none)"))
5743             ;; From.
5744             (progn
5745               (goto-char p)
5746               (if (search-forward "\nfrom:" nil t)
5747                   (nnheader-header-value)
5748                 "(nobody)"))
5749             ;; Date.
5750             (progn
5751               (goto-char p)
5752               (if (search-forward "\ndate:" nil t)
5753                   (nnheader-header-value) ""))
5754             ;; Message-ID.
5755             (progn
5756               (goto-char p)
5757               (setq id (if (re-search-forward
5758                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5759                            ;; We do it this way to make sure the Message-ID
5760                            ;; is (somewhat) syntactically valid.
5761                            (buffer-substring (match-beginning 1)
5762                                              (match-end 1))
5763                          ;; If there was no message-id, we just fake one
5764                          ;; to make subsequent routines simpler.
5765                          (nnheader-generate-fake-message-id))))
5766             ;; References.
5767             (progn
5768               (goto-char p)
5769               (if (search-forward "\nreferences:" nil t)
5770                   (progn
5771                     (setq end (point))
5772                     (prog1
5773                         (nnheader-header-value)
5774                       (setq ref
5775                             (buffer-substring
5776                              (progn
5777                                ;; (end-of-line)
5778                                (search-backward ">" end t)
5779                                (1+ (point)))
5780                              (progn
5781                                (search-backward "<" end t)
5782                                (point))))))
5783                 ;; Get the references from the in-reply-to header if there
5784                 ;; were no references and the in-reply-to header looks
5785                 ;; promising.
5786                 (if (and (search-forward "\nin-reply-to:" nil t)
5787                          (setq in-reply-to (nnheader-header-value))
5788                          (string-match "<[^>]+>" in-reply-to))
5789                     (let (ref2)
5790                       (setq ref (substring in-reply-to (match-beginning 0)
5791                                            (match-end 0)))
5792                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5793                         (setq ref2 (substring in-reply-to (match-beginning 0)
5794                                               (match-end 0)))
5795                         (when (> (length ref2) (length ref))
5796                           (setq ref ref2)))
5797                       ref)
5798                   (setq ref nil))))
5799             ;; Chars.
5800             (progn
5801               (goto-char p)
5802               (if (search-forward "\nchars: " nil t)
5803                   (if (numberp (setq chars (ignore-errors (read cur))))
5804                       chars -1)
5805                 -1))
5806             ;; Lines.
5807             (progn
5808               (goto-char p)
5809               (if (search-forward "\nlines: " nil t)
5810                   (if (numberp (setq lines (ignore-errors (read cur))))
5811                       lines -1)
5812                 -1))
5813             ;; Xref.
5814             (progn
5815               (goto-char p)
5816               (and (search-forward "\nxref:" nil t)
5817                    (nnheader-header-value)))
5818             ;; Extra.
5819             (when gnus-extra-headers
5820               (let ((extra gnus-extra-headers)
5821                     out)
5822                 (while extra
5823                   (goto-char p)
5824                   (when (search-forward
5825                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5826                     (push (cons (car extra) (nnheader-header-value)) out))
5827                   (pop extra))
5828                 out))))
5829           (goto-char p)
5830           (if (and (search-forward "\ncontent-type: " nil t)
5831                    (setq ctype (nnheader-header-value)))
5832               (mime-entity-set-content-type-internal
5833                header (mime-parse-Content-Type ctype)))
5834           (when (equal id ref)
5835             (setq ref nil))
5836
5837           (when gnus-alter-header-function
5838             (funcall gnus-alter-header-function header)
5839             (setq id (mail-header-id header)
5840                   ref (gnus-parent-id (mail-header-references header))))
5841
5842           (when (setq header
5843                       (gnus-dependencies-add-header
5844                        header dependencies force-new))
5845             (push header headers))
5846           (goto-char (point-max))
5847           (widen))
5848         (nreverse headers)))))
5849
5850 ;; Goes through the xover lines and returns a list of vectors
5851 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5852                                                   force-new dependencies
5853                                                   group also-fetch-heads)
5854   "Parse the news overview data in the server buffer.
5855 Return a list of headers that match SEQUENCE (see
5856 `nntp-retrieve-headers')."
5857   ;; Get the Xref when the users reads the articles since most/some
5858   ;; NNTP servers do not include Xrefs when using XOVER.
5859   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5860   (let ((mail-parse-charset gnus-newsgroup-charset)
5861         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5862         (cur nntp-server-buffer)
5863         (dependencies (or dependencies gnus-newsgroup-dependencies))
5864         (allp (cond
5865                ((eq gnus-read-all-available-headers t)
5866                 t)
5867                ((stringp gnus-read-all-available-headers)
5868                 (string-match gnus-read-all-available-headers group))
5869                (t
5870                 nil)))
5871         number headers header)
5872     (save-excursion
5873       (set-buffer nntp-server-buffer)
5874       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5875       ;; Allow the user to mangle the headers before parsing them.
5876       (gnus-run-hooks 'gnus-parse-headers-hook)
5877       (goto-char (point-min))
5878       (gnus-parse-without-error
5879         (while (and (or sequence allp)
5880                     (not (eobp)))
5881           (setq number (read cur))
5882           (when (not allp)
5883             (while (and sequence
5884                         (< (car sequence) number))
5885               (setq sequence (cdr sequence))))
5886           (when (and (or allp
5887                          (and sequence
5888                               (eq number (car sequence))))
5889                      (progn
5890                        (setq sequence (cdr sequence))
5891                        (setq header (inline
5892                                       (gnus-nov-parse-line
5893                                        number dependencies force-new)))))
5894             (push header headers))
5895           (forward-line 1)))
5896       ;; A common bug in inn is that if you have posted an article and
5897       ;; then retrieves the active file, it will answer correctly --
5898       ;; the new article is included.  However, a NOV entry for the
5899       ;; article may not have been generated yet, so this may fail.
5900       ;; We work around this problem by retrieving the last few
5901       ;; headers using HEAD.
5902       (if (or (not also-fetch-heads)
5903               (not sequence))
5904           ;; We (probably) got all the headers.
5905           (nreverse headers)
5906         (let ((gnus-nov-is-evil t))
5907           (nconc
5908            (nreverse headers)
5909            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5910              (gnus-get-newsgroup-headers))))))))
5911
5912 (defun gnus-article-get-xrefs ()
5913   "Fill in the Xref value in `gnus-current-headers', if necessary.
5914 This is meant to be called in `gnus-article-internal-prepare-hook'."
5915   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5916                                  gnus-current-headers)))
5917     (or (not gnus-use-cross-reference)
5918         (not headers)
5919         (and (mail-header-xref headers)
5920              (not (string= (mail-header-xref headers) "")))
5921         (let ((case-fold-search t)
5922               xref)
5923           (save-restriction
5924             (nnheader-narrow-to-headers)
5925             (goto-char (point-min))
5926             (when (or (and (not (eobp))
5927                            (eq (downcase (char-after)) ?x)
5928                            (looking-at "Xref:"))
5929                       (search-forward "\nXref:" nil t))
5930               (goto-char (1+ (match-end 0)))
5931               (setq xref (buffer-substring (point) (gnus-point-at-eol)))
5932               (mail-header-set-xref headers xref)))))))
5933
5934 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5935   "Find article ID and insert the summary line for that article.
5936 OLD-HEADER can either be a header or a line number to insert
5937 the subject line on."
5938   (let* ((line (and (numberp old-header) old-header))
5939          (old-header (and (vectorp old-header) old-header))
5940          (header (cond ((and old-header use-old-header)
5941                         old-header)
5942                        ((and (numberp id)
5943                              (gnus-number-to-header id))
5944                         (gnus-number-to-header id))
5945                        (t
5946                         (gnus-read-header id))))
5947          (number (and (numberp id) id))
5948          d)
5949     (when header
5950       ;; Rebuild the thread that this article is part of and go to the
5951       ;; article we have fetched.
5952       (when (and (not gnus-show-threads)
5953                  old-header)
5954         (when (and number
5955                    (setq d (gnus-data-find (mail-header-number old-header))))
5956           (goto-char (gnus-data-pos d))
5957           (gnus-data-remove
5958            number
5959            (- (gnus-point-at-bol)
5960               (prog1
5961                   (1+ (gnus-point-at-eol))
5962                 (gnus-delete-line))))))
5963       (when old-header
5964         (mail-header-set-number header (mail-header-number old-header)))
5965       (setq gnus-newsgroup-sparse
5966             (delq (setq number (mail-header-number header))
5967                   gnus-newsgroup-sparse))
5968       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5969       (push number gnus-newsgroup-limit)
5970       (gnus-rebuild-thread (mail-header-id header) line)
5971       (gnus-summary-goto-subject number nil t))
5972     (when (and (numberp number)
5973                (> number 0))
5974       ;; We have to update the boundaries even if we can't fetch the
5975       ;; article if ID is a number -- so that the next `P' or `N'
5976       ;; command will fetch the previous (or next) article even
5977       ;; if the one we tried to fetch this time has been canceled.
5978       (when (> number gnus-newsgroup-end)
5979         (setq gnus-newsgroup-end number))
5980       (when (< number gnus-newsgroup-begin)
5981         (setq gnus-newsgroup-begin number))
5982       (setq gnus-newsgroup-unselected
5983             (delq number gnus-newsgroup-unselected)))
5984     ;; Report back a success?
5985     (and header (mail-header-number header))))
5986
5987 ;;; Process/prefix in the summary buffer
5988
5989 (defun gnus-summary-work-articles (n)
5990   "Return a list of articles to be worked upon.
5991 The prefix argument, the list of process marked articles, and the
5992 current article will be taken into consideration."
5993   (save-excursion
5994     (set-buffer gnus-summary-buffer)
5995     (cond
5996      (n
5997       ;; A numerical prefix has been given.
5998       (setq n (prefix-numeric-value n))
5999       (let ((backward (< n 0))
6000             (n (abs (prefix-numeric-value n)))
6001             articles article)
6002         (save-excursion
6003           (while
6004               (and (> n 0)
6005                    (push (setq article (gnus-summary-article-number))
6006                          articles)
6007                    (if backward
6008                        (gnus-summary-find-prev nil article)
6009                      (gnus-summary-find-next nil article)))
6010             (decf n)))
6011         (nreverse articles)))
6012      ((and (gnus-region-active-p) (mark))
6013       (message "region active")
6014       ;; Work on the region between point and mark.
6015       (let ((max (max (point) (mark)))
6016             articles article)
6017         (save-excursion
6018           (goto-char (min (point) (mark)))
6019           (while
6020               (and
6021                (push (setq article (gnus-summary-article-number)) articles)
6022                (gnus-summary-find-next nil article)
6023                (< (point) max)))
6024           (nreverse articles))))
6025      (gnus-newsgroup-processable
6026       ;; There are process-marked articles present.
6027       ;; Save current state.
6028       (gnus-summary-save-process-mark)
6029       ;; Return the list.
6030       (reverse gnus-newsgroup-processable))
6031      (t
6032       ;; Just return the current article.
6033       (list (gnus-summary-article-number))))))
6034
6035 (defmacro gnus-summary-iterate (arg &rest forms)
6036   "Iterate over the process/prefixed articles and do FORMS.
6037 ARG is the interactive prefix given to the command.  FORMS will be
6038 executed with point over the summary line of the articles."
6039   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6040     `(let ((,articles (gnus-summary-work-articles ,arg)))
6041        (while ,articles
6042          (gnus-summary-goto-subject (car ,articles))
6043          ,@forms
6044          (pop ,articles)))))
6045
6046 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6047 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6048
6049 (defun gnus-summary-save-process-mark ()
6050   "Push the current set of process marked articles on the stack."
6051   (interactive)
6052   (push (copy-sequence gnus-newsgroup-processable)
6053         gnus-newsgroup-process-stack))
6054
6055 (defun gnus-summary-kill-process-mark ()
6056   "Push the current set of process marked articles on the stack and unmark."
6057   (interactive)
6058   (gnus-summary-save-process-mark)
6059   (gnus-summary-unmark-all-processable))
6060
6061 (defun gnus-summary-yank-process-mark ()
6062   "Pop the last process mark state off the stack and restore it."
6063   (interactive)
6064   (unless gnus-newsgroup-process-stack
6065     (error "Empty mark stack"))
6066   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6067
6068 (defun gnus-summary-process-mark-set (set)
6069   "Make SET into the current process marked articles."
6070   (gnus-summary-unmark-all-processable)
6071   (while set
6072     (gnus-summary-set-process-mark (pop set))))
6073
6074 ;;; Searching and stuff
6075
6076 (defun gnus-summary-search-group (&optional backward use-level)
6077   "Search for next unread newsgroup.
6078 If optional argument BACKWARD is non-nil, search backward instead."
6079   (save-excursion
6080     (set-buffer gnus-group-buffer)
6081     (when (gnus-group-search-forward
6082            backward nil (if use-level (gnus-group-group-level) nil))
6083       (gnus-group-group-name))))
6084
6085 (defun gnus-summary-best-group (&optional exclude-group)
6086   "Find the name of the best unread group.
6087 If EXCLUDE-GROUP, do not go to this group."
6088   (save-excursion
6089     (set-buffer gnus-group-buffer)
6090     (save-excursion
6091       (gnus-group-best-unread-group exclude-group))))
6092
6093 (defun gnus-summary-find-next (&optional unread article backward)
6094   (if backward (gnus-summary-find-prev unread article)
6095     (let* ((dummy (gnus-summary-article-intangible-p))
6096            (article (or article (gnus-summary-article-number)))
6097            (data (gnus-data-find-list article))
6098            result)
6099       (when (and (not dummy)
6100                  (or (not gnus-summary-check-current)
6101                      (not unread)
6102                      (not (gnus-data-unread-p (car data)))))
6103         (setq data (cdr data)))
6104       (when (setq result
6105                   (if unread
6106                       (progn
6107                         (while data
6108                           (unless (memq (gnus-data-number (car data)) 
6109                                         (cond ((eq gnus-auto-goto-ignores 'always-undownloaded)
6110                                                gnus-newsgroup-undownloaded)
6111                                               (gnus-plugged
6112                                                nil)
6113                                               ((eq gnus-auto-goto-ignores 'unfetched)
6114                                                gnus-newsgroup-unfetched)
6115                                               ((eq gnus-auto-goto-ignores 'undownloaded)
6116                                                gnus-newsgroup-undownloaded)))
6117                             (when (gnus-data-unread-p (car data))
6118                               (setq result (car data)
6119                                     data nil)))
6120                           (setq data (cdr data)))
6121                         result)
6122                     (car data)))
6123         (goto-char (gnus-data-pos result))
6124         (gnus-data-number result)))))
6125
6126 (defun gnus-summary-find-prev (&optional unread article)
6127   (let* ((eobp (eobp))
6128          (article (or article (gnus-summary-article-number)))
6129          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6130          result)
6131     (when (and (not eobp)
6132                (or (not gnus-summary-check-current)
6133                    (not unread)
6134                    (not (gnus-data-unread-p (car data)))))
6135       (setq data (cdr data)))
6136     (when (setq result
6137                 (if unread
6138                     (progn
6139                       (while data
6140                         (unless (memq (gnus-data-number (car data))
6141                                       (cond ((eq gnus-auto-goto-ignores 'always-undownloaded)
6142                                              gnus-newsgroup-undownloaded)
6143                                             (gnus-plugged
6144                                              nil)
6145                                             ((eq gnus-auto-goto-ignores 'unfetched)
6146                                              gnus-newsgroup-unfetched)
6147                                             ((eq gnus-auto-goto-ignores 'undownloaded)
6148                                              gnus-newsgroup-undownloaded)))
6149                           (when (gnus-data-unread-p (car data))
6150                             (setq result (car data)
6151                                   data nil)))
6152                         (setq data (cdr data)))
6153                       result)
6154                   (car data)))
6155       (goto-char (gnus-data-pos result))
6156       (gnus-data-number result))))
6157
6158 (defun gnus-summary-find-subject (subject &optional unread backward article)
6159   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6160          (article (or article (gnus-summary-article-number)))
6161          (articles (gnus-data-list backward))
6162          (arts (gnus-data-find-list article articles))
6163          result)
6164     (when (or (not gnus-summary-check-current)
6165               (not unread)
6166               (not (gnus-data-unread-p (car arts))))
6167       (setq arts (cdr arts)))
6168     (while arts
6169       (and (or (not unread)
6170                (gnus-data-unread-p (car arts)))
6171            (vectorp (gnus-data-header (car arts)))
6172            (gnus-subject-equal
6173             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6174            (setq result (car arts)
6175                  arts nil))
6176       (setq arts (cdr arts)))
6177     (and result
6178          (goto-char (gnus-data-pos result))
6179          (gnus-data-number result))))
6180
6181 (defun gnus-summary-search-forward (&optional unread subject backward)
6182   "Search forward for an article.
6183 If UNREAD, look for unread articles.  If SUBJECT, look for
6184 articles with that subject.  If BACKWARD, search backward instead."
6185   (cond (subject (gnus-summary-find-subject subject unread backward))
6186         (backward (gnus-summary-find-prev unread))
6187         (t (gnus-summary-find-next unread))))
6188
6189 (defun gnus-recenter (&optional n)
6190   "Center point in window and redisplay frame.
6191 Also do horizontal recentering."
6192   (interactive "P")
6193   (when (and gnus-auto-center-summary
6194              (not (eq gnus-auto-center-summary 'vertical)))
6195     (gnus-horizontal-recenter))
6196   (recenter n))
6197
6198 (defun gnus-summary-recenter ()
6199   "Center point in the summary window.
6200 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6201 displayed, no centering will be performed."
6202   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6203   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6204   (interactive)
6205   ;; The user has to want it.
6206   (when gnus-auto-center-summary
6207     (let* ((top (cond ((< (window-height) 4) 0)
6208                       ((< (window-height) 7) 1)
6209                       (t (if (numberp gnus-auto-center-summary)
6210                              gnus-auto-center-summary
6211                            2))))
6212            (height (1- (window-height)))
6213            (bottom (save-excursion (goto-char (point-max))
6214                                    (forward-line (- height))
6215                                    (point)))
6216            (window (get-buffer-window (current-buffer))))
6217       (when (get-buffer-window gnus-article-buffer)
6218         ;; Only do recentering when the article buffer is displayed,
6219         ;; Set the window start to either `bottom', which is the biggest
6220         ;; possible valid number, or the second line from the top,
6221         ;; whichever is the least.
6222         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6223           (if (> bottom top-pos)
6224               ;; Keep the second line from the top visible
6225               (set-window-start window top-pos t)
6226             ;; Try to keep the bottom line visible; if it's partially
6227             ;; obscured, either scroll one more line to make it fully
6228             ;; visible, or revert to using TOP-POS.
6229             (save-excursion
6230               (goto-char (point-max))
6231               (forward-line -1)
6232               (let ((last-line-start (point)))
6233                 (goto-char bottom)
6234                 (set-window-start window (point) t)
6235                 (when (not (pos-visible-in-window-p last-line-start window))
6236                   (forward-line 1)
6237                   (set-window-start window (min (point) top-pos) t)))))))
6238       ;; Do horizontal recentering while we're at it.
6239       (when (and (get-buffer-window (current-buffer) t)
6240                  (not (eq gnus-auto-center-summary 'vertical)))
6241         (let ((selected (selected-window)))
6242           (select-window (get-buffer-window (current-buffer) t))
6243           (gnus-summary-position-point)
6244           (gnus-horizontal-recenter)
6245           (select-window selected))))))
6246
6247 (defun gnus-summary-jump-to-group (newsgroup)
6248   "Move point to NEWSGROUP in group mode buffer."
6249   ;; Keep update point of group mode buffer if visible.
6250   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6251       (save-window-excursion
6252         ;; Take care of tree window mode.
6253         (when (get-buffer-window gnus-group-buffer)
6254           (pop-to-buffer gnus-group-buffer))
6255         (gnus-group-jump-to-group newsgroup))
6256     (save-excursion
6257       ;; Take care of tree window mode.
6258       (if (get-buffer-window gnus-group-buffer)
6259           (pop-to-buffer gnus-group-buffer)
6260         (set-buffer gnus-group-buffer))
6261       (gnus-group-jump-to-group newsgroup))))
6262
6263 ;; This function returns a list of article numbers based on the
6264 ;; difference between the ranges of read articles in this group and
6265 ;; the range of active articles.
6266 (defun gnus-list-of-unread-articles (group)
6267   (let* ((read (gnus-info-read (gnus-get-info group)))
6268          (active (or (gnus-active group) (gnus-activate-group group)))
6269          (last (cdr active))
6270          first nlast unread)
6271     ;; If none are read, then all are unread.
6272     (if (not read)
6273         (setq first (car active))
6274       ;; If the range of read articles is a single range, then the
6275       ;; first unread article is the article after the last read
6276       ;; article.  Sounds logical, doesn't it?
6277       (if (and (not (listp (cdr read)))
6278                (or (< (car read) (car active))
6279                    (progn (setq read (list read))
6280                           nil)))
6281           (setq first (max (car active) (1+ (cdr read))))
6282         ;; `read' is a list of ranges.
6283         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6284                                   (caar read)))
6285                   1)
6286           (setq first (car active)))
6287         (while read
6288           (when first
6289             (while (< first nlast)
6290               (push first unread)
6291               (setq first (1+ first))))
6292           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6293           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6294           (setq read (cdr read)))))
6295     ;; And add the last unread articles.
6296     (while (<= first last)
6297       (push first unread)
6298       (setq first (1+ first)))
6299     ;; Return the list of unread articles.
6300     (delq 0 (nreverse unread))))
6301
6302 (defun gnus-list-of-read-articles (group)
6303   "Return a list of unread, unticked and non-dormant articles."
6304   (let* ((info (gnus-get-info group))
6305          (marked (gnus-info-marks info))
6306          (active (gnus-active group)))
6307     (and info active
6308          (gnus-list-range-difference
6309           (gnus-list-range-difference
6310            (gnus-sorted-complement
6311             (gnus-uncompress-range active)
6312             (gnus-list-of-unread-articles group))
6313            (cdr (assq 'dormant marked)))
6314           (cdr (assq 'tick marked))))))
6315
6316 ;; Various summary commands
6317
6318 (defun gnus-summary-select-article-buffer ()
6319   "Reconfigure windows to show article buffer."
6320   (interactive)
6321   (if (not (gnus-buffer-live-p gnus-article-buffer))
6322       (error "There is no article buffer for this summary buffer")
6323     (gnus-configure-windows 'article)
6324     (select-window (get-buffer-window gnus-article-buffer))))
6325
6326 (defun gnus-summary-universal-argument (arg)
6327   "Perform any operation on all articles that are process/prefixed."
6328   (interactive "P")
6329   (let ((articles (gnus-summary-work-articles arg))
6330         func article)
6331     (if (eq
6332          (setq
6333           func
6334           (key-binding
6335            (read-key-sequence
6336             (substitute-command-keys
6337              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6338          'undefined)
6339         (gnus-error 1 "Undefined key")
6340       (save-excursion
6341         (while articles
6342           (gnus-summary-goto-subject (setq article (pop articles)))
6343           (let (gnus-newsgroup-processable)
6344             (command-execute func))
6345           (gnus-summary-remove-process-mark article)))))
6346   (gnus-summary-position-point))
6347
6348 (defun gnus-summary-toggle-truncation (&optional arg)
6349   "Toggle truncation of summary lines.
6350 With arg, turn line truncation on if arg is positive."
6351   (interactive "P")
6352   (setq truncate-lines
6353         (if (null arg) (not truncate-lines)
6354           (> (prefix-numeric-value arg) 0)))
6355   (redraw-display))
6356
6357 (defun gnus-summary-find-for-reselect ()
6358   "Return the number of an article to stay on across a reselect.
6359 The current article is considered, then following articles, then previous
6360 articles.  An article is sought which is not cancelled and isn't a temporary
6361 insertion from another group.  If there's no such then return a dummy 0."
6362   (let (found)
6363     (dolist (rev '(nil t))
6364       (unless found      ; don't demand the reverse list if we don't need it
6365         (let ((data (gnus-data-find-list
6366                      (gnus-summary-article-number) (gnus-data-list rev))))
6367           (while (and data (not found))
6368             (if (and (< 0 (gnus-data-number (car data)))
6369                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6370                 (setq found (gnus-data-number (car data))))
6371             (setq data (cdr data))))))
6372     (or found 0)))
6373
6374 (defun gnus-summary-reselect-current-group (&optional all rescan)
6375   "Exit and then reselect the current newsgroup.
6376 The prefix argument ALL means to select all articles."
6377   (interactive "P")
6378   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6379     (error "Ephemeral groups can't be reselected"))
6380   (let ((current-subject (gnus-summary-find-for-reselect))
6381         (group gnus-newsgroup-name))
6382     (setq gnus-newsgroup-begin nil)
6383     (gnus-summary-exit)
6384     ;; We have to adjust the point of group mode buffer because
6385     ;; point was moved to the next unread newsgroup by exiting.
6386     (gnus-summary-jump-to-group group)
6387     (when rescan
6388       (save-excursion
6389         (save-window-excursion
6390           ;; Don't show group contents.
6391           (set-window-start (selected-window) (point-max))
6392           (gnus-group-get-new-news-this-group 1))))
6393     (gnus-group-read-group all t)
6394     (gnus-summary-goto-subject current-subject nil t)))
6395
6396 (defun gnus-summary-rescan-group (&optional all)
6397   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6398   (interactive "P")
6399   (gnus-summary-reselect-current-group all t))
6400
6401 (defun gnus-summary-update-info (&optional non-destructive)
6402   (save-excursion
6403     (let ((group gnus-newsgroup-name))
6404       (when group
6405         (when gnus-newsgroup-kill-headers
6406           (setq gnus-newsgroup-killed
6407                 (gnus-compress-sequence
6408                  (gnus-sorted-union
6409                   (gnus-list-range-intersection
6410                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6411                   gnus-newsgroup-unreads)
6412                  t)))
6413         (unless (listp (cdr gnus-newsgroup-killed))
6414           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6415         (let ((headers gnus-newsgroup-headers))
6416           ;; Set the new ranges of read articles.
6417           (save-excursion
6418             (set-buffer gnus-group-buffer)
6419             (gnus-undo-force-boundary))
6420           (gnus-update-read-articles
6421            group (gnus-sorted-union
6422                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6423           ;; Set the current article marks.
6424           (let ((gnus-newsgroup-scored
6425                  (if (and (not gnus-save-score)
6426                           (not non-destructive))
6427                      nil
6428                    gnus-newsgroup-scored)))
6429             (save-excursion
6430               (gnus-update-marks)))
6431           ;; Do the cross-ref thing.
6432           (when gnus-use-cross-reference
6433             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6434           ;; Do not switch windows but change the buffer to work.
6435           (set-buffer gnus-group-buffer)
6436           (unless (gnus-ephemeral-group-p group)
6437             (gnus-group-update-group group)))))))
6438
6439 (defun gnus-summary-save-newsrc (&optional force)
6440   "Save the current number of read/marked articles in the dribble buffer.
6441 The dribble buffer will then be saved.
6442 If FORCE (the prefix), also save the .newsrc file(s)."
6443   (interactive "P")
6444   (gnus-summary-update-info t)
6445   (if force
6446       (gnus-save-newsrc-file)
6447     (gnus-dribble-save)))
6448
6449 (defun gnus-summary-exit (&optional temporary)
6450   "Exit reading current newsgroup, and then return to group selection mode.
6451 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6452   (interactive)
6453   (gnus-set-global-variables)
6454   (gnus-kill-save-kill-buffer)
6455   (gnus-async-halt-prefetch)
6456   (let* ((group gnus-newsgroup-name)
6457          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6458          (gnus-group-is-exiting-p t)
6459          (mode major-mode)
6460          (group-point nil)
6461          (buf (current-buffer)))
6462     (unless quit-config
6463       ;; Do adaptive scoring, and possibly save score files.
6464       (when gnus-newsgroup-adaptive
6465         (gnus-score-adaptive))
6466       (when gnus-use-scoring
6467         (gnus-score-save)))
6468     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6469     ;; If we have several article buffers, we kill them at exit.
6470     (unless gnus-single-article-buffer
6471       (gnus-kill-buffer gnus-original-article-buffer)
6472       (setq gnus-article-current nil))
6473     (when gnus-use-cache
6474       (gnus-cache-possibly-remove-articles)
6475       (gnus-cache-save-buffers))
6476     (gnus-async-prefetch-remove-group group)
6477     (when gnus-suppress-duplicates
6478       (gnus-dup-enter-articles))
6479     (when gnus-use-trees
6480       (gnus-tree-close group))
6481     (when gnus-use-cache
6482       (gnus-cache-write-active))
6483     ;; Remove entries for this group.
6484     (nnmail-purge-split-history (gnus-group-real-name group))
6485     ;; Make all changes in this group permanent.
6486     (unless quit-config
6487       (gnus-run-hooks 'gnus-exit-group-hook)
6488       (gnus-summary-update-info))
6489     (gnus-close-group group)
6490     ;; Make sure where we were, and go to next newsgroup.
6491     (set-buffer gnus-group-buffer)
6492     (unless quit-config
6493       (gnus-group-jump-to-group group))
6494     (gnus-run-hooks 'gnus-summary-exit-hook)
6495     (unless (or quit-config
6496                 ;; If this group has disappeared from the summary
6497                 ;; buffer, don't skip forwards.
6498                 (not (string= group (gnus-group-group-name))))
6499       (gnus-group-next-unread-group 1))
6500     (setq group-point (point))
6501     (if temporary
6502         nil                             ;Nothing to do.
6503       ;; If we have several article buffers, we kill them at exit.
6504       (unless gnus-single-article-buffer
6505         (gnus-kill-buffer gnus-article-buffer)
6506         (gnus-kill-buffer gnus-original-article-buffer)
6507         (setq gnus-article-current nil))
6508       (set-buffer buf)
6509       (if (not gnus-kill-summary-on-exit)
6510           (progn
6511             (gnus-deaden-summary)
6512             (setq mode nil))
6513         ;; We set all buffer-local variables to nil.  It is unclear why
6514         ;; this is needed, but if we don't, buffer-local variables are
6515         ;; not garbage-collected, it seems.  This would the lead to en
6516         ;; ever-growing Emacs.
6517         (gnus-summary-clear-local-variables)
6518         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6519           (gnus-summary-clear-local-variables))
6520         (when (get-buffer gnus-article-buffer)
6521           (bury-buffer gnus-article-buffer))
6522         ;; We clear the global counterparts of the buffer-local
6523         ;; variables as well, just to be on the safe side.
6524         (set-buffer gnus-group-buffer)
6525         (gnus-summary-clear-local-variables)
6526         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6527           (gnus-summary-clear-local-variables))
6528         ;; Return to group mode buffer.
6529         (when (eq mode 'gnus-summary-mode)
6530           (gnus-kill-buffer buf)))
6531       (setq gnus-current-select-method gnus-select-method)
6532       (pop-to-buffer gnus-group-buffer)
6533       (if (not quit-config)
6534           (progn
6535             (goto-char group-point)
6536             (gnus-configure-windows 'group 'force)
6537             (unless (pos-visible-in-window-p)
6538               (forward-line (/ (static-if (featurep 'xemacs)
6539                                    (window-displayed-height)
6540                                  (1- (window-height)))
6541                                -2))
6542               (set-window-start (selected-window) (point))
6543               (goto-char group-point)))
6544         (gnus-handle-ephemeral-exit quit-config))
6545       ;; Clear the current group name.
6546       (unless quit-config
6547         (setq gnus-newsgroup-name nil)))))
6548
6549 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6550 (defun gnus-summary-exit-no-update (&optional no-questions)
6551   "Quit reading current newsgroup without updating read article info."
6552   (interactive)
6553   (let* ((group gnus-newsgroup-name)
6554          (gnus-group-is-exiting-p t)
6555          (gnus-group-is-exiting-without-update-p t)
6556          (quit-config (gnus-group-quit-config group)))
6557     (when (or no-questions
6558               gnus-expert-user
6559               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6560       (gnus-async-halt-prefetch)
6561       (run-hooks 'gnus-summary-prepare-exit-hook)
6562       ;; If we have several article buffers, we kill them at exit.
6563       (unless gnus-single-article-buffer
6564         (gnus-kill-buffer gnus-article-buffer)
6565         (gnus-kill-buffer gnus-original-article-buffer)
6566         (setq gnus-article-current nil))
6567       (if (not gnus-kill-summary-on-exit)
6568           (gnus-deaden-summary)
6569         (gnus-close-group group)
6570         (gnus-summary-clear-local-variables)
6571         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6572           (gnus-summary-clear-local-variables))
6573         (set-buffer gnus-group-buffer)
6574         (gnus-summary-clear-local-variables)
6575         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6576           (gnus-summary-clear-local-variables))
6577         (gnus-kill-buffer gnus-summary-buffer))
6578       (unless gnus-single-article-buffer
6579         (setq gnus-article-current nil))
6580       (when gnus-use-trees
6581         (gnus-tree-close group))
6582       (gnus-async-prefetch-remove-group group)
6583       (when (get-buffer gnus-article-buffer)
6584         (bury-buffer gnus-article-buffer))
6585       ;; Return to the group buffer.
6586       (gnus-configure-windows 'group 'force)
6587       ;; Clear the current group name.
6588       (setq gnus-newsgroup-name nil)
6589       (unless (gnus-ephemeral-group-p group)
6590         (gnus-group-update-group group))
6591       (when (equal (gnus-group-group-name) group)
6592         (gnus-group-next-unread-group 1))
6593       (when quit-config
6594         (gnus-handle-ephemeral-exit quit-config)))))
6595
6596 (defun gnus-handle-ephemeral-exit (quit-config)
6597   "Handle movement when leaving an ephemeral group.
6598 The state which existed when entering the ephemeral is reset."
6599   (if (not (buffer-name (car quit-config)))
6600       (gnus-configure-windows 'group 'force)
6601     (set-buffer (car quit-config))
6602     (cond ((eq major-mode 'gnus-summary-mode)
6603            (gnus-set-global-variables))
6604           ((eq major-mode 'gnus-article-mode)
6605            (save-excursion
6606              ;; The `gnus-summary-buffer' variable may point
6607              ;; to the old summary buffer when using a single
6608              ;; article buffer.
6609              (unless (gnus-buffer-live-p gnus-summary-buffer)
6610                (set-buffer gnus-group-buffer))
6611              (set-buffer gnus-summary-buffer)
6612              (gnus-set-global-variables))))
6613     (if (or (eq (cdr quit-config) 'article)
6614             (eq (cdr quit-config) 'pick))
6615         (progn
6616           ;; The current article may be from the ephemeral group
6617           ;; thus it is best that we reload this article
6618           ;;
6619           ;; If we're exiting from a large digest, this can be
6620           ;; extremely slow.  So, it's better not to reload it. -- jh.
6621           ;;(gnus-summary-show-article)
6622           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6623               (gnus-configure-windows 'pick 'force)
6624             (gnus-configure-windows (cdr quit-config) 'force)))
6625       (gnus-configure-windows (cdr quit-config) 'force))
6626     (when (eq major-mode 'gnus-summary-mode)
6627       (gnus-summary-next-subject 1 nil t)
6628       (gnus-summary-recenter)
6629       (gnus-summary-position-point))))
6630
6631 (defun gnus-summary-preview-mime-message ()
6632   "MIME decode and play this message."
6633   (interactive)
6634   (let ((gnus-break-pages nil)
6635         (gnus-show-mime t))
6636     (gnus-summary-select-article gnus-show-all-headers t))
6637   (let ((w (get-buffer-window gnus-article-buffer)))
6638     (when w
6639       (select-window (get-buffer-window gnus-article-buffer)))))
6640
6641 ;;; Dead summaries.
6642
6643 (defvar gnus-dead-summary-mode-map nil)
6644
6645 (unless gnus-dead-summary-mode-map
6646   (setq gnus-dead-summary-mode-map (make-keymap))
6647   (suppress-keymap gnus-dead-summary-mode-map)
6648   (substitute-key-definition
6649    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6650   (dolist (key '("\C-d" "\r" "\177" [delete]))
6651     (define-key gnus-dead-summary-mode-map
6652       key 'gnus-summary-wake-up-the-dead))
6653   (dolist (key '("q" "Q"))
6654     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6655
6656 (defvar gnus-dead-summary-mode nil
6657   "Minor mode for Gnus summary buffers.")
6658
6659 (defun gnus-dead-summary-mode (&optional arg)
6660   "Minor mode for Gnus summary buffers."
6661   (interactive "P")
6662   (when (eq major-mode 'gnus-summary-mode)
6663     (make-local-variable 'gnus-dead-summary-mode)
6664     (setq gnus-dead-summary-mode
6665           (if (null arg) (not gnus-dead-summary-mode)
6666             (> (prefix-numeric-value arg) 0)))
6667     (when gnus-dead-summary-mode
6668       (gnus-add-minor-mode
6669        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6670
6671 (defun gnus-deaden-summary ()
6672   "Make the current summary buffer into a dead summary buffer."
6673   ;; Kill any previous dead summary buffer.
6674   (when (and gnus-dead-summary
6675              (buffer-name gnus-dead-summary))
6676     (save-excursion
6677       (set-buffer gnus-dead-summary)
6678       (when gnus-dead-summary-mode
6679         (kill-buffer (current-buffer)))))
6680   ;; Make this the current dead summary.
6681   (setq gnus-dead-summary (current-buffer))
6682   (gnus-dead-summary-mode 1)
6683   (let ((name (buffer-name)))
6684     (when (string-match "Summary" name)
6685       (rename-buffer
6686        (concat (substring name 0 (match-beginning 0)) "Dead "
6687                (substring name (match-beginning 0)))
6688        t)
6689       (bury-buffer))))
6690
6691 (defun gnus-kill-or-deaden-summary (buffer)
6692   "Kill or deaden the summary BUFFER."
6693   (save-excursion
6694     (when (and (buffer-name buffer)
6695                (not gnus-single-article-buffer))
6696       (save-excursion
6697         (set-buffer buffer)
6698         (gnus-kill-buffer gnus-article-buffer)
6699         (gnus-kill-buffer gnus-original-article-buffer)))
6700     (cond
6701      ;; Kill the buffer.
6702      (gnus-kill-summary-on-exit
6703       (when (and gnus-use-trees
6704                  (gnus-buffer-exists-p buffer))
6705         (save-excursion
6706           (set-buffer buffer)
6707           (gnus-tree-close gnus-newsgroup-name)))
6708       (gnus-kill-buffer buffer))
6709      ;; Deaden the buffer.
6710      ((gnus-buffer-exists-p buffer)
6711       (save-excursion
6712         (set-buffer buffer)
6713         (gnus-deaden-summary))))))
6714
6715 (defun gnus-summary-wake-up-the-dead (&rest args)
6716   "Wake up the dead summary buffer."
6717   (interactive)
6718   (gnus-dead-summary-mode -1)
6719   (let ((name (buffer-name)))
6720     (when (string-match "Dead " name)
6721       (rename-buffer
6722        (concat (substring name 0 (match-beginning 0))
6723                (substring name (match-end 0)))
6724        t)))
6725   (gnus-message 3 "This dead summary is now alive again"))
6726
6727 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6728 (defun gnus-summary-fetch-faq (&optional faq-dir)
6729   "Fetch the FAQ for the current group.
6730 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6731 in."
6732   (interactive
6733    (list
6734     (when current-prefix-arg
6735       (completing-read
6736        "FAQ dir: " (and (listp gnus-group-faq-directory)
6737                         (mapcar (lambda (file) (list file))
6738                                 gnus-group-faq-directory))))))
6739   (let (gnus-faq-buffer)
6740     (when (setq gnus-faq-buffer
6741                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6742       (gnus-configure-windows 'summary-faq))))
6743
6744 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6745 (defun gnus-summary-describe-group (&optional force)
6746   "Describe the current newsgroup."
6747   (interactive "P")
6748   (gnus-group-describe-group force gnus-newsgroup-name))
6749
6750 (defun gnus-summary-describe-briefly ()
6751   "Describe summary mode commands briefly."
6752   (interactive)
6753   (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")))
6754
6755 ;; Walking around group mode buffer from summary mode.
6756
6757 (defun gnus-summary-next-group (&optional no-article target-group backward)
6758   "Exit current newsgroup and then select next unread newsgroup.
6759 If prefix argument NO-ARTICLE is non-nil, no article is selected
6760 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6761 previous group instead."
6762   (interactive "P")
6763   ;; Stop pre-fetching.
6764   (gnus-async-halt-prefetch)
6765   (let ((current-group gnus-newsgroup-name)
6766         (current-buffer (current-buffer))
6767         entered)
6768     ;; First we semi-exit this group to update Xrefs and all variables.
6769     ;; We can't do a real exit, because the window conf must remain
6770     ;; the same in case the user is prompted for info, and we don't
6771     ;; want the window conf to change before that...
6772     (gnus-summary-exit t)
6773     (while (not entered)
6774       ;; Then we find what group we are supposed to enter.
6775       (set-buffer gnus-group-buffer)
6776       (gnus-group-jump-to-group current-group)
6777       (setq target-group
6778             (or target-group
6779                 (if (eq gnus-keep-same-level 'best)
6780                     (gnus-summary-best-group gnus-newsgroup-name)
6781                   (gnus-summary-search-group backward gnus-keep-same-level))))
6782       (if (not target-group)
6783           ;; There are no further groups, so we return to the group
6784           ;; buffer.
6785           (progn
6786             (gnus-message 5 "Returning to the group buffer")
6787             (setq entered t)
6788             (when (gnus-buffer-live-p current-buffer)
6789               (set-buffer current-buffer)
6790               (gnus-summary-exit))
6791             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6792         ;; We try to enter the target group.
6793         (gnus-group-jump-to-group target-group)
6794         (let ((unreads (gnus-group-group-unread)))
6795           (if (and (or (eq t unreads)
6796                        (and unreads (not (zerop unreads))))
6797                    (gnus-summary-read-group
6798                     target-group nil no-article
6799                     (and (buffer-name current-buffer) current-buffer)
6800                     nil backward))
6801               (setq entered t)
6802             (setq current-group target-group
6803                   target-group nil)))))))
6804
6805 (defun gnus-summary-prev-group (&optional no-article)
6806   "Exit current newsgroup and then select previous unread newsgroup.
6807 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6808   (interactive "P")
6809   (gnus-summary-next-group no-article nil t))
6810
6811 ;; Walking around summary lines.
6812
6813 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6814   "Go to the first subject satisfying any non-nil constraint.
6815 If UNREAD is non-nil, the article should be unread.
6816 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6817 If UNSEED is non-nil, the article should be unseen.
6818 Returns the article selected or nil if there are no matching articles."
6819   (interactive "P")
6820   (cond
6821    ;; Empty summary.
6822    ((null gnus-newsgroup-data)
6823     (gnus-message 3 "No articles in the group")
6824     nil)
6825    ;; Pick the first article.
6826    ((not (or unread undownloaded unseen))
6827     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6828     (gnus-data-number (car gnus-newsgroup-data)))
6829    ;; Find the first unread article.
6830    (t
6831     (let ((data gnus-newsgroup-data))
6832       (while (and data
6833                   (let ((num (gnus-data-number (car data))))
6834                     (or (memq num gnus-newsgroup-unfetched)
6835                         (not (or (and unread
6836                                       (memq num gnus-newsgroup-unreads))
6837                                  (and undownloaded
6838                                       (memq num gnus-newsgroup-undownloaded))
6839                                  (and unseen
6840                                       (memq num gnus-newsgroup-unseen)))))))
6841         (setq data (cdr data)))
6842       (prog1 
6843           (if data
6844               (progn
6845                 (goto-char (gnus-data-pos (car data)))
6846                 (gnus-data-number (car data)))
6847             (gnus-message 3 "No more%s articles"
6848                           (let* ((r (when unread " unread"))
6849                                  (d (when undownloaded " undownloaded"))
6850                                  (s (when unseen " unseen"))
6851                                  (l (delq nil (list r d s))))
6852                             (cond ((= 3 (length l))
6853                                    (concat r "," d ", or" s))
6854                                   ((= 2 (length l))
6855                                    (concat (car l) ", or" (cadr l)))
6856                                   ((= 1 (length l))
6857                                    (car l))
6858                                   (t
6859                                    ""))))
6860             nil
6861             )
6862         (gnus-summary-position-point))))))
6863
6864 (defun gnus-summary-next-subject (n &optional unread dont-display)
6865   "Go to next N'th summary line.
6866 If N is negative, go to the previous N'th subject line.
6867 If UNREAD is non-nil, only unread articles are selected.
6868 The difference between N and the actual number of steps taken is
6869 returned."
6870   (interactive "p")
6871   (let ((backward (< n 0))
6872         (n (abs n)))
6873     (while (and (> n 0)
6874                 (if backward
6875                     (gnus-summary-find-prev unread)
6876                   (gnus-summary-find-next unread)))
6877       (unless (zerop (setq n (1- n)))
6878         (gnus-summary-show-thread)))
6879     (when (/= 0 n)
6880       (gnus-message 7 "No more%s articles"
6881                     (if unread " unread" "")))
6882     (unless dont-display
6883       (gnus-summary-recenter)
6884       (gnus-summary-position-point))
6885     n))
6886
6887 (defun gnus-summary-next-unread-subject (n)
6888   "Go to next N'th unread summary line."
6889   (interactive "p")
6890   (gnus-summary-next-subject n t))
6891
6892 (defun gnus-summary-prev-subject (n &optional unread)
6893   "Go to previous N'th summary line.
6894 If optional argument UNREAD is non-nil, only unread article is selected."
6895   (interactive "p")
6896   (gnus-summary-next-subject (- n) unread))
6897
6898 (defun gnus-summary-prev-unread-subject (n)
6899   "Go to previous N'th unread summary line."
6900   (interactive "p")
6901   (gnus-summary-next-subject (- n) t))
6902
6903 (defun gnus-summary-goto-subjects (articles)
6904   "Insert the subject header for ARTICLES in the current buffer."
6905   (save-excursion
6906     (dolist (article articles)
6907       (gnus-summary-goto-subject article t)))
6908   (gnus-summary-limit (append articles gnus-newsgroup-limit))
6909   (gnus-summary-position-point))
6910  
6911 (defun gnus-summary-goto-subject (article &optional force silent)
6912   "Go the subject line of ARTICLE.
6913 If FORCE, also allow jumping to articles not currently shown."
6914   (interactive "nArticle number: ")
6915   (unless (numberp article)
6916     (error "Article %s is not a number" article))
6917   (let ((b (point))
6918         (data (gnus-data-find article)))
6919     ;; We read in the article if we have to.
6920     (and (not data)
6921          force
6922          (gnus-summary-insert-subject
6923           article
6924           (if (or (numberp force) (vectorp force)) force)
6925           t)
6926          (setq data (gnus-data-find article)))
6927     (goto-char b)
6928     (if (not data)
6929         (progn
6930           (unless silent
6931             (gnus-message 3 "Can't find article %d" article))
6932           nil)
6933       (let ((pt (gnus-data-pos data)))
6934         (goto-char pt)
6935         (gnus-summary-set-article-display-arrow pt))
6936       (gnus-summary-position-point)
6937       article)))
6938
6939 ;; Walking around summary lines with displaying articles.
6940
6941 (defun gnus-summary-expand-window (&optional arg)
6942   "Make the summary buffer take up the entire Emacs frame.
6943 Given a prefix, will force an `article' buffer configuration."
6944   (interactive "P")
6945   (if arg
6946       (gnus-configure-windows 'article 'force)
6947     (gnus-configure-windows 'summary 'force)))
6948
6949 (defun gnus-summary-display-article (article &optional all-header)
6950   "Display ARTICLE in article buffer."
6951   (when (gnus-buffer-live-p gnus-article-buffer)
6952     (with-current-buffer gnus-article-buffer
6953       (set-buffer-multibyte t)))
6954   (gnus-set-global-variables)
6955   (when (gnus-buffer-live-p gnus-article-buffer)
6956     (with-current-buffer gnus-article-buffer
6957       (setq gnus-article-charset gnus-newsgroup-charset)
6958       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6959       (set-buffer-multibyte t)))
6960   (if (null article)
6961       nil
6962     (prog1
6963         (if gnus-summary-display-article-function
6964             (funcall gnus-summary-display-article-function article all-header)
6965           (gnus-article-prepare article all-header))
6966       (with-current-buffer gnus-article-buffer
6967         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6968              nil))
6969       (gnus-run-hooks 'gnus-select-article-hook)
6970       (when (and gnus-current-article
6971                  (not (zerop gnus-current-article)))
6972         (gnus-summary-goto-subject gnus-current-article))
6973       (gnus-summary-recenter)
6974       (when (and gnus-use-trees gnus-show-threads)
6975         (gnus-possibly-generate-tree article)
6976         (gnus-highlight-selected-tree article))
6977       ;; Successfully display article.
6978       (gnus-article-set-window-start
6979        (cdr (assq article gnus-newsgroup-bookmarks))))))
6980
6981 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6982   "Select the current article.
6983 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6984 non-nil, the article will be re-fetched even if it already present in
6985 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6986 be displayed."
6987   ;; Make sure we are in the summary buffer to work around bbdb bug.
6988   (unless (eq major-mode 'gnus-summary-mode)
6989     (set-buffer gnus-summary-buffer))
6990   (let ((article (or article (gnus-summary-article-number)))
6991         (all-headers (not (not all-headers))) ;Must be T or NIL.
6992         gnus-summary-display-article-function)
6993     (and (not pseudo)
6994          (gnus-summary-article-pseudo-p article)
6995          (error "This is a pseudo-article"))
6996     (save-excursion
6997       (set-buffer gnus-summary-buffer)
6998       (if (or (and gnus-single-article-buffer
6999                    (or (null gnus-current-article)
7000                        (null gnus-article-current)
7001                        (null (get-buffer gnus-article-buffer))
7002                        (not (eq article (cdr gnus-article-current)))
7003                        (not (equal (car gnus-article-current)
7004                                    gnus-newsgroup-name))))
7005               (and (not gnus-single-article-buffer)
7006                    (or (null gnus-current-article)
7007                        (not (eq gnus-current-article article))))
7008               force)
7009           ;; The requested article is different from the current article.
7010           (progn
7011             (gnus-summary-display-article article all-headers)
7012             (gnus-article-set-window-start
7013              (cdr (assq article gnus-newsgroup-bookmarks)))
7014             article)
7015         'old))))
7016
7017 (defun gnus-summary-force-verify-and-decrypt ()
7018   "Display buttons for signed/encrypted parts and verify/decrypt them."
7019   (interactive)
7020   (let ((mm-verify-option 'known)
7021         (mm-decrypt-option 'known)
7022         (gnus-buttonized-mime-types (append (list "multipart/signed"
7023                                                   "multipart/encrypted")
7024                                             gnus-buttonized-mime-types)))
7025     (gnus-summary-select-article nil 'force)))
7026
7027 (defun gnus-summary-set-current-mark (&optional current-mark)
7028   "Obsolete function."
7029   nil)
7030
7031 (defun gnus-summary-next-article (&optional unread subject backward push)
7032   "Select the next article.
7033 If UNREAD, only unread articles are selected.
7034 If SUBJECT, only articles with SUBJECT are selected.
7035 If BACKWARD, the previous article is selected instead of the next."
7036   (interactive "P")
7037   (cond
7038    ;; Is there such an article?
7039    ((and (gnus-summary-search-forward unread subject backward)
7040          (or (gnus-summary-display-article (gnus-summary-article-number))
7041              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7042     (gnus-summary-position-point))
7043    ;; If not, we try the first unread, if that is wanted.
7044    ((and subject
7045          gnus-auto-select-same
7046          (gnus-summary-first-unread-article))
7047     (gnus-summary-position-point)
7048     (gnus-message 6 "Wrapped"))
7049    ;; Try to get next/previous article not displayed in this group.
7050    ((and gnus-auto-extend-newsgroup
7051          (not unread) (not subject))
7052     (gnus-summary-goto-article
7053      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7054      nil (count-lines (point-min) (point))))
7055    ;; Go to next/previous group.
7056    (t
7057     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7058       (gnus-summary-jump-to-group gnus-newsgroup-name))
7059     (let ((cmd last-command-char)
7060           (point
7061            (save-excursion
7062              (set-buffer gnus-group-buffer)
7063              (point)))
7064           (group
7065            (if (eq gnus-keep-same-level 'best)
7066                (gnus-summary-best-group gnus-newsgroup-name)
7067              (gnus-summary-search-group backward gnus-keep-same-level))))
7068       ;; For some reason, the group window gets selected.  We change
7069       ;; it back.
7070       (select-window (get-buffer-window (current-buffer)))
7071       ;; Select next unread newsgroup automagically.
7072       (cond
7073        ((or (not gnus-auto-select-next)
7074             (not cmd))
7075         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7076        ((or (eq gnus-auto-select-next 'quietly)
7077             (and (eq gnus-auto-select-next 'slightly-quietly)
7078                  push)
7079             (and (eq gnus-auto-select-next 'almost-quietly)
7080                  (gnus-summary-last-article-p)))
7081         ;; Select quietly.
7082         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7083             (gnus-summary-exit)
7084           (gnus-message 7 "No more%s articles (%s)..."
7085                         (if unread " unread" "")
7086                         (if group (concat "selecting " group)
7087                           "exiting"))
7088           (gnus-summary-next-group nil group backward)))
7089        (t
7090         (when (gnus-key-press-event-p last-input-event)
7091           (gnus-summary-walk-group-buffer
7092            gnus-newsgroup-name cmd unread backward point))))))))
7093
7094 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7095   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7096                       (?\C-p (gnus-group-prev-unread-group 1))))
7097         (cursor-in-echo-area t)
7098         keve key group ended prompt)
7099     (save-excursion
7100       (set-buffer gnus-group-buffer)
7101       (goto-char start)
7102       (setq group
7103             (if (eq gnus-keep-same-level 'best)
7104                 (gnus-summary-best-group gnus-newsgroup-name)
7105               (gnus-summary-search-group backward gnus-keep-same-level))))
7106     (while (not ended)
7107       (setq prompt
7108             (format
7109              "No more%s articles%s " (if unread " unread" "")
7110              (if (and group
7111                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7112                  (format " (Type %s for %s [%s])"
7113                          (single-key-description cmd) group
7114                          (car (gnus-gethash group gnus-newsrc-hashtb)))
7115                (format " (Type %s to exit %s)"
7116                        (single-key-description cmd)
7117                        gnus-newsgroup-name))))
7118       ;; Confirm auto selection.
7119       (setq key (car (setq keve (gnus-read-event-char prompt)))
7120             ended t)
7121       (cond
7122        ((assq key keystrokes)
7123         (let ((obuf (current-buffer)))
7124           (switch-to-buffer gnus-group-buffer)
7125           (when group
7126             (gnus-group-jump-to-group group))
7127           (eval (cadr (assq key keystrokes)))
7128           (setq group (gnus-group-group-name))
7129           (switch-to-buffer obuf))
7130         (setq ended nil))
7131        ((equal key cmd)
7132         (if (or (not group)
7133                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7134             (gnus-summary-exit)
7135           (gnus-summary-next-group nil group backward)))
7136        (t
7137         (push (cdr keve) unread-command-events))))))
7138
7139 (defun gnus-summary-next-unread-article ()
7140   "Select unread article after current one."
7141   (interactive)
7142   (gnus-summary-next-article
7143    (or (not (eq gnus-summary-goto-unread 'never))
7144        (gnus-summary-last-article-p (gnus-summary-article-number)))
7145    (and gnus-auto-select-same
7146         (gnus-summary-article-subject))))
7147
7148 (defun gnus-summary-prev-article (&optional unread subject)
7149   "Select the article after the current one.
7150 If UNREAD is non-nil, only unread articles are selected."
7151   (interactive "P")
7152   (gnus-summary-next-article unread subject t))
7153
7154 (defun gnus-summary-prev-unread-article ()
7155   "Select unread article before current one."
7156   (interactive)
7157   (gnus-summary-prev-article
7158    (or (not (eq gnus-summary-goto-unread 'never))
7159        (gnus-summary-first-article-p (gnus-summary-article-number)))
7160    (and gnus-auto-select-same
7161         (gnus-summary-article-subject))))
7162
7163 (defun gnus-summary-next-page (&optional lines circular stop)
7164   "Show next page of the selected article.
7165 If at the end of the current article, select the next article.
7166 LINES says how many lines should be scrolled up.
7167
7168 If CIRCULAR is non-nil, go to the start of the article instead of
7169 selecting the next article when reaching the end of the current
7170 article.
7171
7172 If STOP is non-nil, just stop when reaching the end of the message.
7173
7174 Also see the variable `gnus-article-skip-boring'."
7175   (interactive "P")
7176   (setq gnus-summary-buffer (current-buffer))
7177   (gnus-set-global-variables)
7178   (let ((article (gnus-summary-article-number))
7179         (article-window (get-buffer-window gnus-article-buffer t))
7180         endp)
7181     ;; If the buffer is empty, we have no article.
7182     (unless article
7183       (error "No article to select"))
7184     (gnus-configure-windows 'article)
7185     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7186         (if (and (eq gnus-summary-goto-unread 'never)
7187                  (not (gnus-summary-last-article-p article)))
7188             (gnus-summary-next-article)
7189           (gnus-summary-next-unread-article))
7190       (if (or (null gnus-current-article)
7191               (null gnus-article-current)
7192               (/= article (cdr gnus-article-current))
7193               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7194           ;; Selected subject is different from current article's.
7195           (gnus-summary-display-article article)
7196         (when article-window
7197           (gnus-eval-in-buffer-window gnus-article-buffer
7198             (setq endp (or (gnus-article-next-page lines)
7199                            (gnus-article-only-boring-p))))
7200           (when endp
7201             (cond (stop
7202                    (gnus-message 3 "End of message"))
7203                   (circular
7204                    (gnus-summary-beginning-of-article))
7205                   (lines
7206                    (gnus-message 3 "End of message"))
7207                   ((null lines)
7208                    (if (and (eq gnus-summary-goto-unread 'never)
7209                             (not (gnus-summary-last-article-p article)))
7210                        (gnus-summary-next-article)
7211                      (gnus-summary-next-unread-article))))))))
7212     (gnus-summary-recenter)
7213     (gnus-summary-position-point)))
7214
7215 (defun gnus-summary-prev-page (&optional lines move)
7216   "Show previous page of selected article.
7217 Argument LINES specifies lines to be scrolled down.
7218 If MOVE, move to the previous unread article if point is at
7219 the beginning of the buffer."
7220   (interactive "P")
7221   (let ((article (gnus-summary-article-number))
7222         (article-window (get-buffer-window gnus-article-buffer t))
7223         endp)
7224     (gnus-configure-windows 'article)
7225     (if (or (null gnus-current-article)
7226             (null gnus-article-current)
7227             (/= article (cdr gnus-article-current))
7228             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7229         ;; Selected subject is different from current article's.
7230         (gnus-summary-display-article article)
7231       (gnus-summary-recenter)
7232       (when article-window
7233         (gnus-eval-in-buffer-window gnus-article-buffer
7234           (setq endp (gnus-article-prev-page lines)))
7235         (when (and move endp)
7236           (cond (lines
7237                  (gnus-message 3 "Beginning of message"))
7238                 ((null lines)
7239                  (if (and (eq gnus-summary-goto-unread 'never)
7240                           (not (gnus-summary-first-article-p article)))
7241                      (gnus-summary-prev-article)
7242                    (gnus-summary-prev-unread-article))))))))
7243   (gnus-summary-position-point))
7244
7245 (defun gnus-summary-prev-page-or-article (&optional lines)
7246   "Show previous page of selected article.
7247 Argument LINES specifies lines to be scrolled down.
7248 If at the beginning of the article, go to the next article."
7249   (interactive "P")
7250   (gnus-summary-prev-page lines t))
7251
7252 (defun gnus-summary-scroll-up (lines)
7253   "Scroll up (or down) one line current article.
7254 Argument LINES specifies lines to be scrolled up (or down if negative)."
7255   (interactive "p")
7256   (gnus-configure-windows 'article)
7257   (gnus-summary-show-thread)
7258   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7259     (gnus-eval-in-buffer-window gnus-article-buffer
7260       (cond ((> lines 0)
7261              (when (gnus-article-next-page lines)
7262                (gnus-message 3 "End of message")))
7263             ((< lines 0)
7264              (gnus-article-prev-page (- lines))))))
7265   (gnus-summary-recenter)
7266   (gnus-summary-position-point))
7267
7268 (defun gnus-summary-scroll-down (lines)
7269   "Scroll down (or up) one line current article.
7270 Argument LINES specifies lines to be scrolled down (or up if negative)."
7271   (interactive "p")
7272   (gnus-summary-scroll-up (- lines)))
7273
7274 (defun gnus-summary-next-same-subject ()
7275   "Select next article which has the same subject as current one."
7276   (interactive)
7277   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7278
7279 (defun gnus-summary-prev-same-subject ()
7280   "Select previous article which has the same subject as current one."
7281   (interactive)
7282   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7283
7284 (defun gnus-summary-next-unread-same-subject ()
7285   "Select next unread article which has the same subject as current one."
7286   (interactive)
7287   (gnus-summary-next-article t (gnus-summary-article-subject)))
7288
7289 (defun gnus-summary-prev-unread-same-subject ()
7290   "Select previous unread article which has the same subject as current one."
7291   (interactive)
7292   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7293
7294 (defun gnus-summary-first-unread-article ()
7295   "Select the first unread article.
7296 Return nil if there are no unread articles."
7297   (interactive)
7298   (prog1
7299       (when (gnus-summary-first-subject t)
7300         (gnus-summary-show-thread)
7301         (gnus-summary-first-subject t)
7302         (gnus-summary-display-article (gnus-summary-article-number)))
7303     (gnus-summary-position-point)))
7304
7305 (defun gnus-summary-first-unread-subject ()
7306   "Place the point on the subject line of the first unread article.
7307 Return nil if there are no unread articles."
7308   (interactive)
7309   (prog1
7310       (when (gnus-summary-first-subject t)
7311         (gnus-summary-show-thread)
7312         (gnus-summary-first-subject t))
7313     (gnus-summary-position-point)))
7314
7315 (defun gnus-summary-first-unseen-subject ()
7316   "Place the point on the subject line of the first unseen article.
7317 Return nil if there are no unseen articles."
7318   (interactive)
7319   (prog1
7320       (when (gnus-summary-first-subject nil nil t)
7321         (gnus-summary-show-thread)
7322         (gnus-summary-first-subject nil nil t))
7323     (gnus-summary-position-point)))
7324
7325 (defun gnus-summary-first-unseen-or-unread-subject ()
7326   "Place the point on the subject line of the first unseen article or,
7327 if all article have been seen, on the subject line of the first unread
7328 article."
7329   (interactive)
7330   (prog1
7331       (unless (when (gnus-summary-first-subject nil nil t)
7332                 (gnus-summary-show-thread)
7333                 (gnus-summary-first-subject nil nil t))
7334         (when (gnus-summary-first-subject t)
7335           (gnus-summary-show-thread)
7336           (gnus-summary-first-subject t)))
7337     (gnus-summary-position-point)))
7338
7339 (defun gnus-summary-first-article ()
7340   "Select the first article.
7341 Return nil if there are no articles."
7342   (interactive)
7343   (prog1
7344       (when (gnus-summary-first-subject)
7345         (gnus-summary-show-thread)
7346         (gnus-summary-first-subject)
7347         (gnus-summary-display-article (gnus-summary-article-number)))
7348     (gnus-summary-position-point)))
7349
7350 (defun gnus-summary-best-unread-article (&optional arg)
7351   "Select the unread article with the highest score.
7352 If given a prefix argument, select the next unread article that has a
7353 score higher than the default score."
7354   (interactive "P")
7355   (let ((article (if arg
7356                      (gnus-summary-better-unread-subject)
7357                    (gnus-summary-best-unread-subject))))
7358     (if article
7359         (gnus-summary-goto-article article)
7360       (error "No unread articles"))))
7361
7362 (defun gnus-summary-best-unread-subject ()
7363   "Select the unread subject with the highest score."
7364   (interactive)
7365   (let ((best -1000000)
7366         (data gnus-newsgroup-data)
7367         article score)
7368     (while data
7369       (and (gnus-data-unread-p (car data))
7370            (> (setq score
7371                     (gnus-summary-article-score (gnus-data-number (car data))))
7372               best)
7373            (setq best score
7374                  article (gnus-data-number (car data))))
7375       (setq data (cdr data)))
7376     (when article
7377       (gnus-summary-goto-subject article))
7378     (gnus-summary-position-point)
7379     article))
7380
7381 (defun gnus-summary-better-unread-subject ()
7382   "Select the first unread subject that has a score over the default score."
7383   (interactive)
7384   (let ((data gnus-newsgroup-data)
7385         article score)
7386     (while (and (setq article (gnus-data-number (car data)))
7387                 (or (gnus-data-read-p (car data))
7388                     (not (> (gnus-summary-article-score article)
7389                             gnus-summary-default-score))))
7390       (setq data (cdr data)))
7391     (when article
7392       (gnus-summary-goto-subject article))
7393     (gnus-summary-position-point)
7394     article))
7395
7396 (defun gnus-summary-last-subject ()
7397   "Go to the last displayed subject line in the group."
7398   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7399     (when article
7400       (gnus-summary-goto-subject article))))
7401
7402 (defun gnus-summary-goto-article (article &optional all-headers force)
7403   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7404 If ALL-HEADERS is non-nil, no header lines are hidden.
7405 If FORCE, go to the article even if it isn't displayed.  If FORCE
7406 is a number, it is the line the article is to be displayed on."
7407   (interactive
7408    (list
7409     (completing-read
7410      "Article number or Message-ID: "
7411      (mapcar (lambda (number) (list (int-to-string number)))
7412              gnus-newsgroup-limit))
7413     current-prefix-arg
7414     t))
7415   (prog1
7416       (if (and (stringp article)
7417                (string-match "@" article))
7418           (gnus-summary-refer-article article)
7419         (when (stringp article)
7420           (setq article (string-to-number article)))
7421         (if (gnus-summary-goto-subject article force)
7422             (gnus-summary-display-article article all-headers)
7423           (gnus-message 4 "Couldn't go to article %s" article) nil))
7424     (gnus-summary-position-point)))
7425
7426 (defun gnus-summary-goto-last-article ()
7427   "Go to the previously read article."
7428   (interactive)
7429   (prog1
7430       (when gnus-last-article
7431         (gnus-summary-goto-article gnus-last-article nil t))
7432     (gnus-summary-position-point)))
7433
7434 (defun gnus-summary-pop-article (number)
7435   "Pop one article off the history and go to the previous.
7436 NUMBER articles will be popped off."
7437   (interactive "p")
7438   (let (to)
7439     (setq gnus-newsgroup-history
7440           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7441     (if to
7442         (gnus-summary-goto-article (car to) nil t)
7443       (error "Article history empty")))
7444   (gnus-summary-position-point))
7445
7446 ;; Summary commands and functions for limiting the summary buffer.
7447
7448 (defun gnus-summary-limit-to-articles (n)
7449   "Limit the summary buffer to the next N articles.
7450 If not given a prefix, use the process marked articles instead."
7451   (interactive "P")
7452   (prog1
7453       (let ((articles (gnus-summary-work-articles n)))
7454         (setq gnus-newsgroup-processable nil)
7455         (gnus-summary-limit articles))
7456     (gnus-summary-position-point)))
7457
7458 (defun gnus-summary-pop-limit (&optional total)
7459   "Restore the previous limit.
7460 If given a prefix, remove all limits."
7461   (interactive "P")
7462   (when total
7463     (setq gnus-newsgroup-limits
7464           (list (mapcar (lambda (h) (mail-header-number h))
7465                         gnus-newsgroup-headers))))
7466   (unless gnus-newsgroup-limits
7467     (error "No limit to pop"))
7468   (prog1
7469       (gnus-summary-limit nil 'pop)
7470     (gnus-summary-position-point)))
7471
7472 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7473   "Limit the summary buffer to articles that have subjects that match a regexp.
7474 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7475   (interactive
7476    (list (read-string (if current-prefix-arg
7477                           "Exclude subject (regexp): "
7478                         "Limit to subject (regexp): "))
7479          nil current-prefix-arg))
7480   (unless header
7481     (setq header "subject"))
7482   (when (not (equal "" subject))
7483     (prog1
7484         (let ((articles (gnus-summary-find-matching
7485                          (or header "subject") subject 'all nil nil
7486                          not-matching)))
7487           (unless articles
7488             (error "Found no matches for \"%s\"" subject))
7489           (gnus-summary-limit articles))
7490       (gnus-summary-position-point))))
7491
7492 (defun gnus-summary-limit-to-author (from &optional not-matching)
7493   "Limit the summary buffer to articles that have authors that match a regexp.
7494 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7495   (interactive
7496    (list (read-string (if current-prefix-arg
7497                           "Exclude author (regexp): "
7498                         "Limit to author (regexp): "))
7499          current-prefix-arg))
7500   (gnus-summary-limit-to-subject from "from" not-matching))
7501
7502 (defun gnus-summary-limit-to-age (age &optional younger-p)
7503   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7504 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7505 articles that are younger than AGE days."
7506   (interactive
7507    (let ((younger current-prefix-arg)
7508          (days-got nil)
7509          days)
7510      (while (not days-got)
7511        (setq days (if younger
7512                       (read-string "Limit to articles younger than (in days, older when negative): ")
7513                     (read-string
7514                      "Limit to articles older than (in days, younger when negative): ")))
7515        (when (> (length days) 0)
7516          (setq days (read days)))
7517        (if (numberp days)
7518            (progn
7519              (setq days-got t)
7520              (if (< days 0)
7521                  (progn
7522                    (setq younger (not younger))
7523                    (setq days (* days -1)))))
7524          (message "Please enter a number.")
7525          (sleep-for 1)))
7526      (list days younger)))
7527   (prog1
7528       (let ((data gnus-newsgroup-data)
7529             (cutoff (days-to-time age))
7530             articles d date is-younger)
7531         (while (setq d (pop data))
7532           (when (and (vectorp (gnus-data-header d))
7533                      (setq date (mail-header-date (gnus-data-header d))))
7534             (setq is-younger (time-less-p
7535                               (time-since (condition-case ()
7536                                               (date-to-time date)
7537                                             (error '(0 0))))
7538                               cutoff))
7539             (when (if younger-p
7540                       is-younger
7541                     (not is-younger))
7542               (push (gnus-data-number d) articles))))
7543         (gnus-summary-limit (nreverse articles)))
7544     (gnus-summary-position-point)))
7545
7546 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7547   "Limit the summary buffer to articles that match an 'extra' header."
7548   (interactive
7549    (let ((header
7550           (intern
7551            (gnus-completing-read-with-default
7552             (symbol-name (car gnus-extra-headers))
7553             (if current-prefix-arg
7554                 "Exclude extra header:"
7555               "Limit extra header:")
7556             (mapcar (lambda (x)
7557                       (cons (symbol-name x) x))
7558                     gnus-extra-headers)
7559             nil
7560             t))))
7561      (list header
7562            (read-string (format "%s header %s (regexp): "
7563                                 (if current-prefix-arg "Exclude" "Limit to")
7564                                 header))
7565            current-prefix-arg)))
7566   (when (not (equal "" regexp))
7567     (prog1
7568         (let ((articles (gnus-summary-find-matching
7569                          (cons 'extra header) regexp 'all nil nil
7570                          not-matching)))
7571           (unless articles
7572             (error "Found no matches for \"%s\"" regexp))
7573           (gnus-summary-limit articles))
7574       (gnus-summary-position-point))))
7575
7576 (defun gnus-summary-limit-to-display-predicate ()
7577   "Limit the summary buffer to the predicated in the `display' group parameter."
7578   (interactive)
7579   (unless gnus-newsgroup-display
7580     (error "There is no `display' group parameter"))
7581   (let (articles)
7582     (dolist (number gnus-newsgroup-articles)
7583       (when (funcall gnus-newsgroup-display)
7584         (push number articles)))
7585     (gnus-summary-limit articles))
7586   (gnus-summary-position-point))
7587
7588 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7589 (make-obsolete
7590  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7591
7592 (defun gnus-summary-limit-to-unread (&optional all)
7593   "Limit the summary buffer to articles that are not marked as read.
7594 If ALL is non-nil, limit strictly to unread articles."
7595   (interactive "P")
7596   (if all
7597       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7598     (gnus-summary-limit-to-marks
7599      ;; Concat all the marks that say that an article is read and have
7600      ;; those removed.
7601      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7602            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7603            gnus-low-score-mark gnus-expirable-mark
7604            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7605            gnus-duplicate-mark gnus-souped-mark)
7606      'reverse)))
7607
7608 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7609 (make-obsolete 'gnus-summary-delete-marked-with
7610                'gnus-summary-limit-exclude-marks)
7611
7612 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7613   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7614 If REVERSE, limit the summary buffer to articles that are marked
7615 with MARKS.  MARKS can either be a string of marks or a list of marks.
7616 Returns how many articles were removed."
7617   (interactive "sMarks: ")
7618   (gnus-summary-limit-to-marks marks t))
7619
7620 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7621   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7622 If REVERSE (the prefix), limit the summary buffer to articles that are
7623 not marked with MARKS.  MARKS can either be a string of marks or a
7624 list of marks.
7625 Returns how many articles were removed."
7626   (interactive "sMarks: \nP")
7627   (prog1
7628       (let ((data gnus-newsgroup-data)
7629             (marks (if (listp marks) marks
7630                      (append marks nil))) ; Transform to list.
7631             articles)
7632         (while data
7633           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7634                   (memq (gnus-data-mark (car data)) marks))
7635             (push (gnus-data-number (car data)) articles))
7636           (setq data (cdr data)))
7637         (gnus-summary-limit articles))
7638     (gnus-summary-position-point)))
7639
7640 (defun gnus-summary-limit-to-score (score)
7641   "Limit to articles with score at or above SCORE."
7642   (interactive "NLimit to articles with score of at least: ")
7643   (let ((data gnus-newsgroup-data)
7644         articles)
7645     (while data
7646       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7647                 score)
7648         (push (gnus-data-number (car data)) articles))
7649       (setq data (cdr data)))
7650     (prog1
7651         (gnus-summary-limit articles)
7652       (gnus-summary-position-point))))
7653
7654 (defun gnus-summary-limit-to-unseen ()
7655   "Limit to unseen articles."
7656   (interactive)
7657   (prog1
7658       (gnus-summary-limit gnus-newsgroup-unseen)
7659     (gnus-summary-position-point)))
7660
7661 (defun gnus-summary-limit-include-thread (id)
7662   "Display all the hidden articles that is in the thread with ID in it.
7663 When called interactively, ID is the Message-ID of the current
7664 article."
7665   (interactive (list (mail-header-id (gnus-summary-article-header))))
7666   (let ((articles (gnus-articles-in-thread
7667                    (gnus-id-to-thread (gnus-root-id id)))))
7668     (prog1
7669         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7670       (gnus-summary-limit-include-matching-articles
7671        "subject"
7672        (regexp-quote (gnus-simplify-subject-re
7673                       (mail-header-subject (gnus-id-to-header id)))))
7674       (gnus-summary-position-point))))
7675
7676 (defun gnus-summary-limit-include-matching-articles (header regexp)
7677   "Display all the hidden articles that have HEADERs that match REGEXP."
7678   (interactive (list (read-string "Match on header: ")
7679                      (read-string "Regexp: ")))
7680   (let ((articles (gnus-find-matching-articles header regexp)))
7681     (prog1
7682         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7683       (gnus-summary-position-point))))
7684
7685 (defun gnus-summary-insert-dormant-articles ()
7686   "Insert all the dormat articles for this group into the current buffer."
7687   (interactive)
7688   (let ((gnus-verbose (max 6 gnus-verbose)))
7689     (if (not gnus-newsgroup-dormant)
7690         (gnus-message 3 "No cached articles for this group")
7691       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7692
7693 (defun gnus-summary-limit-include-dormant ()
7694   "Display all the hidden articles that are marked as dormant.
7695 Note that this command only works on a subset of the articles currently
7696 fetched for this group."
7697   (interactive)
7698   (unless gnus-newsgroup-dormant
7699     (error "There are no dormant articles in this group"))
7700   (prog1
7701       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7702     (gnus-summary-position-point)))
7703
7704 (defun gnus-summary-limit-exclude-dormant ()
7705   "Hide all dormant articles."
7706   (interactive)
7707   (prog1
7708       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7709     (gnus-summary-position-point)))
7710
7711 (defun gnus-summary-limit-exclude-childless-dormant ()
7712   "Hide all dormant articles that have no children."
7713   (interactive)
7714   (let ((data (gnus-data-list t))
7715         articles d children)
7716     ;; Find all articles that are either not dormant or have
7717     ;; children.
7718     (while (setq d (pop data))
7719       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7720                 (and (setq children
7721                            (gnus-article-children (gnus-data-number d)))
7722                      (let (found)
7723                        (while children
7724                          (when (memq (car children) articles)
7725                            (setq children nil
7726                                  found t))
7727                          (pop children))
7728                        found)))
7729         (push (gnus-data-number d) articles)))
7730     ;; Do the limiting.
7731     (prog1
7732         (gnus-summary-limit articles)
7733       (gnus-summary-position-point))))
7734
7735 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7736   "Mark all unread excluded articles as read.
7737 If ALL, mark even excluded ticked and dormants as read."
7738   (interactive "P")
7739   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7740   (let ((articles (gnus-sorted-ndifference
7741                    (sort
7742                     (mapcar (lambda (h) (mail-header-number h))
7743                             gnus-newsgroup-headers)
7744                     '<)
7745                    gnus-newsgroup-limit))
7746         article)
7747     (setq gnus-newsgroup-unreads
7748           (gnus-sorted-intersection gnus-newsgroup-unreads
7749                                     gnus-newsgroup-limit))
7750     (if all
7751         (setq gnus-newsgroup-dormant nil
7752               gnus-newsgroup-marked nil
7753               gnus-newsgroup-reads
7754               (nconc
7755                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7756                gnus-newsgroup-reads))
7757       (while (setq article (pop articles))
7758         (unless (or (memq article gnus-newsgroup-dormant)
7759                     (memq article gnus-newsgroup-marked))
7760           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7761
7762 (defun gnus-summary-limit (articles &optional pop)
7763   (if pop
7764       ;; We pop the previous limit off the stack and use that.
7765       (setq articles (car gnus-newsgroup-limits)
7766             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7767     ;; We use the new limit, so we push the old limit on the stack.
7768     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7769   ;; Set the limit.
7770   (setq gnus-newsgroup-limit articles)
7771   (let ((total (length gnus-newsgroup-data))
7772         (data (gnus-data-find-list (gnus-summary-article-number)))
7773         (gnus-summary-mark-below nil)   ; Inhibit this.
7774         found)
7775     ;; This will do all the work of generating the new summary buffer
7776     ;; according to the new limit.
7777     (gnus-summary-prepare)
7778     ;; Hide any threads, possibly.
7779     (gnus-summary-maybe-hide-threads)
7780     ;; Try to return to the article you were at, or one in the
7781     ;; neighborhood.
7782     (when data
7783       ;; We try to find some article after the current one.
7784       (while data
7785         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7786           (setq data nil
7787                 found t))
7788         (setq data (cdr data))))
7789     (unless found
7790       ;; If there is no data, that means that we were after the last
7791       ;; article.  The same goes when we can't find any articles
7792       ;; after the current one.
7793       (goto-char (point-max))
7794       (gnus-summary-find-prev))
7795     (gnus-set-mode-line 'summary)
7796     ;; We return how many articles were removed from the summary
7797     ;; buffer as a result of the new limit.
7798     (- total (length gnus-newsgroup-data))))
7799
7800 (defsubst gnus-invisible-cut-children (threads)
7801   (let ((num 0))
7802     (while threads
7803       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7804         (incf num))
7805       (pop threads))
7806     (< num 2)))
7807
7808 (defsubst gnus-cut-thread (thread)
7809   "Go forwards in the thread until we find an article that we want to display."
7810   (when (or (eq gnus-fetch-old-headers 'some)
7811             (eq gnus-fetch-old-headers 'invisible)
7812             (numberp gnus-fetch-old-headers)
7813             (eq gnus-build-sparse-threads 'some)
7814             (eq gnus-build-sparse-threads 'more))
7815     ;; Deal with old-fetched headers and sparse threads.
7816     (while (and
7817             thread
7818             (or
7819              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7820              (gnus-summary-article-ancient-p
7821               (mail-header-number (car thread))))
7822             (if (or (<= (length (cdr thread)) 1)
7823                     (eq gnus-fetch-old-headers 'invisible))
7824                 (setq gnus-newsgroup-limit
7825                       (delq (mail-header-number (car thread))
7826                             gnus-newsgroup-limit)
7827                       thread (cadr thread))
7828               (when (gnus-invisible-cut-children (cdr thread))
7829                 (let ((th (cdr thread)))
7830                   (while th
7831                     (if (memq (mail-header-number (caar th))
7832                               gnus-newsgroup-limit)
7833                         (setq thread (car th)
7834                               th nil)
7835                       (setq th (cdr th))))))))))
7836   thread)
7837
7838 (defun gnus-cut-threads (threads)
7839   "Cut off all uninteresting articles from the beginning of threads."
7840   (when (or (eq gnus-fetch-old-headers 'some)
7841             (eq gnus-fetch-old-headers 'invisible)
7842             (numberp gnus-fetch-old-headers)
7843             (eq gnus-build-sparse-threads 'some)
7844             (eq gnus-build-sparse-threads 'more))
7845     (let ((th threads))
7846       (while th
7847         (setcar th (gnus-cut-thread (car th)))
7848         (setq th (cdr th)))))
7849   ;; Remove nixed out threads.
7850   (delq nil threads))
7851
7852 (defun gnus-summary-initial-limit (&optional show-if-empty)
7853   "Figure out what the initial limit is supposed to be on group entry.
7854 This entails weeding out unwanted dormants, low-scored articles,
7855 fetch-old-headers verbiage, and so on."
7856   ;; Most groups have nothing to remove.
7857   (if (or gnus-inhibit-limiting
7858           (and (null gnus-newsgroup-dormant)
7859                (eq gnus-newsgroup-display 'gnus-not-ignore)
7860                (not (eq gnus-fetch-old-headers 'some))
7861                (not (numberp gnus-fetch-old-headers))
7862                (not (eq gnus-fetch-old-headers 'invisible))
7863                (null gnus-summary-expunge-below)
7864                (not (eq gnus-build-sparse-threads 'some))
7865                (not (eq gnus-build-sparse-threads 'more))
7866                (null gnus-thread-expunge-below)
7867                (not gnus-use-nocem)))
7868       ()                                ; Do nothing.
7869     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7870     (setq gnus-newsgroup-limit nil)
7871     (mapatoms
7872      (lambda (node)
7873        (unless (car (symbol-value node))
7874          ;; These threads have no parents -- they are roots.
7875          (let ((nodes (cdr (symbol-value node)))
7876                thread)
7877            (while nodes
7878              (if (and gnus-thread-expunge-below
7879                       (< (gnus-thread-total-score (car nodes))
7880                          gnus-thread-expunge-below))
7881                  (gnus-expunge-thread (pop nodes))
7882                (setq thread (pop nodes))
7883                (gnus-summary-limit-children thread))))))
7884      gnus-newsgroup-dependencies)
7885     ;; If this limitation resulted in an empty group, we might
7886     ;; pop the previous limit and use it instead.
7887     (when (and (not gnus-newsgroup-limit)
7888                show-if-empty)
7889       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7890     gnus-newsgroup-limit))
7891
7892 (defun gnus-summary-limit-children (thread)
7893   "Return 1 if this subthread is visible and 0 if it is not."
7894   ;; First we get the number of visible children to this thread.  This
7895   ;; is done by recursing down the thread using this function, so this
7896   ;; will really go down to a leaf article first, before slowly
7897   ;; working its way up towards the root.
7898   (when thread
7899     (let* ((max-lisp-eval-depth 5000)
7900            (children
7901            (if (cdr thread)
7902                (apply '+ (mapcar 'gnus-summary-limit-children
7903                                  (cdr thread)))
7904              0))
7905           (number (mail-header-number (car thread)))
7906           score)
7907       (if (and
7908            (not (memq number gnus-newsgroup-marked))
7909            (or
7910             ;; If this article is dormant and has absolutely no visible
7911             ;; children, then this article isn't visible.
7912             (and (memq number gnus-newsgroup-dormant)
7913                  (zerop children))
7914             ;; If this is "fetch-old-headered" and there is no
7915             ;; visible children, then we don't want this article.
7916             (and (or (eq gnus-fetch-old-headers 'some)
7917                      (numberp gnus-fetch-old-headers))
7918                  (gnus-summary-article-ancient-p number)
7919                  (zerop children))
7920             ;; If this is "fetch-old-headered" and `invisible', then
7921             ;; we don't want this article.
7922             (and (eq gnus-fetch-old-headers 'invisible)
7923                  (gnus-summary-article-ancient-p number))
7924             ;; If this is a sparsely inserted article with no children,
7925             ;; we don't want it.
7926             (and (eq gnus-build-sparse-threads 'some)
7927                  (gnus-summary-article-sparse-p number)
7928                  (zerop children))
7929             ;; If we use expunging, and this article is really
7930             ;; low-scored, then we don't want this article.
7931             (when (and gnus-summary-expunge-below
7932                        (< (setq score
7933                                 (or (cdr (assq number gnus-newsgroup-scored))
7934                                     gnus-summary-default-score))
7935                           gnus-summary-expunge-below))
7936               ;; We increase the expunge-tally here, but that has
7937               ;; nothing to do with the limits, really.
7938               (incf gnus-newsgroup-expunged-tally)
7939               ;; We also mark as read here, if that's wanted.
7940               (when (and gnus-summary-mark-below
7941                          (< score gnus-summary-mark-below))
7942                 (setq gnus-newsgroup-unreads
7943                       (delq number gnus-newsgroup-unreads))
7944                 (if gnus-newsgroup-auto-expire
7945                     (push number gnus-newsgroup-expirable)
7946                   (push (cons number gnus-low-score-mark)
7947                         gnus-newsgroup-reads)))
7948               t)
7949             ;; Do the `display' group parameter.
7950             (and gnus-newsgroup-display
7951                  (not (funcall gnus-newsgroup-display)))
7952             ;; Check NoCeM things.
7953             (if (and gnus-use-nocem
7954                      (gnus-nocem-unwanted-article-p
7955                       (mail-header-id (car thread))))
7956                 (progn
7957                   (setq gnus-newsgroup-unreads
7958                         (delq number gnus-newsgroup-unreads))
7959                   t))))
7960           ;; Nope, invisible article.
7961           0
7962         ;; Ok, this article is to be visible, so we add it to the limit
7963         ;; and return 1.
7964         (push number gnus-newsgroup-limit)
7965         1))))
7966
7967 (defun gnus-expunge-thread (thread)
7968   "Mark all articles in THREAD as read."
7969   (let* ((number (mail-header-number (car thread))))
7970     (incf gnus-newsgroup-expunged-tally)
7971     ;; We also mark as read here, if that's wanted.
7972     (setq gnus-newsgroup-unreads
7973           (delq number gnus-newsgroup-unreads))
7974     (if gnus-newsgroup-auto-expire
7975         (push number gnus-newsgroup-expirable)
7976       (push (cons number gnus-low-score-mark)
7977             gnus-newsgroup-reads)))
7978   ;; Go recursively through all subthreads.
7979   (mapcar 'gnus-expunge-thread (cdr thread)))
7980
7981 ;; Summary article oriented commands
7982
7983 (defun gnus-summary-refer-parent-article (n)
7984   "Refer parent article N times.
7985 If N is negative, go to ancestor -N instead.
7986 The difference between N and the number of articles fetched is returned."
7987   (interactive "p")
7988   (let ((skip 1)
7989         error header ref)
7990     (when (not (natnump n))
7991       (setq skip (abs n)
7992             n 1))
7993     (while (and (> n 0)
7994                 (not error))
7995       (setq header (gnus-summary-article-header))
7996       (if (and (eq (mail-header-number header)
7997                    (cdr gnus-article-current))
7998                (equal gnus-newsgroup-name
7999                       (car gnus-article-current)))
8000           ;; If we try to find the parent of the currently
8001           ;; displayed article, then we take a look at the actual
8002           ;; References header, since this is slightly more
8003           ;; reliable than the References field we got from the
8004           ;; server.
8005           (save-excursion
8006             (set-buffer gnus-original-article-buffer)
8007             (nnheader-narrow-to-headers)
8008             (unless (setq ref (message-fetch-field "references"))
8009               (setq ref (message-fetch-field "in-reply-to")))
8010             (widen))
8011         (setq ref
8012               ;; It's not the current article, so we take a bet on
8013               ;; the value we got from the server.
8014               (mail-header-references header)))
8015       (if (and ref
8016                (not (equal ref "")))
8017           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8018             (gnus-message 1 "Couldn't find parent"))
8019         (gnus-message 1 "No references in article %d"
8020                       (gnus-summary-article-number))
8021         (setq error t))
8022       (decf n))
8023     (gnus-summary-position-point)
8024     n))
8025
8026 (defun gnus-summary-refer-references ()
8027   "Fetch all articles mentioned in the References header.
8028 Return the number of articles fetched."
8029   (interactive)
8030   (let ((ref (mail-header-references (gnus-summary-article-header)))
8031         (current (gnus-summary-article-number))
8032         (n 0))
8033     (if (or (not ref)
8034             (equal ref ""))
8035         (error "No References in the current article")
8036       ;; For each Message-ID in the References header...
8037       (while (string-match "<[^>]*>" ref)
8038         (incf n)
8039         ;; ... fetch that article.
8040         (gnus-summary-refer-article
8041          (prog1 (match-string 0 ref)
8042            (setq ref (substring ref (match-end 0))))))
8043       (gnus-summary-goto-subject current)
8044       (gnus-summary-position-point)
8045       n)))
8046
8047 (defun gnus-summary-refer-thread (&optional limit)
8048   "Fetch all articles in the current thread.
8049 If LIMIT (the numerical prefix), fetch that many old headers instead
8050 of what's specified by the `gnus-refer-thread-limit' variable."
8051   (interactive "P")
8052   (let ((id (mail-header-id (gnus-summary-article-header)))
8053         (limit (if limit (prefix-numeric-value limit)
8054                  gnus-refer-thread-limit)))
8055     (unless (eq gnus-fetch-old-headers 'invisible)
8056       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8057       ;; Retrieve the headers and read them in.
8058       (if (eq (if (numberp limit)
8059                   (gnus-retrieve-headers
8060                    (list (min
8061                           (+ (mail-header-number
8062                               (gnus-summary-article-header))
8063                              limit)
8064                           gnus-newsgroup-end))
8065                    gnus-newsgroup-name (* limit 2))
8066                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8067                 ;; headers.
8068                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8069                                        gnus-newsgroup-name limit))
8070               'nov)
8071           (gnus-build-all-threads)
8072         (error "Can't fetch thread from backends that don't support NOV"))
8073       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8074     (gnus-summary-limit-include-thread id)))
8075
8076 (defun gnus-summary-refer-article (message-id)
8077   "Fetch an article specified by MESSAGE-ID."
8078   (interactive "sMessage-ID: ")
8079   (when (and (stringp message-id)
8080              (not (zerop (length message-id))))
8081     ;; Construct the correct Message-ID if necessary.
8082     ;; Suggested by tale@pawl.rpi.edu.
8083     (unless (string-match "^<" message-id)
8084       (setq message-id (concat "<" message-id)))
8085     (unless (string-match ">$" message-id)
8086       (setq message-id (concat message-id ">")))
8087     (let* ((header (gnus-id-to-header message-id))
8088            (sparse (and header
8089                         (gnus-summary-article-sparse-p
8090                          (mail-header-number header))
8091                         (memq (mail-header-number header)
8092                               gnus-newsgroup-limit)))
8093            number)
8094       (cond
8095        ;; If the article is present in the buffer we just go to it.
8096        ((and header
8097              (or (not (gnus-summary-article-sparse-p
8098                        (mail-header-number header)))
8099                  sparse))
8100         (prog1
8101             (gnus-summary-goto-article
8102              (mail-header-number header) nil t)
8103           (when sparse
8104             (gnus-summary-update-article (mail-header-number header)))))
8105        (t
8106         ;; We fetch the article.
8107         (catch 'found
8108           (dolist (gnus-override-method (gnus-refer-article-methods))
8109             (when (and (gnus-check-server gnus-override-method)
8110                        ;; Fetch the header,
8111                        (setq number (gnus-summary-insert-subject message-id)))
8112               ;; and display the article.
8113               (gnus-summary-select-article nil nil nil number)
8114               (throw 'found t)))
8115           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8116
8117 (defun gnus-refer-article-methods ()
8118   "Return a list of referable methods."
8119   (cond
8120    ;; No method, so we default to current and native.
8121    ((null gnus-refer-article-method)
8122     (list gnus-current-select-method gnus-select-method))
8123    ;; Current.
8124    ((eq 'current gnus-refer-article-method)
8125     (list gnus-current-select-method))
8126    ;; List of select methods.
8127    ((not (and (symbolp (car gnus-refer-article-method))
8128               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8129     (let (out)
8130       (dolist (method gnus-refer-article-method)
8131         (push (if (eq 'current method)
8132                   gnus-current-select-method
8133                 method)
8134               out))
8135       (nreverse out)))
8136    ;; One single select method.
8137    (t
8138     (list gnus-refer-article-method))))
8139
8140 (defun gnus-summary-edit-parameters ()
8141   "Edit the group parameters of the current group."
8142   (interactive)
8143   (gnus-group-edit-group gnus-newsgroup-name 'params))
8144
8145 (defun gnus-summary-customize-parameters ()
8146   "Customize the group parameters of the current group."
8147   (interactive)
8148   (gnus-group-customize gnus-newsgroup-name))
8149
8150 (defun gnus-summary-enter-digest-group (&optional force)
8151   "Enter an nndoc group based on the current article.
8152 If FORCE, force a digest interpretation.  If not, try
8153 to guess what the document format is."
8154   (interactive "P")
8155   (let ((conf gnus-current-window-configuration))
8156     (save-window-excursion
8157       (save-excursion
8158         (let (gnus-article-prepare-hook
8159               gnus-display-mime-function
8160               gnus-break-pages)
8161           (gnus-summary-select-article))))
8162     (setq gnus-current-window-configuration conf)
8163     (let* ((name (format "%s-%d"
8164                          (gnus-group-prefixed-name
8165                           gnus-newsgroup-name (list 'nndoc ""))
8166                          (save-excursion
8167                            (set-buffer gnus-summary-buffer)
8168                            gnus-current-article)))
8169            (ogroup gnus-newsgroup-name)
8170            (params (append (gnus-info-params (gnus-get-info ogroup))
8171                            (list (cons 'to-group ogroup))
8172                            (list (cons 'save-article-group ogroup))))
8173            (case-fold-search t)
8174            (buf (current-buffer))
8175            dig to-address)
8176       (save-excursion
8177         (set-buffer gnus-original-article-buffer)
8178         ;; Have the digest group inherit the main mail address of
8179         ;; the parent article.
8180         (when (setq to-address (or (gnus-fetch-field "reply-to")
8181                                    (gnus-fetch-field "from")))
8182           (setq params (append
8183                         (list (cons 'to-address
8184                                     (funcall gnus-decode-encoded-word-function
8185                                              to-address))))))
8186         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8187         (insert-buffer-substring gnus-original-article-buffer)
8188         ;; Remove lines that may lead nndoc to misinterpret the
8189         ;; document type.
8190         (narrow-to-region
8191          (goto-char (point-min))
8192          (or (search-forward "\n\n" nil t) (point)))
8193         (goto-char (point-min))
8194         (delete-matching-lines "^Path:\\|^From ")
8195         (widen))
8196       (unwind-protect
8197           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8198                     (gnus-newsgroup-ephemeral-ignored-charsets
8199                      gnus-newsgroup-ignored-charsets))
8200                 (gnus-group-read-ephemeral-group
8201                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8202                               (nndoc-article-type
8203                                ,(if force 'mbox 'guess)))
8204                  t nil nil nil
8205                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8206                                                         "ADAPT")))))
8207               ;; Make all postings to this group go to the parent group.
8208               (nconc (gnus-info-params (gnus-get-info name))
8209                      params)
8210             ;; Couldn't select this doc group.
8211             (switch-to-buffer buf)
8212             (gnus-set-global-variables)
8213             (gnus-configure-windows 'summary)
8214             (gnus-message 3 "Article couldn't be entered?"))
8215         (kill-buffer dig)))))
8216
8217 (defun gnus-summary-read-document (n)
8218   "Open a new group based on the current article(s).
8219 This will allow you to read digests and other similar
8220 documents as newsgroups.
8221 Obeys the standard process/prefix convention."
8222   (interactive "P")
8223   (let* ((articles (gnus-summary-work-articles n))
8224          (ogroup gnus-newsgroup-name)
8225          (params (append (gnus-info-params (gnus-get-info ogroup))
8226                          (list (cons 'to-group ogroup))))
8227          article group egroup groups vgroup)
8228     (while (setq article (pop articles))
8229       (setq group (format "%s-%d" gnus-newsgroup-name article))
8230       (gnus-summary-remove-process-mark article)
8231       (when (gnus-summary-display-article article)
8232         (save-excursion
8233           (with-temp-buffer
8234             (insert-buffer-substring gnus-original-article-buffer)
8235             ;; Remove some headers that may lead nndoc to make
8236             ;; the wrong guess.
8237             (message-narrow-to-head)
8238             (goto-char (point-min))
8239             (delete-matching-lines "^\\(Path\\):\\|^From ")
8240             (widen)
8241             (if (setq egroup
8242                       (gnus-group-read-ephemeral-group
8243                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8244                                      (nndoc-article-type guess))
8245                        t nil t))
8246                 (progn
8247                   ;; Make all postings to this group go to the parent group.
8248                   (nconc (gnus-info-params (gnus-get-info egroup))
8249                          params)
8250                   (push egroup groups))
8251               ;; Couldn't select this doc group.
8252               (gnus-error 3 "Article couldn't be entered"))))))
8253     ;; Now we have selected all the documents.
8254     (cond
8255      ((not groups)
8256       (error "None of the articles could be interpreted as documents"))
8257      ((gnus-group-read-ephemeral-group
8258        (setq vgroup (format
8259                      "nnvirtual:%s-%s" gnus-newsgroup-name
8260                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8261        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8262        t
8263        (cons (current-buffer) 'summary)))
8264      (t
8265       (error "Couldn't select virtual nndoc group")))))
8266
8267 (defun gnus-summary-isearch-article (&optional regexp-p)
8268   "Do incremental search forward on the current article.
8269 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8270   (interactive "P")
8271   (let* ((gnus-inhibit-treatment t)
8272          (old (gnus-summary-select-article)))
8273     (gnus-configure-windows 'article)
8274     (gnus-eval-in-buffer-window gnus-article-buffer
8275       (save-restriction
8276         (widen)
8277         (when (eq 'old old)
8278           (gnus-article-show-all-headers))
8279         (goto-char (point-min))
8280         (isearch-forward regexp-p)))))
8281
8282 (defun gnus-summary-search-article-forward (regexp &optional backward)
8283   "Search for an article containing REGEXP forward.
8284 If BACKWARD, search backward instead."
8285   (interactive
8286    (list (read-string
8287           (format "Search article %s (regexp%s): "
8288                   (if current-prefix-arg "backward" "forward")
8289                   (if gnus-last-search-regexp
8290                       (concat ", default " gnus-last-search-regexp)
8291                     "")))
8292          current-prefix-arg))
8293   (if (string-equal regexp "")
8294       (setq regexp (or gnus-last-search-regexp ""))
8295     (setq gnus-last-search-regexp regexp)
8296     (setq gnus-article-before-search gnus-current-article))
8297   ;; Intentionally set gnus-last-article.
8298   (setq gnus-last-article gnus-article-before-search)
8299   (let ((gnus-last-article gnus-last-article))
8300     (if (gnus-summary-search-article regexp backward)
8301         (gnus-summary-show-thread)
8302       (error "Search failed: \"%s\"" regexp))))
8303
8304 (defun gnus-summary-search-article-backward (regexp)
8305   "Search for an article containing REGEXP backward."
8306   (interactive
8307    (list (read-string
8308           (format "Search article backward (regexp%s): "
8309                   (if gnus-last-search-regexp
8310                       (concat ", default " gnus-last-search-regexp)
8311                     "")))))
8312   (gnus-summary-search-article-forward regexp 'backward))
8313
8314 (eval-when-compile
8315   (defmacro gnus-summary-search-article-position-point (regexp backward)
8316     "Dehighlight the last matched text and goto the beginning position."
8317     (` (if (and gnus-summary-search-article-matched-data
8318                 (let ((text (caddr gnus-summary-search-article-matched-data))
8319                       (inhibit-read-only t)
8320                       buffer-read-only)
8321                   (delete-region
8322                    (goto-char (car gnus-summary-search-article-matched-data))
8323                    (cadr gnus-summary-search-article-matched-data))
8324                   (insert text)
8325                   (string-match (, regexp) text)))
8326            (if (, backward) (beginning-of-line) (end-of-line))
8327          (goto-char (if (, backward) (point-max) (point-min))))))
8328
8329   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8330     "Place point where X-Face image is displayed."
8331     (if (featurep 'xemacs)
8332         (` (let ((end (if (search-forward "\n\n" nil t)
8333                           (goto-char (1- (point)))
8334                         (point-min)))
8335                  extent)
8336              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8337              (unless (and (re-search-forward "^From:" end t)
8338                           (setq extent (extent-at (point)))
8339                           (extent-begin-glyph extent))
8340                (goto-char (, opoint)))))
8341       (` (let ((end (if (search-forward "\n\n" nil t)
8342                         (goto-char (1- (point)))
8343                       (point-min)))
8344                (start (or (search-backward "\n\n" nil t) (point-min))))
8345            (goto-char
8346             (or (text-property-any start end 'x-face-image t);; x-face-e21
8347                 (text-property-any start end 'x-face-mule-bitmap-image t)
8348                 (, opoint)))))))
8349
8350   (defmacro gnus-summary-search-article-highlight-matched-text
8351     (backward treated x-face)
8352     "Highlight matched text in the function `gnus-summary-search-article'."
8353     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8354              (end (set-marker (make-marker) (match-end 0)))
8355              (inhibit-read-only t)
8356              buffer-read-only)
8357          (unless treated
8358            (let ((,@
8359                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8360                     (mapcar
8361                      (lambda (item) (setq items (delq item items)))
8362                      '(gnus-treat-buttonize
8363                        gnus-treat-fill-article
8364                        gnus-treat-fill-long-lines
8365                        gnus-treat-emphasize
8366                        gnus-treat-highlight-headers
8367                        gnus-treat-highlight-citation
8368                        gnus-treat-highlight-signature
8369                        gnus-treat-overstrike
8370                        gnus-treat-display-xface
8371                        gnus-treat-buttonize-head
8372                        gnus-treat-decode-article-as-default-mime-charset))
8373                     (static-if (featurep 'xemacs)
8374                         items
8375                       (cons '(x-face-mule-delete-x-face-field
8376                               (quote never))
8377                             items))))
8378                  (gnus-treat-display-xface
8379                   (when (, x-face) gnus-treat-display-xface)))
8380              (gnus-article-prepare-mime-display)))
8381          (goto-char (if (, backward) start end))
8382          (when (, x-face)
8383            (gnus-summary-search-article-highlight-goto-x-face (point)))
8384          (setq gnus-summary-search-article-matched-data
8385                (list start end (buffer-substring start end)))
8386          (unless (eq start end);; matched text has been deleted. :-<
8387            (put-text-property start end 'face
8388                               (or (find-face 'isearch)
8389                                   'secondary-selection))))))
8390   )
8391
8392 (defun gnus-summary-search-article (regexp &optional backward)
8393   "Search for an article containing REGEXP.
8394 Optional argument BACKWARD means do search for backward.
8395 `gnus-select-article-hook' is not called during the search."
8396   ;; We have to require this here to make sure that the following
8397   ;; dynamic binding isn't shadowed by autoloading.
8398   (require 'gnus-async)
8399   (require 'gnus-art)
8400   (let ((gnus-select-article-hook nil)  ;Disable hook.
8401         (gnus-article-prepare-hook nil)
8402         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8403         (gnus-use-article-prefetch nil)
8404         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8405         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8406         (gnus-visual nil)
8407         (gnus-keep-backlog nil)
8408         (gnus-break-pages nil)
8409         (gnus-summary-display-arrow nil)
8410         (gnus-updated-mode-lines nil)
8411         (gnus-auto-center-summary nil)
8412         (sum (current-buffer))
8413         (found nil)
8414         point treated)
8415     (gnus-save-hidden-threads
8416       (static-if (featurep 'xemacs)
8417           (let ((gnus-inhibit-treatment t))
8418             (setq treated (eq 'old (gnus-summary-select-article)))
8419             (when (and treated
8420                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8421                                  (window-live-p (get-buffer-window
8422                                                  gnus-article-buffer t)))))
8423               (gnus-summary-select-article nil t)
8424               (setq treated nil)))
8425         (let ((gnus-inhibit-treatment t)
8426               (x-face-mule-delete-x-face-field 'never))
8427           (setq treated (eq 'old (gnus-summary-select-article)))
8428           (when (and treated
8429                      (not
8430                       (and (gnus-buffer-live-p gnus-article-buffer)
8431                            (window-live-p (get-buffer-window
8432                                            gnus-article-buffer t))
8433                            (or (not (string-match "^\\^X-Face:" regexp))
8434                                (with-current-buffer gnus-article-buffer
8435                                  gnus-summary-search-article-matched-data)))))
8436             (gnus-summary-select-article nil t)
8437             (setq treated nil))))
8438       (set-buffer gnus-article-buffer)
8439       (widen)
8440       (if treated
8441           (progn
8442             (gnus-article-show-all-headers)
8443             (gnus-summary-search-article-position-point regexp backward))
8444         (goto-char (if backward (point-max) (point-min))))
8445       (while (not found)
8446         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8447         (if (if backward
8448                 (re-search-backward regexp nil t)
8449               (re-search-forward regexp nil t))
8450             ;; We found the regexp.
8451             (progn
8452               (gnus-summary-search-article-highlight-matched-text
8453                backward treated (string-match "^\\^X-Face:" regexp))
8454               (setq found 'found)
8455               (forward-line
8456                (/ (- 2 (window-height
8457                         (get-buffer-window gnus-article-buffer t)))
8458                   2))
8459               (set-window-start
8460                (get-buffer-window (current-buffer))
8461                (point))
8462               (set-buffer sum)
8463               (setq point (point)))
8464           ;; We didn't find it, so we go to the next article.
8465           (set-buffer sum)
8466           (setq found 'not)
8467           (while (eq found 'not)
8468             (if (not (if backward (gnus-summary-find-prev)
8469                        (gnus-summary-find-next)))
8470                 ;; No more articles.
8471                 (setq found t)
8472               ;; Select the next article and adjust point.
8473               (unless (gnus-summary-article-sparse-p
8474                        (gnus-summary-article-number))
8475                 (setq found nil)
8476                 (let ((gnus-inhibit-treatment t))
8477                   (gnus-summary-select-article))
8478                 (setq treated nil)
8479                 (set-buffer gnus-article-buffer)
8480                 (widen)
8481                 (goto-char (if backward (point-max) (point-min))))))))
8482       (gnus-message 7 ""))
8483     ;; Return whether we found the regexp.
8484     (when (eq found 'found)
8485       (goto-char point)
8486       (gnus-summary-show-thread)
8487       (gnus-summary-goto-subject gnus-current-article)
8488       (gnus-summary-position-point)
8489       t)))
8490
8491 (defun gnus-find-matching-articles (header regexp)
8492   "Return a list of all articles that match REGEXP on HEADER.
8493 This search includes all articles in the current group that Gnus has
8494 fetched headers for, whether they are displayed or not."
8495   (let ((articles nil)
8496         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8497         (case-fold-search t))
8498     (dolist (header gnus-newsgroup-headers)
8499       (when (string-match regexp (funcall func header))
8500         (push (mail-header-number header) articles)))
8501     (nreverse articles)))
8502
8503 (defun gnus-summary-find-matching (header regexp &optional backward unread
8504                                           not-case-fold not-matching)
8505   "Return a list of all articles that match REGEXP on HEADER.
8506 The search stars on the current article and goes forwards unless
8507 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8508 If UNREAD is non-nil, only unread articles will
8509 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8510 in the comparisons. If NOT-MATCHING, return a list of all articles that
8511 not match REGEXP on HEADER."
8512   (let ((case-fold-search (not not-case-fold))
8513         articles d func)
8514     (if (consp header)
8515         (if (eq (car header) 'extra)
8516             (setq func
8517                   `(lambda (h)
8518                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8519                          "")))
8520           (error "%s is an invalid header" header))
8521       (unless (fboundp (intern (concat "mail-header-" header)))
8522         (error "%s is not a valid header" header))
8523       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8524     (dolist (d (if (eq backward 'all)
8525                    gnus-newsgroup-data
8526                  (gnus-data-find-list
8527                   (gnus-summary-article-number)
8528                   (gnus-data-list backward))))
8529       (when (and (or (not unread)       ; We want all articles...
8530                      (gnus-data-unread-p d)) ; Or just unreads.
8531                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8532                  (if not-matching
8533                      (not (string-match
8534                            regexp
8535                            (funcall func (gnus-data-header d))))
8536                    (string-match regexp
8537                                  (funcall func (gnus-data-header d)))))
8538         (push (gnus-data-number d) articles))) ; Success!
8539     (nreverse articles)))
8540
8541 (defun gnus-summary-execute-command (header regexp command &optional backward)
8542   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8543 If HEADER is an empty string (or nil), the match is done on the entire
8544 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8545   (interactive
8546    (list (let ((completion-ignore-case t))
8547            (completing-read
8548             "Header name: "
8549             (mapcar (lambda (header) (list (format "%s" header)))
8550                     (append
8551                      '("Number" "Subject" "From" "Lines" "Date"
8552                        "Message-ID" "Xref" "References" "Body")
8553                      gnus-extra-headers))
8554             nil 'require-match))
8555          (read-string "Regexp: ")
8556          (read-key-sequence "Command: ")
8557          current-prefix-arg))
8558   (when (equal header "Body")
8559     (setq header ""))
8560   ;; Hidden thread subtrees must be searched as well.
8561   (gnus-summary-show-all-threads)
8562   ;; We don't want to change current point nor window configuration.
8563   (save-excursion
8564     (save-window-excursion
8565       (let (gnus-visual
8566             gnus-treat-strip-trailing-blank-lines
8567             gnus-treat-strip-leading-blank-lines
8568             gnus-treat-strip-multiple-blank-lines
8569             gnus-treat-hide-boring-headers
8570             gnus-treat-fold-newsgroups
8571             gnus-article-prepare-hook)
8572         (gnus-message 6 "Executing %s..." (key-description command))
8573         ;; We'd like to execute COMMAND interactively so as to give arguments.
8574         (gnus-execute header regexp
8575                       `(call-interactively ',(key-binding command))
8576                       backward)
8577         (gnus-message 6 "Executing %s...done" (key-description command))))))
8578
8579 (defun gnus-summary-beginning-of-article ()
8580   "Scroll the article back to the beginning."
8581   (interactive)
8582   (gnus-summary-select-article)
8583   (gnus-configure-windows 'article)
8584   (gnus-eval-in-buffer-window gnus-article-buffer
8585     (widen)
8586     (goto-char (point-min))
8587     (when gnus-page-broken
8588       (gnus-narrow-to-page))))
8589
8590 (defun gnus-summary-end-of-article ()
8591   "Scroll to the end of the article."
8592   (interactive)
8593   (gnus-summary-select-article)
8594   (gnus-configure-windows 'article)
8595   (gnus-eval-in-buffer-window gnus-article-buffer
8596     (widen)
8597     (goto-char (point-max))
8598     (recenter -3)
8599     (when gnus-page-broken
8600       (gnus-narrow-to-page))))
8601
8602 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8603   "Truncate to LEN and quote all \"(\"'s in STRING."
8604   (gnus-replace-in-string (if (and len (> (length string) len))
8605                               (substring string 0 len)
8606                             string)
8607                           "[()]" "\\\\\\&"))
8608
8609 (defun gnus-summary-print-article (&optional filename n)
8610   "Generate and print a PostScript image of the N next (mail) articles.
8611
8612 If N is negative, print the N previous articles.  If N is nil and articles
8613 have been marked with the process mark, print these instead.
8614
8615 If the optional first argument FILENAME is nil, send the image to the
8616 printer.  If FILENAME is a string, save the PostScript image in a file with
8617 that name.  If FILENAME is a number, prompt the user for the name of the file
8618 to save in."
8619   (interactive (list (ps-print-preprint current-prefix-arg)))
8620   (dolist (article (gnus-summary-work-articles n))
8621     (gnus-summary-select-article nil nil 'pseudo article)
8622     (gnus-eval-in-buffer-window gnus-article-buffer
8623       (gnus-print-buffer))
8624     (gnus-summary-remove-process-mark article))
8625   (ps-despool filename))
8626
8627 (defun gnus-print-buffer ()
8628   (let ((buffer (generate-new-buffer " *print*")))
8629     (unwind-protect
8630         (progn
8631           (copy-to-buffer buffer (point-min) (point-max))
8632           (set-buffer buffer)
8633           (gnus-article-delete-invisible-text)
8634           (gnus-remove-text-with-property 'gnus-decoration)
8635           (when (gnus-visual-p 'article-highlight 'highlight)
8636             ;; Copy-to-buffer doesn't copy overlay.  So redo
8637             ;; highlight.
8638             (let ((gnus-article-buffer buffer))
8639               (gnus-article-highlight-citation t)
8640               (gnus-article-highlight-signature)))
8641           (let ((ps-left-header
8642                  (list
8643                   (concat "("
8644                           (gnus-summary-print-truncate-and-quote
8645                            (mail-header-subject gnus-current-headers)
8646                            66) ")")
8647                   (concat "("
8648                           (gnus-summary-print-truncate-and-quote
8649                            (mail-header-from gnus-current-headers)
8650                            45) ")")))
8651                 (ps-right-header
8652                  (list
8653                   "/pagenumberstring load"
8654                   (concat "("
8655                           (mail-header-date gnus-current-headers) ")"))))
8656             (gnus-run-hooks 'gnus-ps-print-hook)
8657             (save-excursion
8658               (if window-system
8659                   (ps-spool-buffer-with-faces)
8660                 (ps-spool-buffer)))))
8661       (kill-buffer buffer))))
8662
8663 (defun gnus-summary-show-article (&optional arg)
8664   "Force redisplaying of the current article.
8665 If ARG (the prefix) is a number, show the article with the charset
8666 defined in `gnus-summary-show-article-charset-alist', or the charset
8667 input.
8668 If ARG (the prefix) is non-nil and not a number, show the raw article
8669 without any article massaging functions being run.  Normally, the key
8670 strokes are `C-u g'."
8671   (interactive "P")
8672   (cond
8673    ((numberp arg)
8674     (gnus-summary-show-article t)
8675     (let* ((gnus-newsgroup-charset
8676             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8677                 (mm-read-coding-system
8678                  "View as charset: " ;; actually it is coding system.
8679                  (save-excursion
8680                    (set-buffer gnus-article-buffer)
8681                    (mm-detect-coding-region (point) (point-max))))))
8682            (default-mime-charset gnus-newsgroup-charset)
8683            (gnus-newsgroup-ignored-charsets 'gnus-all))
8684       (gnus-summary-select-article nil 'force)
8685       (let ((deps gnus-newsgroup-dependencies)
8686             head header lines)
8687         (save-excursion
8688           (set-buffer gnus-original-article-buffer)
8689           (save-restriction
8690             (message-narrow-to-head)
8691             (setq head (buffer-string))
8692             (goto-char (point-min))
8693             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8694               (goto-char (point-max))
8695               (widen)
8696               (setq lines (1- (count-lines (point) (point-max))))))
8697           (with-temp-buffer
8698             (insert (format "211 %d Article retrieved.\n"
8699                             (cdr gnus-article-current)))
8700             (insert head)
8701             (if lines (insert (format "Lines: %d\n" lines)))
8702             (insert ".\n")
8703             (let ((nntp-server-buffer (current-buffer)))
8704               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8705         (gnus-data-set-header
8706          (gnus-data-find (cdr gnus-article-current))
8707          header)
8708         (gnus-summary-update-article-line
8709          (cdr gnus-article-current) header)
8710         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8711           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8712    ((not arg)
8713     ;; Select the article the normal way.
8714     (gnus-summary-select-article nil 'force))
8715    (t
8716     ;; We have to require this here to make sure that the following
8717     ;; dynamic binding isn't shadowed by autoloading.
8718     (require 'gnus-async)
8719     (require 'gnus-art)
8720     ;; Bind the article treatment functions to nil.
8721     (let ((gnus-have-all-headers t)
8722           gnus-article-prepare-hook
8723           gnus-article-decode-hook
8724           gnus-break-pages
8725           gnus-show-mime
8726           (gnus-inhibit-treatment t))
8727       (gnus-summary-select-article nil 'force))))
8728   (gnus-summary-goto-subject gnus-current-article)
8729   (gnus-summary-position-point))
8730
8731 (defun gnus-summary-show-raw-article ()
8732   "Show the raw article without any article massaging functions being run."
8733   (interactive)
8734   (gnus-summary-show-article t))
8735
8736 (defun gnus-summary-verbose-headers (&optional arg)
8737   "Toggle permanent full header display.
8738 If ARG is a positive number, turn header display on.
8739 If ARG is a negative number, turn header display off."
8740   (interactive "P")
8741   (setq gnus-show-all-headers
8742         (cond ((or (not (numberp arg))
8743                    (zerop arg))
8744                (not gnus-show-all-headers))
8745               ((natnump arg)
8746                t)))
8747   (gnus-summary-show-article))
8748
8749 (defun gnus-summary-toggle-header (&optional arg)
8750   "Show the headers if they are hidden, or hide them if they are shown.
8751 If ARG is a positive number, show the entire header.
8752 If ARG is a negative number, hide the unwanted header lines."
8753   (interactive "P")
8754   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8755                      (get-buffer-window gnus-article-buffer t))))
8756     (with-current-buffer gnus-article-buffer
8757       (widen)
8758       (article-narrow-to-head)
8759       (let* ((buffer-read-only nil)
8760              (inhibit-point-motion-hooks t)
8761              (hidden (if (numberp arg)
8762                          (>= arg 0)
8763                        (gnus-article-hidden-text-p 'headers)))
8764              s e)
8765         (delete-region (point-min) (point-max))
8766         (with-current-buffer gnus-original-article-buffer
8767           (goto-char (setq s (point-min)))
8768           (setq e (if (search-forward "\n\n" nil t)
8769                       (1- (point))
8770                     (point-max))))
8771         (insert-buffer-substring gnus-original-article-buffer s e)
8772         ;; In T-gnus, gnus-article-decode-hook doesn't contain
8773         ;; article-decode-encoded-words by default.
8774         (article-decode-encoded-words)
8775         (run-hooks 'gnus-article-decode-hook)
8776         (if hidden
8777             (let ((gnus-treat-hide-headers nil)
8778                   (gnus-treat-hide-boring-headers nil))
8779               (gnus-delete-wash-type 'headers)
8780               (gnus-treat-article 'head))
8781           (gnus-treat-article 'head))
8782         (widen)
8783         (if window
8784             (set-window-start window (goto-char (point-min))))
8785         (setq gnus-page-broken
8786               (when gnus-break-pages
8787                 (gnus-narrow-to-page)
8788                 t))
8789         (gnus-set-mode-line 'article)))))
8790
8791 (defun gnus-summary-show-all-headers ()
8792   "Make all header lines visible."
8793   (interactive)
8794   (gnus-summary-toggle-header 1))
8795
8796 (defun gnus-summary-toggle-mime (&optional arg)
8797   "Toggle MIME processing.
8798 If ARG is a positive number, turn MIME processing on."
8799   (interactive "P")
8800   (setq gnus-show-mime
8801         (if (null arg)
8802             (not gnus-show-mime)
8803           (> (prefix-numeric-value arg) 0)))
8804   (gnus-summary-select-article t 'force))
8805
8806 (defun gnus-summary-caesar-message (&optional arg)
8807   "Caesar rotate the current article by 13.
8808 The numerical prefix specifies how many places to rotate each letter
8809 forward."
8810   (interactive "P")
8811   (gnus-summary-select-article)
8812   (let ((mail-header-separator ""))
8813     (gnus-eval-in-buffer-window gnus-article-buffer
8814       (save-restriction
8815         (widen)
8816         (let ((start (window-start))
8817               buffer-read-only)
8818           (message-caesar-buffer-body arg)
8819           (set-window-start (get-buffer-window (current-buffer)) start))))))
8820
8821 (autoload 'unmorse-region "morse"
8822   "Convert morse coded text in region to ordinary ASCII text."
8823   t)
8824
8825 (defun gnus-summary-morse-message (&optional arg)
8826   "Morse decode the current article."
8827   (interactive "P")
8828   (gnus-summary-select-article)
8829   (let ((mail-header-separator ""))
8830     (gnus-eval-in-buffer-window gnus-article-buffer
8831       (save-excursion
8832         (save-restriction
8833           (widen)
8834           (let ((pos (window-start))
8835                 buffer-read-only)
8836             (goto-char (point-min))
8837             (when (message-goto-body)
8838               (gnus-narrow-to-body))
8839             (goto-char (point-min))
8840             (while (re-search-forward "·" (point-max) t)
8841               (replace-match "."))
8842             (unmorse-region (point-min) (point-max))
8843             (widen)
8844             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8845
8846 (defun gnus-summary-stop-page-breaking ()
8847   "Stop page breaking in the current article."
8848   (interactive)
8849   (gnus-summary-select-article)
8850   (gnus-eval-in-buffer-window gnus-article-buffer
8851     (widen)
8852     (when (gnus-visual-p 'page-marker)
8853       (let ((buffer-read-only nil))
8854         (gnus-remove-text-with-property 'gnus-prev)
8855         (gnus-remove-text-with-property 'gnus-next))
8856       (setq gnus-page-broken nil))))
8857
8858 (defun gnus-summary-move-article (&optional n to-newsgroup
8859                                             select-method action)
8860   "Move the current article to a different newsgroup.
8861 If N is a positive number, move the N next articles.
8862 If N is a negative number, move the N previous articles.
8863 If N is nil and any articles have been marked with the process mark,
8864 move those articles instead.
8865 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8866 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8867 re-spool using this method.
8868
8869 When called interactively with TO-NEWSGROUP being nil, the value of
8870 the variable `gnus-move-split-methods' is used for finding a default
8871 for the target newsgroup.
8872
8873 For this function to work, both the current newsgroup and the
8874 newsgroup that you want to move to have to support the `request-move'
8875 and `request-accept' functions.
8876
8877 ACTION can be either `move' (the default), `crosspost' or `copy'."
8878   (interactive "P")
8879   (unless action
8880     (setq action 'move))
8881   ;; Check whether the source group supports the required functions.
8882   (cond ((and (eq action 'move)
8883               (not (gnus-check-backend-function
8884                     'request-move-article gnus-newsgroup-name)))
8885          (error "The current group does not support article moving"))
8886         ((and (eq action 'crosspost)
8887               (not (gnus-check-backend-function
8888                     'request-replace-article gnus-newsgroup-name)))
8889          (error "The current group does not support article editing")))
8890   (let ((articles (gnus-summary-work-articles n))
8891         (prefix (if (gnus-check-backend-function
8892                      'request-move-article gnus-newsgroup-name)
8893                     (gnus-group-real-prefix gnus-newsgroup-name)
8894                   ""))
8895         (names '((move "Move" "Moving")
8896                  (copy "Copy" "Copying")
8897                  (crosspost "Crosspost" "Crossposting")))
8898         (copy-buf (save-excursion
8899                     (nnheader-set-temp-buffer " *copy article*")))
8900         (default-marks gnus-article-mark-lists)
8901         (no-expire-marks (delete '(expirable . expire)
8902                                  (copy-sequence gnus-article-mark-lists)))
8903         art-group to-method new-xref article to-groups)
8904     (unless (assq action names)
8905       (error "Unknown action %s" action))
8906     ;; Read the newsgroup name.
8907     (when (and (not to-newsgroup)
8908                (not select-method))
8909       (if (and gnus-move-split-methods
8910                (not
8911                 (and (memq gnus-current-article articles)
8912                      (gnus-buffer-live-p gnus-original-article-buffer))))
8913           ;; When `gnus-move-split-methods' is non-nil, we have to
8914           ;; select an article to give `gnus-read-move-group-name' an
8915           ;; opportunity to suggest an appropriate default.  However,
8916           ;; we needn't render or mark the article.
8917           (let ((gnus-display-mime-function nil)
8918                 (gnus-article-prepare-hook nil)
8919                 (gnus-mark-article-hook nil))
8920             (gnus-summary-select-article nil nil nil (car articles))))
8921       (setq to-newsgroup
8922             (gnus-read-move-group-name
8923              (cadr (assq action names))
8924              (symbol-value (intern (format "gnus-current-%s-group" action)))
8925              articles prefix))
8926       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8927     (setq to-method (or select-method
8928                         (gnus-server-to-method
8929                          (gnus-group-method to-newsgroup))))
8930     ;; Check the method we are to move this article to...
8931     (unless (gnus-check-backend-function
8932              'request-accept-article (car to-method))
8933       (error "%s does not support article copying" (car to-method)))
8934     (unless (gnus-check-server to-method)
8935       (error "Can't open server %s" (car to-method)))
8936     (gnus-message 6 "%s to %s: %s..."
8937                   (caddr (assq action names))
8938                   (or (car select-method) to-newsgroup) articles)
8939     (while articles
8940       (setq article (pop articles))
8941       (setq
8942        art-group
8943        (cond
8944         ;; Move the article.
8945         ((eq action 'move)
8946          ;; Remove this article from future suppression.
8947          (gnus-dup-unsuppress-article article)
8948          (gnus-request-move-article
8949           article                       ; Article to move
8950           gnus-newsgroup-name           ; From newsgroup
8951           (nth 1 (gnus-find-method-for-group
8952                   gnus-newsgroup-name)) ; Server
8953           (list 'gnus-request-accept-article
8954                 to-newsgroup (list 'quote select-method)
8955                 (not articles) t)       ; Accept form
8956           (not articles)))              ; Only save nov last time
8957         ;; Copy the article.
8958         ((eq action 'copy)
8959          (save-excursion
8960            (set-buffer copy-buf)
8961            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8962              (gnus-request-accept-article
8963               to-newsgroup select-method (not articles) t))))
8964         ;; Crosspost the article.
8965         ((eq action 'crosspost)
8966          (let ((xref (message-tokenize-header
8967                       (mail-header-xref (gnus-summary-article-header article))
8968                       " ")))
8969            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8970                                   ":" (number-to-string article)))
8971            (unless xref
8972              (setq xref (list (system-name))))
8973            (setq new-xref
8974                  (concat
8975                   (mapconcat 'identity
8976                              (delete "Xref:" (delete new-xref xref))
8977                              " ")
8978                   " " new-xref))
8979            (save-excursion
8980              (set-buffer copy-buf)
8981              ;; First put the article in the destination group.
8982              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8983              (when (consp (setq art-group
8984                                 (gnus-request-accept-article
8985                                  to-newsgroup select-method (not articles))))
8986                (setq new-xref (concat new-xref " " (car art-group)
8987                                       ":"
8988                                       (number-to-string (cdr art-group))))
8989                ;; Now we have the new Xrefs header, so we insert
8990                ;; it and replace the new article.
8991                (nnheader-replace-header "Xref" new-xref)
8992                (gnus-request-replace-article
8993                 (cdr art-group) to-newsgroup (current-buffer))
8994                art-group))))))
8995       (cond
8996        ((not art-group)
8997         (gnus-message 1 "Couldn't %s article %s: %s"
8998                       (cadr (assq action names)) article
8999                       (nnheader-get-report (car to-method))))
9000        ((eq art-group 'junk)
9001         (when (eq action 'move)
9002           (gnus-summary-mark-article article gnus-canceled-mark)
9003           (gnus-message 4 "Deleted article %s" article)
9004           ;; run the delete hook
9005           (run-hook-with-args 'gnus-summary-article-delete-hook
9006                               action
9007                               (gnus-data-header
9008                                (assoc article (gnus-data-list nil)))
9009                               gnus-newsgroup-name nil
9010                               select-method)))
9011        (t
9012         (let* ((pto-group (gnus-group-prefixed-name
9013                            (car art-group) to-method))
9014                (entry
9015                 (gnus-gethash pto-group gnus-newsrc-hashtb))
9016                (info (nth 2 entry))
9017                (to-group (gnus-info-group info))
9018                to-marks)
9019           ;; Update the group that has been moved to.
9020           (when (and info
9021                      (memq action '(move copy)))
9022             (unless (member to-group to-groups)
9023               (push to-group to-groups))
9024
9025             (unless (memq article gnus-newsgroup-unreads)
9026               (push 'read to-marks)
9027               (gnus-info-set-read
9028                info (gnus-add-to-range (gnus-info-read info)
9029                                        (list (cdr art-group)))))
9030
9031             ;; See whether the article is to be put in the cache.
9032             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9033                              default-marks
9034                            no-expire-marks))
9035                   (to-article (cdr art-group)))
9036
9037               ;; Enter the article into the cache in the new group,
9038               ;; if that is required.
9039               (when gnus-use-cache
9040                 (gnus-cache-possibly-enter-article
9041                  to-group to-article
9042                  (let ((header (copy-sequence
9043                                 (gnus-summary-article-header article))))
9044                    (mail-header-set-number header to-article)
9045                    header)
9046                  (memq article gnus-newsgroup-marked)
9047                  (memq article gnus-newsgroup-dormant)
9048                  (memq article gnus-newsgroup-unreads)))
9049
9050               (when gnus-preserve-marks
9051                 ;; Copy any marks over to the new group.
9052                 (when (and (equal to-group gnus-newsgroup-name)
9053                            (not (memq article gnus-newsgroup-unreads)))
9054                   ;; Mark this article as read in this group.
9055                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9056                   (setcdr (gnus-active to-group) to-article)
9057                   (setcdr gnus-newsgroup-active to-article))
9058
9059                 (while marks
9060                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9061                     (when (memq article (symbol-value
9062                                          (intern (format "gnus-newsgroup-%s"
9063                                                          (caar marks)))))
9064                       (push (cdar marks) to-marks)
9065                       ;; If the other group is the same as this group,
9066                       ;; then we have to add the mark to the list.
9067                       (when (equal to-group gnus-newsgroup-name)
9068                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9069                              (cons to-article
9070                                    (symbol-value
9071                                     (intern (format "gnus-newsgroup-%s"
9072                                                     (caar marks)))))))
9073                       ;; Copy the marks to other group.
9074                       (gnus-add-marked-articles
9075                        to-group (cdar marks) (list to-article) info)))
9076                   (setq marks (cdr marks)))
9077
9078                 (gnus-request-set-mark
9079                  to-group (list (list (list to-article) 'add to-marks))))
9080
9081               (gnus-dribble-enter
9082                (concat "(gnus-group-set-info '"
9083                        (gnus-prin1-to-string (gnus-get-info to-group))
9084                        ")"))))
9085
9086           ;; Update the Xref header in this article to point to
9087           ;; the new crossposted article we have just created.
9088           (when (eq action 'crosspost)
9089             (save-excursion
9090               (set-buffer copy-buf)
9091               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9092               (nnheader-replace-header "Xref" new-xref)
9093               (gnus-request-replace-article
9094                article gnus-newsgroup-name (current-buffer))))
9095
9096           ;; run the move/copy/crosspost/respool hook
9097           (run-hook-with-args 'gnus-summary-article-move-hook 
9098                               action
9099                               (gnus-data-header 
9100                                (assoc article (gnus-data-list nil)))
9101                               gnus-newsgroup-name
9102                               to-newsgroup
9103                               select-method))
9104
9105         ;;;!!!Why is this necessary?
9106         (set-buffer gnus-summary-buffer)
9107         
9108         (gnus-summary-goto-subject article)
9109         (when (eq action 'move)
9110           (gnus-summary-mark-article article gnus-canceled-mark))))
9111       (gnus-summary-remove-process-mark article))
9112     ;; Re-activate all groups that have been moved to.
9113     (save-excursion
9114       (set-buffer gnus-group-buffer)
9115       (let ((gnus-group-marked to-groups))
9116         (gnus-group-get-new-news-this-group nil t)))
9117
9118     (gnus-kill-buffer copy-buf)
9119     (gnus-summary-position-point)
9120     (gnus-set-mode-line 'summary)))
9121
9122 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9123   "Move the current article to a different newsgroup.
9124 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9125 When called interactively, if TO-NEWSGROUP is nil, use the value of
9126 the variable `gnus-move-split-methods' for finding a default target
9127 newsgroup.
9128 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9129 re-spool using this method."
9130   (interactive "P")
9131   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9132
9133 (defun gnus-summary-crosspost-article (&optional n)
9134   "Crosspost the current article to some other group."
9135   (interactive "P")
9136   (gnus-summary-move-article n nil nil 'crosspost))
9137
9138 (defcustom gnus-summary-respool-default-method nil
9139   "Default method type for respooling an article.
9140 If nil, use to the current newsgroup method."
9141   :type 'symbol
9142   :group 'gnus-summary-mail)
9143
9144 (defcustom gnus-summary-display-while-building nil
9145   "If non-nil, show and update the summary buffer as it's being built.
9146 If the value is t, update the buffer after every line is inserted.  If
9147 the value is an integer (N), update the display every N lines."
9148   :group 'gnus-thread
9149   :type '(choice (const :tag "off" nil)
9150                  number
9151                  (const :tag "frequently" t)))
9152
9153 (defun gnus-summary-respool-article (&optional n method)
9154   "Respool the current article.
9155 The article will be squeezed through the mail spooling process again,
9156 which means that it will be put in some mail newsgroup or other
9157 depending on `nnmail-split-methods'.
9158 If N is a positive number, respool the N next articles.
9159 If N is a negative number, respool the N previous articles.
9160 If N is nil and any articles have been marked with the process mark,
9161 respool those articles instead.
9162
9163 Respooling can be done both from mail groups and \"real\" newsgroups.
9164 In the former case, the articles in question will be moved from the
9165 current group into whatever groups they are destined to.  In the
9166 latter case, they will be copied into the relevant groups."
9167   (interactive
9168    (list current-prefix-arg
9169          (let* ((methods (gnus-methods-using 'respool))
9170                 (methname
9171                  (symbol-name (or gnus-summary-respool-default-method
9172                                   (car (gnus-find-method-for-group
9173                                         gnus-newsgroup-name)))))
9174                 (method
9175                  (gnus-completing-read-with-default
9176                   methname "What backend do you want to use when respooling?"
9177                   methods nil t nil 'gnus-mail-method-history))
9178                 ms)
9179            (cond
9180             ((zerop (length (setq ms (gnus-servers-using-backend
9181                                       (intern method)))))
9182              (list (intern method) ""))
9183             ((= 1 (length ms))
9184              (car ms))
9185             (t
9186              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9187                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9188                            ms-alist))))))))
9189   (unless method
9190     (error "No method given for respooling"))
9191   (if (assoc (symbol-name
9192               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9193              (gnus-methods-using 'respool))
9194       (gnus-summary-move-article n nil method)
9195     (gnus-summary-copy-article n nil method)))
9196
9197 (defun gnus-summary-import-article (file &optional edit)
9198   "Import an arbitrary file into a mail newsgroup."
9199   (interactive "fImport file: \nP")
9200   (let ((group gnus-newsgroup-name)
9201         (now (current-time))
9202         atts lines group-art)
9203     (unless (gnus-check-backend-function 'request-accept-article group)
9204       (error "%s does not support article importing" group))
9205     (or (file-readable-p file)
9206         (not (file-regular-p file))
9207         (error "Can't read %s" file))
9208     (save-excursion
9209       (set-buffer (gnus-get-buffer-create " *import file*"))
9210       (erase-buffer)
9211       (nnheader-insert-file-contents file)
9212       (goto-char (point-min))
9213       (if (nnheader-article-p)
9214           (save-restriction
9215             (goto-char (point-min))
9216             (search-forward "\n\n" nil t)
9217             (narrow-to-region (point-min) (1- (point)))
9218             (goto-char (point-min))
9219             (unless (re-search-forward "^date:" nil t)
9220               (goto-char (point-max))
9221               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9222         ;; This doesn't look like an article, so we fudge some headers.
9223         (setq atts (file-attributes file)
9224               lines (count-lines (point-min) (point-max)))
9225         (insert "From: " (read-string "From: ") "\n"
9226                 "Subject: " (read-string "Subject: ") "\n"
9227                 "Date: " (message-make-date (nth 5 atts)) "\n"
9228                 "Message-ID: " (message-make-message-id) "\n"
9229                 "Lines: " (int-to-string lines) "\n"
9230                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9231       (setq group-art (gnus-request-accept-article group nil t))
9232       (kill-buffer (current-buffer)))
9233     (setq gnus-newsgroup-active (gnus-activate-group group))
9234     (forward-line 1)
9235     (gnus-summary-goto-article (cdr group-art) nil t)
9236     (when edit
9237       (gnus-summary-edit-article))))
9238
9239 (defun gnus-summary-create-article ()
9240   "Create an article in a mail newsgroup."
9241   (interactive)
9242   (let ((group gnus-newsgroup-name)
9243         (now (current-time))
9244         group-art)
9245     (unless (gnus-check-backend-function 'request-accept-article group)
9246       (error "%s does not support article importing" group))
9247     (save-excursion
9248       (set-buffer (gnus-get-buffer-create " *import file*"))
9249       (erase-buffer)
9250       (goto-char (point-min))
9251       ;; This doesn't look like an article, so we fudge some headers.
9252       (insert "From: " (read-string "From: ") "\n"
9253               "Subject: " (read-string "Subject: ") "\n"
9254               "Date: " (message-make-date now) "\n"
9255               "Message-ID: " (message-make-message-id) "\n")
9256       (setq group-art (gnus-request-accept-article group nil t))
9257       (kill-buffer (current-buffer)))
9258     (setq gnus-newsgroup-active (gnus-activate-group group))
9259     (forward-line 1)
9260     (gnus-summary-goto-article (cdr group-art) nil t)
9261     (gnus-summary-edit-article)))
9262
9263 (defun gnus-summary-article-posted-p ()
9264   "Say whether the current (mail) article is available from news as well.
9265 This will be the case if the article has both been mailed and posted."
9266   (interactive)
9267   (let ((id (mail-header-references (gnus-summary-article-header)))
9268         (gnus-override-method (car (gnus-refer-article-methods))))
9269     (if (gnus-request-head id "")
9270         (gnus-message 2 "The current message was found on %s"
9271                       gnus-override-method)
9272       (gnus-message 2 "The current message couldn't be found on %s"
9273                     gnus-override-method)
9274       nil)))
9275
9276 (defun gnus-summary-expire-articles (&optional now)
9277   "Expire all articles that are marked as expirable in the current group."
9278   (interactive)
9279   (when (and (not gnus-group-is-exiting-without-update-p)
9280              (gnus-check-backend-function
9281               'request-expire-articles gnus-newsgroup-name))
9282     ;; This backend supports expiry.
9283     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9284            (expirable (if total
9285                           (progn
9286                             ;; We need to update the info for
9287                             ;; this group for `gnus-list-of-read-articles'
9288                             ;; to give us the right answer.
9289                             (gnus-run-hooks 'gnus-exit-group-hook)
9290                             (gnus-summary-update-info)
9291                             (gnus-list-of-read-articles gnus-newsgroup-name))
9292                         (setq gnus-newsgroup-expirable
9293                               (sort gnus-newsgroup-expirable '<))))
9294            (expiry-wait (if now 'immediate
9295                           (gnus-group-find-parameter
9296                            gnus-newsgroup-name 'expiry-wait)))
9297            (nnmail-expiry-target
9298             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9299                 nnmail-expiry-target))
9300            es)
9301       (when expirable
9302         ;; There are expirable articles in this group, so we run them
9303         ;; through the expiry process.
9304         (gnus-message 6 "Expiring articles...")
9305         (unless (gnus-check-group gnus-newsgroup-name)
9306           (error "Can't open server for %s" gnus-newsgroup-name))
9307         ;; The list of articles that weren't expired is returned.
9308         (save-excursion
9309           (if expiry-wait
9310               (let ((nnmail-expiry-wait-function nil)
9311                     (nnmail-expiry-wait expiry-wait))
9312                 (setq es (gnus-request-expire-articles
9313                           expirable gnus-newsgroup-name)))
9314             (setq es (gnus-request-expire-articles
9315                       expirable gnus-newsgroup-name)))
9316           (unless total
9317             (setq gnus-newsgroup-expirable es))
9318           ;; We go through the old list of expirable, and mark all
9319           ;; really expired articles as nonexistent.
9320           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9321             (let ((gnus-use-cache nil))
9322               (dolist (article expirable)
9323                 (when (and (not (memq article es))
9324                            (gnus-data-find article))
9325                   (gnus-summary-mark-article article gnus-canceled-mark)
9326                   (run-hook-with-args 'gnus-summary-article-expire-hook
9327                                       'delete
9328                                       (gnus-data-header
9329                                        (assoc article (gnus-data-list nil)))
9330                                       gnus-newsgroup-name
9331                                       nil
9332                                       nil))))))
9333         (gnus-message 6 "Expiring articles...done")))))
9334
9335 (defun gnus-summary-expire-articles-now ()
9336   "Expunge all expirable articles in the current group.
9337 This means that *all* articles that are marked as expirable will be
9338 deleted forever, right now."
9339   (interactive)
9340   (or gnus-expert-user
9341       (gnus-yes-or-no-p
9342        "Are you really, really, really sure you want to delete all these messages? ")
9343       (error "Phew!"))
9344   (gnus-summary-expire-articles t))
9345
9346 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9347 (defun gnus-summary-delete-article (&optional n)
9348   "Delete the N next (mail) articles.
9349 This command actually deletes articles.  This is not a marking
9350 command.  The article will disappear forever from your life, never to
9351 return.
9352
9353 If N is negative, delete backwards.
9354 If N is nil and articles have been marked with the process mark,
9355 delete these instead.
9356
9357 If `gnus-novice-user' is non-nil you will be asked for
9358 confirmation before the articles are deleted."
9359   (interactive "P")
9360   (unless (gnus-check-backend-function 'request-expire-articles
9361                                        gnus-newsgroup-name)
9362     (error "The current newsgroup does not support article deletion"))
9363   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9364     (error "Couldn't open server"))
9365   ;; Compute the list of articles to delete.
9366   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9367         (nnmail-expiry-target 'delete)
9368         not-deleted)
9369     (if (and gnus-novice-user
9370              (not (gnus-yes-or-no-p
9371                    (format "Do you really want to delete %s forever? "
9372                            (if (> (length articles) 1)
9373                                (format "these %s articles" (length articles))
9374                              "this article")))))
9375         ()
9376       ;; Delete the articles.
9377       (setq not-deleted (gnus-request-expire-articles
9378                          articles gnus-newsgroup-name 'force))
9379       (while articles
9380         (gnus-summary-remove-process-mark (car articles))
9381         ;; The backend might not have been able to delete the article
9382         ;; after all.
9383         (unless (memq (car articles) not-deleted)
9384           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9385         (let* ((article (car articles))
9386                (id (mail-header-id (gnus-data-header 
9387                                     (assoc article (gnus-data-list nil))))))
9388           (run-hook-with-args 'gnus-summary-article-delete-hook
9389                               'delete id gnus-newsgroup-name nil
9390                               nil))
9391         (setq articles (cdr articles)))
9392       (when not-deleted
9393         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9394     (gnus-summary-position-point)
9395     (gnus-set-mode-line 'summary)
9396     not-deleted))
9397
9398 (defun gnus-summary-edit-article (&optional force)
9399   "Edit the current article.
9400 This will have permanent effect only in mail groups.
9401 If FORCE is non-nil, allow editing of articles even in read-only
9402 groups."
9403   (interactive "P")
9404   (save-excursion
9405     (set-buffer gnus-summary-buffer)
9406     (let ((mail-parse-charset gnus-newsgroup-charset)
9407           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9408       (gnus-set-global-variables)
9409       (when (and (not force)
9410                  (gnus-group-read-only-p))
9411         (error "The current newsgroup does not support article editing"))
9412       (gnus-summary-show-article t)
9413       (gnus-article-edit-article
9414        'ignore
9415        `(lambda (no-highlight)
9416           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9417                 (message-options message-options)
9418                 (message-options-set-recipient)
9419                 (mail-parse-ignored-charsets
9420                  ',gnus-newsgroup-ignored-charsets))
9421             (gnus-summary-edit-article-done
9422              ,(or (mail-header-references gnus-current-headers) "")
9423              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9424
9425 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9426
9427 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9428                                                  no-highlight)
9429   "Make edits to the current article permanent."
9430   (interactive)
9431   (save-excursion
9432     ;; The buffer restriction contains the entire article if it exists.
9433     (when (article-goto-body)
9434       (let ((lines (count-lines (point) (point-max)))
9435             (length (- (point-max) (point)))
9436             (case-fold-search t)
9437             (body (copy-marker (point))))
9438         (goto-char (point-min))
9439         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9440           (delete-region (match-beginning 1) (match-end 1))
9441           (insert (number-to-string length)))
9442         (goto-char (point-min))
9443         (when (re-search-forward
9444                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9445           (delete-region (match-beginning 1) (match-end 1))
9446           (insert (number-to-string length)))
9447         (goto-char (point-min))
9448         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9449           (delete-region (match-beginning 1) (match-end 1))
9450           (insert (number-to-string lines))))))
9451   ;; Replace the article.
9452   (let ((buf (current-buffer)))
9453     (with-temp-buffer
9454       (insert-buffer-substring buf)
9455
9456       (if (and (not read-only)
9457                (not (gnus-request-replace-article
9458                      (cdr gnus-article-current) (car gnus-article-current)
9459                      (current-buffer) t)))
9460           (error "Couldn't replace article")
9461         ;; Update the summary buffer.
9462         (if (and references
9463                  (equal (message-tokenize-header references " ")
9464                         (message-tokenize-header
9465                          (or (message-fetch-field "references") "") " ")))
9466             ;; We only have to update this line.
9467             (save-excursion
9468               (save-restriction
9469                 (message-narrow-to-head)
9470                 (let ((head (buffer-string))
9471                       header)
9472                   (with-temp-buffer
9473                     (insert (format "211 %d Article retrieved.\n"
9474                                     (cdr gnus-article-current)))
9475                     (insert head)
9476                     (insert ".\n")
9477                     (let ((nntp-server-buffer (current-buffer)))
9478                       (setq header (car (gnus-get-newsgroup-headers
9479                                          nil t))))
9480                     (save-excursion
9481                       (set-buffer gnus-summary-buffer)
9482                       (gnus-data-set-header
9483                        (gnus-data-find (cdr gnus-article-current))
9484                        header)
9485                       (gnus-summary-update-article-line
9486                        (cdr gnus-article-current) header)
9487                       (if (gnus-summary-goto-subject
9488                            (cdr gnus-article-current) nil t)
9489                           (gnus-summary-update-secondary-mark
9490                            (cdr gnus-article-current))))))))
9491           ;; Update threads.
9492           (set-buffer (or buffer gnus-summary-buffer))
9493           (gnus-summary-update-article (cdr gnus-article-current))
9494           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9495               (gnus-summary-update-secondary-mark
9496                (cdr gnus-article-current))))
9497         ;; Prettify the article buffer again.
9498         (unless no-highlight
9499           (save-excursion
9500             (set-buffer gnus-article-buffer)
9501             ;;;!!! Fix this -- article should be rehighlighted.
9502             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9503             (set-buffer gnus-original-article-buffer)
9504             (gnus-request-article
9505              (cdr gnus-article-current)
9506              (car gnus-article-current) (current-buffer))))
9507         ;; Prettify the summary buffer line.
9508         (when (gnus-visual-p 'summary-highlight 'highlight)
9509           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9510
9511 (defun gnus-summary-edit-wash (key)
9512   "Perform editing command KEY in the article buffer."
9513   (interactive
9514    (list
9515     (progn
9516       (message "%s" (concat (this-command-keys) "- "))
9517       (read-char))))
9518   (message "")
9519   (gnus-summary-edit-article)
9520   (execute-kbd-macro (concat (this-command-keys) key))
9521   (gnus-article-edit-done))
9522
9523 ;;; Respooling
9524
9525 (defun gnus-summary-respool-query (&optional silent trace)
9526   "Query where the respool algorithm would put this article."
9527   (interactive)
9528   (let (gnus-mark-article-hook)
9529     (gnus-summary-select-article)
9530     (save-excursion
9531       (set-buffer gnus-original-article-buffer)
9532       (save-restriction
9533         (message-narrow-to-head)
9534         (let ((groups (nnmail-article-group 'identity trace)))
9535           (unless silent
9536             (if groups
9537                 (message "This message would go to %s"
9538                          (mapconcat 'car groups ", "))
9539               (message "This message would go to no groups"))
9540             groups))))))
9541
9542 (defun gnus-summary-respool-trace ()
9543   "Trace where the respool algorithm would put this article.
9544 Display a buffer showing all fancy splitting patterns which matched."
9545   (interactive)
9546   (gnus-summary-respool-query nil t))
9547
9548 ;; Summary marking commands.
9549
9550 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9551   "Mark articles which has the same subject as read, and then select the next.
9552 If UNMARK is positive, remove any kind of mark.
9553 If UNMARK is negative, tick articles."
9554   (interactive "P")
9555   (when unmark
9556     (setq unmark (prefix-numeric-value unmark)))
9557   (let ((count
9558          (gnus-summary-mark-same-subject
9559           (gnus-summary-article-subject) unmark)))
9560     ;; Select next unread article.  If auto-select-same mode, should
9561     ;; select the first unread article.
9562     (gnus-summary-next-article t (and gnus-auto-select-same
9563                                       (gnus-summary-article-subject)))
9564     (gnus-message 7 "%d article%s marked as %s"
9565                   count (if (= count 1) " is" "s are")
9566                   (if unmark "unread" "read"))))
9567
9568 (defun gnus-summary-kill-same-subject (&optional unmark)
9569   "Mark articles which has the same subject as read.
9570 If UNMARK is positive, remove any kind of mark.
9571 If UNMARK is negative, tick articles."
9572   (interactive "P")
9573   (when unmark
9574     (setq unmark (prefix-numeric-value unmark)))
9575   (let ((count
9576          (gnus-summary-mark-same-subject
9577           (gnus-summary-article-subject) unmark)))
9578     ;; If marked as read, go to next unread subject.
9579     (when (null unmark)
9580       ;; Go to next unread subject.
9581       (gnus-summary-next-subject 1 t))
9582     (gnus-message 7 "%d articles are marked as %s"
9583                   count (if unmark "unread" "read"))))
9584
9585 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9586   "Mark articles with same SUBJECT as read, and return marked number.
9587 If optional argument UNMARK is positive, remove any kinds of marks.
9588 If optional argument UNMARK is negative, mark articles as unread instead."
9589   (let ((count 1))
9590     (save-excursion
9591       (cond
9592        ((null unmark)                   ; Mark as read.
9593         (while (and
9594                 (progn
9595                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9596                   (gnus-summary-show-thread) t)
9597                 (gnus-summary-find-subject subject))
9598           (setq count (1+ count))))
9599        ((> unmark 0)                    ; Tick.
9600         (while (and
9601                 (progn
9602                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9603                   (gnus-summary-show-thread) t)
9604                 (gnus-summary-find-subject subject))
9605           (setq count (1+ count))))
9606        (t                               ; Mark as unread.
9607         (while (and
9608                 (progn
9609                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9610                   (gnus-summary-show-thread) t)
9611                 (gnus-summary-find-subject subject))
9612           (setq count (1+ count)))))
9613       (gnus-set-mode-line 'summary)
9614       ;; Return the number of marked articles.
9615       count)))
9616
9617 (defun gnus-summary-mark-as-processable (n &optional unmark)
9618   "Set the process mark on the next N articles.
9619 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9620 the process mark instead.  The difference between N and the actual
9621 number of articles marked is returned."
9622   (interactive "P")
9623   (if (and (null n) (gnus-region-active-p))
9624       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9625     (setq n (prefix-numeric-value n))
9626     (let ((backward (< n 0))
9627           (n (abs n)))
9628       (while (and
9629               (> n 0)
9630               (if unmark
9631                   (gnus-summary-remove-process-mark
9632                    (gnus-summary-article-number))
9633                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9634               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9635         (setq n (1- n)))
9636       (when (/= 0 n)
9637         (gnus-message 7 "No more articles"))
9638       (gnus-summary-recenter)
9639       (gnus-summary-position-point)
9640       n)))
9641
9642 (defun gnus-summary-unmark-as-processable (n)
9643   "Remove the process mark from the next N articles.
9644 If N is negative, unmark backward instead.  The difference between N and
9645 the actual number of articles unmarked is returned."
9646   (interactive "P")
9647   (gnus-summary-mark-as-processable n t))
9648
9649 (defun gnus-summary-unmark-all-processable ()
9650   "Remove the process mark from all articles."
9651   (interactive)
9652   (save-excursion
9653     (while gnus-newsgroup-processable
9654       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9655   (gnus-summary-position-point))
9656
9657 (defun gnus-summary-add-mark (article type)
9658   "Mark ARTICLE with a mark of TYPE."
9659   (let ((vtype (car (assq type gnus-article-mark-lists)))
9660         var)
9661     (if (not vtype)
9662         (error "No such mark type: %s" type)
9663       (setq var (intern (format "gnus-newsgroup-%s" type)))
9664       (set var (cons article (symbol-value var)))
9665       (if (memq type '(processable cached replied forwarded recent saved))
9666           (gnus-summary-update-secondary-mark article)
9667         ;;; !!! This is bogus.  We should find out what primary
9668         ;;; !!! mark we want to set.
9669         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9670
9671 (defun gnus-summary-mark-as-expirable (n)
9672   "Mark N articles forward as expirable.
9673 If N is negative, mark backward instead.  The difference between N and
9674 the actual number of articles marked is returned."
9675   (interactive "p")
9676   (gnus-summary-mark-forward n gnus-expirable-mark))
9677
9678 (defun gnus-summary-mark-as-spam (n)
9679   "Mark N articles forward as spam.
9680 If N is negative, mark backward instead.  The difference between N and
9681 the actual number of articles marked is returned."
9682   (interactive "p")
9683   (gnus-summary-mark-forward n gnus-spam-mark))
9684
9685 (defun gnus-summary-mark-article-as-replied (article)
9686   "Mark ARTICLE as replied to and update the summary line.
9687 ARTICLE can also be a list of articles."
9688   (interactive (list (gnus-summary-article-number)))
9689   (let ((articles (if (listp article) article (list article))))
9690     (dolist (article articles)
9691       (unless (numberp article)
9692         (error "%s is not a number" article))
9693       (push article gnus-newsgroup-replied)
9694       (let ((buffer-read-only nil))
9695         (when (gnus-summary-goto-subject article nil t)
9696           (gnus-summary-update-secondary-mark article))))))
9697
9698 (defun gnus-summary-mark-article-as-forwarded (article)
9699   "Mark ARTICLE as forwarded and update the summary line.
9700 ARTICLE can also be a list of articles."
9701   (let ((articles (if (listp article) article (list article))))
9702     (dolist (article articles)
9703       (push article gnus-newsgroup-forwarded)
9704       (let ((buffer-read-only nil))
9705         (when (gnus-summary-goto-subject article nil t)
9706           (gnus-summary-update-secondary-mark article))))))
9707
9708 (defun gnus-summary-set-bookmark (article)
9709   "Set a bookmark in current article."
9710   (interactive (list (gnus-summary-article-number)))
9711   (when (or (not (get-buffer gnus-article-buffer))
9712             (not gnus-current-article)
9713             (not gnus-article-current)
9714             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9715     (error "No current article selected"))
9716   ;; Remove old bookmark, if one exists.
9717   (gnus-pull article gnus-newsgroup-bookmarks)
9718   ;; Set the new bookmark, which is on the form
9719   ;; (article-number . line-number-in-body).
9720   (push
9721    (cons article
9722          (save-excursion
9723            (set-buffer gnus-article-buffer)
9724            (count-lines
9725             (min (point)
9726                  (save-excursion
9727                    (article-goto-body)
9728                    (point)))
9729             (point))))
9730    gnus-newsgroup-bookmarks)
9731   (gnus-message 6 "A bookmark has been added to the current article."))
9732
9733 (defun gnus-summary-remove-bookmark (article)
9734   "Remove the bookmark from the current article."
9735   (interactive (list (gnus-summary-article-number)))
9736   ;; Remove old bookmark, if one exists.
9737   (if (not (assq article gnus-newsgroup-bookmarks))
9738       (gnus-message 6 "No bookmark in current article.")
9739     (gnus-pull article gnus-newsgroup-bookmarks)
9740     (gnus-message 6 "Removed bookmark.")))
9741
9742 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9743 (defun gnus-summary-mark-as-dormant (n)
9744   "Mark N articles forward as dormant.
9745 If N is negative, mark backward instead.  The difference between N and
9746 the actual number of articles marked is returned."
9747   (interactive "p")
9748   (gnus-summary-mark-forward n gnus-dormant-mark))
9749
9750 (defun gnus-summary-set-process-mark (article)
9751   "Set the process mark on ARTICLE and update the summary line."
9752   (setq gnus-newsgroup-processable
9753         (cons article
9754               (delq article gnus-newsgroup-processable)))
9755   (when (gnus-summary-goto-subject article)
9756     (gnus-summary-show-thread)
9757     (gnus-summary-goto-subject article)
9758     (gnus-summary-update-secondary-mark article)))
9759
9760 (defun gnus-summary-remove-process-mark (article)
9761   "Remove the process mark from ARTICLE and update the summary line."
9762   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9763   (when (gnus-summary-goto-subject article)
9764     (gnus-summary-show-thread)
9765     (gnus-summary-goto-subject article)
9766     (gnus-summary-update-secondary-mark article)))
9767
9768 (defun gnus-summary-set-saved-mark (article)
9769   "Set the process mark on ARTICLE and update the summary line."
9770   (push article gnus-newsgroup-saved)
9771   (when (gnus-summary-goto-subject article)
9772     (gnus-summary-update-secondary-mark article)))
9773
9774 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9775   "Mark N articles as read forwards.
9776 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9777 The difference between N and the actual number of articles marked is
9778 returned.
9779 If NO-EXPIRE, auto-expiry will be inhibited."
9780   (interactive "p")
9781   (gnus-summary-show-thread)
9782   (let ((backward (< n 0))
9783         (gnus-summary-goto-unread
9784          (and gnus-summary-goto-unread
9785               (not (eq gnus-summary-goto-unread 'never))
9786               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9787                                     gnus-ticked-mark gnus-dormant-mark)))))
9788         (n (abs n))
9789         (mark (or mark gnus-del-mark)))
9790     (while (and (> n 0)
9791                 (gnus-summary-mark-article nil mark no-expire)
9792                 (zerop (gnus-summary-next-subject
9793                         (if backward -1 1)
9794                         (and gnus-summary-goto-unread
9795                              (not (eq gnus-summary-goto-unread 'never)))
9796                         t)))
9797       (setq n (1- n)))
9798     (when (/= 0 n)
9799       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9800     (gnus-summary-recenter)
9801     (gnus-summary-position-point)
9802     (gnus-set-mode-line 'summary)
9803     n))
9804
9805 (defun gnus-summary-mark-article-as-read (mark)
9806   "Mark the current article quickly as read with MARK."
9807   (let ((article (gnus-summary-article-number)))
9808     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9809     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9810     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9811     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9812     (push (cons article mark) gnus-newsgroup-reads)
9813     ;; Possibly remove from cache, if that is used.
9814     (when gnus-use-cache
9815       (gnus-cache-enter-remove-article article))
9816     ;; Allow the backend to change the mark.
9817     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9818     ;; Check for auto-expiry.
9819     (when (and gnus-newsgroup-auto-expire
9820                (memq mark gnus-auto-expirable-marks))
9821       (setq mark gnus-expirable-mark)
9822       ;; Let the backend know about the mark change.
9823       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9824       (push article gnus-newsgroup-expirable))
9825     ;; Set the mark in the buffer.
9826     (gnus-summary-update-mark mark 'unread)
9827     t))
9828
9829 (defun gnus-summary-mark-article-as-unread (mark)
9830   "Mark the current article quickly as unread with MARK."
9831   (let* ((article (gnus-summary-article-number))
9832          (old-mark (gnus-summary-article-mark article)))
9833     ;; Allow the backend to change the mark.
9834     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9835     (if (eq mark old-mark)
9836         t
9837       (if (<= article 0)
9838           (progn
9839             (gnus-error 1 "Can't mark negative article numbers")
9840             nil)
9841         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9842         (setq gnus-newsgroup-spam-marked
9843               (delq article gnus-newsgroup-spam-marked))
9844         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9845         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9846         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9847         (cond ((= mark gnus-ticked-mark)
9848                (setq gnus-newsgroup-marked
9849                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9850                                               article)))
9851               ((= mark gnus-spam-mark)
9852                (setq gnus-newsgroup-spam-marked
9853                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9854                                               article)))
9855               ((= mark gnus-dormant-mark)
9856                (setq gnus-newsgroup-dormant
9857                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9858                                               article)))
9859               (t
9860                (setq gnus-newsgroup-unreads
9861                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9862                                               article))))
9863         (gnus-pull article gnus-newsgroup-reads)
9864
9865         ;; See whether the article is to be put in the cache.
9866         (and gnus-use-cache
9867              (vectorp (gnus-summary-article-header article))
9868              (save-excursion
9869                (gnus-cache-possibly-enter-article
9870                 gnus-newsgroup-name article
9871                 (gnus-summary-article-header article)
9872                 (= mark gnus-ticked-mark)
9873                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9874
9875         ;; Fix the mark.
9876         (gnus-summary-update-mark mark 'unread)
9877         t))))
9878
9879 (defun gnus-summary-mark-article (&optional article mark no-expire)
9880   "Mark ARTICLE with MARK.  MARK can be any character.
9881 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9882 `??' (dormant) and `?E' (expirable).
9883 If MARK is nil, then the default character `?r' is used.
9884 If ARTICLE is nil, then the article on the current line will be
9885 marked.
9886 If NO-EXPIRE, auto-expiry will be inhibited."
9887   ;; The mark might be a string.
9888   (when (stringp mark)
9889     (setq mark (aref mark 0)))
9890   ;; If no mark is given, then we check auto-expiring.
9891   (when (null mark)
9892     (setq mark gnus-del-mark))
9893   (when (and (not no-expire)
9894              gnus-newsgroup-auto-expire
9895              (memq mark gnus-auto-expirable-marks))
9896     (setq mark gnus-expirable-mark))
9897   (let ((article (or article (gnus-summary-article-number)))
9898         (old-mark (gnus-summary-article-mark article)))
9899     ;; Allow the backend to change the mark.
9900     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9901     (if (eq mark old-mark)
9902         t
9903       (unless article
9904         (error "No article on current line"))
9905       (if (not (if (or (= mark gnus-unread-mark)
9906                        (= mark gnus-ticked-mark)
9907                        (= mark gnus-spam-mark)
9908                        (= mark gnus-dormant-mark))
9909                    (gnus-mark-article-as-unread article mark)
9910                  (gnus-mark-article-as-read article mark)))
9911           t
9912         ;; See whether the article is to be put in the cache.
9913         (and gnus-use-cache
9914              (not (= mark gnus-canceled-mark))
9915              (vectorp (gnus-summary-article-header article))
9916              (save-excursion
9917                (gnus-cache-possibly-enter-article
9918                 gnus-newsgroup-name article
9919                 (gnus-summary-article-header article)
9920                 (= mark gnus-ticked-mark)
9921                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9922
9923         (when (gnus-summary-goto-subject article nil t)
9924           (let ((buffer-read-only nil))
9925             (gnus-summary-show-thread)
9926             ;; Fix the mark.
9927             (gnus-summary-update-mark mark 'unread)
9928             t))))))
9929
9930 (defun gnus-summary-update-secondary-mark (article)
9931   "Update the secondary (read, process, cache) mark."
9932   (gnus-summary-update-mark
9933    (cond ((memq article gnus-newsgroup-processable)
9934           gnus-process-mark)
9935          ((memq article gnus-newsgroup-cached)
9936           gnus-cached-mark)
9937          ((memq article gnus-newsgroup-replied)
9938           gnus-replied-mark)
9939          ((memq article gnus-newsgroup-forwarded)
9940           gnus-forwarded-mark)
9941          ((memq article gnus-newsgroup-saved)
9942           gnus-saved-mark)
9943          ((memq article gnus-newsgroup-recent)
9944           gnus-recent-mark)
9945          ((memq article gnus-newsgroup-unseen)
9946           gnus-unseen-mark)
9947          (t gnus-no-mark))
9948    'replied)
9949   (when (gnus-visual-p 'summary-highlight 'highlight)
9950     (gnus-run-hooks 'gnus-summary-update-hook))
9951   t)
9952
9953 (defun gnus-summary-update-download-mark (article)
9954   "Update the download mark."
9955   (gnus-summary-update-mark
9956    (cond ((memq article gnus-newsgroup-undownloaded) 
9957           gnus-undownloaded-mark)
9958          (gnus-newsgroup-agentized
9959           gnus-downloaded-mark)
9960          (t
9961           gnus-no-mark))
9962    'download)
9963   (gnus-summary-update-line t)
9964   t)
9965
9966 (defun gnus-summary-update-mark (mark type)
9967   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9968         (buffer-read-only nil))
9969     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9970     (when forward
9971       (when (looking-at "\r")
9972         (incf forward))
9973       (when (<= (+ forward (point)) (point-max))
9974         ;; Go to the right position on the line.
9975         (goto-char (+ forward (point)))
9976         ;; Replace the old mark with the new mark.
9977         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9978         ;; Optionally update the marks by some user rule.
9979         (when (eq type 'unread)
9980           (gnus-data-set-mark
9981            (gnus-data-find (gnus-summary-article-number)) mark)
9982           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9983
9984 (defun gnus-mark-article-as-read (article &optional mark)
9985   "Enter ARTICLE in the pertinent lists and remove it from others."
9986   ;; Make the article expirable.
9987   (let ((mark (or mark gnus-del-mark)))
9988     (setq gnus-newsgroup-expirable
9989           (if (= mark gnus-expirable-mark)
9990               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9991             (delq article gnus-newsgroup-expirable)))
9992     ;; Remove from unread and marked lists.
9993     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9994     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9995     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9996     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9997     (push (cons article mark) gnus-newsgroup-reads)
9998     ;; Possibly remove from cache, if that is used.
9999     (when gnus-use-cache
10000       (gnus-cache-enter-remove-article article))
10001     t))
10002
10003 (defun gnus-mark-article-as-unread (article &optional mark)
10004   "Enter ARTICLE in the pertinent lists and remove it from others."
10005   (let ((mark (or mark gnus-ticked-mark)))
10006     (if (<= article 0)
10007         (progn
10008           (gnus-error 1 "Can't mark negative article numbers")
10009           nil)
10010       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10011             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10012             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10013             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10014             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10015
10016       ;; Unsuppress duplicates?
10017       (when gnus-suppress-duplicates
10018         (gnus-dup-unsuppress-article article))
10019
10020       (cond ((= mark gnus-ticked-mark)
10021              (setq gnus-newsgroup-marked
10022                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10023             ((= mark gnus-spam-mark)
10024              (setq gnus-newsgroup-spam-marked
10025                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10026                                             article)))
10027             ((= mark gnus-dormant-mark)
10028              (setq gnus-newsgroup-dormant
10029                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10030             (t
10031              (setq gnus-newsgroup-unreads
10032                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10033       (gnus-pull article gnus-newsgroup-reads)
10034       t)))
10035
10036 (defalias 'gnus-summary-mark-as-unread-forward
10037   'gnus-summary-tick-article-forward)
10038 (make-obsolete 'gnus-summary-mark-as-unread-forward
10039                'gnus-summary-tick-article-forward)
10040 (defun gnus-summary-tick-article-forward (n)
10041   "Tick N articles forwards.
10042 If N is negative, tick backwards instead.
10043 The difference between N and the number of articles ticked is returned."
10044   (interactive "p")
10045   (gnus-summary-mark-forward n gnus-ticked-mark))
10046
10047 (defalias 'gnus-summary-mark-as-unread-backward
10048   'gnus-summary-tick-article-backward)
10049 (make-obsolete 'gnus-summary-mark-as-unread-backward
10050                'gnus-summary-tick-article-backward)
10051 (defun gnus-summary-tick-article-backward (n)
10052   "Tick N articles backwards.
10053 The difference between N and the number of articles ticked is returned."
10054   (interactive "p")
10055   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10056
10057 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10058 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10059 (defun gnus-summary-tick-article (&optional article clear-mark)
10060   "Mark current article as unread.
10061 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10062 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10063   (interactive)
10064   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10065                                        gnus-ticked-mark)))
10066
10067 (defun gnus-summary-mark-as-read-forward (n)
10068   "Mark N articles as read forwards.
10069 If N is negative, mark backwards instead.
10070 The difference between N and the actual number of articles marked is
10071 returned."
10072   (interactive "p")
10073   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10074
10075 (defun gnus-summary-mark-as-read-backward (n)
10076   "Mark the N articles as read backwards.
10077 The difference between N and the actual number of articles marked is
10078 returned."
10079   (interactive "p")
10080   (gnus-summary-mark-forward
10081    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10082
10083 (defun gnus-summary-mark-as-read (&optional article mark)
10084   "Mark current article as read.
10085 ARTICLE specifies the article to be marked as read.
10086 MARK specifies a string to be inserted at the beginning of the line."
10087   (gnus-summary-mark-article article mark))
10088
10089 (defun gnus-summary-clear-mark-forward (n)
10090   "Clear marks from N articles forward.
10091 If N is negative, clear backward instead.
10092 The difference between N and the number of marks cleared is returned."
10093   (interactive "p")
10094   (gnus-summary-mark-forward n gnus-unread-mark))
10095
10096 (defun gnus-summary-clear-mark-backward (n)
10097   "Clear marks from N articles backward.
10098 The difference between N and the number of marks cleared is returned."
10099   (interactive "p")
10100   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10101
10102 (defun gnus-summary-mark-unread-as-read ()
10103   "Intended to be used by `gnus-summary-mark-article-hook'."
10104   (when (memq gnus-current-article gnus-newsgroup-unreads)
10105     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10106
10107 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10108   "Intended to be used by `gnus-summary-mark-article-hook'."
10109   (let ((mark (gnus-summary-article-mark)))
10110     (when (or (gnus-unread-mark-p mark)
10111               (gnus-read-mark-p mark))
10112       (gnus-summary-mark-article gnus-current-article
10113                                  (or new-mark gnus-read-mark)))))
10114
10115 (defun gnus-summary-mark-unread-as-ticked ()
10116   "Intended to be used by `gnus-summary-mark-article-hook'."
10117   (when (memq gnus-current-article gnus-newsgroup-unreads)
10118     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10119
10120 (defun gnus-summary-mark-region-as-read (point mark all)
10121   "Mark all unread articles between point and mark as read.
10122 If given a prefix, mark all articles between point and mark as read,
10123 even ticked and dormant ones."
10124   (interactive "r\nP")
10125   (save-excursion
10126     (let (article)
10127       (goto-char point)
10128       (beginning-of-line)
10129       (while (and
10130               (< (point) mark)
10131               (progn
10132                 (when (or all
10133                           (memq (setq article (gnus-summary-article-number))
10134                                 gnus-newsgroup-unreads))
10135                   (gnus-summary-mark-article article gnus-del-mark))
10136                 t)
10137               (gnus-summary-find-next))))))
10138
10139 (defun gnus-summary-mark-below (score mark)
10140   "Mark articles with score less than SCORE with MARK."
10141   (interactive "P\ncMark: ")
10142   (setq score (if score
10143                   (prefix-numeric-value score)
10144                 (or gnus-summary-default-score 0)))
10145   (save-excursion
10146     (set-buffer gnus-summary-buffer)
10147     (goto-char (point-min))
10148     (while
10149         (progn
10150           (and (< (gnus-summary-article-score) score)
10151                (gnus-summary-mark-article nil mark))
10152           (gnus-summary-find-next)))))
10153
10154 (defun gnus-summary-kill-below (&optional score)
10155   "Mark articles with score below SCORE as read."
10156   (interactive "P")
10157   (gnus-summary-mark-below score gnus-killed-mark))
10158
10159 (defun gnus-summary-clear-above (&optional score)
10160   "Clear all marks from articles with score above SCORE."
10161   (interactive "P")
10162   (gnus-summary-mark-above score gnus-unread-mark))
10163
10164 (defun gnus-summary-tick-above (&optional score)
10165   "Tick all articles with score above SCORE."
10166   (interactive "P")
10167   (gnus-summary-mark-above score gnus-ticked-mark))
10168
10169 (defun gnus-summary-mark-above (score mark)
10170   "Mark articles with score over SCORE with MARK."
10171   (interactive "P\ncMark: ")
10172   (setq score (if score
10173                   (prefix-numeric-value score)
10174                 (or gnus-summary-default-score 0)))
10175   (save-excursion
10176     (set-buffer gnus-summary-buffer)
10177     (goto-char (point-min))
10178     (while (and (progn
10179                   (when (> (gnus-summary-article-score) score)
10180                     (gnus-summary-mark-article nil mark))
10181                   t)
10182                 (gnus-summary-find-next)))))
10183
10184 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10185 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10186 (defun gnus-summary-limit-include-expunged (&optional no-error)
10187   "Display all the hidden articles that were expunged for low scores."
10188   (interactive)
10189   (let ((buffer-read-only nil))
10190     (let ((scored gnus-newsgroup-scored)
10191           headers h)
10192       (while scored
10193         (unless (gnus-summary-article-header (caar scored))
10194           (and (setq h (gnus-number-to-header (caar scored)))
10195                (< (cdar scored) gnus-summary-expunge-below)
10196                (push h headers)))
10197         (setq scored (cdr scored)))
10198       (if (not headers)
10199           (when (not no-error)
10200             (error "No expunged articles hidden"))
10201         (goto-char (point-min))
10202         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10203         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10204         (mapcar (lambda (x) (push (mail-header-number x)
10205                                   gnus-newsgroup-limit))
10206                 headers)
10207         (gnus-summary-prepare-unthreaded (nreverse headers))
10208         (goto-char (point-min))
10209         (gnus-summary-position-point)
10210         t))))
10211
10212 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10213   "Mark all unread articles in this newsgroup as read.
10214 If prefix argument ALL is non-nil, ticked and dormant articles will
10215 also be marked as read.
10216 If QUIETLY is non-nil, no questions will be asked.
10217 If TO-HERE is non-nil, it should be a point in the buffer.  All
10218 articles before (after, if REVERSE is set) this point will be marked as read.
10219 Note that this function will only catch up the unread article
10220 in the current summary buffer limitation.
10221 The number of articles marked as read is returned."
10222   (interactive "P")
10223   (prog1
10224       (save-excursion
10225         (when (or quietly
10226                   (not gnus-interactive-catchup) ;Without confirmation?
10227                   gnus-expert-user
10228                   (gnus-y-or-n-p
10229                    (if all
10230                        "Mark absolutely all articles as read? "
10231                      "Mark all unread articles as read? ")))
10232           (if (and not-mark
10233                    (not gnus-newsgroup-adaptive)
10234                    (not gnus-newsgroup-auto-expire)
10235                    (not gnus-suppress-duplicates)
10236                    (or (not gnus-use-cache)
10237                        (eq gnus-use-cache 'passive)))
10238               (progn
10239                 (when all
10240                   (setq gnus-newsgroup-marked nil
10241                         gnus-newsgroup-spam-marked nil
10242                         gnus-newsgroup-dormant nil))
10243                 (setq gnus-newsgroup-unreads
10244                       (gnus-sorted-nunion
10245                        (gnus-intersection gnus-newsgroup-unreads
10246                                           gnus-newsgroup-downloadable)
10247                        gnus-newsgroup-unfetched)))
10248             ;; We actually mark all articles as canceled, which we
10249             ;; have to do when using auto-expiry or adaptive scoring.
10250             (gnus-summary-show-all-threads)
10251             (if (and to-here reverse)
10252                 (progn
10253                   (goto-char to-here)
10254                   (gnus-summary-mark-read-and-unread-as-read gnus-catchup-mark)
10255                   (while (gnus-summary-find-next (not all))
10256                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10257               (when (gnus-summary-first-subject (not all))
10258                 (while (and
10259                         (if to-here (< (point) to-here) t)
10260                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10261                         (gnus-summary-find-next (not all))))))
10262             (gnus-set-mode-line 'summary))
10263           t))
10264     (gnus-summary-position-point)))
10265
10266 (defun gnus-summary-catchup-to-here (&optional all)
10267   "Mark all unticked articles before the current one as read.
10268 If ALL is non-nil, also mark ticked and dormant articles as read."
10269   (interactive "P")
10270   (save-excursion
10271     (gnus-save-hidden-threads
10272       (let ((beg (point)))
10273         ;; We check that there are unread articles.
10274         (when (or all (gnus-summary-find-prev))
10275           (gnus-summary-catchup all t beg)))))
10276   (gnus-summary-position-point))
10277
10278 (defun gnus-summary-catchup-from-here (&optional all)
10279   "Mark all unticked articles after (and including) the current one as read.
10280 If ALL is non-nil, also mark ticked and dormant articles as read."
10281   (interactive "P")
10282   (save-excursion
10283     (gnus-save-hidden-threads
10284       (let ((beg (point)))
10285         ;; We check that there are unread articles.
10286         (when (or all (gnus-summary-find-next))
10287           (gnus-summary-catchup all t beg nil t)))))
10288   (gnus-summary-position-point))
10289
10290 (defun gnus-summary-catchup-all (&optional quietly)
10291   "Mark all articles in this newsgroup as read.
10292 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10293 instead, which marks only unread articles as read."
10294   (interactive "P")
10295   (gnus-summary-catchup t quietly))
10296
10297 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10298   "Mark all unread articles in this group as read, then exit.
10299 If prefix argument ALL is non-nil, all articles are marked as read.
10300 If QUIETLY is non-nil, no questions will be asked."
10301   (interactive "P")
10302   (when (gnus-summary-catchup all quietly nil 'fast)
10303     ;; Select next newsgroup or exit.
10304     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10305              (eq gnus-auto-select-next 'quietly))
10306         (gnus-summary-next-group nil)
10307       (gnus-summary-exit))))
10308
10309 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10310   "Mark all articles in this newsgroup as read, and then exit.
10311 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10312 instead, which marks only unread articles as read."
10313   (interactive "P")
10314   (gnus-summary-catchup-and-exit t quietly))
10315
10316 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10317   "Mark all articles in this group as read and select the next group.
10318 If given a prefix, mark all articles, unread as well as ticked, as
10319 read."
10320   (interactive "P")
10321   (save-excursion
10322     (gnus-summary-catchup all))
10323   (gnus-summary-next-group))
10324
10325 ;;;
10326 ;;; with article
10327 ;;;
10328
10329 (defmacro gnus-with-article (article &rest forms)
10330   "Select ARTICLE and perform FORMS in the original article buffer.
10331 Then replace the article with the result."
10332   `(progn
10333      ;; We don't want the article to be marked as read.
10334      (let (gnus-mark-article-hook)
10335        (gnus-summary-select-article t t nil ,article))
10336      (set-buffer gnus-original-article-buffer)
10337      ,@forms
10338      (if (not (gnus-check-backend-function
10339                'request-replace-article (car gnus-article-current)))
10340          (gnus-message 5 "Read-only group; not replacing")
10341        (unless (gnus-request-replace-article
10342                 ,article (car gnus-article-current)
10343                 (current-buffer) t)
10344          (error "Couldn't replace article")))
10345      ;; The cache and backlog have to be flushed somewhat.
10346      (when gnus-keep-backlog
10347        (gnus-backlog-remove-article
10348         (car gnus-article-current) (cdr gnus-article-current)))
10349      (when gnus-use-cache
10350        (gnus-cache-update-article
10351         (car gnus-article-current) (cdr gnus-article-current)))))
10352
10353 (put 'gnus-with-article 'lisp-indent-function 1)
10354 (put 'gnus-with-article 'edebug-form-spec '(form body))
10355
10356 ;; Thread-based commands.
10357
10358 (defun gnus-summary-articles-in-thread (&optional article)
10359   "Return a list of all articles in the current thread.
10360 If ARTICLE is non-nil, return all articles in the thread that starts
10361 with that article."
10362   (let* ((article (or article (gnus-summary-article-number)))
10363          (data (gnus-data-find-list article))
10364          (top-level (gnus-data-level (car data)))
10365          (top-subject
10366           (cond ((null gnus-thread-operation-ignore-subject)
10367                  (gnus-simplify-subject-re
10368                   (mail-header-subject (gnus-data-header (car data)))))
10369                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10370                  (gnus-simplify-subject-fuzzy
10371                   (mail-header-subject (gnus-data-header (car data)))))
10372                 (t nil)))
10373          (end-point (save-excursion
10374                       (if (gnus-summary-go-to-next-thread)
10375                           (point) (point-max))))
10376          articles)
10377     (while (and data
10378                 (< (gnus-data-pos (car data)) end-point))
10379       (when (or (not top-subject)
10380                 (string= top-subject
10381                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10382                              (gnus-simplify-subject-fuzzy
10383                               (mail-header-subject
10384                                (gnus-data-header (car data))))
10385                            (gnus-simplify-subject-re
10386                             (mail-header-subject
10387                              (gnus-data-header (car data)))))))
10388         (push (gnus-data-number (car data)) articles))
10389       (unless (and (setq data (cdr data))
10390                    (> (gnus-data-level (car data)) top-level))
10391         (setq data nil)))
10392     ;; Return the list of articles.
10393     (nreverse articles)))
10394
10395 (defun gnus-summary-rethread-current ()
10396   "Rethread the thread the current article is part of."
10397   (interactive)
10398   (let* ((gnus-show-threads t)
10399          (article (gnus-summary-article-number))
10400          (id (mail-header-id (gnus-summary-article-header)))
10401          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10402     (unless id
10403       (error "No article on the current line"))
10404     (gnus-rebuild-thread id)
10405     (gnus-summary-goto-subject article)))
10406
10407 (defun gnus-summary-reparent-thread ()
10408   "Make the current article child of the marked (or previous) article.
10409
10410 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10411 is non-nil or the Subject: of both articles are the same."
10412   (interactive)
10413   (unless (not (gnus-group-read-only-p))
10414     (error "The current newsgroup does not support article editing"))
10415   (unless (<= (length gnus-newsgroup-processable) 1)
10416     (error "No more than one article may be marked"))
10417   (save-window-excursion
10418     (let ((gnus-article-buffer " *reparent*")
10419           (current-article (gnus-summary-article-number))
10420           ;; First grab the marked article, otherwise one line up.
10421           (parent-article (if (not (null gnus-newsgroup-processable))
10422                               (car gnus-newsgroup-processable)
10423                             (save-excursion
10424                               (if (eq (forward-line -1) 0)
10425                                   (gnus-summary-article-number)
10426                                 (error "Beginning of summary buffer"))))))
10427       (unless (not (eq current-article parent-article))
10428         (error "An article may not be self-referential"))
10429       (let ((message-id (mail-header-id
10430                          (gnus-summary-article-header parent-article))))
10431         (unless (and message-id (not (equal message-id "")))
10432           (error "No message-id in desired parent"))
10433         (gnus-with-article current-article
10434           (save-restriction
10435             (goto-char (point-min))
10436             (message-narrow-to-head)
10437             (if (re-search-forward "^References: " nil t)
10438                 (progn
10439                   (re-search-forward "^[^ \t]" nil t)
10440                   (forward-line -1)
10441                   (end-of-line)
10442                   (insert " " message-id))
10443               (insert "References: " message-id "\n"))))
10444         (set-buffer gnus-summary-buffer)
10445         (gnus-summary-unmark-all-processable)
10446         (gnus-summary-update-article current-article)
10447         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10448             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10449         (gnus-summary-rethread-current)
10450         (gnus-message 3 "Article %d is now the child of article %d"
10451                       current-article parent-article)))))
10452
10453 (defun gnus-summary-toggle-threads (&optional arg)
10454   "Toggle showing conversation threads.
10455 If ARG is positive number, turn showing conversation threads on."
10456   (interactive "P")
10457   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10458     (setq gnus-show-threads
10459           (if (null arg) (not gnus-show-threads)
10460             (> (prefix-numeric-value arg) 0)))
10461     (gnus-summary-prepare)
10462     (gnus-summary-goto-subject current)
10463     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10464     (gnus-summary-position-point)))
10465
10466 (defun gnus-summary-show-all-threads ()
10467   "Show all threads."
10468   (interactive)
10469   (save-excursion
10470     (let ((buffer-read-only nil))
10471       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10472   (gnus-summary-position-point))
10473
10474 (defun gnus-summary-show-thread ()
10475   "Show thread subtrees.
10476 Returns nil if no thread was there to be shown."
10477   (interactive)
10478   (let ((buffer-read-only nil)
10479         (orig (point))
10480         (end (gnus-point-at-eol))
10481         ;; Leave point at bol
10482         (beg (progn (beginning-of-line) (point))))
10483     (prog1
10484         ;; Any hidden lines here?
10485         (search-forward "\r" end t)
10486       (subst-char-in-region beg end ?\^M ?\n t)
10487       (goto-char orig)
10488       (gnus-summary-position-point))))
10489
10490 (defun gnus-summary-maybe-hide-threads ()
10491   "If requested, hide the threads that should be hidden."
10492   (when (and gnus-show-threads
10493              gnus-thread-hide-subtree)
10494     (gnus-summary-hide-all-threads
10495      (if (or (consp gnus-thread-hide-subtree)
10496              (functionp gnus-thread-hide-subtree))
10497          (gnus-make-predicate gnus-thread-hide-subtree)
10498        nil))))
10499
10500 ;;; Hiding predicates.
10501
10502 (defun gnus-article-unread-p (header)
10503   (memq (mail-header-number header) gnus-newsgroup-unreads))
10504
10505 (defun gnus-article-unseen-p (header)
10506   (memq (mail-header-number header) gnus-newsgroup-unseen))
10507
10508 (defun gnus-map-articles (predicate articles)
10509   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10510   (apply 'gnus-or (mapcar predicate
10511                           (mapcar 'gnus-summary-article-header articles))))
10512
10513 (defun gnus-summary-hide-all-threads (&optional predicate)
10514   "Hide all thread subtrees.
10515 If PREDICATE is supplied, threads that satisfy this predicate
10516 will not be hidden."
10517   (interactive)
10518   (save-excursion
10519     (goto-char (point-min))
10520     (let ((end nil))
10521       (while (not end)
10522         (when (or (not predicate)
10523                   (gnus-map-articles
10524                    predicate (gnus-summary-article-children)))
10525             (gnus-summary-hide-thread))
10526         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10527   (gnus-summary-position-point))
10528
10529 (defun gnus-summary-hide-thread ()
10530   "Hide thread subtrees.
10531 If PREDICATE is supplied, threads that satisfy this predicate
10532 will not be hidden.
10533 Returns nil if no threads were there to be hidden."
10534   (interactive)
10535   (let ((buffer-read-only nil)
10536         (start (point))
10537         (article (gnus-summary-article-number)))
10538     (goto-char start)
10539     ;; Go forward until either the buffer ends or the subthread
10540     ;; ends.
10541     (when (and (not (eobp))
10542                (or (zerop (gnus-summary-next-thread 1 t))
10543                    (goto-char (point-max))))
10544       (prog1
10545           (if (and (> (point) start)
10546                    (search-backward "\n" start t))
10547               (progn
10548                 (subst-char-in-region start (point) ?\n ?\^M)
10549                 (gnus-summary-goto-subject article))
10550             (goto-char start)
10551             nil)))))
10552
10553 (defun gnus-summary-go-to-next-thread (&optional previous)
10554   "Go to the same level (or less) next thread.
10555 If PREVIOUS is non-nil, go to previous thread instead.
10556 Return the article number moved to, or nil if moving was impossible."
10557   (let ((level (gnus-summary-thread-level))
10558         (way (if previous -1 1))
10559         (beg (point)))
10560     (forward-line way)
10561     (while (and (not (eobp))
10562                 (< level (gnus-summary-thread-level)))
10563       (forward-line way))
10564     (if (eobp)
10565         (progn
10566           (goto-char beg)
10567           nil)
10568       (setq beg (point))
10569       (prog1
10570           (gnus-summary-article-number)
10571         (goto-char beg)))))
10572
10573 (defun gnus-summary-next-thread (n &optional silent)
10574   "Go to the same level next N'th thread.
10575 If N is negative, search backward instead.
10576 Returns the difference between N and the number of skips actually
10577 done.
10578
10579 If SILENT, don't output messages."
10580   (interactive "p")
10581   (let ((backward (< n 0))
10582         (n (abs n)))
10583     (while (and (> n 0)
10584                 (gnus-summary-go-to-next-thread backward))
10585       (decf n))
10586     (unless silent
10587       (gnus-summary-position-point))
10588     (when (and (not silent) (/= 0 n))
10589       (gnus-message 7 "No more threads"))
10590     n))
10591
10592 (defun gnus-summary-prev-thread (n)
10593   "Go to the same level previous N'th thread.
10594 Returns the difference between N and the number of skips actually
10595 done."
10596   (interactive "p")
10597   (gnus-summary-next-thread (- n)))
10598
10599 (defun gnus-summary-go-down-thread ()
10600   "Go down one level in the current thread."
10601   (let ((children (gnus-summary-article-children)))
10602     (when children
10603       (gnus-summary-goto-subject (car children)))))
10604
10605 (defun gnus-summary-go-up-thread ()
10606   "Go up one level in the current thread."
10607   (let ((parent (gnus-summary-article-parent)))
10608     (when parent
10609       (gnus-summary-goto-subject parent))))
10610
10611 (defun gnus-summary-down-thread (n)
10612   "Go down thread N steps.
10613 If N is negative, go up instead.
10614 Returns the difference between N and how many steps down that were
10615 taken."
10616   (interactive "p")
10617   (let ((up (< n 0))
10618         (n (abs n)))
10619     (while (and (> n 0)
10620                 (if up (gnus-summary-go-up-thread)
10621                   (gnus-summary-go-down-thread)))
10622       (setq n (1- n)))
10623     (gnus-summary-position-point)
10624     (when (/= 0 n)
10625       (gnus-message 7 "Can't go further"))
10626     n))
10627
10628 (defun gnus-summary-up-thread (n)
10629   "Go up thread N steps.
10630 If N is negative, go down instead.
10631 Returns the difference between N and how many steps down that were
10632 taken."
10633   (interactive "p")
10634   (gnus-summary-down-thread (- n)))
10635
10636 (defun gnus-summary-top-thread ()
10637   "Go to the top of the thread."
10638   (interactive)
10639   (while (gnus-summary-go-up-thread))
10640   (gnus-summary-article-number))
10641
10642 (defun gnus-summary-kill-thread (&optional unmark)
10643   "Mark articles under current thread as read.
10644 If the prefix argument is positive, remove any kinds of marks.
10645 If the prefix argument is negative, tick articles instead."
10646   (interactive "P")
10647   (when unmark
10648     (setq unmark (prefix-numeric-value unmark)))
10649   (let ((articles (gnus-summary-articles-in-thread)))
10650     (save-excursion
10651       ;; Expand the thread.
10652       (gnus-summary-show-thread)
10653       ;; Mark all the articles.
10654       (while articles
10655         (gnus-summary-goto-subject (car articles))
10656         (cond ((null unmark)
10657                (gnus-summary-mark-article-as-read gnus-killed-mark))
10658               ((> unmark 0)
10659                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10660               (t
10661                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10662         (setq articles (cdr articles))))
10663     ;; Hide killed subtrees.
10664     (and (null unmark)
10665          gnus-thread-hide-killed
10666          (gnus-summary-hide-thread))
10667     ;; If marked as read, go to next unread subject.
10668     (when (null unmark)
10669       ;; Go to next unread subject.
10670       (gnus-summary-next-subject 1 t)))
10671   (gnus-set-mode-line 'summary))
10672
10673 ;; Summary sorting commands
10674
10675 (defun gnus-summary-sort-by-number (&optional reverse)
10676   "Sort the summary buffer by article number.
10677 Argument REVERSE means reverse order."
10678   (interactive "P")
10679   (gnus-summary-sort 'number reverse))
10680
10681 (defun gnus-summary-sort-by-random (&optional reverse)
10682   "Randomize the order in the summary buffer.
10683 Argument REVERSE means to randomize in reverse order."
10684   (interactive "P")
10685   (gnus-summary-sort 'random reverse))
10686
10687 (defun gnus-summary-sort-by-author (&optional reverse)
10688   "Sort the summary buffer by author name alphabetically.
10689 If `case-fold-search' is non-nil, case of letters is ignored.
10690 Argument REVERSE means reverse order."
10691   (interactive "P")
10692   (gnus-summary-sort 'author reverse))
10693
10694 (defun gnus-summary-sort-by-subject (&optional reverse)
10695   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10696 If `case-fold-search' is non-nil, case of letters is ignored.
10697 Argument REVERSE means reverse order."
10698   (interactive "P")
10699   (gnus-summary-sort 'subject reverse))
10700
10701 (defun gnus-summary-sort-by-date (&optional reverse)
10702   "Sort the summary buffer by date.
10703 Argument REVERSE means reverse order."
10704   (interactive "P")
10705   (gnus-summary-sort 'date reverse))
10706
10707 (defun gnus-summary-sort-by-score (&optional reverse)
10708   "Sort the summary buffer by score.
10709 Argument REVERSE means reverse order."
10710   (interactive "P")
10711   (gnus-summary-sort 'score reverse))
10712
10713 (defun gnus-summary-sort-by-lines (&optional reverse)
10714   "Sort the summary buffer by the number of lines.
10715 Argument REVERSE means reverse order."
10716   (interactive "P")
10717   (gnus-summary-sort 'lines reverse))
10718
10719 (defun gnus-summary-sort-by-chars (&optional reverse)
10720   "Sort the summary buffer by article length.
10721 Argument REVERSE means reverse order."
10722   (interactive "P")
10723   (gnus-summary-sort 'chars reverse))
10724
10725 (defun gnus-summary-sort-by-original (&optional reverse)
10726   "Sort the summary buffer using the default sorting method.
10727 Argument REVERSE means reverse order."
10728   (interactive "P")
10729   (let* ((buffer-read-only)
10730          (gnus-summary-prepare-hook nil))
10731     ;; We do the sorting by regenerating the threads.
10732     (gnus-summary-prepare)
10733     ;; Hide subthreads if needed.
10734     (gnus-summary-maybe-hide-threads)))
10735
10736 (defun gnus-summary-sort (predicate reverse)
10737   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10738   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10739          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10740          (gnus-thread-sort-functions
10741           (if (not reverse)
10742               thread
10743             `(lambda (t1 t2)
10744                (,thread t2 t1))))
10745          (gnus-sort-gathered-threads-function
10746           gnus-thread-sort-functions)
10747          (gnus-article-sort-functions
10748           (if (not reverse)
10749               article
10750             `(lambda (t1 t2)
10751                (,article t2 t1))))
10752          (buffer-read-only)
10753          (gnus-summary-prepare-hook nil))
10754     ;; We do the sorting by regenerating the threads.
10755     (gnus-summary-prepare)
10756     ;; Hide subthreads if needed.
10757     (gnus-summary-maybe-hide-threads)))
10758
10759 ;; Summary saving commands.
10760
10761 (defun gnus-summary-save-article (&optional n not-saved)
10762   "Save the current article using the default saver function.
10763 If N is a positive number, save the N next articles.
10764 If N is a negative number, save the N previous articles.
10765 If N is nil and any articles have been marked with the process mark,
10766 save those articles instead.
10767 The variable `gnus-default-article-saver' specifies the saver function."
10768   (interactive "P")
10769   (let* ((articles (gnus-summary-work-articles n))
10770          (save-buffer (save-excursion
10771                         (nnheader-set-temp-buffer " *Gnus Save*")))
10772          (num (length articles))
10773          header file)
10774     (dolist (article articles)
10775       (setq header (gnus-summary-article-header article))
10776       (if (not (vectorp header))
10777           ;; This is a pseudo-article.
10778           (if (assq 'name header)
10779               (gnus-copy-file (cdr (assq 'name header)))
10780             (gnus-message 1 "Article %d is unsaveable" article))
10781         ;; This is a real article.
10782         (save-window-excursion
10783           (let ((gnus-display-mime-function nil)
10784                 (gnus-article-prepare-hook nil))
10785             (gnus-summary-select-article t nil nil article)))
10786         (save-excursion
10787           (set-buffer save-buffer)
10788           (erase-buffer)
10789           (insert-buffer-substring gnus-original-article-buffer))
10790         (setq file (gnus-article-save save-buffer file num))
10791         (gnus-summary-remove-process-mark article)
10792         (unless not-saved
10793           (gnus-summary-set-saved-mark article))))
10794     (gnus-kill-buffer save-buffer)
10795     (gnus-summary-position-point)
10796     (gnus-set-mode-line 'summary)
10797     n))
10798
10799 (defun gnus-summary-pipe-output (&optional arg headers)
10800   "Pipe the current article to a subprocess.
10801 If N is a positive number, pipe the N next articles.
10802 If N is a negative number, pipe the N previous articles.
10803 If N is nil and any articles have been marked with the process mark,
10804 pipe those articles instead.
10805 If HEADERS (the symbolic prefix), include the headers, too."
10806   (interactive (gnus-interactive "P\ny"))
10807   (require 'gnus-art)
10808   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10809         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10810     (gnus-summary-save-article arg t))
10811   (let ((buffer (get-buffer "*Shell Command Output*")))
10812     (when (and buffer
10813                (not (zerop (buffer-size buffer))))
10814       (gnus-configure-windows 'pipe))))
10815
10816 (defun gnus-summary-save-article-mail (&optional arg)
10817   "Append the current article to an mail file.
10818 If N is a positive number, save the N next articles.
10819 If N is a negative number, save the N previous articles.
10820 If N is nil and any articles have been marked with the process mark,
10821 save those articles instead."
10822   (interactive "P")
10823   (require 'gnus-art)
10824   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10825     (gnus-summary-save-article arg)))
10826
10827 (defun gnus-summary-save-article-rmail (&optional arg)
10828   "Append the current article to an rmail file.
10829 If N is a positive number, save the N next articles.
10830 If N is a negative number, save the N previous articles.
10831 If N is nil and any articles have been marked with the process mark,
10832 save those articles instead."
10833   (interactive "P")
10834   (require 'gnus-art)
10835   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10836     (gnus-summary-save-article arg)))
10837
10838 (defun gnus-summary-save-article-file (&optional arg)
10839   "Append the current article to a file.
10840 If N is a positive number, save the N next articles.
10841 If N is a negative number, save the N previous articles.
10842 If N is nil and any articles have been marked with the process mark,
10843 save those articles instead."
10844   (interactive "P")
10845   (require 'gnus-art)
10846   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10847     (gnus-summary-save-article arg)))
10848
10849 (defun gnus-summary-write-article-file (&optional arg)
10850   "Write the current article to a file, deleting the previous file.
10851 If N is a positive number, save the N next articles.
10852 If N is a negative number, save the N previous articles.
10853 If N is nil and any articles have been marked with the process mark,
10854 save those articles instead."
10855   (interactive "P")
10856   (require 'gnus-art)
10857   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10858     (gnus-summary-save-article arg)))
10859
10860 (defun gnus-summary-save-article-body-file (&optional arg)
10861   "Append the current article body to a file.
10862 If N is a positive number, save the N next articles.
10863 If N is a negative number, save the N previous articles.
10864 If N is nil and any articles have been marked with the process mark,
10865 save those articles instead."
10866   (interactive "P")
10867   (require 'gnus-art)
10868   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10869     (gnus-summary-save-article arg)))
10870
10871 (defun gnus-summary-muttprint (&optional arg)
10872   "Print the current article using Muttprint.
10873 If N is a positive number, save the N next articles.
10874 If N is a negative number, save the N previous articles.
10875 If N is nil and any articles have been marked with the process mark,
10876 save those articles instead."
10877   (interactive "P")
10878   (require 'gnus-art)
10879   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10880     (gnus-summary-save-article arg t)))
10881
10882 (defun gnus-summary-pipe-message (program)
10883   "Pipe the current article through PROGRAM."
10884   (interactive "sProgram: ")
10885   (gnus-summary-select-article)
10886   (let ((mail-header-separator ""))
10887     (gnus-eval-in-buffer-window gnus-article-buffer
10888       (save-restriction
10889         (widen)
10890         (let ((start (window-start))
10891               buffer-read-only)
10892           (message-pipe-buffer-body program)
10893           (set-window-start (get-buffer-window (current-buffer)) start))))))
10894
10895 (defun gnus-get-split-value (methods)
10896   "Return a value based on the split METHODS."
10897   (let (split-name method result match)
10898     (when methods
10899       (save-excursion
10900         (set-buffer gnus-original-article-buffer)
10901         (save-restriction
10902           (nnheader-narrow-to-headers)
10903           (while (and methods (not split-name))
10904             (goto-char (point-min))
10905             (setq method (pop methods))
10906             (setq match (car method))
10907             (when (cond
10908                    ((stringp match)
10909                     ;; Regular expression.
10910                     (ignore-errors
10911                       (re-search-forward match nil t)))
10912                    ((functionp match)
10913                     ;; Function.
10914                     (save-restriction
10915                       (widen)
10916                       (setq result (funcall match gnus-newsgroup-name))))
10917                    ((consp match)
10918                     ;; Form.
10919                     (save-restriction
10920                       (widen)
10921                       (setq result (eval match)))))
10922               (setq split-name (cdr method))
10923               (cond ((stringp result)
10924                      (push (expand-file-name
10925                             result gnus-article-save-directory)
10926                            split-name))
10927                     ((consp result)
10928                      (setq split-name (append result split-name)))))))))
10929     (nreverse split-name)))
10930
10931 (defun gnus-valid-move-group-p (group)
10932   (and (boundp group)
10933        (symbol-name group)
10934        (symbol-value group)
10935        (gnus-get-function (gnus-find-method-for-group
10936                            (symbol-name group)) 'request-accept-article t)))
10937
10938 (defun gnus-read-move-group-name (prompt default articles prefix)
10939   "Read a group name."
10940   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10941          (minibuffer-confirm-incomplete nil) ; XEmacs
10942          (prom
10943           (format "%s %s to:"
10944                   prompt
10945                   (if (> (length articles) 1)
10946                       (format "these %d articles" (length articles))
10947                     "this article")))
10948          (to-newsgroup
10949           (cond
10950            ((null split-name)
10951             (gnus-completing-read-with-default
10952              default prom
10953              gnus-active-hashtb
10954              'gnus-valid-move-group-p
10955              nil prefix
10956              'gnus-group-history))
10957            ((= 1 (length split-name))
10958             (gnus-completing-read-with-default
10959              (car split-name) prom
10960              gnus-active-hashtb
10961              'gnus-valid-move-group-p
10962              nil nil
10963              'gnus-group-history))
10964            (t
10965             (gnus-completing-read-with-default
10966              nil prom
10967              (mapcar (lambda (el) (list el))
10968                      (nreverse split-name))
10969              nil nil nil
10970              'gnus-group-history))))
10971          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10972     (when to-newsgroup
10973       (if (or (string= to-newsgroup "")
10974               (string= to-newsgroup prefix))
10975           (setq to-newsgroup default))
10976       (unless to-newsgroup
10977         (error "No group name entered"))
10978       (or (gnus-active to-newsgroup)
10979           (gnus-activate-group to-newsgroup nil nil to-method)
10980           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10981                                      to-newsgroup))
10982               (or (and (gnus-request-create-group to-newsgroup to-method)
10983                        (gnus-activate-group
10984                         to-newsgroup nil nil to-method)
10985                        (gnus-subscribe-group to-newsgroup))
10986                   (error "Couldn't create group %s" to-newsgroup)))
10987           (error "No such group: %s" to-newsgroup)))
10988     to-newsgroup))
10989
10990 (defun gnus-summary-save-parts (type dir n &optional reverse)
10991   "Save parts matching TYPE to DIR.
10992 If REVERSE, save parts that do not match TYPE."
10993   (interactive
10994    (list (read-string "Save parts of type: "
10995                       (or (car gnus-summary-save-parts-type-history)
10996                           gnus-summary-save-parts-default-mime)
10997                       'gnus-summary-save-parts-type-history)
10998          (setq gnus-summary-save-parts-last-directory
10999                (read-file-name "Save to directory: "
11000                                gnus-summary-save-parts-last-directory
11001                                nil t))
11002          current-prefix-arg))
11003   (gnus-summary-iterate n
11004     (let ((gnus-display-mime-function nil)
11005           (gnus-inhibit-treatment t))
11006       (gnus-summary-select-article))
11007     (save-excursion
11008       (set-buffer gnus-article-buffer)
11009       (let ((handles (or gnus-article-mime-handles
11010                          (mm-dissect-buffer nil gnus-article-loose-mime)
11011                          (and gnus-article-emulate-mime
11012                               (mm-uu-dissect)))))
11013         (when handles
11014           (gnus-summary-save-parts-1 type dir handles reverse)
11015           (unless gnus-article-mime-handles ;; Don't destroy this case.
11016             (mm-destroy-parts handles)))))))
11017
11018 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11019   (if (stringp (car handle))
11020       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11021               (cdr handle))
11022     (when (if reverse
11023               (not (string-match type (mm-handle-media-type handle)))
11024             (string-match type (mm-handle-media-type handle)))
11025       (let ((file (expand-file-name
11026                    (file-name-nondirectory
11027                     (or
11028                      (mail-content-type-get
11029                       (mm-handle-disposition handle) 'filename)
11030                      (concat gnus-newsgroup-name
11031                              "." (number-to-string
11032                                   (cdr gnus-article-current)))))
11033                    dir)))
11034         (unless (file-exists-p file)
11035           (mm-save-part-to-file handle file))))))
11036
11037 ;; Summary extract commands
11038
11039 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11040   (let ((buffer-read-only nil)
11041         (article (gnus-summary-article-number))
11042         after-article b e)
11043     (unless (gnus-summary-goto-subject article)
11044       (error "No such article: %d" article))
11045     (gnus-summary-position-point)
11046     ;; If all commands are to be bunched up on one line, we collect
11047     ;; them here.
11048     (unless gnus-view-pseudos-separately
11049       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11050             files action)
11051         (while ps
11052           (setq action (cdr (assq 'action (car ps))))
11053           (setq files (list (cdr (assq 'name (car ps)))))
11054           (while (and ps (cdr ps)
11055                       (string= (or action "1")
11056                                (or (cdr (assq 'action (cadr ps))) "2")))
11057             (push (cdr (assq 'name (cadr ps))) files)
11058             (setcdr ps (cddr ps)))
11059           (when files
11060             (when (not (string-match "%s" action))
11061               (push " " files))
11062             (push " " files)
11063             (when (assq 'execute (car ps))
11064               (setcdr (assq 'execute (car ps))
11065                       (funcall (if (string-match "%s" action)
11066                                    'format 'concat)
11067                                action
11068                                (mapconcat
11069                                 (lambda (f)
11070                                   (if (equal f " ")
11071                                       f
11072                                     (gnus-quote-arg-for-sh-or-csh f)))
11073                                 files " ")))))
11074           (setq ps (cdr ps)))))
11075     (if (and gnus-view-pseudos (not not-view))
11076         (while pslist
11077           (when (assq 'execute (car pslist))
11078             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11079                                   (eq gnus-view-pseudos 'not-confirm)))
11080           (setq pslist (cdr pslist)))
11081       (save-excursion
11082         (while pslist
11083           (setq after-article (or (cdr (assq 'article (car pslist)))
11084                                   (gnus-summary-article-number)))
11085           (gnus-summary-goto-subject after-article)
11086           (forward-line 1)
11087           (setq b (point))
11088           (insert "    " (file-name-nondirectory
11089                           (cdr (assq 'name (car pslist))))
11090                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11091           (setq e (point))
11092           (forward-line -1)             ; back to `b'
11093           (gnus-add-text-properties
11094            b (1- e) (list 'gnus-number gnus-reffed-article-number
11095                           gnus-mouse-face-prop gnus-mouse-face))
11096           (gnus-data-enter
11097            after-article gnus-reffed-article-number
11098            gnus-unread-mark b (car pslist) 0 (- e b))
11099           (setq gnus-newsgroup-unreads
11100                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11101                                          gnus-reffed-article-number))
11102           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11103           (setq pslist (cdr pslist)))))))
11104
11105 (defun gnus-pseudos< (p1 p2)
11106   (let ((c1 (cdr (assq 'action p1)))
11107         (c2 (cdr (assq 'action p2))))
11108     (and c1 c2 (string< c1 c2))))
11109
11110 (defun gnus-request-pseudo-article (props)
11111   (cond ((assq 'execute props)
11112          (gnus-execute-command (cdr (assq 'execute props)))))
11113   (let ((gnus-current-article (gnus-summary-article-number)))
11114     (gnus-run-hooks 'gnus-mark-article-hook)))
11115
11116 (defun gnus-execute-command (command &optional automatic)
11117   (save-excursion
11118     (gnus-article-setup-buffer)
11119     (set-buffer gnus-article-buffer)
11120     (setq buffer-read-only nil)
11121     (let ((command (if automatic command
11122                      (read-string "Command: " (cons command 0)))))
11123       (erase-buffer)
11124       (insert "$ " command "\n\n")
11125       (if gnus-view-pseudo-asynchronously
11126           (start-process "gnus-execute" (current-buffer) shell-file-name
11127                          shell-command-switch command)
11128         (call-process shell-file-name nil t nil
11129                       shell-command-switch command)))))
11130
11131 ;; Summary kill commands.
11132
11133 (defun gnus-summary-edit-global-kill (article)
11134   "Edit the \"global\" kill file."
11135   (interactive (list (gnus-summary-article-number)))
11136   (gnus-group-edit-global-kill article))
11137
11138 (defun gnus-summary-edit-local-kill ()
11139   "Edit a local kill file applied to the current newsgroup."
11140   (interactive)
11141   (setq gnus-current-headers (gnus-summary-article-header))
11142   (gnus-group-edit-local-kill
11143    (gnus-summary-article-number) gnus-newsgroup-name))
11144
11145 ;;; Header reading.
11146
11147 (defun gnus-read-header (id &optional header)
11148   "Read the headers of article ID and enter them into the Gnus system."
11149   (let ((group gnus-newsgroup-name)
11150         (gnus-override-method
11151          (or
11152           gnus-override-method
11153           (and (gnus-news-group-p gnus-newsgroup-name)
11154                (car (gnus-refer-article-methods)))))
11155         where)
11156     ;; First we check to see whether the header in question is already
11157     ;; fetched.
11158     (if (stringp id)
11159         ;; This is a Message-ID.
11160         (setq header (or header (gnus-id-to-header id)))
11161       ;; This is an article number.
11162       (setq header (or header (gnus-summary-article-header id))))
11163     (if (and header
11164              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11165         ;; We have found the header.
11166         header
11167       ;; If this is a sparse article, we have to nix out its
11168       ;; previous entry in the thread hashtb.
11169       (when (and header
11170                  (gnus-summary-article-sparse-p (mail-header-number header)))
11171         (let* ((parent (gnus-parent-id (mail-header-references header)))
11172                (thread (and parent (gnus-id-to-thread parent))))
11173           (when thread
11174             (delq (assq header thread) thread))))
11175       ;; We have to really fetch the header to this article.
11176       (save-excursion
11177         (set-buffer nntp-server-buffer)
11178         (when (setq where (gnus-request-head id group))
11179           (nnheader-fold-continuation-lines)
11180           (goto-char (point-max))
11181           (insert ".\n")
11182           (goto-char (point-min))
11183           (insert "211 ")
11184           (princ (cond
11185                   ((numberp id) id)
11186                   ((cdr where) (cdr where))
11187                   (header (mail-header-number header))
11188                   (t gnus-reffed-article-number))
11189                  (current-buffer))
11190           (insert " Article retrieved.\n"))
11191         (if (or (not where)
11192                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11193             ()                          ; Malformed head.
11194           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11195             (when (and (stringp id)
11196                        (not (string= (gnus-group-real-name group)
11197                                      (car where))))
11198               ;; If we fetched by Message-ID and the article came
11199               ;; from a different group, we fudge some bogus article
11200               ;; numbers for this article.
11201               (mail-header-set-number header gnus-reffed-article-number))
11202             (save-excursion
11203               (set-buffer gnus-summary-buffer)
11204               (decf gnus-reffed-article-number)
11205               (gnus-remove-header (mail-header-number header))
11206               (push header gnus-newsgroup-headers)
11207               (setq gnus-current-headers header)
11208               (push (mail-header-number header) gnus-newsgroup-limit)))
11209           header)))))
11210
11211 (defun gnus-remove-header (number)
11212   "Remove header NUMBER from `gnus-newsgroup-headers'."
11213   (if (and gnus-newsgroup-headers
11214            (= number (mail-header-number (car gnus-newsgroup-headers))))
11215       (pop gnus-newsgroup-headers)
11216     (let ((headers gnus-newsgroup-headers))
11217       (while (and (cdr headers)
11218                   (not (= number (mail-header-number (cadr headers)))))
11219         (pop headers))
11220       (when (cdr headers)
11221         (setcdr headers (cddr headers))))))
11222
11223 ;;;
11224 ;;; summary highlights
11225 ;;;
11226
11227 (defun gnus-highlight-selected-summary ()
11228   "Highlight selected article in summary buffer."
11229   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11230   (when gnus-summary-selected-face
11231     (save-excursion
11232       (let* ((beg (gnus-point-at-bol))
11233              (end (gnus-point-at-eol))
11234              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11235              (from (if (get-text-property beg gnus-mouse-face-prop)
11236                        beg
11237                      (or (next-single-property-change
11238                           beg gnus-mouse-face-prop nil end)
11239                          beg)))
11240              (to
11241               (if (= from end)
11242                   (- from 2)
11243                 (or (next-single-property-change
11244                      from gnus-mouse-face-prop nil end)
11245                     end))))
11246         ;; If no mouse-face prop on line we will have to = from = end,
11247         ;; so we highlight the entire line instead.
11248         (when (= (+ to 2) from)
11249           (setq from beg)
11250           (setq to end))
11251         (if gnus-newsgroup-selected-overlay
11252             ;; Move old overlay.
11253             (gnus-move-overlay
11254              gnus-newsgroup-selected-overlay from to (current-buffer))
11255           ;; Create new overlay.
11256           (gnus-overlay-put
11257            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11258            'face gnus-summary-selected-face))))))
11259
11260 (defvar gnus-summary-highlight-line-cached nil)
11261 (defvar gnus-summary-highlight-line-trigger nil)
11262
11263 (defun gnus-summary-highlight-line-0 ()
11264   (if (and (eq gnus-summary-highlight-line-trigger 
11265                gnus-summary-highlight)
11266            gnus-summary-highlight-line-cached)
11267       gnus-summary-highlight-line-cached
11268     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11269           gnus-summary-highlight-line-cached
11270           (let* ((cond (list 'cond))
11271                  (c cond)
11272                  (list gnus-summary-highlight))
11273             (while list
11274               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11275                               nil))
11276               (setq c (cdr c)
11277                     list (cdr list)))
11278             (gnus-byte-compile (list 'lambda nil cond))))))
11279
11280 (defun gnus-summary-highlight-line ()
11281   "Highlight current line according to `gnus-summary-highlight'."
11282   (let* ((beg (gnus-point-at-bol))
11283          (article (or (gnus-summary-article-number) gnus-current-article))
11284          (score (or (cdr (assq article
11285                                gnus-newsgroup-scored))
11286                     gnus-summary-default-score 0))
11287          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11288          (inhibit-read-only t)
11289          (default gnus-summary-default-score)
11290          (default-high gnus-summary-default-high-score)
11291          (default-low gnus-summary-default-low-score)
11292          (uncached (memq article gnus-newsgroup-undownloaded))
11293          (downloaded (not uncached)))
11294     (let ((face (funcall (gnus-summary-highlight-line-0))))
11295       (unless (eq face (get-text-property beg 'face))
11296         (gnus-put-text-property-excluding-characters-with-faces
11297          beg (gnus-point-at-eol) 'face
11298          (setq face (if (boundp face) (symbol-value face) face)))
11299         (when gnus-summary-highlight-line-function
11300           (funcall gnus-summary-highlight-line-function article face))))))
11301
11302 (defun gnus-update-read-articles (group unread &optional compute)
11303   "Update the list of read articles in GROUP.
11304 UNREAD is a sorted list."
11305   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
11306          (entry (gnus-gethash group gnus-newsrc-hashtb))
11307          (info (nth 2 entry))
11308          (prev 1)
11309          read)
11310     (if (or (not info) (not active))
11311         ;; There is no info on this group if it was, in fact,
11312         ;; killed.  Gnus stores no information on killed groups, so
11313         ;; there's nothing to be done.
11314         ;; One could store the information somewhere temporarily,
11315         ;; perhaps...  Hmmm...
11316         ()
11317       ;; Remove any negative articles numbers.
11318       (while (and unread (< (car unread) 0))
11319         (setq unread (cdr unread)))
11320       ;; Remove any expired article numbers
11321       (while (and unread (< (car unread) (car active)))
11322         (setq unread (cdr unread)))
11323       ;; Compute the ranges of read articles by looking at the list of
11324       ;; unread articles.
11325       (while unread
11326         (when (/= (car unread) prev)
11327           (push (if (= prev (1- (car unread))) prev
11328                   (cons prev (1- (car unread))))
11329                 read))
11330         (setq prev (1+ (car unread)))
11331         (setq unread (cdr unread)))
11332       (when (<= prev (cdr active))
11333         (push (cons prev (cdr active)) read))
11334       (setq read (if (> (length read) 1) (nreverse read) read))
11335       (if compute
11336           read
11337         (save-excursion
11338           (let (setmarkundo)
11339             ;; Propagate the read marks to the backend.
11340             (when (gnus-check-backend-function 'request-set-mark group)
11341               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11342                     (add (gnus-remove-from-range read (gnus-info-read info))))
11343                 (when (or add del)
11344                   (unless (gnus-check-group group)
11345                     (error "Can't open server for %s" group))
11346                   (gnus-request-set-mark
11347                    group (delq nil (list (if add (list add 'add '(read)))
11348                                          (if del (list del 'del '(read))))))
11349                   (setq setmarkundo
11350                         `(gnus-request-set-mark
11351                           ,group
11352                           ',(delq nil (list
11353                                        (if del (list del 'add '(read)))
11354                                        (if add (list add 'del '(read))))))))))
11355             (set-buffer gnus-group-buffer)
11356             (gnus-undo-register
11357               `(progn
11358                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11359                  (gnus-info-set-read ',info ',(gnus-info-read info))
11360                  (gnus-get-unread-articles-in-group ',info
11361                                                     (gnus-active ,group))
11362                  (gnus-group-update-group ,group t)
11363                  ,setmarkundo))))
11364         ;; Enter this list into the group info.
11365         (gnus-info-set-read info read)
11366         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11367         (gnus-get-unread-articles-in-group info (gnus-active group))
11368         t))))
11369
11370 (defun gnus-offer-save-summaries ()
11371   "Offer to save all active summary buffers."
11372   (let (buffers)
11373     ;; Go through all buffers and find all summaries.
11374     (dolist (buffer (buffer-list))
11375       (when (and (setq buffer (buffer-name buffer))
11376                  (string-match "Summary" buffer)
11377                  (save-excursion
11378                    (set-buffer buffer)
11379                    ;; We check that this is, indeed, a summary buffer.
11380                    (and (eq major-mode 'gnus-summary-mode)
11381                         ;; Also make sure this isn't bogus.
11382                         gnus-newsgroup-prepared
11383                         ;; Also make sure that this isn't a
11384                         ;; dead summary buffer.
11385                         (not gnus-dead-summary-mode))))
11386         (push buffer buffers)))
11387     ;; Go through all these summary buffers and offer to save them.
11388     (when buffers
11389       (save-excursion
11390         (map-y-or-n-p
11391          "Update summary buffer %s? "
11392          (lambda (buf)
11393            (switch-to-buffer buf)
11394            (gnus-summary-exit))
11395          buffers)))))
11396
11397
11398 ;;; @ for mime-partial
11399 ;;;
11400
11401 (defun gnus-request-partial-message ()
11402   (save-excursion
11403     (let ((number (gnus-summary-article-number))
11404           (group gnus-newsgroup-name)
11405           (mother gnus-article-buffer))
11406       (set-buffer (get-buffer-create " *Partial Article*"))
11407       (erase-buffer)
11408       (setq mime-preview-buffer mother)
11409       (gnus-request-article-this-buffer number group)
11410       (mime-parse-buffer)
11411       )))
11412
11413 (autoload 'mime-combine-message/partial-pieces-automatically
11414   "mime-partial"
11415   "Internal method to combine message/partial messages automatically.")
11416
11417 (mime-add-condition
11418  'action '((type . message)(subtype . partial)
11419            (major-mode . gnus-original-article-mode)
11420            (method . mime-combine-message/partial-pieces-automatically)
11421            (summary-buffer-exp . gnus-summary-buffer)
11422            (request-partial-message-method . gnus-request-partial-message)
11423            ))
11424
11425
11426 ;;; @ for message/rfc822
11427 ;;;
11428
11429 (defun gnus-mime-extract-message/rfc822 (entity situation)
11430   "Burst a forwarded article."
11431   (save-excursion
11432     (set-buffer gnus-summary-buffer)
11433     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11434                                    gnus-newsgroup-name 'gnus-group-history))
11435            (gnus-group-marked (list group))
11436            article info)
11437       (with-temp-buffer
11438         (mime-insert-entity-content entity)
11439         (setq article (gnus-request-accept-article group)))
11440       (when (and (consp article)
11441                  (numberp (setq article (cdr article))))
11442         (setq info (gnus-get-info group))
11443         (gnus-info-set-read info
11444                             (gnus-remove-from-range (gnus-info-read info)
11445                                                     (list article)))
11446         (when (string-equal group gnus-newsgroup-name)
11447           (forward-line 1)
11448           (let (gnus-show-threads)
11449             (gnus-summary-goto-subject article t))
11450           (gnus-summary-clear-mark-forward 1))
11451         (set-buffer gnus-group-buffer)
11452         (gnus-group-get-new-news-this-group nil t)))))
11453
11454 (mime-add-condition
11455  'action '((type . message)(subtype . rfc822)
11456            (major-mode . gnus-original-article-mode)
11457            (method . gnus-mime-extract-message/rfc822)
11458            (mode . "extract")
11459            ))
11460
11461 (mime-add-condition
11462  'action '((type . message)(subtype . news)
11463            (major-mode . gnus-original-article-mode)
11464            (method . gnus-mime-extract-message/rfc822)
11465            (mode . "extract")
11466            ))
11467
11468 (defun gnus-mime-extract-multipart (entity situation)
11469   (let ((children (mime-entity-children entity))
11470         mime-acting-situation-to-override
11471         f)
11472     (while children
11473       (mime-play-entity (car children)
11474                         (cons (assq 'mode situation)
11475                               mime-acting-situation-to-override))
11476       (setq children (cdr children)))
11477     (if (setq f (cdr (assq 'after-method
11478                            mime-acting-situation-to-override)))
11479         (eval f)
11480       )))
11481
11482 (mime-add-condition
11483  'action '((type . multipart)
11484            (method . gnus-mime-extract-multipart)
11485            (mode . "extract")
11486            )
11487  'with-default)
11488
11489
11490 ;;; @ end
11491 ;;;
11492
11493 (defun gnus-summary-inherit-default-charset ()
11494   "Import `default-mime-charset' from summary buffer.
11495 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11496 of FLIM is used."
11497   (if (buffer-live-p gnus-summary-buffer)
11498       (let (d-m-c d-m-c-u)
11499         (with-current-buffer gnus-summary-buffer
11500           (setq d-m-c (if (local-variable-p 'default-mime-charset
11501                                             gnus-summary-buffer)
11502                           default-mime-charset
11503                         t)
11504                 ;; LIMIT
11505                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11506                                               gnus-summary-buffer)
11507                             (symbol-value 'default-mime-charset-unlimited)
11508                           t)))
11509         (if (eq t d-m-c)
11510             (kill-local-variable 'default-mime-charset)
11511           (set (make-local-variable 'default-mime-charset) d-m-c))
11512         (if (eq t d-m-c-u)
11513             (kill-local-variable 'default-mime-charset-unlimited)
11514           (set (make-local-variable 'default-mime-charset-unlimited)
11515                d-m-c-u)))))
11516
11517 (defun gnus-summary-setup-default-charset ()
11518   "Setup newsgroup default charset."
11519   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11520       (progn
11521         (setq gnus-newsgroup-charset nil)
11522         (set (make-local-variable 'default-mime-charset) nil)
11523         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11524           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11525     (let ((ignored-charsets
11526            (or gnus-newsgroup-ephemeral-ignored-charsets
11527                (append
11528                 (and gnus-newsgroup-name
11529                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11530                 gnus-newsgroup-ignored-charsets)))
11531           charset)
11532       (setq gnus-newsgroup-charset
11533             (or gnus-newsgroup-ephemeral-charset
11534                 (when (and gnus-newsgroup-name
11535                            (setq charset (gnus-parameter-charset
11536                                           gnus-newsgroup-name)))
11537                   (make-local-variable 'default-mime-charset)
11538                   (setq default-mime-charset charset))
11539                 gnus-default-charset))
11540       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11541            ignored-charsets))))
11542
11543 ;;;
11544 ;;; Mime Commands
11545 ;;;
11546
11547 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11548   "Display the current article buffer fully MIME-buttonized.
11549 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11550 treated as multipart/mixed."
11551   (interactive "P")
11552   (require 'gnus-art)
11553   (let ((gnus-unbuttonized-mime-types nil)
11554         (gnus-mime-display-multipart-as-mixed show-all-parts))
11555     (gnus-summary-show-article)))
11556
11557 (defun gnus-summary-repair-multipart (article)
11558   "Add a Content-Type header to a multipart article without one."
11559   (interactive (list (gnus-summary-article-number)))
11560   (gnus-with-article article
11561     (message-narrow-to-head)
11562     (message-remove-header "Mime-Version")
11563     (goto-char (point-max))
11564     (insert "Mime-Version: 1.0\n")
11565     (widen)
11566     (when (search-forward "\n--" nil t)
11567       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11568         (message-narrow-to-head)
11569         (message-remove-header "Content-Type")
11570         (goto-char (point-max))
11571         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11572                         separator))
11573         (widen))))
11574   (let (gnus-mark-article-hook)
11575     (gnus-summary-select-article t t nil article)))
11576
11577 (defun gnus-summary-toggle-display-buttonized ()
11578   "Toggle the buttonizing of the article buffer."
11579   (interactive)
11580   (require 'gnus-art)
11581   (if (setq gnus-inhibit-mime-unbuttonizing
11582             (not gnus-inhibit-mime-unbuttonizing))
11583       (let ((gnus-unbuttonized-mime-types nil))
11584         (gnus-summary-show-article))
11585     (gnus-summary-show-article)))
11586
11587 ;;;
11588 ;;; Intelli-mouse commmands
11589 ;;;
11590
11591 (defun gnus-wheel-summary-scroll (event)
11592   (interactive "e")
11593   (let ((amount (if (memq 'shift (event-modifiers event))
11594                     (car gnus-wheel-scroll-amount)
11595                   (cdr gnus-wheel-scroll-amount)))
11596         (direction (- (* (static-if (featurep 'xemacs)
11597                              (event-button event)
11598                            (cond ((eq 'mouse-4 (event-basic-type event))
11599                                   4)
11600                                  ((eq 'mouse-5 (event-basic-type event))
11601                                   5)))
11602                          2) 9))
11603         edge)
11604     (gnus-summary-scroll-up (* amount direction))
11605     (when (gnus-eval-in-buffer-window gnus-article-buffer
11606             (save-restriction
11607               (widen)
11608               (and (if (< 0 direction)
11609                        (gnus-article-next-page 0)
11610                      (gnus-article-prev-page 0)
11611                      (bobp))
11612                    (if (setq edge (get-text-property
11613                                    (point-min) 'gnus-wheel-edge))
11614                        (setq edge (* edge direction))
11615                      (setq edge -1))
11616                    (or (plusp edge)
11617                        (let ((buffer-read-only nil)
11618                              (inhibit-read-only t))
11619                          (put-text-property (point-min) (point-max)
11620                                             'gnus-wheel-edge direction)
11621                          nil))
11622                    (or (> edge gnus-wheel-edge-resistance)
11623                        (let ((buffer-read-only nil)
11624                              (inhibit-read-only t))
11625                          (put-text-property (point-min) (point-max)
11626                                             'gnus-wheel-edge
11627                                             (* (1+ edge) direction))
11628                          nil))
11629                    (eq last-command 'gnus-wheel-summary-scroll))))
11630       (gnus-summary-next-article nil nil (minusp direction)))))
11631
11632 (defun gnus-wheel-install ()
11633   "Enable mouse wheel support on summary window."
11634   (when gnus-use-wheel
11635     (let ((keys
11636            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11637       (dolist (key keys)
11638         (define-key gnus-summary-mode-map key
11639           'gnus-wheel-summary-scroll)))))
11640
11641 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11642
11643 ;;;
11644 ;;; Traditional PGP commmands
11645 ;;;
11646
11647 (defun gnus-summary-decrypt-article (&optional force)
11648   "Decrypt the current article in traditional PGP way.
11649 This will have permanent effect only in mail groups.
11650 If FORCE is non-nil, allow editing of articles even in read-only
11651 groups."
11652   (interactive "P")
11653   (gnus-summary-select-article t)
11654   (gnus-eval-in-buffer-window gnus-article-buffer
11655     (save-excursion
11656       (save-restriction
11657         (widen)
11658         (goto-char (point-min))
11659         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11660           (error "Not a traditional PGP message!"))
11661         (let ((armor-start (match-beginning 0)))
11662           (if (and (pgg-decrypt-region armor-start (point-max))
11663                    (or force (not (gnus-group-read-only-p))))
11664               (let ((inhibit-read-only t)
11665                     buffer-read-only)
11666                 (delete-region armor-start
11667                                (progn
11668                                  (re-search-forward "^-+END PGP" nil t)
11669                                  (beginning-of-line 2)
11670                                  (point)))
11671                 (insert-buffer-substring pgg-output-buffer))))))))
11672
11673 (defun gnus-summary-verify-article ()
11674   "Verify the current article in traditional PGP way."
11675   (interactive)
11676   (save-excursion
11677     (set-buffer gnus-original-article-buffer)
11678     (goto-char (point-min))
11679     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11680       (error "Not a traditional PGP message!"))
11681     (re-search-forward "^-+END PGP" nil t)
11682     (beginning-of-line 2)
11683     (call-interactively (function pgg-verify-region))))
11684
11685 ;;;
11686 ;;; Generic summary marking commands
11687 ;;;
11688
11689 (defvar gnus-summary-marking-alist
11690   '((read gnus-del-mark "d")
11691     (unread gnus-unread-mark "u")
11692     (ticked gnus-ticked-mark "!")
11693     (dormant gnus-dormant-mark "?")
11694     (expirable gnus-expirable-mark "e"))
11695   "An alist of names/marks/keystrokes.")
11696
11697 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11698 (defvar gnus-summary-mark-map)
11699
11700 (defun gnus-summary-make-all-marking-commands ()
11701   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11702   (dolist (elem gnus-summary-marking-alist)
11703     (apply 'gnus-summary-make-marking-command elem)))
11704
11705 (defun gnus-summary-make-marking-command (name mark keystroke)
11706   (let ((map (make-sparse-keymap)))
11707     (define-key gnus-summary-generic-mark-map keystroke map)
11708     (dolist (lway `((next "next" next nil "n")
11709                     (next-unread "next unread" next t "N")
11710                     (prev "previous" prev nil "p")
11711                     (prev-unread "previous unread" prev t "P")
11712                     (nomove "" nil nil ,keystroke)))
11713       (let ((func (gnus-summary-make-marking-command-1
11714                    mark (car lway) lway name)))
11715         (setq func (eval func))
11716         (define-key map (nth 4 lway) func)))))
11717
11718 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11719   `(defun ,(intern
11720             (format "gnus-summary-put-mark-as-%s%s"
11721                     name (if (eq way 'nomove)
11722                              ""
11723                            (concat "-" (symbol-name way)))))
11724      (n)
11725      ,(format
11726        "Mark the current article as %s%s.
11727 If N, the prefix, then repeat N times.
11728 If N is negative, move in reverse order.
11729 The difference between N and the actual number of articles marked is
11730 returned."
11731        name (car (cdr lway)))
11732      (interactive "p")
11733      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11734
11735 (defun gnus-summary-generic-mark (n mark move unread)
11736   "Mark N articles with MARK."
11737   (unless (eq major-mode 'gnus-summary-mode)
11738     (error "This command can only be used in the summary buffer"))
11739   (gnus-summary-show-thread)
11740   (let ((nummove
11741          (cond
11742           ((eq move 'next) 1)
11743           ((eq move 'prev) -1)
11744           (t 0))))
11745     (if (zerop nummove)
11746         (setq n 1)
11747       (when (< n 0)
11748         (setq n (abs n)
11749               nummove (* -1 nummove))))
11750     (while (and (> n 0)
11751                 (gnus-summary-mark-article nil mark)
11752                 (zerop (gnus-summary-next-subject nummove unread t)))
11753       (setq n (1- n)))
11754     (when (/= 0 n)
11755       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11756     (gnus-summary-recenter)
11757     (gnus-summary-position-point)
11758     (gnus-set-mode-line 'summary)
11759     n))
11760
11761 (defun gnus-summary-insert-articles (articles)
11762   (when (setq articles
11763               (gnus-sorted-difference articles
11764                                       (mapcar (lambda (h)
11765                                                 (mail-header-number h))
11766                                               gnus-newsgroup-headers)))
11767     (setq gnus-newsgroup-headers
11768           (gnus-merge 'list
11769                       gnus-newsgroup-headers
11770                       (gnus-fetch-headers articles)
11771                       'gnus-article-sort-by-number))
11772     ;; Suppress duplicates?
11773     (when gnus-suppress-duplicates
11774       (gnus-dup-suppress-articles))
11775
11776     ;; We might want to build some more threads first.
11777     (when (and gnus-fetch-old-headers
11778                (eq gnus-headers-retrieved-by 'nov))
11779       (if (eq gnus-fetch-old-headers 'invisible)
11780           (gnus-build-all-threads)
11781         (gnus-build-old-threads)))
11782     ;; Let the Gnus agent mark articles as read.
11783     (when gnus-agent
11784       (gnus-agent-get-undownloaded-list))
11785     ;; Remove list identifiers from subject
11786     (when gnus-list-identifiers
11787       (gnus-summary-remove-list-identifiers))
11788     ;; First and last article in this newsgroup.
11789     (when gnus-newsgroup-headers
11790       (setq gnus-newsgroup-begin
11791             (mail-header-number (car gnus-newsgroup-headers))
11792             gnus-newsgroup-end
11793             (mail-header-number
11794              (gnus-last-element gnus-newsgroup-headers))))
11795     (when gnus-use-scoring
11796       (gnus-possibly-score-headers))))
11797
11798 (defun gnus-summary-insert-old-articles (&optional all)
11799   "Insert all old articles in this group.
11800 If ALL is non-nil, already read articles become readable.
11801 If ALL is a number, fetch this number of articles."
11802   (interactive "P")
11803   (prog1
11804       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11805             older len)
11806         (setq older
11807               ;; Some nntp servers lie about their active range.  When
11808               ;; this happens, the active range can be in the millions.
11809               ;; Use a compressed range to avoid creating a huge list.
11810               (gnus-range-difference (list gnus-newsgroup-active) old))
11811         (setq len (gnus-range-length older))
11812         (cond
11813          ((null older) nil)
11814          ((numberp all)
11815           (if (< all len)
11816               (let ((older-range (nreverse older)))
11817                 (setq older nil)
11818
11819                 (while (> all 0)
11820                   (let* ((r (pop older-range))
11821                          (min (if (numberp r) r (car r)))
11822                          (max (if (numberp r) r (cdr r))))
11823                     (while (and (<= min max)
11824                                 (> all 0))
11825                       (push max older)
11826                       (setq all (1- all)
11827                             max (1- max))))))
11828             (setq older (gnus-uncompress-range older))))
11829          (all
11830           (setq older (gnus-uncompress-range older)))
11831          (t
11832           (when (and (numberp gnus-large-newsgroup)
11833                    (> len gnus-large-newsgroup))
11834               (let* ((cursor-in-echo-area nil)
11835                      (initial (gnus-parameter-large-newsgroup-initial
11836                                gnus-newsgroup-name))
11837                      (input
11838                       (read-string
11839                        (format
11840                         "How many articles from %s (%s %d): "
11841                         (gnus-limit-string
11842                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11843                         (if initial "max" "default")
11844                         len)
11845                        (if initial
11846                            (cons (number-to-string initial)
11847                                  0)))))
11848                 (unless (string-match "^[ \t]*$" input)
11849                   (setq all (string-to-number input))
11850                   (if (< all len)
11851                       (let ((older-range (nreverse older)))
11852                         (setq older nil)
11853
11854                         (while (> all 0)
11855                           (let* ((r (pop older-range))
11856                                  (min (if (numberp r) r (car r)))
11857                                  (max (if (numberp r) r (cdr r))))
11858                             (while (and (<= min max)
11859                                         (> all 0))
11860                               (push max older)
11861                               (setq all (1- all)
11862                                     max (1- max))))))))))
11863           (setq older (gnus-uncompress-range older))))
11864         (if (not older)
11865             (message "No old news.")
11866           (gnus-summary-insert-articles older)
11867           (gnus-summary-limit (gnus-sorted-nunion old older))))
11868     (gnus-summary-position-point)))
11869
11870 (defun gnus-summary-insert-new-articles ()
11871   "Insert all new articles in this group."
11872   (interactive)
11873   (prog1
11874       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11875             (old-active gnus-newsgroup-active)
11876             (nnmail-fetched-sources (list t))
11877             i new)
11878         (setq gnus-newsgroup-active
11879               (gnus-activate-group gnus-newsgroup-name 'scan))
11880         (setq i (cdr gnus-newsgroup-active))
11881         (while (> i (cdr old-active))
11882           (push i new)
11883           (decf i))
11884         (if (not new)
11885             (message "No gnus is bad news.")
11886           (gnus-summary-insert-articles new)
11887           (setq gnus-newsgroup-unreads
11888                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11889           (gnus-summary-limit (gnus-sorted-nunion old new))))
11890     (gnus-summary-position-point)))
11891
11892 (gnus-summary-make-all-marking-commands)
11893
11894 (gnus-ems-redefine)
11895
11896 (provide 'gnus-sum)
11897
11898 (run-hooks 'gnus-sum-load-hook)
11899
11900 ;; Local Variables:
11901 ;; coding: iso-8859-1
11902 ;; End:
11903
11904 ;;; gnus-sum.el ends here