* gnus-sum.el: Concur with Steve Young, 5th argument to 'load' is
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for 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 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile
30   (require 'cl)
31   (defvar tool-bar-map))
32
33 (require 'gnus)
34 (require 'gnus-group)
35 (require 'gnus-spec)
36 (require 'gnus-range)
37 (require 'gnus-int)
38 (require 'gnus-undo)
39 (require 'gnus-util)
40 (require 'mm-decode)
41 (require 'nnoo)
42
43 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
44 (autoload 'gnus-cache-write-active "gnus-cache")
45 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
46 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
47 (autoload 'mm-uu-dissect "mm-uu")
48 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
49   "Deuglify broken Outlook (Express) articles and redisplay."
50   t)
51 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
52 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
53 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
54
55 (defcustom gnus-kill-summary-on-exit t
56   "*If non-nil, kill the summary buffer when you exit from it.
57 If nil, the summary will become a \"*Dead Summary*\" buffer, and
58 it will be killed sometime later."
59   :group 'gnus-summary-exit
60   :type 'boolean)
61
62 (defcustom gnus-fetch-old-headers nil
63   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
64 If an unread article in the group refers to an older, already read (or
65 just marked as read) article, the old article will not normally be
66 displayed in the Summary buffer.  If this variable is non-nil, Gnus
67 will attempt to grab the headers to the old articles, and thereby
68 build complete threads.  If it has the value `some', only enough
69 headers to connect otherwise loose threads will be displayed.  This
70 variable can also be a number.  In that case, no more than that number
71 of old headers will be fetched.  If it has the value `invisible', all
72 old headers will be fetched, but none will be displayed.
73
74 The server has to support NOV for any of this to work."
75   :group 'gnus-thread
76   :type '(choice (const :tag "off" nil)
77                  (const some)
78                  number
79                  (sexp :menu-tag "other" t)))
80
81 (defcustom gnus-refer-thread-limit 200
82   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
83 If t, fetch all the available old headers."
84   :group 'gnus-thread
85   :type '(choice number
86                  (sexp :menu-tag "other" t)))
87
88 (defcustom gnus-summary-make-false-root 'adopt
89   "*nil means that Gnus won't gather loose threads.
90 If the root of a thread has expired or been read in a previous
91 session, the information necessary to build a complete thread has been
92 lost.  Instead of having many small sub-threads from this original thread
93 scattered all over the summary buffer, Gnus can gather them.
94
95 If non-nil, Gnus will try to gather all loose sub-threads from an
96 original thread into one large thread.
97
98 If this variable is non-nil, it should be one of `none', `adopt',
99 `dummy' or `empty'.
100
101 If this variable is `none', Gnus will not make a false root, but just
102 present the sub-threads after another.
103 If this variable is `dummy', Gnus will create a dummy root that will
104 have all the sub-threads as children.
105 If this variable is `adopt', Gnus will make one of the \"children\"
106 the parent and mark all the step-children as such.
107 If this variable is `empty', the \"children\" are printed with empty
108 subject fields.  (Or rather, they will be printed with a string
109 given by the `gnus-summary-same-subject' variable.)"
110   :group 'gnus-thread
111   :type '(choice (const :tag "off" nil)
112                  (const none)
113                  (const dummy)
114                  (const adopt)
115                  (const empty)))
116
117 (defcustom gnus-summary-make-false-root-always nil
118   "Always make a false dummy root."
119   :group 'gnus-thread
120   :type 'boolean)
121
122 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
123   "*A regexp to match subjects to be excluded from loose thread gathering.
124 As loose thread gathering is done on subjects only, that means that
125 there can be many false gatherings performed.  By rooting out certain
126 common subjects, gathering might become saner."
127   :group 'gnus-thread
128   :type 'regexp)
129
130 (defcustom gnus-summary-gather-subject-limit nil
131   "*Maximum length of subject comparisons when gathering loose threads.
132 Use nil to compare full subjects.  Setting this variable to a low
133 number will help gather threads that have been corrupted by
134 newsreaders chopping off subject lines, but it might also mean that
135 unrelated articles that have subject that happen to begin with the
136 same few characters will be incorrectly gathered.
137
138 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
139 comparing subjects."
140   :group 'gnus-thread
141   :type '(choice (const :tag "off" nil)
142                  (const fuzzy)
143                  (sexp :menu-tag "on" t)))
144
145 (defcustom gnus-simplify-subject-functions nil
146   "List of functions taking a string argument that simplify subjects.
147 The functions are applied recursively.
148
149 Useful functions to put in this list include:
150 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
151 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
152   :group 'gnus-thread
153   :type '(repeat function))
154
155 (defcustom gnus-simplify-ignored-prefixes nil
156   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
157   :group 'gnus-thread
158   :type '(choice (const :tag "off" nil)
159                  regexp))
160
161 (defcustom gnus-build-sparse-threads nil
162   "*If non-nil, fill in the gaps in threads.
163 If `some', only fill in the gaps that are needed to tie loose threads
164 together.  If `more', fill in all leaf nodes that Gnus can find.  If
165 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
166   :group 'gnus-thread
167   :type '(choice (const :tag "off" nil)
168                  (const some)
169                  (const more)
170                  (sexp :menu-tag "all" t)))
171
172 (defcustom gnus-summary-thread-gathering-function
173   'gnus-gather-threads-by-subject
174   "*Function used for gathering loose threads.
175 There are two pre-defined functions: `gnus-gather-threads-by-subject',
176 which only takes Subjects into consideration; and
177 `gnus-gather-threads-by-references', which compared the References
178 headers of the articles to find matches."
179   :group 'gnus-thread
180   :type '(radio (function-item gnus-gather-threads-by-subject)
181                 (function-item gnus-gather-threads-by-references)
182                 (function :tag "other")))
183
184 (defcustom gnus-summary-same-subject ""
185   "*String indicating that the current article has the same subject as the previous.
186 This variable will only be used if the value of
187 `gnus-summary-make-false-root' is `empty'."
188   :group 'gnus-summary-format
189   :type 'string)
190
191 (defcustom gnus-summary-goto-unread t
192   "*If t, many commands will go to the next unread article.
193 This applies to marking commands as well as other commands that
194 \"naturally\" select the next article, like, for instance, `SPC' at
195 the end of an article.
196
197 If nil, the marking commands do NOT go to the next unread article
198 \(they go to the next article instead).  If `never', commands that
199 usually go to the next unread article, will go to the next article,
200 whether it is read or not."
201   :group 'gnus-summary-marks
202   :link '(custom-manual "(gnus)Setting Marks")
203   :type '(choice (const :tag "off" nil)
204                  (const never)
205                  (sexp :menu-tag "on" t)))
206
207 (defcustom gnus-summary-default-score 0
208   "*Default article score level.
209 All scores generated by the score files will be added to this score.
210 If this variable is nil, scoring will be disabled."
211   :group 'gnus-score-default
212   :type '(choice (const :tag "disable")
213                  integer))
214
215 (defcustom gnus-summary-default-high-score 0
216   "*Default threshold for a high scored article.
217 An article will be highlighted as high scored if its score is greater
218 than this score."
219   :group 'gnus-score-default
220   :type 'integer)
221
222 (defcustom gnus-summary-default-low-score 0
223   "*Default threshold for a low scored article.
224 An article will be highlighted as low scored if its score is smaller
225 than this score."
226   :group 'gnus-score-default
227   :type 'integer)
228
229 (defcustom gnus-summary-zcore-fuzz 0
230   "*Fuzziness factor for the zcore in the summary buffer.
231 Articles with scores closer than this to `gnus-summary-default-score'
232 will not be marked."
233   :group 'gnus-summary-format
234   :type 'integer)
235
236 (defcustom gnus-simplify-subject-fuzzy-regexp nil
237   "*Strings to be removed when doing fuzzy matches.
238 This can either be a regular expression or list of regular expressions
239 that will be removed from subject strings if fuzzy subject
240 simplification is selected."
241   :group 'gnus-thread
242   :type '(repeat regexp))
243
244 (defcustom gnus-show-threads t
245   "*If non-nil, display threads in summary mode."
246   :group 'gnus-thread
247   :type 'boolean)
248
249 (defcustom gnus-thread-hide-subtree nil
250   "*If non-nil, hide all threads initially.
251 This can be a predicate specifier which says which threads to hide.
252 If threads are hidden, you have to run the command
253 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
254 to expose hidden threads."
255   :group 'gnus-thread
256   :type 'boolean)
257
258 (defcustom gnus-thread-hide-killed t
259   "*If non-nil, hide killed threads automatically."
260   :group 'gnus-thread
261   :type 'boolean)
262
263 (defcustom gnus-thread-ignore-subject t
264   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
265 If nil, articles that have different subjects from their parents will
266 start separate threads."
267   :group 'gnus-thread
268   :type 'boolean)
269
270 (defcustom gnus-thread-operation-ignore-subject t
271   "*If non-nil, subjects will be ignored when doing thread commands.
272 This affects commands like `gnus-summary-kill-thread' and
273 `gnus-summary-lower-thread'.
274
275 If this variable is nil, articles in the same thread with different
276 subjects will not be included in the operation in question.  If this
277 variable is `fuzzy', only articles that have subjects that are fuzzily
278 equal will be included."
279   :group 'gnus-thread
280   :type '(choice (const :tag "off" nil)
281                  (const fuzzy)
282                  (sexp :tag "on" t)))
283
284 (defcustom gnus-thread-indent-level 4
285   "*Number that says how much each sub-thread should be indented."
286   :group 'gnus-thread
287   :type 'integer)
288
289 (defcustom gnus-auto-extend-newsgroup t
290   "*If non-nil, extend newsgroup forward and backward when requested."
291   :group 'gnus-summary-choose
292   :type 'boolean)
293
294 (defcustom gnus-auto-select-first t
295   "*If non-nil, select the article under point.
296 Which article this is is controlled by the `gnus-auto-select-subject'
297 variable.
298
299 If you want to prevent automatic selection of articles in some
300 newsgroups, set the variable to nil in `gnus-select-group-hook'."
301   :group 'gnus-group-select
302   :type '(choice (const :tag "none" nil)
303                  (sexp :menu-tag "first" t)))
304
305 (defcustom gnus-auto-select-subject 'unread
306   "*Says what subject to place under point when entering a group.
307
308 This variable can either be the symbols `first' (place point on the
309 first subject), `unread' (place point on the subject line of the first
310 unread article), `best' (place point on the subject line of the
311 higest-scored article), `unseen' (place point on the subject line of
312 the first unseen article), 'unseen-or-unread' (place point on the subject
313 line of the first unseen article or, if all article have been seen, on the
314 subject line of the first unread article), or a function to be called to
315 place point on some subject line."
316   :group 'gnus-group-select
317   :type '(choice (const best)
318                  (const unread)
319                  (const first)
320                  (const unseen)
321                  (const unseen-or-unread)))
322
323 (defcustom gnus-auto-select-next t
324   "*If non-nil, offer to go to the next group from the end of the previous.
325 If the value is t and the next newsgroup is empty, Gnus will exit
326 summary mode and go back to group mode.  If the value is neither nil
327 nor t, Gnus will select the following unread newsgroup.  In
328 particular, if the value is the symbol `quietly', the next unread
329 newsgroup will be selected without any confirmation, and if it is
330 `almost-quietly', the next group will be selected without any
331 confirmation if you are located on the last article in the group.
332 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
333 will go to the next group without confirmation."
334   :group 'gnus-summary-maneuvering
335   :type '(choice (const :tag "off" nil)
336                  (const quietly)
337                  (const almost-quietly)
338                  (const slightly-quietly)
339                  (sexp :menu-tag "on" t)))
340
341 (defcustom gnus-auto-select-same nil
342   "*If non-nil, select the next article with the same subject.
343 If there are no more articles with the same subject, go to
344 the first unread article."
345   :group 'gnus-summary-maneuvering
346   :type 'boolean)
347
348 (defcustom gnus-auto-goto-ignores 'unfetched
349   "*Says how to handle unfetched articles when maneuvering.
350
351 This variable can either be the symbols `nil' (maneuver to any
352 article), `undownloaded' (maneuvering while unplugged ignores articles
353 that have not been fetched), `always-undownloaded' (maneuvering always
354 ignores articles that have not been fetched), `unfetched' (maneuvering
355 ignores articles whose headers have not been fetched).
356
357 NOTE: The list of unfetched articles will always be nil when plugged
358 and, when unplugged, a subset of the undownloaded article list."
359   :group 'gnus-summary-maneuvering
360   :type '(choice (const :tag "None" nil)
361                  (const :tag "Undownloaded when unplugged" undownloaded)
362                  (const :tag "Undownloaded" always-undownloaded)
363                  (const :tag "Unfetched" unfetched)))
364
365 (defcustom gnus-summary-check-current nil
366   "*If non-nil, consider the current article when moving.
367 The \"unread\" movement commands will stay on the same line if the
368 current article is unread."
369   :group 'gnus-summary-maneuvering
370   :type 'boolean)
371
372 (defcustom gnus-auto-center-summary t
373   "*If non-nil, always center the current summary buffer.
374 In particular, if `vertical' do only vertical recentering.  If non-nil
375 and non-`vertical', do both horizontal and vertical recentering."
376   :group 'gnus-summary-maneuvering
377   :type '(choice (const :tag "none" nil)
378                  (const vertical)
379                  (integer :tag "height")
380                  (sexp :menu-tag "both" t)))
381
382 (defvar gnus-auto-center-group t
383   "*If non-nil, always center the group buffer.")
384
385 (defcustom gnus-show-all-headers nil
386   "*If non-nil, don't hide any headers."
387   :group 'gnus-article-hiding
388   :group 'gnus-article-headers
389   :type 'boolean)
390
391 (defcustom gnus-summary-ignore-duplicates nil
392   "*If non-nil, ignore articles with identical Message-ID headers."
393   :group 'gnus-summary
394   :type 'boolean)
395
396 (defcustom gnus-single-article-buffer t
397   "*If non-nil, display all articles in the same buffer.
398 If nil, each group will get its own article buffer."
399   :group 'gnus-article-various
400   :type 'boolean)
401
402 (defcustom gnus-break-pages t
403   "*If non-nil, do page breaking on articles.
404 The page delimiter is specified by the `gnus-page-delimiter'
405 variable."
406   :group 'gnus-article-various
407   :type 'boolean)
408
409 (defcustom gnus-move-split-methods nil
410   "*Variable used to suggest where articles are to be moved to.
411 It uses the same syntax as the `gnus-split-methods' variable.
412 However, whereas `gnus-split-methods' specifies file names as targets,
413 this variable specifies group names."
414   :group 'gnus-summary-mail
415   :type '(repeat (choice (list :value (fun) function)
416                          (cons :value ("" "") regexp (repeat string))
417                          (sexp :value nil))))
418
419 (defcustom gnus-unread-mark ?           ;Whitespace
420   "*Mark used for unread articles."
421   :group 'gnus-summary-marks
422   :type 'character)
423
424 (defcustom gnus-ticked-mark ?!
425   "*Mark used for ticked articles."
426   :group 'gnus-summary-marks
427   :type 'character)
428
429 (defcustom gnus-dormant-mark ??
430   "*Mark used for dormant articles."
431   :group 'gnus-summary-marks
432   :type 'character)
433
434 (defcustom gnus-del-mark ?r
435   "*Mark used for del'd articles."
436   :group 'gnus-summary-marks
437   :type 'character)
438
439 (defcustom gnus-read-mark ?R
440   "*Mark used for read articles."
441   :group 'gnus-summary-marks
442   :type 'character)
443
444 (defcustom gnus-expirable-mark ?E
445   "*Mark used for expirable articles."
446   :group 'gnus-summary-marks
447   :type 'character)
448
449 (defcustom gnus-killed-mark ?K
450   "*Mark used for killed articles."
451   :group 'gnus-summary-marks
452   :type 'character)
453
454 (defcustom gnus-spam-mark ?$
455   "*Mark used for spam articles."
456   :group 'gnus-summary-marks
457   :type 'character)
458
459 (defcustom gnus-souped-mark ?F
460   "*Mark used for souped articles."
461   :group 'gnus-summary-marks
462   :type 'character)
463
464 (defcustom gnus-kill-file-mark ?X
465   "*Mark used for articles killed by kill files."
466   :group 'gnus-summary-marks
467   :type 'character)
468
469 (defcustom gnus-low-score-mark ?Y
470   "*Mark used for articles with a low score."
471   :group 'gnus-summary-marks
472   :type 'character)
473
474 (defcustom gnus-catchup-mark ?C
475   "*Mark used for articles that are caught up."
476   :group 'gnus-summary-marks
477   :type 'character)
478
479 (defcustom gnus-replied-mark ?A
480   "*Mark used for articles that have been replied to."
481   :group 'gnus-summary-marks
482   :type 'character)
483
484 (defcustom gnus-forwarded-mark ?F
485   "*Mark used for articles that have been forwarded."
486   :group 'gnus-summary-marks
487   :type 'character)
488
489 (defcustom gnus-recent-mark ?N
490   "*Mark used for articles that are recent."
491   :group 'gnus-summary-marks
492   :type 'character)
493
494 (defcustom gnus-cached-mark ?*
495   "*Mark used for articles that are in the cache."
496   :group 'gnus-summary-marks
497   :type 'character)
498
499 (defcustom gnus-saved-mark ?S
500   "*Mark used for articles that have been saved."
501   :group 'gnus-summary-marks
502   :type 'character)
503
504 (defcustom gnus-unseen-mark ?.
505   "*Mark used for articles that haven't been seen."
506   :group 'gnus-summary-marks
507   :type 'character)
508
509 (defcustom gnus-no-mark ?               ;Whitespace
510   "*Mark used for articles that have no other secondary mark."
511   :group 'gnus-summary-marks
512   :type 'character)
513
514 (defcustom gnus-ancient-mark ?O
515   "*Mark used for ancient articles."
516   :group 'gnus-summary-marks
517   :type 'character)
518
519 (defcustom gnus-sparse-mark ?Q
520   "*Mark used for sparsely reffed articles."
521   :group 'gnus-summary-marks
522   :type 'character)
523
524 (defcustom gnus-canceled-mark ?G
525   "*Mark used for canceled articles."
526   :group 'gnus-summary-marks
527   :type 'character)
528
529 (defcustom gnus-duplicate-mark ?M
530   "*Mark used for duplicate articles."
531   :group 'gnus-summary-marks
532   :type 'character)
533
534 (defcustom gnus-undownloaded-mark ?-
535   "*Mark used for articles that weren't downloaded."
536   :group 'gnus-summary-marks
537   :type 'character)
538
539 (defcustom gnus-downloaded-mark ?+
540   "*Mark used for articles that were downloaded."
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-downloadable-mark ?%
545   "*Mark used for articles that are to be downloaded."
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-unsendable-mark ?=
550   "*Mark used for articles that won't be sent."
551   :group 'gnus-summary-marks
552   :type 'character)
553
554 (defcustom gnus-score-over-mark ?+
555   "*Score mark used for articles with high scores."
556   :group 'gnus-summary-marks
557   :type 'character)
558
559 (defcustom gnus-score-below-mark ?-
560   "*Score mark used for articles with low scores."
561   :group 'gnus-summary-marks
562   :type 'character)
563
564 (defcustom gnus-empty-thread-mark ?     ;Whitespace
565   "*There is no thread under the article."
566   :group 'gnus-summary-marks
567   :type 'character)
568
569 (defcustom gnus-not-empty-thread-mark ?=
570   "*There is a thread under the article."
571   :group 'gnus-summary-marks
572   :type 'character)
573
574 (defcustom gnus-view-pseudo-asynchronously nil
575   "*If non-nil, Gnus will view pseudo-articles asynchronously."
576   :group 'gnus-extract-view
577   :type 'boolean)
578
579 (defcustom gnus-auto-expirable-marks
580   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
581         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
582         gnus-souped-mark gnus-duplicate-mark)
583   "*The list of marks converted into expiration if a group is auto-expirable."
584   :version "21.1"
585   :group 'gnus-summary
586   :type '(repeat character))
587
588 (defcustom gnus-inhibit-user-auto-expire t
589   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
590   :version "21.1"
591   :group 'gnus-summary
592   :type 'boolean)
593
594 (defcustom gnus-view-pseudos nil
595   "*If `automatic', pseudo-articles will be viewed automatically.
596 If `not-confirm', pseudos will be viewed automatically, and the user
597 will not be asked to confirm the command."
598   :group 'gnus-extract-view
599   :type '(choice (const :tag "off" nil)
600                  (const automatic)
601                  (const not-confirm)))
602
603 (defcustom gnus-view-pseudos-separately t
604   "*If non-nil, one pseudo-article will be created for each file to be viewed.
605 If nil, all files that use the same viewing command will be given as a
606 list of parameters to that command."
607   :group 'gnus-extract-view
608   :type 'boolean)
609
610 (defcustom gnus-insert-pseudo-articles t
611   "*If non-nil, insert pseudo-articles when decoding articles."
612   :group 'gnus-extract-view
613   :type 'boolean)
614
615 (defcustom gnus-summary-dummy-line-format
616   "   %(:                             :%) %S\n"
617   "*The format specification for the dummy roots in the summary buffer.
618 It works along the same lines as a normal formatting string,
619 with some simple extensions.
620
621 %S  The subject
622
623 General format specifiers can also be used.
624 See `(gnus)Formatting Variables'."
625   :link '(custom-manual "(gnus)Formatting Variables")
626   :group 'gnus-threading
627   :type 'string)
628
629 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
630   "*The format specification for the summary mode line.
631 It works along the same lines as a normal formatting string,
632 with some simple extensions:
633
634 %G  Group name
635 %p  Unprefixed group name
636 %A  Current article number
637 %z  Current article score
638 %V  Gnus version
639 %U  Number of unread articles in the group
640 %e  Number of unselected articles in the group
641 %Z  A string with unread/unselected article counts
642 %g  Shortish group name
643 %S  Subject of the current article
644 %u  User-defined spec
645 %s  Current score file name
646 %d  Number of dormant articles
647 %r  Number of articles that have been marked as read in this session
648 %E  Number of articles expunged by the score files"
649   :group 'gnus-summary-format
650   :type 'string)
651
652 (defcustom gnus-list-identifiers nil
653   "Regexp that matches list identifiers to be removed from subject.
654 This can also be a list of regexps."
655   :version "21.1"
656   :group 'gnus-summary-format
657   :group 'gnus-article-hiding
658   :type '(choice (const :tag "none" nil)
659                  (regexp :value ".*")
660                  (repeat :value (".*") regexp)))
661
662 (defcustom gnus-summary-mark-below 0
663   "*Mark all articles with a score below this variable as read.
664 This variable is local to each summary buffer and usually set by the
665 score file."
666   :group 'gnus-score-default
667   :type 'integer)
668
669 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
670   "*List of functions used for sorting articles in the summary buffer.
671
672 Each function takes two articles and returns non-nil if the first
673 article should be sorted before the other.  If you use more than one
674 function, the primary sort function should be the last.  You should
675 probably always include `gnus-article-sort-by-number' in the list of
676 sorting functions -- preferably first.  Also note that sorting by date
677 is often much slower than sorting by number, and the sorting order is
678 very similar.  (Sorting by date means sorting by the time the message
679 was sent, sorting by number means sorting by arrival time.)
680
681 Ready-made functions include `gnus-article-sort-by-number',
682 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
683 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
684 and `gnus-article-sort-by-score'.
685
686 When threading is turned on, the variable `gnus-thread-sort-functions'
687 controls how articles are sorted."
688   :group 'gnus-summary-sort
689   :type '(repeat (choice (function-item gnus-article-sort-by-number)
690                          (function-item gnus-article-sort-by-author)
691                          (function-item gnus-article-sort-by-subject)
692                          (function-item gnus-article-sort-by-date)
693                          (function-item gnus-article-sort-by-score)
694                          (function-item gnus-article-sort-by-random)
695                          (function :tag "other"))))
696
697 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
698   "*List of functions used for sorting threads in the summary buffer.
699 By default, threads are sorted by article number.
700
701 Each function takes two threads and returns non-nil if the first
702 thread should be sorted before the other.  If you use more than one
703 function, the primary sort function should be the last.  You should
704 probably always include `gnus-thread-sort-by-number' in the list of
705 sorting functions -- preferably first.  Also note that sorting by date
706 is often much slower than sorting by number, and the sorting order is
707 very similar.  (Sorting by date means sorting by the time the message
708 was sent, sorting by number means sorting by arrival time.)
709
710 Ready-made functions include `gnus-thread-sort-by-number',
711 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
712 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
713 `gnus-thread-sort-by-most-recent-number',
714 `gnus-thread-sort-by-most-recent-date',
715 `gnus-thread-sort-by-random', and
716 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
717
718 When threading is turned off, the variable
719 `gnus-article-sort-functions' controls how articles are sorted."
720   :group 'gnus-summary-sort
721   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
722                          (function-item gnus-thread-sort-by-author)
723                          (function-item gnus-thread-sort-by-subject)
724                          (function-item gnus-thread-sort-by-date)
725                          (function-item gnus-thread-sort-by-score)
726                          (function-item gnus-thread-sort-by-total-score)
727                          (function-item gnus-thread-sort-by-random)
728                          (function :tag "other"))))
729
730 (defcustom gnus-thread-score-function '+
731   "*Function used for calculating the total score of a thread.
732
733 The function is called with the scores of the article and each
734 subthread and should then return the score of the thread.
735
736 Some functions you can use are `+', `max', or `min'."
737   :group 'gnus-summary-sort
738   :type 'function)
739
740 (defcustom gnus-summary-expunge-below nil
741   "All articles that have a score less than this variable will be expunged.
742 This variable is local to the summary buffers."
743   :group 'gnus-score-default
744   :type '(choice (const :tag "off" nil)
745                  integer))
746
747 (defcustom gnus-thread-expunge-below nil
748   "All threads that have a total score less than this variable will be expunged.
749 See `gnus-thread-score-function' for en explanation of what a
750 \"thread score\" is.
751
752 This variable is local to the summary buffers."
753   :group 'gnus-threading
754   :group 'gnus-score-default
755   :type '(choice (const :tag "off" nil)
756                  integer))
757
758 (defcustom gnus-summary-mode-hook nil
759   "*A hook for Gnus summary mode.
760 This hook is run before any variables are set in the summary buffer."
761   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
762   :group 'gnus-summary-various
763   :type 'hook)
764
765 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
766 (when (featurep 'xemacs)
767   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
768   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
769   (add-hook 'gnus-summary-mode-hook
770             'gnus-xmas-switch-horizontal-scrollbar-off))
771
772 (defcustom gnus-summary-menu-hook nil
773   "*Hook run after the creation of the summary mode menu."
774   :group 'gnus-summary-visual
775   :type 'hook)
776
777 (defcustom gnus-summary-exit-hook nil
778   "*A hook called on exit from the summary buffer.
779 It will be called with point in the group buffer."
780   :group 'gnus-summary-exit
781   :type 'hook)
782
783 (defcustom gnus-summary-prepare-hook nil
784   "*A hook called after the summary buffer has been generated.
785 If you want to modify the summary buffer, you can use this hook."
786   :group 'gnus-summary-various
787   :type 'hook)
788
789 (defcustom gnus-summary-prepared-hook nil
790   "*A hook called as the last thing after the summary buffer has been generated."
791   :group 'gnus-summary-various
792   :type 'hook)
793
794 (defcustom gnus-summary-generate-hook nil
795   "*A hook run just before generating the summary buffer.
796 This hook is commonly used to customize threading variables and the
797 like."
798   :group 'gnus-summary-various
799   :type 'hook)
800
801 (defcustom gnus-select-group-hook nil
802   "*A hook called when a newsgroup is selected.
803
804 If you'd like to simplify subjects like the
805 `gnus-summary-next-same-subject' command does, you can use the
806 following hook:
807
808  (add-hook gnus-select-group-hook
809            (lambda ()
810              (mapcar (lambda (header)
811                        (mail-header-set-subject
812                         header
813                         (gnus-simplify-subject
814                          (mail-header-subject header) 're-only)))
815                      gnus-newsgroup-headers)))"
816   :group 'gnus-group-select
817   :type 'hook)
818
819 (defcustom gnus-select-article-hook nil
820   "*A hook called when an article is selected."
821   :group 'gnus-summary-choose
822   :options '(gnus-agent-fetch-selected-article)
823   :type 'hook)
824
825 (defcustom gnus-visual-mark-article-hook
826   (list 'gnus-highlight-selected-summary)
827   "*Hook run after selecting an article in the summary buffer.
828 It is meant to be used for highlighting the article in some way.  It
829 is not run if `gnus-visual' is nil."
830   :group 'gnus-summary-visual
831   :type 'hook)
832
833 (defcustom gnus-parse-headers-hook nil
834   "*A hook called before parsing the headers."
835   :group 'gnus-various
836   :type 'hook)
837
838 (defcustom gnus-exit-group-hook nil
839   "*A hook called when exiting summary mode.
840 This hook is not called from the non-updating exit commands like `Q'."
841   :group 'gnus-various
842   :type 'hook)
843
844 (defcustom gnus-summary-update-hook
845   (list 'gnus-summary-highlight-line)
846   "*A hook called when a summary line is changed.
847 The hook will not be called if `gnus-visual' is nil.
848
849 The default function `gnus-summary-highlight-line' will
850 highlight the line according to the `gnus-summary-highlight'
851 variable."
852   :group 'gnus-summary-visual
853   :type 'hook)
854
855 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
856   "*A hook called when an article is selected for the first time.
857 The hook is intended to mark an article as read (or unread)
858 automatically when it is selected."
859   :group 'gnus-summary-choose
860   :type 'hook)
861
862 (defcustom gnus-group-no-more-groups-hook nil
863   "*A hook run when returning to group mode having no more (unread) groups."
864   :group 'gnus-group-select
865   :type 'hook)
866
867 (defcustom gnus-ps-print-hook nil
868   "*A hook run before ps-printing something from Gnus."
869   :group 'gnus-summary
870   :type 'hook)
871
872 (defcustom gnus-summary-article-move-hook nil
873   "*A hook called after an article is moved, copied, respooled, or crossposted."
874   :group 'gnus-summary
875   :type 'hook)
876
877 (defcustom gnus-summary-article-delete-hook nil
878   "*A hook called after an article is deleted."
879   :group 'gnus-summary
880   :type 'hook)
881
882 (defcustom gnus-summary-article-expire-hook nil
883   "*A hook called after an article is expired."
884   :group 'gnus-summary
885   :type 'hook)
886
887 (defcustom gnus-summary-display-arrow
888   (and (fboundp 'display-graphic-p)
889        (display-graphic-p))
890   "*If non-nil, display an arrow highlighting the current article."
891   :version "21.1"
892   :group 'gnus-summary
893   :type 'boolean)
894
895 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
896   "Face used for highlighting the current article in the summary buffer."
897   :group 'gnus-summary-visual
898   :type 'face)
899
900 (defvar gnus-tmp-downloaded nil)
901
902 (defcustom gnus-summary-highlight
903   '(((eq mark gnus-canceled-mark)
904      . gnus-summary-cancelled-face)
905     ((and uncached (> score default-high))
906      . gnus-summary-high-undownloaded-face)
907     ((and uncached (< score default-low))
908      . gnus-summary-low-undownloaded-face)
909     (uncached
910      . gnus-summary-normal-undownloaded-face)
911     ((and (> score default-high)
912           (or (eq mark gnus-dormant-mark)
913               (eq mark gnus-ticked-mark)))
914      . gnus-summary-high-ticked-face)
915     ((and (< score default-low)
916           (or (eq mark gnus-dormant-mark)
917               (eq mark gnus-ticked-mark)))
918      . gnus-summary-low-ticked-face)
919     ((or (eq mark gnus-dormant-mark)
920          (eq mark gnus-ticked-mark))
921      . gnus-summary-normal-ticked-face)
922     ((and (> score default-high) (eq mark gnus-ancient-mark))
923      . gnus-summary-high-ancient-face)
924     ((and (< score default-low) (eq mark gnus-ancient-mark))
925      . gnus-summary-low-ancient-face)
926     ((eq mark gnus-ancient-mark)
927      . gnus-summary-normal-ancient-face)
928     ((and (> score default-high) (eq mark gnus-unread-mark))
929      . gnus-summary-high-unread-face)
930     ((and (< score default-low) (eq mark gnus-unread-mark))
931      . gnus-summary-low-unread-face)
932     ((eq mark gnus-unread-mark)
933      . gnus-summary-normal-unread-face)
934     ((> score default-high)
935      . gnus-summary-high-read-face)
936     ((< score default-low)
937      . gnus-summary-low-read-face)
938     (t
939      . gnus-summary-normal-read-face))
940   "*Controls the highlighting of summary buffer lines.
941
942 A list of (FORM . FACE) pairs.  When deciding how a a particular
943 summary line should be displayed, each form is evaluated.  The content
944 of the face field after the first true form is used.  You can change
945 how those summary lines are displayed, by editing the face field.
946
947 You can use the following variables in the FORM field.
948
949 score:        The article's score
950 default:      The default article score.
951 default-high: The default score for high scored articles.
952 default-low:  The default score for low scored articles.
953 below:        The score below which articles are automatically marked as read.
954 mark:         The articles mark."
955   :group 'gnus-summary-visual
956   :type '(repeat (cons (sexp :tag "Form" nil)
957                        face)))
958
959 (defcustom gnus-alter-header-function nil
960   "Function called to allow alteration of article header structures.
961 The function is called with one parameter, the article header vector,
962 which it may alter in any way."
963   :type '(choice (const :tag "None" nil)
964                  function)
965   :group 'gnus-summary)
966
967 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
968   "Variable that says which function should be used to decode a string with encoded words.")
969
970 (defcustom gnus-extra-headers '(To Newsgroups)
971   "*Extra headers to parse."
972   :version "21.1"
973   :group 'gnus-summary
974   :type '(repeat symbol))
975
976 (defcustom gnus-ignored-from-addresses
977   (and user-mail-address (regexp-quote user-mail-address))
978   "*Regexp of From headers that may be suppressed in favor of To headers."
979   :version "21.1"
980   :group 'gnus-summary
981   :type 'regexp)
982
983 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
984   "List of charsets that should be ignored.
985 When these charsets are used in the \"charset\" parameter, the
986 default charset will be used instead."
987   :version "21.1"
988   :type '(repeat symbol)
989   :group 'gnus-charset)
990
991 (gnus-define-group-parameter
992  ignored-charsets
993  :type list
994  :function-document
995  "Return the ignored charsets of GROUP."
996  :variable gnus-group-ignored-charsets-alist
997  :variable-default
998  '(("alt\\.chinese\\.text" iso-8859-1))
999  :variable-document
1000  "Alist of regexps (to match group names) and charsets that should be ignored.
1001 When these charsets are used in the \"charset\" parameter, the
1002 default charset will be used instead."
1003  :variable-group gnus-charset
1004  :variable-type '(repeat (cons (regexp :tag "Group")
1005                                (repeat symbol)))
1006  :parameter-type '(choice :tag "Ignored charsets"
1007                           :value nil
1008                           (repeat (symbol)))
1009  :parameter-document       "\
1010 List of charsets that should be ignored.
1011
1012 When these charsets are used in the \"charset\" parameter, the
1013 default charset will be used instead.")
1014
1015 (defcustom gnus-group-highlight-words-alist nil
1016   "Alist of group regexps and highlight regexps.
1017 This variable uses the same syntax as `gnus-emphasis-alist'."
1018   :version "21.1"
1019   :type '(repeat (cons (regexp :tag "Group")
1020                        (repeat (list (regexp :tag "Highlight regexp")
1021                                      (number :tag "Group for entire word" 0)
1022                                      (number :tag "Group for displayed part" 0)
1023                                      (symbol :tag "Face"
1024                                              gnus-emphasis-highlight-words)))))
1025   :group 'gnus-summary-visual)
1026
1027 (defcustom gnus-summary-show-article-charset-alist
1028   nil
1029   "Alist of number and charset.
1030 The article will be shown with the charset corresponding to the
1031 numbered argument.
1032 For example: ((1 . cn-gb-2312) (2 . big5))."
1033   :version "21.1"
1034   :type '(repeat (cons (number :tag "Argument" 1)
1035                        (symbol :tag "Charset")))
1036   :group 'gnus-charset)
1037
1038 (defcustom gnus-preserve-marks t
1039   "Whether marks are preserved when moving, copying and respooling messages."
1040   :version "21.1"
1041   :type 'boolean
1042   :group 'gnus-summary-marks)
1043
1044 (defcustom gnus-alter-articles-to-read-function nil
1045   "Function to be called to alter the list of articles to be selected."
1046   :type '(choice (const nil) function)
1047   :group 'gnus-summary)
1048
1049 (defcustom gnus-orphan-score nil
1050   "*All orphans get this score added.  Set in the score file."
1051   :group 'gnus-score-default
1052   :type '(choice (const nil)
1053                  integer))
1054
1055 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1056   "*A regexp to match MIME parts when saving multiple parts of a
1057 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1058 This regexp will be used by default when prompting the user for which
1059 type of files to save."
1060   :group 'gnus-summary
1061   :type 'regexp)
1062
1063 (defcustom gnus-read-all-available-headers nil
1064   "Whether Gnus should parse all headers made available to it.
1065 This is mostly relevant for slow backends where the user may
1066 wish to widen the summary buffer to include all headers
1067 that were fetched.  Say, for nnultimate groups."
1068   :group 'gnus-summary
1069   :type '(choice boolean regexp))
1070
1071 (defcustom gnus-summary-muttprint-program "muttprint"
1072   "Command (and optional arguments) used to run Muttprint."
1073   :version "21.3"
1074   :group 'gnus-summary
1075   :type 'string)
1076
1077 (defcustom gnus-article-loose-mime nil
1078   "If non-nil, don't require MIME-Version header.
1079 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1080 supply the MIME-Version header or deliberately strip it From the mail.
1081 Set it to non-nil, Gnus will treat some articles as MIME even if
1082 the MIME-Version header is missed."
1083   :version "21.3"
1084   :type 'boolean
1085   :group 'gnus-article-mime)
1086
1087 (defcustom gnus-article-emulate-mime t
1088   "If non-nil, use MIME emulation for uuencode and the like.
1089 This means that Gnus will search message bodies for text that look
1090 like uuencoded bits, yEncoded bits, and so on, and present that using
1091 the normal Gnus MIME machinery."
1092   :type 'boolean
1093   :group 'gnus-article-mime)
1094
1095 ;;; Internal variables
1096
1097 (defvar gnus-summary-display-cache nil)
1098 (defvar gnus-article-mime-handles nil)
1099 (defvar gnus-article-decoded-p nil)
1100 (defvar gnus-article-charset nil)
1101 (defvar gnus-article-ignored-charsets nil)
1102 (defvar gnus-scores-exclude-files nil)
1103 (defvar gnus-page-broken nil)
1104
1105 (defvar gnus-original-article nil)
1106 (defvar gnus-article-internal-prepare-hook nil)
1107 (defvar gnus-newsgroup-process-stack nil)
1108
1109 (defvar gnus-thread-indent-array nil)
1110 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1111 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1112   "Function called to sort the articles within a thread after it has been gathered together.")
1113
1114 (defvar gnus-summary-save-parts-type-history nil)
1115 (defvar gnus-summary-save-parts-last-directory nil)
1116
1117 ;; Avoid highlighting in kill files.
1118 (defvar gnus-summary-inhibit-highlight nil)
1119 (defvar gnus-newsgroup-selected-overlay nil)
1120 (defvar gnus-inhibit-limiting nil)
1121 (defvar gnus-newsgroup-adaptive-score-file nil)
1122 (defvar gnus-current-score-file nil)
1123 (defvar gnus-current-move-group nil)
1124 (defvar gnus-current-copy-group nil)
1125 (defvar gnus-current-crosspost-group nil)
1126 (defvar gnus-newsgroup-display nil)
1127
1128 (defvar gnus-newsgroup-dependencies nil)
1129 (defvar gnus-newsgroup-adaptive nil)
1130 (defvar gnus-summary-display-article-function nil)
1131 (defvar gnus-summary-highlight-line-function nil
1132   "Function called after highlighting a summary line.")
1133
1134 (defvar gnus-summary-line-format-alist
1135   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1136     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1137     (?s gnus-tmp-subject-or-nil ?s)
1138     (?n gnus-tmp-name ?s)
1139     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1140         ?s)
1141     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1142             gnus-tmp-from) ?s)
1143     (?F gnus-tmp-from ?s)
1144     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1145     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1146     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1147     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1148     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1149     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1150     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1151     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1152     (?L gnus-tmp-lines ?s)
1153     (?O gnus-tmp-downloaded ?c)
1154     (?I gnus-tmp-indentation ?s)
1155     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1156     (?R gnus-tmp-replied ?c)
1157     (?\[ gnus-tmp-opening-bracket ?c)
1158     (?\] gnus-tmp-closing-bracket ?c)
1159     (?\> (make-string gnus-tmp-level ? ) ?s)
1160     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1161     (?i gnus-tmp-score ?d)
1162     (?z gnus-tmp-score-char ?c)
1163     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1164     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1165     (?U gnus-tmp-unread ?c)
1166     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1167         ?s)
1168     (?t (gnus-summary-number-of-articles-in-thread
1169          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1170         ?d)
1171     (?e (gnus-summary-number-of-articles-in-thread
1172          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1173         ?c)
1174     (?u gnus-tmp-user-defined ?s)
1175     (?P (gnus-pick-line-number) ?d)
1176     (?B gnus-tmp-thread-tree-header-string ?s)
1177     (user-date (gnus-user-date
1178                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1179   "An alist of format specifications that can appear in summary lines.
1180 These are paired with what variables they correspond with, along with
1181 the type of the variable (string, integer, character, etc).")
1182
1183 (defvar gnus-summary-dummy-line-format-alist
1184   `((?S gnus-tmp-subject ?s)
1185     (?N gnus-tmp-number ?d)
1186     (?u gnus-tmp-user-defined ?s)))
1187
1188 (defvar gnus-summary-mode-line-format-alist
1189   `((?G gnus-tmp-group-name ?s)
1190     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1191     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1192     (?A gnus-tmp-article-number ?d)
1193     (?Z gnus-tmp-unread-and-unselected ?s)
1194     (?V gnus-version ?s)
1195     (?U gnus-tmp-unread-and-unticked ?d)
1196     (?S gnus-tmp-subject ?s)
1197     (?e gnus-tmp-unselected ?d)
1198     (?u gnus-tmp-user-defined ?s)
1199     (?d (length gnus-newsgroup-dormant) ?d)
1200     (?t (length gnus-newsgroup-marked) ?d)
1201     (?h (length gnus-newsgroup-spam-marked) ?d)
1202     (?r (length gnus-newsgroup-reads) ?d)
1203     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1204     (?E gnus-newsgroup-expunged-tally ?d)
1205     (?s (gnus-current-score-file-nondirectory) ?s)))
1206
1207 (defvar gnus-last-search-regexp nil
1208   "Default regexp for article search command.")
1209
1210 (defvar gnus-last-shell-command nil
1211   "Default shell command on article.")
1212
1213 (defvar gnus-newsgroup-agentized nil
1214   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1215 (defvar gnus-newsgroup-begin nil)
1216 (defvar gnus-newsgroup-end nil)
1217 (defvar gnus-newsgroup-last-rmail nil)
1218 (defvar gnus-newsgroup-last-mail nil)
1219 (defvar gnus-newsgroup-last-folder nil)
1220 (defvar gnus-newsgroup-last-file nil)
1221 (defvar gnus-newsgroup-auto-expire nil)
1222 (defvar gnus-newsgroup-active nil)
1223
1224 (defvar gnus-newsgroup-data nil)
1225 (defvar gnus-newsgroup-data-reverse nil)
1226 (defvar gnus-newsgroup-limit nil)
1227 (defvar gnus-newsgroup-limits nil)
1228
1229 (defvar gnus-newsgroup-unreads nil
1230   "Sorted list of unread articles in the current newsgroup.")
1231
1232 (defvar gnus-newsgroup-unselected nil
1233   "Sorted list of unselected unread articles in the current newsgroup.")
1234
1235 (defvar gnus-newsgroup-reads nil
1236   "Alist of read articles and article marks in the current newsgroup.")
1237
1238 (defvar gnus-newsgroup-expunged-tally nil)
1239
1240 (defvar gnus-newsgroup-marked nil
1241   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1242
1243 (defvar gnus-newsgroup-spam-marked nil
1244   "List of ranges of articles that have been marked as spam.")
1245
1246 (defvar gnus-newsgroup-killed nil
1247   "List of ranges of articles that have been through the scoring process.")
1248
1249 (defvar gnus-newsgroup-cached nil
1250   "Sorted list of articles that come from the article cache.")
1251
1252 (defvar gnus-newsgroup-saved nil
1253   "List of articles that have been saved.")
1254
1255 (defvar gnus-newsgroup-kill-headers nil)
1256
1257 (defvar gnus-newsgroup-replied nil
1258   "List of articles that have been replied to in the current newsgroup.")
1259
1260 (defvar gnus-newsgroup-forwarded nil
1261   "List of articles that have been forwarded in the current newsgroup.")
1262
1263 (defvar gnus-newsgroup-recent nil
1264   "List of articles that have are recent in the current newsgroup.")
1265
1266 (defvar gnus-newsgroup-expirable nil
1267   "Sorted list of articles in the current newsgroup that can be expired.")
1268
1269 (defvar gnus-newsgroup-processable nil
1270   "List of articles in the current newsgroup that can be processed.")
1271
1272 (defvar gnus-newsgroup-downloadable nil
1273   "Sorted list of articles in the current newsgroup that can be processed.")
1274
1275 (defvar gnus-newsgroup-unfetched nil
1276   "Sorted list of articles in the current newsgroup whose headers have
1277 not been fetched into the agent.
1278
1279 This list will always be a subset of gnus-newsgroup-undownloaded.")
1280
1281 (defvar gnus-newsgroup-undownloaded nil
1282   "List of articles in the current newsgroup that haven't been downloaded.")
1283
1284 (defvar gnus-newsgroup-unsendable nil
1285   "List of articles in the current newsgroup that won't be sent.")
1286
1287 (defvar gnus-newsgroup-bookmarks nil
1288   "List of articles in the current newsgroup that have bookmarks.")
1289
1290 (defvar gnus-newsgroup-dormant nil
1291   "Sorted list of dormant articles in the current newsgroup.")
1292
1293 (defvar gnus-newsgroup-unseen nil
1294   "List of unseen articles in the current newsgroup.")
1295
1296 (defvar gnus-newsgroup-seen nil
1297   "Range of seen articles in the current newsgroup.")
1298
1299 (defvar gnus-newsgroup-articles nil
1300   "List of articles in the current newsgroup.")
1301
1302 (defvar gnus-newsgroup-scored nil
1303   "List of scored articles in the current newsgroup.")
1304
1305 (defvar gnus-newsgroup-headers nil
1306   "List of article headers in the current newsgroup.")
1307
1308 (defvar gnus-newsgroup-threads nil)
1309
1310 (defvar gnus-newsgroup-prepared nil
1311   "Whether the current group has been prepared properly.")
1312
1313 (defvar gnus-newsgroup-ancient nil
1314   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1315
1316 (defvar gnus-newsgroup-sparse nil)
1317
1318 (defvar gnus-current-article nil)
1319 (defvar gnus-article-current nil)
1320 (defvar gnus-current-headers nil)
1321 (defvar gnus-have-all-headers nil)
1322 (defvar gnus-last-article nil)
1323 (defvar gnus-newsgroup-history nil)
1324 (defvar gnus-newsgroup-charset nil)
1325 (defvar gnus-newsgroup-ephemeral-charset nil)
1326 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1327
1328 (defvar gnus-article-before-search nil)
1329
1330 (defconst gnus-summary-local-variables
1331   '(gnus-newsgroup-name
1332     gnus-newsgroup-begin gnus-newsgroup-end
1333     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1334     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1335     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1336     gnus-newsgroup-unselected gnus-newsgroup-marked
1337     gnus-newsgroup-spam-marked
1338     gnus-newsgroup-reads gnus-newsgroup-saved
1339     gnus-newsgroup-replied gnus-newsgroup-forwarded
1340     gnus-newsgroup-recent
1341     gnus-newsgroup-expirable
1342     gnus-newsgroup-processable gnus-newsgroup-killed
1343     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1344     gnus-newsgroup-unfetched
1345     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1346     gnus-newsgroup-seen gnus-newsgroup-articles
1347     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1348     gnus-newsgroup-headers gnus-newsgroup-threads
1349     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1350     gnus-current-article gnus-current-headers gnus-have-all-headers
1351     gnus-last-article gnus-article-internal-prepare-hook
1352     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1353     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1354     gnus-thread-expunge-below
1355     gnus-score-alist gnus-current-score-file
1356     (gnus-summary-expunge-below . global)
1357     (gnus-summary-mark-below . global)
1358     (gnus-orphan-score . global)
1359     gnus-newsgroup-active gnus-scores-exclude-files
1360     gnus-newsgroup-history gnus-newsgroup-ancient
1361     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1362     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1363     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1364     (gnus-newsgroup-expunged-tally . 0)
1365     gnus-cache-removable-articles gnus-newsgroup-cached
1366     gnus-newsgroup-data gnus-newsgroup-data-reverse
1367     gnus-newsgroup-limit gnus-newsgroup-limits
1368     gnus-newsgroup-charset gnus-newsgroup-display)
1369   "Variables that are buffer-local to the summary buffers.")
1370
1371 (defvar gnus-newsgroup-variables nil
1372   "A list of variables that have separate values in different newsgroups.
1373 A list of newsgroup (summary buffer) local variables, or cons of
1374 variables and their default values (when the default values are not
1375 nil), that should be made global while the summary buffer is active.
1376 These variables can be used to set variables in the group parameters
1377 while still allowing them to affect operations done in other
1378 buffers. For example:
1379
1380 \(setq gnus-newsgroup-variables
1381      '(message-use-followup-to
1382        (gnus-visible-headers .
1383          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1384 ")
1385
1386 ;; Byte-compiler warning.
1387 (eval-when-compile
1388   ;; Bind features so that require will believe that gnus-sum has
1389   ;; already been loaded (avoids infinite recursion)
1390   (let ((features (cons 'gnus-sum features)))
1391     ;; Several of the declarations in gnus-sum are needed to load the
1392     ;; following files. Right now, these definitions have been
1393     ;; compiled but not defined (evaluated).  We could either do a
1394     ;; eval-and-compile about all of the declarations or evaluate the
1395     ;; source file.
1396     (if (boundp 'gnus-newsgroup-variables)
1397         nil
1398       (load "gnus-sum.el" t t t))
1399     (require 'gnus)
1400     (require 'gnus-agent)
1401     (require 'gnus-art)))
1402
1403 ;; MIME stuff.
1404
1405 (defvar gnus-decode-encoded-word-methods
1406   '(mail-decode-encoded-word-string)
1407   "List of methods used to decode encoded words.
1408
1409 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1410 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1411 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1412 whose names match REGEXP.
1413
1414 For example:
1415 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1416  mail-decode-encoded-word-string
1417  (\"chinese\" . rfc1843-decode-string))")
1418
1419 (defvar gnus-decode-encoded-word-methods-cache nil)
1420
1421 (defun gnus-multi-decode-encoded-word-string (string)
1422   "Apply the functions from `gnus-encoded-word-methods' that match."
1423   (unless (and gnus-decode-encoded-word-methods-cache
1424                (eq gnus-newsgroup-name
1425                    (car gnus-decode-encoded-word-methods-cache)))
1426     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1427     (mapcar (lambda (x)
1428               (if (symbolp x)
1429                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1430                 (if (and gnus-newsgroup-name
1431                          (string-match (car x) gnus-newsgroup-name))
1432                     (nconc gnus-decode-encoded-word-methods-cache
1433                            (list (cdr x))))))
1434             gnus-decode-encoded-word-methods))
1435   (let ((xlist gnus-decode-encoded-word-methods-cache))
1436     (pop xlist)
1437     (while xlist
1438       (setq string (funcall (pop xlist) string))))
1439   string)
1440
1441 ;; Subject simplification.
1442
1443 (defun gnus-simplify-whitespace (str)
1444   "Remove excessive whitespace from STR."
1445   ;; Multiple spaces.
1446   (while (string-match "[ \t][ \t]+" str)
1447     (setq str (concat (substring str 0 (match-beginning 0))
1448                         " "
1449                         (substring str (match-end 0)))))
1450   ;; Leading spaces.
1451   (when (string-match "^[ \t]+" str)
1452     (setq str (substring str (match-end 0))))
1453   ;; Trailing spaces.
1454   (when (string-match "[ \t]+$" str)
1455     (setq str (substring str 0 (match-beginning 0))))
1456   str)
1457
1458 (defun gnus-simplify-all-whitespace (str)
1459   "Remove all whitespace from STR."
1460   (while (string-match "[ \t\n]+" str)
1461     (setq str (replace-match "" nil nil str)))
1462   str)
1463
1464 (defsubst gnus-simplify-subject-re (subject)
1465   "Remove \"Re:\" from subject lines."
1466   (if (string-match message-subject-re-regexp subject)
1467       (substring subject (match-end 0))
1468     subject))
1469
1470 (defun gnus-simplify-subject (subject &optional re-only)
1471   "Remove `Re:' and words in parentheses.
1472 If RE-ONLY is non-nil, strip leading `Re:'s only."
1473   (let ((case-fold-search t))           ;Ignore case.
1474     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1475     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1476       (setq subject (substring subject (match-end 0))))
1477     ;; Remove uninteresting prefixes.
1478     (when (and (not re-only)
1479                gnus-simplify-ignored-prefixes
1480                (string-match gnus-simplify-ignored-prefixes subject))
1481       (setq subject (substring subject (match-end 0))))
1482     ;; Remove words in parentheses from end.
1483     (unless re-only
1484       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1485         (setq subject (substring subject 0 (match-beginning 0)))))
1486     ;; Return subject string.
1487     subject))
1488
1489 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1490 ;; all whitespace.
1491 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1492   (goto-char (point-min))
1493   (while (re-search-forward regexp nil t)
1494     (replace-match (or newtext ""))))
1495
1496 (defun gnus-simplify-buffer-fuzzy ()
1497   "Simplify string in the buffer fuzzily.
1498 The string in the accessible portion of the current buffer is simplified.
1499 It is assumed to be a single-line subject.
1500 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1501 matter is removed.  Additional things can be deleted by setting
1502 `gnus-simplify-subject-fuzzy-regexp'."
1503   (let ((case-fold-search t)
1504         (modified-tick))
1505     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1506
1507     (while (not (eq modified-tick (buffer-modified-tick)))
1508       (setq modified-tick (buffer-modified-tick))
1509       (cond
1510        ((listp gnus-simplify-subject-fuzzy-regexp)
1511         (mapcar 'gnus-simplify-buffer-fuzzy-step
1512                 gnus-simplify-subject-fuzzy-regexp))
1513        (gnus-simplify-subject-fuzzy-regexp
1514         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1515       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1516       (gnus-simplify-buffer-fuzzy-step
1517        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1518       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1519
1520     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1521     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1522     (gnus-simplify-buffer-fuzzy-step " $")
1523     (gnus-simplify-buffer-fuzzy-step "^ +")))
1524
1525 (defun gnus-simplify-subject-fuzzy (subject)
1526   "Simplify a subject string fuzzily.
1527 See `gnus-simplify-buffer-fuzzy' for details."
1528   (save-excursion
1529     (gnus-set-work-buffer)
1530     (let ((case-fold-search t))
1531       ;; Remove uninteresting prefixes.
1532       (when (and gnus-simplify-ignored-prefixes
1533                  (string-match gnus-simplify-ignored-prefixes subject))
1534         (setq subject (substring subject (match-end 0))))
1535       (insert subject)
1536       (inline (gnus-simplify-buffer-fuzzy))
1537       (buffer-string))))
1538
1539 (defsubst gnus-simplify-subject-fully (subject)
1540   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1541   (cond
1542    (gnus-simplify-subject-functions
1543     (gnus-map-function gnus-simplify-subject-functions subject))
1544    ((null gnus-summary-gather-subject-limit)
1545     (gnus-simplify-subject-re subject))
1546    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1547     (gnus-simplify-subject-fuzzy subject))
1548    ((numberp gnus-summary-gather-subject-limit)
1549     (gnus-limit-string (gnus-simplify-subject-re subject)
1550                        gnus-summary-gather-subject-limit))
1551    (t
1552     subject)))
1553
1554 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1555   "Check whether two subjects are equal.
1556 If optional argument SIMPLE-FIRST is t, first argument is already
1557 simplified."
1558   (cond
1559    ((null simple-first)
1560     (equal (gnus-simplify-subject-fully s1)
1561            (gnus-simplify-subject-fully s2)))
1562    (t
1563     (equal s1
1564            (gnus-simplify-subject-fully s2)))))
1565
1566 (defun gnus-summary-bubble-group ()
1567   "Increase the score of the current group.
1568 This is a handy function to add to `gnus-summary-exit-hook' to
1569 increase the score of each group you read."
1570   (gnus-group-add-score gnus-newsgroup-name))
1571
1572 \f
1573 ;;;
1574 ;;; Gnus summary mode
1575 ;;;
1576
1577 (put 'gnus-summary-mode 'mode-class 'special)
1578
1579 (defvar gnus-article-commands-menu)
1580
1581 ;; Non-orthogonal keys
1582
1583 (gnus-define-keys gnus-summary-mode-map
1584   " " gnus-summary-next-page
1585   "\177" gnus-summary-prev-page
1586   [delete] gnus-summary-prev-page
1587   [backspace] gnus-summary-prev-page
1588   "\r" gnus-summary-scroll-up
1589   "\M-\r" gnus-summary-scroll-down
1590   "n" gnus-summary-next-unread-article
1591   "p" gnus-summary-prev-unread-article
1592   "N" gnus-summary-next-article
1593   "P" gnus-summary-prev-article
1594   "\M-\C-n" gnus-summary-next-same-subject
1595   "\M-\C-p" gnus-summary-prev-same-subject
1596   "\M-n" gnus-summary-next-unread-subject
1597   "\M-p" gnus-summary-prev-unread-subject
1598   "." gnus-summary-first-unread-article
1599   "," gnus-summary-best-unread-article
1600   "\M-s" gnus-summary-search-article-forward
1601   "\M-r" gnus-summary-search-article-backward
1602   "<" gnus-summary-beginning-of-article
1603   ">" gnus-summary-end-of-article
1604   "j" gnus-summary-goto-article
1605   "^" gnus-summary-refer-parent-article
1606   "\M-^" gnus-summary-refer-article
1607   "u" gnus-summary-tick-article-forward
1608   "!" gnus-summary-tick-article-forward
1609   "U" gnus-summary-tick-article-backward
1610   "d" gnus-summary-mark-as-read-forward
1611   "D" gnus-summary-mark-as-read-backward
1612   "E" gnus-summary-mark-as-expirable
1613   "\M-u" gnus-summary-clear-mark-forward
1614   "\M-U" gnus-summary-clear-mark-backward
1615   "k" gnus-summary-kill-same-subject-and-select
1616   "\C-k" gnus-summary-kill-same-subject
1617   "\M-\C-k" gnus-summary-kill-thread
1618   "\M-\C-l" gnus-summary-lower-thread
1619   "e" gnus-summary-edit-article
1620   "#" gnus-summary-mark-as-processable
1621   "\M-#" gnus-summary-unmark-as-processable
1622   "\M-\C-t" gnus-summary-toggle-threads
1623   "\M-\C-s" gnus-summary-show-thread
1624   "\M-\C-h" gnus-summary-hide-thread
1625   "\M-\C-f" gnus-summary-next-thread
1626   "\M-\C-b" gnus-summary-prev-thread
1627   [(meta down)] gnus-summary-next-thread
1628   [(meta up)] gnus-summary-prev-thread
1629   "\M-\C-u" gnus-summary-up-thread
1630   "\M-\C-d" gnus-summary-down-thread
1631   "&" gnus-summary-execute-command
1632   "c" gnus-summary-catchup-and-exit
1633   "\C-w" gnus-summary-mark-region-as-read
1634   "\C-t" gnus-summary-toggle-truncation
1635   "?" gnus-summary-mark-as-dormant
1636   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1637   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1638   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1639   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1640   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1641   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1642   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1643   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1644   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1645   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1646   "=" gnus-summary-expand-window
1647   "\C-x\C-s" gnus-summary-reselect-current-group
1648   "\M-g" gnus-summary-rescan-group
1649   "w" gnus-summary-stop-page-breaking
1650   "\C-c\C-r" gnus-summary-caesar-message
1651   "f" gnus-summary-followup
1652   "F" gnus-summary-followup-with-original
1653   "C" gnus-summary-cancel-article
1654   "r" gnus-summary-reply
1655   "R" gnus-summary-reply-with-original
1656   "\C-c\C-f" gnus-summary-mail-forward
1657   "o" gnus-summary-save-article
1658   "\C-o" gnus-summary-save-article-mail
1659   "|" gnus-summary-pipe-output
1660   "\M-k" gnus-summary-edit-local-kill
1661   "\M-K" gnus-summary-edit-global-kill
1662   ;; "V" gnus-version
1663   "\C-c\C-d" gnus-summary-describe-group
1664   "q" gnus-summary-exit
1665   "Q" gnus-summary-exit-no-update
1666   "\C-c\C-i" gnus-info-find-node
1667   gnus-mouse-2 gnus-mouse-pick-article
1668   "m" gnus-summary-mail-other-window
1669   "a" gnus-summary-post-news
1670   "i" gnus-summary-news-other-window
1671   "x" gnus-summary-limit-to-unread
1672   "s" gnus-summary-isearch-article
1673   "t" gnus-summary-toggle-header
1674   "g" gnus-summary-show-article
1675   "l" gnus-summary-goto-last-article
1676   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1677   "\C-d" gnus-summary-enter-digest-group
1678   "\M-\C-d" gnus-summary-read-document
1679   "\M-\C-e" gnus-summary-edit-parameters
1680   "\M-\C-a" gnus-summary-customize-parameters
1681   "\C-c\C-b" gnus-bug
1682   "*" gnus-cache-enter-article
1683   "\M-*" gnus-cache-remove-article
1684   "\M-&" gnus-summary-universal-argument
1685   "\C-l" gnus-recenter
1686   "I" gnus-summary-increase-score
1687   "L" gnus-summary-lower-score
1688   "\M-i" gnus-symbolic-argument
1689   "h" gnus-summary-select-article-buffer
1690
1691   "b" gnus-article-view-part
1692   "\M-t" gnus-summary-toggle-display-buttonized
1693
1694   "V" gnus-summary-score-map
1695   "X" gnus-uu-extract-map
1696   "S" gnus-summary-send-map)
1697
1698 ;; Sort of orthogonal keymap
1699 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1700   "t" gnus-summary-tick-article-forward
1701   "!" gnus-summary-tick-article-forward
1702   "d" gnus-summary-mark-as-read-forward
1703   "r" gnus-summary-mark-as-read-forward
1704   "c" gnus-summary-clear-mark-forward
1705   " " gnus-summary-clear-mark-forward
1706   "e" gnus-summary-mark-as-expirable
1707   "x" gnus-summary-mark-as-expirable
1708   "?" gnus-summary-mark-as-dormant
1709   "b" gnus-summary-set-bookmark
1710   "B" gnus-summary-remove-bookmark
1711   "#" gnus-summary-mark-as-processable
1712   "\M-#" gnus-summary-unmark-as-processable
1713   "S" gnus-summary-limit-include-expunged
1714   "C" gnus-summary-catchup
1715   "H" gnus-summary-catchup-to-here
1716   "h" gnus-summary-catchup-from-here
1717   "\C-c" gnus-summary-catchup-all
1718   "k" gnus-summary-kill-same-subject-and-select
1719   "K" gnus-summary-kill-same-subject
1720   "P" gnus-uu-mark-map)
1721
1722 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1723   "c" gnus-summary-clear-above
1724   "u" gnus-summary-tick-above
1725   "m" gnus-summary-mark-above
1726   "k" gnus-summary-kill-below)
1727
1728 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1729   "/" gnus-summary-limit-to-subject
1730   "n" gnus-summary-limit-to-articles
1731   "w" gnus-summary-pop-limit
1732   "s" gnus-summary-limit-to-subject
1733   "a" gnus-summary-limit-to-author
1734   "u" gnus-summary-limit-to-unread
1735   "m" gnus-summary-limit-to-marks
1736   "M" gnus-summary-limit-exclude-marks
1737   "v" gnus-summary-limit-to-score
1738   "*" gnus-summary-limit-include-cached
1739   "D" gnus-summary-limit-include-dormant
1740   "T" gnus-summary-limit-include-thread
1741   "d" gnus-summary-limit-exclude-dormant
1742   "t" gnus-summary-limit-to-age
1743   "." gnus-summary-limit-to-unseen
1744   "x" gnus-summary-limit-to-extra
1745   "p" gnus-summary-limit-to-display-predicate
1746   "E" gnus-summary-limit-include-expunged
1747   "c" gnus-summary-limit-exclude-childless-dormant
1748   "C" gnus-summary-limit-mark-excluded-as-read
1749   "o" gnus-summary-insert-old-articles
1750   "N" gnus-summary-insert-new-articles)
1751
1752 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1753   "n" gnus-summary-next-unread-article
1754   "p" gnus-summary-prev-unread-article
1755   "N" gnus-summary-next-article
1756   "P" gnus-summary-prev-article
1757   "\C-n" gnus-summary-next-same-subject
1758   "\C-p" gnus-summary-prev-same-subject
1759   "\M-n" gnus-summary-next-unread-subject
1760   "\M-p" gnus-summary-prev-unread-subject
1761   "f" gnus-summary-first-unread-article
1762   "b" gnus-summary-best-unread-article
1763   "j" gnus-summary-goto-article
1764   "g" gnus-summary-goto-subject
1765   "l" gnus-summary-goto-last-article
1766   "o" gnus-summary-pop-article)
1767
1768 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1769   "k" gnus-summary-kill-thread
1770   "l" gnus-summary-lower-thread
1771   "i" gnus-summary-raise-thread
1772   "T" gnus-summary-toggle-threads
1773   "t" gnus-summary-rethread-current
1774   "^" gnus-summary-reparent-thread
1775   "s" gnus-summary-show-thread
1776   "S" gnus-summary-show-all-threads
1777   "h" gnus-summary-hide-thread
1778   "H" gnus-summary-hide-all-threads
1779   "n" gnus-summary-next-thread
1780   "p" gnus-summary-prev-thread
1781   "u" gnus-summary-up-thread
1782   "o" gnus-summary-top-thread
1783   "d" gnus-summary-down-thread
1784   "#" gnus-uu-mark-thread
1785   "\M-#" gnus-uu-unmark-thread)
1786
1787 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1788   "g" gnus-summary-prepare
1789   "c" gnus-summary-insert-cached-articles
1790   "d" gnus-summary-insert-dormant-articles)
1791
1792 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1793   "c" gnus-summary-catchup-and-exit
1794   "C" gnus-summary-catchup-all-and-exit
1795   "E" gnus-summary-exit-no-update
1796   "Q" gnus-summary-exit
1797   "Z" gnus-summary-exit
1798   "n" gnus-summary-catchup-and-goto-next-group
1799   "R" gnus-summary-reselect-current-group
1800   "G" gnus-summary-rescan-group
1801   "N" gnus-summary-next-group
1802   "s" gnus-summary-save-newsrc
1803   "P" gnus-summary-prev-group)
1804
1805 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1806   " " gnus-summary-next-page
1807   "n" gnus-summary-next-page
1808   "\177" gnus-summary-prev-page
1809   [delete] gnus-summary-prev-page
1810   "p" gnus-summary-prev-page
1811   "\r" gnus-summary-scroll-up
1812   "\M-\r" gnus-summary-scroll-down
1813   "<" gnus-summary-beginning-of-article
1814   ">" gnus-summary-end-of-article
1815   "b" gnus-summary-beginning-of-article
1816   "e" gnus-summary-end-of-article
1817   "^" gnus-summary-refer-parent-article
1818   "r" gnus-summary-refer-parent-article
1819   "D" gnus-summary-enter-digest-group
1820   "R" gnus-summary-refer-references
1821   "T" gnus-summary-refer-thread
1822   "g" gnus-summary-show-article
1823   "s" gnus-summary-isearch-article
1824   "P" gnus-summary-print-article
1825   "M" gnus-mailing-list-insinuate
1826   "t" gnus-article-babel)
1827
1828 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1829   "b" gnus-article-add-buttons
1830   "B" gnus-article-add-buttons-to-head
1831   "o" gnus-article-treat-overstrike
1832   "e" gnus-article-emphasize
1833   "w" gnus-article-fill-cited-article
1834   "Q" gnus-article-fill-long-lines
1835   "C" gnus-article-capitalize-sentences
1836   "c" gnus-article-remove-cr
1837   "q" gnus-article-de-quoted-unreadable
1838   "6" gnus-article-de-base64-unreadable
1839   "Z" gnus-article-decode-HZ
1840   "h" gnus-article-wash-html
1841   "u" gnus-article-unsplit-urls
1842   "s" gnus-summary-force-verify-and-decrypt
1843   "f" gnus-article-display-x-face
1844   "l" gnus-summary-stop-page-breaking
1845   "r" gnus-summary-caesar-message
1846   "m" gnus-summary-morse-message
1847   "t" gnus-summary-toggle-header
1848   "g" gnus-treat-smiley
1849   "v" gnus-summary-verbose-headers
1850   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1851   "p" gnus-article-verify-x-pgp-sig
1852   "d" gnus-article-treat-dumbquotes)
1853
1854 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1855   ;; mnemonic: deuglif*Y*
1856   "u" gnus-article-outlook-unwrap-lines
1857   "a" gnus-article-outlook-repair-attribution
1858   "c" gnus-article-outlook-rearrange-citation
1859   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1860
1861 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1862   "a" gnus-article-hide
1863   "h" gnus-article-hide-headers
1864   "b" gnus-article-hide-boring-headers
1865   "s" gnus-article-hide-signature
1866   "c" gnus-article-hide-citation
1867   "C" gnus-article-hide-citation-in-followups
1868   "l" gnus-article-hide-list-identifiers
1869   "B" gnus-article-strip-banner
1870   "P" gnus-article-hide-pem
1871   "\C-c" gnus-article-hide-citation-maybe)
1872
1873 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1874   "a" gnus-article-highlight
1875   "h" gnus-article-highlight-headers
1876   "c" gnus-article-highlight-citation
1877   "s" gnus-article-highlight-signature)
1878
1879 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1880   "f" gnus-article-treat-fold-headers
1881   "u" gnus-article-treat-unfold-headers
1882   "n" gnus-article-treat-fold-newsgroups)
1883
1884 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1885   "x" gnus-article-display-x-face
1886   "d" gnus-article-display-face
1887   "s" gnus-treat-smiley
1888   "D" gnus-article-remove-images
1889   "f" gnus-treat-from-picon
1890   "m" gnus-treat-mail-picon
1891   "n" gnus-treat-newsgroups-picon)
1892
1893 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1894   "w" gnus-article-decode-mime-words
1895   "c" gnus-article-decode-charset
1896   "v" gnus-mime-view-all-parts
1897   "b" gnus-article-view-part)
1898
1899 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1900   "z" gnus-article-date-ut
1901   "u" gnus-article-date-ut
1902   "l" gnus-article-date-local
1903   "p" gnus-article-date-english
1904   "e" gnus-article-date-lapsed
1905   "o" gnus-article-date-original
1906   "i" gnus-article-date-iso8601
1907   "s" gnus-article-date-user)
1908
1909 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1910   "t" gnus-article-remove-trailing-blank-lines
1911   "l" gnus-article-strip-leading-blank-lines
1912   "m" gnus-article-strip-multiple-blank-lines
1913   "a" gnus-article-strip-blank-lines
1914   "A" gnus-article-strip-all-blank-lines
1915   "s" gnus-article-strip-leading-space
1916   "e" gnus-article-strip-trailing-space
1917   "w" gnus-article-remove-leading-whitespace)
1918
1919 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1920   "v" gnus-version
1921   "f" gnus-summary-fetch-faq
1922   "d" gnus-summary-describe-group
1923   "h" gnus-summary-describe-briefly
1924   "i" gnus-info-find-node
1925   "c" gnus-group-fetch-charter
1926   "C" gnus-group-fetch-control)
1927
1928 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1929   "e" gnus-summary-expire-articles
1930   "\M-\C-e" gnus-summary-expire-articles-now
1931   "\177" gnus-summary-delete-article
1932   [delete] gnus-summary-delete-article
1933   [backspace] gnus-summary-delete-article
1934   "m" gnus-summary-move-article
1935   "r" gnus-summary-respool-article
1936   "w" gnus-summary-edit-article
1937   "c" gnus-summary-copy-article
1938   "B" gnus-summary-crosspost-article
1939   "q" gnus-summary-respool-query
1940   "t" gnus-summary-respool-trace
1941   "i" gnus-summary-import-article
1942   "I" gnus-summary-create-article
1943   "p" gnus-summary-article-posted-p)
1944
1945 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1946   "o" gnus-summary-save-article
1947   "m" gnus-summary-save-article-mail
1948   "F" gnus-summary-write-article-file
1949   "r" gnus-summary-save-article-rmail
1950   "f" gnus-summary-save-article-file
1951   "b" gnus-summary-save-article-body-file
1952   "h" gnus-summary-save-article-folder
1953   "v" gnus-summary-save-article-vm
1954   "p" gnus-summary-pipe-output
1955   "P" gnus-summary-muttprint
1956   "s" gnus-soup-add-article)
1957
1958 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1959   "b" gnus-summary-display-buttonized
1960   "m" gnus-summary-repair-multipart
1961   "v" gnus-article-view-part
1962   "o" gnus-article-save-part
1963   "c" gnus-article-copy-part
1964   "C" gnus-article-view-part-as-charset
1965   "e" gnus-article-view-part-externally
1966   "E" gnus-article-encrypt-body
1967   "i" gnus-article-inline-part
1968   "|" gnus-article-pipe-part)
1969
1970 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1971   "p" gnus-summary-mark-as-processable
1972   "u" gnus-summary-unmark-as-processable
1973   "U" gnus-summary-unmark-all-processable
1974   "v" gnus-uu-mark-over
1975   "s" gnus-uu-mark-series
1976   "r" gnus-uu-mark-region
1977   "g" gnus-uu-unmark-region
1978   "R" gnus-uu-mark-by-regexp
1979   "G" gnus-uu-unmark-by-regexp
1980   "t" gnus-uu-mark-thread
1981   "T" gnus-uu-unmark-thread
1982   "a" gnus-uu-mark-all
1983   "b" gnus-uu-mark-buffer
1984   "S" gnus-uu-mark-sparse
1985   "k" gnus-summary-kill-process-mark
1986   "y" gnus-summary-yank-process-mark
1987   "w" gnus-summary-save-process-mark
1988   "i" gnus-uu-invert-processable)
1989
1990 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1991   ;;"x" gnus-uu-extract-any
1992   "m" gnus-summary-save-parts
1993   "u" gnus-uu-decode-uu
1994   "U" gnus-uu-decode-uu-and-save
1995   "s" gnus-uu-decode-unshar
1996   "S" gnus-uu-decode-unshar-and-save
1997   "o" gnus-uu-decode-save
1998   "O" gnus-uu-decode-save
1999   "b" gnus-uu-decode-binhex
2000   "B" gnus-uu-decode-binhex
2001   "p" gnus-uu-decode-postscript
2002   "P" gnus-uu-decode-postscript-and-save)
2003
2004 (gnus-define-keys
2005     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2006   "u" gnus-uu-decode-uu-view
2007   "U" gnus-uu-decode-uu-and-save-view
2008   "s" gnus-uu-decode-unshar-view
2009   "S" gnus-uu-decode-unshar-and-save-view
2010   "o" gnus-uu-decode-save-view
2011   "O" gnus-uu-decode-save-view
2012   "b" gnus-uu-decode-binhex-view
2013   "B" gnus-uu-decode-binhex-view
2014   "p" gnus-uu-decode-postscript-view
2015   "P" gnus-uu-decode-postscript-and-save-view)
2016
2017 (defvar gnus-article-post-menu nil)
2018
2019 (defconst gnus-summary-menu-maxlen 20)
2020
2021 (defun gnus-summary-menu-split (menu)
2022   ;; If we have lots of elements, divide them into groups of 20
2023   ;; and make a pane (or submenu) for each one.
2024   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2025       (let ((menu menu) sublists next
2026             (i 1))
2027         (while menu
2028           ;; Pull off the next gnus-summary-menu-maxlen elements
2029           ;; and make them the next element of sublist.
2030           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2031           (if next
2032               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2033                       nil))
2034           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2035                                              (aref (car (last menu)) 0)) menu)
2036                                sublists))
2037           (setq i (1+ i))
2038           (setq menu next))
2039         (nreverse sublists))
2040     ;; Few elements--put them all in one pane.
2041     menu))
2042
2043 (defun gnus-summary-make-menu-bar ()
2044   (gnus-turn-off-edit-menu 'summary)
2045
2046   (unless (boundp 'gnus-summary-misc-menu)
2047
2048     (easy-menu-define
2049       gnus-summary-kill-menu gnus-summary-mode-map ""
2050       (cons
2051        "Score"
2052        (nconc
2053         (list
2054          ["Customize" gnus-score-customize t])
2055         (gnus-make-score-map 'increase)
2056         (gnus-make-score-map 'lower)
2057         '(("Mark"
2058            ["Kill below" gnus-summary-kill-below t]
2059            ["Mark above" gnus-summary-mark-above t]
2060            ["Tick above" gnus-summary-tick-above t]
2061            ["Clear above" gnus-summary-clear-above t])
2062           ["Current score" gnus-summary-current-score t]
2063           ["Set score" gnus-summary-set-score t]
2064           ["Switch current score file..." gnus-score-change-score-file t]
2065           ["Set mark below..." gnus-score-set-mark-below t]
2066           ["Set expunge below..." gnus-score-set-expunge-below t]
2067           ["Edit current score file" gnus-score-edit-current-scores t]
2068           ["Edit score file" gnus-score-edit-file t]
2069           ["Trace score" gnus-score-find-trace t]
2070           ["Find words" gnus-score-find-favourite-words t]
2071           ["Rescore buffer" gnus-summary-rescore t]
2072           ["Increase score..." gnus-summary-increase-score t]
2073           ["Lower score..." gnus-summary-lower-score t]))))
2074
2075     ;; Define both the Article menu in the summary buffer and the
2076     ;; equivalent Commands menu in the article buffer here for
2077     ;; consistency.
2078     (let ((innards
2079            `(("Hide"
2080               ["All" gnus-article-hide t]
2081               ["Headers" gnus-article-hide-headers t]
2082               ["Signature" gnus-article-hide-signature t]
2083               ["Citation" gnus-article-hide-citation t]
2084               ["List identifiers" gnus-article-hide-list-identifiers t]
2085               ["Banner" gnus-article-strip-banner t]
2086               ["Boring headers" gnus-article-hide-boring-headers t])
2087              ("Highlight"
2088               ["All" gnus-article-highlight t]
2089               ["Headers" gnus-article-highlight-headers t]
2090               ["Signature" gnus-article-highlight-signature t]
2091               ["Citation" gnus-article-highlight-citation t])
2092              ("MIME"
2093               ["Words" gnus-article-decode-mime-words t]
2094               ["Charset" gnus-article-decode-charset t]
2095               ["QP" gnus-article-de-quoted-unreadable t]
2096               ["Base64" gnus-article-de-base64-unreadable t]
2097               ["View MIME buttons" gnus-summary-display-buttonized t]
2098               ["View all" gnus-mime-view-all-parts t]
2099               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2100               ["Encrypt body" gnus-article-encrypt-body t]
2101               ["Extract all parts" gnus-summary-save-parts t]
2102               ("Multipart"
2103                ["Repair multipart" gnus-summary-repair-multipart t]
2104                ["Add buttons" gnus-summary-display-buttonized t]
2105                ["Pipe part" gnus-article-pipe-part t]
2106                ["Inline part" gnus-article-inline-part t]
2107                ["Encrypt body" gnus-article-encrypt-body t]
2108                ["View part externally" gnus-article-view-part-externally t]
2109                ["View part with charset" gnus-article-view-part-as-charset t]
2110                ["Copy part" gnus-article-copy-part t]
2111                ["Save part" gnus-article-save-part t]
2112                ["View part" gnus-article-view-part t]))
2113              ("Date"
2114               ["Local" gnus-article-date-local t]
2115               ["ISO8601" gnus-article-date-iso8601 t]
2116               ["UT" gnus-article-date-ut t]
2117               ["Original" gnus-article-date-original t]
2118               ["Lapsed" gnus-article-date-lapsed t]
2119               ["User-defined" gnus-article-date-user t])
2120              ("Display"
2121               ["Remove images" gnus-article-remove-images t]
2122               ["Toggle smiley" gnus-treat-smiley t]
2123               ["Show X-Face" gnus-article-display-x-face t]
2124               ["Show picons in From" gnus-treat-from-picon t]
2125               ["Show picons in mail headers" gnus-treat-mail-picon t]
2126               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2127               ("View as different encoding"
2128                ,@(gnus-summary-menu-split
2129                   (mapcar
2130                    (lambda (cs)
2131                      ;; Since easymenu under FSF Emacs doesn't allow lambda
2132                      ;; forms for menu commands, we should provide intern'ed
2133                      ;; function symbols.
2134                      (let ((command (intern (format "\
2135 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2136                        (fset command
2137                              `(lambda ()
2138                                 (interactive)
2139                                 (let ((gnus-summary-show-article-charset-alist
2140                                        '((1 . ,cs))))
2141                                   (gnus-summary-show-article 1))))
2142                        `[,(symbol-name cs) ,command t]))
2143                    (sort (if (fboundp 'coding-system-list)
2144                              (coding-system-list)
2145                            (mapcar 'car mm-mime-mule-charset-alist))
2146                          'string<)))))
2147              ("Washing"
2148               ("Remove Blanks"
2149                ["Leading" gnus-article-strip-leading-blank-lines t]
2150                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2151                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2152                ["All of the above" gnus-article-strip-blank-lines t]
2153                ["All" gnus-article-strip-all-blank-lines t]
2154                ["Leading space" gnus-article-strip-leading-space t]
2155                ["Trailing space" gnus-article-strip-trailing-space t]
2156                ["Leading space in headers"
2157                 gnus-article-remove-leading-whitespace t])
2158               ["Overstrike" gnus-article-treat-overstrike t]
2159               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2160               ["Emphasis" gnus-article-emphasize t]
2161               ["Word wrap" gnus-article-fill-cited-article t]
2162               ["Fill long lines" gnus-article-fill-long-lines t]
2163               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2164               ["CR" gnus-article-remove-cr t]
2165               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2166               ["Base64" gnus-article-de-base64-unreadable t]
2167               ["Rot 13" gnus-summary-caesar-message
2168                ,@(if (featurep 'xemacs) '(t)
2169                    '(:help "\"Caesar rotate\" article by 13"))]
2170               ["Morse decode" gnus-summary-morse-message t]
2171               ["Unix pipe..." gnus-summary-pipe-message t]
2172               ["Add buttons" gnus-article-add-buttons t]
2173               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2174               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2175               ["Verbose header" gnus-summary-verbose-headers t]
2176               ["Toggle header" gnus-summary-toggle-header t]
2177               ["Unfold headers" gnus-article-treat-unfold-headers t]
2178               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2179               ["Html" gnus-article-wash-html t]
2180               ["URLs" gnus-article-unsplit-urls t]
2181               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2182               ["HZ" gnus-article-decode-HZ t]
2183               ("(Outlook) Deuglify"
2184                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2185                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2186                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2187                ["Full (Outlook) deuglify"
2188                 gnus-article-outlook-deuglify-article t])
2189               )
2190              ("Output"
2191               ["Save in default format" gnus-summary-save-article
2192                ,@(if (featurep 'xemacs) '(t)
2193                    '(:help "Save article using default method"))]
2194               ["Save in file" gnus-summary-save-article-file
2195                ,@(if (featurep 'xemacs) '(t)
2196                    '(:help "Save article in file"))]
2197               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2198               ["Save in MH folder" gnus-summary-save-article-folder t]
2199               ["Save in VM folder" gnus-summary-save-article-vm t]
2200               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2201               ["Save body in file" gnus-summary-save-article-body-file t]
2202               ["Pipe through a filter" gnus-summary-pipe-output t]
2203               ["Add to SOUP packet" gnus-soup-add-article t]
2204               ["Print with Muttprint" gnus-summary-muttprint t]
2205               ["Print" gnus-summary-print-article t])
2206              ("Backend"
2207               ["Respool article..." gnus-summary-respool-article t]
2208               ["Move article..." gnus-summary-move-article
2209                (gnus-check-backend-function
2210                 'request-move-article gnus-newsgroup-name)]
2211               ["Copy article..." gnus-summary-copy-article t]
2212               ["Crosspost article..." gnus-summary-crosspost-article
2213                (gnus-check-backend-function
2214                 'request-replace-article gnus-newsgroup-name)]
2215               ["Import file..." gnus-summary-import-article t]
2216               ["Create article..." gnus-summary-create-article t]
2217               ["Check if posted" gnus-summary-article-posted-p t]
2218               ["Edit article" gnus-summary-edit-article
2219                (not (gnus-group-read-only-p))]
2220               ["Delete article" gnus-summary-delete-article
2221                (gnus-check-backend-function
2222                 'request-expire-articles gnus-newsgroup-name)]
2223               ["Query respool" gnus-summary-respool-query t]
2224               ["Trace respool" gnus-summary-respool-trace t]
2225               ["Delete expirable articles" gnus-summary-expire-articles-now
2226                (gnus-check-backend-function
2227                 'request-expire-articles gnus-newsgroup-name)])
2228              ("Extract"
2229               ["Uudecode" gnus-uu-decode-uu
2230                ,@(if (featurep 'xemacs) '(t)
2231                    '(:help "Decode uuencoded article(s)"))]
2232               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2233               ["Unshar" gnus-uu-decode-unshar t]
2234               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2235               ["Save" gnus-uu-decode-save t]
2236               ["Binhex" gnus-uu-decode-binhex t]
2237               ["Postscript" gnus-uu-decode-postscript t]
2238               ["All MIME parts" gnus-summary-save-parts t])
2239              ("Cache"
2240               ["Enter article" gnus-cache-enter-article t]
2241               ["Remove article" gnus-cache-remove-article t])
2242              ["Translate" gnus-article-babel t]
2243              ["Select article buffer" gnus-summary-select-article-buffer t]
2244              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2245              ["Isearch article..." gnus-summary-isearch-article t]
2246              ["Beginning of the article" gnus-summary-beginning-of-article t]
2247              ["End of the article" gnus-summary-end-of-article t]
2248              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2249              ["Fetch referenced articles" gnus-summary-refer-references t]
2250              ["Fetch current thread" gnus-summary-refer-thread t]
2251              ["Fetch article with id..." gnus-summary-refer-article t]
2252              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2253              ["Redisplay" gnus-summary-show-article t]
2254              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2255       (easy-menu-define
2256         gnus-summary-article-menu gnus-summary-mode-map ""
2257         (cons "Article" innards))
2258
2259       (if (not (keymapp gnus-summary-article-menu))
2260           (easy-menu-define
2261             gnus-article-commands-menu gnus-article-mode-map ""
2262             (cons "Commands" innards))
2263         ;; in Emacs, don't share menu.
2264         (setq gnus-article-commands-menu
2265               (copy-keymap gnus-summary-article-menu))
2266         (define-key gnus-article-mode-map [menu-bar commands]
2267           (cons "Commands" gnus-article-commands-menu))))
2268
2269     (easy-menu-define
2270       gnus-summary-thread-menu gnus-summary-mode-map ""
2271       '("Threads"
2272         ["Find all messages in thread" gnus-summary-refer-thread t]
2273         ["Toggle threading" gnus-summary-toggle-threads t]
2274         ["Hide threads" gnus-summary-hide-all-threads t]
2275         ["Show threads" gnus-summary-show-all-threads t]
2276         ["Hide thread" gnus-summary-hide-thread t]
2277         ["Show thread" gnus-summary-show-thread t]
2278         ["Go to next thread" gnus-summary-next-thread t]
2279         ["Go to previous thread" gnus-summary-prev-thread t]
2280         ["Go down thread" gnus-summary-down-thread t]
2281         ["Go up thread" gnus-summary-up-thread t]
2282         ["Top of thread" gnus-summary-top-thread t]
2283         ["Mark thread as read" gnus-summary-kill-thread t]
2284         ["Lower thread score" gnus-summary-lower-thread t]
2285         ["Raise thread score" gnus-summary-raise-thread t]
2286         ["Rethread current" gnus-summary-rethread-current t]))
2287
2288     (easy-menu-define
2289       gnus-summary-post-menu gnus-summary-mode-map ""
2290       `("Post"
2291         ["Send a message (mail or news)" gnus-summary-post-news
2292          ,@(if (featurep 'xemacs) '(t)
2293              '(:help "Post an article"))]
2294         ["Followup" gnus-summary-followup
2295          ,@(if (featurep 'xemacs) '(t)
2296              '(:help "Post followup to this article"))]
2297         ["Followup and yank" gnus-summary-followup-with-original
2298          ,@(if (featurep 'xemacs) '(t)
2299              '(:help "Post followup to this article, quoting its contents"))]
2300         ["Supersede article" gnus-summary-supersede-article t]
2301         ["Cancel article" gnus-summary-cancel-article
2302          ,@(if (featurep 'xemacs) '(t)
2303              '(:help "Cancel an article you posted"))]
2304         ["Reply" gnus-summary-reply t]
2305         ["Reply and yank" gnus-summary-reply-with-original t]
2306         ["Wide reply" gnus-summary-wide-reply t]
2307         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2308          ,@(if (featurep 'xemacs) '(t)
2309              '(:help "Mail a reply, quoting this article"))]
2310         ["Very wide reply" gnus-summary-very-wide-reply t]
2311         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2312          ,@(if (featurep 'xemacs) '(t)
2313              '(:help "Mail a very wide reply, quoting this article"))]
2314         ["Mail forward" gnus-summary-mail-forward t]
2315         ["Post forward" gnus-summary-post-forward t]
2316         ["Digest and mail" gnus-uu-digest-mail-forward t]
2317         ["Digest and post" gnus-uu-digest-post-forward t]
2318         ["Resend message" gnus-summary-resend-message t]
2319         ["Resend message edit" gnus-summary-resend-message-edit t]
2320         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2321         ["Send a mail" gnus-summary-mail-other-window t]
2322         ["Create a local message" gnus-summary-news-other-window t]
2323         ["Uuencode and post" gnus-uu-post-news
2324          ,@(if (featurep 'xemacs) '(t)
2325              '(:help "Post a uuencoded article"))]
2326         ["Followup via news" gnus-summary-followup-to-mail t]
2327         ["Followup via news and yank"
2328          gnus-summary-followup-to-mail-with-original t]
2329         ;;("Draft"
2330         ;;["Send" gnus-summary-send-draft t]
2331         ;;["Send bounced" gnus-resend-bounced-mail t])
2332         ))
2333
2334     (cond
2335      ((not (keymapp gnus-summary-post-menu))
2336       (setq gnus-article-post-menu gnus-summary-post-menu))
2337      ((not gnus-article-post-menu)
2338       ;; Don't share post menu.
2339       (setq gnus-article-post-menu
2340             (copy-keymap gnus-summary-post-menu))))
2341     (define-key gnus-article-mode-map [menu-bar post]
2342       (cons "Post" gnus-article-post-menu))
2343
2344     (easy-menu-define
2345       gnus-summary-misc-menu gnus-summary-mode-map ""
2346       `("Gnus"
2347         ("Mark Read"
2348          ["Mark as read" gnus-summary-mark-as-read-forward t]
2349          ["Mark same subject and select"
2350           gnus-summary-kill-same-subject-and-select t]
2351          ["Mark same subject" gnus-summary-kill-same-subject t]
2352          ["Catchup" gnus-summary-catchup
2353           ,@(if (featurep 'xemacs) '(t)
2354               '(:help "Mark unread articles in this group as read"))]
2355          ["Catchup all" gnus-summary-catchup-all t]
2356          ["Catchup to here" gnus-summary-catchup-to-here t]
2357          ["Catchup from here" gnus-summary-catchup-from-here t]
2358          ["Catchup region" gnus-summary-mark-region-as-read 
2359           (gnus-mark-active-p)]
2360          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2361         ("Mark Various"
2362          ["Tick" gnus-summary-tick-article-forward t]
2363          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2364          ["Remove marks" gnus-summary-clear-mark-forward t]
2365          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2366          ["Set bookmark" gnus-summary-set-bookmark t]
2367          ["Remove bookmark" gnus-summary-remove-bookmark t])
2368         ("Limit to"
2369          ["Marks..." gnus-summary-limit-to-marks t]
2370          ["Subject..." gnus-summary-limit-to-subject t]
2371          ["Author..." gnus-summary-limit-to-author t]
2372          ["Age..." gnus-summary-limit-to-age t]
2373          ["Extra..." gnus-summary-limit-to-extra t]
2374          ["Score..." gnus-summary-limit-to-score t]
2375          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2376          ["Unread" gnus-summary-limit-to-unread t]
2377          ["Unseen" gnus-summary-limit-to-unseen t]
2378          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2379          ["Next articles" gnus-summary-limit-to-articles t]
2380          ["Pop limit" gnus-summary-pop-limit t]
2381          ["Show dormant" gnus-summary-limit-include-dormant t]
2382          ["Hide childless dormant"
2383           gnus-summary-limit-exclude-childless-dormant t]
2384          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2385          ["Hide marked" gnus-summary-limit-exclude-marks t]
2386          ["Show expunged" gnus-summary-limit-include-expunged t])
2387         ("Process Mark"
2388          ["Set mark" gnus-summary-mark-as-processable t]
2389          ["Remove mark" gnus-summary-unmark-as-processable t]
2390          ["Remove all marks" gnus-summary-unmark-all-processable t]
2391          ["Mark above" gnus-uu-mark-over t]
2392          ["Mark series" gnus-uu-mark-series t]
2393          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2394          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2395          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2396          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2397          ["Mark all" gnus-uu-mark-all t]
2398          ["Mark buffer" gnus-uu-mark-buffer t]
2399          ["Mark sparse" gnus-uu-mark-sparse t]
2400          ["Mark thread" gnus-uu-mark-thread t]
2401          ["Unmark thread" gnus-uu-unmark-thread t]
2402          ("Process Mark Sets"
2403           ["Kill" gnus-summary-kill-process-mark t]
2404           ["Yank" gnus-summary-yank-process-mark
2405            gnus-newsgroup-process-stack]
2406           ["Save" gnus-summary-save-process-mark t]
2407           ["Run command on marked..." gnus-summary-universal-argument t]))
2408         ("Scroll article"
2409          ["Page forward" gnus-summary-next-page
2410           ,@(if (featurep 'xemacs) '(t)
2411               '(:help "Show next page of article"))]
2412          ["Page backward" gnus-summary-prev-page
2413           ,@(if (featurep 'xemacs) '(t)
2414               '(:help "Show previous page of article"))]
2415          ["Line forward" gnus-summary-scroll-up t])
2416         ("Move"
2417          ["Next unread article" gnus-summary-next-unread-article t]
2418          ["Previous unread article" gnus-summary-prev-unread-article t]
2419          ["Next article" gnus-summary-next-article t]
2420          ["Previous article" gnus-summary-prev-article t]
2421          ["Next unread subject" gnus-summary-next-unread-subject t]
2422          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2423          ["Next article same subject" gnus-summary-next-same-subject t]
2424          ["Previous article same subject" gnus-summary-prev-same-subject t]
2425          ["First unread article" gnus-summary-first-unread-article t]
2426          ["Best unread article" gnus-summary-best-unread-article t]
2427          ["Go to subject number..." gnus-summary-goto-subject t]
2428          ["Go to article number..." gnus-summary-goto-article t]
2429          ["Go to the last article" gnus-summary-goto-last-article t]
2430          ["Pop article off history" gnus-summary-pop-article t])
2431         ("Sort"
2432          ["Sort by number" gnus-summary-sort-by-number t]
2433          ["Sort by author" gnus-summary-sort-by-author t]
2434          ["Sort by subject" gnus-summary-sort-by-subject t]
2435          ["Sort by date" gnus-summary-sort-by-date t]
2436          ["Sort by score" gnus-summary-sort-by-score t]
2437          ["Sort by lines" gnus-summary-sort-by-lines t]
2438          ["Sort by characters" gnus-summary-sort-by-chars t]
2439          ["Randomize" gnus-summary-sort-by-random t]
2440          ["Original sort" gnus-summary-sort-by-original t])
2441         ("Help"
2442          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2443          ["Describe group" gnus-summary-describe-group t]
2444          ["Fetch charter" gnus-group-fetch-charter
2445           ,@(if (featurep 'xemacs) nil
2446               '(:help "Display the charter of the current group"))]
2447          ["Fetch control message" gnus-group-fetch-control
2448           ,@(if (featurep 'xemacs) nil
2449               '(:help "Display the archived control message for the current group"))]
2450          ["Read manual" gnus-info-find-node t])
2451         ("Modes"
2452          ["Pick and read" gnus-pick-mode t]
2453          ["Binary" gnus-binary-mode t])
2454         ("Regeneration"
2455          ["Regenerate" gnus-summary-prepare t]
2456          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2457          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2458          ["Toggle threading" gnus-summary-toggle-threads t])
2459         ["See old articles" gnus-summary-insert-old-articles t]
2460         ["See new articles" gnus-summary-insert-new-articles t]
2461         ["Filter articles..." gnus-summary-execute-command t]
2462         ["Run command on articles..." gnus-summary-universal-argument t]
2463         ["Search articles forward..." gnus-summary-search-article-forward t]
2464         ["Search articles backward..." gnus-summary-search-article-backward t]
2465         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2466         ["Expand window" gnus-summary-expand-window t]
2467         ["Expire expirable articles" gnus-summary-expire-articles
2468          (gnus-check-backend-function
2469           'request-expire-articles gnus-newsgroup-name)]
2470         ["Edit local kill file" gnus-summary-edit-local-kill t]
2471         ["Edit main kill file" gnus-summary-edit-global-kill t]
2472         ["Edit group parameters" gnus-summary-edit-parameters t]
2473         ["Customize group parameters" gnus-summary-customize-parameters t]
2474         ["Send a bug report" gnus-bug t]
2475         ("Exit"
2476          ["Catchup and exit" gnus-summary-catchup-and-exit
2477           ,@(if (featurep 'xemacs) '(t)
2478               '(:help "Mark unread articles in this group as read, then exit"))]
2479          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2480          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2481          ["Exit group" gnus-summary-exit
2482           ,@(if (featurep 'xemacs) '(t)
2483               '(:help "Exit current group, return to group selection mode"))]
2484          ["Exit group without updating" gnus-summary-exit-no-update t]
2485          ["Exit and goto next group" gnus-summary-next-group t]
2486          ["Exit and goto prev group" gnus-summary-prev-group t]
2487          ["Reselect group" gnus-summary-reselect-current-group t]
2488          ["Rescan group" gnus-summary-rescan-group t]
2489          ["Update dribble" gnus-summary-save-newsrc t])))
2490
2491     (gnus-run-hooks 'gnus-summary-menu-hook)))
2492
2493 (defvar gnus-summary-tool-bar-map nil)
2494
2495 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2496 (defun gnus-summary-make-tool-bar ()
2497   (if (and (fboundp 'tool-bar-add-item-from-menu)
2498            (default-value 'tool-bar-mode)
2499            (not gnus-summary-tool-bar-map))
2500       (setq gnus-summary-tool-bar-map
2501             (let ((tool-bar-map (make-sparse-keymap))
2502                   (load-path (mm-image-load-path)))
2503               (tool-bar-add-item-from-menu
2504                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2505               (tool-bar-add-item-from-menu
2506                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2507               (tool-bar-add-item-from-menu
2508                'gnus-summary-post-news "post" gnus-summary-mode-map)
2509               (tool-bar-add-item-from-menu
2510                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2511               (tool-bar-add-item-from-menu
2512                'gnus-summary-followup "followup" gnus-summary-mode-map)
2513               (tool-bar-add-item-from-menu
2514                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2515               (tool-bar-add-item-from-menu
2516                'gnus-summary-reply "reply" gnus-summary-mode-map)
2517               (tool-bar-add-item-from-menu
2518                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2519               (tool-bar-add-item-from-menu
2520                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2521               (tool-bar-add-item-from-menu
2522                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2523               (tool-bar-add-item-from-menu
2524                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2525               (tool-bar-add-item-from-menu
2526                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2527               (tool-bar-add-item-from-menu
2528                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2529               (tool-bar-add-item-from-menu
2530                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2531               (tool-bar-add-item-from-menu
2532                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2533               tool-bar-map)))
2534   (if gnus-summary-tool-bar-map
2535       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2536
2537 (defun gnus-score-set-default (var value)
2538   "A version of set that updates the GNU Emacs menu-bar."
2539   (set var value)
2540   ;; It is the message that forces the active status to be updated.
2541   (message ""))
2542
2543 (defun gnus-make-score-map (type)
2544   "Make a summary score map of type TYPE."
2545   (if t
2546       nil
2547     (let ((headers '(("author" "from" string)
2548                      ("subject" "subject" string)
2549                      ("article body" "body" string)
2550                      ("article head" "head" string)
2551                      ("xref" "xref" string)
2552                      ("extra header" "extra" string)
2553                      ("lines" "lines" number)
2554                      ("followups to author" "followup" string)))
2555           (types '((number ("less than" <)
2556                            ("greater than" >)
2557                            ("equal" =))
2558                    (string ("substring" s)
2559                            ("exact string" e)
2560                            ("fuzzy string" f)
2561                            ("regexp" r))))
2562           (perms '(("temporary" (current-time-string))
2563                    ("permanent" nil)
2564                    ("immediate" now)))
2565           header)
2566       (list
2567        (apply
2568         'nconc
2569         (list
2570          (if (eq type 'lower)
2571              "Lower score"
2572            "Increase score"))
2573         (let (outh)
2574           (while headers
2575             (setq header (car headers))
2576             (setq outh
2577                   (cons
2578                    (apply
2579                     'nconc
2580                     (list (car header))
2581                     (let ((ts (cdr (assoc (nth 2 header) types)))
2582                           outt)
2583                       (while ts
2584                         (setq outt
2585                               (cons
2586                                (apply
2587                                 'nconc
2588                                 (list (caar ts))
2589                                 (let ((ps perms)
2590                                       outp)
2591                                   (while ps
2592                                     (setq outp
2593                                           (cons
2594                                            (vector
2595                                             (caar ps)
2596                                             (list
2597                                              'gnus-summary-score-entry
2598                                              (nth 1 header)
2599                                              (if (or (string= (nth 1 header)
2600                                                               "head")
2601                                                      (string= (nth 1 header)
2602                                                               "body"))
2603                                                  ""
2604                                                (list 'gnus-summary-header
2605                                                      (nth 1 header)))
2606                                              (list 'quote (nth 1 (car ts)))
2607                                              (list 'gnus-score-delta-default
2608                                                    nil)
2609                                              (nth 1 (car ps))
2610                                              t)
2611                                             t)
2612                                            outp))
2613                                     (setq ps (cdr ps)))
2614                                   (list (nreverse outp))))
2615                                outt))
2616                         (setq ts (cdr ts)))
2617                       (list (nreverse outt))))
2618                    outh))
2619             (setq headers (cdr headers)))
2620           (list (nreverse outh))))))))
2621
2622 \f
2623
2624 (defun gnus-summary-mode (&optional group)
2625   "Major mode for reading articles.
2626
2627 All normal editing commands are switched off.
2628 \\<gnus-summary-mode-map>
2629 Each line in this buffer represents one article.  To read an
2630 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2631 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2632 respectively.
2633
2634 You can also post articles and send mail from this buffer.  To
2635 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2636 of an article, type `\\[gnus-summary-reply]'.
2637
2638 There are approx. one gazillion commands you can execute in this
2639 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2640
2641 The following commands are available:
2642
2643 \\{gnus-summary-mode-map}"
2644   (interactive)
2645   (kill-all-local-variables)
2646   (when (gnus-visual-p 'summary-menu 'menu)
2647     (gnus-summary-make-menu-bar)
2648     (gnus-summary-make-tool-bar))
2649   (gnus-summary-make-local-variables)
2650   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2651     (gnus-summary-make-local-variables))
2652   (gnus-make-thread-indent-array)
2653   (gnus-simplify-mode-line)
2654   (setq major-mode 'gnus-summary-mode)
2655   (setq mode-name "Summary")
2656   (make-local-variable 'minor-mode-alist)
2657   (use-local-map gnus-summary-mode-map)
2658   (buffer-disable-undo)
2659   (setq buffer-read-only t)             ;Disable modification
2660   (setq truncate-lines t)
2661   (setq selective-display t)
2662   (setq selective-display-ellipses t)   ;Display `...'
2663   (gnus-summary-set-display-table)
2664   (gnus-set-default-directory)
2665   (setq gnus-newsgroup-name group)
2666   (make-local-variable 'gnus-summary-line-format)
2667   (make-local-variable 'gnus-summary-line-format-spec)
2668   (make-local-variable 'gnus-summary-dummy-line-format)
2669   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2670   (make-local-variable 'gnus-summary-mark-positions)
2671   (make-local-hook 'pre-command-hook)
2672   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2673   (gnus-run-hooks 'gnus-summary-mode-hook)
2674   (turn-on-gnus-mailing-list-mode)
2675   (mm-enable-multibyte)
2676   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2677   (gnus-update-summary-mark-positions))
2678
2679 (defun gnus-summary-make-local-variables ()
2680   "Make all the local summary buffer variables."
2681   (let (global)
2682     (dolist (local gnus-summary-local-variables)
2683       (if (consp local)
2684           (progn
2685             (if (eq (cdr local) 'global)
2686                 ;; Copy the global value of the variable.
2687                 (setq global (symbol-value (car local)))
2688               ;; Use the value from the list.
2689               (setq global (eval (cdr local))))
2690             (set (make-local-variable (car local)) global))
2691         ;; Simple nil-valued local variable.
2692         (set (make-local-variable local) nil)))))
2693
2694 (defun gnus-summary-clear-local-variables ()
2695   (let ((locals gnus-summary-local-variables))
2696     (while locals
2697       (if (consp (car locals))
2698           (and (vectorp (caar locals))
2699                (set (caar locals) nil))
2700         (and (vectorp (car locals))
2701              (set (car locals) nil)))
2702       (setq locals (cdr locals)))))
2703
2704 ;; Summary data functions.
2705
2706 (defmacro gnus-data-number (data)
2707   `(car ,data))
2708
2709 (defmacro gnus-data-set-number (data number)
2710   `(setcar ,data ,number))
2711
2712 (defmacro gnus-data-mark (data)
2713   `(nth 1 ,data))
2714
2715 (defmacro gnus-data-set-mark (data mark)
2716   `(setcar (nthcdr 1 ,data) ,mark))
2717
2718 (defmacro gnus-data-pos (data)
2719   `(nth 2 ,data))
2720
2721 (defmacro gnus-data-set-pos (data pos)
2722   `(setcar (nthcdr 2 ,data) ,pos))
2723
2724 (defmacro gnus-data-header (data)
2725   `(nth 3 ,data))
2726
2727 (defmacro gnus-data-set-header (data header)
2728   `(setf (nth 3 ,data) ,header))
2729
2730 (defmacro gnus-data-level (data)
2731   `(nth 4 ,data))
2732
2733 (defmacro gnus-data-unread-p (data)
2734   `(= (nth 1 ,data) gnus-unread-mark))
2735
2736 (defmacro gnus-data-read-p (data)
2737   `(/= (nth 1 ,data) gnus-unread-mark))
2738
2739 (defmacro gnus-data-pseudo-p (data)
2740   `(consp (nth 3 ,data)))
2741
2742 (defmacro gnus-data-find (number)
2743   `(assq ,number gnus-newsgroup-data))
2744
2745 (defmacro gnus-data-find-list (number &optional data)
2746   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2747      (memq (assq ,number bdata)
2748            bdata)))
2749
2750 (defmacro gnus-data-make (number mark pos header level)
2751   `(list ,number ,mark ,pos ,header ,level))
2752
2753 (defun gnus-data-enter (after-article number mark pos header level offset)
2754   (let ((data (gnus-data-find-list after-article)))
2755     (unless data
2756       (error "No such article: %d" after-article))
2757     (setcdr data (cons (gnus-data-make number mark pos header level)
2758                        (cdr data)))
2759     (setq gnus-newsgroup-data-reverse nil)
2760     (gnus-data-update-list (cddr data) offset)))
2761
2762 (defun gnus-data-enter-list (after-article list &optional offset)
2763   (when list
2764     (let ((data (and after-article (gnus-data-find-list after-article)))
2765           (ilist list))
2766       (if (not (or data
2767                    after-article))
2768           (let ((odata gnus-newsgroup-data))
2769             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2770             (when offset
2771               (gnus-data-update-list odata offset)))
2772       ;; Find the last element in the list to be spliced into the main
2773         ;; list.
2774         (while (cdr list)
2775           (setq list (cdr list)))
2776         (if (not data)
2777             (progn
2778               (setcdr list gnus-newsgroup-data)
2779               (setq gnus-newsgroup-data ilist)
2780               (when offset
2781                 (gnus-data-update-list (cdr list) offset)))
2782           (setcdr list (cdr data))
2783           (setcdr data ilist)
2784           (when offset
2785             (gnus-data-update-list (cdr list) offset))))
2786       (setq gnus-newsgroup-data-reverse nil))))
2787
2788 (defun gnus-data-remove (article &optional offset)
2789   (let ((data gnus-newsgroup-data))
2790     (if (= (gnus-data-number (car data)) article)
2791         (progn
2792           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2793                 gnus-newsgroup-data-reverse nil)
2794           (when offset
2795             (gnus-data-update-list gnus-newsgroup-data offset)))
2796       (while (cdr data)
2797         (when (= (gnus-data-number (cadr data)) article)
2798           (setcdr data (cddr data))
2799           (when offset
2800             (gnus-data-update-list (cdr data) offset))
2801           (setq data nil
2802                 gnus-newsgroup-data-reverse nil))
2803         (setq data (cdr data))))))
2804
2805 (defmacro gnus-data-list (backward)
2806   `(if ,backward
2807        (or gnus-newsgroup-data-reverse
2808            (setq gnus-newsgroup-data-reverse
2809                  (reverse gnus-newsgroup-data)))
2810      gnus-newsgroup-data))
2811
2812 (defun gnus-data-update-list (data offset)
2813   "Add OFFSET to the POS of all data entries in DATA."
2814   (setq gnus-newsgroup-data-reverse nil)
2815   (while data
2816     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2817     (setq data (cdr data))))
2818
2819 (defun gnus-summary-article-pseudo-p (article)
2820   "Say whether this article is a pseudo article or not."
2821   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2822
2823 (defmacro gnus-summary-article-sparse-p (article)
2824   "Say whether this article is a sparse article or not."
2825   `(memq ,article gnus-newsgroup-sparse))
2826
2827 (defmacro gnus-summary-article-ancient-p (article)
2828   "Say whether this article is a sparse article or not."
2829   `(memq ,article gnus-newsgroup-ancient))
2830
2831 (defun gnus-article-parent-p (number)
2832   "Say whether this article is a parent or not."
2833   (let ((data (gnus-data-find-list number)))
2834     (and (cdr data)              ; There has to be an article after...
2835          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2836             (gnus-data-level (nth 1 data))))))
2837
2838 (defun gnus-article-children (number)
2839   "Return a list of all children to NUMBER."
2840   (let* ((data (gnus-data-find-list number))
2841          (level (gnus-data-level (car data)))
2842          children)
2843     (setq data (cdr data))
2844     (while (and data
2845                 (= (gnus-data-level (car data)) (1+ level)))
2846       (push (gnus-data-number (car data)) children)
2847       (setq data (cdr data)))
2848     children))
2849
2850 (defmacro gnus-summary-skip-intangible ()
2851   "If the current article is intangible, then jump to a different article."
2852   '(let ((to (get-text-property (point) 'gnus-intangible)))
2853      (and to (gnus-summary-goto-subject to))))
2854
2855 (defmacro gnus-summary-article-intangible-p ()
2856   "Say whether this article is intangible or not."
2857   '(get-text-property (point) 'gnus-intangible))
2858
2859 (defun gnus-article-read-p (article)
2860   "Say whether ARTICLE is read or not."
2861   (not (or (memq article gnus-newsgroup-marked)
2862            (memq article gnus-newsgroup-spam-marked)
2863            (memq article gnus-newsgroup-unreads)
2864            (memq article gnus-newsgroup-unselected)
2865            (memq article gnus-newsgroup-dormant))))
2866
2867 ;; Some summary mode macros.
2868
2869 (defmacro gnus-summary-article-number ()
2870   "The article number of the article on the current line.
2871 If there isn't an article number here, then we return the current
2872 article number."
2873   '(progn
2874      (gnus-summary-skip-intangible)
2875      (or (get-text-property (point) 'gnus-number)
2876          (gnus-summary-last-subject))))
2877
2878 (defmacro gnus-summary-article-header (&optional number)
2879   "Return the header of article NUMBER."
2880   `(gnus-data-header (gnus-data-find
2881                       ,(or number '(gnus-summary-article-number)))))
2882
2883 (defmacro gnus-summary-thread-level (&optional number)
2884   "Return the level of thread that starts with article NUMBER."
2885   `(if (and (eq gnus-summary-make-false-root 'dummy)
2886             (get-text-property (point) 'gnus-intangible))
2887        0
2888      (gnus-data-level (gnus-data-find
2889                        ,(or number '(gnus-summary-article-number))))))
2890
2891 (defmacro gnus-summary-article-mark (&optional number)
2892   "Return the mark of article NUMBER."
2893   `(gnus-data-mark (gnus-data-find
2894                     ,(or number '(gnus-summary-article-number)))))
2895
2896 (defmacro gnus-summary-article-pos (&optional number)
2897   "Return the position of the line of article NUMBER."
2898   `(gnus-data-pos (gnus-data-find
2899                    ,(or number '(gnus-summary-article-number)))))
2900
2901 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2902 (defmacro gnus-summary-article-subject (&optional number)
2903   "Return current subject string or nil if nothing."
2904   `(let ((headers
2905           ,(if number
2906                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2907              '(gnus-data-header (assq (gnus-summary-article-number)
2908                                       gnus-newsgroup-data)))))
2909      (and headers
2910           (vectorp headers)
2911           (mail-header-subject headers))))
2912
2913 (defmacro gnus-summary-article-score (&optional number)
2914   "Return current article score."
2915   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2916                   gnus-newsgroup-scored))
2917        gnus-summary-default-score 0))
2918
2919 (defun gnus-summary-article-children (&optional number)
2920   "Return a list of article numbers that are children of article NUMBER."
2921   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2922          (level (gnus-data-level (car data)))
2923          l children)
2924     (while (and (setq data (cdr data))
2925                 (> (setq l (gnus-data-level (car data))) level))
2926       (and (= (1+ level) l)
2927            (push (gnus-data-number (car data))
2928                  children)))
2929     (nreverse children)))
2930
2931 (defun gnus-summary-article-parent (&optional number)
2932   "Return the article number of the parent of article NUMBER."
2933   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2934                                     (gnus-data-list t)))
2935          (level (gnus-data-level (car data))))
2936     (if (zerop level)
2937         ()                              ; This is a root.
2938       ;; We search until we find an article with a level less than
2939       ;; this one.  That function has to be the parent.
2940       (while (and (setq data (cdr data))
2941                   (not (< (gnus-data-level (car data)) level))))
2942       (and data (gnus-data-number (car data))))))
2943
2944 (defun gnus-unread-mark-p (mark)
2945   "Say whether MARK is the unread mark."
2946   (= mark gnus-unread-mark))
2947
2948 (defun gnus-read-mark-p (mark)
2949   "Say whether MARK is one of the marks that mark as read.
2950 This is all marks except unread, ticked, dormant, and expirable."
2951   (not (or (= mark gnus-unread-mark)
2952            (= mark gnus-ticked-mark)
2953            (= mark gnus-spam-mark)
2954            (= mark gnus-dormant-mark)
2955            (= mark gnus-expirable-mark))))
2956
2957 (defmacro gnus-article-mark (number)
2958   "Return the MARK of article NUMBER.
2959 This macro should only be used when computing the mark the \"first\"
2960 time; i.e., when generating the summary lines.  After that,
2961 `gnus-summary-article-mark' should be used to examine the
2962 marks of articles."
2963   `(cond
2964     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2965     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2966     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2967     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2968     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2969     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2970     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2971     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2972            gnus-ancient-mark))))
2973
2974 ;; Saving hidden threads.
2975
2976 (defmacro gnus-save-hidden-threads (&rest forms)
2977   "Save hidden threads, eval FORMS, and restore the hidden threads."
2978   (let ((config (make-symbol "config")))
2979     `(let ((,config (gnus-hidden-threads-configuration)))
2980        (unwind-protect
2981            (save-excursion
2982              ,@forms)
2983          (gnus-restore-hidden-threads-configuration ,config)))))
2984 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2985 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2986
2987 (defun gnus-data-compute-positions ()
2988   "Compute the positions of all articles."
2989   (setq gnus-newsgroup-data-reverse nil)
2990   (let ((data gnus-newsgroup-data))
2991     (save-excursion
2992       (gnus-save-hidden-threads
2993         (gnus-summary-show-all-threads)
2994         (goto-char (point-min))
2995         (while data
2996           (while (get-text-property (point) 'gnus-intangible)
2997             (forward-line 1))
2998           (gnus-data-set-pos (car data) (+ (point) 3))
2999           (setq data (cdr data))
3000           (forward-line 1))))))
3001
3002 (defun gnus-hidden-threads-configuration ()
3003   "Return the current hidden threads configuration."
3004   (save-excursion
3005     (let (config)
3006       (goto-char (point-min))
3007       (while (search-forward "\r" nil t)
3008         (push (1- (point)) config))
3009       config)))
3010
3011 (defun gnus-restore-hidden-threads-configuration (config)
3012   "Restore hidden threads configuration from CONFIG."
3013   (save-excursion
3014     (let (point buffer-read-only)
3015       (while (setq point (pop config))
3016         (when (and (< point (point-max))
3017                    (goto-char point)
3018                    (eq (char-after) ?\n))
3019           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3020
3021 ;; Various summary mode internalish functions.
3022
3023 (defun gnus-mouse-pick-article (e)
3024   (interactive "e")
3025   (mouse-set-point e)
3026   (gnus-summary-next-page nil t))
3027
3028 (defun gnus-summary-set-display-table ()
3029   "Change the display table.
3030 Odd characters have a tendency to mess
3031 up nicely formatted displays - we make all possible glyphs
3032 display only a single character."
3033
3034   ;; We start from the standard display table, if any.
3035   (let ((table (or (copy-sequence standard-display-table)
3036                    (make-display-table)))
3037         (i 32))
3038     ;; Nix out all the control chars...
3039     (while (>= (setq i (1- i)) 0)
3040       (aset table i [??]))
3041    ;; ... but not newline and cr, of course.  (cr is necessary for the
3042     ;; selective display).
3043     (aset table ?\n nil)
3044     (aset table ?\r nil)
3045     ;; We keep TAB as well.
3046     (aset table ?\t nil)
3047     ;; We nix out any glyphs over 126 that are not set already.
3048     (let ((i 256))
3049       (while (>= (setq i (1- i)) 127)
3050         ;; Only modify if the entry is nil.
3051         (unless (aref table i)
3052           (aset table i [??]))))
3053     (setq buffer-display-table table)))
3054
3055 (defun gnus-summary-set-article-display-arrow (pos)
3056   "Update the overlay arrow to point to line at position POS."
3057   (when (and gnus-summary-display-arrow
3058              (boundp 'overlay-arrow-position)
3059              (boundp 'overlay-arrow-string))
3060     (save-excursion
3061       (goto-char pos)
3062       (beginning-of-line)
3063       (unless overlay-arrow-position
3064         (setq overlay-arrow-position (make-marker)))
3065       (setq overlay-arrow-string "=>"
3066             overlay-arrow-position (set-marker overlay-arrow-position
3067                                                (point)
3068                                                (current-buffer))))))
3069
3070 (defun gnus-summary-setup-buffer (group)
3071   "Initialize summary buffer."
3072   (let ((buffer (gnus-summary-buffer-name group))
3073         (dead-name (concat "*Dead Summary "
3074                            (gnus-group-decoded-name group) "*")))
3075     ;; If a dead summary buffer exists, we kill it.
3076     (when (gnus-buffer-live-p dead-name)
3077       (gnus-kill-buffer dead-name))
3078     (if (get-buffer buffer)
3079         (progn
3080           (set-buffer buffer)
3081           (setq gnus-summary-buffer (current-buffer))
3082           (not gnus-newsgroup-prepared))
3083       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3084       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3085       (gnus-summary-mode group)
3086       (when gnus-carpal
3087         (gnus-carpal-setup-buffer 'summary))
3088       (unless gnus-single-article-buffer
3089         (make-local-variable 'gnus-article-buffer)
3090         (make-local-variable 'gnus-article-current)
3091         (make-local-variable 'gnus-original-article-buffer))
3092       (setq gnus-newsgroup-name group)
3093       ;; Set any local variables in the group parameters.
3094       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3095       t)))
3096
3097 (defun gnus-set-global-variables ()
3098   "Set the global equivalents of the buffer-local variables.
3099 They are set to the latest values they had.  These reflect the summary
3100 buffer that was in action when the last article was fetched."
3101   (when (eq major-mode 'gnus-summary-mode)
3102     (setq gnus-summary-buffer (current-buffer))
3103     (let ((name gnus-newsgroup-name)
3104           (marked gnus-newsgroup-marked)
3105           (spam gnus-newsgroup-spam-marked)
3106           (unread gnus-newsgroup-unreads)
3107           (headers gnus-current-headers)
3108           (data gnus-newsgroup-data)
3109           (summary gnus-summary-buffer)
3110           (article-buffer gnus-article-buffer)
3111           (original gnus-original-article-buffer)
3112           (gac gnus-article-current)
3113           (reffed gnus-reffed-article-number)
3114           (score-file gnus-current-score-file)
3115           (default-charset gnus-newsgroup-charset)
3116           vlist)
3117       (let ((locals gnus-newsgroup-variables))
3118         (while locals
3119           (if (consp (car locals))
3120               (push (eval (caar locals)) vlist)
3121             (push (eval (car locals)) vlist))
3122           (setq locals (cdr locals)))
3123         (setq vlist (nreverse vlist)))
3124       (save-excursion
3125         (set-buffer gnus-group-buffer)
3126         (setq gnus-newsgroup-name name
3127               gnus-newsgroup-marked marked
3128               gnus-newsgroup-spam-marked spam
3129               gnus-newsgroup-unreads unread
3130               gnus-current-headers headers
3131               gnus-newsgroup-data data
3132               gnus-article-current gac
3133               gnus-summary-buffer summary
3134               gnus-article-buffer article-buffer
3135               gnus-original-article-buffer original
3136               gnus-reffed-article-number reffed
3137               gnus-current-score-file score-file
3138               gnus-newsgroup-charset default-charset)
3139         (let ((locals gnus-newsgroup-variables))
3140           (while locals
3141             (if (consp (car locals))
3142                 (set (caar locals) (pop vlist))
3143               (set (car locals) (pop vlist)))
3144             (setq locals (cdr locals))))
3145         ;; The article buffer also has local variables.
3146         (when (gnus-buffer-live-p gnus-article-buffer)
3147           (set-buffer gnus-article-buffer)
3148           (setq gnus-summary-buffer summary))))))
3149
3150 (defun gnus-summary-article-unread-p (article)
3151   "Say whether ARTICLE is unread or not."
3152   (memq article gnus-newsgroup-unreads))
3153
3154 (defun gnus-summary-first-article-p (&optional article)
3155   "Return whether ARTICLE is the first article in the buffer."
3156   (if (not (setq article (or article (gnus-summary-article-number))))
3157       nil
3158     (eq article (caar gnus-newsgroup-data))))
3159
3160 (defun gnus-summary-last-article-p (&optional article)
3161   "Return whether ARTICLE is the last article in the buffer."
3162   (if (not (setq article (or article (gnus-summary-article-number))))
3163       ;; All non-existent numbers are the last article.  :-)
3164       t
3165     (not (cdr (gnus-data-find-list article)))))
3166
3167 (defun gnus-make-thread-indent-array ()
3168   (let ((n 200))
3169     (unless (and gnus-thread-indent-array
3170                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3171       (setq gnus-thread-indent-array (make-vector 201 "")
3172             gnus-thread-indent-array-level gnus-thread-indent-level)
3173       (while (>= n 0)
3174         (aset gnus-thread-indent-array n
3175               (make-string (* n gnus-thread-indent-level) ? ))
3176         (setq n (1- n))))))
3177
3178 (defun gnus-update-summary-mark-positions ()
3179   "Compute where the summary marks are to go."
3180   (save-excursion
3181     (when (gnus-buffer-exists-p gnus-summary-buffer)
3182       (set-buffer gnus-summary-buffer))
3183     (let ((gnus-replied-mark 129)
3184           (gnus-score-below-mark 130)
3185           (gnus-score-over-mark 130)
3186           (gnus-undownloaded-mark 131)
3187           (spec gnus-summary-line-format-spec)
3188           gnus-visual pos)
3189       (save-excursion
3190         (gnus-set-work-buffer)
3191         (let ((gnus-summary-line-format-spec spec)
3192               (gnus-newsgroup-downloadable '(0)))
3193           (gnus-summary-insert-line
3194            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
3195            0 nil t 128 t nil "" nil 1)
3196           (goto-char (point-min))
3197           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3198                                              (- (point) (point-min) 1)))))
3199           (goto-char (point-min))
3200           (push (cons 'replied (and (search-forward "\201" nil t)
3201                                     (- (point) (point-min) 1)))
3202                 pos)
3203           (goto-char (point-min))
3204           (push (cons 'score (and (search-forward "\202" nil t)
3205                                   (- (point) (point-min) 1)))
3206                 pos)
3207           (goto-char (point-min))
3208           (push (cons 'download
3209                       (and (search-forward "\203" nil t)
3210                            (- (point) (point-min) 1)))
3211                 pos)))
3212       (setq gnus-summary-mark-positions pos))))
3213
3214 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3215   "Insert a dummy root in the summary buffer."
3216   (beginning-of-line)
3217   (gnus-add-text-properties
3218    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3219    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3220
3221 (defun gnus-summary-extract-address-component (from)
3222   (or (car (funcall gnus-extract-address-components from))
3223       from))
3224
3225 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3226   (let ((mail-parse-charset gnus-newsgroup-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         (mail-parse-ignored-charsets
3230          (save-excursion (set-buffer gnus-summary-buffer)
3231                          gnus-newsgroup-ignored-charsets)))
3232     (or
3233      (and gnus-ignored-from-addresses
3234           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3235           (let ((extra-headers (mail-header-extra header))
3236                 to
3237                 newsgroups)
3238             (cond
3239              ((setq to (cdr (assq 'To extra-headers)))
3240               (concat "-> "
3241                       (inline
3242                         (gnus-summary-extract-address-component
3243                          (funcall gnus-decode-encoded-word-function to)))))
3244              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3245               (concat "=> " newsgroups)))))
3246      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3247
3248 (defun gnus-summary-insert-line (gnus-tmp-header
3249                                  gnus-tmp-level gnus-tmp-current
3250                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3251                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3252                                  &optional gnus-tmp-dummy gnus-tmp-score
3253                                  gnus-tmp-process)
3254   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3255          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3256          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3257          (gnus-tmp-score-char
3258           (if (or (null gnus-summary-default-score)
3259                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3260                       gnus-summary-zcore-fuzz))
3261               ?                         ;Whitespace
3262             (if (< gnus-tmp-score gnus-summary-default-score)
3263                 gnus-score-below-mark gnus-score-over-mark)))
3264          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3265          (gnus-tmp-replied
3266           (cond (gnus-tmp-process gnus-process-mark)
3267                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3268                  gnus-cached-mark)
3269                 (gnus-tmp-replied gnus-replied-mark)
3270                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3271                  gnus-forwarded-mark)
3272                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3273                  gnus-saved-mark)
3274                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3275                  gnus-recent-mark)
3276                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3277                  gnus-unseen-mark)
3278                 (t gnus-no-mark)))
3279          (gnus-tmp-downloaded
3280           (cond (undownloaded 
3281                  gnus-undownloaded-mark)
3282                 (gnus-newsgroup-agentized
3283                  gnus-downloaded-mark)
3284                 (t
3285                  gnus-no-mark)))
3286          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3287          (gnus-tmp-name
3288           (cond
3289            ((string-match "<[^>]+> *$" gnus-tmp-from)
3290             (let ((beg (match-beginning 0)))
3291               (or (and (string-match "^\".+\"" gnus-tmp-from)
3292                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3293                   (substring gnus-tmp-from 0 beg))))
3294            ((string-match "(.+)" gnus-tmp-from)
3295             (substring gnus-tmp-from
3296                        (1+ (match-beginning 0)) (1- (match-end 0))))
3297            (t gnus-tmp-from)))
3298          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3299          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3300          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3301          (buffer-read-only nil))
3302     (when (string= gnus-tmp-name "")
3303       (setq gnus-tmp-name gnus-tmp-from))
3304     (unless (numberp gnus-tmp-lines)
3305       (setq gnus-tmp-lines -1))
3306     (if (= gnus-tmp-lines -1)
3307         (setq gnus-tmp-lines "?")
3308       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines))) 
3309       (gnus-put-text-property
3310      (point)
3311      (progn (eval gnus-summary-line-format-spec) (point))
3312        'gnus-number gnus-tmp-number)
3313     (when (gnus-visual-p 'summary-highlight 'highlight)
3314       (forward-line -1)
3315       (gnus-run-hooks 'gnus-summary-update-hook)
3316       (forward-line 1))))
3317
3318 (defun gnus-summary-update-line (&optional dont-update)
3319   "Update summary line after change."
3320   (when (and gnus-summary-default-score
3321              (not gnus-summary-inhibit-highlight))
3322     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3323            (article (gnus-summary-article-number))
3324            (score (gnus-summary-article-score article)))
3325       (unless dont-update
3326         (if (and gnus-summary-mark-below
3327                  (< (gnus-summary-article-score)
3328                     gnus-summary-mark-below))
3329             ;; This article has a low score, so we mark it as read.
3330             (when (memq article gnus-newsgroup-unreads)
3331               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3332           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3333             ;; This article was previously marked as read on account
3334             ;; of a low score, but now it has risen, so we mark it as
3335             ;; unread.
3336             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3337         (gnus-summary-update-mark
3338          (if (or (null gnus-summary-default-score)
3339                  (<= (abs (- score gnus-summary-default-score))
3340                      gnus-summary-zcore-fuzz))
3341              ?                          ;Whitespace
3342            (if (< score gnus-summary-default-score)
3343                gnus-score-below-mark gnus-score-over-mark))
3344          'score))
3345       ;; Do visual highlighting.
3346       (when (gnus-visual-p 'summary-highlight 'highlight)
3347         (gnus-run-hooks 'gnus-summary-update-hook)))))
3348
3349 (defvar gnus-tmp-new-adopts nil)
3350
3351 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3352   "Return the number of articles in THREAD.
3353 This may be 0 in some cases -- if none of the articles in
3354 the thread are to be displayed."
3355   (let* ((number
3356          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3357           (cond
3358            ((not (listp thread))
3359             1)
3360            ((and (consp thread) (cdr thread))
3361             (apply
3362              '+ 1 (mapcar
3363                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3364            ((null thread)
3365             1)
3366            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3367             1)
3368            (t 0))))
3369     (when (and level (zerop level) gnus-tmp-new-adopts)
3370       (incf number
3371             (apply '+ (mapcar
3372                        'gnus-summary-number-of-articles-in-thread
3373                        gnus-tmp-new-adopts))))
3374     (if char
3375         (if (> number 1) gnus-not-empty-thread-mark
3376           gnus-empty-thread-mark)
3377       number)))
3378
3379 (defsubst gnus-summary-line-message-size (head)
3380   "Return pretty-printed version of message size.
3381 This function is intended to be used in
3382 `gnus-summary-line-format-alist', which see."
3383   (let ((c (or (mail-header-chars head) -1)))
3384     (cond ((< c 0) "n/a")               ; chars not available
3385           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3386           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3387           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3388           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3389
3390
3391 (defun gnus-summary-set-local-parameters (group)
3392   "Go through the local params of GROUP and set all variable specs in that list."
3393   (let ((params (gnus-group-find-parameter group))
3394         (vars '(quit-config))           ; Ignore quit-config.
3395         elem)
3396     (while params
3397       (setq elem (car params)
3398             params (cdr params))
3399       (and (consp elem)                 ; Has to be a cons.
3400            (consp (cdr elem))           ; The cdr has to be a list.
3401            (symbolp (car elem))         ; Has to be a symbol in there.
3402            (not (memq (car elem) vars))
3403            (ignore-errors               ; So we set it.
3404              (push (car elem) vars)
3405              (make-local-variable (car elem))
3406              (set (car elem) (eval (nth 1 elem))))))))
3407
3408 (defun gnus-summary-read-group (group &optional show-all no-article
3409                                       kill-buffer no-display backward
3410                                       select-articles)
3411   "Start reading news in newsgroup GROUP.
3412 If SHOW-ALL is non-nil, already read articles are also listed.
3413 If NO-ARTICLE is non-nil, no article is selected initially.
3414 If NO-DISPLAY, don't generate a summary buffer."
3415   (let (result)
3416     (while (and group
3417                 (null (setq result
3418                             (let ((gnus-auto-select-next nil))
3419                               (or (gnus-summary-read-group-1
3420                                    group show-all no-article
3421                                    kill-buffer no-display
3422                                    select-articles)
3423                                   (setq show-all nil
3424                                         select-articles nil)))))
3425                 (eq gnus-auto-select-next 'quietly))
3426       (set-buffer gnus-group-buffer)
3427       ;; The entry function called above goes to the next
3428       ;; group automatically, so we go two groups back
3429       ;; if we are searching for the previous group.
3430       (when backward
3431         (gnus-group-prev-unread-group 2))
3432       (if (not (equal group (gnus-group-group-name)))
3433           (setq group (gnus-group-group-name))
3434         (setq group nil)))
3435     result))
3436
3437 (defun gnus-summary-read-group-1 (group show-all no-article
3438                                         kill-buffer no-display
3439                                         &optional select-articles)
3440   ;; Killed foreign groups can't be entered.
3441   ;;  (when (and (not (gnus-group-native-p group))
3442   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3443   ;;    (error "Dead non-native groups can't be entered"))
3444   (gnus-message 5 "Retrieving newsgroup: %s..."
3445                 (gnus-group-decoded-name group))
3446   (let* ((new-group (gnus-summary-setup-buffer group))
3447          (quit-config (gnus-group-quit-config group))
3448          (did-select (and new-group (gnus-select-newsgroup
3449                                      group show-all select-articles))))
3450     (cond
3451      ;; This summary buffer exists already, so we just select it.
3452      ((not new-group)
3453       (gnus-set-global-variables)
3454       (when kill-buffer
3455         (gnus-kill-or-deaden-summary kill-buffer))
3456       (gnus-configure-windows 'summary 'force)
3457       (gnus-set-mode-line 'summary)
3458       (gnus-summary-position-point)
3459       (message "")
3460       t)
3461      ;; We couldn't select this group.
3462      ((null did-select)
3463       (when (and (eq major-mode 'gnus-summary-mode)
3464                  (not (equal (current-buffer) kill-buffer)))
3465         (kill-buffer (current-buffer))
3466         (if (not quit-config)
3467             (progn
3468               ;; Update the info -- marks might need to be removed,
3469               ;; for instance.
3470               (gnus-summary-update-info)
3471               (set-buffer gnus-group-buffer)
3472               (gnus-group-jump-to-group group)
3473               (gnus-group-next-unread-group 1))
3474           (gnus-handle-ephemeral-exit quit-config)))
3475       (let ((grpinfo (gnus-get-info group)))
3476         (if (null (gnus-info-read grpinfo))
3477             (gnus-message 3 "Group %s contains no messages"
3478                           (gnus-group-decoded-name group))
3479           (gnus-message 3 "Can't select group")))
3480       nil)
3481      ;; The user did a `C-g' while prompting for number of articles,
3482      ;; so we exit this group.
3483      ((eq did-select 'quit)
3484       (and (eq major-mode 'gnus-summary-mode)
3485            (not (equal (current-buffer) kill-buffer))
3486            (kill-buffer (current-buffer)))
3487       (when kill-buffer
3488         (gnus-kill-or-deaden-summary kill-buffer))
3489       (if (not quit-config)
3490           (progn
3491             (set-buffer gnus-group-buffer)
3492             (gnus-group-jump-to-group group)
3493             (gnus-group-next-unread-group 1)
3494             (gnus-configure-windows 'group 'force))
3495         (gnus-handle-ephemeral-exit quit-config))
3496       ;; Finally signal the quit.
3497       (signal 'quit nil))
3498      ;; The group was successfully selected.
3499      (t
3500       (gnus-set-global-variables)
3501       ;; Save the active value in effect when the group was entered.
3502       (setq gnus-newsgroup-active
3503             (gnus-copy-sequence
3504              (gnus-active gnus-newsgroup-name)))
3505       ;; You can change the summary buffer in some way with this hook.
3506       (gnus-run-hooks 'gnus-select-group-hook)
3507       (gnus-update-format-specifications
3508        nil 'summary 'summary-mode 'summary-dummy)
3509       (gnus-update-summary-mark-positions)
3510       ;; Do score processing.
3511       (when gnus-use-scoring
3512         (gnus-possibly-score-headers))
3513       ;; Check whether to fill in the gaps in the threads.
3514       (when gnus-build-sparse-threads
3515         (gnus-build-sparse-threads))
3516       ;; Find the initial limit.
3517       (if gnus-show-threads
3518           (if show-all
3519               (let ((gnus-newsgroup-dormant nil))
3520                 (gnus-summary-initial-limit show-all))
3521             (gnus-summary-initial-limit show-all))
3522         ;; When unthreaded, all articles are always shown.
3523         (setq gnus-newsgroup-limit
3524               (mapcar
3525                (lambda (header) (mail-header-number header))
3526                gnus-newsgroup-headers)))
3527       ;; Generate the summary buffer.
3528       (unless no-display
3529         (gnus-summary-prepare))
3530       (when gnus-use-trees
3531         (gnus-tree-open group)
3532         (setq gnus-summary-highlight-line-function
3533               'gnus-tree-highlight-article))
3534       ;; If the summary buffer is empty, but there are some low-scored
3535       ;; articles or some excluded dormants, we include these in the
3536       ;; buffer.
3537       (when (and (zerop (buffer-size))
3538                  (not no-display))
3539         (cond (gnus-newsgroup-dormant
3540                (gnus-summary-limit-include-dormant))
3541               ((and gnus-newsgroup-scored show-all)
3542                (gnus-summary-limit-include-expunged t))))
3543       ;; Function `gnus-apply-kill-file' must be called in this hook.
3544       (gnus-run-hooks 'gnus-apply-kill-hook)
3545       (if (and (zerop (buffer-size))
3546                (not no-display))
3547           (progn
3548             ;; This newsgroup is empty.
3549             (gnus-summary-catchup-and-exit nil t)
3550             (gnus-message 6 "No unread news")
3551             (when kill-buffer
3552               (gnus-kill-or-deaden-summary kill-buffer))
3553             ;; Return nil from this function.
3554             nil)
3555         ;; Hide conversation thread subtrees.  We cannot do this in
3556         ;; gnus-summary-prepare-hook since kill processing may not
3557         ;; work with hidden articles.
3558         (gnus-summary-maybe-hide-threads)
3559         (when kill-buffer
3560           (gnus-kill-or-deaden-summary kill-buffer))
3561         (gnus-summary-auto-select-subject)
3562         ;; Show first unread article if requested.
3563         (if (and (not no-article)
3564                  (not no-display)
3565                  gnus-newsgroup-unreads
3566                  gnus-auto-select-first)
3567             (progn
3568               (gnus-configure-windows 'summary)
3569               (let ((art (gnus-summary-article-number)))
3570                 (unless (and (not gnus-plugged)
3571                              (or (memq art gnus-newsgroup-undownloaded)
3572                                  (memq art gnus-newsgroup-downloadable)))
3573                   (gnus-summary-goto-article art))))
3574           ;; Don't select any articles.
3575           (gnus-summary-position-point)
3576           (gnus-configure-windows 'summary 'force)
3577           (gnus-set-mode-line 'summary))
3578         (when (and gnus-auto-center-group
3579                    (get-buffer-window gnus-group-buffer t))
3580           ;; Gotta use windows, because recenter does weird stuff if
3581           ;; the current buffer ain't the displayed window.
3582           (let ((owin (selected-window)))
3583             (select-window (get-buffer-window gnus-group-buffer t))
3584             (when (gnus-group-goto-group group)
3585               (recenter))
3586             (select-window owin)))
3587         ;; Mark this buffer as "prepared".
3588         (setq gnus-newsgroup-prepared t)
3589         (gnus-run-hooks 'gnus-summary-prepared-hook)
3590         (unless (gnus-ephemeral-group-p group)
3591           (gnus-group-update-group group))
3592         t)))))
3593
3594 (defun gnus-summary-auto-select-subject ()
3595   "Select the subject line on initial group entry."
3596   (goto-char (point-min))
3597   (cond
3598    ((eq gnus-auto-select-subject 'best)
3599     (gnus-summary-best-unread-subject))
3600    ((eq gnus-auto-select-subject 'unread)
3601     (gnus-summary-first-unread-subject))
3602    ((eq gnus-auto-select-subject 'unseen)
3603     (gnus-summary-first-unseen-subject))
3604    ((eq gnus-auto-select-subject 'unseen-or-unread)
3605     (gnus-summary-first-unseen-or-unread-subject))
3606    ((eq gnus-auto-select-subject 'first)
3607     ;; Do nothing.
3608     )
3609    ((gnus-functionp gnus-auto-select-subject)
3610     (funcall gnus-auto-select-subject))))
3611
3612 (defun gnus-summary-prepare ()
3613   "Generate the summary buffer."
3614   (interactive)
3615   (let ((buffer-read-only nil))
3616     (erase-buffer)
3617     (setq gnus-newsgroup-data nil
3618           gnus-newsgroup-data-reverse nil)
3619     (gnus-run-hooks 'gnus-summary-generate-hook)
3620     ;; Generate the buffer, either with threads or without.
3621     (when gnus-newsgroup-headers
3622       (gnus-summary-prepare-threads
3623        (if gnus-show-threads
3624            (gnus-sort-gathered-threads
3625             (funcall gnus-summary-thread-gathering-function
3626                      (gnus-sort-threads
3627                       (gnus-cut-threads (gnus-make-threads)))))
3628          ;; Unthreaded display.
3629          (gnus-sort-articles gnus-newsgroup-headers))))
3630     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3631     ;; Call hooks for modifying summary buffer.
3632     (goto-char (point-min))
3633     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3634
3635 (defsubst gnus-general-simplify-subject (subject)
3636   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3637   (setq subject
3638         (cond
3639          ;; Truncate the subject.
3640          (gnus-simplify-subject-functions
3641           (gnus-map-function gnus-simplify-subject-functions subject))
3642          ((numberp gnus-summary-gather-subject-limit)
3643           (setq subject (gnus-simplify-subject-re subject))
3644           (if (> (length subject) gnus-summary-gather-subject-limit)
3645               (substring subject 0 gnus-summary-gather-subject-limit)
3646             subject))
3647          ;; Fuzzily simplify it.
3648          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3649           (gnus-simplify-subject-fuzzy subject))
3650          ;; Just remove the leading "Re:".
3651          (t
3652           (gnus-simplify-subject-re subject))))
3653
3654   (if (and gnus-summary-gather-exclude-subject
3655            (string-match gnus-summary-gather-exclude-subject subject))
3656       nil                         ; This article shouldn't be gathered
3657     subject))
3658
3659 (defun gnus-summary-simplify-subject-query ()
3660   "Query where the respool algorithm would put this article."
3661   (interactive)
3662   (gnus-summary-select-article)
3663   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3664
3665 (defun gnus-gather-threads-by-subject (threads)
3666   "Gather threads by looking at Subject headers."
3667   (if (not gnus-summary-make-false-root)
3668       threads
3669     (let ((hashtb (gnus-make-hashtable 1024))
3670           (prev threads)
3671           (result threads)
3672           subject hthread whole-subject)
3673       (while threads
3674         (setq subject (gnus-general-simplify-subject
3675                        (setq whole-subject (mail-header-subject
3676                                             (caar threads)))))
3677         (when subject
3678           (if (setq hthread (gnus-gethash subject hashtb))
3679               (progn
3680                 ;; We enter a dummy root into the thread, if we
3681                 ;; haven't done that already.
3682                 (unless (stringp (caar hthread))
3683                   (setcar hthread (list whole-subject (car hthread))))
3684                 ;; We add this new gathered thread to this gathered
3685                 ;; thread.
3686                 (setcdr (car hthread)
3687                         (nconc (cdar hthread) (list (car threads))))
3688                 ;; Remove it from the list of threads.
3689                 (setcdr prev (cdr threads))
3690                 (setq threads prev))
3691             ;; Enter this thread into the hash table.
3692             (gnus-sethash subject
3693                           (if gnus-summary-make-false-root-always
3694                               (progn
3695                                 ;; If you want a dummy root above all
3696                                 ;; threads...
3697                                 (setcar threads (list whole-subject
3698                                                       (car threads)))
3699                                 threads)
3700                             threads)
3701                           hashtb)))
3702         (setq prev threads)
3703         (setq threads (cdr threads)))
3704       result)))
3705
3706 (defun gnus-gather-threads-by-references (threads)
3707   "Gather threads by looking at References headers."
3708   (let ((idhashtb (gnus-make-hashtable 1024))
3709         (thhashtb (gnus-make-hashtable 1024))
3710         (prev threads)
3711         (result threads)
3712         ids references id gthread gid entered ref)
3713     (while threads
3714       (when (setq references (mail-header-references (caar threads)))
3715         (setq id (mail-header-id (caar threads))
3716               ids (inline (gnus-split-references references))
3717               entered nil)
3718         (while (setq ref (pop ids))
3719           (setq ids (delete ref ids))
3720           (if (not (setq gid (gnus-gethash ref idhashtb)))
3721               (progn
3722                 (gnus-sethash ref id idhashtb)
3723                 (gnus-sethash id threads thhashtb))
3724             (setq gthread (gnus-gethash gid thhashtb))
3725             (unless entered
3726               ;; We enter a dummy root into the thread, if we
3727               ;; haven't done that already.
3728               (unless (stringp (caar gthread))
3729                 (setcar gthread (list (mail-header-subject (caar gthread))
3730                                       (car gthread))))
3731               ;; We add this new gathered thread to this gathered
3732               ;; thread.
3733               (setcdr (car gthread)
3734                       (nconc (cdar gthread) (list (car threads)))))
3735             ;; Add it into the thread hash table.
3736             (gnus-sethash id gthread thhashtb)
3737             (setq entered t)
3738             ;; Remove it from the list of threads.
3739             (setcdr prev (cdr threads))
3740             (setq threads prev))))
3741       (setq prev threads)
3742       (setq threads (cdr threads)))
3743     result))
3744
3745 (defun gnus-sort-gathered-threads (threads)
3746   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3747   (let ((result threads))
3748     (while threads
3749       (when (stringp (caar threads))
3750         (setcdr (car threads)
3751                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3752       (setq threads (cdr threads)))
3753     result))
3754
3755 (defun gnus-thread-loop-p (root thread)
3756   "Say whether ROOT is in THREAD."
3757   (let ((stack (list thread))
3758         (infloop 0)
3759         th)
3760     (while (setq thread (pop stack))
3761       (setq th (cdr thread))
3762       (while (and th
3763                   (not (eq (caar th) root)))
3764         (pop th))
3765       (if th
3766           ;; We have found a loop.
3767           (let (ref-dep)
3768             (setcdr thread (delq (car th) (cdr thread)))
3769             (if (boundp (setq ref-dep (intern "none"
3770                                               gnus-newsgroup-dependencies)))
3771                 (setcdr (symbol-value ref-dep)
3772                         (nconc (cdr (symbol-value ref-dep))
3773                                (list (car th))))
3774               (set ref-dep (list nil (car th))))
3775             (setq infloop 1
3776                   stack nil))
3777         ;; Push all the subthreads onto the stack.
3778         (push (cdr thread) stack)))
3779     infloop))
3780
3781 (defun gnus-make-threads ()
3782   "Go through the dependency hashtb and find the roots.  Return all threads."
3783   (let (threads)
3784     (while (catch 'infloop
3785              (mapatoms
3786               (lambda (refs)
3787                 ;; Deal with self-referencing References loops.
3788                 (when (and (car (symbol-value refs))
3789                            (not (zerop
3790                                  (apply
3791                                   '+
3792                                   (mapcar
3793                                    (lambda (thread)
3794                                      (gnus-thread-loop-p
3795                                       (car (symbol-value refs)) thread))
3796                                    (cdr (symbol-value refs)))))))
3797                   (setq threads nil)
3798                   (throw 'infloop t))
3799                 (unless (car (symbol-value refs))
3800                   ;; These threads do not refer back to any other
3801                   ;; articles, so they're roots.
3802                   (setq threads (append (cdr (symbol-value refs)) threads))))
3803               gnus-newsgroup-dependencies)))
3804     threads))
3805
3806 ;; Build the thread tree.
3807 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3808   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3809
3810 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3811 if it was already present.
3812
3813 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3814 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3815 Message-IDs will be renamed to a unique Message-ID before being
3816 entered.
3817
3818 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3819   (let* ((id (mail-header-id header))
3820          (id-dep (and id (intern id dependencies)))
3821          parent-id ref ref-dep ref-header replaced)
3822     ;; Enter this `header' in the `dependencies' table.
3823     (cond
3824      ((not id-dep)
3825       (setq header nil))
3826      ;; The first two cases do the normal part: enter a new `header'
3827      ;; in the `dependencies' table.
3828      ((not (boundp id-dep))
3829       (set id-dep (list header)))
3830      ((null (car (symbol-value id-dep)))
3831       (setcar (symbol-value id-dep) header))
3832
3833      ;; From here the `header' was already present in the
3834      ;; `dependencies' table.
3835      (force-new
3836       ;; Overrides an existing entry;
3837       ;; just set the header part of the entry.
3838       (setcar (symbol-value id-dep) header)
3839       (setq replaced t))
3840
3841      ;; Renames the existing `header' to a unique Message-ID.
3842      ((not gnus-summary-ignore-duplicates)
3843       ;; An article with this Message-ID has already been seen.
3844       ;; We rename the Message-ID.
3845       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3846            (list header))
3847       (mail-header-set-id header id))
3848
3849      ;; The last case ignores an existing entry, except it adds any
3850      ;; additional Xrefs (in case the two articles came from different
3851      ;; servers.
3852      ;; Also sets `header' to `nil' meaning that the `dependencies'
3853      ;; table was *not* modified.
3854      (t
3855       (mail-header-set-xref
3856        (car (symbol-value id-dep))
3857        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3858                    "")
3859                (or (mail-header-xref header) "")))
3860       (setq header nil)))
3861
3862     (when (and header (not replaced))
3863       ;; First check that we are not creating a References loop.
3864       (setq parent-id (gnus-parent-id (mail-header-references header)))
3865       (setq ref parent-id)
3866       (while (and ref
3867                   (setq ref-dep (intern-soft ref dependencies))
3868                   (boundp ref-dep)
3869                   (setq ref-header (car (symbol-value ref-dep))))
3870         (if (string= id ref)
3871             ;; Yuk!  This is a reference loop.  Make the article be a
3872             ;; root article.
3873             (progn
3874               (mail-header-set-references (car (symbol-value id-dep)) "none")
3875               (setq ref nil)
3876               (setq parent-id nil))
3877           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3878       (setq ref-dep (intern (or parent-id "none") dependencies))
3879       (if (boundp ref-dep)
3880           (setcdr (symbol-value ref-dep)
3881                   (nconc (cdr (symbol-value ref-dep))
3882                          (list (symbol-value id-dep))))
3883         (set ref-dep (list nil (symbol-value id-dep)))))
3884     header))
3885
3886 (defun gnus-extract-message-id-from-in-reply-to (string)
3887   (if (string-match "<[^>]+>" string)
3888       (substring string (match-beginning 0) (match-end 0))
3889     nil))
3890
3891 (defun gnus-build-sparse-threads ()
3892   (let ((headers gnus-newsgroup-headers)
3893         (mail-parse-charset gnus-newsgroup-charset)
3894         (gnus-summary-ignore-duplicates t)
3895         header references generation relations
3896         subject child end new-child date)
3897     ;; First we create an alist of generations/relations, where
3898     ;; generations is how much we trust the relation, and the relation
3899     ;; is parent/child.
3900     (gnus-message 7 "Making sparse threads...")
3901     (save-excursion
3902       (nnheader-set-temp-buffer " *gnus sparse threads*")
3903       (while (setq header (pop headers))
3904         (when (and (setq references (mail-header-references header))
3905                    (not (string= references "")))
3906           (insert references)
3907           (setq child (mail-header-id header)
3908                 subject (mail-header-subject header)
3909                 date (mail-header-date header)
3910                 generation 0)
3911           (while (search-backward ">" nil t)
3912             (setq end (1+ (point)))
3913             (when (search-backward "<" nil t)
3914               (setq new-child (buffer-substring (point) end))
3915               (push (list (incf generation)
3916                           child (setq child new-child)
3917                           subject date)
3918                     relations)))
3919           (when child
3920             (push (list (1+ generation) child nil subject) relations))
3921           (erase-buffer)))
3922       (kill-buffer (current-buffer)))
3923     ;; Sort over trustworthiness.
3924     (mapcar
3925      (lambda (relation)
3926        (when (gnus-dependencies-add-header
3927               (make-full-mail-header
3928                gnus-reffed-article-number
3929                (nth 3 relation) "" (or (nth 4 relation) "")
3930                (nth 1 relation)
3931                (or (nth 2 relation) "") 0 0 "")
3932               gnus-newsgroup-dependencies nil)
3933          (push gnus-reffed-article-number gnus-newsgroup-limit)
3934          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3935          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3936                gnus-newsgroup-reads)
3937          (decf gnus-reffed-article-number)))
3938      (sort relations 'car-less-than-car))
3939     (gnus-message 7 "Making sparse threads...done")))
3940
3941 (defun gnus-build-old-threads ()
3942   ;; Look at all the articles that refer back to old articles, and
3943   ;; fetch the headers for the articles that aren't there.  This will
3944   ;; build complete threads - if the roots haven't been expired by the
3945   ;; server, that is.
3946   (let ((mail-parse-charset gnus-newsgroup-charset)
3947         id heads)
3948     (mapatoms
3949      (lambda (refs)
3950        (when (not (car (symbol-value refs)))
3951          (setq heads (cdr (symbol-value refs)))
3952          (while heads
3953            (if (memq (mail-header-number (caar heads))
3954                      gnus-newsgroup-dormant)
3955                (setq heads (cdr heads))
3956              (setq id (symbol-name refs))
3957              (while (and (setq id (gnus-build-get-header id))
3958                          (not (car (gnus-id-to-thread id)))))
3959              (setq heads nil)))))
3960      gnus-newsgroup-dependencies)))
3961
3962 ;; This function has to be called with point after the article number
3963 ;; on the beginning of the line.
3964 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3965   (let ((eol (gnus-point-at-eol))
3966         (buffer (current-buffer))
3967         header references in-reply-to)
3968
3969     ;; overview: [num subject from date id refs chars lines misc]
3970     (unwind-protect
3971         (let (x)
3972           (narrow-to-region (point) eol)
3973           (unless (eobp)
3974             (forward-char))
3975
3976           (setq header
3977                 (make-full-mail-header
3978                  number                 ; number
3979                  (condition-case ()     ; subject
3980                      (funcall gnus-decode-encoded-word-function
3981                               (setq x (nnheader-nov-field)))
3982                    (error x))
3983                  (condition-case ()     ; from
3984                      (funcall gnus-decode-encoded-word-function
3985                               (setq x (nnheader-nov-field)))
3986                    (error x))
3987                  (nnheader-nov-field)   ; date
3988                  (nnheader-nov-read-message-id) ; id
3989                  (setq references (nnheader-nov-field)) ; refs
3990                  (nnheader-nov-read-integer) ; chars
3991                  (nnheader-nov-read-integer) ; lines
3992                  (unless (eobp)
3993                    (if (looking-at "Xref: ")
3994                        (goto-char (match-end 0)))
3995                    (nnheader-nov-field)) ; Xref
3996                  (nnheader-nov-parse-extra)))) ; extra
3997
3998       (widen))
3999
4000     (when (and (string= references "")
4001                (setq in-reply-to (mail-header-extra header))
4002                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4003       (mail-header-set-references
4004        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4005
4006     (when gnus-alter-header-function
4007       (funcall gnus-alter-header-function header))
4008     (gnus-dependencies-add-header header dependencies force-new)))
4009
4010 (defun gnus-build-get-header (id)
4011   "Look through the buffer of NOV lines and find the header to ID.
4012 Enter this line into the dependencies hash table, and return
4013 the id of the parent article (if any)."
4014   (let ((deps gnus-newsgroup-dependencies)
4015         found header)
4016     (prog1
4017         (save-excursion
4018           (set-buffer nntp-server-buffer)
4019           (let ((case-fold-search nil))
4020             (goto-char (point-min))
4021             (while (and (not found)
4022                         (search-forward id nil t))
4023               (beginning-of-line)
4024               (setq found (looking-at
4025                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4026                                    (regexp-quote id))))
4027               (or found (beginning-of-line 2)))
4028             (when found
4029               (beginning-of-line)
4030               (and
4031                (setq header (gnus-nov-parse-line
4032                              (read (current-buffer)) deps))
4033                (gnus-parent-id (mail-header-references header))))))
4034       (when header
4035         (let ((number (mail-header-number header)))
4036           (push number gnus-newsgroup-limit)
4037           (push header gnus-newsgroup-headers)
4038           (if (memq number gnus-newsgroup-unselected)
4039               (progn
4040                 (setq gnus-newsgroup-unreads
4041                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4042                                                number))
4043                 (setq gnus-newsgroup-unselected
4044                       (delq number gnus-newsgroup-unselected)))
4045             (push number gnus-newsgroup-ancient)))))))
4046
4047 (defun gnus-build-all-threads ()
4048   "Read all the headers."
4049   (let ((gnus-summary-ignore-duplicates t)
4050         (mail-parse-charset gnus-newsgroup-charset)
4051         (dependencies gnus-newsgroup-dependencies)
4052         header article)
4053     (save-excursion
4054       (set-buffer nntp-server-buffer)
4055       (let ((case-fold-search nil))
4056         (goto-char (point-min))
4057         (while (not (eobp))
4058           (ignore-errors
4059             (setq article (read (current-buffer))
4060                   header (gnus-nov-parse-line article dependencies)))
4061           (when header
4062             (save-excursion
4063               (set-buffer gnus-summary-buffer)
4064               (push header gnus-newsgroup-headers)
4065               (if (memq (setq article (mail-header-number header))
4066                         gnus-newsgroup-unselected)
4067                   (progn
4068                     (setq gnus-newsgroup-unreads
4069                           (gnus-add-to-sorted-list
4070                            gnus-newsgroup-unreads article))
4071                     (setq gnus-newsgroup-unselected
4072                           (delq article gnus-newsgroup-unselected)))
4073                 (push article gnus-newsgroup-ancient)))
4074             (forward-line 1)))))))
4075
4076 (defun gnus-summary-update-article-line (article header)
4077   "Update the line for ARTICLE using HEADERS."
4078   (let* ((id (mail-header-id header))
4079          (thread (gnus-id-to-thread id)))
4080     (unless thread
4081       (error "Article in no thread"))
4082     ;; Update the thread.
4083     (setcar thread header)
4084     (gnus-summary-goto-subject article)
4085     (let* ((datal (gnus-data-find-list article))
4086            (data (car datal))
4087            (buffer-read-only nil)
4088            (level (gnus-summary-thread-level)))
4089       (gnus-delete-line)
4090       (let ((inserted (- (point)
4091                          (progn
4092                            (gnus-summary-insert-line
4093                             header level nil 
4094                             (memq article gnus-newsgroup-undownloaded)
4095                             (gnus-article-mark article)
4096                             (memq article gnus-newsgroup-replied)
4097                             (memq article gnus-newsgroup-expirable)
4098                             ;; Only insert the Subject string when it's different
4099                             ;; from the previous Subject string.
4100                             (if (and
4101                                  gnus-show-threads
4102                                  (gnus-subject-equal
4103                                   (condition-case ()
4104                                       (mail-header-subject
4105                                        (gnus-data-header
4106                                         (cadr
4107                                          (gnus-data-find-list
4108                                           article
4109                                           (gnus-data-list t)))))
4110                                     ;; Error on the side of excessive subjects.
4111                                     (error ""))
4112                                   (mail-header-subject header)))
4113                                 ""
4114                               (mail-header-subject header))
4115                             nil (cdr (assq article gnus-newsgroup-scored))
4116                             (memq article gnus-newsgroup-processable))
4117                            (point)))))
4118         (when (cdr datal)
4119           (gnus-data-update-list
4120            (cdr datal) 
4121            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4122
4123 (defun gnus-summary-update-article (article &optional iheader)
4124   "Update ARTICLE in the summary buffer."
4125   (set-buffer gnus-summary-buffer)
4126   (let* ((header (gnus-summary-article-header article))
4127          (id (mail-header-id header))
4128          (data (gnus-data-find article))
4129          (thread (gnus-id-to-thread id))
4130          (references (mail-header-references header))
4131          (parent
4132           (gnus-id-to-thread
4133            (or (gnus-parent-id
4134                 (when (and references
4135                            (not (equal "" references)))
4136                   references))
4137                "none")))
4138          (buffer-read-only nil)
4139          (old (car thread)))
4140     (when thread
4141       (unless iheader
4142         (setcar thread nil)
4143         (when parent
4144           (delq thread parent)))
4145       (if (gnus-summary-insert-subject id header)
4146           ;; Set the (possibly) new article number in the data structure.
4147           (gnus-data-set-number data (gnus-id-to-article id))
4148         (setcar thread old)
4149         nil))))
4150
4151 (defun gnus-rebuild-thread (id &optional line)
4152   "Rebuild the thread containing ID.
4153 If LINE, insert the rebuilt thread starting on line LINE."
4154   (let ((buffer-read-only nil)
4155         old-pos current thread data)
4156     (if (not gnus-show-threads)
4157         (setq thread (list (car (gnus-id-to-thread id))))
4158       ;; Get the thread this article is part of.
4159       (setq thread (gnus-remove-thread id)))
4160     (setq old-pos (gnus-point-at-bol))
4161     (setq current (save-excursion
4162                     (and (re-search-backward "[\r\n]" nil t)
4163                          (gnus-summary-article-number))))
4164     ;; If this is a gathered thread, we have to go some re-gathering.
4165     (when (stringp (car thread))
4166       (let ((subject (car thread))
4167             roots thr)
4168         (setq thread (cdr thread))
4169         (while thread
4170           (unless (memq (setq thr (gnus-id-to-thread
4171                                    (gnus-root-id
4172                                     (mail-header-id (caar thread)))))
4173                         roots)
4174             (push thr roots))
4175           (setq thread (cdr thread)))
4176         ;; We now have all (unique) roots.
4177         (if (= (length roots) 1)
4178             ;; All the loose roots are now one solid root.
4179             (setq thread (car roots))
4180           (setq thread (cons subject (gnus-sort-threads roots))))))
4181     (let (threads)
4182       ;; We then insert this thread into the summary buffer.
4183       (when line
4184         (goto-char (point-min))
4185         (forward-line (1- line)))
4186       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4187         (if gnus-show-threads
4188             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4189           (gnus-summary-prepare-unthreaded thread))
4190         (setq data (nreverse gnus-newsgroup-data))
4191         (setq threads gnus-newsgroup-threads))
4192       ;; We splice the new data into the data structure.
4193       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4194       ;;!!! then we want to insert at the beginning of the buffer.
4195       ;;!!! That happens to be true with Gnus now, but that may
4196       ;;!!! change in the future.  Perhaps.
4197       (gnus-data-enter-list
4198        (if line nil current) data (- (point) old-pos))
4199       (setq gnus-newsgroup-threads
4200             (nconc threads gnus-newsgroup-threads))
4201       (gnus-data-compute-positions))))
4202
4203 (defun gnus-number-to-header (number)
4204   "Return the header for article NUMBER."
4205   (let ((headers gnus-newsgroup-headers))
4206     (while (and headers
4207                 (not (= number (mail-header-number (car headers)))))
4208       (pop headers))
4209     (when headers
4210       (car headers))))
4211
4212 (defun gnus-parent-headers (in-headers &optional generation)
4213   "Return the headers of the GENERATIONeth parent of HEADERS."
4214   (unless generation
4215     (setq generation 1))
4216   (let ((parent t)
4217         (headers in-headers)
4218         references)
4219     (while (and parent
4220                 (not (zerop generation))
4221                 (setq references (mail-header-references headers)))
4222       (setq headers (if (and references
4223                              (setq parent (gnus-parent-id references)))
4224                         (car (gnus-id-to-thread parent))
4225                       nil))
4226       (decf generation))
4227     (and (not (eq headers in-headers))
4228          headers)))
4229
4230 (defun gnus-id-to-thread (id)
4231   "Return the (sub-)thread where ID appears."
4232   (gnus-gethash id gnus-newsgroup-dependencies))
4233
4234 (defun gnus-id-to-article (id)
4235   "Return the article number of ID."
4236   (let ((thread (gnus-id-to-thread id)))
4237     (when (and thread
4238                (car thread))
4239       (mail-header-number (car thread)))))
4240
4241 (defun gnus-id-to-header (id)
4242   "Return the article headers of ID."
4243   (car (gnus-id-to-thread id)))
4244
4245 (defun gnus-article-displayed-root-p (article)
4246   "Say whether ARTICLE is a root(ish) article."
4247   (let ((level (gnus-summary-thread-level article))
4248         (refs (mail-header-references  (gnus-summary-article-header article)))
4249         particle)
4250     (cond
4251      ((null level) nil)
4252      ((zerop level) t)
4253      ((null refs) t)
4254      ((null (gnus-parent-id refs)) t)
4255      ((and (= 1 level)
4256            (null (setq particle (gnus-id-to-article
4257                                  (gnus-parent-id refs))))
4258            (null (gnus-summary-thread-level particle)))))))
4259
4260 (defun gnus-root-id (id)
4261   "Return the id of the root of the thread where ID appears."
4262   (let (last-id prev)
4263     (while (and id (setq prev (car (gnus-id-to-thread id))))
4264       (setq last-id id
4265             id (gnus-parent-id (mail-header-references prev))))
4266     last-id))
4267
4268 (defun gnus-articles-in-thread (thread)
4269   "Return the list of articles in THREAD."
4270   (cons (mail-header-number (car thread))
4271         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4272
4273 (defun gnus-remove-thread (id &optional dont-remove)
4274   "Remove the thread that has ID in it."
4275   (let (headers thread last-id)
4276     ;; First go up in this thread until we find the root.
4277     (setq last-id (gnus-root-id id)
4278           headers (message-flatten-list (gnus-id-to-thread last-id)))
4279     ;; We have now found the real root of this thread.  It might have
4280     ;; been gathered into some loose thread, so we have to search
4281     ;; through the threads to find the thread we wanted.
4282     (let ((threads gnus-newsgroup-threads)
4283           sub)
4284       (while threads
4285         (setq sub (car threads))
4286         (if (stringp (car sub))
4287             ;; This is a gathered thread, so we look at the roots
4288             ;; below it to find whether this article is in this
4289             ;; gathered root.
4290             (progn
4291               (setq sub (cdr sub))
4292               (while sub
4293                 (when (member (caar sub) headers)
4294                   (setq thread (car threads)
4295                         threads nil
4296                         sub nil))
4297                 (setq sub (cdr sub))))
4298           ;; It's an ordinary thread, so we check it.
4299           (when (eq (car sub) (car headers))
4300             (setq thread sub
4301                   threads nil)))
4302         (setq threads (cdr threads)))
4303       ;; If this article is in no thread, then it's a root.
4304       (if thread
4305           (unless dont-remove
4306             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4307         (setq thread (gnus-id-to-thread last-id)))
4308       (when thread
4309         (prog1
4310             thread                      ; We return this thread.
4311           (unless dont-remove
4312             (if (stringp (car thread))
4313                 (progn
4314                   ;; If we use dummy roots, then we have to remove the
4315                   ;; dummy root as well.
4316                   (when (eq gnus-summary-make-false-root 'dummy)
4317                     ;; We go to the dummy root by going to
4318                     ;; the first sub-"thread", and then one line up.
4319                     (gnus-summary-goto-article
4320                      (mail-header-number (caadr thread)))
4321                     (forward-line -1)
4322                     (gnus-delete-line)
4323                     (gnus-data-compute-positions))
4324                   (setq thread (cdr thread))
4325                   (while thread
4326                     (gnus-remove-thread-1 (car thread))
4327                     (setq thread (cdr thread))))
4328               (gnus-remove-thread-1 thread))))))))
4329
4330 (defun gnus-remove-thread-1 (thread)
4331   "Remove the thread THREAD recursively."
4332   (let ((number (mail-header-number (pop thread)))
4333         d)
4334     (setq thread (reverse thread))
4335     (while thread
4336       (gnus-remove-thread-1 (pop thread)))
4337     (when (setq d (gnus-data-find number))
4338       (goto-char (gnus-data-pos d))
4339       (gnus-summary-show-thread)
4340       (gnus-data-remove
4341        number
4342        (- (gnus-point-at-bol)
4343           (prog1
4344               (1+ (gnus-point-at-eol))
4345             (gnus-delete-line)))))))
4346
4347 (defun gnus-sort-threads-1 (threads func)
4348   (sort (mapcar (lambda (thread)
4349                   (cons (car thread)
4350                         (and (cdr thread)
4351                              (gnus-sort-threads-1 (cdr thread) func))))
4352                 threads) func))
4353
4354 (defun gnus-sort-threads (threads)
4355   "Sort THREADS."
4356   (if (not gnus-thread-sort-functions)
4357       threads
4358     (gnus-message 8 "Sorting threads...")
4359     (let ((max-lisp-eval-depth 5000))
4360       (prog1 (gnus-sort-threads-1
4361          threads
4362          (gnus-make-sort-function gnus-thread-sort-functions))
4363         (gnus-message 8 "Sorting threads...done")))))
4364
4365 (defun gnus-sort-articles (articles)
4366   "Sort ARTICLES."
4367   (when gnus-article-sort-functions
4368     (gnus-message 7 "Sorting articles...")
4369     (prog1
4370         (setq gnus-newsgroup-headers
4371               (sort articles (gnus-make-sort-function
4372                               gnus-article-sort-functions)))
4373       (gnus-message 7 "Sorting articles...done"))))
4374
4375 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4376 (defmacro gnus-thread-header (thread)
4377   "Return header of first article in THREAD.
4378 Note that THREAD must never, ever be anything else than a variable -
4379 using some other form will lead to serious barfage."
4380   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4381   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4382   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4383         (vector thread) 2))
4384
4385 (defsubst gnus-article-sort-by-number (h1 h2)
4386   "Sort articles by article number."
4387   (< (mail-header-number h1)
4388      (mail-header-number h2)))
4389
4390 (defun gnus-thread-sort-by-number (h1 h2)
4391   "Sort threads by root article number."
4392   (gnus-article-sort-by-number
4393    (gnus-thread-header h1) (gnus-thread-header h2)))
4394
4395 (defsubst gnus-article-sort-by-random (h1 h2)
4396   "Sort articles by article number."
4397   (zerop (random 2)))
4398
4399 (defun gnus-thread-sort-by-random (h1 h2)
4400   "Sort threads by root article number."
4401   (gnus-article-sort-by-random
4402    (gnus-thread-header h1) (gnus-thread-header h2)))
4403
4404 (defsubst gnus-article-sort-by-lines (h1 h2)
4405   "Sort articles by article Lines header."
4406   (< (mail-header-lines h1)
4407      (mail-header-lines h2)))
4408
4409 (defun gnus-thread-sort-by-lines (h1 h2)
4410   "Sort threads by root article Lines header."
4411   (gnus-article-sort-by-lines
4412    (gnus-thread-header h1) (gnus-thread-header h2)))
4413
4414 (defsubst gnus-article-sort-by-chars (h1 h2)
4415   "Sort articles by octet length."
4416   (< (mail-header-chars h1)
4417      (mail-header-chars h2)))
4418
4419 (defun gnus-thread-sort-by-chars (h1 h2)
4420   "Sort threads by root article octet length."
4421   (gnus-article-sort-by-chars
4422    (gnus-thread-header h1) (gnus-thread-header h2)))
4423
4424 (defsubst gnus-article-sort-by-author (h1 h2)
4425   "Sort articles by root author."
4426   (string-lessp
4427    (let ((extract (funcall
4428                    gnus-extract-address-components
4429                    (mail-header-from h1))))
4430      (or (car extract) (cadr extract) ""))
4431    (let ((extract (funcall
4432                    gnus-extract-address-components
4433                    (mail-header-from h2))))
4434      (or (car extract) (cadr extract) ""))))
4435
4436 (defun gnus-thread-sort-by-author (h1 h2)
4437   "Sort threads by root author."
4438   (gnus-article-sort-by-author
4439    (gnus-thread-header h1)  (gnus-thread-header h2)))
4440
4441 (defsubst gnus-article-sort-by-subject (h1 h2)
4442   "Sort articles by root subject."
4443   (string-lessp
4444    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4445    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4446
4447 (defun gnus-thread-sort-by-subject (h1 h2)
4448   "Sort threads by root subject."
4449   (gnus-article-sort-by-subject
4450    (gnus-thread-header h1) (gnus-thread-header h2)))
4451
4452 (defsubst gnus-article-sort-by-date (h1 h2)
4453   "Sort articles by root article date."
4454   (time-less-p
4455    (gnus-date-get-time (mail-header-date h1))
4456    (gnus-date-get-time (mail-header-date h2))))
4457
4458 (defun gnus-thread-sort-by-date (h1 h2)
4459   "Sort threads by root article date."
4460   (gnus-article-sort-by-date
4461    (gnus-thread-header h1) (gnus-thread-header h2)))
4462
4463 (defsubst gnus-article-sort-by-score (h1 h2)
4464   "Sort articles by root article score.
4465 Unscored articles will be counted as having a score of zero."
4466   (> (or (cdr (assq (mail-header-number h1)
4467                     gnus-newsgroup-scored))
4468          gnus-summary-default-score 0)
4469      (or (cdr (assq (mail-header-number h2)
4470                     gnus-newsgroup-scored))
4471          gnus-summary-default-score 0)))
4472
4473 (defun gnus-thread-sort-by-score (h1 h2)
4474   "Sort threads by root article score."
4475   (gnus-article-sort-by-score
4476    (gnus-thread-header h1) (gnus-thread-header h2)))
4477
4478 (defun gnus-thread-sort-by-total-score (h1 h2)
4479   "Sort threads by the sum of all scores in the thread.
4480 Unscored articles will be counted as having a score of zero."
4481   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4482
4483 (defun gnus-thread-total-score (thread)
4484   ;; This function find the total score of THREAD.
4485   (cond
4486    ((null thread)
4487     0)
4488    ((consp thread)
4489     (if (stringp (car thread))
4490         (apply gnus-thread-score-function 0
4491                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4492       (gnus-thread-total-score-1 thread)))
4493    (t
4494     (gnus-thread-total-score-1 (list thread)))))
4495
4496 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4497   "Sort threads such that the thread with the most recently arrived article comes first."
4498   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4499
4500 (defun gnus-thread-highest-number (thread)
4501   "Return the highest article number in THREAD."
4502   (apply 'max (mapcar (lambda (header)
4503                         (mail-header-number header))
4504                       (message-flatten-list thread))))
4505
4506 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4507   "Sort threads such that the thread with the most recently dated article comes first."
4508   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4509
4510 (defun gnus-thread-latest-date (thread)
4511   "Return the highest article date in THREAD."
4512   (let ((previous-time 0))
4513     (apply 'max
4514            (mapcar
4515             (lambda (header)
4516               (setq previous-time
4517                     (time-to-seconds
4518                      (condition-case ()
4519                          (mail-header-parse-date (mail-header-date header))
4520                        (error previous-time)))))
4521             (sort
4522              (message-flatten-list thread)
4523              (lambda (h1 h2)
4524                (< (mail-header-number h1)
4525                   (mail-header-number h2))))))))
4526
4527 (defun gnus-thread-total-score-1 (root)
4528   ;; This function find the total score of the thread below ROOT.
4529   (setq root (car root))
4530   (apply gnus-thread-score-function
4531          (or (append
4532               (mapcar 'gnus-thread-total-score
4533                       (cdr (gnus-id-to-thread (mail-header-id root))))
4534               (when (> (mail-header-number root) 0)
4535                 (list (or (cdr (assq (mail-header-number root)
4536                                      gnus-newsgroup-scored))
4537                           gnus-summary-default-score 0))))
4538              (list gnus-summary-default-score)
4539              '(0))))
4540
4541 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4542 (defvar gnus-tmp-prev-subject nil)
4543 (defvar gnus-tmp-false-parent nil)
4544 (defvar gnus-tmp-root-expunged nil)
4545 (defvar gnus-tmp-dummy-line nil)
4546
4547 (eval-when-compile (defvar gnus-tmp-header))
4548 (defun gnus-extra-header (type &optional header)
4549   "Return the extra header of TYPE."
4550   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4551       ""))
4552
4553 (defvar gnus-tmp-thread-tree-header-string "")
4554
4555 (defcustom gnus-sum-thread-tree-root "> "
4556   "With %B spec, used for the root of a thread.
4557 If nil, use subject instead."
4558   :type 'string
4559   :group 'gnus-thread)
4560 (defcustom gnus-sum-thread-tree-single-indent ""
4561   "With %B spec, used for a thread with just one message.
4562 If nil, use subject instead."
4563   :type 'string
4564   :group 'gnus-thread)
4565 (defcustom gnus-sum-thread-tree-vertical "| "
4566   "With %B spec, used for drawing a vertical line."
4567   :type 'string
4568   :group 'gnus-thread)
4569 (defcustom gnus-sum-thread-tree-indent "  "
4570   "With %B spec, used for indenting."
4571   :type 'string
4572   :group 'gnus-thread)
4573 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4574   "With %B spec, used for a leaf with brothers."
4575   :type 'string
4576   :group 'gnus-thread)
4577 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4578   "With %B spec, used for a leaf without brothers."
4579   :type 'string
4580   :group 'gnus-thread)
4581
4582 (defun gnus-summary-prepare-threads (threads)
4583   "Prepare summary buffer from THREADS and indentation LEVEL.
4584 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4585 or a straight list of headers."
4586   (gnus-message 7 "Generating summary...")
4587
4588   (setq gnus-newsgroup-threads threads)
4589   (beginning-of-line)
4590
4591   (let ((gnus-tmp-level 0)
4592         (default-score (or gnus-summary-default-score 0))
4593         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4594         (building-line-count gnus-summary-display-while-building)
4595         (building-count (integerp gnus-summary-display-while-building))
4596         thread number subject stack state gnus-tmp-gathered beg-match
4597         new-roots gnus-tmp-new-adopts thread-end simp-subject
4598         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4599         gnus-tmp-replied gnus-tmp-subject-or-nil
4600         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4601         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4602         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4603         tree-stack)
4604
4605     (setq gnus-tmp-prev-subject nil
4606           gnus-tmp-thread-tree-header-string "")
4607
4608     (if (vectorp (car threads))
4609         ;; If this is a straight (sic) list of headers, then a
4610         ;; threaded summary display isn't required, so we just create
4611         ;; an unthreaded one.
4612         (gnus-summary-prepare-unthreaded threads)
4613
4614       ;; Do the threaded display.
4615
4616       (if gnus-summary-display-while-building
4617           (switch-to-buffer (buffer-name)))
4618       (while (or threads stack gnus-tmp-new-adopts new-roots)
4619
4620         (if (and (= gnus-tmp-level 0)
4621                  (or (not stack)
4622                      (= (caar stack) 0))
4623                  (not gnus-tmp-false-parent)
4624                  (or gnus-tmp-new-adopts new-roots))
4625             (if gnus-tmp-new-adopts
4626                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4627                       thread (list (car gnus-tmp-new-adopts))
4628                       gnus-tmp-header (caar thread)
4629                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4630               (when new-roots
4631                 (setq thread (list (car new-roots))
4632                       gnus-tmp-header (caar thread)
4633                       new-roots (cdr new-roots))))
4634
4635           (if threads
4636               ;; If there are some threads, we do them before the
4637               ;; threads on the stack.
4638               (setq thread threads
4639                     gnus-tmp-header (caar thread))
4640             ;; There were no current threads, so we pop something off
4641             ;; the stack.
4642             (setq state (car stack)
4643                   gnus-tmp-level (car state)
4644                   tree-stack (cadr state)
4645                   thread (caddr state)
4646                   stack (cdr stack)
4647                   gnus-tmp-header (caar thread))))
4648
4649         (setq gnus-tmp-false-parent nil)
4650         (setq gnus-tmp-root-expunged nil)
4651         (setq thread-end nil)
4652
4653         (if (stringp gnus-tmp-header)
4654             ;; The header is a dummy root.
4655             (cond
4656              ((eq gnus-summary-make-false-root 'adopt)
4657               ;; We let the first article adopt the rest.
4658               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4659                                                (cddar thread)))
4660               (setq gnus-tmp-gathered
4661                     (nconc (mapcar
4662                             (lambda (h) (mail-header-number (car h)))
4663                             (cddar thread))
4664                            gnus-tmp-gathered))
4665               (setq thread (cons (list (caar thread)
4666                                        (cadar thread))
4667                                  (cdr thread)))
4668               (setq gnus-tmp-level -1
4669                     gnus-tmp-false-parent t))
4670              ((eq gnus-summary-make-false-root 'empty)
4671               ;; We print adopted articles with empty subject fields.
4672               (setq gnus-tmp-gathered
4673                     (nconc (mapcar
4674                             (lambda (h) (mail-header-number (car h)))
4675                             (cddar thread))
4676                            gnus-tmp-gathered))
4677               (setq gnus-tmp-level -1))
4678              ((eq gnus-summary-make-false-root 'dummy)
4679               ;; We remember that we probably want to output a dummy
4680               ;; root.
4681               (setq gnus-tmp-dummy-line gnus-tmp-header)
4682               (setq gnus-tmp-prev-subject gnus-tmp-header))
4683              (t
4684               ;; We do not make a root for the gathered
4685               ;; sub-threads at all.
4686               (setq gnus-tmp-level -1)))
4687
4688           (setq number (mail-header-number gnus-tmp-header)
4689                 subject (mail-header-subject gnus-tmp-header)
4690                 simp-subject (gnus-simplify-subject-fully subject))
4691
4692           (cond
4693            ;; If the thread has changed subject, we might want to make
4694            ;; this subthread into a root.
4695            ((and (null gnus-thread-ignore-subject)
4696                  (not (zerop gnus-tmp-level))
4697                  gnus-tmp-prev-subject
4698                  (not (string= gnus-tmp-prev-subject simp-subject)))
4699             (setq new-roots (nconc new-roots (list (car thread)))
4700                   thread-end t
4701                   gnus-tmp-header nil))
4702            ;; If the article lies outside the current limit,
4703            ;; then we do not display it.
4704            ((not (memq number gnus-newsgroup-limit))
4705             (setq gnus-tmp-gathered
4706                   (nconc (mapcar
4707                           (lambda (h) (mail-header-number (car h)))
4708                           (cdar thread))
4709                          gnus-tmp-gathered))
4710             (setq gnus-tmp-new-adopts (if (cdar thread)
4711                                           (append gnus-tmp-new-adopts
4712                                                   (cdar thread))
4713                                         gnus-tmp-new-adopts)
4714                   thread-end t
4715                   gnus-tmp-header nil)
4716             (when (zerop gnus-tmp-level)
4717               (setq gnus-tmp-root-expunged t)))
4718            ;; Perhaps this article is to be marked as read?
4719            ((and gnus-summary-mark-below
4720                  (< (or (cdr (assq number gnus-newsgroup-scored))
4721                         default-score)
4722                     gnus-summary-mark-below)
4723                  ;; Don't touch sparse articles.
4724                  (not (gnus-summary-article-sparse-p number))
4725                  (not (gnus-summary-article-ancient-p number)))
4726             (setq gnus-newsgroup-unreads
4727                   (delq number gnus-newsgroup-unreads))
4728             (if gnus-newsgroup-auto-expire
4729                 (setq gnus-newsgroup-expirable
4730                       (gnus-add-to-sorted-list
4731                        gnus-newsgroup-expirable number))
4732               (push (cons number gnus-low-score-mark)
4733                     gnus-newsgroup-reads))))
4734
4735           (when gnus-tmp-header
4736             ;; We may have an old dummy line to output before this
4737             ;; article.
4738             (when (and gnus-tmp-dummy-line
4739                        (gnus-subject-equal
4740                         gnus-tmp-dummy-line
4741                         (mail-header-subject gnus-tmp-header)))
4742               (gnus-summary-insert-dummy-line
4743                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4744               (setq gnus-tmp-dummy-line nil))
4745
4746             ;; Compute the mark.
4747             (setq gnus-tmp-unread (gnus-article-mark number))
4748
4749             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4750                                   gnus-tmp-header gnus-tmp-level)
4751                   gnus-newsgroup-data)
4752
4753             ;; Actually insert the line.
4754             (setq
4755              gnus-tmp-subject-or-nil
4756              (cond
4757               ((and gnus-thread-ignore-subject
4758                     gnus-tmp-prev-subject
4759                     (not (string= gnus-tmp-prev-subject simp-subject)))
4760                subject)
4761               ((zerop gnus-tmp-level)
4762                (if (and (eq gnus-summary-make-false-root 'empty)
4763                         (memq number gnus-tmp-gathered)
4764                         gnus-tmp-prev-subject
4765                         (string= gnus-tmp-prev-subject simp-subject))
4766                    gnus-summary-same-subject
4767                  subject))
4768               (t gnus-summary-same-subject)))
4769             (if (and (eq gnus-summary-make-false-root 'adopt)
4770                      (= gnus-tmp-level 1)
4771                      (memq number gnus-tmp-gathered))
4772                 (setq gnus-tmp-opening-bracket ?\<
4773                       gnus-tmp-closing-bracket ?\>)
4774               (setq gnus-tmp-opening-bracket ?\[
4775                     gnus-tmp-closing-bracket ?\]))
4776             (setq
4777              gnus-tmp-indentation
4778              (aref gnus-thread-indent-array gnus-tmp-level)
4779              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4780              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4781                                 gnus-summary-default-score 0)
4782              gnus-tmp-score-char
4783              (if (or (null gnus-summary-default-score)
4784                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4785                          gnus-summary-zcore-fuzz))
4786                  ?                      ;Whitespace
4787                (if (< gnus-tmp-score gnus-summary-default-score)
4788                    gnus-score-below-mark gnus-score-over-mark))
4789              gnus-tmp-replied
4790              (cond ((memq number gnus-newsgroup-processable)
4791                     gnus-process-mark)
4792                    ((memq number gnus-newsgroup-cached)
4793                     gnus-cached-mark)
4794                    ((memq number gnus-newsgroup-replied)
4795                     gnus-replied-mark)
4796                    ((memq number gnus-newsgroup-forwarded)
4797                     gnus-forwarded-mark)
4798                    ((memq number gnus-newsgroup-saved)
4799                     gnus-saved-mark)
4800                    ((memq number gnus-newsgroup-recent)
4801                     gnus-recent-mark)
4802                    ((memq number gnus-newsgroup-unseen)
4803                     gnus-unseen-mark)
4804                    (t gnus-no-mark))
4805              gnus-tmp-downloaded
4806              (cond ((memq number gnus-newsgroup-undownloaded) 
4807                     gnus-undownloaded-mark)
4808                    (gnus-newsgroup-agentized
4809                     gnus-downloaded-mark)
4810                    (t
4811                     gnus-no-mark))
4812              gnus-tmp-from (mail-header-from gnus-tmp-header)
4813              gnus-tmp-name
4814              (cond
4815               ((string-match "<[^>]+> *$" gnus-tmp-from)
4816                (setq beg-match (match-beginning 0))
4817                (or (and (string-match "^\".+\"" gnus-tmp-from)
4818                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4819                    (substring gnus-tmp-from 0 beg-match)))
4820               ((string-match "(.+)" gnus-tmp-from)
4821                (substring gnus-tmp-from
4822                           (1+ (match-beginning 0)) (1- (match-end 0))))
4823               (t gnus-tmp-from))
4824
4825              ;; Do the %B string
4826              gnus-tmp-thread-tree-header-string
4827              (cond
4828               ((not gnus-show-threads) "")
4829               ((zerop gnus-tmp-level)
4830                (if (cdar thread)
4831                    (or gnus-sum-thread-tree-root subject)
4832                  (or gnus-sum-thread-tree-single-indent subject)))
4833               (t
4834                (concat (apply 'concat
4835                               (mapcar (lambda (item)
4836                                         (if (= item 1)
4837                                             gnus-sum-thread-tree-vertical
4838                                           gnus-sum-thread-tree-indent))
4839                                       (cdr (reverse tree-stack))))
4840                        (if (nth 1 thread)
4841                            gnus-sum-thread-tree-leaf-with-other
4842                          gnus-sum-thread-tree-single-leaf)))))
4843             (when (string= gnus-tmp-name "")
4844               (setq gnus-tmp-name gnus-tmp-from))
4845             (unless (numberp gnus-tmp-lines)
4846               (setq gnus-tmp-lines -1))
4847             (if (= gnus-tmp-lines -1)
4848                 (setq gnus-tmp-lines "?")
4849               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4850               (gnus-put-text-property
4851              (point)
4852              (progn (eval gnus-summary-line-format-spec) (point))
4853                'gnus-number number)
4854             (when gnus-visual-p
4855               (forward-line -1)
4856               (gnus-run-hooks 'gnus-summary-update-hook)
4857               (forward-line 1))
4858
4859             (setq gnus-tmp-prev-subject simp-subject)))
4860
4861         (when (nth 1 thread)
4862           (push (list (max 0 gnus-tmp-level)
4863                       (copy-list tree-stack)
4864                       (nthcdr 1 thread))
4865                 stack))
4866         (push (if (nth 1 thread) 1 0) tree-stack)
4867         (incf gnus-tmp-level)
4868         (setq threads (if thread-end nil (cdar thread)))
4869         (if gnus-summary-display-while-building
4870             (if building-count
4871                 (progn
4872                   ;; use a set frequency
4873                   (setq building-line-count (1- building-line-count))
4874                   (when (= building-line-count 0)
4875                     (sit-for 0)
4876                     (setq building-line-count
4877                           gnus-summary-display-while-building)))
4878               ;; always
4879               (sit-for 0)))
4880         (unless threads
4881           (setq gnus-tmp-level 0)))))
4882   (gnus-message 7 "Generating summary...done"))
4883
4884 (defun gnus-summary-prepare-unthreaded (headers)
4885   "Generate an unthreaded summary buffer based on HEADERS."
4886   (let (header number mark)
4887
4888     (beginning-of-line)
4889
4890     (while headers
4891       ;; We may have to root out some bad articles...
4892       (when (memq (setq number (mail-header-number
4893                                 (setq header (pop headers))))
4894                   gnus-newsgroup-limit)
4895         ;; Mark article as read when it has a low score.
4896         (when (and gnus-summary-mark-below
4897                    (< (or (cdr (assq number gnus-newsgroup-scored))
4898                           gnus-summary-default-score 0)
4899                       gnus-summary-mark-below)
4900                    (not (gnus-summary-article-ancient-p number)))
4901           (setq gnus-newsgroup-unreads
4902                 (delq number gnus-newsgroup-unreads))
4903           (if gnus-newsgroup-auto-expire
4904               (push number gnus-newsgroup-expirable)
4905             (push (cons number gnus-low-score-mark)
4906                   gnus-newsgroup-reads)))
4907
4908         (setq mark (gnus-article-mark number))
4909         (push (gnus-data-make number mark (1+ (point)) header 0)
4910               gnus-newsgroup-data)
4911         (gnus-summary-insert-line
4912          header 0 number
4913          (memq number gnus-newsgroup-undownloaded)
4914          mark (memq number gnus-newsgroup-replied)
4915          (memq number gnus-newsgroup-expirable)
4916          (mail-header-subject header) nil
4917          (cdr (assq number gnus-newsgroup-scored))
4918          (memq number gnus-newsgroup-processable))))))
4919
4920 (defun gnus-summary-remove-list-identifiers ()
4921   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4922   (let ((regexp (if (consp gnus-list-identifiers)
4923                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4924                   gnus-list-identifiers))
4925         changed subject)
4926     (when regexp
4927       (dolist (header gnus-newsgroup-headers)
4928         (setq subject (mail-header-subject header)
4929               changed nil)
4930         (while (string-match
4931                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4932                 subject)
4933           (setq subject
4934                 (concat (substring subject 0 (match-beginning 2))
4935                         (substring subject (match-end 0)))
4936                 changed t))
4937         (when (and changed
4938                    (string-match
4939                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4940           (setq subject
4941                 (concat (substring subject 0 (match-beginning 1))
4942                         (substring subject (match-end 1)))))
4943         (when changed
4944           (mail-header-set-subject header subject))))))
4945
4946 (defun gnus-fetch-headers (articles)
4947   "Fetch headers of ARTICLES."
4948   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4949     (gnus-message 5 "Fetching headers for %s..." name)
4950     (prog1
4951         (if (eq 'nov
4952                 (setq gnus-headers-retrieved-by
4953                       (gnus-retrieve-headers
4954                        articles gnus-newsgroup-name
4955                        ;; We might want to fetch old headers, but
4956                        ;; not if there is only 1 article.
4957                        (and (or (and
4958                                  (not (eq gnus-fetch-old-headers 'some))
4959                                  (not (numberp gnus-fetch-old-headers)))
4960                                 (> (length articles) 1))
4961                             gnus-fetch-old-headers))))
4962             (gnus-get-newsgroup-headers-xover
4963              articles nil nil gnus-newsgroup-name t)
4964           (gnus-get-newsgroup-headers))
4965       (gnus-message 5 "Fetching headers for %s...done" name))))
4966
4967 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4968   "Select newsgroup GROUP.
4969 If READ-ALL is non-nil, all articles in the group are selected.
4970 If SELECT-ARTICLES, only select those articles from GROUP."
4971   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4972          ;;!!! Dirty hack; should be removed.
4973          (gnus-summary-ignore-duplicates
4974           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4975               t
4976             gnus-summary-ignore-duplicates))
4977          (info (nth 2 entry))
4978          articles fetched-articles cached)
4979
4980     (unless (gnus-check-server
4981              (set (make-local-variable 'gnus-current-select-method)
4982                   (gnus-find-method-for-group group)))
4983       (error "Couldn't open server"))
4984
4985     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4986         (gnus-activate-group group)     ; Or we can activate it...
4987         (progn                          ; Or we bug out.
4988           (when (equal major-mode 'gnus-summary-mode)
4989             (gnus-kill-buffer (current-buffer)))
4990           (error "Couldn't activate group %s: %s"
4991                  group (gnus-status-message group))))
4992
4993     (unless (gnus-request-group group t)
4994       (when (equal major-mode 'gnus-summary-mode)
4995         (gnus-kill-buffer (current-buffer)))
4996       (error "Couldn't request group %s: %s"
4997              group (gnus-status-message group)))
4998
4999     (when gnus-agent
5000       ;; The agent may be storing articles that are no longer in the
5001       ;; server's active range.  If that is the case, the active range
5002       ;; needs to be expanded such that the agent's articles can be
5003       ;; included in the summary.
5004       (let* ((gnus-command-method (gnus-find-method-for-group group))
5005              (alist (gnus-agent-load-alist group))
5006              (active (gnus-active group)))
5007         (if (and (car alist)
5008                  (< (caar alist) (car active)))
5009             (gnus-set-active group (cons (caar alist) (cdr active))))))
5010
5011     (setq gnus-newsgroup-name group
5012           gnus-newsgroup-unselected nil
5013           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5014
5015     (let ((display (gnus-group-find-parameter group 'display)))
5016       (setq gnus-newsgroup-display
5017             (cond
5018              ((not (zerop (or (car-safe read-all) 0)))
5019               ;; The user entered the group with C-u SPC/RET, let's show
5020               ;; all articles.
5021               'gnus-not-ignore)
5022              ((eq display 'all)
5023               'gnus-not-ignore)
5024              ((arrayp display)
5025               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5026              ((numberp display)
5027               ;; The following is probably the "correct" solution, but
5028               ;; it makes Gnus fetch all headers and then limit the
5029               ;; articles (which is slow), so instead we hack the
5030               ;; select-articles parameter instead. -- Simon Josefsson
5031               ;; <jas@kth.se>
5032               ;;
5033               ;; (gnus-byte-compile
5034               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5035               ;;                         display)))))
5036               (setq select-articles
5037                     (gnus-uncompress-range
5038                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5039                              (if (> tmp 0)
5040                                  tmp
5041                                1))
5042                            (cdr (gnus-active group)))))
5043               nil)
5044              (t
5045               nil))))
5046
5047     (gnus-summary-setup-default-charset)
5048
5049     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5050     (when (gnus-virtual-group-p group)
5051       (setq cached gnus-newsgroup-cached))
5052
5053     (setq gnus-newsgroup-unreads
5054           (gnus-sorted-ndifference
5055            (gnus-sorted-ndifference gnus-newsgroup-unreads
5056                                     gnus-newsgroup-marked)
5057            gnus-newsgroup-dormant))
5058
5059     (setq gnus-newsgroup-processable nil)
5060
5061     (gnus-update-read-articles group gnus-newsgroup-unreads)
5062
5063     ;; Adjust and set lists of article marks.
5064     (when info
5065       (gnus-adjust-marked-articles info))
5066     (if (setq articles select-articles)
5067         (setq gnus-newsgroup-unselected
5068               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5069       (setq articles (gnus-articles-to-read group read-all)))
5070
5071     (cond
5072      ((null articles)
5073       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5074       'quit)
5075      ((eq articles 0) nil)
5076      (t
5077       ;; Init the dependencies hash table.
5078       (setq gnus-newsgroup-dependencies
5079             (gnus-make-hashtable (length articles)))
5080       (gnus-set-global-variables)
5081       ;; Retrieve the headers and read them in.
5082
5083       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5084
5085       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5086       (when cached
5087         (setq gnus-newsgroup-cached cached))
5088
5089       ;; Suppress duplicates?
5090       (when gnus-suppress-duplicates
5091         (gnus-dup-suppress-articles))
5092
5093       ;; Set the initial limit.
5094       (setq gnus-newsgroup-limit (copy-sequence articles))
5095       ;; Remove canceled articles from the list of unread articles.
5096       (setq fetched-articles
5097             (mapcar (lambda (headers) (mail-header-number headers))
5098                     gnus-newsgroup-headers))
5099       (setq gnus-newsgroup-articles fetched-articles)
5100       (setq gnus-newsgroup-unreads
5101             (gnus-sorted-nintersection
5102              gnus-newsgroup-unreads fetched-articles))
5103       (gnus-compute-unseen-list)
5104
5105       ;; Removed marked articles that do not exist.
5106       (gnus-update-missing-marks
5107        (gnus-sorted-difference articles fetched-articles))
5108       ;; We might want to build some more threads first.
5109       (when (and gnus-fetch-old-headers
5110                  (eq gnus-headers-retrieved-by 'nov))
5111         (if (eq gnus-fetch-old-headers 'invisible)
5112             (gnus-build-all-threads)
5113           (gnus-build-old-threads)))
5114       ;; Let the Gnus agent mark articles as read.
5115       (when gnus-agent
5116         (gnus-agent-get-undownloaded-list))
5117       ;; Remove list identifiers from subject
5118       (when gnus-list-identifiers
5119         (gnus-summary-remove-list-identifiers))
5120       ;; Check whether auto-expire is to be done in this group.
5121       (setq gnus-newsgroup-auto-expire
5122             (gnus-group-auto-expirable-p group))
5123       ;; Set up the article buffer now, if necessary.
5124       (unless gnus-single-article-buffer
5125         (gnus-article-setup-buffer))
5126       ;; First and last article in this newsgroup.
5127       (when gnus-newsgroup-headers
5128         (setq gnus-newsgroup-begin
5129               (mail-header-number (car gnus-newsgroup-headers))
5130               gnus-newsgroup-end
5131               (mail-header-number
5132                (gnus-last-element gnus-newsgroup-headers))))
5133       ;; GROUP is successfully selected.
5134       (or gnus-newsgroup-headers t)))))
5135
5136 (defun gnus-compute-unseen-list ()
5137   ;; The `seen' marks are treated specially.
5138   (if (not gnus-newsgroup-seen)
5139       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5140     (setq gnus-newsgroup-unseen
5141           (gnus-inverse-list-range-intersection
5142            gnus-newsgroup-articles gnus-newsgroup-seen))))
5143
5144 (defun gnus-summary-display-make-predicate (display)
5145   (require 'gnus-agent)
5146   (when (= (length display) 1)
5147     (setq display (car display)))
5148   (unless gnus-summary-display-cache
5149     (dolist (elem (append '((unread . unread)
5150                             (read . read)
5151                             (unseen . unseen))
5152                           gnus-article-mark-lists))
5153       (push (cons (cdr elem)
5154                   (gnus-byte-compile
5155                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5156             gnus-summary-display-cache)))
5157   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5158         (gnus-category-predicate-cache gnus-summary-display-cache))
5159     (gnus-get-predicate display)))
5160
5161 ;; Uses the dynamically bound `number' variable.
5162 (eval-when-compile
5163   (defvar number))
5164 (defun gnus-article-marked-p (type &optional article)
5165   (let ((article (or article number)))
5166     (cond
5167      ((eq type 'tick)
5168       (memq article gnus-newsgroup-marked))
5169      ((eq type 'spam)
5170       (memq article gnus-newsgroup-spam-marked))
5171      ((eq type 'unsend)
5172       (memq article gnus-newsgroup-unsendable))
5173      ((eq type 'undownload)
5174       (memq article gnus-newsgroup-undownloaded))
5175      ((eq type 'download)
5176       (memq article gnus-newsgroup-downloadable))
5177      ((eq type 'unread)
5178       (memq article gnus-newsgroup-unreads))
5179      ((eq type 'read)
5180       (memq article gnus-newsgroup-reads))
5181      ((eq type 'dormant)
5182       (memq article gnus-newsgroup-dormant) )
5183      ((eq type 'expire)
5184       (memq article gnus-newsgroup-expirable))
5185      ((eq type 'reply)
5186       (memq article gnus-newsgroup-replied))
5187      ((eq type 'killed)
5188       (memq article gnus-newsgroup-killed))
5189      ((eq type 'bookmark)
5190       (assq article gnus-newsgroup-bookmarks))
5191      ((eq type 'score)
5192       (assq article gnus-newsgroup-scored))
5193      ((eq type 'save)
5194       (memq article gnus-newsgroup-saved))
5195      ((eq type 'cache)
5196       (memq article gnus-newsgroup-cached))
5197      ((eq type 'forward)
5198       (memq article gnus-newsgroup-forwarded))
5199      ((eq type 'seen)
5200       (not (memq article gnus-newsgroup-unseen)))
5201      ((eq type 'recent)
5202       (memq article gnus-newsgroup-recent))
5203      (t t))))
5204
5205 (defun gnus-articles-to-read (group &optional read-all)
5206   "Find out what articles the user wants to read."
5207   (let* ((display (gnus-group-find-parameter group 'display))
5208          (articles
5209           ;; Select all articles if `read-all' is non-nil, or if there
5210           ;; are no unread articles.
5211           (if (or read-all
5212                   (and (zerop (length gnus-newsgroup-marked))
5213                        (zerop (length gnus-newsgroup-unreads)))
5214                   ;; Fetch all if the predicate is non-nil.
5215                   gnus-newsgroup-display)
5216               ;; We want to select the headers for all the articles in
5217               ;; the group, so we select either all the active
5218               ;; articles in the group, or (if that's nil), the
5219               ;; articles in the cache.
5220               (or
5221                (gnus-uncompress-range (gnus-active group))
5222                (gnus-cache-articles-in-group group))
5223             ;; Select only the "normal" subset of articles.
5224             (gnus-sorted-nunion
5225              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5226              gnus-newsgroup-unreads)))
5227          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5228          (scored (length scored-list))
5229          (number (length articles))
5230          (marked (+ (length gnus-newsgroup-marked)
5231                     (length gnus-newsgroup-dormant)))
5232          (select
5233           (cond
5234            ((numberp read-all)
5235             read-all)
5236            ((numberp gnus-newsgroup-display)
5237             gnus-newsgroup-display)
5238            (t
5239             (condition-case ()
5240                 (cond
5241                  ((and (or (<= scored marked) (= scored number))
5242                        (numberp gnus-large-newsgroup)
5243                        (> number gnus-large-newsgroup))
5244                   (let* ((cursor-in-echo-area nil)
5245                          (initial (gnus-parameter-large-newsgroup-initial
5246                                    gnus-newsgroup-name))
5247                          (input
5248                           (read-string
5249                            (format
5250                             "How many articles from %s (%s %d): "
5251                             (gnus-limit-string
5252                              (gnus-group-decoded-name gnus-newsgroup-name)
5253                              35)
5254                             (if initial "max" "default")
5255                             number)
5256                            (if initial
5257                                (cons (number-to-string initial)
5258                                      0)))))
5259                     (if (string-match "^[ \t]*$" input) number input)))
5260                  ((and (> scored marked) (< scored number)
5261                        (> (- scored number) 20))
5262                   (let ((input
5263                          (read-string
5264                           (format "%s %s (%d scored, %d total): "
5265                                   "How many articles from"
5266                                   (gnus-group-decoded-name group)
5267                                   scored number))))
5268                     (if (string-match "^[ \t]*$" input)
5269                         number input)))
5270                  (t number))
5271               (quit
5272                (message "Quit getting the articles to read")
5273                nil))))))
5274     (setq select (if (stringp select) (string-to-number select) select))
5275     (if (or (null select) (zerop select))
5276         select
5277       (if (and (not (zerop scored)) (<= (abs select) scored))
5278           (progn
5279             (setq articles (sort scored-list '<))
5280             (setq number (length articles)))
5281         (setq articles (copy-sequence articles)))
5282
5283       (when (< (abs select) number)
5284         (if (< select 0)
5285             ;; Select the N oldest articles.
5286             (setcdr (nthcdr (1- (abs select)) articles) nil)
5287           ;; Select the N most recent articles.
5288           (setq articles (nthcdr (- number select) articles))))
5289       (setq gnus-newsgroup-unselected
5290             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5291       (when gnus-alter-articles-to-read-function
5292         (setq articles
5293               (sort
5294                (funcall gnus-alter-articles-to-read-function
5295                         gnus-newsgroup-name articles)
5296                '<)))
5297       articles)))
5298
5299 (defun gnus-killed-articles (killed articles)
5300   (let (out)
5301     (while articles
5302       (when (inline (gnus-member-of-range (car articles) killed))
5303         (push (car articles) out))
5304       (setq articles (cdr articles)))
5305     out))
5306
5307 (defun gnus-uncompress-marks (marks)
5308   "Uncompress the mark ranges in MARKS."
5309   (let ((uncompressed '(score bookmark))
5310         out)
5311     (while marks
5312       (if (memq (caar marks) uncompressed)
5313           (push (car marks) out)
5314         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5315       (setq marks (cdr marks)))
5316     out))
5317
5318 (defun gnus-article-mark-to-type (mark)
5319   "Return the type of MARK."
5320   (or (cadr (assq mark gnus-article-special-mark-lists))
5321       'list))
5322
5323 (defun gnus-article-unpropagatable-p (mark)
5324   "Return whether MARK should be propagated to backend."
5325   (memq mark gnus-article-unpropagated-mark-lists))
5326
5327 (defun gnus-adjust-marked-articles (info)
5328   "Set all article lists and remove all marks that are no longer valid."
5329   (let* ((marked-lists (gnus-info-marks info))
5330          (active (gnus-active (gnus-info-group info)))
5331          (min (car active))
5332          (max (cdr active))
5333          (types gnus-article-mark-lists)
5334          marks var articles article mark mark-type)
5335
5336     (dolist (marks marked-lists)
5337       (setq mark (car marks)
5338             mark-type (gnus-article-mark-to-type mark)
5339             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5340
5341       ;; We set the variable according to the type of the marks list,
5342       ;; and then adjust the marks to a subset of the active articles.
5343       (cond
5344        ;; Adjust "simple" lists.
5345        ((eq mark-type 'list)
5346         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5347         (when (memq mark '(tick dormant expire reply save))
5348           (while articles
5349             (when (or (< (setq article (pop articles)) min) (> article max))
5350               (set var (delq article (symbol-value var)))))))
5351        ;; Adjust assocs.
5352        ((eq mark-type 'tuple)
5353         (set var (setq articles (cdr marks)))
5354         (when (not (listp (cdr (symbol-value var))))
5355           (set var (list (symbol-value var))))
5356         (when (not (listp (cdr articles)))
5357           (setq articles (list articles)))
5358         (while articles
5359           (when (or (not (consp (setq article (pop articles))))
5360                     (< (car article) min)
5361                     (> (car article) max))
5362             (set var (delq article (symbol-value var))))))
5363        ;; Adjust ranges (sloppily).
5364        ((eq mark-type 'range)
5365         (cond
5366          ((eq mark 'seen)
5367           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5368           ;; It should be (seen (NUM1 . NUM2)).
5369           (when (numberp (cddr marks))
5370             (setcdr marks (list (cdr marks))))
5371           (setq articles (cdr marks))
5372           (while (and articles
5373                       (or (and (consp (car articles))
5374                                (> min (cdar articles)))
5375                           (and (numberp (car articles))
5376                                (> min (car articles)))))
5377             (pop articles))
5378           (set var articles))))))))
5379
5380 (defun gnus-update-missing-marks (missing)
5381   "Go through the list of MISSING articles and remove them from the mark lists."
5382   (when missing
5383     (let (var m)
5384       ;; Go through all types.
5385       (dolist (elem gnus-article-mark-lists)
5386         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5387           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5388           (when (symbol-value var)
5389             ;; This list has articles.  So we delete all missing
5390             ;; articles from it.
5391             (setq m missing)
5392             (while m
5393               (set var (delq (pop m) (symbol-value var))))))))))
5394
5395 (defun gnus-update-marks ()
5396   "Enter the various lists of marked articles into the newsgroup info list."
5397   (let ((types gnus-article-mark-lists)
5398         (info (gnus-get-info gnus-newsgroup-name))
5399         type list newmarked symbol delta-marks)
5400     (when info
5401       ;; Add all marks lists to the list of marks lists.
5402       (while (setq type (pop types))
5403         (setq list (symbol-value
5404                     (setq symbol
5405                           (intern (format "gnus-newsgroup-%s" (car type))))))
5406
5407         (when list
5408           ;; Get rid of the entries of the articles that have the
5409           ;; default score.
5410           (when (and (eq (cdr type) 'score)
5411                      gnus-save-score
5412                      list)
5413             (let* ((arts list)
5414                    (prev (cons nil list))
5415                    (all prev))
5416               (while arts
5417                 (if (or (not (consp (car arts)))
5418                         (= (cdar arts) gnus-summary-default-score))
5419                     (setcdr prev (cdr arts))
5420                   (setq prev arts))
5421                 (setq arts (cdr arts)))
5422               (setq list (cdr all)))))
5423
5424         (when (eq (cdr type) 'seen)
5425           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5426
5427         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5428           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5429
5430         (when (and (gnus-check-backend-function
5431                     'request-set-mark gnus-newsgroup-name)
5432                    (not (gnus-article-unpropagatable-p (cdr type))))
5433           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5434                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5435                  (add (gnus-remove-from-range
5436                        (gnus-copy-sequence list) old)))
5437             (when add
5438               (push (list add 'add (list (cdr type))) delta-marks))
5439             (when del
5440               (push (list del 'del (list (cdr type))) delta-marks))))
5441
5442         (when list
5443           (push (cons (cdr type) list) newmarked)))
5444
5445       (when delta-marks
5446         (unless (gnus-check-group gnus-newsgroup-name)
5447           (error "Can't open server for %s" gnus-newsgroup-name))
5448         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5449
5450       ;; Enter these new marks into the info of the group.
5451       (if (nthcdr 3 info)
5452           (setcar (nthcdr 3 info) newmarked)
5453         ;; Add the marks lists to the end of the info.
5454         (when newmarked
5455           (setcdr (nthcdr 2 info) (list newmarked))))
5456
5457       ;; Cut off the end of the info if there's nothing else there.
5458       (let ((i 5))
5459         (while (and (> i 2)
5460                     (not (nth i info)))
5461           (when (nthcdr (decf i) info)
5462             (setcdr (nthcdr i info) nil)))))))
5463
5464 (defun gnus-set-mode-line (where)
5465   "Set the mode line of the article or summary buffers.
5466 If WHERE is `summary', the summary mode line format will be used."
5467   ;; Is this mode line one we keep updated?
5468   (when (and (memq where gnus-updated-mode-lines)
5469              (symbol-value
5470               (intern (format "gnus-%s-mode-line-format-spec" where))))
5471     (let (mode-string)
5472       (save-excursion
5473         ;; We evaluate this in the summary buffer since these
5474         ;; variables are buffer-local to that buffer.
5475         (set-buffer gnus-summary-buffer)
5476        ;; We bind all these variables that are used in the `eval' form
5477         ;; below.
5478         (let* ((mformat (symbol-value
5479                          (intern
5480                           (format "gnus-%s-mode-line-format-spec" where))))
5481                (gnus-tmp-group-name (gnus-group-decoded-name
5482                                      gnus-newsgroup-name))
5483                (gnus-tmp-article-number (or gnus-current-article 0))
5484                (gnus-tmp-unread gnus-newsgroup-unreads)
5485                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5486                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5487                (gnus-tmp-unread-and-unselected
5488                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5489                             (zerop gnus-tmp-unselected))
5490                        "")
5491                       ((zerop gnus-tmp-unselected)
5492                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5493                       (t (format "{%d(+%d) more}"
5494                                  gnus-tmp-unread-and-unticked
5495                                  gnus-tmp-unselected))))
5496                (gnus-tmp-subject
5497                 (if (and gnus-current-headers
5498                          (vectorp gnus-current-headers))
5499                     (gnus-mode-string-quote
5500                      (mail-header-subject gnus-current-headers))
5501                   ""))
5502                bufname-length max-len
5503                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5504           (setq mode-string (eval mformat))
5505           (setq bufname-length (if (string-match "%b" mode-string)
5506                                    (- (length
5507                                        (buffer-name
5508                                         (if (eq where 'summary)
5509                                             nil
5510                                           (get-buffer gnus-article-buffer))))
5511                                       2)
5512                                  0))
5513           (setq max-len (max 4 (if gnus-mode-non-string-length
5514                                    (- (window-width)
5515                                       gnus-mode-non-string-length
5516                                       bufname-length)
5517                                  (length mode-string))))
5518           ;; We might have to chop a bit of the string off...
5519           (when (> (length mode-string) max-len)
5520             (setq mode-string
5521                   (concat (truncate-string-to-width mode-string (- max-len 3))
5522                           "...")))
5523           ;; Pad the mode string a bit.
5524           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5525       ;; Update the mode line.
5526       (setq mode-line-buffer-identification
5527             (gnus-mode-line-buffer-identification (list mode-string)))
5528       (set-buffer-modified-p t))))
5529
5530 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5531   "Go through the HEADERS list and add all Xrefs to a hash table.
5532 The resulting hash table is returned, or nil if no Xrefs were found."
5533   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5534          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5535          (xref-hashtb (gnus-make-hashtable))
5536          start group entry number xrefs header)
5537     (while headers
5538       (setq header (pop headers))
5539       (when (and (setq xrefs (mail-header-xref header))
5540                  (not (memq (setq number (mail-header-number header))
5541                             unreads)))
5542         (setq start 0)
5543         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5544           (setq start (match-end 0))
5545           (setq group (if prefix
5546                           (concat prefix (substring xrefs (match-beginning 1)
5547                                                     (match-end 1)))
5548                         (substring xrefs (match-beginning 1) (match-end 1))))
5549           (setq number
5550                 (string-to-int (substring xrefs (match-beginning 2)
5551                                           (match-end 2))))
5552           (if (setq entry (gnus-gethash group xref-hashtb))
5553               (setcdr entry (cons number (cdr entry)))
5554             (gnus-sethash group (cons number nil) xref-hashtb)))))
5555     (and start xref-hashtb)))
5556
5557 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5558   "Look through all the headers and mark the Xrefs as read."
5559   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5560         name entry info xref-hashtb idlist method nth4)
5561     (save-excursion
5562       (set-buffer gnus-group-buffer)
5563       (when (setq xref-hashtb
5564                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5565         (mapatoms
5566          (lambda (group)
5567            (unless (string= from-newsgroup (setq name (symbol-name group)))
5568              (setq idlist (symbol-value group))
5569              ;; Dead groups are not updated.
5570              (and (prog1
5571                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5572                             info (nth 2 entry))
5573                     (when (stringp (setq nth4 (gnus-info-method info)))
5574                       (setq nth4 (gnus-server-to-method nth4))))
5575                   ;; Only do the xrefs if the group has the same
5576                   ;; select method as the group we have just read.
5577                   (or (gnus-methods-equal-p
5578                        nth4 (gnus-find-method-for-group from-newsgroup))
5579                       virtual
5580                       (equal nth4 (setq method (gnus-find-method-for-group
5581                                                 from-newsgroup)))
5582                       (and (equal (car nth4) (car method))
5583                            (equal (nth 1 nth4) (nth 1 method))))
5584                   gnus-use-cross-reference
5585                   (or (not (eq gnus-use-cross-reference t))
5586                       virtual
5587                       ;; Only do cross-references on subscribed
5588                       ;; groups, if that is what is wanted.
5589                       (<= (gnus-info-level info) gnus-level-subscribed))
5590                   (gnus-group-make-articles-read name idlist))))
5591          xref-hashtb)))))
5592
5593 (defun gnus-compute-read-articles (group articles)
5594   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5595          (info (nth 2 entry))
5596          (active (gnus-active group))
5597          ninfo)
5598     (when entry
5599       ;; First peel off all invalid article numbers.
5600       (when active
5601         (let ((ids articles)
5602               id first)
5603           (while (setq id (pop ids))
5604             (when (and first (> id (cdr active)))
5605               ;; We'll end up in this situation in one particular
5606               ;; obscure situation.  If you re-scan a group and get
5607               ;; a new article that is cross-posted to a different
5608               ;; group that has not been re-scanned, you might get
5609               ;; crossposted article that has a higher number than
5610               ;; Gnus believes possible.  So we re-activate this
5611               ;; group as well.  This might mean doing the
5612               ;; crossposting thingy will *increase* the number
5613               ;; of articles in some groups.  Tsk, tsk.
5614               (setq active (or (gnus-activate-group group) active)))
5615             (when (or (> id (cdr active))
5616                       (< id (car active)))
5617               (setq articles (delq id articles))))))
5618       ;; If the read list is nil, we init it.
5619       (if (and active
5620                (null (gnus-info-read info))
5621                (> (car active) 1))
5622           (setq ninfo (cons 1 (1- (car active))))
5623         (setq ninfo (gnus-info-read info)))
5624       ;; Then we add the read articles to the range.
5625       (gnus-add-to-range
5626        ninfo (setq articles (sort articles '<))))))
5627
5628 (defun gnus-group-make-articles-read (group articles)
5629   "Update the info of GROUP to say that ARTICLES are read."
5630   (let* ((num 0)
5631          (entry (gnus-gethash group gnus-newsrc-hashtb))
5632          (info (nth 2 entry))
5633          (active (gnus-active group))
5634          range)
5635     (when entry
5636       (setq range (gnus-compute-read-articles group articles))
5637       (save-excursion
5638         (set-buffer gnus-group-buffer)
5639         (gnus-undo-register
5640           `(progn
5641              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5642              (gnus-info-set-read ',info ',(gnus-info-read info))
5643              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5644              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5645              (gnus-group-update-group ,group t))))
5646       ;; Add the read articles to the range.
5647       (gnus-info-set-read info range)
5648       (gnus-request-set-mark group (list (list range 'add '(read))))
5649       ;; Then we have to re-compute how many unread
5650       ;; articles there are in this group.
5651       (when active
5652         (cond
5653          ((not range)
5654           (setq num (- (1+ (cdr active)) (car active))))
5655          ((not (listp (cdr range)))
5656           (setq num (- (cdr active) (- (1+ (cdr range))
5657                                        (car range)))))
5658          (t
5659           (while range
5660             (if (numberp (car range))
5661                 (setq num (1+ num))
5662               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5663             (setq range (cdr range)))
5664           (setq num (- (cdr active) num))))
5665         ;; Update the number of unread articles.
5666         (setcar entry num)
5667         ;; Update the group buffer.
5668         (unless (gnus-ephemeral-group-p group)
5669           (gnus-group-update-group group t))))))
5670
5671 (defvar gnus-newsgroup-none-id 0)
5672
5673 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5674   (let ((cur nntp-server-buffer)
5675         (dependencies
5676          (or dependencies
5677              (save-excursion (set-buffer gnus-summary-buffer)
5678                              gnus-newsgroup-dependencies)))
5679         headers id end ref
5680         (mail-parse-charset gnus-newsgroup-charset)
5681         (mail-parse-ignored-charsets
5682          (save-excursion (condition-case nil
5683                              (set-buffer gnus-summary-buffer)
5684                            (error))
5685                          gnus-newsgroup-ignored-charsets)))
5686     (save-excursion
5687       (set-buffer nntp-server-buffer)
5688       ;; Translate all TAB characters into SPACE characters.
5689       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5690       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5691       (gnus-run-hooks 'gnus-parse-headers-hook)
5692       (let ((case-fold-search t)
5693             in-reply-to header p lines chars)
5694         (goto-char (point-min))
5695         ;; Search to the beginning of the next header.  Error messages
5696         ;; do not begin with 2 or 3.
5697         (while (re-search-forward "^[23][0-9]+ " nil t)
5698           (setq id nil
5699                 ref nil)
5700           ;; This implementation of this function, with nine
5701           ;; search-forwards instead of the one re-search-forward and
5702           ;; a case (which basically was the old function) is actually
5703           ;; about twice as fast, even though it looks messier.  You
5704           ;; can't have everything, I guess.  Speed and elegance
5705           ;; doesn't always go hand in hand.
5706           (setq
5707            header
5708            (vector
5709             ;; Number.
5710             (prog1
5711                 (read cur)
5712               (end-of-line)
5713               (setq p (point))
5714               (narrow-to-region (point)
5715                                 (or (and (search-forward "\n.\n" nil t)
5716                                          (- (point) 2))
5717                                     (point))))
5718             ;; Subject.
5719             (progn
5720               (goto-char p)
5721               (if (search-forward "\nsubject:" nil t)
5722                   (funcall gnus-decode-encoded-word-function
5723                            (nnheader-header-value))
5724                 "(none)"))
5725             ;; From.
5726             (progn
5727               (goto-char p)
5728               (if (search-forward "\nfrom:" nil t)
5729                   (funcall gnus-decode-encoded-word-function
5730                            (nnheader-header-value))
5731                 "(nobody)"))
5732             ;; Date.
5733             (progn
5734               (goto-char p)
5735               (if (search-forward "\ndate:" nil t)
5736                   (nnheader-header-value) ""))
5737             ;; Message-ID.
5738             (progn
5739               (goto-char p)
5740               (setq id (if (re-search-forward
5741                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5742                            ;; We do it this way to make sure the Message-ID
5743                            ;; is (somewhat) syntactically valid.
5744                            (buffer-substring (match-beginning 1)
5745                                              (match-end 1))
5746                          ;; If there was no message-id, we just fake one
5747                          ;; to make subsequent routines simpler.
5748                          (nnheader-generate-fake-message-id))))
5749             ;; References.
5750             (progn
5751               (goto-char p)
5752               (if (search-forward "\nreferences:" nil t)
5753                   (progn
5754                     (setq end (point))
5755                     (prog1
5756                         (nnheader-header-value)
5757                       (setq ref
5758                             (buffer-substring
5759                              (progn
5760                                (end-of-line)
5761                                (search-backward ">" end t)
5762                                (1+ (point)))
5763                              (progn
5764                                (search-backward "<" end t)
5765                                (point))))))
5766                 ;; Get the references from the in-reply-to header if there
5767                 ;; were no references and the in-reply-to header looks
5768                 ;; promising.
5769                 (if (and (search-forward "\nin-reply-to:" nil t)
5770                          (setq in-reply-to (nnheader-header-value))
5771                          (string-match "<[^>]+>" in-reply-to))
5772                     (let (ref2)
5773                       (setq ref (substring in-reply-to (match-beginning 0)
5774                                            (match-end 0)))
5775                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5776                         (setq ref2 (substring in-reply-to (match-beginning 0)
5777                                               (match-end 0)))
5778                         (when (> (length ref2) (length ref))
5779                           (setq ref ref2)))
5780                       ref)
5781                   (setq ref nil))))
5782             ;; Chars.
5783             (progn
5784               (goto-char p)
5785               (if (search-forward "\nchars: " nil t)
5786                   (if (numberp (setq chars (ignore-errors (read cur))))
5787                       chars -1)
5788                 -1))
5789             ;; Lines.
5790             (progn
5791               (goto-char p)
5792               (if (search-forward "\nlines: " nil t)
5793                   (if (numberp (setq lines (ignore-errors (read cur))))
5794                       lines -1)
5795                 -1))
5796             ;; Xref.
5797             (progn
5798               (goto-char p)
5799               (and (search-forward "\nxref:" nil t)
5800                    (nnheader-header-value)))
5801             ;; Extra.
5802             (when gnus-extra-headers
5803               (let ((extra gnus-extra-headers)
5804                     out)
5805                 (while extra
5806                   (goto-char p)
5807                   (when (search-forward
5808                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5809                     (push (cons (car extra) (nnheader-header-value))
5810                           out))
5811                   (pop extra))
5812                 out))))
5813           (when (equal id ref)
5814             (setq ref nil))
5815
5816           (when gnus-alter-header-function
5817             (funcall gnus-alter-header-function header)
5818             (setq id (mail-header-id header)
5819                   ref (gnus-parent-id (mail-header-references header))))
5820
5821           (when (setq header
5822                       (gnus-dependencies-add-header
5823                        header dependencies force-new))
5824             (push header headers))
5825           (goto-char (point-max))
5826           (widen))
5827         (nreverse headers)))))
5828
5829 ;; Goes through the xover lines and returns a list of vectors
5830 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5831                                                   force-new dependencies
5832                                                   group also-fetch-heads)
5833   "Parse the news overview data in the server buffer.
5834 Return a list of headers that match SEQUENCE (see
5835 `nntp-retrieve-headers')."
5836   ;; Get the Xref when the users reads the articles since most/some
5837   ;; NNTP servers do not include Xrefs when using XOVER.
5838   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5839   (let ((mail-parse-charset gnus-newsgroup-charset)
5840         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5841         (cur nntp-server-buffer)
5842         (dependencies (or dependencies gnus-newsgroup-dependencies))
5843         (allp (cond
5844                ((eq gnus-read-all-available-headers t)
5845                 t)
5846                ((stringp gnus-read-all-available-headers)
5847                 (string-match gnus-read-all-available-headers group))
5848                (t
5849                 nil)))
5850         number headers header)
5851     (save-excursion
5852       (set-buffer nntp-server-buffer)
5853       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5854       ;; Allow the user to mangle the headers before parsing them.
5855       (gnus-run-hooks 'gnus-parse-headers-hook)
5856       (goto-char (point-min))
5857       (gnus-parse-without-error
5858         (while (and (or sequence allp)
5859                     (not (eobp)))
5860           (setq number (read cur))
5861           (when (not allp)
5862             (while (and sequence
5863                         (< (car sequence) number))
5864               (setq sequence (cdr sequence))))
5865           (when (and (or allp
5866                          (and sequence
5867                               (eq number (car sequence))))
5868                      (progn
5869                        (setq sequence (cdr sequence))
5870                        (setq header (inline
5871                                       (gnus-nov-parse-line
5872                                        number dependencies force-new)))))
5873             (push header headers))
5874           (forward-line 1)))
5875       ;; A common bug in inn is that if you have posted an article and
5876       ;; then retrieves the active file, it will answer correctly --
5877       ;; the new article is included.  However, a NOV entry for the
5878       ;; article may not have been generated yet, so this may fail.
5879       ;; We work around this problem by retrieving the last few
5880       ;; headers using HEAD.
5881       (if (or (not also-fetch-heads)
5882               (not sequence))
5883           ;; We (probably) got all the headers.
5884           (nreverse headers)
5885         (let ((gnus-nov-is-evil t))
5886           (nconc
5887            (nreverse headers)
5888            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5889              (gnus-get-newsgroup-headers))))))))
5890
5891 (defun gnus-article-get-xrefs ()
5892   "Fill in the Xref value in `gnus-current-headers', if necessary.
5893 This is meant to be called in `gnus-article-internal-prepare-hook'."
5894   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5895                                  gnus-current-headers)))
5896     (or (not gnus-use-cross-reference)
5897         (not headers)
5898         (and (mail-header-xref headers)
5899              (not (string= (mail-header-xref headers) "")))
5900         (let ((case-fold-search t)
5901               xref)
5902           (save-restriction
5903             (nnheader-narrow-to-headers)
5904             (goto-char (point-min))
5905             (when (or (and (not (eobp))
5906                            (eq (downcase (char-after)) ?x)
5907                            (looking-at "Xref:"))
5908                       (search-forward "\nXref:" nil t))
5909               (goto-char (1+ (match-end 0)))
5910               (setq xref (buffer-substring (point) (gnus-point-at-eol)))
5911               (mail-header-set-xref headers xref)))))))
5912
5913 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5914   "Find article ID and insert the summary line for that article.
5915 OLD-HEADER can either be a header or a line number to insert
5916 the subject line on."
5917   (let* ((line (and (numberp old-header) old-header))
5918          (old-header (and (vectorp old-header) old-header))
5919          (header (cond ((and old-header use-old-header)
5920                         old-header)
5921                        ((and (numberp id)
5922                              (gnus-number-to-header id))
5923                         (gnus-number-to-header id))
5924                        (t
5925                         (gnus-read-header id))))
5926          (number (and (numberp id) id))
5927          d)
5928     (when header
5929       ;; Rebuild the thread that this article is part of and go to the
5930       ;; article we have fetched.
5931       (when (and (not gnus-show-threads)
5932                  old-header)
5933         (when (and number
5934                    (setq d (gnus-data-find (mail-header-number old-header))))
5935           (goto-char (gnus-data-pos d))
5936           (gnus-data-remove
5937            number
5938            (- (gnus-point-at-bol)
5939               (prog1
5940                   (1+ (gnus-point-at-eol))
5941                 (gnus-delete-line))))))
5942       (when old-header
5943         (mail-header-set-number header (mail-header-number old-header)))
5944       (setq gnus-newsgroup-sparse
5945             (delq (setq number (mail-header-number header))
5946                   gnus-newsgroup-sparse))
5947       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5948       (push number gnus-newsgroup-limit)
5949       (gnus-rebuild-thread (mail-header-id header) line)
5950       (gnus-summary-goto-subject number nil t))
5951     (when (and (numberp number)
5952                (> number 0))
5953       ;; We have to update the boundaries even if we can't fetch the
5954       ;; article if ID is a number -- so that the next `P' or `N'
5955       ;; command will fetch the previous (or next) article even
5956       ;; if the one we tried to fetch this time has been canceled.
5957       (when (> number gnus-newsgroup-end)
5958         (setq gnus-newsgroup-end number))
5959       (when (< number gnus-newsgroup-begin)
5960         (setq gnus-newsgroup-begin number))
5961       (setq gnus-newsgroup-unselected
5962             (delq number gnus-newsgroup-unselected)))
5963     ;; Report back a success?
5964     (and header (mail-header-number header))))
5965
5966 ;;; Process/prefix in the summary buffer
5967
5968 (defun gnus-summary-work-articles (n)
5969   "Return a list of articles to be worked upon.
5970 The prefix argument, the list of process marked articles, and the
5971 current article will be taken into consideration."
5972   (save-excursion
5973     (set-buffer gnus-summary-buffer)
5974     (cond
5975      (n
5976       ;; A numerical prefix has been given.
5977       (setq n (prefix-numeric-value n))
5978       (let ((backward (< n 0))
5979             (n (abs (prefix-numeric-value n)))
5980             articles article)
5981         (save-excursion
5982           (while
5983               (and (> n 0)
5984                    (push (setq article (gnus-summary-article-number))
5985                          articles)
5986                    (if backward
5987                        (gnus-summary-find-prev nil article)
5988                      (gnus-summary-find-next nil article)))
5989             (decf n)))
5990         (nreverse articles)))
5991      ((and (gnus-region-active-p) (mark))
5992       (message "region active")
5993       ;; Work on the region between point and mark.
5994       (let ((max (max (point) (mark)))
5995             articles article)
5996         (save-excursion
5997           (goto-char (min (min (point) (mark))))
5998           (while
5999               (and
6000                (push (setq article (gnus-summary-article-number)) articles)
6001                (gnus-summary-find-next nil article)
6002                (< (point) max)))
6003           (nreverse articles))))
6004      (gnus-newsgroup-processable
6005       ;; There are process-marked articles present.
6006       ;; Save current state.
6007       (gnus-summary-save-process-mark)
6008       ;; Return the list.
6009       (reverse gnus-newsgroup-processable))
6010      (t
6011       ;; Just return the current article.
6012       (list (gnus-summary-article-number))))))
6013
6014 (defmacro gnus-summary-iterate (arg &rest forms)
6015   "Iterate over the process/prefixed articles and do FORMS.
6016 ARG is the interactive prefix given to the command.  FORMS will be
6017 executed with point over the summary line of the articles."
6018   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6019     `(let ((,articles (gnus-summary-work-articles ,arg)))
6020        (while ,articles
6021          (gnus-summary-goto-subject (car ,articles))
6022          ,@forms
6023          (pop ,articles)))))
6024
6025 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6026 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6027
6028 (defun gnus-summary-save-process-mark ()
6029   "Push the current set of process marked articles on the stack."
6030   (interactive)
6031   (push (copy-sequence gnus-newsgroup-processable)
6032         gnus-newsgroup-process-stack))
6033
6034 (defun gnus-summary-kill-process-mark ()
6035   "Push the current set of process marked articles on the stack and unmark."
6036   (interactive)
6037   (gnus-summary-save-process-mark)
6038   (gnus-summary-unmark-all-processable))
6039
6040 (defun gnus-summary-yank-process-mark ()
6041   "Pop the last process mark state off the stack and restore it."
6042   (interactive)
6043   (unless gnus-newsgroup-process-stack
6044     (error "Empty mark stack"))
6045   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6046
6047 (defun gnus-summary-process-mark-set (set)
6048   "Make SET into the current process marked articles."
6049   (gnus-summary-unmark-all-processable)
6050   (while set
6051     (gnus-summary-set-process-mark (pop set))))
6052
6053 ;;; Searching and stuff
6054
6055 (defun gnus-summary-search-group (&optional backward use-level)
6056   "Search for next unread newsgroup.
6057 If optional argument BACKWARD is non-nil, search backward instead."
6058   (save-excursion
6059     (set-buffer gnus-group-buffer)
6060     (when (gnus-group-search-forward
6061            backward nil (if use-level (gnus-group-group-level) nil))
6062       (gnus-group-group-name))))
6063
6064 (defun gnus-summary-best-group (&optional exclude-group)
6065   "Find the name of the best unread group.
6066 If EXCLUDE-GROUP, do not go to this group."
6067   (save-excursion
6068     (set-buffer gnus-group-buffer)
6069     (save-excursion
6070       (gnus-group-best-unread-group exclude-group))))
6071
6072 (defun gnus-summary-find-next (&optional unread article backward)
6073   (if backward (gnus-summary-find-prev unread article)
6074     (let* ((dummy (gnus-summary-article-intangible-p))
6075            (article (or article (gnus-summary-article-number)))
6076            (data (gnus-data-find-list article))
6077            result)
6078       (when (and (not dummy)
6079                  (or (not gnus-summary-check-current)
6080                      (not unread)
6081                      (not (gnus-data-unread-p (car data)))))
6082         (setq data (cdr data)))
6083       (when (setq result
6084                   (if unread
6085                       (progn
6086                         (while data
6087                           (unless (memq (gnus-data-number (car data)) 
6088                                         (cond ((eq gnus-auto-goto-ignores 'always-undownloaded)
6089                                                gnus-newsgroup-undownloaded)
6090                                               (gnus-plugged
6091                                                nil)
6092                                               ((eq gnus-auto-goto-ignores 'unfetched)
6093                                                gnus-newsgroup-unfetched)
6094                                               ((eq gnus-auto-goto-ignores 'undownloaded)
6095                                                gnus-newsgroup-undownloaded)))
6096                             (when (gnus-data-unread-p (car data))
6097                               (setq result (car data)
6098                                     data nil)))
6099                           (setq data (cdr data)))
6100                         result)
6101                     (car data)))
6102         (goto-char (gnus-data-pos result))
6103         (gnus-data-number result)))))
6104
6105 (defun gnus-summary-find-prev (&optional unread article)
6106   (let* ((eobp (eobp))
6107          (article (or article (gnus-summary-article-number)))
6108          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6109          result)
6110     (when (and (not eobp)
6111                (or (not gnus-summary-check-current)
6112                    (not unread)
6113                    (not (gnus-data-unread-p (car data)))))
6114       (setq data (cdr data)))
6115     (when (setq result
6116                 (if unread
6117                     (progn
6118                       (while data
6119                         (unless (memq (gnus-data-number (car data))
6120                                       (cond ((eq gnus-auto-goto-ignores 'always-undownloaded)
6121                                              gnus-newsgroup-undownloaded)
6122                                             (gnus-plugged
6123                                              nil)
6124                                             ((eq gnus-auto-goto-ignores 'unfetched)
6125                                              gnus-newsgroup-unfetched)
6126                                             ((eq gnus-auto-goto-ignores 'undownloaded)
6127                                              gnus-newsgroup-undownloaded)))
6128                           (when (gnus-data-unread-p (car data))
6129                             (setq result (car data)
6130                                   data nil)))
6131                         (setq data (cdr data)))
6132                       result)
6133                   (car data)))
6134       (goto-char (gnus-data-pos result))
6135       (gnus-data-number result))))
6136
6137 (defun gnus-summary-find-subject (subject &optional unread backward article)
6138   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6139          (article (or article (gnus-summary-article-number)))
6140          (articles (gnus-data-list backward))
6141          (arts (gnus-data-find-list article articles))
6142          result)
6143     (when (or (not gnus-summary-check-current)
6144               (not unread)
6145               (not (gnus-data-unread-p (car arts))))
6146       (setq arts (cdr arts)))
6147     (while arts
6148       (and (or (not unread)
6149                (gnus-data-unread-p (car arts)))
6150            (vectorp (gnus-data-header (car arts)))
6151            (gnus-subject-equal
6152             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6153            (setq result (car arts)
6154                  arts nil))
6155       (setq arts (cdr arts)))
6156     (and result
6157          (goto-char (gnus-data-pos result))
6158          (gnus-data-number result))))
6159
6160 (defun gnus-summary-search-forward (&optional unread subject backward)
6161   "Search forward for an article.
6162 If UNREAD, look for unread articles.  If SUBJECT, look for
6163 articles with that subject.  If BACKWARD, search backward instead."
6164   (cond (subject (gnus-summary-find-subject subject unread backward))
6165         (backward (gnus-summary-find-prev unread))
6166         (t (gnus-summary-find-next unread))))
6167
6168 (defun gnus-recenter (&optional n)
6169   "Center point in window and redisplay frame.
6170 Also do horizontal recentering."
6171   (interactive "P")
6172   (when (and gnus-auto-center-summary
6173              (not (eq gnus-auto-center-summary 'vertical)))
6174     (gnus-horizontal-recenter))
6175   (recenter n))
6176
6177 (defun gnus-summary-recenter ()
6178   "Center point in the summary window.
6179 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6180 displayed, no centering will be performed."
6181   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6182   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6183   (interactive)
6184   ;; The user has to want it.
6185   (when gnus-auto-center-summary
6186     (let* ((top (cond ((< (window-height) 4) 0)
6187                       ((< (window-height) 7) 1)
6188                       (t (if (numberp gnus-auto-center-summary)
6189                              gnus-auto-center-summary
6190                            2))))
6191            (height (1- (window-height)))
6192            (bottom (save-excursion (goto-char (point-max))
6193                                    (forward-line (- height))
6194                                    (point)))
6195            (window (get-buffer-window (current-buffer))))
6196       (when (get-buffer-window gnus-article-buffer)
6197         ;; Only do recentering when the article buffer is displayed,
6198         ;; Set the window start to either `bottom', which is the biggest
6199         ;; possible valid number, or the second line from the top,
6200         ;; whichever is the least.
6201         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6202           (if (> bottom top-pos)
6203               ;; Keep the second line from the top visible
6204               (set-window-start window top-pos t)
6205             ;; Try to keep the bottom line visible; if it's partially
6206             ;; obscured, either scroll one more line to make it fully
6207             ;; visible, or revert to using TOP-POS.
6208             (save-excursion
6209               (goto-char (point-max))
6210               (forward-line -1)
6211               (let ((last-line-start (point)))
6212                 (goto-char bottom)
6213                 (set-window-start window (point) t)
6214                 (when (not (pos-visible-in-window-p last-line-start window))
6215                   (forward-line 1)
6216                   (set-window-start window (min (point) top-pos) t)))))))
6217       ;; Do horizontal recentering while we're at it.
6218       (when (and (get-buffer-window (current-buffer) t)
6219                  (not (eq gnus-auto-center-summary 'vertical)))
6220         (let ((selected (selected-window)))
6221           (select-window (get-buffer-window (current-buffer) t))
6222           (gnus-summary-position-point)
6223           (gnus-horizontal-recenter)
6224           (select-window selected))))))
6225
6226 (defun gnus-summary-jump-to-group (newsgroup)
6227   "Move point to NEWSGROUP in group mode buffer."
6228   ;; Keep update point of group mode buffer if visible.
6229   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6230       (save-window-excursion
6231         ;; Take care of tree window mode.
6232         (when (get-buffer-window gnus-group-buffer)
6233           (pop-to-buffer gnus-group-buffer))
6234         (gnus-group-jump-to-group newsgroup))
6235     (save-excursion
6236       ;; Take care of tree window mode.
6237       (if (get-buffer-window gnus-group-buffer)
6238           (pop-to-buffer gnus-group-buffer)
6239         (set-buffer gnus-group-buffer))
6240       (gnus-group-jump-to-group newsgroup))))
6241
6242 ;; This function returns a list of article numbers based on the
6243 ;; difference between the ranges of read articles in this group and
6244 ;; the range of active articles.
6245 (defun gnus-list-of-unread-articles (group)
6246   (let* ((read (gnus-info-read (gnus-get-info group)))
6247          (active (or (gnus-active group) (gnus-activate-group group)))
6248          (last (cdr active))
6249          first nlast unread)
6250     ;; If none are read, then all are unread.
6251     (if (not read)
6252         (setq first (car active))
6253       ;; If the range of read articles is a single range, then the
6254       ;; first unread article is the article after the last read
6255       ;; article.  Sounds logical, doesn't it?
6256       (if (and (not (listp (cdr read)))
6257                (or (< (car read) (car active))
6258                    (progn (setq read (list read))
6259                           nil)))
6260           (setq first (max (car active) (1+ (cdr read))))
6261         ;; `read' is a list of ranges.
6262         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6263                                   (caar read)))
6264                   1)
6265           (setq first (car active)))
6266         (while read
6267           (when first
6268             (while (< first nlast)
6269               (push first unread)
6270               (setq first (1+ first))))
6271           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6272           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6273           (setq read (cdr read)))))
6274     ;; And add the last unread articles.
6275     (while (<= first last)
6276       (push first unread)
6277       (setq first (1+ first)))
6278     ;; Return the list of unread articles.
6279     (delq 0 (nreverse unread))))
6280
6281 (defun gnus-list-of-read-articles (group)
6282   "Return a list of unread, unticked and non-dormant articles."
6283   (let* ((info (gnus-get-info group))
6284          (marked (gnus-info-marks info))
6285          (active (gnus-active group)))
6286     (and info active
6287          (gnus-list-range-difference
6288           (gnus-list-range-difference
6289            (gnus-sorted-complement
6290             (gnus-uncompress-range active)
6291             (gnus-list-of-unread-articles group))
6292            (cdr (assq 'dormant marked)))
6293           (cdr (assq 'tick marked))))))
6294
6295 ;; Various summary commands
6296
6297 (defun gnus-summary-select-article-buffer ()
6298   "Reconfigure windows to show article buffer."
6299   (interactive)
6300   (if (not (gnus-buffer-live-p gnus-article-buffer))
6301       (error "There is no article buffer for this summary buffer")
6302     (gnus-configure-windows 'article)
6303     (select-window (get-buffer-window gnus-article-buffer))))
6304
6305 (defun gnus-summary-universal-argument (arg)
6306   "Perform any operation on all articles that are process/prefixed."
6307   (interactive "P")
6308   (let ((articles (gnus-summary-work-articles arg))
6309         func article)
6310     (if (eq
6311          (setq
6312           func
6313           (key-binding
6314            (read-key-sequence
6315             (substitute-command-keys
6316              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6317          'undefined)
6318         (gnus-error 1 "Undefined key")
6319       (save-excursion
6320         (while articles
6321           (gnus-summary-goto-subject (setq article (pop articles)))
6322           (let (gnus-newsgroup-processable)
6323             (command-execute func))
6324           (gnus-summary-remove-process-mark article)))))
6325   (gnus-summary-position-point))
6326
6327 (defun gnus-summary-toggle-truncation (&optional arg)
6328   "Toggle truncation of summary lines.
6329 With arg, turn line truncation on if arg is positive."
6330   (interactive "P")
6331   (setq truncate-lines
6332         (if (null arg) (not truncate-lines)
6333           (> (prefix-numeric-value arg) 0)))
6334   (redraw-display))
6335
6336 (defun gnus-summary-find-for-reselect ()
6337   "Return the number of an article to stay on across a reselect.
6338 The current article is considered, then following articles, then previous
6339 articles.  An article is sought which is not cancelled and isn't a temporary
6340 insertion from another group.  If there's no such then return a dummy 0."
6341   (let (found)
6342     (dolist (rev '(nil t))
6343       (unless found      ; don't demand the reverse list if we don't need it
6344         (let ((data (gnus-data-find-list
6345                      (gnus-summary-article-number) (gnus-data-list rev))))
6346           (while (and data (not found))
6347             (if (and (< 0 (gnus-data-number (car data)))
6348                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6349                 (setq found (gnus-data-number (car data))))
6350             (setq data (cdr data))))))
6351     (or found 0)))
6352
6353 (defun gnus-summary-reselect-current-group (&optional all rescan)
6354   "Exit and then reselect the current newsgroup.
6355 The prefix argument ALL means to select all articles."
6356   (interactive "P")
6357   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6358     (error "Ephemeral groups can't be reselected"))
6359   (let ((current-subject (gnus-summary-find-for-reselect))
6360         (group gnus-newsgroup-name))
6361     (setq gnus-newsgroup-begin nil)
6362     (gnus-summary-exit)
6363     ;; We have to adjust the point of group mode buffer because
6364     ;; point was moved to the next unread newsgroup by exiting.
6365     (gnus-summary-jump-to-group group)
6366     (when rescan
6367       (save-excursion
6368         (gnus-group-get-new-news-this-group 1)))
6369     (gnus-group-read-group all t)
6370     (gnus-summary-goto-subject current-subject nil t)))
6371
6372 (defun gnus-summary-rescan-group (&optional all)
6373   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6374   (interactive "P")
6375   (gnus-summary-reselect-current-group all t))
6376
6377 (defun gnus-summary-update-info (&optional non-destructive)
6378   (save-excursion
6379     (let ((group gnus-newsgroup-name))
6380       (when group
6381         (when gnus-newsgroup-kill-headers
6382           (setq gnus-newsgroup-killed
6383                 (gnus-compress-sequence
6384                  (gnus-sorted-union
6385                   (gnus-list-range-intersection
6386                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6387                   gnus-newsgroup-unreads)
6388                  t)))
6389         (unless (listp (cdr gnus-newsgroup-killed))
6390           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6391         (let ((headers gnus-newsgroup-headers))
6392           ;; Set the new ranges of read articles.
6393           (save-excursion
6394             (set-buffer gnus-group-buffer)
6395             (gnus-undo-force-boundary))
6396           (gnus-update-read-articles
6397            group (gnus-sorted-union
6398                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6399           ;; Set the current article marks.
6400           (let ((gnus-newsgroup-scored
6401                  (if (and (not gnus-save-score)
6402                           (not non-destructive))
6403                      nil
6404                    gnus-newsgroup-scored)))
6405             (save-excursion
6406               (gnus-update-marks)))
6407           ;; Do the cross-ref thing.
6408           (when gnus-use-cross-reference
6409             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6410           ;; Do not switch windows but change the buffer to work.
6411           (set-buffer gnus-group-buffer)
6412           (unless (gnus-ephemeral-group-p group)
6413             (gnus-group-update-group group)))))))
6414
6415 (defun gnus-summary-save-newsrc (&optional force)
6416   "Save the current number of read/marked articles in the dribble buffer.
6417 The dribble buffer will then be saved.
6418 If FORCE (the prefix), also save the .newsrc file(s)."
6419   (interactive "P")
6420   (gnus-summary-update-info t)
6421   (if force
6422       (gnus-save-newsrc-file)
6423     (gnus-dribble-save)))
6424
6425 (defun gnus-summary-exit (&optional temporary)
6426   "Exit reading current newsgroup, and then return to group selection mode.
6427 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6428   (interactive)
6429   (gnus-set-global-variables)
6430   (when (gnus-buffer-live-p gnus-article-buffer)
6431     (save-excursion
6432       (set-buffer gnus-article-buffer)
6433       (mm-destroy-parts gnus-article-mime-handles)
6434       ;; Set it to nil for safety reason.
6435       (setq gnus-article-mime-handle-alist nil)
6436       (setq gnus-article-mime-handles nil)))
6437   (gnus-kill-save-kill-buffer)
6438   (gnus-async-halt-prefetch)
6439   (let* ((group gnus-newsgroup-name)
6440          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6441          (gnus-group-is-exiting-p t)
6442          (mode major-mode)
6443          (group-point nil)
6444          (buf (current-buffer)))
6445     (unless quit-config
6446       ;; Do adaptive scoring, and possibly save score files.
6447       (when gnus-newsgroup-adaptive
6448         (gnus-score-adaptive))
6449       (when gnus-use-scoring
6450         (gnus-score-save)))
6451     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6452     ;; If we have several article buffers, we kill them at exit.
6453     (unless gnus-single-article-buffer
6454       (gnus-kill-buffer gnus-original-article-buffer)
6455       (setq gnus-article-current nil))
6456     (when gnus-use-cache
6457       (gnus-cache-possibly-remove-articles)
6458       (gnus-cache-save-buffers))
6459     (gnus-async-prefetch-remove-group group)
6460     (when gnus-suppress-duplicates
6461       (gnus-dup-enter-articles))
6462     (when gnus-use-trees
6463       (gnus-tree-close group))
6464     (when gnus-use-cache
6465       (gnus-cache-write-active))
6466     ;; Remove entries for this group.
6467     (nnmail-purge-split-history (gnus-group-real-name group))
6468     ;; Make all changes in this group permanent.
6469     (unless quit-config
6470       (gnus-run-hooks 'gnus-exit-group-hook)
6471       (gnus-summary-update-info))
6472     (gnus-close-group group)
6473     ;; Make sure where we were, and go to next newsgroup.
6474     (set-buffer gnus-group-buffer)
6475     (unless quit-config
6476       (gnus-group-jump-to-group group))
6477     (gnus-run-hooks 'gnus-summary-exit-hook)
6478     (unless (or quit-config
6479                 ;; If this group has disappeared from the summary
6480                 ;; buffer, don't skip forwards.
6481                 (not (string= group (gnus-group-group-name))))
6482       (gnus-group-next-unread-group 1))
6483     (setq group-point (point))
6484     (if temporary
6485         nil                             ;Nothing to do.
6486       ;; If we have several article buffers, we kill them at exit.
6487       (unless gnus-single-article-buffer
6488         (gnus-kill-buffer gnus-article-buffer)
6489         (gnus-kill-buffer gnus-original-article-buffer)
6490         (setq gnus-article-current nil))
6491       (set-buffer buf)
6492       (if (not gnus-kill-summary-on-exit)
6493           (progn
6494             (gnus-deaden-summary)
6495             (setq mode nil))
6496         ;; We set all buffer-local variables to nil.  It is unclear why
6497         ;; this is needed, but if we don't, buffer-local variables are
6498         ;; not garbage-collected, it seems.  This would the lead to en
6499         ;; ever-growing Emacs.
6500         (gnus-summary-clear-local-variables)
6501         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6502           (gnus-summary-clear-local-variables))
6503         (when (get-buffer gnus-article-buffer)
6504           (bury-buffer gnus-article-buffer))
6505         ;; We clear the global counterparts of the buffer-local
6506         ;; variables as well, just to be on the safe side.
6507         (set-buffer gnus-group-buffer)
6508         (gnus-summary-clear-local-variables)
6509         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6510           (gnus-summary-clear-local-variables))
6511         ;; Return to group mode buffer.
6512         (when (eq mode 'gnus-summary-mode)
6513           (gnus-kill-buffer buf)))
6514       (setq gnus-current-select-method gnus-select-method)
6515       (pop-to-buffer gnus-group-buffer)
6516       (if (not quit-config)
6517           (progn
6518             (goto-char group-point)
6519             (gnus-configure-windows 'group 'force))
6520         (gnus-handle-ephemeral-exit quit-config))
6521       ;; Clear the current group name.
6522       (unless quit-config
6523         (setq gnus-newsgroup-name nil)))))
6524
6525 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6526 (defun gnus-summary-exit-no-update (&optional no-questions)
6527   "Quit reading current newsgroup without updating read article info."
6528   (interactive)
6529   (let* ((group gnus-newsgroup-name)
6530          (gnus-group-is-exiting-p t)
6531          (gnus-group-is-exiting-without-update-p t)
6532          (quit-config (gnus-group-quit-config group)))
6533     (when (or no-questions
6534               gnus-expert-user
6535               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6536       (gnus-async-halt-prefetch)
6537       (run-hooks 'gnus-summary-prepare-exit-hook)
6538       (when (gnus-buffer-live-p gnus-article-buffer)
6539         (save-excursion
6540           (set-buffer gnus-article-buffer)
6541           (mm-destroy-parts gnus-article-mime-handles)
6542           ;; Set it to nil for safety reason.
6543           (setq gnus-article-mime-handle-alist nil)
6544           (setq gnus-article-mime-handles nil)))
6545       ;; If we have several article buffers, we kill them at exit.
6546       (unless gnus-single-article-buffer
6547         (gnus-kill-buffer gnus-article-buffer)
6548         (gnus-kill-buffer gnus-original-article-buffer)
6549         (setq gnus-article-current nil))
6550       (if (not gnus-kill-summary-on-exit)
6551           (gnus-deaden-summary)
6552         (gnus-close-group group)
6553         (gnus-summary-clear-local-variables)
6554         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6555           (gnus-summary-clear-local-variables))
6556         (set-buffer gnus-group-buffer)
6557         (gnus-summary-clear-local-variables)
6558         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6559           (gnus-summary-clear-local-variables))
6560         (gnus-kill-buffer gnus-summary-buffer))
6561       (unless gnus-single-article-buffer
6562         (setq gnus-article-current nil))
6563       (when gnus-use-trees
6564         (gnus-tree-close group))
6565       (gnus-async-prefetch-remove-group group)
6566       (when (get-buffer gnus-article-buffer)
6567         (bury-buffer gnus-article-buffer))
6568       ;; Return to the group buffer.
6569       (gnus-configure-windows 'group 'force)
6570       ;; Clear the current group name.
6571       (setq gnus-newsgroup-name nil)
6572       (unless (gnus-ephemeral-group-p group)
6573         (gnus-group-update-group group))
6574       (when (equal (gnus-group-group-name) group)
6575         (gnus-group-next-unread-group 1))
6576       (when quit-config
6577         (gnus-handle-ephemeral-exit quit-config)))))
6578
6579 (defun gnus-handle-ephemeral-exit (quit-config)
6580   "Handle movement when leaving an ephemeral group.
6581 The state which existed when entering the ephemeral is reset."
6582   (if (not (buffer-name (car quit-config)))
6583       (gnus-configure-windows 'group 'force)
6584     (set-buffer (car quit-config))
6585     (cond ((eq major-mode 'gnus-summary-mode)
6586            (gnus-set-global-variables))
6587           ((eq major-mode 'gnus-article-mode)
6588            (save-excursion
6589              ;; The `gnus-summary-buffer' variable may point
6590              ;; to the old summary buffer when using a single
6591              ;; article buffer.
6592              (unless (gnus-buffer-live-p gnus-summary-buffer)
6593                (set-buffer gnus-group-buffer))
6594              (set-buffer gnus-summary-buffer)
6595              (gnus-set-global-variables))))
6596     (if (or (eq (cdr quit-config) 'article)
6597             (eq (cdr quit-config) 'pick))
6598         (progn
6599           ;; The current article may be from the ephemeral group
6600           ;; thus it is best that we reload this article
6601           (gnus-summary-show-article)
6602           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6603               (gnus-configure-windows 'pick 'force)
6604             (gnus-configure-windows (cdr quit-config) 'force)))
6605       (gnus-configure-windows (cdr quit-config) 'force))
6606     (when (eq major-mode 'gnus-summary-mode)
6607       (gnus-summary-next-subject 1 nil t)
6608       (gnus-summary-recenter)
6609       (gnus-summary-position-point))))
6610
6611 ;;; Dead summaries.
6612
6613 (defvar gnus-dead-summary-mode-map nil)
6614
6615 (unless gnus-dead-summary-mode-map
6616   (setq gnus-dead-summary-mode-map (make-keymap))
6617   (suppress-keymap gnus-dead-summary-mode-map)
6618   (substitute-key-definition
6619    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6620   (dolist (key '("\C-d" "\r" "\177" [delete]))
6621     (define-key gnus-dead-summary-mode-map
6622       key 'gnus-summary-wake-up-the-dead))
6623   (dolist (key '("q" "Q"))
6624     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6625
6626 (defvar gnus-dead-summary-mode nil
6627   "Minor mode for Gnus summary buffers.")
6628
6629 (defun gnus-dead-summary-mode (&optional arg)
6630   "Minor mode for Gnus summary buffers."
6631   (interactive "P")
6632   (when (eq major-mode 'gnus-summary-mode)
6633     (make-local-variable 'gnus-dead-summary-mode)
6634     (setq gnus-dead-summary-mode
6635           (if (null arg) (not gnus-dead-summary-mode)
6636             (> (prefix-numeric-value arg) 0)))
6637     (when gnus-dead-summary-mode
6638       (gnus-add-minor-mode
6639        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6640
6641 (defun gnus-deaden-summary ()
6642   "Make the current summary buffer into a dead summary buffer."
6643   ;; Kill any previous dead summary buffer.
6644   (when (and gnus-dead-summary
6645              (buffer-name gnus-dead-summary))
6646     (save-excursion
6647       (set-buffer gnus-dead-summary)
6648       (when gnus-dead-summary-mode
6649         (kill-buffer (current-buffer)))))
6650   ;; Make this the current dead summary.
6651   (setq gnus-dead-summary (current-buffer))
6652   (gnus-dead-summary-mode 1)
6653   (let ((name (buffer-name)))
6654     (when (string-match "Summary" name)
6655       (rename-buffer
6656        (concat (substring name 0 (match-beginning 0)) "Dead "
6657                (substring name (match-beginning 0)))
6658        t)
6659       (bury-buffer))))
6660
6661 (defun gnus-kill-or-deaden-summary (buffer)
6662   "Kill or deaden the summary BUFFER."
6663   (save-excursion
6664     (when (and (buffer-name buffer)
6665                (not gnus-single-article-buffer))
6666       (save-excursion
6667         (set-buffer buffer)
6668         (gnus-kill-buffer gnus-article-buffer)
6669         (gnus-kill-buffer gnus-original-article-buffer)))
6670     (cond
6671      ;; Kill the buffer.
6672      (gnus-kill-summary-on-exit
6673       (when (and gnus-use-trees
6674                  (gnus-buffer-exists-p buffer))
6675         (save-excursion
6676           (set-buffer buffer)
6677           (gnus-tree-close gnus-newsgroup-name)))
6678       (gnus-kill-buffer buffer))
6679      ;; Deaden the buffer.
6680      ((gnus-buffer-exists-p buffer)
6681       (save-excursion
6682         (set-buffer buffer)
6683         (gnus-deaden-summary))))))
6684
6685 (defun gnus-summary-wake-up-the-dead (&rest args)
6686   "Wake up the dead summary buffer."
6687   (interactive)
6688   (gnus-dead-summary-mode -1)
6689   (let ((name (buffer-name)))
6690     (when (string-match "Dead " name)
6691       (rename-buffer
6692        (concat (substring name 0 (match-beginning 0))
6693                (substring name (match-end 0)))
6694        t)))
6695   (gnus-message 3 "This dead summary is now alive again"))
6696
6697 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6698 (defun gnus-summary-fetch-faq (&optional faq-dir)
6699   "Fetch the FAQ for the current group.
6700 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6701 in."
6702   (interactive
6703    (list
6704     (when current-prefix-arg
6705       (completing-read
6706        "FAQ dir: " (and (listp gnus-group-faq-directory)
6707                         (mapcar (lambda (file) (list file))
6708                                 gnus-group-faq-directory))))))
6709   (let (gnus-faq-buffer)
6710     (when (setq gnus-faq-buffer
6711                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6712       (gnus-configure-windows 'summary-faq))))
6713
6714 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6715 (defun gnus-summary-describe-group (&optional force)
6716   "Describe the current newsgroup."
6717   (interactive "P")
6718   (gnus-group-describe-group force gnus-newsgroup-name))
6719
6720 (defun gnus-summary-describe-briefly ()
6721   "Describe summary mode commands briefly."
6722   (interactive)
6723   (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")))
6724
6725 ;; Walking around group mode buffer from summary mode.
6726
6727 (defun gnus-summary-next-group (&optional no-article target-group backward)
6728   "Exit current newsgroup and then select next unread newsgroup.
6729 If prefix argument NO-ARTICLE is non-nil, no article is selected
6730 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6731 previous group instead."
6732   (interactive "P")
6733   ;; Stop pre-fetching.
6734   (gnus-async-halt-prefetch)
6735   (let ((current-group gnus-newsgroup-name)
6736         (current-buffer (current-buffer))
6737         entered)
6738     ;; First we semi-exit this group to update Xrefs and all variables.
6739     ;; We can't do a real exit, because the window conf must remain
6740     ;; the same in case the user is prompted for info, and we don't
6741     ;; want the window conf to change before that...
6742     (gnus-summary-exit t)
6743     (while (not entered)
6744       ;; Then we find what group we are supposed to enter.
6745       (set-buffer gnus-group-buffer)
6746       (gnus-group-jump-to-group current-group)
6747       (setq target-group
6748             (or target-group
6749                 (if (eq gnus-keep-same-level 'best)
6750                     (gnus-summary-best-group gnus-newsgroup-name)
6751                   (gnus-summary-search-group backward gnus-keep-same-level))))
6752       (if (not target-group)
6753           ;; There are no further groups, so we return to the group
6754           ;; buffer.
6755           (progn
6756             (gnus-message 5 "Returning to the group buffer")
6757             (setq entered t)
6758             (when (gnus-buffer-live-p current-buffer)
6759               (set-buffer current-buffer)
6760               (gnus-summary-exit))
6761             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6762         ;; We try to enter the target group.
6763         (gnus-group-jump-to-group target-group)
6764         (let ((unreads (gnus-group-group-unread)))
6765           (if (and (or (eq t unreads)
6766                        (and unreads (not (zerop unreads))))
6767                    (gnus-summary-read-group
6768                     target-group nil no-article
6769                     (and (buffer-name current-buffer) current-buffer)
6770                     nil backward))
6771               (setq entered t)
6772             (setq current-group target-group
6773                   target-group nil)))))))
6774
6775 (defun gnus-summary-prev-group (&optional no-article)
6776   "Exit current newsgroup and then select previous unread newsgroup.
6777 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6778   (interactive "P")
6779   (gnus-summary-next-group no-article nil t))
6780
6781 ;; Walking around summary lines.
6782
6783 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6784   "Go to the first subject satisfying any non-nil constraint.
6785 If UNREAD is non-nil, the article should be unread.
6786 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6787 If UNSEED is non-nil, the article should be unseen.
6788 Returns the article selected or nil if there are no matching articles."
6789   (interactive "P")
6790   (cond
6791    ;; Empty summary.
6792    ((null gnus-newsgroup-data)
6793     (gnus-message 3 "No articles in the group")
6794     nil)
6795    ;; Pick the first article.
6796    ((not (or unread undownloaded unseen))
6797     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6798     (gnus-data-number (car gnus-newsgroup-data)))
6799    ;; Find the first unread article.
6800    (t
6801     (let ((data gnus-newsgroup-data))
6802       (while (and data
6803                   (let ((num (gnus-data-number (car data))))
6804                     (or (memq num gnus-newsgroup-unfetched)
6805                         (not (or (and unread
6806                                       (memq num gnus-newsgroup-unreads))
6807                                  (and undownloaded
6808                                       (memq num gnus-newsgroup-undownloaded))
6809                                  (and unseen
6810                                       (memq num gnus-newsgroup-unseen)))))))
6811         (setq data (cdr data)))
6812       (prog1 
6813           (if data
6814               (progn
6815                 (goto-char (gnus-data-pos (car data)))
6816                 (gnus-data-number (car data)))
6817             (gnus-message 3 "No more%s articles"
6818                           (let* ((r (when unread " unread"))
6819                                  (d (when undownloaded " undownloaded"))
6820                                  (s (when unseen " unseen"))
6821                                  (l (delq nil (list r d s))))
6822                             (cond ((= 3 (length l))
6823                                    (concat r "," d ", or" s))
6824                                   ((= 2 (length l))
6825                                    (concat (car l) ", or" (cadr l)))
6826                                   ((= 1 (length l))
6827                                    (car l))
6828                                   (t
6829                                    ""))))
6830             nil
6831             )
6832         (gnus-summary-position-point))))))
6833
6834 (defun gnus-summary-next-subject (n &optional unread dont-display)
6835   "Go to next N'th summary line.
6836 If N is negative, go to the previous N'th subject line.
6837 If UNREAD is non-nil, only unread articles are selected.
6838 The difference between N and the actual number of steps taken is
6839 returned."
6840   (interactive "p")
6841   (let ((backward (< n 0))
6842         (n (abs n)))
6843     (while (and (> n 0)
6844                 (if backward
6845                     (gnus-summary-find-prev unread)
6846                   (gnus-summary-find-next unread)))
6847       (unless (zerop (setq n (1- n)))
6848         (gnus-summary-show-thread)))
6849     (when (/= 0 n)
6850       (gnus-message 7 "No more%s articles"
6851                     (if unread " unread" "")))
6852     (unless dont-display
6853       (gnus-summary-recenter)
6854       (gnus-summary-position-point))
6855     n))
6856
6857 (defun gnus-summary-next-unread-subject (n)
6858   "Go to next N'th unread summary line."
6859   (interactive "p")
6860   (gnus-summary-next-subject n t))
6861
6862 (defun gnus-summary-prev-subject (n &optional unread)
6863   "Go to previous N'th summary line.
6864 If optional argument UNREAD is non-nil, only unread article is selected."
6865   (interactive "p")
6866   (gnus-summary-next-subject (- n) unread))
6867
6868 (defun gnus-summary-prev-unread-subject (n)
6869   "Go to previous N'th unread summary line."
6870   (interactive "p")
6871   (gnus-summary-next-subject (- n) t))
6872
6873 (defun gnus-summary-goto-subjects (articles)
6874   "Insert the subject header for ARTICLES in the current buffer."
6875   (save-excursion
6876     (dolist (article articles)
6877       (gnus-summary-goto-subject article t)))
6878   (gnus-summary-limit (append articles gnus-newsgroup-limit))
6879   (gnus-summary-position-point))
6880  
6881 (defun gnus-summary-goto-subject (article &optional force silent)
6882   "Go the subject line of ARTICLE.
6883 If FORCE, also allow jumping to articles not currently shown."
6884   (interactive "nArticle number: ")
6885   (unless (numberp article)
6886     (error "Article %s is not a number" article))
6887   (let ((b (point))
6888         (data (gnus-data-find article)))
6889     ;; We read in the article if we have to.
6890     (and (not data)
6891          force
6892          (gnus-summary-insert-subject
6893           article
6894           (if (or (numberp force) (vectorp force)) force)
6895           t)
6896          (setq data (gnus-data-find article)))
6897     (goto-char b)
6898     (if (not data)
6899         (progn
6900           (unless silent
6901             (gnus-message 3 "Can't find article %d" article))
6902           nil)
6903       (let ((pt (gnus-data-pos data)))
6904         (goto-char pt)
6905         (gnus-summary-set-article-display-arrow pt))
6906       (gnus-summary-position-point)
6907       article)))
6908
6909 ;; Walking around summary lines with displaying articles.
6910
6911 (defun gnus-summary-expand-window (&optional arg)
6912   "Make the summary buffer take up the entire Emacs frame.
6913 Given a prefix, will force an `article' buffer configuration."
6914   (interactive "P")
6915   (if arg
6916       (gnus-configure-windows 'article 'force)
6917     (gnus-configure-windows 'summary 'force)))
6918
6919 (defun gnus-summary-display-article (article &optional all-header)
6920   "Display ARTICLE in article buffer."
6921   (when (gnus-buffer-live-p gnus-article-buffer)
6922     (with-current-buffer gnus-article-buffer
6923       (mm-enable-multibyte)))
6924   (gnus-set-global-variables)
6925   (when (gnus-buffer-live-p gnus-article-buffer)
6926     (with-current-buffer gnus-article-buffer
6927       (setq gnus-article-charset gnus-newsgroup-charset)
6928       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6929       (mm-enable-multibyte)))
6930   (if (null article)
6931       nil
6932     (prog1
6933         (if gnus-summary-display-article-function
6934             (funcall gnus-summary-display-article-function article all-header)
6935           (gnus-article-prepare article all-header))
6936       (gnus-run-hooks 'gnus-select-article-hook)
6937       (when (and gnus-current-article
6938                  (not (zerop gnus-current-article)))
6939         (gnus-summary-goto-subject gnus-current-article))
6940       (gnus-summary-recenter)
6941       (when (and gnus-use-trees gnus-show-threads)
6942         (gnus-possibly-generate-tree article)
6943         (gnus-highlight-selected-tree article))
6944       ;; Successfully display article.
6945       (gnus-article-set-window-start
6946        (cdr (assq article gnus-newsgroup-bookmarks))))))
6947
6948 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6949   "Select the current article.
6950 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6951 non-nil, the article will be re-fetched even if it already present in
6952 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6953 be displayed."
6954   ;; Make sure we are in the summary buffer to work around bbdb bug.
6955   (unless (eq major-mode 'gnus-summary-mode)
6956     (set-buffer gnus-summary-buffer))
6957   (let ((article (or article (gnus-summary-article-number)))
6958         (all-headers (not (not all-headers))) ;Must be t or nil.
6959         gnus-summary-display-article-function)
6960     (and (not pseudo)
6961          (gnus-summary-article-pseudo-p article)
6962          (error "This is a pseudo-article"))
6963     (save-excursion
6964       (set-buffer gnus-summary-buffer)
6965       (if (or (and gnus-single-article-buffer
6966                    (or (null gnus-current-article)
6967                        (null gnus-article-current)
6968                        (null (get-buffer gnus-article-buffer))
6969                        (not (eq article (cdr gnus-article-current)))
6970                        (not (equal (car gnus-article-current)
6971                                    gnus-newsgroup-name))))
6972               (and (not gnus-single-article-buffer)
6973                    (or (null gnus-current-article)
6974                        (not (eq gnus-current-article article))))
6975               force)
6976           ;; The requested article is different from the current article.
6977           (progn
6978             (gnus-summary-display-article article all-headers)
6979             (when (gnus-buffer-live-p gnus-article-buffer)
6980               (with-current-buffer gnus-article-buffer
6981                 (if (not gnus-article-decoded-p) ;; a local variable
6982                     (mm-disable-multibyte))))
6983             (gnus-article-set-window-start
6984              (cdr (assq article gnus-newsgroup-bookmarks)))
6985             article)
6986         'old))))
6987
6988 (defun gnus-summary-force-verify-and-decrypt ()
6989   "Display buttons for signed/encrypted parts and verify/decrypt them."
6990   (interactive)
6991   (let ((mm-verify-option 'known)
6992         (mm-decrypt-option 'known)
6993         (gnus-buttonized-mime-types (append (list "multipart/signed"
6994                                                   "multipart/encrypted")
6995                                             gnus-buttonized-mime-types)))
6996     (gnus-summary-select-article nil 'force)))
6997
6998 (defun gnus-summary-set-current-mark (&optional current-mark)
6999   "Obsolete function."
7000   nil)
7001
7002 (defun gnus-summary-next-article (&optional unread subject backward push)
7003   "Select the next article.
7004 If UNREAD, only unread articles are selected.
7005 If SUBJECT, only articles with SUBJECT are selected.
7006 If BACKWARD, the previous article is selected instead of the next."
7007   (interactive "P")
7008   (cond
7009    ;; Is there such an article?
7010    ((and (gnus-summary-search-forward unread subject backward)
7011          (or (gnus-summary-display-article (gnus-summary-article-number))
7012              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7013     (gnus-summary-position-point))
7014    ;; If not, we try the first unread, if that is wanted.
7015    ((and subject
7016          gnus-auto-select-same
7017          (gnus-summary-first-unread-article))
7018     (gnus-summary-position-point)
7019     (gnus-message 6 "Wrapped"))
7020    ;; Try to get next/previous article not displayed in this group.
7021    ((and gnus-auto-extend-newsgroup
7022          (not unread) (not subject))
7023     (gnus-summary-goto-article
7024      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7025      nil (count-lines (point-min) (point))))
7026    ;; Go to next/previous group.
7027    (t
7028     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7029       (gnus-summary-jump-to-group gnus-newsgroup-name))
7030     (let ((cmd last-command-char)
7031           (point
7032            (save-excursion
7033              (set-buffer gnus-group-buffer)
7034              (point)))
7035           (group
7036            (if (eq gnus-keep-same-level 'best)
7037                (gnus-summary-best-group gnus-newsgroup-name)
7038              (gnus-summary-search-group backward gnus-keep-same-level))))
7039       ;; For some reason, the group window gets selected.  We change
7040       ;; it back.
7041       (select-window (get-buffer-window (current-buffer)))
7042       ;; Select next unread newsgroup automagically.
7043       (cond
7044        ((or (not gnus-auto-select-next)
7045             (not cmd))
7046         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7047        ((or (eq gnus-auto-select-next 'quietly)
7048             (and (eq gnus-auto-select-next 'slightly-quietly)
7049                  push)
7050             (and (eq gnus-auto-select-next 'almost-quietly)
7051                  (gnus-summary-last-article-p)))
7052         ;; Select quietly.
7053         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7054             (gnus-summary-exit)
7055           (gnus-message 7 "No more%s articles (%s)..."
7056                         (if unread " unread" "")
7057                         (if group (concat "selecting " group)
7058                           "exiting"))
7059           (gnus-summary-next-group nil group backward)))
7060        (t
7061         (when (gnus-key-press-event-p last-input-event)
7062           (gnus-summary-walk-group-buffer
7063            gnus-newsgroup-name cmd unread backward point))))))))
7064
7065 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7066   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7067                       (?\C-p (gnus-group-prev-unread-group 1))))
7068         (cursor-in-echo-area t)
7069         keve key group ended prompt)
7070     (save-excursion
7071       (set-buffer gnus-group-buffer)
7072       (goto-char start)
7073       (setq group
7074             (if (eq gnus-keep-same-level 'best)
7075                 (gnus-summary-best-group gnus-newsgroup-name)
7076               (gnus-summary-search-group backward gnus-keep-same-level))))
7077     (while (not ended)
7078       (setq prompt
7079             (format
7080              "No more%s articles%s " (if unread " unread" "")
7081              (if (and group
7082                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7083                  (format " (Type %s for %s [%s])"
7084                          (single-key-description cmd) group
7085                          (car (gnus-gethash group gnus-newsrc-hashtb)))
7086                (format " (Type %s to exit %s)"
7087                        (single-key-description cmd)
7088                        gnus-newsgroup-name))))
7089       ;; Confirm auto selection.
7090       (setq key (car (setq keve (gnus-read-event-char prompt)))
7091             ended t)
7092       (cond
7093        ((assq key keystrokes)
7094         (let ((obuf (current-buffer)))
7095           (switch-to-buffer gnus-group-buffer)
7096           (when group
7097             (gnus-group-jump-to-group group))
7098           (eval (cadr (assq key keystrokes)))
7099           (setq group (gnus-group-group-name))
7100           (switch-to-buffer obuf))
7101         (setq ended nil))
7102        ((equal key cmd)
7103         (if (or (not group)
7104                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7105             (gnus-summary-exit)
7106           (gnus-summary-next-group nil group backward)))
7107        (t
7108         (push (cdr keve) unread-command-events))))))
7109
7110 (defun gnus-summary-next-unread-article ()
7111   "Select unread article after current one."
7112   (interactive)
7113   (gnus-summary-next-article
7114    (or (not (eq gnus-summary-goto-unread 'never))
7115        (gnus-summary-last-article-p (gnus-summary-article-number)))
7116    (and gnus-auto-select-same
7117         (gnus-summary-article-subject))))
7118
7119 (defun gnus-summary-prev-article (&optional unread subject)
7120   "Select the article after the current one.
7121 If UNREAD is non-nil, only unread articles are selected."
7122   (interactive "P")
7123   (gnus-summary-next-article unread subject t))
7124
7125 (defun gnus-summary-prev-unread-article ()
7126   "Select unread article before current one."
7127   (interactive)
7128   (gnus-summary-prev-article
7129    (or (not (eq gnus-summary-goto-unread 'never))
7130        (gnus-summary-first-article-p (gnus-summary-article-number)))
7131    (and gnus-auto-select-same
7132         (gnus-summary-article-subject))))
7133
7134 (defun gnus-summary-next-page (&optional lines circular stop)
7135   "Show next page of the selected article.
7136 If at the end of the current article, select the next article.
7137 LINES says how many lines should be scrolled up.
7138
7139 If CIRCULAR is non-nil, go to the start of the article instead of
7140 selecting the next article when reaching the end of the current
7141 article.
7142
7143 If STOP is non-nil, just stop when reaching the end of the message."
7144   (interactive "P")
7145   (setq gnus-summary-buffer (current-buffer))
7146   (gnus-set-global-variables)
7147   (let ((article (gnus-summary-article-number))
7148         (article-window (get-buffer-window gnus-article-buffer t))
7149         endp)
7150     ;; If the buffer is empty, we have no article.
7151     (unless article
7152       (error "No article to select"))
7153     (gnus-configure-windows 'article)
7154     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7155         (if (and (eq gnus-summary-goto-unread 'never)
7156                  (not (gnus-summary-last-article-p article)))
7157             (gnus-summary-next-article)
7158           (gnus-summary-next-unread-article))
7159       (if (or (null gnus-current-article)
7160               (null gnus-article-current)
7161               (/= article (cdr gnus-article-current))
7162               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7163           ;; Selected subject is different from current article's.
7164           (gnus-summary-display-article article)
7165         (when article-window
7166           (gnus-eval-in-buffer-window gnus-article-buffer
7167             (setq endp (or (gnus-article-next-page lines)
7168                            (gnus-article-only-boring-p))))
7169           (when endp
7170             (cond (stop
7171                    (gnus-message 3 "End of message"))
7172                   (circular
7173                    (gnus-summary-beginning-of-article))
7174                   (lines
7175                    (gnus-message 3 "End of message"))
7176                   ((null lines)
7177                    (if (and (eq gnus-summary-goto-unread 'never)
7178                             (not (gnus-summary-last-article-p article)))
7179                        (gnus-summary-next-article)
7180                      (gnus-summary-next-unread-article))))))))
7181     (gnus-summary-recenter)
7182     (gnus-summary-position-point)))
7183
7184 (defun gnus-summary-prev-page (&optional lines move)
7185   "Show previous page of selected article.
7186 Argument LINES specifies lines to be scrolled down.
7187 If MOVE, move to the previous unread article if point is at
7188 the beginning of the buffer."
7189   (interactive "P")
7190   (let ((article (gnus-summary-article-number))
7191         (article-window (get-buffer-window gnus-article-buffer t))
7192         endp)
7193     (gnus-configure-windows 'article)
7194     (if (or (null gnus-current-article)
7195             (null gnus-article-current)
7196             (/= article (cdr gnus-article-current))
7197             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7198         ;; Selected subject is different from current article's.
7199         (gnus-summary-display-article article)
7200       (gnus-summary-recenter)
7201       (when article-window
7202         (gnus-eval-in-buffer-window gnus-article-buffer
7203           (setq endp (gnus-article-prev-page lines)))
7204         (when (and move endp)
7205           (cond (lines
7206                  (gnus-message 3 "Beginning of message"))
7207                 ((null lines)
7208                  (if (and (eq gnus-summary-goto-unread 'never)
7209                           (not (gnus-summary-first-article-p article)))
7210                      (gnus-summary-prev-article)
7211                    (gnus-summary-prev-unread-article))))))))
7212   (gnus-summary-position-point))
7213
7214 (defun gnus-summary-prev-page-or-article (&optional lines)
7215   "Show previous page of selected article.
7216 Argument LINES specifies lines to be scrolled down.
7217 If at the beginning of the article, go to the next article."
7218   (interactive "P")
7219   (gnus-summary-prev-page lines t))
7220
7221 (defun gnus-summary-scroll-up (lines)
7222   "Scroll up (or down) one line current article.
7223 Argument LINES specifies lines to be scrolled up (or down if negative)."
7224   (interactive "p")
7225   (gnus-configure-windows 'article)
7226   (gnus-summary-show-thread)
7227   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7228     (gnus-eval-in-buffer-window gnus-article-buffer
7229       (cond ((> lines 0)
7230              (when (gnus-article-next-page lines)
7231                (gnus-message 3 "End of message")))
7232             ((< lines 0)
7233              (gnus-article-prev-page (- lines))))))
7234   (gnus-summary-recenter)
7235   (gnus-summary-position-point))
7236
7237 (defun gnus-summary-scroll-down (lines)
7238   "Scroll down (or up) one line current article.
7239 Argument LINES specifies lines to be scrolled down (or up if negative)."
7240   (interactive "p")
7241   (gnus-summary-scroll-up (- lines)))
7242
7243 (defun gnus-summary-next-same-subject ()
7244   "Select next article which has the same subject as current one."
7245   (interactive)
7246   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7247
7248 (defun gnus-summary-prev-same-subject ()
7249   "Select previous article which has the same subject as current one."
7250   (interactive)
7251   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7252
7253 (defun gnus-summary-next-unread-same-subject ()
7254   "Select next unread article which has the same subject as current one."
7255   (interactive)
7256   (gnus-summary-next-article t (gnus-summary-article-subject)))
7257
7258 (defun gnus-summary-prev-unread-same-subject ()
7259   "Select previous unread article which has the same subject as current one."
7260   (interactive)
7261   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7262
7263 (defun gnus-summary-first-unread-article ()
7264   "Select the first unread article.
7265 Return nil if there are no unread articles."
7266   (interactive)
7267   (prog1
7268       (when (gnus-summary-first-subject t)
7269         (gnus-summary-show-thread)
7270         (gnus-summary-first-subject t)
7271         (gnus-summary-display-article (gnus-summary-article-number)))
7272     (gnus-summary-position-point)))
7273
7274 (defun gnus-summary-first-unread-subject ()
7275   "Place the point on the subject line of the first unread article.
7276 Return nil if there are no unread articles."
7277   (interactive)
7278   (prog1
7279       (when (gnus-summary-first-subject t)
7280         (gnus-summary-show-thread)
7281         (gnus-summary-first-subject t))
7282     (gnus-summary-position-point)))
7283
7284 (defun gnus-summary-first-unseen-subject ()
7285   "Place the point on the subject line of the first unseen article.
7286 Return nil if there are no unseen articles."
7287   (interactive)
7288   (prog1
7289       (when (gnus-summary-first-subject nil nil t)
7290         (gnus-summary-show-thread)
7291         (gnus-summary-first-subject nil nil t))
7292     (gnus-summary-position-point)))
7293
7294 (defun gnus-summary-first-unseen-or-unread-subject ()
7295   "Place the point on the subject line of the first unseen article or,
7296 if all article have been seen, on the subject line of the first unread
7297 article."
7298   (interactive)
7299   (prog1
7300       (unless (when (gnus-summary-first-subject nil nil t)
7301                 (gnus-summary-show-thread)
7302                 (gnus-summary-first-subject nil nil t))
7303         (when (gnus-summary-first-subject t)
7304           (gnus-summary-show-thread)
7305           (gnus-summary-first-subject t)))
7306     (gnus-summary-position-point)))
7307
7308 (defun gnus-summary-first-article ()
7309   "Select the first article.
7310 Return nil if there are no articles."
7311   (interactive)
7312   (prog1
7313       (when (gnus-summary-first-subject)
7314         (gnus-summary-show-thread)
7315         (gnus-summary-first-subject)
7316         (gnus-summary-display-article (gnus-summary-article-number)))
7317     (gnus-summary-position-point)))
7318
7319 (defun gnus-summary-best-unread-article (&optional arg)
7320   "Select the unread article with the highest score.
7321 If given a prefix argument, select the next unread article that has a
7322 score higher than the default score."
7323   (interactive "P")
7324   (let ((article (if arg
7325                      (gnus-summary-better-unread-subject)
7326                    (gnus-summary-best-unread-subject))))
7327     (if article
7328         (gnus-summary-goto-article article)
7329       (error "No unread articles"))))
7330
7331 (defun gnus-summary-best-unread-subject ()
7332   "Select the unread subject with the highest score."
7333   (interactive)
7334   (let ((best -1000000)
7335         (data gnus-newsgroup-data)
7336         article score)
7337     (while data
7338       (and (gnus-data-unread-p (car data))
7339            (> (setq score
7340                     (gnus-summary-article-score (gnus-data-number (car data))))
7341               best)
7342            (setq best score
7343                  article (gnus-data-number (car data))))
7344       (setq data (cdr data)))
7345     (when article
7346       (gnus-summary-goto-subject article))
7347     (gnus-summary-position-point)
7348     article))
7349
7350 (defun gnus-summary-better-unread-subject ()
7351   "Select the first unread subject that has a score over the default score."
7352   (interactive)
7353   (let ((data gnus-newsgroup-data)
7354         article score)
7355     (while (and (setq article (gnus-data-number (car data)))
7356                 (or (gnus-data-read-p (car data))
7357                     (not (> (gnus-summary-article-score article)
7358                             gnus-summary-default-score))))
7359       (setq data (cdr data)))
7360     (when article
7361       (gnus-summary-goto-subject article))
7362     (gnus-summary-position-point)
7363     article))
7364
7365 (defun gnus-summary-last-subject ()
7366   "Go to the last displayed subject line in the group."
7367   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7368     (when article
7369       (gnus-summary-goto-subject article))))
7370
7371 (defun gnus-summary-goto-article (article &optional all-headers force)
7372   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7373 If ALL-HEADERS is non-nil, no header lines are hidden.
7374 If FORCE, go to the article even if it isn't displayed.  If FORCE
7375 is a number, it is the line the article is to be displayed on."
7376   (interactive
7377    (list
7378     (completing-read
7379      "Article number or Message-ID: "
7380      (mapcar (lambda (number) (list (int-to-string number)))
7381              gnus-newsgroup-limit))
7382     current-prefix-arg
7383     t))
7384   (prog1
7385       (if (and (stringp article)
7386                (string-match "@" article))
7387           (gnus-summary-refer-article article)
7388         (when (stringp article)
7389           (setq article (string-to-number article)))
7390         (if (gnus-summary-goto-subject article force)
7391             (gnus-summary-display-article article all-headers)
7392           (gnus-message 4 "Couldn't go to article %s" article) nil))
7393     (gnus-summary-position-point)))
7394
7395 (defun gnus-summary-goto-last-article ()
7396   "Go to the previously read article."
7397   (interactive)
7398   (prog1
7399       (when gnus-last-article
7400         (gnus-summary-goto-article gnus-last-article nil t))
7401     (gnus-summary-position-point)))
7402
7403 (defun gnus-summary-pop-article (number)
7404   "Pop one article off the history and go to the previous.
7405 NUMBER articles will be popped off."
7406   (interactive "p")
7407   (let (to)
7408     (setq gnus-newsgroup-history
7409           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7410     (if to
7411         (gnus-summary-goto-article (car to) nil t)
7412       (error "Article history empty")))
7413   (gnus-summary-position-point))
7414
7415 ;; Summary commands and functions for limiting the summary buffer.
7416
7417 (defun gnus-summary-limit-to-articles (n)
7418   "Limit the summary buffer to the next N articles.
7419 If not given a prefix, use the process marked articles instead."
7420   (interactive "P")
7421   (prog1
7422       (let ((articles (gnus-summary-work-articles n)))
7423         (setq gnus-newsgroup-processable nil)
7424         (gnus-summary-limit articles))
7425     (gnus-summary-position-point)))
7426
7427 (defun gnus-summary-pop-limit (&optional total)
7428   "Restore the previous limit.
7429 If given a prefix, remove all limits."
7430   (interactive "P")
7431   (when total
7432     (setq gnus-newsgroup-limits
7433           (list (mapcar (lambda (h) (mail-header-number h))
7434                         gnus-newsgroup-headers))))
7435   (unless gnus-newsgroup-limits
7436     (error "No limit to pop"))
7437   (prog1
7438       (gnus-summary-limit nil 'pop)
7439     (gnus-summary-position-point)))
7440
7441 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7442   "Limit the summary buffer to articles that have subjects that match a regexp.
7443 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7444   (interactive
7445    (list (read-string (if current-prefix-arg
7446                           "Exclude subject (regexp): "
7447                         "Limit to subject (regexp): "))
7448          nil current-prefix-arg))
7449   (unless header
7450     (setq header "subject"))
7451   (when (not (equal "" subject))
7452     (prog1
7453         (let ((articles (gnus-summary-find-matching
7454                          (or header "subject") subject 'all nil nil
7455                          not-matching)))
7456           (unless articles
7457             (error "Found no matches for \"%s\"" subject))
7458           (gnus-summary-limit articles))
7459       (gnus-summary-position-point))))
7460
7461 (defun gnus-summary-limit-to-author (from &optional not-matching)
7462   "Limit the summary buffer to articles that have authors that match a regexp.
7463 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7464   (interactive
7465    (list (read-string (if current-prefix-arg
7466                           "Exclude author (regexp): "
7467                         "Limit to author (regexp): "))
7468          current-prefix-arg))
7469   (gnus-summary-limit-to-subject from "from" not-matching))
7470
7471 (defun gnus-summary-limit-to-age (age &optional younger-p)
7472   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7473 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7474 articles that are younger than AGE days."
7475   (interactive
7476    (let ((younger current-prefix-arg)
7477          (days-got nil)
7478          days)
7479      (while (not days-got)
7480        (setq days (if younger
7481                       (read-string "Limit to articles younger than (in days, older when negative): ")
7482                     (read-string
7483                      "Limit to articles older than (in days, younger when negative): ")))
7484        (when (> (length days) 0)
7485          (setq days (read days)))
7486        (if (numberp days)
7487            (progn
7488              (setq days-got t)
7489              (if (< days 0)
7490                  (progn
7491                    (setq younger (not younger))
7492                    (setq days (* days -1)))))
7493          (message "Please enter a number.")
7494          (sleep-for 1)))
7495      (list days younger)))
7496   (prog1
7497       (let ((data gnus-newsgroup-data)
7498             (cutoff (days-to-time age))
7499             articles d date is-younger)
7500         (while (setq d (pop data))
7501           (when (and (vectorp (gnus-data-header d))
7502                      (setq date (mail-header-date (gnus-data-header d))))
7503             (setq is-younger (time-less-p
7504                               (time-since (condition-case ()
7505                                               (date-to-time date)
7506                                             (error '(0 0))))
7507                               cutoff))
7508             (when (if younger-p
7509                       is-younger
7510                     (not is-younger))
7511               (push (gnus-data-number d) articles))))
7512         (gnus-summary-limit (nreverse articles)))
7513     (gnus-summary-position-point)))
7514
7515 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7516   "Limit the summary buffer to articles that match an 'extra' header."
7517   (interactive
7518    (let ((header
7519           (intern
7520            (gnus-completing-read-with-default
7521             (symbol-name (car gnus-extra-headers))
7522             (if current-prefix-arg
7523                 "Exclude extra header:"
7524               "Limit extra header:")
7525             (mapcar (lambda (x)
7526                       (cons (symbol-name x) x))
7527                     gnus-extra-headers)
7528             nil
7529             t))))
7530      (list header
7531            (read-string (format "%s header %s (regexp): "
7532                                 (if current-prefix-arg "Exclude" "Limit to")
7533                                 header))
7534            current-prefix-arg)))
7535   (when (not (equal "" regexp))
7536     (prog1
7537         (let ((articles (gnus-summary-find-matching
7538                          (cons 'extra header) regexp 'all nil nil
7539                          not-matching)))
7540           (unless articles
7541             (error "Found no matches for \"%s\"" regexp))
7542           (gnus-summary-limit articles))
7543       (gnus-summary-position-point))))
7544
7545 (defun gnus-summary-limit-to-display-predicate ()
7546   "Limit the summary buffer to the predicated in the `display' group parameter."
7547   (interactive)
7548   (unless gnus-newsgroup-display
7549     (error "There is no `display' group parameter"))
7550   (let (articles)
7551     (dolist (number gnus-newsgroup-articles)
7552       (when (funcall gnus-newsgroup-display)
7553         (push number articles)))
7554     (gnus-summary-limit articles))
7555   (gnus-summary-position-point))
7556
7557 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7558 (make-obsolete
7559  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7560
7561 (defun gnus-summary-limit-to-unread (&optional all)
7562   "Limit the summary buffer to articles that are not marked as read.
7563 If ALL is non-nil, limit strictly to unread articles."
7564   (interactive "P")
7565   (if all
7566       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7567     (gnus-summary-limit-to-marks
7568      ;; Concat all the marks that say that an article is read and have
7569      ;; those removed.
7570      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7571            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7572            gnus-low-score-mark gnus-expirable-mark
7573            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7574            gnus-duplicate-mark gnus-souped-mark)
7575      'reverse)))
7576
7577 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7578 (make-obsolete 'gnus-summary-delete-marked-with
7579                'gnus-summary-limit-exclude-marks)
7580
7581 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7582   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7583 If REVERSE, limit the summary buffer to articles that are marked
7584 with MARKS.  MARKS can either be a string of marks or a list of marks.
7585 Returns how many articles were removed."
7586   (interactive "sMarks: ")
7587   (gnus-summary-limit-to-marks marks t))
7588
7589 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7590   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7591 If REVERSE (the prefix), limit the summary buffer to articles that are
7592 not marked with MARKS.  MARKS can either be a string of marks or a
7593 list of marks.
7594 Returns how many articles were removed."
7595   (interactive "sMarks: \nP")
7596   (prog1
7597       (let ((data gnus-newsgroup-data)
7598             (marks (if (listp marks) marks
7599                      (append marks nil))) ; Transform to list.
7600             articles)
7601         (while data
7602           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7603                   (memq (gnus-data-mark (car data)) marks))
7604             (push (gnus-data-number (car data)) articles))
7605           (setq data (cdr data)))
7606         (gnus-summary-limit articles))
7607     (gnus-summary-position-point)))
7608
7609 (defun gnus-summary-limit-to-score (score)
7610   "Limit to articles with score at or above SCORE."
7611   (interactive "NLimit to articles with score of at least: ")
7612   (let ((data gnus-newsgroup-data)
7613         articles)
7614     (while data
7615       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7616                 score)
7617         (push (gnus-data-number (car data)) articles))
7618       (setq data (cdr data)))
7619     (prog1
7620         (gnus-summary-limit articles)
7621       (gnus-summary-position-point))))
7622
7623 (defun gnus-summary-limit-to-unseen ()
7624   "Limit to unseen articles."
7625   (interactive)
7626   (prog1
7627       (gnus-summary-limit gnus-newsgroup-unseen)
7628     (gnus-summary-position-point)))
7629
7630 (defun gnus-summary-limit-include-thread (id)
7631   "Display all the hidden articles that is in the thread with ID in it.
7632 When called interactively, ID is the Message-ID of the current
7633 article."
7634   (interactive (list (mail-header-id (gnus-summary-article-header))))
7635   (let ((articles (gnus-articles-in-thread
7636                    (gnus-id-to-thread (gnus-root-id id)))))
7637     (prog1
7638         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7639       (gnus-summary-limit-include-matching-articles
7640        "subject"
7641        (regexp-quote (gnus-simplify-subject-re
7642                       (mail-header-subject (gnus-id-to-header id)))))
7643       (gnus-summary-position-point))))
7644
7645 (defun gnus-summary-limit-include-matching-articles (header regexp)
7646   "Display all the hidden articles that have HEADERs that match REGEXP."
7647   (interactive (list (read-string "Match on header: ")
7648                      (read-string "Regexp: ")))
7649   (let ((articles (gnus-find-matching-articles header regexp)))
7650     (prog1
7651         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7652       (gnus-summary-position-point))))
7653
7654 (defun gnus-summary-insert-dormant-articles ()
7655   "Insert all the dormat articles for this group into the current buffer."
7656   (interactive)
7657   (let ((gnus-verbose (max 6 gnus-verbose)))
7658     (if (not gnus-newsgroup-dormant)
7659         (gnus-message 3 "No cached articles for this group")
7660       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7661
7662 (defun gnus-summary-limit-include-dormant ()
7663   "Display all the hidden articles that are marked as dormant.
7664 Note that this command only works on a subset of the articles currently
7665 fetched for this group."
7666   (interactive)
7667   (unless gnus-newsgroup-dormant
7668     (error "There are no dormant articles in this group"))
7669   (prog1
7670       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7671     (gnus-summary-position-point)))
7672
7673 (defun gnus-summary-limit-exclude-dormant ()
7674   "Hide all dormant articles."
7675   (interactive)
7676   (prog1
7677       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7678     (gnus-summary-position-point)))
7679
7680 (defun gnus-summary-limit-exclude-childless-dormant ()
7681   "Hide all dormant articles that have no children."
7682   (interactive)
7683   (let ((data (gnus-data-list t))
7684         articles d children)
7685     ;; Find all articles that are either not dormant or have
7686     ;; children.
7687     (while (setq d (pop data))
7688       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7689                 (and (setq children
7690                            (gnus-article-children (gnus-data-number d)))
7691                      (let (found)
7692                        (while children
7693                          (when (memq (car children) articles)
7694                            (setq children nil
7695                                  found t))
7696                          (pop children))
7697                        found)))
7698         (push (gnus-data-number d) articles)))
7699     ;; Do the limiting.
7700     (prog1
7701         (gnus-summary-limit articles)
7702       (gnus-summary-position-point))))
7703
7704 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7705   "Mark all unread excluded articles as read.
7706 If ALL, mark even excluded ticked and dormants as read."
7707   (interactive "P")
7708   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7709   (let ((articles (gnus-sorted-ndifference
7710                    (sort
7711                     (mapcar (lambda (h) (mail-header-number h))
7712                             gnus-newsgroup-headers)
7713                     '<)
7714                    gnus-newsgroup-limit))
7715         article)
7716     (setq gnus-newsgroup-unreads
7717           (gnus-sorted-intersection gnus-newsgroup-unreads
7718                                     gnus-newsgroup-limit))
7719     (if all
7720         (setq gnus-newsgroup-dormant nil
7721               gnus-newsgroup-marked nil
7722               gnus-newsgroup-reads
7723               (nconc
7724                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7725                gnus-newsgroup-reads))
7726       (while (setq article (pop articles))
7727         (unless (or (memq article gnus-newsgroup-dormant)
7728                     (memq article gnus-newsgroup-marked))
7729           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7730
7731 (defun gnus-summary-limit (articles &optional pop)
7732   (if pop
7733       ;; We pop the previous limit off the stack and use that.
7734       (setq articles (car gnus-newsgroup-limits)
7735             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7736     ;; We use the new limit, so we push the old limit on the stack.
7737     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7738   ;; Set the limit.
7739   (setq gnus-newsgroup-limit articles)
7740   (let ((total (length gnus-newsgroup-data))
7741         (data (gnus-data-find-list (gnus-summary-article-number)))
7742         (gnus-summary-mark-below nil)   ; Inhibit this.
7743         found)
7744     ;; This will do all the work of generating the new summary buffer
7745     ;; according to the new limit.
7746     (gnus-summary-prepare)
7747     ;; Hide any threads, possibly.
7748     (gnus-summary-maybe-hide-threads)
7749     ;; Try to return to the article you were at, or one in the
7750     ;; neighborhood.
7751     (when data
7752       ;; We try to find some article after the current one.
7753       (while data
7754         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7755           (setq data nil
7756                 found t))
7757         (setq data (cdr data))))
7758     (unless found
7759       ;; If there is no data, that means that we were after the last
7760       ;; article.  The same goes when we can't find any articles
7761       ;; after the current one.
7762       (goto-char (point-max))
7763       (gnus-summary-find-prev))
7764     (gnus-set-mode-line 'summary)
7765     ;; We return how many articles were removed from the summary
7766     ;; buffer as a result of the new limit.
7767     (- total (length gnus-newsgroup-data))))
7768
7769 (defsubst gnus-invisible-cut-children (threads)
7770   (let ((num 0))
7771     (while threads
7772       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7773         (incf num))
7774       (pop threads))
7775     (< num 2)))
7776
7777 (defsubst gnus-cut-thread (thread)
7778   "Go forwards in the thread until we find an article that we want to display."
7779   (when (or (eq gnus-fetch-old-headers 'some)
7780             (eq gnus-fetch-old-headers 'invisible)
7781             (numberp gnus-fetch-old-headers)
7782             (eq gnus-build-sparse-threads 'some)
7783             (eq gnus-build-sparse-threads 'more))
7784     ;; Deal with old-fetched headers and sparse threads.
7785     (while (and
7786             thread
7787             (or
7788              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7789              (gnus-summary-article-ancient-p
7790               (mail-header-number (car thread))))
7791             (if (or (<= (length (cdr thread)) 1)
7792                     (eq gnus-fetch-old-headers 'invisible))
7793                 (setq gnus-newsgroup-limit
7794                       (delq (mail-header-number (car thread))
7795                             gnus-newsgroup-limit)
7796                       thread (cadr thread))
7797               (when (gnus-invisible-cut-children (cdr thread))
7798                 (let ((th (cdr thread)))
7799                   (while th
7800                     (if (memq (mail-header-number (caar th))
7801                               gnus-newsgroup-limit)
7802                         (setq thread (car th)
7803                               th nil)
7804                       (setq th (cdr th))))))))))
7805   thread)
7806
7807 (defun gnus-cut-threads (threads)
7808   "Cut off all uninteresting articles from the beginning of threads."
7809   (when (or (eq gnus-fetch-old-headers 'some)
7810             (eq gnus-fetch-old-headers 'invisible)
7811             (numberp gnus-fetch-old-headers)
7812             (eq gnus-build-sparse-threads 'some)
7813             (eq gnus-build-sparse-threads 'more))
7814     (let ((th threads))
7815       (while th
7816         (setcar th (gnus-cut-thread (car th)))
7817         (setq th (cdr th)))))
7818   ;; Remove nixed out threads.
7819   (delq nil threads))
7820
7821 (defun gnus-summary-initial-limit (&optional show-if-empty)
7822   "Figure out what the initial limit is supposed to be on group entry.
7823 This entails weeding out unwanted dormants, low-scored articles,
7824 fetch-old-headers verbiage, and so on."
7825   ;; Most groups have nothing to remove.
7826   (if (or gnus-inhibit-limiting
7827           (and (null gnus-newsgroup-dormant)
7828                (eq gnus-newsgroup-display 'gnus-not-ignore)
7829                (not (eq gnus-fetch-old-headers 'some))
7830                (not (numberp gnus-fetch-old-headers))
7831                (not (eq gnus-fetch-old-headers 'invisible))
7832                (null gnus-summary-expunge-below)
7833                (not (eq gnus-build-sparse-threads 'some))
7834                (not (eq gnus-build-sparse-threads 'more))
7835                (null gnus-thread-expunge-below)
7836                (not gnus-use-nocem)))
7837       ()                                ; Do nothing.
7838     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7839     (setq gnus-newsgroup-limit nil)
7840     (mapatoms
7841      (lambda (node)
7842        (unless (car (symbol-value node))
7843          ;; These threads have no parents -- they are roots.
7844          (let ((nodes (cdr (symbol-value node)))
7845                thread)
7846            (while nodes
7847              (if (and gnus-thread-expunge-below
7848                       (< (gnus-thread-total-score (car nodes))
7849                          gnus-thread-expunge-below))
7850                  (gnus-expunge-thread (pop nodes))
7851                (setq thread (pop nodes))
7852                (gnus-summary-limit-children thread))))))
7853      gnus-newsgroup-dependencies)
7854     ;; If this limitation resulted in an empty group, we might
7855     ;; pop the previous limit and use it instead.
7856     (when (and (not gnus-newsgroup-limit)
7857                show-if-empty)
7858       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7859     gnus-newsgroup-limit))
7860
7861 (defun gnus-summary-limit-children (thread)
7862   "Return 1 if this subthread is visible and 0 if it is not."
7863   ;; First we get the number of visible children to this thread.  This
7864   ;; is done by recursing down the thread using this function, so this
7865   ;; will really go down to a leaf article first, before slowly
7866   ;; working its way up towards the root.
7867   (when thread
7868     (let* ((max-lisp-eval-depth 5000)
7869            (children
7870            (if (cdr thread)
7871                (apply '+ (mapcar 'gnus-summary-limit-children
7872                                  (cdr thread)))
7873              0))
7874           (number (mail-header-number (car thread)))
7875           score)
7876       (if (and
7877            (not (memq number gnus-newsgroup-marked))
7878            (or
7879             ;; If this article is dormant and has absolutely no visible
7880             ;; children, then this article isn't visible.
7881             (and (memq number gnus-newsgroup-dormant)
7882                  (zerop children))
7883             ;; If this is "fetch-old-headered" and there is no
7884             ;; visible children, then we don't want this article.
7885             (and (or (eq gnus-fetch-old-headers 'some)
7886                      (numberp gnus-fetch-old-headers))
7887                  (gnus-summary-article-ancient-p number)
7888                  (zerop children))
7889             ;; If this is "fetch-old-headered" and `invisible', then
7890             ;; we don't want this article.
7891             (and (eq gnus-fetch-old-headers 'invisible)
7892                  (gnus-summary-article-ancient-p number))
7893             ;; If this is a sparsely inserted article with no children,
7894             ;; we don't want it.
7895             (and (eq gnus-build-sparse-threads 'some)
7896                  (gnus-summary-article-sparse-p number)
7897                  (zerop children))
7898             ;; If we use expunging, and this article is really
7899             ;; low-scored, then we don't want this article.
7900             (when (and gnus-summary-expunge-below
7901                        (< (setq score
7902                                 (or (cdr (assq number gnus-newsgroup-scored))
7903                                     gnus-summary-default-score))
7904                           gnus-summary-expunge-below))
7905               ;; We increase the expunge-tally here, but that has
7906               ;; nothing to do with the limits, really.
7907               (incf gnus-newsgroup-expunged-tally)
7908               ;; We also mark as read here, if that's wanted.
7909               (when (and gnus-summary-mark-below
7910                          (< score gnus-summary-mark-below))
7911                 (setq gnus-newsgroup-unreads
7912                       (delq number gnus-newsgroup-unreads))
7913                 (if gnus-newsgroup-auto-expire
7914                     (push number gnus-newsgroup-expirable)
7915                   (push (cons number gnus-low-score-mark)
7916                         gnus-newsgroup-reads)))
7917               t)
7918             ;; Do the `display' group parameter.
7919             (and gnus-newsgroup-display
7920                  (not (funcall gnus-newsgroup-display)))
7921             ;; Check NoCeM things.
7922             (if (and gnus-use-nocem
7923                      (gnus-nocem-unwanted-article-p
7924                       (mail-header-id (car thread))))
7925                 (progn
7926                   (setq gnus-newsgroup-unreads
7927                         (delq number gnus-newsgroup-unreads))
7928                   t))))
7929           ;; Nope, invisible article.
7930           0
7931         ;; Ok, this article is to be visible, so we add it to the limit
7932         ;; and return 1.
7933         (push number gnus-newsgroup-limit)
7934         1))))
7935
7936 (defun gnus-expunge-thread (thread)
7937   "Mark all articles in THREAD as read."
7938   (let* ((number (mail-header-number (car thread))))
7939     (incf gnus-newsgroup-expunged-tally)
7940     ;; We also mark as read here, if that's wanted.
7941     (setq gnus-newsgroup-unreads
7942           (delq number gnus-newsgroup-unreads))
7943     (if gnus-newsgroup-auto-expire
7944         (push number gnus-newsgroup-expirable)
7945       (push (cons number gnus-low-score-mark)
7946             gnus-newsgroup-reads)))
7947   ;; Go recursively through all subthreads.
7948   (mapcar 'gnus-expunge-thread (cdr thread)))
7949
7950 ;; Summary article oriented commands
7951
7952 (defun gnus-summary-refer-parent-article (n)
7953   "Refer parent article N times.
7954 If N is negative, go to ancestor -N instead.
7955 The difference between N and the number of articles fetched is returned."
7956   (interactive "p")
7957   (let ((skip 1)
7958         error header ref)
7959     (when (not (natnump n))
7960       (setq skip (abs n)
7961             n 1))
7962     (while (and (> n 0)
7963                 (not error))
7964       (setq header (gnus-summary-article-header))
7965       (if (and (eq (mail-header-number header)
7966                    (cdr gnus-article-current))
7967                (equal gnus-newsgroup-name
7968                       (car gnus-article-current)))
7969           ;; If we try to find the parent of the currently
7970           ;; displayed article, then we take a look at the actual
7971           ;; References header, since this is slightly more
7972           ;; reliable than the References field we got from the
7973           ;; server.
7974           (save-excursion
7975             (set-buffer gnus-original-article-buffer)
7976             (nnheader-narrow-to-headers)
7977             (unless (setq ref (message-fetch-field "references"))
7978               (setq ref (message-fetch-field "in-reply-to")))
7979             (widen))
7980         (setq ref
7981               ;; It's not the current article, so we take a bet on
7982               ;; the value we got from the server.
7983               (mail-header-references header)))
7984       (if (and ref
7985                (not (equal ref "")))
7986           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7987             (gnus-message 1 "Couldn't find parent"))
7988         (gnus-message 1 "No references in article %d"
7989                       (gnus-summary-article-number))
7990         (setq error t))
7991       (decf n))
7992     (gnus-summary-position-point)
7993     n))
7994
7995 (defun gnus-summary-refer-references ()
7996   "Fetch all articles mentioned in the References header.
7997 Return the number of articles fetched."
7998   (interactive)
7999   (let ((ref (mail-header-references (gnus-summary-article-header)))
8000         (current (gnus-summary-article-number))
8001         (n 0))
8002     (if (or (not ref)
8003             (equal ref ""))
8004         (error "No References in the current article")
8005       ;; For each Message-ID in the References header...
8006       (while (string-match "<[^>]*>" ref)
8007         (incf n)
8008         ;; ... fetch that article.
8009         (gnus-summary-refer-article
8010          (prog1 (match-string 0 ref)
8011            (setq ref (substring ref (match-end 0))))))
8012       (gnus-summary-goto-subject current)
8013       (gnus-summary-position-point)
8014       n)))
8015
8016 (defun gnus-summary-refer-thread (&optional limit)
8017   "Fetch all articles in the current thread.
8018 If LIMIT (the numerical prefix), fetch that many old headers instead
8019 of what's specified by the `gnus-refer-thread-limit' variable."
8020   (interactive "P")
8021   (let ((id (mail-header-id (gnus-summary-article-header)))
8022         (limit (if limit (prefix-numeric-value limit)
8023                  gnus-refer-thread-limit)))
8024     (unless (eq gnus-fetch-old-headers 'invisible)
8025       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8026       ;; Retrieve the headers and read them in.
8027       (if (eq (if (numberp limit)
8028                   (gnus-retrieve-headers
8029                    (list (min
8030                           (+ (mail-header-number
8031                               (gnus-summary-article-header))
8032                              limit)
8033                           gnus-newsgroup-end))
8034                    gnus-newsgroup-name (* limit 2))
8035                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8036                 ;; headers.
8037                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8038                                        gnus-newsgroup-name limit))
8039               'nov)
8040           (gnus-build-all-threads)
8041         (error "Can't fetch thread from backends that don't support NOV"))
8042       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8043     (gnus-summary-limit-include-thread id)))
8044
8045 (defun gnus-summary-refer-article (message-id)
8046   "Fetch an article specified by MESSAGE-ID."
8047   (interactive "sMessage-ID: ")
8048   (when (and (stringp message-id)
8049              (not (zerop (length message-id))))
8050     ;; Construct the correct Message-ID if necessary.
8051     ;; Suggested by tale@pawl.rpi.edu.
8052     (unless (string-match "^<" message-id)
8053       (setq message-id (concat "<" message-id)))
8054     (unless (string-match ">$" message-id)
8055       (setq message-id (concat message-id ">")))
8056     (let* ((header (gnus-id-to-header message-id))
8057            (sparse (and header
8058                         (gnus-summary-article-sparse-p
8059                          (mail-header-number header))
8060                         (memq (mail-header-number header)
8061                               gnus-newsgroup-limit)))
8062            number)
8063       (cond
8064        ;; If the article is present in the buffer we just go to it.
8065        ((and header
8066              (or (not (gnus-summary-article-sparse-p
8067                        (mail-header-number header)))
8068                  sparse))
8069         (prog1
8070             (gnus-summary-goto-article
8071              (mail-header-number header) nil t)
8072           (when sparse
8073             (gnus-summary-update-article (mail-header-number header)))))
8074        (t
8075         ;; We fetch the article.
8076         (catch 'found
8077           (dolist (gnus-override-method (gnus-refer-article-methods))
8078             (when (and (gnus-check-server gnus-override-method)
8079                        ;; Fetch the header,
8080                        (setq number (gnus-summary-insert-subject message-id)))
8081               ;; and display the article.
8082               (gnus-summary-select-article nil nil nil number)
8083               (throw 'found t)))
8084           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8085
8086 (defun gnus-refer-article-methods ()
8087   "Return a list of referable methods."
8088   (cond
8089    ;; No method, so we default to current and native.
8090    ((null gnus-refer-article-method)
8091     (list gnus-current-select-method gnus-select-method))
8092    ;; Current.
8093    ((eq 'current gnus-refer-article-method)
8094     (list gnus-current-select-method))
8095    ;; List of select methods.
8096    ((not (and (symbolp (car gnus-refer-article-method))
8097               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8098     (let (out)
8099       (dolist (method gnus-refer-article-method)
8100         (push (if (eq 'current method)
8101                   gnus-current-select-method
8102                 method)
8103               out))
8104       (nreverse out)))
8105    ;; One single select method.
8106    (t
8107     (list gnus-refer-article-method))))
8108
8109 (defun gnus-summary-edit-parameters ()
8110   "Edit the group parameters of the current group."
8111   (interactive)
8112   (gnus-group-edit-group gnus-newsgroup-name 'params))
8113
8114 (defun gnus-summary-customize-parameters ()
8115   "Customize the group parameters of the current group."
8116   (interactive)
8117   (gnus-group-customize gnus-newsgroup-name))
8118
8119 (defun gnus-summary-enter-digest-group (&optional force)
8120   "Enter an nndoc group based on the current article.
8121 If FORCE, force a digest interpretation.  If not, try
8122 to guess what the document format is."
8123   (interactive "P")
8124   (let ((conf gnus-current-window-configuration))
8125     (save-excursion
8126       (gnus-summary-select-article))
8127     (setq gnus-current-window-configuration conf)
8128     (let* ((name (format "%s-%d"
8129                          (gnus-group-prefixed-name
8130                           gnus-newsgroup-name (list 'nndoc ""))
8131                          (save-excursion
8132                            (set-buffer gnus-summary-buffer)
8133                            gnus-current-article)))
8134            (ogroup gnus-newsgroup-name)
8135            (params (append (gnus-info-params (gnus-get-info ogroup))
8136                            (list (cons 'to-group ogroup))
8137                            (list (cons 'save-article-group ogroup))))
8138            (case-fold-search t)
8139            (buf (current-buffer))
8140            dig to-address)
8141       (save-excursion
8142         (set-buffer gnus-original-article-buffer)
8143         ;; Have the digest group inherit the main mail address of
8144         ;; the parent article.
8145         (when (setq to-address (or (gnus-fetch-field "reply-to")
8146                                    (gnus-fetch-field "from")))
8147           (setq params (append
8148                         (list (cons 'to-address
8149                                     (funcall gnus-decode-encoded-word-function
8150                                              to-address))))))
8151         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8152         (insert-buffer-substring gnus-original-article-buffer)
8153         ;; Remove lines that may lead nndoc to misinterpret the
8154         ;; document type.
8155         (narrow-to-region
8156          (goto-char (point-min))
8157          (or (search-forward "\n\n" nil t) (point)))
8158         (goto-char (point-min))
8159         (delete-matching-lines "^Path:\\|^From ")
8160         (widen))
8161       (unwind-protect
8162           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8163                     (gnus-newsgroup-ephemeral-ignored-charsets
8164                      gnus-newsgroup-ignored-charsets))
8165                 (gnus-group-read-ephemeral-group
8166                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8167                               (nndoc-article-type
8168                                ,(if force 'mbox 'guess)))
8169                  t nil nil nil
8170                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8171                                                         "ADAPT")))))
8172               ;; Make all postings to this group go to the parent group.
8173               (nconc (gnus-info-params (gnus-get-info name))
8174                      params)
8175             ;; Couldn't select this doc group.
8176             (switch-to-buffer buf)
8177             (gnus-set-global-variables)
8178             (gnus-configure-windows 'summary)
8179             (gnus-message 3 "Article couldn't be entered?"))
8180         (kill-buffer dig)))))
8181
8182 (defun gnus-summary-read-document (n)
8183   "Open a new group based on the current article(s).
8184 This will allow you to read digests and other similar
8185 documents as newsgroups.
8186 Obeys the standard process/prefix convention."
8187   (interactive "P")
8188   (let* ((articles (gnus-summary-work-articles n))
8189          (ogroup gnus-newsgroup-name)
8190          (params (append (gnus-info-params (gnus-get-info ogroup))
8191                          (list (cons 'to-group ogroup))))
8192          article group egroup groups vgroup)
8193     (while (setq article (pop articles))
8194       (setq group (format "%s-%d" gnus-newsgroup-name article))
8195       (gnus-summary-remove-process-mark article)
8196       (when (gnus-summary-display-article article)
8197         (save-excursion
8198           (with-temp-buffer
8199             (insert-buffer-substring gnus-original-article-buffer)
8200             ;; Remove some headers that may lead nndoc to make
8201             ;; the wrong guess.
8202             (message-narrow-to-head)
8203             (goto-char (point-min))
8204             (delete-matching-lines "^\\(Path\\):\\|^From ")
8205             (widen)
8206             (if (setq egroup
8207                       (gnus-group-read-ephemeral-group
8208                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8209                                      (nndoc-article-type guess))
8210                        t nil t))
8211                 (progn
8212             ;; Make all postings to this group go to the parent group.
8213                   (nconc (gnus-info-params (gnus-get-info egroup))
8214                          params)
8215                   (push egroup groups))
8216               ;; Couldn't select this doc group.
8217               (gnus-error 3 "Article couldn't be entered"))))))
8218     ;; Now we have selected all the documents.
8219     (cond
8220      ((not groups)
8221       (error "None of the articles could be interpreted as documents"))
8222      ((gnus-group-read-ephemeral-group
8223        (setq vgroup (format
8224                      "nnvirtual:%s-%s" gnus-newsgroup-name
8225                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8226        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8227        t
8228        (cons (current-buffer) 'summary)))
8229      (t
8230       (error "Couldn't select virtual nndoc group")))))
8231
8232 (defun gnus-summary-isearch-article (&optional regexp-p)
8233   "Do incremental search forward on the current article.
8234 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8235   (interactive "P")
8236   (gnus-summary-select-article)
8237   (gnus-configure-windows 'article)
8238   (gnus-eval-in-buffer-window gnus-article-buffer
8239     (save-restriction
8240       (widen)
8241       (isearch-forward regexp-p))))
8242
8243 (defun gnus-summary-search-article-forward (regexp &optional backward)
8244   "Search for an article containing REGEXP forward.
8245 If BACKWARD, search backward instead."
8246   (interactive
8247    (list (read-string
8248           (format "Search article %s (regexp%s): "
8249                   (if current-prefix-arg "backward" "forward")
8250                   (if gnus-last-search-regexp
8251                       (concat ", default " gnus-last-search-regexp)
8252                     "")))
8253          current-prefix-arg))
8254   (if (string-equal regexp "")
8255       (setq regexp (or gnus-last-search-regexp ""))
8256     (setq gnus-last-search-regexp regexp)
8257     (setq gnus-article-before-search gnus-current-article))
8258   ;; Intentionally set gnus-last-article.
8259   (setq gnus-last-article gnus-article-before-search)
8260   (let ((gnus-last-article gnus-last-article))
8261     (if (gnus-summary-search-article regexp backward)
8262         (gnus-summary-show-thread)
8263       (error "Search failed: \"%s\"" regexp))))
8264
8265 (defun gnus-summary-search-article-backward (regexp)
8266   "Search for an article containing REGEXP backward."
8267   (interactive
8268    (list (read-string
8269           (format "Search article backward (regexp%s): "
8270                   (if gnus-last-search-regexp
8271                       (concat ", default " gnus-last-search-regexp)
8272                     "")))))
8273   (gnus-summary-search-article-forward regexp 'backward))
8274
8275 (defun gnus-summary-search-article (regexp &optional backward)
8276   "Search for an article containing REGEXP.
8277 Optional argument BACKWARD means do search for backward.
8278 `gnus-select-article-hook' is not called during the search."
8279   ;; We have to require this here to make sure that the following
8280   ;; dynamic binding isn't shadowed by autoloading.
8281   (require 'gnus-async)
8282   (require 'gnus-art)
8283   (let ((gnus-select-article-hook nil)  ;Disable hook.
8284         (gnus-article-prepare-hook nil)
8285         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8286         (gnus-use-article-prefetch nil)
8287         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8288         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8289         (gnus-visual nil)
8290         (gnus-keep-backlog nil)
8291         (gnus-break-pages nil)
8292         (gnus-summary-display-arrow nil)
8293         (gnus-updated-mode-lines nil)
8294         (gnus-auto-center-summary nil)
8295         (sum (current-buffer))
8296         (gnus-display-mime-function nil)
8297         (found nil)
8298         point)
8299     (gnus-save-hidden-threads
8300       (gnus-summary-select-article)
8301       (set-buffer gnus-article-buffer)
8302       (goto-char (window-point (get-buffer-window (current-buffer))))
8303       (when backward
8304         (forward-line -1))
8305       (while (not found)
8306         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8307         (if (if backward
8308                 (re-search-backward regexp nil t)
8309               (re-search-forward regexp nil t))
8310             ;; We found the regexp.
8311             (progn
8312               (setq found 'found)
8313               (beginning-of-line)
8314               (set-window-start
8315                (get-buffer-window (current-buffer))
8316                (point))
8317               (forward-line 1)
8318               (set-window-point
8319                (get-buffer-window (current-buffer))
8320                (point))
8321               (set-buffer sum)
8322               (setq point (point)))
8323           ;; We didn't find it, so we go to the next article.
8324           (set-buffer sum)
8325           (setq found 'not)
8326           (while (eq found 'not)
8327             (if (not (if backward (gnus-summary-find-prev)
8328                        (gnus-summary-find-next)))
8329                 ;; No more articles.
8330                 (setq found t)
8331               ;; Select the next article and adjust point.
8332               (unless (gnus-summary-article-sparse-p
8333                        (gnus-summary-article-number))
8334                 (setq found nil)
8335                 (gnus-summary-select-article)
8336                 (set-buffer gnus-article-buffer)
8337                 (widen)
8338                 (goto-char (if backward (point-max) (point-min))))))))
8339       (gnus-message 7 ""))
8340     ;; Return whether we found the regexp.
8341     (when (eq found 'found)
8342       (goto-char point)
8343       (gnus-summary-show-thread)
8344       (gnus-summary-goto-subject gnus-current-article)
8345       (gnus-summary-position-point)
8346       t)))
8347
8348 (defun gnus-find-matching-articles (header regexp)
8349   "Return a list of all articles that match REGEXP on HEADER.
8350 This search includes all articles in the current group that Gnus has
8351 fetched headers for, whether they are displayed or not."
8352   (let ((articles nil)
8353         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8354         (case-fold-search t))
8355     (dolist (header gnus-newsgroup-headers)
8356       (when (string-match regexp (funcall func header))
8357         (push (mail-header-number header) articles)))
8358     (nreverse articles)))
8359
8360 (defun gnus-summary-find-matching (header regexp &optional backward unread
8361                                           not-case-fold not-matching)
8362   "Return a list of all articles that match REGEXP on HEADER.
8363 The search stars on the current article and goes forwards unless
8364 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8365 If UNREAD is non-nil, only unread articles will
8366 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8367 in the comparisons. If NOT-MATCHING, return a list of all articles that
8368 not match REGEXP on HEADER."
8369   (let ((case-fold-search (not not-case-fold))
8370         articles d func)
8371     (if (consp header)
8372         (if (eq (car header) 'extra)
8373             (setq func
8374                   `(lambda (h)
8375                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8376                          "")))
8377           (error "%s is an invalid header" header))
8378       (unless (fboundp (intern (concat "mail-header-" header)))
8379         (error "%s is not a valid header" header))
8380       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8381     (dolist (d (if (eq backward 'all)
8382                    gnus-newsgroup-data
8383                  (gnus-data-find-list
8384                   (gnus-summary-article-number)
8385                   (gnus-data-list backward))))
8386       (when (and (or (not unread)       ; We want all articles...
8387                      (gnus-data-unread-p d)) ; Or just unreads.
8388                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8389                  (if not-matching
8390                      (not (string-match
8391                            regexp
8392                            (funcall func (gnus-data-header d))))
8393                    (string-match regexp
8394                                  (funcall func (gnus-data-header d)))))
8395         (push (gnus-data-number d) articles))) ; Success!
8396     (nreverse articles)))
8397
8398 (defun gnus-summary-execute-command (header regexp command &optional backward)
8399   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8400 If HEADER is an empty string (or nil), the match is done on the entire
8401 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8402   (interactive
8403    (list (let ((completion-ignore-case t))
8404            (completing-read
8405             "Header name: "
8406             (mapcar (lambda (header) (list (format "%s" header)))
8407                     (append
8408                      '("Number" "Subject" "From" "Lines" "Date"
8409                        "Message-ID" "Xref" "References" "Body")
8410                      gnus-extra-headers))
8411             nil 'require-match))
8412          (read-string "Regexp: ")
8413          (read-key-sequence "Command: ")
8414          current-prefix-arg))
8415   (when (equal header "Body")
8416     (setq header ""))
8417   ;; Hidden thread subtrees must be searched as well.
8418   (gnus-summary-show-all-threads)
8419   ;; We don't want to change current point nor window configuration.
8420   (save-excursion
8421     (save-window-excursion
8422       (let (gnus-visual
8423             gnus-treat-strip-trailing-blank-lines
8424             gnus-treat-strip-leading-blank-lines
8425             gnus-treat-strip-multiple-blank-lines
8426             gnus-treat-hide-boring-headers
8427             gnus-treat-fold-newsgroups
8428             gnus-article-prepare-hook)
8429         (gnus-message 6 "Executing %s..." (key-description command))
8430         ;; We'd like to execute COMMAND interactively so as to give arguments.
8431         (gnus-execute header regexp
8432                       `(call-interactively ',(key-binding command))
8433                       backward)
8434         (gnus-message 6 "Executing %s...done" (key-description command))))))
8435
8436 (defun gnus-summary-beginning-of-article ()
8437   "Scroll the article back to the beginning."
8438   (interactive)
8439   (gnus-summary-select-article)
8440   (gnus-configure-windows 'article)
8441   (gnus-eval-in-buffer-window gnus-article-buffer
8442     (widen)
8443     (goto-char (point-min))
8444     (when gnus-page-broken
8445       (gnus-narrow-to-page))))
8446
8447 (defun gnus-summary-end-of-article ()
8448   "Scroll to the end of the article."
8449   (interactive)
8450   (gnus-summary-select-article)
8451   (gnus-configure-windows 'article)
8452   (gnus-eval-in-buffer-window gnus-article-buffer
8453     (widen)
8454     (goto-char (point-max))
8455     (recenter -3)
8456     (when gnus-page-broken
8457       (gnus-narrow-to-page))))
8458
8459 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8460   "Truncate to LEN and quote all \"(\"'s in STRING."
8461   (gnus-replace-in-string (if (and len (> (length string) len))
8462                               (substring string 0 len)
8463                             string)
8464                           "[()]" "\\\\\\&"))
8465
8466 (defun gnus-summary-print-article (&optional filename n)
8467   "Generate and print a PostScript image of the N next (mail) articles.
8468
8469 If N is negative, print the N previous articles.  If N is nil and articles
8470 have been marked with the process mark, print these instead.
8471
8472 If the optional first argument FILENAME is nil, send the image to the
8473 printer.  If FILENAME is a string, save the PostScript image in a file with
8474 that name.  If FILENAME is a number, prompt the user for the name of the file
8475 to save in."
8476   (interactive (list (ps-print-preprint current-prefix-arg)))
8477   (dolist (article (gnus-summary-work-articles n))
8478     (gnus-summary-select-article nil nil 'pseudo article)
8479     (gnus-eval-in-buffer-window gnus-article-buffer
8480       (gnus-print-buffer))
8481     (gnus-summary-remove-process-mark article))
8482   (ps-despool filename))
8483
8484 (defun gnus-print-buffer ()
8485   (let ((buffer (generate-new-buffer " *print*")))
8486     (unwind-protect
8487         (progn
8488           (copy-to-buffer buffer (point-min) (point-max))
8489           (set-buffer buffer)
8490           (gnus-article-delete-invisible-text)
8491           (gnus-remove-text-with-property 'gnus-decoration)
8492           (when (gnus-visual-p 'article-highlight 'highlight)
8493             ;; Copy-to-buffer doesn't copy overlay.  So redo
8494             ;; highlight.
8495             (let ((gnus-article-buffer buffer))
8496               (gnus-article-highlight-citation t)
8497               (gnus-article-highlight-signature)))
8498           (let ((ps-left-header
8499                  (list
8500                   (concat "("
8501                           (gnus-summary-print-truncate-and-quote
8502                            (mail-header-subject gnus-current-headers)
8503                            66) ")")
8504                   (concat "("
8505                           (gnus-summary-print-truncate-and-quote
8506                            (mail-header-from gnus-current-headers)
8507                            45) ")")))
8508                 (ps-right-header
8509                  (list
8510                   "/pagenumberstring load"
8511                   (concat "("
8512                           (mail-header-date gnus-current-headers) ")"))))
8513             (gnus-run-hooks 'gnus-ps-print-hook)
8514             (save-excursion
8515               (if window-system
8516                   (ps-spool-buffer-with-faces)
8517                 (ps-spool-buffer)))))
8518       (kill-buffer buffer))))
8519
8520 (defun gnus-summary-show-article (&optional arg)
8521   "Force redisplaying of the current article.
8522 If ARG (the prefix) is a number, show the article with the charset
8523 defined in `gnus-summary-show-article-charset-alist', or the charset
8524 input.
8525 If ARG (the prefix) is non-nil and not a number, show the raw article
8526 without any article massaging functions being run.  Normally, the key strokes
8527 are `C-u g'."
8528   (interactive "P")
8529   (cond
8530    ((numberp arg)
8531     (gnus-summary-show-article t)
8532     (let ((gnus-newsgroup-charset
8533            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8534                (mm-read-coding-system
8535                 "View as charset: " ;; actually it is coding system.
8536                 (save-excursion
8537                   (set-buffer gnus-article-buffer)
8538                   (mm-detect-coding-region (point) (point-max))))))
8539           (gnus-newsgroup-ignored-charsets 'gnus-all))
8540       (gnus-summary-select-article nil 'force)
8541       (let ((deps gnus-newsgroup-dependencies)
8542             head header lines)
8543         (save-excursion
8544           (set-buffer gnus-original-article-buffer)
8545           (save-restriction
8546             (message-narrow-to-head)
8547             (setq head (buffer-string))
8548             (goto-char (point-min))
8549             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8550               (goto-char (point-max))
8551               (widen)
8552               (setq lines (1- (count-lines (point) (point-max))))))
8553           (with-temp-buffer
8554             (insert (format "211 %d Article retrieved.\n"
8555                             (cdr gnus-article-current)))
8556             (insert head)
8557             (if lines (insert (format "Lines: %d\n" lines)))
8558             (insert ".\n")
8559             (let ((nntp-server-buffer (current-buffer)))
8560               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8561         (gnus-data-set-header
8562          (gnus-data-find (cdr gnus-article-current))
8563          header)
8564         (gnus-summary-update-article-line
8565          (cdr gnus-article-current) header)
8566         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8567           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8568    ((not arg)
8569     ;; Select the article the normal way.
8570     (gnus-summary-select-article nil 'force))
8571    (t
8572     ;; We have to require this here to make sure that the following
8573     ;; dynamic binding isn't shadowed by autoloading.
8574     (require 'gnus-async)
8575     (require 'gnus-art)
8576     ;; Bind the article treatment functions to nil.
8577     (let ((gnus-have-all-headers t)
8578           gnus-article-prepare-hook
8579           gnus-article-decode-hook
8580           gnus-display-mime-function
8581           gnus-break-pages)
8582       ;; Destroy any MIME parts.
8583       (when (gnus-buffer-live-p gnus-article-buffer)
8584         (save-excursion
8585           (set-buffer gnus-article-buffer)
8586           (mm-destroy-parts gnus-article-mime-handles)
8587           ;; Set it to nil for safety reason.
8588           (setq gnus-article-mime-handle-alist nil)
8589           (setq gnus-article-mime-handles nil)))
8590       (gnus-summary-select-article nil 'force))))
8591   (gnus-summary-goto-subject gnus-current-article)
8592   (gnus-summary-position-point))
8593
8594 (defun gnus-summary-show-raw-article ()
8595   "Show the raw article without any article massaging functions being run."
8596   (interactive)
8597   (gnus-summary-show-article t))
8598
8599 (defun gnus-summary-verbose-headers (&optional arg)
8600   "Toggle permanent full header display.
8601 If ARG is a positive number, turn header display on.
8602 If ARG is a negative number, turn header display off."
8603   (interactive "P")
8604   (setq gnus-show-all-headers
8605         (cond ((or (not (numberp arg))
8606                    (zerop arg))
8607                (not gnus-show-all-headers))
8608               ((natnump arg)
8609                t)))
8610   (gnus-summary-show-article))
8611
8612 (defun gnus-summary-toggle-header (&optional arg)
8613   "Show the headers if they are hidden, or hide them if they are shown.
8614 If ARG is a positive number, show the entire header.
8615 If ARG is a negative number, hide the unwanted header lines."
8616   (interactive "P")
8617   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8618                      (get-buffer-window gnus-article-buffer t))))
8619     (with-current-buffer gnus-article-buffer
8620       (widen)
8621       (article-narrow-to-head)
8622       (let* ((buffer-read-only nil)
8623              (inhibit-point-motion-hooks t)
8624              (hidden (if (numberp arg)
8625                          (>= arg 0)
8626                        (gnus-article-hidden-text-p 'headers)))
8627              s e)
8628         (delete-region (point-min) (point-max))
8629         (with-current-buffer gnus-original-article-buffer
8630           (goto-char (setq s (point-min)))
8631           (setq e (if (search-forward "\n\n" nil t)
8632                       (1- (point))
8633                     (point-max))))
8634         (insert-buffer-substring gnus-original-article-buffer s e)
8635         (run-hooks 'gnus-article-decode-hook)
8636         (if hidden
8637             (let ((gnus-treat-hide-headers nil)
8638                   (gnus-treat-hide-boring-headers nil))
8639               (gnus-delete-wash-type 'headers)
8640               (gnus-treat-article 'head))
8641           (gnus-treat-article 'head))
8642         (widen)
8643         (if window
8644             (set-window-start window (goto-char (point-min))))
8645         (setq gnus-page-broken
8646               (when gnus-break-pages
8647                 (gnus-narrow-to-page)
8648                 t))
8649         (gnus-set-mode-line 'article)))))
8650
8651 (defun gnus-summary-show-all-headers ()
8652   "Make all header lines visible."
8653   (interactive)
8654   (gnus-summary-toggle-header 1))
8655
8656 (defun gnus-summary-caesar-message (&optional arg)
8657   "Caesar rotate the current article by 13.
8658 The numerical prefix specifies how many places to rotate each letter
8659 forward."
8660   (interactive "P")
8661   (gnus-summary-select-article)
8662   (let ((mail-header-separator ""))
8663     (gnus-eval-in-buffer-window gnus-article-buffer
8664       (save-restriction
8665         (widen)
8666         (let ((start (window-start))
8667               buffer-read-only)
8668           (message-caesar-buffer-body arg)
8669           (set-window-start (get-buffer-window (current-buffer)) start))))))
8670
8671 (autoload 'unmorse-region "morse"
8672   "Convert morse coded text in region to ordinary ASCII text."
8673   t)
8674
8675 (defun gnus-summary-morse-message (&optional arg)
8676   "Morse decode the current article."
8677   (interactive "P")
8678   (gnus-summary-select-article)
8679   (let ((mail-header-separator ""))
8680     (gnus-eval-in-buffer-window gnus-article-buffer
8681       (save-excursion
8682         (save-restriction
8683           (widen)
8684           (let ((pos (window-start))
8685                 buffer-read-only)
8686             (goto-char (point-min))
8687             (when (message-goto-body)
8688               (gnus-narrow-to-body))
8689             (goto-char (point-min))
8690             (while (re-search-forward "·" (point-max) t)
8691               (replace-match "."))
8692             (unmorse-region (point-min) (point-max))
8693             (widen)
8694             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8695
8696 (defun gnus-summary-stop-page-breaking ()
8697   "Stop page breaking in the current article."
8698   (interactive)
8699   (gnus-summary-select-article)
8700   (gnus-eval-in-buffer-window gnus-article-buffer
8701     (widen)
8702     (when (gnus-visual-p 'page-marker)
8703       (let ((buffer-read-only nil))
8704         (gnus-remove-text-with-property 'gnus-prev)
8705         (gnus-remove-text-with-property 'gnus-next))
8706       (setq gnus-page-broken nil))))
8707
8708 (defun gnus-summary-move-article (&optional n to-newsgroup
8709                                             select-method action)
8710   "Move the current article to a different newsgroup.
8711 If N is a positive number, move the N next articles.
8712 If N is a negative number, move the N previous articles.
8713 If N is nil and any articles have been marked with the process mark,
8714 move those articles instead.
8715 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8716 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8717 re-spool using this method.
8718
8719 When called interactively with TO-NEWSGROUP being nil, the value of
8720 the variable `gnus-move-split-methods' is used for finding a default
8721 for the target newsgroup.
8722
8723 For this function to work, both the current newsgroup and the
8724 newsgroup that you want to move to have to support the `request-move'
8725 and `request-accept' functions.
8726
8727 ACTION can be either `move' (the default), `crosspost' or `copy'."
8728   (interactive "P")
8729   (unless action
8730     (setq action 'move))
8731   ;; Check whether the source group supports the required functions.
8732   (cond ((and (eq action 'move)
8733               (not (gnus-check-backend-function
8734                     'request-move-article gnus-newsgroup-name)))
8735          (error "The current group does not support article moving"))
8736         ((and (eq action 'crosspost)
8737               (not (gnus-check-backend-function
8738                     'request-replace-article gnus-newsgroup-name)))
8739          (error "The current group does not support article editing")))
8740   (let ((articles (gnus-summary-work-articles n))
8741         (prefix (if (gnus-check-backend-function
8742                      'request-move-article gnus-newsgroup-name)
8743                     (gnus-group-real-prefix gnus-newsgroup-name)
8744                   ""))
8745         (names '((move "Move" "Moving")
8746                  (copy "Copy" "Copying")
8747                  (crosspost "Crosspost" "Crossposting")))
8748         (copy-buf (save-excursion
8749                     (nnheader-set-temp-buffer " *copy article*")))
8750         art-group to-method new-xref article to-groups)
8751     (unless (assq action names)
8752       (error "Unknown action %s" action))
8753     ;; Read the newsgroup name.
8754     (when (and (not to-newsgroup)
8755                (not select-method))
8756       (if (and gnus-move-split-methods
8757                (not
8758                 (and (memq gnus-current-article articles)
8759                      (gnus-buffer-live-p gnus-original-article-buffer))))
8760           ;; When `gnus-move-split-methods' is non-nil, we have to
8761           ;; select an article to give `gnus-read-move-group-name' an
8762           ;; opportunity to suggest an appropriate default.  However,
8763           ;; we needn't render or mark the article.
8764           (let ((gnus-display-mime-function nil)
8765                 (gnus-article-prepare-hook nil)
8766                 (gnus-mark-article-hook nil))
8767             (gnus-summary-select-article nil nil nil (car articles))))
8768       (setq to-newsgroup
8769             (gnus-read-move-group-name
8770              (cadr (assq action names))
8771              (symbol-value (intern (format "gnus-current-%s-group" action)))
8772              articles prefix))
8773       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8774     (setq to-method (or select-method
8775                         (gnus-server-to-method
8776                          (gnus-group-method to-newsgroup))))
8777     ;; Check the method we are to move this article to...
8778     (unless (gnus-check-backend-function
8779              'request-accept-article (car to-method))
8780       (error "%s does not support article copying" (car to-method)))
8781     (unless (gnus-check-server to-method)
8782       (error "Can't open server %s" (car to-method)))
8783     (gnus-message 6 "%s to %s: %s..."
8784                   (caddr (assq action names))
8785                   (or (car select-method) to-newsgroup) articles)
8786     (while articles
8787       (setq article (pop articles))
8788       (setq
8789        art-group
8790        (cond
8791         ;; Move the article.
8792         ((eq action 'move)
8793          ;; Remove this article from future suppression.
8794          (gnus-dup-unsuppress-article article)
8795          (gnus-request-move-article
8796           article                       ; Article to move
8797           gnus-newsgroup-name           ; From newsgroup
8798           (nth 1 (gnus-find-method-for-group
8799                   gnus-newsgroup-name)) ; Server
8800           (list 'gnus-request-accept-article
8801                 to-newsgroup (list 'quote select-method)
8802                 (not articles) t)       ; Accept form
8803           (not articles)))              ; Only save nov last time
8804         ;; Copy the article.
8805         ((eq action 'copy)
8806          (save-excursion
8807            (set-buffer copy-buf)
8808            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8809              (gnus-request-accept-article
8810               to-newsgroup select-method (not articles) t))))
8811         ;; Crosspost the article.
8812         ((eq action 'crosspost)
8813          (let ((xref (message-tokenize-header
8814                       (mail-header-xref (gnus-summary-article-header article))
8815                       " ")))
8816            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8817                                   ":" (number-to-string article)))
8818            (unless xref
8819              (setq xref (list (system-name))))
8820            (setq new-xref
8821                  (concat
8822                   (mapconcat 'identity
8823                              (delete "Xref:" (delete new-xref xref))
8824                              " ")
8825                   " " new-xref))
8826            (save-excursion
8827              (set-buffer copy-buf)
8828              ;; First put the article in the destination group.
8829              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8830              (when (consp (setq art-group
8831                                 (gnus-request-accept-article
8832                                  to-newsgroup select-method (not articles))))
8833                (setq new-xref (concat new-xref " " (car art-group)
8834                                       ":"
8835                                       (number-to-string (cdr art-group))))
8836                ;; Now we have the new Xrefs header, so we insert
8837                ;; it and replace the new article.
8838                (nnheader-replace-header "Xref" new-xref)
8839                (gnus-request-replace-article
8840                 (cdr art-group) to-newsgroup (current-buffer))
8841                art-group))))))
8842       (cond
8843        ((not art-group)
8844         (gnus-message 1 "Couldn't %s article %s: %s"
8845                       (cadr (assq action names)) article
8846                       (nnheader-get-report (car to-method))))
8847        ((eq art-group 'junk)
8848         (when (eq action 'move)
8849           (gnus-summary-mark-article article gnus-canceled-mark)
8850           (gnus-message 4 "Deleted article %s" article)
8851           ;; run the delete hook
8852           (run-hook-with-args 'gnus-summary-article-delete-hook
8853                               action
8854                               (gnus-data-header
8855                                (assoc article (gnus-data-list nil)))
8856                               gnus-newsgroup-name nil
8857                               select-method)))
8858        (t
8859         (let* ((pto-group (gnus-group-prefixed-name
8860                            (car art-group) to-method))
8861                (entry
8862                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8863                (info (nth 2 entry))
8864                (to-group (gnus-info-group info))
8865                to-marks)
8866           ;; Update the group that has been moved to.
8867           (when (and info
8868                      (memq action '(move copy)))
8869             (unless (member to-group to-groups)
8870               (push to-group to-groups))
8871
8872             (unless (memq article gnus-newsgroup-unreads)
8873               (push 'read to-marks)
8874               (gnus-info-set-read
8875                info (gnus-add-to-range (gnus-info-read info)
8876                                        (list (cdr art-group)))))
8877
8878             ;; See whether the article is to be put in the cache.
8879             (let ((marks gnus-article-mark-lists)
8880                   (to-article (cdr art-group)))
8881
8882               ;; Enter the article into the cache in the new group,
8883               ;; if that is required.
8884               (when gnus-use-cache
8885                 (gnus-cache-possibly-enter-article
8886                  to-group to-article
8887                  (memq article gnus-newsgroup-marked)
8888                  (memq article gnus-newsgroup-dormant)
8889                  (memq article gnus-newsgroup-unreads)))
8890
8891               (when gnus-preserve-marks
8892                 ;; Copy any marks over to the new group.
8893                 (when (and (equal to-group gnus-newsgroup-name)
8894                            (not (memq article gnus-newsgroup-unreads)))
8895                   ;; Mark this article as read in this group.
8896                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8897                   (setcdr (gnus-active to-group) to-article)
8898                   (setcdr gnus-newsgroup-active to-article))
8899
8900                 (while marks
8901                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8902                     (when (memq article (symbol-value
8903                                          (intern (format "gnus-newsgroup-%s"
8904                                                          (caar marks)))))
8905                       (push (cdar marks) to-marks)
8906                       ;; If the other group is the same as this group,
8907                       ;; then we have to add the mark to the list.
8908                       (when (equal to-group gnus-newsgroup-name)
8909                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8910                              (cons to-article
8911                                    (symbol-value
8912                                     (intern (format "gnus-newsgroup-%s"
8913                                                     (caar marks)))))))
8914                       ;; Copy the marks to other group.
8915                       (gnus-add-marked-articles
8916                        to-group (cdar marks) (list to-article) info)))
8917                   (setq marks (cdr marks)))
8918
8919                 (gnus-request-set-mark
8920                  to-group (list (list (list to-article) 'add to-marks))))
8921
8922               (gnus-dribble-enter
8923                (concat "(gnus-group-set-info '"
8924                        (gnus-prin1-to-string (gnus-get-info to-group))
8925                        ")"))))
8926
8927           ;; Update the Xref header in this article to point to
8928           ;; the new crossposted article we have just created.
8929           (when (eq action 'crosspost)
8930             (save-excursion
8931               (set-buffer copy-buf)
8932               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8933               (nnheader-replace-header "Xref" new-xref)
8934               (gnus-request-replace-article
8935                article gnus-newsgroup-name (current-buffer))))
8936
8937           ;; run the move/copy/crosspost/respool hook
8938           (run-hook-with-args 'gnus-summary-article-move-hook 
8939                               action
8940                               (gnus-data-header 
8941                                (assoc article (gnus-data-list nil)))
8942                               gnus-newsgroup-name
8943                               to-newsgroup
8944                               select-method))
8945
8946         ;;;!!!Why is this necessary?
8947         (set-buffer gnus-summary-buffer)
8948         
8949         (gnus-summary-goto-subject article)
8950         (when (eq action 'move)
8951           (gnus-summary-mark-article article gnus-canceled-mark))))
8952       (gnus-summary-remove-process-mark article))
8953     ;; Re-activate all groups that have been moved to.
8954     (save-excursion
8955       (set-buffer gnus-group-buffer)
8956       (let ((gnus-group-marked to-groups))
8957         (gnus-group-get-new-news-this-group nil t)))
8958
8959     (gnus-kill-buffer copy-buf)
8960     (gnus-summary-position-point)
8961     (gnus-set-mode-line 'summary)))
8962
8963 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8964   "Move the current article to a different newsgroup.
8965 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8966 When called interactively, if TO-NEWSGROUP is nil, use the value of
8967 the variable `gnus-move-split-methods' for finding a default target
8968 newsgroup.
8969 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8970 re-spool using this method."
8971   (interactive "P")
8972   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8973
8974 (defun gnus-summary-crosspost-article (&optional n)
8975   "Crosspost the current article to some other group."
8976   (interactive "P")
8977   (gnus-summary-move-article n nil nil 'crosspost))
8978
8979 (defcustom gnus-summary-respool-default-method nil
8980   "Default method type for respooling an article.
8981 If nil, use to the current newsgroup method."
8982   :type 'symbol
8983   :group 'gnus-summary-mail)
8984
8985 (defcustom gnus-summary-display-while-building nil
8986   "If not-nil, show and update the summary buffer as it's being built.
8987 If the value is t, update the buffer after every line is inserted.  If
8988 the value is an integer (N), update the display every N lines."
8989   :group 'gnus-thread
8990   :type '(choice (const :tag "off" nil)
8991                  number
8992                  (const :tag "frequently" t)))
8993
8994 (defun gnus-summary-respool-article (&optional n method)
8995   "Respool the current article.
8996 The article will be squeezed through the mail spooling process again,
8997 which means that it will be put in some mail newsgroup or other
8998 depending on `nnmail-split-methods'.
8999 If N is a positive number, respool the N next articles.
9000 If N is a negative number, respool the N previous articles.
9001 If N is nil and any articles have been marked with the process mark,
9002 respool those articles instead.
9003
9004 Respooling can be done both from mail groups and \"real\" newsgroups.
9005 In the former case, the articles in question will be moved from the
9006 current group into whatever groups they are destined to.  In the
9007 latter case, they will be copied into the relevant groups."
9008   (interactive
9009    (list current-prefix-arg
9010          (let* ((methods (gnus-methods-using 'respool))
9011                 (methname
9012                  (symbol-name (or gnus-summary-respool-default-method
9013                                   (car (gnus-find-method-for-group
9014                                         gnus-newsgroup-name)))))
9015                 (method
9016                  (gnus-completing-read-with-default
9017                   methname "What backend do you want to use when respooling?"
9018                   methods nil t nil 'gnus-mail-method-history))
9019                 ms)
9020            (cond
9021             ((zerop (length (setq ms (gnus-servers-using-backend
9022                                       (intern method)))))
9023              (list (intern method) ""))
9024             ((= 1 (length ms))
9025              (car ms))
9026             (t
9027              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9028                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9029                            ms-alist))))))))
9030   (unless method
9031     (error "No method given for respooling"))
9032   (if (assoc (symbol-name
9033               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9034              (gnus-methods-using 'respool))
9035       (gnus-summary-move-article n nil method)
9036     (gnus-summary-copy-article n nil method)))
9037
9038 (defun gnus-summary-import-article (file &optional edit)
9039   "Import an arbitrary file into a mail newsgroup."
9040   (interactive "fImport file: \nP")
9041   (let ((group gnus-newsgroup-name)
9042         (now (current-time))
9043         atts lines group-art)
9044     (unless (gnus-check-backend-function 'request-accept-article group)
9045       (error "%s does not support article importing" group))
9046     (or (file-readable-p file)
9047         (not (file-regular-p file))
9048         (error "Can't read %s" file))
9049     (save-excursion
9050       (set-buffer (gnus-get-buffer-create " *import file*"))
9051       (erase-buffer)
9052       (nnheader-insert-file-contents file)
9053       (goto-char (point-min))
9054       (if (nnheader-article-p)
9055           (save-restriction
9056             (goto-char (point-min))
9057             (search-forward "\n\n" nil t)
9058             (narrow-to-region (point-min) (1- (point)))
9059             (goto-char (point-min))
9060             (unless (re-search-forward "^date:" nil t)
9061               (goto-char (point-max))
9062               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9063        ;; This doesn't look like an article, so we fudge some headers.
9064         (setq atts (file-attributes file)
9065               lines (count-lines (point-min) (point-max)))
9066         (insert "From: " (read-string "From: ") "\n"
9067                 "Subject: " (read-string "Subject: ") "\n"
9068                 "Date: " (message-make-date (nth 5 atts)) "\n"
9069                 "Message-ID: " (message-make-message-id) "\n"
9070                 "Lines: " (int-to-string lines) "\n"
9071                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9072       (setq group-art (gnus-request-accept-article group nil t))
9073       (kill-buffer (current-buffer)))
9074     (setq gnus-newsgroup-active (gnus-activate-group group))
9075     (forward-line 1)
9076     (gnus-summary-goto-article (cdr group-art) nil t)
9077     (when edit
9078       (gnus-summary-edit-article))))
9079
9080 (defun gnus-summary-create-article ()
9081   "Create an article in a mail newsgroup."
9082   (interactive)
9083   (let ((group gnus-newsgroup-name)
9084         (now (current-time))
9085         group-art)
9086     (unless (gnus-check-backend-function 'request-accept-article group)
9087       (error "%s does not support article importing" group))
9088     (save-excursion
9089       (set-buffer (gnus-get-buffer-create " *import file*"))
9090       (erase-buffer)
9091       (goto-char (point-min))
9092       ;; This doesn't look like an article, so we fudge some headers.
9093       (insert "From: " (read-string "From: ") "\n"
9094               "Subject: " (read-string "Subject: ") "\n"
9095               "Date: " (message-make-date now) "\n"
9096               "Message-ID: " (message-make-message-id) "\n")
9097       (setq group-art (gnus-request-accept-article group nil t))
9098       (kill-buffer (current-buffer)))
9099     (setq gnus-newsgroup-active (gnus-activate-group group))
9100     (forward-line 1)
9101     (gnus-summary-goto-article (cdr group-art) nil t)
9102     (gnus-summary-edit-article)))
9103
9104 (defun gnus-summary-article-posted-p ()
9105   "Say whether the current (mail) article is available from news as well.
9106 This will be the case if the article has both been mailed and posted."
9107   (interactive)
9108   (let ((id (mail-header-references (gnus-summary-article-header)))
9109         (gnus-override-method (car (gnus-refer-article-methods))))
9110     (if (gnus-request-head id "")
9111         (gnus-message 2 "The current message was found on %s"
9112                       gnus-override-method)
9113       (gnus-message 2 "The current message couldn't be found on %s"
9114                     gnus-override-method)
9115       nil)))
9116
9117 (defun gnus-summary-expire-articles (&optional now)
9118   "Expire all articles that are marked as expirable in the current group."
9119   (interactive)
9120   (when (and (not gnus-group-is-exiting-without-update-p)
9121              (gnus-check-backend-function
9122               'request-expire-articles gnus-newsgroup-name))
9123     ;; This backend supports expiry.
9124     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9125            (expirable (if total
9126                           (progn
9127                             ;; We need to update the info for
9128                             ;; this group for `gnus-list-of-read-articles'
9129                             ;; to give us the right answer.
9130                             (gnus-run-hooks 'gnus-exit-group-hook)
9131                             (gnus-summary-update-info)
9132                             (gnus-list-of-read-articles gnus-newsgroup-name))
9133                         (setq gnus-newsgroup-expirable
9134                               (sort gnus-newsgroup-expirable '<))))
9135            (expiry-wait (if now 'immediate
9136                           (gnus-group-find-parameter
9137                            gnus-newsgroup-name 'expiry-wait)))
9138            (nnmail-expiry-target
9139             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9140                 nnmail-expiry-target))
9141            es)
9142       (when expirable
9143         ;; There are expirable articles in this group, so we run them
9144         ;; through the expiry process.
9145         (gnus-message 6 "Expiring articles...")
9146         (unless (gnus-check-group gnus-newsgroup-name)
9147           (error "Can't open server for %s" gnus-newsgroup-name))
9148         ;; The list of articles that weren't expired is returned.
9149         (save-excursion
9150           (if expiry-wait
9151               (let ((nnmail-expiry-wait-function nil)
9152                     (nnmail-expiry-wait expiry-wait))
9153                 (setq es (gnus-request-expire-articles
9154                           expirable gnus-newsgroup-name)))
9155             (setq es (gnus-request-expire-articles
9156                       expirable gnus-newsgroup-name)))
9157           (unless total
9158             (setq gnus-newsgroup-expirable es))
9159           ;; We go through the old list of expirable, and mark all
9160           ;; really expired articles as nonexistent.
9161           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9162             (let ((gnus-use-cache nil))
9163               (dolist (article expirable)
9164                 (when (and (not (memq article es))
9165                            (gnus-data-find article))
9166                   (gnus-summary-mark-article article gnus-canceled-mark)
9167                   (run-hook-with-args 'gnus-summary-article-expire-hook
9168                                       'delete
9169                                       (gnus-data-header
9170                                        (assoc article (gnus-data-list nil)))
9171                                       gnus-newsgroup-name
9172                                       nil
9173                                       nil))))))
9174         (gnus-message 6 "Expiring articles...done")))))
9175
9176 (defun gnus-summary-expire-articles-now ()
9177   "Expunge all expirable articles in the current group.
9178 This means that *all* articles that are marked as expirable will be
9179 deleted forever, right now."
9180   (interactive)
9181   (or gnus-expert-user
9182       (gnus-yes-or-no-p
9183        "Are you really, really, really sure you want to delete all these messages? ")
9184       (error "Phew!"))
9185   (gnus-summary-expire-articles t))
9186
9187 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9188 (defun gnus-summary-delete-article (&optional n)
9189   "Delete the N next (mail) articles.
9190 This command actually deletes articles.  This is not a marking
9191 command.  The article will disappear forever from your life, never to
9192 return.
9193 If N is negative, delete backwards.
9194 If N is nil and articles have been marked with the process mark,
9195 delete these instead."
9196   (interactive "P")
9197   (unless (gnus-check-backend-function 'request-expire-articles
9198                                        gnus-newsgroup-name)
9199     (error "The current newsgroup does not support article deletion"))
9200   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9201     (error "Couldn't open server"))
9202   ;; Compute the list of articles to delete.
9203   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9204         (nnmail-expiry-target 'delete)
9205         not-deleted)
9206     (if (and gnus-novice-user
9207              (not (gnus-yes-or-no-p
9208                    (format "Do you really want to delete %s forever? "
9209                            (if (> (length articles) 1)
9210                                (format "these %s articles" (length articles))
9211                              "this article")))))
9212         ()
9213       ;; Delete the articles.
9214       (setq not-deleted (gnus-request-expire-articles
9215                          articles gnus-newsgroup-name 'force))
9216       (while articles
9217         (gnus-summary-remove-process-mark (car articles))
9218         ;; The backend might not have been able to delete the article
9219         ;; after all.
9220         (unless (memq (car articles) not-deleted)
9221           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9222         (let* ((article (car articles))
9223                (id (mail-header-id (gnus-data-header 
9224                                     (assoc article (gnus-data-list nil))))))
9225           (run-hook-with-args 'gnus-summary-article-delete-hook
9226                               'delete id gnus-newsgroup-name nil
9227                               nil))
9228         (setq articles (cdr articles)))
9229       (when not-deleted
9230         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9231     (gnus-summary-position-point)
9232     (gnus-set-mode-line 'summary)
9233     not-deleted))
9234
9235 (defun gnus-summary-edit-article (&optional arg)
9236   "Edit the current article.
9237 This will have permanent effect only in mail groups.
9238 If ARG is nil, edit the decoded articles.
9239 If ARG is 1, edit the raw articles.
9240 If ARG is 2, edit the raw articles even in read-only groups.
9241 If ARG is 3, edit the articles with the current handles.
9242 Otherwise, allow editing of articles even in read-only
9243 groups."
9244   (interactive "P")
9245   (let (force raw current-handles)
9246     (cond
9247      ((null arg))
9248      ((eq arg 1)
9249       (setq raw t))
9250      ((eq arg 2)
9251       (setq raw t
9252             force t))
9253      ((eq arg 3)
9254       (setq current-handles
9255             (and (gnus-buffer-live-p gnus-article-buffer)
9256                  (with-current-buffer gnus-article-buffer
9257                    (prog1
9258                        gnus-article-mime-handles
9259                      (setq gnus-article-mime-handles nil))))))
9260      (t
9261       (setq force t)))
9262     (when (and raw (not force)
9263                (member gnus-newsgroup-name '("nndraft:delayed"
9264                                              "nndraft:drafts"
9265                                              "nndraft:queue")))
9266       (error "Can't edit the raw article in group %s"
9267              gnus-newsgroup-name))
9268     (save-excursion
9269       (set-buffer gnus-summary-buffer)
9270       (let ((mail-parse-charset gnus-newsgroup-charset)
9271             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9272         (gnus-set-global-variables)
9273         (when (and (not force)
9274                    (gnus-group-read-only-p))
9275           (error "The current newsgroup does not support article editing"))
9276         (gnus-summary-show-article t)
9277         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9278           (with-current-buffer gnus-article-buffer
9279             (mm-enable-multibyte)))
9280         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9281             (setq raw t))
9282         (gnus-article-edit-article
9283          (if raw 'ignore
9284            `(lambda ()
9285               (let ((mbl mml-buffer-list))
9286                 (setq mml-buffer-list nil)
9287                 (mime-to-mml ,'current-handles)
9288                 (let ((mbl1 mml-buffer-list))
9289                   (setq mml-buffer-list mbl)
9290                   (set (make-local-variable 'mml-buffer-list) mbl1))
9291                 (make-local-hook 'kill-buffer-hook)
9292                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9293          `(lambda (no-highlight)
9294             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9295                   (message-options message-options)
9296                   (message-options-set-recipient)
9297                   (mail-parse-ignored-charsets
9298                    ',gnus-newsgroup-ignored-charsets))
9299               ,(if (not raw) '(progn
9300                                 (mml-to-mime)
9301                                 (mml-destroy-buffers)
9302                                 (remove-hook 'kill-buffer-hook
9303                                              'mml-destroy-buffers t)
9304                                 (kill-local-variable 'mml-buffer-list)))
9305               (gnus-summary-edit-article-done
9306                ,(or (mail-header-references gnus-current-headers) "")
9307                ,(gnus-group-read-only-p)
9308                ,gnus-summary-buffer no-highlight))))))))
9309
9310 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9311
9312 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9313                                                  no-highlight)
9314   "Make edits to the current article permanent."
9315   (interactive)
9316   (save-excursion
9317    ;; The buffer restriction contains the entire article if it exists.
9318     (when (article-goto-body)
9319       (let ((lines (count-lines (point) (point-max)))
9320             (length (- (point-max) (point)))
9321             (case-fold-search t)
9322             (body (copy-marker (point))))
9323         (goto-char (point-min))
9324         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9325           (delete-region (match-beginning 1) (match-end 1))
9326           (insert (number-to-string length)))
9327         (goto-char (point-min))
9328         (when (re-search-forward
9329                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9330           (delete-region (match-beginning 1) (match-end 1))
9331           (insert (number-to-string length)))
9332         (goto-char (point-min))
9333         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9334           (delete-region (match-beginning 1) (match-end 1))
9335           (insert (number-to-string lines))))))
9336   ;; Replace the article.
9337   (let ((buf (current-buffer)))
9338     (with-temp-buffer
9339       (insert-buffer-substring buf)
9340
9341       (if (and (not read-only)
9342                (not (gnus-request-replace-article
9343                      (cdr gnus-article-current) (car gnus-article-current)
9344                      (current-buffer) t)))
9345           (error "Couldn't replace article")
9346         ;; Update the summary buffer.
9347         (if (and references
9348                  (equal (message-tokenize-header references " ")
9349                         (message-tokenize-header
9350                          (or (message-fetch-field "references") "") " ")))
9351             ;; We only have to update this line.
9352             (save-excursion
9353               (save-restriction
9354                 (message-narrow-to-head)
9355                 (let ((head (buffer-string))
9356                       header)
9357                   (with-temp-buffer
9358                     (insert (format "211 %d Article retrieved.\n"
9359                                     (cdr gnus-article-current)))
9360                     (insert head)
9361                     (insert ".\n")
9362                     (let ((nntp-server-buffer (current-buffer)))
9363                       (setq header (car (gnus-get-newsgroup-headers
9364                                          nil t))))
9365                     (save-excursion
9366                       (set-buffer gnus-summary-buffer)
9367                       (gnus-data-set-header
9368                        (gnus-data-find (cdr gnus-article-current))
9369                        header)
9370                       (gnus-summary-update-article-line
9371                        (cdr gnus-article-current) header)
9372                       (if (gnus-summary-goto-subject
9373                            (cdr gnus-article-current) nil t)
9374                           (gnus-summary-update-secondary-mark
9375                            (cdr gnus-article-current))))))))
9376           ;; Update threads.
9377           (set-buffer (or buffer gnus-summary-buffer))
9378           (gnus-summary-update-article (cdr gnus-article-current))
9379           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9380               (gnus-summary-update-secondary-mark
9381                (cdr gnus-article-current))))
9382         ;; Prettify the article buffer again.
9383         (unless no-highlight
9384           (save-excursion
9385             (set-buffer gnus-article-buffer)
9386             ;;;!!! Fix this -- article should be rehighlighted.
9387             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9388             (set-buffer gnus-original-article-buffer)
9389             (gnus-request-article
9390              (cdr gnus-article-current)
9391              (car gnus-article-current) (current-buffer))))
9392         ;; Prettify the summary buffer line.
9393         (when (gnus-visual-p 'summary-highlight 'highlight)
9394           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9395
9396 (defun gnus-summary-edit-wash (key)
9397   "Perform editing command KEY in the article buffer."
9398   (interactive
9399    (list
9400     (progn
9401       (message "%s" (concat (this-command-keys) "- "))
9402       (read-char))))
9403   (message "")
9404   (gnus-summary-edit-article)
9405   (execute-kbd-macro (concat (this-command-keys) key))
9406   (gnus-article-edit-done))
9407
9408 ;;; Respooling
9409
9410 (defun gnus-summary-respool-query (&optional silent trace)
9411   "Query where the respool algorithm would put this article."
9412   (interactive)
9413   (let (gnus-mark-article-hook)
9414     (gnus-summary-select-article)
9415     (save-excursion
9416       (set-buffer gnus-original-article-buffer)
9417       (save-restriction
9418         (message-narrow-to-head)
9419         (let ((groups (nnmail-article-group 'identity trace)))
9420           (unless silent
9421             (if groups
9422                 (message "This message would go to %s"
9423                          (mapconcat 'car groups ", "))
9424               (message "This message would go to no groups"))
9425             groups))))))
9426
9427 (defun gnus-summary-respool-trace ()
9428   "Trace where the respool algorithm would put this article.
9429 Display a buffer showing all fancy splitting patterns which matched."
9430   (interactive)
9431   (gnus-summary-respool-query nil t))
9432
9433 ;; Summary marking commands.
9434
9435 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9436   "Mark articles which has the same subject as read, and then select the next.
9437 If UNMARK is positive, remove any kind of mark.
9438 If UNMARK is negative, tick articles."
9439   (interactive "P")
9440   (when unmark
9441     (setq unmark (prefix-numeric-value unmark)))
9442   (let ((count
9443          (gnus-summary-mark-same-subject
9444           (gnus-summary-article-subject) unmark)))
9445     ;; Select next unread article.  If auto-select-same mode, should
9446     ;; select the first unread article.
9447     (gnus-summary-next-article t (and gnus-auto-select-same
9448                                       (gnus-summary-article-subject)))
9449     (gnus-message 7 "%d article%s marked as %s"
9450                   count (if (= count 1) " is" "s are")
9451                   (if unmark "unread" "read"))))
9452
9453 (defun gnus-summary-kill-same-subject (&optional unmark)
9454   "Mark articles which has the same subject as read.
9455 If UNMARK is positive, remove any kind of mark.
9456 If UNMARK is negative, tick articles."
9457   (interactive "P")
9458   (when unmark
9459     (setq unmark (prefix-numeric-value unmark)))
9460   (let ((count
9461          (gnus-summary-mark-same-subject
9462           (gnus-summary-article-subject) unmark)))
9463     ;; If marked as read, go to next unread subject.
9464     (when (null unmark)
9465       ;; Go to next unread subject.
9466       (gnus-summary-next-subject 1 t))
9467     (gnus-message 7 "%d articles are marked as %s"
9468                   count (if unmark "unread" "read"))))
9469
9470 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9471   "Mark articles with same SUBJECT as read, and return marked number.
9472 If optional argument UNMARK is positive, remove any kinds of marks.
9473 If optional argument UNMARK is negative, mark articles as unread instead."
9474   (let ((count 1))
9475     (save-excursion
9476       (cond
9477        ((null unmark)                   ; Mark as read.
9478         (while (and
9479                 (progn
9480                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9481                   (gnus-summary-show-thread) t)
9482                 (gnus-summary-find-subject subject))
9483           (setq count (1+ count))))
9484        ((> unmark 0)                    ; Tick.
9485         (while (and
9486                 (progn
9487                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9488                   (gnus-summary-show-thread) t)
9489                 (gnus-summary-find-subject subject))
9490           (setq count (1+ count))))
9491        (t                               ; Mark as unread.
9492         (while (and
9493                 (progn
9494                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9495                   (gnus-summary-show-thread) t)
9496                 (gnus-summary-find-subject subject))
9497           (setq count (1+ count)))))
9498       (gnus-set-mode-line 'summary)
9499       ;; Return the number of marked articles.
9500       count)))
9501
9502 (defun gnus-summary-mark-as-processable (n &optional unmark)
9503   "Set the process mark on the next N articles.
9504 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9505 the process mark instead.  The difference between N and the actual
9506 number of articles marked is returned."
9507   (interactive "P")
9508   (if (and (null n) (gnus-region-active-p))
9509       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9510     (setq n (prefix-numeric-value n))
9511     (let ((backward (< n 0))
9512           (n (abs n)))
9513       (while (and
9514               (> n 0)
9515               (if unmark
9516                   (gnus-summary-remove-process-mark
9517                    (gnus-summary-article-number))
9518                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9519               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9520         (setq n (1- n)))
9521       (when (/= 0 n)
9522         (gnus-message 7 "No more articles"))
9523       (gnus-summary-recenter)
9524       (gnus-summary-position-point)
9525       n)))
9526
9527 (defun gnus-summary-unmark-as-processable (n)
9528   "Remove the process mark from the next N articles.
9529 If N is negative, unmark backward instead.  The difference between N and
9530 the actual number of articles unmarked is returned."
9531   (interactive "P")
9532   (gnus-summary-mark-as-processable n t))
9533
9534 (defun gnus-summary-unmark-all-processable ()
9535   "Remove the process mark from all articles."
9536   (interactive)
9537   (save-excursion
9538     (while gnus-newsgroup-processable
9539       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9540   (gnus-summary-position-point))
9541
9542 (defun gnus-summary-add-mark (article type)
9543   "Mark ARTICLE with a mark of TYPE."
9544   (let ((vtype (car (assq type gnus-article-mark-lists)))
9545         var)
9546     (if (not vtype)
9547         (error "No such mark type: %s" type)
9548       (setq var (intern (format "gnus-newsgroup-%s" type)))
9549       (set var (cons article (symbol-value var)))
9550       (if (memq type '(processable cached replied forwarded recent saved))
9551           (gnus-summary-update-secondary-mark article)
9552         ;;; !!! This is bogus.  We should find out what primary
9553         ;;; !!! mark we want to set.
9554         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9555
9556 (defun gnus-summary-mark-as-expirable (n)
9557   "Mark N articles forward as expirable.
9558 If N is negative, mark backward instead.  The difference between N and
9559 the actual number of articles marked is returned."
9560   (interactive "p")
9561   (gnus-summary-mark-forward n gnus-expirable-mark))
9562
9563 (defun gnus-summary-mark-as-spam (n)
9564   "Mark N articles forward as spam.
9565 If N is negative, mark backward instead.  The difference between N and
9566 the actual number of articles marked is returned."
9567   (interactive "p")
9568   (gnus-summary-mark-forward n gnus-spam-mark))
9569
9570 (defun gnus-summary-mark-article-as-replied (article)
9571   "Mark ARTICLE as replied to and update the summary line.
9572 ARTICLE can also be a list of articles."
9573   (interactive (list (gnus-summary-article-number)))
9574   (let ((articles (if (listp article) article (list article))))
9575     (dolist (article articles)
9576       (unless (numberp article)
9577         (error "%s is not a number" article))
9578       (push article gnus-newsgroup-replied)
9579       (let ((buffer-read-only nil))
9580         (when (gnus-summary-goto-subject article nil t)
9581           (gnus-summary-update-secondary-mark article))))))
9582
9583 (defun gnus-summary-mark-article-as-forwarded (article)
9584   "Mark ARTICLE as forwarded and update the summary line.
9585 ARTICLE can also be a list of articles."
9586   (let ((articles (if (listp article) article (list article))))
9587     (dolist (article articles)
9588       (push article gnus-newsgroup-forwarded)
9589       (let ((buffer-read-only nil))
9590         (when (gnus-summary-goto-subject article nil t)
9591           (gnus-summary-update-secondary-mark article))))))
9592
9593 (defun gnus-summary-set-bookmark (article)
9594   "Set a bookmark in current article."
9595   (interactive (list (gnus-summary-article-number)))
9596   (when (or (not (get-buffer gnus-article-buffer))
9597             (not gnus-current-article)
9598             (not gnus-article-current)
9599             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9600     (error "No current article selected"))
9601   ;; Remove old bookmark, if one exists.
9602   (gnus-pull article gnus-newsgroup-bookmarks)
9603   ;; Set the new bookmark, which is on the form
9604   ;; (article-number . line-number-in-body).
9605   (push
9606    (cons article
9607          (save-excursion
9608            (set-buffer gnus-article-buffer)
9609            (count-lines
9610             (min (point)
9611                  (save-excursion
9612                    (article-goto-body)
9613                    (point)))
9614             (point))))
9615    gnus-newsgroup-bookmarks)
9616   (gnus-message 6 "A bookmark has been added to the current article."))
9617
9618 (defun gnus-summary-remove-bookmark (article)
9619   "Remove the bookmark from the current article."
9620   (interactive (list (gnus-summary-article-number)))
9621   ;; Remove old bookmark, if one exists.
9622   (if (not (assq article gnus-newsgroup-bookmarks))
9623       (gnus-message 6 "No bookmark in current article.")
9624     (gnus-pull article gnus-newsgroup-bookmarks)
9625     (gnus-message 6 "Removed bookmark.")))
9626
9627 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9628 (defun gnus-summary-mark-as-dormant (n)
9629   "Mark N articles forward as dormant.
9630 If N is negative, mark backward instead.  The difference between N and
9631 the actual number of articles marked is returned."
9632   (interactive "p")
9633   (gnus-summary-mark-forward n gnus-dormant-mark))
9634
9635 (defun gnus-summary-set-process-mark (article)
9636   "Set the process mark on ARTICLE and update the summary line."
9637   (setq gnus-newsgroup-processable
9638         (cons article
9639               (delq article gnus-newsgroup-processable)))
9640   (when (gnus-summary-goto-subject article)
9641     (gnus-summary-show-thread)
9642     (gnus-summary-goto-subject article)
9643     (gnus-summary-update-secondary-mark article)))
9644
9645 (defun gnus-summary-remove-process-mark (article)
9646   "Remove the process mark from ARTICLE and update the summary line."
9647   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9648   (when (gnus-summary-goto-subject article)
9649     (gnus-summary-show-thread)
9650     (gnus-summary-goto-subject article)
9651     (gnus-summary-update-secondary-mark article)))
9652
9653 (defun gnus-summary-set-saved-mark (article)
9654   "Set the process mark on ARTICLE and update the summary line."
9655   (push article gnus-newsgroup-saved)
9656   (when (gnus-summary-goto-subject article)
9657     (gnus-summary-update-secondary-mark article)))
9658
9659 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9660   "Mark N articles as read forwards.
9661 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9662 The difference between N and the actual number of articles marked is
9663 returned.
9664 If NO-EXPIRE, auto-expiry will be inhibited."
9665   (interactive "p")
9666   (gnus-summary-show-thread)
9667   (let ((backward (< n 0))
9668         (gnus-summary-goto-unread
9669          (and gnus-summary-goto-unread
9670               (not (eq gnus-summary-goto-unread 'never))
9671               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9672                                     gnus-ticked-mark gnus-dormant-mark)))))
9673         (n (abs n))
9674         (mark (or mark gnus-del-mark)))
9675     (while (and (> n 0)
9676                 (gnus-summary-mark-article nil mark no-expire)
9677                 (zerop (gnus-summary-next-subject
9678                         (if backward -1 1)
9679                         (and gnus-summary-goto-unread
9680                              (not (eq gnus-summary-goto-unread 'never)))
9681                         t)))
9682       (setq n (1- n)))
9683     (when (/= 0 n)
9684       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9685     (gnus-summary-recenter)
9686     (gnus-summary-position-point)
9687     (gnus-set-mode-line 'summary)
9688     n))
9689
9690 (defun gnus-summary-mark-article-as-read (mark)
9691   "Mark the current article quickly as read with MARK."
9692   (let ((article (gnus-summary-article-number)))
9693     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9694     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9695     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9696     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9697     (push (cons article mark) gnus-newsgroup-reads)
9698     ;; Possibly remove from cache, if that is used.
9699     (when gnus-use-cache
9700       (gnus-cache-enter-remove-article article))
9701     ;; Allow the backend to change the mark.
9702     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9703     ;; Check for auto-expiry.
9704     (when (and gnus-newsgroup-auto-expire
9705                (memq mark gnus-auto-expirable-marks))
9706       (setq mark gnus-expirable-mark)
9707       ;; Let the backend know about the mark change.
9708       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9709       (push article gnus-newsgroup-expirable))
9710     ;; Set the mark in the buffer.
9711     (gnus-summary-update-mark mark 'unread)
9712     t))
9713
9714 (defun gnus-summary-mark-article-as-unread (mark)
9715   "Mark the current article quickly as unread with MARK."
9716   (let* ((article (gnus-summary-article-number))
9717          (old-mark (gnus-summary-article-mark article)))
9718     ;; Allow the backend to change the mark.
9719     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9720     (if (eq mark old-mark)
9721         t
9722       (if (<= article 0)
9723           (progn
9724             (gnus-error 1 "Can't mark negative article numbers")
9725             nil)
9726         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9727         (setq gnus-newsgroup-spam-marked
9728               (delq article gnus-newsgroup-spam-marked))
9729         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9730         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9731         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9732         (cond ((= mark gnus-ticked-mark)
9733                (setq gnus-newsgroup-marked
9734                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9735                                               article)))
9736               ((= mark gnus-spam-mark)
9737                (setq gnus-newsgroup-spam-marked
9738                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9739                                               article)))
9740               ((= mark gnus-dormant-mark)
9741                (setq gnus-newsgroup-dormant
9742                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9743                                               article)))
9744               (t
9745                (setq gnus-newsgroup-unreads
9746                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9747                                               article))))
9748         (gnus-pull article gnus-newsgroup-reads)
9749
9750         ;; See whether the article is to be put in the cache.
9751         (and gnus-use-cache
9752              (vectorp (gnus-summary-article-header article))
9753              (save-excursion
9754                (gnus-cache-possibly-enter-article
9755                 gnus-newsgroup-name article
9756                 (= mark gnus-ticked-mark)
9757                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9758
9759         ;; Fix the mark.
9760         (gnus-summary-update-mark mark 'unread)
9761         t))))
9762
9763 (defun gnus-summary-mark-article (&optional article mark no-expire)
9764   "Mark ARTICLE with MARK.  MARK can be any character.
9765 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9766 `??' (dormant) and `?E' (expirable).
9767 If MARK is nil, then the default character `?r' is used.
9768 If ARTICLE is nil, then the article on the current line will be
9769 marked.
9770 If NO-EXPIRE, auto-expiry will be inhibited."
9771   ;; The mark might be a string.
9772   (when (stringp mark)
9773     (setq mark (aref mark 0)))
9774   ;; If no mark is given, then we check auto-expiring.
9775   (when (null mark)
9776     (setq mark gnus-del-mark))
9777   (when (and (not no-expire)
9778              gnus-newsgroup-auto-expire
9779              (memq mark gnus-auto-expirable-marks))
9780     (setq mark gnus-expirable-mark))
9781   (let ((article (or article (gnus-summary-article-number)))
9782         (old-mark (gnus-summary-article-mark article)))
9783     ;; Allow the backend to change the mark.
9784     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9785     (if (eq mark old-mark)
9786         t
9787       (unless article
9788         (error "No article on current line"))
9789       (if (not (if (or (= mark gnus-unread-mark)
9790                        (= mark gnus-ticked-mark)
9791                        (= mark gnus-spam-mark)
9792                        (= mark gnus-dormant-mark))
9793                    (gnus-mark-article-as-unread article mark)
9794                  (gnus-mark-article-as-read article mark)))
9795           t
9796         ;; See whether the article is to be put in the cache.
9797         (and gnus-use-cache
9798              (not (= mark gnus-canceled-mark))
9799              (vectorp (gnus-summary-article-header article))
9800              (save-excursion
9801                (gnus-cache-possibly-enter-article
9802                 gnus-newsgroup-name article
9803                 (= mark gnus-ticked-mark)
9804                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9805
9806         (when (gnus-summary-goto-subject article nil t)
9807           (let ((buffer-read-only nil))
9808             (gnus-summary-show-thread)
9809             ;; Fix the mark.
9810             (gnus-summary-update-mark mark 'unread)
9811             t))))))
9812
9813 (defun gnus-summary-update-secondary-mark (article)
9814   "Update the secondary (read, process, cache) mark."
9815   (gnus-summary-update-mark
9816    (cond ((memq article gnus-newsgroup-processable)
9817           gnus-process-mark)
9818          ((memq article gnus-newsgroup-cached)
9819           gnus-cached-mark)
9820          ((memq article gnus-newsgroup-replied)
9821           gnus-replied-mark)
9822          ((memq article gnus-newsgroup-forwarded)
9823           gnus-forwarded-mark)
9824          ((memq article gnus-newsgroup-saved)
9825           gnus-saved-mark)
9826          ((memq article gnus-newsgroup-recent)
9827           gnus-recent-mark)
9828          ((memq article gnus-newsgroup-unseen)
9829           gnus-unseen-mark)
9830          (t gnus-no-mark))
9831    'replied)
9832   (when (gnus-visual-p 'summary-highlight 'highlight)
9833     (gnus-run-hooks 'gnus-summary-update-hook))
9834   t)
9835
9836 (defun gnus-summary-update-download-mark (article)
9837   "Update the download mark."
9838   (gnus-summary-update-mark
9839    (cond ((memq article gnus-newsgroup-undownloaded) 
9840           gnus-undownloaded-mark)
9841          (gnus-newsgroup-agentized
9842           gnus-downloaded-mark)
9843          (t
9844           gnus-no-mark))
9845    'download)
9846   (gnus-summary-update-line t)
9847   t)
9848
9849 (defun gnus-summary-update-mark (mark type)
9850   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9851         (buffer-read-only nil))
9852     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9853     (when forward
9854       (when (looking-at "\r")
9855         (incf forward))
9856       (when (<= (+ forward (point)) (point-max))
9857         ;; Go to the right position on the line.
9858         (goto-char (+ forward (point)))
9859         ;; Replace the old mark with the new mark.
9860         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9861         ;; Optionally update the marks by some user rule.
9862         (when (eq type 'unread)
9863           (gnus-data-set-mark
9864            (gnus-data-find (gnus-summary-article-number)) mark)
9865           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9866
9867 (defun gnus-mark-article-as-read (article &optional mark)
9868   "Enter ARTICLE in the pertinent lists and remove it from others."
9869   ;; Make the article expirable.
9870   (let ((mark (or mark gnus-del-mark)))
9871     (setq gnus-newsgroup-expirable
9872           (if (= mark gnus-expirable-mark)
9873               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9874             (delq article gnus-newsgroup-expirable)))
9875     ;; Remove from unread and marked lists.
9876     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9877     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9878     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9879     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9880     (push (cons article mark) gnus-newsgroup-reads)
9881     ;; Possibly remove from cache, if that is used.
9882     (when gnus-use-cache
9883       (gnus-cache-enter-remove-article article))
9884     t))
9885
9886 (defun gnus-mark-article-as-unread (article &optional mark)
9887   "Enter ARTICLE in the pertinent lists and remove it from others."
9888   (let ((mark (or mark gnus-ticked-mark)))
9889     (if (<= article 0)
9890         (progn
9891           (gnus-error 1 "Can't mark negative article numbers")
9892           nil)
9893       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9894             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
9895             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9896             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9897             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9898
9899       ;; Unsuppress duplicates?
9900       (when gnus-suppress-duplicates
9901         (gnus-dup-unsuppress-article article))
9902
9903       (cond ((= mark gnus-ticked-mark)
9904              (setq gnus-newsgroup-marked
9905                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9906             ((= mark gnus-spam-mark)
9907              (setq gnus-newsgroup-spam-marked
9908                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9909                                             article)))
9910             ((= mark gnus-dormant-mark)
9911              (setq gnus-newsgroup-dormant
9912                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9913             (t
9914              (setq gnus-newsgroup-unreads
9915                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9916       (gnus-pull article gnus-newsgroup-reads)
9917       t)))
9918
9919 (defalias 'gnus-summary-mark-as-unread-forward
9920   'gnus-summary-tick-article-forward)
9921 (make-obsolete 'gnus-summary-mark-as-unread-forward
9922                'gnus-summary-tick-article-forward)
9923 (defun gnus-summary-tick-article-forward (n)
9924   "Tick N articles forwards.
9925 If N is negative, tick backwards instead.
9926 The difference between N and the number of articles ticked is returned."
9927   (interactive "p")
9928   (gnus-summary-mark-forward n gnus-ticked-mark))
9929
9930 (defalias 'gnus-summary-mark-as-unread-backward
9931   'gnus-summary-tick-article-backward)
9932 (make-obsolete 'gnus-summary-mark-as-unread-backward
9933                'gnus-summary-tick-article-backward)
9934 (defun gnus-summary-tick-article-backward (n)
9935   "Tick N articles backwards.
9936 The difference between N and the number of articles ticked is returned."
9937   (interactive "p")
9938   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9939
9940 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9941 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9942 (defun gnus-summary-tick-article (&optional article clear-mark)
9943   "Mark current article as unread.
9944 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9945 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9946   (interactive)
9947   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9948                                        gnus-ticked-mark)))
9949
9950 (defun gnus-summary-mark-as-read-forward (n)
9951   "Mark N articles as read forwards.
9952 If N is negative, mark backwards instead.
9953 The difference between N and the actual number of articles marked is
9954 returned."
9955   (interactive "p")
9956   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9957
9958 (defun gnus-summary-mark-as-read-backward (n)
9959   "Mark the N articles as read backwards.
9960 The difference between N and the actual number of articles marked is
9961 returned."
9962   (interactive "p")
9963   (gnus-summary-mark-forward
9964    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9965
9966 (defun gnus-summary-mark-as-read (&optional article mark)
9967   "Mark current article as read.
9968 ARTICLE specifies the article to be marked as read.
9969 MARK specifies a string to be inserted at the beginning of the line."
9970   (gnus-summary-mark-article article mark))
9971
9972 (defun gnus-summary-clear-mark-forward (n)
9973   "Clear marks from N articles forward.
9974 If N is negative, clear backward instead.
9975 The difference between N and the number of marks cleared is returned."
9976   (interactive "p")
9977   (gnus-summary-mark-forward n gnus-unread-mark))
9978
9979 (defun gnus-summary-clear-mark-backward (n)
9980   "Clear marks from N articles backward.
9981 The difference between N and the number of marks cleared is returned."
9982   (interactive "p")
9983   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9984
9985 (defun gnus-summary-mark-unread-as-read ()
9986   "Intended to be used by `gnus-summary-mark-article-hook'."
9987   (when (memq gnus-current-article gnus-newsgroup-unreads)
9988     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9989
9990 (defun gnus-summary-mark-read-and-unread-as-read ()
9991   "Intended to be used by `gnus-summary-mark-article-hook'."
9992   (let ((mark (gnus-summary-article-mark)))
9993     (when (or (gnus-unread-mark-p mark)
9994               (gnus-read-mark-p mark))
9995       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9996
9997 (defun gnus-summary-mark-unread-as-ticked ()
9998   "Intended to be used by `gnus-summary-mark-article-hook'."
9999   (when (memq gnus-current-article gnus-newsgroup-unreads)
10000     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10001
10002 (defun gnus-summary-mark-region-as-read (point mark all)
10003   "Mark all unread articles between point and mark as read.
10004 If given a prefix, mark all articles between point and mark as read,
10005 even ticked and dormant ones."
10006   (interactive "r\nP")
10007   (save-excursion
10008     (let (article)
10009       (goto-char point)
10010       (beginning-of-line)
10011       (while (and
10012               (< (point) mark)
10013               (progn
10014                 (when (or all
10015                           (memq (setq article (gnus-summary-article-number))
10016                                 gnus-newsgroup-unreads))
10017                   (gnus-summary-mark-article article gnus-del-mark))
10018                 t)
10019               (gnus-summary-find-next))))))
10020
10021 (defun gnus-summary-mark-below (score mark)
10022   "Mark articles with score less than SCORE with MARK."
10023   (interactive "P\ncMark: ")
10024   (setq score (if score
10025                   (prefix-numeric-value score)
10026                 (or gnus-summary-default-score 0)))
10027   (save-excursion
10028     (set-buffer gnus-summary-buffer)
10029     (goto-char (point-min))
10030     (while
10031         (progn
10032           (and (< (gnus-summary-article-score) score)
10033                (gnus-summary-mark-article nil mark))
10034           (gnus-summary-find-next)))))
10035
10036 (defun gnus-summary-kill-below (&optional score)
10037   "Mark articles with score below SCORE as read."
10038   (interactive "P")
10039   (gnus-summary-mark-below score gnus-killed-mark))
10040
10041 (defun gnus-summary-clear-above (&optional score)
10042   "Clear all marks from articles with score above SCORE."
10043   (interactive "P")
10044   (gnus-summary-mark-above score gnus-unread-mark))
10045
10046 (defun gnus-summary-tick-above (&optional score)
10047   "Tick all articles with score above SCORE."
10048   (interactive "P")
10049   (gnus-summary-mark-above score gnus-ticked-mark))
10050
10051 (defun gnus-summary-mark-above (score mark)
10052   "Mark articles with score over SCORE with MARK."
10053   (interactive "P\ncMark: ")
10054   (setq score (if score
10055                   (prefix-numeric-value score)
10056                 (or gnus-summary-default-score 0)))
10057   (save-excursion
10058     (set-buffer gnus-summary-buffer)
10059     (goto-char (point-min))
10060     (while (and (progn
10061                   (when (> (gnus-summary-article-score) score)
10062                     (gnus-summary-mark-article nil mark))
10063                   t)
10064                 (gnus-summary-find-next)))))
10065
10066 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10067 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10068 (defun gnus-summary-limit-include-expunged (&optional no-error)
10069   "Display all the hidden articles that were expunged for low scores."
10070   (interactive)
10071   (let ((buffer-read-only nil))
10072     (let ((scored gnus-newsgroup-scored)
10073           headers h)
10074       (while scored
10075         (unless (gnus-summary-article-header (caar scored))
10076           (and (setq h (gnus-number-to-header (caar scored)))
10077                (< (cdar scored) gnus-summary-expunge-below)
10078                (push h headers)))
10079         (setq scored (cdr scored)))
10080       (if (not headers)
10081           (when (not no-error)
10082             (error "No expunged articles hidden"))
10083         (goto-char (point-min))
10084         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10085         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10086         (mapcar (lambda (x) (push (mail-header-number x)
10087                                   gnus-newsgroup-limit))
10088                 headers)
10089         (gnus-summary-prepare-unthreaded (nreverse headers))
10090         (goto-char (point-min))
10091         (gnus-summary-position-point)
10092         t))))
10093
10094 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10095   "Mark all unread articles in this newsgroup as read.
10096 If prefix argument ALL is non-nil, ticked and dormant articles will
10097 also be marked as read.
10098 If QUIETLY is non-nil, no questions will be asked.
10099 If TO-HERE is non-nil, it should be a point in the buffer.  All
10100 articles before (after, if REVERSE is set) this point will be marked as read.
10101 Note that this function will only catch up the unread article
10102 in the current summary buffer limitation.
10103 The number of articles marked as read is returned."
10104   (interactive "P")
10105   (prog1
10106       (save-excursion
10107         (when (or quietly
10108                   (not gnus-interactive-catchup) ;Without confirmation?
10109                   gnus-expert-user
10110                   (gnus-y-or-n-p
10111                    (if all
10112                        "Mark absolutely all articles as read? "
10113                      "Mark all unread articles as read? ")))
10114           (if (and not-mark
10115                    (not gnus-newsgroup-adaptive)
10116                    (not gnus-newsgroup-auto-expire)
10117                    (not gnus-suppress-duplicates)
10118                    (or (not gnus-use-cache)
10119                        (eq gnus-use-cache 'passive)))
10120               (progn
10121                 (when all
10122                   (setq gnus-newsgroup-marked nil
10123                         gnus-newsgroup-spam-marked nil
10124                         gnus-newsgroup-dormant nil))
10125                 (setq gnus-newsgroup-unreads
10126                       (gnus-sorted-nunion
10127                        (gnus-intersection gnus-newsgroup-unreads
10128                                           gnus-newsgroup-downloadable)
10129                        gnus-newsgroup-unfetched)))
10130             ;; We actually mark all articles as canceled, which we
10131             ;; have to do when using auto-expiry or adaptive scoring.
10132             (gnus-summary-show-all-threads)
10133             (if (and to-here reverse)
10134                 (progn
10135                   (goto-char to-here)
10136                   (while (and
10137                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
10138                           (gnus-summary-find-next (not all)))))
10139               (when (gnus-summary-first-subject (not all))
10140                 (while (and
10141                         (if to-here (< (point) to-here) t)
10142                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10143                         (gnus-summary-find-next (not all))))))
10144             (gnus-set-mode-line 'summary))
10145           t))
10146     (gnus-summary-position-point)))
10147
10148 (defun gnus-summary-catchup-to-here (&optional all)
10149   "Mark all unticked articles before the current one as read.
10150 If ALL is non-nil, also mark ticked and dormant articles as read."
10151   (interactive "P")
10152   (save-excursion
10153     (gnus-save-hidden-threads
10154       (let ((beg (point)))
10155         ;; We check that there are unread articles.
10156         (when (or all (gnus-summary-find-prev))
10157           (gnus-summary-catchup all t beg)))))
10158   (gnus-summary-position-point))
10159
10160 (defun gnus-summary-catchup-from-here (&optional all)
10161   "Mark all unticked articles after the current one as read.
10162 If ALL is non-nil, also mark ticked and dormant articles as read."
10163   (interactive "P")
10164   (save-excursion
10165     (gnus-save-hidden-threads
10166       (let ((beg (point)))
10167         ;; We check that there are unread articles.
10168         (when (or all (gnus-summary-find-next))
10169           (gnus-summary-catchup all t beg nil t)))))
10170
10171   (gnus-summary-position-point))
10172 (defun gnus-summary-catchup-all (&optional quietly)
10173   "Mark all articles in this newsgroup as read.
10174 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10175 instead, which marks only unread articles as read."
10176   (interactive "P")
10177   (gnus-summary-catchup t quietly))
10178
10179 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10180   "Mark all unread articles in this group as read, then exit.
10181 If prefix argument ALL is non-nil, all articles are marked as read.
10182 If QUIETLY is non-nil, no questions will be asked."
10183   (interactive "P")
10184   (when (gnus-summary-catchup all quietly nil 'fast)
10185     ;; Select next newsgroup or exit.
10186     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10187              (eq gnus-auto-select-next 'quietly))
10188         (gnus-summary-next-group nil)
10189       (gnus-summary-exit))))
10190
10191 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10192   "Mark all articles in this newsgroup as read, and then exit.
10193 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10194 instead, which marks only unread articles as read."
10195   (interactive "P")
10196   (gnus-summary-catchup-and-exit t quietly))
10197
10198 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10199   "Mark all articles in this group as read and select the next group.
10200 If given a prefix, mark all articles, unread as well as ticked, as
10201 read."
10202   (interactive "P")
10203   (save-excursion
10204     (gnus-summary-catchup all))
10205   (gnus-summary-next-group))
10206
10207 ;;;
10208 ;;; with article
10209 ;;;
10210
10211 (defmacro gnus-with-article (article &rest forms)
10212   "Select ARTICLE and perform FORMS in the original article buffer.
10213 Then replace the article with the result."
10214   `(progn
10215      ;; We don't want the article to be marked as read.
10216      (let (gnus-mark-article-hook)
10217        (gnus-summary-select-article t t nil ,article))
10218      (set-buffer gnus-original-article-buffer)
10219      ,@forms
10220      (if (not (gnus-check-backend-function
10221                'request-replace-article (car gnus-article-current)))
10222          (gnus-message 5 "Read-only group; not replacing")
10223        (unless (gnus-request-replace-article
10224                 ,article (car gnus-article-current)
10225                 (current-buffer) t)
10226          (error "Couldn't replace article")))
10227      ;; The cache and backlog have to be flushed somewhat.
10228      (when gnus-keep-backlog
10229        (gnus-backlog-remove-article
10230         (car gnus-article-current) (cdr gnus-article-current)))
10231      (when gnus-use-cache
10232        (gnus-cache-update-article
10233         (car gnus-article-current) (cdr gnus-article-current)))))
10234
10235 (put 'gnus-with-article 'lisp-indent-function 1)
10236 (put 'gnus-with-article 'edebug-form-spec '(form body))
10237
10238 ;; Thread-based commands.
10239
10240 (defun gnus-summary-articles-in-thread (&optional article)
10241   "Return a list of all articles in the current thread.
10242 If ARTICLE is non-nil, return all articles in the thread that starts
10243 with that article."
10244   (let* ((article (or article (gnus-summary-article-number)))
10245          (data (gnus-data-find-list article))
10246          (top-level (gnus-data-level (car data)))
10247          (top-subject
10248           (cond ((null gnus-thread-operation-ignore-subject)
10249                  (gnus-simplify-subject-re
10250                   (mail-header-subject (gnus-data-header (car data)))))
10251                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10252                  (gnus-simplify-subject-fuzzy
10253                   (mail-header-subject (gnus-data-header (car data)))))
10254                 (t nil)))
10255          (end-point (save-excursion
10256                       (if (gnus-summary-go-to-next-thread)
10257                           (point) (point-max))))
10258          articles)
10259     (while (and data
10260                 (< (gnus-data-pos (car data)) end-point))
10261       (when (or (not top-subject)
10262                 (string= top-subject
10263                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10264                              (gnus-simplify-subject-fuzzy
10265                               (mail-header-subject
10266                                (gnus-data-header (car data))))
10267                            (gnus-simplify-subject-re
10268                             (mail-header-subject
10269                              (gnus-data-header (car data)))))))
10270         (push (gnus-data-number (car data)) articles))
10271       (unless (and (setq data (cdr data))
10272                    (> (gnus-data-level (car data)) top-level))
10273         (setq data nil)))
10274     ;; Return the list of articles.
10275     (nreverse articles)))
10276
10277 (defun gnus-summary-rethread-current ()
10278   "Rethread the thread the current article is part of."
10279   (interactive)
10280   (let* ((gnus-show-threads t)
10281          (article (gnus-summary-article-number))
10282          (id (mail-header-id (gnus-summary-article-header)))
10283          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10284     (unless id
10285       (error "No article on the current line"))
10286     (gnus-rebuild-thread id)
10287     (gnus-summary-goto-subject article)))
10288
10289 (defun gnus-summary-reparent-thread ()
10290   "Make the current article child of the marked (or previous) article.
10291
10292 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10293 is non-nil or the Subject: of both articles are the same."
10294   (interactive)
10295   (unless (not (gnus-group-read-only-p))
10296     (error "The current newsgroup does not support article editing"))
10297   (unless (<= (length gnus-newsgroup-processable) 1)
10298     (error "No more than one article may be marked"))
10299   (save-window-excursion
10300     (let ((gnus-article-buffer " *reparent*")
10301           (current-article (gnus-summary-article-number))
10302           ;; First grab the marked article, otherwise one line up.
10303           (parent-article (if (not (null gnus-newsgroup-processable))
10304                               (car gnus-newsgroup-processable)
10305                             (save-excursion
10306                               (if (eq (forward-line -1) 0)
10307                                   (gnus-summary-article-number)
10308                                 (error "Beginning of summary buffer"))))))
10309       (unless (not (eq current-article parent-article))
10310         (error "An article may not be self-referential"))
10311       (let ((message-id (mail-header-id
10312                          (gnus-summary-article-header parent-article))))
10313         (unless (and message-id (not (equal message-id "")))
10314           (error "No message-id in desired parent"))
10315         (gnus-with-article current-article
10316           (save-restriction
10317             (goto-char (point-min))
10318             (message-narrow-to-head)
10319             (if (re-search-forward "^References: " nil t)
10320                 (progn
10321                   (re-search-forward "^[^ \t]" nil t)
10322                   (forward-line -1)
10323                   (end-of-line)
10324                   (insert " " message-id))
10325               (insert "References: " message-id "\n"))))
10326         (set-buffer gnus-summary-buffer)
10327         (gnus-summary-unmark-all-processable)
10328         (gnus-summary-update-article current-article)
10329         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10330             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10331         (gnus-summary-rethread-current)
10332         (gnus-message 3 "Article %d is now the child of article %d"
10333                       current-article parent-article)))))
10334
10335 (defun gnus-summary-toggle-threads (&optional arg)
10336   "Toggle showing conversation threads.
10337 If ARG is positive number, turn showing conversation threads on."
10338   (interactive "P")
10339   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10340     (setq gnus-show-threads
10341           (if (null arg) (not gnus-show-threads)
10342             (> (prefix-numeric-value arg) 0)))
10343     (gnus-summary-prepare)
10344     (gnus-summary-goto-subject current)
10345     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10346     (gnus-summary-position-point)))
10347
10348 (defun gnus-summary-show-all-threads ()
10349   "Show all threads."
10350   (interactive)
10351   (save-excursion
10352     (let ((buffer-read-only nil))
10353       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10354   (gnus-summary-position-point))
10355
10356 (defun gnus-summary-show-thread ()
10357   "Show thread subtrees.
10358 Returns nil if no thread was there to be shown."
10359   (interactive)
10360   (let ((buffer-read-only nil)
10361         (orig (point))
10362         (end (gnus-point-at-eol))
10363         ;; Leave point at bol
10364         (beg (progn (beginning-of-line) (point))))
10365     (prog1
10366         ;; Any hidden lines here?
10367         (search-forward "\r" end t)
10368       (subst-char-in-region beg end ?\^M ?\n t)
10369       (goto-char orig)
10370       (gnus-summary-position-point))))
10371
10372 (defun gnus-summary-maybe-hide-threads ()
10373   "If requested, hide the threads that should be hidden."
10374   (when (and gnus-show-threads
10375              gnus-thread-hide-subtree)
10376     (gnus-summary-hide-all-threads
10377      (if (or (consp gnus-thread-hide-subtree)
10378              (gnus-functionp gnus-thread-hide-subtree))
10379          (gnus-make-predicate gnus-thread-hide-subtree)
10380        nil))))
10381
10382 ;;; Hiding predicates.
10383
10384 (defun gnus-article-unread-p (header)
10385   (memq (mail-header-number header) gnus-newsgroup-unreads))
10386
10387 (defun gnus-article-unseen-p (header)
10388   (memq (mail-header-number header) gnus-newsgroup-unseen))
10389
10390 (defun gnus-map-articles (predicate articles)
10391   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10392   (apply 'gnus-or (mapcar predicate
10393                           (mapcar 'gnus-summary-article-header articles))))
10394
10395 (defun gnus-summary-hide-all-threads (&optional predicate)
10396   "Hide all thread subtrees.
10397 If PREDICATE is supplied, threads that satisfy this predicate
10398 will not be hidden."
10399   (interactive)
10400   (save-excursion
10401     (goto-char (point-min))
10402     (let ((end nil))
10403       (while (not end)
10404         (when (or (not predicate)
10405                   (gnus-map-articles
10406                    predicate (gnus-summary-article-children)))
10407             (gnus-summary-hide-thread))
10408         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10409   (gnus-summary-position-point))
10410
10411 (defun gnus-summary-hide-thread ()
10412   "Hide thread subtrees.
10413 If PREDICATE is supplied, threads that satisfy this predicate
10414 will not be hidden.
10415 Returns nil if no threads were there to be hidden."
10416   (interactive)
10417   (let ((buffer-read-only nil)
10418         (start (point))
10419         (article (gnus-summary-article-number)))
10420     (goto-char start)
10421     ;; Go forward until either the buffer ends or the subthread
10422     ;; ends.
10423     (when (and (not (eobp))
10424                (or (zerop (gnus-summary-next-thread 1 t))
10425                    (goto-char (point-max))))
10426       (prog1
10427           (if (and (> (point) start)
10428                    (search-backward "\n" start t))
10429               (progn
10430                 (subst-char-in-region start (point) ?\n ?\^M)
10431                 (gnus-summary-goto-subject article))
10432             (goto-char start)
10433             nil)))))
10434
10435 (defun gnus-summary-go-to-next-thread (&optional previous)
10436   "Go to the same level (or less) next thread.
10437 If PREVIOUS is non-nil, go to previous thread instead.
10438 Return the article number moved to, or nil if moving was impossible."
10439   (let ((level (gnus-summary-thread-level))
10440         (way (if previous -1 1))
10441         (beg (point)))
10442     (forward-line way)
10443     (while (and (not (eobp))
10444                 (< level (gnus-summary-thread-level)))
10445       (forward-line way))
10446     (if (eobp)
10447         (progn
10448           (goto-char beg)
10449           nil)
10450       (setq beg (point))
10451       (prog1
10452           (gnus-summary-article-number)
10453         (goto-char beg)))))
10454
10455 (defun gnus-summary-next-thread (n &optional silent)
10456   "Go to the same level next N'th thread.
10457 If N is negative, search backward instead.
10458 Returns the difference between N and the number of skips actually
10459 done.
10460
10461 If SILENT, don't output messages."
10462   (interactive "p")
10463   (let ((backward (< n 0))
10464         (n (abs n)))
10465     (while (and (> n 0)
10466                 (gnus-summary-go-to-next-thread backward))
10467       (decf n))
10468     (unless silent
10469       (gnus-summary-position-point))
10470     (when (and (not silent) (/= 0 n))
10471       (gnus-message 7 "No more threads"))
10472     n))
10473
10474 (defun gnus-summary-prev-thread (n)
10475   "Go to the same level previous N'th thread.
10476 Returns the difference between N and the number of skips actually
10477 done."
10478   (interactive "p")
10479   (gnus-summary-next-thread (- n)))
10480
10481 (defun gnus-summary-go-down-thread ()
10482   "Go down one level in the current thread."
10483   (let ((children (gnus-summary-article-children)))
10484     (when children
10485       (gnus-summary-goto-subject (car children)))))
10486
10487 (defun gnus-summary-go-up-thread ()
10488   "Go up one level in the current thread."
10489   (let ((parent (gnus-summary-article-parent)))
10490     (when parent
10491       (gnus-summary-goto-subject parent))))
10492
10493 (defun gnus-summary-down-thread (n)
10494   "Go down thread N steps.
10495 If N is negative, go up instead.
10496 Returns the difference between N and how many steps down that were
10497 taken."
10498   (interactive "p")
10499   (let ((up (< n 0))
10500         (n (abs n)))
10501     (while (and (> n 0)
10502                 (if up (gnus-summary-go-up-thread)
10503                   (gnus-summary-go-down-thread)))
10504       (setq n (1- n)))
10505     (gnus-summary-position-point)
10506     (when (/= 0 n)
10507       (gnus-message 7 "Can't go further"))
10508     n))
10509
10510 (defun gnus-summary-up-thread (n)
10511   "Go up thread N steps.
10512 If N is negative, go down instead.
10513 Returns the difference between N and how many steps down that were
10514 taken."
10515   (interactive "p")
10516   (gnus-summary-down-thread (- n)))
10517
10518 (defun gnus-summary-top-thread ()
10519   "Go to the top of the thread."
10520   (interactive)
10521   (while (gnus-summary-go-up-thread))
10522   (gnus-summary-article-number))
10523
10524 (defun gnus-summary-kill-thread (&optional unmark)
10525   "Mark articles under current thread as read.
10526 If the prefix argument is positive, remove any kinds of marks.
10527 If the prefix argument is negative, tick articles instead."
10528   (interactive "P")
10529   (when unmark
10530     (setq unmark (prefix-numeric-value unmark)))
10531   (let ((articles (gnus-summary-articles-in-thread)))
10532     (save-excursion
10533       ;; Expand the thread.
10534       (gnus-summary-show-thread)
10535       ;; Mark all the articles.
10536       (while articles
10537         (gnus-summary-goto-subject (car articles))
10538         (cond ((null unmark)
10539                (gnus-summary-mark-article-as-read gnus-killed-mark))
10540               ((> unmark 0)
10541                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10542               (t
10543                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10544         (setq articles (cdr articles))))
10545     ;; Hide killed subtrees.
10546     (and (null unmark)
10547          gnus-thread-hide-killed
10548          (gnus-summary-hide-thread))
10549     ;; If marked as read, go to next unread subject.
10550     (when (null unmark)
10551       ;; Go to next unread subject.
10552       (gnus-summary-next-subject 1 t)))
10553   (gnus-set-mode-line 'summary))
10554
10555 ;; Summary sorting commands
10556
10557 (defun gnus-summary-sort-by-number (&optional reverse)
10558   "Sort the summary buffer by article number.
10559 Argument REVERSE means reverse order."
10560   (interactive "P")
10561   (gnus-summary-sort 'number reverse))
10562
10563 (defun gnus-summary-sort-by-random (&optional reverse)
10564   "Randomize the order in the summary buffer.
10565 Argument REVERSE means to randomize in reverse order."
10566   (interactive "P")
10567   (gnus-summary-sort 'random reverse))
10568
10569 (defun gnus-summary-sort-by-author (&optional reverse)
10570   "Sort the summary buffer by author name alphabetically.
10571 If `case-fold-search' is non-nil, case of letters is ignored.
10572 Argument REVERSE means reverse order."
10573   (interactive "P")
10574   (gnus-summary-sort 'author reverse))
10575
10576 (defun gnus-summary-sort-by-subject (&optional reverse)
10577   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10578 If `case-fold-search' is non-nil, case of letters is ignored.
10579 Argument REVERSE means reverse order."
10580   (interactive "P")
10581   (gnus-summary-sort 'subject reverse))
10582
10583 (defun gnus-summary-sort-by-date (&optional reverse)
10584   "Sort the summary buffer by date.
10585 Argument REVERSE means reverse order."
10586   (interactive "P")
10587   (gnus-summary-sort 'date reverse))
10588
10589 (defun gnus-summary-sort-by-score (&optional reverse)
10590   "Sort the summary buffer by score.
10591 Argument REVERSE means reverse order."
10592   (interactive "P")
10593   (gnus-summary-sort 'score reverse))
10594
10595 (defun gnus-summary-sort-by-lines (&optional reverse)
10596   "Sort the summary buffer by the number of lines.
10597 Argument REVERSE means reverse order."
10598   (interactive "P")
10599   (gnus-summary-sort 'lines reverse))
10600
10601 (defun gnus-summary-sort-by-chars (&optional reverse)
10602   "Sort the summary buffer by article length.
10603 Argument REVERSE means reverse order."
10604   (interactive "P")
10605   (gnus-summary-sort 'chars reverse))
10606
10607 (defun gnus-summary-sort-by-original (&optional reverse)
10608   "Sort the summary buffer using the default sorting method.
10609 Argument REVERSE means reverse order."
10610   (interactive "P")
10611   (let* ((buffer-read-only)
10612          (gnus-summary-prepare-hook nil))
10613     ;; We do the sorting by regenerating the threads.
10614     (gnus-summary-prepare)
10615     ;; Hide subthreads if needed.
10616     (gnus-summary-maybe-hide-threads)))
10617
10618 (defun gnus-summary-sort (predicate reverse)
10619   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10620   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10621          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10622          (gnus-thread-sort-functions
10623           (if (not reverse)
10624               thread
10625             `(lambda (t1 t2)
10626                (,thread t2 t1))))
10627          (gnus-sort-gathered-threads-function
10628           gnus-thread-sort-functions)
10629          (gnus-article-sort-functions
10630           (if (not reverse)
10631               article
10632             `(lambda (t1 t2)
10633                (,article t2 t1))))
10634          (buffer-read-only)
10635          (gnus-summary-prepare-hook nil))
10636     ;; We do the sorting by regenerating the threads.
10637     (gnus-summary-prepare)
10638     ;; Hide subthreads if needed.
10639     (gnus-summary-maybe-hide-threads)))
10640
10641 ;; Summary saving commands.
10642
10643 (defun gnus-summary-save-article (&optional n not-saved)
10644   "Save the current article using the default saver function.
10645 If N is a positive number, save the N next articles.
10646 If N is a negative number, save the N previous articles.
10647 If N is nil and any articles have been marked with the process mark,
10648 save those articles instead.
10649 The variable `gnus-default-article-saver' specifies the saver function."
10650   (interactive "P")
10651   (let* ((articles (gnus-summary-work-articles n))
10652          (save-buffer (save-excursion
10653                         (nnheader-set-temp-buffer " *Gnus Save*")))
10654          (num (length articles))
10655          header file)
10656     (dolist (article articles)
10657       (setq header (gnus-summary-article-header article))
10658       (if (not (vectorp header))
10659           ;; This is a pseudo-article.
10660           (if (assq 'name header)
10661               (gnus-copy-file (cdr (assq 'name header)))
10662             (gnus-message 1 "Article %d is unsaveable" article))
10663         ;; This is a real article.
10664         (save-window-excursion
10665           (let ((gnus-display-mime-function nil)
10666                 (gnus-article-prepare-hook nil))
10667             (gnus-summary-select-article t nil nil article)))
10668         (save-excursion
10669           (set-buffer save-buffer)
10670           (erase-buffer)
10671           (insert-buffer-substring gnus-original-article-buffer))
10672         (setq file (gnus-article-save save-buffer file num))
10673         (gnus-summary-remove-process-mark article)
10674         (unless not-saved
10675           (gnus-summary-set-saved-mark article))))
10676     (gnus-kill-buffer save-buffer)
10677     (gnus-summary-position-point)
10678     (gnus-set-mode-line 'summary)
10679     n))
10680
10681 (defun gnus-summary-pipe-output (&optional arg headers)
10682   "Pipe the current article to a subprocess.
10683 If N is a positive number, pipe the N next articles.
10684 If N is a negative number, pipe the N previous articles.
10685 If N is nil and any articles have been marked with the process mark,
10686 pipe those articles instead.
10687 If HEADERS (the symbolic prefix), include the headers, too."
10688   (interactive (gnus-interactive "P\ny"))
10689   (require 'gnus-art)
10690   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10691         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10692     (gnus-summary-save-article arg t))
10693   (let ((buffer (get-buffer "*Shell Command Output*")))
10694     (when (and buffer
10695                (not (zerop (buffer-size buffer))))
10696       (gnus-configure-windows 'pipe))))
10697
10698 (defun gnus-summary-save-article-mail (&optional arg)
10699   "Append the current article to an mail file.
10700 If N is a positive number, save the N next articles.
10701 If N is a negative number, save the N previous articles.
10702 If N is nil and any articles have been marked with the process mark,
10703 save those articles instead."
10704   (interactive "P")
10705   (require 'gnus-art)
10706   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10707     (gnus-summary-save-article arg)))
10708
10709 (defun gnus-summary-save-article-rmail (&optional arg)
10710   "Append the current article to an rmail file.
10711 If N is a positive number, save the N next articles.
10712 If N is a negative number, save the N previous articles.
10713 If N is nil and any articles have been marked with the process mark,
10714 save those articles instead."
10715   (interactive "P")
10716   (require 'gnus-art)
10717   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10718     (gnus-summary-save-article arg)))
10719
10720 (defun gnus-summary-save-article-file (&optional arg)
10721   "Append the current article to a file.
10722 If N is a positive number, save the N next articles.
10723 If N is a negative number, save the N previous articles.
10724 If N is nil and any articles have been marked with the process mark,
10725 save those articles instead."
10726   (interactive "P")
10727   (require 'gnus-art)
10728   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10729     (gnus-summary-save-article arg)))
10730
10731 (defun gnus-summary-write-article-file (&optional arg)
10732   "Write the current article to a file, deleting the previous file.
10733 If N is a positive number, save the N next articles.
10734 If N is a negative number, save the N previous articles.
10735 If N is nil and any articles have been marked with the process mark,
10736 save those articles instead."
10737   (interactive "P")
10738   (require 'gnus-art)
10739   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10740     (gnus-summary-save-article arg)))
10741
10742 (defun gnus-summary-save-article-body-file (&optional arg)
10743   "Append the current article body to a file.
10744 If N is a positive number, save the N next articles.
10745 If N is a negative number, save the N previous articles.
10746 If N is nil and any articles have been marked with the process mark,
10747 save those articles instead."
10748   (interactive "P")
10749   (require 'gnus-art)
10750   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10751     (gnus-summary-save-article arg)))
10752
10753 (defun gnus-summary-muttprint (&optional arg)
10754   "Print the current article using Muttprint.
10755 If N is a positive number, save the N next articles.
10756 If N is a negative number, save the N previous articles.
10757 If N is nil and any articles have been marked with the process mark,
10758 save those articles instead."
10759   (interactive "P")
10760   (require 'gnus-art)
10761   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10762     (gnus-summary-save-article arg t)))
10763
10764 (defun gnus-summary-pipe-message (program)
10765   "Pipe the current article through PROGRAM."
10766   (interactive "sProgram: ")
10767   (gnus-summary-select-article)
10768   (let ((mail-header-separator ""))
10769     (gnus-eval-in-buffer-window gnus-article-buffer
10770       (save-restriction
10771         (widen)
10772         (let ((start (window-start))
10773               buffer-read-only)
10774           (message-pipe-buffer-body program)
10775           (set-window-start (get-buffer-window (current-buffer)) start))))))
10776
10777 (defun gnus-get-split-value (methods)
10778   "Return a value based on the split METHODS."
10779   (let (split-name method result match)
10780     (when methods
10781       (save-excursion
10782         (set-buffer gnus-original-article-buffer)
10783         (save-restriction
10784           (nnheader-narrow-to-headers)
10785           (while (and methods (not split-name))
10786             (goto-char (point-min))
10787             (setq method (pop methods))
10788             (setq match (car method))
10789             (when (cond
10790                    ((stringp match)
10791                     ;; Regular expression.
10792                     (ignore-errors
10793                       (re-search-forward match nil t)))
10794                    ((gnus-functionp match)
10795                     ;; Function.
10796                     (save-restriction
10797                       (widen)
10798                       (setq result (funcall match gnus-newsgroup-name))))
10799                    ((consp match)
10800                     ;; Form.
10801                     (save-restriction
10802                       (widen)
10803                       (setq result (eval match)))))
10804               (setq split-name (cdr method))
10805               (cond ((stringp result)
10806                      (push (expand-file-name
10807                             result gnus-article-save-directory)
10808                            split-name))
10809                     ((consp result)
10810                      (setq split-name (append result split-name)))))))))
10811     (nreverse split-name)))
10812
10813 (defun gnus-valid-move-group-p (group)
10814   (and (boundp group)
10815        (symbol-name group)
10816        (symbol-value group)
10817        (gnus-get-function (gnus-find-method-for-group
10818                            (symbol-name group)) 'request-accept-article t)))
10819
10820 (defun gnus-read-move-group-name (prompt default articles prefix)
10821   "Read a group name."
10822   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10823          (minibuffer-confirm-incomplete nil) ; XEmacs
10824          (prom
10825           (format "%s %s to:"
10826                   prompt
10827                   (if (> (length articles) 1)
10828                       (format "these %d articles" (length articles))
10829                     "this article")))
10830          (to-newsgroup
10831           (cond
10832            ((null split-name)
10833             (gnus-completing-read-with-default
10834              default prom
10835              gnus-active-hashtb
10836              'gnus-valid-move-group-p
10837              nil prefix
10838              'gnus-group-history))
10839            ((= 1 (length split-name))
10840             (gnus-completing-read-with-default
10841              (car split-name) prom
10842              gnus-active-hashtb
10843              'gnus-valid-move-group-p
10844              nil nil
10845              'gnus-group-history))
10846            (t
10847             (gnus-completing-read-with-default
10848              nil prom
10849              (mapcar (lambda (el) (list el))
10850                      (nreverse split-name))
10851              nil nil nil
10852              'gnus-group-history))))
10853          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10854     (when to-newsgroup
10855       (if (or (string= to-newsgroup "")
10856               (string= to-newsgroup prefix))
10857           (setq to-newsgroup default))
10858       (unless to-newsgroup
10859         (error "No group name entered"))
10860       (or (gnus-active to-newsgroup)
10861           (gnus-activate-group to-newsgroup nil nil to-method)
10862           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10863                                      to-newsgroup))
10864               (or (and (gnus-request-create-group to-newsgroup to-method)
10865                        (gnus-activate-group
10866                         to-newsgroup nil nil to-method)
10867                        (gnus-subscribe-group to-newsgroup))
10868                   (error "Couldn't create group %s" to-newsgroup)))
10869           (error "No such group: %s" to-newsgroup)))
10870     to-newsgroup))
10871
10872 (defun gnus-summary-save-parts (type dir n &optional reverse)
10873   "Save parts matching TYPE to DIR.
10874 If REVERSE, save parts that do not match TYPE."
10875   (interactive
10876    (list (read-string "Save parts of type: "
10877                       (or (car gnus-summary-save-parts-type-history)
10878                           gnus-summary-save-parts-default-mime)
10879                       'gnus-summary-save-parts-type-history)
10880          (setq gnus-summary-save-parts-last-directory
10881                (read-file-name "Save to directory: "
10882                                gnus-summary-save-parts-last-directory
10883                                nil t))
10884          current-prefix-arg))
10885   (gnus-summary-iterate n
10886     (let ((gnus-display-mime-function nil)
10887           (gnus-inhibit-treatment t))
10888       (gnus-summary-select-article))
10889     (save-excursion
10890       (set-buffer gnus-article-buffer)
10891       (let ((handles (or gnus-article-mime-handles
10892                          (mm-dissect-buffer nil gnus-article-loose-mime)
10893                          (and gnus-article-emulate-mime
10894                               (mm-uu-dissect)))))
10895         (when handles
10896           (gnus-summary-save-parts-1 type dir handles reverse)
10897           (unless gnus-article-mime-handles ;; Don't destroy this case.
10898             (mm-destroy-parts handles)))))))
10899
10900 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10901   (if (stringp (car handle))
10902       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10903               (cdr handle))
10904     (when (if reverse
10905               (not (string-match type (mm-handle-media-type handle)))
10906             (string-match type (mm-handle-media-type handle)))
10907       (let ((file (expand-file-name
10908                    (file-name-nondirectory
10909                     (or
10910                      (mail-content-type-get
10911                       (mm-handle-disposition handle) 'filename)
10912                      (concat gnus-newsgroup-name
10913                              "." (number-to-string
10914                                   (cdr gnus-article-current)))))
10915                    dir)))
10916         (unless (file-exists-p file)
10917           (mm-save-part-to-file handle file))))))
10918
10919 ;; Summary extract commands
10920
10921 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10922   (let ((buffer-read-only nil)
10923         (article (gnus-summary-article-number))
10924         after-article b e)
10925     (unless (gnus-summary-goto-subject article)
10926       (error "No such article: %d" article))
10927     (gnus-summary-position-point)
10928     ;; If all commands are to be bunched up on one line, we collect
10929     ;; them here.
10930     (unless gnus-view-pseudos-separately
10931       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10932             files action)
10933         (while ps
10934           (setq action (cdr (assq 'action (car ps))))
10935           (setq files (list (cdr (assq 'name (car ps)))))
10936           (while (and ps (cdr ps)
10937                       (string= (or action "1")
10938                                (or (cdr (assq 'action (cadr ps))) "2")))
10939             (push (cdr (assq 'name (cadr ps))) files)
10940             (setcdr ps (cddr ps)))
10941           (when files
10942             (when (not (string-match "%s" action))
10943               (push " " files))
10944             (push " " files)
10945             (when (assq 'execute (car ps))
10946               (setcdr (assq 'execute (car ps))
10947                       (funcall (if (string-match "%s" action)
10948                                    'format 'concat)
10949                                action
10950                                (mapconcat
10951                                 (lambda (f)
10952                                   (if (equal f " ")
10953                                       f
10954                                     (mm-quote-arg f)))
10955                                 files " ")))))
10956           (setq ps (cdr ps)))))
10957     (if (and gnus-view-pseudos (not not-view))
10958         (while pslist
10959           (when (assq 'execute (car pslist))
10960             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10961                                   (eq gnus-view-pseudos 'not-confirm)))
10962           (setq pslist (cdr pslist)))
10963       (save-excursion
10964         (while pslist
10965           (setq after-article (or (cdr (assq 'article (car pslist)))
10966                                   (gnus-summary-article-number)))
10967           (gnus-summary-goto-subject after-article)
10968           (forward-line 1)
10969           (setq b (point))
10970           (insert "    " (file-name-nondirectory
10971                           (cdr (assq 'name (car pslist))))
10972                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10973           (setq e (point))
10974           (forward-line -1)             ; back to `b'
10975           (gnus-add-text-properties
10976            b (1- e) (list 'gnus-number gnus-reffed-article-number
10977                           gnus-mouse-face-prop gnus-mouse-face))
10978           (gnus-data-enter
10979            after-article gnus-reffed-article-number
10980            gnus-unread-mark b (car pslist) 0 (- e b))
10981           (setq gnus-newsgroup-unreads
10982                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10983                                          gnus-reffed-article-number))
10984           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10985           (setq pslist (cdr pslist)))))))
10986
10987 (defun gnus-pseudos< (p1 p2)
10988   (let ((c1 (cdr (assq 'action p1)))
10989         (c2 (cdr (assq 'action p2))))
10990     (and c1 c2 (string< c1 c2))))
10991
10992 (defun gnus-request-pseudo-article (props)
10993   (cond ((assq 'execute props)
10994          (gnus-execute-command (cdr (assq 'execute props)))))
10995   (let ((gnus-current-article (gnus-summary-article-number)))
10996     (gnus-run-hooks 'gnus-mark-article-hook)))
10997
10998 (defun gnus-execute-command (command &optional automatic)
10999   (save-excursion
11000     (gnus-article-setup-buffer)
11001     (set-buffer gnus-article-buffer)
11002     (setq buffer-read-only nil)
11003     (let ((command (if automatic command
11004                      (read-string "Command: " (cons command 0)))))
11005       (erase-buffer)
11006       (insert "$ " command "\n\n")
11007       (if gnus-view-pseudo-asynchronously
11008           (start-process "gnus-execute" (current-buffer) shell-file-name
11009                          shell-command-switch command)
11010         (call-process shell-file-name nil t nil
11011                       shell-command-switch command)))))
11012
11013 ;; Summary kill commands.
11014
11015 (defun gnus-summary-edit-global-kill (article)
11016   "Edit the \"global\" kill file."
11017   (interactive (list (gnus-summary-article-number)))
11018   (gnus-group-edit-global-kill article))
11019
11020 (defun gnus-summary-edit-local-kill ()
11021   "Edit a local kill file applied to the current newsgroup."
11022   (interactive)
11023   (setq gnus-current-headers (gnus-summary-article-header))
11024   (gnus-group-edit-local-kill
11025    (gnus-summary-article-number) gnus-newsgroup-name))
11026
11027 ;;; Header reading.
11028
11029 (defun gnus-read-header (id &optional header)
11030   "Read the headers of article ID and enter them into the Gnus system."
11031   (let ((group gnus-newsgroup-name)
11032         (gnus-override-method
11033          (or
11034           gnus-override-method
11035           (and (gnus-news-group-p gnus-newsgroup-name)
11036                (car (gnus-refer-article-methods)))))
11037         where)
11038     ;; First we check to see whether the header in question is already
11039     ;; fetched.
11040     (if (stringp id)
11041         ;; This is a Message-ID.
11042         (setq header (or header (gnus-id-to-header id)))
11043       ;; This is an article number.
11044       (setq header (or header (gnus-summary-article-header id))))
11045     (if (and header
11046              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11047         ;; We have found the header.
11048         header
11049       ;; If this is a sparse article, we have to nix out its
11050       ;; previous entry in the thread hashtb.
11051       (when (and header
11052                  (gnus-summary-article-sparse-p (mail-header-number header)))
11053         (let* ((parent (gnus-parent-id (mail-header-references header)))
11054                (thread (and parent (gnus-id-to-thread parent))))
11055           (when thread
11056             (delq (assq header thread) thread))))
11057       ;; We have to really fetch the header to this article.
11058       (save-excursion
11059         (set-buffer nntp-server-buffer)
11060         (when (setq where (gnus-request-head id group))
11061           (nnheader-fold-continuation-lines)
11062           (goto-char (point-max))
11063           (insert ".\n")
11064           (goto-char (point-min))
11065           (insert "211 ")
11066           (princ (cond
11067                   ((numberp id) id)
11068                   ((cdr where) (cdr where))
11069                   (header (mail-header-number header))
11070                   (t gnus-reffed-article-number))
11071                  (current-buffer))
11072           (insert " Article retrieved.\n"))
11073         (if (or (not where)
11074                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11075             ()                          ; Malformed head.
11076           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11077             (when (and (stringp id)
11078                        (not (string= (gnus-group-real-name group)
11079                                      (car where))))
11080               ;; If we fetched by Message-ID and the article came
11081               ;; from a different group, we fudge some bogus article
11082               ;; numbers for this article.
11083               (mail-header-set-number header gnus-reffed-article-number))
11084             (save-excursion
11085               (set-buffer gnus-summary-buffer)
11086               (decf gnus-reffed-article-number)
11087               (gnus-remove-header (mail-header-number header))
11088               (push header gnus-newsgroup-headers)
11089               (setq gnus-current-headers header)
11090               (push (mail-header-number header) gnus-newsgroup-limit)))
11091           header)))))
11092
11093 (defun gnus-remove-header (number)
11094   "Remove header NUMBER from `gnus-newsgroup-headers'."
11095   (if (and gnus-newsgroup-headers
11096            (= number (mail-header-number (car gnus-newsgroup-headers))))
11097       (pop gnus-newsgroup-headers)
11098     (let ((headers gnus-newsgroup-headers))
11099       (while (and (cdr headers)
11100                   (not (= number (mail-header-number (cadr headers)))))
11101         (pop headers))
11102       (when (cdr headers)
11103         (setcdr headers (cddr headers))))))
11104
11105 ;;;
11106 ;;; summary highlights
11107 ;;;
11108
11109 (defun gnus-highlight-selected-summary ()
11110   "Highlight selected article in summary buffer."
11111   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11112   (when gnus-summary-selected-face
11113     (save-excursion
11114       (let* ((beg (gnus-point-at-bol))
11115              (end (gnus-point-at-eol))
11116              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11117              (from (if (get-text-property beg gnus-mouse-face-prop)
11118                        beg
11119                      (or (next-single-property-change
11120                           beg gnus-mouse-face-prop nil end)
11121                          beg)))
11122              (to
11123               (if (= from end)
11124                   (- from 2)
11125                 (or (next-single-property-change
11126                      from gnus-mouse-face-prop nil end)
11127                     end))))
11128         ;; If no mouse-face prop on line we will have to = from = end,
11129         ;; so we highlight the entire line instead.
11130         (when (= (+ to 2) from)
11131           (setq from beg)
11132           (setq to end))
11133         (if gnus-newsgroup-selected-overlay
11134             ;; Move old overlay.
11135             (gnus-move-overlay
11136              gnus-newsgroup-selected-overlay from to (current-buffer))
11137           ;; Create new overlay.
11138           (gnus-overlay-put
11139            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11140            'face gnus-summary-selected-face))))))
11141
11142 (defvar gnus-summary-highlight-line-cached nil)
11143 (defvar gnus-summary-highlight-line-trigger nil)
11144
11145 (defun gnus-summary-highlight-line-0 ()
11146   (if (and (eq gnus-summary-highlight-line-trigger 
11147                gnus-summary-highlight)
11148            gnus-summary-highlight-line-cached)
11149       gnus-summary-highlight-line-cached
11150     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11151           gnus-summary-highlight-line-cached
11152           (let* ((cond (list 'cond))
11153                  (c cond)
11154                  (list gnus-summary-highlight))
11155             (while list
11156               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11157                               nil))
11158               (setq c (cdr c)
11159                     list (cdr list)))
11160             (gnus-byte-compile (list 'lambda nil cond))))))
11161
11162 (defun gnus-summary-highlight-line ()
11163   "Highlight current line according to `gnus-summary-highlight'."
11164   (let* ((beg (gnus-point-at-bol))
11165          (article (or (gnus-summary-article-number) gnus-current-article))
11166          (score (or (cdr (assq article
11167                                gnus-newsgroup-scored))
11168                     gnus-summary-default-score 0))
11169          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11170          (inhibit-read-only t)
11171          (default gnus-summary-default-score)
11172          (default-high gnus-summary-default-high-score)
11173          (default-low gnus-summary-default-low-score)
11174          (uncached (memq article gnus-newsgroup-undownloaded))
11175          (downloaded (not uncached)))
11176     (let ((face (funcall (gnus-summary-highlight-line-0))))
11177       (unless (eq face (get-text-property beg 'face))
11178         (gnus-put-text-property-excluding-characters-with-faces
11179          beg (gnus-point-at-eol) 'face
11180          (setq face (if (boundp face) (symbol-value face) face)))
11181         (when gnus-summary-highlight-line-function
11182           (funcall gnus-summary-highlight-line-function article face))))))
11183
11184 (defun gnus-update-read-articles (group unread &optional compute)
11185   "Update the list of read articles in GROUP.
11186 UNREAD is a sorted list."
11187   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
11188          (entry (gnus-gethash group gnus-newsrc-hashtb))
11189          (info (nth 2 entry))
11190          (prev 1)
11191          read)
11192     (if (or (not info) (not active))
11193         ;; There is no info on this group if it was, in fact,
11194         ;; killed.  Gnus stores no information on killed groups, so
11195         ;; there's nothing to be done.
11196         ;; One could store the information somewhere temporarily,
11197         ;; perhaps...  Hmmm...
11198         ()
11199       ;; Remove any negative articles numbers.
11200       (while (and unread (< (car unread) 0))
11201         (setq unread (cdr unread)))
11202       ;; Remove any expired article numbers
11203       (while (and unread (< (car unread) (car active)))
11204         (setq unread (cdr unread)))
11205       ;; Compute the ranges of read articles by looking at the list of
11206       ;; unread articles.
11207       (while unread
11208         (when (/= (car unread) prev)
11209           (push (if (= prev (1- (car unread))) prev
11210                   (cons prev (1- (car unread))))
11211                 read))
11212         (setq prev (1+ (car unread)))
11213         (setq unread (cdr unread)))
11214       (when (<= prev (cdr active))
11215         (push (cons prev (cdr active)) read))
11216       (setq read (if (> (length read) 1) (nreverse read) read))
11217       (if compute
11218           read
11219         (save-excursion
11220           (let (setmarkundo)
11221             ;; Propagate the read marks to the backend.
11222             (when (gnus-check-backend-function 'request-set-mark group)
11223               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11224                     (add (gnus-remove-from-range read (gnus-info-read info))))
11225                 (when (or add del)
11226                   (unless (gnus-check-group group)
11227                     (error "Can't open server for %s" group))
11228                   (gnus-request-set-mark
11229                    group (delq nil (list (if add (list add 'add '(read)))
11230                                          (if del (list del 'del '(read))))))
11231                   (setq setmarkundo
11232                         `(gnus-request-set-mark
11233                           ,group
11234                           ',(delq nil (list
11235                                        (if del (list del 'add '(read)))
11236                                        (if add (list add 'del '(read))))))))))
11237             (set-buffer gnus-group-buffer)
11238             (gnus-undo-register
11239               `(progn
11240                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11241                  (gnus-info-set-read ',info ',(gnus-info-read info))
11242                  (gnus-get-unread-articles-in-group ',info
11243                                                     (gnus-active ,group))
11244                  (gnus-group-update-group ,group t)
11245                  ,setmarkundo))))
11246         ;; Enter this list into the group info.
11247         (gnus-info-set-read info read)
11248         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11249         (gnus-get-unread-articles-in-group info (gnus-active group))
11250         t))))
11251
11252 (defun gnus-offer-save-summaries ()
11253   "Offer to save all active summary buffers."
11254   (let (buffers)
11255     ;; Go through all buffers and find all summaries.
11256     (dolist (buffer (buffer-list))
11257       (when (and (setq buffer (buffer-name buffer))
11258                  (string-match "Summary" buffer)
11259                  (save-excursion
11260                    (set-buffer buffer)
11261                    ;; We check that this is, indeed, a summary buffer.
11262                    (and (eq major-mode 'gnus-summary-mode)
11263                         ;; Also make sure this isn't bogus.
11264                         gnus-newsgroup-prepared
11265                         ;; Also make sure that this isn't a
11266                         ;; dead summary buffer.
11267                         (not gnus-dead-summary-mode))))
11268         (push buffer buffers)))
11269     ;; Go through all these summary buffers and offer to save them.
11270     (when buffers
11271       (save-excursion
11272         (map-y-or-n-p
11273          "Update summary buffer %s? "
11274          (lambda (buf)
11275            (switch-to-buffer buf)
11276            (gnus-summary-exit))
11277          buffers)))))
11278
11279 (defun gnus-summary-setup-default-charset ()
11280   "Setup newsgroup default charset."
11281   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11282       (setq gnus-newsgroup-charset nil)
11283     (let* ((ignored-charsets
11284             (or gnus-newsgroup-ephemeral-ignored-charsets
11285                 (append
11286                  (and gnus-newsgroup-name
11287                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11288                  gnus-newsgroup-ignored-charsets))))
11289       (setq gnus-newsgroup-charset
11290             (or gnus-newsgroup-ephemeral-charset
11291                 (and gnus-newsgroup-name
11292                      (gnus-parameter-charset gnus-newsgroup-name))
11293                 gnus-default-charset))
11294       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11295            ignored-charsets))))
11296
11297 ;;;
11298 ;;; Mime Commands
11299 ;;;
11300
11301 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11302   "Display the current article buffer fully MIME-buttonized.
11303 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11304 treated as multipart/mixed."
11305   (interactive "P")
11306   (require 'gnus-art)
11307   (let ((gnus-unbuttonized-mime-types nil)
11308         (gnus-mime-display-multipart-as-mixed show-all-parts))
11309     (gnus-summary-show-article)))
11310
11311 (defun gnus-summary-repair-multipart (article)
11312   "Add a Content-Type header to a multipart article without one."
11313   (interactive (list (gnus-summary-article-number)))
11314   (gnus-with-article article
11315     (message-narrow-to-head)
11316     (message-remove-header "Mime-Version")
11317     (goto-char (point-max))
11318     (insert "Mime-Version: 1.0\n")
11319     (widen)
11320     (when (search-forward "\n--" nil t)
11321       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11322         (message-narrow-to-head)
11323         (message-remove-header "Content-Type")
11324         (goto-char (point-max))
11325         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11326                         separator))
11327         (widen))))
11328   (let (gnus-mark-article-hook)
11329     (gnus-summary-select-article t t nil article)))
11330
11331 (defun gnus-summary-toggle-display-buttonized ()
11332   "Toggle the buttonizing of the article buffer."
11333   (interactive)
11334   (require 'gnus-art)
11335   (if (setq gnus-inhibit-mime-unbuttonizing
11336             (not gnus-inhibit-mime-unbuttonizing))
11337       (let ((gnus-unbuttonized-mime-types nil))
11338         (gnus-summary-show-article))
11339     (gnus-summary-show-article)))
11340
11341 ;;;
11342 ;;; Generic summary marking commands
11343 ;;;
11344
11345 (defvar gnus-summary-marking-alist
11346   '((read gnus-del-mark "d")
11347     (unread gnus-unread-mark "u")
11348     (ticked gnus-ticked-mark "!")
11349     (dormant gnus-dormant-mark "?")
11350     (expirable gnus-expirable-mark "e"))
11351   "An alist of names/marks/keystrokes.")
11352
11353 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11354 (defvar gnus-summary-mark-map)
11355
11356 (defun gnus-summary-make-all-marking-commands ()
11357   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11358   (dolist (elem gnus-summary-marking-alist)
11359     (apply 'gnus-summary-make-marking-command elem)))
11360
11361 (defun gnus-summary-make-marking-command (name mark keystroke)
11362   (let ((map (make-sparse-keymap)))
11363     (define-key gnus-summary-generic-mark-map keystroke map)
11364     (dolist (lway `((next "next" next nil "n")
11365                     (next-unread "next unread" next t "N")
11366                     (prev "previous" prev nil "p")
11367                     (prev-unread "previous unread" prev t "P")
11368                     (nomove "" nil nil ,keystroke)))
11369       (let ((func (gnus-summary-make-marking-command-1
11370                    mark (car lway) lway name)))
11371         (setq func (eval func))
11372         (define-key map (nth 4 lway) func)))))
11373
11374 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11375   `(defun ,(intern
11376             (format "gnus-summary-put-mark-as-%s%s"
11377                     name (if (eq way 'nomove)
11378                              ""
11379                            (concat "-" (symbol-name way)))))
11380      (n)
11381      ,(format
11382        "Mark the current article as %s%s.
11383 If N, the prefix, then repeat N times.
11384 If N is negative, move in reverse order.
11385 The difference between N and the actual number of articles marked is
11386 returned."
11387        name (cadr lway))
11388      (interactive "p")
11389      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11390
11391 (defun gnus-summary-generic-mark (n mark move unread)
11392   "Mark N articles with MARK."
11393   (unless (eq major-mode 'gnus-summary-mode)
11394     (error "This command can only be used in the summary buffer"))
11395   (gnus-summary-show-thread)
11396   (let ((nummove
11397          (cond
11398           ((eq move 'next) 1)
11399           ((eq move 'prev) -1)
11400           (t 0))))
11401     (if (zerop nummove)
11402         (setq n 1)
11403       (when (< n 0)
11404         (setq n (abs n)
11405               nummove (* -1 nummove))))
11406     (while (and (> n 0)
11407                 (gnus-summary-mark-article nil mark)
11408                 (zerop (gnus-summary-next-subject nummove unread t)))
11409       (setq n (1- n)))
11410     (when (/= 0 n)
11411       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11412     (gnus-summary-recenter)
11413     (gnus-summary-position-point)
11414     (gnus-set-mode-line 'summary)
11415     n))
11416
11417 (defun gnus-summary-insert-articles (articles)
11418   (when (setq articles
11419               (gnus-sorted-difference articles
11420                                       (mapcar (lambda (h)
11421                                                 (mail-header-number h))
11422                                               gnus-newsgroup-headers)))
11423     (setq gnus-newsgroup-headers
11424           (merge 'list
11425                  gnus-newsgroup-headers
11426                  (gnus-fetch-headers articles)
11427                  'gnus-article-sort-by-number))
11428     ;; Suppress duplicates?
11429     (when gnus-suppress-duplicates
11430       (gnus-dup-suppress-articles))
11431
11432     ;; We might want to build some more threads first.
11433     (when (and gnus-fetch-old-headers
11434                (eq gnus-headers-retrieved-by 'nov))
11435       (if (eq gnus-fetch-old-headers 'invisible)
11436           (gnus-build-all-threads)
11437         (gnus-build-old-threads)))
11438     ;; Let the Gnus agent mark articles as read.
11439     (when gnus-agent
11440       (gnus-agent-get-undownloaded-list))
11441     ;; Remove list identifiers from subject
11442     (when gnus-list-identifiers
11443       (gnus-summary-remove-list-identifiers))
11444     ;; First and last article in this newsgroup.
11445     (when gnus-newsgroup-headers
11446       (setq gnus-newsgroup-begin
11447             (mail-header-number (car gnus-newsgroup-headers))
11448             gnus-newsgroup-end
11449             (mail-header-number
11450              (gnus-last-element gnus-newsgroup-headers))))
11451     (when gnus-use-scoring
11452       (gnus-possibly-score-headers))))
11453
11454 (defun gnus-summary-insert-old-articles (&optional all)
11455   "Insert all old articles in this group.
11456 If ALL is non-nil, already read articles become readable.
11457 If ALL is a number, fetch this number of articles."
11458   (interactive "P")
11459   (prog1
11460       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11461             older len)
11462         (setq older
11463               ;; Some nntp servers lie about their active range.  When
11464               ;; this happens, the active range can be in the millions.
11465               ;; Use a compressed range to avoid creating a huge list.
11466               (gnus-range-difference (list gnus-newsgroup-active) old))
11467         (setq len (gnus-range-length older))
11468         (cond
11469          ((null older) nil)
11470          ((numberp all)
11471           (if (< all len)
11472               (let ((older-range (nreverse older)))
11473                 (setq older nil)
11474
11475                 (while (> all 0)
11476                   (let* ((r (pop older-range))
11477                          (min (if (numberp r) r (car r)))
11478                          (max (if (numberp r) r (cdr r))))
11479                     (while (and (<= min max)
11480                                 (> all 0))
11481                       (push max older)
11482                       (setq all (1- all)
11483                             max (1- max))))))
11484             (setq older (gnus-uncompress-range older))))
11485          (all
11486           (setq older (gnus-uncompress-range older)))
11487          (t
11488           (when (and (numberp gnus-large-newsgroup)
11489                    (> len gnus-large-newsgroup))
11490               (let* ((cursor-in-echo-area nil)
11491                      (initial (gnus-parameter-large-newsgroup-initial
11492                                gnus-newsgroup-name))
11493                      (input
11494                       (read-string
11495                        (format
11496                         "How many articles from %s (%s %d): "
11497                         (gnus-limit-string
11498                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11499                         (if initial "max" "default")
11500                         len)
11501                        (if initial
11502                            (cons (number-to-string initial)
11503                                  0)))))
11504                 (unless (string-match "^[ \t]*$" input)
11505                   (setq all (string-to-number input))
11506                   (if (< all len)
11507                       (let ((older-range (nreverse older)))
11508                         (setq older nil)
11509
11510                         (while (> all 0)
11511                           (let* ((r (pop older-range))
11512                                  (min (if (numberp r) r (car r)))
11513                                  (max (if (numberp r) r (cdr r))))
11514                             (while (and (<= min max)
11515                                         (> all 0))
11516                               (push max older)
11517                               (setq all (1- all)
11518                                     max (1- max))))))))))
11519           (setq older (gnus-uncompress-range older))))
11520         (if (not older)
11521             (message "No old news.")
11522           (gnus-summary-insert-articles older)
11523           (gnus-summary-limit (gnus-sorted-nunion old older))))
11524     (gnus-summary-position-point)))
11525
11526 (defun gnus-summary-insert-new-articles ()
11527   "Insert all new articles in this group."
11528   (interactive)
11529   (prog1
11530       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11531             (old-active gnus-newsgroup-active)
11532             (nnmail-fetched-sources (list t))
11533             i new)
11534         (setq gnus-newsgroup-active
11535               (gnus-activate-group gnus-newsgroup-name 'scan))
11536         (setq i (cdr gnus-newsgroup-active))
11537         (while (> i (cdr old-active))
11538           (push i new)
11539           (decf i))
11540         (if (not new)
11541             (message "No gnus is bad news.")
11542           (gnus-summary-insert-articles new)
11543           (setq gnus-newsgroup-unreads
11544                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11545           (gnus-summary-limit (gnus-sorted-nunion old new))))
11546     (gnus-summary-position-point)))
11547
11548 (gnus-summary-make-all-marking-commands)
11549
11550 (gnus-ems-redefine)
11551
11552 (provide 'gnus-sum)
11553
11554 (run-hooks 'gnus-sum-load-hook)
11555
11556 ;;; gnus-sum.el ends here