Synch to Gnus 200305161606.
[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 (defvar gnus-summary-use-undownloaded-faces nil)
1281
1282 (defvar gnus-newsgroup-unreads nil
1283   "Sorted list of unread articles in the current newsgroup.")
1284
1285 (defvar gnus-newsgroup-unselected nil
1286   "Sorted list of unselected unread articles in the current newsgroup.")
1287
1288 (defvar gnus-newsgroup-reads nil
1289   "Alist of read articles and article marks in the current newsgroup.")
1290
1291 (defvar gnus-newsgroup-expunged-tally nil)
1292
1293 (defvar gnus-newsgroup-marked nil
1294   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1295
1296 (defvar gnus-newsgroup-spam-marked nil
1297   "List of ranges of articles that have been marked as spam.")
1298
1299 (defvar gnus-newsgroup-killed nil
1300   "List of ranges of articles that have been through the scoring process.")
1301
1302 (defvar gnus-newsgroup-cached nil
1303   "Sorted list of articles that come from the article cache.")
1304
1305 (defvar gnus-newsgroup-saved nil
1306   "List of articles that have been saved.")
1307
1308 (defvar gnus-newsgroup-kill-headers nil)
1309
1310 (defvar gnus-newsgroup-replied nil
1311   "List of articles that have been replied to in the current newsgroup.")
1312
1313 (defvar gnus-newsgroup-forwarded nil
1314   "List of articles that have been forwarded in the current newsgroup.")
1315
1316 (defvar gnus-newsgroup-recent nil
1317   "List of articles that have are recent in the current newsgroup.")
1318
1319 (defvar gnus-newsgroup-expirable nil
1320   "Sorted list of articles in the current newsgroup that can be expired.")
1321
1322 (defvar gnus-newsgroup-processable nil
1323   "List of articles in the current newsgroup that can be processed.")
1324
1325 (defvar gnus-newsgroup-downloadable nil
1326   "Sorted list of articles in the current newsgroup that can be processed.")
1327
1328 (defvar gnus-newsgroup-unfetched nil
1329   "Sorted list of articles in the current newsgroup whose headers have
1330 not been fetched into the agent.
1331
1332 This list will always be a subset of gnus-newsgroup-undownloaded.")
1333
1334 (defvar gnus-newsgroup-undownloaded nil
1335   "List of articles in the current newsgroup that haven't been downloaded.")
1336
1337 (defvar gnus-newsgroup-unsendable nil
1338   "List of articles in the current newsgroup that won't be sent.")
1339
1340 (defvar gnus-newsgroup-bookmarks nil
1341   "List of articles in the current newsgroup that have bookmarks.")
1342
1343 (defvar gnus-newsgroup-dormant nil
1344   "Sorted list of dormant articles in the current newsgroup.")
1345
1346 (defvar gnus-newsgroup-unseen nil
1347   "List of unseen articles in the current newsgroup.")
1348
1349 (defvar gnus-newsgroup-seen nil
1350   "Range of seen articles in the current newsgroup.")
1351
1352 (defvar gnus-newsgroup-articles nil
1353   "List of articles in the current newsgroup.")
1354
1355 (defvar gnus-newsgroup-scored nil
1356   "List of scored articles in the current newsgroup.")
1357
1358 (defvar gnus-newsgroup-incorporated nil
1359   "List of incorporated articles in the current newsgroup.")
1360
1361 (defvar gnus-newsgroup-headers nil
1362   "List of article headers in the current newsgroup.")
1363
1364 (defvar gnus-newsgroup-threads nil)
1365
1366 (defvar gnus-newsgroup-prepared nil
1367   "Whether the current group has been prepared properly.")
1368
1369 (defvar gnus-newsgroup-ancient nil
1370   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1371
1372 (defvar gnus-newsgroup-sparse nil)
1373
1374 (defvar gnus-current-article nil)
1375 (defvar gnus-article-current nil)
1376 (defvar gnus-current-headers nil)
1377 (defvar gnus-have-all-headers nil)
1378 (defvar gnus-last-article nil)
1379 (defvar gnus-newsgroup-history nil)
1380 (defvar gnus-newsgroup-charset nil)
1381 (defvar gnus-newsgroup-ephemeral-charset nil)
1382 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1383
1384 (defvar gnus-article-before-search nil)
1385
1386 (defvar gnus-summary-local-variables
1387   '(gnus-newsgroup-name
1388     gnus-newsgroup-begin gnus-newsgroup-end
1389     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1390     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1391     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1392     gnus-newsgroup-unselected gnus-newsgroup-marked
1393     gnus-newsgroup-spam-marked
1394     gnus-newsgroup-reads gnus-newsgroup-saved
1395     gnus-newsgroup-replied gnus-newsgroup-forwarded
1396     gnus-newsgroup-recent
1397     gnus-newsgroup-expirable
1398     gnus-newsgroup-processable gnus-newsgroup-killed
1399     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1400     gnus-newsgroup-unfetched
1401     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1402     gnus-newsgroup-seen gnus-newsgroup-articles
1403     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1404     gnus-newsgroup-headers gnus-newsgroup-threads
1405     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1406     gnus-current-article gnus-current-headers gnus-have-all-headers
1407     gnus-last-article gnus-article-internal-prepare-hook
1408     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1409     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1410     gnus-thread-expunge-below
1411     gnus-score-alist gnus-current-score-file
1412     (gnus-summary-expunge-below . global)
1413     (gnus-summary-mark-below . global)
1414     (gnus-orphan-score . global)
1415     gnus-newsgroup-active gnus-scores-exclude-files
1416     gnus-newsgroup-history gnus-newsgroup-ancient
1417     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1418     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1419     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1420     (gnus-newsgroup-expunged-tally . 0)
1421     gnus-cache-removable-articles gnus-newsgroup-cached
1422     gnus-newsgroup-data gnus-newsgroup-data-reverse
1423     gnus-newsgroup-limit gnus-newsgroup-limits
1424     gnus-newsgroup-charset gnus-newsgroup-display
1425     gnus-summary-use-undownloaded-faces
1426     gnus-newsgroup-incorporated)
1427   "Variables that are buffer-local to the summary buffers.")
1428
1429 (defvar gnus-newsgroup-variables nil
1430   "A list of variables that have separate values in different newsgroups.
1431 A list of newsgroup (summary buffer) local variables, or cons of
1432 variables and their default values (when the default values are not
1433 nil), that should be made global while the summary buffer is active.
1434 These variables can be used to set variables in the group parameters
1435 while still allowing them to affect operations done in other
1436 buffers. For example:
1437
1438 \(setq gnus-newsgroup-variables
1439      '(message-use-followup-to
1440        (gnus-visible-headers .
1441          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1442 ")
1443
1444 ;; Byte-compiler warning.
1445 (eval-when-compile
1446   ;; Bind features so that require will believe that gnus-sum has
1447   ;; already been loaded (avoids infinite recursion)
1448   (let ((features (cons 'gnus-sum features)))
1449     ;; Several of the declarations in gnus-sum are needed to load the
1450     ;; following files. Right now, these definitions have been
1451     ;; compiled but not defined (evaluated).  We could either do a
1452     ;; eval-and-compile about all of the declarations or evaluate the
1453     ;; source file.
1454     (if (boundp 'gnus-newsgroup-variables)
1455         nil
1456       (load "gnus-sum.el" t t t))
1457     (require 'gnus)
1458     (require 'gnus-agent)
1459     (require 'gnus-art)))
1460
1461 ;; Subject simplification.
1462
1463 (defun gnus-simplify-whitespace (str)
1464   "Remove excessive whitespace from STR."
1465   ;; Multiple spaces.
1466   (while (string-match "[ \t][ \t]+" str)
1467     (setq str (concat (substring str 0 (match-beginning 0))
1468                         " "
1469                         (substring str (match-end 0)))))
1470   ;; Leading spaces.
1471   (when (string-match "^[ \t]+" str)
1472     (setq str (substring str (match-end 0))))
1473   ;; Trailing spaces.
1474   (when (string-match "[ \t]+$" str)
1475     (setq str (substring str 0 (match-beginning 0))))
1476   str)
1477
1478 (defun gnus-simplify-all-whitespace (str)
1479   "Remove all whitespace from STR."
1480   (while (string-match "[ \t\n]+" str)
1481     (setq str (replace-match "" nil nil str)))
1482   str)
1483
1484 (defsubst gnus-simplify-subject-re (subject)
1485   "Remove \"Re:\" from subject lines."
1486   (if (string-match message-subject-re-regexp subject)
1487       (substring subject (match-end 0))
1488     subject))
1489
1490 (defun gnus-simplify-subject (subject &optional re-only)
1491   "Remove `Re:' and words in parentheses.
1492 If RE-ONLY is non-nil, strip leading `Re:'s only."
1493   (let ((case-fold-search t))           ;Ignore case.
1494     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1495     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1496       (setq subject (substring subject (match-end 0))))
1497     ;; Remove uninteresting prefixes.
1498     (when (and (not re-only)
1499                gnus-simplify-ignored-prefixes
1500                (string-match gnus-simplify-ignored-prefixes subject))
1501       (setq subject (substring subject (match-end 0))))
1502     ;; Remove words in parentheses from end.
1503     (unless re-only
1504       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1505         (setq subject (substring subject 0 (match-beginning 0)))))
1506     ;; Return subject string.
1507     subject))
1508
1509 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1510 ;; all whitespace.
1511 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1512   (goto-char (point-min))
1513   (while (re-search-forward regexp nil t)
1514     (replace-match (or newtext ""))))
1515
1516 (defun gnus-simplify-buffer-fuzzy ()
1517   "Simplify string in the buffer fuzzily.
1518 The string in the accessible portion of the current buffer is simplified.
1519 It is assumed to be a single-line subject.
1520 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1521 matter is removed.  Additional things can be deleted by setting
1522 `gnus-simplify-subject-fuzzy-regexp'."
1523   (let ((case-fold-search t)
1524         (modified-tick))
1525     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1526
1527     (while (not (eq modified-tick (buffer-modified-tick)))
1528       (setq modified-tick (buffer-modified-tick))
1529       (cond
1530        ((listp gnus-simplify-subject-fuzzy-regexp)
1531         (mapcar 'gnus-simplify-buffer-fuzzy-step
1532                 gnus-simplify-subject-fuzzy-regexp))
1533        (gnus-simplify-subject-fuzzy-regexp
1534         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1535       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1536       (gnus-simplify-buffer-fuzzy-step
1537        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1538       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1539
1540     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1541     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1542     (gnus-simplify-buffer-fuzzy-step " $")
1543     (gnus-simplify-buffer-fuzzy-step "^ +")))
1544
1545 (defun gnus-simplify-subject-fuzzy (subject)
1546   "Simplify a subject string fuzzily.
1547 See `gnus-simplify-buffer-fuzzy' for details."
1548   (save-excursion
1549     (gnus-set-work-buffer)
1550     (let ((case-fold-search t))
1551       ;; Remove uninteresting prefixes.
1552       (when (and gnus-simplify-ignored-prefixes
1553                  (string-match gnus-simplify-ignored-prefixes subject))
1554         (setq subject (substring subject (match-end 0))))
1555       (insert subject)
1556       (inline (gnus-simplify-buffer-fuzzy))
1557       (buffer-string))))
1558
1559 (defsubst gnus-simplify-subject-fully (subject)
1560   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1561   (cond
1562    (gnus-simplify-subject-functions
1563     (gnus-map-function gnus-simplify-subject-functions subject))
1564    ((null gnus-summary-gather-subject-limit)
1565     (gnus-simplify-subject-re subject))
1566    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1567     (gnus-simplify-subject-fuzzy subject))
1568    ((numberp gnus-summary-gather-subject-limit)
1569     (gnus-limit-string (gnus-simplify-subject-re subject)
1570                        gnus-summary-gather-subject-limit))
1571    (t
1572     subject)))
1573
1574 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1575   "Check whether two subjects are equal.
1576 If optional argument SIMPLE-FIRST is t, first argument is already
1577 simplified."
1578   (cond
1579    ((null simple-first)
1580     (equal (gnus-simplify-subject-fully s1)
1581            (gnus-simplify-subject-fully s2)))
1582    (t
1583     (equal s1
1584            (gnus-simplify-subject-fully s2)))))
1585
1586 (defun gnus-summary-bubble-group ()
1587   "Increase the score of the current group.
1588 This is a handy function to add to `gnus-summary-exit-hook' to
1589 increase the score of each group you read."
1590   (gnus-group-add-score gnus-newsgroup-name))
1591
1592 \f
1593 ;;;
1594 ;;; Gnus summary mode
1595 ;;;
1596
1597 (put 'gnus-summary-mode 'mode-class 'special)
1598
1599 (defvar gnus-article-commands-menu)
1600
1601 ;; Non-orthogonal keys
1602
1603 (gnus-define-keys gnus-summary-mode-map
1604   " " gnus-summary-next-page
1605   "\177" gnus-summary-prev-page
1606   [delete] gnus-summary-prev-page
1607   [backspace] gnus-summary-prev-page
1608   "\r" gnus-summary-scroll-up
1609   "\M-\r" gnus-summary-scroll-down
1610   "n" gnus-summary-next-unread-article
1611   "p" gnus-summary-prev-unread-article
1612   "N" gnus-summary-next-article
1613   "P" gnus-summary-prev-article
1614   "\M-\C-n" gnus-summary-next-same-subject
1615   "\M-\C-p" gnus-summary-prev-same-subject
1616   "\M-n" gnus-summary-next-unread-subject
1617   "\M-p" gnus-summary-prev-unread-subject
1618   "." gnus-summary-first-unread-article
1619   "," gnus-summary-best-unread-article
1620   "\M-s" gnus-summary-search-article-forward
1621   "\M-r" gnus-summary-search-article-backward
1622   "<" gnus-summary-beginning-of-article
1623   ">" gnus-summary-end-of-article
1624   "j" gnus-summary-goto-article
1625   "^" gnus-summary-refer-parent-article
1626   "\M-^" gnus-summary-refer-article
1627   "u" gnus-summary-tick-article-forward
1628   "!" gnus-summary-tick-article-forward
1629   "U" gnus-summary-tick-article-backward
1630   "d" gnus-summary-mark-as-read-forward
1631   "D" gnus-summary-mark-as-read-backward
1632   "E" gnus-summary-mark-as-expirable
1633   "\M-u" gnus-summary-clear-mark-forward
1634   "\M-U" gnus-summary-clear-mark-backward
1635   "k" gnus-summary-kill-same-subject-and-select
1636   "\C-k" gnus-summary-kill-same-subject
1637   "\M-\C-k" gnus-summary-kill-thread
1638   "\M-\C-l" gnus-summary-lower-thread
1639   "e" gnus-summary-edit-article
1640   "#" gnus-summary-mark-as-processable
1641   "\M-#" gnus-summary-unmark-as-processable
1642   "\M-\C-t" gnus-summary-toggle-threads
1643   "\M-\C-s" gnus-summary-show-thread
1644   "\M-\C-h" gnus-summary-hide-thread
1645   "\M-\C-f" gnus-summary-next-thread
1646   "\M-\C-b" gnus-summary-prev-thread
1647   [(meta down)] gnus-summary-next-thread
1648   [(meta up)] gnus-summary-prev-thread
1649   "\M-\C-u" gnus-summary-up-thread
1650   "\M-\C-d" gnus-summary-down-thread
1651   "&" gnus-summary-execute-command
1652   "c" gnus-summary-catchup-and-exit
1653   "\C-w" gnus-summary-mark-region-as-read
1654   "\C-t" gnus-summary-toggle-truncation
1655   "?" gnus-summary-mark-as-dormant
1656   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1657   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1658   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1659   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1660   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1661   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1662   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1663   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1664   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1665   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1666   "=" gnus-summary-expand-window
1667   "\C-x\C-s" gnus-summary-reselect-current-group
1668   "\M-g" gnus-summary-rescan-group
1669   "w" gnus-summary-stop-page-breaking
1670   "\C-c\C-r" gnus-summary-caesar-message
1671   "\M-t" gnus-summary-toggle-mime
1672   "f" gnus-summary-followup
1673   "F" gnus-summary-followup-with-original
1674   "C" gnus-summary-cancel-article
1675   "r" gnus-summary-reply
1676   "R" gnus-summary-reply-with-original
1677   "\C-c\C-f" gnus-summary-mail-forward
1678   "o" gnus-summary-save-article
1679   "\C-o" gnus-summary-save-article-mail
1680   "|" gnus-summary-pipe-output
1681   "\M-k" gnus-summary-edit-local-kill
1682   "\M-K" gnus-summary-edit-global-kill
1683   ;; "V" gnus-version
1684   "\C-c\C-d" gnus-summary-describe-group
1685   "q" gnus-summary-exit
1686   "Q" gnus-summary-exit-no-update
1687   "\C-c\C-i" gnus-info-find-node
1688   gnus-mouse-2 gnus-mouse-pick-article
1689   "m" gnus-summary-mail-other-window
1690   "a" gnus-summary-post-news
1691   "i" gnus-summary-news-other-window
1692   "x" gnus-summary-limit-to-unread
1693   "s" gnus-summary-isearch-article
1694   "t" gnus-summary-toggle-header
1695   "g" gnus-summary-show-article
1696   "l" gnus-summary-goto-last-article
1697   "v" gnus-summary-preview-mime-message
1698   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1699   "\C-d" gnus-summary-enter-digest-group
1700   "\M-\C-d" gnus-summary-read-document
1701   "\M-\C-e" gnus-summary-edit-parameters
1702   "\M-\C-a" gnus-summary-customize-parameters
1703   "\C-c\C-b" gnus-bug
1704   "\C-c\C-n" gnus-namazu-search
1705   "*" gnus-cache-enter-article
1706   "\M-*" gnus-cache-remove-article
1707   "\M-&" gnus-summary-universal-argument
1708   "\C-l" gnus-recenter
1709   "I" gnus-summary-increase-score
1710   "L" gnus-summary-lower-score
1711   "\M-i" gnus-symbolic-argument
1712   "h" gnus-summary-select-article-buffer
1713
1714   "V" gnus-summary-score-map
1715   "X" gnus-uu-extract-map
1716   "S" gnus-summary-send-map)
1717
1718   ;; Sort of orthogonal keymap
1719 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1720   "t" gnus-summary-tick-article-forward
1721   "!" gnus-summary-tick-article-forward
1722   "d" gnus-summary-mark-as-read-forward
1723   "r" gnus-summary-mark-as-read-forward
1724   "c" gnus-summary-clear-mark-forward
1725   " " gnus-summary-clear-mark-forward
1726   "e" gnus-summary-mark-as-expirable
1727   "x" gnus-summary-mark-as-expirable
1728   "?" gnus-summary-mark-as-dormant
1729   "b" gnus-summary-set-bookmark
1730   "B" gnus-summary-remove-bookmark
1731   "#" gnus-summary-mark-as-processable
1732   "\M-#" gnus-summary-unmark-as-processable
1733   "S" gnus-summary-limit-include-expunged
1734   "C" gnus-summary-catchup
1735   "H" gnus-summary-catchup-to-here
1736   "h" gnus-summary-catchup-from-here
1737   "\C-c" gnus-summary-catchup-all
1738   "k" gnus-summary-kill-same-subject-and-select
1739   "K" gnus-summary-kill-same-subject
1740   "P" gnus-uu-mark-map)
1741
1742 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1743   "c" gnus-summary-clear-above
1744   "u" gnus-summary-tick-above
1745   "m" gnus-summary-mark-above
1746   "k" gnus-summary-kill-below)
1747
1748 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1749   "/" gnus-summary-limit-to-subject
1750   "n" gnus-summary-limit-to-articles
1751   "w" gnus-summary-pop-limit
1752   "s" gnus-summary-limit-to-subject
1753   "a" gnus-summary-limit-to-author
1754   "u" gnus-summary-limit-to-unread
1755   "m" gnus-summary-limit-to-marks
1756   "M" gnus-summary-limit-exclude-marks
1757   "v" gnus-summary-limit-to-score
1758   "*" gnus-summary-limit-include-cached
1759   "D" gnus-summary-limit-include-dormant
1760   "T" gnus-summary-limit-include-thread
1761   "d" gnus-summary-limit-exclude-dormant
1762   "t" gnus-summary-limit-to-age
1763   "." gnus-summary-limit-to-unseen
1764   "x" gnus-summary-limit-to-extra
1765   "p" gnus-summary-limit-to-display-predicate
1766   "E" gnus-summary-limit-include-expunged
1767   "c" gnus-summary-limit-exclude-childless-dormant
1768   "C" gnus-summary-limit-mark-excluded-as-read
1769   "o" gnus-summary-insert-old-articles
1770   "N" gnus-summary-insert-new-articles)
1771
1772 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1773   "n" gnus-summary-next-unread-article
1774   "p" gnus-summary-prev-unread-article
1775   "N" gnus-summary-next-article
1776   "P" gnus-summary-prev-article
1777   "\C-n" gnus-summary-next-same-subject
1778   "\C-p" gnus-summary-prev-same-subject
1779   "\M-n" gnus-summary-next-unread-subject
1780   "\M-p" gnus-summary-prev-unread-subject
1781   "f" gnus-summary-first-unread-article
1782   "b" gnus-summary-best-unread-article
1783   "j" gnus-summary-goto-article
1784   "g" gnus-summary-goto-subject
1785   "l" gnus-summary-goto-last-article
1786   "o" gnus-summary-pop-article)
1787
1788 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1789   "k" gnus-summary-kill-thread
1790   "l" gnus-summary-lower-thread
1791   "i" gnus-summary-raise-thread
1792   "T" gnus-summary-toggle-threads
1793   "t" gnus-summary-rethread-current
1794   "^" gnus-summary-reparent-thread
1795   "s" gnus-summary-show-thread
1796   "S" gnus-summary-show-all-threads
1797   "h" gnus-summary-hide-thread
1798   "H" gnus-summary-hide-all-threads
1799   "n" gnus-summary-next-thread
1800   "p" gnus-summary-prev-thread
1801   "u" gnus-summary-up-thread
1802   "o" gnus-summary-top-thread
1803   "d" gnus-summary-down-thread
1804   "#" gnus-uu-mark-thread
1805   "\M-#" gnus-uu-unmark-thread)
1806
1807 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1808   "g" gnus-summary-prepare
1809   "c" gnus-summary-insert-cached-articles
1810   "d" gnus-summary-insert-dormant-articles)
1811
1812 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1813   "c" gnus-summary-catchup-and-exit
1814   "C" gnus-summary-catchup-all-and-exit
1815   "E" gnus-summary-exit-no-update
1816   "J" gnus-summary-jump-to-other-group
1817   "Q" gnus-summary-exit
1818   "Z" gnus-summary-exit
1819   "n" gnus-summary-catchup-and-goto-next-group
1820   "R" gnus-summary-reselect-current-group
1821   "G" gnus-summary-rescan-group
1822   "N" gnus-summary-next-group
1823   "s" gnus-summary-save-newsrc
1824   "P" gnus-summary-prev-group)
1825
1826 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1827   " " gnus-summary-next-page
1828   "n" gnus-summary-next-page
1829   "\177" gnus-summary-prev-page
1830   [delete] gnus-summary-prev-page
1831   "p" gnus-summary-prev-page
1832   "\r" gnus-summary-scroll-up
1833   "\M-\r" gnus-summary-scroll-down
1834   "<" gnus-summary-beginning-of-article
1835   ">" gnus-summary-end-of-article
1836   "b" gnus-summary-beginning-of-article
1837   "e" gnus-summary-end-of-article
1838   "^" gnus-summary-refer-parent-article
1839   "r" gnus-summary-refer-parent-article
1840   "D" gnus-summary-enter-digest-group
1841   "R" gnus-summary-refer-references
1842   "T" gnus-summary-refer-thread
1843   "g" gnus-summary-show-article
1844   "s" gnus-summary-isearch-article
1845   "P" gnus-summary-print-article
1846   "M" gnus-mailing-list-insinuate
1847   "t" gnus-article-babel)
1848
1849 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1850   "b" gnus-article-add-buttons
1851   "B" gnus-article-add-buttons-to-head
1852   "o" gnus-article-treat-overstrike
1853   "e" gnus-article-emphasize
1854   "w" gnus-article-fill-cited-article
1855   "Q" gnus-article-fill-long-lines
1856   "C" gnus-article-capitalize-sentences
1857   "c" gnus-article-remove-cr
1858   "Z" gnus-article-decode-HZ
1859   "h" gnus-article-wash-html
1860   "u" gnus-article-unsplit-urls
1861   "f" gnus-article-display-x-face
1862   "l" gnus-summary-stop-page-breaking
1863   "r" gnus-summary-caesar-message
1864   "m" gnus-summary-morse-message
1865   "t" gnus-summary-toggle-header
1866   "g" gnus-treat-smiley
1867   "v" gnus-summary-verbose-headers
1868   "m" gnus-summary-toggle-mime
1869   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1870   "p" gnus-article-verify-x-pgp-sig
1871   "d" gnus-article-treat-dumbquotes)
1872
1873 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1874   ;; mnemonic: deuglif*Y*
1875   "u" gnus-article-outlook-unwrap-lines
1876   "a" gnus-article-outlook-repair-attribution
1877   "c" gnus-article-outlook-rearrange-citation
1878   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1879
1880 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1881   "a" gnus-article-hide
1882   "h" gnus-article-hide-headers
1883   "b" gnus-article-hide-boring-headers
1884   "s" gnus-article-hide-signature
1885   "c" gnus-article-hide-citation
1886   "C" gnus-article-hide-citation-in-followups
1887   "l" gnus-article-hide-list-identifiers
1888   "B" gnus-article-strip-banner
1889   "P" gnus-article-hide-pem
1890   "\C-c" gnus-article-hide-citation-maybe)
1891
1892 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1893   "a" gnus-article-highlight
1894   "h" gnus-article-highlight-headers
1895   "c" gnus-article-highlight-citation
1896   "s" gnus-article-highlight-signature)
1897
1898 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1899   "f" gnus-article-treat-fold-headers
1900   "u" gnus-article-treat-unfold-headers
1901   "n" gnus-article-treat-fold-newsgroups)
1902
1903 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1904   "x" gnus-article-display-x-face
1905   "d" gnus-article-display-face
1906   "s" gnus-treat-smiley
1907   "D" gnus-article-remove-images
1908   "f" gnus-treat-from-picon
1909   "m" gnus-treat-mail-picon
1910   "n" gnus-treat-newsgroups-picon)
1911
1912 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1913   "z" gnus-article-date-ut
1914   "u" gnus-article-date-ut
1915   "l" gnus-article-date-local
1916   "p" gnus-article-date-english
1917   "e" gnus-article-date-lapsed
1918   "o" gnus-article-date-original
1919   "i" gnus-article-date-iso8601
1920   "s" gnus-article-date-user)
1921
1922 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1923   "t" gnus-article-remove-trailing-blank-lines
1924   "l" gnus-article-strip-leading-blank-lines
1925   "m" gnus-article-strip-multiple-blank-lines
1926   "a" gnus-article-strip-blank-lines
1927   "A" gnus-article-strip-all-blank-lines
1928   "s" gnus-article-strip-leading-space
1929   "e" gnus-article-strip-trailing-space
1930   "w" gnus-article-remove-leading-whitespace)
1931
1932 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1933   "v" gnus-version
1934   "f" gnus-summary-fetch-faq
1935   "d" gnus-summary-describe-group
1936   "h" gnus-summary-describe-briefly
1937   "i" gnus-info-find-node
1938   "c" gnus-group-fetch-charter
1939   "C" gnus-group-fetch-control)
1940
1941 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1942   "e" gnus-summary-expire-articles
1943   "\M-\C-e" gnus-summary-expire-articles-now
1944   "\177" gnus-summary-delete-article
1945   [delete] gnus-summary-delete-article
1946   [backspace] gnus-summary-delete-article
1947   "m" gnus-summary-move-article
1948   "r" gnus-summary-respool-article
1949   "w" gnus-summary-edit-article
1950   "c" gnus-summary-copy-article
1951   "B" gnus-summary-crosspost-article
1952   "q" gnus-summary-respool-query
1953   "t" gnus-summary-respool-trace
1954   "i" gnus-summary-import-article
1955   "I" gnus-summary-create-article
1956   "p" gnus-summary-article-posted-p)
1957
1958 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1959   "o" gnus-summary-save-article
1960   "m" gnus-summary-save-article-mail
1961   "F" gnus-summary-write-article-file
1962   "r" gnus-summary-save-article-rmail
1963   "f" gnus-summary-save-article-file
1964   "b" gnus-summary-save-article-body-file
1965   "h" gnus-summary-save-article-folder
1966   "v" gnus-summary-save-article-vm
1967   "p" gnus-summary-pipe-output
1968   "P" gnus-summary-muttprint
1969   "s" gnus-soup-add-article)
1970
1971 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1972   "b" gnus-summary-display-buttonized
1973   "m" gnus-summary-repair-multipart
1974   "v" gnus-article-view-part
1975   "o" gnus-article-save-part
1976   "c" gnus-article-copy-part
1977   "C" gnus-article-view-part-as-charset
1978   "e" gnus-article-view-part-externally
1979   "E" gnus-article-encrypt-body
1980   "i" gnus-article-inline-part
1981   "|" gnus-article-pipe-part)
1982
1983 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1984   "p" gnus-summary-mark-as-processable
1985   "u" gnus-summary-unmark-as-processable
1986   "U" gnus-summary-unmark-all-processable
1987   "v" gnus-uu-mark-over
1988   "s" gnus-uu-mark-series
1989   "r" gnus-uu-mark-region
1990   "g" gnus-uu-unmark-region
1991   "R" gnus-uu-mark-by-regexp
1992   "G" gnus-uu-unmark-by-regexp
1993   "t" gnus-uu-mark-thread
1994   "T" gnus-uu-unmark-thread
1995   "a" gnus-uu-mark-all
1996   "b" gnus-uu-mark-buffer
1997   "S" gnus-uu-mark-sparse
1998   "k" gnus-summary-kill-process-mark
1999   "y" gnus-summary-yank-process-mark
2000   "w" gnus-summary-save-process-mark
2001   "i" gnus-uu-invert-processable)
2002
2003 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2004   ;;"x" gnus-uu-extract-any
2005   "m" gnus-summary-save-parts
2006   "u" gnus-uu-decode-uu
2007   "U" gnus-uu-decode-uu-and-save
2008   "s" gnus-uu-decode-unshar
2009   "S" gnus-uu-decode-unshar-and-save
2010   "o" gnus-uu-decode-save
2011   "O" gnus-uu-decode-save
2012   "b" gnus-uu-decode-binhex
2013   "B" gnus-uu-decode-binhex
2014   "p" gnus-uu-decode-postscript
2015   "P" gnus-uu-decode-postscript-and-save)
2016
2017 (gnus-define-keys
2018     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2019   "u" gnus-uu-decode-uu-view
2020   "U" gnus-uu-decode-uu-and-save-view
2021   "s" gnus-uu-decode-unshar-view
2022   "S" gnus-uu-decode-unshar-and-save-view
2023   "o" gnus-uu-decode-save-view
2024   "O" gnus-uu-decode-save-view
2025   "b" gnus-uu-decode-binhex-view
2026   "B" gnus-uu-decode-binhex-view
2027   "p" gnus-uu-decode-postscript-view
2028   "P" gnus-uu-decode-postscript-and-save-view)
2029
2030 (defvar gnus-article-post-menu nil)
2031
2032 (defconst gnus-summary-menu-maxlen 20)
2033
2034 (defun gnus-summary-menu-split (menu)
2035   ;; If we have lots of elements, divide them into groups of 20
2036   ;; and make a pane (or submenu) for each one.
2037   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2038       (let ((menu menu) sublists next
2039             (i 1))
2040         (while menu
2041           ;; Pull off the next gnus-summary-menu-maxlen elements
2042           ;; and make them the next element of sublist.
2043           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2044           (if next
2045               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2046                       nil))
2047           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2048                                              (aref (car (last menu)) 0)) menu)
2049                                sublists))
2050           (setq i (1+ i))
2051           (setq menu next))
2052         (nreverse sublists))
2053     ;; Few elements--put them all in one pane.
2054     menu))
2055
2056 (defun gnus-summary-make-menu-bar ()
2057   (gnus-turn-off-edit-menu 'summary)
2058
2059   (unless (boundp 'gnus-summary-misc-menu)
2060
2061     (easy-menu-define
2062      gnus-summary-kill-menu gnus-summary-mode-map ""
2063      (cons
2064       "Score"
2065       (nconc
2066        (list
2067         ["Customize" gnus-score-customize t])
2068        (gnus-make-score-map 'increase)
2069        (gnus-make-score-map 'lower)
2070        '(("Mark"
2071           ["Kill below" gnus-summary-kill-below t]
2072           ["Mark above" gnus-summary-mark-above t]
2073           ["Tick above" gnus-summary-tick-above t]
2074           ["Clear above" gnus-summary-clear-above t])
2075          ["Current score" gnus-summary-current-score t]
2076          ["Set score" gnus-summary-set-score t]
2077          ["Switch current score file..." gnus-score-change-score-file t]
2078          ["Set mark below..." gnus-score-set-mark-below t]
2079          ["Set expunge below..." gnus-score-set-expunge-below t]
2080          ["Edit current score file" gnus-score-edit-current-scores t]
2081          ["Edit score file" gnus-score-edit-file t]
2082          ["Trace score" gnus-score-find-trace t]
2083          ["Find words" gnus-score-find-favourite-words t]
2084          ["Rescore buffer" gnus-summary-rescore t]
2085          ["Increase score..." gnus-summary-increase-score t]
2086          ["Lower score..." gnus-summary-lower-score t]))))
2087
2088     ;; Define both the Article menu in the summary buffer and the
2089     ;; equivalent Commands menu in the article buffer here for
2090     ;; consistency.
2091     (let ((innards
2092            `(("Hide"
2093               ["All" gnus-article-hide t]
2094               ["Headers" gnus-article-hide-headers t]
2095               ["Signature" gnus-article-hide-signature t]
2096               ["Citation" gnus-article-hide-citation t]
2097               ["List identifiers" gnus-article-hide-list-identifiers t]
2098               ["Banner" gnus-article-strip-banner t]
2099               ["Boring headers" gnus-article-hide-boring-headers t])
2100              ("Highlight"
2101               ["All" gnus-article-highlight t]
2102               ["Headers" gnus-article-highlight-headers t]
2103               ["Signature" gnus-article-highlight-signature t]
2104               ["Citation" gnus-article-highlight-citation t])
2105              ("Date"
2106               ["Local" gnus-article-date-local t]
2107               ["ISO8601" gnus-article-date-iso8601 t]
2108               ["UT" gnus-article-date-ut t]
2109               ["Original" gnus-article-date-original t]
2110               ["Lapsed" gnus-article-date-lapsed t]
2111               ["User-defined" gnus-article-date-user t])
2112              ("Display"
2113               ["Remove images" gnus-article-remove-images t]
2114               ["Toggle smiley" gnus-treat-smiley t]
2115               ["Show X-Face" gnus-article-display-x-face t]
2116               ["Show picons in From" gnus-treat-from-picon t]
2117               ["Show picons in mail headers" gnus-treat-mail-picon t]
2118               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2119               ("View as different encoding"
2120                ,@(gnus-summary-menu-split
2121                   (mapcar
2122                    (lambda (cs)
2123                      ;; Since easymenu under Emacs doesn't allow
2124                      ;; lambda forms for menu commands, we should
2125                      ;; provide intern'ed function symbols.
2126                      (let ((command (intern (format "\
2127 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2128                        (fset command
2129                              `(lambda ()
2130                                 (interactive)
2131                                 (let ((gnus-summary-show-article-charset-alist
2132                                        '((1 . ,cs))))
2133                                   (gnus-summary-show-article 1))))
2134                        `[,(symbol-name cs) ,command t]))
2135                    (sort (if (fboundp 'coding-system-list)
2136                              (coding-system-list)
2137                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2138                            )
2139                          'string<)))))
2140              ("Washing"
2141               ("Remove Blanks"
2142                ["Leading" gnus-article-strip-leading-blank-lines t]
2143                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2144                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2145                ["All of the above" gnus-article-strip-blank-lines t]
2146                ["All" gnus-article-strip-all-blank-lines t]
2147                ["Leading space" gnus-article-strip-leading-space t]
2148                ["Trailing space" gnus-article-strip-trailing-space t]
2149                ["Leading space in headers"
2150                 gnus-article-remove-leading-whitespace t])
2151               ["Overstrike" gnus-article-treat-overstrike t]
2152               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2153               ["Emphasis" gnus-article-emphasize t]
2154               ["Word wrap" gnus-article-fill-cited-article t]
2155               ["Fill long lines" gnus-article-fill-long-lines t]
2156               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2157               ["CR" gnus-article-remove-cr t]
2158               ["Rot 13" gnus-summary-caesar-message
2159                ,@(if (featurep 'xemacs) '(t)
2160                    '(:help "\"Caesar rotate\" article by 13"))]
2161               ["Morse decode" gnus-summary-morse-message t]
2162               ["Unix pipe..." gnus-summary-pipe-message t]
2163               ["Add buttons" gnus-article-add-buttons t]
2164               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2165               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2166               ["Toggle MIME" gnus-summary-toggle-mime t]
2167               ["Verbose header" gnus-summary-verbose-headers t]
2168               ["Toggle header" gnus-summary-toggle-header t]
2169               ["Unfold headers" gnus-article-treat-unfold-headers t]
2170               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2171               ["Html" gnus-article-wash-html t]
2172               ["URLs" gnus-article-unsplit-urls t]
2173               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2174               ["HZ" gnus-article-decode-HZ t]
2175               ("(Outlook) Deuglify"
2176                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2177                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2178                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2179                ["Full (Outlook) deuglify"
2180                 gnus-article-outlook-deuglify-article t])
2181               )
2182              ("Output"
2183               ["Save in default format" gnus-summary-save-article
2184                ,@(if (featurep 'xemacs) '(t)
2185                    '(:help "Save article using default method"))]
2186               ["Save in file" gnus-summary-save-article-file
2187                ,@(if (featurep 'xemacs) '(t)
2188                    '(:help "Save article in file"))]
2189               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2190               ["Save in MH folder" gnus-summary-save-article-folder t]
2191               ["Save in VM folder" gnus-summary-save-article-vm t]
2192               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2193               ["Save body in file" gnus-summary-save-article-body-file t]
2194               ["Pipe through a filter" gnus-summary-pipe-output t]
2195               ["Add to SOUP packet" gnus-soup-add-article t]
2196               ["Print with Muttprint" gnus-summary-muttprint t]
2197               ["Print" gnus-summary-print-article t])
2198              ("Backend"
2199               ["Respool article..." gnus-summary-respool-article t]
2200               ["Move article..." gnus-summary-move-article
2201                (gnus-check-backend-function
2202                 'request-move-article gnus-newsgroup-name)]
2203               ["Copy article..." gnus-summary-copy-article t]
2204               ["Crosspost article..." gnus-summary-crosspost-article
2205                (gnus-check-backend-function
2206                 'request-replace-article gnus-newsgroup-name)]
2207               ["Import file..." gnus-summary-import-article
2208                (gnus-check-backend-function
2209                 'request-accept-article gnus-newsgroup-name)]
2210               ["Create article..." gnus-summary-create-article
2211                (gnus-check-backend-function
2212                 'request-accept-article gnus-newsgroup-name)]
2213               ["Check if posted" gnus-summary-article-posted-p t]
2214               ["Edit article" gnus-summary-edit-article
2215                (not (gnus-group-read-only-p))]
2216               ["Delete article" gnus-summary-delete-article
2217                (gnus-check-backend-function
2218                 'request-expire-articles gnus-newsgroup-name)]
2219               ["Query respool" gnus-summary-respool-query t]
2220               ["Trace respool" gnus-summary-respool-trace t]
2221               ["Delete expirable articles" gnus-summary-expire-articles-now
2222                (gnus-check-backend-function
2223                 'request-expire-articles gnus-newsgroup-name)])
2224              ("Extract"
2225               ["Uudecode" gnus-uu-decode-uu
2226                ,@(if (featurep 'xemacs) '(t)
2227                    '(:help "Decode uuencoded article(s)"))]
2228               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2229               ["Unshar" gnus-uu-decode-unshar t]
2230               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2231               ["Save" gnus-uu-decode-save t]
2232               ["Binhex" gnus-uu-decode-binhex t]
2233               ["Postscript" gnus-uu-decode-postscript t])
2234              ("Cache"
2235               ["Enter article" gnus-cache-enter-article t]
2236               ["Remove article" gnus-cache-remove-article t])
2237              ["Translate" gnus-article-babel t]
2238              ["Select article buffer" gnus-summary-select-article-buffer t]
2239              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2240              ["Isearch article..." gnus-summary-isearch-article t]
2241              ["Beginning of the article" gnus-summary-beginning-of-article t]
2242              ["End of the article" gnus-summary-end-of-article t]
2243              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2244              ["Fetch referenced articles" gnus-summary-refer-references t]
2245              ["Fetch current thread" gnus-summary-refer-thread t]
2246              ["Fetch article with id..." gnus-summary-refer-article t]
2247              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2248              ["Redisplay" gnus-summary-show-article t]
2249              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2250       (easy-menu-define
2251        gnus-summary-article-menu gnus-summary-mode-map ""
2252        (cons "Article" innards))
2253
2254       (if (not (keymapp gnus-summary-article-menu))
2255           (easy-menu-define
2256            gnus-article-commands-menu gnus-article-mode-map ""
2257            (cons "Commands" innards))
2258         ;; in Emacs, don't share menu.
2259         (setq gnus-article-commands-menu
2260               (copy-keymap gnus-summary-article-menu))
2261         (define-key gnus-article-mode-map [menu-bar commands]
2262           (cons "Commands" gnus-article-commands-menu))))
2263
2264     (easy-menu-define
2265      gnus-summary-thread-menu gnus-summary-mode-map ""
2266      '("Threads"
2267        ["Find all messages in thread" gnus-summary-refer-thread t]
2268        ["Toggle threading" gnus-summary-toggle-threads t]
2269        ["Hide threads" gnus-summary-hide-all-threads t]
2270        ["Show threads" gnus-summary-show-all-threads t]
2271        ["Hide thread" gnus-summary-hide-thread t]
2272        ["Show thread" gnus-summary-show-thread t]
2273        ["Go to next thread" gnus-summary-next-thread t]
2274        ["Go to previous thread" gnus-summary-prev-thread t]
2275        ["Go down thread" gnus-summary-down-thread t]
2276        ["Go up thread" gnus-summary-up-thread t]
2277        ["Top of thread" gnus-summary-top-thread t]
2278        ["Mark thread as read" gnus-summary-kill-thread t]
2279        ["Lower thread score" gnus-summary-lower-thread t]
2280        ["Raise thread score" gnus-summary-raise-thread t]
2281        ["Rethread current" gnus-summary-rethread-current t]))
2282
2283     (easy-menu-define
2284      gnus-summary-post-menu gnus-summary-mode-map ""
2285      `("Post"
2286        ["Send a message (mail or news)" gnus-summary-post-news
2287         ,@(if (featurep 'xemacs) '(t)
2288             '(:help "Post an article"))]
2289        ["Followup" gnus-summary-followup
2290         ,@(if (featurep 'xemacs) '(t)
2291             '(:help "Post followup to this article"))]
2292        ["Followup and yank" gnus-summary-followup-with-original
2293         ,@(if (featurep 'xemacs) '(t)
2294             '(:help "Post followup to this article, quoting its contents"))]
2295        ["Supersede article" gnus-summary-supersede-article t]
2296        ["Cancel article" gnus-summary-cancel-article
2297         ,@(if (featurep 'xemacs) '(t)
2298             '(:help "Cancel an article you posted"))]
2299        ["Reply" gnus-summary-reply t]
2300        ["Reply and yank" gnus-summary-reply-with-original t]
2301        ["Wide reply" gnus-summary-wide-reply t]
2302        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2303         ,@(if (featurep 'xemacs) '(t)
2304             '(:help "Mail a reply, quoting this article"))]
2305        ["Very wide reply" gnus-summary-very-wide-reply t]
2306        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2307         ,@(if (featurep 'xemacs) '(t)
2308             '(:help "Mail a very wide reply, quoting this article"))]
2309        ["Mail forward" gnus-summary-mail-forward t]
2310        ["Post forward" gnus-summary-post-forward t]
2311        ["Digest and mail" gnus-summary-digest-mail-forward t]
2312        ["Digest and post" gnus-summary-digest-post-forward t]
2313        ["Resend message" gnus-summary-resend-message t]
2314        ["Resend message edit" gnus-summary-resend-message-edit t]
2315        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2316        ["Send a mail" gnus-summary-mail-other-window t]
2317        ["Create a local message" gnus-summary-news-other-window t]
2318        ["Uuencode and post" gnus-uu-post-news
2319         ,@(if (featurep 'xemacs) '(t)
2320             '(:help "Post a uuencoded article"))]
2321        ["Followup via news" gnus-summary-followup-to-mail t]
2322        ["Followup via news and yank"
2323         gnus-summary-followup-to-mail-with-original t]
2324        ;;("Draft"
2325        ;;["Send" gnus-summary-send-draft t]
2326        ;;["Send bounced" gnus-resend-bounced-mail t])
2327        ))
2328
2329     (cond
2330      ((not (keymapp gnus-summary-post-menu))
2331       (setq gnus-article-post-menu gnus-summary-post-menu))
2332      ((not gnus-article-post-menu)
2333       ;; Don't share post menu.
2334       (setq gnus-article-post-menu
2335             (copy-keymap gnus-summary-post-menu))))
2336     (define-key gnus-article-mode-map [menu-bar post]
2337       (cons "Post" gnus-article-post-menu))
2338
2339     (easy-menu-define
2340      gnus-summary-misc-menu gnus-summary-mode-map ""
2341      `("Gnus"
2342        ("Mark Read"
2343         ["Mark as read" gnus-summary-mark-as-read-forward t]
2344         ["Mark same subject and select"
2345          gnus-summary-kill-same-subject-and-select t]
2346         ["Mark same subject" gnus-summary-kill-same-subject t]
2347         ["Catchup" gnus-summary-catchup
2348          ,@(if (featurep 'xemacs) '(t)
2349              '(:help "Mark unread articles in this group as read"))]
2350         ["Catchup all" gnus-summary-catchup-all t]
2351         ["Catchup to here" gnus-summary-catchup-to-here t]
2352         ["Catchup from here" gnus-summary-catchup-from-here t]
2353         ["Catchup region" gnus-summary-mark-region-as-read
2354          (gnus-mark-active-p)]
2355         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2356        ("Mark Various"
2357         ["Tick" gnus-summary-tick-article-forward t]
2358         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2359         ["Remove marks" gnus-summary-clear-mark-forward t]
2360         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2361         ["Set bookmark" gnus-summary-set-bookmark t]
2362         ["Remove bookmark" gnus-summary-remove-bookmark t])
2363        ("Limit to"
2364         ["Marks..." gnus-summary-limit-to-marks t]
2365         ["Subject..." gnus-summary-limit-to-subject t]
2366         ["Author..." gnus-summary-limit-to-author t]
2367         ["Age..." gnus-summary-limit-to-age t]
2368         ["Extra..." gnus-summary-limit-to-extra t]
2369         ["Score..." gnus-summary-limit-to-score t]
2370         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2371         ["Unread" gnus-summary-limit-to-unread t]
2372         ["Unseen" gnus-summary-limit-to-unseen t]
2373         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2374         ["Next articles" gnus-summary-limit-to-articles t]
2375         ["Pop limit" gnus-summary-pop-limit t]
2376         ["Show dormant" gnus-summary-limit-include-dormant t]
2377         ["Hide childless dormant"
2378          gnus-summary-limit-exclude-childless-dormant t]
2379         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2380         ["Hide marked" gnus-summary-limit-exclude-marks t]
2381         ["Show expunged" gnus-summary-limit-include-expunged t])
2382        ("Process Mark"
2383         ["Set mark" gnus-summary-mark-as-processable t]
2384         ["Remove mark" gnus-summary-unmark-as-processable t]
2385         ["Remove all marks" gnus-summary-unmark-all-processable t]
2386         ["Mark above" gnus-uu-mark-over t]
2387         ["Mark series" gnus-uu-mark-series t]
2388         ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2389         ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2390         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2391         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2392         ["Mark all" gnus-uu-mark-all t]
2393         ["Mark buffer" gnus-uu-mark-buffer t]
2394         ["Mark sparse" gnus-uu-mark-sparse t]
2395         ["Mark thread" gnus-uu-mark-thread t]
2396         ["Unmark thread" gnus-uu-unmark-thread t]
2397         ("Process Mark Sets"
2398          ["Kill" gnus-summary-kill-process-mark t]
2399          ["Yank" gnus-summary-yank-process-mark
2400           gnus-newsgroup-process-stack]
2401          ["Save" gnus-summary-save-process-mark t]
2402          ["Run command on marked..." gnus-summary-universal-argument t]))
2403        ("Scroll article"
2404         ["Page forward" gnus-summary-next-page
2405          ,@(if (featurep 'xemacs) '(t)
2406              '(:help "Show next page of article"))]
2407         ["Page backward" gnus-summary-prev-page
2408          ,@(if (featurep 'xemacs) '(t)
2409              '(:help "Show previous page of article"))]
2410         ["Line forward" gnus-summary-scroll-up t])
2411        ("Move"
2412         ["Next unread article" gnus-summary-next-unread-article t]
2413         ["Previous unread article" gnus-summary-prev-unread-article t]
2414         ["Next article" gnus-summary-next-article t]
2415         ["Previous article" gnus-summary-prev-article t]
2416         ["Next unread subject" gnus-summary-next-unread-subject t]
2417         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2418         ["Next article same subject" gnus-summary-next-same-subject t]
2419         ["Previous article same subject" gnus-summary-prev-same-subject t]
2420         ["First unread article" gnus-summary-first-unread-article t]
2421         ["Best unread article" gnus-summary-best-unread-article t]
2422         ["Go to subject number..." gnus-summary-goto-subject t]
2423         ["Go to article number..." gnus-summary-goto-article t]
2424         ["Go to the last article" gnus-summary-goto-last-article t]
2425         ["Pop article off history" gnus-summary-pop-article t])
2426        ("Sort"
2427         ["Sort by number" gnus-summary-sort-by-number t]
2428         ["Sort by author" gnus-summary-sort-by-author t]
2429         ["Sort by subject" gnus-summary-sort-by-subject t]
2430         ["Sort by date" gnus-summary-sort-by-date t]
2431         ["Sort by score" gnus-summary-sort-by-score t]
2432         ["Sort by lines" gnus-summary-sort-by-lines t]
2433         ["Sort by characters" gnus-summary-sort-by-chars t]
2434         ["Randomize" gnus-summary-sort-by-random t]
2435         ["Original sort" gnus-summary-sort-by-original t])
2436        ("Help"
2437         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2438         ["Describe group" gnus-summary-describe-group t]
2439         ["Fetch charter" gnus-group-fetch-charter
2440          ,@(if (featurep 'xemacs) nil
2441              '(:help "Display the charter of the current group"))]
2442         ["Fetch control message" gnus-group-fetch-control
2443          ,@(if (featurep 'xemacs) nil
2444              '(:help "Display the archived control message for the current group"))]
2445         ["Read manual" gnus-info-find-node t])
2446        ("Modes"
2447         ["Pick and read" gnus-pick-mode t]
2448         ["Binary" gnus-binary-mode t])
2449        ("Regeneration"
2450         ["Regenerate" gnus-summary-prepare t]
2451         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2452         ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2453         ["Toggle threading" gnus-summary-toggle-threads t])
2454        ["See old articles" gnus-summary-insert-old-articles t]
2455        ["See new articles" gnus-summary-insert-new-articles t]
2456        ["Filter articles..." gnus-summary-execute-command t]
2457        ["Run command on articles..." gnus-summary-universal-argument t]
2458        ["Search articles forward..." gnus-summary-search-article-forward t]
2459        ["Search articles backward..." gnus-summary-search-article-backward t]
2460        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2461        ["Expand window" gnus-summary-expand-window t]
2462        ["Expire expirable articles" gnus-summary-expire-articles
2463         (gnus-check-backend-function
2464          'request-expire-articles gnus-newsgroup-name)]
2465        ["Edit local kill file" gnus-summary-edit-local-kill t]
2466        ["Edit main kill file" gnus-summary-edit-global-kill t]
2467        ["Edit group parameters" gnus-summary-edit-parameters t]
2468        ["Customize group parameters" gnus-summary-customize-parameters t]
2469        ["Send a bug report" gnus-bug t]
2470        ("Exit"
2471         ["Catchup and exit" gnus-summary-catchup-and-exit
2472          ,@(if (featurep 'xemacs) '(t)
2473              '(:help "Mark unread articles in this group as read, then exit"))]
2474         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2475         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2476         ["Exit group" gnus-summary-exit
2477          ,@(if (featurep 'xemacs) '(t)
2478              '(:help "Exit current group, return to group selection mode"))]
2479         ["Exit group without updating" gnus-summary-exit-no-update t]
2480         ["Exit and goto next group" gnus-summary-next-group t]
2481         ["Exit and goto prev group" gnus-summary-prev-group t]
2482         ["Reselect group" gnus-summary-reselect-current-group t]
2483         ["Rescan group" gnus-summary-rescan-group t]
2484         ["Update dribble" gnus-summary-save-newsrc t])))
2485
2486     (gnus-run-hooks 'gnus-summary-menu-hook)))
2487
2488 (defvar gnus-summary-tool-bar-map nil)
2489
2490 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2491 (defun gnus-summary-make-tool-bar ()
2492   (if (and (fboundp 'tool-bar-add-item-from-menu)
2493            (default-value 'tool-bar-mode)
2494            (not gnus-summary-tool-bar-map))
2495       (setq gnus-summary-tool-bar-map
2496             (let ((tool-bar-map (make-sparse-keymap))
2497                   (load-path (mm-image-load-path)))
2498               (tool-bar-add-item-from-menu
2499                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2500               (tool-bar-add-item-from-menu
2501                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2502               (tool-bar-add-item-from-menu
2503                'gnus-summary-post-news "post" gnus-summary-mode-map)
2504               (tool-bar-add-item-from-menu
2505                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2506               (tool-bar-add-item-from-menu
2507                'gnus-summary-followup "followup" gnus-summary-mode-map)
2508               (tool-bar-add-item-from-menu
2509                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2510               (tool-bar-add-item-from-menu
2511                'gnus-summary-reply "reply" gnus-summary-mode-map)
2512               (tool-bar-add-item-from-menu
2513                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2514               (tool-bar-add-item-from-menu
2515                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2516               (tool-bar-add-item-from-menu
2517                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2518               (tool-bar-add-item-from-menu
2519                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2520               (tool-bar-add-item-from-menu
2521                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2522               (tool-bar-add-item-from-menu
2523                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2524               (tool-bar-add-item-from-menu
2525                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2526               (tool-bar-add-item-from-menu
2527                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2528               tool-bar-map)))
2529   (if gnus-summary-tool-bar-map
2530       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2531
2532 (defun gnus-score-set-default (var value)
2533   "A version of set that updates the GNU Emacs menu-bar."
2534   (set var value)
2535   ;; It is the message that forces the active status to be updated.
2536   (message ""))
2537
2538 (defun gnus-make-score-map (type)
2539   "Make a summary score map of type TYPE."
2540   (if t
2541       nil
2542     (let ((headers '(("author" "from" string)
2543                      ("subject" "subject" string)
2544                      ("article body" "body" string)
2545                      ("article head" "head" string)
2546                      ("xref" "xref" string)
2547                      ("extra header" "extra" string)
2548                      ("lines" "lines" number)
2549                      ("followups to author" "followup" string)))
2550           (types '((number ("less than" <)
2551                            ("greater than" >)
2552                            ("equal" =))
2553                    (string ("substring" s)
2554                            ("exact string" e)
2555                            ("fuzzy string" f)
2556                            ("regexp" r))))
2557           (perms '(("temporary" (current-time-string))
2558                    ("permanent" nil)
2559                    ("immediate" now)))
2560           header)
2561       (list
2562        (apply
2563         'nconc
2564         (list
2565          (if (eq type 'lower)
2566              "Lower score"
2567            "Increase score"))
2568         (let (outh)
2569           (while headers
2570             (setq header (car headers))
2571             (setq outh
2572                   (cons
2573                    (apply
2574                     'nconc
2575                     (list (car header))
2576                     (let ((ts (cdr (assoc (nth 2 header) types)))
2577                           outt)
2578                       (while ts
2579                         (setq outt
2580                               (cons
2581                                (apply
2582                                 'nconc
2583                                 (list (caar ts))
2584                                 (let ((ps perms)
2585                                       outp)
2586                                   (while ps
2587                                     (setq outp
2588                                           (cons
2589                                            (vector
2590                                             (caar ps)
2591                                             (list
2592                                              'gnus-summary-score-entry
2593                                              (nth 1 header)
2594                                              (if (or (string= (nth 1 header)
2595                                                               "head")
2596                                                      (string= (nth 1 header)
2597                                                               "body"))
2598                                                  ""
2599                                                (list 'gnus-summary-header
2600                                                      (nth 1 header)))
2601                                              (list 'quote (nth 1 (car ts)))
2602                                              (list 'gnus-score-delta-default
2603                                                    nil)
2604                                              (nth 1 (car ps))
2605                                              t)
2606                                             t)
2607                                            outp))
2608                                     (setq ps (cdr ps)))
2609                                   (list (nreverse outp))))
2610                                outt))
2611                         (setq ts (cdr ts)))
2612                       (list (nreverse outt))))
2613                    outh))
2614             (setq headers (cdr headers)))
2615           (list (nreverse outh))))))))
2616
2617 \f
2618
2619 (defun gnus-summary-mode (&optional group)
2620   "Major mode for reading articles.
2621
2622 All normal editing commands are switched off.
2623 \\<gnus-summary-mode-map>
2624 Each line in this buffer represents one article.  To read an
2625 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2626 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2627 respectively.
2628
2629 You can also post articles and send mail from this buffer.  To
2630 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2631 of an article, type `\\[gnus-summary-reply]'.
2632
2633 There are approx. one gazillion commands you can execute in this
2634 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2635
2636 The following commands are available:
2637
2638 \\{gnus-summary-mode-map}"
2639   (interactive)
2640   (kill-all-local-variables)
2641   (when (gnus-visual-p 'summary-menu 'menu)
2642     (gnus-summary-make-menu-bar)
2643     (gnus-summary-make-tool-bar))
2644   (gnus-summary-make-local-variables)
2645   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2646     (gnus-summary-make-local-variables))
2647   (gnus-make-thread-indent-array)
2648   (gnus-simplify-mode-line)
2649   (setq major-mode 'gnus-summary-mode)
2650   (setq mode-name "Summary")
2651   (make-local-variable 'minor-mode-alist)
2652   (use-local-map gnus-summary-mode-map)
2653   (buffer-disable-undo)
2654   (setq buffer-read-only t)             ;Disable modification
2655   (setq truncate-lines t)
2656   (setq selective-display t)
2657   (setq selective-display-ellipses t)   ;Display `...'
2658   (gnus-summary-set-display-table)
2659   (gnus-set-default-directory)
2660   (setq gnus-newsgroup-name group)
2661   (unless (gnus-news-group-p group)
2662     (setq gnus-newsgroup-incorporated
2663           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2664   (make-local-variable 'gnus-summary-line-format)
2665   (make-local-variable 'gnus-summary-line-format-spec)
2666   (make-local-variable 'gnus-summary-dummy-line-format)
2667   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2668   (make-local-variable 'gnus-summary-mark-positions)
2669   (gnus-make-local-hook 'pre-command-hook)
2670   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2671   (gnus-run-hooks 'gnus-summary-mode-hook)
2672   (turn-on-gnus-mailing-list-mode)
2673   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2674   (gnus-update-summary-mark-positions))
2675
2676 (defun gnus-summary-make-local-variables ()
2677   "Make all the local summary buffer variables."
2678   (let (global)
2679     (dolist (local gnus-summary-local-variables)
2680       (if (consp local)
2681           (progn
2682             (if (eq (cdr local) 'global)
2683                 ;; Copy the global value of the variable.
2684                 (setq global (symbol-value (car local)))
2685               ;; Use the value from the list.
2686               (setq global (eval (cdr local))))
2687             (set (make-local-variable (car local)) global))
2688         ;; Simple nil-valued local variable.
2689         (set (make-local-variable local) nil)))))
2690
2691 (defun gnus-summary-clear-local-variables ()
2692   (let ((locals gnus-summary-local-variables))
2693     (while locals
2694       (if (consp (car locals))
2695           (and (vectorp (caar locals))
2696                (set (caar locals) nil))
2697         (and (vectorp (car locals))
2698              (set (car locals) nil)))
2699       (setq locals (cdr locals)))))
2700
2701 ;; Summary data functions.
2702
2703 (defmacro gnus-data-number (data)
2704   `(car ,data))
2705
2706 (defmacro gnus-data-set-number (data number)
2707   `(setcar ,data ,number))
2708
2709 (defmacro gnus-data-mark (data)
2710   `(nth 1 ,data))
2711
2712 (defmacro gnus-data-set-mark (data mark)
2713   `(setcar (nthcdr 1 ,data) ,mark))
2714
2715 (defmacro gnus-data-pos (data)
2716   `(nth 2 ,data))
2717
2718 (defmacro gnus-data-set-pos (data pos)
2719   `(setcar (nthcdr 2 ,data) ,pos))
2720
2721 (defmacro gnus-data-header (data)
2722   `(nth 3 ,data))
2723
2724 (defmacro gnus-data-set-header (data header)
2725   `(setcar (nthcdr 3 ,data) ,header))
2726
2727 (defmacro gnus-data-level (data)
2728   `(nth 4 ,data))
2729
2730 (defmacro gnus-data-unread-p (data)
2731   `(= (nth 1 ,data) gnus-unread-mark))
2732
2733 (defmacro gnus-data-read-p (data)
2734   `(/= (nth 1 ,data) gnus-unread-mark))
2735
2736 (defmacro gnus-data-pseudo-p (data)
2737   `(consp (nth 3 ,data)))
2738
2739 (defmacro gnus-data-find (number)
2740   `(assq ,number gnus-newsgroup-data))
2741
2742 (defmacro gnus-data-find-list (number &optional data)
2743   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2744      (memq (assq ,number bdata)
2745            bdata)))
2746
2747 (defmacro gnus-data-make (number mark pos header level)
2748   `(list ,number ,mark ,pos ,header ,level))
2749
2750 (defun gnus-data-enter (after-article number mark pos header level offset)
2751   (let ((data (gnus-data-find-list after-article)))
2752     (unless data
2753       (error "No such article: %d" after-article))
2754     (setcdr data (cons (gnus-data-make number mark pos header level)
2755                        (cdr data)))
2756     (setq gnus-newsgroup-data-reverse nil)
2757     (gnus-data-update-list (cddr data) offset)))
2758
2759 (defun gnus-data-enter-list (after-article list &optional offset)
2760   (when list
2761     (let ((data (and after-article (gnus-data-find-list after-article)))
2762           (ilist list))
2763       (if (not (or data
2764                    after-article))
2765           (let ((odata gnus-newsgroup-data))
2766             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2767             (when offset
2768               (gnus-data-update-list odata offset)))
2769         ;; Find the last element in the list to be spliced into the main
2770         ;; list.
2771         (while (cdr list)
2772           (setq list (cdr list)))
2773         (if (not data)
2774             (progn
2775               (setcdr list gnus-newsgroup-data)
2776               (setq gnus-newsgroup-data ilist)
2777               (when offset
2778                 (gnus-data-update-list (cdr list) offset)))
2779           (setcdr list (cdr data))
2780           (setcdr data ilist)
2781           (when offset
2782             (gnus-data-update-list (cdr list) offset))))
2783       (setq gnus-newsgroup-data-reverse nil))))
2784
2785 (defun gnus-data-remove (article &optional offset)
2786   (let ((data gnus-newsgroup-data))
2787     (if (= (gnus-data-number (car data)) article)
2788         (progn
2789           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2790                 gnus-newsgroup-data-reverse nil)
2791           (when offset
2792             (gnus-data-update-list gnus-newsgroup-data offset)))
2793       (while (cdr data)
2794         (when (= (gnus-data-number (cadr data)) article)
2795           (setcdr data (cddr data))
2796           (when offset
2797             (gnus-data-update-list (cdr data) offset))
2798           (setq data nil
2799                 gnus-newsgroup-data-reverse nil))
2800         (setq data (cdr data))))))
2801
2802 (defmacro gnus-data-list (backward)
2803   `(if ,backward
2804        (or gnus-newsgroup-data-reverse
2805            (setq gnus-newsgroup-data-reverse
2806                  (reverse gnus-newsgroup-data)))
2807      gnus-newsgroup-data))
2808
2809 (defun gnus-data-update-list (data offset)
2810   "Add OFFSET to the POS of all data entries in DATA."
2811   (setq gnus-newsgroup-data-reverse nil)
2812   (while data
2813     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2814     (setq data (cdr data))))
2815
2816 (defun gnus-summary-article-pseudo-p (article)
2817   "Say whether this article is a pseudo article or not."
2818   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2819
2820 (defmacro gnus-summary-article-sparse-p (article)
2821   "Say whether this article is a sparse article or not."
2822   `(memq ,article gnus-newsgroup-sparse))
2823
2824 (defmacro gnus-summary-article-ancient-p (article)
2825   "Say whether this article is a sparse article or not."
2826   `(memq ,article gnus-newsgroup-ancient))
2827
2828 (defun gnus-article-parent-p (number)
2829   "Say whether this article is a parent or not."
2830   (let ((data (gnus-data-find-list number)))
2831     (and (cdr data)                     ; There has to be an article after...
2832          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2833             (gnus-data-level (nth 1 data))))))
2834
2835 (defun gnus-article-children (number)
2836   "Return a list of all children to NUMBER."
2837   (let* ((data (gnus-data-find-list number))
2838          (level (gnus-data-level (car data)))
2839          children)
2840     (setq data (cdr data))
2841     (while (and data
2842                 (= (gnus-data-level (car data)) (1+ level)))
2843       (push (gnus-data-number (car data)) children)
2844       (setq data (cdr data)))
2845     children))
2846
2847 (defmacro gnus-summary-skip-intangible ()
2848   "If the current article is intangible, then jump to a different article."
2849   '(let ((to (get-text-property (point) 'gnus-intangible)))
2850      (and to (gnus-summary-goto-subject to))))
2851
2852 (defmacro gnus-summary-article-intangible-p ()
2853   "Say whether this article is intangible or not."
2854   '(get-text-property (point) 'gnus-intangible))
2855
2856 (defun gnus-article-read-p (article)
2857   "Say whether ARTICLE is read or not."
2858   (not (or (memq article gnus-newsgroup-marked)
2859            (memq article gnus-newsgroup-spam-marked)
2860            (memq article gnus-newsgroup-unreads)
2861            (memq article gnus-newsgroup-unselected)
2862            (memq article gnus-newsgroup-dormant))))
2863
2864 ;; Some summary mode macros.
2865
2866 (defmacro gnus-summary-article-number ()
2867   "The article number of the article on the current line.
2868 If there isn't an article number here, then we return the current
2869 article number."
2870   '(progn
2871      (gnus-summary-skip-intangible)
2872      (or (get-text-property (point) 'gnus-number)
2873          (gnus-summary-last-subject))))
2874
2875 (defmacro gnus-summary-article-header (&optional number)
2876   "Return the header of article NUMBER."
2877   `(gnus-data-header (gnus-data-find
2878                       ,(or number '(gnus-summary-article-number)))))
2879
2880 (defmacro gnus-summary-thread-level (&optional number)
2881   "Return the level of thread that starts with article NUMBER."
2882   `(if (and (eq gnus-summary-make-false-root 'dummy)
2883             (get-text-property (point) 'gnus-intangible))
2884        0
2885      (gnus-data-level (gnus-data-find
2886                        ,(or number '(gnus-summary-article-number))))))
2887
2888 (defmacro gnus-summary-article-mark (&optional number)
2889   "Return the mark of article NUMBER."
2890   `(gnus-data-mark (gnus-data-find
2891                     ,(or number '(gnus-summary-article-number)))))
2892
2893 (defmacro gnus-summary-article-pos (&optional number)
2894   "Return the position of the line of article NUMBER."
2895   `(gnus-data-pos (gnus-data-find
2896                    ,(or number '(gnus-summary-article-number)))))
2897
2898 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2899 (defmacro gnus-summary-article-subject (&optional number)
2900   "Return current subject string or nil if nothing."
2901   `(let ((headers
2902           ,(if number
2903                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2904              '(gnus-data-header (assq (gnus-summary-article-number)
2905                                       gnus-newsgroup-data)))))
2906      (and headers
2907           (vectorp headers)
2908           (mail-header-subject headers))))
2909
2910 (defmacro gnus-summary-article-score (&optional number)
2911   "Return current article score."
2912   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2913                   gnus-newsgroup-scored))
2914        gnus-summary-default-score 0))
2915
2916 (defun gnus-summary-article-children (&optional number)
2917   "Return a list of article numbers that are children of article NUMBER."
2918   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2919          (level (gnus-data-level (car data)))
2920          l children)
2921     (while (and (setq data (cdr data))
2922                 (> (setq l (gnus-data-level (car data))) level))
2923       (and (= (1+ level) l)
2924            (push (gnus-data-number (car data))
2925                  children)))
2926     (nreverse children)))
2927
2928 (defun gnus-summary-article-parent (&optional number)
2929   "Return the article number of the parent of article NUMBER."
2930   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2931                                     (gnus-data-list t)))
2932          (level (gnus-data-level (car data))))
2933     (if (zerop level)
2934         ()                              ; This is a root.
2935       ;; We search until we find an article with a level less than
2936       ;; this one.  That function has to be the parent.
2937       (while (and (setq data (cdr data))
2938                   (not (< (gnus-data-level (car data)) level))))
2939       (and data (gnus-data-number (car data))))))
2940
2941 (defun gnus-unread-mark-p (mark)
2942   "Say whether MARK is the unread mark."
2943   (= mark gnus-unread-mark))
2944
2945 (defun gnus-read-mark-p (mark)
2946   "Say whether MARK is one of the marks that mark as read.
2947 This is all marks except unread, ticked, dormant, and expirable."
2948   (not (or (= mark gnus-unread-mark)
2949            (= mark gnus-ticked-mark)
2950            (= mark gnus-spam-mark)
2951            (= mark gnus-dormant-mark)
2952            (= mark gnus-expirable-mark))))
2953
2954 (defmacro gnus-article-mark (number)
2955   "Return the MARK of article NUMBER.
2956 This macro should only be used when computing the mark the \"first\"
2957 time; i.e., when generating the summary lines.  After that,
2958 `gnus-summary-article-mark' should be used to examine the
2959 marks of articles."
2960   `(cond
2961     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2962     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2963     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2964     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2965     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2966     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2967     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2968     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2969            gnus-ancient-mark))))
2970
2971 ;; Saving hidden threads.
2972
2973 (defmacro gnus-save-hidden-threads (&rest forms)
2974   "Save hidden threads, eval FORMS, and restore the hidden threads."
2975   (let ((config (make-symbol "config")))
2976     `(let ((,config (gnus-hidden-threads-configuration)))
2977        (unwind-protect
2978            (save-excursion
2979              ,@forms)
2980          (gnus-restore-hidden-threads-configuration ,config)))))
2981 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2982 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2983
2984 (defun gnus-data-compute-positions ()
2985   "Compute the positions of all articles."
2986   (setq gnus-newsgroup-data-reverse nil)
2987   (let ((data gnus-newsgroup-data))
2988     (save-excursion
2989       (gnus-save-hidden-threads
2990         (gnus-summary-show-all-threads)
2991         (goto-char (point-min))
2992         (while data
2993           (while (get-text-property (point) 'gnus-intangible)
2994             (forward-line 1))
2995           (gnus-data-set-pos (car data) (+ (point) 3))
2996           (setq data (cdr data))
2997           (forward-line 1))))))
2998
2999 (defun gnus-hidden-threads-configuration ()
3000   "Return the current hidden threads configuration."
3001   (save-excursion
3002     (let (config)
3003       (goto-char (point-min))
3004       (while (search-forward "\r" nil t)
3005         (push (1- (point)) config))
3006       config)))
3007
3008 (defun gnus-restore-hidden-threads-configuration (config)
3009   "Restore hidden threads configuration from CONFIG."
3010   (save-excursion
3011     (let (point buffer-read-only)
3012       (while (setq point (pop config))
3013         (when (and (< point (point-max))
3014                    (goto-char point)
3015                    (eq (char-after) ?\n))
3016           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3017
3018 ;; Various summary mode internalish functions.
3019
3020 (defun gnus-mouse-pick-article (e)
3021   (interactive "e")
3022   (mouse-set-point e)
3023   (gnus-summary-next-page nil t))
3024
3025 (defun gnus-summary-set-display-table ()
3026   "Change the display table.
3027 Odd characters have a tendency to mess
3028 up nicely formatted displays - we make all possible glyphs
3029 display only a single character."
3030
3031   ;; We start from the standard display table, if any.
3032   (let ((table (or (copy-sequence standard-display-table)
3033                    (make-display-table)))
3034         (i 32))
3035     ;; Nix out all the control chars...
3036     (while (>= (setq i (1- i)) 0)
3037       (aset table i [??]))
3038     ;; ... but not newline and cr, of course.  (cr is necessary for the
3039     ;; selective display).
3040     (aset table ?\n nil)
3041     (aset table ?\r nil)
3042     ;; We keep TAB as well.
3043     (aset table ?\t nil)
3044     ;; We nix out any glyphs over 126 that are not set already.
3045     (let ((i 256))
3046       (while (>= (setq i (1- i)) 127)
3047         ;; Only modify if the entry is nil.
3048         (unless (aref table i)
3049           (aset table i [??]))))
3050     (setq buffer-display-table table)))
3051
3052 (defun gnus-summary-set-article-display-arrow (pos)
3053   "Update the overlay arrow to point to line at position POS."
3054   (when (and gnus-summary-display-arrow
3055              (boundp 'overlay-arrow-position)
3056              (boundp 'overlay-arrow-string))
3057     (save-excursion
3058       (goto-char pos)
3059       (beginning-of-line)
3060       (unless overlay-arrow-position
3061         (setq overlay-arrow-position (make-marker)))
3062       (setq overlay-arrow-string "=>"
3063             overlay-arrow-position (set-marker overlay-arrow-position
3064                                                (point)
3065                                                (current-buffer))))))
3066
3067 (defun gnus-summary-setup-buffer (group)
3068   "Initialize summary buffer."
3069   (let ((buffer (gnus-summary-buffer-name group))
3070         (dead-name (concat "*Dead Summary "
3071                            (gnus-group-decoded-name group) "*")))
3072     ;; If a dead summary buffer exists, we kill it.
3073     (when (gnus-buffer-live-p dead-name)
3074       (gnus-kill-buffer dead-name))
3075     (if (get-buffer buffer)
3076         (progn
3077           (set-buffer buffer)
3078           (setq gnus-summary-buffer (current-buffer))
3079           (not gnus-newsgroup-prepared))
3080       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3081       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3082       (gnus-summary-mode group)
3083       (when gnus-carpal
3084         (gnus-carpal-setup-buffer 'summary))
3085       (unless gnus-single-article-buffer
3086         (make-local-variable 'gnus-article-buffer)
3087         (make-local-variable 'gnus-article-current)
3088         (make-local-variable 'gnus-original-article-buffer))
3089       (setq gnus-newsgroup-name group)
3090       ;; Set any local variables in the group parameters.
3091       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3092       t)))
3093
3094 (defun gnus-set-global-variables ()
3095   "Set the global equivalents of the buffer-local variables.
3096 They are set to the latest values they had.  These reflect the summary
3097 buffer that was in action when the last article was fetched."
3098   (when (eq major-mode 'gnus-summary-mode)
3099     (setq gnus-summary-buffer (current-buffer))
3100     (let ((name gnus-newsgroup-name)
3101           (marked gnus-newsgroup-marked)
3102           (spam gnus-newsgroup-spam-marked)
3103           (unread gnus-newsgroup-unreads)
3104           (headers gnus-current-headers)
3105           (data gnus-newsgroup-data)
3106           (summary gnus-summary-buffer)
3107           (article-buffer gnus-article-buffer)
3108           (original gnus-original-article-buffer)
3109           (gac gnus-article-current)
3110           (reffed gnus-reffed-article-number)
3111           (score-file gnus-current-score-file)
3112           (default-charset gnus-newsgroup-charset)
3113           vlist)
3114       (let ((locals gnus-newsgroup-variables))
3115         (while locals
3116           (if (consp (car locals))
3117               (push (eval (caar locals)) vlist)
3118             (push (eval (car locals)) vlist))
3119           (setq locals (cdr locals)))
3120         (setq vlist (nreverse vlist)))
3121       (save-excursion
3122         (set-buffer gnus-group-buffer)
3123         (setq gnus-newsgroup-name name
3124               gnus-newsgroup-marked marked
3125               gnus-newsgroup-spam-marked spam
3126               gnus-newsgroup-unreads unread
3127               gnus-current-headers headers
3128               gnus-newsgroup-data data
3129               gnus-article-current gac
3130               gnus-summary-buffer summary
3131               gnus-article-buffer article-buffer
3132               gnus-original-article-buffer original
3133               gnus-reffed-article-number reffed
3134               gnus-current-score-file score-file
3135               gnus-newsgroup-charset default-charset)
3136         (let ((locals gnus-newsgroup-variables))
3137           (while locals
3138             (if (consp (car locals))
3139                 (set (caar locals) (pop vlist))
3140               (set (car locals) (pop vlist)))
3141             (setq locals (cdr locals))))
3142         ;; The article buffer also has local variables.
3143         (when (gnus-buffer-live-p gnus-article-buffer)
3144           (set-buffer gnus-article-buffer)
3145           (setq gnus-summary-buffer summary))))))
3146
3147 (defun gnus-summary-article-unread-p (article)
3148   "Say whether ARTICLE is unread or not."
3149   (memq article gnus-newsgroup-unreads))
3150
3151 (defun gnus-summary-first-article-p (&optional article)
3152   "Return whether ARTICLE is the first article in the buffer."
3153   (if (not (setq article (or article (gnus-summary-article-number))))
3154       nil
3155     (eq article (caar gnus-newsgroup-data))))
3156
3157 (defun gnus-summary-last-article-p (&optional article)
3158   "Return whether ARTICLE is the last article in the buffer."
3159   (if (not (setq article (or article (gnus-summary-article-number))))
3160       ;; All non-existent numbers are the last article.  :-)
3161       t
3162     (not (cdr (gnus-data-find-list article)))))
3163
3164 (defun gnus-make-thread-indent-array ()
3165   (let ((n 200))
3166     (unless (and gnus-thread-indent-array
3167                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3168       (setq gnus-thread-indent-array (make-vector 201 "")
3169             gnus-thread-indent-array-level gnus-thread-indent-level)
3170       (while (>= n 0)
3171         (aset gnus-thread-indent-array n
3172               (make-string (* n gnus-thread-indent-level) ? ))
3173         (setq n (1- n))))))
3174
3175 (defun gnus-update-summary-mark-positions ()
3176   "Compute where the summary marks are to go."
3177   (save-excursion
3178     (when (gnus-buffer-exists-p gnus-summary-buffer)
3179       (set-buffer gnus-summary-buffer))
3180     (let ((gnus-replied-mark 129)
3181           (gnus-score-below-mark 130)
3182           (gnus-score-over-mark 130)
3183           (gnus-undownloaded-mark 131)
3184           (spec gnus-summary-line-format-spec)
3185           gnus-visual pos)
3186       (save-excursion
3187         (gnus-set-work-buffer)
3188         (let ((gnus-summary-line-format-spec spec)
3189               (gnus-newsgroup-downloadable '(0)))
3190           (gnus-summary-insert-line
3191            (make-full-mail-header 0 "" "nobody"
3192                                   "05 Apr 2001 23:33:09 +0400"
3193                                   "" "" 0 0 "" nil)
3194            0 nil t 128 t nil "" nil 1)
3195           (goto-char (point-min))
3196           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3197                                              (- (point) (point-min) 1)))))
3198           (goto-char (point-min))
3199           (push (cons 'replied (and (search-forward "\201" nil t)
3200                                     (- (point) (point-min) 1)))
3201                 pos)
3202           (goto-char (point-min))
3203           (push (cons 'score (and (search-forward "\202" nil t)
3204                                   (- (point) (point-min) 1)))
3205                 pos)
3206           (goto-char (point-min))
3207           (push (cons 'download
3208                       (and (search-forward "\203" nil t)
3209                            (- (point) (point-min) 1)))
3210                 pos)))
3211       (setq gnus-summary-mark-positions pos))))
3212
3213 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3214   "Insert a dummy root in the summary buffer."
3215   (beginning-of-line)
3216   (gnus-add-text-properties
3217    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3218    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3219
3220 (defun gnus-summary-extract-address-component (from)
3221   (or (car (funcall gnus-extract-address-components from))
3222       from))
3223
3224 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3225   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3226                                 default-mime-charset)))
3227     ;; Is it really necessary to do this next part for each summary line?
3228     ;; Luckily, doesn't seem to slow things down much.
3229     (or
3230      (and gnus-ignored-from-addresses
3231           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3232           (let ((extra-headers (mail-header-extra header))
3233                 to
3234                 newsgroups)
3235             (cond
3236              ((setq to (cdr (assq 'To extra-headers)))
3237               (concat "-> "
3238                       (inline
3239                         (gnus-summary-extract-address-component
3240                          (funcall gnus-decode-encoded-word-function to)))))
3241              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3242               (concat "=> " newsgroups)))))
3243      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3244
3245 (defun gnus-summary-insert-line (gnus-tmp-header
3246                                  gnus-tmp-level gnus-tmp-current
3247                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3248                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3249                                  &optional gnus-tmp-dummy gnus-tmp-score
3250                                  gnus-tmp-process)
3251   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3252          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3253          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3254          (gnus-tmp-score-char
3255           (if (or (null gnus-summary-default-score)
3256                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3257                       gnus-summary-zcore-fuzz))
3258               ?\ ;;;Whitespace
3259             (if (< gnus-tmp-score gnus-summary-default-score)
3260                 gnus-score-below-mark gnus-score-over-mark)))
3261          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3262          (gnus-tmp-replied
3263           (cond (gnus-tmp-process gnus-process-mark)
3264                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3265                  gnus-cached-mark)
3266                 (gnus-tmp-replied gnus-replied-mark)
3267                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3268                  gnus-forwarded-mark)
3269                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3270                  gnus-saved-mark)
3271                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3272                  gnus-recent-mark)
3273                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3274                  gnus-unseen-mark)
3275                 (t gnus-no-mark)))
3276          (gnus-tmp-downloaded
3277           (cond (undownloaded 
3278                  gnus-undownloaded-mark)
3279                 (gnus-newsgroup-agentized
3280                  gnus-downloaded-mark)
3281                 (t
3282                  gnus-no-mark)))
3283          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3284          (gnus-tmp-name
3285           (cond
3286            ((string-match "<[^>]+> *$" gnus-tmp-from)
3287             (let ((beg (match-beginning 0)))
3288               (or (and (string-match "^\".+\"" gnus-tmp-from)
3289                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3290                   (substring gnus-tmp-from 0 beg))))
3291            ((string-match "(.+)" gnus-tmp-from)
3292             (substring gnus-tmp-from
3293                        (1+ (match-beginning 0)) (1- (match-end 0))))
3294            (t gnus-tmp-from)))
3295          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3296          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3297          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3298          (buffer-read-only nil))
3299     (when (string= gnus-tmp-name "")
3300       (setq gnus-tmp-name gnus-tmp-from))
3301     (unless (numberp gnus-tmp-lines)
3302       (setq gnus-tmp-lines -1))
3303     (if (= gnus-tmp-lines -1)
3304         (setq gnus-tmp-lines "?")
3305       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3306     (gnus-put-text-property-excluding-characters-with-faces
3307      (point)
3308      (progn (eval gnus-summary-line-format-spec) (point))
3309      'gnus-number gnus-tmp-number)
3310     (when (gnus-visual-p 'summary-highlight 'highlight)
3311       (forward-line -1)
3312       (gnus-run-hooks 'gnus-summary-update-hook)
3313       (forward-line 1))))
3314
3315 (defun gnus-summary-update-line (&optional dont-update)
3316   "Update summary line after change."
3317   (when (and gnus-summary-default-score
3318              (not gnus-summary-inhibit-highlight))
3319     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3320            (article (gnus-summary-article-number))
3321            (score (gnus-summary-article-score article)))
3322       (unless dont-update
3323         (if (and gnus-summary-mark-below
3324                  (< (gnus-summary-article-score)
3325                     gnus-summary-mark-below))
3326             ;; This article has a low score, so we mark it as read.
3327             (when (memq article gnus-newsgroup-unreads)
3328               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3329           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3330             ;; This article was previously marked as read on account
3331             ;; of a low score, but now it has risen, so we mark it as
3332             ;; unread.
3333             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3334         (gnus-summary-update-mark
3335          (if (or (null gnus-summary-default-score)
3336                  (<= (abs (- score gnus-summary-default-score))
3337                      gnus-summary-zcore-fuzz))
3338              ?\ ;;;Whitespace
3339            (if (< score gnus-summary-default-score)
3340                gnus-score-below-mark gnus-score-over-mark))
3341          'score))
3342       ;; Do visual highlighting.
3343       (when (gnus-visual-p 'summary-highlight 'highlight)
3344         (gnus-run-hooks 'gnus-summary-update-hook)))))
3345
3346 (defvar gnus-tmp-new-adopts nil)
3347
3348 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3349   "Return the number of articles in THREAD.
3350 This may be 0 in some cases -- if none of the articles in
3351 the thread are to be displayed."
3352   (let* ((number
3353           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3354           (cond
3355            ((not (listp thread))
3356             1)
3357            ((and (consp thread) (cdr thread))
3358             (apply
3359              '+ 1 (mapcar
3360                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3361            ((null thread)
3362             1)
3363            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3364             1)
3365            (t 0))))
3366     (when (and level (zerop level) gnus-tmp-new-adopts)
3367       (incf number
3368             (apply '+ (mapcar
3369                        'gnus-summary-number-of-articles-in-thread
3370                        gnus-tmp-new-adopts))))
3371     (if char
3372         (if (> number 1) gnus-not-empty-thread-mark
3373           gnus-empty-thread-mark)
3374       number)))
3375
3376 (defsubst gnus-summary-line-message-size (head)
3377   "Return pretty-printed version of message size.
3378 This function is intended to be used in
3379 `gnus-summary-line-format-alist'."
3380   (let ((c (or (mail-header-chars head) -1)))
3381     (cond ((< c 0) "n/a")               ; chars not available
3382           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3383           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3384           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3385           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3386
3387
3388 (defun gnus-summary-set-local-parameters (group)
3389   "Go through the local params of GROUP and set all variable specs in that list."
3390   (let ((params (gnus-group-find-parameter group))
3391         (vars '(quit-config))           ; Ignore quit-config.
3392         elem)
3393     (while params
3394       (setq elem (car params)
3395             params (cdr params))
3396       (and (consp elem)                 ; Has to be a cons.
3397            (consp (cdr elem))           ; The cdr has to be a list.
3398            (symbolp (car elem))         ; Has to be a symbol in there.
3399            (not (memq (car elem) vars))
3400            (ignore-errors               ; So we set it.
3401              (push (car elem) vars)
3402              (make-local-variable (car elem))
3403              (set (car elem) (eval (nth 1 elem))))))))
3404
3405 (defun gnus-summary-read-group (group &optional show-all no-article
3406                                       kill-buffer no-display backward
3407                                       select-articles)
3408   "Start reading news in newsgroup GROUP.
3409 If SHOW-ALL is non-nil, already read articles are also listed.
3410 If NO-ARTICLE is non-nil, no article is selected initially.
3411 If NO-DISPLAY, don't generate a summary buffer."
3412   (let (result)
3413     (while (and group
3414                 (null (setq result
3415                             (let ((gnus-auto-select-next nil))
3416                               (or (gnus-summary-read-group-1
3417                                    group show-all no-article
3418                                    kill-buffer no-display
3419                                    select-articles)
3420                                   (setq show-all nil
3421                                         select-articles nil)))))
3422                 (eq gnus-auto-select-next 'quietly))
3423       (set-buffer gnus-group-buffer)
3424       ;; The entry function called above goes to the next
3425       ;; group automatically, so we go two groups back
3426       ;; if we are searching for the previous group.
3427       (when backward
3428         (gnus-group-prev-unread-group 2))
3429       (if (not (equal group (gnus-group-group-name)))
3430           (setq group (gnus-group-group-name))
3431         (setq group nil)))
3432     result))
3433
3434 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3435   "Directly jump to the other GROUP from summary buffer.
3436 If SHOW-ALL is non-nil, already read articles are also listed."
3437   (interactive
3438    (if (eq gnus-summary-buffer (current-buffer))
3439        (list (completing-read
3440               "Group: " gnus-active-hashtb nil t
3441               (when (and gnus-newsgroup-name
3442                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3443                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3444               'gnus-group-history)
3445              current-prefix-arg)
3446      (error "%s must be invoked from a gnus summary buffer." this-command)))
3447   (unless (or (zerop (length group))
3448               (and gnus-newsgroup-name
3449                    (string-equal gnus-newsgroup-name group)))
3450     (gnus-summary-exit)
3451     (gnus-summary-read-group group show-all
3452                              gnus-dont-select-after-jump-to-other-group)))
3453
3454 (defun gnus-summary-read-group-1 (group show-all no-article
3455                                         kill-buffer no-display
3456                                         &optional select-articles)
3457   ;; Killed foreign groups can't be entered.
3458   ;;  (when (and (not (gnus-group-native-p group))
3459   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3460   ;;    (error "Dead non-native groups can't be entered"))
3461   (gnus-message 5 "Retrieving newsgroup: %s..."
3462                 (gnus-group-decoded-name group))
3463   (let* ((new-group (gnus-summary-setup-buffer group))
3464          (quit-config (gnus-group-quit-config group))
3465          (did-select (and new-group (gnus-select-newsgroup
3466                                      group show-all select-articles))))
3467     (cond
3468      ;; This summary buffer exists already, so we just select it.
3469      ((not new-group)
3470       (gnus-set-global-variables)
3471       (when kill-buffer
3472         (gnus-kill-or-deaden-summary kill-buffer))
3473       (gnus-configure-windows 'summary 'force)
3474       (gnus-set-mode-line 'summary)
3475       (gnus-summary-position-point)
3476       (message "")
3477       t)
3478      ;; We couldn't select this group.
3479      ((null did-select)
3480       (when (and (eq major-mode 'gnus-summary-mode)
3481                  (not (equal (current-buffer) kill-buffer)))
3482         (kill-buffer (current-buffer))
3483         (if (not quit-config)
3484             (progn
3485               ;; Update the info -- marks might need to be removed,
3486               ;; for instance.
3487               (gnus-summary-update-info)
3488               (set-buffer gnus-group-buffer)
3489               (gnus-group-jump-to-group group)
3490               (gnus-group-next-unread-group 1))
3491           (gnus-handle-ephemeral-exit quit-config)))
3492       (let ((grpinfo (gnus-get-info group)))
3493         (if (null (gnus-info-read grpinfo))
3494             (gnus-message 3 "Group %s contains no messages"
3495                           (gnus-group-decoded-name group))
3496           (gnus-message 3 "Can't select group")))
3497       nil)
3498      ;; The user did a `C-g' while prompting for number of articles,
3499      ;; so we exit this group.
3500      ((eq did-select 'quit)
3501       (and (eq major-mode 'gnus-summary-mode)
3502            (not (equal (current-buffer) kill-buffer))
3503            (kill-buffer (current-buffer)))
3504       (when kill-buffer
3505         (gnus-kill-or-deaden-summary kill-buffer))
3506       (if (not quit-config)
3507           (progn
3508             (set-buffer gnus-group-buffer)
3509             (gnus-group-jump-to-group group)
3510             (gnus-group-next-unread-group 1)
3511             (gnus-configure-windows 'group 'force))
3512         (gnus-handle-ephemeral-exit quit-config))
3513       ;; Finally signal the quit.
3514       (signal 'quit nil))
3515      ;; The group was successfully selected.
3516      (t
3517       (gnus-set-global-variables)
3518       ;; Save the active value in effect when the group was entered.
3519       (setq gnus-newsgroup-active
3520             (gnus-copy-sequence
3521              (gnus-active gnus-newsgroup-name)))
3522       ;; You can change the summary buffer in some way with this hook.
3523       (gnus-run-hooks 'gnus-select-group-hook)
3524       (gnus-update-format-specifications
3525        nil 'summary 'summary-mode 'summary-dummy)
3526       (gnus-update-summary-mark-positions)
3527       ;; Do score processing.
3528       (when gnus-use-scoring
3529         (gnus-possibly-score-headers))
3530       ;; Check whether to fill in the gaps in the threads.
3531       (when gnus-build-sparse-threads
3532         (gnus-build-sparse-threads))
3533       ;; Find the initial limit.
3534       (if gnus-show-threads
3535           (if show-all
3536               (let ((gnus-newsgroup-dormant nil))
3537                 (gnus-summary-initial-limit show-all))
3538             (gnus-summary-initial-limit show-all))
3539         ;; When unthreaded, all articles are always shown.
3540         (setq gnus-newsgroup-limit
3541               (mapcar
3542                (lambda (header) (mail-header-number header))
3543                gnus-newsgroup-headers)))
3544       ;; Generate the summary buffer.
3545       (unless no-display
3546         (gnus-summary-prepare))
3547       (when gnus-use-trees
3548         (gnus-tree-open group)
3549         (setq gnus-summary-highlight-line-function
3550               'gnus-tree-highlight-article))
3551       ;; If the summary buffer is empty, but there are some low-scored
3552       ;; articles or some excluded dormants, we include these in the
3553       ;; buffer.
3554       (when (and (zerop (buffer-size))
3555                  (not no-display))
3556         (cond (gnus-newsgroup-dormant
3557                (gnus-summary-limit-include-dormant))
3558               ((and gnus-newsgroup-scored show-all)
3559                (gnus-summary-limit-include-expunged t))))
3560       ;; Function `gnus-apply-kill-file' must be called in this hook.
3561       (gnus-run-hooks 'gnus-apply-kill-hook)
3562       (if (and (zerop (buffer-size))
3563                (not no-display))
3564           (progn
3565             ;; This newsgroup is empty.
3566             (gnus-summary-catchup-and-exit nil t)
3567             (gnus-message 6 "No unread news")
3568             (when kill-buffer
3569               (gnus-kill-or-deaden-summary kill-buffer))
3570             ;; Return nil from this function.
3571             nil)
3572         ;; Hide conversation thread subtrees.  We cannot do this in
3573         ;; gnus-summary-prepare-hook since kill processing may not
3574         ;; work with hidden articles.
3575         (gnus-summary-maybe-hide-threads)
3576         (when kill-buffer
3577           (gnus-kill-or-deaden-summary kill-buffer))
3578         (gnus-summary-auto-select-subject)
3579         ;; Show first unread article if requested.
3580         (if (and (not no-article)
3581                  (not no-display)
3582                  gnus-newsgroup-unreads
3583                  gnus-auto-select-first)
3584             (progn
3585               (gnus-configure-windows 'summary)
3586               (let ((art (gnus-summary-article-number)))
3587                 (unless (and (not gnus-plugged)
3588                              (or (memq art gnus-newsgroup-undownloaded)
3589                                  (memq art gnus-newsgroup-downloadable)))
3590                   (gnus-summary-goto-article art))))
3591           ;; Don't select any articles.
3592           (gnus-summary-position-point)
3593           (gnus-configure-windows 'summary 'force)
3594           (gnus-set-mode-line 'summary))
3595         (when (and gnus-auto-center-group
3596                    (get-buffer-window gnus-group-buffer t))
3597           ;; Gotta use windows, because recenter does weird stuff if
3598           ;; the current buffer ain't the displayed window.
3599           (let ((owin (selected-window)))
3600             (select-window (get-buffer-window gnus-group-buffer t))
3601             (when (gnus-group-goto-group group)
3602               (recenter))
3603             (select-window owin)))
3604         ;; Mark this buffer as "prepared".
3605         (setq gnus-newsgroup-prepared t)
3606         (gnus-run-hooks 'gnus-summary-prepared-hook)
3607         (unless (gnus-ephemeral-group-p group)
3608           (gnus-group-update-group group))
3609         t)))))
3610
3611 (defun gnus-summary-auto-select-subject ()
3612   "Select the subject line on initial group entry."
3613   (goto-char (point-min))
3614   (cond
3615    ((eq gnus-auto-select-subject 'best)
3616     (gnus-summary-best-unread-subject))
3617    ((eq gnus-auto-select-subject 'unread)
3618     (gnus-summary-first-unread-subject))
3619    ((eq gnus-auto-select-subject 'unseen)
3620     (gnus-summary-first-unseen-subject))
3621    ((eq gnus-auto-select-subject 'unseen-or-unread)
3622     (gnus-summary-first-unseen-or-unread-subject))
3623    ((eq gnus-auto-select-subject 'first)
3624     ;; Do nothing.
3625     )
3626    ((functionp gnus-auto-select-subject)
3627     (funcall gnus-auto-select-subject))))
3628
3629 (defun gnus-summary-prepare ()
3630   "Generate the summary buffer."
3631   (interactive)
3632   (let ((buffer-read-only nil))
3633     (erase-buffer)
3634     (setq gnus-newsgroup-data nil
3635           gnus-newsgroup-data-reverse nil)
3636     (gnus-run-hooks 'gnus-summary-generate-hook)
3637     ;; Generate the buffer, either with threads or without.
3638     (when gnus-newsgroup-headers
3639       (gnus-summary-prepare-threads
3640        (if gnus-show-threads
3641            (gnus-sort-gathered-threads
3642             (funcall gnus-summary-thread-gathering-function
3643                      (gnus-sort-threads
3644                       (gnus-cut-threads (gnus-make-threads)))))
3645          ;; Unthreaded display.
3646          (gnus-sort-articles gnus-newsgroup-headers))))
3647     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3648     ;; Call hooks for modifying summary buffer.
3649     (goto-char (point-min))
3650     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3651
3652 (defsubst gnus-general-simplify-subject (subject)
3653   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3654   (setq subject
3655         (cond
3656          ;; Truncate the subject.
3657          (gnus-simplify-subject-functions
3658           (gnus-map-function gnus-simplify-subject-functions subject))
3659          ((numberp gnus-summary-gather-subject-limit)
3660           (setq subject (gnus-simplify-subject-re subject))
3661           (if (> (length subject) gnus-summary-gather-subject-limit)
3662               (substring subject 0 gnus-summary-gather-subject-limit)
3663             subject))
3664          ;; Fuzzily simplify it.
3665          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3666           (gnus-simplify-subject-fuzzy subject))
3667          ;; Just remove the leading "Re:".
3668          (t
3669           (gnus-simplify-subject-re subject))))
3670
3671   (if (and gnus-summary-gather-exclude-subject
3672            (string-match gnus-summary-gather-exclude-subject subject))
3673       nil                               ; This article shouldn't be gathered
3674     subject))
3675
3676 (defun gnus-summary-simplify-subject-query ()
3677   "Query where the respool algorithm would put this article."
3678   (interactive)
3679   (gnus-summary-select-article)
3680   (message "%s"
3681            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3682
3683 (defun gnus-gather-threads-by-subject (threads)
3684   "Gather threads by looking at Subject headers."
3685   (if (not gnus-summary-make-false-root)
3686       threads
3687     (let ((hashtb (gnus-make-hashtable 1024))
3688           (prev threads)
3689           (result threads)
3690           subject hthread whole-subject)
3691       (while threads
3692         (setq subject (gnus-general-simplify-subject
3693                        (setq whole-subject (mail-header-subject
3694                                             (caar threads)))))
3695         (when subject
3696           (if (setq hthread (gnus-gethash subject hashtb))
3697               (progn
3698                 ;; We enter a dummy root into the thread, if we
3699                 ;; haven't done that already.
3700                 (unless (stringp (caar hthread))
3701                   (setcar hthread (list whole-subject (car hthread))))
3702                 ;; We add this new gathered thread to this gathered
3703                 ;; thread.
3704                 (setcdr (car hthread)
3705                         (nconc (cdar hthread) (list (car threads))))
3706                 ;; Remove it from the list of threads.
3707                 (setcdr prev (cdr threads))
3708                 (setq threads prev))
3709             ;; Enter this thread into the hash table.
3710             (gnus-sethash subject
3711                           (if gnus-summary-make-false-root-always
3712                               (progn
3713                                 ;; If you want a dummy root above all
3714                                 ;; threads...
3715                                 (setcar threads (list whole-subject
3716                                                       (car threads)))
3717                                 threads)
3718                             threads)
3719                           hashtb)))
3720         (setq prev threads)
3721         (setq threads (cdr threads)))
3722       result)))
3723
3724 (defun gnus-gather-threads-by-references (threads)
3725   "Gather threads by looking at References headers."
3726   (let ((idhashtb (gnus-make-hashtable 1024))
3727         (thhashtb (gnus-make-hashtable 1024))
3728         (prev threads)
3729         (result threads)
3730         ids references id gthread gid entered ref)
3731     (while threads
3732       (when (setq references (mail-header-references (caar threads)))
3733         (setq id (mail-header-id (caar threads))
3734               ids (inline (gnus-split-references references))
3735               entered nil)
3736         (while (setq ref (pop ids))
3737           (setq ids (delete ref ids))
3738           (if (not (setq gid (gnus-gethash ref idhashtb)))
3739               (progn
3740                 (gnus-sethash ref id idhashtb)
3741                 (gnus-sethash id threads thhashtb))
3742             (setq gthread (gnus-gethash gid thhashtb))
3743             (unless entered
3744               ;; We enter a dummy root into the thread, if we
3745               ;; haven't done that already.
3746               (unless (stringp (caar gthread))
3747                 (setcar gthread (list (mail-header-subject (caar gthread))
3748                                       (car gthread))))
3749               ;; We add this new gathered thread to this gathered
3750               ;; thread.
3751               (setcdr (car gthread)
3752                       (nconc (cdar gthread) (list (car threads)))))
3753             ;; Add it into the thread hash table.
3754             (gnus-sethash id gthread thhashtb)
3755             (setq entered t)
3756             ;; Remove it from the list of threads.
3757             (setcdr prev (cdr threads))
3758             (setq threads prev))))
3759       (setq prev threads)
3760       (setq threads (cdr threads)))
3761     result))
3762
3763 (defun gnus-sort-gathered-threads (threads)
3764   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3765   (let ((result threads))
3766     (while threads
3767       (when (stringp (caar threads))
3768         (setcdr (car threads)
3769                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3770       (setq threads (cdr threads)))
3771     result))
3772
3773 (defun gnus-thread-loop-p (root thread)
3774   "Say whether ROOT is in THREAD."
3775   (let ((stack (list thread))
3776         (infloop 0)
3777         th)
3778     (while (setq thread (pop stack))
3779       (setq th (cdr thread))
3780       (while (and th
3781                   (not (eq (caar th) root)))
3782         (pop th))
3783       (if th
3784           ;; We have found a loop.
3785           (let (ref-dep)
3786             (setcdr thread (delq (car th) (cdr thread)))
3787             (if (boundp (setq ref-dep (intern "none"
3788                                               gnus-newsgroup-dependencies)))
3789                 (setcdr (symbol-value ref-dep)
3790                         (nconc (cdr (symbol-value ref-dep))
3791                                (list (car th))))
3792               (set ref-dep (list nil (car th))))
3793             (setq infloop 1
3794                   stack nil))
3795         ;; Push all the subthreads onto the stack.
3796         (push (cdr thread) stack)))
3797     infloop))
3798
3799 (defun gnus-make-threads ()
3800   "Go through the dependency hashtb and find the roots.  Return all threads."
3801   (let (threads)
3802     (while (catch 'infloop
3803              (mapatoms
3804               (lambda (refs)
3805                 ;; Deal with self-referencing References loops.
3806                 (when (and (car (symbol-value refs))
3807                            (not (zerop
3808                                  (apply
3809                                   '+
3810                                   (mapcar
3811                                    (lambda (thread)
3812                                      (gnus-thread-loop-p
3813                                       (car (symbol-value refs)) thread))
3814                                    (cdr (symbol-value refs)))))))
3815                   (setq threads nil)
3816                   (throw 'infloop t))
3817                 (unless (car (symbol-value refs))
3818                   ;; These threads do not refer back to any other articles,
3819                   ;; so they're roots.
3820                   (setq threads (append (cdr (symbol-value refs)) threads))))
3821               gnus-newsgroup-dependencies)))
3822     threads))
3823
3824 ;; Build the thread tree.
3825 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3826   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3827
3828 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3829 if it was already present.
3830
3831 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3832 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3833 Message-IDs will be renamed to a unique Message-ID before being
3834 entered.
3835
3836 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3837   (let* ((id (mail-header-id header))
3838          (id-dep (and id (intern id dependencies)))
3839          parent-id ref ref-dep ref-header replaced)
3840     ;; Enter this `header' in the `dependencies' table.
3841     (cond
3842      ((not id-dep)
3843       (setq header nil))
3844      ;; The first two cases do the normal part: enter a new `header'
3845      ;; in the `dependencies' table.
3846      ((not (boundp id-dep))
3847       (set id-dep (list header)))
3848      ((null (car (symbol-value id-dep)))
3849       (setcar (symbol-value id-dep) header))
3850
3851      ;; From here the `header' was already present in the
3852      ;; `dependencies' table.
3853      (force-new
3854       ;; Overrides an existing entry;
3855       ;; just set the header part of the entry.
3856       (setcar (symbol-value id-dep) header)
3857       (setq replaced t))
3858
3859      ;; Renames the existing `header' to a unique Message-ID.
3860      ((not gnus-summary-ignore-duplicates)
3861       ;; An article with this Message-ID has already been seen.
3862       ;; We rename the Message-ID.
3863       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3864            (list header))
3865       (mail-header-set-id header id))
3866
3867      ;; The last case ignores an existing entry, except it adds any
3868      ;; additional Xrefs (in case the two articles came from different
3869      ;; servers.
3870      ;; Also sets `header' to `nil' meaning that the `dependencies'
3871      ;; table was *not* modified.
3872      (t
3873       (mail-header-set-xref
3874        (car (symbol-value id-dep))
3875        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3876                    "")
3877                (or (mail-header-xref header) "")))
3878       (setq header nil)))
3879
3880     (when (and header (not replaced))
3881       ;; First check that we are not creating a References loop.
3882       (setq parent-id (gnus-parent-id (mail-header-references header)))
3883       (setq ref parent-id)
3884       (while (and ref
3885                   (setq ref-dep (intern-soft ref dependencies))
3886                   (boundp ref-dep)
3887                   (setq ref-header (car (symbol-value ref-dep))))
3888         (if (string= id ref)
3889             ;; Yuk!  This is a reference loop.  Make the article be a
3890             ;; root article.
3891             (progn
3892               (mail-header-set-references (car (symbol-value id-dep)) "none")
3893               (setq ref nil)
3894               (setq parent-id nil))
3895           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3896       (setq ref-dep (intern (or parent-id "none") dependencies))
3897       (if (boundp ref-dep)
3898           (setcdr (symbol-value ref-dep)
3899                   (nconc (cdr (symbol-value ref-dep))
3900                          (list (symbol-value id-dep))))
3901         (set ref-dep (list nil (symbol-value id-dep)))))
3902     header))
3903
3904 (defun gnus-extract-message-id-from-in-reply-to (string)
3905   (if (string-match "<[^>]+>" string)
3906       (substring string (match-beginning 0) (match-end 0))
3907     nil))
3908
3909 (defun gnus-build-sparse-threads ()
3910   (let ((headers gnus-newsgroup-headers)
3911         (mail-parse-charset gnus-newsgroup-charset)
3912         (gnus-summary-ignore-duplicates t)
3913         header references generation relations
3914         subject child end new-child date)
3915     ;; First we create an alist of generations/relations, where
3916     ;; generations is how much we trust the relation, and the relation
3917     ;; is parent/child.
3918     (gnus-message 7 "Making sparse threads...")
3919     (save-excursion
3920       (nnheader-set-temp-buffer " *gnus sparse threads*")
3921       (while (setq header (pop headers))
3922         (when (and (setq references (mail-header-references header))
3923                    (not (string= references "")))
3924           (insert references)
3925           (setq child (mail-header-id header)
3926                 subject (mail-header-subject header)
3927                 date (mail-header-date header)
3928                 generation 0)
3929           (while (search-backward ">" nil t)
3930             (setq end (1+ (point)))
3931             (when (search-backward "<" nil t)
3932               (setq new-child (buffer-substring (point) end))
3933               (push (list (incf generation)
3934                           child (setq child new-child)
3935                           subject date)
3936                     relations)))
3937           (when child
3938             (push (list (1+ generation) child nil subject) relations))
3939           (erase-buffer)))
3940       (kill-buffer (current-buffer)))
3941     ;; Sort over trustworthiness.
3942     (mapcar
3943      (lambda (relation)
3944        (when (gnus-dependencies-add-header
3945               (make-full-mail-header-from-decoded-header
3946                gnus-reffed-article-number
3947                (nth 3 relation) "" (or (nth 4 relation) "")
3948                (nth 1 relation)
3949                (or (nth 2 relation) "") 0 0 "")
3950               gnus-newsgroup-dependencies nil)
3951          (push gnus-reffed-article-number gnus-newsgroup-limit)
3952          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3953          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3954                gnus-newsgroup-reads)
3955          (decf gnus-reffed-article-number)))
3956      (sort relations 'car-less-than-car))
3957     (gnus-message 7 "Making sparse threads...done")))
3958
3959 (defun gnus-build-old-threads ()
3960   ;; Look at all the articles that refer back to old articles, and
3961   ;; fetch the headers for the articles that aren't there.  This will
3962   ;; build complete threads - if the roots haven't been expired by the
3963   ;; server, that is.
3964   (let ((mail-parse-charset gnus-newsgroup-charset)
3965         id heads)
3966     (mapatoms
3967      (lambda (refs)
3968        (when (not (car (symbol-value refs)))
3969          (setq heads (cdr (symbol-value refs)))
3970          (while heads
3971            (if (memq (mail-header-number (caar heads))
3972                      gnus-newsgroup-dormant)
3973                (setq heads (cdr heads))
3974              (setq id (symbol-name refs))
3975              (while (and (setq id (gnus-build-get-header id))
3976                          (not (car (gnus-id-to-thread id)))))
3977              (setq heads nil)))))
3978      gnus-newsgroup-dependencies)))
3979
3980 ;; This function has to be called with point after the article number
3981 ;; on the beginning of the line.
3982 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3983   (let ((eol (gnus-point-at-eol))
3984         (buffer (current-buffer))
3985         header references in-reply-to)
3986
3987     ;; overview: [num subject from date id refs chars lines misc]
3988     (unwind-protect
3989         (progn
3990           (narrow-to-region (point) eol)
3991           (unless (eobp)
3992             (forward-char))
3993
3994           (setq header
3995                 (make-full-mail-header
3996                  number                         ; number
3997                  (nnheader-nov-field)           ; subject
3998                  (nnheader-nov-field)           ; from
3999                  (nnheader-nov-field)           ; date
4000                  (nnheader-nov-read-message-id) ; id
4001                  (nnheader-nov-field)           ; refs
4002                  (nnheader-nov-read-integer)    ; chars
4003                  (nnheader-nov-read-integer)    ; lines
4004                  (unless (eobp)
4005                    (if (looking-at "Xref: ")
4006                        (goto-char (match-end 0)))
4007                    (nnheader-nov-field))        ; Xref
4008                  (nnheader-nov-parse-extra))))  ; extra
4009
4010       (widen))
4011
4012     (when (and (string= references "")
4013                (setq in-reply-to (mail-header-extra header))
4014                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4015       (mail-header-set-references
4016        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4017
4018     (when gnus-alter-header-function
4019       (funcall gnus-alter-header-function header))
4020     (gnus-dependencies-add-header header dependencies force-new)))
4021
4022 (defun gnus-build-get-header (id)
4023   "Look through the buffer of NOV lines and find the header to ID.
4024 Enter this line into the dependencies hash table, and return
4025 the id of the parent article (if any)."
4026   (let ((deps gnus-newsgroup-dependencies)
4027         found header)
4028     (prog1
4029         (save-excursion
4030           (set-buffer nntp-server-buffer)
4031           (let ((case-fold-search nil))
4032             (goto-char (point-min))
4033             (while (and (not found)
4034                         (search-forward id nil t))
4035               (beginning-of-line)
4036               (setq found (looking-at
4037                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4038                                    (regexp-quote id))))
4039               (or found (beginning-of-line 2)))
4040             (when found
4041               (beginning-of-line)
4042               (and
4043                (setq header (gnus-nov-parse-line
4044                              (read (current-buffer)) deps))
4045                (gnus-parent-id (mail-header-references header))))))
4046       (when header
4047         (let ((number (mail-header-number header)))
4048           (push number gnus-newsgroup-limit)
4049           (push header gnus-newsgroup-headers)
4050           (if (memq number gnus-newsgroup-unselected)
4051               (progn
4052                 (setq gnus-newsgroup-unreads
4053                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4054                                                number))
4055                 (setq gnus-newsgroup-unselected
4056                       (delq number gnus-newsgroup-unselected)))
4057             (push number gnus-newsgroup-ancient)))))))
4058
4059 (defun gnus-build-all-threads ()
4060   "Read all the headers."
4061   (let ((gnus-summary-ignore-duplicates t)
4062         (mail-parse-charset gnus-newsgroup-charset)
4063         (dependencies gnus-newsgroup-dependencies)
4064         header article)
4065     (save-excursion
4066       (set-buffer nntp-server-buffer)
4067       (let ((case-fold-search nil))
4068         (goto-char (point-min))
4069         (while (not (eobp))
4070           (ignore-errors
4071             (setq article (read (current-buffer))
4072                   header (gnus-nov-parse-line article dependencies)))
4073           (when header
4074             (save-excursion
4075               (set-buffer gnus-summary-buffer)
4076               (push header gnus-newsgroup-headers)
4077               (if (memq (setq article (mail-header-number header))
4078                         gnus-newsgroup-unselected)
4079                   (progn
4080                     (setq gnus-newsgroup-unreads
4081                           (gnus-add-to-sorted-list
4082                            gnus-newsgroup-unreads article))
4083                     (setq gnus-newsgroup-unselected
4084                           (delq article gnus-newsgroup-unselected)))
4085                 (push article gnus-newsgroup-ancient)))
4086             (forward-line 1)))))))
4087
4088 (defun gnus-summary-update-article-line (article header)
4089   "Update the line for ARTICLE using HEADERS."
4090   (let* ((id (mail-header-id header))
4091          (thread (gnus-id-to-thread id)))
4092     (unless thread
4093       (error "Article in no thread"))
4094     ;; Update the thread.
4095     (setcar thread header)
4096     (gnus-summary-goto-subject article)
4097     (let* ((datal (gnus-data-find-list article))
4098            (data (car datal))
4099            (buffer-read-only nil)
4100            (level (gnus-summary-thread-level)))
4101       (gnus-delete-line)
4102       (let ((inserted (- (point)
4103                          (progn
4104                            (gnus-summary-insert-line
4105                             header level nil 
4106                             (memq article gnus-newsgroup-undownloaded)
4107                             (gnus-article-mark article)
4108                             (memq article gnus-newsgroup-replied)
4109                             (memq article gnus-newsgroup-expirable)
4110                             ;; Only insert the Subject string when it's different
4111                             ;; from the previous Subject string.
4112                             (if (and
4113                                  gnus-show-threads
4114                                  (gnus-subject-equal
4115                                   (condition-case ()
4116                                       (mail-header-subject
4117                                        (gnus-data-header
4118                                         (cadr
4119                                          (gnus-data-find-list
4120                                           article
4121                                           (gnus-data-list t)))))
4122                                     ;; Error on the side of excessive subjects.
4123                                     (error ""))
4124                                   (mail-header-subject header)))
4125                                 ""
4126                               (mail-header-subject header))
4127                             nil (cdr (assq article gnus-newsgroup-scored))
4128                             (memq article gnus-newsgroup-processable))
4129                            (point)))))
4130         (when (cdr datal)
4131           (gnus-data-update-list
4132            (cdr datal) 
4133            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4134
4135 (defun gnus-summary-update-article (article &optional iheader)
4136   "Update ARTICLE in the summary buffer."
4137   (set-buffer gnus-summary-buffer)
4138   (let* ((header (gnus-summary-article-header article))
4139          (id (mail-header-id header))
4140          (data (gnus-data-find article))
4141          (thread (gnus-id-to-thread id))
4142          (references (mail-header-references header))
4143          (parent
4144           (gnus-id-to-thread
4145            (or (gnus-parent-id
4146                 (when (and references
4147                            (not (equal "" references)))
4148                   references))
4149                "none")))
4150          (buffer-read-only nil)
4151          (old (car thread)))
4152     (when thread
4153       (unless iheader
4154         (setcar thread nil)
4155         (when parent
4156           (delq thread parent)))
4157       (if (gnus-summary-insert-subject id header)
4158           ;; Set the (possibly) new article number in the data structure.
4159           (gnus-data-set-number data (gnus-id-to-article id))
4160         (setcar thread old)
4161         nil))))
4162
4163 (defun gnus-rebuild-thread (id &optional line)
4164   "Rebuild the thread containing ID.
4165 If LINE, insert the rebuilt thread starting on line LINE."
4166   (let ((buffer-read-only nil)
4167         old-pos current thread data)
4168     (if (not gnus-show-threads)
4169         (setq thread (list (car (gnus-id-to-thread id))))
4170       ;; Get the thread this article is part of.
4171       (setq thread (gnus-remove-thread id)))
4172     (setq old-pos (gnus-point-at-bol))
4173     (setq current (save-excursion
4174                     (and (re-search-backward "[\r\n]" nil t)
4175                          (gnus-summary-article-number))))
4176     ;; If this is a gathered thread, we have to go some re-gathering.
4177     (when (stringp (car thread))
4178       (let ((subject (car thread))
4179             roots thr)
4180         (setq thread (cdr thread))
4181         (while thread
4182           (unless (memq (setq thr (gnus-id-to-thread
4183                                    (gnus-root-id
4184                                     (mail-header-id (caar thread)))))
4185                         roots)
4186             (push thr roots))
4187           (setq thread (cdr thread)))
4188         ;; We now have all (unique) roots.
4189         (if (= (length roots) 1)
4190             ;; All the loose roots are now one solid root.
4191             (setq thread (car roots))
4192           (setq thread (cons subject (gnus-sort-threads roots))))))
4193     (let (threads)
4194       ;; We then insert this thread into the summary buffer.
4195       (when line
4196         (goto-char (point-min))
4197         (forward-line (1- line)))
4198       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4199         (if gnus-show-threads
4200             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4201           (gnus-summary-prepare-unthreaded thread))
4202         (setq data (nreverse gnus-newsgroup-data))
4203         (setq threads gnus-newsgroup-threads))
4204       ;; We splice the new data into the data structure.
4205       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4206       ;;!!! then we want to insert at the beginning of the buffer.
4207       ;;!!! That happens to be true with Gnus now, but that may
4208       ;;!!! change in the future.  Perhaps.
4209       (gnus-data-enter-list
4210        (if line nil current) data (- (point) old-pos))
4211       (setq gnus-newsgroup-threads
4212             (nconc threads gnus-newsgroup-threads))
4213       (gnus-data-compute-positions))))
4214
4215 (defun gnus-number-to-header (number)
4216   "Return the header for article NUMBER."
4217   (let ((headers gnus-newsgroup-headers))
4218     (while (and headers
4219                 (not (= number (mail-header-number (car headers)))))
4220       (pop headers))
4221     (when headers
4222       (car headers))))
4223
4224 (defun gnus-parent-headers (in-headers &optional generation)
4225   "Return the headers of the GENERATIONeth parent of HEADERS."
4226   (unless generation
4227     (setq generation 1))
4228   (let ((parent t)
4229         (headers in-headers)
4230         references)
4231     (while (and parent
4232                 (not (zerop generation))
4233                 (setq references (mail-header-references headers)))
4234       (setq headers (if (and references
4235                              (setq parent (gnus-parent-id references)))
4236                         (car (gnus-id-to-thread parent))
4237                       nil))
4238       (decf generation))
4239     (and (not (eq headers in-headers))
4240          headers)))
4241
4242 (defun gnus-id-to-thread (id)
4243   "Return the (sub-)thread where ID appears."
4244   (gnus-gethash id gnus-newsgroup-dependencies))
4245
4246 (defun gnus-id-to-article (id)
4247   "Return the article number of ID."
4248   (let ((thread (gnus-id-to-thread id)))
4249     (when (and thread
4250                (car thread))
4251       (mail-header-number (car thread)))))
4252
4253 (defun gnus-id-to-header (id)
4254   "Return the article headers of ID."
4255   (car (gnus-id-to-thread id)))
4256
4257 (defun gnus-article-displayed-root-p (article)
4258   "Say whether ARTICLE is a root(ish) article."
4259   (let ((level (gnus-summary-thread-level article))
4260         (refs (mail-header-references  (gnus-summary-article-header article)))
4261         particle)
4262     (cond
4263      ((null level) nil)
4264      ((zerop level) t)
4265      ((null refs) t)
4266      ((null (gnus-parent-id refs)) t)
4267      ((and (= 1 level)
4268            (null (setq particle (gnus-id-to-article
4269                                  (gnus-parent-id refs))))
4270            (null (gnus-summary-thread-level particle)))))))
4271
4272 (defun gnus-root-id (id)
4273   "Return the id of the root of the thread where ID appears."
4274   (let (last-id prev)
4275     (while (and id (setq prev (car (gnus-id-to-thread id))))
4276       (setq last-id id
4277             id (gnus-parent-id (mail-header-references prev))))
4278     last-id))
4279
4280 (defun gnus-articles-in-thread (thread)
4281   "Return the list of articles in THREAD."
4282   (cons (mail-header-number (car thread))
4283         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4284
4285 (defun gnus-remove-thread (id &optional dont-remove)
4286   "Remove the thread that has ID in it."
4287   (let (headers thread last-id)
4288     ;; First go up in this thread until we find the root.
4289     (setq last-id (gnus-root-id id)
4290           headers (message-flatten-list (gnus-id-to-thread last-id)))
4291     ;; We have now found the real root of this thread.  It might have
4292     ;; been gathered into some loose thread, so we have to search
4293     ;; through the threads to find the thread we wanted.
4294     (let ((threads gnus-newsgroup-threads)
4295           sub)
4296       (while threads
4297         (setq sub (car threads))
4298         (if (stringp (car sub))
4299             ;; This is a gathered thread, so we look at the roots
4300             ;; below it to find whether this article is in this
4301             ;; gathered root.
4302             (progn
4303               (setq sub (cdr sub))
4304               (while sub
4305                 (when (member (caar sub) headers)
4306                   (setq thread (car threads)
4307                         threads nil
4308                         sub nil))
4309                 (setq sub (cdr sub))))
4310           ;; It's an ordinary thread, so we check it.
4311           (when (eq (car sub) (car headers))
4312             (setq thread sub
4313                   threads nil)))
4314         (setq threads (cdr threads)))
4315       ;; If this article is in no thread, then it's a root.
4316       (if thread
4317           (unless dont-remove
4318             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4319         (setq thread (gnus-id-to-thread last-id)))
4320       (when thread
4321         (prog1
4322             thread                      ; We return this thread.
4323           (unless dont-remove
4324             (if (stringp (car thread))
4325                 (progn
4326                   ;; If we use dummy roots, then we have to remove the
4327                   ;; dummy root as well.
4328                   (when (eq gnus-summary-make-false-root 'dummy)
4329                     ;; We go to the dummy root by going to
4330                     ;; the first sub-"thread", and then one line up.
4331                     (gnus-summary-goto-article
4332                      (mail-header-number (caadr thread)))
4333                     (forward-line -1)
4334                     (gnus-delete-line)
4335                     (gnus-data-compute-positions))
4336                   (setq thread (cdr thread))
4337                   (while thread
4338                     (gnus-remove-thread-1 (car thread))
4339                     (setq thread (cdr thread))))
4340               (gnus-remove-thread-1 thread))))))))
4341
4342 (defun gnus-remove-thread-1 (thread)
4343   "Remove the thread THREAD recursively."
4344   (let ((number (mail-header-number (pop thread)))
4345         d)
4346     (setq thread (reverse thread))
4347     (while thread
4348       (gnus-remove-thread-1 (pop thread)))
4349     (when (setq d (gnus-data-find number))
4350       (goto-char (gnus-data-pos d))
4351       (gnus-summary-show-thread)
4352       (gnus-data-remove
4353        number
4354        (- (gnus-point-at-bol)
4355           (prog1
4356               (1+ (gnus-point-at-eol))
4357             (gnus-delete-line)))))))
4358
4359 (defun gnus-sort-threads-1 (threads func)
4360   (sort (mapcar (lambda (thread)
4361                   (cons (car thread)
4362                         (and (cdr thread)
4363                              (gnus-sort-threads-1 (cdr thread) func))))
4364                 threads) func))
4365
4366 (defun gnus-sort-threads (threads)
4367   "Sort THREADS."
4368   (if (not gnus-thread-sort-functions)
4369       threads
4370     (gnus-message 8 "Sorting threads...")
4371     (let ((max-lisp-eval-depth 5000))
4372       (prog1 (gnus-sort-threads-1
4373          threads
4374          (gnus-make-sort-function gnus-thread-sort-functions))
4375         (gnus-message 8 "Sorting threads...done")))))
4376
4377 (defun gnus-sort-articles (articles)
4378   "Sort ARTICLES."
4379   (when gnus-article-sort-functions
4380     (gnus-message 7 "Sorting articles...")
4381     (prog1
4382         (setq gnus-newsgroup-headers
4383               (sort articles (gnus-make-sort-function
4384                               gnus-article-sort-functions)))
4385       (gnus-message 7 "Sorting articles...done"))))
4386
4387 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4388 (defmacro gnus-thread-header (thread)
4389   "Return header of first article in THREAD.
4390 Note that THREAD must never, ever be anything else than a variable -
4391 using some other form will lead to serious barfage."
4392   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4393   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4394   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4395         (vector thread) 2))
4396
4397 (defsubst gnus-article-sort-by-number (h1 h2)
4398   "Sort articles by article number."
4399   (< (mail-header-number h1)
4400      (mail-header-number h2)))
4401
4402 (defun gnus-thread-sort-by-number (h1 h2)
4403   "Sort threads by root article number."
4404   (gnus-article-sort-by-number
4405    (gnus-thread-header h1) (gnus-thread-header h2)))
4406
4407 (defsubst gnus-article-sort-by-random (h1 h2)
4408   "Sort articles by article number."
4409   (zerop (random 2)))
4410
4411 (defun gnus-thread-sort-by-random (h1 h2)
4412   "Sort threads by root article number."
4413   (gnus-article-sort-by-random
4414    (gnus-thread-header h1) (gnus-thread-header h2)))
4415
4416 (defsubst gnus-article-sort-by-lines (h1 h2)
4417   "Sort articles by article Lines header."
4418   (< (mail-header-lines h1)
4419      (mail-header-lines h2)))
4420
4421 (defun gnus-thread-sort-by-lines (h1 h2)
4422   "Sort threads by root article Lines header."
4423   (gnus-article-sort-by-lines
4424    (gnus-thread-header h1) (gnus-thread-header h2)))
4425
4426 (defsubst gnus-article-sort-by-chars (h1 h2)
4427   "Sort articles by octet length."
4428   (< (mail-header-chars h1)
4429      (mail-header-chars h2)))
4430
4431 (defun gnus-thread-sort-by-chars (h1 h2)
4432   "Sort threads by root article octet length."
4433   (gnus-article-sort-by-chars
4434    (gnus-thread-header h1) (gnus-thread-header h2)))
4435
4436 (defsubst gnus-article-sort-by-author (h1 h2)
4437   "Sort articles by root author."
4438   (string-lessp
4439    (let ((addr (car (mime-entity-read-field h1 'From))))
4440      (or (std11-full-name-string addr)
4441          (std11-address-string addr)
4442          ""))
4443    (let ((addr (car (mime-entity-read-field h2 'From))))
4444      (or (std11-full-name-string addr)
4445          (std11-address-string addr)
4446          ""))
4447    ))
4448
4449 (defun gnus-thread-sort-by-author (h1 h2)
4450   "Sort threads by root author."
4451   (gnus-article-sort-by-author
4452    (gnus-thread-header h1)  (gnus-thread-header h2)))
4453
4454 (defsubst gnus-article-sort-by-subject (h1 h2)
4455   "Sort articles by root subject."
4456   (string-lessp
4457    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4458    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4459
4460 (defun gnus-thread-sort-by-subject (h1 h2)
4461   "Sort threads by root subject."
4462   (gnus-article-sort-by-subject
4463    (gnus-thread-header h1) (gnus-thread-header h2)))
4464
4465 (defsubst gnus-article-sort-by-date (h1 h2)
4466   "Sort articles by root article date."
4467   (time-less-p
4468    (gnus-date-get-time (mail-header-date h1))
4469    (gnus-date-get-time (mail-header-date h2))))
4470
4471 (defun gnus-thread-sort-by-date (h1 h2)
4472   "Sort threads by root article date."
4473   (gnus-article-sort-by-date
4474    (gnus-thread-header h1) (gnus-thread-header h2)))
4475
4476 (defsubst gnus-article-sort-by-score (h1 h2)
4477   "Sort articles by root article score.
4478 Unscored articles will be counted as having a score of zero."
4479   (> (or (cdr (assq (mail-header-number h1)
4480                     gnus-newsgroup-scored))
4481          gnus-summary-default-score 0)
4482      (or (cdr (assq (mail-header-number h2)
4483                     gnus-newsgroup-scored))
4484          gnus-summary-default-score 0)))
4485
4486 (defun gnus-thread-sort-by-score (h1 h2)
4487   "Sort threads by root article score."
4488   (gnus-article-sort-by-score
4489    (gnus-thread-header h1) (gnus-thread-header h2)))
4490
4491 (defun gnus-thread-sort-by-total-score (h1 h2)
4492   "Sort threads by the sum of all scores in the thread.
4493 Unscored articles will be counted as having a score of zero."
4494   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4495
4496 (defun gnus-thread-total-score (thread)
4497   ;; This function find the total score of THREAD.
4498   (cond
4499    ((null thread)
4500     0)
4501    ((consp thread)
4502     (if (stringp (car thread))
4503         (apply gnus-thread-score-function 0
4504                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4505       (gnus-thread-total-score-1 thread)))
4506    (t
4507     (gnus-thread-total-score-1 (list thread)))))
4508
4509 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4510   "Sort threads such that the thread with the most recently arrived article comes first."
4511   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4512
4513 (defun gnus-thread-highest-number (thread)
4514   "Return the highest article number in THREAD."
4515   (apply 'max (mapcar (lambda (header)
4516                         (mail-header-number header))
4517                       (message-flatten-list thread))))
4518
4519 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4520   "Sort threads such that the thread with the most recently dated article comes first."
4521   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4522
4523 (defun gnus-thread-latest-date (thread)
4524   "Return the highest article date in THREAD."
4525   (let ((previous-time 0))
4526     (apply 'max
4527            (mapcar
4528             (lambda (header)
4529               (setq previous-time
4530                     (time-to-seconds
4531                      (condition-case ()
4532                          (mail-header-parse-date (mail-header-date header))
4533                        (error previous-time)))))
4534             (sort
4535              (message-flatten-list thread)
4536              (lambda (h1 h2)
4537                (< (mail-header-number h1)
4538                   (mail-header-number h2))))))))
4539
4540 (defun gnus-thread-total-score-1 (root)
4541   ;; This function find the total score of the thread below ROOT.
4542   (setq root (car root))
4543   (apply gnus-thread-score-function
4544          (or (append
4545               (mapcar 'gnus-thread-total-score
4546                       (cdr (gnus-id-to-thread (mail-header-id root))))
4547               (when (> (mail-header-number root) 0)
4548                 (list (or (cdr (assq (mail-header-number root)
4549                                      gnus-newsgroup-scored))
4550                           gnus-summary-default-score 0))))
4551              (list gnus-summary-default-score)
4552              '(0))))
4553
4554 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4555 (defvar gnus-tmp-prev-subject nil)
4556 (defvar gnus-tmp-false-parent nil)
4557 (defvar gnus-tmp-root-expunged nil)
4558 (defvar gnus-tmp-dummy-line nil)
4559
4560 (eval-when-compile (defvar gnus-tmp-header))
4561 (defun gnus-extra-header (type &optional header)
4562   "Return the extra header of TYPE."
4563   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4564       ""))
4565
4566 (defvar gnus-tmp-thread-tree-header-string "")
4567
4568 (defcustom gnus-sum-thread-tree-root "> "
4569   "With %B spec, used for the root of a thread.
4570 If nil, use subject instead."
4571   :type 'string
4572   :group 'gnus-thread)
4573 (defcustom gnus-sum-thread-tree-false-root "> "
4574   "With %B spec, used for a false root of a thread.
4575 If nil, use subject instead."
4576   :type 'string
4577   :group 'gnus-thread)
4578 (defcustom gnus-sum-thread-tree-single-indent ""
4579   "With %B spec, used for a thread with just one message.
4580 If nil, use subject instead."
4581   :type 'string
4582   :group 'gnus-thread)
4583 (defcustom gnus-sum-thread-tree-vertical "| "
4584   "With %B spec, used for drawing a vertical line."
4585   :type 'string
4586   :group 'gnus-thread)
4587 (defcustom gnus-sum-thread-tree-indent "  "
4588   "With %B spec, used for indenting."
4589   :type 'string
4590   :group 'gnus-thread)
4591 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4592   "With %B spec, used for a leaf with brothers."
4593   :type 'string
4594   :group 'gnus-thread)
4595 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4596   "With %B spec, used for a leaf without brothers."
4597   :type 'string
4598   :group 'gnus-thread)
4599
4600 (defun gnus-summary-prepare-threads (threads)
4601   "Prepare summary buffer from THREADS and indentation LEVEL.
4602 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4603 or a straight list of headers."
4604   (gnus-message 7 "Generating summary...")
4605
4606   (setq gnus-newsgroup-threads threads)
4607   (beginning-of-line)
4608
4609   (let ((gnus-tmp-level 0)
4610         (default-score (or gnus-summary-default-score 0))
4611         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4612         (building-line-count gnus-summary-display-while-building)
4613         (building-count (integerp gnus-summary-display-while-building))
4614         thread number subject stack state gnus-tmp-gathered beg-match
4615         new-roots gnus-tmp-new-adopts thread-end simp-subject
4616         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4617         gnus-tmp-replied gnus-tmp-subject-or-nil
4618         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4619         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4620         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4621         tree-stack)
4622
4623     (setq gnus-tmp-prev-subject nil
4624           gnus-tmp-thread-tree-header-string "")
4625
4626     (if (vectorp (car threads))
4627         ;; If this is a straight (sic) list of headers, then a
4628         ;; threaded summary display isn't required, so we just create
4629         ;; an unthreaded one.
4630         (gnus-summary-prepare-unthreaded threads)
4631
4632       ;; Do the threaded display.
4633
4634       (if gnus-summary-display-while-building
4635           (switch-to-buffer (buffer-name)))
4636       (while (or threads stack gnus-tmp-new-adopts new-roots)
4637
4638         (if (and (= gnus-tmp-level 0)
4639                  (or (not stack)
4640                      (= (caar stack) 0))
4641                  (not gnus-tmp-false-parent)
4642                  (or gnus-tmp-new-adopts new-roots))
4643             (if gnus-tmp-new-adopts
4644                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4645                       thread (list (car gnus-tmp-new-adopts))
4646                       gnus-tmp-header (caar thread)
4647                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4648               (when new-roots
4649                 (setq thread (list (car new-roots))
4650                       gnus-tmp-header (caar thread)
4651                       new-roots (cdr new-roots))))
4652
4653           (if threads
4654               ;; If there are some threads, we do them before the
4655               ;; threads on the stack.
4656               (setq thread threads
4657                     gnus-tmp-header (caar thread))
4658             ;; There were no current threads, so we pop something off
4659             ;; the stack.
4660             (setq state (car stack)
4661                   gnus-tmp-level (car state)
4662                   tree-stack (cadr state)
4663                   thread (caddr state)
4664                   stack (cdr stack)
4665                   gnus-tmp-header (caar thread))))
4666
4667         (setq gnus-tmp-false-parent nil)
4668         (setq gnus-tmp-root-expunged nil)
4669         (setq thread-end nil)
4670
4671         (if (stringp gnus-tmp-header)
4672             ;; The header is a dummy root.
4673             (cond
4674              ((eq gnus-summary-make-false-root 'adopt)
4675               ;; We let the first article adopt the rest.
4676               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4677                                                (cddar thread)))
4678               (setq gnus-tmp-gathered
4679                     (nconc (mapcar
4680                             (lambda (h) (mail-header-number (car h)))
4681                             (cddar thread))
4682                            gnus-tmp-gathered))
4683               (setq thread (cons (list (caar thread)
4684                                        (cadar thread))
4685                                  (cdr thread)))
4686               (setq gnus-tmp-level -1
4687                     gnus-tmp-false-parent t))
4688              ((eq gnus-summary-make-false-root 'empty)
4689               ;; We print adopted articles with empty subject fields.
4690               (setq gnus-tmp-gathered
4691                     (nconc (mapcar
4692                             (lambda (h) (mail-header-number (car h)))
4693                             (cddar thread))
4694                            gnus-tmp-gathered))
4695               (setq gnus-tmp-level -1))
4696              ((eq gnus-summary-make-false-root 'dummy)
4697               ;; We remember that we probably want to output a dummy
4698               ;; root.
4699               (setq gnus-tmp-dummy-line gnus-tmp-header)
4700               (setq gnus-tmp-prev-subject gnus-tmp-header))
4701              (t
4702               ;; We do not make a root for the gathered
4703               ;; sub-threads at all.
4704               (setq gnus-tmp-level -1)))
4705
4706           (setq number (mail-header-number gnus-tmp-header)
4707                 subject (mail-header-subject gnus-tmp-header)
4708                 simp-subject (gnus-simplify-subject-fully subject))
4709
4710           (cond
4711            ;; If the thread has changed subject, we might want to make
4712            ;; this subthread into a root.
4713            ((and (null gnus-thread-ignore-subject)
4714                  (not (zerop gnus-tmp-level))
4715                  gnus-tmp-prev-subject
4716                  (not (string= gnus-tmp-prev-subject simp-subject)))
4717             (setq new-roots (nconc new-roots (list (car thread)))
4718                   thread-end t
4719                   gnus-tmp-header nil))
4720            ;; If the article lies outside the current limit,
4721            ;; then we do not display it.
4722            ((not (memq number gnus-newsgroup-limit))
4723             (setq gnus-tmp-gathered
4724                   (nconc (mapcar
4725                           (lambda (h) (mail-header-number (car h)))
4726                           (cdar thread))
4727                          gnus-tmp-gathered))
4728             (setq gnus-tmp-new-adopts (if (cdar thread)
4729                                           (append gnus-tmp-new-adopts
4730                                                   (cdar thread))
4731                                         gnus-tmp-new-adopts)
4732                   thread-end t
4733                   gnus-tmp-header nil)
4734             (when (zerop gnus-tmp-level)
4735               (setq gnus-tmp-root-expunged t)))
4736            ;; Perhaps this article is to be marked as read?
4737            ((and gnus-summary-mark-below
4738                  (< (or (cdr (assq number gnus-newsgroup-scored))
4739                         default-score)
4740                     gnus-summary-mark-below)
4741                  ;; Don't touch sparse articles.
4742                  (not (gnus-summary-article-sparse-p number))
4743                  (not (gnus-summary-article-ancient-p number)))
4744             (setq gnus-newsgroup-unreads
4745                   (delq number gnus-newsgroup-unreads))
4746             (if gnus-newsgroup-auto-expire
4747                 (setq gnus-newsgroup-expirable
4748                       (gnus-add-to-sorted-list
4749                        gnus-newsgroup-expirable number))
4750               (push (cons number gnus-low-score-mark)
4751                     gnus-newsgroup-reads))))
4752
4753           (when gnus-tmp-header
4754             ;; We may have an old dummy line to output before this
4755             ;; article.
4756             (when (and gnus-tmp-dummy-line
4757                        (gnus-subject-equal
4758                         gnus-tmp-dummy-line
4759                         (mail-header-subject gnus-tmp-header)))
4760               (gnus-summary-insert-dummy-line
4761                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4762               (setq gnus-tmp-dummy-line nil))
4763
4764             ;; Compute the mark.
4765             (setq gnus-tmp-unread (gnus-article-mark number))
4766
4767             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4768                                   gnus-tmp-header gnus-tmp-level)
4769                   gnus-newsgroup-data)
4770
4771             ;; Actually insert the line.
4772             (setq
4773              gnus-tmp-subject-or-nil
4774              (cond
4775               ((and gnus-thread-ignore-subject
4776                     gnus-tmp-prev-subject
4777                     (not (string= gnus-tmp-prev-subject simp-subject)))
4778                subject)
4779               ((zerop gnus-tmp-level)
4780                (if (and (eq gnus-summary-make-false-root 'empty)
4781                         (memq number gnus-tmp-gathered)
4782                         gnus-tmp-prev-subject
4783                         (string= gnus-tmp-prev-subject simp-subject))
4784                    gnus-summary-same-subject
4785                  subject))
4786               (t gnus-summary-same-subject)))
4787             (if (and (eq gnus-summary-make-false-root 'adopt)
4788                      (= gnus-tmp-level 1)
4789                      (memq number gnus-tmp-gathered))
4790                 (setq gnus-tmp-opening-bracket ?\<
4791                       gnus-tmp-closing-bracket ?\>)
4792               (setq gnus-tmp-opening-bracket ?\[
4793                     gnus-tmp-closing-bracket ?\]))
4794             (setq
4795              gnus-tmp-indentation
4796              (aref gnus-thread-indent-array gnus-tmp-level)
4797              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4798              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4799                                 gnus-summary-default-score 0)
4800              gnus-tmp-score-char
4801              (if (or (null gnus-summary-default-score)
4802                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4803                          gnus-summary-zcore-fuzz))
4804                  ?\ ;;;Whitespace
4805                (if (< gnus-tmp-score gnus-summary-default-score)
4806                    gnus-score-below-mark gnus-score-over-mark))
4807              gnus-tmp-replied
4808              (cond ((memq number gnus-newsgroup-processable)
4809                     gnus-process-mark)
4810                    ((memq number gnus-newsgroup-cached)
4811                     gnus-cached-mark)
4812                    ((memq number gnus-newsgroup-replied)
4813                     gnus-replied-mark)
4814                    ((memq number gnus-newsgroup-forwarded)
4815                     gnus-forwarded-mark)
4816                    ((memq number gnus-newsgroup-saved)
4817                     gnus-saved-mark)
4818                    ((memq number gnus-newsgroup-recent)
4819                     gnus-recent-mark)
4820                    ((memq number gnus-newsgroup-unseen)
4821                     gnus-unseen-mark)
4822                    (t gnus-no-mark))
4823              gnus-tmp-downloaded
4824              (cond ((memq number gnus-newsgroup-undownloaded) 
4825                     gnus-undownloaded-mark)
4826                    (gnus-newsgroup-agentized
4827                     gnus-downloaded-mark)
4828                    (t
4829                     gnus-no-mark))
4830              gnus-tmp-from (mail-header-from gnus-tmp-header)
4831              gnus-tmp-name
4832              (cond
4833               ((string-match "<[^>]+> *$" gnus-tmp-from)
4834                (setq beg-match (match-beginning 0))
4835                (or (and (string-match "^\".+\"" gnus-tmp-from)
4836                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4837                    (substring gnus-tmp-from 0 beg-match)))
4838               ((string-match "(.+)" gnus-tmp-from)
4839                (substring gnus-tmp-from
4840                           (1+ (match-beginning 0)) (1- (match-end 0))))
4841               (t gnus-tmp-from))
4842
4843              ;; Do the %B string
4844              gnus-tmp-thread-tree-header-string
4845              (cond
4846               ((not gnus-show-threads) "")
4847               ((zerop gnus-tmp-level)
4848                (cond ((cdar thread)
4849                       (or gnus-sum-thread-tree-root subject))
4850                      (gnus-tmp-new-adopts
4851                       (or gnus-sum-thread-tree-false-root subject))
4852                      (t
4853                       (or gnus-sum-thread-tree-single-indent subject))))
4854               (t
4855                (concat (apply 'concat
4856                               (mapcar (lambda (item)
4857                                         (if (= item 1)
4858                                             gnus-sum-thread-tree-vertical
4859                                           gnus-sum-thread-tree-indent))
4860                                       (cdr (reverse tree-stack))))
4861                        (if (nth 1 thread)
4862                            gnus-sum-thread-tree-leaf-with-other
4863                          gnus-sum-thread-tree-single-leaf)))))
4864             (when (string= gnus-tmp-name "")
4865               (setq gnus-tmp-name gnus-tmp-from))
4866             (unless (numberp gnus-tmp-lines)
4867               (setq gnus-tmp-lines -1))
4868             (if (= gnus-tmp-lines -1)
4869                 (setq gnus-tmp-lines "?")
4870               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4871               (gnus-put-text-property
4872              (point)
4873              (progn (eval gnus-summary-line-format-spec) (point))
4874                'gnus-number number)
4875             (when gnus-visual-p
4876               (forward-line -1)
4877               (gnus-run-hooks 'gnus-summary-update-hook)
4878               (forward-line 1))
4879
4880             (setq gnus-tmp-prev-subject simp-subject)))
4881
4882         (when (nth 1 thread)
4883           (push (list (max 0 gnus-tmp-level)
4884                       (copy-sequence tree-stack)
4885                       (nthcdr 1 thread))
4886                 stack))
4887         (push (if (nth 1 thread) 1 0) tree-stack)
4888         (incf gnus-tmp-level)
4889         (setq threads (if thread-end nil (cdar thread)))
4890         (if gnus-summary-display-while-building
4891             (if building-count
4892                 (progn
4893                   ;; use a set frequency
4894                   (setq building-line-count (1- building-line-count))
4895                   (when (= building-line-count 0)
4896                     (sit-for 0)
4897                     (setq building-line-count
4898                           gnus-summary-display-while-building)))
4899               ;; always
4900               (sit-for 0)))
4901         (unless threads
4902           (setq gnus-tmp-level 0)))))
4903   (gnus-message 7 "Generating summary...done"))
4904
4905 (defun gnus-summary-prepare-unthreaded (headers)
4906   "Generate an unthreaded summary buffer based on HEADERS."
4907   (let (header number mark)
4908
4909     (beginning-of-line)
4910
4911     (while headers
4912       ;; We may have to root out some bad articles...
4913       (when (memq (setq number (mail-header-number
4914                                 (setq header (pop headers))))
4915                   gnus-newsgroup-limit)
4916         ;; Mark article as read when it has a low score.
4917         (when (and gnus-summary-mark-below
4918                    (< (or (cdr (assq number gnus-newsgroup-scored))
4919                           gnus-summary-default-score 0)
4920                       gnus-summary-mark-below)
4921                    (not (gnus-summary-article-ancient-p number)))
4922           (setq gnus-newsgroup-unreads
4923                 (delq number gnus-newsgroup-unreads))
4924           (if gnus-newsgroup-auto-expire
4925               (push number gnus-newsgroup-expirable)
4926             (push (cons number gnus-low-score-mark)
4927                   gnus-newsgroup-reads)))
4928
4929         (setq mark (gnus-article-mark number))
4930         (push (gnus-data-make number mark (1+ (point)) header 0)
4931               gnus-newsgroup-data)
4932         (gnus-summary-insert-line
4933          header 0 number
4934          (memq number gnus-newsgroup-undownloaded)
4935          mark (memq number gnus-newsgroup-replied)
4936          (memq number gnus-newsgroup-expirable)
4937          (mail-header-subject header) nil
4938          (cdr (assq number gnus-newsgroup-scored))
4939          (memq number gnus-newsgroup-processable))))))
4940
4941 (defun gnus-summary-remove-list-identifiers ()
4942   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4943   (let ((regexp (if (consp gnus-list-identifiers)
4944                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4945                   gnus-list-identifiers))
4946         changed subject)
4947     (when regexp
4948       (dolist (header gnus-newsgroup-headers)
4949         (setq subject (mail-header-subject header)
4950               changed nil)
4951         (while (string-match
4952                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4953                 subject)
4954           (setq subject
4955                 (concat (substring subject 0 (match-beginning 2))
4956                         (substring subject (match-end 0)))
4957                 changed t))
4958         (when (and changed
4959                    (string-match
4960                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4961           (setq subject
4962                 (concat (substring subject 0 (match-beginning 1))
4963                         (substring subject (match-end 1)))))
4964         (when changed
4965           (mail-header-set-subject header subject))))))
4966
4967 (defun gnus-fetch-headers (articles)
4968   "Fetch headers of ARTICLES."
4969   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4970     (gnus-message 5 "Fetching headers for %s..." name)
4971     (prog1
4972         (if (eq 'nov
4973                 (setq gnus-headers-retrieved-by
4974                       (gnus-retrieve-headers
4975                        articles gnus-newsgroup-name
4976                        ;; We might want to fetch old headers, but
4977                        ;; not if there is only 1 article.
4978                        (and (or (and
4979                                  (not (eq gnus-fetch-old-headers 'some))
4980                                  (not (numberp gnus-fetch-old-headers)))
4981                                 (> (length articles) 1))
4982                             gnus-fetch-old-headers))))
4983             (gnus-get-newsgroup-headers-xover
4984              articles nil nil gnus-newsgroup-name t)
4985           (gnus-get-newsgroup-headers))
4986       (gnus-message 5 "Fetching headers for %s...done" name))))
4987
4988 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4989   "Select newsgroup GROUP.
4990 If READ-ALL is non-nil, all articles in the group are selected.
4991 If SELECT-ARTICLES, only select those articles from GROUP."
4992   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4993          ;;!!! Dirty hack; should be removed.
4994          (gnus-summary-ignore-duplicates
4995           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4996               t
4997             gnus-summary-ignore-duplicates))
4998          (info (nth 2 entry))
4999          articles fetched-articles cached)
5000
5001     (unless (gnus-check-server
5002              (set (make-local-variable 'gnus-current-select-method)
5003                   (gnus-find-method-for-group group)))
5004       (error "Couldn't open server"))
5005
5006     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5007         (gnus-activate-group group)     ; Or we can activate it...
5008         (progn                          ; Or we bug out.
5009           (when (equal major-mode 'gnus-summary-mode)
5010             (gnus-kill-buffer (current-buffer)))
5011           (error "Couldn't activate group %s: %s"
5012                  group (gnus-status-message group))))
5013
5014     (unless (gnus-request-group group t)
5015       (when (equal major-mode 'gnus-summary-mode)
5016         (gnus-kill-buffer (current-buffer)))
5017       (error "Couldn't request group %s: %s"
5018              group (gnus-status-message group)))
5019
5020     (when gnus-agent
5021       ;; The agent may be storing articles that are no longer in the
5022       ;; server's active range.  If that is the case, the active range
5023       ;; needs to be expanded such that the agent's articles can be
5024       ;; included in the summary.
5025       (let* ((gnus-command-method (gnus-find-method-for-group group))
5026              (alist (gnus-agent-load-alist group))
5027              (active (gnus-active group)))
5028         (if (and (car alist)
5029                  (< (caar alist) (car active)))
5030             (gnus-set-active group (cons (caar alist) (cdr active)))))
5031
5032       (setq gnus-summary-use-undownloaded-faces
5033             (not (gnus-agent-find-parameter 
5034                   group
5035                   'agent-disable-undownloaded-faces))))
5036
5037     (setq gnus-newsgroup-name group
5038           gnus-newsgroup-unselected nil
5039           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5040
5041     (let ((display (gnus-group-find-parameter group 'display)))
5042       (setq gnus-newsgroup-display
5043             (cond
5044              ((not (zerop (or (car-safe read-all) 0)))
5045               ;; The user entered the group with C-u SPC/RET, let's show
5046               ;; all articles.
5047               'gnus-not-ignore)
5048              ((eq display 'all)
5049               'gnus-not-ignore)
5050              ((arrayp display)
5051               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5052              ((numberp display)
5053               ;; The following is probably the "correct" solution, but
5054               ;; it makes Gnus fetch all headers and then limit the
5055               ;; articles (which is slow), so instead we hack the
5056               ;; select-articles parameter instead. -- Simon Josefsson
5057               ;; <jas@kth.se>
5058               ;;
5059               ;; (gnus-byte-compile
5060               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5061               ;;                         display)))))
5062               (setq select-articles
5063                     (gnus-uncompress-range
5064                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5065                              (if (> tmp 0)
5066                                  tmp
5067                                1))
5068                            (cdr (gnus-active group)))))
5069               nil)
5070              (t
5071               nil))))
5072
5073     (gnus-summary-setup-default-charset)
5074
5075     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5076     (when (gnus-virtual-group-p group)
5077       (setq cached gnus-newsgroup-cached))
5078
5079     (setq gnus-newsgroup-unreads
5080           (gnus-sorted-ndifference
5081            (gnus-sorted-ndifference gnus-newsgroup-unreads
5082                                     gnus-newsgroup-marked)
5083            gnus-newsgroup-dormant))
5084
5085     (setq gnus-newsgroup-processable nil)
5086
5087     (gnus-update-read-articles group gnus-newsgroup-unreads)
5088
5089     ;; Adjust and set lists of article marks.
5090     (when info
5091       (gnus-adjust-marked-articles info))
5092     (if (setq articles select-articles)
5093         (setq gnus-newsgroup-unselected
5094               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5095       (setq articles (gnus-articles-to-read group read-all)))
5096
5097     (cond
5098      ((null articles)
5099       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5100       'quit)
5101      ((eq articles 0) nil)
5102      (t
5103       ;; Init the dependencies hash table.
5104       (setq gnus-newsgroup-dependencies
5105             (gnus-make-hashtable (length articles)))
5106       (gnus-set-global-variables)
5107       ;; Retrieve the headers and read them in.
5108
5109       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5110
5111       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5112       (when cached
5113         (setq gnus-newsgroup-cached cached))
5114
5115       ;; Suppress duplicates?
5116       (when gnus-suppress-duplicates
5117         (gnus-dup-suppress-articles))
5118
5119       ;; Set the initial limit.
5120       (setq gnus-newsgroup-limit (copy-sequence articles))
5121       ;; Remove canceled articles from the list of unread articles.
5122       (setq fetched-articles
5123             (mapcar (lambda (headers) (mail-header-number headers))
5124                     gnus-newsgroup-headers))
5125       (setq gnus-newsgroup-articles fetched-articles)
5126       (setq gnus-newsgroup-unreads
5127             (gnus-sorted-nintersection
5128              gnus-newsgroup-unreads fetched-articles))
5129       (gnus-compute-unseen-list)
5130
5131       ;; Removed marked articles that do not exist.
5132       (gnus-update-missing-marks
5133        (gnus-sorted-difference articles fetched-articles))
5134       ;; We might want to build some more threads first.
5135       (when (and gnus-fetch-old-headers
5136                  (eq gnus-headers-retrieved-by 'nov))
5137         (if (eq gnus-fetch-old-headers 'invisible)
5138             (gnus-build-all-threads)
5139           (gnus-build-old-threads)))
5140       ;; Let the Gnus agent mark articles as read.
5141       (when gnus-agent
5142         (gnus-agent-get-undownloaded-list))
5143       ;; Remove list identifiers from subject
5144       (when gnus-list-identifiers
5145         (gnus-summary-remove-list-identifiers))
5146       ;; Check whether auto-expire is to be done in this group.
5147       (setq gnus-newsgroup-auto-expire
5148             (gnus-group-auto-expirable-p group))
5149       ;; Set up the article buffer now, if necessary.
5150       (unless gnus-single-article-buffer
5151         (gnus-article-setup-buffer))
5152       ;; First and last article in this newsgroup.
5153       (when gnus-newsgroup-headers
5154         (setq gnus-newsgroup-begin
5155               (mail-header-number (car gnus-newsgroup-headers))
5156               gnus-newsgroup-end
5157               (mail-header-number
5158                (gnus-last-element gnus-newsgroup-headers))))
5159       ;; GROUP is successfully selected.
5160       (or gnus-newsgroup-headers t)))))
5161
5162 (defun gnus-compute-unseen-list ()
5163   ;; The `seen' marks are treated specially.
5164   (if (not gnus-newsgroup-seen)
5165       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5166     (setq gnus-newsgroup-unseen
5167           (gnus-inverse-list-range-intersection
5168            gnus-newsgroup-articles gnus-newsgroup-seen))))
5169
5170 (defun gnus-summary-display-make-predicate (display)
5171   (require 'gnus-agent)
5172   (when (= (length display) 1)
5173     (setq display (car display)))
5174   (unless gnus-summary-display-cache
5175     (dolist (elem (append '((unread . unread)
5176                             (read . read)
5177                             (unseen . unseen))
5178                           gnus-article-mark-lists))
5179       (push (cons (cdr elem)
5180                   (gnus-byte-compile
5181                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5182             gnus-summary-display-cache)))
5183   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5184         (gnus-category-predicate-cache gnus-summary-display-cache))
5185     (gnus-get-predicate display)))
5186
5187 ;; Uses the dynamically bound `number' variable.
5188 (eval-when-compile
5189   (defvar number))
5190 (defun gnus-article-marked-p (type &optional article)
5191   (let ((article (or article number)))
5192     (cond
5193      ((eq type 'tick)
5194       (memq article gnus-newsgroup-marked))
5195      ((eq type 'spam)
5196       (memq article gnus-newsgroup-spam-marked))
5197      ((eq type 'unsend)
5198       (memq article gnus-newsgroup-unsendable))
5199      ((eq type 'undownload)
5200       (memq article gnus-newsgroup-undownloaded))
5201      ((eq type 'download)
5202       (memq article gnus-newsgroup-downloadable))
5203      ((eq type 'unread)
5204       (memq article gnus-newsgroup-unreads))
5205      ((eq type 'read)
5206       (memq article gnus-newsgroup-reads))
5207      ((eq type 'dormant)
5208       (memq article gnus-newsgroup-dormant) )
5209      ((eq type 'expire)
5210       (memq article gnus-newsgroup-expirable))
5211      ((eq type 'reply)
5212       (memq article gnus-newsgroup-replied))
5213      ((eq type 'killed)
5214       (memq article gnus-newsgroup-killed))
5215      ((eq type 'bookmark)
5216       (assq article gnus-newsgroup-bookmarks))
5217      ((eq type 'score)
5218       (assq article gnus-newsgroup-scored))
5219      ((eq type 'save)
5220       (memq article gnus-newsgroup-saved))
5221      ((eq type 'cache)
5222       (memq article gnus-newsgroup-cached))
5223      ((eq type 'forward)
5224       (memq article gnus-newsgroup-forwarded))
5225      ((eq type 'seen)
5226       (not (memq article gnus-newsgroup-unseen)))
5227      ((eq type 'recent)
5228       (memq article gnus-newsgroup-recent))
5229      (t t))))
5230
5231 (defun gnus-articles-to-read (group &optional read-all)
5232   "Find out what articles the user wants to read."
5233   (let* ((display (gnus-group-find-parameter group 'display))
5234          (articles
5235           ;; Select all articles if `read-all' is non-nil, or if there
5236           ;; are no unread articles.
5237           (if (or read-all
5238                   (and (zerop (length gnus-newsgroup-marked))
5239                        (zerop (length gnus-newsgroup-unreads)))
5240                   ;; Fetch all if the predicate is non-nil.
5241                   gnus-newsgroup-display)
5242               ;; We want to select the headers for all the articles in
5243               ;; the group, so we select either all the active
5244               ;; articles in the group, or (if that's nil), the
5245               ;; articles in the cache.
5246               (or
5247                (gnus-uncompress-range (gnus-active group))
5248                (gnus-cache-articles-in-group group))
5249             ;; Select only the "normal" subset of articles.
5250             (gnus-sorted-nunion
5251              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5252              gnus-newsgroup-unreads)))
5253          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5254          (scored (length scored-list))
5255          (number (length articles))
5256          (marked (+ (length gnus-newsgroup-marked)
5257                     (length gnus-newsgroup-dormant)))
5258          (select
5259           (cond
5260            ((numberp read-all)
5261             read-all)
5262            ((numberp gnus-newsgroup-display)
5263             gnus-newsgroup-display)
5264            (t
5265             (condition-case ()
5266                 (cond
5267                  ((and (or (<= scored marked) (= scored number))
5268                        (numberp gnus-large-newsgroup)
5269                        (> number gnus-large-newsgroup))
5270                   (let* ((cursor-in-echo-area nil)
5271                          (initial (gnus-parameter-large-newsgroup-initial
5272                                    gnus-newsgroup-name))
5273                          (input
5274                           (read-string
5275                            (format
5276                             "How many articles from %s (%s %d): "
5277                             (gnus-limit-string
5278                              (gnus-group-decoded-name gnus-newsgroup-name)
5279                              35)
5280                             (if initial "max" "default")
5281                             number)
5282                            (if initial
5283                                (cons (number-to-string initial)
5284                                      0)))))
5285                     (if (string-match "^[ \t]*$" input) number input)))
5286                  ((and (> scored marked) (< scored number)
5287                        (> (- scored number) 20))
5288                   (let ((input
5289                          (read-string
5290                           (format "%s %s (%d scored, %d total): "
5291                                   "How many articles from"
5292                                   (gnus-group-decoded-name group)
5293                                   scored number))))
5294                     (if (string-match "^[ \t]*$" input)
5295                         number input)))
5296                  (t number))
5297               (quit
5298                (message "Quit getting the articles to read")
5299                nil))))))
5300     (setq select (if (stringp select) (string-to-number select) select))
5301     (if (or (null select) (zerop select))
5302         select
5303       (if (and (not (zerop scored)) (<= (abs select) scored))
5304           (progn
5305             (setq articles (sort scored-list '<))
5306             (setq number (length articles)))
5307         (setq articles (copy-sequence articles)))
5308
5309       (when (< (abs select) number)
5310         (if (< select 0)
5311             ;; Select the N oldest articles.
5312             (setcdr (nthcdr (1- (abs select)) articles) nil)
5313           ;; Select the N most recent articles.
5314           (setq articles (nthcdr (- number select) articles))))
5315       (setq gnus-newsgroup-unselected
5316             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5317       (when gnus-alter-articles-to-read-function
5318         (setq articles
5319               (sort
5320                (funcall gnus-alter-articles-to-read-function
5321                         gnus-newsgroup-name articles)
5322                '<)))
5323       articles)))
5324
5325 (defun gnus-killed-articles (killed articles)
5326   (let (out)
5327     (while articles
5328       (when (inline (gnus-member-of-range (car articles) killed))
5329         (push (car articles) out))
5330       (setq articles (cdr articles)))
5331     out))
5332
5333 (defun gnus-uncompress-marks (marks)
5334   "Uncompress the mark ranges in MARKS."
5335   (let ((uncompressed '(score bookmark))
5336         out)
5337     (while marks
5338       (if (memq (caar marks) uncompressed)
5339           (push (car marks) out)
5340         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5341       (setq marks (cdr marks)))
5342     out))
5343
5344 (defun gnus-article-mark-to-type (mark)
5345   "Return the type of MARK."
5346   (or (cadr (assq mark gnus-article-special-mark-lists))
5347       'list))
5348
5349 (defun gnus-article-unpropagatable-p (mark)
5350   "Return whether MARK should be propagated to backend."
5351   (memq mark gnus-article-unpropagated-mark-lists))
5352
5353 (defun gnus-adjust-marked-articles (info)
5354   "Set all article lists and remove all marks that are no longer valid."
5355   (let* ((marked-lists (gnus-info-marks info))
5356          (active (gnus-active (gnus-info-group info)))
5357          (min (car active))
5358          (max (cdr active))
5359          (types gnus-article-mark-lists)
5360          marks var articles article mark mark-type)
5361
5362     (dolist (marks marked-lists)
5363       (setq mark (car marks)
5364             mark-type (gnus-article-mark-to-type mark)
5365             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5366
5367       ;; We set the variable according to the type of the marks list,
5368       ;; and then adjust the marks to a subset of the active articles.
5369       (cond
5370        ;; Adjust "simple" lists.
5371        ((eq mark-type 'list)
5372         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5373         (when (memq mark '(tick dormant expire reply save))
5374           (while articles
5375             (when (or (< (setq article (pop articles)) min) (> article max))
5376               (set var (delq article (symbol-value var)))))))
5377        ;; Adjust assocs.
5378        ((eq mark-type 'tuple)
5379         (set var (setq articles (cdr marks)))
5380         (when (not (listp (cdr (symbol-value var))))
5381           (set var (list (symbol-value var))))
5382         (when (not (listp (cdr articles)))
5383           (setq articles (list articles)))
5384         (while articles
5385           (when (or (not (consp (setq article (pop articles))))
5386                     (< (car article) min)
5387                     (> (car article) max))
5388             (set var (delq article (symbol-value var))))))
5389        ;; Adjust ranges (sloppily).
5390        ((eq mark-type 'range)
5391         (cond
5392          ((eq mark 'seen)
5393           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5394           ;; It should be (seen (NUM1 . NUM2)).
5395           (when (numberp (cddr marks))
5396             (setcdr marks (list (cdr marks))))
5397           (setq articles (cdr marks))
5398           (while (and articles
5399                       (or (and (consp (car articles))
5400                                (> min (cdar articles)))
5401                           (and (numberp (car articles))
5402                                (> min (car articles)))))
5403             (pop articles))
5404           (set var articles))))))))
5405
5406 (defun gnus-update-missing-marks (missing)
5407   "Go through the list of MISSING articles and remove them from the mark lists."
5408   (when missing
5409     (let (var m)
5410       ;; Go through all types.
5411       (dolist (elem gnus-article-mark-lists)
5412         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5413           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5414           (when (symbol-value var)
5415             ;; This list has articles.  So we delete all missing
5416             ;; articles from it.
5417             (setq m missing)
5418             (while m
5419               (set var (delq (pop m) (symbol-value var))))))))))
5420
5421 (defun gnus-update-marks ()
5422   "Enter the various lists of marked articles into the newsgroup info list."
5423   (let ((types gnus-article-mark-lists)
5424         (info (gnus-get-info gnus-newsgroup-name))
5425         type list newmarked symbol delta-marks)
5426     (when info
5427       ;; Add all marks lists to the list of marks lists.
5428       (while (setq type (pop types))
5429         (setq list (symbol-value
5430                     (setq symbol
5431                           (intern (format "gnus-newsgroup-%s" (car type))))))
5432
5433         (when list
5434           ;; Get rid of the entries of the articles that have the
5435           ;; default score.
5436           (when (and (eq (cdr type) 'score)
5437                      gnus-save-score
5438                      list)
5439             (let* ((arts list)
5440                    (prev (cons nil list))
5441                    (all prev))
5442               (while arts
5443                 (if (or (not (consp (car arts)))
5444                         (= (cdar arts) gnus-summary-default-score))
5445                     (setcdr prev (cdr arts))
5446                   (setq prev arts))
5447                 (setq arts (cdr arts)))
5448               (setq list (cdr all)))))
5449
5450         (when (eq (cdr type) 'seen)
5451           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5452
5453         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5454           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5455
5456         (when (and (gnus-check-backend-function
5457                     'request-set-mark gnus-newsgroup-name)
5458                    (not (gnus-article-unpropagatable-p (cdr type))))
5459           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5460                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5461                  (add (gnus-remove-from-range
5462                        (gnus-copy-sequence list) old)))
5463             (when add
5464               (push (list add 'add (list (cdr type))) delta-marks))
5465             (when del
5466               (push (list del 'del (list (cdr type))) delta-marks))))
5467
5468         (when list
5469           (push (cons (cdr type) list) newmarked)))
5470
5471       (when delta-marks
5472         (unless (gnus-check-group gnus-newsgroup-name)
5473           (error "Can't open server for %s" gnus-newsgroup-name))
5474         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5475
5476       ;; Enter these new marks into the info of the group.
5477       (if (nthcdr 3 info)
5478           (setcar (nthcdr 3 info) newmarked)
5479         ;; Add the marks lists to the end of the info.
5480         (when newmarked
5481           (setcdr (nthcdr 2 info) (list newmarked))))
5482
5483       ;; Cut off the end of the info if there's nothing else there.
5484       (let ((i 5))
5485         (while (and (> i 2)
5486                     (not (nth i info)))
5487           (when (nthcdr (decf i) info)
5488             (setcdr (nthcdr i info) nil)))))))
5489
5490 (defun gnus-set-mode-line (where)
5491   "Set the mode line of the article or summary buffers.
5492 If WHERE is `summary', the summary mode line format will be used."
5493   ;; Is this mode line one we keep updated?
5494   (when (and (memq where gnus-updated-mode-lines)
5495              (symbol-value
5496               (intern (format "gnus-%s-mode-line-format-spec" where))))
5497     (let (mode-string)
5498       (save-excursion
5499         ;; We evaluate this in the summary buffer since these
5500         ;; variables are buffer-local to that buffer.
5501         (set-buffer gnus-summary-buffer)
5502         ;; We bind all these variables that are used in the `eval' form
5503         ;; below.
5504         (let* ((mformat (symbol-value
5505                          (intern
5506                           (format "gnus-%s-mode-line-format-spec" where))))
5507                (gnus-tmp-group-name (gnus-group-decoded-name
5508                                      gnus-newsgroup-name))
5509                (gnus-tmp-article-number (or gnus-current-article 0))
5510                (gnus-tmp-unread gnus-newsgroup-unreads)
5511                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5512                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5513                (gnus-tmp-unread-and-unselected
5514                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5515                             (zerop gnus-tmp-unselected))
5516                        "")
5517                       ((zerop gnus-tmp-unselected)
5518                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5519                       (t (format "{%d(+%d) more}"
5520                                  gnus-tmp-unread-and-unticked
5521                                  gnus-tmp-unselected))))
5522                (gnus-tmp-subject
5523                 (if (and gnus-current-headers
5524                          (vectorp gnus-current-headers))
5525                     (gnus-mode-string-quote
5526                      (mail-header-subject gnus-current-headers))
5527                   ""))
5528                bufname-length max-len
5529                gnus-tmp-header);; passed as argument to any user-format-funcs
5530           (setq mode-string (eval mformat))
5531           (setq bufname-length (if (string-match "%b" mode-string)
5532                                    (- (length
5533                                        (buffer-name
5534                                         (if (eq where 'summary)
5535                                             nil
5536                                           (get-buffer gnus-article-buffer))))
5537                                       2)
5538                                  0))
5539           (setq max-len (max 4 (if gnus-mode-non-string-length
5540                                    (- (window-width)
5541                                       gnus-mode-non-string-length
5542                                       bufname-length)
5543                                  (length mode-string))))
5544           ;; We might have to chop a bit of the string off...
5545           (when (> (length mode-string) max-len)
5546             (setq mode-string
5547                   (concat (gnus-truncate-string mode-string (- max-len 3))
5548                           "...")))
5549           ;; Pad the mode string a bit.
5550           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5551       ;; Update the mode line.
5552       (setq mode-line-buffer-identification
5553             (gnus-mode-line-buffer-identification (list mode-string)))
5554       (set-buffer-modified-p t))))
5555
5556 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5557   "Go through the HEADERS list and add all Xrefs to a hash table.
5558 The resulting hash table is returned, or nil if no Xrefs were found."
5559   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5560          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5561          (xref-hashtb (gnus-make-hashtable))
5562          start group entry number xrefs header)
5563     (while headers
5564       (setq header (pop headers))
5565       (when (and (setq xrefs (mail-header-xref header))
5566                  (not (memq (setq number (mail-header-number header))
5567                             unreads)))
5568         (setq start 0)
5569         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5570           (setq start (match-end 0))
5571           (setq group (if prefix
5572                           (concat prefix (substring xrefs (match-beginning 1)
5573                                                     (match-end 1)))
5574                         (substring xrefs (match-beginning 1) (match-end 1))))
5575           (setq number
5576                 (string-to-int (substring xrefs (match-beginning 2)
5577                                           (match-end 2))))
5578           (if (setq entry (gnus-gethash group xref-hashtb))
5579               (setcdr entry (cons number (cdr entry)))
5580             (gnus-sethash group (cons number nil) xref-hashtb)))))
5581     (and start xref-hashtb)))
5582
5583 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5584   "Look through all the headers and mark the Xrefs as read."
5585   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5586         name entry info xref-hashtb idlist method nth4)
5587     (save-excursion
5588       (set-buffer gnus-group-buffer)
5589       (when (setq xref-hashtb
5590                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5591         (mapatoms
5592          (lambda (group)
5593            (unless (string= from-newsgroup (setq name (symbol-name group)))
5594              (setq idlist (symbol-value group))
5595              ;; Dead groups are not updated.
5596              (and (prog1
5597                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5598                             info (nth 2 entry))
5599                     (when (stringp (setq nth4 (gnus-info-method info)))
5600                       (setq nth4 (gnus-server-to-method nth4))))
5601                   ;; Only do the xrefs if the group has the same
5602                   ;; select method as the group we have just read.
5603                   (or (gnus-methods-equal-p
5604                        nth4 (gnus-find-method-for-group from-newsgroup))
5605                       virtual
5606                       (equal nth4 (setq method (gnus-find-method-for-group
5607                                                 from-newsgroup)))
5608                       (and (equal (car nth4) (car method))
5609                            (equal (nth 1 nth4) (nth 1 method))))
5610                   gnus-use-cross-reference
5611                   (or (not (eq gnus-use-cross-reference t))
5612                       virtual
5613                       ;; Only do cross-references on subscribed
5614                       ;; groups, if that is what is wanted.
5615                       (<= (gnus-info-level info) gnus-level-subscribed))
5616                   (gnus-group-make-articles-read name idlist))))
5617          xref-hashtb)))))
5618
5619 (defun gnus-compute-read-articles (group articles)
5620   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5621          (info (nth 2 entry))
5622          (active (gnus-active group))
5623          ninfo)
5624     (when entry
5625       ;; First peel off all invalid article numbers.
5626       (when active
5627         (let ((ids articles)
5628               id first)
5629           (while (setq id (pop ids))
5630             (when (and first (> id (cdr active)))
5631               ;; We'll end up in this situation in one particular
5632               ;; obscure situation.  If you re-scan a group and get
5633               ;; a new article that is cross-posted to a different
5634               ;; group that has not been re-scanned, you might get
5635               ;; crossposted article that has a higher number than
5636               ;; Gnus believes possible.  So we re-activate this
5637               ;; group as well.  This might mean doing the
5638               ;; crossposting thingy will *increase* the number
5639               ;; of articles in some groups.  Tsk, tsk.
5640               (setq active (or (gnus-activate-group group) active)))
5641             (when (or (> id (cdr active))
5642                       (< id (car active)))
5643               (setq articles (delq id articles))))))
5644       ;; If the read list is nil, we init it.
5645       (if (and active
5646                (null (gnus-info-read info))
5647                (> (car active) 1))
5648           (setq ninfo (cons 1 (1- (car active))))
5649         (setq ninfo (gnus-info-read info)))
5650       ;; Then we add the read articles to the range.
5651       (gnus-add-to-range
5652        ninfo (setq articles (sort articles '<))))))
5653
5654 (defun gnus-group-make-articles-read (group articles)
5655   "Update the info of GROUP to say that ARTICLES are read."
5656   (let* ((num 0)
5657          (entry (gnus-gethash group gnus-newsrc-hashtb))
5658          (info (nth 2 entry))
5659          (active (gnus-active group))
5660          range)
5661     (when entry
5662       (setq range (gnus-compute-read-articles group articles))
5663       (save-excursion
5664         (set-buffer gnus-group-buffer)
5665         (gnus-undo-register
5666           `(progn
5667              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5668              (gnus-info-set-read ',info ',(gnus-info-read info))
5669              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5670              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5671              (gnus-group-update-group ,group t))))
5672       ;; Add the read articles to the range.
5673       (gnus-info-set-read info range)
5674       (gnus-request-set-mark group (list (list range 'add '(read))))
5675       ;; Then we have to re-compute how many unread
5676       ;; articles there are in this group.
5677       (when active
5678         (cond
5679          ((not range)
5680           (setq num (- (1+ (cdr active)) (car active))))
5681          ((not (listp (cdr range)))
5682           (setq num (- (cdr active) (- (1+ (cdr range))
5683                                        (car range)))))
5684          (t
5685           (while range
5686             (if (numberp (car range))
5687                 (setq num (1+ num))
5688               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5689             (setq range (cdr range)))
5690           (setq num (- (cdr active) num))))
5691         ;; Update the number of unread articles.
5692         (setcar entry num)
5693         ;; Update the group buffer.
5694         (unless (gnus-ephemeral-group-p group)
5695           (gnus-group-update-group group t))))))
5696
5697 (defvar gnus-newsgroup-none-id 0)
5698
5699 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5700   (let ((cur nntp-server-buffer)
5701         (dependencies
5702          (or dependencies
5703              (save-excursion (set-buffer gnus-summary-buffer)
5704                              gnus-newsgroup-dependencies)))
5705         headers id end ref
5706         (mail-parse-charset gnus-newsgroup-charset)
5707         (mail-parse-ignored-charsets
5708          (save-excursion (condition-case nil
5709                              (set-buffer gnus-summary-buffer)
5710                            (error))
5711                          gnus-newsgroup-ignored-charsets)))
5712     (save-excursion
5713       (set-buffer nntp-server-buffer)
5714       ;; Translate all TAB characters into SPACE characters.
5715       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5716       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5717       (gnus-run-hooks 'gnus-parse-headers-hook)
5718       (let ((case-fold-search t)
5719             in-reply-to header p lines chars ctype)
5720         (goto-char (point-min))
5721         ;; Search to the beginning of the next header.  Error messages
5722         ;; do not begin with 2 or 3.
5723         (while (re-search-forward "^[23][0-9]+ " nil t)
5724           (setq id nil
5725                 ref nil)
5726           ;; This implementation of this function, with nine
5727           ;; search-forwards instead of the one re-search-forward and
5728           ;; a case (which basically was the old function) is actually
5729           ;; about twice as fast, even though it looks messier.  You
5730           ;; can't have everything, I guess.  Speed and elegance
5731           ;; doesn't always go hand in hand.
5732           (setq
5733            header
5734            (make-full-mail-header
5735             ;; Number.
5736             (prog1
5737                 (read cur)
5738               (end-of-line)
5739               (setq p (point))
5740               (narrow-to-region (point)
5741                                 (or (and (search-forward "\n.\n" nil t)
5742                                          (- (point) 2))
5743                                     (point))))
5744             ;; Subject.
5745             (progn
5746               (goto-char p)
5747               (if (search-forward "\nsubject:" nil t)
5748                   (nnheader-header-value)
5749                 "(none)"))
5750             ;; From.
5751             (progn
5752               (goto-char p)
5753               (if (search-forward "\nfrom:" nil t)
5754                   (nnheader-header-value)
5755                 "(nobody)"))
5756             ;; Date.
5757             (progn
5758               (goto-char p)
5759               (if (search-forward "\ndate:" nil t)
5760                   (nnheader-header-value) ""))
5761             ;; Message-ID.
5762             (progn
5763               (goto-char p)
5764               (setq id (if (re-search-forward
5765                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5766                            ;; We do it this way to make sure the Message-ID
5767                            ;; is (somewhat) syntactically valid.
5768                            (buffer-substring (match-beginning 1)
5769                                              (match-end 1))
5770                          ;; If there was no message-id, we just fake one
5771                          ;; to make subsequent routines simpler.
5772                          (nnheader-generate-fake-message-id))))
5773             ;; References.
5774             (progn
5775               (goto-char p)
5776               (if (search-forward "\nreferences:" nil t)
5777                   (progn
5778                     (setq end (point))
5779                     (prog1
5780                         (nnheader-header-value)
5781                       (setq ref
5782                             (buffer-substring
5783                              (progn
5784                                ;; (end-of-line)
5785                                (search-backward ">" end t)
5786                                (1+ (point)))
5787                              (progn
5788                                (search-backward "<" end t)
5789                                (point))))))
5790                 ;; Get the references from the in-reply-to header if there
5791                 ;; were no references and the in-reply-to header looks
5792                 ;; promising.
5793                 (if (and (search-forward "\nin-reply-to:" nil t)
5794                          (setq in-reply-to (nnheader-header-value))
5795                          (string-match "<[^>]+>" in-reply-to))
5796                     (let (ref2)
5797                       (setq ref (substring in-reply-to (match-beginning 0)
5798                                            (match-end 0)))
5799                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5800                         (setq ref2 (substring in-reply-to (match-beginning 0)
5801                                               (match-end 0)))
5802                         (when (> (length ref2) (length ref))
5803                           (setq ref ref2)))
5804                       ref)
5805                   (setq ref nil))))
5806             ;; Chars.
5807             (progn
5808               (goto-char p)
5809               (if (search-forward "\nchars: " nil t)
5810                   (if (numberp (setq chars (ignore-errors (read cur))))
5811                       chars -1)
5812                 -1))
5813             ;; Lines.
5814             (progn
5815               (goto-char p)
5816               (if (search-forward "\nlines: " nil t)
5817                   (if (numberp (setq lines (ignore-errors (read cur))))
5818                       lines -1)
5819                 -1))
5820             ;; Xref.
5821             (progn
5822               (goto-char p)
5823               (and (search-forward "\nxref:" nil t)
5824                    (nnheader-header-value)))
5825             ;; Extra.
5826             (when gnus-extra-headers
5827               (let ((extra gnus-extra-headers)
5828                     out)
5829                 (while extra
5830                   (goto-char p)
5831                   (when (search-forward
5832                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5833                     (push (cons (car extra) (nnheader-header-value)) out))
5834                   (pop extra))
5835                 out))))
5836           (goto-char p)
5837           (if (and (search-forward "\ncontent-type: " nil t)
5838                    (setq ctype (nnheader-header-value)))
5839               (mime-entity-set-content-type-internal
5840                header (mime-parse-Content-Type ctype)))
5841           (when (equal id ref)
5842             (setq ref nil))
5843
5844           (when gnus-alter-header-function
5845             (funcall gnus-alter-header-function header)
5846             (setq id (mail-header-id header)
5847                   ref (gnus-parent-id (mail-header-references header))))
5848
5849           (when (setq header
5850                       (gnus-dependencies-add-header
5851                        header dependencies force-new))
5852             (push header headers))
5853           (goto-char (point-max))
5854           (widen))
5855         (nreverse headers)))))
5856
5857 ;; Goes through the xover lines and returns a list of vectors
5858 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5859                                                   force-new dependencies
5860                                                   group also-fetch-heads)
5861   "Parse the news overview data in the server buffer.
5862 Return a list of headers that match SEQUENCE (see
5863 `nntp-retrieve-headers')."
5864   ;; Get the Xref when the users reads the articles since most/some
5865   ;; NNTP servers do not include Xrefs when using XOVER.
5866   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5867   (let ((mail-parse-charset gnus-newsgroup-charset)
5868         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5869         (cur nntp-server-buffer)
5870         (dependencies (or dependencies gnus-newsgroup-dependencies))
5871         (allp (cond
5872                ((eq gnus-read-all-available-headers t)
5873                 t)
5874                ((stringp gnus-read-all-available-headers)
5875                 (string-match gnus-read-all-available-headers group))
5876                (t
5877                 nil)))
5878         number headers header)
5879     (save-excursion
5880       (set-buffer nntp-server-buffer)
5881       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5882       ;; Allow the user to mangle the headers before parsing them.
5883       (gnus-run-hooks 'gnus-parse-headers-hook)
5884       (goto-char (point-min))
5885       (gnus-parse-without-error
5886         (while (and (or sequence allp)
5887                     (not (eobp)))
5888           (setq number (read cur))
5889           (when (not allp)
5890             (while (and sequence
5891                         (< (car sequence) number))
5892               (setq sequence (cdr sequence))))
5893           (when (and (or allp
5894                          (and sequence
5895                               (eq number (car sequence))))
5896                      (progn
5897                        (setq sequence (cdr sequence))
5898                        (setq header (inline
5899                                       (gnus-nov-parse-line
5900                                        number dependencies force-new)))))
5901             (push header headers))
5902           (forward-line 1)))
5903       ;; A common bug in inn is that if you have posted an article and
5904       ;; then retrieves the active file, it will answer correctly --
5905       ;; the new article is included.  However, a NOV entry for the
5906       ;; article may not have been generated yet, so this may fail.
5907       ;; We work around this problem by retrieving the last few
5908       ;; headers using HEAD.
5909       (if (or (not also-fetch-heads)
5910               (not sequence))
5911           ;; We (probably) got all the headers.
5912           (nreverse headers)
5913         (let ((gnus-nov-is-evil t))
5914           (nconc
5915            (nreverse headers)
5916            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5917              (gnus-get-newsgroup-headers))))))))
5918
5919 (defun gnus-article-get-xrefs ()
5920   "Fill in the Xref value in `gnus-current-headers', if necessary.
5921 This is meant to be called in `gnus-article-internal-prepare-hook'."
5922   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5923                                  gnus-current-headers)))
5924     (or (not gnus-use-cross-reference)
5925         (not headers)
5926         (and (mail-header-xref headers)
5927              (not (string= (mail-header-xref headers) "")))
5928         (let ((case-fold-search t)
5929               xref)
5930           (save-restriction
5931             (nnheader-narrow-to-headers)
5932             (goto-char (point-min))
5933             (when (or (and (not (eobp))
5934                            (eq (downcase (char-after)) ?x)
5935                            (looking-at "Xref:"))
5936                       (search-forward "\nXref:" nil t))
5937               (goto-char (1+ (match-end 0)))
5938               (setq xref (buffer-substring (point) (gnus-point-at-eol)))
5939               (mail-header-set-xref headers xref)))))))
5940
5941 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5942   "Find article ID and insert the summary line for that article.
5943 OLD-HEADER can either be a header or a line number to insert
5944 the subject line on."
5945   (let* ((line (and (numberp old-header) old-header))
5946          (old-header (and (vectorp old-header) old-header))
5947          (header (cond ((and old-header use-old-header)
5948                         old-header)
5949                        ((and (numberp id)
5950                              (gnus-number-to-header id))
5951                         (gnus-number-to-header id))
5952                        (t
5953                         (gnus-read-header id))))
5954          (number (and (numberp id) id))
5955          d)
5956     (when header
5957       ;; Rebuild the thread that this article is part of and go to the
5958       ;; article we have fetched.
5959       (when (and (not gnus-show-threads)
5960                  old-header)
5961         (when (and number
5962                    (setq d (gnus-data-find (mail-header-number old-header))))
5963           (goto-char (gnus-data-pos d))
5964           (gnus-data-remove
5965            number
5966            (- (gnus-point-at-bol)
5967               (prog1
5968                   (1+ (gnus-point-at-eol))
5969                 (gnus-delete-line))))))
5970       (when old-header
5971         (mail-header-set-number header (mail-header-number old-header)))
5972       (setq gnus-newsgroup-sparse
5973             (delq (setq number (mail-header-number header))
5974                   gnus-newsgroup-sparse))
5975       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5976       (push number gnus-newsgroup-limit)
5977       (gnus-rebuild-thread (mail-header-id header) line)
5978       (gnus-summary-goto-subject number nil t))
5979     (when (and (numberp number)
5980                (> number 0))
5981       ;; We have to update the boundaries even if we can't fetch the
5982       ;; article if ID is a number -- so that the next `P' or `N'
5983       ;; command will fetch the previous (or next) article even
5984       ;; if the one we tried to fetch this time has been canceled.
5985       (when (> number gnus-newsgroup-end)
5986         (setq gnus-newsgroup-end number))
5987       (when (< number gnus-newsgroup-begin)
5988         (setq gnus-newsgroup-begin number))
5989       (setq gnus-newsgroup-unselected
5990             (delq number gnus-newsgroup-unselected)))
5991     ;; Report back a success?
5992     (and header (mail-header-number header))))
5993
5994 ;;; Process/prefix in the summary buffer
5995
5996 (defun gnus-summary-work-articles (n)
5997   "Return a list of articles to be worked upon.
5998 The prefix argument, the list of process marked articles, and the
5999 current article will be taken into consideration."
6000   (save-excursion
6001     (set-buffer gnus-summary-buffer)
6002     (cond
6003      (n
6004       ;; A numerical prefix has been given.
6005       (setq n (prefix-numeric-value n))
6006       (let ((backward (< n 0))
6007             (n (abs (prefix-numeric-value n)))
6008             articles article)
6009         (save-excursion
6010           (while
6011               (and (> n 0)
6012                    (push (setq article (gnus-summary-article-number))
6013                          articles)
6014                    (if backward
6015                        (gnus-summary-find-prev nil article)
6016                      (gnus-summary-find-next nil article)))
6017             (decf n)))
6018         (nreverse articles)))
6019      ((and (gnus-region-active-p) (mark))
6020       (message "region active")
6021       ;; Work on the region between point and mark.
6022       (let ((max (max (point) (mark)))
6023             articles article)
6024         (save-excursion
6025           (goto-char (min (point) (mark)))
6026           (while
6027               (and
6028                (push (setq article (gnus-summary-article-number)) articles)
6029                (gnus-summary-find-next nil article)
6030                (< (point) max)))
6031           (nreverse articles))))
6032      (gnus-newsgroup-processable
6033       ;; There are process-marked articles present.
6034       ;; Save current state.
6035       (gnus-summary-save-process-mark)
6036       ;; Return the list.
6037       (reverse gnus-newsgroup-processable))
6038      (t
6039       ;; Just return the current article.
6040       (list (gnus-summary-article-number))))))
6041
6042 (defmacro gnus-summary-iterate (arg &rest forms)
6043   "Iterate over the process/prefixed articles and do FORMS.
6044 ARG is the interactive prefix given to the command.  FORMS will be
6045 executed with point over the summary line of the articles."
6046   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6047     `(let ((,articles (gnus-summary-work-articles ,arg)))
6048        (while ,articles
6049          (gnus-summary-goto-subject (car ,articles))
6050          ,@forms
6051          (pop ,articles)))))
6052
6053 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6054 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6055
6056 (defun gnus-summary-save-process-mark ()
6057   "Push the current set of process marked articles on the stack."
6058   (interactive)
6059   (push (copy-sequence gnus-newsgroup-processable)
6060         gnus-newsgroup-process-stack))
6061
6062 (defun gnus-summary-kill-process-mark ()
6063   "Push the current set of process marked articles on the stack and unmark."
6064   (interactive)
6065   (gnus-summary-save-process-mark)
6066   (gnus-summary-unmark-all-processable))
6067
6068 (defun gnus-summary-yank-process-mark ()
6069   "Pop the last process mark state off the stack and restore it."
6070   (interactive)
6071   (unless gnus-newsgroup-process-stack
6072     (error "Empty mark stack"))
6073   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6074
6075 (defun gnus-summary-process-mark-set (set)
6076   "Make SET into the current process marked articles."
6077   (gnus-summary-unmark-all-processable)
6078   (while set
6079     (gnus-summary-set-process-mark (pop set))))
6080
6081 ;;; Searching and stuff
6082
6083 (defun gnus-summary-search-group (&optional backward use-level)
6084   "Search for next unread newsgroup.
6085 If optional argument BACKWARD is non-nil, search backward instead."
6086   (save-excursion
6087     (set-buffer gnus-group-buffer)
6088     (when (gnus-group-search-forward
6089            backward nil (if use-level (gnus-group-group-level) nil))
6090       (gnus-group-group-name))))
6091
6092 (defun gnus-summary-best-group (&optional exclude-group)
6093   "Find the name of the best unread group.
6094 If EXCLUDE-GROUP, do not go to this group."
6095   (save-excursion
6096     (set-buffer gnus-group-buffer)
6097     (save-excursion
6098       (gnus-group-best-unread-group exclude-group))))
6099
6100 (defun gnus-summary-find-next (&optional unread article backward)
6101   (if backward
6102       (gnus-summary-find-prev unread article)
6103     (let* ((dummy (gnus-summary-article-intangible-p))
6104            (article (or article (gnus-summary-article-number)))
6105            (data (gnus-data-find-list article))
6106            result)
6107       (when (and (not dummy)
6108                  (or (not gnus-summary-check-current)
6109                      (not unread)
6110                      (not (gnus-data-unread-p (car data)))))
6111         (setq data (cdr data)))
6112       (when (setq result
6113                   (if unread
6114                       (progn
6115                         (while data
6116                           (unless (memq (gnus-data-number (car data)) 
6117                                         (cond
6118                                          ((eq gnus-auto-goto-ignores
6119                                               'always-undownloaded)
6120                                           gnus-newsgroup-undownloaded)
6121                                          (gnus-plugged
6122                                           nil)
6123                                          ((eq gnus-auto-goto-ignores
6124                                               'unfetched)
6125                                           gnus-newsgroup-unfetched)
6126                                          ((eq gnus-auto-goto-ignores
6127                                               'undownloaded)
6128                                           gnus-newsgroup-undownloaded)))
6129                             (when (gnus-data-unread-p (car data))
6130                               (setq result (car data)
6131                                     data nil)))
6132                           (setq data (cdr data)))
6133                         result)
6134                     (car data)))
6135         (goto-char (gnus-data-pos result))
6136         (gnus-data-number result)))))
6137
6138 (defun gnus-summary-find-prev (&optional unread article)
6139   (let* ((eobp (eobp))
6140          (article (or article (gnus-summary-article-number)))
6141          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6142          result)
6143     (when (and (not eobp)
6144                (or (not gnus-summary-check-current)
6145                    (not unread)
6146                    (not (gnus-data-unread-p (car data)))))
6147       (setq data (cdr data)))
6148     (when (setq result
6149                 (if unread
6150                     (progn
6151                       (while data
6152                         (unless (memq (gnus-data-number (car data))
6153                                       (cond
6154                                        ((eq gnus-auto-goto-ignores
6155                                             'always-undownloaded)
6156                                         gnus-newsgroup-undownloaded)
6157                                        (gnus-plugged
6158                                         nil)
6159                                        ((eq gnus-auto-goto-ignores
6160                                             'unfetched)
6161                                         gnus-newsgroup-unfetched)
6162                                        ((eq gnus-auto-goto-ignores
6163                                             'undownloaded)
6164                                         gnus-newsgroup-undownloaded)))
6165                           (when (gnus-data-unread-p (car data))
6166                             (setq result (car data)
6167                                   data nil)))
6168                         (setq data (cdr data)))
6169                       result)
6170                   (car data)))
6171       (goto-char (gnus-data-pos result))
6172       (gnus-data-number result))))
6173
6174 (defun gnus-summary-find-subject (subject &optional unread backward article)
6175   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6176          (article (or article (gnus-summary-article-number)))
6177          (articles (gnus-data-list backward))
6178          (arts (gnus-data-find-list article articles))
6179          result)
6180     (when (or (not gnus-summary-check-current)
6181               (not unread)
6182               (not (gnus-data-unread-p (car arts))))
6183       (setq arts (cdr arts)))
6184     (while arts
6185       (and (or (not unread)
6186                (gnus-data-unread-p (car arts)))
6187            (vectorp (gnus-data-header (car arts)))
6188            (gnus-subject-equal
6189             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6190            (setq result (car arts)
6191                  arts nil))
6192       (setq arts (cdr arts)))
6193     (and result
6194          (goto-char (gnus-data-pos result))
6195          (gnus-data-number result))))
6196
6197 (defun gnus-summary-search-forward (&optional unread subject backward)
6198   "Search forward for an article.
6199 If UNREAD, look for unread articles.  If SUBJECT, look for
6200 articles with that subject.  If BACKWARD, search backward instead."
6201   (cond (subject (gnus-summary-find-subject subject unread backward))
6202         (backward (gnus-summary-find-prev unread))
6203         (t (gnus-summary-find-next unread))))
6204
6205 (defun gnus-recenter (&optional n)
6206   "Center point in window and redisplay frame.
6207 Also do horizontal recentering."
6208   (interactive "P")
6209   (when (and gnus-auto-center-summary
6210              (not (eq gnus-auto-center-summary 'vertical)))
6211     (gnus-horizontal-recenter))
6212   (recenter n))
6213
6214 (defun gnus-summary-recenter ()
6215   "Center point in the summary window.
6216 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6217 displayed, no centering will be performed."
6218   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6219   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6220   (interactive)
6221   ;; The user has to want it.
6222   (when gnus-auto-center-summary
6223     (let* ((top (cond ((< (window-height) 4) 0)
6224                       ((< (window-height) 7) 1)
6225                       (t (if (numberp gnus-auto-center-summary)
6226                              gnus-auto-center-summary
6227                            2))))
6228            (height (1- (window-height)))
6229            (bottom (save-excursion (goto-char (point-max))
6230                                    (forward-line (- height))
6231                                    (point)))
6232            (window (get-buffer-window (current-buffer))))
6233       (when (get-buffer-window gnus-article-buffer)
6234         ;; Only do recentering when the article buffer is displayed,
6235         ;; Set the window start to either `bottom', which is the biggest
6236         ;; possible valid number, or the second line from the top,
6237         ;; whichever is the least.
6238         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6239           (if (> bottom top-pos)
6240               ;; Keep the second line from the top visible
6241               (set-window-start window top-pos t)
6242             ;; Try to keep the bottom line visible; if it's partially
6243             ;; obscured, either scroll one more line to make it fully
6244             ;; visible, or revert to using TOP-POS.
6245             (save-excursion
6246               (goto-char (point-max))
6247               (forward-line -1)
6248               (let ((last-line-start (point)))
6249                 (goto-char bottom)
6250                 (set-window-start window (point) t)
6251                 (when (not (pos-visible-in-window-p last-line-start window))
6252                   (forward-line 1)
6253                   (set-window-start window (min (point) top-pos) t)))))))
6254       ;; Do horizontal recentering while we're at it.
6255       (when (and (get-buffer-window (current-buffer) t)
6256                  (not (eq gnus-auto-center-summary 'vertical)))
6257         (let ((selected (selected-window)))
6258           (select-window (get-buffer-window (current-buffer) t))
6259           (gnus-summary-position-point)
6260           (gnus-horizontal-recenter)
6261           (select-window selected))))))
6262
6263 (defun gnus-summary-jump-to-group (newsgroup)
6264   "Move point to NEWSGROUP in group mode buffer."
6265   ;; Keep update point of group mode buffer if visible.
6266   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6267       (save-window-excursion
6268         ;; Take care of tree window mode.
6269         (when (get-buffer-window gnus-group-buffer)
6270           (pop-to-buffer gnus-group-buffer))
6271         (gnus-group-jump-to-group newsgroup))
6272     (save-excursion
6273       ;; Take care of tree window mode.
6274       (if (get-buffer-window gnus-group-buffer)
6275           (pop-to-buffer gnus-group-buffer)
6276         (set-buffer gnus-group-buffer))
6277       (gnus-group-jump-to-group newsgroup))))
6278
6279 ;; This function returns a list of article numbers based on the
6280 ;; difference between the ranges of read articles in this group and
6281 ;; the range of active articles.
6282 (defun gnus-list-of-unread-articles (group)
6283   (let* ((read (gnus-info-read (gnus-get-info group)))
6284          (active (or (gnus-active group) (gnus-activate-group group)))
6285          (last (cdr active))
6286          first nlast unread)
6287     ;; If none are read, then all are unread.
6288     (if (not read)
6289         (setq first (car active))
6290       ;; If the range of read articles is a single range, then the
6291       ;; first unread article is the article after the last read
6292       ;; article.  Sounds logical, doesn't it?
6293       (if (and (not (listp (cdr read)))
6294                (or (< (car read) (car active))
6295                    (progn (setq read (list read))
6296                           nil)))
6297           (setq first (max (car active) (1+ (cdr read))))
6298         ;; `read' is a list of ranges.
6299         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6300                                   (caar read)))
6301                   1)
6302           (setq first (car active)))
6303         (while read
6304           (when first
6305             (while (< first nlast)
6306               (push first unread)
6307               (setq first (1+ first))))
6308           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6309           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6310           (setq read (cdr read)))))
6311     ;; And add the last unread articles.
6312     (while (<= first last)
6313       (push first unread)
6314       (setq first (1+ first)))
6315     ;; Return the list of unread articles.
6316     (delq 0 (nreverse unread))))
6317
6318 (defun gnus-list-of-read-articles (group)
6319   "Return a list of unread, unticked and non-dormant articles."
6320   (let* ((info (gnus-get-info group))
6321          (marked (gnus-info-marks info))
6322          (active (gnus-active group)))
6323     (and info active
6324          (gnus-list-range-difference
6325           (gnus-list-range-difference
6326            (gnus-sorted-complement
6327             (gnus-uncompress-range active)
6328             (gnus-list-of-unread-articles group))
6329            (cdr (assq 'dormant marked)))
6330           (cdr (assq 'tick marked))))))
6331
6332 ;; Various summary commands
6333
6334 (defun gnus-summary-select-article-buffer ()
6335   "Reconfigure windows to show article buffer."
6336   (interactive)
6337   (if (not (gnus-buffer-live-p gnus-article-buffer))
6338       (error "There is no article buffer for this summary buffer")
6339     (gnus-configure-windows 'article)
6340     (select-window (get-buffer-window gnus-article-buffer))))
6341
6342 (defun gnus-summary-universal-argument (arg)
6343   "Perform any operation on all articles that are process/prefixed."
6344   (interactive "P")
6345   (let ((articles (gnus-summary-work-articles arg))
6346         func article)
6347     (if (eq
6348          (setq
6349           func
6350           (key-binding
6351            (read-key-sequence
6352             (substitute-command-keys
6353              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6354          'undefined)
6355         (gnus-error 1 "Undefined key")
6356       (save-excursion
6357         (while articles
6358           (gnus-summary-goto-subject (setq article (pop articles)))
6359           (let (gnus-newsgroup-processable)
6360             (command-execute func))
6361           (gnus-summary-remove-process-mark article)))))
6362   (gnus-summary-position-point))
6363
6364 (defun gnus-summary-toggle-truncation (&optional arg)
6365   "Toggle truncation of summary lines.
6366 With arg, turn line truncation on if arg is positive."
6367   (interactive "P")
6368   (setq truncate-lines
6369         (if (null arg) (not truncate-lines)
6370           (> (prefix-numeric-value arg) 0)))
6371   (redraw-display))
6372
6373 (defun gnus-summary-find-for-reselect ()
6374   "Return the number of an article to stay on across a reselect.
6375 The current article is considered, then following articles, then previous
6376 articles.  An article is sought which is not cancelled and isn't a temporary
6377 insertion from another group.  If there's no such then return a dummy 0."
6378   (let (found)
6379     (dolist (rev '(nil t))
6380       (unless found      ; don't demand the reverse list if we don't need it
6381         (let ((data (gnus-data-find-list
6382                      (gnus-summary-article-number) (gnus-data-list rev))))
6383           (while (and data (not found))
6384             (if (and (< 0 (gnus-data-number (car data)))
6385                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6386                 (setq found (gnus-data-number (car data))))
6387             (setq data (cdr data))))))
6388     (or found 0)))
6389
6390 (defun gnus-summary-reselect-current-group (&optional all rescan)
6391   "Exit and then reselect the current newsgroup.
6392 The prefix argument ALL means to select all articles."
6393   (interactive "P")
6394   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6395     (error "Ephemeral groups can't be reselected"))
6396   (let ((current-subject (gnus-summary-find-for-reselect))
6397         (group gnus-newsgroup-name))
6398     (setq gnus-newsgroup-begin nil)
6399     (gnus-summary-exit nil 'leave-hidden)
6400     ;; We have to adjust the point of group mode buffer because
6401     ;; point was moved to the next unread newsgroup by exiting.
6402     (gnus-summary-jump-to-group group)
6403     (when rescan
6404       (save-excursion
6405         (save-window-excursion
6406           ;; Don't show group contents.
6407           (set-window-start (selected-window) (point-max))
6408           (gnus-group-get-new-news-this-group 1))))
6409     (gnus-group-read-group all t)
6410     (gnus-summary-goto-subject current-subject nil t)))
6411
6412 (defun gnus-summary-rescan-group (&optional all)
6413   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6414   (interactive "P")
6415   (gnus-summary-reselect-current-group all t))
6416
6417 (defun gnus-summary-update-info (&optional non-destructive)
6418   (save-excursion
6419     (let ((group gnus-newsgroup-name))
6420       (when group
6421         (when gnus-newsgroup-kill-headers
6422           (setq gnus-newsgroup-killed
6423                 (gnus-compress-sequence
6424                  (gnus-sorted-union
6425                   (gnus-list-range-intersection
6426                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6427                   gnus-newsgroup-unreads)
6428                  t)))
6429         (unless (listp (cdr gnus-newsgroup-killed))
6430           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6431         (let ((headers gnus-newsgroup-headers))
6432           ;; Set the new ranges of read articles.
6433           (save-excursion
6434             (set-buffer gnus-group-buffer)
6435             (gnus-undo-force-boundary))
6436           (gnus-update-read-articles
6437            group (gnus-sorted-union
6438                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6439           ;; Set the current article marks.
6440           (let ((gnus-newsgroup-scored
6441                  (if (and (not gnus-save-score)
6442                           (not non-destructive))
6443                      nil
6444                    gnus-newsgroup-scored)))
6445             (save-excursion
6446               (gnus-update-marks)))
6447           ;; Do the cross-ref thing.
6448           (when gnus-use-cross-reference
6449             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6450           ;; Do not switch windows but change the buffer to work.
6451           (set-buffer gnus-group-buffer)
6452           (unless (gnus-ephemeral-group-p group)
6453             (gnus-group-update-group group)))))))
6454
6455 (defun gnus-summary-save-newsrc (&optional force)
6456   "Save the current number of read/marked articles in the dribble buffer.
6457 The dribble buffer will then be saved.
6458 If FORCE (the prefix), also save the .newsrc file(s)."
6459   (interactive "P")
6460   (gnus-summary-update-info t)
6461   (if force
6462       (gnus-save-newsrc-file)
6463     (gnus-dribble-save)))
6464
6465 (defun gnus-summary-exit (&optional temporary leave-hidden)
6466   "Exit reading current newsgroup, and then return to group selection mode.
6467 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6468   (interactive)
6469   (gnus-set-global-variables)
6470   (gnus-kill-save-kill-buffer)
6471   (gnus-async-halt-prefetch)
6472   (let* ((group gnus-newsgroup-name)
6473          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6474          (gnus-group-is-exiting-p t)
6475          (mode major-mode)
6476          (group-point nil)
6477          (buf (current-buffer)))
6478     (unless quit-config
6479       ;; Do adaptive scoring, and possibly save score files.
6480       (when gnus-newsgroup-adaptive
6481         (gnus-score-adaptive))
6482       (when gnus-use-scoring
6483         (gnus-score-save)))
6484     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6485     ;; If we have several article buffers, we kill them at exit.
6486     (unless gnus-single-article-buffer
6487       (gnus-kill-buffer gnus-original-article-buffer)
6488       (setq gnus-article-current nil))
6489     (when gnus-use-cache
6490       (gnus-cache-possibly-remove-articles)
6491       (gnus-cache-save-buffers))
6492     (gnus-async-prefetch-remove-group group)
6493     (when gnus-suppress-duplicates
6494       (gnus-dup-enter-articles))
6495     (when gnus-use-trees
6496       (gnus-tree-close group))
6497     (when gnus-use-cache
6498       (gnus-cache-write-active))
6499     ;; Remove entries for this group.
6500     (nnmail-purge-split-history (gnus-group-real-name group))
6501     ;; Make all changes in this group permanent.
6502     (unless quit-config
6503       (gnus-run-hooks 'gnus-exit-group-hook)
6504       (gnus-summary-update-info))
6505     (gnus-close-group group)
6506     ;; Make sure where we were, and go to next newsgroup.
6507     (set-buffer gnus-group-buffer)
6508     (unless quit-config
6509       (gnus-group-jump-to-group group))
6510     (gnus-run-hooks 'gnus-summary-exit-hook)
6511     (unless (or quit-config
6512                 ;; If this group has disappeared from the summary
6513                 ;; buffer, don't skip forwards.
6514                 (not (string= group (gnus-group-group-name))))
6515       (gnus-group-next-unread-group 1))
6516     (setq group-point (point))
6517     (if temporary
6518         nil                             ;Nothing to do.
6519       ;; If we have several article buffers, we kill them at exit.
6520       (unless gnus-single-article-buffer
6521         (gnus-kill-buffer gnus-article-buffer)
6522         (gnus-kill-buffer gnus-original-article-buffer)
6523         (setq gnus-article-current nil))
6524       (set-buffer buf)
6525       (if (not gnus-kill-summary-on-exit)
6526           (progn
6527             (gnus-deaden-summary)
6528             (setq mode nil))
6529         ;; We set all buffer-local variables to nil.  It is unclear why
6530         ;; this is needed, but if we don't, buffer-local variables are
6531         ;; not garbage-collected, it seems.  This would the lead to en
6532         ;; ever-growing Emacs.
6533         (gnus-summary-clear-local-variables)
6534         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6535           (gnus-summary-clear-local-variables))
6536         (when (get-buffer gnus-article-buffer)
6537           (bury-buffer gnus-article-buffer))
6538         ;; We clear the global counterparts of the buffer-local
6539         ;; variables as well, just to be on the safe side.
6540         (set-buffer gnus-group-buffer)
6541         (gnus-summary-clear-local-variables)
6542         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6543           (gnus-summary-clear-local-variables))
6544         ;; Return to group mode buffer.
6545         (when (eq mode 'gnus-summary-mode)
6546           (gnus-kill-buffer buf)))
6547       (setq gnus-current-select-method gnus-select-method)
6548       (if leave-hidden
6549           (set-buffer gnus-group-buffer)
6550         (pop-to-buffer gnus-group-buffer))
6551       (if (not quit-config)
6552           (progn
6553             (goto-char group-point)
6554             (unless leave-hidden
6555               (gnus-configure-windows 'group 'force))
6556             (unless (pos-visible-in-window-p)
6557               (forward-line (/ (static-if (featurep 'xemacs)
6558                                    (window-displayed-height)
6559                                  (1- (window-height)))
6560                                -2))
6561               (set-window-start (selected-window) (point))
6562               (goto-char group-point)))
6563         (gnus-handle-ephemeral-exit quit-config))
6564       ;; Clear the current group name.
6565       (unless quit-config
6566         (setq gnus-newsgroup-name nil)))))
6567
6568 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6569 (defun gnus-summary-exit-no-update (&optional no-questions)
6570   "Quit reading current newsgroup without updating read article info."
6571   (interactive)
6572   (let* ((group gnus-newsgroup-name)
6573          (gnus-group-is-exiting-p t)
6574          (gnus-group-is-exiting-without-update-p t)
6575          (quit-config (gnus-group-quit-config group)))
6576     (when (or no-questions
6577               gnus-expert-user
6578               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6579       (gnus-async-halt-prefetch)
6580       (run-hooks 'gnus-summary-prepare-exit-hook)
6581       ;; If we have several article buffers, we kill them at exit.
6582       (unless gnus-single-article-buffer
6583         (gnus-kill-buffer gnus-article-buffer)
6584         (gnus-kill-buffer gnus-original-article-buffer)
6585         (setq gnus-article-current nil))
6586       (if (not gnus-kill-summary-on-exit)
6587           (gnus-deaden-summary)
6588         (gnus-close-group group)
6589         (gnus-summary-clear-local-variables)
6590         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6591           (gnus-summary-clear-local-variables))
6592         (set-buffer gnus-group-buffer)
6593         (gnus-summary-clear-local-variables)
6594         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6595           (gnus-summary-clear-local-variables))
6596         (gnus-kill-buffer gnus-summary-buffer))
6597       (unless gnus-single-article-buffer
6598         (setq gnus-article-current nil))
6599       (when gnus-use-trees
6600         (gnus-tree-close group))
6601       (gnus-async-prefetch-remove-group group)
6602       (when (get-buffer gnus-article-buffer)
6603         (bury-buffer gnus-article-buffer))
6604       ;; Return to the group buffer.
6605       (gnus-configure-windows 'group 'force)
6606       ;; Clear the current group name.
6607       (setq gnus-newsgroup-name nil)
6608       (unless (gnus-ephemeral-group-p group)
6609         (gnus-group-update-group group))
6610       (when (equal (gnus-group-group-name) group)
6611         (gnus-group-next-unread-group 1))
6612       (when quit-config
6613         (gnus-handle-ephemeral-exit quit-config)))))
6614
6615 (defun gnus-handle-ephemeral-exit (quit-config)
6616   "Handle movement when leaving an ephemeral group.
6617 The state which existed when entering the ephemeral is reset."
6618   (if (not (buffer-name (car quit-config)))
6619       (gnus-configure-windows 'group 'force)
6620     (set-buffer (car quit-config))
6621     (cond ((eq major-mode 'gnus-summary-mode)
6622            (gnus-set-global-variables))
6623           ((eq major-mode 'gnus-article-mode)
6624            (save-excursion
6625              ;; The `gnus-summary-buffer' variable may point
6626              ;; to the old summary buffer when using a single
6627              ;; article buffer.
6628              (unless (gnus-buffer-live-p gnus-summary-buffer)
6629                (set-buffer gnus-group-buffer))
6630              (set-buffer gnus-summary-buffer)
6631              (gnus-set-global-variables))))
6632     (if (or (eq (cdr quit-config) 'article)
6633             (eq (cdr quit-config) 'pick))
6634         (progn
6635           ;; The current article may be from the ephemeral group
6636           ;; thus it is best that we reload this article
6637           ;;
6638           ;; If we're exiting from a large digest, this can be
6639           ;; extremely slow.  So, it's better not to reload it. -- jh.
6640           ;;(gnus-summary-show-article)
6641           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6642               (gnus-configure-windows 'pick 'force)
6643             (gnus-configure-windows (cdr quit-config) 'force)))
6644       (gnus-configure-windows (cdr quit-config) 'force))
6645     (when (eq major-mode 'gnus-summary-mode)
6646       (gnus-summary-next-subject 1 nil t)
6647       (gnus-summary-recenter)
6648       (gnus-summary-position-point))))
6649
6650 (defun gnus-summary-preview-mime-message ()
6651   "MIME decode and play this message."
6652   (interactive)
6653   (let ((gnus-break-pages nil)
6654         (gnus-show-mime t))
6655     (gnus-summary-select-article gnus-show-all-headers t))
6656   (let ((w (get-buffer-window gnus-article-buffer)))
6657     (when w
6658       (select-window (get-buffer-window gnus-article-buffer)))))
6659
6660 ;;; Dead summaries.
6661
6662 (defvar gnus-dead-summary-mode-map nil)
6663
6664 (unless gnus-dead-summary-mode-map
6665   (setq gnus-dead-summary-mode-map (make-keymap))
6666   (suppress-keymap gnus-dead-summary-mode-map)
6667   (substitute-key-definition
6668    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6669   (dolist (key '("\C-d" "\r" "\177" [delete]))
6670     (define-key gnus-dead-summary-mode-map
6671       key 'gnus-summary-wake-up-the-dead))
6672   (dolist (key '("q" "Q"))
6673     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6674
6675 (defvar gnus-dead-summary-mode nil
6676   "Minor mode for Gnus summary buffers.")
6677
6678 (defun gnus-dead-summary-mode (&optional arg)
6679   "Minor mode for Gnus summary buffers."
6680   (interactive "P")
6681   (when (eq major-mode 'gnus-summary-mode)
6682     (make-local-variable 'gnus-dead-summary-mode)
6683     (setq gnus-dead-summary-mode
6684           (if (null arg) (not gnus-dead-summary-mode)
6685             (> (prefix-numeric-value arg) 0)))
6686     (when gnus-dead-summary-mode
6687       (gnus-add-minor-mode
6688        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6689
6690 (defun gnus-deaden-summary ()
6691   "Make the current summary buffer into a dead summary buffer."
6692   ;; Kill any previous dead summary buffer.
6693   (when (and gnus-dead-summary
6694              (buffer-name gnus-dead-summary))
6695     (save-excursion
6696       (set-buffer gnus-dead-summary)
6697       (when gnus-dead-summary-mode
6698         (kill-buffer (current-buffer)))))
6699   ;; Make this the current dead summary.
6700   (setq gnus-dead-summary (current-buffer))
6701   (gnus-dead-summary-mode 1)
6702   (let ((name (buffer-name)))
6703     (when (string-match "Summary" name)
6704       (rename-buffer
6705        (concat (substring name 0 (match-beginning 0)) "Dead "
6706                (substring name (match-beginning 0)))
6707        t)
6708       (bury-buffer))))
6709
6710 (defun gnus-kill-or-deaden-summary (buffer)
6711   "Kill or deaden the summary BUFFER."
6712   (save-excursion
6713     (when (and (buffer-name buffer)
6714                (not gnus-single-article-buffer))
6715       (save-excursion
6716         (set-buffer buffer)
6717         (gnus-kill-buffer gnus-article-buffer)
6718         (gnus-kill-buffer gnus-original-article-buffer)))
6719     (cond
6720      ;; Kill the buffer.
6721      (gnus-kill-summary-on-exit
6722       (when (and gnus-use-trees
6723                  (gnus-buffer-exists-p buffer))
6724         (save-excursion
6725           (set-buffer buffer)
6726           (gnus-tree-close gnus-newsgroup-name)))
6727       (gnus-kill-buffer buffer))
6728      ;; Deaden the buffer.
6729      ((gnus-buffer-exists-p buffer)
6730       (save-excursion
6731         (set-buffer buffer)
6732         (gnus-deaden-summary))))))
6733
6734 (defun gnus-summary-wake-up-the-dead (&rest args)
6735   "Wake up the dead summary buffer."
6736   (interactive)
6737   (gnus-dead-summary-mode -1)
6738   (let ((name (buffer-name)))
6739     (when (string-match "Dead " name)
6740       (rename-buffer
6741        (concat (substring name 0 (match-beginning 0))
6742                (substring name (match-end 0)))
6743        t)))
6744   (gnus-message 3 "This dead summary is now alive again"))
6745
6746 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6747 (defun gnus-summary-fetch-faq (&optional faq-dir)
6748   "Fetch the FAQ for the current group.
6749 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6750 in."
6751   (interactive
6752    (list
6753     (when current-prefix-arg
6754       (completing-read
6755        "FAQ dir: " (and (listp gnus-group-faq-directory)
6756                         (mapcar (lambda (file) (list file))
6757                                 gnus-group-faq-directory))))))
6758   (let (gnus-faq-buffer)
6759     (when (setq gnus-faq-buffer
6760                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6761       (gnus-configure-windows 'summary-faq))))
6762
6763 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6764 (defun gnus-summary-describe-group (&optional force)
6765   "Describe the current newsgroup."
6766   (interactive "P")
6767   (gnus-group-describe-group force gnus-newsgroup-name))
6768
6769 (defun gnus-summary-describe-briefly ()
6770   "Describe summary mode commands briefly."
6771   (interactive)
6772   (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")))
6773
6774 ;; Walking around group mode buffer from summary mode.
6775
6776 (defun gnus-summary-next-group (&optional no-article target-group backward)
6777   "Exit current newsgroup and then select next unread newsgroup.
6778 If prefix argument NO-ARTICLE is non-nil, no article is selected
6779 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6780 previous group instead."
6781   (interactive "P")
6782   ;; Stop pre-fetching.
6783   (gnus-async-halt-prefetch)
6784   (let ((current-group gnus-newsgroup-name)
6785         (current-buffer (current-buffer))
6786         entered)
6787     ;; First we semi-exit this group to update Xrefs and all variables.
6788     ;; We can't do a real exit, because the window conf must remain
6789     ;; the same in case the user is prompted for info, and we don't
6790     ;; want the window conf to change before that...
6791     (gnus-summary-exit t)
6792     (while (not entered)
6793       ;; Then we find what group we are supposed to enter.
6794       (set-buffer gnus-group-buffer)
6795       (gnus-group-jump-to-group current-group)
6796       (setq target-group
6797             (or target-group
6798                 (if (eq gnus-keep-same-level 'best)
6799                     (gnus-summary-best-group gnus-newsgroup-name)
6800                   (gnus-summary-search-group backward gnus-keep-same-level))))
6801       (if (not target-group)
6802           ;; There are no further groups, so we return to the group
6803           ;; buffer.
6804           (progn
6805             (gnus-message 5 "Returning to the group buffer")
6806             (setq entered t)
6807             (when (gnus-buffer-live-p current-buffer)
6808               (set-buffer current-buffer)
6809               (gnus-summary-exit))
6810             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6811         ;; We try to enter the target group.
6812         (gnus-group-jump-to-group target-group)
6813         (let ((unreads (gnus-group-group-unread)))
6814           (if (and (or (eq t unreads)
6815                        (and unreads (not (zerop unreads))))
6816                    (gnus-summary-read-group
6817                     target-group nil no-article
6818                     (and (buffer-name current-buffer) current-buffer)
6819                     nil backward))
6820               (setq entered t)
6821             (setq current-group target-group
6822                   target-group nil)))))))
6823
6824 (defun gnus-summary-prev-group (&optional no-article)
6825   "Exit current newsgroup and then select previous unread newsgroup.
6826 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6827   (interactive "P")
6828   (gnus-summary-next-group no-article nil t))
6829
6830 ;; Walking around summary lines.
6831
6832 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6833   "Go to the first subject satisfying any non-nil constraint.
6834 If UNREAD is non-nil, the article should be unread.
6835 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6836 If UNSEED is non-nil, the article should be unseen.
6837 Returns the article selected or nil if there are no matching articles."
6838   (interactive "P")
6839   (cond
6840    ;; Empty summary.
6841    ((null gnus-newsgroup-data)
6842     (gnus-message 3 "No articles in the group")
6843     nil)
6844    ;; Pick the first article.
6845    ((not (or unread undownloaded unseen))
6846     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6847     (gnus-data-number (car gnus-newsgroup-data)))
6848    ;; Find the first unread article.
6849    (t
6850     (let ((data gnus-newsgroup-data))
6851       (while (and data
6852                   (let ((num (gnus-data-number (car data))))
6853                     (or (memq num gnus-newsgroup-unfetched)
6854                         (not (or (and unread
6855                                       (memq num gnus-newsgroup-unreads))
6856                                  (and undownloaded
6857                                       (memq num gnus-newsgroup-undownloaded))
6858                                  (and unseen
6859                                       (memq num gnus-newsgroup-unseen)))))))
6860         (setq data (cdr data)))
6861       (prog1 
6862           (if data
6863               (progn
6864                 (goto-char (gnus-data-pos (car data)))
6865                 (gnus-data-number (car data)))
6866             (gnus-message 3 "No more%s articles"
6867                           (let* ((r (when unread " unread"))
6868                                  (d (when undownloaded " undownloaded"))
6869                                  (s (when unseen " unseen"))
6870                                  (l (delq nil (list r d s))))
6871                             (cond ((= 3 (length l))
6872                                    (concat r "," d ", or" s))
6873                                   ((= 2 (length l))
6874                                    (concat (car l) ", or" (cadr l)))
6875                                   ((= 1 (length l))
6876                                    (car l))
6877                                   (t
6878                                    ""))))
6879             nil
6880             )
6881         (gnus-summary-position-point))))))
6882
6883 (defun gnus-summary-next-subject (n &optional unread dont-display)
6884   "Go to next N'th summary line.
6885 If N is negative, go to the previous N'th subject line.
6886 If UNREAD is non-nil, only unread articles are selected.
6887 The difference between N and the actual number of steps taken is
6888 returned."
6889   (interactive "p")
6890   (let ((backward (< n 0))
6891         (n (abs n)))
6892     (while (and (> n 0)
6893                 (if backward
6894                     (gnus-summary-find-prev unread)
6895                   (gnus-summary-find-next unread)))
6896       (unless (zerop (setq n (1- n)))
6897         (gnus-summary-show-thread)))
6898     (when (/= 0 n)
6899       (gnus-message 7 "No more%s articles"
6900                     (if unread " unread" "")))
6901     (unless dont-display
6902       (gnus-summary-recenter)
6903       (gnus-summary-position-point))
6904     n))
6905
6906 (defun gnus-summary-next-unread-subject (n)
6907   "Go to next N'th unread summary line."
6908   (interactive "p")
6909   (gnus-summary-next-subject n t))
6910
6911 (defun gnus-summary-prev-subject (n &optional unread)
6912   "Go to previous N'th summary line.
6913 If optional argument UNREAD is non-nil, only unread article is selected."
6914   (interactive "p")
6915   (gnus-summary-next-subject (- n) unread))
6916
6917 (defun gnus-summary-prev-unread-subject (n)
6918   "Go to previous N'th unread summary line."
6919   (interactive "p")
6920   (gnus-summary-next-subject (- n) t))
6921
6922 (defun gnus-summary-goto-subjects (articles)
6923   "Insert the subject header for ARTICLES in the current buffer."
6924   (save-excursion
6925     (dolist (article articles)
6926       (gnus-summary-goto-subject article t)))
6927   (gnus-summary-limit (append articles gnus-newsgroup-limit))
6928   (gnus-summary-position-point))
6929  
6930 (defun gnus-summary-goto-subject (article &optional force silent)
6931   "Go the subject line of ARTICLE.
6932 If FORCE, also allow jumping to articles not currently shown."
6933   (interactive "nArticle number: ")
6934   (unless (numberp article)
6935     (error "Article %s is not a number" article))
6936   (let ((b (point))
6937         (data (gnus-data-find article)))
6938     ;; We read in the article if we have to.
6939     (and (not data)
6940          force
6941          (gnus-summary-insert-subject
6942           article
6943           (if (or (numberp force) (vectorp force)) force)
6944           t)
6945          (setq data (gnus-data-find article)))
6946     (goto-char b)
6947     (if (not data)
6948         (progn
6949           (unless silent
6950             (gnus-message 3 "Can't find article %d" article))
6951           nil)
6952       (let ((pt (gnus-data-pos data)))
6953         (goto-char pt)
6954         (gnus-summary-set-article-display-arrow pt))
6955       (gnus-summary-position-point)
6956       article)))
6957
6958 ;; Walking around summary lines with displaying articles.
6959
6960 (defun gnus-summary-expand-window (&optional arg)
6961   "Make the summary buffer take up the entire Emacs frame.
6962 Given a prefix, will force an `article' buffer configuration."
6963   (interactive "P")
6964   (if arg
6965       (gnus-configure-windows 'article 'force)
6966     (gnus-configure-windows 'summary 'force)))
6967
6968 (defun gnus-summary-display-article (article &optional all-header)
6969   "Display ARTICLE in article buffer."
6970   (when (gnus-buffer-live-p gnus-article-buffer)
6971     (with-current-buffer gnus-article-buffer
6972       (set-buffer-multibyte t)))
6973   (gnus-set-global-variables)
6974   (when (gnus-buffer-live-p gnus-article-buffer)
6975     (with-current-buffer gnus-article-buffer
6976       (setq gnus-article-charset gnus-newsgroup-charset)
6977       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6978       (set-buffer-multibyte t)))
6979   (if (null article)
6980       nil
6981     (prog1
6982         (if gnus-summary-display-article-function
6983             (funcall gnus-summary-display-article-function article all-header)
6984           (gnus-article-prepare article all-header))
6985       (with-current-buffer gnus-article-buffer
6986         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6987              nil))
6988       (gnus-run-hooks 'gnus-select-article-hook)
6989       (when (and gnus-current-article
6990                  (not (zerop gnus-current-article)))
6991         (gnus-summary-goto-subject gnus-current-article))
6992       (gnus-summary-recenter)
6993       (when (and gnus-use-trees gnus-show-threads)
6994         (gnus-possibly-generate-tree article)
6995         (gnus-highlight-selected-tree article))
6996       ;; Successfully display article.
6997       (gnus-article-set-window-start
6998        (cdr (assq article gnus-newsgroup-bookmarks))))))
6999
7000 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7001   "Select the current article.
7002 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7003 non-nil, the article will be re-fetched even if it already present in
7004 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7005 be displayed."
7006   ;; Make sure we are in the summary buffer to work around bbdb bug.
7007   (unless (eq major-mode 'gnus-summary-mode)
7008     (set-buffer gnus-summary-buffer))
7009   (let ((article (or article (gnus-summary-article-number)))
7010         (all-headers (not (not all-headers))) ;Must be T or NIL.
7011         gnus-summary-display-article-function)
7012     (and (not pseudo)
7013          (gnus-summary-article-pseudo-p article)
7014          (error "This is a pseudo-article"))
7015     (save-excursion
7016       (set-buffer gnus-summary-buffer)
7017       (if (or (and gnus-single-article-buffer
7018                    (or (null gnus-current-article)
7019                        (null gnus-article-current)
7020                        (null (get-buffer gnus-article-buffer))
7021                        (not (eq article (cdr gnus-article-current)))
7022                        (not (equal (car gnus-article-current)
7023                                    gnus-newsgroup-name))))
7024               (and (not gnus-single-article-buffer)
7025                    (or (null gnus-current-article)
7026                        (not (eq gnus-current-article article))))
7027               force)
7028           ;; The requested article is different from the current article.
7029           (progn
7030             (gnus-summary-display-article article all-headers)
7031             (gnus-article-set-window-start
7032              (cdr (assq article gnus-newsgroup-bookmarks)))
7033             article)
7034         'old))))
7035
7036 (defun gnus-summary-force-verify-and-decrypt ()
7037   "Display buttons for signed/encrypted parts and verify/decrypt them."
7038   (interactive)
7039   (let ((mm-verify-option 'known)
7040         (mm-decrypt-option 'known)
7041         (gnus-buttonized-mime-types (append (list "multipart/signed"
7042                                                   "multipart/encrypted")
7043                                             gnus-buttonized-mime-types)))
7044     (gnus-summary-select-article nil 'force)))
7045
7046 (defun gnus-summary-set-current-mark (&optional current-mark)
7047   "Obsolete function."
7048   nil)
7049
7050 (defun gnus-summary-next-article (&optional unread subject backward push)
7051   "Select the next article.
7052 If UNREAD, only unread articles are selected.
7053 If SUBJECT, only articles with SUBJECT are selected.
7054 If BACKWARD, the previous article is selected instead of the next."
7055   (interactive "P")
7056   (cond
7057    ;; Is there such an article?
7058    ((and (gnus-summary-search-forward unread subject backward)
7059          (or (gnus-summary-display-article (gnus-summary-article-number))
7060              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7061     (gnus-summary-position-point))
7062    ;; If not, we try the first unread, if that is wanted.
7063    ((and subject
7064          gnus-auto-select-same
7065          (gnus-summary-first-unread-article))
7066     (gnus-summary-position-point)
7067     (gnus-message 6 "Wrapped"))
7068    ;; Try to get next/previous article not displayed in this group.
7069    ((and gnus-auto-extend-newsgroup
7070          (not unread) (not subject))
7071     (gnus-summary-goto-article
7072      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7073      nil (count-lines (point-min) (point))))
7074    ;; Go to next/previous group.
7075    (t
7076     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7077       (gnus-summary-jump-to-group gnus-newsgroup-name))
7078     (let ((cmd last-command-char)
7079           (point
7080            (save-excursion
7081              (set-buffer gnus-group-buffer)
7082              (point)))
7083           (group
7084            (if (eq gnus-keep-same-level 'best)
7085                (gnus-summary-best-group gnus-newsgroup-name)
7086              (gnus-summary-search-group backward gnus-keep-same-level))))
7087       ;; For some reason, the group window gets selected.  We change
7088       ;; it back.
7089       (select-window (get-buffer-window (current-buffer)))
7090       ;; Select next unread newsgroup automagically.
7091       (cond
7092        ((or (not gnus-auto-select-next)
7093             (not cmd))
7094         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7095        ((or (eq gnus-auto-select-next 'quietly)
7096             (and (eq gnus-auto-select-next 'slightly-quietly)
7097                  push)
7098             (and (eq gnus-auto-select-next 'almost-quietly)
7099                  (gnus-summary-last-article-p)))
7100         ;; Select quietly.
7101         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7102             (gnus-summary-exit)
7103           (gnus-message 7 "No more%s articles (%s)..."
7104                         (if unread " unread" "")
7105                         (if group (concat "selecting " group)
7106                           "exiting"))
7107           (gnus-summary-next-group nil group backward)))
7108        (t
7109         (when (gnus-key-press-event-p last-input-event)
7110           (gnus-summary-walk-group-buffer
7111            gnus-newsgroup-name cmd unread backward point))))))))
7112
7113 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7114   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7115                       (?\C-p (gnus-group-prev-unread-group 1))))
7116         (cursor-in-echo-area t)
7117         keve key group ended prompt)
7118     (save-excursion
7119       (set-buffer gnus-group-buffer)
7120       (goto-char start)
7121       (setq group
7122             (if (eq gnus-keep-same-level 'best)
7123                 (gnus-summary-best-group gnus-newsgroup-name)
7124               (gnus-summary-search-group backward gnus-keep-same-level))))
7125     (while (not ended)
7126       (setq prompt
7127             (format
7128              "No more%s articles%s " (if unread " unread" "")
7129              (if (and group
7130                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7131                  (format " (Type %s for %s [%s])"
7132                          (single-key-description cmd) group
7133                          (car (gnus-gethash group gnus-newsrc-hashtb)))
7134                (format " (Type %s to exit %s)"
7135                        (single-key-description cmd)
7136                        gnus-newsgroup-name))))
7137       ;; Confirm auto selection.
7138       (setq key (car (setq keve (gnus-read-event-char prompt)))
7139             ended t)
7140       (cond
7141        ((assq key keystrokes)
7142         (let ((obuf (current-buffer)))
7143           (switch-to-buffer gnus-group-buffer)
7144           (when group
7145             (gnus-group-jump-to-group group))
7146           (eval (cadr (assq key keystrokes)))
7147           (setq group (gnus-group-group-name))
7148           (switch-to-buffer obuf))
7149         (setq ended nil))
7150        ((equal key cmd)
7151         (if (or (not group)
7152                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7153             (gnus-summary-exit)
7154           (gnus-summary-next-group nil group backward)))
7155        (t
7156         (push (cdr keve) unread-command-events))))))
7157
7158 (defun gnus-summary-next-unread-article ()
7159   "Select unread article after current one."
7160   (interactive)
7161   (gnus-summary-next-article
7162    (or (not (eq gnus-summary-goto-unread 'never))
7163        (gnus-summary-last-article-p (gnus-summary-article-number)))
7164    (and gnus-auto-select-same
7165         (gnus-summary-article-subject))))
7166
7167 (defun gnus-summary-prev-article (&optional unread subject)
7168   "Select the article after the current one.
7169 If UNREAD is non-nil, only unread articles are selected."
7170   (interactive "P")
7171   (gnus-summary-next-article unread subject t))
7172
7173 (defun gnus-summary-prev-unread-article ()
7174   "Select unread article before current one."
7175   (interactive)
7176   (gnus-summary-prev-article
7177    (or (not (eq gnus-summary-goto-unread 'never))
7178        (gnus-summary-first-article-p (gnus-summary-article-number)))
7179    (and gnus-auto-select-same
7180         (gnus-summary-article-subject))))
7181
7182 (defun gnus-summary-next-page (&optional lines circular stop)
7183   "Show next page of the selected article.
7184 If at the end of the current article, select the next article.
7185 LINES says how many lines should be scrolled up.
7186
7187 If CIRCULAR is non-nil, go to the start of the article instead of
7188 selecting the next article when reaching the end of the current
7189 article.
7190
7191 If STOP is non-nil, just stop when reaching the end of the message.
7192
7193 Also see the variable `gnus-article-skip-boring'."
7194   (interactive "P")
7195   (setq gnus-summary-buffer (current-buffer))
7196   (gnus-set-global-variables)
7197   (let ((article (gnus-summary-article-number))
7198         (article-window (get-buffer-window gnus-article-buffer t))
7199         endp)
7200     ;; If the buffer is empty, we have no article.
7201     (unless article
7202       (error "No article to select"))
7203     (gnus-configure-windows 'article)
7204     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7205         (if (and (eq gnus-summary-goto-unread 'never)
7206                  (not (gnus-summary-last-article-p article)))
7207             (gnus-summary-next-article)
7208           (gnus-summary-next-unread-article))
7209       (if (or (null gnus-current-article)
7210               (null gnus-article-current)
7211               (/= article (cdr gnus-article-current))
7212               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7213           ;; Selected subject is different from current article's.
7214           (gnus-summary-display-article article)
7215         (when article-window
7216           (gnus-eval-in-buffer-window gnus-article-buffer
7217             (setq endp (or (gnus-article-next-page lines)
7218                            (gnus-article-only-boring-p))))
7219           (when endp
7220             (cond (stop
7221                    (gnus-message 3 "End of message"))
7222                   (circular
7223                    (gnus-summary-beginning-of-article))
7224                   (lines
7225                    (gnus-message 3 "End of message"))
7226                   ((null lines)
7227                    (if (and (eq gnus-summary-goto-unread 'never)
7228                             (not (gnus-summary-last-article-p article)))
7229                        (gnus-summary-next-article)
7230                      (gnus-summary-next-unread-article))))))))
7231     (gnus-summary-recenter)
7232     (gnus-summary-position-point)))
7233
7234 (defun gnus-summary-prev-page (&optional lines move)
7235   "Show previous page of selected article.
7236 Argument LINES specifies lines to be scrolled down.
7237 If MOVE, move to the previous unread article if point is at
7238 the beginning of the buffer."
7239   (interactive "P")
7240   (let ((article (gnus-summary-article-number))
7241         (article-window (get-buffer-window gnus-article-buffer t))
7242         endp)
7243     (gnus-configure-windows 'article)
7244     (if (or (null gnus-current-article)
7245             (null gnus-article-current)
7246             (/= article (cdr gnus-article-current))
7247             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7248         ;; Selected subject is different from current article's.
7249         (gnus-summary-display-article article)
7250       (gnus-summary-recenter)
7251       (when article-window
7252         (gnus-eval-in-buffer-window gnus-article-buffer
7253           (setq endp (gnus-article-prev-page lines)))
7254         (when (and move endp)
7255           (cond (lines
7256                  (gnus-message 3 "Beginning of message"))
7257                 ((null lines)
7258                  (if (and (eq gnus-summary-goto-unread 'never)
7259                           (not (gnus-summary-first-article-p article)))
7260                      (gnus-summary-prev-article)
7261                    (gnus-summary-prev-unread-article))))))))
7262   (gnus-summary-position-point))
7263
7264 (defun gnus-summary-prev-page-or-article (&optional lines)
7265   "Show previous page of selected article.
7266 Argument LINES specifies lines to be scrolled down.
7267 If at the beginning of the article, go to the next article."
7268   (interactive "P")
7269   (gnus-summary-prev-page lines t))
7270
7271 (defun gnus-summary-scroll-up (lines)
7272   "Scroll up (or down) one line current article.
7273 Argument LINES specifies lines to be scrolled up (or down if negative)."
7274   (interactive "p")
7275   (gnus-configure-windows 'article)
7276   (gnus-summary-show-thread)
7277   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7278     (gnus-eval-in-buffer-window gnus-article-buffer
7279       (cond ((> lines 0)
7280              (when (gnus-article-next-page lines)
7281                (gnus-message 3 "End of message")))
7282             ((< lines 0)
7283              (gnus-article-prev-page (- lines))))))
7284   (gnus-summary-recenter)
7285   (gnus-summary-position-point))
7286
7287 (defun gnus-summary-scroll-down (lines)
7288   "Scroll down (or up) one line current article.
7289 Argument LINES specifies lines to be scrolled down (or up if negative)."
7290   (interactive "p")
7291   (gnus-summary-scroll-up (- lines)))
7292
7293 (defun gnus-summary-next-same-subject ()
7294   "Select next article which has the same subject as current one."
7295   (interactive)
7296   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7297
7298 (defun gnus-summary-prev-same-subject ()
7299   "Select previous article which has the same subject as current one."
7300   (interactive)
7301   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7302
7303 (defun gnus-summary-next-unread-same-subject ()
7304   "Select next unread article which has the same subject as current one."
7305   (interactive)
7306   (gnus-summary-next-article t (gnus-summary-article-subject)))
7307
7308 (defun gnus-summary-prev-unread-same-subject ()
7309   "Select previous unread article which has the same subject as current one."
7310   (interactive)
7311   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7312
7313 (defun gnus-summary-first-unread-article ()
7314   "Select the first unread article.
7315 Return nil if there are no unread articles."
7316   (interactive)
7317   (prog1
7318       (when (gnus-summary-first-subject t)
7319         (gnus-summary-show-thread)
7320         (gnus-summary-first-subject t)
7321         (gnus-summary-display-article (gnus-summary-article-number)))
7322     (gnus-summary-position-point)))
7323
7324 (defun gnus-summary-first-unread-subject ()
7325   "Place the point on the subject line of the first unread article.
7326 Return nil if there are no unread articles."
7327   (interactive)
7328   (prog1
7329       (when (gnus-summary-first-subject t)
7330         (gnus-summary-show-thread)
7331         (gnus-summary-first-subject t))
7332     (gnus-summary-position-point)))
7333
7334 (defun gnus-summary-first-unseen-subject ()
7335   "Place the point on the subject line of the first unseen article.
7336 Return nil if there are no unseen articles."
7337   (interactive)
7338   (prog1
7339       (when (gnus-summary-first-subject nil nil t)
7340         (gnus-summary-show-thread)
7341         (gnus-summary-first-subject nil nil t))
7342     (gnus-summary-position-point)))
7343
7344 (defun gnus-summary-first-unseen-or-unread-subject ()
7345   "Place the point on the subject line of the first unseen article or,
7346 if all article have been seen, on the subject line of the first unread
7347 article."
7348   (interactive)
7349   (prog1
7350       (unless (when (gnus-summary-first-subject nil nil t)
7351                 (gnus-summary-show-thread)
7352                 (gnus-summary-first-subject nil nil t))
7353         (when (gnus-summary-first-subject t)
7354           (gnus-summary-show-thread)
7355           (gnus-summary-first-subject t)))
7356     (gnus-summary-position-point)))
7357
7358 (defun gnus-summary-first-article ()
7359   "Select the first article.
7360 Return nil if there are no articles."
7361   (interactive)
7362   (prog1
7363       (when (gnus-summary-first-subject)
7364         (gnus-summary-show-thread)
7365         (gnus-summary-first-subject)
7366         (gnus-summary-display-article (gnus-summary-article-number)))
7367     (gnus-summary-position-point)))
7368
7369 (defun gnus-summary-best-unread-article (&optional arg)
7370   "Select the unread article with the highest score.
7371 If given a prefix argument, select the next unread article that has a
7372 score higher than the default score."
7373   (interactive "P")
7374   (let ((article (if arg
7375                      (gnus-summary-better-unread-subject)
7376                    (gnus-summary-best-unread-subject))))
7377     (if article
7378         (gnus-summary-goto-article article)
7379       (error "No unread articles"))))
7380
7381 (defun gnus-summary-best-unread-subject ()
7382   "Select the unread subject with the highest score."
7383   (interactive)
7384   (let ((best -1000000)
7385         (data gnus-newsgroup-data)
7386         article score)
7387     (while data
7388       (and (gnus-data-unread-p (car data))
7389            (> (setq score
7390                     (gnus-summary-article-score (gnus-data-number (car data))))
7391               best)
7392            (setq best score
7393                  article (gnus-data-number (car data))))
7394       (setq data (cdr data)))
7395     (when article
7396       (gnus-summary-goto-subject article))
7397     (gnus-summary-position-point)
7398     article))
7399
7400 (defun gnus-summary-better-unread-subject ()
7401   "Select the first unread subject that has a score over the default score."
7402   (interactive)
7403   (let ((data gnus-newsgroup-data)
7404         article score)
7405     (while (and (setq article (gnus-data-number (car data)))
7406                 (or (gnus-data-read-p (car data))
7407                     (not (> (gnus-summary-article-score article)
7408                             gnus-summary-default-score))))
7409       (setq data (cdr data)))
7410     (when article
7411       (gnus-summary-goto-subject article))
7412     (gnus-summary-position-point)
7413     article))
7414
7415 (defun gnus-summary-last-subject ()
7416   "Go to the last displayed subject line in the group."
7417   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7418     (when article
7419       (gnus-summary-goto-subject article))))
7420
7421 (defun gnus-summary-goto-article (article &optional all-headers force)
7422   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7423 If ALL-HEADERS is non-nil, no header lines are hidden.
7424 If FORCE, go to the article even if it isn't displayed.  If FORCE
7425 is a number, it is the line the article is to be displayed on."
7426   (interactive
7427    (list
7428     (completing-read
7429      "Article number or Message-ID: "
7430      (mapcar (lambda (number) (list (int-to-string number)))
7431              gnus-newsgroup-limit))
7432     current-prefix-arg
7433     t))
7434   (prog1
7435       (if (and (stringp article)
7436                (string-match "@" article))
7437           (gnus-summary-refer-article article)
7438         (when (stringp article)
7439           (setq article (string-to-number article)))
7440         (if (gnus-summary-goto-subject article force)
7441             (gnus-summary-display-article article all-headers)
7442           (gnus-message 4 "Couldn't go to article %s" article) nil))
7443     (gnus-summary-position-point)))
7444
7445 (defun gnus-summary-goto-last-article ()
7446   "Go to the previously read article."
7447   (interactive)
7448   (prog1
7449       (when gnus-last-article
7450         (gnus-summary-goto-article gnus-last-article nil t))
7451     (gnus-summary-position-point)))
7452
7453 (defun gnus-summary-pop-article (number)
7454   "Pop one article off the history and go to the previous.
7455 NUMBER articles will be popped off."
7456   (interactive "p")
7457   (let (to)
7458     (setq gnus-newsgroup-history
7459           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7460     (if to
7461         (gnus-summary-goto-article (car to) nil t)
7462       (error "Article history empty")))
7463   (gnus-summary-position-point))
7464
7465 ;; Summary commands and functions for limiting the summary buffer.
7466
7467 (defun gnus-summary-limit-to-articles (n)
7468   "Limit the summary buffer to the next N articles.
7469 If not given a prefix, use the process marked articles instead."
7470   (interactive "P")
7471   (prog1
7472       (let ((articles (gnus-summary-work-articles n)))
7473         (setq gnus-newsgroup-processable nil)
7474         (gnus-summary-limit articles))
7475     (gnus-summary-position-point)))
7476
7477 (defun gnus-summary-pop-limit (&optional total)
7478   "Restore the previous limit.
7479 If given a prefix, remove all limits."
7480   (interactive "P")
7481   (when total
7482     (setq gnus-newsgroup-limits
7483           (list (mapcar (lambda (h) (mail-header-number h))
7484                         gnus-newsgroup-headers))))
7485   (unless gnus-newsgroup-limits
7486     (error "No limit to pop"))
7487   (prog1
7488       (gnus-summary-limit nil 'pop)
7489     (gnus-summary-position-point)))
7490
7491 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7492   "Limit the summary buffer to articles that have subjects that match a regexp.
7493 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7494   (interactive
7495    (list (read-string (if current-prefix-arg
7496                           "Exclude subject (regexp): "
7497                         "Limit to subject (regexp): "))
7498          nil current-prefix-arg))
7499   (unless header
7500     (setq header "subject"))
7501   (when (not (equal "" subject))
7502     (prog1
7503         (let ((articles (gnus-summary-find-matching
7504                          (or header "subject") subject 'all nil nil
7505                          not-matching)))
7506           (unless articles
7507             (error "Found no matches for \"%s\"" subject))
7508           (gnus-summary-limit articles))
7509       (gnus-summary-position-point))))
7510
7511 (defun gnus-summary-limit-to-author (from &optional not-matching)
7512   "Limit the summary buffer to articles that have authors that match a regexp.
7513 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7514   (interactive
7515    (list (read-string (if current-prefix-arg
7516                           "Exclude author (regexp): "
7517                         "Limit to author (regexp): "))
7518          current-prefix-arg))
7519   (gnus-summary-limit-to-subject from "from" not-matching))
7520
7521 (defun gnus-summary-limit-to-age (age &optional younger-p)
7522   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7523 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7524 articles that are younger than AGE days."
7525   (interactive
7526    (let ((younger current-prefix-arg)
7527          (days-got nil)
7528          days)
7529      (while (not days-got)
7530        (setq days (if younger
7531                       (read-string "Limit to articles younger than (in days, older when negative): ")
7532                     (read-string
7533                      "Limit to articles older than (in days, younger when negative): ")))
7534        (when (> (length days) 0)
7535          (setq days (read days)))
7536        (if (numberp days)
7537            (progn
7538              (setq days-got t)
7539              (if (< days 0)
7540                  (progn
7541                    (setq younger (not younger))
7542                    (setq days (* days -1)))))
7543          (message "Please enter a number.")
7544          (sleep-for 1)))
7545      (list days younger)))
7546   (prog1
7547       (let ((data gnus-newsgroup-data)
7548             (cutoff (days-to-time age))
7549             articles d date is-younger)
7550         (while (setq d (pop data))
7551           (when (and (vectorp (gnus-data-header d))
7552                      (setq date (mail-header-date (gnus-data-header d))))
7553             (setq is-younger (time-less-p
7554                               (time-since (condition-case ()
7555                                               (date-to-time date)
7556                                             (error '(0 0))))
7557                               cutoff))
7558             (when (if younger-p
7559                       is-younger
7560                     (not is-younger))
7561               (push (gnus-data-number d) articles))))
7562         (gnus-summary-limit (nreverse articles)))
7563     (gnus-summary-position-point)))
7564
7565 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7566   "Limit the summary buffer to articles that match an 'extra' header."
7567   (interactive
7568    (let ((header
7569           (intern
7570            (gnus-completing-read-with-default
7571             (symbol-name (car gnus-extra-headers))
7572             (if current-prefix-arg
7573                 "Exclude extra header:"
7574               "Limit extra header:")
7575             (mapcar (lambda (x)
7576                       (cons (symbol-name x) x))
7577                     gnus-extra-headers)
7578             nil
7579             t))))
7580      (list header
7581            (read-string (format "%s header %s (regexp): "
7582                                 (if current-prefix-arg "Exclude" "Limit to")
7583                                 header))
7584            current-prefix-arg)))
7585   (when (not (equal "" regexp))
7586     (prog1
7587         (let ((articles (gnus-summary-find-matching
7588                          (cons 'extra header) regexp 'all nil nil
7589                          not-matching)))
7590           (unless articles
7591             (error "Found no matches for \"%s\"" regexp))
7592           (gnus-summary-limit articles))
7593       (gnus-summary-position-point))))
7594
7595 (defun gnus-summary-limit-to-display-predicate ()
7596   "Limit the summary buffer to the predicated in the `display' group parameter."
7597   (interactive)
7598   (unless gnus-newsgroup-display
7599     (error "There is no `display' group parameter"))
7600   (let (articles)
7601     (dolist (number gnus-newsgroup-articles)
7602       (when (funcall gnus-newsgroup-display)
7603         (push number articles)))
7604     (gnus-summary-limit articles))
7605   (gnus-summary-position-point))
7606
7607 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7608 (make-obsolete
7609  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7610
7611 (defun gnus-summary-limit-to-unread (&optional all)
7612   "Limit the summary buffer to articles that are not marked as read.
7613 If ALL is non-nil, limit strictly to unread articles."
7614   (interactive "P")
7615   (if all
7616       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7617     (gnus-summary-limit-to-marks
7618      ;; Concat all the marks that say that an article is read and have
7619      ;; those removed.
7620      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7621            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7622            gnus-low-score-mark gnus-expirable-mark
7623            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7624            gnus-duplicate-mark gnus-souped-mark)
7625      'reverse)))
7626
7627 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7628 (make-obsolete 'gnus-summary-delete-marked-with
7629                'gnus-summary-limit-exclude-marks)
7630
7631 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7632   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7633 If REVERSE, limit the summary buffer to articles that are marked
7634 with MARKS.  MARKS can either be a string of marks or a list of marks.
7635 Returns how many articles were removed."
7636   (interactive "sMarks: ")
7637   (gnus-summary-limit-to-marks marks t))
7638
7639 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7640   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7641 If REVERSE (the prefix), limit the summary buffer to articles that are
7642 not marked with MARKS.  MARKS can either be a string of marks or a
7643 list of marks.
7644 Returns how many articles were removed."
7645   (interactive "sMarks: \nP")
7646   (prog1
7647       (let ((data gnus-newsgroup-data)
7648             (marks (if (listp marks) marks
7649                      (append marks nil))) ; Transform to list.
7650             articles)
7651         (while data
7652           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7653                   (memq (gnus-data-mark (car data)) marks))
7654             (push (gnus-data-number (car data)) articles))
7655           (setq data (cdr data)))
7656         (gnus-summary-limit articles))
7657     (gnus-summary-position-point)))
7658
7659 (defun gnus-summary-limit-to-score (score)
7660   "Limit to articles with score at or above SCORE."
7661   (interactive "NLimit to articles with score of at least: ")
7662   (let ((data gnus-newsgroup-data)
7663         articles)
7664     (while data
7665       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7666                 score)
7667         (push (gnus-data-number (car data)) articles))
7668       (setq data (cdr data)))
7669     (prog1
7670         (gnus-summary-limit articles)
7671       (gnus-summary-position-point))))
7672
7673 (defun gnus-summary-limit-to-unseen ()
7674   "Limit to unseen articles."
7675   (interactive)
7676   (prog1
7677       (gnus-summary-limit gnus-newsgroup-unseen)
7678     (gnus-summary-position-point)))
7679
7680 (defun gnus-summary-limit-include-thread (id)
7681   "Display all the hidden articles that is in the thread with ID in it.
7682 When called interactively, ID is the Message-ID of the current
7683 article."
7684   (interactive (list (mail-header-id (gnus-summary-article-header))))
7685   (let ((articles (gnus-articles-in-thread
7686                    (gnus-id-to-thread (gnus-root-id id)))))
7687     (prog1
7688         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7689       (gnus-summary-limit-include-matching-articles
7690        "subject"
7691        (regexp-quote (gnus-simplify-subject-re
7692                       (mail-header-subject (gnus-id-to-header id)))))
7693       (gnus-summary-position-point))))
7694
7695 (defun gnus-summary-limit-include-matching-articles (header regexp)
7696   "Display all the hidden articles that have HEADERs that match REGEXP."
7697   (interactive (list (read-string "Match on header: ")
7698                      (read-string "Regexp: ")))
7699   (let ((articles (gnus-find-matching-articles header regexp)))
7700     (prog1
7701         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7702       (gnus-summary-position-point))))
7703
7704 (defun gnus-summary-insert-dormant-articles ()
7705   "Insert all the dormat articles for this group into the current buffer."
7706   (interactive)
7707   (let ((gnus-verbose (max 6 gnus-verbose)))
7708     (if (not gnus-newsgroup-dormant)
7709         (gnus-message 3 "No cached articles for this group")
7710       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7711
7712 (defun gnus-summary-limit-include-dormant ()
7713   "Display all the hidden articles that are marked as dormant.
7714 Note that this command only works on a subset of the articles currently
7715 fetched for this group."
7716   (interactive)
7717   (unless gnus-newsgroup-dormant
7718     (error "There are no dormant articles in this group"))
7719   (prog1
7720       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7721     (gnus-summary-position-point)))
7722
7723 (defun gnus-summary-limit-exclude-dormant ()
7724   "Hide all dormant articles."
7725   (interactive)
7726   (prog1
7727       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7728     (gnus-summary-position-point)))
7729
7730 (defun gnus-summary-limit-exclude-childless-dormant ()
7731   "Hide all dormant articles that have no children."
7732   (interactive)
7733   (let ((data (gnus-data-list t))
7734         articles d children)
7735     ;; Find all articles that are either not dormant or have
7736     ;; children.
7737     (while (setq d (pop data))
7738       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7739                 (and (setq children
7740                            (gnus-article-children (gnus-data-number d)))
7741                      (let (found)
7742                        (while children
7743                          (when (memq (car children) articles)
7744                            (setq children nil
7745                                  found t))
7746                          (pop children))
7747                        found)))
7748         (push (gnus-data-number d) articles)))
7749     ;; Do the limiting.
7750     (prog1
7751         (gnus-summary-limit articles)
7752       (gnus-summary-position-point))))
7753
7754 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7755   "Mark all unread excluded articles as read.
7756 If ALL, mark even excluded ticked and dormants as read."
7757   (interactive "P")
7758   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7759   (let ((articles (gnus-sorted-ndifference
7760                    (sort
7761                     (mapcar (lambda (h) (mail-header-number h))
7762                             gnus-newsgroup-headers)
7763                     '<)
7764                    gnus-newsgroup-limit))
7765         article)
7766     (setq gnus-newsgroup-unreads
7767           (gnus-sorted-intersection gnus-newsgroup-unreads
7768                                     gnus-newsgroup-limit))
7769     (if all
7770         (setq gnus-newsgroup-dormant nil
7771               gnus-newsgroup-marked nil
7772               gnus-newsgroup-reads
7773               (nconc
7774                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7775                gnus-newsgroup-reads))
7776       (while (setq article (pop articles))
7777         (unless (or (memq article gnus-newsgroup-dormant)
7778                     (memq article gnus-newsgroup-marked))
7779           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7780
7781 (defun gnus-summary-limit (articles &optional pop)
7782   (if pop
7783       ;; We pop the previous limit off the stack and use that.
7784       (setq articles (car gnus-newsgroup-limits)
7785             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7786     ;; We use the new limit, so we push the old limit on the stack.
7787     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7788   ;; Set the limit.
7789   (setq gnus-newsgroup-limit articles)
7790   (let ((total (length gnus-newsgroup-data))
7791         (data (gnus-data-find-list (gnus-summary-article-number)))
7792         (gnus-summary-mark-below nil)   ; Inhibit this.
7793         found)
7794     ;; This will do all the work of generating the new summary buffer
7795     ;; according to the new limit.
7796     (gnus-summary-prepare)
7797     ;; Hide any threads, possibly.
7798     (gnus-summary-maybe-hide-threads)
7799     ;; Try to return to the article you were at, or one in the
7800     ;; neighborhood.
7801     (when data
7802       ;; We try to find some article after the current one.
7803       (while data
7804         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7805           (setq data nil
7806                 found t))
7807         (setq data (cdr data))))
7808     (unless found
7809       ;; If there is no data, that means that we were after the last
7810       ;; article.  The same goes when we can't find any articles
7811       ;; after the current one.
7812       (goto-char (point-max))
7813       (gnus-summary-find-prev))
7814     (gnus-set-mode-line 'summary)
7815     ;; We return how many articles were removed from the summary
7816     ;; buffer as a result of the new limit.
7817     (- total (length gnus-newsgroup-data))))
7818
7819 (defsubst gnus-invisible-cut-children (threads)
7820   (let ((num 0))
7821     (while threads
7822       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7823         (incf num))
7824       (pop threads))
7825     (< num 2)))
7826
7827 (defsubst gnus-cut-thread (thread)
7828   "Go forwards in the thread until we find an article that we want to display."
7829   (when (or (eq gnus-fetch-old-headers 'some)
7830             (eq gnus-fetch-old-headers 'invisible)
7831             (numberp gnus-fetch-old-headers)
7832             (eq gnus-build-sparse-threads 'some)
7833             (eq gnus-build-sparse-threads 'more))
7834     ;; Deal with old-fetched headers and sparse threads.
7835     (while (and
7836             thread
7837             (or
7838              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7839              (gnus-summary-article-ancient-p
7840               (mail-header-number (car thread))))
7841             (if (or (<= (length (cdr thread)) 1)
7842                     (eq gnus-fetch-old-headers 'invisible))
7843                 (setq gnus-newsgroup-limit
7844                       (delq (mail-header-number (car thread))
7845                             gnus-newsgroup-limit)
7846                       thread (cadr thread))
7847               (when (gnus-invisible-cut-children (cdr thread))
7848                 (let ((th (cdr thread)))
7849                   (while th
7850                     (if (memq (mail-header-number (caar th))
7851                               gnus-newsgroup-limit)
7852                         (setq thread (car th)
7853                               th nil)
7854                       (setq th (cdr th))))))))))
7855   thread)
7856
7857 (defun gnus-cut-threads (threads)
7858   "Cut off all uninteresting articles from the beginning of threads."
7859   (when (or (eq gnus-fetch-old-headers 'some)
7860             (eq gnus-fetch-old-headers 'invisible)
7861             (numberp gnus-fetch-old-headers)
7862             (eq gnus-build-sparse-threads 'some)
7863             (eq gnus-build-sparse-threads 'more))
7864     (let ((th threads))
7865       (while th
7866         (setcar th (gnus-cut-thread (car th)))
7867         (setq th (cdr th)))))
7868   ;; Remove nixed out threads.
7869   (delq nil threads))
7870
7871 (defun gnus-summary-initial-limit (&optional show-if-empty)
7872   "Figure out what the initial limit is supposed to be on group entry.
7873 This entails weeding out unwanted dormants, low-scored articles,
7874 fetch-old-headers verbiage, and so on."
7875   ;; Most groups have nothing to remove.
7876   (if (or gnus-inhibit-limiting
7877           (and (null gnus-newsgroup-dormant)
7878                (eq gnus-newsgroup-display 'gnus-not-ignore)
7879                (not (eq gnus-fetch-old-headers 'some))
7880                (not (numberp gnus-fetch-old-headers))
7881                (not (eq gnus-fetch-old-headers 'invisible))
7882                (null gnus-summary-expunge-below)
7883                (not (eq gnus-build-sparse-threads 'some))
7884                (not (eq gnus-build-sparse-threads 'more))
7885                (null gnus-thread-expunge-below)
7886                (not gnus-use-nocem)))
7887       ()                                ; Do nothing.
7888     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7889     (setq gnus-newsgroup-limit nil)
7890     (mapatoms
7891      (lambda (node)
7892        (unless (car (symbol-value node))
7893          ;; These threads have no parents -- they are roots.
7894          (let ((nodes (cdr (symbol-value node)))
7895                thread)
7896            (while nodes
7897              (if (and gnus-thread-expunge-below
7898                       (< (gnus-thread-total-score (car nodes))
7899                          gnus-thread-expunge-below))
7900                  (gnus-expunge-thread (pop nodes))
7901                (setq thread (pop nodes))
7902                (gnus-summary-limit-children thread))))))
7903      gnus-newsgroup-dependencies)
7904     ;; If this limitation resulted in an empty group, we might
7905     ;; pop the previous limit and use it instead.
7906     (when (and (not gnus-newsgroup-limit)
7907                show-if-empty)
7908       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7909     gnus-newsgroup-limit))
7910
7911 (defun gnus-summary-limit-children (thread)
7912   "Return 1 if this subthread is visible and 0 if it is not."
7913   ;; First we get the number of visible children to this thread.  This
7914   ;; is done by recursing down the thread using this function, so this
7915   ;; will really go down to a leaf article first, before slowly
7916   ;; working its way up towards the root.
7917   (when thread
7918     (let* ((max-lisp-eval-depth 5000)
7919            (children
7920            (if (cdr thread)
7921                (apply '+ (mapcar 'gnus-summary-limit-children
7922                                  (cdr thread)))
7923              0))
7924           (number (mail-header-number (car thread)))
7925           score)
7926       (if (and
7927            (not (memq number gnus-newsgroup-marked))
7928            (or
7929             ;; If this article is dormant and has absolutely no visible
7930             ;; children, then this article isn't visible.
7931             (and (memq number gnus-newsgroup-dormant)
7932                  (zerop children))
7933             ;; If this is "fetch-old-headered" and there is no
7934             ;; visible children, then we don't want this article.
7935             (and (or (eq gnus-fetch-old-headers 'some)
7936                      (numberp gnus-fetch-old-headers))
7937                  (gnus-summary-article-ancient-p number)
7938                  (zerop children))
7939             ;; If this is "fetch-old-headered" and `invisible', then
7940             ;; we don't want this article.
7941             (and (eq gnus-fetch-old-headers 'invisible)
7942                  (gnus-summary-article-ancient-p number))
7943             ;; If this is a sparsely inserted article with no children,
7944             ;; we don't want it.
7945             (and (eq gnus-build-sparse-threads 'some)
7946                  (gnus-summary-article-sparse-p number)
7947                  (zerop children))
7948             ;; If we use expunging, and this article is really
7949             ;; low-scored, then we don't want this article.
7950             (when (and gnus-summary-expunge-below
7951                        (< (setq score
7952                                 (or (cdr (assq number gnus-newsgroup-scored))
7953                                     gnus-summary-default-score))
7954                           gnus-summary-expunge-below))
7955               ;; We increase the expunge-tally here, but that has
7956               ;; nothing to do with the limits, really.
7957               (incf gnus-newsgroup-expunged-tally)
7958               ;; We also mark as read here, if that's wanted.
7959               (when (and gnus-summary-mark-below
7960                          (< score gnus-summary-mark-below))
7961                 (setq gnus-newsgroup-unreads
7962                       (delq number gnus-newsgroup-unreads))
7963                 (if gnus-newsgroup-auto-expire
7964                     (push number gnus-newsgroup-expirable)
7965                   (push (cons number gnus-low-score-mark)
7966                         gnus-newsgroup-reads)))
7967               t)
7968             ;; Do the `display' group parameter.
7969             (and gnus-newsgroup-display
7970                  (not (funcall gnus-newsgroup-display)))
7971             ;; Check NoCeM things.
7972             (if (and gnus-use-nocem
7973                      (gnus-nocem-unwanted-article-p
7974                       (mail-header-id (car thread))))
7975                 (progn
7976                   (setq gnus-newsgroup-unreads
7977                         (delq number gnus-newsgroup-unreads))
7978                   t))))
7979           ;; Nope, invisible article.
7980           0
7981         ;; Ok, this article is to be visible, so we add it to the limit
7982         ;; and return 1.
7983         (push number gnus-newsgroup-limit)
7984         1))))
7985
7986 (defun gnus-expunge-thread (thread)
7987   "Mark all articles in THREAD as read."
7988   (let* ((number (mail-header-number (car thread))))
7989     (incf gnus-newsgroup-expunged-tally)
7990     ;; We also mark as read here, if that's wanted.
7991     (setq gnus-newsgroup-unreads
7992           (delq number gnus-newsgroup-unreads))
7993     (if gnus-newsgroup-auto-expire
7994         (push number gnus-newsgroup-expirable)
7995       (push (cons number gnus-low-score-mark)
7996             gnus-newsgroup-reads)))
7997   ;; Go recursively through all subthreads.
7998   (mapcar 'gnus-expunge-thread (cdr thread)))
7999
8000 ;; Summary article oriented commands
8001
8002 (defun gnus-summary-refer-parent-article (n)
8003   "Refer parent article N times.
8004 If N is negative, go to ancestor -N instead.
8005 The difference between N and the number of articles fetched is returned."
8006   (interactive "p")
8007   (let ((skip 1)
8008         error header ref)
8009     (when (not (natnump n))
8010       (setq skip (abs n)
8011             n 1))
8012     (while (and (> n 0)
8013                 (not error))
8014       (setq header (gnus-summary-article-header))
8015       (if (and (eq (mail-header-number header)
8016                    (cdr gnus-article-current))
8017                (equal gnus-newsgroup-name
8018                       (car gnus-article-current)))
8019           ;; If we try to find the parent of the currently
8020           ;; displayed article, then we take a look at the actual
8021           ;; References header, since this is slightly more
8022           ;; reliable than the References field we got from the
8023           ;; server.
8024           (save-excursion
8025             (set-buffer gnus-original-article-buffer)
8026             (nnheader-narrow-to-headers)
8027             (unless (setq ref (message-fetch-field "references"))
8028               (setq ref (message-fetch-field "in-reply-to")))
8029             (widen))
8030         (setq ref
8031               ;; It's not the current article, so we take a bet on
8032               ;; the value we got from the server.
8033               (mail-header-references header)))
8034       (if (and ref
8035                (not (equal ref "")))
8036           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8037             (gnus-message 1 "Couldn't find parent"))
8038         (gnus-message 1 "No references in article %d"
8039                       (gnus-summary-article-number))
8040         (setq error t))
8041       (decf n))
8042     (gnus-summary-position-point)
8043     n))
8044
8045 (defun gnus-summary-refer-references ()
8046   "Fetch all articles mentioned in the References header.
8047 Return the number of articles fetched."
8048   (interactive)
8049   (let ((ref (mail-header-references (gnus-summary-article-header)))
8050         (current (gnus-summary-article-number))
8051         (n 0))
8052     (if (or (not ref)
8053             (equal ref ""))
8054         (error "No References in the current article")
8055       ;; For each Message-ID in the References header...
8056       (while (string-match "<[^>]*>" ref)
8057         (incf n)
8058         ;; ... fetch that article.
8059         (gnus-summary-refer-article
8060          (prog1 (match-string 0 ref)
8061            (setq ref (substring ref (match-end 0))))))
8062       (gnus-summary-goto-subject current)
8063       (gnus-summary-position-point)
8064       n)))
8065
8066 (defun gnus-summary-refer-thread (&optional limit)
8067   "Fetch all articles in the current thread.
8068 If LIMIT (the numerical prefix), fetch that many old headers instead
8069 of what's specified by the `gnus-refer-thread-limit' variable."
8070   (interactive "P")
8071   (let ((id (mail-header-id (gnus-summary-article-header)))
8072         (limit (if limit (prefix-numeric-value limit)
8073                  gnus-refer-thread-limit)))
8074     (unless (eq gnus-fetch-old-headers 'invisible)
8075       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8076       ;; Retrieve the headers and read them in.
8077       (if (eq (if (numberp limit)
8078                   (gnus-retrieve-headers
8079                    (list (min
8080                           (+ (mail-header-number
8081                               (gnus-summary-article-header))
8082                              limit)
8083                           gnus-newsgroup-end))
8084                    gnus-newsgroup-name (* limit 2))
8085                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8086                 ;; headers.
8087                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8088                                        gnus-newsgroup-name limit))
8089               'nov)
8090           (gnus-build-all-threads)
8091         (error "Can't fetch thread from backends that don't support NOV"))
8092       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8093     (gnus-summary-limit-include-thread id)))
8094
8095 (defun gnus-summary-refer-article (message-id)
8096   "Fetch an article specified by MESSAGE-ID."
8097   (interactive "sMessage-ID: ")
8098   (when (and (stringp message-id)
8099              (not (zerop (length message-id))))
8100     ;; Construct the correct Message-ID if necessary.
8101     ;; Suggested by tale@pawl.rpi.edu.
8102     (unless (string-match "^<" message-id)
8103       (setq message-id (concat "<" message-id)))
8104     (unless (string-match ">$" message-id)
8105       (setq message-id (concat message-id ">")))
8106     (let* ((header (gnus-id-to-header message-id))
8107            (sparse (and header
8108                         (gnus-summary-article-sparse-p
8109                          (mail-header-number header))
8110                         (memq (mail-header-number header)
8111                               gnus-newsgroup-limit)))
8112            number)
8113       (cond
8114        ;; If the article is present in the buffer we just go to it.
8115        ((and header
8116              (or (not (gnus-summary-article-sparse-p
8117                        (mail-header-number header)))
8118                  sparse))
8119         (prog1
8120             (gnus-summary-goto-article
8121              (mail-header-number header) nil t)
8122           (when sparse
8123             (gnus-summary-update-article (mail-header-number header)))))
8124        (t
8125         ;; We fetch the article.
8126         (catch 'found
8127           (dolist (gnus-override-method (gnus-refer-article-methods))
8128             (when (and (gnus-check-server gnus-override-method)
8129                        ;; Fetch the header,
8130                        (setq number (gnus-summary-insert-subject message-id)))
8131               ;; and display the article.
8132               (gnus-summary-select-article nil nil nil number)
8133               (throw 'found t)))
8134           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8135
8136 (defun gnus-refer-article-methods ()
8137   "Return a list of referable methods."
8138   (cond
8139    ;; No method, so we default to current and native.
8140    ((null gnus-refer-article-method)
8141     (list gnus-current-select-method gnus-select-method))
8142    ;; Current.
8143    ((eq 'current gnus-refer-article-method)
8144     (list gnus-current-select-method))
8145    ;; List of select methods.
8146    ((not (and (symbolp (car gnus-refer-article-method))
8147               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8148     (let (out)
8149       (dolist (method gnus-refer-article-method)
8150         (push (if (eq 'current method)
8151                   gnus-current-select-method
8152                 method)
8153               out))
8154       (nreverse out)))
8155    ;; One single select method.
8156    (t
8157     (list gnus-refer-article-method))))
8158
8159 (defun gnus-summary-edit-parameters ()
8160   "Edit the group parameters of the current group."
8161   (interactive)
8162   (gnus-group-edit-group gnus-newsgroup-name 'params))
8163
8164 (defun gnus-summary-customize-parameters ()
8165   "Customize the group parameters of the current group."
8166   (interactive)
8167   (gnus-group-customize gnus-newsgroup-name))
8168
8169 (defun gnus-summary-enter-digest-group (&optional force)
8170   "Enter an nndoc group based on the current article.
8171 If FORCE, force a digest interpretation.  If not, try
8172 to guess what the document format is."
8173   (interactive "P")
8174   (let ((conf gnus-current-window-configuration))
8175     (save-window-excursion
8176       (save-excursion
8177         (let (gnus-article-prepare-hook
8178               gnus-display-mime-function
8179               gnus-break-pages)
8180           (gnus-summary-select-article))))
8181     (setq gnus-current-window-configuration conf)
8182     (let* ((name (format "%s-%d"
8183                          (gnus-group-prefixed-name
8184                           gnus-newsgroup-name (list 'nndoc ""))
8185                          (save-excursion
8186                            (set-buffer gnus-summary-buffer)
8187                            gnus-current-article)))
8188            (ogroup gnus-newsgroup-name)
8189            (params (append (gnus-info-params (gnus-get-info ogroup))
8190                            (list (cons 'to-group ogroup))
8191                            (list (cons 'save-article-group ogroup))))
8192            (case-fold-search t)
8193            (buf (current-buffer))
8194            dig to-address)
8195       (save-excursion
8196         (set-buffer gnus-original-article-buffer)
8197         ;; Have the digest group inherit the main mail address of
8198         ;; the parent article.
8199         (when (setq to-address (or (gnus-fetch-field "reply-to")
8200                                    (gnus-fetch-field "from")))
8201           (setq params (append
8202                         (list (cons 'to-address
8203                                     (funcall gnus-decode-encoded-word-function
8204                                              to-address))))))
8205         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8206         (insert-buffer-substring gnus-original-article-buffer)
8207         ;; Remove lines that may lead nndoc to misinterpret the
8208         ;; document type.
8209         (narrow-to-region
8210          (goto-char (point-min))
8211          (or (search-forward "\n\n" nil t) (point)))
8212         (goto-char (point-min))
8213         (delete-matching-lines "^Path:\\|^From ")
8214         (widen))
8215       (unwind-protect
8216           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8217                     (gnus-newsgroup-ephemeral-ignored-charsets
8218                      gnus-newsgroup-ignored-charsets))
8219                 (gnus-group-read-ephemeral-group
8220                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8221                               (nndoc-article-type
8222                                ,(if force 'mbox 'guess)))
8223                  t nil nil nil
8224                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8225                                                         "ADAPT")))))
8226               ;; Make all postings to this group go to the parent group.
8227               (nconc (gnus-info-params (gnus-get-info name))
8228                      params)
8229             ;; Couldn't select this doc group.
8230             (switch-to-buffer buf)
8231             (gnus-set-global-variables)
8232             (gnus-configure-windows 'summary)
8233             (gnus-message 3 "Article couldn't be entered?"))
8234         (kill-buffer dig)))))
8235
8236 (defun gnus-summary-read-document (n)
8237   "Open a new group based on the current article(s).
8238 This will allow you to read digests and other similar
8239 documents as newsgroups.
8240 Obeys the standard process/prefix convention."
8241   (interactive "P")
8242   (let* ((articles (gnus-summary-work-articles n))
8243          (ogroup gnus-newsgroup-name)
8244          (params (append (gnus-info-params (gnus-get-info ogroup))
8245                          (list (cons 'to-group ogroup))))
8246          article group egroup groups vgroup)
8247     (while (setq article (pop articles))
8248       (setq group (format "%s-%d" gnus-newsgroup-name article))
8249       (gnus-summary-remove-process-mark article)
8250       (when (gnus-summary-display-article article)
8251         (save-excursion
8252           (with-temp-buffer
8253             (insert-buffer-substring gnus-original-article-buffer)
8254             ;; Remove some headers that may lead nndoc to make
8255             ;; the wrong guess.
8256             (message-narrow-to-head)
8257             (goto-char (point-min))
8258             (delete-matching-lines "^\\(Path\\):\\|^From ")
8259             (widen)
8260             (if (setq egroup
8261                       (gnus-group-read-ephemeral-group
8262                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8263                                      (nndoc-article-type guess))
8264                        t nil t))
8265                 (progn
8266                   ;; Make all postings to this group go to the parent group.
8267                   (nconc (gnus-info-params (gnus-get-info egroup))
8268                          params)
8269                   (push egroup groups))
8270               ;; Couldn't select this doc group.
8271               (gnus-error 3 "Article couldn't be entered"))))))
8272     ;; Now we have selected all the documents.
8273     (cond
8274      ((not groups)
8275       (error "None of the articles could be interpreted as documents"))
8276      ((gnus-group-read-ephemeral-group
8277        (setq vgroup (format
8278                      "nnvirtual:%s-%s" gnus-newsgroup-name
8279                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8280        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8281        t
8282        (cons (current-buffer) 'summary)))
8283      (t
8284       (error "Couldn't select virtual nndoc group")))))
8285
8286 (defun gnus-summary-isearch-article (&optional regexp-p)
8287   "Do incremental search forward on the current article.
8288 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8289   (interactive "P")
8290   (let* ((gnus-inhibit-treatment t)
8291          (old (gnus-summary-select-article)))
8292     (gnus-configure-windows 'article)
8293     (gnus-eval-in-buffer-window gnus-article-buffer
8294       (save-restriction
8295         (widen)
8296         (when (eq 'old old)
8297           (gnus-article-show-all-headers))
8298         (goto-char (point-min))
8299         (isearch-forward regexp-p)))))
8300
8301 (defun gnus-summary-search-article-forward (regexp &optional backward)
8302   "Search for an article containing REGEXP forward.
8303 If BACKWARD, search backward instead."
8304   (interactive
8305    (list (read-string
8306           (format "Search article %s (regexp%s): "
8307                   (if current-prefix-arg "backward" "forward")
8308                   (if gnus-last-search-regexp
8309                       (concat ", default " gnus-last-search-regexp)
8310                     "")))
8311          current-prefix-arg))
8312   (if (string-equal regexp "")
8313       (setq regexp (or gnus-last-search-regexp ""))
8314     (setq gnus-last-search-regexp regexp)
8315     (setq gnus-article-before-search gnus-current-article))
8316   ;; Intentionally set gnus-last-article.
8317   (setq gnus-last-article gnus-article-before-search)
8318   (let ((gnus-last-article gnus-last-article))
8319     (if (gnus-summary-search-article regexp backward)
8320         (gnus-summary-show-thread)
8321       (error "Search failed: \"%s\"" regexp))))
8322
8323 (defun gnus-summary-search-article-backward (regexp)
8324   "Search for an article containing REGEXP backward."
8325   (interactive
8326    (list (read-string
8327           (format "Search article backward (regexp%s): "
8328                   (if gnus-last-search-regexp
8329                       (concat ", default " gnus-last-search-regexp)
8330                     "")))))
8331   (gnus-summary-search-article-forward regexp 'backward))
8332
8333 (eval-when-compile
8334   (defmacro gnus-summary-search-article-position-point (regexp backward)
8335     "Dehighlight the last matched text and goto the beginning position."
8336     (` (if (and gnus-summary-search-article-matched-data
8337                 (let ((text (caddr gnus-summary-search-article-matched-data))
8338                       (inhibit-read-only t)
8339                       buffer-read-only)
8340                   (delete-region
8341                    (goto-char (car gnus-summary-search-article-matched-data))
8342                    (cadr gnus-summary-search-article-matched-data))
8343                   (insert text)
8344                   (string-match (, regexp) text)))
8345            (if (, backward) (beginning-of-line) (end-of-line))
8346          (goto-char (if (, backward) (point-max) (point-min))))))
8347
8348   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8349     "Place point where X-Face image is displayed."
8350     (if (featurep 'xemacs)
8351         (` (let ((end (if (search-forward "\n\n" nil t)
8352                           (goto-char (1- (point)))
8353                         (point-min)))
8354                  extent)
8355              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8356              (unless (and (re-search-forward "^From:" end t)
8357                           (setq extent (extent-at (point)))
8358                           (extent-begin-glyph extent))
8359                (goto-char (, opoint)))))
8360       (` (let ((end (if (search-forward "\n\n" nil t)
8361                         (goto-char (1- (point)))
8362                       (point-min)))
8363                (start (or (search-backward "\n\n" nil t) (point-min))))
8364            (goto-char
8365             (or (text-property-any start end 'x-face-image t);; x-face-e21
8366                 (text-property-any start end 'x-face-mule-bitmap-image t)
8367                 (, opoint)))))))
8368
8369   (defmacro gnus-summary-search-article-highlight-matched-text
8370     (backward treated x-face)
8371     "Highlight matched text in the function `gnus-summary-search-article'."
8372     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8373              (end (set-marker (make-marker) (match-end 0)))
8374              (inhibit-read-only t)
8375              buffer-read-only)
8376          (unless treated
8377            (let ((,@
8378                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8379                     (mapcar
8380                      (lambda (item) (setq items (delq item items)))
8381                      '(gnus-treat-buttonize
8382                        gnus-treat-fill-article
8383                        gnus-treat-fill-long-lines
8384                        gnus-treat-emphasize
8385                        gnus-treat-highlight-headers
8386                        gnus-treat-highlight-citation
8387                        gnus-treat-highlight-signature
8388                        gnus-treat-overstrike
8389                        gnus-treat-display-xface
8390                        gnus-treat-buttonize-head
8391                        gnus-treat-decode-article-as-default-mime-charset))
8392                     (static-if (featurep 'xemacs)
8393                         items
8394                       (cons '(x-face-mule-delete-x-face-field
8395                               (quote never))
8396                             items))))
8397                  (gnus-treat-display-xface
8398                   (when (, x-face) gnus-treat-display-xface)))
8399              (gnus-article-prepare-mime-display)))
8400          (goto-char (if (, backward) start end))
8401          (when (, x-face)
8402            (gnus-summary-search-article-highlight-goto-x-face (point)))
8403          (setq gnus-summary-search-article-matched-data
8404                (list start end (buffer-substring start end)))
8405          (unless (eq start end);; matched text has been deleted. :-<
8406            (put-text-property start end 'face
8407                               (or (find-face 'isearch)
8408                                   'secondary-selection))))))
8409   )
8410
8411 (defun gnus-summary-search-article (regexp &optional backward)
8412   "Search for an article containing REGEXP.
8413 Optional argument BACKWARD means do search for backward.
8414 `gnus-select-article-hook' is not called during the search."
8415   ;; We have to require this here to make sure that the following
8416   ;; dynamic binding isn't shadowed by autoloading.
8417   (require 'gnus-async)
8418   (require 'gnus-art)
8419   (let ((gnus-select-article-hook nil)  ;Disable hook.
8420         (gnus-article-prepare-hook nil)
8421         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8422         (gnus-use-article-prefetch nil)
8423         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8424         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8425         (gnus-visual nil)
8426         (gnus-keep-backlog nil)
8427         (gnus-break-pages nil)
8428         (gnus-summary-display-arrow nil)
8429         (gnus-updated-mode-lines nil)
8430         (gnus-auto-center-summary nil)
8431         (sum (current-buffer))
8432         (found nil)
8433         point treated)
8434     (gnus-save-hidden-threads
8435       (static-if (featurep 'xemacs)
8436           (let ((gnus-inhibit-treatment t))
8437             (setq treated (eq 'old (gnus-summary-select-article)))
8438             (when (and treated
8439                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8440                                  (window-live-p (get-buffer-window
8441                                                  gnus-article-buffer t)))))
8442               (gnus-summary-select-article nil t)
8443               (setq treated nil)))
8444         (let ((gnus-inhibit-treatment t)
8445               (x-face-mule-delete-x-face-field 'never))
8446           (setq treated (eq 'old (gnus-summary-select-article)))
8447           (when (and treated
8448                      (not
8449                       (and (gnus-buffer-live-p gnus-article-buffer)
8450                            (window-live-p (get-buffer-window
8451                                            gnus-article-buffer t))
8452                            (or (not (string-match "^\\^X-Face:" regexp))
8453                                (with-current-buffer gnus-article-buffer
8454                                  gnus-summary-search-article-matched-data)))))
8455             (gnus-summary-select-article nil t)
8456             (setq treated nil))))
8457       (set-buffer gnus-article-buffer)
8458       (widen)
8459       (if treated
8460           (progn
8461             (gnus-article-show-all-headers)
8462             (gnus-summary-search-article-position-point regexp backward))
8463         (goto-char (if backward (point-max) (point-min))))
8464       (while (not found)
8465         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8466         (if (if backward
8467                 (re-search-backward regexp nil t)
8468               (re-search-forward regexp nil t))
8469             ;; We found the regexp.
8470             (progn
8471               (gnus-summary-search-article-highlight-matched-text
8472                backward treated (string-match "^\\^X-Face:" regexp))
8473               (setq found 'found)
8474               (forward-line
8475                (/ (- 2 (window-height
8476                         (get-buffer-window gnus-article-buffer t)))
8477                   2))
8478               (set-window-start
8479                (get-buffer-window (current-buffer))
8480                (point))
8481               (set-buffer sum)
8482               (setq point (point)))
8483           ;; We didn't find it, so we go to the next article.
8484           (set-buffer sum)
8485           (setq found 'not)
8486           (while (eq found 'not)
8487             (if (not (if backward (gnus-summary-find-prev)
8488                        (gnus-summary-find-next)))
8489                 ;; No more articles.
8490                 (setq found t)
8491               ;; Select the next article and adjust point.
8492               (unless (gnus-summary-article-sparse-p
8493                        (gnus-summary-article-number))
8494                 (setq found nil)
8495                 (let ((gnus-inhibit-treatment t))
8496                   (gnus-summary-select-article))
8497                 (setq treated nil)
8498                 (set-buffer gnus-article-buffer)
8499                 (widen)
8500                 (goto-char (if backward (point-max) (point-min))))))))
8501       (gnus-message 7 ""))
8502     ;; Return whether we found the regexp.
8503     (when (eq found 'found)
8504       (goto-char point)
8505       (gnus-summary-show-thread)
8506       (gnus-summary-goto-subject gnus-current-article)
8507       (gnus-summary-position-point)
8508       t)))
8509
8510 (defun gnus-find-matching-articles (header regexp)
8511   "Return a list of all articles that match REGEXP on HEADER.
8512 This search includes all articles in the current group that Gnus has
8513 fetched headers for, whether they are displayed or not."
8514   (let ((articles nil)
8515         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8516         (case-fold-search t))
8517     (dolist (header gnus-newsgroup-headers)
8518       (when (string-match regexp (funcall func header))
8519         (push (mail-header-number header) articles)))
8520     (nreverse articles)))
8521
8522 (defun gnus-summary-find-matching (header regexp &optional backward unread
8523                                           not-case-fold not-matching)
8524   "Return a list of all articles that match REGEXP on HEADER.
8525 The search stars on the current article and goes forwards unless
8526 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8527 If UNREAD is non-nil, only unread articles will
8528 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8529 in the comparisons. If NOT-MATCHING, return a list of all articles that
8530 not match REGEXP on HEADER."
8531   (let ((case-fold-search (not not-case-fold))
8532         articles d func)
8533     (if (consp header)
8534         (if (eq (car header) 'extra)
8535             (setq func
8536                   `(lambda (h)
8537                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8538                          "")))
8539           (error "%s is an invalid header" header))
8540       (unless (fboundp (intern (concat "mail-header-" header)))
8541         (error "%s is not a valid header" header))
8542       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8543     (dolist (d (if (eq backward 'all)
8544                    gnus-newsgroup-data
8545                  (gnus-data-find-list
8546                   (gnus-summary-article-number)
8547                   (gnus-data-list backward))))
8548       (when (and (or (not unread)       ; We want all articles...
8549                      (gnus-data-unread-p d)) ; Or just unreads.
8550                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8551                  (if not-matching
8552                      (not (string-match
8553                            regexp
8554                            (funcall func (gnus-data-header d))))
8555                    (string-match regexp
8556                                  (funcall func (gnus-data-header d)))))
8557         (push (gnus-data-number d) articles))) ; Success!
8558     (nreverse articles)))
8559
8560 (defun gnus-summary-execute-command (header regexp command &optional backward)
8561   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8562 If HEADER is an empty string (or nil), the match is done on the entire
8563 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8564   (interactive
8565    (list (let ((completion-ignore-case t))
8566            (completing-read
8567             "Header name: "
8568             (mapcar (lambda (header) (list (format "%s" header)))
8569                     (append
8570                      '("Number" "Subject" "From" "Lines" "Date"
8571                        "Message-ID" "Xref" "References" "Body")
8572                      gnus-extra-headers))
8573             nil 'require-match))
8574          (read-string "Regexp: ")
8575          (read-key-sequence "Command: ")
8576          current-prefix-arg))
8577   (when (equal header "Body")
8578     (setq header ""))
8579   ;; Hidden thread subtrees must be searched as well.
8580   (gnus-summary-show-all-threads)
8581   ;; We don't want to change current point nor window configuration.
8582   (save-excursion
8583     (save-window-excursion
8584       (let (gnus-visual
8585             gnus-treat-strip-trailing-blank-lines
8586             gnus-treat-strip-leading-blank-lines
8587             gnus-treat-strip-multiple-blank-lines
8588             gnus-treat-hide-boring-headers
8589             gnus-treat-fold-newsgroups
8590             gnus-article-prepare-hook)
8591         (gnus-message 6 "Executing %s..." (key-description command))
8592         ;; We'd like to execute COMMAND interactively so as to give arguments.
8593         (gnus-execute header regexp
8594                       `(call-interactively ',(key-binding command))
8595                       backward)
8596         (gnus-message 6 "Executing %s...done" (key-description command))))))
8597
8598 (defun gnus-summary-beginning-of-article ()
8599   "Scroll the article back to the beginning."
8600   (interactive)
8601   (gnus-summary-select-article)
8602   (gnus-configure-windows 'article)
8603   (gnus-eval-in-buffer-window gnus-article-buffer
8604     (widen)
8605     (goto-char (point-min))
8606     (when gnus-page-broken
8607       (gnus-narrow-to-page))))
8608
8609 (defun gnus-summary-end-of-article ()
8610   "Scroll to the end of the article."
8611   (interactive)
8612   (gnus-summary-select-article)
8613   (gnus-configure-windows 'article)
8614   (gnus-eval-in-buffer-window gnus-article-buffer
8615     (widen)
8616     (goto-char (point-max))
8617     (recenter -3)
8618     (when gnus-page-broken
8619       (gnus-narrow-to-page))))
8620
8621 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8622   "Truncate to LEN and quote all \"(\"'s in STRING."
8623   (gnus-replace-in-string (if (and len (> (length string) len))
8624                               (substring string 0 len)
8625                             string)
8626                           "[()]" "\\\\\\&"))
8627
8628 (defun gnus-summary-print-article (&optional filename n)
8629   "Generate and print a PostScript image of the N next (mail) articles.
8630
8631 If N is negative, print the N previous articles.  If N is nil and articles
8632 have been marked with the process mark, print these instead.
8633
8634 If the optional first argument FILENAME is nil, send the image to the
8635 printer.  If FILENAME is a string, save the PostScript image in a file with
8636 that name.  If FILENAME is a number, prompt the user for the name of the file
8637 to save in."
8638   (interactive (list (ps-print-preprint current-prefix-arg)))
8639   (dolist (article (gnus-summary-work-articles n))
8640     (gnus-summary-select-article nil nil 'pseudo article)
8641     (gnus-eval-in-buffer-window gnus-article-buffer
8642       (gnus-print-buffer))
8643     (gnus-summary-remove-process-mark article))
8644   (ps-despool filename))
8645
8646 (defun gnus-print-buffer ()
8647   (let ((buffer (generate-new-buffer " *print*")))
8648     (unwind-protect
8649         (progn
8650           (copy-to-buffer buffer (point-min) (point-max))
8651           (set-buffer buffer)
8652           (gnus-article-delete-invisible-text)
8653           (gnus-remove-text-with-property 'gnus-decoration)
8654           (when (gnus-visual-p 'article-highlight 'highlight)
8655             ;; Copy-to-buffer doesn't copy overlay.  So redo
8656             ;; highlight.
8657             (let ((gnus-article-buffer buffer))
8658               (gnus-article-highlight-citation t)
8659               (gnus-article-highlight-signature)))
8660           (let ((ps-left-header
8661                  (list
8662                   (concat "("
8663                           (gnus-summary-print-truncate-and-quote
8664                            (mail-header-subject gnus-current-headers)
8665                            66) ")")
8666                   (concat "("
8667                           (gnus-summary-print-truncate-and-quote
8668                            (mail-header-from gnus-current-headers)
8669                            45) ")")))
8670                 (ps-right-header
8671                  (list
8672                   "/pagenumberstring load"
8673                   (concat "("
8674                           (mail-header-date gnus-current-headers) ")"))))
8675             (gnus-run-hooks 'gnus-ps-print-hook)
8676             (save-excursion
8677               (if window-system
8678                   (ps-spool-buffer-with-faces)
8679                 (ps-spool-buffer)))))
8680       (kill-buffer buffer))))
8681
8682 (defun gnus-summary-show-article (&optional arg)
8683   "Force redisplaying of the current article.
8684 If ARG (the prefix) is a number, show the article with the charset
8685 defined in `gnus-summary-show-article-charset-alist', or the charset
8686 input.
8687 If ARG (the prefix) is non-nil and not a number, show the raw article
8688 without any article massaging functions being run.  Normally, the key
8689 strokes are `C-u g'."
8690   (interactive "P")
8691   (cond
8692    ((numberp arg)
8693     (gnus-summary-show-article t)
8694     (let* ((gnus-newsgroup-charset
8695             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8696                 (mm-read-coding-system
8697                  "View as charset: " ;; actually it is coding system.
8698                  (save-excursion
8699                    (set-buffer gnus-article-buffer)
8700                    (mm-detect-coding-region (point) (point-max))))))
8701            (default-mime-charset gnus-newsgroup-charset)
8702            (gnus-newsgroup-ignored-charsets 'gnus-all))
8703       (gnus-summary-select-article nil 'force)
8704       (let ((deps gnus-newsgroup-dependencies)
8705             head header lines)
8706         (save-excursion
8707           (set-buffer gnus-original-article-buffer)
8708           (save-restriction
8709             (message-narrow-to-head)
8710             (setq head (buffer-string))
8711             (goto-char (point-min))
8712             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8713               (goto-char (point-max))
8714               (widen)
8715               (setq lines (1- (count-lines (point) (point-max))))))
8716           (with-temp-buffer
8717             (insert (format "211 %d Article retrieved.\n"
8718                             (cdr gnus-article-current)))
8719             (insert head)
8720             (if lines (insert (format "Lines: %d\n" lines)))
8721             (insert ".\n")
8722             (let ((nntp-server-buffer (current-buffer)))
8723               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8724         (gnus-data-set-header
8725          (gnus-data-find (cdr gnus-article-current))
8726          header)
8727         (gnus-summary-update-article-line
8728          (cdr gnus-article-current) header)
8729         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8730           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8731    ((not arg)
8732     ;; Select the article the normal way.
8733     (gnus-summary-select-article nil 'force))
8734    (t
8735     ;; We have to require this here to make sure that the following
8736     ;; dynamic binding isn't shadowed by autoloading.
8737     (require 'gnus-async)
8738     (require 'gnus-art)
8739     ;; Bind the article treatment functions to nil.
8740     (let ((gnus-have-all-headers t)
8741           gnus-article-prepare-hook
8742           gnus-article-decode-hook
8743           gnus-break-pages
8744           gnus-show-mime
8745           (gnus-inhibit-treatment t))
8746       (gnus-summary-select-article nil 'force))))
8747   (gnus-summary-goto-subject gnus-current-article)
8748   (gnus-summary-position-point))
8749
8750 (defun gnus-summary-show-raw-article ()
8751   "Show the raw article without any article massaging functions being run."
8752   (interactive)
8753   (gnus-summary-show-article t))
8754
8755 (defun gnus-summary-verbose-headers (&optional arg)
8756   "Toggle permanent full header display.
8757 If ARG is a positive number, turn header display on.
8758 If ARG is a negative number, turn header display off."
8759   (interactive "P")
8760   (setq gnus-show-all-headers
8761         (cond ((or (not (numberp arg))
8762                    (zerop arg))
8763                (not gnus-show-all-headers))
8764               ((natnump arg)
8765                t)))
8766   (gnus-summary-show-article))
8767
8768 (defun gnus-summary-toggle-header (&optional arg)
8769   "Show the headers if they are hidden, or hide them if they are shown.
8770 If ARG is a positive number, show the entire header.
8771 If ARG is a negative number, hide the unwanted header lines."
8772   (interactive "P")
8773   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8774                      (get-buffer-window gnus-article-buffer t))))
8775     (with-current-buffer gnus-article-buffer
8776       (widen)
8777       (article-narrow-to-head)
8778       (let* ((buffer-read-only nil)
8779              (inhibit-point-motion-hooks t)
8780              (hidden (if (numberp arg)
8781                          (>= arg 0)
8782                        (gnus-article-hidden-text-p 'headers)))
8783              s e)
8784         (delete-region (point-min) (point-max))
8785         (with-current-buffer gnus-original-article-buffer
8786           (goto-char (setq s (point-min)))
8787           (setq e (if (search-forward "\n\n" nil t)
8788                       (1- (point))
8789                     (point-max))))
8790         (insert-buffer-substring gnus-original-article-buffer s e)
8791         ;; In T-gnus, gnus-article-decode-hook doesn't contain
8792         ;; article-decode-encoded-words by default.
8793         (article-decode-encoded-words)
8794         (run-hooks 'gnus-article-decode-hook)
8795         (if hidden
8796             (let ((gnus-treat-hide-headers nil)
8797                   (gnus-treat-hide-boring-headers nil))
8798               (gnus-delete-wash-type 'headers)
8799               (gnus-treat-article 'head))
8800           (gnus-treat-article 'head))
8801         (widen)
8802         (if window
8803             (set-window-start window (goto-char (point-min))))
8804         (setq gnus-page-broken
8805               (when gnus-break-pages
8806                 (gnus-narrow-to-page)
8807                 t))
8808         (gnus-set-mode-line 'article)))))
8809
8810 (defun gnus-summary-show-all-headers ()
8811   "Make all header lines visible."
8812   (interactive)
8813   (gnus-summary-toggle-header 1))
8814
8815 (defun gnus-summary-toggle-mime (&optional arg)
8816   "Toggle MIME processing.
8817 If ARG is a positive number, turn MIME processing on."
8818   (interactive "P")
8819   (setq gnus-show-mime
8820         (if (null arg)
8821             (not gnus-show-mime)
8822           (> (prefix-numeric-value arg) 0)))
8823   (gnus-summary-select-article t 'force))
8824
8825 (defun gnus-summary-caesar-message (&optional arg)
8826   "Caesar rotate the current article by 13.
8827 The numerical prefix specifies how many places to rotate each letter
8828 forward."
8829   (interactive "P")
8830   (gnus-summary-select-article)
8831   (let ((mail-header-separator ""))
8832     (gnus-eval-in-buffer-window gnus-article-buffer
8833       (save-restriction
8834         (widen)
8835         (let ((start (window-start))
8836               buffer-read-only)
8837           (message-caesar-buffer-body arg)
8838           (set-window-start (get-buffer-window (current-buffer)) start))))))
8839
8840 (autoload 'unmorse-region "morse"
8841   "Convert morse coded text in region to ordinary ASCII text."
8842   t)
8843
8844 (defun gnus-summary-morse-message (&optional arg)
8845   "Morse decode the current article."
8846   (interactive "P")
8847   (gnus-summary-select-article)
8848   (let ((mail-header-separator ""))
8849     (gnus-eval-in-buffer-window gnus-article-buffer
8850       (save-excursion
8851         (save-restriction
8852           (widen)
8853           (let ((pos (window-start))
8854                 buffer-read-only)
8855             (goto-char (point-min))
8856             (when (message-goto-body)
8857               (gnus-narrow-to-body))
8858             (goto-char (point-min))
8859             (while (re-search-forward "·" (point-max) t)
8860               (replace-match "."))
8861             (unmorse-region (point-min) (point-max))
8862             (widen)
8863             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8864
8865 (defun gnus-summary-stop-page-breaking ()
8866   "Stop page breaking in the current article."
8867   (interactive)
8868   (gnus-summary-select-article)
8869   (gnus-eval-in-buffer-window gnus-article-buffer
8870     (widen)
8871     (when (gnus-visual-p 'page-marker)
8872       (let ((buffer-read-only nil))
8873         (gnus-remove-text-with-property 'gnus-prev)
8874         (gnus-remove-text-with-property 'gnus-next))
8875       (setq gnus-page-broken nil))))
8876
8877 (defun gnus-summary-move-article (&optional n to-newsgroup
8878                                             select-method action)
8879   "Move the current article to a different newsgroup.
8880 If N is a positive number, move the N next articles.
8881 If N is a negative number, move the N previous articles.
8882 If N is nil and any articles have been marked with the process mark,
8883 move those articles instead.
8884 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8885 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8886 re-spool using this method.
8887
8888 When called interactively with TO-NEWSGROUP being nil, the value of
8889 the variable `gnus-move-split-methods' is used for finding a default
8890 for the target newsgroup.
8891
8892 For this function to work, both the current newsgroup and the
8893 newsgroup that you want to move to have to support the `request-move'
8894 and `request-accept' functions.
8895
8896 ACTION can be either `move' (the default), `crosspost' or `copy'."
8897   (interactive "P")
8898   (unless action
8899     (setq action 'move))
8900   ;; Check whether the source group supports the required functions.
8901   (cond ((and (eq action 'move)
8902               (not (gnus-check-backend-function
8903                     'request-move-article gnus-newsgroup-name)))
8904          (error "The current group does not support article moving"))
8905         ((and (eq action 'crosspost)
8906               (not (gnus-check-backend-function
8907                     'request-replace-article gnus-newsgroup-name)))
8908          (error "The current group does not support article editing")))
8909   (let ((articles (gnus-summary-work-articles n))
8910         (prefix (if (gnus-check-backend-function
8911                      'request-move-article gnus-newsgroup-name)
8912                     (gnus-group-real-prefix gnus-newsgroup-name)
8913                   ""))
8914         (names '((move "Move" "Moving")
8915                  (copy "Copy" "Copying")
8916                  (crosspost "Crosspost" "Crossposting")))
8917         (copy-buf (save-excursion
8918                     (nnheader-set-temp-buffer " *copy article*")))
8919         art-group to-method new-xref article to-groups)
8920     (unless (assq action names)
8921       (error "Unknown action %s" action))
8922     ;; Read the newsgroup name.
8923     (when (and (not to-newsgroup)
8924                (not select-method))
8925       (if (and gnus-move-split-methods
8926                (not
8927                 (and (memq gnus-current-article articles)
8928                      (gnus-buffer-live-p gnus-original-article-buffer))))
8929           ;; When `gnus-move-split-methods' is non-nil, we have to
8930           ;; select an article to give `gnus-read-move-group-name' an
8931           ;; opportunity to suggest an appropriate default.  However,
8932           ;; we needn't render or mark the article.
8933           (let ((gnus-display-mime-function nil)
8934                 (gnus-article-prepare-hook nil)
8935                 (gnus-mark-article-hook nil))
8936             (gnus-summary-select-article nil nil nil (car articles))))
8937       (setq to-newsgroup
8938             (gnus-read-move-group-name
8939              (cadr (assq action names))
8940              (symbol-value (intern (format "gnus-current-%s-group" action)))
8941              articles prefix))
8942       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8943     (setq to-method (or select-method
8944                         (gnus-server-to-method
8945                          (gnus-group-method to-newsgroup))))
8946     ;; Check the method we are to move this article to...
8947     (unless (gnus-check-backend-function
8948              'request-accept-article (car to-method))
8949       (error "%s does not support article copying" (car to-method)))
8950     (unless (gnus-check-server to-method)
8951       (error "Can't open server %s" (car to-method)))
8952     (gnus-message 6 "%s to %s: %s..."
8953                   (caddr (assq action names))
8954                   (or (car select-method) to-newsgroup) articles)
8955     (while articles
8956       (setq article (pop articles))
8957       (setq
8958        art-group
8959        (cond
8960         ;; Move the article.
8961         ((eq action 'move)
8962          ;; Remove this article from future suppression.
8963          (gnus-dup-unsuppress-article article)
8964          (gnus-request-move-article
8965           article                       ; Article to move
8966           gnus-newsgroup-name           ; From newsgroup
8967           (nth 1 (gnus-find-method-for-group
8968                   gnus-newsgroup-name)) ; Server
8969           (list 'gnus-request-accept-article
8970                 to-newsgroup (list 'quote select-method)
8971                 (not articles) t)       ; Accept form
8972           (not articles)))              ; Only save nov last time
8973         ;; Copy the article.
8974         ((eq action 'copy)
8975          (save-excursion
8976            (set-buffer copy-buf)
8977            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8978              (gnus-request-accept-article
8979               to-newsgroup select-method (not articles) t))))
8980         ;; Crosspost the article.
8981         ((eq action 'crosspost)
8982          (let ((xref (message-tokenize-header
8983                       (mail-header-xref (gnus-summary-article-header article))
8984                       " ")))
8985            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8986                                   ":" (number-to-string article)))
8987            (unless xref
8988              (setq xref (list (system-name))))
8989            (setq new-xref
8990                  (concat
8991                   (mapconcat 'identity
8992                              (delete "Xref:" (delete new-xref xref))
8993                              " ")
8994                   " " new-xref))
8995            (save-excursion
8996              (set-buffer copy-buf)
8997              ;; First put the article in the destination group.
8998              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8999              (when (consp (setq art-group
9000                                 (gnus-request-accept-article
9001                                  to-newsgroup select-method (not articles))))
9002                (setq new-xref (concat new-xref " " (car art-group)
9003                                       ":"
9004                                       (number-to-string (cdr art-group))))
9005                ;; Now we have the new Xrefs header, so we insert
9006                ;; it and replace the new article.
9007                (nnheader-replace-header "Xref" new-xref)
9008                (gnus-request-replace-article
9009                 (cdr art-group) to-newsgroup (current-buffer))
9010                art-group))))))
9011       (cond
9012        ((not art-group)
9013         (gnus-message 1 "Couldn't %s article %s: %s"
9014                       (cadr (assq action names)) article
9015                       (nnheader-get-report (car to-method))))
9016        ((eq art-group 'junk)
9017         (when (eq action 'move)
9018           (gnus-summary-mark-article article gnus-canceled-mark)
9019           (gnus-message 4 "Deleted article %s" article)
9020           ;; run the delete hook
9021           (run-hook-with-args 'gnus-summary-article-delete-hook
9022                               action
9023                               (gnus-data-header
9024                                (assoc article (gnus-data-list nil)))
9025                               gnus-newsgroup-name nil
9026                               select-method)))
9027        (t
9028         (let* ((pto-group (gnus-group-prefixed-name
9029                            (car art-group) to-method))
9030                (entry
9031                 (gnus-gethash pto-group gnus-newsrc-hashtb))
9032                (info (nth 2 entry))
9033                (to-group (gnus-info-group info))
9034                to-marks)
9035           ;; Update the group that has been moved to.
9036           (when (and info
9037                      (memq action '(move copy)))
9038             (unless (member to-group to-groups)
9039               (push to-group to-groups))
9040
9041             (unless (memq article gnus-newsgroup-unreads)
9042               (push 'read to-marks)
9043               (gnus-info-set-read
9044                info (gnus-add-to-range (gnus-info-read info)
9045                                        (list (cdr art-group)))))
9046
9047             ;; See whether the article is to be put in the cache.
9048             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9049                              gnus-article-mark-lists
9050                            (delete '(expirable . expire)
9051                                    (copy-sequence gnus-article-mark-lists))))
9052                   (to-article (cdr art-group)))
9053
9054               ;; Enter the article into the cache in the new group,
9055               ;; if that is required.
9056               (when gnus-use-cache
9057                 (gnus-cache-possibly-enter-article
9058                  to-group to-article
9059                  (let ((header (copy-sequence
9060                                 (gnus-summary-article-header article))))
9061                    (mail-header-set-number header to-article)
9062                    header)
9063                  (memq article gnus-newsgroup-marked)
9064                  (memq article gnus-newsgroup-dormant)
9065                  (memq article gnus-newsgroup-unreads)))
9066
9067               (when gnus-preserve-marks
9068                 ;; Copy any marks over to the new group.
9069                 (when (and (equal to-group gnus-newsgroup-name)
9070                            (not (memq article gnus-newsgroup-unreads)))
9071                   ;; Mark this article as read in this group.
9072                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9073                   (setcdr (gnus-active to-group) to-article)
9074                   (setcdr gnus-newsgroup-active to-article))
9075
9076                 (while marks
9077                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9078                     (when (memq article (symbol-value
9079                                          (intern (format "gnus-newsgroup-%s"
9080                                                          (caar marks)))))
9081                       (push (cdar marks) to-marks)
9082                       ;; If the other group is the same as this group,
9083                       ;; then we have to add the mark to the list.
9084                       (when (equal to-group gnus-newsgroup-name)
9085                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9086                              (cons to-article
9087                                    (symbol-value
9088                                     (intern (format "gnus-newsgroup-%s"
9089                                                     (caar marks)))))))
9090                       ;; Copy the marks to other group.
9091                       (gnus-add-marked-articles
9092                        to-group (cdar marks) (list to-article) info)))
9093                   (setq marks (cdr marks)))
9094
9095                 (gnus-request-set-mark
9096                  to-group (list (list (list to-article) 'add to-marks))))
9097
9098               (gnus-dribble-enter
9099                (concat "(gnus-group-set-info '"
9100                        (gnus-prin1-to-string (gnus-get-info to-group))
9101                        ")"))))
9102
9103           ;; Update the Xref header in this article to point to
9104           ;; the new crossposted article we have just created.
9105           (when (eq action 'crosspost)
9106             (save-excursion
9107               (set-buffer copy-buf)
9108               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9109               (nnheader-replace-header "Xref" new-xref)
9110               (gnus-request-replace-article
9111                article gnus-newsgroup-name (current-buffer))))
9112
9113           ;; run the move/copy/crosspost/respool hook
9114           (run-hook-with-args 'gnus-summary-article-move-hook 
9115                               action
9116                               (gnus-data-header 
9117                                (assoc article (gnus-data-list nil)))
9118                               gnus-newsgroup-name
9119                               to-newsgroup
9120                               select-method))
9121
9122         ;;;!!!Why is this necessary?
9123         (set-buffer gnus-summary-buffer)
9124         
9125         (gnus-summary-goto-subject article)
9126         (when (eq action 'move)
9127           (gnus-summary-mark-article article gnus-canceled-mark))))
9128       (gnus-summary-remove-process-mark article))
9129     ;; Re-activate all groups that have been moved to.
9130     (save-excursion
9131       (set-buffer gnus-group-buffer)
9132       (let ((gnus-group-marked to-groups))
9133         (gnus-group-get-new-news-this-group nil t)))
9134
9135     (gnus-kill-buffer copy-buf)
9136     (gnus-summary-position-point)
9137     (gnus-set-mode-line 'summary)))
9138
9139 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9140   "Move the current article to a different newsgroup.
9141 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9142 When called interactively, if TO-NEWSGROUP is nil, use the value of
9143 the variable `gnus-move-split-methods' for finding a default target
9144 newsgroup.
9145 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9146 re-spool using this method."
9147   (interactive "P")
9148   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9149
9150 (defun gnus-summary-crosspost-article (&optional n)
9151   "Crosspost the current article to some other group."
9152   (interactive "P")
9153   (gnus-summary-move-article n nil nil 'crosspost))
9154
9155 (defcustom gnus-summary-respool-default-method nil
9156   "Default method type for respooling an article.
9157 If nil, use to the current newsgroup method."
9158   :type 'symbol
9159   :group 'gnus-summary-mail)
9160
9161 (defcustom gnus-summary-display-while-building nil
9162   "If non-nil, show and update the summary buffer as it's being built.
9163 If the value is t, update the buffer after every line is inserted.  If
9164 the value is an integer (N), update the display every N lines."
9165   :group 'gnus-thread
9166   :type '(choice (const :tag "off" nil)
9167                  number
9168                  (const :tag "frequently" t)))
9169
9170 (defun gnus-summary-respool-article (&optional n method)
9171   "Respool the current article.
9172 The article will be squeezed through the mail spooling process again,
9173 which means that it will be put in some mail newsgroup or other
9174 depending on `nnmail-split-methods'.
9175 If N is a positive number, respool the N next articles.
9176 If N is a negative number, respool the N previous articles.
9177 If N is nil and any articles have been marked with the process mark,
9178 respool those articles instead.
9179
9180 Respooling can be done both from mail groups and \"real\" newsgroups.
9181 In the former case, the articles in question will be moved from the
9182 current group into whatever groups they are destined to.  In the
9183 latter case, they will be copied into the relevant groups."
9184   (interactive
9185    (list current-prefix-arg
9186          (let* ((methods (gnus-methods-using 'respool))
9187                 (methname
9188                  (symbol-name (or gnus-summary-respool-default-method
9189                                   (car (gnus-find-method-for-group
9190                                         gnus-newsgroup-name)))))
9191                 (method
9192                  (gnus-completing-read-with-default
9193                   methname "What backend do you want to use when respooling?"
9194                   methods nil t nil 'gnus-mail-method-history))
9195                 ms)
9196            (cond
9197             ((zerop (length (setq ms (gnus-servers-using-backend
9198                                       (intern method)))))
9199              (list (intern method) ""))
9200             ((= 1 (length ms))
9201              (car ms))
9202             (t
9203              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9204                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9205                            ms-alist))))))))
9206   (unless method
9207     (error "No method given for respooling"))
9208   (if (assoc (symbol-name
9209               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9210              (gnus-methods-using 'respool))
9211       (gnus-summary-move-article n nil method)
9212     (gnus-summary-copy-article n nil method)))
9213
9214 (defun gnus-summary-import-article (file &optional edit)
9215   "Import an arbitrary file into a mail newsgroup."
9216   (interactive "fImport file: \nP")
9217   (let ((group gnus-newsgroup-name)
9218         (now (current-time))
9219         atts lines group-art)
9220     (unless (gnus-check-backend-function 'request-accept-article group)
9221       (error "%s does not support article importing" group))
9222     (or (file-readable-p file)
9223         (not (file-regular-p file))
9224         (error "Can't read %s" file))
9225     (save-excursion
9226       (set-buffer (gnus-get-buffer-create " *import file*"))
9227       (erase-buffer)
9228       (nnheader-insert-file-contents file)
9229       (goto-char (point-min))
9230       (if (nnheader-article-p)
9231           (save-restriction
9232             (goto-char (point-min))
9233             (search-forward "\n\n" nil t)
9234             (narrow-to-region (point-min) (1- (point)))
9235             (goto-char (point-min))
9236             (unless (re-search-forward "^date:" nil t)
9237               (goto-char (point-max))
9238               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9239         ;; This doesn't look like an article, so we fudge some headers.
9240         (setq atts (file-attributes file)
9241               lines (count-lines (point-min) (point-max)))
9242         (insert "From: " (read-string "From: ") "\n"
9243                 "Subject: " (read-string "Subject: ") "\n"
9244                 "Date: " (message-make-date (nth 5 atts)) "\n"
9245                 "Message-ID: " (message-make-message-id) "\n"
9246                 "Lines: " (int-to-string lines) "\n"
9247                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9248       (setq group-art (gnus-request-accept-article group nil t))
9249       (kill-buffer (current-buffer)))
9250     (setq gnus-newsgroup-active (gnus-activate-group group))
9251     (forward-line 1)
9252     (gnus-summary-goto-article (cdr group-art) nil t)
9253     (when edit
9254       (gnus-summary-edit-article))))
9255
9256 (defun gnus-summary-create-article ()
9257   "Create an article in a mail newsgroup."
9258   (interactive)
9259   (let ((group gnus-newsgroup-name)
9260         (now (current-time))
9261         group-art)
9262     (unless (gnus-check-backend-function 'request-accept-article group)
9263       (error "%s does not support article importing" group))
9264     (save-excursion
9265       (set-buffer (gnus-get-buffer-create " *import file*"))
9266       (erase-buffer)
9267       (goto-char (point-min))
9268       ;; This doesn't look like an article, so we fudge some headers.
9269       (insert "From: " (read-string "From: ") "\n"
9270               "Subject: " (read-string "Subject: ") "\n"
9271               "Date: " (message-make-date now) "\n"
9272               "Message-ID: " (message-make-message-id) "\n")
9273       (setq group-art (gnus-request-accept-article group nil t))
9274       (kill-buffer (current-buffer)))
9275     (setq gnus-newsgroup-active (gnus-activate-group group))
9276     (forward-line 1)
9277     (gnus-summary-goto-article (cdr group-art) nil t)
9278     (gnus-summary-edit-article)))
9279
9280 (defun gnus-summary-article-posted-p ()
9281   "Say whether the current (mail) article is available from news as well.
9282 This will be the case if the article has both been mailed and posted."
9283   (interactive)
9284   (let ((id (mail-header-references (gnus-summary-article-header)))
9285         (gnus-override-method (car (gnus-refer-article-methods))))
9286     (if (gnus-request-head id "")
9287         (gnus-message 2 "The current message was found on %s"
9288                       gnus-override-method)
9289       (gnus-message 2 "The current message couldn't be found on %s"
9290                     gnus-override-method)
9291       nil)))
9292
9293 (defun gnus-summary-expire-articles (&optional now)
9294   "Expire all articles that are marked as expirable in the current group."
9295   (interactive)
9296   (when (and (not gnus-group-is-exiting-without-update-p)
9297              (gnus-check-backend-function
9298               'request-expire-articles gnus-newsgroup-name))
9299     ;; This backend supports expiry.
9300     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9301            (expirable (if total
9302                           (progn
9303                             ;; We need to update the info for
9304                             ;; this group for `gnus-list-of-read-articles'
9305                             ;; to give us the right answer.
9306                             (gnus-run-hooks 'gnus-exit-group-hook)
9307                             (gnus-summary-update-info)
9308                             (gnus-list-of-read-articles gnus-newsgroup-name))
9309                         (setq gnus-newsgroup-expirable
9310                               (sort gnus-newsgroup-expirable '<))))
9311            (expiry-wait (if now 'immediate
9312                           (gnus-group-find-parameter
9313                            gnus-newsgroup-name 'expiry-wait)))
9314            (nnmail-expiry-target
9315             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9316                 nnmail-expiry-target))
9317            es)
9318       (when expirable
9319         ;; There are expirable articles in this group, so we run them
9320         ;; through the expiry process.
9321         (gnus-message 6 "Expiring articles...")
9322         (unless (gnus-check-group gnus-newsgroup-name)
9323           (error "Can't open server for %s" gnus-newsgroup-name))
9324         ;; The list of articles that weren't expired is returned.
9325         (save-excursion
9326           (if expiry-wait
9327               (let ((nnmail-expiry-wait-function nil)
9328                     (nnmail-expiry-wait expiry-wait))
9329                 (setq es (gnus-request-expire-articles
9330                           expirable gnus-newsgroup-name)))
9331             (setq es (gnus-request-expire-articles
9332                       expirable gnus-newsgroup-name)))
9333           (unless total
9334             (setq gnus-newsgroup-expirable es))
9335           ;; We go through the old list of expirable, and mark all
9336           ;; really expired articles as nonexistent.
9337           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9338             (let ((gnus-use-cache nil))
9339               (dolist (article expirable)
9340                 (when (and (not (memq article es))
9341                            (gnus-data-find article))
9342                   (gnus-summary-mark-article article gnus-canceled-mark)
9343                   (run-hook-with-args 'gnus-summary-article-expire-hook
9344                                       'delete
9345                                       (gnus-data-header
9346                                        (assoc article (gnus-data-list nil)))
9347                                       gnus-newsgroup-name
9348                                       nil
9349                                       nil))))))
9350         (gnus-message 6 "Expiring articles...done")))))
9351
9352 (defun gnus-summary-expire-articles-now ()
9353   "Expunge all expirable articles in the current group.
9354 This means that *all* articles that are marked as expirable will be
9355 deleted forever, right now."
9356   (interactive)
9357   (or gnus-expert-user
9358       (gnus-yes-or-no-p
9359        "Are you really, really, really sure you want to delete all these messages? ")
9360       (error "Phew!"))
9361   (gnus-summary-expire-articles t))
9362
9363 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9364 (defun gnus-summary-delete-article (&optional n)
9365   "Delete the N next (mail) articles.
9366 This command actually deletes articles.  This is not a marking
9367 command.  The article will disappear forever from your life, never to
9368 return.
9369
9370 If N is negative, delete backwards.
9371 If N is nil and articles have been marked with the process mark,
9372 delete these instead.
9373
9374 If `gnus-novice-user' is non-nil you will be asked for
9375 confirmation before the articles are deleted."
9376   (interactive "P")
9377   (unless (gnus-check-backend-function 'request-expire-articles
9378                                        gnus-newsgroup-name)
9379     (error "The current newsgroup does not support article deletion"))
9380   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9381     (error "Couldn't open server"))
9382   ;; Compute the list of articles to delete.
9383   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9384         (nnmail-expiry-target 'delete)
9385         not-deleted)
9386     (if (and gnus-novice-user
9387              (not (gnus-yes-or-no-p
9388                    (format "Do you really want to delete %s forever? "
9389                            (if (> (length articles) 1)
9390                                (format "these %s articles" (length articles))
9391                              "this article")))))
9392         ()
9393       ;; Delete the articles.
9394       (setq not-deleted (gnus-request-expire-articles
9395                          articles gnus-newsgroup-name 'force))
9396       (while articles
9397         (gnus-summary-remove-process-mark (car articles))
9398         ;; The backend might not have been able to delete the article
9399         ;; after all.
9400         (unless (memq (car articles) not-deleted)
9401           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9402         (let* ((article (car articles))
9403                (id (mail-header-id (gnus-data-header 
9404                                     (assoc article (gnus-data-list nil))))))
9405           (run-hook-with-args 'gnus-summary-article-delete-hook
9406                               'delete id gnus-newsgroup-name nil
9407                               nil))
9408         (setq articles (cdr articles)))
9409       (when not-deleted
9410         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9411     (gnus-summary-position-point)
9412     (gnus-set-mode-line 'summary)
9413     not-deleted))
9414
9415 (defun gnus-summary-edit-article (&optional force)
9416   "Edit the current article.
9417 This will have permanent effect only in mail groups.
9418 If FORCE is non-nil, allow editing of articles even in read-only
9419 groups."
9420   (interactive "P")
9421   (save-excursion
9422     (set-buffer gnus-summary-buffer)
9423     (let ((mail-parse-charset gnus-newsgroup-charset)
9424           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9425       (gnus-set-global-variables)
9426       (when (and (not force)
9427                  (gnus-group-read-only-p))
9428         (error "The current newsgroup does not support article editing"))
9429       (gnus-summary-show-article t)
9430       (gnus-article-edit-article
9431        'ignore
9432        `(lambda (no-highlight)
9433           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9434                 (message-options message-options)
9435                 (message-options-set-recipient)
9436                 (mail-parse-ignored-charsets
9437                  ',gnus-newsgroup-ignored-charsets))
9438             (gnus-summary-edit-article-done
9439              ,(or (mail-header-references gnus-current-headers) "")
9440              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9441
9442 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9443
9444 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9445                                                  no-highlight)
9446   "Make edits to the current article permanent."
9447   (interactive)
9448   (save-excursion
9449     ;; The buffer restriction contains the entire article if it exists.
9450     (when (article-goto-body)
9451       (let ((lines (count-lines (point) (point-max)))
9452             (length (- (point-max) (point)))
9453             (case-fold-search t)
9454             (body (copy-marker (point))))
9455         (goto-char (point-min))
9456         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9457           (delete-region (match-beginning 1) (match-end 1))
9458           (insert (number-to-string length)))
9459         (goto-char (point-min))
9460         (when (re-search-forward
9461                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9462           (delete-region (match-beginning 1) (match-end 1))
9463           (insert (number-to-string length)))
9464         (goto-char (point-min))
9465         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9466           (delete-region (match-beginning 1) (match-end 1))
9467           (insert (number-to-string lines))))))
9468   ;; Replace the article.
9469   (let ((buf (current-buffer)))
9470     (with-temp-buffer
9471       (insert-buffer-substring buf)
9472
9473       (if (and (not read-only)
9474                (not (gnus-request-replace-article
9475                      (cdr gnus-article-current) (car gnus-article-current)
9476                      (current-buffer) t)))
9477           (error "Couldn't replace article")
9478         ;; Update the summary buffer.
9479         (if (and references
9480                  (equal (message-tokenize-header references " ")
9481                         (message-tokenize-header
9482                          (or (message-fetch-field "references") "") " ")))
9483             ;; We only have to update this line.
9484             (save-excursion
9485               (save-restriction
9486                 (message-narrow-to-head)
9487                 (let ((head (buffer-string))
9488                       header)
9489                   (with-temp-buffer
9490                     (insert (format "211 %d Article retrieved.\n"
9491                                     (cdr gnus-article-current)))
9492                     (insert head)
9493                     (insert ".\n")
9494                     (let ((nntp-server-buffer (current-buffer)))
9495                       (setq header (car (gnus-get-newsgroup-headers
9496                                          nil t))))
9497                     (save-excursion
9498                       (set-buffer gnus-summary-buffer)
9499                       (gnus-data-set-header
9500                        (gnus-data-find (cdr gnus-article-current))
9501                        header)
9502                       (gnus-summary-update-article-line
9503                        (cdr gnus-article-current) header)
9504                       (if (gnus-summary-goto-subject
9505                            (cdr gnus-article-current) nil t)
9506                           (gnus-summary-update-secondary-mark
9507                            (cdr gnus-article-current))))))))
9508           ;; Update threads.
9509           (set-buffer (or buffer gnus-summary-buffer))
9510           (gnus-summary-update-article (cdr gnus-article-current))
9511           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9512               (gnus-summary-update-secondary-mark
9513                (cdr gnus-article-current))))
9514         ;; Prettify the article buffer again.
9515         (unless no-highlight
9516           (save-excursion
9517             (set-buffer gnus-article-buffer)
9518             ;;;!!! Fix this -- article should be rehighlighted.
9519             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9520             (set-buffer gnus-original-article-buffer)
9521             (gnus-request-article
9522              (cdr gnus-article-current)
9523              (car gnus-article-current) (current-buffer))))
9524         ;; Prettify the summary buffer line.
9525         (when (gnus-visual-p 'summary-highlight 'highlight)
9526           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9527
9528 (defun gnus-summary-edit-wash (key)
9529   "Perform editing command KEY in the article buffer."
9530   (interactive
9531    (list
9532     (progn
9533       (message "%s" (concat (this-command-keys) "- "))
9534       (read-char))))
9535   (message "")
9536   (gnus-summary-edit-article)
9537   (execute-kbd-macro (concat (this-command-keys) key))
9538   (gnus-article-edit-done))
9539
9540 ;;; Respooling
9541
9542 (defun gnus-summary-respool-query (&optional silent trace)
9543   "Query where the respool algorithm would put this article."
9544   (interactive)
9545   (let (gnus-mark-article-hook)
9546     (gnus-summary-select-article)
9547     (save-excursion
9548       (set-buffer gnus-original-article-buffer)
9549       (save-restriction
9550         (message-narrow-to-head)
9551         (let ((groups (nnmail-article-group 'identity trace)))
9552           (unless silent
9553             (if groups
9554                 (message "This message would go to %s"
9555                          (mapconcat 'car groups ", "))
9556               (message "This message would go to no groups"))
9557             groups))))))
9558
9559 (defun gnus-summary-respool-trace ()
9560   "Trace where the respool algorithm would put this article.
9561 Display a buffer showing all fancy splitting patterns which matched."
9562   (interactive)
9563   (gnus-summary-respool-query nil t))
9564
9565 ;; Summary marking commands.
9566
9567 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9568   "Mark articles which has the same subject as read, and then select the next.
9569 If UNMARK is positive, remove any kind of mark.
9570 If UNMARK is negative, tick articles."
9571   (interactive "P")
9572   (when unmark
9573     (setq unmark (prefix-numeric-value unmark)))
9574   (let ((count
9575          (gnus-summary-mark-same-subject
9576           (gnus-summary-article-subject) unmark)))
9577     ;; Select next unread article.  If auto-select-same mode, should
9578     ;; select the first unread article.
9579     (gnus-summary-next-article t (and gnus-auto-select-same
9580                                       (gnus-summary-article-subject)))
9581     (gnus-message 7 "%d article%s marked as %s"
9582                   count (if (= count 1) " is" "s are")
9583                   (if unmark "unread" "read"))))
9584
9585 (defun gnus-summary-kill-same-subject (&optional unmark)
9586   "Mark articles which has the same subject as read.
9587 If UNMARK is positive, remove any kind of mark.
9588 If UNMARK is negative, tick articles."
9589   (interactive "P")
9590   (when unmark
9591     (setq unmark (prefix-numeric-value unmark)))
9592   (let ((count
9593          (gnus-summary-mark-same-subject
9594           (gnus-summary-article-subject) unmark)))
9595     ;; If marked as read, go to next unread subject.
9596     (when (null unmark)
9597       ;; Go to next unread subject.
9598       (gnus-summary-next-subject 1 t))
9599     (gnus-message 7 "%d articles are marked as %s"
9600                   count (if unmark "unread" "read"))))
9601
9602 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9603   "Mark articles with same SUBJECT as read, and return marked number.
9604 If optional argument UNMARK is positive, remove any kinds of marks.
9605 If optional argument UNMARK is negative, mark articles as unread instead."
9606   (let ((count 1))
9607     (save-excursion
9608       (cond
9609        ((null unmark)                   ; Mark as read.
9610         (while (and
9611                 (progn
9612                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9613                   (gnus-summary-show-thread) t)
9614                 (gnus-summary-find-subject subject))
9615           (setq count (1+ count))))
9616        ((> unmark 0)                    ; Tick.
9617         (while (and
9618                 (progn
9619                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9620                   (gnus-summary-show-thread) t)
9621                 (gnus-summary-find-subject subject))
9622           (setq count (1+ count))))
9623        (t                               ; Mark as unread.
9624         (while (and
9625                 (progn
9626                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9627                   (gnus-summary-show-thread) t)
9628                 (gnus-summary-find-subject subject))
9629           (setq count (1+ count)))))
9630       (gnus-set-mode-line 'summary)
9631       ;; Return the number of marked articles.
9632       count)))
9633
9634 (defun gnus-summary-mark-as-processable (n &optional unmark)
9635   "Set the process mark on the next N articles.
9636 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9637 the process mark instead.  The difference between N and the actual
9638 number of articles marked is returned."
9639   (interactive "P")
9640   (if (and (null n) (gnus-region-active-p))
9641       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9642     (setq n (prefix-numeric-value n))
9643     (let ((backward (< n 0))
9644           (n (abs n)))
9645       (while (and
9646               (> n 0)
9647               (if unmark
9648                   (gnus-summary-remove-process-mark
9649                    (gnus-summary-article-number))
9650                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9651               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9652         (setq n (1- n)))
9653       (when (/= 0 n)
9654         (gnus-message 7 "No more articles"))
9655       (gnus-summary-recenter)
9656       (gnus-summary-position-point)
9657       n)))
9658
9659 (defun gnus-summary-unmark-as-processable (n)
9660   "Remove the process mark from the next N articles.
9661 If N is negative, unmark backward instead.  The difference between N and
9662 the actual number of articles unmarked is returned."
9663   (interactive "P")
9664   (gnus-summary-mark-as-processable n t))
9665
9666 (defun gnus-summary-unmark-all-processable ()
9667   "Remove the process mark from all articles."
9668   (interactive)
9669   (save-excursion
9670     (while gnus-newsgroup-processable
9671       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9672   (gnus-summary-position-point))
9673
9674 (defun gnus-summary-add-mark (article type)
9675   "Mark ARTICLE with a mark of TYPE."
9676   (let ((vtype (car (assq type gnus-article-mark-lists)))
9677         var)
9678     (if (not vtype)
9679         (error "No such mark type: %s" type)
9680       (setq var (intern (format "gnus-newsgroup-%s" type)))
9681       (set var (cons article (symbol-value var)))
9682       (if (memq type '(processable cached replied forwarded recent saved))
9683           (gnus-summary-update-secondary-mark article)
9684         ;;; !!! This is bogus.  We should find out what primary
9685         ;;; !!! mark we want to set.
9686         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9687
9688 (defun gnus-summary-mark-as-expirable (n)
9689   "Mark N articles forward as expirable.
9690 If N is negative, mark backward instead.  The difference between N and
9691 the actual number of articles marked is returned."
9692   (interactive "p")
9693   (gnus-summary-mark-forward n gnus-expirable-mark))
9694
9695 (defun gnus-summary-mark-as-spam (n)
9696   "Mark N articles forward as spam.
9697 If N is negative, mark backward instead.  The difference between N and
9698 the actual number of articles marked is returned."
9699   (interactive "p")
9700   (gnus-summary-mark-forward n gnus-spam-mark))
9701
9702 (defun gnus-summary-mark-article-as-replied (article)
9703   "Mark ARTICLE as replied to and update the summary line.
9704 ARTICLE can also be a list of articles."
9705   (interactive (list (gnus-summary-article-number)))
9706   (let ((articles (if (listp article) article (list article))))
9707     (dolist (article articles)
9708       (unless (numberp article)
9709         (error "%s is not a number" article))
9710       (push article gnus-newsgroup-replied)
9711       (let ((buffer-read-only nil))
9712         (when (gnus-summary-goto-subject article nil t)
9713           (gnus-summary-update-secondary-mark article))))))
9714
9715 (defun gnus-summary-mark-article-as-forwarded (article)
9716   "Mark ARTICLE as forwarded and update the summary line.
9717 ARTICLE can also be a list of articles."
9718   (let ((articles (if (listp article) article (list article))))
9719     (dolist (article articles)
9720       (push article gnus-newsgroup-forwarded)
9721       (let ((buffer-read-only nil))
9722         (when (gnus-summary-goto-subject article nil t)
9723           (gnus-summary-update-secondary-mark article))))))
9724
9725 (defun gnus-summary-set-bookmark (article)
9726   "Set a bookmark in current article."
9727   (interactive (list (gnus-summary-article-number)))
9728   (when (or (not (get-buffer gnus-article-buffer))
9729             (not gnus-current-article)
9730             (not gnus-article-current)
9731             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9732     (error "No current article selected"))
9733   ;; Remove old bookmark, if one exists.
9734   (gnus-pull article gnus-newsgroup-bookmarks)
9735   ;; Set the new bookmark, which is on the form
9736   ;; (article-number . line-number-in-body).
9737   (push
9738    (cons article
9739          (save-excursion
9740            (set-buffer gnus-article-buffer)
9741            (count-lines
9742             (min (point)
9743                  (save-excursion
9744                    (article-goto-body)
9745                    (point)))
9746             (point))))
9747    gnus-newsgroup-bookmarks)
9748   (gnus-message 6 "A bookmark has been added to the current article."))
9749
9750 (defun gnus-summary-remove-bookmark (article)
9751   "Remove the bookmark from the current article."
9752   (interactive (list (gnus-summary-article-number)))
9753   ;; Remove old bookmark, if one exists.
9754   (if (not (assq article gnus-newsgroup-bookmarks))
9755       (gnus-message 6 "No bookmark in current article.")
9756     (gnus-pull article gnus-newsgroup-bookmarks)
9757     (gnus-message 6 "Removed bookmark.")))
9758
9759 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9760 (defun gnus-summary-mark-as-dormant (n)
9761   "Mark N articles forward as dormant.
9762 If N is negative, mark backward instead.  The difference between N and
9763 the actual number of articles marked is returned."
9764   (interactive "p")
9765   (gnus-summary-mark-forward n gnus-dormant-mark))
9766
9767 (defun gnus-summary-set-process-mark (article)
9768   "Set the process mark on ARTICLE and update the summary line."
9769   (setq gnus-newsgroup-processable
9770         (cons article
9771               (delq article gnus-newsgroup-processable)))
9772   (when (gnus-summary-goto-subject article)
9773     (gnus-summary-show-thread)
9774     (gnus-summary-goto-subject article)
9775     (gnus-summary-update-secondary-mark article)))
9776
9777 (defun gnus-summary-remove-process-mark (article)
9778   "Remove the process mark from ARTICLE and update the summary line."
9779   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9780   (when (gnus-summary-goto-subject article)
9781     (gnus-summary-show-thread)
9782     (gnus-summary-goto-subject article)
9783     (gnus-summary-update-secondary-mark article)))
9784
9785 (defun gnus-summary-set-saved-mark (article)
9786   "Set the process mark on ARTICLE and update the summary line."
9787   (push article gnus-newsgroup-saved)
9788   (when (gnus-summary-goto-subject article)
9789     (gnus-summary-update-secondary-mark article)))
9790
9791 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9792   "Mark N articles as read forwards.
9793 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9794 The difference between N and the actual number of articles marked is
9795 returned.
9796 If NO-EXPIRE, auto-expiry will be inhibited."
9797   (interactive "p")
9798   (gnus-summary-show-thread)
9799   (let ((backward (< n 0))
9800         (gnus-summary-goto-unread
9801          (and gnus-summary-goto-unread
9802               (not (eq gnus-summary-goto-unread 'never))
9803               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9804                                     gnus-ticked-mark gnus-dormant-mark)))))
9805         (n (abs n))
9806         (mark (or mark gnus-del-mark)))
9807     (while (and (> n 0)
9808                 (gnus-summary-mark-article nil mark no-expire)
9809                 (zerop (gnus-summary-next-subject
9810                         (if backward -1 1)
9811                         (and gnus-summary-goto-unread
9812                              (not (eq gnus-summary-goto-unread 'never)))
9813                         t)))
9814       (setq n (1- n)))
9815     (when (/= 0 n)
9816       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9817     (gnus-summary-recenter)
9818     (gnus-summary-position-point)
9819     (gnus-set-mode-line 'summary)
9820     n))
9821
9822 (defun gnus-summary-mark-article-as-read (mark)
9823   "Mark the current article quickly as read with MARK."
9824   (let ((article (gnus-summary-article-number)))
9825     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9826     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9827     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9828     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9829     (push (cons article mark) gnus-newsgroup-reads)
9830     ;; Possibly remove from cache, if that is used.
9831     (when gnus-use-cache
9832       (gnus-cache-enter-remove-article article))
9833     ;; Allow the backend to change the mark.
9834     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9835     ;; Check for auto-expiry.
9836     (when (and gnus-newsgroup-auto-expire
9837                (memq mark gnus-auto-expirable-marks))
9838       (setq mark gnus-expirable-mark)
9839       ;; Let the backend know about the mark change.
9840       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9841       (push article gnus-newsgroup-expirable))
9842     ;; Set the mark in the buffer.
9843     (gnus-summary-update-mark mark 'unread)
9844     t))
9845
9846 (defun gnus-summary-mark-article-as-unread (mark)
9847   "Mark the current article quickly as unread with MARK."
9848   (let* ((article (gnus-summary-article-number))
9849          (old-mark (gnus-summary-article-mark article)))
9850     ;; Allow the backend to change the mark.
9851     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9852     (if (eq mark old-mark)
9853         t
9854       (if (<= article 0)
9855           (progn
9856             (gnus-error 1 "Can't mark negative article numbers")
9857             nil)
9858         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9859         (setq gnus-newsgroup-spam-marked
9860               (delq article gnus-newsgroup-spam-marked))
9861         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9862         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9863         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9864         (cond ((= mark gnus-ticked-mark)
9865                (setq gnus-newsgroup-marked
9866                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9867                                               article)))
9868               ((= mark gnus-spam-mark)
9869                (setq gnus-newsgroup-spam-marked
9870                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9871                                               article)))
9872               ((= mark gnus-dormant-mark)
9873                (setq gnus-newsgroup-dormant
9874                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9875                                               article)))
9876               (t
9877                (setq gnus-newsgroup-unreads
9878                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9879                                               article))))
9880         (gnus-pull article gnus-newsgroup-reads)
9881
9882         ;; See whether the article is to be put in the cache.
9883         (and gnus-use-cache
9884              (vectorp (gnus-summary-article-header article))
9885              (save-excursion
9886                (gnus-cache-possibly-enter-article
9887                 gnus-newsgroup-name article
9888                 (gnus-summary-article-header article)
9889                 (= mark gnus-ticked-mark)
9890                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9891
9892         ;; Fix the mark.
9893         (gnus-summary-update-mark mark 'unread)
9894         t))))
9895
9896 (defun gnus-summary-mark-article (&optional article mark no-expire)
9897   "Mark ARTICLE with MARK.  MARK can be any character.
9898 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9899 `??' (dormant) and `?E' (expirable).
9900 If MARK is nil, then the default character `?r' is used.
9901 If ARTICLE is nil, then the article on the current line will be
9902 marked.
9903 If NO-EXPIRE, auto-expiry will be inhibited."
9904   ;; The mark might be a string.
9905   (when (stringp mark)
9906     (setq mark (aref mark 0)))
9907   ;; If no mark is given, then we check auto-expiring.
9908   (when (null mark)
9909     (setq mark gnus-del-mark))
9910   (when (and (not no-expire)
9911              gnus-newsgroup-auto-expire
9912              (memq mark gnus-auto-expirable-marks))
9913     (setq mark gnus-expirable-mark))
9914   (let ((article (or article (gnus-summary-article-number)))
9915         (old-mark (gnus-summary-article-mark article)))
9916     ;; Allow the backend to change the mark.
9917     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9918     (if (eq mark old-mark)
9919         t
9920       (unless article
9921         (error "No article on current line"))
9922       (if (not (if (or (= mark gnus-unread-mark)
9923                        (= mark gnus-ticked-mark)
9924                        (= mark gnus-spam-mark)
9925                        (= mark gnus-dormant-mark))
9926                    (gnus-mark-article-as-unread article mark)
9927                  (gnus-mark-article-as-read article mark)))
9928           t
9929         ;; See whether the article is to be put in the cache.
9930         (and gnus-use-cache
9931              (not (= mark gnus-canceled-mark))
9932              (vectorp (gnus-summary-article-header article))
9933              (save-excursion
9934                (gnus-cache-possibly-enter-article
9935                 gnus-newsgroup-name article
9936                 (gnus-summary-article-header article)
9937                 (= mark gnus-ticked-mark)
9938                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9939
9940         (when (gnus-summary-goto-subject article nil t)
9941           (let ((buffer-read-only nil))
9942             (gnus-summary-show-thread)
9943             ;; Fix the mark.
9944             (gnus-summary-update-mark mark 'unread)
9945             t))))))
9946
9947 (defun gnus-summary-update-secondary-mark (article)
9948   "Update the secondary (read, process, cache) mark."
9949   (gnus-summary-update-mark
9950    (cond ((memq article gnus-newsgroup-processable)
9951           gnus-process-mark)
9952          ((memq article gnus-newsgroup-cached)
9953           gnus-cached-mark)
9954          ((memq article gnus-newsgroup-replied)
9955           gnus-replied-mark)
9956          ((memq article gnus-newsgroup-forwarded)
9957           gnus-forwarded-mark)
9958          ((memq article gnus-newsgroup-saved)
9959           gnus-saved-mark)
9960          ((memq article gnus-newsgroup-recent)
9961           gnus-recent-mark)
9962          ((memq article gnus-newsgroup-unseen)
9963           gnus-unseen-mark)
9964          (t gnus-no-mark))
9965    'replied)
9966   (when (gnus-visual-p 'summary-highlight 'highlight)
9967     (gnus-run-hooks 'gnus-summary-update-hook))
9968   t)
9969
9970 (defun gnus-summary-update-download-mark (article)
9971   "Update the download mark."
9972   (gnus-summary-update-mark
9973    (cond ((memq article gnus-newsgroup-undownloaded) 
9974           gnus-undownloaded-mark)
9975          (gnus-newsgroup-agentized
9976           gnus-downloaded-mark)
9977          (t
9978           gnus-no-mark))
9979    'download)
9980   (gnus-summary-update-line t)
9981   t)
9982
9983 (defun gnus-summary-update-mark (mark type)
9984   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9985         (buffer-read-only nil))
9986     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9987     (when forward
9988       (when (looking-at "\r")
9989         (incf forward))
9990       (when (<= (+ forward (point)) (point-max))
9991         ;; Go to the right position on the line.
9992         (goto-char (+ forward (point)))
9993         ;; Replace the old mark with the new mark.
9994         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9995         ;; Optionally update the marks by some user rule.
9996         (when (eq type 'unread)
9997           (gnus-data-set-mark
9998            (gnus-data-find (gnus-summary-article-number)) mark)
9999           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10000
10001 (defun gnus-mark-article-as-read (article &optional mark)
10002   "Enter ARTICLE in the pertinent lists and remove it from others."
10003   ;; Make the article expirable.
10004   (let ((mark (or mark gnus-del-mark)))
10005     (setq gnus-newsgroup-expirable
10006           (if (= mark gnus-expirable-mark)
10007               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10008             (delq article gnus-newsgroup-expirable)))
10009     ;; Remove from unread and marked lists.
10010     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10011     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10012     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10013     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10014     (push (cons article mark) gnus-newsgroup-reads)
10015     ;; Possibly remove from cache, if that is used.
10016     (when gnus-use-cache
10017       (gnus-cache-enter-remove-article article))
10018     t))
10019
10020 (defun gnus-mark-article-as-unread (article &optional mark)
10021   "Enter ARTICLE in the pertinent lists and remove it from others."
10022   (let ((mark (or mark gnus-ticked-mark)))
10023     (if (<= article 0)
10024         (progn
10025           (gnus-error 1 "Can't mark negative article numbers")
10026           nil)
10027       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10028             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10029             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10030             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10031             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10032
10033       ;; Unsuppress duplicates?
10034       (when gnus-suppress-duplicates
10035         (gnus-dup-unsuppress-article article))
10036
10037       (cond ((= mark gnus-ticked-mark)
10038              (setq gnus-newsgroup-marked
10039                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10040             ((= mark gnus-spam-mark)
10041              (setq gnus-newsgroup-spam-marked
10042                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10043                                             article)))
10044             ((= mark gnus-dormant-mark)
10045              (setq gnus-newsgroup-dormant
10046                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10047             (t
10048              (setq gnus-newsgroup-unreads
10049                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10050       (gnus-pull article gnus-newsgroup-reads)
10051       t)))
10052
10053 (defalias 'gnus-summary-mark-as-unread-forward
10054   'gnus-summary-tick-article-forward)
10055 (make-obsolete 'gnus-summary-mark-as-unread-forward
10056                'gnus-summary-tick-article-forward)
10057 (defun gnus-summary-tick-article-forward (n)
10058   "Tick N articles forwards.
10059 If N is negative, tick backwards instead.
10060 The difference between N and the number of articles ticked is returned."
10061   (interactive "p")
10062   (gnus-summary-mark-forward n gnus-ticked-mark))
10063
10064 (defalias 'gnus-summary-mark-as-unread-backward
10065   'gnus-summary-tick-article-backward)
10066 (make-obsolete 'gnus-summary-mark-as-unread-backward
10067                'gnus-summary-tick-article-backward)
10068 (defun gnus-summary-tick-article-backward (n)
10069   "Tick N articles backwards.
10070 The difference between N and the number of articles ticked is returned."
10071   (interactive "p")
10072   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10073
10074 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10075 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10076 (defun gnus-summary-tick-article (&optional article clear-mark)
10077   "Mark current article as unread.
10078 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10079 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10080   (interactive)
10081   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10082                                        gnus-ticked-mark)))
10083
10084 (defun gnus-summary-mark-as-read-forward (n)
10085   "Mark N articles as read forwards.
10086 If N is negative, mark backwards instead.
10087 The difference between N and the actual number of articles marked is
10088 returned."
10089   (interactive "p")
10090   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10091
10092 (defun gnus-summary-mark-as-read-backward (n)
10093   "Mark the N articles as read backwards.
10094 The difference between N and the actual number of articles marked is
10095 returned."
10096   (interactive "p")
10097   (gnus-summary-mark-forward
10098    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10099
10100 (defun gnus-summary-mark-as-read (&optional article mark)
10101   "Mark current article as read.
10102 ARTICLE specifies the article to be marked as read.
10103 MARK specifies a string to be inserted at the beginning of the line."
10104   (gnus-summary-mark-article article mark))
10105
10106 (defun gnus-summary-clear-mark-forward (n)
10107   "Clear marks from N articles forward.
10108 If N is negative, clear backward instead.
10109 The difference between N and the number of marks cleared is returned."
10110   (interactive "p")
10111   (gnus-summary-mark-forward n gnus-unread-mark))
10112
10113 (defun gnus-summary-clear-mark-backward (n)
10114   "Clear marks from N articles backward.
10115 The difference between N and the number of marks cleared is returned."
10116   (interactive "p")
10117   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10118
10119 (defun gnus-summary-mark-unread-as-read ()
10120   "Intended to be used by `gnus-summary-mark-article-hook'."
10121   (when (memq gnus-current-article gnus-newsgroup-unreads)
10122     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10123
10124 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10125   "Intended to be used by `gnus-summary-mark-article-hook'."
10126   (let ((mark (gnus-summary-article-mark)))
10127     (when (or (gnus-unread-mark-p mark)
10128               (gnus-read-mark-p mark))
10129       (gnus-summary-mark-article gnus-current-article
10130                                  (or new-mark gnus-read-mark)))))
10131
10132 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10133   "Intended to be used by `gnus-summary-mark-article-hook'."
10134   (let ((mark (gnus-summary-article-mark)))
10135     (when (or (gnus-unread-mark-p mark)
10136               (gnus-read-mark-p mark))
10137       (gnus-summary-mark-article (gnus-summary-article-number)
10138                                  (or new-mark gnus-read-mark)))))
10139
10140 (defun gnus-summary-mark-unread-as-ticked ()
10141   "Intended to be used by `gnus-summary-mark-article-hook'."
10142   (when (memq gnus-current-article gnus-newsgroup-unreads)
10143     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10144
10145 (defun gnus-summary-mark-region-as-read (point mark all)
10146   "Mark all unread articles between point and mark as read.
10147 If given a prefix, mark all articles between point and mark as read,
10148 even ticked and dormant ones."
10149   (interactive "r\nP")
10150   (save-excursion
10151     (let (article)
10152       (goto-char point)
10153       (beginning-of-line)
10154       (while (and
10155               (< (point) mark)
10156               (progn
10157                 (when (or all
10158                           (memq (setq article (gnus-summary-article-number))
10159                                 gnus-newsgroup-unreads))
10160                   (gnus-summary-mark-article article gnus-del-mark))
10161                 t)
10162               (gnus-summary-find-next))))))
10163
10164 (defun gnus-summary-mark-below (score mark)
10165   "Mark articles with score less than SCORE with MARK."
10166   (interactive "P\ncMark: ")
10167   (setq score (if score
10168                   (prefix-numeric-value score)
10169                 (or gnus-summary-default-score 0)))
10170   (save-excursion
10171     (set-buffer gnus-summary-buffer)
10172     (goto-char (point-min))
10173     (while
10174         (progn
10175           (and (< (gnus-summary-article-score) score)
10176                (gnus-summary-mark-article nil mark))
10177           (gnus-summary-find-next)))))
10178
10179 (defun gnus-summary-kill-below (&optional score)
10180   "Mark articles with score below SCORE as read."
10181   (interactive "P")
10182   (gnus-summary-mark-below score gnus-killed-mark))
10183
10184 (defun gnus-summary-clear-above (&optional score)
10185   "Clear all marks from articles with score above SCORE."
10186   (interactive "P")
10187   (gnus-summary-mark-above score gnus-unread-mark))
10188
10189 (defun gnus-summary-tick-above (&optional score)
10190   "Tick all articles with score above SCORE."
10191   (interactive "P")
10192   (gnus-summary-mark-above score gnus-ticked-mark))
10193
10194 (defun gnus-summary-mark-above (score mark)
10195   "Mark articles with score over SCORE with MARK."
10196   (interactive "P\ncMark: ")
10197   (setq score (if score
10198                   (prefix-numeric-value score)
10199                 (or gnus-summary-default-score 0)))
10200   (save-excursion
10201     (set-buffer gnus-summary-buffer)
10202     (goto-char (point-min))
10203     (while (and (progn
10204                   (when (> (gnus-summary-article-score) score)
10205                     (gnus-summary-mark-article nil mark))
10206                   t)
10207                 (gnus-summary-find-next)))))
10208
10209 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10210 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10211 (defun gnus-summary-limit-include-expunged (&optional no-error)
10212   "Display all the hidden articles that were expunged for low scores."
10213   (interactive)
10214   (let ((buffer-read-only nil))
10215     (let ((scored gnus-newsgroup-scored)
10216           headers h)
10217       (while scored
10218         (unless (gnus-summary-article-header (caar scored))
10219           (and (setq h (gnus-number-to-header (caar scored)))
10220                (< (cdar scored) gnus-summary-expunge-below)
10221                (push h headers)))
10222         (setq scored (cdr scored)))
10223       (if (not headers)
10224           (when (not no-error)
10225             (error "No expunged articles hidden"))
10226         (goto-char (point-min))
10227         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10228         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10229         (mapcar (lambda (x) (push (mail-header-number x)
10230                                   gnus-newsgroup-limit))
10231                 headers)
10232         (gnus-summary-prepare-unthreaded (nreverse headers))
10233         (goto-char (point-min))
10234         (gnus-summary-position-point)
10235         t))))
10236
10237 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10238   "Mark all unread articles in this newsgroup as read.
10239 If prefix argument ALL is non-nil, ticked and dormant articles will
10240 also be marked as read.
10241 If QUIETLY is non-nil, no questions will be asked.
10242
10243 If TO-HERE is non-nil, it should be a point in the buffer.  All
10244 articles before (after, if REVERSE is set) this point will be marked
10245 as read.
10246
10247 Note that this function will only catch up the unread article
10248 in the current summary buffer limitation.
10249
10250 The number of articles marked as read is returned."
10251   (interactive "P")
10252   (prog1
10253       (save-excursion
10254         (when (or quietly
10255                   (not gnus-interactive-catchup) ;Without confirmation?
10256                   gnus-expert-user
10257                   (gnus-y-or-n-p
10258                    (if all
10259                        "Mark absolutely all articles as read? "
10260                      "Mark all unread articles as read? ")))
10261           (if (and not-mark
10262                    (not gnus-newsgroup-adaptive)
10263                    (not gnus-newsgroup-auto-expire)
10264                    (not gnus-suppress-duplicates)
10265                    (or (not gnus-use-cache)
10266                        (eq gnus-use-cache 'passive)))
10267               (progn
10268                 (when all
10269                   (setq gnus-newsgroup-marked nil
10270                         gnus-newsgroup-spam-marked nil
10271                         gnus-newsgroup-dormant nil))
10272                 (setq gnus-newsgroup-unreads
10273                       (gnus-sorted-nunion
10274                        (gnus-intersection gnus-newsgroup-unreads
10275                                           gnus-newsgroup-downloadable)
10276                        gnus-newsgroup-unfetched)))
10277             ;; We actually mark all articles as canceled, which we
10278             ;; have to do when using auto-expiry or adaptive scoring.
10279             (gnus-summary-show-all-threads)
10280             (if (and to-here reverse)
10281                 (progn
10282                   (goto-char to-here)
10283                   (gnus-summary-mark-current-read-and-unread-as-read
10284                    gnus-catchup-mark)
10285                   (while (gnus-summary-find-next (not all))
10286                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10287               (when (gnus-summary-first-subject (not all))
10288                 (while (and
10289                         (if to-here (< (point) to-here) t)
10290                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10291                         (gnus-summary-find-next (not all))))))
10292             (gnus-set-mode-line 'summary))
10293           t))
10294     (gnus-summary-position-point)))
10295
10296 (defun gnus-summary-catchup-to-here (&optional all)
10297   "Mark all unticked articles before the current one as read.
10298 If ALL is non-nil, also mark ticked and dormant articles as read."
10299   (interactive "P")
10300   (save-excursion
10301     (gnus-save-hidden-threads
10302       (let ((beg (point)))
10303         ;; We check that there are unread articles.
10304         (when (or all (gnus-summary-find-prev))
10305           (gnus-summary-catchup all t beg)))))
10306   (gnus-summary-position-point))
10307
10308 (defun gnus-summary-catchup-from-here (&optional all)
10309   "Mark all unticked articles after (and including) the current one as read.
10310 If ALL is non-nil, also mark ticked and dormant articles as read."
10311   (interactive "P")
10312   (save-excursion
10313     (gnus-save-hidden-threads
10314       (let ((beg (point)))
10315         ;; We check that there are unread articles.
10316         (when (or all (gnus-summary-find-next))
10317           (gnus-summary-catchup all t beg nil t)))))
10318   (gnus-summary-position-point))
10319
10320 (defun gnus-summary-catchup-all (&optional quietly)
10321   "Mark all articles in this newsgroup as read.
10322 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10323 instead, which marks only unread articles as read."
10324   (interactive "P")
10325   (gnus-summary-catchup t quietly))
10326
10327 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10328   "Mark all unread articles in this group as read, then exit.
10329 If prefix argument ALL is non-nil, all articles are marked as read.
10330 If QUIETLY is non-nil, no questions will be asked."
10331   (interactive "P")
10332   (when (gnus-summary-catchup all quietly nil 'fast)
10333     ;; Select next newsgroup or exit.
10334     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10335              (eq gnus-auto-select-next 'quietly))
10336         (gnus-summary-next-group nil)
10337       (gnus-summary-exit))))
10338
10339 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10340   "Mark all articles in this newsgroup as read, and then exit.
10341 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10342 instead, which marks only unread articles as read."
10343   (interactive "P")
10344   (gnus-summary-catchup-and-exit t quietly))
10345
10346 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10347   "Mark all articles in this group as read and select the next group.
10348 If given a prefix, mark all articles, unread as well as ticked, as
10349 read."
10350   (interactive "P")
10351   (save-excursion
10352     (gnus-summary-catchup all))
10353   (gnus-summary-next-group))
10354
10355 ;;;
10356 ;;; with article
10357 ;;;
10358
10359 (defmacro gnus-with-article (article &rest forms)
10360   "Select ARTICLE and perform FORMS in the original article buffer.
10361 Then replace the article with the result."
10362   `(progn
10363      ;; We don't want the article to be marked as read.
10364      (let (gnus-mark-article-hook)
10365        (gnus-summary-select-article t t nil ,article))
10366      (set-buffer gnus-original-article-buffer)
10367      ,@forms
10368      (if (not (gnus-check-backend-function
10369                'request-replace-article (car gnus-article-current)))
10370          (gnus-message 5 "Read-only group; not replacing")
10371        (unless (gnus-request-replace-article
10372                 ,article (car gnus-article-current)
10373                 (current-buffer) t)
10374          (error "Couldn't replace article")))
10375      ;; The cache and backlog have to be flushed somewhat.
10376      (when gnus-keep-backlog
10377        (gnus-backlog-remove-article
10378         (car gnus-article-current) (cdr gnus-article-current)))
10379      (when gnus-use-cache
10380        (gnus-cache-update-article
10381         (car gnus-article-current) (cdr gnus-article-current)))))
10382
10383 (put 'gnus-with-article 'lisp-indent-function 1)
10384 (put 'gnus-with-article 'edebug-form-spec '(form body))
10385
10386 ;; Thread-based commands.
10387
10388 (defun gnus-summary-articles-in-thread (&optional article)
10389   "Return a list of all articles in the current thread.
10390 If ARTICLE is non-nil, return all articles in the thread that starts
10391 with that article."
10392   (let* ((article (or article (gnus-summary-article-number)))
10393          (data (gnus-data-find-list article))
10394          (top-level (gnus-data-level (car data)))
10395          (top-subject
10396           (cond ((null gnus-thread-operation-ignore-subject)
10397                  (gnus-simplify-subject-re
10398                   (mail-header-subject (gnus-data-header (car data)))))
10399                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10400                  (gnus-simplify-subject-fuzzy
10401                   (mail-header-subject (gnus-data-header (car data)))))
10402                 (t nil)))
10403          (end-point (save-excursion
10404                       (if (gnus-summary-go-to-next-thread)
10405                           (point) (point-max))))
10406          articles)
10407     (while (and data
10408                 (< (gnus-data-pos (car data)) end-point))
10409       (when (or (not top-subject)
10410                 (string= top-subject
10411                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10412                              (gnus-simplify-subject-fuzzy
10413                               (mail-header-subject
10414                                (gnus-data-header (car data))))
10415                            (gnus-simplify-subject-re
10416                             (mail-header-subject
10417                              (gnus-data-header (car data)))))))
10418         (push (gnus-data-number (car data)) articles))
10419       (unless (and (setq data (cdr data))
10420                    (> (gnus-data-level (car data)) top-level))
10421         (setq data nil)))
10422     ;; Return the list of articles.
10423     (nreverse articles)))
10424
10425 (defun gnus-summary-rethread-current ()
10426   "Rethread the thread the current article is part of."
10427   (interactive)
10428   (let* ((gnus-show-threads t)
10429          (article (gnus-summary-article-number))
10430          (id (mail-header-id (gnus-summary-article-header)))
10431          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10432     (unless id
10433       (error "No article on the current line"))
10434     (gnus-rebuild-thread id)
10435     (gnus-summary-goto-subject article)))
10436
10437 (defun gnus-summary-reparent-thread ()
10438   "Make the current article child of the marked (or previous) article.
10439
10440 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10441 is non-nil or the Subject: of both articles are the same."
10442   (interactive)
10443   (unless (not (gnus-group-read-only-p))
10444     (error "The current newsgroup does not support article editing"))
10445   (unless (<= (length gnus-newsgroup-processable) 1)
10446     (error "No more than one article may be marked"))
10447   (save-window-excursion
10448     (let ((gnus-article-buffer " *reparent*")
10449           (current-article (gnus-summary-article-number))
10450           ;; First grab the marked article, otherwise one line up.
10451           (parent-article (if (not (null gnus-newsgroup-processable))
10452                               (car gnus-newsgroup-processable)
10453                             (save-excursion
10454                               (if (eq (forward-line -1) 0)
10455                                   (gnus-summary-article-number)
10456                                 (error "Beginning of summary buffer"))))))
10457       (unless (not (eq current-article parent-article))
10458         (error "An article may not be self-referential"))
10459       (let ((message-id (mail-header-id
10460                          (gnus-summary-article-header parent-article))))
10461         (unless (and message-id (not (equal message-id "")))
10462           (error "No message-id in desired parent"))
10463         (gnus-with-article current-article
10464           (save-restriction
10465             (goto-char (point-min))
10466             (message-narrow-to-head)
10467             (if (re-search-forward "^References: " nil t)
10468                 (progn
10469                   (re-search-forward "^[^ \t]" nil t)
10470                   (forward-line -1)
10471                   (end-of-line)
10472                   (insert " " message-id))
10473               (insert "References: " message-id "\n"))))
10474         (set-buffer gnus-summary-buffer)
10475         (gnus-summary-unmark-all-processable)
10476         (gnus-summary-update-article current-article)
10477         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10478             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10479         (gnus-summary-rethread-current)
10480         (gnus-message 3 "Article %d is now the child of article %d"
10481                       current-article parent-article)))))
10482
10483 (defun gnus-summary-toggle-threads (&optional arg)
10484   "Toggle showing conversation threads.
10485 If ARG is positive number, turn showing conversation threads on."
10486   (interactive "P")
10487   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10488     (setq gnus-show-threads
10489           (if (null arg) (not gnus-show-threads)
10490             (> (prefix-numeric-value arg) 0)))
10491     (gnus-summary-prepare)
10492     (gnus-summary-goto-subject current)
10493     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10494     (gnus-summary-position-point)))
10495
10496 (defun gnus-summary-show-all-threads ()
10497   "Show all threads."
10498   (interactive)
10499   (save-excursion
10500     (let ((buffer-read-only nil))
10501       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10502   (gnus-summary-position-point))
10503
10504 (defun gnus-summary-show-thread ()
10505   "Show thread subtrees.
10506 Returns nil if no thread was there to be shown."
10507   (interactive)
10508   (let ((buffer-read-only nil)
10509         (orig (point))
10510         (end (gnus-point-at-eol))
10511         ;; Leave point at bol
10512         (beg (progn (beginning-of-line) (point))))
10513     (prog1
10514         ;; Any hidden lines here?
10515         (search-forward "\r" end t)
10516       (subst-char-in-region beg end ?\^M ?\n t)
10517       (goto-char orig)
10518       (gnus-summary-position-point))))
10519
10520 (defun gnus-summary-maybe-hide-threads ()
10521   "If requested, hide the threads that should be hidden."
10522   (when (and gnus-show-threads
10523              gnus-thread-hide-subtree)
10524     (gnus-summary-hide-all-threads
10525      (if (or (consp gnus-thread-hide-subtree)
10526              (functionp gnus-thread-hide-subtree))
10527          (gnus-make-predicate gnus-thread-hide-subtree)
10528        nil))))
10529
10530 ;;; Hiding predicates.
10531
10532 (defun gnus-article-unread-p (header)
10533   (memq (mail-header-number header) gnus-newsgroup-unreads))
10534
10535 (defun gnus-article-unseen-p (header)
10536   (memq (mail-header-number header) gnus-newsgroup-unseen))
10537
10538 (defun gnus-map-articles (predicate articles)
10539   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10540   (apply 'gnus-or (mapcar predicate
10541                           (mapcar 'gnus-summary-article-header articles))))
10542
10543 (defun gnus-summary-hide-all-threads (&optional predicate)
10544   "Hide all thread subtrees.
10545 If PREDICATE is supplied, threads that satisfy this predicate
10546 will not be hidden."
10547   (interactive)
10548   (save-excursion
10549     (goto-char (point-min))
10550     (let ((end nil))
10551       (while (not end)
10552         (when (or (not predicate)
10553                   (gnus-map-articles
10554                    predicate (gnus-summary-article-children)))
10555             (gnus-summary-hide-thread))
10556         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10557   (gnus-summary-position-point))
10558
10559 (defun gnus-summary-hide-thread ()
10560   "Hide thread subtrees.
10561 If PREDICATE is supplied, threads that satisfy this predicate
10562 will not be hidden.
10563 Returns nil if no threads were there to be hidden."
10564   (interactive)
10565   (let ((buffer-read-only nil)
10566         (start (point))
10567         (article (gnus-summary-article-number)))
10568     (goto-char start)
10569     ;; Go forward until either the buffer ends or the subthread
10570     ;; ends.
10571     (when (and (not (eobp))
10572                (or (zerop (gnus-summary-next-thread 1 t))
10573                    (goto-char (point-max))))
10574       (prog1
10575           (if (and (> (point) start)
10576                    (search-backward "\n" start t))
10577               (progn
10578                 (subst-char-in-region start (point) ?\n ?\^M)
10579                 (gnus-summary-goto-subject article))
10580             (goto-char start)
10581             nil)))))
10582
10583 (defun gnus-summary-go-to-next-thread (&optional previous)
10584   "Go to the same level (or less) next thread.
10585 If PREVIOUS is non-nil, go to previous thread instead.
10586 Return the article number moved to, or nil if moving was impossible."
10587   (let ((level (gnus-summary-thread-level))
10588         (way (if previous -1 1))
10589         (beg (point)))
10590     (forward-line way)
10591     (while (and (not (eobp))
10592                 (< level (gnus-summary-thread-level)))
10593       (forward-line way))
10594     (if (eobp)
10595         (progn
10596           (goto-char beg)
10597           nil)
10598       (setq beg (point))
10599       (prog1
10600           (gnus-summary-article-number)
10601         (goto-char beg)))))
10602
10603 (defun gnus-summary-next-thread (n &optional silent)
10604   "Go to the same level next N'th thread.
10605 If N is negative, search backward instead.
10606 Returns the difference between N and the number of skips actually
10607 done.
10608
10609 If SILENT, don't output messages."
10610   (interactive "p")
10611   (let ((backward (< n 0))
10612         (n (abs n)))
10613     (while (and (> n 0)
10614                 (gnus-summary-go-to-next-thread backward))
10615       (decf n))
10616     (unless silent
10617       (gnus-summary-position-point))
10618     (when (and (not silent) (/= 0 n))
10619       (gnus-message 7 "No more threads"))
10620     n))
10621
10622 (defun gnus-summary-prev-thread (n)
10623   "Go to the same level previous N'th thread.
10624 Returns the difference between N and the number of skips actually
10625 done."
10626   (interactive "p")
10627   (gnus-summary-next-thread (- n)))
10628
10629 (defun gnus-summary-go-down-thread ()
10630   "Go down one level in the current thread."
10631   (let ((children (gnus-summary-article-children)))
10632     (when children
10633       (gnus-summary-goto-subject (car children)))))
10634
10635 (defun gnus-summary-go-up-thread ()
10636   "Go up one level in the current thread."
10637   (let ((parent (gnus-summary-article-parent)))
10638     (when parent
10639       (gnus-summary-goto-subject parent))))
10640
10641 (defun gnus-summary-down-thread (n)
10642   "Go down thread N steps.
10643 If N is negative, go up instead.
10644 Returns the difference between N and how many steps down that were
10645 taken."
10646   (interactive "p")
10647   (let ((up (< n 0))
10648         (n (abs n)))
10649     (while (and (> n 0)
10650                 (if up (gnus-summary-go-up-thread)
10651                   (gnus-summary-go-down-thread)))
10652       (setq n (1- n)))
10653     (gnus-summary-position-point)
10654     (when (/= 0 n)
10655       (gnus-message 7 "Can't go further"))
10656     n))
10657
10658 (defun gnus-summary-up-thread (n)
10659   "Go up thread N steps.
10660 If N is negative, go down instead.
10661 Returns the difference between N and how many steps down that were
10662 taken."
10663   (interactive "p")
10664   (gnus-summary-down-thread (- n)))
10665
10666 (defun gnus-summary-top-thread ()
10667   "Go to the top of the thread."
10668   (interactive)
10669   (while (gnus-summary-go-up-thread))
10670   (gnus-summary-article-number))
10671
10672 (defun gnus-summary-kill-thread (&optional unmark)
10673   "Mark articles under current thread as read.
10674 If the prefix argument is positive, remove any kinds of marks.
10675 If the prefix argument is negative, tick articles instead."
10676   (interactive "P")
10677   (when unmark
10678     (setq unmark (prefix-numeric-value unmark)))
10679   (let ((articles (gnus-summary-articles-in-thread)))
10680     (save-excursion
10681       ;; Expand the thread.
10682       (gnus-summary-show-thread)
10683       ;; Mark all the articles.
10684       (while articles
10685         (gnus-summary-goto-subject (car articles))
10686         (cond ((null unmark)
10687                (gnus-summary-mark-article-as-read gnus-killed-mark))
10688               ((> unmark 0)
10689                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10690               (t
10691                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10692         (setq articles (cdr articles))))
10693     ;; Hide killed subtrees.
10694     (and (null unmark)
10695          gnus-thread-hide-killed
10696          (gnus-summary-hide-thread))
10697     ;; If marked as read, go to next unread subject.
10698     (when (null unmark)
10699       ;; Go to next unread subject.
10700       (gnus-summary-next-subject 1 t)))
10701   (gnus-set-mode-line 'summary))
10702
10703 ;; Summary sorting commands
10704
10705 (defun gnus-summary-sort-by-number (&optional reverse)
10706   "Sort the summary buffer by article number.
10707 Argument REVERSE means reverse order."
10708   (interactive "P")
10709   (gnus-summary-sort 'number reverse))
10710
10711 (defun gnus-summary-sort-by-random (&optional reverse)
10712   "Randomize the order in the summary buffer.
10713 Argument REVERSE means to randomize in reverse order."
10714   (interactive "P")
10715   (gnus-summary-sort 'random reverse))
10716
10717 (defun gnus-summary-sort-by-author (&optional reverse)
10718   "Sort the summary buffer by author name alphabetically.
10719 If `case-fold-search' is non-nil, case of letters is ignored.
10720 Argument REVERSE means reverse order."
10721   (interactive "P")
10722   (gnus-summary-sort 'author reverse))
10723
10724 (defun gnus-summary-sort-by-subject (&optional reverse)
10725   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10726 If `case-fold-search' is non-nil, case of letters is ignored.
10727 Argument REVERSE means reverse order."
10728   (interactive "P")
10729   (gnus-summary-sort 'subject reverse))
10730
10731 (defun gnus-summary-sort-by-date (&optional reverse)
10732   "Sort the summary buffer by date.
10733 Argument REVERSE means reverse order."
10734   (interactive "P")
10735   (gnus-summary-sort 'date reverse))
10736
10737 (defun gnus-summary-sort-by-score (&optional reverse)
10738   "Sort the summary buffer by score.
10739 Argument REVERSE means reverse order."
10740   (interactive "P")
10741   (gnus-summary-sort 'score reverse))
10742
10743 (defun gnus-summary-sort-by-lines (&optional reverse)
10744   "Sort the summary buffer by the number of lines.
10745 Argument REVERSE means reverse order."
10746   (interactive "P")
10747   (gnus-summary-sort 'lines reverse))
10748
10749 (defun gnus-summary-sort-by-chars (&optional reverse)
10750   "Sort the summary buffer by article length.
10751 Argument REVERSE means reverse order."
10752   (interactive "P")
10753   (gnus-summary-sort 'chars reverse))
10754
10755 (defun gnus-summary-sort-by-original (&optional reverse)
10756   "Sort the summary buffer using the default sorting method.
10757 Argument REVERSE means reverse order."
10758   (interactive "P")
10759   (let* ((buffer-read-only)
10760          (gnus-summary-prepare-hook nil))
10761     ;; We do the sorting by regenerating the threads.
10762     (gnus-summary-prepare)
10763     ;; Hide subthreads if needed.
10764     (gnus-summary-maybe-hide-threads)))
10765
10766 (defun gnus-summary-sort (predicate reverse)
10767   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10768   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10769          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10770          (gnus-thread-sort-functions
10771           (if (not reverse)
10772               thread
10773             `(lambda (t1 t2)
10774                (,thread t2 t1))))
10775          (gnus-sort-gathered-threads-function
10776           gnus-thread-sort-functions)
10777          (gnus-article-sort-functions
10778           (if (not reverse)
10779               article
10780             `(lambda (t1 t2)
10781                (,article t2 t1))))
10782          (buffer-read-only)
10783          (gnus-summary-prepare-hook nil))
10784     ;; We do the sorting by regenerating the threads.
10785     (gnus-summary-prepare)
10786     ;; Hide subthreads if needed.
10787     (gnus-summary-maybe-hide-threads)))
10788
10789 ;; Summary saving commands.
10790
10791 (defun gnus-summary-save-article (&optional n not-saved)
10792   "Save the current article using the default saver function.
10793 If N is a positive number, save the N next articles.
10794 If N is a negative number, save the N previous articles.
10795 If N is nil and any articles have been marked with the process mark,
10796 save those articles instead.
10797 The variable `gnus-default-article-saver' specifies the saver function."
10798   (interactive "P")
10799   (let* ((articles (gnus-summary-work-articles n))
10800          (save-buffer (save-excursion
10801                         (nnheader-set-temp-buffer " *Gnus Save*")))
10802          (num (length articles))
10803          header file)
10804     (dolist (article articles)
10805       (setq header (gnus-summary-article-header article))
10806       (if (not (vectorp header))
10807           ;; This is a pseudo-article.
10808           (if (assq 'name header)
10809               (gnus-copy-file (cdr (assq 'name header)))
10810             (gnus-message 1 "Article %d is unsaveable" article))
10811         ;; This is a real article.
10812         (save-window-excursion
10813           (let ((gnus-display-mime-function nil)
10814                 (gnus-article-prepare-hook nil))
10815             (gnus-summary-select-article t nil nil article)))
10816         (save-excursion
10817           (set-buffer save-buffer)
10818           (erase-buffer)
10819           (insert-buffer-substring gnus-original-article-buffer))
10820         (setq file (gnus-article-save save-buffer file num))
10821         (gnus-summary-remove-process-mark article)
10822         (unless not-saved
10823           (gnus-summary-set-saved-mark article))))
10824     (gnus-kill-buffer save-buffer)
10825     (gnus-summary-position-point)
10826     (gnus-set-mode-line 'summary)
10827     n))
10828
10829 (defun gnus-summary-pipe-output (&optional arg headers)
10830   "Pipe the current article to a subprocess.
10831 If N is a positive number, pipe the N next articles.
10832 If N is a negative number, pipe the N previous articles.
10833 If N is nil and any articles have been marked with the process mark,
10834 pipe those articles instead.
10835 If HEADERS (the symbolic prefix), include the headers, too."
10836   (interactive (gnus-interactive "P\ny"))
10837   (require 'gnus-art)
10838   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10839         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10840     (gnus-summary-save-article arg t))
10841   (let ((buffer (get-buffer "*Shell Command Output*")))
10842     (when (and buffer
10843                (not (zerop (buffer-size buffer))))
10844       (gnus-configure-windows 'pipe))))
10845
10846 (defun gnus-summary-save-article-mail (&optional arg)
10847   "Append the current article to an mail file.
10848 If N is a positive number, save the N next articles.
10849 If N is a negative number, save the N previous articles.
10850 If N is nil and any articles have been marked with the process mark,
10851 save those articles instead."
10852   (interactive "P")
10853   (require 'gnus-art)
10854   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10855     (gnus-summary-save-article arg)))
10856
10857 (defun gnus-summary-save-article-rmail (&optional arg)
10858   "Append the current article to an rmail file.
10859 If N is a positive number, save the N next articles.
10860 If N is a negative number, save the N previous articles.
10861 If N is nil and any articles have been marked with the process mark,
10862 save those articles instead."
10863   (interactive "P")
10864   (require 'gnus-art)
10865   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10866     (gnus-summary-save-article arg)))
10867
10868 (defun gnus-summary-save-article-file (&optional arg)
10869   "Append the current article to a file.
10870 If N is a positive number, save the N next articles.
10871 If N is a negative number, save the N previous articles.
10872 If N is nil and any articles have been marked with the process mark,
10873 save those articles instead."
10874   (interactive "P")
10875   (require 'gnus-art)
10876   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10877     (gnus-summary-save-article arg)))
10878
10879 (defun gnus-summary-write-article-file (&optional arg)
10880   "Write the current article to a file, deleting the previous file.
10881 If N is a positive number, save the N next articles.
10882 If N is a negative number, save the N previous articles.
10883 If N is nil and any articles have been marked with the process mark,
10884 save those articles instead."
10885   (interactive "P")
10886   (require 'gnus-art)
10887   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10888     (gnus-summary-save-article arg)))
10889
10890 (defun gnus-summary-save-article-body-file (&optional arg)
10891   "Append the current article body to a file.
10892 If N is a positive number, save the N next articles.
10893 If N is a negative number, save the N previous articles.
10894 If N is nil and any articles have been marked with the process mark,
10895 save those articles instead."
10896   (interactive "P")
10897   (require 'gnus-art)
10898   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10899     (gnus-summary-save-article arg)))
10900
10901 (defun gnus-summary-muttprint (&optional arg)
10902   "Print the current article using Muttprint.
10903 If N is a positive number, save the N next articles.
10904 If N is a negative number, save the N previous articles.
10905 If N is nil and any articles have been marked with the process mark,
10906 save those articles instead."
10907   (interactive "P")
10908   (require 'gnus-art)
10909   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10910     (gnus-summary-save-article arg t)))
10911
10912 (defun gnus-summary-pipe-message (program)
10913   "Pipe the current article through PROGRAM."
10914   (interactive "sProgram: ")
10915   (gnus-summary-select-article)
10916   (let ((mail-header-separator ""))
10917     (gnus-eval-in-buffer-window gnus-article-buffer
10918       (save-restriction
10919         (widen)
10920         (let ((start (window-start))
10921               buffer-read-only)
10922           (message-pipe-buffer-body program)
10923           (set-window-start (get-buffer-window (current-buffer)) start))))))
10924
10925 (defun gnus-get-split-value (methods)
10926   "Return a value based on the split METHODS."
10927   (let (split-name method result match)
10928     (when methods
10929       (save-excursion
10930         (set-buffer gnus-original-article-buffer)
10931         (save-restriction
10932           (nnheader-narrow-to-headers)
10933           (while (and methods (not split-name))
10934             (goto-char (point-min))
10935             (setq method (pop methods))
10936             (setq match (car method))
10937             (when (cond
10938                    ((stringp match)
10939                     ;; Regular expression.
10940                     (ignore-errors
10941                       (re-search-forward match nil t)))
10942                    ((functionp match)
10943                     ;; Function.
10944                     (save-restriction
10945                       (widen)
10946                       (setq result (funcall match gnus-newsgroup-name))))
10947                    ((consp match)
10948                     ;; Form.
10949                     (save-restriction
10950                       (widen)
10951                       (setq result (eval match)))))
10952               (setq split-name (cdr method))
10953               (cond ((stringp result)
10954                      (push (expand-file-name
10955                             result gnus-article-save-directory)
10956                            split-name))
10957                     ((consp result)
10958                      (setq split-name (append result split-name)))))))))
10959     (nreverse split-name)))
10960
10961 (defun gnus-valid-move-group-p (group)
10962   (and (boundp group)
10963        (symbol-name group)
10964        (symbol-value group)
10965        (gnus-get-function (gnus-find-method-for-group
10966                            (symbol-name group)) 'request-accept-article t)))
10967
10968 (defun gnus-read-move-group-name (prompt default articles prefix)
10969   "Read a group name."
10970   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10971          (minibuffer-confirm-incomplete nil) ; XEmacs
10972          (prom
10973           (format "%s %s to:"
10974                   prompt
10975                   (if (> (length articles) 1)
10976                       (format "these %d articles" (length articles))
10977                     "this article")))
10978          (to-newsgroup
10979           (cond
10980            ((null split-name)
10981             (gnus-completing-read-with-default
10982              default prom
10983              gnus-active-hashtb
10984              'gnus-valid-move-group-p
10985              nil prefix
10986              'gnus-group-history))
10987            ((= 1 (length split-name))
10988             (gnus-completing-read-with-default
10989              (car split-name) prom
10990              gnus-active-hashtb
10991              'gnus-valid-move-group-p
10992              nil nil
10993              'gnus-group-history))
10994            (t
10995             (gnus-completing-read-with-default
10996              nil prom
10997              (mapcar (lambda (el) (list el))
10998                      (nreverse split-name))
10999              nil nil nil
11000              'gnus-group-history))))
11001          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11002     (when to-newsgroup
11003       (if (or (string= to-newsgroup "")
11004               (string= to-newsgroup prefix))
11005           (setq to-newsgroup default))
11006       (unless to-newsgroup
11007         (error "No group name entered"))
11008       (or (gnus-active to-newsgroup)
11009           (gnus-activate-group to-newsgroup nil nil to-method)
11010           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11011                                      to-newsgroup))
11012               (or (and (gnus-request-create-group to-newsgroup to-method)
11013                        (gnus-activate-group
11014                         to-newsgroup nil nil to-method)
11015                        (gnus-subscribe-group to-newsgroup))
11016                   (error "Couldn't create group %s" to-newsgroup)))
11017           (error "No such group: %s" to-newsgroup)))
11018     to-newsgroup))
11019
11020 (defun gnus-summary-save-parts (type dir n &optional reverse)
11021   "Save parts matching TYPE to DIR.
11022 If REVERSE, save parts that do not match TYPE."
11023   (interactive
11024    (list (read-string "Save parts of type: "
11025                       (or (car gnus-summary-save-parts-type-history)
11026                           gnus-summary-save-parts-default-mime)
11027                       'gnus-summary-save-parts-type-history)
11028          (setq gnus-summary-save-parts-last-directory
11029                (read-file-name "Save to directory: "
11030                                gnus-summary-save-parts-last-directory
11031                                nil t))
11032          current-prefix-arg))
11033   (gnus-summary-iterate n
11034     (let ((gnus-display-mime-function nil)
11035           (gnus-inhibit-treatment t))
11036       (gnus-summary-select-article))
11037     (save-excursion
11038       (set-buffer gnus-article-buffer)
11039       (let ((handles (or gnus-article-mime-handles
11040                          (mm-dissect-buffer nil gnus-article-loose-mime)
11041                          (and gnus-article-emulate-mime
11042                               (mm-uu-dissect)))))
11043         (when handles
11044           (gnus-summary-save-parts-1 type dir handles reverse)
11045           (unless gnus-article-mime-handles ;; Don't destroy this case.
11046             (mm-destroy-parts handles)))))))
11047
11048 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11049   (if (stringp (car handle))
11050       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11051               (cdr handle))
11052     (when (if reverse
11053               (not (string-match type (mm-handle-media-type handle)))
11054             (string-match type (mm-handle-media-type handle)))
11055       (let ((file (expand-file-name
11056                    (file-name-nondirectory
11057                     (or
11058                      (mail-content-type-get
11059                       (mm-handle-disposition handle) 'filename)
11060                      (concat gnus-newsgroup-name
11061                              "." (number-to-string
11062                                   (cdr gnus-article-current)))))
11063                    dir)))
11064         (unless (file-exists-p file)
11065           (mm-save-part-to-file handle file))))))
11066
11067 ;; Summary extract commands
11068
11069 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11070   (let ((buffer-read-only nil)
11071         (article (gnus-summary-article-number))
11072         after-article b e)
11073     (unless (gnus-summary-goto-subject article)
11074       (error "No such article: %d" article))
11075     (gnus-summary-position-point)
11076     ;; If all commands are to be bunched up on one line, we collect
11077     ;; them here.
11078     (unless gnus-view-pseudos-separately
11079       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11080             files action)
11081         (while ps
11082           (setq action (cdr (assq 'action (car ps))))
11083           (setq files (list (cdr (assq 'name (car ps)))))
11084           (while (and ps (cdr ps)
11085                       (string= (or action "1")
11086                                (or (cdr (assq 'action (cadr ps))) "2")))
11087             (push (cdr (assq 'name (cadr ps))) files)
11088             (setcdr ps (cddr ps)))
11089           (when files
11090             (when (not (string-match "%s" action))
11091               (push " " files))
11092             (push " " files)
11093             (when (assq 'execute (car ps))
11094               (setcdr (assq 'execute (car ps))
11095                       (funcall (if (string-match "%s" action)
11096                                    'format 'concat)
11097                                action
11098                                (mapconcat
11099                                 (lambda (f)
11100                                   (if (equal f " ")
11101                                       f
11102                                     (gnus-quote-arg-for-sh-or-csh f)))
11103                                 files " ")))))
11104           (setq ps (cdr ps)))))
11105     (if (and gnus-view-pseudos (not not-view))
11106         (while pslist
11107           (when (assq 'execute (car pslist))
11108             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11109                                   (eq gnus-view-pseudos 'not-confirm)))
11110           (setq pslist (cdr pslist)))
11111       (save-excursion
11112         (while pslist
11113           (setq after-article (or (cdr (assq 'article (car pslist)))
11114                                   (gnus-summary-article-number)))
11115           (gnus-summary-goto-subject after-article)
11116           (forward-line 1)
11117           (setq b (point))
11118           (insert "    " (file-name-nondirectory
11119                           (cdr (assq 'name (car pslist))))
11120                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11121           (setq e (point))
11122           (forward-line -1)             ; back to `b'
11123           (gnus-add-text-properties
11124            b (1- e) (list 'gnus-number gnus-reffed-article-number
11125                           gnus-mouse-face-prop gnus-mouse-face))
11126           (gnus-data-enter
11127            after-article gnus-reffed-article-number
11128            gnus-unread-mark b (car pslist) 0 (- e b))
11129           (setq gnus-newsgroup-unreads
11130                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11131                                          gnus-reffed-article-number))
11132           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11133           (setq pslist (cdr pslist)))))))
11134
11135 (defun gnus-pseudos< (p1 p2)
11136   (let ((c1 (cdr (assq 'action p1)))
11137         (c2 (cdr (assq 'action p2))))
11138     (and c1 c2 (string< c1 c2))))
11139
11140 (defun gnus-request-pseudo-article (props)
11141   (cond ((assq 'execute props)
11142          (gnus-execute-command (cdr (assq 'execute props)))))
11143   (let ((gnus-current-article (gnus-summary-article-number)))
11144     (gnus-run-hooks 'gnus-mark-article-hook)))
11145
11146 (defun gnus-execute-command (command &optional automatic)
11147   (save-excursion
11148     (gnus-article-setup-buffer)
11149     (set-buffer gnus-article-buffer)
11150     (setq buffer-read-only nil)
11151     (let ((command (if automatic command
11152                      (read-string "Command: " (cons command 0)))))
11153       (erase-buffer)
11154       (insert "$ " command "\n\n")
11155       (if gnus-view-pseudo-asynchronously
11156           (start-process "gnus-execute" (current-buffer) shell-file-name
11157                          shell-command-switch command)
11158         (call-process shell-file-name nil t nil
11159                       shell-command-switch command)))))
11160
11161 ;; Summary kill commands.
11162
11163 (defun gnus-summary-edit-global-kill (article)
11164   "Edit the \"global\" kill file."
11165   (interactive (list (gnus-summary-article-number)))
11166   (gnus-group-edit-global-kill article))
11167
11168 (defun gnus-summary-edit-local-kill ()
11169   "Edit a local kill file applied to the current newsgroup."
11170   (interactive)
11171   (setq gnus-current-headers (gnus-summary-article-header))
11172   (gnus-group-edit-local-kill
11173    (gnus-summary-article-number) gnus-newsgroup-name))
11174
11175 ;;; Header reading.
11176
11177 (defun gnus-read-header (id &optional header)
11178   "Read the headers of article ID and enter them into the Gnus system."
11179   (let ((group gnus-newsgroup-name)
11180         (gnus-override-method
11181          (or
11182           gnus-override-method
11183           (and (gnus-news-group-p gnus-newsgroup-name)
11184                (car (gnus-refer-article-methods)))))
11185         where)
11186     ;; First we check to see whether the header in question is already
11187     ;; fetched.
11188     (if (stringp id)
11189         ;; This is a Message-ID.
11190         (setq header (or header (gnus-id-to-header id)))
11191       ;; This is an article number.
11192       (setq header (or header (gnus-summary-article-header id))))
11193     (if (and header
11194              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11195         ;; We have found the header.
11196         header
11197       ;; If this is a sparse article, we have to nix out its
11198       ;; previous entry in the thread hashtb.
11199       (when (and header
11200                  (gnus-summary-article-sparse-p (mail-header-number header)))
11201         (let* ((parent (gnus-parent-id (mail-header-references header)))
11202                (thread (and parent (gnus-id-to-thread parent))))
11203           (when thread
11204             (delq (assq header thread) thread))))
11205       ;; We have to really fetch the header to this article.
11206       (save-excursion
11207         (set-buffer nntp-server-buffer)
11208         (when (setq where (gnus-request-head id group))
11209           (nnheader-fold-continuation-lines)
11210           (goto-char (point-max))
11211           (insert ".\n")
11212           (goto-char (point-min))
11213           (insert "211 ")
11214           (princ (cond
11215                   ((numberp id) id)
11216                   ((cdr where) (cdr where))
11217                   (header (mail-header-number header))
11218                   (t gnus-reffed-article-number))
11219                  (current-buffer))
11220           (insert " Article retrieved.\n"))
11221         (if (or (not where)
11222                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11223             ()                          ; Malformed head.
11224           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11225             (when (and (stringp id)
11226                        (not (string= (gnus-group-real-name group)
11227                                      (car where))))
11228               ;; If we fetched by Message-ID and the article came
11229               ;; from a different group, we fudge some bogus article
11230               ;; numbers for this article.
11231               (mail-header-set-number header gnus-reffed-article-number))
11232             (save-excursion
11233               (set-buffer gnus-summary-buffer)
11234               (decf gnus-reffed-article-number)
11235               (gnus-remove-header (mail-header-number header))
11236               (push header gnus-newsgroup-headers)
11237               (setq gnus-current-headers header)
11238               (push (mail-header-number header) gnus-newsgroup-limit)))
11239           header)))))
11240
11241 (defun gnus-remove-header (number)
11242   "Remove header NUMBER from `gnus-newsgroup-headers'."
11243   (if (and gnus-newsgroup-headers
11244            (= number (mail-header-number (car gnus-newsgroup-headers))))
11245       (pop gnus-newsgroup-headers)
11246     (let ((headers gnus-newsgroup-headers))
11247       (while (and (cdr headers)
11248                   (not (= number (mail-header-number (cadr headers)))))
11249         (pop headers))
11250       (when (cdr headers)
11251         (setcdr headers (cddr headers))))))
11252
11253 ;;;
11254 ;;; summary highlights
11255 ;;;
11256
11257 (defun gnus-highlight-selected-summary ()
11258   "Highlight selected article in summary buffer."
11259   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11260   (when gnus-summary-selected-face
11261     (save-excursion
11262       (let* ((beg (gnus-point-at-bol))
11263              (end (gnus-point-at-eol))
11264              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11265              (from (if (get-text-property beg gnus-mouse-face-prop)
11266                        beg
11267                      (or (next-single-property-change
11268                           beg gnus-mouse-face-prop nil end)
11269                          beg)))
11270              (to
11271               (if (= from end)
11272                   (- from 2)
11273                 (or (next-single-property-change
11274                      from gnus-mouse-face-prop nil end)
11275                     end))))
11276         ;; If no mouse-face prop on line we will have to = from = end,
11277         ;; so we highlight the entire line instead.
11278         (when (= (+ to 2) from)
11279           (setq from beg)
11280           (setq to end))
11281         (if gnus-newsgroup-selected-overlay
11282             ;; Move old overlay.
11283             (gnus-move-overlay
11284              gnus-newsgroup-selected-overlay from to (current-buffer))
11285           ;; Create new overlay.
11286           (gnus-overlay-put
11287            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11288            'face gnus-summary-selected-face))))))
11289
11290 (defvar gnus-summary-highlight-line-cached nil)
11291 (defvar gnus-summary-highlight-line-trigger nil)
11292
11293 (defun gnus-summary-highlight-line-0 ()
11294   (if (and (eq gnus-summary-highlight-line-trigger 
11295                gnus-summary-highlight)
11296            gnus-summary-highlight-line-cached)
11297       gnus-summary-highlight-line-cached
11298     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11299           gnus-summary-highlight-line-cached
11300           (let* ((cond (list 'cond))
11301                  (c cond)
11302                  (list gnus-summary-highlight))
11303             (while list
11304               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11305                               nil))
11306               (setq c (cdr c)
11307                     list (cdr list)))
11308             (gnus-byte-compile (list 'lambda nil cond))))))
11309
11310 (defun gnus-summary-highlight-line ()
11311   "Highlight current line according to `gnus-summary-highlight'."
11312   (let* ((beg (gnus-point-at-bol))
11313          (article (or (gnus-summary-article-number) gnus-current-article))
11314          (score (or (cdr (assq article
11315                                gnus-newsgroup-scored))
11316                     gnus-summary-default-score 0))
11317          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11318          (inhibit-read-only t)
11319          (default gnus-summary-default-score)
11320          (default-high gnus-summary-default-high-score)
11321          (default-low gnus-summary-default-low-score)
11322          (uncached (and gnus-summary-use-undownloaded-faces
11323                         (memq article gnus-newsgroup-undownloaded))))
11324     (let ((face (funcall (gnus-summary-highlight-line-0))))
11325       (unless (eq face (get-text-property beg 'face))
11326         (gnus-put-text-property-excluding-characters-with-faces
11327          beg (gnus-point-at-eol) 'face
11328          (setq face (if (boundp face) (symbol-value face) face)))
11329         (when gnus-summary-highlight-line-function
11330           (funcall gnus-summary-highlight-line-function article face))))))
11331
11332 (defun gnus-update-read-articles (group unread &optional compute)
11333   "Update the list of read articles in GROUP.
11334 UNREAD is a sorted list."
11335   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
11336          (entry (gnus-gethash group gnus-newsrc-hashtb))
11337          (info (nth 2 entry))
11338          (prev 1)
11339          read)
11340     (if (or (not info) (not active))
11341         ;; There is no info on this group if it was, in fact,
11342         ;; killed.  Gnus stores no information on killed groups, so
11343         ;; there's nothing to be done.
11344         ;; One could store the information somewhere temporarily,
11345         ;; perhaps...  Hmmm...
11346         ()
11347       ;; Remove any negative articles numbers.
11348       (while (and unread (< (car unread) 0))
11349         (setq unread (cdr unread)))
11350       ;; Remove any expired article numbers
11351       (while (and unread (< (car unread) (car active)))
11352         (setq unread (cdr unread)))
11353       ;; Compute the ranges of read articles by looking at the list of
11354       ;; unread articles.
11355       (while unread
11356         (when (/= (car unread) prev)
11357           (push (if (= prev (1- (car unread))) prev
11358                   (cons prev (1- (car unread))))
11359                 read))
11360         (setq prev (1+ (car unread)))
11361         (setq unread (cdr unread)))
11362       (when (<= prev (cdr active))
11363         (push (cons prev (cdr active)) read))
11364       (setq read (if (> (length read) 1) (nreverse read) read))
11365       (if compute
11366           read
11367         (save-excursion
11368           (let (setmarkundo)
11369             ;; Propagate the read marks to the backend.
11370             (when (gnus-check-backend-function 'request-set-mark group)
11371               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11372                     (add (gnus-remove-from-range read (gnus-info-read info))))
11373                 (when (or add del)
11374                   (unless (gnus-check-group group)
11375                     (error "Can't open server for %s" group))
11376                   (gnus-request-set-mark
11377                    group (delq nil (list (if add (list add 'add '(read)))
11378                                          (if del (list del 'del '(read))))))
11379                   (setq setmarkundo
11380                         `(gnus-request-set-mark
11381                           ,group
11382                           ',(delq nil (list
11383                                        (if del (list del 'add '(read)))
11384                                        (if add (list add 'del '(read))))))))))
11385             (set-buffer gnus-group-buffer)
11386             (gnus-undo-register
11387               `(progn
11388                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11389                  (gnus-info-set-read ',info ',(gnus-info-read info))
11390                  (gnus-get-unread-articles-in-group ',info
11391                                                     (gnus-active ,group))
11392                  (gnus-group-update-group ,group t)
11393                  ,setmarkundo))))
11394         ;; Enter this list into the group info.
11395         (gnus-info-set-read info read)
11396         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11397         (gnus-get-unread-articles-in-group info (gnus-active group))
11398         t))))
11399
11400 (defun gnus-offer-save-summaries ()
11401   "Offer to save all active summary buffers."
11402   (let (buffers)
11403     ;; Go through all buffers and find all summaries.
11404     (dolist (buffer (buffer-list))
11405       (when (and (setq buffer (buffer-name buffer))
11406                  (string-match "Summary" buffer)
11407                  (save-excursion
11408                    (set-buffer buffer)
11409                    ;; We check that this is, indeed, a summary buffer.
11410                    (and (eq major-mode 'gnus-summary-mode)
11411                         ;; Also make sure this isn't bogus.
11412                         gnus-newsgroup-prepared
11413                         ;; Also make sure that this isn't a
11414                         ;; dead summary buffer.
11415                         (not gnus-dead-summary-mode))))
11416         (push buffer buffers)))
11417     ;; Go through all these summary buffers and offer to save them.
11418     (when buffers
11419       (save-excursion
11420         (map-y-or-n-p
11421          "Update summary buffer %s? "
11422          (lambda (buf)
11423            (switch-to-buffer buf)
11424            (gnus-summary-exit))
11425          buffers)))))
11426
11427
11428 ;;; @ for mime-partial
11429 ;;;
11430
11431 (defun gnus-request-partial-message ()
11432   (save-excursion
11433     (let ((number (gnus-summary-article-number))
11434           (group gnus-newsgroup-name)
11435           (mother gnus-article-buffer))
11436       (set-buffer (get-buffer-create " *Partial Article*"))
11437       (erase-buffer)
11438       (setq mime-preview-buffer mother)
11439       (gnus-request-article-this-buffer number group)
11440       (mime-parse-buffer)
11441       )))
11442
11443 (autoload 'mime-combine-message/partial-pieces-automatically
11444   "mime-partial"
11445   "Internal method to combine message/partial messages automatically.")
11446
11447 (mime-add-condition
11448  'action '((type . message)(subtype . partial)
11449            (major-mode . gnus-original-article-mode)
11450            (method . mime-combine-message/partial-pieces-automatically)
11451            (summary-buffer-exp . gnus-summary-buffer)
11452            (request-partial-message-method . gnus-request-partial-message)
11453            ))
11454
11455
11456 ;;; @ for message/rfc822
11457 ;;;
11458
11459 (defun gnus-mime-extract-message/rfc822 (entity situation)
11460   "Burst a forwarded article."
11461   (save-excursion
11462     (set-buffer gnus-summary-buffer)
11463     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11464                                    gnus-newsgroup-name 'gnus-group-history))
11465            (gnus-group-marked (list group))
11466            article info)
11467       (with-temp-buffer
11468         (mime-insert-entity-content entity)
11469         (setq article (gnus-request-accept-article group)))
11470       (when (and (consp article)
11471                  (numberp (setq article (cdr article))))
11472         (setq info (gnus-get-info group))
11473         (gnus-info-set-read info
11474                             (gnus-remove-from-range (gnus-info-read info)
11475                                                     (list article)))
11476         (when (string-equal group gnus-newsgroup-name)
11477           (forward-line 1)
11478           (let (gnus-show-threads)
11479             (gnus-summary-goto-subject article t))
11480           (gnus-summary-clear-mark-forward 1))
11481         (set-buffer gnus-group-buffer)
11482         (gnus-group-get-new-news-this-group nil t)))))
11483
11484 (mime-add-condition
11485  'action '((type . message)(subtype . rfc822)
11486            (major-mode . gnus-original-article-mode)
11487            (method . gnus-mime-extract-message/rfc822)
11488            (mode . "extract")
11489            ))
11490
11491 (mime-add-condition
11492  'action '((type . message)(subtype . news)
11493            (major-mode . gnus-original-article-mode)
11494            (method . gnus-mime-extract-message/rfc822)
11495            (mode . "extract")
11496            ))
11497
11498 (defun gnus-mime-extract-multipart (entity situation)
11499   (let ((children (mime-entity-children entity))
11500         mime-acting-situation-to-override
11501         f)
11502     (while children
11503       (mime-play-entity (car children)
11504                         (cons (assq 'mode situation)
11505                               mime-acting-situation-to-override))
11506       (setq children (cdr children)))
11507     (if (setq f (cdr (assq 'after-method
11508                            mime-acting-situation-to-override)))
11509         (eval f)
11510       )))
11511
11512 (mime-add-condition
11513  'action '((type . multipart)
11514            (method . gnus-mime-extract-multipart)
11515            (mode . "extract")
11516            )
11517  'with-default)
11518
11519
11520 ;;; @ end
11521 ;;;
11522
11523 (defun gnus-summary-inherit-default-charset ()
11524   "Import `default-mime-charset' from summary buffer.
11525 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11526 of FLIM is used."
11527   (if (buffer-live-p gnus-summary-buffer)
11528       (let (d-m-c d-m-c-u)
11529         (with-current-buffer gnus-summary-buffer
11530           (setq d-m-c (if (local-variable-p 'default-mime-charset
11531                                             gnus-summary-buffer)
11532                           default-mime-charset
11533                         t)
11534                 ;; LIMIT
11535                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11536                                               gnus-summary-buffer)
11537                             (symbol-value 'default-mime-charset-unlimited)
11538                           t)))
11539         (if (eq t d-m-c)
11540             (kill-local-variable 'default-mime-charset)
11541           (set (make-local-variable 'default-mime-charset) d-m-c))
11542         (if (eq t d-m-c-u)
11543             (kill-local-variable 'default-mime-charset-unlimited)
11544           (set (make-local-variable 'default-mime-charset-unlimited)
11545                d-m-c-u)))))
11546
11547 (defun gnus-summary-setup-default-charset ()
11548   "Setup newsgroup default charset."
11549   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11550       (progn
11551         (setq gnus-newsgroup-charset nil)
11552         (set (make-local-variable 'default-mime-charset) nil)
11553         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11554           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11555     (let ((ignored-charsets
11556            (or gnus-newsgroup-ephemeral-ignored-charsets
11557                (append
11558                 (and gnus-newsgroup-name
11559                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11560                 gnus-newsgroup-ignored-charsets)))
11561           charset)
11562       (setq gnus-newsgroup-charset
11563             (or gnus-newsgroup-ephemeral-charset
11564                 (when (and gnus-newsgroup-name
11565                            (setq charset (gnus-parameter-charset
11566                                           gnus-newsgroup-name)))
11567                   (make-local-variable 'default-mime-charset)
11568                   (setq default-mime-charset charset))
11569                 gnus-default-charset))
11570       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11571            ignored-charsets))))
11572
11573 ;;;
11574 ;;; Mime Commands
11575 ;;;
11576
11577 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11578   "Display the current article buffer fully MIME-buttonized.
11579 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11580 treated as multipart/mixed."
11581   (interactive "P")
11582   (require 'gnus-art)
11583   (let ((gnus-unbuttonized-mime-types nil)
11584         (gnus-mime-display-multipart-as-mixed show-all-parts))
11585     (gnus-summary-show-article)))
11586
11587 (defun gnus-summary-repair-multipart (article)
11588   "Add a Content-Type header to a multipart article without one."
11589   (interactive (list (gnus-summary-article-number)))
11590   (gnus-with-article article
11591     (message-narrow-to-head)
11592     (message-remove-header "Mime-Version")
11593     (goto-char (point-max))
11594     (insert "Mime-Version: 1.0\n")
11595     (widen)
11596     (when (search-forward "\n--" nil t)
11597       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11598         (message-narrow-to-head)
11599         (message-remove-header "Content-Type")
11600         (goto-char (point-max))
11601         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11602                         separator))
11603         (widen))))
11604   (let (gnus-mark-article-hook)
11605     (gnus-summary-select-article t t nil article)))
11606
11607 (defun gnus-summary-toggle-display-buttonized ()
11608   "Toggle the buttonizing of the article buffer."
11609   (interactive)
11610   (require 'gnus-art)
11611   (if (setq gnus-inhibit-mime-unbuttonizing
11612             (not gnus-inhibit-mime-unbuttonizing))
11613       (let ((gnus-unbuttonized-mime-types nil))
11614         (gnus-summary-show-article))
11615     (gnus-summary-show-article)))
11616
11617 ;;;
11618 ;;; Intelli-mouse commmands
11619 ;;;
11620
11621 (defun gnus-wheel-summary-scroll (event)
11622   (interactive "e")
11623   (let ((amount (if (memq 'shift (event-modifiers event))
11624                     (car gnus-wheel-scroll-amount)
11625                   (cdr gnus-wheel-scroll-amount)))
11626         (direction (- (* (static-if (featurep 'xemacs)
11627                              (event-button event)
11628                            (cond ((eq 'mouse-4 (event-basic-type event))
11629                                   4)
11630                                  ((eq 'mouse-5 (event-basic-type event))
11631                                   5)))
11632                          2) 9))
11633         edge)
11634     (gnus-summary-scroll-up (* amount direction))
11635     (when (gnus-eval-in-buffer-window gnus-article-buffer
11636             (save-restriction
11637               (widen)
11638               (and (if (< 0 direction)
11639                        (gnus-article-next-page 0)
11640                      (gnus-article-prev-page 0)
11641                      (bobp))
11642                    (if (setq edge (get-text-property
11643                                    (point-min) 'gnus-wheel-edge))
11644                        (setq edge (* edge direction))
11645                      (setq edge -1))
11646                    (or (plusp edge)
11647                        (let ((buffer-read-only nil)
11648                              (inhibit-read-only t))
11649                          (put-text-property (point-min) (point-max)
11650                                             'gnus-wheel-edge direction)
11651                          nil))
11652                    (or (> edge gnus-wheel-edge-resistance)
11653                        (let ((buffer-read-only nil)
11654                              (inhibit-read-only t))
11655                          (put-text-property (point-min) (point-max)
11656                                             'gnus-wheel-edge
11657                                             (* (1+ edge) direction))
11658                          nil))
11659                    (eq last-command 'gnus-wheel-summary-scroll))))
11660       (gnus-summary-next-article nil nil (minusp direction)))))
11661
11662 (defun gnus-wheel-install ()
11663   "Enable mouse wheel support on summary window."
11664   (when gnus-use-wheel
11665     (let ((keys
11666            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11667       (dolist (key keys)
11668         (define-key gnus-summary-mode-map key
11669           'gnus-wheel-summary-scroll)))))
11670
11671 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11672
11673 ;;;
11674 ;;; Traditional PGP commmands
11675 ;;;
11676
11677 (defun gnus-summary-decrypt-article (&optional force)
11678   "Decrypt the current article in traditional PGP way.
11679 This will have permanent effect only in mail groups.
11680 If FORCE is non-nil, allow editing of articles even in read-only
11681 groups."
11682   (interactive "P")
11683   (gnus-summary-select-article t)
11684   (gnus-eval-in-buffer-window gnus-article-buffer
11685     (save-excursion
11686       (save-restriction
11687         (widen)
11688         (goto-char (point-min))
11689         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11690           (error "Not a traditional PGP message!"))
11691         (let ((armor-start (match-beginning 0)))
11692           (if (and (pgg-decrypt-region armor-start (point-max))
11693                    (or force (not (gnus-group-read-only-p))))
11694               (let ((inhibit-read-only t)
11695                     buffer-read-only)
11696                 (delete-region armor-start
11697                                (progn
11698                                  (re-search-forward "^-+END PGP" nil t)
11699                                  (beginning-of-line 2)
11700                                  (point)))
11701                 (insert-buffer-substring pgg-output-buffer))))))))
11702
11703 (defun gnus-summary-verify-article ()
11704   "Verify the current article in traditional PGP way."
11705   (interactive)
11706   (save-excursion
11707     (set-buffer gnus-original-article-buffer)
11708     (goto-char (point-min))
11709     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11710       (error "Not a traditional PGP message!"))
11711     (re-search-forward "^-+END PGP" nil t)
11712     (beginning-of-line 2)
11713     (call-interactively (function pgg-verify-region))))
11714
11715 ;;;
11716 ;;; Generic summary marking commands
11717 ;;;
11718
11719 (defvar gnus-summary-marking-alist
11720   '((read gnus-del-mark "d")
11721     (unread gnus-unread-mark "u")
11722     (ticked gnus-ticked-mark "!")
11723     (dormant gnus-dormant-mark "?")
11724     (expirable gnus-expirable-mark "e"))
11725   "An alist of names/marks/keystrokes.")
11726
11727 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11728 (defvar gnus-summary-mark-map)
11729
11730 (defun gnus-summary-make-all-marking-commands ()
11731   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11732   (dolist (elem gnus-summary-marking-alist)
11733     (apply 'gnus-summary-make-marking-command elem)))
11734
11735 (defun gnus-summary-make-marking-command (name mark keystroke)
11736   (let ((map (make-sparse-keymap)))
11737     (define-key gnus-summary-generic-mark-map keystroke map)
11738     (dolist (lway `((next "next" next nil "n")
11739                     (next-unread "next unread" next t "N")
11740                     (prev "previous" prev nil "p")
11741                     (prev-unread "previous unread" prev t "P")
11742                     (nomove "" nil nil ,keystroke)))
11743       (let ((func (gnus-summary-make-marking-command-1
11744                    mark (car lway) lway name)))
11745         (setq func (eval func))
11746         (define-key map (nth 4 lway) func)))))
11747
11748 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11749   `(defun ,(intern
11750             (format "gnus-summary-put-mark-as-%s%s"
11751                     name (if (eq way 'nomove)
11752                              ""
11753                            (concat "-" (symbol-name way)))))
11754      (n)
11755      ,(format
11756        "Mark the current article as %s%s.
11757 If N, the prefix, then repeat N times.
11758 If N is negative, move in reverse order.
11759 The difference between N and the actual number of articles marked is
11760 returned."
11761        name (car (cdr lway)))
11762      (interactive "p")
11763      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11764
11765 (defun gnus-summary-generic-mark (n mark move unread)
11766   "Mark N articles with MARK."
11767   (unless (eq major-mode 'gnus-summary-mode)
11768     (error "This command can only be used in the summary buffer"))
11769   (gnus-summary-show-thread)
11770   (let ((nummove
11771          (cond
11772           ((eq move 'next) 1)
11773           ((eq move 'prev) -1)
11774           (t 0))))
11775     (if (zerop nummove)
11776         (setq n 1)
11777       (when (< n 0)
11778         (setq n (abs n)
11779               nummove (* -1 nummove))))
11780     (while (and (> n 0)
11781                 (gnus-summary-mark-article nil mark)
11782                 (zerop (gnus-summary-next-subject nummove unread t)))
11783       (setq n (1- n)))
11784     (when (/= 0 n)
11785       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11786     (gnus-summary-recenter)
11787     (gnus-summary-position-point)
11788     (gnus-set-mode-line 'summary)
11789     n))
11790
11791 (defun gnus-summary-insert-articles (articles)
11792   (when (setq articles
11793               (gnus-sorted-difference articles
11794                                       (mapcar (lambda (h)
11795                                                 (mail-header-number h))
11796                                               gnus-newsgroup-headers)))
11797     (setq gnus-newsgroup-headers
11798           (gnus-merge 'list
11799                       gnus-newsgroup-headers
11800                       (gnus-fetch-headers articles)
11801                       'gnus-article-sort-by-number))
11802     ;; Suppress duplicates?
11803     (when gnus-suppress-duplicates
11804       (gnus-dup-suppress-articles))
11805
11806     ;; We might want to build some more threads first.
11807     (when (and gnus-fetch-old-headers
11808                (eq gnus-headers-retrieved-by 'nov))
11809       (if (eq gnus-fetch-old-headers 'invisible)
11810           (gnus-build-all-threads)
11811         (gnus-build-old-threads)))
11812     ;; Let the Gnus agent mark articles as read.
11813     (when gnus-agent
11814       (gnus-agent-get-undownloaded-list))
11815     ;; Remove list identifiers from subject
11816     (when gnus-list-identifiers
11817       (gnus-summary-remove-list-identifiers))
11818     ;; First and last article in this newsgroup.
11819     (when gnus-newsgroup-headers
11820       (setq gnus-newsgroup-begin
11821             (mail-header-number (car gnus-newsgroup-headers))
11822             gnus-newsgroup-end
11823             (mail-header-number
11824              (gnus-last-element gnus-newsgroup-headers))))
11825     (when gnus-use-scoring
11826       (gnus-possibly-score-headers))))
11827
11828 (defun gnus-summary-insert-old-articles (&optional all)
11829   "Insert all old articles in this group.
11830 If ALL is non-nil, already read articles become readable.
11831 If ALL is a number, fetch this number of articles."
11832   (interactive "P")
11833   (prog1
11834       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11835             older len)
11836         (setq older
11837               ;; Some nntp servers lie about their active range.  When
11838               ;; this happens, the active range can be in the millions.
11839               ;; Use a compressed range to avoid creating a huge list.
11840               (gnus-range-difference (list gnus-newsgroup-active) old))
11841         (setq len (gnus-range-length older))
11842         (cond
11843          ((null older) nil)
11844          ((numberp all)
11845           (if (< all len)
11846               (let ((older-range (nreverse older)))
11847                 (setq older nil)
11848
11849                 (while (> all 0)
11850                   (let* ((r (pop older-range))
11851                          (min (if (numberp r) r (car r)))
11852                          (max (if (numberp r) r (cdr r))))
11853                     (while (and (<= min max)
11854                                 (> all 0))
11855                       (push max older)
11856                       (setq all (1- all)
11857                             max (1- max))))))
11858             (setq older (gnus-uncompress-range older))))
11859          (all
11860           (setq older (gnus-uncompress-range older)))
11861          (t
11862           (when (and (numberp gnus-large-newsgroup)
11863                    (> len gnus-large-newsgroup))
11864               (let* ((cursor-in-echo-area nil)
11865                      (initial (gnus-parameter-large-newsgroup-initial
11866                                gnus-newsgroup-name))
11867                      (input
11868                       (read-string
11869                        (format
11870                         "How many articles from %s (%s %d): "
11871                         (gnus-limit-string
11872                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11873                         (if initial "max" "default")
11874                         len)
11875                        (if initial
11876                            (cons (number-to-string initial)
11877                                  0)))))
11878                 (unless (string-match "^[ \t]*$" input)
11879                   (setq all (string-to-number input))
11880                   (if (< all len)
11881                       (let ((older-range (nreverse older)))
11882                         (setq older nil)
11883
11884                         (while (> all 0)
11885                           (let* ((r (pop older-range))
11886                                  (min (if (numberp r) r (car r)))
11887                                  (max (if (numberp r) r (cdr r))))
11888                             (while (and (<= min max)
11889                                         (> all 0))
11890                               (push max older)
11891                               (setq all (1- all)
11892                                     max (1- max))))))))))
11893           (setq older (gnus-uncompress-range older))))
11894         (if (not older)
11895             (message "No old news.")
11896           (gnus-summary-insert-articles older)
11897           (gnus-summary-limit (gnus-sorted-nunion old older))))
11898     (gnus-summary-position-point)))
11899
11900 (defun gnus-summary-insert-new-articles ()
11901   "Insert all new articles in this group."
11902   (interactive)
11903   (prog1
11904       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11905             (old-active gnus-newsgroup-active)
11906             (nnmail-fetched-sources (list t))
11907             i new)
11908         (setq gnus-newsgroup-active
11909               (gnus-activate-group gnus-newsgroup-name 'scan))
11910         (setq i (cdr gnus-newsgroup-active))
11911         (while (> i (cdr old-active))
11912           (push i new)
11913           (decf i))
11914         (if (not new)
11915             (message "No gnus is bad news.")
11916           (gnus-summary-insert-articles new)
11917           (setq gnus-newsgroup-unreads
11918                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11919           (gnus-summary-limit (gnus-sorted-nunion old new))))
11920     (gnus-summary-position-point)))
11921
11922 (gnus-summary-make-all-marking-commands)
11923
11924 (gnus-ems-redefine)
11925
11926 (provide 'gnus-sum)
11927
11928 (run-hooks 'gnus-sum-load-hook)
11929
11930 ;; Local Variables:
11931 ;; coding: iso-8859-1
11932 ;; End:
11933
11934 ;;; gnus-sum.el ends here