3cdf51e42e4cee905c92b76201aa5e2793ea48f7
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'gnus-clfns))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'nnoo)
42 (require 'mime-view)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
55 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
56 (autoload 'mm-uu-dissect "mm-uu")
57 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
58   "Deuglify broken Outlook (Express) articles and redisplay."
59   t)
60 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
61 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
62 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
63
64 (defcustom gnus-kill-summary-on-exit t
65   "*If non-nil, kill the summary buffer when you exit from it.
66 If nil, the summary will become a \"*Dead Summary*\" buffer, and
67 it will be killed sometime later."
68   :group 'gnus-summary-exit
69   :type 'boolean)
70
71 (defcustom gnus-fetch-old-headers nil
72   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
73 If an unread article in the group refers to an older, already read (or
74 just marked as read) article, the old article will not normally be
75 displayed in the Summary buffer.  If this variable is non-nil, Gnus
76 will attempt to grab the headers to the old articles, and thereby
77 build complete threads.  If it has the value `some', only enough
78 headers to connect otherwise loose threads will be displayed.  This
79 variable can also be a number.  In that case, no more than that number
80 of old headers will be fetched.  If it has the value `invisible', all
81 old headers will be fetched, but none will be displayed.
82
83 The server has to support NOV for any of this to work."
84   :group 'gnus-thread
85   :type '(choice (const :tag "off" nil)
86                  (const some)
87                  number
88                  (sexp :menu-tag "other" t)))
89
90 (defcustom gnus-refer-thread-limit 200
91   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
92 If t, fetch all the available old headers."
93   :group 'gnus-thread
94   :type '(choice number
95                  (sexp :menu-tag "other" t)))
96
97 (defcustom gnus-summary-make-false-root 'adopt
98   "*nil means that Gnus won't gather loose threads.
99 If the root of a thread has expired or been read in a previous
100 session, the information necessary to build a complete thread has been
101 lost.  Instead of having many small sub-threads from this original thread
102 scattered all over the summary buffer, Gnus can gather them.
103
104 If non-nil, Gnus will try to gather all loose sub-threads from an
105 original thread into one large thread.
106
107 If this variable is non-nil, it should be one of `none', `adopt',
108 `dummy' or `empty'.
109
110 If this variable is `none', Gnus will not make a false root, but just
111 present the sub-threads after another.
112 If this variable is `dummy', Gnus will create a dummy root that will
113 have all the sub-threads as children.
114 If this variable is `adopt', Gnus will make one of the \"children\"
115 the parent and mark all the step-children as such.
116 If this variable is `empty', the \"children\" are printed with empty
117 subject fields.  (Or rather, they will be printed with a string
118 given by the `gnus-summary-same-subject' variable.)"
119   :group 'gnus-thread
120   :type '(choice (const :tag "off" nil)
121                  (const none)
122                  (const dummy)
123                  (const adopt)
124                  (const empty)))
125
126 (defcustom gnus-summary-make-false-root-always nil
127   "Always make a false dummy root."
128   :group 'gnus-thread
129   :type 'boolean)
130
131 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
132   "*A regexp to match subjects to be excluded from loose thread gathering.
133 As loose thread gathering is done on subjects only, that means that
134 there can be many false gatherings performed.  By rooting out certain
135 common subjects, gathering might become saner."
136   :group 'gnus-thread
137   :type 'regexp)
138
139 (defcustom gnus-summary-gather-subject-limit nil
140   "*Maximum length of subject comparisons when gathering loose threads.
141 Use nil to compare full subjects.  Setting this variable to a low
142 number will help gather threads that have been corrupted by
143 newsreaders chopping off subject lines, but it might also mean that
144 unrelated articles that have subject that happen to begin with the
145 same few characters will be incorrectly gathered.
146
147 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
148 comparing subjects."
149   :group 'gnus-thread
150   :type '(choice (const :tag "off" nil)
151                  (const fuzzy)
152                  (sexp :menu-tag "on" t)))
153
154 (defcustom gnus-simplify-subject-functions nil
155   "List of functions taking a string argument that simplify subjects.
156 The functions are applied recursively.
157
158 Useful functions to put in this list include:
159 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
160 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
161   :group 'gnus-thread
162   :type '(repeat function))
163
164 (defcustom gnus-simplify-ignored-prefixes nil
165   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
166   :group 'gnus-thread
167   :type '(choice (const :tag "off" nil)
168                  regexp))
169
170 (defcustom gnus-build-sparse-threads nil
171   "*If non-nil, fill in the gaps in threads.
172 If `some', only fill in the gaps that are needed to tie loose threads
173 together.  If `more', fill in all leaf nodes that Gnus can find.  If
174 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
175   :group 'gnus-thread
176   :type '(choice (const :tag "off" nil)
177                  (const some)
178                  (const more)
179                  (sexp :menu-tag "all" t)))
180
181 (defcustom gnus-summary-thread-gathering-function
182   'gnus-gather-threads-by-subject
183   "*Function used for gathering loose threads.
184 There are two pre-defined functions: `gnus-gather-threads-by-subject',
185 which only takes Subjects into consideration; and
186 `gnus-gather-threads-by-references', which compared the References
187 headers of the articles to find matches."
188   :group 'gnus-thread
189   :type '(radio (function-item gnus-gather-threads-by-subject)
190                 (function-item gnus-gather-threads-by-references)
191                 (function :tag "other")))
192
193 (defcustom gnus-summary-same-subject ""
194   "*String indicating that the current article has the same subject as the previous.
195 This variable will only be used if the value of
196 `gnus-summary-make-false-root' is `empty'."
197   :group 'gnus-summary-format
198   :type 'string)
199
200 (defcustom gnus-summary-goto-unread t
201   "*If t, many commands will go to the next unread article.
202 This applies to marking commands as well as other commands that
203 \"naturally\" select the next article, like, for instance, `SPC' at
204 the end of an article.
205
206 If nil, the marking commands do NOT go to the next unread article
207 \(they go to the next article instead).  If `never', commands that
208 usually go to the next unread article, will go to the next article,
209 whether it is read or not."
210   :group 'gnus-summary-marks
211   :link '(custom-manual "(gnus)Setting Marks")
212   :type '(choice (const :tag "off" nil)
213                  (const never)
214                  (sexp :menu-tag "on" t)))
215
216 (defcustom gnus-summary-default-score 0
217   "*Default article score level.
218 All scores generated by the score files will be added to this score.
219 If this variable is nil, scoring will be disabled."
220   :group 'gnus-score-default
221   :type '(choice (const :tag "disable")
222                  integer))
223
224 (defcustom gnus-summary-default-high-score 0
225   "*Default threshold for a high scored article.
226 An article will be highlighted as high scored if its score is greater
227 than this score."
228   :group 'gnus-score-default
229   :type 'integer)
230
231 (defcustom gnus-summary-default-low-score 0
232   "*Default threshold for a low scored article.
233 An article will be highlighted as low scored if its score is smaller
234 than this score."
235   :group 'gnus-score-default
236   :type 'integer)
237
238 (defcustom gnus-summary-zcore-fuzz 0
239   "*Fuzziness factor for the zcore in the summary buffer.
240 Articles with scores closer than this to `gnus-summary-default-score'
241 will not be marked."
242   :group 'gnus-summary-format
243   :type 'integer)
244
245 (defcustom gnus-simplify-subject-fuzzy-regexp nil
246   "*Strings to be removed when doing fuzzy matches.
247 This can either be a regular expression or list of regular expressions
248 that will be removed from subject strings if fuzzy subject
249 simplification is selected."
250   :group 'gnus-thread
251   :type '(repeat regexp))
252
253 (defcustom gnus-show-threads t
254   "*If non-nil, display threads in summary mode."
255   :group 'gnus-thread
256   :type 'boolean)
257
258 (defcustom gnus-thread-hide-subtree nil
259   "*If non-nil, hide all threads initially.
260 This can be a predicate specifier which says which threads to hide.
261 If threads are hidden, you have to run the command
262 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
263 to expose hidden threads."
264   :group 'gnus-thread
265   :type 'boolean)
266
267 (defcustom gnus-thread-hide-killed t
268   "*If non-nil, hide killed threads automatically."
269   :group 'gnus-thread
270   :type 'boolean)
271
272 (defcustom gnus-thread-ignore-subject t
273   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
274 If nil, articles that have different subjects from their parents will
275 start separate threads."
276   :group 'gnus-thread
277   :type 'boolean)
278
279 (defcustom gnus-thread-operation-ignore-subject t
280   "*If non-nil, subjects will be ignored when doing thread commands.
281 This affects commands like `gnus-summary-kill-thread' and
282 `gnus-summary-lower-thread'.
283
284 If this variable is nil, articles in the same thread with different
285 subjects will not be included in the operation in question.  If this
286 variable is `fuzzy', only articles that have subjects that are fuzzily
287 equal will be included."
288   :group 'gnus-thread
289   :type '(choice (const :tag "off" nil)
290                  (const fuzzy)
291                  (sexp :tag "on" t)))
292
293 (defcustom gnus-thread-indent-level 4
294   "*Number that says how much each sub-thread should be indented."
295   :group 'gnus-thread
296   :type 'integer)
297
298 (defcustom gnus-auto-extend-newsgroup t
299   "*If non-nil, extend newsgroup forward and backward when requested."
300   :group 'gnus-summary-choose
301   :type 'boolean)
302
303 (defcustom gnus-auto-select-first t
304   "*If non-nil, select the article under point.
305 Which article this is is controlled by the `gnus-auto-select-subject'
306 variable.
307
308 If you want to prevent automatic selection of articles in some
309 newsgroups, set the variable to nil in `gnus-select-group-hook'."
310   :group 'gnus-group-select
311   :type '(choice (const :tag "none" nil)
312                  (sexp :menu-tag "first" t)))
313
314 (defcustom gnus-auto-select-subject 'unread
315   "*Says what subject to place under point when entering a group.
316
317 This variable can either be the symbols `first' (place point on the
318 first subject), `unread' (place point on the subject line of the first
319 unread article), `best' (place point on the subject line of the
320 higest-scored article), `unseen' (place point on the subject line of
321 the first unseen article), 'unseen-or-unread' (place point on the subject
322 line of the first unseen article or, if all article have been seen, on the
323 subject line of the first unread article), or a function to be called to
324 place point on some subject line."
325   :group 'gnus-group-select
326   :type '(choice (const best)
327                  (const unread)
328                  (const first)
329                  (const unseen)
330                  (const unseen-or-unread)))
331
332 (defcustom gnus-dont-select-after-jump-to-other-group nil
333   "If non-nil, don't select the first unread article after entering the
334 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
335 it is depend on the value of `gnus-auto-select-first' whether to select
336 or not."
337   :group 'gnus-group-select
338   :type 'boolean)
339
340 (defcustom gnus-auto-select-next t
341   "*If non-nil, offer to go to the next group from the end of the previous.
342 If the value is t and the next newsgroup is empty, Gnus will exit
343 summary mode and go back to group mode.  If the value is neither nil
344 nor t, Gnus will select the following unread newsgroup.  In
345 particular, if the value is the symbol `quietly', the next unread
346 newsgroup will be selected without any confirmation, and if it is
347 `almost-quietly', the next group will be selected without any
348 confirmation if you are located on the last article in the group.
349 Finally, if this variable is `slightly-quietly', the `Z n' command
350 will go to the next group without confirmation."
351   :group 'gnus-summary-maneuvering
352   :type '(choice (const :tag "off" nil)
353                  (const quietly)
354                  (const almost-quietly)
355                  (const slightly-quietly)
356                  (sexp :menu-tag "on" t)))
357
358 (defcustom gnus-auto-select-same nil
359   "*If non-nil, select the next article with the same subject.
360 If there are no more articles with the same subject, go to
361 the first unread article."
362   :group 'gnus-summary-maneuvering
363   :type 'boolean)
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 (defcustom gnus-show-all-headers nil
383   "*If non-nil, don't hide any headers."
384   :group 'gnus-article-hiding
385   :group 'gnus-article-headers
386   :type 'boolean)
387
388 (defcustom gnus-summary-ignore-duplicates nil
389   "*If non-nil, ignore articles with identical Message-ID headers."
390   :group 'gnus-summary
391   :type 'boolean)
392
393 (defcustom gnus-single-article-buffer t
394   "*If non-nil, display all articles in the same buffer.
395 If nil, each group will get its own article buffer."
396   :group 'gnus-article-various
397   :type 'boolean)
398
399 (defcustom gnus-break-pages t
400   "*If non-nil, do page breaking on articles.
401 The page delimiter is specified by the `gnus-page-delimiter'
402 variable."
403   :group 'gnus-article-various
404   :type 'boolean)
405
406 (defcustom gnus-show-mime t
407   "*If non-nil, do mime processing of articles.
408 The articles will simply be fed to the function given by
409 `gnus-article-display-method-for-mime'."
410   :group 'gnus-article-mime
411   :type 'boolean)
412
413 (defcustom gnus-move-split-methods nil
414   "*Variable used to suggest where articles are to be moved to.
415 It uses the same syntax as the `gnus-split-methods' variable.
416 However, whereas `gnus-split-methods' specifies file names as targets,
417 this variable specifies group names."
418   :group 'gnus-summary-mail
419   :type '(repeat (choice (list :value (fun) function)
420                          (cons :value ("" "") regexp (repeat string))
421                          (sexp :value nil))))
422
423 (defcustom gnus-unread-mark ?\ ;;;Whitespace
424   "*Mark used for unread articles."
425   :group 'gnus-summary-marks
426   :type 'character)
427
428 (defcustom gnus-ticked-mark ?!
429   "*Mark used for ticked articles."
430   :group 'gnus-summary-marks
431   :type 'character)
432
433 (defcustom gnus-dormant-mark ??
434   "*Mark used for dormant articles."
435   :group 'gnus-summary-marks
436   :type 'character)
437
438 (defcustom gnus-del-mark ?r
439   "*Mark used for del'd articles."
440   :group 'gnus-summary-marks
441   :type 'character)
442
443 (defcustom gnus-read-mark ?R
444   "*Mark used for read articles."
445   :group 'gnus-summary-marks
446   :type 'character)
447
448 (defcustom gnus-expirable-mark ?E
449   "*Mark used for expirable articles."
450   :group 'gnus-summary-marks
451   :type 'character)
452
453 (defcustom gnus-killed-mark ?K
454   "*Mark used for killed articles."
455   :group 'gnus-summary-marks
456   :type 'character)
457
458 (defcustom gnus-spam-mark ?$
459   "*Mark used for spam articles."
460   :group 'gnus-summary-marks
461   :type 'character)
462
463 (defcustom gnus-souped-mark ?F
464   "*Mark used for souped articles."
465   :group 'gnus-summary-marks
466   :type 'character)
467
468 (defcustom gnus-kill-file-mark ?X
469   "*Mark used for articles killed by kill files."
470   :group 'gnus-summary-marks
471   :type 'character)
472
473 (defcustom gnus-low-score-mark ?Y
474   "*Mark used for articles with a low score."
475   :group 'gnus-summary-marks
476   :type 'character)
477
478 (defcustom gnus-catchup-mark ?C
479   "*Mark used for articles that are caught up."
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-replied-mark ?A
484   "*Mark used for articles that have been replied to."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-forwarded-mark ?F
489   "*Mark used for articles that have been forwarded."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-recent-mark ?N
494   "*Mark used for articles that are recent."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-cached-mark ?*
499   "*Mark used for articles that are in the cache."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-saved-mark ?S
504   "*Mark used for articles that have been saved."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-unseen-mark ?.
509   "*Mark used for articles that haven't been seen."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-no-mark ?\ ;;;Whitespace
514   "*Mark used for articles that have no other secondary mark."
515   :group 'gnus-summary-marks
516   :type 'character)
517
518 (defcustom gnus-ancient-mark ?O
519   "*Mark used for ancient articles."
520   :group 'gnus-summary-marks
521   :type 'character)
522
523 (defcustom gnus-sparse-mark ?Q
524   "*Mark used for sparsely reffed articles."
525   :group 'gnus-summary-marks
526   :type 'character)
527
528 (defcustom gnus-canceled-mark ?G
529   "*Mark used for canceled articles."
530   :group 'gnus-summary-marks
531   :type 'character)
532
533 (defcustom gnus-duplicate-mark ?M
534   "*Mark used for duplicate articles."
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-undownloaded-mark ?-
539   "*Mark used for articles that weren't downloaded."
540   :group 'gnus-summary-marks
541   :type 'character)
542
543 (defcustom gnus-downloaded-mark ?+
544   "*Mark used for articles that were downloaded."
545   :group 'gnus-summary-marks
546   :type 'character)
547
548 (defcustom gnus-downloadable-mark ?%
549   "*Mark used for articles that are to be downloaded."
550   :group 'gnus-summary-marks
551   :type 'character)
552
553 (defcustom gnus-unsendable-mark ?=
554   "*Mark used for articles that won't be sent."
555   :group 'gnus-summary-marks
556   :type 'character)
557
558 (defcustom gnus-score-over-mark ?+
559   "*Score mark used for articles with high scores."
560   :group 'gnus-summary-marks
561   :type 'character)
562
563 (defcustom gnus-score-below-mark ?-
564   "*Score mark used for articles with low scores."
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
569   "*There is no thread under the article."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-not-empty-thread-mark ?=
574   "*There is a thread under the article."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-view-pseudo-asynchronously nil
579   "*If non-nil, Gnus will view pseudo-articles asynchronously."
580   :group 'gnus-extract-view
581   :type 'boolean)
582
583 (defcustom gnus-auto-expirable-marks
584   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
585         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
586         gnus-souped-mark gnus-duplicate-mark)
587   "*The list of marks converted into expiration if a group is auto-expirable."
588   :version "21.1"
589   :group 'gnus-summary
590   :type '(repeat character))
591
592 (defcustom gnus-inhibit-user-auto-expire t
593   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
594   :version "21.1"
595   :group 'gnus-summary
596   :type 'boolean)
597
598 (defcustom gnus-view-pseudos nil
599   "*If `automatic', pseudo-articles will be viewed automatically.
600 If `not-confirm', pseudos will be viewed automatically, and the user
601 will not be asked to confirm the command."
602   :group 'gnus-extract-view
603   :type '(choice (const :tag "off" nil)
604                  (const automatic)
605                  (const not-confirm)))
606
607 (defcustom gnus-view-pseudos-separately t
608   "*If non-nil, one pseudo-article will be created for each file to be viewed.
609 If nil, all files that use the same viewing command will be given as a
610 list of parameters to that command."
611   :group 'gnus-extract-view
612   :type 'boolean)
613
614 (defcustom gnus-insert-pseudo-articles t
615   "*If non-nil, insert pseudo-articles when decoding articles."
616   :group 'gnus-extract-view
617   :type 'boolean)
618
619 (defcustom gnus-summary-dummy-line-format
620   "   %(:                             :%) %S\n"
621   "*The format specification for the dummy roots in the summary buffer.
622 It works along the same lines as a normal formatting string,
623 with some simple extensions.
624
625 %S  The subject
626
627 General format specifiers can also be used.
628 See `(gnus)Formatting Variables'."
629   :link '(custom-manual "(gnus)Formatting Variables")
630   :group 'gnus-threading
631   :type 'string)
632
633 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
634   "*The format specification for the summary mode line.
635 It works along the same lines as a normal formatting string,
636 with some simple extensions:
637
638 %G  Group name
639 %p  Unprefixed group name
640 %A  Current article number
641 %z  Current article score
642 %V  Gnus version
643 %U  Number of unread articles in the group
644 %e  Number of unselected articles in the group
645 %Z  A string with unread/unselected article counts
646 %g  Shortish group name
647 %S  Subject of the current article
648 %u  User-defined spec
649 %s  Current score file name
650 %d  Number of dormant articles
651 %r  Number of articles that have been marked as read in this session
652 %E  Number of articles expunged by the score files"
653   :group 'gnus-summary-format
654   :type 'string)
655
656 (defcustom gnus-list-identifiers nil
657   "Regexp that matches list identifiers to be removed from subject.
658 This can also be a list of regexps."
659   :version "21.1"
660   :group 'gnus-summary-format
661   :group 'gnus-article-hiding
662   :type '(choice (const :tag "none" nil)
663                  (regexp :value ".*")
664                  (repeat :value (".*") regexp)))
665
666 (defcustom gnus-summary-mark-below 0
667   "*Mark all articles with a score below this variable as read.
668 This variable is local to each summary buffer and usually set by the
669 score file."
670   :group 'gnus-score-default
671   :type 'integer)
672
673 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
674   "*List of functions used for sorting articles in the summary buffer.
675
676 Each function takes two articles and returns non-nil if the first
677 article should be sorted before the other.  If you use more than one
678 function, the primary sort function should be the last.  You should
679 probably always include `gnus-article-sort-by-number' in the list of
680 sorting functions -- preferably first.  Also note that sorting by date
681 is often much slower than sorting by number, and the sorting order is
682 very similar.  (Sorting by date means sorting by the time the message
683 was sent, sorting by number means sorting by arrival time.)
684
685 Ready-made functions include `gnus-article-sort-by-number',
686 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
687 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
688 and `gnus-article-sort-by-score'.
689
690 When threading is turned on, the variable `gnus-thread-sort-functions'
691 controls how articles are sorted."
692   :group 'gnus-summary-sort
693   :type '(repeat (choice (function-item gnus-article-sort-by-number)
694                          (function-item gnus-article-sort-by-author)
695                          (function-item gnus-article-sort-by-subject)
696                          (function-item gnus-article-sort-by-date)
697                          (function-item gnus-article-sort-by-score)
698                          (function-item gnus-article-sort-by-random)
699                          (function :tag "other"))))
700
701 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
702   "*List of functions used for sorting threads in the summary buffer.
703 By default, threads are sorted by article number.
704
705 Each function takes two threads and returns non-nil if the first
706 thread should be sorted before the other.  If you use more than one
707 function, the primary sort function should be the last.  You should
708 probably always include `gnus-thread-sort-by-number' in the list of
709 sorting functions -- preferably first.  Also note that sorting by date
710 is often much slower than sorting by number, and the sorting order is
711 very similar.  (Sorting by date means sorting by the time the message
712 was sent, sorting by number means sorting by arrival time.)
713
714 Ready-made functions include `gnus-thread-sort-by-number',
715 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
716 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
717 `gnus-thread-sort-by-most-recent-number',
718 `gnus-thread-sort-by-most-recent-date',
719 `gnus-thread-sort-by-random', and
720 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
721
722 When threading is turned off, the variable
723 `gnus-article-sort-functions' controls how articles are sorted."
724   :group 'gnus-summary-sort
725   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
726                          (function-item gnus-thread-sort-by-author)
727                          (function-item gnus-thread-sort-by-subject)
728                          (function-item gnus-thread-sort-by-date)
729                          (function-item gnus-thread-sort-by-score)
730                          (function-item gnus-thread-sort-by-total-score)
731                          (function-item gnus-thread-sort-by-random)
732                          (function :tag "other"))))
733
734 (defcustom gnus-thread-score-function '+
735   "*Function used for calculating the total score of a thread.
736
737 The function is called with the scores of the article and each
738 subthread and should then return the score of the thread.
739
740 Some functions you can use are `+', `max', or `min'."
741   :group 'gnus-summary-sort
742   :type 'function)
743
744 (defcustom gnus-summary-expunge-below nil
745   "All articles that have a score less than this variable will be expunged.
746 This variable is local to the summary buffers."
747   :group 'gnus-score-default
748   :type '(choice (const :tag "off" nil)
749                  integer))
750
751 (defcustom gnus-thread-expunge-below nil
752   "All threads that have a total score less than this variable will be expunged.
753 See `gnus-thread-score-function' for en explanation of what a
754 \"thread score\" is.
755
756 This variable is local to the summary buffers."
757   :group 'gnus-threading
758   :group 'gnus-score-default
759   :type '(choice (const :tag "off" nil)
760                  integer))
761
762 (defcustom gnus-summary-mode-hook nil
763   "*A hook for Gnus summary mode.
764 This hook is run before any variables are set in the summary buffer."
765   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
766   :group 'gnus-summary-various
767   :type 'hook)
768
769 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
770 (when (featurep 'xemacs)
771   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
772   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
773   (add-hook 'gnus-summary-mode-hook
774             'gnus-xmas-switch-horizontal-scrollbar-off))
775
776 (defcustom gnus-summary-menu-hook nil
777   "*Hook run after the creation of the summary mode menu."
778   :group 'gnus-summary-visual
779   :type 'hook)
780
781 (defcustom gnus-summary-exit-hook nil
782   "*A hook called on exit from the summary buffer.
783 It will be called with point in the group buffer."
784   :group 'gnus-summary-exit
785   :type 'hook)
786
787 (defcustom gnus-summary-prepare-hook nil
788   "*A hook called after the summary buffer has been generated.
789 If you want to modify the summary buffer, you can use this hook."
790   :group 'gnus-summary-various
791   :type 'hook)
792
793 (defcustom gnus-summary-prepared-hook nil
794   "*A hook called as the last thing after the summary buffer has been generated."
795   :group 'gnus-summary-various
796   :type 'hook)
797
798 (defcustom gnus-summary-generate-hook nil
799   "*A hook run just before generating the summary buffer.
800 This hook is commonly used to customize threading variables and the
801 like."
802   :group 'gnus-summary-various
803   :type 'hook)
804
805 (defcustom gnus-select-group-hook nil
806   "*A hook called when a newsgroup is selected.
807
808 If you'd like to simplify subjects like the
809 `gnus-summary-next-same-subject' command does, you can use the
810 following hook:
811
812  (add-hook gnus-select-group-hook
813            (lambda ()
814              (mapcar (lambda (header)
815                        (mail-header-set-subject
816                         header
817                         (gnus-simplify-subject
818                          (mail-header-subject header) 're-only)))
819                      gnus-newsgroup-headers)))"
820   :group 'gnus-group-select
821   :type 'hook)
822
823 (defcustom gnus-select-article-hook nil
824   "*A hook called when an article is selected."
825   :group 'gnus-summary-choose
826   :options '(gnus-agent-fetch-selected-article)
827   :type 'hook)
828
829 (defcustom gnus-visual-mark-article-hook
830   (list 'gnus-highlight-selected-summary)
831   "*Hook run after selecting an article in the summary buffer.
832 It is meant to be used for highlighting the article in some way.  It
833 is not run if `gnus-visual' is nil."
834   :group 'gnus-summary-visual
835   :type 'hook)
836
837 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
838   "*A hook called before parsing the headers."
839   :group 'gnus-various
840   :type 'hook)
841
842 (defcustom gnus-exit-group-hook nil
843   "*A hook called when exiting summary mode.
844 This hook is not called from the non-updating exit commands like `Q'."
845   :group 'gnus-various
846   :type 'hook)
847
848 (defcustom gnus-summary-update-hook
849   (list 'gnus-summary-highlight-line)
850   "*A hook called when a summary line is changed.
851 The hook will not be called if `gnus-visual' is nil.
852
853 The default function `gnus-summary-highlight-line' will
854 highlight the line according to the `gnus-summary-highlight'
855 variable."
856   :group 'gnus-summary-visual
857   :type 'hook)
858
859 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
860   "*A hook called when an article is selected for the first time.
861 The hook is intended to mark an article as read (or unread)
862 automatically when it is selected."
863   :group 'gnus-summary-choose
864   :type 'hook)
865
866 (defcustom gnus-group-no-more-groups-hook nil
867   "*A hook run when returning to group mode having no more (unread) groups."
868   :group 'gnus-group-select
869   :type 'hook)
870
871 (defcustom gnus-ps-print-hook nil
872   "*A hook run before ps-printing something from Gnus."
873   :group 'gnus-summary
874   :type 'hook)
875
876 (defcustom gnus-summary-display-arrow
877   (and (fboundp 'display-graphic-p)
878        (display-graphic-p))
879   "*If non-nil, display an arrow highlighting the current article."
880   :version "21.1"
881   :group 'gnus-summary
882   :type 'boolean)
883
884 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
885   "Face used for highlighting the current article in the summary buffer."
886   :group 'gnus-summary-visual
887   :type 'face)
888
889 (defvar gnus-tmp-downloaded nil)
890
891 (defcustom gnus-summary-highlight
892   '(((eq mark gnus-canceled-mark)
893      . gnus-summary-cancelled-face)
894     ((and uncached (> score default-high))
895      . gnus-summary-high-undownloaded-face)
896     ((and uncached (< score default-low))
897      . gnus-summary-low-undownloaded-face)
898     (uncached
899      . gnus-summary-normal-undownloaded-face)
900     ((and (> score default-high)
901           (or (eq mark gnus-dormant-mark)
902               (eq mark gnus-ticked-mark)))
903      . gnus-summary-high-ticked-face)
904     ((and (< score default-low)
905           (or (eq mark gnus-dormant-mark)
906               (eq mark gnus-ticked-mark)))
907      . gnus-summary-low-ticked-face)
908     ((or (eq mark gnus-dormant-mark)
909          (eq mark gnus-ticked-mark))
910      . gnus-summary-normal-ticked-face)
911     ((and (> score default-high) (eq mark gnus-ancient-mark))
912      . gnus-summary-high-ancient-face)
913     ((and (< score default-low) (eq mark gnus-ancient-mark))
914      . gnus-summary-low-ancient-face)
915     ((eq mark gnus-ancient-mark)
916      . gnus-summary-normal-ancient-face)
917     ((and (> score default-high) (eq mark gnus-unread-mark))
918      . gnus-summary-high-unread-face)
919     ((and (< score default-low) (eq mark gnus-unread-mark))
920      . gnus-summary-low-unread-face)
921     ((eq mark gnus-unread-mark)
922      . gnus-summary-normal-unread-face)
923     ((> score default-high)
924      . gnus-summary-high-read-face)
925     ((< score default-low)
926      . gnus-summary-low-read-face)
927     (t
928      . gnus-summary-normal-read-face))
929   "*Controls the highlighting of summary buffer lines.
930
931 A list of (FORM . FACE) pairs.  When deciding how a a particular
932 summary line should be displayed, each form is evaluated.  The content
933 of the face field after the first true form is used.  You can change
934 how those summary lines are displayed, by editing the face field.
935
936 You can use the following variables in the FORM field.
937
938 score:        The article's score
939 default:      The default article score.
940 default-high: The default score for high scored articles.
941 default-low:  The default score for low scored articles.
942 below:        The score below which articles are automatically marked as read.
943 mark:         The articles mark."
944   :group 'gnus-summary-visual
945   :type '(repeat (cons (sexp :tag "Form" nil)
946                        face)))
947
948 (defcustom gnus-alter-header-function nil
949   "Function called to allow alteration of article header structures.
950 The function is called with one parameter, the article header vector,
951 which it may alter in any way."
952   :type '(choice (const :tag "None" nil)
953                  function)
954   :group 'gnus-summary)
955
956 (defvar gnus-decode-encoded-word-function
957   (mime-find-field-decoder 'From 'nov)
958   "Variable that says which function should be used to decode a string with encoded words.")
959
960 (defcustom gnus-extra-headers '(To Newsgroups)
961   "*Extra headers to parse."
962   :version "21.1"
963   :group 'gnus-summary
964   :type '(repeat symbol))
965
966 (defcustom gnus-ignored-from-addresses
967   (and user-mail-address (regexp-quote user-mail-address))
968   "*Regexp of From headers that may be suppressed in favor of To headers."
969   :version "21.1"
970   :group 'gnus-summary
971   :type 'regexp)
972
973 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
974   "List of charsets that should be ignored.
975 When these charsets are used in the \"charset\" parameter, the
976 default charset will be used instead."
977   :version "21.1"
978   :type '(repeat symbol)
979   :group 'gnus-charset)
980
981 (gnus-define-group-parameter
982  ignored-charsets
983  :type list
984  :function-document
985  "Return the ignored charsets of GROUP."
986  :variable gnus-group-ignored-charsets-alist
987  :variable-default
988  '(("alt\\.chinese\\.text" iso-8859-1))
989  :variable-document
990  "Alist of regexps (to match group names) and charsets that should be ignored.
991 When these charsets are used in the \"charset\" parameter, the
992 default charset will be used instead."
993  :variable-group gnus-charset
994  :variable-type '(repeat (cons (regexp :tag "Group")
995                                (repeat symbol)))
996  :parameter-type '(choice :tag "Ignored charsets"
997                           :value nil
998                           (repeat (symbol)))
999  :parameter-document       "\
1000 List of charsets that should be ignored.
1001
1002 When these charsets are used in the \"charset\" parameter, the
1003 default charset will be used instead.")
1004
1005 (defcustom gnus-group-highlight-words-alist nil
1006   "Alist of group regexps and highlight regexps.
1007 This variable uses the same syntax as `gnus-emphasis-alist'."
1008   :version "21.1"
1009   :type '(repeat (cons (regexp :tag "Group")
1010                        (repeat (list (regexp :tag "Highlight regexp")
1011                                      (number :tag "Group for entire word" 0)
1012                                      (number :tag "Group for displayed part" 0)
1013                                      (symbol :tag "Face"
1014                                              gnus-emphasis-highlight-words)))))
1015   :group 'gnus-summary-visual)
1016
1017 (defcustom gnus-use-wheel nil
1018   "Use Intelli-mouse on summary movement"
1019   :type 'boolean
1020   :group 'gnus-summary-maneuvering)
1021
1022 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1023   "Amount to scroll messages by spinning the mouse wheel.
1024 This is actually a cons cell, where the first item is the amount to scroll
1025 on a normal wheel event, and the second is the amount to scroll when the
1026 wheel is moved with the shift key depressed."
1027   :type '(cons (integer :tag "Shift") integer)
1028   :group 'gnus-summary-maneuvering)
1029
1030 (defcustom gnus-wheel-edge-resistance 2
1031   "How hard it should be to change the current article
1032 by moving the mouse over the edge of the article window."
1033   :type 'integer
1034   :group 'gnus-summary-maneuvering)
1035
1036 (defcustom gnus-summary-show-article-charset-alist
1037   nil
1038   "Alist of number and charset.
1039 The article will be shown with the charset corresponding to the
1040 numbered argument.
1041 For example: ((1 . cn-gb-2312) (2 . big5))."
1042   :version "21.1"
1043   :type '(repeat (cons (number :tag "Argument" 1)
1044                        (symbol :tag "Charset")))
1045   :group 'gnus-charset)
1046
1047 (defcustom gnus-preserve-marks t
1048   "Whether marks are preserved when moving, copying and respooling messages."
1049   :version "21.1"
1050   :type 'boolean
1051   :group 'gnus-summary-marks)
1052
1053 (defcustom gnus-alter-articles-to-read-function nil
1054   "Function to be called to alter the list of articles to be selected."
1055   :type '(choice (const nil) function)
1056   :group 'gnus-summary)
1057
1058 (defcustom gnus-orphan-score nil
1059   "*All orphans get this score added.  Set in the score file."
1060   :group 'gnus-score-default
1061   :type '(choice (const nil)
1062                  integer))
1063
1064 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1065   "*A regexp to match MIME parts when saving multiple parts of a message
1066 with gnus-summary-save-parts (X m). This regexp will be used by default
1067 when prompting the user for which type of files to save."
1068   :group 'gnus-summary
1069   :type 'regexp)
1070
1071 (defcustom gnus-read-all-available-headers nil
1072   "Whether Gnus should parse all headers made available to it.
1073 This is mostly relevant for slow backends where the user may
1074 wish to widen the summary buffer to include all headers
1075 that were fetched.  Say, for nnultimate groups."
1076   :group 'gnus-summary
1077   :type '(choice boolean regexp))
1078
1079 (defcustom gnus-summary-muttprint-program "muttprint"
1080   "Command (and optional arguments) used to run Muttprint."
1081   :version "21.3"
1082   :group 'gnus-summary
1083   :type 'string)
1084
1085 (defcustom gnus-article-loose-mime nil
1086   "If non-nil, don't require MIME-Version header.
1087 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1088 supply the MIME-Version header or deliberately strip it From the mail.
1089 Set it to non-nil, Gnus will treat some articles as MIME even if
1090 the MIME-Version header is missed."
1091   :version "21.3"
1092   :type 'boolean
1093   :group 'gnus-article)
1094
1095 (defcustom gnus-article-emulate-mime t
1096   "If non-nil, use MIME emulation for uuencode and the like.
1097 This means that Gnus will search message bodies for text that look
1098 like uuencoded bits, yEncoded bits, and so on, and present that using
1099 the normal Gnus MIME machinery."
1100   :type 'boolean
1101   :group 'gnus-article)
1102
1103 ;;; Internal variables
1104
1105 (defvar gnus-summary-display-cache nil)
1106 (defvar gnus-article-mime-handles nil)
1107 (defvar gnus-article-decoded-p nil)
1108 (defvar gnus-article-charset nil)
1109 (defvar gnus-article-ignored-charsets nil)
1110 (defvar gnus-scores-exclude-files nil)
1111 (defvar gnus-page-broken nil)
1112
1113 (defvar gnus-original-article nil)
1114 (defvar gnus-article-internal-prepare-hook nil)
1115 (defvar gnus-newsgroup-process-stack nil)
1116
1117 (defvar gnus-thread-indent-array nil)
1118 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1119 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1120   "Function called to sort the articles within a thread after it has been gathered together.")
1121
1122 (defvar gnus-summary-save-parts-type-history nil)
1123 (defvar gnus-summary-save-parts-last-directory nil)
1124
1125 ;; Avoid highlighting in kill files.
1126 (defvar gnus-summary-inhibit-highlight nil)
1127 (defvar gnus-newsgroup-selected-overlay nil)
1128 (defvar gnus-inhibit-limiting nil)
1129 (defvar gnus-newsgroup-adaptive-score-file nil)
1130 (defvar gnus-current-score-file nil)
1131 (defvar gnus-current-move-group nil)
1132 (defvar gnus-current-copy-group nil)
1133 (defvar gnus-current-crosspost-group nil)
1134 (defvar gnus-newsgroup-display nil)
1135
1136 (defvar gnus-newsgroup-dependencies nil)
1137 (defvar gnus-newsgroup-adaptive nil)
1138 (defvar gnus-summary-display-article-function nil)
1139 (defvar gnus-summary-highlight-line-function nil
1140   "Function called after highlighting a summary line.")
1141
1142 (defvar gnus-summary-line-format-alist
1143   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1144     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1145     (?s gnus-tmp-subject-or-nil ?s)
1146     (?n gnus-tmp-name ?s)
1147     (?A (std11-address-string
1148          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1149     (?a (or (std11-full-name-string
1150              (car (mime-entity-read-field gnus-tmp-header 'From)))
1151             gnus-tmp-from) ?s)
1152     (?F gnus-tmp-from ?s)
1153     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1154     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1155     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1156     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1157     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1158     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1159     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1160     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1161     (?L gnus-tmp-lines ?s)
1162     (?O gnus-tmp-downloaded ?c)
1163     (?I gnus-tmp-indentation ?s)
1164     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1165     (?R gnus-tmp-replied ?c)
1166     (?\[ gnus-tmp-opening-bracket ?c)
1167     (?\] gnus-tmp-closing-bracket ?c)
1168     (?\> (make-string gnus-tmp-level ? ) ?s)
1169     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1170     (?i gnus-tmp-score ?d)
1171     (?z gnus-tmp-score-char ?c)
1172     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1173     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1174     (?U gnus-tmp-unread ?c)
1175     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1176         ?s)
1177     (?t (gnus-summary-number-of-articles-in-thread
1178          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1179         ?d)
1180     (?e (gnus-summary-number-of-articles-in-thread
1181          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1182         ?c)
1183     (?u gnus-tmp-user-defined ?s)
1184     (?P (gnus-pick-line-number) ?d)
1185     (?B gnus-tmp-thread-tree-header-string ?s)
1186     (user-date (gnus-user-date
1187                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1188   "An alist of format specifications that can appear in summary lines.
1189 These are paired with what variables they correspond with, along with
1190 the type of the variable (string, integer, character, etc).")
1191
1192 (defvar gnus-summary-dummy-line-format-alist
1193   `((?S gnus-tmp-subject ?s)
1194     (?N gnus-tmp-number ?d)
1195     (?u gnus-tmp-user-defined ?s)))
1196
1197 (defvar gnus-summary-mode-line-format-alist
1198   `((?G gnus-tmp-group-name ?s)
1199     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1200     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1201     (?A gnus-tmp-article-number ?d)
1202     (?Z gnus-tmp-unread-and-unselected ?s)
1203     (?V gnus-version ?s)
1204     (?U gnus-tmp-unread-and-unticked ?d)
1205     (?S gnus-tmp-subject ?s)
1206     (?e gnus-tmp-unselected ?d)
1207     (?u gnus-tmp-user-defined ?s)
1208     (?d (length gnus-newsgroup-dormant) ?d)
1209     (?t (length gnus-newsgroup-marked) ?d)
1210     (?h (length gnus-newsgroup-spam-marked) ?d)
1211     (?r (length gnus-newsgroup-reads) ?d)
1212     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1213     (?E gnus-newsgroup-expunged-tally ?d)
1214     (?s (gnus-current-score-file-nondirectory) ?s)))
1215
1216 (defvar gnus-last-search-regexp nil
1217   "Default regexp for article search command.")
1218
1219 (defvar gnus-summary-search-article-matched-data nil
1220   "Last matched data of article search command.  It is the local variable
1221 in `gnus-article-buffer' which consists of the list of start position,
1222 end position and text.")
1223
1224 (defvar gnus-last-shell-command nil
1225   "Default shell command on article.")
1226
1227 (defvar gnus-newsgroup-agentized nil
1228   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1229 (defvar gnus-newsgroup-begin nil)
1230 (defvar gnus-newsgroup-end nil)
1231 (defvar gnus-newsgroup-last-rmail nil)
1232 (defvar gnus-newsgroup-last-mail nil)
1233 (defvar gnus-newsgroup-last-folder nil)
1234 (defvar gnus-newsgroup-last-file nil)
1235 (defvar gnus-newsgroup-auto-expire nil)
1236 (defvar gnus-newsgroup-active nil)
1237
1238 (defvar gnus-newsgroup-data nil)
1239 (defvar gnus-newsgroup-data-reverse nil)
1240 (defvar gnus-newsgroup-limit nil)
1241 (defvar gnus-newsgroup-limits nil)
1242
1243 (defvar gnus-newsgroup-unreads nil
1244   "Sorted list of unread articles in the current newsgroup.")
1245
1246 (defvar gnus-newsgroup-unselected nil
1247   "Sorted list of unselected unread articles in the current newsgroup.")
1248
1249 (defvar gnus-newsgroup-reads nil
1250   "Alist of read articles and article marks in the current newsgroup.")
1251
1252 (defvar gnus-newsgroup-expunged-tally nil)
1253
1254 (defvar gnus-newsgroup-marked nil
1255   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1256
1257 (defvar gnus-newsgroup-spam-marked nil
1258   "List of ranges of articles that have been marked as spam.")
1259
1260 (defvar gnus-newsgroup-killed nil
1261   "List of ranges of articles that have been through the scoring process.")
1262
1263 (defvar gnus-newsgroup-cached nil
1264   "Sorted list of articles that come from the article cache.")
1265
1266 (defvar gnus-newsgroup-saved nil
1267   "List of articles that have been saved.")
1268
1269 (defvar gnus-newsgroup-kill-headers nil)
1270
1271 (defvar gnus-newsgroup-replied nil
1272   "List of articles that have been replied to in the current newsgroup.")
1273
1274 (defvar gnus-newsgroup-forwarded nil
1275   "List of articles that have been forwarded in the current newsgroup.")
1276
1277 (defvar gnus-newsgroup-recent nil
1278   "List of articles that have are recent in the current newsgroup.")
1279
1280 (defvar gnus-newsgroup-expirable nil
1281   "Sorted list of articles in the current newsgroup that can be expired.")
1282
1283 (defvar gnus-newsgroup-processable nil
1284   "List of articles in the current newsgroup that can be processed.")
1285
1286 (defvar gnus-newsgroup-downloadable nil
1287   "Sorted list of articles in the current newsgroup that can be processed.")
1288
1289 (defvar gnus-newsgroup-unfetched nil
1290   "Sorted list of articles in the current newsgroup whose headers have not been fetched into the agent.")
1291
1292 (defvar gnus-newsgroup-undownloaded nil
1293   "List of articles in the current newsgroup that haven't been downloaded..")
1294
1295 (defvar gnus-newsgroup-unsendable nil
1296   "List of articles in the current newsgroup that won't be sent.")
1297
1298 (defvar gnus-newsgroup-bookmarks nil
1299   "List of articles in the current newsgroup that have bookmarks.")
1300
1301 (defvar gnus-newsgroup-dormant nil
1302   "Sorted list of dormant articles in the current newsgroup.")
1303
1304 (defvar gnus-newsgroup-unseen nil
1305   "List of unseen articles in the current newsgroup.")
1306
1307 (defvar gnus-newsgroup-seen nil
1308   "Range of seen articles in the current newsgroup.")
1309
1310 (defvar gnus-newsgroup-articles nil
1311   "List of articles in the current newsgroup.")
1312
1313 (defvar gnus-newsgroup-scored nil
1314   "List of scored articles in the current newsgroup.")
1315
1316 (defvar gnus-newsgroup-incorporated nil
1317   "List of incorporated articles in the current newsgroup.")
1318
1319 (defvar gnus-newsgroup-headers nil
1320   "List of article headers in the current newsgroup.")
1321
1322 (defvar gnus-newsgroup-threads nil)
1323
1324 (defvar gnus-newsgroup-prepared nil
1325   "Whether the current group has been prepared properly.")
1326
1327 (defvar gnus-newsgroup-ancient nil
1328   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1329
1330 (defvar gnus-newsgroup-sparse nil)
1331
1332 (defvar gnus-current-article nil)
1333 (defvar gnus-article-current nil)
1334 (defvar gnus-current-headers nil)
1335 (defvar gnus-have-all-headers nil)
1336 (defvar gnus-last-article nil)
1337 (defvar gnus-newsgroup-history nil)
1338 (defvar gnus-newsgroup-charset nil)
1339 (defvar gnus-newsgroup-ephemeral-charset nil)
1340 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1341
1342 (defvar gnus-article-before-search nil)
1343
1344 (defconst gnus-summary-local-variables
1345   '(gnus-newsgroup-name
1346     gnus-newsgroup-begin gnus-newsgroup-end
1347     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1348     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1349     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1350     gnus-newsgroup-unselected gnus-newsgroup-marked
1351     gnus-newsgroup-spam-marked
1352     gnus-newsgroup-reads gnus-newsgroup-saved
1353     gnus-newsgroup-replied gnus-newsgroup-forwarded
1354     gnus-newsgroup-recent
1355     gnus-newsgroup-expirable
1356     gnus-newsgroup-processable gnus-newsgroup-killed
1357     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1358     gnus-newsgroup-unfetched
1359     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1360     gnus-newsgroup-seen gnus-newsgroup-articles
1361     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1362     gnus-newsgroup-headers gnus-newsgroup-threads
1363     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1364     gnus-current-article gnus-current-headers gnus-have-all-headers
1365     gnus-last-article gnus-article-internal-prepare-hook
1366     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1367     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1368     gnus-thread-expunge-below
1369     gnus-score-alist gnus-current-score-file
1370     (gnus-summary-expunge-below . global)
1371     (gnus-summary-mark-below . global)
1372     (gnus-orphan-score . global)
1373     gnus-newsgroup-active gnus-scores-exclude-files
1374     gnus-newsgroup-history gnus-newsgroup-ancient
1375     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1376     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1377     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1378     (gnus-newsgroup-expunged-tally . 0)
1379     gnus-cache-removable-articles gnus-newsgroup-cached
1380     gnus-newsgroup-data gnus-newsgroup-data-reverse
1381     gnus-newsgroup-limit gnus-newsgroup-limits
1382     gnus-newsgroup-charset gnus-newsgroup-display
1383     gnus-newsgroup-incorporated)
1384   "Variables that are buffer-local to the summary buffers.")
1385
1386 (defvar gnus-newsgroup-variables nil
1387   "A list of variables that have separate values in different newsgroups.
1388 A list of newsgroup (summary buffer) local variables, or cons of
1389 variables and their default values (when the default values are not
1390 nil), that should be made global while the summary buffer is active.
1391 These variables can be used to set variables in the group parameters
1392 while still allowing them to affect operations done in other
1393 buffers. For example:
1394
1395 \(setq gnus-newsgroup-variables
1396      '(message-use-followup-to
1397        (gnus-visible-headers .
1398          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1399 ")
1400
1401 ;; Byte-compiler warning.
1402 ;(eval-when-compile (defvar gnus-article-mode-map))
1403 (eval-when-compile
1404   (let ((features (cons 'gnus-sum features)))
1405     (require 'gnus)
1406     (require 'gnus-agent)
1407     (require 'gnus-art)))
1408
1409 ;; Subject simplification.
1410
1411 (defun gnus-simplify-whitespace (str)
1412   "Remove excessive whitespace from STR."
1413   (let ((mystr str))
1414     ;; Multiple spaces.
1415     (while (string-match "[ \t][ \t]+" mystr)
1416       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1417                           " "
1418                           (substring mystr (match-end 0)))))
1419     ;; Leading spaces.
1420     (when (string-match "^[ \t]+" mystr)
1421       (setq mystr (substring mystr (match-end 0))))
1422     ;; Trailing spaces.
1423     (when (string-match "[ \t]+$" mystr)
1424       (setq mystr (substring mystr 0 (match-beginning 0))))
1425     mystr))
1426
1427 (defun gnus-simplify-all-whitespace (str)
1428   "Remove all whitespace from STR."
1429   (let ((mystr str))
1430     (while (string-match "[ \t\n]+" mystr)
1431       (setq mystr (replace-match "" nil nil mystr)))
1432     mystr))
1433
1434 (defsubst gnus-simplify-subject-re (subject)
1435   "Remove \"Re:\" from subject lines."
1436   (if (string-match message-subject-re-regexp subject)
1437       (substring subject (match-end 0))
1438     subject))
1439
1440 (defun gnus-simplify-subject (subject &optional re-only)
1441   "Remove `Re:' and words in parentheses.
1442 If RE-ONLY is non-nil, strip leading `Re:'s only."
1443   (let ((case-fold-search t))           ;Ignore case.
1444     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1445     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1446       (setq subject (substring subject (match-end 0))))
1447     ;; Remove uninteresting prefixes.
1448     (when (and (not re-only)
1449                gnus-simplify-ignored-prefixes
1450                (string-match gnus-simplify-ignored-prefixes subject))
1451       (setq subject (substring subject (match-end 0))))
1452     ;; Remove words in parentheses from end.
1453     (unless re-only
1454       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1455         (setq subject (substring subject 0 (match-beginning 0)))))
1456     ;; Return subject string.
1457     subject))
1458
1459 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1460 ;; all whitespace.
1461 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1462   (goto-char (point-min))
1463   (while (re-search-forward regexp nil t)
1464     (replace-match (or newtext ""))))
1465
1466 (defun gnus-simplify-buffer-fuzzy ()
1467   "Simplify string in the buffer fuzzily.
1468 The string in the accessible portion of the current buffer is simplified.
1469 It is assumed to be a single-line subject.
1470 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1471 matter is removed.  Additional things can be deleted by setting
1472 `gnus-simplify-subject-fuzzy-regexp'."
1473   (let ((case-fold-search t)
1474         (modified-tick))
1475     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1476
1477     (while (not (eq modified-tick (buffer-modified-tick)))
1478       (setq modified-tick (buffer-modified-tick))
1479       (cond
1480        ((listp gnus-simplify-subject-fuzzy-regexp)
1481         (mapcar 'gnus-simplify-buffer-fuzzy-step
1482                 gnus-simplify-subject-fuzzy-regexp))
1483        (gnus-simplify-subject-fuzzy-regexp
1484         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1485       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1486       (gnus-simplify-buffer-fuzzy-step
1487        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1488       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1489
1490     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1491     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1492     (gnus-simplify-buffer-fuzzy-step " $")
1493     (gnus-simplify-buffer-fuzzy-step "^ +")))
1494
1495 (defun gnus-simplify-subject-fuzzy (subject)
1496   "Simplify a subject string fuzzily.
1497 See `gnus-simplify-buffer-fuzzy' for details."
1498   (save-excursion
1499     (gnus-set-work-buffer)
1500     (let ((case-fold-search t))
1501       ;; Remove uninteresting prefixes.
1502       (when (and gnus-simplify-ignored-prefixes
1503                  (string-match gnus-simplify-ignored-prefixes subject))
1504         (setq subject (substring subject (match-end 0))))
1505       (insert subject)
1506       (inline (gnus-simplify-buffer-fuzzy))
1507       (buffer-string))))
1508
1509 (defsubst gnus-simplify-subject-fully (subject)
1510   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1511   (cond
1512    (gnus-simplify-subject-functions
1513     (gnus-map-function gnus-simplify-subject-functions subject))
1514    ((null gnus-summary-gather-subject-limit)
1515     (gnus-simplify-subject-re subject))
1516    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1517     (gnus-simplify-subject-fuzzy subject))
1518    ((numberp gnus-summary-gather-subject-limit)
1519     (gnus-limit-string (gnus-simplify-subject-re subject)
1520                        gnus-summary-gather-subject-limit))
1521    (t
1522     subject)))
1523
1524 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1525   "Check whether two subjects are equal.
1526 If optional argument simple-first is t, first argument is already
1527 simplified."
1528   (cond
1529    ((null simple-first)
1530     (equal (gnus-simplify-subject-fully s1)
1531            (gnus-simplify-subject-fully s2)))
1532    (t
1533     (equal s1
1534            (gnus-simplify-subject-fully s2)))))
1535
1536 (defun gnus-summary-bubble-group ()
1537   "Increase the score of the current group.
1538 This is a handy function to add to `gnus-summary-exit-hook' to
1539 increase the score of each group you read."
1540   (gnus-group-add-score gnus-newsgroup-name))
1541
1542 \f
1543 ;;;
1544 ;;; Gnus summary mode
1545 ;;;
1546
1547 (put 'gnus-summary-mode 'mode-class 'special)
1548
1549 (defvar gnus-article-commands-menu)
1550
1551 ;; Non-orthogonal keys
1552
1553 (gnus-define-keys gnus-summary-mode-map
1554   " " gnus-summary-next-page
1555   "\177" gnus-summary-prev-page
1556   [delete] gnus-summary-prev-page
1557   [backspace] gnus-summary-prev-page
1558   "\r" gnus-summary-scroll-up
1559   "\M-\r" gnus-summary-scroll-down
1560   "n" gnus-summary-next-unread-article
1561   "p" gnus-summary-prev-unread-article
1562   "N" gnus-summary-next-article
1563   "P" gnus-summary-prev-article
1564   "\M-\C-n" gnus-summary-next-same-subject
1565   "\M-\C-p" gnus-summary-prev-same-subject
1566   "\M-n" gnus-summary-next-unread-subject
1567   "\M-p" gnus-summary-prev-unread-subject
1568   "." gnus-summary-first-unread-article
1569   "," gnus-summary-best-unread-article
1570   "\M-s" gnus-summary-search-article-forward
1571   "\M-r" gnus-summary-search-article-backward
1572   "<" gnus-summary-beginning-of-article
1573   ">" gnus-summary-end-of-article
1574   "j" gnus-summary-goto-article
1575   "^" gnus-summary-refer-parent-article
1576   "\M-^" gnus-summary-refer-article
1577   "u" gnus-summary-tick-article-forward
1578   "!" gnus-summary-tick-article-forward
1579   "U" gnus-summary-tick-article-backward
1580   "d" gnus-summary-mark-as-read-forward
1581   "D" gnus-summary-mark-as-read-backward
1582   "E" gnus-summary-mark-as-expirable
1583   "\M-u" gnus-summary-clear-mark-forward
1584   "\M-U" gnus-summary-clear-mark-backward
1585   "k" gnus-summary-kill-same-subject-and-select
1586   "\C-k" gnus-summary-kill-same-subject
1587   "\M-\C-k" gnus-summary-kill-thread
1588   "\M-\C-l" gnus-summary-lower-thread
1589   "e" gnus-summary-edit-article
1590   "#" gnus-summary-mark-as-processable
1591   "\M-#" gnus-summary-unmark-as-processable
1592   "\M-\C-t" gnus-summary-toggle-threads
1593   "\M-\C-s" gnus-summary-show-thread
1594   "\M-\C-h" gnus-summary-hide-thread
1595   "\M-\C-f" gnus-summary-next-thread
1596   "\M-\C-b" gnus-summary-prev-thread
1597   [(meta down)] gnus-summary-next-thread
1598   [(meta up)] gnus-summary-prev-thread
1599   "\M-\C-u" gnus-summary-up-thread
1600   "\M-\C-d" gnus-summary-down-thread
1601   "&" gnus-summary-execute-command
1602   "c" gnus-summary-catchup-and-exit
1603   "\C-w" gnus-summary-mark-region-as-read
1604   "\C-t" gnus-summary-toggle-truncation
1605   "?" gnus-summary-mark-as-dormant
1606   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1607   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1608   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1609   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1610   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1611   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1612   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1613   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1614   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1615   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1616   "=" gnus-summary-expand-window
1617   "\C-x\C-s" gnus-summary-reselect-current-group
1618   "\M-g" gnus-summary-rescan-group
1619   "w" gnus-summary-stop-page-breaking
1620   "\C-c\C-r" gnus-summary-caesar-message
1621   "\M-t" gnus-summary-toggle-mime
1622   "f" gnus-summary-followup
1623   "F" gnus-summary-followup-with-original
1624   "C" gnus-summary-cancel-article
1625   "r" gnus-summary-reply
1626   "R" gnus-summary-reply-with-original
1627   "\C-c\C-f" gnus-summary-mail-forward
1628   "o" gnus-summary-save-article
1629   "\C-o" gnus-summary-save-article-mail
1630   "|" gnus-summary-pipe-output
1631   "\M-k" gnus-summary-edit-local-kill
1632   "\M-K" gnus-summary-edit-global-kill
1633   ;; "V" gnus-version
1634   "\C-c\C-d" gnus-summary-describe-group
1635   "q" gnus-summary-exit
1636   "Q" gnus-summary-exit-no-update
1637   "\C-c\C-i" gnus-info-find-node
1638   gnus-mouse-2 gnus-mouse-pick-article
1639   "m" gnus-summary-mail-other-window
1640   "a" gnus-summary-post-news
1641   "i" gnus-summary-news-other-window
1642   "x" gnus-summary-limit-to-unread
1643   "s" gnus-summary-isearch-article
1644   "t" gnus-summary-toggle-header
1645   "g" gnus-summary-show-article
1646   "l" gnus-summary-goto-last-article
1647   "v" gnus-summary-preview-mime-message
1648   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1649   "\C-d" gnus-summary-enter-digest-group
1650   "\M-\C-d" gnus-summary-read-document
1651   "\M-\C-e" gnus-summary-edit-parameters
1652   "\M-\C-a" gnus-summary-customize-parameters
1653   "\C-c\C-b" gnus-bug
1654   "\C-c\C-n" gnus-namazu-search
1655   "*" gnus-cache-enter-article
1656   "\M-*" gnus-cache-remove-article
1657   "\M-&" gnus-summary-universal-argument
1658   "\C-l" gnus-recenter
1659   "I" gnus-summary-increase-score
1660   "L" gnus-summary-lower-score
1661   "\M-i" gnus-symbolic-argument
1662   "h" gnus-summary-select-article-buffer
1663
1664   "V" gnus-summary-score-map
1665   "X" gnus-uu-extract-map
1666   "S" gnus-summary-send-map)
1667
1668   ;; Sort of orthogonal keymap
1669 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1670   "t" gnus-summary-tick-article-forward
1671   "!" gnus-summary-tick-article-forward
1672   "d" gnus-summary-mark-as-read-forward
1673   "r" gnus-summary-mark-as-read-forward
1674   "c" gnus-summary-clear-mark-forward
1675   " " gnus-summary-clear-mark-forward
1676   "e" gnus-summary-mark-as-expirable
1677   "x" gnus-summary-mark-as-expirable
1678   "?" gnus-summary-mark-as-dormant
1679   "b" gnus-summary-set-bookmark
1680   "B" gnus-summary-remove-bookmark
1681   "#" gnus-summary-mark-as-processable
1682   "\M-#" gnus-summary-unmark-as-processable
1683   "S" gnus-summary-limit-include-expunged
1684   "C" gnus-summary-catchup
1685   "H" gnus-summary-catchup-to-here
1686   "h" gnus-summary-catchup-from-here
1687   "\C-c" gnus-summary-catchup-all
1688   "k" gnus-summary-kill-same-subject-and-select
1689   "K" gnus-summary-kill-same-subject
1690   "P" gnus-uu-mark-map)
1691
1692 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1693   "c" gnus-summary-clear-above
1694   "u" gnus-summary-tick-above
1695   "m" gnus-summary-mark-above
1696   "k" gnus-summary-kill-below)
1697
1698 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1699   "/" gnus-summary-limit-to-subject
1700   "n" gnus-summary-limit-to-articles
1701   "w" gnus-summary-pop-limit
1702   "s" gnus-summary-limit-to-subject
1703   "a" gnus-summary-limit-to-author
1704   "u" gnus-summary-limit-to-unread
1705   "m" gnus-summary-limit-to-marks
1706   "M" gnus-summary-limit-exclude-marks
1707   "v" gnus-summary-limit-to-score
1708   "*" gnus-summary-limit-include-cached
1709   "D" gnus-summary-limit-include-dormant
1710   "T" gnus-summary-limit-include-thread
1711   "d" gnus-summary-limit-exclude-dormant
1712   "t" gnus-summary-limit-to-age
1713   "." gnus-summary-limit-to-unseen
1714   "x" gnus-summary-limit-to-extra
1715   "p" gnus-summary-limit-to-display-predicate
1716   "E" gnus-summary-limit-include-expunged
1717   "c" gnus-summary-limit-exclude-childless-dormant
1718   "C" gnus-summary-limit-mark-excluded-as-read
1719   "o" gnus-summary-insert-old-articles
1720   "N" gnus-summary-insert-new-articles)
1721
1722 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1723   "n" gnus-summary-next-unread-article
1724   "p" gnus-summary-prev-unread-article
1725   "N" gnus-summary-next-article
1726   "P" gnus-summary-prev-article
1727   "\C-n" gnus-summary-next-same-subject
1728   "\C-p" gnus-summary-prev-same-subject
1729   "\M-n" gnus-summary-next-unread-subject
1730   "\M-p" gnus-summary-prev-unread-subject
1731   "f" gnus-summary-first-unread-article
1732   "b" gnus-summary-best-unread-article
1733   "j" gnus-summary-goto-article
1734   "g" gnus-summary-goto-subject
1735   "l" gnus-summary-goto-last-article
1736   "o" gnus-summary-pop-article)
1737
1738 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1739   "k" gnus-summary-kill-thread
1740   "l" gnus-summary-lower-thread
1741   "i" gnus-summary-raise-thread
1742   "T" gnus-summary-toggle-threads
1743   "t" gnus-summary-rethread-current
1744   "^" gnus-summary-reparent-thread
1745   "s" gnus-summary-show-thread
1746   "S" gnus-summary-show-all-threads
1747   "h" gnus-summary-hide-thread
1748   "H" gnus-summary-hide-all-threads
1749   "n" gnus-summary-next-thread
1750   "p" gnus-summary-prev-thread
1751   "u" gnus-summary-up-thread
1752   "o" gnus-summary-top-thread
1753   "d" gnus-summary-down-thread
1754   "#" gnus-uu-mark-thread
1755   "\M-#" gnus-uu-unmark-thread)
1756
1757 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1758   "g" gnus-summary-prepare
1759   "c" gnus-summary-insert-cached-articles
1760   "d" gnus-summary-insert-dormant-articles)
1761
1762 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1763   "c" gnus-summary-catchup-and-exit
1764   "C" gnus-summary-catchup-all-and-exit
1765   "E" gnus-summary-exit-no-update
1766   "J" gnus-summary-jump-to-other-group
1767   "Q" gnus-summary-exit
1768   "Z" gnus-summary-exit
1769   "n" gnus-summary-catchup-and-goto-next-group
1770   "R" gnus-summary-reselect-current-group
1771   "G" gnus-summary-rescan-group
1772   "N" gnus-summary-next-group
1773   "s" gnus-summary-save-newsrc
1774   "P" gnus-summary-prev-group)
1775
1776 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1777   " " gnus-summary-next-page
1778   "n" gnus-summary-next-page
1779   "\177" gnus-summary-prev-page
1780   [delete] gnus-summary-prev-page
1781   "p" gnus-summary-prev-page
1782   "\r" gnus-summary-scroll-up
1783   "\M-\r" gnus-summary-scroll-down
1784   "<" gnus-summary-beginning-of-article
1785   ">" gnus-summary-end-of-article
1786   "b" gnus-summary-beginning-of-article
1787   "e" gnus-summary-end-of-article
1788   "^" gnus-summary-refer-parent-article
1789   "r" gnus-summary-refer-parent-article
1790   "D" gnus-summary-enter-digest-group
1791   "R" gnus-summary-refer-references
1792   "T" gnus-summary-refer-thread
1793   "g" gnus-summary-show-article
1794   "s" gnus-summary-isearch-article
1795   "P" gnus-summary-print-article
1796   "M" gnus-mailing-list-insinuate
1797   "t" gnus-article-babel)
1798
1799 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1800   "b" gnus-article-add-buttons
1801   "B" gnus-article-add-buttons-to-head
1802   "o" gnus-article-treat-overstrike
1803   "e" gnus-article-emphasize
1804   "w" gnus-article-fill-cited-article
1805   "Q" gnus-article-fill-long-lines
1806   "C" gnus-article-capitalize-sentences
1807   "c" gnus-article-remove-cr
1808   "Z" gnus-article-decode-HZ
1809   "h" gnus-article-wash-html
1810   "u" gnus-article-unsplit-urls
1811   "f" gnus-article-display-x-face
1812   "l" gnus-summary-stop-page-breaking
1813   "r" gnus-summary-caesar-message
1814   "m" gnus-summary-morse-message
1815   "t" gnus-summary-toggle-header
1816   "g" gnus-treat-smiley
1817   "v" gnus-summary-verbose-headers
1818   "m" gnus-summary-toggle-mime
1819   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1820   "p" gnus-article-verify-x-pgp-sig
1821   "d" gnus-article-treat-dumbquotes)
1822
1823 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1824   ;; mnemonic: deuglif*Y*
1825   "u" gnus-article-outlook-unwrap-lines
1826   "a" gnus-article-outlook-repair-attribution
1827   "c" gnus-article-outlook-rearrange-citation
1828   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1829
1830 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1831   "a" gnus-article-hide
1832   "h" gnus-article-hide-headers
1833   "b" gnus-article-hide-boring-headers
1834   "s" gnus-article-hide-signature
1835   "c" gnus-article-hide-citation
1836   "C" gnus-article-hide-citation-in-followups
1837   "l" gnus-article-hide-list-identifiers
1838   "B" gnus-article-strip-banner
1839   "P" gnus-article-hide-pem
1840   "\C-c" gnus-article-hide-citation-maybe)
1841
1842 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1843   "a" gnus-article-highlight
1844   "h" gnus-article-highlight-headers
1845   "c" gnus-article-highlight-citation
1846   "s" gnus-article-highlight-signature)
1847
1848 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1849   "f" gnus-article-treat-fold-headers
1850   "u" gnus-article-treat-unfold-headers
1851   "n" gnus-article-treat-fold-newsgroups)
1852
1853 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1854   "x" gnus-article-display-x-face
1855   "d" gnus-article-display-face
1856   "s" gnus-treat-smiley
1857   "D" gnus-article-remove-images
1858   "f" gnus-treat-from-picon
1859   "m" gnus-treat-mail-picon
1860   "n" gnus-treat-newsgroups-picon)
1861
1862 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1863   "z" gnus-article-date-ut
1864   "u" gnus-article-date-ut
1865   "l" gnus-article-date-local
1866   "p" gnus-article-date-english
1867   "e" gnus-article-date-lapsed
1868   "o" gnus-article-date-original
1869   "i" gnus-article-date-iso8601
1870   "s" gnus-article-date-user)
1871
1872 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1873   "t" gnus-article-remove-trailing-blank-lines
1874   "l" gnus-article-strip-leading-blank-lines
1875   "m" gnus-article-strip-multiple-blank-lines
1876   "a" gnus-article-strip-blank-lines
1877   "A" gnus-article-strip-all-blank-lines
1878   "s" gnus-article-strip-leading-space
1879   "e" gnus-article-strip-trailing-space
1880   "w" gnus-article-remove-leading-whitespace)
1881
1882 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1883   "v" gnus-version
1884   "f" gnus-summary-fetch-faq
1885   "d" gnus-summary-describe-group
1886   "h" gnus-summary-describe-briefly
1887   "i" gnus-info-find-node
1888   "c" gnus-group-fetch-charter
1889   "C" gnus-group-fetch-control)
1890
1891 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1892   "e" gnus-summary-expire-articles
1893   "\M-\C-e" gnus-summary-expire-articles-now
1894   "\177" gnus-summary-delete-article
1895   [delete] gnus-summary-delete-article
1896   [backspace] gnus-summary-delete-article
1897   "m" gnus-summary-move-article
1898   "r" gnus-summary-respool-article
1899   "w" gnus-summary-edit-article
1900   "c" gnus-summary-copy-article
1901   "B" gnus-summary-crosspost-article
1902   "q" gnus-summary-respool-query
1903   "t" gnus-summary-respool-trace
1904   "i" gnus-summary-import-article
1905   "I" gnus-summary-create-article
1906   "p" gnus-summary-article-posted-p)
1907
1908 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1909   "o" gnus-summary-save-article
1910   "m" gnus-summary-save-article-mail
1911   "F" gnus-summary-write-article-file
1912   "r" gnus-summary-save-article-rmail
1913   "f" gnus-summary-save-article-file
1914   "b" gnus-summary-save-article-body-file
1915   "h" gnus-summary-save-article-folder
1916   "v" gnus-summary-save-article-vm
1917   "p" gnus-summary-pipe-output
1918   "P" gnus-summary-muttprint
1919   "s" gnus-soup-add-article)
1920
1921 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1922   "b" gnus-summary-display-buttonized
1923   "m" gnus-summary-repair-multipart
1924   "v" gnus-article-view-part
1925   "o" gnus-article-save-part
1926   "c" gnus-article-copy-part
1927   "C" gnus-article-view-part-as-charset
1928   "e" gnus-article-view-part-externally
1929   "E" gnus-article-encrypt-body
1930   "i" gnus-article-inline-part
1931   "|" gnus-article-pipe-part)
1932
1933 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1934   "p" gnus-summary-mark-as-processable
1935   "u" gnus-summary-unmark-as-processable
1936   "U" gnus-summary-unmark-all-processable
1937   "v" gnus-uu-mark-over
1938   "s" gnus-uu-mark-series
1939   "r" gnus-uu-mark-region
1940   "g" gnus-uu-unmark-region
1941   "R" gnus-uu-mark-by-regexp
1942   "G" gnus-uu-unmark-by-regexp
1943   "t" gnus-uu-mark-thread
1944   "T" gnus-uu-unmark-thread
1945   "a" gnus-uu-mark-all
1946   "b" gnus-uu-mark-buffer
1947   "S" gnus-uu-mark-sparse
1948   "k" gnus-summary-kill-process-mark
1949   "y" gnus-summary-yank-process-mark
1950   "w" gnus-summary-save-process-mark
1951   "i" gnus-uu-invert-processable)
1952
1953 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1954   ;;"x" gnus-uu-extract-any
1955   "m" gnus-summary-save-parts
1956   "u" gnus-uu-decode-uu
1957   "U" gnus-uu-decode-uu-and-save
1958   "s" gnus-uu-decode-unshar
1959   "S" gnus-uu-decode-unshar-and-save
1960   "o" gnus-uu-decode-save
1961   "O" gnus-uu-decode-save
1962   "b" gnus-uu-decode-binhex
1963   "B" gnus-uu-decode-binhex
1964   "p" gnus-uu-decode-postscript
1965   "P" gnus-uu-decode-postscript-and-save)
1966
1967 (gnus-define-keys
1968     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1969   "u" gnus-uu-decode-uu-view
1970   "U" gnus-uu-decode-uu-and-save-view
1971   "s" gnus-uu-decode-unshar-view
1972   "S" gnus-uu-decode-unshar-and-save-view
1973   "o" gnus-uu-decode-save-view
1974   "O" gnus-uu-decode-save-view
1975   "b" gnus-uu-decode-binhex-view
1976   "B" gnus-uu-decode-binhex-view
1977   "p" gnus-uu-decode-postscript-view
1978   "P" gnus-uu-decode-postscript-and-save-view)
1979
1980 (defvar gnus-article-post-menu nil)
1981
1982 (defconst gnus-summary-menu-maxlen 20)
1983
1984 (defun gnus-summary-menu-split (menu)
1985   ;; If we have lots of elements, divide them into groups of 20
1986   ;; and make a pane (or submenu) for each one.
1987   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
1988       (let ((menu menu) sublists next
1989             (i 1))
1990         (while menu
1991           ;; Pull off the next gnus-summary-menu-maxlen elements
1992           ;; and make them the next element of sublist.
1993           (setq next (nthcdr gnus-summary-menu-maxlen menu))
1994           (if next
1995               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
1996                       nil))
1997           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
1998                                              (aref (car (last menu)) 0)) menu)
1999                                sublists))
2000           (setq i (1+ i))
2001           (setq menu next))
2002         (nreverse sublists))
2003     ;; Few elements--put them all in one pane.
2004     menu))
2005
2006 (defun gnus-summary-make-menu-bar ()
2007   (gnus-turn-off-edit-menu 'summary)
2008
2009   (unless (boundp 'gnus-summary-misc-menu)
2010
2011     (easy-menu-define
2012      gnus-summary-kill-menu gnus-summary-mode-map ""
2013      (cons
2014       "Score"
2015       (nconc
2016        (list
2017         ["Customize" gnus-score-customize t])
2018        (gnus-make-score-map 'increase)
2019        (gnus-make-score-map 'lower)
2020        '(("Mark"
2021           ["Kill below" gnus-summary-kill-below t]
2022           ["Mark above" gnus-summary-mark-above t]
2023           ["Tick above" gnus-summary-tick-above t]
2024           ["Clear above" gnus-summary-clear-above t])
2025          ["Current score" gnus-summary-current-score t]
2026          ["Set score" gnus-summary-set-score t]
2027          ["Switch current score file..." gnus-score-change-score-file t]
2028          ["Set mark below..." gnus-score-set-mark-below t]
2029          ["Set expunge below..." gnus-score-set-expunge-below t]
2030          ["Edit current score file" gnus-score-edit-current-scores t]
2031          ["Edit score file" gnus-score-edit-file t]
2032          ["Trace score" gnus-score-find-trace t]
2033          ["Find words" gnus-score-find-favourite-words t]
2034          ["Rescore buffer" gnus-summary-rescore t]
2035          ["Increase score..." gnus-summary-increase-score t]
2036          ["Lower score..." gnus-summary-lower-score t]))))
2037
2038     ;; Define both the Article menu in the summary buffer and the
2039     ;; equivalent Commands menu in the article buffer here for
2040     ;; consistency.
2041     (let ((innards
2042            `(("Hide"
2043               ["All" gnus-article-hide t]
2044               ["Headers" gnus-article-hide-headers t]
2045               ["Signature" gnus-article-hide-signature t]
2046               ["Citation" gnus-article-hide-citation t]
2047               ["List identifiers" gnus-article-hide-list-identifiers t]
2048               ["Banner" gnus-article-strip-banner t]
2049               ["Boring headers" gnus-article-hide-boring-headers t])
2050              ("Highlight"
2051               ["All" gnus-article-highlight t]
2052               ["Headers" gnus-article-highlight-headers t]
2053               ["Signature" gnus-article-highlight-signature t]
2054               ["Citation" gnus-article-highlight-citation t])
2055              ("Date"
2056               ["Local" gnus-article-date-local t]
2057               ["ISO8601" gnus-article-date-iso8601 t]
2058               ["UT" gnus-article-date-ut t]
2059               ["Original" gnus-article-date-original t]
2060               ["Lapsed" gnus-article-date-lapsed t]
2061               ["User-defined" gnus-article-date-user t])
2062              ("Display"
2063               ["Remove images" gnus-article-remove-images t]
2064               ["Toggle smiley" gnus-treat-smiley t]
2065               ["Show X-Face" gnus-article-display-x-face t]
2066               ["Show picons in From" gnus-treat-from-picon t]
2067               ["Show picons in mail headers" gnus-treat-mail-picon t]
2068               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2069               ("View as different encoding"
2070                ,@(gnus-summary-menu-split
2071                   (mapcar
2072                    (lambda (cs)
2073                      ;; Since easymenu under FSF Emacs doesn't allow lambda
2074                      ;; forms for menu commands, we should provide intern'ed
2075                      ;; function symbols.
2076                      (let ((command (intern (format "\
2077 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2078                        (fset command
2079                              `(lambda ()
2080                                 (interactive)
2081                                 (let ((gnus-summary-show-article-charset-alist
2082                                        '((1 . ,cs))))
2083                                   (gnus-summary-show-article 1))))
2084                        `[,(symbol-name cs) ,command t]))
2085                    (sort (if (fboundp 'coding-system-list)
2086                              (coding-system-list)
2087                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2088                            )
2089                          'string<)))))
2090              ("Washing"
2091               ("Remove Blanks"
2092                ["Leading" gnus-article-strip-leading-blank-lines t]
2093                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2094                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2095                ["All of the above" gnus-article-strip-blank-lines t]
2096                ["All" gnus-article-strip-all-blank-lines t]
2097                ["Leading space" gnus-article-strip-leading-space t]
2098                ["Trailing space" gnus-article-strip-trailing-space t]
2099                ["Leading space in headers"
2100                 gnus-article-remove-leading-whitespace t])
2101               ["Overstrike" gnus-article-treat-overstrike t]
2102               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2103               ["Emphasis" gnus-article-emphasize t]
2104               ["Word wrap" gnus-article-fill-cited-article t]
2105               ["Fill long lines" gnus-article-fill-long-lines t]
2106               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2107               ["CR" gnus-article-remove-cr t]
2108               ["Rot 13" gnus-summary-caesar-message
2109                ,@(if (featurep 'xemacs) '(t)
2110                    '(:help "\"Caesar rotate\" article by 13"))]
2111               ["Morse decode" gnus-summary-morse-message t]
2112               ["Unix pipe..." gnus-summary-pipe-message t]
2113               ["Add buttons" gnus-article-add-buttons t]
2114               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2115               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2116               ["Toggle MIME" gnus-summary-toggle-mime t]
2117               ["Verbose header" gnus-summary-verbose-headers t]
2118               ["Toggle header" gnus-summary-toggle-header t]
2119               ["Unfold headers" gnus-article-treat-unfold-headers t]
2120               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2121               ["Html" gnus-article-wash-html t]
2122               ["URLs" gnus-article-unsplit-urls t]
2123               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2124               ["HZ" gnus-article-decode-HZ t]
2125               ("(Outlook) Deuglify"
2126                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2127                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2128                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2129                ["Full (Outlook) deuglify"
2130                 gnus-article-outlook-deuglify-article t])
2131               )
2132              ("Output"
2133               ["Save in default format" gnus-summary-save-article
2134                ,@(if (featurep 'xemacs) '(t)
2135                    '(:help "Save article using default method"))]
2136               ["Save in file" gnus-summary-save-article-file
2137                ,@(if (featurep 'xemacs) '(t)
2138                    '(:help "Save article in file"))]
2139               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2140               ["Save in MH folder" gnus-summary-save-article-folder t]
2141               ["Save in VM folder" gnus-summary-save-article-vm t]
2142               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2143               ["Save body in file" gnus-summary-save-article-body-file t]
2144               ["Pipe through a filter" gnus-summary-pipe-output t]
2145               ["Add to SOUP packet" gnus-soup-add-article t]
2146               ["Print with Muttprint" gnus-summary-muttprint t]
2147               ["Print" gnus-summary-print-article t])
2148              ("Backend"
2149               ["Respool article..." gnus-summary-respool-article t]
2150               ["Move article..." gnus-summary-move-article
2151                (gnus-check-backend-function
2152                 'request-move-article gnus-newsgroup-name)]
2153               ["Copy article..." gnus-summary-copy-article t]
2154               ["Crosspost article..." gnus-summary-crosspost-article
2155                (gnus-check-backend-function
2156                 'request-replace-article gnus-newsgroup-name)]
2157               ["Import file..." gnus-summary-import-article t]
2158               ["Create article..." gnus-summary-create-article t]
2159               ["Check if posted" gnus-summary-article-posted-p t]
2160               ["Edit article" gnus-summary-edit-article
2161                (not (gnus-group-read-only-p))]
2162               ["Delete article" gnus-summary-delete-article
2163                (gnus-check-backend-function
2164                 'request-expire-articles gnus-newsgroup-name)]
2165               ["Query respool" gnus-summary-respool-query t]
2166               ["Trace respool" gnus-summary-respool-trace t]
2167               ["Delete expirable articles" gnus-summary-expire-articles-now
2168                (gnus-check-backend-function
2169                 'request-expire-articles gnus-newsgroup-name)])
2170              ("Extract"
2171               ["Uudecode" gnus-uu-decode-uu
2172                ,@(if (featurep 'xemacs) '(t)
2173                    '(:help "Decode uuencoded article(s)"))]
2174               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2175               ["Unshar" gnus-uu-decode-unshar t]
2176               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2177               ["Save" gnus-uu-decode-save t]
2178               ["Binhex" gnus-uu-decode-binhex t]
2179               ["Postscript" gnus-uu-decode-postscript t])
2180              ("Cache"
2181               ["Enter article" gnus-cache-enter-article t]
2182               ["Remove article" gnus-cache-remove-article t])
2183              ["Translate" gnus-article-babel t]
2184              ["Select article buffer" gnus-summary-select-article-buffer t]
2185              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2186              ["Isearch article..." gnus-summary-isearch-article t]
2187              ["Beginning of the article" gnus-summary-beginning-of-article t]
2188              ["End of the article" gnus-summary-end-of-article t]
2189              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2190              ["Fetch referenced articles" gnus-summary-refer-references t]
2191              ["Fetch current thread" gnus-summary-refer-thread t]
2192              ["Fetch article with id..." gnus-summary-refer-article t]
2193              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2194              ["Redisplay" gnus-summary-show-article t]
2195              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2196       (easy-menu-define
2197        gnus-summary-article-menu gnus-summary-mode-map ""
2198        (cons "Article" innards))
2199
2200       (if (not (keymapp gnus-summary-article-menu))
2201           (easy-menu-define
2202            gnus-article-commands-menu gnus-article-mode-map ""
2203            (cons "Commands" innards))
2204         ;; in Emacs, don't share menu.
2205         (setq gnus-article-commands-menu
2206               (copy-keymap gnus-summary-article-menu))
2207         (define-key gnus-article-mode-map [menu-bar commands]
2208           (cons "Commands" gnus-article-commands-menu))))
2209
2210     (easy-menu-define
2211      gnus-summary-thread-menu gnus-summary-mode-map ""
2212      '("Threads"
2213        ["Find all messages in thread" gnus-summary-refer-thread t]
2214        ["Toggle threading" gnus-summary-toggle-threads t]
2215        ["Hide threads" gnus-summary-hide-all-threads t]
2216        ["Show threads" gnus-summary-show-all-threads t]
2217        ["Hide thread" gnus-summary-hide-thread t]
2218        ["Show thread" gnus-summary-show-thread t]
2219        ["Go to next thread" gnus-summary-next-thread t]
2220        ["Go to previous thread" gnus-summary-prev-thread t]
2221        ["Go down thread" gnus-summary-down-thread t]
2222        ["Go up thread" gnus-summary-up-thread t]
2223        ["Top of thread" gnus-summary-top-thread t]
2224        ["Mark thread as read" gnus-summary-kill-thread t]
2225        ["Lower thread score" gnus-summary-lower-thread t]
2226        ["Raise thread score" gnus-summary-raise-thread t]
2227        ["Rethread current" gnus-summary-rethread-current t]))
2228
2229     (easy-menu-define
2230      gnus-summary-post-menu gnus-summary-mode-map ""
2231      `("Post"
2232        ["Send a message (mail or news)" gnus-summary-post-news
2233         ,@(if (featurep 'xemacs) '(t)
2234             '(:help "Post an article"))]
2235        ["Followup" gnus-summary-followup
2236         ,@(if (featurep 'xemacs) '(t)
2237             '(:help "Post followup to this article"))]
2238        ["Followup and yank" gnus-summary-followup-with-original
2239         ,@(if (featurep 'xemacs) '(t)
2240             '(:help "Post followup to this article, quoting its contents"))]
2241        ["Supersede article" gnus-summary-supersede-article t]
2242        ["Cancel article" gnus-summary-cancel-article
2243         ,@(if (featurep 'xemacs) '(t)
2244             '(:help "Cancel an article you posted"))]
2245        ["Reply" gnus-summary-reply t]
2246        ["Reply and yank" gnus-summary-reply-with-original t]
2247        ["Wide reply" gnus-summary-wide-reply t]
2248        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2249         ,@(if (featurep 'xemacs) '(t)
2250             '(:help "Mail a reply, quoting this article"))]
2251        ["Very wide reply" gnus-summary-very-wide-reply t]
2252        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2253         ,@(if (featurep 'xemacs) '(t)
2254             '(:help "Mail a very wide reply, quoting this article"))]
2255        ["Mail forward" gnus-summary-mail-forward t]
2256        ["Post forward" gnus-summary-post-forward t]
2257        ["Digest and mail" gnus-summary-digest-mail-forward t]
2258        ["Digest and post" gnus-summary-digest-post-forward t]
2259        ["Resend message" gnus-summary-resend-message t]
2260        ["Resend message edit" gnus-summary-resend-message-edit t]
2261        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2262        ["Send a mail" gnus-summary-mail-other-window t]
2263        ["Create a local message" gnus-summary-news-other-window t]
2264        ["Uuencode and post" gnus-uu-post-news
2265         ,@(if (featurep 'xemacs) '(t)
2266             '(:help "Post a uuencoded article"))]
2267        ["Followup via news" gnus-summary-followup-to-mail t]
2268        ["Followup via news and yank"
2269         gnus-summary-followup-to-mail-with-original t]
2270        ;;("Draft"
2271        ;;["Send" gnus-summary-send-draft t]
2272        ;;["Send bounced" gnus-resend-bounced-mail t])
2273        ))
2274
2275     (cond
2276      ((not (keymapp gnus-summary-post-menu))
2277       (setq gnus-article-post-menu gnus-summary-post-menu))
2278      ((not gnus-article-post-menu)
2279       ;; Don't share post menu.
2280       (setq gnus-article-post-menu
2281             (copy-keymap gnus-summary-post-menu))))
2282     (define-key gnus-article-mode-map [menu-bar post]
2283       (cons "Post" gnus-article-post-menu))
2284
2285     (easy-menu-define
2286      gnus-summary-misc-menu gnus-summary-mode-map ""
2287      `("Gnus"
2288        ("Mark Read"
2289         ["Mark as read" gnus-summary-mark-as-read-forward t]
2290         ["Mark same subject and select"
2291          gnus-summary-kill-same-subject-and-select t]
2292         ["Mark same subject" gnus-summary-kill-same-subject t]
2293         ["Catchup" gnus-summary-catchup
2294          ,@(if (featurep 'xemacs) '(t)
2295              '(:help "Mark unread articles in this group as read"))]
2296         ["Catchup all" gnus-summary-catchup-all t]
2297         ["Catchup to here" gnus-summary-catchup-to-here t]
2298         ["Catchup from here" gnus-summary-catchup-from-here t]
2299         ["Catchup region" gnus-summary-mark-region-as-read
2300          (gnus-mark-active-p)]
2301         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2302        ("Mark Various"
2303         ["Tick" gnus-summary-tick-article-forward t]
2304         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2305         ["Remove marks" gnus-summary-clear-mark-forward t]
2306         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2307         ["Set bookmark" gnus-summary-set-bookmark t]
2308         ["Remove bookmark" gnus-summary-remove-bookmark t])
2309        ("Limit to"
2310         ["Marks..." gnus-summary-limit-to-marks t]
2311         ["Subject..." gnus-summary-limit-to-subject t]
2312         ["Author..." gnus-summary-limit-to-author t]
2313         ["Age..." gnus-summary-limit-to-age t]
2314         ["Extra..." gnus-summary-limit-to-extra t]
2315         ["Score..." gnus-summary-limit-to-score t]
2316         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2317         ["Unread" gnus-summary-limit-to-unread t]
2318         ["Unseen" gnus-summary-limit-to-unseen t]
2319         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2320         ["Next articles" gnus-summary-limit-to-articles t]
2321         ["Pop limit" gnus-summary-pop-limit t]
2322         ["Show dormant" gnus-summary-limit-include-dormant t]
2323         ["Hide childless dormant"
2324          gnus-summary-limit-exclude-childless-dormant t]
2325         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2326         ["Hide marked" gnus-summary-limit-exclude-marks t]
2327         ["Show expunged" gnus-summary-limit-include-expunged t])
2328        ("Process Mark"
2329         ["Set mark" gnus-summary-mark-as-processable t]
2330         ["Remove mark" gnus-summary-unmark-as-processable t]
2331         ["Remove all marks" gnus-summary-unmark-all-processable t]
2332         ["Mark above" gnus-uu-mark-over t]
2333         ["Mark series" gnus-uu-mark-series t]
2334         ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2335         ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2336         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2337         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2338         ["Mark all" gnus-uu-mark-all t]
2339         ["Mark buffer" gnus-uu-mark-buffer t]
2340         ["Mark sparse" gnus-uu-mark-sparse t]
2341         ["Mark thread" gnus-uu-mark-thread t]
2342         ["Unmark thread" gnus-uu-unmark-thread t]
2343         ("Process Mark Sets"
2344          ["Kill" gnus-summary-kill-process-mark t]
2345          ["Yank" gnus-summary-yank-process-mark
2346           gnus-newsgroup-process-stack]
2347          ["Save" gnus-summary-save-process-mark t]))
2348        ("Scroll article"
2349         ["Page forward" gnus-summary-next-page
2350          ,@(if (featurep 'xemacs) '(t)
2351              '(:help "Show next page of article"))]
2352         ["Page backward" gnus-summary-prev-page
2353          ,@(if (featurep 'xemacs) '(t)
2354              '(:help "Show previous page of article"))]
2355         ["Line forward" gnus-summary-scroll-up t])
2356        ("Move"
2357         ["Next unread article" gnus-summary-next-unread-article t]
2358         ["Previous unread article" gnus-summary-prev-unread-article t]
2359         ["Next article" gnus-summary-next-article t]
2360         ["Previous article" gnus-summary-prev-article t]
2361         ["Next unread subject" gnus-summary-next-unread-subject t]
2362         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2363         ["Next article same subject" gnus-summary-next-same-subject t]
2364         ["Previous article same subject" gnus-summary-prev-same-subject t]
2365         ["First unread article" gnus-summary-first-unread-article t]
2366         ["Best unread article" gnus-summary-best-unread-article t]
2367         ["Go to subject number..." gnus-summary-goto-subject t]
2368         ["Go to article number..." gnus-summary-goto-article t]
2369         ["Go to the last article" gnus-summary-goto-last-article t]
2370         ["Pop article off history" gnus-summary-pop-article t])
2371        ("Sort"
2372         ["Sort by number" gnus-summary-sort-by-number t]
2373         ["Sort by author" gnus-summary-sort-by-author t]
2374         ["Sort by subject" gnus-summary-sort-by-subject t]
2375         ["Sort by date" gnus-summary-sort-by-date t]
2376         ["Sort by score" gnus-summary-sort-by-score t]
2377         ["Sort by lines" gnus-summary-sort-by-lines t]
2378         ["Sort by characters" gnus-summary-sort-by-chars t]
2379         ["Randomize" gnus-summary-sort-by-random t]
2380         ["Original sort" gnus-summary-sort-by-original t])
2381        ("Help"
2382         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2383         ["Describe group" gnus-summary-describe-group t]
2384         ["Fetch charter" gnus-group-fetch-charter
2385          ,@(if (featurep 'xemacs) nil
2386              '(:help "Display the charter of the current group"))]
2387         ["Fetch control message" gnus-group-fetch-control
2388          ,@(if (featurep 'xemacs) nil
2389              '(:help "Display the archived control message for the current group"))]
2390         ["Read manual" gnus-info-find-node t])
2391        ("Modes"
2392         ["Pick and read" gnus-pick-mode t]
2393         ["Binary" gnus-binary-mode t])
2394        ("Regeneration"
2395         ["Regenerate" gnus-summary-prepare t]
2396         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2397         ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2398         ["Toggle threading" gnus-summary-toggle-threads t])
2399        ["See old articles" gnus-summary-insert-old-articles t]
2400        ["See new articles" gnus-summary-insert-new-articles t]
2401        ["Filter articles..." gnus-summary-execute-command t]
2402        ["Run command on subjects..." gnus-summary-universal-argument t]
2403        ["Search articles forward..." gnus-summary-search-article-forward t]
2404        ["Search articles backward..." gnus-summary-search-article-backward t]
2405        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2406        ["Expand window" gnus-summary-expand-window t]
2407        ["Expire expirable articles" gnus-summary-expire-articles
2408         (gnus-check-backend-function
2409          'request-expire-articles gnus-newsgroup-name)]
2410        ["Edit local kill file" gnus-summary-edit-local-kill t]
2411        ["Edit main kill file" gnus-summary-edit-global-kill t]
2412        ["Edit group parameters" gnus-summary-edit-parameters t]
2413        ["Customize group parameters" gnus-summary-customize-parameters t]
2414        ["Send a bug report" gnus-bug t]
2415        ("Exit"
2416         ["Catchup and exit" gnus-summary-catchup-and-exit
2417          ,@(if (featurep 'xemacs) '(t)
2418              '(:help "Mark unread articles in this group as read, then exit"))]
2419         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2420         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2421         ["Exit group" gnus-summary-exit
2422          ,@(if (featurep 'xemacs) '(t)
2423              '(:help "Exit current group, return to group selection mode"))]
2424         ["Exit group without updating" gnus-summary-exit-no-update t]
2425         ["Exit and goto next group" gnus-summary-next-group t]
2426         ["Exit and goto prev group" gnus-summary-prev-group t]
2427         ["Reselect group" gnus-summary-reselect-current-group t]
2428         ["Rescan group" gnus-summary-rescan-group t]
2429         ["Update dribble" gnus-summary-save-newsrc t])))
2430
2431     (gnus-run-hooks 'gnus-summary-menu-hook)))
2432
2433 (defvar gnus-summary-tool-bar-map nil)
2434
2435 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2436 (defun gnus-summary-make-tool-bar ()
2437   (if (and (fboundp 'tool-bar-add-item-from-menu)
2438            (default-value 'tool-bar-mode)
2439            (not gnus-summary-tool-bar-map))
2440       (setq gnus-summary-tool-bar-map
2441             (let ((tool-bar-map (make-sparse-keymap))
2442                   (load-path (mm-image-load-path)))
2443               (tool-bar-add-item-from-menu
2444                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2445               (tool-bar-add-item-from-menu
2446                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2447               (tool-bar-add-item-from-menu
2448                'gnus-summary-post-news "post" gnus-summary-mode-map)
2449               (tool-bar-add-item-from-menu
2450                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2451               (tool-bar-add-item-from-menu
2452                'gnus-summary-followup "followup" gnus-summary-mode-map)
2453               (tool-bar-add-item-from-menu
2454                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2455               (tool-bar-add-item-from-menu
2456                'gnus-summary-reply "reply" gnus-summary-mode-map)
2457               (tool-bar-add-item-from-menu
2458                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2459               (tool-bar-add-item-from-menu
2460                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2461               (tool-bar-add-item-from-menu
2462                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2463               (tool-bar-add-item-from-menu
2464                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2465               (tool-bar-add-item-from-menu
2466                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2467               (tool-bar-add-item-from-menu
2468                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2469               (tool-bar-add-item-from-menu
2470                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2471               (tool-bar-add-item-from-menu
2472                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2473               tool-bar-map)))
2474   (if gnus-summary-tool-bar-map
2475       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2476
2477 (defun gnus-score-set-default (var value)
2478   "A version of set that updates the GNU Emacs menu-bar."
2479   (set var value)
2480   ;; It is the message that forces the active status to be updated.
2481   (message ""))
2482
2483 (defun gnus-make-score-map (type)
2484   "Make a summary score map of type TYPE."
2485   (if t
2486       nil
2487     (let ((headers '(("author" "from" string)
2488                      ("subject" "subject" string)
2489                      ("article body" "body" string)
2490                      ("article head" "head" string)
2491                      ("xref" "xref" string)
2492                      ("extra header" "extra" string)
2493                      ("lines" "lines" number)
2494                      ("followups to author" "followup" string)))
2495           (types '((number ("less than" <)
2496                            ("greater than" >)
2497                            ("equal" =))
2498                    (string ("substring" s)
2499                            ("exact string" e)
2500                            ("fuzzy string" f)
2501                            ("regexp" r))))
2502           (perms '(("temporary" (current-time-string))
2503                    ("permanent" nil)
2504                    ("immediate" now)))
2505           header)
2506       (list
2507        (apply
2508         'nconc
2509         (list
2510          (if (eq type 'lower)
2511              "Lower score"
2512            "Increase score"))
2513         (let (outh)
2514           (while headers
2515             (setq header (car headers))
2516             (setq outh
2517                   (cons
2518                    (apply
2519                     'nconc
2520                     (list (car header))
2521                     (let ((ts (cdr (assoc (nth 2 header) types)))
2522                           outt)
2523                       (while ts
2524                         (setq outt
2525                               (cons
2526                                (apply
2527                                 'nconc
2528                                 (list (caar ts))
2529                                 (let ((ps perms)
2530                                       outp)
2531                                   (while ps
2532                                     (setq outp
2533                                           (cons
2534                                            (vector
2535                                             (caar ps)
2536                                             (list
2537                                              'gnus-summary-score-entry
2538                                              (nth 1 header)
2539                                              (if (or (string= (nth 1 header)
2540                                                               "head")
2541                                                      (string= (nth 1 header)
2542                                                               "body"))
2543                                                  ""
2544                                                (list 'gnus-summary-header
2545                                                      (nth 1 header)))
2546                                              (list 'quote (nth 1 (car ts)))
2547                                              (list 'gnus-score-delta-default
2548                                                    nil)
2549                                              (nth 1 (car ps))
2550                                              t)
2551                                             t)
2552                                            outp))
2553                                     (setq ps (cdr ps)))
2554                                   (list (nreverse outp))))
2555                                outt))
2556                         (setq ts (cdr ts)))
2557                       (list (nreverse outt))))
2558                    outh))
2559             (setq headers (cdr headers)))
2560           (list (nreverse outh))))))))
2561
2562 \f
2563
2564 (defun gnus-summary-mode (&optional group)
2565   "Major mode for reading articles.
2566
2567 All normal editing commands are switched off.
2568 \\<gnus-summary-mode-map>
2569 Each line in this buffer represents one article.  To read an
2570 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2571 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2572 respectively.
2573
2574 You can also post articles and send mail from this buffer.  To
2575 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2576 of an article, type `\\[gnus-summary-reply]'.
2577
2578 There are approx. one gazillion commands you can execute in this
2579 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2580
2581 The following commands are available:
2582
2583 \\{gnus-summary-mode-map}"
2584   (interactive)
2585   (kill-all-local-variables)
2586   (when (gnus-visual-p 'summary-menu 'menu)
2587     (gnus-summary-make-menu-bar)
2588     (gnus-summary-make-tool-bar))
2589   (gnus-summary-make-local-variables)
2590   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2591     (gnus-summary-make-local-variables))
2592   (gnus-make-thread-indent-array)
2593   (gnus-simplify-mode-line)
2594   (setq major-mode 'gnus-summary-mode)
2595   (setq mode-name "Summary")
2596   (make-local-variable 'minor-mode-alist)
2597   (use-local-map gnus-summary-mode-map)
2598   (buffer-disable-undo)
2599   (setq buffer-read-only t)             ;Disable modification
2600   (setq truncate-lines t)
2601   (setq selective-display t)
2602   (setq selective-display-ellipses t)   ;Display `...'
2603   (gnus-summary-set-display-table)
2604   (gnus-set-default-directory)
2605   (setq gnus-newsgroup-name group)
2606   (unless (gnus-news-group-p group)
2607     (setq gnus-newsgroup-incorporated
2608           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2609   (make-local-variable 'gnus-summary-line-format)
2610   (make-local-variable 'gnus-summary-line-format-spec)
2611   (make-local-variable 'gnus-summary-dummy-line-format)
2612   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2613   (make-local-variable 'gnus-summary-mark-positions)
2614   (make-local-hook 'pre-command-hook)
2615   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2616   (gnus-run-hooks 'gnus-summary-mode-hook)
2617   (turn-on-gnus-mailing-list-mode)
2618   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2619   (gnus-update-summary-mark-positions))
2620
2621 (defun gnus-summary-make-local-variables ()
2622   "Make all the local summary buffer variables."
2623   (let (global)
2624     (dolist (local gnus-summary-local-variables)
2625       (if (consp local)
2626           (progn
2627             (if (eq (cdr local) 'global)
2628                 ;; Copy the global value of the variable.
2629                 (setq global (symbol-value (car local)))
2630               ;; Use the value from the list.
2631               (setq global (eval (cdr local))))
2632             (set (make-local-variable (car local)) global))
2633         ;; Simple nil-valued local variable.
2634         (set (make-local-variable local) nil)))))
2635
2636 (defun gnus-summary-clear-local-variables ()
2637   (let ((locals gnus-summary-local-variables))
2638     (while locals
2639       (if (consp (car locals))
2640           (and (vectorp (caar locals))
2641                (set (caar locals) nil))
2642         (and (vectorp (car locals))
2643              (set (car locals) nil)))
2644       (setq locals (cdr locals)))))
2645
2646 ;; Summary data functions.
2647
2648 (defmacro gnus-data-number (data)
2649   `(car ,data))
2650
2651 (defmacro gnus-data-set-number (data number)
2652   `(setcar ,data ,number))
2653
2654 (defmacro gnus-data-mark (data)
2655   `(nth 1 ,data))
2656
2657 (defmacro gnus-data-set-mark (data mark)
2658   `(setcar (nthcdr 1 ,data) ,mark))
2659
2660 (defmacro gnus-data-pos (data)
2661   `(nth 2 ,data))
2662
2663 (defmacro gnus-data-set-pos (data pos)
2664   `(setcar (nthcdr 2 ,data) ,pos))
2665
2666 (defmacro gnus-data-header (data)
2667   `(nth 3 ,data))
2668
2669 (defmacro gnus-data-set-header (data header)
2670   `(setcar (nthcdr 3 ,data) ,header))
2671
2672 (defmacro gnus-data-level (data)
2673   `(nth 4 ,data))
2674
2675 (defmacro gnus-data-unread-p (data)
2676   `(= (nth 1 ,data) gnus-unread-mark))
2677
2678 (defmacro gnus-data-read-p (data)
2679   `(/= (nth 1 ,data) gnus-unread-mark))
2680
2681 (defmacro gnus-data-pseudo-p (data)
2682   `(consp (nth 3 ,data)))
2683
2684 (defmacro gnus-data-find (number)
2685   `(assq ,number gnus-newsgroup-data))
2686
2687 (defmacro gnus-data-find-list (number &optional data)
2688   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2689      (memq (assq ,number bdata)
2690            bdata)))
2691
2692 (defmacro gnus-data-make (number mark pos header level)
2693   `(list ,number ,mark ,pos ,header ,level))
2694
2695 (defun gnus-data-enter (after-article number mark pos header level offset)
2696   (let ((data (gnus-data-find-list after-article)))
2697     (unless data
2698       (error "No such article: %d" after-article))
2699     (setcdr data (cons (gnus-data-make number mark pos header level)
2700                        (cdr data)))
2701     (setq gnus-newsgroup-data-reverse nil)
2702     (gnus-data-update-list (cddr data) offset)))
2703
2704 (defun gnus-data-enter-list (after-article list &optional offset)
2705   (when list
2706     (let ((data (and after-article (gnus-data-find-list after-article)))
2707           (ilist list))
2708       (if (not (or data
2709                    after-article))
2710           (let ((odata gnus-newsgroup-data))
2711             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2712             (when offset
2713               (gnus-data-update-list odata offset)))
2714         ;; Find the last element in the list to be spliced into the main
2715         ;; list.
2716         (while (cdr list)
2717           (setq list (cdr list)))
2718         (if (not data)
2719             (progn
2720               (setcdr list gnus-newsgroup-data)
2721               (setq gnus-newsgroup-data ilist)
2722               (when offset
2723                 (gnus-data-update-list (cdr list) offset)))
2724           (setcdr list (cdr data))
2725           (setcdr data ilist)
2726           (when offset
2727             (gnus-data-update-list (cdr list) offset))))
2728       (setq gnus-newsgroup-data-reverse nil))))
2729
2730 (defun gnus-data-remove (article &optional offset)
2731   (let ((data gnus-newsgroup-data))
2732     (if (= (gnus-data-number (car data)) article)
2733         (progn
2734           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2735                 gnus-newsgroup-data-reverse nil)
2736           (when offset
2737             (gnus-data-update-list gnus-newsgroup-data offset)))
2738       (while (cdr data)
2739         (when (= (gnus-data-number (cadr data)) article)
2740           (setcdr data (cddr data))
2741           (when offset
2742             (gnus-data-update-list (cdr data) offset))
2743           (setq data nil
2744                 gnus-newsgroup-data-reverse nil))
2745         (setq data (cdr data))))))
2746
2747 (defmacro gnus-data-list (backward)
2748   `(if ,backward
2749        (or gnus-newsgroup-data-reverse
2750            (setq gnus-newsgroup-data-reverse
2751                  (reverse gnus-newsgroup-data)))
2752      gnus-newsgroup-data))
2753
2754 (defun gnus-data-update-list (data offset)
2755   "Add OFFSET to the POS of all data entries in DATA."
2756   (setq gnus-newsgroup-data-reverse nil)
2757   (while data
2758     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2759     (setq data (cdr data))))
2760
2761 (defun gnus-summary-article-pseudo-p (article)
2762   "Say whether this article is a pseudo article or not."
2763   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2764
2765 (defmacro gnus-summary-article-sparse-p (article)
2766   "Say whether this article is a sparse article or not."
2767   `(memq ,article gnus-newsgroup-sparse))
2768
2769 (defmacro gnus-summary-article-ancient-p (article)
2770   "Say whether this article is a sparse article or not."
2771   `(memq ,article gnus-newsgroup-ancient))
2772
2773 (defun gnus-article-parent-p (number)
2774   "Say whether this article is a parent or not."
2775   (let ((data (gnus-data-find-list number)))
2776     (and (cdr data)                     ; There has to be an article after...
2777          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2778             (gnus-data-level (nth 1 data))))))
2779
2780 (defun gnus-article-children (number)
2781   "Return a list of all children to NUMBER."
2782   (let* ((data (gnus-data-find-list number))
2783          (level (gnus-data-level (car data)))
2784          children)
2785     (setq data (cdr data))
2786     (while (and data
2787                 (= (gnus-data-level (car data)) (1+ level)))
2788       (push (gnus-data-number (car data)) children)
2789       (setq data (cdr data)))
2790     children))
2791
2792 (defmacro gnus-summary-skip-intangible ()
2793   "If the current article is intangible, then jump to a different article."
2794   '(let ((to (get-text-property (point) 'gnus-intangible)))
2795      (and to (gnus-summary-goto-subject to))))
2796
2797 (defmacro gnus-summary-article-intangible-p ()
2798   "Say whether this article is intangible or not."
2799   '(get-text-property (point) 'gnus-intangible))
2800
2801 (defun gnus-article-read-p (article)
2802   "Say whether ARTICLE is read or not."
2803   (not (or (memq article gnus-newsgroup-marked)
2804            (memq article gnus-newsgroup-spam-marked)
2805            (memq article gnus-newsgroup-unreads)
2806            (memq article gnus-newsgroup-unselected)
2807            (memq article gnus-newsgroup-dormant))))
2808
2809 ;; Some summary mode macros.
2810
2811 (defmacro gnus-summary-article-number ()
2812   "The article number of the article on the current line.
2813 If there isn't an article number here, then we return the current
2814 article number."
2815   '(progn
2816      (gnus-summary-skip-intangible)
2817      (or (get-text-property (point) 'gnus-number)
2818          (gnus-summary-last-subject))))
2819
2820 (defmacro gnus-summary-article-header (&optional number)
2821   "Return the header of article NUMBER."
2822   `(gnus-data-header (gnus-data-find
2823                       ,(or number '(gnus-summary-article-number)))))
2824
2825 (defmacro gnus-summary-thread-level (&optional number)
2826   "Return the level of thread that starts with article NUMBER."
2827   `(if (and (eq gnus-summary-make-false-root 'dummy)
2828             (get-text-property (point) 'gnus-intangible))
2829        0
2830      (gnus-data-level (gnus-data-find
2831                        ,(or number '(gnus-summary-article-number))))))
2832
2833 (defmacro gnus-summary-article-mark (&optional number)
2834   "Return the mark of article NUMBER."
2835   `(gnus-data-mark (gnus-data-find
2836                     ,(or number '(gnus-summary-article-number)))))
2837
2838 (defmacro gnus-summary-article-pos (&optional number)
2839   "Return the position of the line of article NUMBER."
2840   `(gnus-data-pos (gnus-data-find
2841                    ,(or number '(gnus-summary-article-number)))))
2842
2843 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2844 (defmacro gnus-summary-article-subject (&optional number)
2845   "Return current subject string or nil if nothing."
2846   `(let ((headers
2847           ,(if number
2848                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2849              '(gnus-data-header (assq (gnus-summary-article-number)
2850                                       gnus-newsgroup-data)))))
2851      (and headers
2852           (vectorp headers)
2853           (mail-header-subject headers))))
2854
2855 (defmacro gnus-summary-article-score (&optional number)
2856   "Return current article score."
2857   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2858                   gnus-newsgroup-scored))
2859        gnus-summary-default-score 0))
2860
2861 (defun gnus-summary-article-children (&optional number)
2862   "Return a list of article numbers that are children of article NUMBER."
2863   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2864          (level (gnus-data-level (car data)))
2865          l children)
2866     (while (and (setq data (cdr data))
2867                 (> (setq l (gnus-data-level (car data))) level))
2868       (and (= (1+ level) l)
2869            (push (gnus-data-number (car data))
2870                  children)))
2871     (nreverse children)))
2872
2873 (defun gnus-summary-article-parent (&optional number)
2874   "Return the article number of the parent of article NUMBER."
2875   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2876                                     (gnus-data-list t)))
2877          (level (gnus-data-level (car data))))
2878     (if (zerop level)
2879         ()                              ; This is a root.
2880       ;; We search until we find an article with a level less than
2881       ;; this one.  That function has to be the parent.
2882       (while (and (setq data (cdr data))
2883                   (not (< (gnus-data-level (car data)) level))))
2884       (and data (gnus-data-number (car data))))))
2885
2886 (defun gnus-unread-mark-p (mark)
2887   "Say whether MARK is the unread mark."
2888   (= mark gnus-unread-mark))
2889
2890 (defun gnus-read-mark-p (mark)
2891   "Say whether MARK is one of the marks that mark as read.
2892 This is all marks except unread, ticked, dormant, and expirable."
2893   (not (or (= mark gnus-unread-mark)
2894            (= mark gnus-ticked-mark)
2895            (= mark gnus-spam-mark)
2896            (= mark gnus-dormant-mark)
2897            (= mark gnus-expirable-mark))))
2898
2899 (defmacro gnus-article-mark (number)
2900   "Return the MARK of article NUMBER.
2901 This macro should only be used when computing the mark the \"first\"
2902 time; i.e., when generating the summary lines.  After that,
2903 `gnus-summary-article-mark' should be used to examine the
2904 marks of articles."
2905   `(cond
2906     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2907     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2908     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2909     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2910     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2911     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2912     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2913     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2914            gnus-ancient-mark))))
2915
2916 ;; Saving hidden threads.
2917
2918 (defmacro gnus-save-hidden-threads (&rest forms)
2919   "Save hidden threads, eval FORMS, and restore the hidden threads."
2920   (let ((config (make-symbol "config")))
2921     `(let ((,config (gnus-hidden-threads-configuration)))
2922        (unwind-protect
2923            (save-excursion
2924              ,@forms)
2925          (gnus-restore-hidden-threads-configuration ,config)))))
2926 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2927 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2928
2929 (defun gnus-data-compute-positions ()
2930   "Compute the positions of all articles."
2931   (setq gnus-newsgroup-data-reverse nil)
2932   (let ((data gnus-newsgroup-data))
2933     (save-excursion
2934       (gnus-save-hidden-threads
2935         (gnus-summary-show-all-threads)
2936         (goto-char (point-min))
2937         (while data
2938           (while (get-text-property (point) 'gnus-intangible)
2939             (forward-line 1))
2940           (gnus-data-set-pos (car data) (+ (point) 3))
2941           (setq data (cdr data))
2942           (forward-line 1))))))
2943
2944 (defun gnus-hidden-threads-configuration ()
2945   "Return the current hidden threads configuration."
2946   (save-excursion
2947     (let (config)
2948       (goto-char (point-min))
2949       (while (search-forward "\r" nil t)
2950         (push (1- (point)) config))
2951       config)))
2952
2953 (defun gnus-restore-hidden-threads-configuration (config)
2954   "Restore hidden threads configuration from CONFIG."
2955   (save-excursion
2956     (let (point buffer-read-only)
2957       (while (setq point (pop config))
2958         (when (and (< point (point-max))
2959                    (goto-char point)
2960                    (eq (char-after) ?\n))
2961           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2962
2963 ;; Various summary mode internalish functions.
2964
2965 (defun gnus-mouse-pick-article (e)
2966   (interactive "e")
2967   (mouse-set-point e)
2968   (gnus-summary-next-page nil t))
2969
2970 (defun gnus-summary-set-display-table ()
2971   "Change the display table.
2972 Odd characters have a tendency to mess
2973 up nicely formatted displays - we make all possible glyphs
2974 display only a single character."
2975
2976   ;; We start from the standard display table, if any.
2977   (let ((table (or (copy-sequence standard-display-table)
2978                    (make-display-table)))
2979         (i 32))
2980     ;; Nix out all the control chars...
2981     (while (>= (setq i (1- i)) 0)
2982       (aset table i [??]))
2983     ;; ... but not newline and cr, of course.  (cr is necessary for the
2984     ;; selective display).
2985     (aset table ?\n nil)
2986     (aset table ?\r nil)
2987     ;; We keep TAB as well.
2988     (aset table ?\t nil)
2989     ;; We nix out any glyphs over 126 that are not set already.
2990     (let ((i 256))
2991       (while (>= (setq i (1- i)) 127)
2992         ;; Only modify if the entry is nil.
2993         (unless (aref table i)
2994           (aset table i [??]))))
2995     (setq buffer-display-table table)))
2996
2997 (defun gnus-summary-set-article-display-arrow (pos)
2998   "Update the overlay arrow to point to line at position POS."
2999   (when (and gnus-summary-display-arrow
3000              (boundp 'overlay-arrow-position)
3001              (boundp 'overlay-arrow-string))
3002     (save-excursion
3003       (goto-char pos)
3004       (beginning-of-line)
3005       (unless overlay-arrow-position
3006         (setq overlay-arrow-position (make-marker)))
3007       (setq overlay-arrow-string "=>"
3008             overlay-arrow-position (set-marker overlay-arrow-position
3009                                                (point)
3010                                                (current-buffer))))))
3011
3012 (defun gnus-summary-buffer-name (group)
3013   "Return the summary buffer name of GROUP."
3014   (concat "*Summary " (gnus-group-decoded-name group) "*"))
3015
3016 (defun gnus-summary-setup-buffer (group)
3017   "Initialize summary buffer."
3018   (let ((buffer (gnus-summary-buffer-name group))
3019         (dead-name (concat "*Dead Summary "
3020                            (gnus-group-decoded-name group) "*")))
3021     ;; If a dead summary buffer exists, we kill it.
3022     (when (gnus-buffer-live-p dead-name)
3023       (gnus-kill-buffer dead-name))
3024     (if (get-buffer buffer)
3025         (progn
3026           (set-buffer buffer)
3027           (setq gnus-summary-buffer (current-buffer))
3028           (not gnus-newsgroup-prepared))
3029       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3030       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3031       (gnus-summary-mode group)
3032       (when gnus-carpal
3033         (gnus-carpal-setup-buffer 'summary))
3034       (unless gnus-single-article-buffer
3035         (make-local-variable 'gnus-article-buffer)
3036         (make-local-variable 'gnus-article-current)
3037         (make-local-variable 'gnus-original-article-buffer))
3038       (setq gnus-newsgroup-name group)
3039       ;; Set any local variables in the group parameters.
3040       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3041       t)))
3042
3043 (defun gnus-set-global-variables ()
3044   "Set the global equivalents of the buffer-local variables.
3045 They are set to the latest values they had.  These reflect the summary
3046 buffer that was in action when the last article was fetched."
3047   (when (eq major-mode 'gnus-summary-mode)
3048     (setq gnus-summary-buffer (current-buffer))
3049     (let ((name gnus-newsgroup-name)
3050           (marked gnus-newsgroup-marked)
3051           (spam gnus-newsgroup-spam-marked)
3052           (unread gnus-newsgroup-unreads)
3053           (headers gnus-current-headers)
3054           (data gnus-newsgroup-data)
3055           (summary gnus-summary-buffer)
3056           (article-buffer gnus-article-buffer)
3057           (original gnus-original-article-buffer)
3058           (gac gnus-article-current)
3059           (reffed gnus-reffed-article-number)
3060           (score-file gnus-current-score-file)
3061           (default-charset gnus-newsgroup-charset)
3062           vlist)
3063       (let ((locals gnus-newsgroup-variables))
3064         (while locals
3065           (if (consp (car locals))
3066               (push (eval (caar locals)) vlist)
3067             (push (eval (car locals)) vlist))
3068           (setq locals (cdr locals)))
3069         (setq vlist (nreverse vlist)))
3070       (save-excursion
3071         (set-buffer gnus-group-buffer)
3072         (setq gnus-newsgroup-name name
3073               gnus-newsgroup-marked marked
3074               gnus-newsgroup-spam-marked spam
3075               gnus-newsgroup-unreads unread
3076               gnus-current-headers headers
3077               gnus-newsgroup-data data
3078               gnus-article-current gac
3079               gnus-summary-buffer summary
3080               gnus-article-buffer article-buffer
3081               gnus-original-article-buffer original
3082               gnus-reffed-article-number reffed
3083               gnus-current-score-file score-file
3084               gnus-newsgroup-charset default-charset)
3085         (let ((locals gnus-newsgroup-variables))
3086           (while locals
3087             (if (consp (car locals))
3088                 (set (caar locals) (pop vlist))
3089               (set (car locals) (pop vlist)))
3090             (setq locals (cdr locals))))
3091         ;; The article buffer also has local variables.
3092         (when (gnus-buffer-live-p gnus-article-buffer)
3093           (set-buffer gnus-article-buffer)
3094           (setq gnus-summary-buffer summary))))))
3095
3096 (defun gnus-summary-article-unread-p (article)
3097   "Say whether ARTICLE is unread or not."
3098   (memq article gnus-newsgroup-unreads))
3099
3100 (defun gnus-summary-first-article-p (&optional article)
3101   "Return whether ARTICLE is the first article in the buffer."
3102   (if (not (setq article (or article (gnus-summary-article-number))))
3103       nil
3104     (eq article (caar gnus-newsgroup-data))))
3105
3106 (defun gnus-summary-last-article-p (&optional article)
3107   "Return whether ARTICLE is the last article in the buffer."
3108   (if (not (setq article (or article (gnus-summary-article-number))))
3109       ;; All non-existent numbers are the last article.  :-)
3110       t
3111     (not (cdr (gnus-data-find-list article)))))
3112
3113 (defun gnus-make-thread-indent-array ()
3114   (let ((n 200))
3115     (unless (and gnus-thread-indent-array
3116                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3117       (setq gnus-thread-indent-array (make-vector 201 "")
3118             gnus-thread-indent-array-level gnus-thread-indent-level)
3119       (while (>= n 0)
3120         (aset gnus-thread-indent-array n
3121               (make-string (* n gnus-thread-indent-level) ? ))
3122         (setq n (1- n))))))
3123
3124 (defun gnus-update-summary-mark-positions ()
3125   "Compute where the summary marks are to go."
3126   (save-excursion
3127     (when (gnus-buffer-exists-p gnus-summary-buffer)
3128       (set-buffer gnus-summary-buffer))
3129     (let ((gnus-replied-mark 129)
3130           (gnus-score-below-mark 130)
3131           (gnus-score-over-mark 130)
3132           (gnus-undownloaded-mark 131)
3133           (spec gnus-summary-line-format-spec)
3134           gnus-visual pos)
3135       (save-excursion
3136         (gnus-set-work-buffer)
3137         (let ((gnus-summary-line-format-spec spec)
3138               (gnus-newsgroup-downloadable '(0)))
3139           (gnus-summary-insert-line
3140            (make-full-mail-header 0 "" "nobody"
3141                                   "05 Apr 2001 23:33:09 +0400"
3142                                   "" "" 0 0 "" nil)
3143            0 nil t 128 t nil "" nil 1)
3144           (goto-char (point-min))
3145           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3146                                              (- (point) (point-min) 1)))))
3147           (goto-char (point-min))
3148           (push (cons 'replied (and (search-forward "\201" nil t)
3149                                     (- (point) (point-min) 1)))
3150                 pos)
3151           (goto-char (point-min))
3152           (push (cons 'score (and (search-forward "\202" nil t)
3153                                   (- (point) (point-min) 1)))
3154                 pos)
3155           (goto-char (point-min))
3156           (push (cons 'download
3157                       (and (search-forward "\203" nil t)
3158                            (- (point) (point-min) 1)))
3159                 pos)))
3160       (setq gnus-summary-mark-positions pos))))
3161
3162 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3163   "Insert a dummy root in the summary buffer."
3164   (beginning-of-line)
3165   (gnus-add-text-properties
3166    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3167    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3168
3169 (defun gnus-summary-extract-address-component (from)
3170   (or (car (funcall gnus-extract-address-components from))
3171       from))
3172
3173 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3174   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3175                                 default-mime-charset)))
3176     ;; Is it really necessary to do this next part for each summary line?
3177     ;; Luckily, doesn't seem to slow things down much.
3178     (or
3179      (and gnus-ignored-from-addresses
3180           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3181           (let ((extra-headers (mail-header-extra header))
3182                 to
3183                 newsgroups)
3184             (cond
3185              ((setq to (cdr (assq 'To extra-headers)))
3186               (concat "-> "
3187                       (inline
3188                         (gnus-summary-extract-address-component
3189                          (funcall gnus-decode-encoded-word-function to)))))
3190              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3191               (concat "=> " newsgroups)))))
3192      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3193
3194 (defun gnus-summary-insert-line (gnus-tmp-header
3195                                  gnus-tmp-level gnus-tmp-current
3196                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3197                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3198                                  &optional gnus-tmp-dummy gnus-tmp-score
3199                                  gnus-tmp-process)
3200   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3201          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3202          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3203          (gnus-tmp-score-char
3204           (if (or (null gnus-summary-default-score)
3205                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3206                       gnus-summary-zcore-fuzz))
3207               ?\ ;;;Whitespace
3208             (if (< gnus-tmp-score gnus-summary-default-score)
3209                 gnus-score-below-mark gnus-score-over-mark)))
3210          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3211          (gnus-tmp-replied
3212           (cond (gnus-tmp-process gnus-process-mark)
3213                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3214                  gnus-cached-mark)
3215                 (gnus-tmp-replied gnus-replied-mark)
3216                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3217                  gnus-forwarded-mark)
3218                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3219                  gnus-saved-mark)
3220                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3221                  gnus-recent-mark)
3222                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3223                  gnus-unseen-mark)
3224                 (t gnus-no-mark)))
3225          (gnus-tmp-downloaded
3226           (cond (undownloaded 
3227                  gnus-undownloaded-mark)
3228                 (gnus-newsgroup-agentized
3229                  gnus-downloaded-mark)
3230                 (t
3231                  gnus-no-mark)))
3232          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3233          (gnus-tmp-name
3234           (cond
3235            ((string-match "<[^>]+> *$" gnus-tmp-from)
3236             (let ((beg (match-beginning 0)))
3237               (or (and (string-match "^\".+\"" gnus-tmp-from)
3238                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3239                   (substring gnus-tmp-from 0 beg))))
3240            ((string-match "(.+)" gnus-tmp-from)
3241             (substring gnus-tmp-from
3242                        (1+ (match-beginning 0)) (1- (match-end 0))))
3243            (t gnus-tmp-from)))
3244          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3245          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3246          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3247          (buffer-read-only nil))
3248     (when (string= gnus-tmp-name "")
3249       (setq gnus-tmp-name gnus-tmp-from))
3250     (unless (numberp gnus-tmp-lines)
3251       (setq gnus-tmp-lines -1))
3252     (if (= gnus-tmp-lines -1)
3253         (setq gnus-tmp-lines "?")
3254       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3255     (gnus-put-text-property-excluding-characters-with-faces
3256      (point)
3257      (progn (eval gnus-summary-line-format-spec) (point))
3258      'gnus-number gnus-tmp-number)
3259     (when (gnus-visual-p 'summary-highlight 'highlight)
3260       (forward-line -1)
3261       (gnus-run-hooks 'gnus-summary-update-hook)
3262       (forward-line 1))))
3263
3264 (defun gnus-summary-update-line (&optional dont-update)
3265   "Update summary line after change."
3266   (when (and gnus-summary-default-score
3267              (not gnus-summary-inhibit-highlight))
3268     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3269            (article (gnus-summary-article-number))
3270            (score (gnus-summary-article-score article)))
3271       (unless dont-update
3272         (if (and gnus-summary-mark-below
3273                  (< (gnus-summary-article-score)
3274                     gnus-summary-mark-below))
3275             ;; This article has a low score, so we mark it as read.
3276             (when (memq article gnus-newsgroup-unreads)
3277               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3278           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3279             ;; This article was previously marked as read on account
3280             ;; of a low score, but now it has risen, so we mark it as
3281             ;; unread.
3282             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3283         (gnus-summary-update-mark
3284          (if (or (null gnus-summary-default-score)
3285                  (<= (abs (- score gnus-summary-default-score))
3286                      gnus-summary-zcore-fuzz))
3287              ?\ ;;;Whitespace
3288            (if (< score gnus-summary-default-score)
3289                gnus-score-below-mark gnus-score-over-mark))
3290          'score))
3291       ;; Do visual highlighting.
3292       (when (gnus-visual-p 'summary-highlight 'highlight)
3293         (gnus-run-hooks 'gnus-summary-update-hook)))))
3294
3295 (defvar gnus-tmp-new-adopts nil)
3296
3297 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3298   "Return the number of articles in THREAD.
3299 This may be 0 in some cases -- if none of the articles in
3300 the thread are to be displayed."
3301   (let* ((number
3302           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3303           (cond
3304            ((not (listp thread))
3305             1)
3306            ((and (consp thread) (cdr thread))
3307             (apply
3308              '+ 1 (mapcar
3309                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3310            ((null thread)
3311             1)
3312            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3313             1)
3314            (t 0))))
3315     (when (and level (zerop level) gnus-tmp-new-adopts)
3316       (incf number
3317             (apply '+ (mapcar
3318                        'gnus-summary-number-of-articles-in-thread
3319                        gnus-tmp-new-adopts))))
3320     (if char
3321         (if (> number 1) gnus-not-empty-thread-mark
3322           gnus-empty-thread-mark)
3323       number)))
3324
3325 (defsubst gnus-summary-line-message-size (head)
3326   "Return pretty-printed version of message size.
3327 This function is intended to be used in
3328 `gnus-summary-line-format-alist', which see."
3329   (let ((c (or (mail-header-chars head) -1)))
3330     (cond ((< c 0) "n/a")               ; chars not available
3331           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3332           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3333           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3334           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3335
3336
3337 (defun gnus-summary-set-local-parameters (group)
3338   "Go through the local params of GROUP and set all variable specs in that list."
3339   (let ((params (gnus-group-find-parameter group))
3340         (vars '(quit-config))           ; Ignore quit-config.
3341         elem)
3342     (while params
3343       (setq elem (car params)
3344             params (cdr params))
3345       (and (consp elem)                 ; Has to be a cons.
3346            (consp (cdr elem))           ; The cdr has to be a list.
3347            (symbolp (car elem))         ; Has to be a symbol in there.
3348            (not (memq (car elem) vars))
3349            (ignore-errors               ; So we set it.
3350              (push (car elem) vars)
3351              (make-local-variable (car elem))
3352              (set (car elem) (eval (nth 1 elem))))))))
3353
3354 (defun gnus-summary-read-group (group &optional show-all no-article
3355                                       kill-buffer no-display backward
3356                                       select-articles)
3357   "Start reading news in newsgroup GROUP.
3358 If SHOW-ALL is non-nil, already read articles are also listed.
3359 If NO-ARTICLE is non-nil, no article is selected initially.
3360 If NO-DISPLAY, don't generate a summary buffer."
3361   (let (result)
3362     (while (and group
3363                 (null (setq result
3364                             (let ((gnus-auto-select-next nil))
3365                               (or (gnus-summary-read-group-1
3366                                    group show-all no-article
3367                                    kill-buffer no-display
3368                                    select-articles)
3369                                   (setq show-all nil
3370                                         select-articles nil)))))
3371                 (eq gnus-auto-select-next 'quietly))
3372       (set-buffer gnus-group-buffer)
3373       ;; The entry function called above goes to the next
3374       ;; group automatically, so we go two groups back
3375       ;; if we are searching for the previous group.
3376       (when backward
3377         (gnus-group-prev-unread-group 2))
3378       (if (not (equal group (gnus-group-group-name)))
3379           (setq group (gnus-group-group-name))
3380         (setq group nil)))
3381     result))
3382
3383 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3384   "Directly jump to the other GROUP from summary buffer.
3385 If SHOW-ALL is non-nil, already read articles are also listed."
3386   (interactive
3387    (if (eq gnus-summary-buffer (current-buffer))
3388        (list (completing-read
3389               "Group: " gnus-active-hashtb nil t
3390               (when (and gnus-newsgroup-name
3391                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3392                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3393               'gnus-group-history)
3394              current-prefix-arg)
3395      (error "%s must be invoked from a gnus summary buffer." this-command)))
3396   (unless (or (zerop (length group))
3397               (and gnus-newsgroup-name
3398                    (string-equal gnus-newsgroup-name group)))
3399     (gnus-summary-exit)
3400     (gnus-summary-read-group group show-all
3401                              gnus-dont-select-after-jump-to-other-group)))
3402
3403 (defun gnus-summary-read-group-1 (group show-all no-article
3404                                         kill-buffer no-display
3405                                         &optional select-articles)
3406   ;; Killed foreign groups can't be entered.
3407   ;;  (when (and (not (gnus-group-native-p group))
3408   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3409   ;;    (error "Dead non-native groups can't be entered"))
3410   (gnus-message 5 "Retrieving newsgroup: %s..."
3411                 (gnus-group-decoded-name group))
3412   (let* ((new-group (gnus-summary-setup-buffer group))
3413          (quit-config (gnus-group-quit-config group))
3414          (did-select (and new-group (gnus-select-newsgroup
3415                                      group show-all select-articles))))
3416     (cond
3417      ;; This summary buffer exists already, so we just select it.
3418      ((not new-group)
3419       (gnus-set-global-variables)
3420       (when kill-buffer
3421         (gnus-kill-or-deaden-summary kill-buffer))
3422       (gnus-configure-windows 'summary 'force)
3423       (gnus-set-mode-line 'summary)
3424       (gnus-summary-position-point)
3425       (message "")
3426       t)
3427      ;; We couldn't select this group.
3428      ((null did-select)
3429       (when (and (eq major-mode 'gnus-summary-mode)
3430                  (not (equal (current-buffer) kill-buffer)))
3431         (kill-buffer (current-buffer))
3432         (if (not quit-config)
3433             (progn
3434               ;; Update the info -- marks might need to be removed,
3435               ;; for instance.
3436               (gnus-summary-update-info)
3437               (set-buffer gnus-group-buffer)
3438               (gnus-group-jump-to-group group)
3439               (gnus-group-next-unread-group 1))
3440           (gnus-handle-ephemeral-exit quit-config)))
3441       (let ((grpinfo (gnus-get-info group)))
3442         (if (null (gnus-info-read grpinfo))
3443             (gnus-message 3 "Group %s contains no messages"
3444                           (gnus-group-decoded-name group))
3445           (gnus-message 3 "Can't select group")))
3446       nil)
3447      ;; The user did a `C-g' while prompting for number of articles,
3448      ;; so we exit this group.
3449      ((eq did-select 'quit)
3450       (and (eq major-mode 'gnus-summary-mode)
3451            (not (equal (current-buffer) kill-buffer))
3452            (kill-buffer (current-buffer)))
3453       (when kill-buffer
3454         (gnus-kill-or-deaden-summary kill-buffer))
3455       (if (not quit-config)
3456           (progn
3457             (set-buffer gnus-group-buffer)
3458             (gnus-group-jump-to-group group)
3459             (gnus-group-next-unread-group 1)
3460             (gnus-configure-windows 'group 'force))
3461         (gnus-handle-ephemeral-exit quit-config))
3462       ;; Finally signal the quit.
3463       (signal 'quit nil))
3464      ;; The group was successfully selected.
3465      (t
3466       (gnus-set-global-variables)
3467       ;; Save the active value in effect when the group was entered.
3468       (setq gnus-newsgroup-active
3469             (gnus-copy-sequence
3470              (gnus-active gnus-newsgroup-name)))
3471       ;; You can change the summary buffer in some way with this hook.
3472       (gnus-run-hooks 'gnus-select-group-hook)
3473       (gnus-update-format-specifications
3474        nil 'summary 'summary-mode 'summary-dummy)
3475       (gnus-update-summary-mark-positions)
3476       ;; Do score processing.
3477       (when gnus-use-scoring
3478         (gnus-possibly-score-headers))
3479       ;; Check whether to fill in the gaps in the threads.
3480       (when gnus-build-sparse-threads
3481         (gnus-build-sparse-threads))
3482       ;; Find the initial limit.
3483       (if gnus-show-threads
3484           (if show-all
3485               (let ((gnus-newsgroup-dormant nil))
3486                 (gnus-summary-initial-limit show-all))
3487             (gnus-summary-initial-limit show-all))
3488         ;; When unthreaded, all articles are always shown.
3489         (setq gnus-newsgroup-limit
3490               (mapcar
3491                (lambda (header) (mail-header-number header))
3492                gnus-newsgroup-headers)))
3493       ;; Generate the summary buffer.
3494       (unless no-display
3495         (gnus-summary-prepare))
3496       (when gnus-use-trees
3497         (gnus-tree-open group)
3498         (setq gnus-summary-highlight-line-function
3499               'gnus-tree-highlight-article))
3500       ;; If the summary buffer is empty, but there are some low-scored
3501       ;; articles or some excluded dormants, we include these in the
3502       ;; buffer.
3503       (when (and (zerop (buffer-size))
3504                  (not no-display))
3505         (cond (gnus-newsgroup-dormant
3506                (gnus-summary-limit-include-dormant))
3507               ((and gnus-newsgroup-scored show-all)
3508                (gnus-summary-limit-include-expunged t))))
3509       ;; Function `gnus-apply-kill-file' must be called in this hook.
3510       (gnus-run-hooks 'gnus-apply-kill-hook)
3511       (if (and (zerop (buffer-size))
3512                (not no-display))
3513           (progn
3514             ;; This newsgroup is empty.
3515             (gnus-summary-catchup-and-exit nil t)
3516             (gnus-message 6 "No unread news")
3517             (when kill-buffer
3518               (gnus-kill-or-deaden-summary kill-buffer))
3519             ;; Return nil from this function.
3520             nil)
3521         ;; Hide conversation thread subtrees.  We cannot do this in
3522         ;; gnus-summary-prepare-hook since kill processing may not
3523         ;; work with hidden articles.
3524         (gnus-summary-maybe-hide-threads)
3525         (when kill-buffer
3526           (gnus-kill-or-deaden-summary kill-buffer))
3527         (gnus-summary-auto-select-subject)
3528         ;; Show first unread article if requested.
3529         (if (and (not no-article)
3530                  (not no-display)
3531                  gnus-newsgroup-unreads
3532                  gnus-auto-select-first)
3533             (progn
3534               (gnus-configure-windows 'summary)
3535               (let ((art (gnus-summary-article-number)))
3536                 (unless (and (not gnus-plugged)
3537                              (or (memq art gnus-newsgroup-undownloaded)
3538                                  (memq art gnus-newsgroup-downloadable)))
3539                   (gnus-summary-goto-article art))))
3540           ;; Don't select any articles.
3541           (gnus-summary-position-point)
3542           (gnus-configure-windows 'summary 'force)
3543           (gnus-set-mode-line 'summary))
3544         (when (get-buffer-window gnus-group-buffer t)
3545           ;; Gotta use windows, because recenter does weird stuff if
3546           ;; the current buffer ain't the displayed window.
3547           (let ((owin (selected-window)))
3548             (select-window (get-buffer-window gnus-group-buffer t))
3549             (when (gnus-group-goto-group group)
3550               (recenter))
3551             (select-window owin)))
3552         ;; Mark this buffer as "prepared".
3553         (setq gnus-newsgroup-prepared t)
3554         (gnus-run-hooks 'gnus-summary-prepared-hook)
3555         (unless (gnus-ephemeral-group-p group)
3556           (gnus-group-update-group group))
3557         t)))))
3558
3559 (defun gnus-summary-auto-select-subject ()
3560   "Select the subject line on initial group entry."
3561   (goto-char (point-min))
3562   (cond
3563    ((eq gnus-auto-select-subject 'best)
3564     (gnus-summary-best-unread-subject))
3565    ((eq gnus-auto-select-subject 'unread)
3566     (gnus-summary-first-unread-subject))
3567    ((eq gnus-auto-select-subject 'unseen)
3568     (gnus-summary-first-unseen-subject))
3569    ((eq gnus-auto-select-subject 'unseen-or-unread)
3570     (gnus-summary-first-unseen-or-unread-subject))
3571    ((eq gnus-auto-select-subject 'first)
3572     ;; Do nothing.
3573     )
3574    ((gnus-functionp gnus-auto-select-subject)
3575     (funcall gnus-auto-select-subject))))
3576
3577 (defun gnus-summary-prepare ()
3578   "Generate the summary buffer."
3579   (interactive)
3580   (let ((buffer-read-only nil))
3581     (erase-buffer)
3582     (setq gnus-newsgroup-data nil
3583           gnus-newsgroup-data-reverse nil)
3584     (gnus-run-hooks 'gnus-summary-generate-hook)
3585     ;; Generate the buffer, either with threads or without.
3586     (when gnus-newsgroup-headers
3587       (gnus-summary-prepare-threads
3588        (if gnus-show-threads
3589            (gnus-sort-gathered-threads
3590             (funcall gnus-summary-thread-gathering-function
3591                      (gnus-sort-threads
3592                       (gnus-cut-threads (gnus-make-threads)))))
3593          ;; Unthreaded display.
3594          (gnus-sort-articles gnus-newsgroup-headers))))
3595     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3596     ;; Call hooks for modifying summary buffer.
3597     (goto-char (point-min))
3598     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3599
3600 (defsubst gnus-general-simplify-subject (subject)
3601   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3602   (setq subject
3603         (cond
3604          ;; Truncate the subject.
3605          (gnus-simplify-subject-functions
3606           (gnus-map-function gnus-simplify-subject-functions subject))
3607          ((numberp gnus-summary-gather-subject-limit)
3608           (setq subject (gnus-simplify-subject-re subject))
3609           (if (> (length subject) gnus-summary-gather-subject-limit)
3610               (substring subject 0 gnus-summary-gather-subject-limit)
3611             subject))
3612          ;; Fuzzily simplify it.
3613          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3614           (gnus-simplify-subject-fuzzy subject))
3615          ;; Just remove the leading "Re:".
3616          (t
3617           (gnus-simplify-subject-re subject))))
3618
3619   (if (and gnus-summary-gather-exclude-subject
3620            (string-match gnus-summary-gather-exclude-subject subject))
3621       nil                               ; This article shouldn't be gathered
3622     subject))
3623
3624 (defun gnus-summary-simplify-subject-query ()
3625   "Query where the respool algorithm would put this article."
3626   (interactive)
3627   (gnus-summary-select-article)
3628   (message "%s"
3629            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3630
3631 (defun gnus-gather-threads-by-subject (threads)
3632   "Gather threads by looking at Subject headers."
3633   (if (not gnus-summary-make-false-root)
3634       threads
3635     (let ((hashtb (gnus-make-hashtable 1024))
3636           (prev threads)
3637           (result threads)
3638           subject hthread whole-subject)
3639       (while threads
3640         (setq subject (gnus-general-simplify-subject
3641                        (setq whole-subject (mail-header-subject
3642                                             (caar threads)))))
3643         (when subject
3644           (if (setq hthread (gnus-gethash subject hashtb))
3645               (progn
3646                 ;; We enter a dummy root into the thread, if we
3647                 ;; haven't done that already.
3648                 (unless (stringp (caar hthread))
3649                   (setcar hthread (list whole-subject (car hthread))))
3650                 ;; We add this new gathered thread to this gathered
3651                 ;; thread.
3652                 (setcdr (car hthread)
3653                         (nconc (cdar hthread) (list (car threads))))
3654                 ;; Remove it from the list of threads.
3655                 (setcdr prev (cdr threads))
3656                 (setq threads prev))
3657             ;; Enter this thread into the hash table.
3658             (gnus-sethash subject
3659                           (if gnus-summary-make-false-root-always
3660                               (progn
3661                                 ;; If you want a dummy root above all
3662                                 ;; threads...
3663                                 (setcar threads (list whole-subject
3664                                                       (car threads)))
3665                                 threads)
3666                             threads)
3667                           hashtb)))
3668         (setq prev threads)
3669         (setq threads (cdr threads)))
3670       result)))
3671
3672 (defun gnus-gather-threads-by-references (threads)
3673   "Gather threads by looking at References headers."
3674   (let ((idhashtb (gnus-make-hashtable 1024))
3675         (thhashtb (gnus-make-hashtable 1024))
3676         (prev threads)
3677         (result threads)
3678         ids references id gthread gid entered ref)
3679     (while threads
3680       (when (setq references (mail-header-references (caar threads)))
3681         (setq id (mail-header-id (caar threads))
3682               ids (inline (gnus-split-references references))
3683               entered nil)
3684         (while (setq ref (pop ids))
3685           (setq ids (delete ref ids))
3686           (if (not (setq gid (gnus-gethash ref idhashtb)))
3687               (progn
3688                 (gnus-sethash ref id idhashtb)
3689                 (gnus-sethash id threads thhashtb))
3690             (setq gthread (gnus-gethash gid thhashtb))
3691             (unless entered
3692               ;; We enter a dummy root into the thread, if we
3693               ;; haven't done that already.
3694               (unless (stringp (caar gthread))
3695                 (setcar gthread (list (mail-header-subject (caar gthread))
3696                                       (car gthread))))
3697               ;; We add this new gathered thread to this gathered
3698               ;; thread.
3699               (setcdr (car gthread)
3700                       (nconc (cdar gthread) (list (car threads)))))
3701             ;; Add it into the thread hash table.
3702             (gnus-sethash id gthread thhashtb)
3703             (setq entered t)
3704             ;; Remove it from the list of threads.
3705             (setcdr prev (cdr threads))
3706             (setq threads prev))))
3707       (setq prev threads)
3708       (setq threads (cdr threads)))
3709     result))
3710
3711 (defun gnus-sort-gathered-threads (threads)
3712   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3713   (let ((result threads))
3714     (while threads
3715       (when (stringp (caar threads))
3716         (setcdr (car threads)
3717                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3718       (setq threads (cdr threads)))
3719     result))
3720
3721 (defun gnus-thread-loop-p (root thread)
3722   "Say whether ROOT is in THREAD."
3723   (let ((stack (list thread))
3724         (infloop 0)
3725         th)
3726     (while (setq thread (pop stack))
3727       (setq th (cdr thread))
3728       (while (and th
3729                   (not (eq (caar th) root)))
3730         (pop th))
3731       (if th
3732           ;; We have found a loop.
3733           (let (ref-dep)
3734             (setcdr thread (delq (car th) (cdr thread)))
3735             (if (boundp (setq ref-dep (intern "none"
3736                                               gnus-newsgroup-dependencies)))
3737                 (setcdr (symbol-value ref-dep)
3738                         (nconc (cdr (symbol-value ref-dep))
3739                                (list (car th))))
3740               (set ref-dep (list nil (car th))))
3741             (setq infloop 1
3742                   stack nil))
3743         ;; Push all the subthreads onto the stack.
3744         (push (cdr thread) stack)))
3745     infloop))
3746
3747 (defun gnus-make-threads ()
3748   "Go through the dependency hashtb and find the roots.  Return all threads."
3749   (let (threads)
3750     (while (catch 'infloop
3751              (mapatoms
3752               (lambda (refs)
3753                 ;; Deal with self-referencing References loops.
3754                 (when (and (car (symbol-value refs))
3755                            (not (zerop
3756                                  (apply
3757                                   '+
3758                                   (mapcar
3759                                    (lambda (thread)
3760                                      (gnus-thread-loop-p
3761                                       (car (symbol-value refs)) thread))
3762                                    (cdr (symbol-value refs)))))))
3763                   (setq threads nil)
3764                   (throw 'infloop t))
3765                 (unless (car (symbol-value refs))
3766                   ;; These threads do not refer back to any other articles,
3767                   ;; so they're roots.
3768                   (setq threads (append (cdr (symbol-value refs)) threads))))
3769               gnus-newsgroup-dependencies)))
3770     threads))
3771
3772 ;; Build the thread tree.
3773 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3774   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3775
3776 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3777 if it was already present.
3778
3779 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3780 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3781 Message-IDs will be renamed to a unique Message-ID before being
3782 entered.
3783
3784 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3785   (let* ((id (mail-header-id header))
3786          (id-dep (and id (intern id dependencies)))
3787          parent-id ref ref-dep ref-header replaced)
3788     ;; Enter this `header' in the `dependencies' table.
3789     (cond
3790      ((not id-dep)
3791       (setq header nil))
3792      ;; The first two cases do the normal part: enter a new `header'
3793      ;; in the `dependencies' table.
3794      ((not (boundp id-dep))
3795       (set id-dep (list header)))
3796      ((null (car (symbol-value id-dep)))
3797       (setcar (symbol-value id-dep) header))
3798
3799      ;; From here the `header' was already present in the
3800      ;; `dependencies' table.
3801      (force-new
3802       ;; Overrides an existing entry;
3803       ;; just set the header part of the entry.
3804       (setcar (symbol-value id-dep) header)
3805       (setq replaced t))
3806
3807      ;; Renames the existing `header' to a unique Message-ID.
3808      ((not gnus-summary-ignore-duplicates)
3809       ;; An article with this Message-ID has already been seen.
3810       ;; We rename the Message-ID.
3811       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3812            (list header))
3813       (mail-header-set-id header id))
3814
3815      ;; The last case ignores an existing entry, except it adds any
3816      ;; additional Xrefs (in case the two articles came from different
3817      ;; servers.
3818      ;; Also sets `header' to `nil' meaning that the `dependencies'
3819      ;; table was *not* modified.
3820      (t
3821       (mail-header-set-xref
3822        (car (symbol-value id-dep))
3823        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3824                    "")
3825                (or (mail-header-xref header) "")))
3826       (setq header nil)))
3827
3828     (when (and header (not replaced))
3829       ;; First check that we are not creating a References loop.
3830       (setq parent-id (gnus-parent-id (mail-header-references header)))
3831       (setq ref parent-id)
3832       (while (and ref
3833                   (setq ref-dep (intern-soft ref dependencies))
3834                   (boundp ref-dep)
3835                   (setq ref-header (car (symbol-value ref-dep))))
3836         (if (string= id ref)
3837             ;; Yuk!  This is a reference loop.  Make the article be a
3838             ;; root article.
3839             (progn
3840               (mail-header-set-references (car (symbol-value id-dep)) "none")
3841               (setq ref nil)
3842               (setq parent-id nil))
3843           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3844       (setq ref-dep (intern (or parent-id "none") dependencies))
3845       (if (boundp ref-dep)
3846           (setcdr (symbol-value ref-dep)
3847                   (nconc (cdr (symbol-value ref-dep))
3848                          (list (symbol-value id-dep))))
3849         (set ref-dep (list nil (symbol-value id-dep)))))
3850     header))
3851
3852 (defun gnus-extract-message-id-from-in-reply-to (string)
3853   (if (string-match "<[^>]+>" string)
3854       (substring string (match-beginning 0) (match-end 0))
3855     nil))
3856
3857 (defun gnus-build-sparse-threads ()
3858   (let ((headers gnus-newsgroup-headers)
3859         (mail-parse-charset gnus-newsgroup-charset)
3860         (gnus-summary-ignore-duplicates t)
3861         header references generation relations
3862         subject child end new-child date)
3863     ;; First we create an alist of generations/relations, where
3864     ;; generations is how much we trust the relation, and the relation
3865     ;; is parent/child.
3866     (gnus-message 7 "Making sparse threads...")
3867     (save-excursion
3868       (nnheader-set-temp-buffer " *gnus sparse threads*")
3869       (while (setq header (pop headers))
3870         (when (and (setq references (mail-header-references header))
3871                    (not (string= references "")))
3872           (insert references)
3873           (setq child (mail-header-id header)
3874                 subject (mail-header-subject header)
3875                 date (mail-header-date header)
3876                 generation 0)
3877           (while (search-backward ">" nil t)
3878             (setq end (1+ (point)))
3879             (when (search-backward "<" nil t)
3880               (setq new-child (buffer-substring (point) end))
3881               (push (list (incf generation)
3882                           child (setq child new-child)
3883                           subject date)
3884                     relations)))
3885           (when child
3886             (push (list (1+ generation) child nil subject) relations))
3887           (erase-buffer)))
3888       (kill-buffer (current-buffer)))
3889     ;; Sort over trustworthiness.
3890     (mapcar
3891      (lambda (relation)
3892        (when (gnus-dependencies-add-header
3893               (make-full-mail-header-from-decoded-header
3894                gnus-reffed-article-number
3895                (nth 3 relation) "" (or (nth 4 relation) "")
3896                (nth 1 relation)
3897                (or (nth 2 relation) "") 0 0 "")
3898               gnus-newsgroup-dependencies nil)
3899          (push gnus-reffed-article-number gnus-newsgroup-limit)
3900          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3901          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3902                gnus-newsgroup-reads)
3903          (decf gnus-reffed-article-number)))
3904      (sort relations 'car-less-than-car))
3905     (gnus-message 7 "Making sparse threads...done")))
3906
3907 (defun gnus-build-old-threads ()
3908   ;; Look at all the articles that refer back to old articles, and
3909   ;; fetch the headers for the articles that aren't there.  This will
3910   ;; build complete threads - if the roots haven't been expired by the
3911   ;; server, that is.
3912   (let ((mail-parse-charset gnus-newsgroup-charset)
3913         id heads)
3914     (mapatoms
3915      (lambda (refs)
3916        (when (not (car (symbol-value refs)))
3917          (setq heads (cdr (symbol-value refs)))
3918          (while heads
3919            (if (memq (mail-header-number (caar heads))
3920                      gnus-newsgroup-dormant)
3921                (setq heads (cdr heads))
3922              (setq id (symbol-name refs))
3923              (while (and (setq id (gnus-build-get-header id))
3924                          (not (car (gnus-id-to-thread id)))))
3925              (setq heads nil)))))
3926      gnus-newsgroup-dependencies)))
3927
3928 ;; This function has to be called with point after the article number
3929 ;; on the beginning of the line.
3930 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3931   (let ((eol (gnus-point-at-eol))
3932         (buffer (current-buffer))
3933         header references in-reply-to)
3934
3935     ;; overview: [num subject from date id refs chars lines misc]
3936     (unwind-protect
3937         (progn
3938           (narrow-to-region (point) eol)
3939           (unless (eobp)
3940             (forward-char))
3941
3942           (setq header
3943                 (make-full-mail-header
3944                  number                         ; number
3945                  (nnheader-nov-field)           ; subject
3946                  (nnheader-nov-field)           ; from
3947                  (nnheader-nov-field)           ; date
3948                  (nnheader-nov-read-message-id) ; id
3949                  (nnheader-nov-field)           ; refs
3950                  (nnheader-nov-read-integer)    ; chars
3951                  (nnheader-nov-read-integer)    ; lines
3952                  (unless (eobp)
3953                    (if (looking-at "Xref: ")
3954                        (goto-char (match-end 0)))
3955                    (nnheader-nov-field))        ; Xref
3956                  (nnheader-nov-parse-extra))))  ; extra
3957
3958       (widen))
3959
3960     (when (and (string= references "")
3961                (setq in-reply-to (mail-header-extra header))
3962                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3963       (mail-header-set-references
3964        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3965
3966     (when gnus-alter-header-function
3967       (funcall gnus-alter-header-function header))
3968     (gnus-dependencies-add-header header dependencies force-new)))
3969
3970 (defun gnus-build-get-header (id)
3971   "Look through the buffer of NOV lines and find the header to ID.
3972 Enter this line into the dependencies hash table, and return
3973 the id of the parent article (if any)."
3974   (let ((deps gnus-newsgroup-dependencies)
3975         found header)
3976     (prog1
3977         (save-excursion
3978           (set-buffer nntp-server-buffer)
3979           (let ((case-fold-search nil))
3980             (goto-char (point-min))
3981             (while (and (not found)
3982                         (search-forward id nil t))
3983               (beginning-of-line)
3984               (setq found (looking-at
3985                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3986                                    (regexp-quote id))))
3987               (or found (beginning-of-line 2)))
3988             (when found
3989               (beginning-of-line)
3990               (and
3991                (setq header (gnus-nov-parse-line
3992                              (read (current-buffer)) deps))
3993                (gnus-parent-id (mail-header-references header))))))
3994       (when header
3995         (let ((number (mail-header-number header)))
3996           (push number gnus-newsgroup-limit)
3997           (push header gnus-newsgroup-headers)
3998           (if (memq number gnus-newsgroup-unselected)
3999               (progn
4000                 (setq gnus-newsgroup-unreads
4001                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4002                                                number))
4003                 (setq gnus-newsgroup-unselected
4004                       (delq number gnus-newsgroup-unselected)))
4005             (push number gnus-newsgroup-ancient)))))))
4006
4007 (defun gnus-build-all-threads ()
4008   "Read all the headers."
4009   (let ((gnus-summary-ignore-duplicates t)
4010         (mail-parse-charset gnus-newsgroup-charset)
4011         (dependencies gnus-newsgroup-dependencies)
4012         header article)
4013     (save-excursion
4014       (set-buffer nntp-server-buffer)
4015       (let ((case-fold-search nil))
4016         (goto-char (point-min))
4017         (while (not (eobp))
4018           (ignore-errors
4019             (setq article (read (current-buffer))
4020                   header (gnus-nov-parse-line article dependencies)))
4021           (when header
4022             (save-excursion
4023               (set-buffer gnus-summary-buffer)
4024               (push header gnus-newsgroup-headers)
4025               (if (memq (setq article (mail-header-number header))
4026                         gnus-newsgroup-unselected)
4027                   (progn
4028                     (setq gnus-newsgroup-unreads
4029                           (gnus-add-to-sorted-list
4030                            gnus-newsgroup-unreads article))
4031                     (setq gnus-newsgroup-unselected
4032                           (delq article gnus-newsgroup-unselected)))
4033                 (push article gnus-newsgroup-ancient)))
4034             (forward-line 1)))))))
4035
4036 (defun gnus-summary-update-article-line (article header)
4037   "Update the line for ARTICLE using HEADERS."
4038   (let* ((id (mail-header-id header))
4039          (thread (gnus-id-to-thread id)))
4040     (unless thread
4041       (error "Article in no thread"))
4042     ;; Update the thread.
4043     (setcar thread header)
4044     (gnus-summary-goto-subject article)
4045     (let* ((datal (gnus-data-find-list article))
4046            (data (car datal))
4047            (buffer-read-only nil)
4048            (level (gnus-summary-thread-level)))
4049       (gnus-delete-line)
4050       (let ((inserted (- (point)
4051                          (progn
4052                            (gnus-summary-insert-line
4053                             header level nil 
4054                             (memq article gnus-newsgroup-undownloaded)
4055                             (gnus-article-mark article)
4056                             (memq article gnus-newsgroup-replied)
4057                             (memq article gnus-newsgroup-expirable)
4058                             ;; Only insert the Subject string when it's different
4059                             ;; from the previous Subject string.
4060                             (if (and
4061                                  gnus-show-threads
4062                                  (gnus-subject-equal
4063                                   (condition-case ()
4064                                       (mail-header-subject
4065                                        (gnus-data-header
4066                                         (cadr
4067                                          (gnus-data-find-list
4068                                           article
4069                                           (gnus-data-list t)))))
4070                                     ;; Error on the side of excessive subjects.
4071                                     (error ""))
4072                                   (mail-header-subject header)))
4073                                 ""
4074                               (mail-header-subject header))
4075                             nil (cdr (assq article gnus-newsgroup-scored))
4076                             (memq article gnus-newsgroup-processable))
4077                            (point)))))
4078         (when (cdr datal)
4079           (gnus-data-update-list
4080            (cdr datal) 
4081            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4082
4083 (defun gnus-summary-update-article (article &optional iheader)
4084   "Update ARTICLE in the summary buffer."
4085   (set-buffer gnus-summary-buffer)
4086   (let* ((header (gnus-summary-article-header article))
4087          (id (mail-header-id header))
4088          (data (gnus-data-find article))
4089          (thread (gnus-id-to-thread id))
4090          (references (mail-header-references header))
4091          (parent
4092           (gnus-id-to-thread
4093            (or (gnus-parent-id
4094                 (when (and references
4095                            (not (equal "" references)))
4096                   references))
4097                "none")))
4098          (buffer-read-only nil)
4099          (old (car thread)))
4100     (when thread
4101       (unless iheader
4102         (setcar thread nil)
4103         (when parent
4104           (delq thread parent)))
4105       (if (gnus-summary-insert-subject id header)
4106           ;; Set the (possibly) new article number in the data structure.
4107           (gnus-data-set-number data (gnus-id-to-article id))
4108         (setcar thread old)
4109         nil))))
4110
4111 (defun gnus-rebuild-thread (id &optional line)
4112   "Rebuild the thread containing ID.
4113 If LINE, insert the rebuilt thread starting on line LINE."
4114   (let ((buffer-read-only nil)
4115         old-pos current thread data)
4116     (if (not gnus-show-threads)
4117         (setq thread (list (car (gnus-id-to-thread id))))
4118       ;; Get the thread this article is part of.
4119       (setq thread (gnus-remove-thread id)))
4120     (setq old-pos (gnus-point-at-bol))
4121     (setq current (save-excursion
4122                     (and (re-search-backward "[\r\n]" nil t)
4123                          (gnus-summary-article-number))))
4124     ;; If this is a gathered thread, we have to go some re-gathering.
4125     (when (stringp (car thread))
4126       (let ((subject (car thread))
4127             roots thr)
4128         (setq thread (cdr thread))
4129         (while thread
4130           (unless (memq (setq thr (gnus-id-to-thread
4131                                    (gnus-root-id
4132                                     (mail-header-id (caar thread)))))
4133                         roots)
4134             (push thr roots))
4135           (setq thread (cdr thread)))
4136         ;; We now have all (unique) roots.
4137         (if (= (length roots) 1)
4138             ;; All the loose roots are now one solid root.
4139             (setq thread (car roots))
4140           (setq thread (cons subject (gnus-sort-threads roots))))))
4141     (let (threads)
4142       ;; We then insert this thread into the summary buffer.
4143       (when line
4144         (goto-char (point-min))
4145         (forward-line (1- line)))
4146       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4147         (if gnus-show-threads
4148             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4149           (gnus-summary-prepare-unthreaded thread))
4150         (setq data (nreverse gnus-newsgroup-data))
4151         (setq threads gnus-newsgroup-threads))
4152       ;; We splice the new data into the data structure.
4153       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4154       ;;!!! then we want to insert at the beginning of the buffer.
4155       ;;!!! That happens to be true with Gnus now, but that may
4156       ;;!!! change in the future.  Perhaps.
4157       (gnus-data-enter-list
4158        (if line nil current) data (- (point) old-pos))
4159       (setq gnus-newsgroup-threads
4160             (nconc threads gnus-newsgroup-threads))
4161       (gnus-data-compute-positions))))
4162
4163 (defun gnus-number-to-header (number)
4164   "Return the header for article NUMBER."
4165   (let ((headers gnus-newsgroup-headers))
4166     (while (and headers
4167                 (not (= number (mail-header-number (car headers)))))
4168       (pop headers))
4169     (when headers
4170       (car headers))))
4171
4172 (defun gnus-parent-headers (in-headers &optional generation)
4173   "Return the headers of the GENERATIONeth parent of HEADERS."
4174   (unless generation
4175     (setq generation 1))
4176   (let ((parent t)
4177         (headers in-headers)
4178         references)
4179     (while (and parent
4180                 (not (zerop generation))
4181                 (setq references (mail-header-references headers)))
4182       (setq headers (if (and references
4183                              (setq parent (gnus-parent-id references)))
4184                         (car (gnus-id-to-thread parent))
4185                       nil))
4186       (decf generation))
4187     (and (not (eq headers in-headers))
4188          headers)))
4189
4190 (defun gnus-id-to-thread (id)
4191   "Return the (sub-)thread where ID appears."
4192   (gnus-gethash id gnus-newsgroup-dependencies))
4193
4194 (defun gnus-id-to-article (id)
4195   "Return the article number of ID."
4196   (let ((thread (gnus-id-to-thread id)))
4197     (when (and thread
4198                (car thread))
4199       (mail-header-number (car thread)))))
4200
4201 (defun gnus-id-to-header (id)
4202   "Return the article headers of ID."
4203   (car (gnus-id-to-thread id)))
4204
4205 (defun gnus-article-displayed-root-p (article)
4206   "Say whether ARTICLE is a root(ish) article."
4207   (let ((level (gnus-summary-thread-level article))
4208         (refs (mail-header-references  (gnus-summary-article-header article)))
4209         particle)
4210     (cond
4211      ((null level) nil)
4212      ((zerop level) t)
4213      ((null refs) t)
4214      ((null (gnus-parent-id refs)) t)
4215      ((and (= 1 level)
4216            (null (setq particle (gnus-id-to-article
4217                                  (gnus-parent-id refs))))
4218            (null (gnus-summary-thread-level particle)))))))
4219
4220 (defun gnus-root-id (id)
4221   "Return the id of the root of the thread where ID appears."
4222   (let (last-id prev)
4223     (while (and id (setq prev (car (gnus-id-to-thread id))))
4224       (setq last-id id
4225             id (gnus-parent-id (mail-header-references prev))))
4226     last-id))
4227
4228 (defun gnus-articles-in-thread (thread)
4229   "Return the list of articles in THREAD."
4230   (cons (mail-header-number (car thread))
4231         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4232
4233 (defun gnus-remove-thread (id &optional dont-remove)
4234   "Remove the thread that has ID in it."
4235   (let (headers thread last-id)
4236     ;; First go up in this thread until we find the root.
4237     (setq last-id (gnus-root-id id)
4238           headers (message-flatten-list (gnus-id-to-thread last-id)))
4239     ;; We have now found the real root of this thread.  It might have
4240     ;; been gathered into some loose thread, so we have to search
4241     ;; through the threads to find the thread we wanted.
4242     (let ((threads gnus-newsgroup-threads)
4243           sub)
4244       (while threads
4245         (setq sub (car threads))
4246         (if (stringp (car sub))
4247             ;; This is a gathered thread, so we look at the roots
4248             ;; below it to find whether this article is in this
4249             ;; gathered root.
4250             (progn
4251               (setq sub (cdr sub))
4252               (while sub
4253                 (when (member (caar sub) headers)
4254                   (setq thread (car threads)
4255                         threads nil
4256                         sub nil))
4257                 (setq sub (cdr sub))))
4258           ;; It's an ordinary thread, so we check it.
4259           (when (eq (car sub) (car headers))
4260             (setq thread sub
4261                   threads nil)))
4262         (setq threads (cdr threads)))
4263       ;; If this article is in no thread, then it's a root.
4264       (if thread
4265           (unless dont-remove
4266             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4267         (setq thread (gnus-id-to-thread last-id)))
4268       (when thread
4269         (prog1
4270             thread                      ; We return this thread.
4271           (unless dont-remove
4272             (if (stringp (car thread))
4273                 (progn
4274                   ;; If we use dummy roots, then we have to remove the
4275                   ;; dummy root as well.
4276                   (when (eq gnus-summary-make-false-root 'dummy)
4277                     ;; We go to the dummy root by going to
4278                     ;; the first sub-"thread", and then one line up.
4279                     (gnus-summary-goto-article
4280                      (mail-header-number (caadr thread)))
4281                     (forward-line -1)
4282                     (gnus-delete-line)
4283                     (gnus-data-compute-positions))
4284                   (setq thread (cdr thread))
4285                   (while thread
4286                     (gnus-remove-thread-1 (car thread))
4287                     (setq thread (cdr thread))))
4288               (gnus-remove-thread-1 thread))))))))
4289
4290 (defun gnus-remove-thread-1 (thread)
4291   "Remove the thread THREAD recursively."
4292   (let ((number (mail-header-number (pop thread)))
4293         d)
4294     (setq thread (reverse thread))
4295     (while thread
4296       (gnus-remove-thread-1 (pop thread)))
4297     (when (setq d (gnus-data-find number))
4298       (goto-char (gnus-data-pos d))
4299       (gnus-summary-show-thread)
4300       (gnus-data-remove
4301        number
4302        (- (gnus-point-at-bol)
4303           (prog1
4304               (1+ (gnus-point-at-eol))
4305             (gnus-delete-line)))))))
4306
4307 (defun gnus-sort-threads-1 (threads func)
4308   (sort (mapcar (lambda (thread)
4309                   (cons (car thread)
4310                         (and (cdr thread)
4311                              (gnus-sort-threads-1 (cdr thread) func))))
4312                 threads) func))
4313
4314 (defun gnus-sort-threads (threads)
4315   "Sort THREADS."
4316   (if (not gnus-thread-sort-functions)
4317       threads
4318     (gnus-message 8 "Sorting threads...")
4319     (let ((max-lisp-eval-depth 5000))
4320       (prog1 (gnus-sort-threads-1
4321          threads
4322          (gnus-make-sort-function gnus-thread-sort-functions))
4323         (gnus-message 8 "Sorting threads...done")))))
4324
4325 (defun gnus-sort-articles (articles)
4326   "Sort ARTICLES."
4327   (when gnus-article-sort-functions
4328     (gnus-message 7 "Sorting articles...")
4329     (prog1
4330         (setq gnus-newsgroup-headers
4331               (sort articles (gnus-make-sort-function
4332                               gnus-article-sort-functions)))
4333       (gnus-message 7 "Sorting articles...done"))))
4334
4335 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4336 (defmacro gnus-thread-header (thread)
4337   "Return header of first article in THREAD.
4338 Note that THREAD must never, ever be anything else than a variable -
4339 using some other form will lead to serious barfage."
4340   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4341   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4342   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4343         (vector thread) 2))
4344
4345 (defsubst gnus-article-sort-by-number (h1 h2)
4346   "Sort articles by article number."
4347   (< (mail-header-number h1)
4348      (mail-header-number h2)))
4349
4350 (defun gnus-thread-sort-by-number (h1 h2)
4351   "Sort threads by root article number."
4352   (gnus-article-sort-by-number
4353    (gnus-thread-header h1) (gnus-thread-header h2)))
4354
4355 (defsubst gnus-article-sort-by-random (h1 h2)
4356   "Sort articles by article number."
4357   (zerop (random 2)))
4358
4359 (defun gnus-thread-sort-by-random (h1 h2)
4360   "Sort threads by root article number."
4361   (gnus-article-sort-by-random
4362    (gnus-thread-header h1) (gnus-thread-header h2)))
4363
4364 (defsubst gnus-article-sort-by-lines (h1 h2)
4365   "Sort articles by article Lines header."
4366   (< (mail-header-lines h1)
4367      (mail-header-lines h2)))
4368
4369 (defun gnus-thread-sort-by-lines (h1 h2)
4370   "Sort threads by root article Lines header."
4371   (gnus-article-sort-by-lines
4372    (gnus-thread-header h1) (gnus-thread-header h2)))
4373
4374 (defsubst gnus-article-sort-by-chars (h1 h2)
4375   "Sort articles by octet length."
4376   (< (mail-header-chars h1)
4377      (mail-header-chars h2)))
4378
4379 (defun gnus-thread-sort-by-chars (h1 h2)
4380   "Sort threads by root article octet length."
4381   (gnus-article-sort-by-chars
4382    (gnus-thread-header h1) (gnus-thread-header h2)))
4383
4384 (defsubst gnus-article-sort-by-author (h1 h2)
4385   "Sort articles by root author."
4386   (string-lessp
4387    (let ((addr (car (mime-entity-read-field h1 'From))))
4388      (or (std11-full-name-string addr)
4389          (std11-address-string addr)
4390          ""))
4391    (let ((addr (car (mime-entity-read-field h2 'From))))
4392      (or (std11-full-name-string addr)
4393          (std11-address-string addr)
4394          ""))
4395    ))
4396
4397 (defun gnus-thread-sort-by-author (h1 h2)
4398   "Sort threads by root author."
4399   (gnus-article-sort-by-author
4400    (gnus-thread-header h1)  (gnus-thread-header h2)))
4401
4402 (defsubst gnus-article-sort-by-subject (h1 h2)
4403   "Sort articles by root subject."
4404   (string-lessp
4405    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4406    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4407
4408 (defun gnus-thread-sort-by-subject (h1 h2)
4409   "Sort threads by root subject."
4410   (gnus-article-sort-by-subject
4411    (gnus-thread-header h1) (gnus-thread-header h2)))
4412
4413 (defsubst gnus-article-sort-by-date (h1 h2)
4414   "Sort articles by root article date."
4415   (time-less-p
4416    (gnus-date-get-time (mail-header-date h1))
4417    (gnus-date-get-time (mail-header-date h2))))
4418
4419 (defun gnus-thread-sort-by-date (h1 h2)
4420   "Sort threads by root article date."
4421   (gnus-article-sort-by-date
4422    (gnus-thread-header h1) (gnus-thread-header h2)))
4423
4424 (defsubst gnus-article-sort-by-score (h1 h2)
4425   "Sort articles by root article score.
4426 Unscored articles will be counted as having a score of zero."
4427   (> (or (cdr (assq (mail-header-number h1)
4428                     gnus-newsgroup-scored))
4429          gnus-summary-default-score 0)
4430      (or (cdr (assq (mail-header-number h2)
4431                     gnus-newsgroup-scored))
4432          gnus-summary-default-score 0)))
4433
4434 (defun gnus-thread-sort-by-score (h1 h2)
4435   "Sort threads by root article score."
4436   (gnus-article-sort-by-score
4437    (gnus-thread-header h1) (gnus-thread-header h2)))
4438
4439 (defun gnus-thread-sort-by-total-score (h1 h2)
4440   "Sort threads by the sum of all scores in the thread.
4441 Unscored articles will be counted as having a score of zero."
4442   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4443
4444 (defun gnus-thread-total-score (thread)
4445   ;; This function find the total score of THREAD.
4446   (cond
4447    ((null thread)
4448     0)
4449    ((consp thread)
4450     (if (stringp (car thread))
4451         (apply gnus-thread-score-function 0
4452                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4453       (gnus-thread-total-score-1 thread)))
4454    (t
4455     (gnus-thread-total-score-1 (list thread)))))
4456
4457 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4458   "Sort threads such that the thread with the most recently arrived article comes first."
4459   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4460
4461 (defun gnus-thread-highest-number (thread)
4462   "Return the highest article number in THREAD."
4463   (apply 'max (mapcar (lambda (header)
4464                         (mail-header-number header))
4465                       (message-flatten-list thread))))
4466
4467 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4468   "Sort threads such that the thread with the most recently dated article comes first."
4469   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4470
4471 (defun gnus-thread-latest-date (thread)
4472   "Return the highest article date in THREAD."
4473   (let ((previous-time 0))
4474     (apply 'max
4475            (mapcar
4476             (lambda (header)
4477               (setq previous-time
4478                     (time-to-seconds
4479                      (condition-case ()
4480                          (mail-header-parse-date (mail-header-date header))
4481                        (error previous-time)))))
4482             (sort
4483              (message-flatten-list thread)
4484              (lambda (h1 h2)
4485                (< (mail-header-number h1)
4486                   (mail-header-number h2))))))))
4487
4488 (defun gnus-thread-total-score-1 (root)
4489   ;; This function find the total score of the thread below ROOT.
4490   (setq root (car root))
4491   (apply gnus-thread-score-function
4492          (or (append
4493               (mapcar 'gnus-thread-total-score
4494                       (cdr (gnus-id-to-thread (mail-header-id root))))
4495               (when (> (mail-header-number root) 0)
4496                 (list (or (cdr (assq (mail-header-number root)
4497                                      gnus-newsgroup-scored))
4498                           gnus-summary-default-score 0))))
4499              (list gnus-summary-default-score)
4500              '(0))))
4501
4502 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4503 (defvar gnus-tmp-prev-subject nil)
4504 (defvar gnus-tmp-false-parent nil)
4505 (defvar gnus-tmp-root-expunged nil)
4506 (defvar gnus-tmp-dummy-line nil)
4507
4508 (eval-when-compile (defvar gnus-tmp-header))
4509 (defun gnus-extra-header (type &optional header)
4510   "Return the extra header of TYPE."
4511   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4512       ""))
4513
4514 (defvar gnus-tmp-thread-tree-header-string "")
4515
4516 (defcustom gnus-sum-thread-tree-root "> "
4517   "With %B spec, used for the root of a thread.
4518 If nil, use subject instead."
4519   :type 'string
4520   :group 'gnus-thread)
4521 (defcustom gnus-sum-thread-tree-single-indent ""
4522   "With %B spec, used for a thread with just one message.
4523 If nil, use subject instead."
4524   :type 'string
4525   :group 'gnus-thread)
4526 (defcustom gnus-sum-thread-tree-vertical "| "
4527   "With %B spec, used for drawing a vertical line."
4528   :type 'string
4529   :group 'gnus-thread)
4530 (defcustom gnus-sum-thread-tree-indent "  "
4531   "With %B spec, used for indenting."
4532   :type 'string
4533   :group 'gnus-thread)
4534 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4535   "With %B spec, used for a leaf with brothers."
4536   :type 'string
4537   :group 'gnus-thread)
4538 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4539   "With %B spec, used for a leaf without brothers."
4540   :type 'string
4541   :group 'gnus-thread)
4542
4543 (defun gnus-summary-prepare-threads (threads)
4544   "Prepare summary buffer from THREADS and indentation LEVEL.
4545 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4546 or a straight list of headers."
4547   (gnus-message 7 "Generating summary...")
4548
4549   (setq gnus-newsgroup-threads threads)
4550   (beginning-of-line)
4551
4552   (let ((gnus-tmp-level 0)
4553         (default-score (or gnus-summary-default-score 0))
4554         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4555         (building-line-count gnus-summary-display-while-building)
4556         (building-count (integerp gnus-summary-display-while-building))
4557         thread number subject stack state gnus-tmp-gathered beg-match
4558         new-roots gnus-tmp-new-adopts thread-end simp-subject
4559         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4560         gnus-tmp-replied gnus-tmp-subject-or-nil
4561         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4562         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4563         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4564         tree-stack)
4565
4566     (setq gnus-tmp-prev-subject nil
4567           gnus-tmp-thread-tree-header-string "")
4568
4569     (if (vectorp (car threads))
4570         ;; If this is a straight (sic) list of headers, then a
4571         ;; threaded summary display isn't required, so we just create
4572         ;; an unthreaded one.
4573         (gnus-summary-prepare-unthreaded threads)
4574
4575       ;; Do the threaded display.
4576
4577       (if gnus-summary-display-while-building
4578           (switch-to-buffer (buffer-name)))
4579       (while (or threads stack gnus-tmp-new-adopts new-roots)
4580
4581         (if (and (= gnus-tmp-level 0)
4582                  (or (not stack)
4583                      (= (caar stack) 0))
4584                  (not gnus-tmp-false-parent)
4585                  (or gnus-tmp-new-adopts new-roots))
4586             (if gnus-tmp-new-adopts
4587                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4588                       thread (list (car gnus-tmp-new-adopts))
4589                       gnus-tmp-header (caar thread)
4590                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4591               (when new-roots
4592                 (setq thread (list (car new-roots))
4593                       gnus-tmp-header (caar thread)
4594                       new-roots (cdr new-roots))))
4595
4596           (if threads
4597               ;; If there are some threads, we do them before the
4598               ;; threads on the stack.
4599               (setq thread threads
4600                     gnus-tmp-header (caar thread))
4601             ;; There were no current threads, so we pop something off
4602             ;; the stack.
4603             (setq state (car stack)
4604                   gnus-tmp-level (car state)
4605                   tree-stack (cadr state)
4606                   thread (caddr state)
4607                   stack (cdr stack)
4608                   gnus-tmp-header (caar thread))))
4609
4610         (setq gnus-tmp-false-parent nil)
4611         (setq gnus-tmp-root-expunged nil)
4612         (setq thread-end nil)
4613
4614         (if (stringp gnus-tmp-header)
4615             ;; The header is a dummy root.
4616             (cond
4617              ((eq gnus-summary-make-false-root 'adopt)
4618               ;; We let the first article adopt the rest.
4619               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4620                                                (cddar thread)))
4621               (setq gnus-tmp-gathered
4622                     (nconc (mapcar
4623                             (lambda (h) (mail-header-number (car h)))
4624                             (cddar thread))
4625                            gnus-tmp-gathered))
4626               (setq thread (cons (list (caar thread)
4627                                        (cadar thread))
4628                                  (cdr thread)))
4629               (setq gnus-tmp-level -1
4630                     gnus-tmp-false-parent t))
4631              ((eq gnus-summary-make-false-root 'empty)
4632               ;; We print adopted articles with empty subject fields.
4633               (setq gnus-tmp-gathered
4634                     (nconc (mapcar
4635                             (lambda (h) (mail-header-number (car h)))
4636                             (cddar thread))
4637                            gnus-tmp-gathered))
4638               (setq gnus-tmp-level -1))
4639              ((eq gnus-summary-make-false-root 'dummy)
4640               ;; We remember that we probably want to output a dummy
4641               ;; root.
4642               (setq gnus-tmp-dummy-line gnus-tmp-header)
4643               (setq gnus-tmp-prev-subject gnus-tmp-header))
4644              (t
4645               ;; We do not make a root for the gathered
4646               ;; sub-threads at all.
4647               (setq gnus-tmp-level -1)))
4648
4649           (setq number (mail-header-number gnus-tmp-header)
4650                 subject (mail-header-subject gnus-tmp-header)
4651                 simp-subject (gnus-simplify-subject-fully subject))
4652
4653           (cond
4654            ;; If the thread has changed subject, we might want to make
4655            ;; this subthread into a root.
4656            ((and (null gnus-thread-ignore-subject)
4657                  (not (zerop gnus-tmp-level))
4658                  gnus-tmp-prev-subject
4659                  (not (string= gnus-tmp-prev-subject simp-subject)))
4660             (setq new-roots (nconc new-roots (list (car thread)))
4661                   thread-end t
4662                   gnus-tmp-header nil))
4663            ;; If the article lies outside the current limit,
4664            ;; then we do not display it.
4665            ((not (memq number gnus-newsgroup-limit))
4666             (setq gnus-tmp-gathered
4667                   (nconc (mapcar
4668                           (lambda (h) (mail-header-number (car h)))
4669                           (cdar thread))
4670                          gnus-tmp-gathered))
4671             (setq gnus-tmp-new-adopts (if (cdar thread)
4672                                           (append gnus-tmp-new-adopts
4673                                                   (cdar thread))
4674                                         gnus-tmp-new-adopts)
4675                   thread-end t
4676                   gnus-tmp-header nil)
4677             (when (zerop gnus-tmp-level)
4678               (setq gnus-tmp-root-expunged t)))
4679            ;; Perhaps this article is to be marked as read?
4680            ((and gnus-summary-mark-below
4681                  (< (or (cdr (assq number gnus-newsgroup-scored))
4682                         default-score)
4683                     gnus-summary-mark-below)
4684                  ;; Don't touch sparse articles.
4685                  (not (gnus-summary-article-sparse-p number))
4686                  (not (gnus-summary-article-ancient-p number)))
4687             (setq gnus-newsgroup-unreads
4688                   (delq number gnus-newsgroup-unreads))
4689             (if gnus-newsgroup-auto-expire
4690                 (setq gnus-newsgroup-expirable
4691                       (gnus-add-to-sorted-list
4692                        gnus-newsgroup-expirable number))
4693               (push (cons number gnus-low-score-mark)
4694                     gnus-newsgroup-reads))))
4695
4696           (when gnus-tmp-header
4697             ;; We may have an old dummy line to output before this
4698             ;; article.
4699             (when (and gnus-tmp-dummy-line
4700                        (gnus-subject-equal
4701                         gnus-tmp-dummy-line
4702                         (mail-header-subject gnus-tmp-header)))
4703               (gnus-summary-insert-dummy-line
4704                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4705               (setq gnus-tmp-dummy-line nil))
4706
4707             ;; Compute the mark.
4708             (setq gnus-tmp-unread (gnus-article-mark number))
4709
4710             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4711                                   gnus-tmp-header gnus-tmp-level)
4712                   gnus-newsgroup-data)
4713
4714             ;; Actually insert the line.
4715             (setq
4716              gnus-tmp-subject-or-nil
4717              (cond
4718               ((and gnus-thread-ignore-subject
4719                     gnus-tmp-prev-subject
4720                     (not (string= gnus-tmp-prev-subject simp-subject)))
4721                subject)
4722               ((zerop gnus-tmp-level)
4723                (if (and (eq gnus-summary-make-false-root 'empty)
4724                         (memq number gnus-tmp-gathered)
4725                         gnus-tmp-prev-subject
4726                         (string= gnus-tmp-prev-subject simp-subject))
4727                    gnus-summary-same-subject
4728                  subject))
4729               (t gnus-summary-same-subject)))
4730             (if (and (eq gnus-summary-make-false-root 'adopt)
4731                      (= gnus-tmp-level 1)
4732                      (memq number gnus-tmp-gathered))
4733                 (setq gnus-tmp-opening-bracket ?\<
4734                       gnus-tmp-closing-bracket ?\>)
4735               (setq gnus-tmp-opening-bracket ?\[
4736                     gnus-tmp-closing-bracket ?\]))
4737             (setq
4738              gnus-tmp-indentation
4739              (aref gnus-thread-indent-array gnus-tmp-level)
4740              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4741              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4742                                 gnus-summary-default-score 0)
4743              gnus-tmp-score-char
4744              (if (or (null gnus-summary-default-score)
4745                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4746                          gnus-summary-zcore-fuzz))
4747                  ?\ ;;;Whitespace
4748                (if (< gnus-tmp-score gnus-summary-default-score)
4749                    gnus-score-below-mark gnus-score-over-mark))
4750              gnus-tmp-replied
4751              (cond ((memq number gnus-newsgroup-processable)
4752                     gnus-process-mark)
4753                    ((memq number gnus-newsgroup-cached)
4754                     gnus-cached-mark)
4755                    ((memq number gnus-newsgroup-replied)
4756                     gnus-replied-mark)
4757                    ((memq number gnus-newsgroup-forwarded)
4758                     gnus-forwarded-mark)
4759                    ((memq number gnus-newsgroup-saved)
4760                     gnus-saved-mark)
4761                    ((memq number gnus-newsgroup-recent)
4762                     gnus-recent-mark)
4763                    ((memq number gnus-newsgroup-unseen)
4764                     gnus-unseen-mark)
4765                    (t gnus-no-mark))
4766              gnus-tmp-downloaded
4767              (cond ((memq number gnus-newsgroup-undownloaded) 
4768                     gnus-undownloaded-mark)
4769                    (gnus-newsgroup-agentized
4770                     gnus-downloaded-mark)
4771                    (t
4772                     gnus-no-mark))
4773              gnus-tmp-from (mail-header-from gnus-tmp-header)
4774              gnus-tmp-name
4775              (cond
4776               ((string-match "<[^>]+> *$" gnus-tmp-from)
4777                (setq beg-match (match-beginning 0))
4778                (or (and (string-match "^\".+\"" gnus-tmp-from)
4779                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4780                    (substring gnus-tmp-from 0 beg-match)))
4781               ((string-match "(.+)" gnus-tmp-from)
4782                (substring gnus-tmp-from
4783                           (1+ (match-beginning 0)) (1- (match-end 0))))
4784               (t gnus-tmp-from))
4785              gnus-tmp-thread-tree-header-string
4786              (cond
4787               ((not gnus-show-threads) "")
4788               ((zerop gnus-tmp-level)
4789                (if (cdar thread)
4790                    (or gnus-sum-thread-tree-root subject)
4791                  (or gnus-sum-thread-tree-single-indent subject)))
4792               (t
4793                (concat (apply 'concat
4794                               (mapcar (lambda (item)
4795                                         (if (= item 1)
4796                                             gnus-sum-thread-tree-vertical
4797                                           gnus-sum-thread-tree-indent))
4798                                       (cdr (reverse tree-stack))))
4799                        (if (nth 1 thread)
4800                            gnus-sum-thread-tree-leaf-with-other
4801                          gnus-sum-thread-tree-single-leaf)))))
4802             (when (string= gnus-tmp-name "")
4803               (setq gnus-tmp-name gnus-tmp-from))
4804             (unless (numberp gnus-tmp-lines)
4805               (setq gnus-tmp-lines -1))
4806             (if (= gnus-tmp-lines -1)
4807                 (setq gnus-tmp-lines "?")
4808               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4809               (gnus-put-text-property
4810              (point)
4811              (progn (eval gnus-summary-line-format-spec) (point))
4812                'gnus-number number)
4813             (when gnus-visual-p
4814               (forward-line -1)
4815               (gnus-run-hooks 'gnus-summary-update-hook)
4816               (forward-line 1))
4817
4818             (setq gnus-tmp-prev-subject simp-subject)))
4819
4820         (when (nth 1 thread)
4821           (push (list (max 0 gnus-tmp-level)
4822                       (copy-list tree-stack)
4823                       (nthcdr 1 thread))
4824                 stack))
4825         (push (if (nth 1 thread) 1 0) tree-stack)
4826         (incf gnus-tmp-level)
4827         (setq threads (if thread-end nil (cdar thread)))
4828         (if gnus-summary-display-while-building
4829             (if building-count
4830                 (progn
4831                   ;; use a set frequency
4832                   (setq building-line-count (1- building-line-count))
4833                   (when (= building-line-count 0)
4834                     (sit-for 0)
4835                     (setq building-line-count
4836                           gnus-summary-display-while-building)))
4837               ;; always
4838               (sit-for 0)))
4839         (unless threads
4840           (setq gnus-tmp-level 0)))))
4841   (gnus-message 7 "Generating summary...done"))
4842
4843 (defun gnus-summary-prepare-unthreaded (headers)
4844   "Generate an unthreaded summary buffer based on HEADERS."
4845   (let (header number mark)
4846
4847     (beginning-of-line)
4848
4849     (while headers
4850       ;; We may have to root out some bad articles...
4851       (when (memq (setq number (mail-header-number
4852                                 (setq header (pop headers))))
4853                   gnus-newsgroup-limit)
4854         ;; Mark article as read when it has a low score.
4855         (when (and gnus-summary-mark-below
4856                    (< (or (cdr (assq number gnus-newsgroup-scored))
4857                           gnus-summary-default-score 0)
4858                       gnus-summary-mark-below)
4859                    (not (gnus-summary-article-ancient-p number)))
4860           (setq gnus-newsgroup-unreads
4861                 (delq number gnus-newsgroup-unreads))
4862           (if gnus-newsgroup-auto-expire
4863               (push number gnus-newsgroup-expirable)
4864             (push (cons number gnus-low-score-mark)
4865                   gnus-newsgroup-reads)))
4866
4867         (setq mark (gnus-article-mark number))
4868         (push (gnus-data-make number mark (1+ (point)) header 0)
4869               gnus-newsgroup-data)
4870         (gnus-summary-insert-line
4871          header 0 number
4872          (memq number gnus-newsgroup-undownloaded)
4873          mark (memq number gnus-newsgroup-replied)
4874          (memq number gnus-newsgroup-expirable)
4875          (mail-header-subject header) nil
4876          (cdr (assq number gnus-newsgroup-scored))
4877          (memq number gnus-newsgroup-processable))))))
4878
4879 (defun gnus-summary-remove-list-identifiers ()
4880   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4881   (let ((regexp (if (consp gnus-list-identifiers)
4882                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4883                   gnus-list-identifiers))
4884         changed subject)
4885     (when regexp
4886       (dolist (header gnus-newsgroup-headers)
4887         (setq subject (mail-header-subject header)
4888               changed nil)
4889         (while (string-match
4890                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4891                 subject)
4892           (setq subject
4893                 (concat (substring subject 0 (match-beginning 2))
4894                         (substring subject (match-end 0)))
4895                 changed t))
4896         (when (and changed
4897                    (string-match
4898                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4899           (setq subject
4900                 (concat (substring subject 0 (match-beginning 1))
4901                         (substring subject (match-end 1)))))
4902         (when changed
4903           (mail-header-set-subject header subject))))))
4904
4905 (defun gnus-fetch-headers (articles)
4906   "Fetch headers of ARTICLES."
4907   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4908     (gnus-message 5 "Fetching headers for %s..." name)
4909     (prog1
4910         (if (eq 'nov
4911                 (setq gnus-headers-retrieved-by
4912                       (gnus-retrieve-headers
4913                        articles gnus-newsgroup-name
4914                        ;; We might want to fetch old headers, but
4915                        ;; not if there is only 1 article.
4916                        (and (or (and
4917                                  (not (eq gnus-fetch-old-headers 'some))
4918                                  (not (numberp gnus-fetch-old-headers)))
4919                                 (> (length articles) 1))
4920                             gnus-fetch-old-headers))))
4921             (gnus-get-newsgroup-headers-xover
4922              articles nil nil gnus-newsgroup-name t)
4923           (gnus-get-newsgroup-headers))
4924       (gnus-message 5 "Fetching headers for %s...done" name))))
4925
4926 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4927   "Select newsgroup GROUP.
4928 If READ-ALL is non-nil, all articles in the group are selected.
4929 If SELECT-ARTICLES, only select those articles from GROUP."
4930   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4931          ;;!!! Dirty hack; should be removed.
4932          (gnus-summary-ignore-duplicates
4933           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4934               t
4935             gnus-summary-ignore-duplicates))
4936          (info (nth 2 entry))
4937          articles fetched-articles cached)
4938
4939     (unless (gnus-check-server
4940              (set (make-local-variable 'gnus-current-select-method)
4941                   (gnus-find-method-for-group group)))
4942       (error "Couldn't open server"))
4943
4944     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4945         (gnus-activate-group group)     ; Or we can activate it...
4946         (progn                          ; Or we bug out.
4947           (when (equal major-mode 'gnus-summary-mode)
4948             (kill-buffer (current-buffer)))
4949           (error "Couldn't activate group %s: %s"
4950                  group (gnus-status-message group))))
4951
4952     (unless (gnus-request-group group t)
4953       (when (equal major-mode 'gnus-summary-mode)
4954         (kill-buffer (current-buffer)))
4955       (error "Couldn't request group %s: %s"
4956              group (gnus-status-message group)))
4957
4958     (setq gnus-newsgroup-name group
4959           gnus-newsgroup-unselected nil
4960           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4961
4962     (let ((display (gnus-group-find-parameter group 'display)))
4963       (setq gnus-newsgroup-display
4964             (cond
4965              ((not (zerop (or (car-safe read-all) 0)))
4966               ;; The user entered the group with C-u SPC/RET, let's show
4967               ;; all articles.
4968               'gnus-not-ignore)
4969              ((eq display 'all)
4970               'gnus-not-ignore)
4971              ((arrayp display)
4972               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4973              ((numberp display)
4974               ;; The following is probably the "correct" solution, but
4975               ;; it makes Gnus fetch all headers and then limit the
4976               ;; articles (which is slow), so instead we hack the
4977               ;; select-articles parameter instead. -- Simon Josefsson
4978               ;; <jas@kth.se>
4979               ;;
4980               ;; (gnus-byte-compile
4981               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4982               ;;                         display)))))
4983               (setq select-articles
4984                     (gnus-uncompress-range
4985                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4986                              (if (> tmp 0)
4987                                  tmp
4988                                1))
4989                            (cdr (gnus-active group)))))
4990               nil)
4991              (t
4992               nil))))
4993
4994     (gnus-summary-setup-default-charset)
4995
4996     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4997     (when (gnus-virtual-group-p group)
4998       (setq cached gnus-newsgroup-cached))
4999
5000     (setq gnus-newsgroup-unreads
5001           (gnus-sorted-ndifference
5002            (gnus-sorted-ndifference gnus-newsgroup-unreads
5003                                     gnus-newsgroup-marked)
5004            gnus-newsgroup-dormant))
5005
5006     (setq gnus-newsgroup-processable nil)
5007
5008     (gnus-update-read-articles group gnus-newsgroup-unreads)
5009
5010     ;; Adjust and set lists of article marks.
5011     (when info
5012       (gnus-adjust-marked-articles info))
5013     (if (setq articles select-articles)
5014         (setq gnus-newsgroup-unselected
5015               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5016       (setq articles (gnus-articles-to-read group read-all)))
5017
5018     (cond
5019      ((null articles)
5020       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5021       'quit)
5022      ((eq articles 0) nil)
5023      (t
5024       ;; Init the dependencies hash table.
5025       (setq gnus-newsgroup-dependencies
5026             (gnus-make-hashtable (length articles)))
5027       (gnus-set-global-variables)
5028       ;; Retrieve the headers and read them in.
5029
5030       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5031
5032       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5033       (when cached
5034         (setq gnus-newsgroup-cached cached))
5035
5036       ;; Suppress duplicates?
5037       (when gnus-suppress-duplicates
5038         (gnus-dup-suppress-articles))
5039
5040       ;; Set the initial limit.
5041       (setq gnus-newsgroup-limit (copy-sequence articles))
5042       ;; Remove canceled articles from the list of unread articles.
5043       (setq fetched-articles
5044             (mapcar (lambda (headers) (mail-header-number headers))
5045                     gnus-newsgroup-headers))
5046       (setq gnus-newsgroup-articles fetched-articles)
5047       (setq gnus-newsgroup-unreads
5048             (gnus-sorted-nintersection
5049              gnus-newsgroup-unreads fetched-articles))
5050       (gnus-compute-unseen-list)
5051
5052       ;; Removed marked articles that do not exist.
5053       (gnus-update-missing-marks
5054        (gnus-sorted-difference articles fetched-articles))
5055       ;; We might want to build some more threads first.
5056       (when (and gnus-fetch-old-headers
5057                  (eq gnus-headers-retrieved-by 'nov))
5058         (if (eq gnus-fetch-old-headers 'invisible)
5059             (gnus-build-all-threads)
5060           (gnus-build-old-threads)))
5061       ;; Let the Gnus agent mark articles as read.
5062       (when gnus-agent
5063         (gnus-agent-get-undownloaded-list))
5064       ;; Remove list identifiers from subject
5065       (when gnus-list-identifiers
5066         (gnus-summary-remove-list-identifiers))
5067       ;; Check whether auto-expire is to be done in this group.
5068       (setq gnus-newsgroup-auto-expire
5069             (gnus-group-auto-expirable-p group))
5070       ;; Set up the article buffer now, if necessary.
5071       (unless gnus-single-article-buffer
5072         (gnus-article-setup-buffer))
5073       ;; First and last article in this newsgroup.
5074       (when gnus-newsgroup-headers
5075         (setq gnus-newsgroup-begin
5076               (mail-header-number (car gnus-newsgroup-headers))
5077               gnus-newsgroup-end
5078               (mail-header-number
5079                (gnus-last-element gnus-newsgroup-headers))))
5080       ;; GROUP is successfully selected.
5081       (or gnus-newsgroup-headers t)))))
5082
5083 (defun gnus-compute-unseen-list ()
5084   ;; The `seen' marks are treated specially.
5085   (if (not gnus-newsgroup-seen)
5086       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5087     (setq gnus-newsgroup-unseen
5088           (gnus-inverse-list-range-intersection
5089            gnus-newsgroup-articles gnus-newsgroup-seen))))
5090
5091 (defun gnus-summary-display-make-predicate (display)
5092   (require 'gnus-agent)
5093   (when (= (length display) 1)
5094     (setq display (car display)))
5095   (unless gnus-summary-display-cache
5096     (dolist (elem (append '((unread . unread)
5097                             (read . read)
5098                             (unseen . unseen))
5099                           gnus-article-mark-lists))
5100       (push (cons (cdr elem)
5101                   (gnus-byte-compile
5102                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5103             gnus-summary-display-cache)))
5104   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5105         (gnus-category-predicate-cache gnus-summary-display-cache))
5106     (gnus-get-predicate display)))
5107
5108 ;; Uses the dynamically bound `number' variable.
5109 (eval-when-compile
5110   (defvar number))
5111 (defun gnus-article-marked-p (type &optional article)
5112   (let ((article (or article number)))
5113     (cond
5114      ((eq type 'tick)
5115       (memq article gnus-newsgroup-marked))
5116      ((eq type 'spam)
5117       (memq article gnus-newsgroup-spam-marked))
5118      ((eq type 'unsend)
5119       (memq article gnus-newsgroup-unsendable))
5120      ((eq type 'undownload)
5121       (memq article gnus-newsgroup-undownloaded))
5122      ((eq type 'download)
5123       (memq article gnus-newsgroup-downloadable))
5124      ((eq type 'unread)
5125       (memq article gnus-newsgroup-unreads))
5126      ((eq type 'read)
5127       (memq article gnus-newsgroup-reads))
5128      ((eq type 'dormant)
5129       (memq article gnus-newsgroup-dormant) )
5130      ((eq type 'expire)
5131       (memq article gnus-newsgroup-expirable))
5132      ((eq type 'reply)
5133       (memq article gnus-newsgroup-replied))
5134      ((eq type 'killed)
5135       (memq article gnus-newsgroup-killed))
5136      ((eq type 'bookmark)
5137       (assq article gnus-newsgroup-bookmarks))
5138      ((eq type 'score)
5139       (assq article gnus-newsgroup-scored))
5140      ((eq type 'save)
5141       (memq article gnus-newsgroup-saved))
5142      ((eq type 'cache)
5143       (memq article gnus-newsgroup-cached))
5144      ((eq type 'forward)
5145       (memq article gnus-newsgroup-forwarded))
5146      ((eq type 'seen)
5147       (not (memq article gnus-newsgroup-unseen)))
5148      ((eq type 'recent)
5149       (memq article gnus-newsgroup-recent))
5150      (t t))))
5151
5152 (defun gnus-articles-to-read (group &optional read-all)
5153   "Find out what articles the user wants to read."
5154   (let* ((display (gnus-group-find-parameter group 'display))
5155          (articles
5156           ;; Select all articles if `read-all' is non-nil, or if there
5157           ;; are no unread articles.
5158           (if (or read-all
5159                   (and (zerop (length gnus-newsgroup-marked))
5160                        (zerop (length gnus-newsgroup-unreads)))
5161                   ;; Fetch all if the predicate is non-nil.
5162                   gnus-newsgroup-display)
5163               ;; We want to select the headers for all the articles in
5164               ;; the group, so we select either all the active
5165               ;; articles in the group, or (if that's nil), the
5166               ;; articles in the cache.
5167               (or
5168                (gnus-uncompress-range (gnus-active group))
5169                (gnus-cache-articles-in-group group))
5170             ;; Select only the "normal" subset of articles.
5171             (gnus-sorted-nunion
5172              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5173              gnus-newsgroup-unreads)))
5174          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5175          (scored (length scored-list))
5176          (number (length articles))
5177          (marked (+ (length gnus-newsgroup-marked)
5178                     (length gnus-newsgroup-dormant)))
5179          (select
5180           (cond
5181            ((numberp read-all)
5182             read-all)
5183            ((numberp gnus-newsgroup-display)
5184             gnus-newsgroup-display)
5185            (t
5186             (condition-case ()
5187                 (cond
5188                  ((and (or (<= scored marked) (= scored number))
5189                        (numberp gnus-large-newsgroup)
5190                        (> number gnus-large-newsgroup))
5191                   (let* ((cursor-in-echo-area nil)
5192                          (initial (gnus-parameter-large-newsgroup-initial
5193                                    gnus-newsgroup-name))
5194                          (input
5195                           (read-string
5196                            (format
5197                             "How many articles from %s (%s %d): "
5198                             (gnus-limit-string
5199                              (gnus-group-decoded-name gnus-newsgroup-name)
5200                              35)
5201                             (if initial "max" "default")
5202                             number)
5203                            (if initial
5204                                (cons (number-to-string initial)
5205                                      0)))))
5206                     (if (string-match "^[ \t]*$" input) number input)))
5207                  ((and (> scored marked) (< scored number)
5208                        (> (- scored number) 20))
5209                   (let ((input
5210                          (read-string
5211                           (format "%s %s (%d scored, %d total): "
5212                                   "How many articles from"
5213                                   (gnus-group-decoded-name group)
5214                                   scored number))))
5215                     (if (string-match "^[ \t]*$" input)
5216                         number input)))
5217                  (t number))
5218               (quit
5219                (message "Quit getting the articles to read")
5220                nil))))))
5221     (setq select (if (stringp select) (string-to-number select) select))
5222     (if (or (null select) (zerop select))
5223         select
5224       (if (and (not (zerop scored)) (<= (abs select) scored))
5225           (progn
5226             (setq articles (sort scored-list '<))
5227             (setq number (length articles)))
5228         (setq articles (copy-sequence articles)))
5229
5230       (when (< (abs select) number)
5231         (if (< select 0)
5232             ;; Select the N oldest articles.
5233             (setcdr (nthcdr (1- (abs select)) articles) nil)
5234           ;; Select the N most recent articles.
5235           (setq articles (nthcdr (- number select) articles))))
5236       (setq gnus-newsgroup-unselected
5237             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5238       (when gnus-alter-articles-to-read-function
5239         (setq articles
5240               (sort
5241                (funcall gnus-alter-articles-to-read-function
5242                         gnus-newsgroup-name articles)
5243                '<)))
5244       articles)))
5245
5246 (defun gnus-killed-articles (killed articles)
5247   (let (out)
5248     (while articles
5249       (when (inline (gnus-member-of-range (car articles) killed))
5250         (push (car articles) out))
5251       (setq articles (cdr articles)))
5252     out))
5253
5254 (defun gnus-uncompress-marks (marks)
5255   "Uncompress the mark ranges in MARKS."
5256   (let ((uncompressed '(score bookmark))
5257         out)
5258     (while marks
5259       (if (memq (caar marks) uncompressed)
5260           (push (car marks) out)
5261         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5262       (setq marks (cdr marks)))
5263     out))
5264
5265 (defun gnus-article-mark-to-type (mark)
5266   "Return the type of MARK."
5267   (or (cadr (assq mark gnus-article-special-mark-lists))
5268       'list))
5269
5270 (defun gnus-article-unpropagatable-p (mark)
5271   "Return whether MARK should be propagated to backend."
5272   (memq mark gnus-article-unpropagated-mark-lists))
5273
5274 (defun gnus-adjust-marked-articles (info)
5275   "Set all article lists and remove all marks that are no longer valid."
5276   (let* ((marked-lists (gnus-info-marks info))
5277          (active (gnus-active (gnus-info-group info)))
5278          (min (car active))
5279          (max (cdr active))
5280          (types gnus-article-mark-lists)
5281          marks var articles article mark mark-type)
5282
5283     (dolist (marks marked-lists)
5284       (setq mark (car marks)
5285             mark-type (gnus-article-mark-to-type mark)
5286             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5287
5288       ;; We set the variable according to the type of the marks list,
5289       ;; and then adjust the marks to a subset of the active articles.
5290       (cond
5291        ;; Adjust "simple" lists.
5292        ((eq mark-type 'list)
5293         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5294         (when (memq mark '(tick dormant expire reply save))
5295           (while articles
5296             (when (or (< (setq article (pop articles)) min) (> article max))
5297               (set var (delq article (symbol-value var)))))))
5298        ;; Adjust assocs.
5299        ((eq mark-type 'tuple)
5300         (set var (setq articles (cdr marks)))
5301         (when (not (listp (cdr (symbol-value var))))
5302           (set var (list (symbol-value var))))
5303         (when (not (listp (cdr articles)))
5304           (setq articles (list articles)))
5305         (while articles
5306           (when (or (not (consp (setq article (pop articles))))
5307                     (< (car article) min)
5308                     (> (car article) max))
5309             (set var (delq article (symbol-value var))))))
5310        ;; Adjust ranges (sloppily).
5311        ((eq mark-type 'range)
5312         (cond
5313          ((eq mark 'seen)
5314           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5315           ;; It should be (seen (NUM1 . NUM2)).
5316           (when (numberp (cddr marks))
5317             (setcdr marks (list (cdr marks))))
5318           (setq articles (cdr marks))
5319           (while (and articles
5320                       (or (and (consp (car articles))
5321                                (> min (cdar articles)))
5322                           (and (numberp (car articles))
5323                                (> min (car articles)))))
5324             (pop articles))
5325           (set var articles))))))))
5326
5327 (defun gnus-update-missing-marks (missing)
5328   "Go through the list of MISSING articles and remove them from the mark lists."
5329   (when missing
5330     (let (var m)
5331       ;; Go through all types.
5332       (dolist (elem gnus-article-mark-lists)
5333         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5334           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5335           (when (symbol-value var)
5336             ;; This list has articles.  So we delete all missing
5337             ;; articles from it.
5338             (setq m missing)
5339             (while m
5340               (set var (delq (pop m) (symbol-value var))))))))))
5341
5342 (defun gnus-update-marks ()
5343   "Enter the various lists of marked articles into the newsgroup info list."
5344   (let ((types gnus-article-mark-lists)
5345         (info (gnus-get-info gnus-newsgroup-name))
5346         type list newmarked symbol delta-marks)
5347     (when info
5348       ;; Add all marks lists to the list of marks lists.
5349       (while (setq type (pop types))
5350         (setq list (symbol-value
5351                     (setq symbol
5352                           (intern (format "gnus-newsgroup-%s" (car type))))))
5353
5354         (when list
5355           ;; Get rid of the entries of the articles that have the
5356           ;; default score.
5357           (when (and (eq (cdr type) 'score)
5358                      gnus-save-score
5359                      list)
5360             (let* ((arts list)
5361                    (prev (cons nil list))
5362                    (all prev))
5363               (while arts
5364                 (if (or (not (consp (car arts)))
5365                         (= (cdar arts) gnus-summary-default-score))
5366                     (setcdr prev (cdr arts))
5367                   (setq prev arts))
5368                 (setq arts (cdr arts)))
5369               (setq list (cdr all)))))
5370
5371         (when (eq (cdr type) 'seen)
5372           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5373
5374         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5375           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5376
5377         (when (and (gnus-check-backend-function
5378                     'request-set-mark gnus-newsgroup-name)
5379                    (not (gnus-article-unpropagatable-p (cdr type))))
5380           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5381                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5382                  (add (gnus-remove-from-range
5383                        (gnus-copy-sequence list) old)))
5384             (when add
5385               (push (list add 'add (list (cdr type))) delta-marks))
5386             (when del
5387               (push (list del 'del (list (cdr type))) delta-marks))))
5388
5389         (when list
5390           (push (cons (cdr type) list) newmarked)))
5391
5392       (when delta-marks
5393         (unless (gnus-check-group gnus-newsgroup-name)
5394           (error "Can't open server for %s" gnus-newsgroup-name))
5395         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5396
5397       ;; Enter these new marks into the info of the group.
5398       (if (nthcdr 3 info)
5399           (setcar (nthcdr 3 info) newmarked)
5400         ;; Add the marks lists to the end of the info.
5401         (when newmarked
5402           (setcdr (nthcdr 2 info) (list newmarked))))
5403
5404       ;; Cut off the end of the info if there's nothing else there.
5405       (let ((i 5))
5406         (while (and (> i 2)
5407                     (not (nth i info)))
5408           (when (nthcdr (decf i) info)
5409             (setcdr (nthcdr i info) nil)))))))
5410
5411 (defun gnus-set-mode-line (where)
5412   "Set the mode line of the article or summary buffers.
5413 If WHERE is `summary', the summary mode line format will be used."
5414   ;; Is this mode line one we keep updated?
5415   (when (and (memq where gnus-updated-mode-lines)
5416              (symbol-value
5417               (intern (format "gnus-%s-mode-line-format-spec" where))))
5418     (let (mode-string)
5419       (save-excursion
5420         ;; We evaluate this in the summary buffer since these
5421         ;; variables are buffer-local to that buffer.
5422         (set-buffer gnus-summary-buffer)
5423         ;; We bind all these variables that are used in the `eval' form
5424         ;; below.
5425         (let* ((mformat (symbol-value
5426                          (intern
5427                           (format "gnus-%s-mode-line-format-spec" where))))
5428                (gnus-tmp-group-name (gnus-group-decoded-name
5429                                      gnus-newsgroup-name))
5430                (gnus-tmp-article-number (or gnus-current-article 0))
5431                (gnus-tmp-unread gnus-newsgroup-unreads)
5432                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5433                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5434                (gnus-tmp-unread-and-unselected
5435                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5436                             (zerop gnus-tmp-unselected))
5437                        "")
5438                       ((zerop gnus-tmp-unselected)
5439                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5440                       (t (format "{%d(+%d) more}"
5441                                  gnus-tmp-unread-and-unticked
5442                                  gnus-tmp-unselected))))
5443                (gnus-tmp-subject
5444                 (if (and gnus-current-headers
5445                          (vectorp gnus-current-headers))
5446                     (gnus-mode-string-quote
5447                      (mail-header-subject gnus-current-headers))
5448                   ""))
5449                bufname-length max-len
5450                gnus-tmp-header);; passed as argument to any user-format-funcs
5451           (setq mode-string (eval mformat))
5452           (setq bufname-length (if (string-match "%b" mode-string)
5453                                    (- (length
5454                                        (buffer-name
5455                                         (if (eq where 'summary)
5456                                             nil
5457                                           (get-buffer gnus-article-buffer))))
5458                                       2)
5459                                  0))
5460           (setq max-len (max 4 (if gnus-mode-non-string-length
5461                                    (- (window-width)
5462                                       gnus-mode-non-string-length
5463                                       bufname-length)
5464                                  (length mode-string))))
5465           ;; We might have to chop a bit of the string off...
5466           (when (> (length mode-string) max-len)
5467             (setq mode-string
5468                   (concat (gnus-truncate-string mode-string (- max-len 3))
5469                           "...")))
5470           ;; Pad the mode string a bit.
5471           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5472       ;; Update the mode line.
5473       (setq mode-line-buffer-identification
5474             (gnus-mode-line-buffer-identification (list mode-string)))
5475       (set-buffer-modified-p t))))
5476
5477 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5478   "Go through the HEADERS list and add all Xrefs to a hash table.
5479 The resulting hash table is returned, or nil if no Xrefs were found."
5480   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5481          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5482          (xref-hashtb (gnus-make-hashtable))
5483          start group entry number xrefs header)
5484     (while headers
5485       (setq header (pop headers))
5486       (when (and (setq xrefs (mail-header-xref header))
5487                  (not (memq (setq number (mail-header-number header))
5488                             unreads)))
5489         (setq start 0)
5490         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5491           (setq start (match-end 0))
5492           (setq group (if prefix
5493                           (concat prefix (substring xrefs (match-beginning 1)
5494                                                     (match-end 1)))
5495                         (substring xrefs (match-beginning 1) (match-end 1))))
5496           (setq number
5497                 (string-to-int (substring xrefs (match-beginning 2)
5498                                           (match-end 2))))
5499           (if (setq entry (gnus-gethash group xref-hashtb))
5500               (setcdr entry (cons number (cdr entry)))
5501             (gnus-sethash group (cons number nil) xref-hashtb)))))
5502     (and start xref-hashtb)))
5503
5504 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5505   "Look through all the headers and mark the Xrefs as read."
5506   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5507         name entry info xref-hashtb idlist method nth4)
5508     (save-excursion
5509       (set-buffer gnus-group-buffer)
5510       (when (setq xref-hashtb
5511                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5512         (mapatoms
5513          (lambda (group)
5514            (unless (string= from-newsgroup (setq name (symbol-name group)))
5515              (setq idlist (symbol-value group))
5516              ;; Dead groups are not updated.
5517              (and (prog1
5518                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5519                             info (nth 2 entry))
5520                     (when (stringp (setq nth4 (gnus-info-method info)))
5521                       (setq nth4 (gnus-server-to-method nth4))))
5522                   ;; Only do the xrefs if the group has the same
5523                   ;; select method as the group we have just read.
5524                   (or (gnus-methods-equal-p
5525                        nth4 (gnus-find-method-for-group from-newsgroup))
5526                       virtual
5527                       (equal nth4 (setq method (gnus-find-method-for-group
5528                                                 from-newsgroup)))
5529                       (and (equal (car nth4) (car method))
5530                            (equal (nth 1 nth4) (nth 1 method))))
5531                   gnus-use-cross-reference
5532                   (or (not (eq gnus-use-cross-reference t))
5533                       virtual
5534                       ;; Only do cross-references on subscribed
5535                       ;; groups, if that is what is wanted.
5536                       (<= (gnus-info-level info) gnus-level-subscribed))
5537                   (gnus-group-make-articles-read name idlist))))
5538          xref-hashtb)))))
5539
5540 (defun gnus-compute-read-articles (group articles)
5541   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5542          (info (nth 2 entry))
5543          (active (gnus-active group))
5544          ninfo)
5545     (when entry
5546       ;; First peel off all invalid article numbers.
5547       (when active
5548         (let ((ids articles)
5549               id first)
5550           (while (setq id (pop ids))
5551             (when (and first (> id (cdr active)))
5552               ;; We'll end up in this situation in one particular
5553               ;; obscure situation.  If you re-scan a group and get
5554               ;; a new article that is cross-posted to a different
5555               ;; group that has not been re-scanned, you might get
5556               ;; crossposted article that has a higher number than
5557               ;; Gnus believes possible.  So we re-activate this
5558               ;; group as well.  This might mean doing the
5559               ;; crossposting thingy will *increase* the number
5560               ;; of articles in some groups.  Tsk, tsk.
5561               (setq active (or (gnus-activate-group group) active)))
5562             (when (or (> id (cdr active))
5563                       (< id (car active)))
5564               (setq articles (delq id articles))))))
5565       ;; If the read list is nil, we init it.
5566       (if (and active
5567                (null (gnus-info-read info))
5568                (> (car active) 1))
5569           (setq ninfo (cons 1 (1- (car active))))
5570         (setq ninfo (gnus-info-read info)))
5571       ;; Then we add the read articles to the range.
5572       (gnus-add-to-range
5573        ninfo (setq articles (sort articles '<))))))
5574
5575 (defun gnus-group-make-articles-read (group articles)
5576   "Update the info of GROUP to say that ARTICLES are read."
5577   (let* ((num 0)
5578          (entry (gnus-gethash group gnus-newsrc-hashtb))
5579          (info (nth 2 entry))
5580          (active (gnus-active group))
5581          range)
5582     (when entry
5583       (setq range (gnus-compute-read-articles group articles))
5584       (save-excursion
5585         (set-buffer gnus-group-buffer)
5586         (gnus-undo-register
5587           `(progn
5588              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5589              (gnus-info-set-read ',info ',(gnus-info-read info))
5590              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5591              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5592              (gnus-group-update-group ,group t))))
5593       ;; Add the read articles to the range.
5594       (gnus-info-set-read info range)
5595       (gnus-request-set-mark group (list (list range 'add '(read))))
5596       ;; Then we have to re-compute how many unread
5597       ;; articles there are in this group.
5598       (when active
5599         (cond
5600          ((not range)
5601           (setq num (- (1+ (cdr active)) (car active))))
5602          ((not (listp (cdr range)))
5603           (setq num (- (cdr active) (- (1+ (cdr range))
5604                                        (car range)))))
5605          (t
5606           (while range
5607             (if (numberp (car range))
5608                 (setq num (1+ num))
5609               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5610             (setq range (cdr range)))
5611           (setq num (- (cdr active) num))))
5612         ;; Update the number of unread articles.
5613         (setcar entry num)
5614         ;; Update the group buffer.
5615         (unless (gnus-ephemeral-group-p group)
5616           (gnus-group-update-group group t))))))
5617
5618 (defvar gnus-newsgroup-none-id 0)
5619
5620 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5621   (let ((cur nntp-server-buffer)
5622         (dependencies
5623          (or dependencies
5624              (save-excursion (set-buffer gnus-summary-buffer)
5625                              gnus-newsgroup-dependencies)))
5626         headers id end ref
5627         (mail-parse-charset gnus-newsgroup-charset)
5628         (mail-parse-ignored-charsets
5629          (save-excursion (condition-case nil
5630                              (set-buffer gnus-summary-buffer)
5631                            (error))
5632                          gnus-newsgroup-ignored-charsets)))
5633     (save-excursion
5634       (set-buffer nntp-server-buffer)
5635       ;; Translate all TAB characters into SPACE characters.
5636       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5637       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5638       (gnus-run-hooks 'gnus-parse-headers-hook)
5639       (let ((case-fold-search t)
5640             in-reply-to header p lines chars ctype)
5641         (goto-char (point-min))
5642         ;; Search to the beginning of the next header.  Error messages
5643         ;; do not begin with 2 or 3.
5644         (while (re-search-forward "^[23][0-9]+ " nil t)
5645           (setq id nil
5646                 ref nil)
5647           ;; This implementation of this function, with nine
5648           ;; search-forwards instead of the one re-search-forward and
5649           ;; a case (which basically was the old function) is actually
5650           ;; about twice as fast, even though it looks messier.  You
5651           ;; can't have everything, I guess.  Speed and elegance
5652           ;; doesn't always go hand in hand.
5653           (setq
5654            header
5655            (make-full-mail-header
5656             ;; Number.
5657             (prog1
5658                 (read cur)
5659               (end-of-line)
5660               (setq p (point))
5661               (narrow-to-region (point)
5662                                 (or (and (search-forward "\n.\n" nil t)
5663                                          (- (point) 2))
5664                                     (point))))
5665             ;; Subject.
5666             (progn
5667               (goto-char p)
5668               (if (search-forward "\nsubject:" nil t)
5669                   (nnheader-header-value)
5670                 "(none)"))
5671             ;; From.
5672             (progn
5673               (goto-char p)
5674               (if (search-forward "\nfrom:" nil t)
5675                   (nnheader-header-value)
5676                 "(nobody)"))
5677             ;; Date.
5678             (progn
5679               (goto-char p)
5680               (if (search-forward "\ndate:" nil t)
5681                   (nnheader-header-value) ""))
5682             ;; Message-ID.
5683             (progn
5684               (goto-char p)
5685               (setq id (if (re-search-forward
5686                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5687                            ;; We do it this way to make sure the Message-ID
5688                            ;; is (somewhat) syntactically valid.
5689                            (buffer-substring (match-beginning 1)
5690                                              (match-end 1))
5691                          ;; If there was no message-id, we just fake one
5692                          ;; to make subsequent routines simpler.
5693                          (nnheader-generate-fake-message-id))))
5694             ;; References.
5695             (progn
5696               (goto-char p)
5697               (if (search-forward "\nreferences:" nil t)
5698                   (progn
5699                     (setq end (point))
5700                     (prog1
5701                         (nnheader-header-value)
5702                       (setq ref
5703                             (buffer-substring
5704                              (progn
5705                                ;; (end-of-line)
5706                                (search-backward ">" end t)
5707                                (1+ (point)))
5708                              (progn
5709                                (search-backward "<" end t)
5710                                (point))))))
5711                 ;; Get the references from the in-reply-to header if there
5712                 ;; were no references and the in-reply-to header looks
5713                 ;; promising.
5714                 (if (and (search-forward "\nin-reply-to:" nil t)
5715                          (setq in-reply-to (nnheader-header-value))
5716                          (string-match "<[^>]+>" in-reply-to))
5717                     (let (ref2)
5718                       (setq ref (substring in-reply-to (match-beginning 0)
5719                                            (match-end 0)))
5720                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5721                         (setq ref2 (substring in-reply-to (match-beginning 0)
5722                                               (match-end 0)))
5723                         (when (> (length ref2) (length ref))
5724                           (setq ref ref2)))
5725                       ref)
5726                   (setq ref nil))))
5727             ;; Chars.
5728             (progn
5729               (goto-char p)
5730               (if (search-forward "\nchars: " nil t)
5731                   (if (numberp (setq chars (ignore-errors (read cur))))
5732                       chars -1)
5733                 -1))
5734             ;; Lines.
5735             (progn
5736               (goto-char p)
5737               (if (search-forward "\nlines: " nil t)
5738                   (if (numberp (setq lines (ignore-errors (read cur))))
5739                       lines -1)
5740                 -1))
5741             ;; Xref.
5742             (progn
5743               (goto-char p)
5744               (and (search-forward "\nxref:" nil t)
5745                    (nnheader-header-value)))
5746             ;; Extra.
5747             (when gnus-extra-headers
5748               (let ((extra gnus-extra-headers)
5749                     out)
5750                 (while extra
5751                   (goto-char p)
5752                   (when (search-forward
5753                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5754                     (push (cons (car extra) (nnheader-header-value)) out))
5755                   (pop extra))
5756                 out))))
5757           (goto-char p)
5758           (if (and (search-forward "\ncontent-type: " nil t)
5759                    (setq ctype (nnheader-header-value)))
5760               (mime-entity-set-content-type-internal
5761                header (mime-parse-Content-Type ctype)))
5762           (when (equal id ref)
5763             (setq ref nil))
5764
5765           (when gnus-alter-header-function
5766             (funcall gnus-alter-header-function header)
5767             (setq id (mail-header-id header)
5768                   ref (gnus-parent-id (mail-header-references header))))
5769
5770           (when (setq header
5771                       (gnus-dependencies-add-header
5772                        header dependencies force-new))
5773             (push header headers))
5774           (goto-char (point-max))
5775           (widen))
5776         (nreverse headers)))))
5777
5778 ;; Goes through the xover lines and returns a list of vectors
5779 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5780                                                   force-new dependencies
5781                                                   group also-fetch-heads)
5782   "Parse the news overview data in the server buffer.
5783 Return a list of headers that match SEQUENCE (see
5784 `nntp-retrieve-headers')."
5785   ;; Get the Xref when the users reads the articles since most/some
5786   ;; NNTP servers do not include Xrefs when using XOVER.
5787   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5788   (let ((mail-parse-charset gnus-newsgroup-charset)
5789         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5790         (cur nntp-server-buffer)
5791         (dependencies (or dependencies gnus-newsgroup-dependencies))
5792         (allp (cond
5793                ((eq gnus-read-all-available-headers t)
5794                 t)
5795                ((stringp gnus-read-all-available-headers)
5796                 (string-match gnus-read-all-available-headers group))
5797                (t
5798                 nil)))
5799         number headers header)
5800     (save-excursion
5801       (set-buffer nntp-server-buffer)
5802       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5803       ;; Allow the user to mangle the headers before parsing them.
5804       (gnus-run-hooks 'gnus-parse-headers-hook)
5805       (goto-char (point-min))
5806       (gnus-parse-without-error
5807         (while (and (or sequence allp)
5808                     (not (eobp)))
5809           (setq number (read cur))
5810           (when (not allp)
5811             (while (and sequence
5812                         (< (car sequence) number))
5813               (setq sequence (cdr sequence))))
5814           (when (and (or allp
5815                          (and sequence
5816                               (eq number (car sequence))))
5817                      (progn
5818                        (setq sequence (cdr sequence))
5819                        (setq header (inline
5820                                       (gnus-nov-parse-line
5821                                        number dependencies force-new)))))
5822             (push header headers))
5823           (forward-line 1)))
5824       ;; A common bug in inn is that if you have posted an article and
5825       ;; then retrieves the active file, it will answer correctly --
5826       ;; the new article is included.  However, a NOV entry for the
5827       ;; article may not have been generated yet, so this may fail.
5828       ;; We work around this problem by retrieving the last few
5829       ;; headers using HEAD.
5830       (if (or (not also-fetch-heads)
5831               (not sequence))
5832           ;; We (probably) got all the headers.
5833           (nreverse headers)
5834         (let ((gnus-nov-is-evil t))
5835           (nconc
5836            (nreverse headers)
5837            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5838              (gnus-get-newsgroup-headers))))))))
5839
5840 (defun gnus-article-get-xrefs ()
5841   "Fill in the Xref value in `gnus-current-headers', if necessary.
5842 This is meant to be called in `gnus-article-internal-prepare-hook'."
5843   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5844                                  gnus-current-headers)))
5845     (or (not gnus-use-cross-reference)
5846         (not headers)
5847         (and (mail-header-xref headers)
5848              (not (string= (mail-header-xref headers) "")))
5849         (let ((case-fold-search t)
5850               xref)
5851           (save-restriction
5852             (nnheader-narrow-to-headers)
5853             (goto-char (point-min))
5854             (when (or (and (not (eobp))
5855                            (eq (downcase (char-after)) ?x)
5856                            (looking-at "Xref:"))
5857                       (search-forward "\nXref:" nil t))
5858               (goto-char (1+ (match-end 0)))
5859               (setq xref (buffer-substring (point)
5860                                            (progn (end-of-line) (point))))
5861               (mail-header-set-xref headers xref)))))))
5862
5863 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5864   "Find article ID and insert the summary line for that article.
5865 OLD-HEADER can either be a header or a line number to insert
5866 the subject line on."
5867   (let* ((line (and (numberp old-header) old-header))
5868          (old-header (and (vectorp old-header) old-header))
5869          (header (cond ((and old-header use-old-header)
5870                         old-header)
5871                        ((and (numberp id)
5872                              (gnus-number-to-header id))
5873                         (gnus-number-to-header id))
5874                        (t
5875                         (gnus-read-header id))))
5876          (number (and (numberp id) id))
5877          d)
5878     (when header
5879       ;; Rebuild the thread that this article is part of and go to the
5880       ;; article we have fetched.
5881       (when (and (not gnus-show-threads)
5882                  old-header)
5883         (when (and number
5884                    (setq d (gnus-data-find (mail-header-number old-header))))
5885           (goto-char (gnus-data-pos d))
5886           (gnus-data-remove
5887            number
5888            (- (gnus-point-at-bol)
5889               (prog1
5890                   (1+ (gnus-point-at-eol))
5891                 (gnus-delete-line))))))
5892       (when old-header
5893         (mail-header-set-number header (mail-header-number old-header)))
5894       (setq gnus-newsgroup-sparse
5895             (delq (setq number (mail-header-number header))
5896                   gnus-newsgroup-sparse))
5897       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5898       (push number gnus-newsgroup-limit)
5899       (gnus-rebuild-thread (mail-header-id header) line)
5900       (gnus-summary-goto-subject number nil t))
5901     (when (and (numberp number)
5902                (> number 0))
5903       ;; We have to update the boundaries even if we can't fetch the
5904       ;; article if ID is a number -- so that the next `P' or `N'
5905       ;; command will fetch the previous (or next) article even
5906       ;; if the one we tried to fetch this time has been canceled.
5907       (when (> number gnus-newsgroup-end)
5908         (setq gnus-newsgroup-end number))
5909       (when (< number gnus-newsgroup-begin)
5910         (setq gnus-newsgroup-begin number))
5911       (setq gnus-newsgroup-unselected
5912             (delq number gnus-newsgroup-unselected)))
5913     ;; Report back a success?
5914     (and header (mail-header-number header))))
5915
5916 ;;; Process/prefix in the summary buffer
5917
5918 (defun gnus-summary-work-articles (n)
5919   "Return a list of articles to be worked upon.
5920 The prefix argument, the list of process marked articles, and the
5921 current article will be taken into consideration."
5922   (save-excursion
5923     (set-buffer gnus-summary-buffer)
5924     (cond
5925      (n
5926       ;; A numerical prefix has been given.
5927       (setq n (prefix-numeric-value n))
5928       (let ((backward (< n 0))
5929             (n (abs (prefix-numeric-value n)))
5930             articles article)
5931         (save-excursion
5932           (while
5933               (and (> n 0)
5934                    (push (setq article (gnus-summary-article-number))
5935                          articles)
5936                    (if backward
5937                        (gnus-summary-find-prev nil article)
5938                      (gnus-summary-find-next nil article)))
5939             (decf n)))
5940         (nreverse articles)))
5941      ((and (gnus-region-active-p) (mark))
5942       (message "region active")
5943       ;; Work on the region between point and mark.
5944       (let ((max (max (point) (mark)))
5945             articles article)
5946         (save-excursion
5947           (goto-char (min (point) (mark)))
5948           (while
5949               (and
5950                (push (setq article (gnus-summary-article-number)) articles)
5951                (gnus-summary-find-next nil article)
5952                (< (point) max)))
5953           (nreverse articles))))
5954      (gnus-newsgroup-processable
5955       ;; There are process-marked articles present.
5956       ;; Save current state.
5957       (gnus-summary-save-process-mark)
5958       ;; Return the list.
5959       (reverse gnus-newsgroup-processable))
5960      (t
5961       ;; Just return the current article.
5962       (list (gnus-summary-article-number))))))
5963
5964 (defmacro gnus-summary-iterate (arg &rest forms)
5965   "Iterate over the process/prefixed articles and do FORMS.
5966 ARG is the interactive prefix given to the command.  FORMS will be
5967 executed with point over the summary line of the articles."
5968   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5969     `(let ((,articles (gnus-summary-work-articles ,arg)))
5970        (while ,articles
5971          (gnus-summary-goto-subject (car ,articles))
5972          ,@forms
5973          (pop ,articles)))))
5974
5975 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5976 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5977
5978 (defun gnus-summary-save-process-mark ()
5979   "Push the current set of process marked articles on the stack."
5980   (interactive)
5981   (push (copy-sequence gnus-newsgroup-processable)
5982         gnus-newsgroup-process-stack))
5983
5984 (defun gnus-summary-kill-process-mark ()
5985   "Push the current set of process marked articles on the stack and unmark."
5986   (interactive)
5987   (gnus-summary-save-process-mark)
5988   (gnus-summary-unmark-all-processable))
5989
5990 (defun gnus-summary-yank-process-mark ()
5991   "Pop the last process mark state off the stack and restore it."
5992   (interactive)
5993   (unless gnus-newsgroup-process-stack
5994     (error "Empty mark stack"))
5995   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5996
5997 (defun gnus-summary-process-mark-set (set)
5998   "Make SET into the current process marked articles."
5999   (gnus-summary-unmark-all-processable)
6000   (while set
6001     (gnus-summary-set-process-mark (pop set))))
6002
6003 ;;; Searching and stuff
6004
6005 (defun gnus-summary-search-group (&optional backward use-level)
6006   "Search for next unread newsgroup.
6007 If optional argument BACKWARD is non-nil, search backward instead."
6008   (save-excursion
6009     (set-buffer gnus-group-buffer)
6010     (when (gnus-group-search-forward
6011            backward nil (if use-level (gnus-group-group-level) nil))
6012       (gnus-group-group-name))))
6013
6014 (defun gnus-summary-best-group (&optional exclude-group)
6015   "Find the name of the best unread group.
6016 If EXCLUDE-GROUP, do not go to this group."
6017   (save-excursion
6018     (set-buffer gnus-group-buffer)
6019     (save-excursion
6020       (gnus-group-best-unread-group exclude-group))))
6021
6022 (defun gnus-summary-find-next (&optional unread article backward)
6023   (if backward (gnus-summary-find-prev)
6024     (let* ((dummy (gnus-summary-article-intangible-p))
6025            (article (or article (gnus-summary-article-number)))
6026            (data (gnus-data-find-list article))
6027            result)
6028       (when (and (not dummy)
6029                  (or (not gnus-summary-check-current)
6030                      (not unread)
6031                      (not (gnus-data-unread-p (car data)))))
6032         (setq data (cdr data)))
6033       (when (setq result
6034                   (if unread
6035                       (progn
6036                         (while data
6037                           (unless (memq (gnus-data-number (car data)) 
6038                                         gnus-newsgroup-unfetched)
6039                             (when (gnus-data-unread-p (car data))
6040                               (setq result (car data)
6041                                     data nil)))
6042                           (setq data (cdr data)))
6043                         result)
6044                     (car data)))
6045         (goto-char (gnus-data-pos result))
6046         (gnus-data-number result)))))
6047
6048 (defun gnus-summary-find-prev (&optional unread article)
6049   (let* ((eobp (eobp))
6050          (article (or article (gnus-summary-article-number)))
6051          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6052          result)
6053     (when (and (not eobp)
6054                (or (not gnus-summary-check-current)
6055                    (not unread)
6056                    (not (gnus-data-unread-p (car data)))))
6057       (setq data (cdr data)))
6058     (when (setq result
6059                 (if unread
6060                     (progn
6061                       (while data
6062                         (unless (memq (gnus-data-number (car data)) gnus-newsgroup-unfetched)
6063                           (when (gnus-data-unread-p (car data))
6064                             (setq result (car data)
6065                                   data nil)))
6066                         (setq data (cdr data)))
6067                       result)
6068                   (car data)))
6069       (goto-char (gnus-data-pos result))
6070       (gnus-data-number result))))
6071
6072 (defun gnus-summary-find-subject (subject &optional unread backward article)
6073   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6074          (article (or article (gnus-summary-article-number)))
6075          (articles (gnus-data-list backward))
6076          (arts (gnus-data-find-list article articles))
6077          result)
6078     (when (or (not gnus-summary-check-current)
6079               (not unread)
6080               (not (gnus-data-unread-p (car arts))))
6081       (setq arts (cdr arts)))
6082     (while arts
6083       (and (or (not unread)
6084                (gnus-data-unread-p (car arts)))
6085            (vectorp (gnus-data-header (car arts)))
6086            (gnus-subject-equal
6087             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6088            (setq result (car arts)
6089                  arts nil))
6090       (setq arts (cdr arts)))
6091     (and result
6092          (goto-char (gnus-data-pos result))
6093          (gnus-data-number result))))
6094
6095 (defun gnus-summary-search-forward (&optional unread subject backward)
6096   "Search forward for an article.
6097 If UNREAD, look for unread articles.  If SUBJECT, look for
6098 articles with that subject.  If BACKWARD, search backward instead."
6099   (cond (subject (gnus-summary-find-subject subject unread backward))
6100         (backward (gnus-summary-find-prev unread))
6101         (t (gnus-summary-find-next unread))))
6102
6103 (defun gnus-recenter (&optional n)
6104   "Center point in window and redisplay frame.
6105 Also do horizontal recentering."
6106   (interactive "P")
6107   (when (and gnus-auto-center-summary
6108              (not (eq gnus-auto-center-summary 'vertical)))
6109     (gnus-horizontal-recenter))
6110   (recenter n))
6111
6112 (defun gnus-summary-recenter ()
6113   "Center point in the summary window.
6114 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6115 displayed, no centering will be performed."
6116   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6117   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6118   (interactive)
6119   (let* ((top (cond ((< (window-height) 4) 0)
6120                     ((< (window-height) 7) 1)
6121                     (t (if (numberp gnus-auto-center-summary)
6122                            gnus-auto-center-summary
6123                          2))))
6124          (height (1- (window-height)))
6125          (bottom (save-excursion (goto-char (point-max))
6126                                  (forward-line (- height))
6127                                  (point)))
6128          (window (get-buffer-window (current-buffer))))
6129     ;; The user has to want it.
6130     (when gnus-auto-center-summary
6131       (when (get-buffer-window gnus-article-buffer)
6132         ;; Only do recentering when the article buffer is displayed,
6133         ;; Set the window start to either `bottom', which is the biggest
6134         ;; possible valid number, or the second line from the top,
6135         ;; whichever is the least.
6136         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6137           (if (> bottom top-pos)
6138               ;; Keep the second line from the top visible
6139               (set-window-start window top-pos t)
6140             ;; Try to keep the bottom line visible; if it's partially
6141             ;; obscured, either scroll one more line to make it fully
6142             ;; visible, or revert to using TOP-POS.
6143             (save-excursion
6144               (goto-char (point-max))
6145               (forward-line -1)
6146               (let ((last-line-start (point)))
6147                 (goto-char bottom)
6148                 (set-window-start window (point) t)
6149                 (when (not (pos-visible-in-window-p last-line-start window))
6150                   (forward-line 1)
6151                   (set-window-start window (min (point) top-pos) t)))))))
6152       ;; Do horizontal recentering while we're at it.
6153       (when (and (get-buffer-window (current-buffer) t)
6154                  (not (eq gnus-auto-center-summary 'vertical)))
6155         (let ((selected (selected-window)))
6156           (select-window (get-buffer-window (current-buffer) t))
6157           (gnus-summary-position-point)
6158           (gnus-horizontal-recenter)
6159           (select-window selected))))))
6160
6161 (defun gnus-summary-jump-to-group (newsgroup)
6162   "Move point to NEWSGROUP in group mode buffer."
6163   ;; Keep update point of group mode buffer if visible.
6164   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6165       (save-window-excursion
6166         ;; Take care of tree window mode.
6167         (when (get-buffer-window gnus-group-buffer)
6168           (pop-to-buffer gnus-group-buffer))
6169         (gnus-group-jump-to-group newsgroup))
6170     (save-excursion
6171       ;; Take care of tree window mode.
6172       (if (get-buffer-window gnus-group-buffer)
6173           (pop-to-buffer gnus-group-buffer)
6174         (set-buffer gnus-group-buffer))
6175       (gnus-group-jump-to-group newsgroup))))
6176
6177 ;; This function returns a list of article numbers based on the
6178 ;; difference between the ranges of read articles in this group and
6179 ;; the range of active articles.
6180 (defun gnus-list-of-unread-articles (group)
6181   (let* ((read (gnus-info-read (gnus-get-info group)))
6182          (active (or (gnus-active group) (gnus-activate-group group)))
6183          (last (cdr active))
6184          first nlast unread)
6185     ;; If none are read, then all are unread.
6186     (if (not read)
6187         (setq first (car active))
6188       ;; If the range of read articles is a single range, then the
6189       ;; first unread article is the article after the last read
6190       ;; article.  Sounds logical, doesn't it?
6191       (if (and (not (listp (cdr read)))
6192                (or (< (car read) (car active))
6193                    (progn (setq read (list read))
6194                           nil)))
6195           (setq first (max (car active) (1+ (cdr read))))
6196         ;; `read' is a list of ranges.
6197         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6198                                   (caar read)))
6199                   1)
6200           (setq first (car active)))
6201         (while read
6202           (when first
6203             (while (< first nlast)
6204               (push first unread)
6205               (setq first (1+ first))))
6206           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6207           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6208           (setq read (cdr read)))))
6209     ;; And add the last unread articles.
6210     (while (<= first last)
6211       (push first unread)
6212       (setq first (1+ first)))
6213     ;; Return the list of unread articles.
6214     (delq 0 (nreverse unread))))
6215
6216 (defun gnus-list-of-read-articles (group)
6217   "Return a list of unread, unticked and non-dormant articles."
6218   (let* ((info (gnus-get-info group))
6219          (marked (gnus-info-marks info))
6220          (active (gnus-active group)))
6221     (and info active
6222          (gnus-list-range-difference
6223           (gnus-list-range-difference
6224            (gnus-sorted-complement
6225             (gnus-uncompress-range active)
6226             (gnus-list-of-unread-articles group))
6227            (cdr (assq 'dormant marked)))
6228           (cdr (assq 'tick marked))))))
6229
6230 ;; Various summary commands
6231
6232 (defun gnus-summary-select-article-buffer ()
6233   "Reconfigure windows to show article buffer."
6234   (interactive)
6235   (if (not (gnus-buffer-live-p gnus-article-buffer))
6236       (error "There is no article buffer for this summary buffer")
6237     (gnus-configure-windows 'article)
6238     (select-window (get-buffer-window gnus-article-buffer))))
6239
6240 (defun gnus-summary-universal-argument (arg)
6241   "Perform any operation on all articles that are process/prefixed."
6242   (interactive "P")
6243   (let ((articles (gnus-summary-work-articles arg))
6244         func article)
6245     (if (eq
6246          (setq
6247           func
6248           (key-binding
6249            (read-key-sequence
6250             (substitute-command-keys
6251              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6252          'undefined)
6253         (gnus-error 1 "Undefined key")
6254       (save-excursion
6255         (while articles
6256           (gnus-summary-goto-subject (setq article (pop articles)))
6257           (let (gnus-newsgroup-processable)
6258             (command-execute func))
6259           (gnus-summary-remove-process-mark article)))))
6260   (gnus-summary-position-point))
6261
6262 (defun gnus-summary-toggle-truncation (&optional arg)
6263   "Toggle truncation of summary lines.
6264 With arg, turn line truncation on if arg is positive."
6265   (interactive "P")
6266   (setq truncate-lines
6267         (if (null arg) (not truncate-lines)
6268           (> (prefix-numeric-value arg) 0)))
6269   (redraw-display))
6270
6271 (defun gnus-summary-find-uncancelled ()
6272   "Return the number of an uncancelled article.
6273 The current article is considered, then following articles, then previous
6274 articles.  If all articles are cancelled then return a dummy 0."
6275   (let (found)
6276     (dolist (rev '(nil t))
6277       (unless found      ; don't demand the reverse list if we don't need it
6278         (let ((data (gnus-data-find-list
6279                      (gnus-summary-article-number) (gnus-data-list rev))))
6280           (while (and data (not found))
6281             (if (not (eq gnus-canceled-mark (gnus-data-mark (car data))))
6282                 (setq found (gnus-data-number (car data))))
6283             (setq data (cdr data))))))
6284     (or found 0)))
6285
6286 (defun gnus-summary-reselect-current-group (&optional all rescan)
6287   "Exit and then reselect the current newsgroup.
6288 The prefix argument ALL means to select all articles."
6289   (interactive "P")
6290   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6291     (error "Ephemeral groups can't be reselected"))
6292   (let ((current-subject (gnus-summary-find-uncancelled))
6293         (group gnus-newsgroup-name))
6294     (setq gnus-newsgroup-begin nil)
6295     (gnus-summary-exit)
6296     ;; We have to adjust the point of group mode buffer because
6297     ;; point was moved to the next unread newsgroup by exiting.
6298     (gnus-summary-jump-to-group group)
6299     (when rescan
6300       (save-excursion
6301         (save-window-excursion
6302           ;; Don't show group contents.
6303           (set-window-start (selected-window) (point-max))
6304           (gnus-group-get-new-news-this-group 1))))
6305     (gnus-group-read-group all t)
6306     (gnus-summary-goto-subject current-subject nil t)))
6307
6308 (defun gnus-summary-rescan-group (&optional all)
6309   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6310   (interactive "P")
6311   (gnus-summary-reselect-current-group all t))
6312
6313 (defun gnus-summary-update-info (&optional non-destructive)
6314   (save-excursion
6315     (let ((group gnus-newsgroup-name))
6316       (when group
6317         (when gnus-newsgroup-kill-headers
6318           (setq gnus-newsgroup-killed
6319                 (gnus-compress-sequence
6320                  (gnus-sorted-union
6321                   (gnus-list-range-intersection
6322                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6323                   gnus-newsgroup-unreads)
6324                  t)))
6325         (unless (listp (cdr gnus-newsgroup-killed))
6326           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6327         (let ((headers gnus-newsgroup-headers))
6328           ;; Set the new ranges of read articles.
6329           (save-excursion
6330             (set-buffer gnus-group-buffer)
6331             (gnus-undo-force-boundary))
6332           (gnus-update-read-articles
6333            group (gnus-sorted-union
6334                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6335           ;; Set the current article marks.
6336           (let ((gnus-newsgroup-scored
6337                  (if (and (not gnus-save-score)
6338                           (not non-destructive))
6339                      nil
6340                    gnus-newsgroup-scored)))
6341             (save-excursion
6342               (gnus-update-marks)))
6343           ;; Do the cross-ref thing.
6344           (when gnus-use-cross-reference
6345             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6346           ;; Do not switch windows but change the buffer to work.
6347           (set-buffer gnus-group-buffer)
6348           (unless (gnus-ephemeral-group-p group)
6349             (gnus-group-update-group group)))))))
6350
6351 (defun gnus-summary-save-newsrc (&optional force)
6352   "Save the current number of read/marked articles in the dribble buffer.
6353 The dribble buffer will then be saved.
6354 If FORCE (the prefix), also save the .newsrc file(s)."
6355   (interactive "P")
6356   (gnus-summary-update-info t)
6357   (if force
6358       (gnus-save-newsrc-file)
6359     (gnus-dribble-save)))
6360
6361 (defun gnus-summary-exit (&optional temporary)
6362   "Exit reading current newsgroup, and then return to group selection mode.
6363 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6364   (interactive)
6365   (gnus-set-global-variables)
6366   (gnus-kill-save-kill-buffer)
6367   (gnus-async-halt-prefetch)
6368   (let* ((group gnus-newsgroup-name)
6369          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6370          (gnus-group-is-exiting-p t)
6371          (mode major-mode)
6372          (group-point nil)
6373          (buf (current-buffer)))
6374     (unless quit-config
6375       ;; Do adaptive scoring, and possibly save score files.
6376       (when gnus-newsgroup-adaptive
6377         (gnus-score-adaptive))
6378       (when gnus-use-scoring
6379         (gnus-score-save)))
6380     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6381     ;; If we have several article buffers, we kill them at exit.
6382     (unless gnus-single-article-buffer
6383       (gnus-kill-buffer gnus-original-article-buffer)
6384       (setq gnus-article-current nil))
6385     (when gnus-use-cache
6386       (gnus-cache-possibly-remove-articles)
6387       (gnus-cache-save-buffers))
6388     (gnus-async-prefetch-remove-group group)
6389     (when gnus-suppress-duplicates
6390       (gnus-dup-enter-articles))
6391     (when gnus-use-trees
6392       (gnus-tree-close group))
6393     (when gnus-use-cache
6394       (gnus-cache-write-active))
6395     ;; Remove entries for this group.
6396     (nnmail-purge-split-history (gnus-group-real-name group))
6397     ;; Make all changes in this group permanent.
6398     (unless quit-config
6399       (gnus-run-hooks 'gnus-exit-group-hook)
6400       (gnus-summary-update-info))
6401     (gnus-close-group group)
6402     ;; Make sure where we were, and go to next newsgroup.
6403     (set-buffer gnus-group-buffer)
6404     (unless quit-config
6405       (gnus-group-jump-to-group group))
6406     (gnus-run-hooks 'gnus-summary-exit-hook)
6407     (unless (or quit-config
6408                 ;; If this group has disappeared from the summary
6409                 ;; buffer, don't skip forwards.
6410                 (not (string= group (gnus-group-group-name))))
6411       (gnus-group-next-unread-group 1))
6412     (setq group-point (point))
6413     (if temporary
6414         nil                             ;Nothing to do.
6415       ;; If we have several article buffers, we kill them at exit.
6416       (unless gnus-single-article-buffer
6417         (gnus-kill-buffer gnus-article-buffer)
6418         (gnus-kill-buffer gnus-original-article-buffer)
6419         (setq gnus-article-current nil))
6420       (set-buffer buf)
6421       (if (not gnus-kill-summary-on-exit)
6422           (progn
6423             (gnus-deaden-summary)
6424             (setq mode nil))
6425         ;; We set all buffer-local variables to nil.  It is unclear why
6426         ;; this is needed, but if we don't, buffer-local variables are
6427         ;; not garbage-collected, it seems.  This would the lead to en
6428         ;; ever-growing Emacs.
6429         (gnus-summary-clear-local-variables)
6430         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6431           (gnus-summary-clear-local-variables))
6432         (when (get-buffer gnus-article-buffer)
6433           (bury-buffer gnus-article-buffer))
6434         ;; We clear the global counterparts of the buffer-local
6435         ;; variables as well, just to be on the safe side.
6436         (set-buffer gnus-group-buffer)
6437         (gnus-summary-clear-local-variables)
6438         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6439           (gnus-summary-clear-local-variables))
6440         ;; Return to group mode buffer.
6441         (when (eq mode 'gnus-summary-mode)
6442           (gnus-kill-buffer buf)))
6443       (setq gnus-current-select-method gnus-select-method)
6444       (pop-to-buffer gnus-group-buffer)
6445       (if (not quit-config)
6446           (progn
6447             (goto-char group-point)
6448             (gnus-configure-windows 'group 'force)
6449             (unless (pos-visible-in-window-p)
6450               (forward-line (/ (static-if (featurep 'xemacs)
6451                                    (window-displayed-height)
6452                                  (1- (window-height)))
6453                                -2))
6454               (set-window-start (selected-window) (point))
6455               (goto-char group-point)))
6456         (gnus-handle-ephemeral-exit quit-config))
6457       ;; Clear the current group name.
6458       (unless quit-config
6459         (setq gnus-newsgroup-name nil)))))
6460
6461 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6462 (defun gnus-summary-exit-no-update (&optional no-questions)
6463   "Quit reading current newsgroup without updating read article info."
6464   (interactive)
6465   (let* ((group gnus-newsgroup-name)
6466          (gnus-group-is-exiting-p t)
6467          (quit-config (gnus-group-quit-config group)))
6468     (when (or no-questions
6469               gnus-expert-user
6470               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6471       (gnus-async-halt-prefetch)
6472       (mapcar 'funcall
6473               (delq 'gnus-summary-expire-articles
6474                     (copy-sequence gnus-summary-prepare-exit-hook)))
6475       ;; If we have several article buffers, we kill them at exit.
6476       (unless gnus-single-article-buffer
6477         (gnus-kill-buffer gnus-article-buffer)
6478         (gnus-kill-buffer gnus-original-article-buffer)
6479         (setq gnus-article-current nil))
6480       (if (not gnus-kill-summary-on-exit)
6481           (gnus-deaden-summary)
6482         (gnus-close-group group)
6483         (gnus-summary-clear-local-variables)
6484         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6485           (gnus-summary-clear-local-variables))
6486         (set-buffer gnus-group-buffer)
6487         (gnus-summary-clear-local-variables)
6488         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6489           (gnus-summary-clear-local-variables))
6490         (when (get-buffer gnus-summary-buffer)
6491           (kill-buffer gnus-summary-buffer)))
6492       (unless gnus-single-article-buffer
6493         (setq gnus-article-current nil))
6494       (when gnus-use-trees
6495         (gnus-tree-close group))
6496       (gnus-async-prefetch-remove-group group)
6497       (when (get-buffer gnus-article-buffer)
6498         (bury-buffer gnus-article-buffer))
6499       ;; Return to the group buffer.
6500       (gnus-configure-windows 'group 'force)
6501       ;; Clear the current group name.
6502       (setq gnus-newsgroup-name nil)
6503       (unless (gnus-ephemeral-group-p group)
6504         (gnus-group-update-group group))
6505       (when (equal (gnus-group-group-name) group)
6506         (gnus-group-next-unread-group 1))
6507       (when quit-config
6508         (gnus-handle-ephemeral-exit quit-config)))))
6509
6510 (defun gnus-handle-ephemeral-exit (quit-config)
6511   "Handle movement when leaving an ephemeral group.
6512 The state which existed when entering the ephemeral is reset."
6513   (if (not (buffer-name (car quit-config)))
6514       (gnus-configure-windows 'group 'force)
6515     (set-buffer (car quit-config))
6516     (cond ((eq major-mode 'gnus-summary-mode)
6517            (gnus-set-global-variables))
6518           ((eq major-mode 'gnus-article-mode)
6519            (save-excursion
6520              ;; The `gnus-summary-buffer' variable may point
6521              ;; to the old summary buffer when using a single
6522              ;; article buffer.
6523              (unless (gnus-buffer-live-p gnus-summary-buffer)
6524                (set-buffer gnus-group-buffer))
6525              (set-buffer gnus-summary-buffer)
6526              (gnus-set-global-variables))))
6527     (if (or (eq (cdr quit-config) 'article)
6528             (eq (cdr quit-config) 'pick))
6529         (progn
6530           ;; The current article may be from the ephemeral group
6531           ;; thus it is best that we reload this article
6532           (gnus-summary-show-article)
6533           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6534               (gnus-configure-windows 'pick 'force)
6535             (gnus-configure-windows (cdr quit-config) 'force)))
6536       (gnus-configure-windows (cdr quit-config) 'force))
6537     (when (eq major-mode 'gnus-summary-mode)
6538       (gnus-summary-next-subject 1 nil t)
6539       (gnus-summary-recenter)
6540       (gnus-summary-position-point))))
6541
6542 (defun gnus-summary-preview-mime-message ()
6543   "MIME decode and play this message."
6544   (interactive)
6545   (let ((gnus-break-pages nil)
6546         (gnus-show-mime t))
6547     (gnus-summary-select-article gnus-show-all-headers t))
6548   (let ((w (get-buffer-window gnus-article-buffer)))
6549     (when w
6550       (select-window (get-buffer-window gnus-article-buffer)))))
6551
6552 ;;; Dead summaries.
6553
6554 (defvar gnus-dead-summary-mode-map nil)
6555
6556 (unless gnus-dead-summary-mode-map
6557   (setq gnus-dead-summary-mode-map (make-keymap))
6558   (suppress-keymap gnus-dead-summary-mode-map)
6559   (substitute-key-definition
6560    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6561   (dolist (key '("\C-d" "\r" "\177" [delete]))
6562     (define-key gnus-dead-summary-mode-map
6563       key 'gnus-summary-wake-up-the-dead))
6564   (dolist (key '("q" "Q"))
6565     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6566
6567 (defvar gnus-dead-summary-mode nil
6568   "Minor mode for Gnus summary buffers.")
6569
6570 (defun gnus-dead-summary-mode (&optional arg)
6571   "Minor mode for Gnus summary buffers."
6572   (interactive "P")
6573   (when (eq major-mode 'gnus-summary-mode)
6574     (make-local-variable 'gnus-dead-summary-mode)
6575     (setq gnus-dead-summary-mode
6576           (if (null arg) (not gnus-dead-summary-mode)
6577             (> (prefix-numeric-value arg) 0)))
6578     (when gnus-dead-summary-mode
6579       (gnus-add-minor-mode
6580        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6581
6582 (defun gnus-deaden-summary ()
6583   "Make the current summary buffer into a dead summary buffer."
6584   ;; Kill any previous dead summary buffer.
6585   (when (and gnus-dead-summary
6586              (buffer-name gnus-dead-summary))
6587     (save-excursion
6588       (set-buffer gnus-dead-summary)
6589       (when gnus-dead-summary-mode
6590         (kill-buffer (current-buffer)))))
6591   ;; Make this the current dead summary.
6592   (setq gnus-dead-summary (current-buffer))
6593   (gnus-dead-summary-mode 1)
6594   (let ((name (buffer-name)))
6595     (when (string-match "Summary" name)
6596       (rename-buffer
6597        (concat (substring name 0 (match-beginning 0)) "Dead "
6598                (substring name (match-beginning 0)))
6599        t)
6600       (bury-buffer))))
6601
6602 (defun gnus-kill-or-deaden-summary (buffer)
6603   "Kill or deaden the summary BUFFER."
6604   (save-excursion
6605     (when (and (buffer-name buffer)
6606                (not gnus-single-article-buffer))
6607       (save-excursion
6608         (set-buffer buffer)
6609         (gnus-kill-buffer gnus-article-buffer)
6610         (gnus-kill-buffer gnus-original-article-buffer)))
6611     (cond
6612      ;; Kill the buffer.
6613      (gnus-kill-summary-on-exit
6614       (when (and gnus-use-trees
6615                  (gnus-buffer-exists-p buffer))
6616         (save-excursion
6617           (set-buffer buffer)
6618           (gnus-tree-close gnus-newsgroup-name)))
6619       (gnus-kill-buffer buffer))
6620      ;; Deaden the buffer.
6621      ((gnus-buffer-exists-p buffer)
6622       (save-excursion
6623         (set-buffer buffer)
6624         (gnus-deaden-summary))))))
6625
6626 (defun gnus-summary-wake-up-the-dead (&rest args)
6627   "Wake up the dead summary buffer."
6628   (interactive)
6629   (gnus-dead-summary-mode -1)
6630   (let ((name (buffer-name)))
6631     (when (string-match "Dead " name)
6632       (rename-buffer
6633        (concat (substring name 0 (match-beginning 0))
6634                (substring name (match-end 0)))
6635        t)))
6636   (gnus-message 3 "This dead summary is now alive again"))
6637
6638 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6639 (defun gnus-summary-fetch-faq (&optional faq-dir)
6640   "Fetch the FAQ for the current group.
6641 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6642 in."
6643   (interactive
6644    (list
6645     (when current-prefix-arg
6646       (completing-read
6647        "FAQ dir: " (and (listp gnus-group-faq-directory)
6648                         (mapcar (lambda (file) (list file))
6649                                 gnus-group-faq-directory))))))
6650   (let (gnus-faq-buffer)
6651     (when (setq gnus-faq-buffer
6652                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6653       (gnus-configure-windows 'summary-faq))))
6654
6655 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6656 (defun gnus-summary-describe-group (&optional force)
6657   "Describe the current newsgroup."
6658   (interactive "P")
6659   (gnus-group-describe-group force gnus-newsgroup-name))
6660
6661 (defun gnus-summary-describe-briefly ()
6662   "Describe summary mode commands briefly."
6663   (interactive)
6664   (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")))
6665
6666 ;; Walking around group mode buffer from summary mode.
6667
6668 (defun gnus-summary-next-group (&optional no-article target-group backward)
6669   "Exit current newsgroup and then select next unread newsgroup.
6670 If prefix argument NO-ARTICLE is non-nil, no article is selected
6671 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6672 previous group instead."
6673   (interactive "P")
6674   ;; Stop pre-fetching.
6675   (gnus-async-halt-prefetch)
6676   (let ((current-group gnus-newsgroup-name)
6677         (current-buffer (current-buffer))
6678         entered)
6679     (gnus-summary-exit t)
6680     (while (not entered)
6681       ;; Then we find what group we are supposed to enter.
6682       (set-buffer gnus-group-buffer)
6683       (gnus-group-jump-to-group current-group)
6684       (setq target-group
6685             (or target-group
6686                 (if (eq gnus-keep-same-level 'best)
6687                     (gnus-summary-best-group gnus-newsgroup-name)
6688                   (gnus-summary-search-group backward gnus-keep-same-level))))
6689       (if (not target-group)
6690           ;; There are no further groups, so we return to the group
6691           ;; buffer.
6692           (progn
6693             (gnus-message 5 "Returning to the group buffer")
6694             (setq entered t)
6695             (when (gnus-buffer-live-p current-buffer)
6696               (set-buffer current-buffer)
6697               (gnus-summary-exit))
6698             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6699         ;; We try to enter the target group.
6700         (gnus-group-jump-to-group target-group)
6701         (let ((unreads (gnus-group-group-unread)))
6702           (if (and (or (eq t unreads)
6703                        (and unreads (not (zerop unreads))))
6704                    (progn
6705                      ;; Now we semi-exit this group to update Xrefs
6706                      ;; and all variables.  We can't do a real exit,
6707                      ;; because the window conf must remain the same
6708                      ;; in case the user is prompted for info, and we
6709                      ;; don't want the window conf to change before
6710                      ;; that...
6711                      (when (gnus-buffer-live-p current-buffer)
6712                        (set-buffer current-buffer)
6713                        (gnus-summary-exit t))
6714                      (gnus-summary-read-group
6715                       target-group nil no-article
6716                       (and (buffer-name current-buffer) current-buffer)
6717                       nil backward)))
6718               (setq entered t)
6719             (setq current-group target-group
6720                   target-group nil)))))))
6721
6722 (defun gnus-summary-prev-group (&optional no-article)
6723   "Exit current newsgroup and then select previous unread newsgroup.
6724 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6725   (interactive "P")
6726   (gnus-summary-next-group no-article nil t))
6727
6728 ;; Walking around summary lines.
6729
6730 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6731   "Go to the first subject satisfying any non-nil constraint.
6732 If UNREAD is non-nil, the article should be unread.
6733 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6734 If UNSEED is non-nil, the article should be unseen.
6735 Returns the article selected or nil if there are no matching articles."
6736   (interactive "P")
6737   (cond
6738    ;; Empty summary.
6739    ((null gnus-newsgroup-data)
6740     (gnus-message 3 "No articles in the group")
6741     nil)
6742    ;; Pick the first article.
6743    ((not (or unread undownloaded unseen))
6744     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6745     (gnus-data-number (car gnus-newsgroup-data)))
6746    ;; Find the first unread article.
6747    (t
6748     (let ((data gnus-newsgroup-data))
6749       (while (and data
6750                   (let ((num (gnus-data-number (car data))))
6751                     (or (memq num gnus-newsgroup-unfetched)
6752                         (not (or (and unread
6753                                       (memq num gnus-newsgroup-unreads))
6754                                  (and undownloaded
6755                                       (memq num gnus-newsgroup-undownloaded))
6756                                  (and unseen
6757                                       (memq num gnus-newsgroup-unseen)))))))
6758         (setq data (cdr data)))
6759       (prog1 
6760           (if data
6761               (progn
6762                 (goto-char (gnus-data-pos (car data)))
6763                 (gnus-data-number (car data)))
6764             (gnus-message 3 "No more%s articles"
6765                           (let* ((r (when unread " unread"))
6766                                  (d (when undownloaded " undownloaded"))
6767                                  (s (when unseen " unseen"))
6768                                  (l (delq nil (list r d s))))
6769                             (cond ((= 3 (length l))
6770                                    (concat r "," d ", or" s))
6771                                   ((= 2 (length l))
6772                                    (concat (car l) ", or" (cadr l)))
6773                                   ((= 1 (length l))
6774                                    (car l))
6775                                   (t
6776                                    ""))))
6777             nil
6778             )
6779         (gnus-summary-position-point))))))
6780
6781 (defun gnus-summary-next-subject (n &optional unread dont-display)
6782   "Go to next N'th summary line.
6783 If N is negative, go to the previous N'th subject line.
6784 If UNREAD is non-nil, only unread articles are selected.
6785 The difference between N and the actual number of steps taken is
6786 returned."
6787   (interactive "p")
6788   (let ((backward (< n 0))
6789         (n (abs n)))
6790     (while (and (> n 0)
6791                 (if backward
6792                     (gnus-summary-find-prev unread)
6793                   (gnus-summary-find-next unread)))
6794       (unless (zerop (setq n (1- n)))
6795         (gnus-summary-show-thread)))
6796     (when (/= 0 n)
6797       (gnus-message 7 "No more%s articles"
6798                     (if unread " unread" "")))
6799     (unless dont-display
6800       (gnus-summary-recenter)
6801       (gnus-summary-position-point))
6802     n))
6803
6804 (defun gnus-summary-next-unread-subject (n)
6805   "Go to next N'th unread summary line."
6806   (interactive "p")
6807   (gnus-summary-next-subject n t))
6808
6809 (defun gnus-summary-prev-subject (n &optional unread)
6810   "Go to previous N'th summary line.
6811 If optional argument UNREAD is non-nil, only unread article is selected."
6812   (interactive "p")
6813   (gnus-summary-next-subject (- n) unread))
6814
6815 (defun gnus-summary-prev-unread-subject (n)
6816   "Go to previous N'th unread summary line."
6817   (interactive "p")
6818   (gnus-summary-next-subject (- n) t))
6819
6820 (defun gnus-summary-goto-subjects (articles)
6821   "Insert the subject header for ARTICLES in the current buffer."
6822   (save-excursion
6823     (dolist (article articles)
6824       (gnus-summary-goto-subject article t)))
6825   (gnus-summary-limit (append articles gnus-newsgroup-limit))
6826   (gnus-summary-position-point))
6827  
6828 (defun gnus-summary-goto-subject (article &optional force silent)
6829   "Go the subject line of ARTICLE.
6830 If FORCE, also allow jumping to articles not currently shown."
6831   (interactive "nArticle number: ")
6832   (unless (numberp article)
6833     (error "Article %s is not a number" article))
6834   (let ((b (point))
6835         (data (gnus-data-find article)))
6836     ;; We read in the article if we have to.
6837     (and (not data)
6838          force
6839          (gnus-summary-insert-subject
6840           article
6841           (if (or (numberp force) (vectorp force)) force)
6842           t)
6843          (setq data (gnus-data-find article)))
6844     (goto-char b)
6845     (if (not data)
6846         (progn
6847           (unless silent
6848             (gnus-message 3 "Can't find article %d" article))
6849           nil)
6850       (let ((pt (gnus-data-pos data)))
6851         (goto-char pt)
6852         (gnus-summary-set-article-display-arrow pt))
6853       (gnus-summary-position-point)
6854       article)))
6855
6856 ;; Walking around summary lines with displaying articles.
6857
6858 (defun gnus-summary-expand-window (&optional arg)
6859   "Make the summary buffer take up the entire Emacs frame.
6860 Given a prefix, will force an `article' buffer configuration."
6861   (interactive "P")
6862   (if arg
6863       (gnus-configure-windows 'article 'force)
6864     (gnus-configure-windows 'summary 'force)))
6865
6866 (defun gnus-summary-display-article (article &optional all-header)
6867   "Display ARTICLE in article buffer."
6868   (when (gnus-buffer-live-p gnus-article-buffer)
6869     (with-current-buffer gnus-article-buffer
6870       (set-buffer-multibyte t)))
6871   (gnus-set-global-variables)
6872   (when (gnus-buffer-live-p gnus-article-buffer)
6873     (with-current-buffer gnus-article-buffer
6874       (setq gnus-article-charset gnus-newsgroup-charset)
6875       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6876       (set-buffer-multibyte t)))
6877   (if (null article)
6878       nil
6879     (prog1
6880         (if gnus-summary-display-article-function
6881             (funcall gnus-summary-display-article-function article all-header)
6882           (gnus-article-prepare article all-header))
6883       (with-current-buffer gnus-article-buffer
6884         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6885              nil))
6886       (gnus-run-hooks 'gnus-select-article-hook)
6887       (when (and gnus-current-article
6888                  (not (zerop gnus-current-article)))
6889         (gnus-summary-goto-subject gnus-current-article))
6890       (gnus-summary-recenter)
6891       (when (and gnus-use-trees gnus-show-threads)
6892         (gnus-possibly-generate-tree article)
6893         (gnus-highlight-selected-tree article))
6894       ;; Successfully display article.
6895       (gnus-article-set-window-start
6896        (cdr (assq article gnus-newsgroup-bookmarks))))))
6897
6898 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6899   "Select the current article.
6900 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6901 non-nil, the article will be re-fetched even if it already present in
6902 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6903 be displayed."
6904   ;; Make sure we are in the summary buffer to work around bbdb bug.
6905   (unless (eq major-mode 'gnus-summary-mode)
6906     (set-buffer gnus-summary-buffer))
6907   (let ((article (or article (gnus-summary-article-number)))
6908         (all-headers (not (not all-headers))) ;Must be T or NIL.
6909         gnus-summary-display-article-function)
6910     (and (not pseudo)
6911          (gnus-summary-article-pseudo-p article)
6912          (error "This is a pseudo-article"))
6913     (save-excursion
6914       (set-buffer gnus-summary-buffer)
6915       (if (or (and gnus-single-article-buffer
6916                    (or (null gnus-current-article)
6917                        (null gnus-article-current)
6918                        (null (get-buffer gnus-article-buffer))
6919                        (not (eq article (cdr gnus-article-current)))
6920                        (not (equal (car gnus-article-current)
6921                                    gnus-newsgroup-name))))
6922               (and (not gnus-single-article-buffer)
6923                    (or (null gnus-current-article)
6924                        (not (eq gnus-current-article article))))
6925               force)
6926           ;; The requested article is different from the current article.
6927           (progn
6928             (gnus-summary-display-article article all-headers)
6929             (gnus-article-set-window-start
6930              (cdr (assq article gnus-newsgroup-bookmarks)))
6931             article)
6932         'old))))
6933
6934 (defun gnus-summary-force-verify-and-decrypt ()
6935   "Display buttons for signed/encrypted parts and verify/decrypt them."
6936   (interactive)
6937   (let ((mm-verify-option 'known)
6938         (mm-decrypt-option 'known)
6939         (gnus-buttonized-mime-types (append (list "multipart/signed"
6940                                                   "multipart/encrypted")
6941                                             gnus-buttonized-mime-types)))
6942     (gnus-summary-select-article nil 'force)))
6943
6944 (defun gnus-summary-set-current-mark (&optional current-mark)
6945   "Obsolete function."
6946   nil)
6947
6948 (defun gnus-summary-next-article (&optional unread subject backward push)
6949   "Select the next article.
6950 If UNREAD, only unread articles are selected.
6951 If SUBJECT, only articles with SUBJECT are selected.
6952 If BACKWARD, the previous article is selected instead of the next."
6953   (interactive "P")
6954   (cond
6955    ;; Is there such an article?
6956    ((and (gnus-summary-search-forward unread subject backward)
6957          (or (gnus-summary-display-article (gnus-summary-article-number))
6958              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6959     (gnus-summary-position-point))
6960    ;; If not, we try the first unread, if that is wanted.
6961    ((and subject
6962          gnus-auto-select-same
6963          (gnus-summary-first-unread-article))
6964     (gnus-summary-position-point)
6965     (gnus-message 6 "Wrapped"))
6966    ;; Try to get next/previous article not displayed in this group.
6967    ((and gnus-auto-extend-newsgroup
6968          (not unread) (not subject))
6969     (gnus-summary-goto-article
6970      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6971      nil (count-lines (point-min) (point))))
6972    ;; Go to next/previous group.
6973    (t
6974     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6975       (gnus-summary-jump-to-group gnus-newsgroup-name))
6976     (let ((cmd last-command-char)
6977           (point
6978            (save-excursion
6979              (set-buffer gnus-group-buffer)
6980              (point)))
6981           (group
6982            (if (eq gnus-keep-same-level 'best)
6983                (gnus-summary-best-group gnus-newsgroup-name)
6984              (gnus-summary-search-group backward gnus-keep-same-level))))
6985       ;; For some reason, the group window gets selected.  We change
6986       ;; it back.
6987       (select-window (get-buffer-window (current-buffer)))
6988       ;; Select next unread newsgroup automagically.
6989       (cond
6990        ((or (not gnus-auto-select-next)
6991             (not cmd))
6992         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6993        ((or (eq gnus-auto-select-next 'quietly)
6994             (and (eq gnus-auto-select-next 'slightly-quietly)
6995                  push)
6996             (and (eq gnus-auto-select-next 'almost-quietly)
6997                  (gnus-summary-last-article-p)))
6998         ;; Select quietly.
6999         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7000             (gnus-summary-exit)
7001           (gnus-message 7 "No more%s articles (%s)..."
7002                         (if unread " unread" "")
7003                         (if group (concat "selecting " group)
7004                           "exiting"))
7005           (gnus-summary-next-group nil group backward)))
7006        (t
7007         (when (gnus-key-press-event-p last-input-event)
7008           (gnus-summary-walk-group-buffer
7009            gnus-newsgroup-name cmd unread backward point))))))))
7010
7011 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7012   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7013                       (?\C-p (gnus-group-prev-unread-group 1))))
7014         (cursor-in-echo-area t)
7015         keve key group ended prompt)
7016     (save-excursion
7017       (set-buffer gnus-group-buffer)
7018       (goto-char start)
7019       (setq group
7020             (if (eq gnus-keep-same-level 'best)
7021                 (gnus-summary-best-group gnus-newsgroup-name)
7022               (gnus-summary-search-group backward gnus-keep-same-level))))
7023     (while (not ended)
7024       (setq prompt
7025             (format
7026              "No more%s articles%s " (if unread " unread" "")
7027              (if (and group
7028                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7029                  (format " (Type %s for %s [%s])"
7030                          (single-key-description cmd) group
7031                          (car (gnus-gethash group gnus-newsrc-hashtb)))
7032                (format " (Type %s to exit %s)"
7033                        (single-key-description cmd)
7034                        gnus-newsgroup-name))))
7035       ;; Confirm auto selection.
7036       (setq key (car (setq keve (gnus-read-event-char prompt)))
7037             ended t)
7038       (cond
7039        ((assq key keystrokes)
7040         (let ((obuf (current-buffer)))
7041           (switch-to-buffer gnus-group-buffer)
7042           (when group
7043             (gnus-group-jump-to-group group))
7044           (eval (cadr (assq key keystrokes)))
7045           (setq group (gnus-group-group-name))
7046           (switch-to-buffer obuf))
7047         (setq ended nil))
7048        ((equal key cmd)
7049         (if (or (not group)
7050                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7051             (gnus-summary-exit)
7052           (gnus-summary-next-group nil group backward)))
7053        (t
7054         (push (cdr keve) unread-command-events))))))
7055
7056 (defun gnus-summary-next-unread-article ()
7057   "Select unread article after current one."
7058   (interactive)
7059   (gnus-summary-next-article
7060    (or (not (eq gnus-summary-goto-unread 'never))
7061        (gnus-summary-last-article-p (gnus-summary-article-number)))
7062    (and gnus-auto-select-same
7063         (gnus-summary-article-subject))))
7064
7065 (defun gnus-summary-prev-article (&optional unread subject)
7066   "Select the article after the current one.
7067 If UNREAD is non-nil, only unread articles are selected."
7068   (interactive "P")
7069   (gnus-summary-next-article unread subject t))
7070
7071 (defun gnus-summary-prev-unread-article ()
7072   "Select unread article before current one."
7073   (interactive)
7074   (gnus-summary-prev-article
7075    (or (not (eq gnus-summary-goto-unread 'never))
7076        (gnus-summary-first-article-p (gnus-summary-article-number)))
7077    (and gnus-auto-select-same
7078         (gnus-summary-article-subject))))
7079
7080 (defun gnus-summary-next-page (&optional lines circular stop)
7081   "Show next page of the selected article.
7082 If at the end of the current article, select the next article.
7083 LINES says how many lines should be scrolled up.
7084
7085 If CIRCULAR is non-nil, go to the start of the article instead of
7086 selecting the next article when reaching the end of the current
7087 article.
7088
7089 If STOP is non-nil, just stop when reaching the end of the message."
7090   (interactive "P")
7091   (setq gnus-summary-buffer (current-buffer))
7092   (gnus-set-global-variables)
7093   (let ((article (gnus-summary-article-number))
7094         (article-window (get-buffer-window gnus-article-buffer t))
7095         endp)
7096     ;; If the buffer is empty, we have no article.
7097     (unless article
7098       (error "No article to select"))
7099     (gnus-configure-windows 'article)
7100     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7101         (if (and (eq gnus-summary-goto-unread 'never)
7102                  (not (gnus-summary-last-article-p article)))
7103             (gnus-summary-next-article)
7104           (gnus-summary-next-unread-article))
7105       (if (or (null gnus-current-article)
7106               (null gnus-article-current)
7107               (/= article (cdr gnus-article-current))
7108               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7109           ;; Selected subject is different from current article's.
7110           (gnus-summary-display-article article)
7111         (when article-window
7112           (gnus-eval-in-buffer-window gnus-article-buffer
7113             (setq endp (gnus-article-next-page lines)))
7114           (when endp
7115             (cond (stop
7116                    (gnus-message 3 "End of message"))
7117                   (circular
7118                    (gnus-summary-beginning-of-article))
7119                   (lines
7120                    (gnus-message 3 "End of message"))
7121                   ((null lines)
7122                    (if (and (eq gnus-summary-goto-unread 'never)
7123                             (not (gnus-summary-last-article-p article)))
7124                        (gnus-summary-next-article)
7125                      (gnus-summary-next-unread-article))))))))
7126     (gnus-summary-recenter)
7127     (gnus-summary-position-point)))
7128
7129 (defun gnus-summary-prev-page (&optional lines move)
7130   "Show previous page of selected article.
7131 Argument LINES specifies lines to be scrolled down.
7132 If MOVE, move to the previous unread article if point is at
7133 the beginning of the buffer."
7134   (interactive "P")
7135   (let ((article (gnus-summary-article-number))
7136         (article-window (get-buffer-window gnus-article-buffer t))
7137         endp)
7138     (gnus-configure-windows 'article)
7139     (if (or (null gnus-current-article)
7140             (null gnus-article-current)
7141             (/= article (cdr gnus-article-current))
7142             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7143         ;; Selected subject is different from current article's.
7144         (gnus-summary-display-article article)
7145       (gnus-summary-recenter)
7146       (when article-window
7147         (gnus-eval-in-buffer-window gnus-article-buffer
7148           (setq endp (gnus-article-prev-page lines)))
7149         (when (and move endp)
7150           (cond (lines
7151                  (gnus-message 3 "Beginning of message"))
7152                 ((null lines)
7153                  (if (and (eq gnus-summary-goto-unread 'never)
7154                           (not (gnus-summary-first-article-p article)))
7155                      (gnus-summary-prev-article)
7156                    (gnus-summary-prev-unread-article))))))))
7157   (gnus-summary-position-point))
7158
7159 (defun gnus-summary-prev-page-or-article (&optional lines)
7160   "Show previous page of selected article.
7161 Argument LINES specifies lines to be scrolled down.
7162 If at the beginning of the article, go to the next article."
7163   (interactive "P")
7164   (gnus-summary-prev-page lines t))
7165
7166 (defun gnus-summary-scroll-up (lines)
7167   "Scroll up (or down) one line current article.
7168 Argument LINES specifies lines to be scrolled up (or down if negative)."
7169   (interactive "p")
7170   (gnus-configure-windows 'article)
7171   (gnus-summary-show-thread)
7172   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7173     (gnus-eval-in-buffer-window gnus-article-buffer
7174       (cond ((> lines 0)
7175              (when (gnus-article-next-page lines)
7176                (gnus-message 3 "End of message")))
7177             ((< lines 0)
7178              (gnus-article-prev-page (- lines))))))
7179   (gnus-summary-recenter)
7180   (gnus-summary-position-point))
7181
7182 (defun gnus-summary-scroll-down (lines)
7183   "Scroll down (or up) one line current article.
7184 Argument LINES specifies lines to be scrolled down (or up if negative)."
7185   (interactive "p")
7186   (gnus-summary-scroll-up (- lines)))
7187
7188 (defun gnus-summary-next-same-subject ()
7189   "Select next article which has the same subject as current one."
7190   (interactive)
7191   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7192
7193 (defun gnus-summary-prev-same-subject ()
7194   "Select previous article which has the same subject as current one."
7195   (interactive)
7196   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7197
7198 (defun gnus-summary-next-unread-same-subject ()
7199   "Select next unread article which has the same subject as current one."
7200   (interactive)
7201   (gnus-summary-next-article t (gnus-summary-article-subject)))
7202
7203 (defun gnus-summary-prev-unread-same-subject ()
7204   "Select previous unread article which has the same subject as current one."
7205   (interactive)
7206   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7207
7208 (defun gnus-summary-first-unread-article ()
7209   "Select the first unread article.
7210 Return nil if there are no unread articles."
7211   (interactive)
7212   (prog1
7213       (when (gnus-summary-first-subject t)
7214         (gnus-summary-show-thread)
7215         (gnus-summary-first-subject t)
7216         (gnus-summary-display-article (gnus-summary-article-number)))
7217     (gnus-summary-position-point)))
7218
7219 (defun gnus-summary-first-unread-subject ()
7220   "Place the point on the subject line of the first unread article.
7221 Return nil if there are no unread articles."
7222   (interactive)
7223   (prog1
7224       (when (gnus-summary-first-subject t)
7225         (gnus-summary-show-thread)
7226         (gnus-summary-first-subject t))
7227     (gnus-summary-position-point)))
7228
7229 (defun gnus-summary-first-unseen-subject ()
7230   "Place the point on the subject line of the first unseen article.
7231 Return nil if there are no unseen articles."
7232   (interactive)
7233   (prog1
7234       (when (gnus-summary-first-subject nil nil t)
7235         (gnus-summary-show-thread)
7236         (gnus-summary-first-subject nil nil t))
7237     (gnus-summary-position-point)))
7238
7239 (defun gnus-summary-first-unseen-or-unread-subject ()
7240   "Place the point on the subject line of the first unseen article or,
7241 if all article have been seen, on the subject line of the first unread
7242 article."
7243   (interactive)
7244   (prog1
7245       (unless (when (gnus-summary-first-subject nil nil t)
7246                 (gnus-summary-show-thread)
7247                 (gnus-summary-first-subject nil nil t))
7248         (when (gnus-summary-first-subject t)
7249           (gnus-summary-show-thread)
7250           (gnus-summary-first-subject t)))
7251     (gnus-summary-position-point)))
7252
7253 (defun gnus-summary-first-article ()
7254   "Select the first article.
7255 Return nil if there are no articles."
7256   (interactive)
7257   (prog1
7258       (when (gnus-summary-first-subject)
7259         (gnus-summary-show-thread)
7260         (gnus-summary-first-subject)
7261         (gnus-summary-display-article (gnus-summary-article-number)))
7262     (gnus-summary-position-point)))
7263
7264 (defun gnus-summary-best-unread-article (&optional arg)
7265   "Select the unread article with the highest score.
7266 If given a prefix argument, select the next unread article that has a
7267 score higher than the default score."
7268   (interactive "P")
7269   (let ((article (if arg
7270                      (gnus-summary-better-unread-subject)
7271                    (gnus-summary-best-unread-subject))))
7272     (if article
7273         (gnus-summary-goto-article article)
7274       (error "No unread articles"))))
7275
7276 (defun gnus-summary-best-unread-subject ()
7277   "Select the unread subject with the highest score."
7278   (interactive)
7279   (let ((best -1000000)
7280         (data gnus-newsgroup-data)
7281         article score)
7282     (while data
7283       (and (gnus-data-unread-p (car data))
7284            (> (setq score
7285                     (gnus-summary-article-score (gnus-data-number (car data))))
7286               best)
7287            (setq best score
7288                  article (gnus-data-number (car data))))
7289       (setq data (cdr data)))
7290     (when article
7291       (gnus-summary-goto-subject article))
7292     (gnus-summary-position-point)
7293     article))
7294
7295 (defun gnus-summary-better-unread-subject ()
7296   "Select the first unread subject that has a score over the default score."
7297   (interactive)
7298   (let ((data gnus-newsgroup-data)
7299         article score)
7300     (while (and (setq article (gnus-data-number (car data)))
7301                 (or (gnus-data-read-p (car data))
7302                     (not (> (gnus-summary-article-score article)
7303                             gnus-summary-default-score))))
7304       (setq data (cdr data)))
7305     (when article
7306       (gnus-summary-goto-subject article))
7307     (gnus-summary-position-point)
7308     article))
7309
7310 (defun gnus-summary-last-subject ()
7311   "Go to the last displayed subject line in the group."
7312   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7313     (when article
7314       (gnus-summary-goto-subject article))))
7315
7316 (defun gnus-summary-goto-article (article &optional all-headers force)
7317   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7318 If ALL-HEADERS is non-nil, no header lines are hidden.
7319 If FORCE, go to the article even if it isn't displayed.  If FORCE
7320 is a number, it is the line the article is to be displayed on."
7321   (interactive
7322    (list
7323     (completing-read
7324      "Article number or Message-ID: "
7325      (mapcar (lambda (number) (list (int-to-string number)))
7326              gnus-newsgroup-limit))
7327     current-prefix-arg
7328     t))
7329   (prog1
7330       (if (and (stringp article)
7331                (string-match "@" article))
7332           (gnus-summary-refer-article article)
7333         (when (stringp article)
7334           (setq article (string-to-number article)))
7335         (if (gnus-summary-goto-subject article force)
7336             (gnus-summary-display-article article all-headers)
7337           (gnus-message 4 "Couldn't go to article %s" article) nil))
7338     (gnus-summary-position-point)))
7339
7340 (defun gnus-summary-goto-last-article ()
7341   "Go to the previously read article."
7342   (interactive)
7343   (prog1
7344       (when gnus-last-article
7345         (gnus-summary-goto-article gnus-last-article nil t))
7346     (gnus-summary-position-point)))
7347
7348 (defun gnus-summary-pop-article (number)
7349   "Pop one article off the history and go to the previous.
7350 NUMBER articles will be popped off."
7351   (interactive "p")
7352   (let (to)
7353     (setq gnus-newsgroup-history
7354           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7355     (if to
7356         (gnus-summary-goto-article (car to) nil t)
7357       (error "Article history empty")))
7358   (gnus-summary-position-point))
7359
7360 ;; Summary commands and functions for limiting the summary buffer.
7361
7362 (defun gnus-summary-limit-to-articles (n)
7363   "Limit the summary buffer to the next N articles.
7364 If not given a prefix, use the process marked articles instead."
7365   (interactive "P")
7366   (prog1
7367       (let ((articles (gnus-summary-work-articles n)))
7368         (setq gnus-newsgroup-processable nil)
7369         (gnus-summary-limit articles))
7370     (gnus-summary-position-point)))
7371
7372 (defun gnus-summary-pop-limit (&optional total)
7373   "Restore the previous limit.
7374 If given a prefix, remove all limits."
7375   (interactive "P")
7376   (when total
7377     (setq gnus-newsgroup-limits
7378           (list (mapcar (lambda (h) (mail-header-number h))
7379                         gnus-newsgroup-headers))))
7380   (unless gnus-newsgroup-limits
7381     (error "No limit to pop"))
7382   (prog1
7383       (gnus-summary-limit nil 'pop)
7384     (gnus-summary-position-point)))
7385
7386 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7387   "Limit the summary buffer to articles that have subjects that match a regexp.
7388 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7389   (interactive
7390    (list (read-string (if current-prefix-arg
7391                           "Exclude subject (regexp): "
7392                         "Limit to subject (regexp): "))
7393          nil current-prefix-arg))
7394   (unless header
7395     (setq header "subject"))
7396   (when (not (equal "" subject))
7397     (prog1
7398         (let ((articles (gnus-summary-find-matching
7399                          (or header "subject") subject 'all nil nil
7400                          not-matching)))
7401           (unless articles
7402             (error "Found no matches for \"%s\"" subject))
7403           (gnus-summary-limit articles))
7404       (gnus-summary-position-point))))
7405
7406 (defun gnus-summary-limit-to-author (from &optional not-matching)
7407   "Limit the summary buffer to articles that have authors that match a regexp.
7408 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7409   (interactive
7410    (list (read-string (if current-prefix-arg
7411                           "Exclude author (regexp): "
7412                         "Limit to author (regexp): "))
7413          current-prefix-arg))
7414   (gnus-summary-limit-to-subject from "from" not-matching))
7415
7416 (defun gnus-summary-limit-to-age (age &optional younger-p)
7417   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7418 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7419 articles that are younger than AGE days."
7420   (interactive
7421    (let ((younger current-prefix-arg)
7422          (days-got nil)
7423          days)
7424      (while (not days-got)
7425        (setq days (if younger
7426                       (read-string "Limit to articles younger than (in days, older when negative): ")
7427                     (read-string
7428                      "Limit to articles older than (in days, younger when negative): ")))
7429        (when (> (length days) 0)
7430          (setq days (read days)))
7431        (if (numberp days)
7432            (progn
7433              (setq days-got t)
7434              (if (< days 0)
7435                  (progn
7436                    (setq younger (not younger))
7437                    (setq days (* days -1)))))
7438          (message "Please enter a number.")
7439          (sleep-for 1)))
7440      (list days younger)))
7441   (prog1
7442       (let ((data gnus-newsgroup-data)
7443             (cutoff (days-to-time age))
7444             articles d date is-younger)
7445         (while (setq d (pop data))
7446           (when (and (vectorp (gnus-data-header d))
7447                      (setq date (mail-header-date (gnus-data-header d))))
7448             (setq is-younger (time-less-p
7449                               (time-since (condition-case ()
7450                                               (date-to-time date)
7451                                             (error '(0 0))))
7452                               cutoff))
7453             (when (if younger-p
7454                       is-younger
7455                     (not is-younger))
7456               (push (gnus-data-number d) articles))))
7457         (gnus-summary-limit (nreverse articles)))
7458     (gnus-summary-position-point)))
7459
7460 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7461   "Limit the summary buffer to articles that match an 'extra' header."
7462   (interactive
7463    (let ((header
7464           (intern
7465            (gnus-completing-read-with-default
7466             (symbol-name (car gnus-extra-headers))
7467             (if current-prefix-arg
7468                 "Exclude extra header:"
7469               "Limit extra header:")
7470             (mapcar (lambda (x)
7471                       (cons (symbol-name x) x))
7472                     gnus-extra-headers)
7473             nil
7474             t))))
7475      (list header
7476            (read-string (format "%s header %s (regexp): "
7477                                 (if current-prefix-arg "Exclude" "Limit to")
7478                                 header))
7479            current-prefix-arg)))
7480   (when (not (equal "" regexp))
7481     (prog1
7482         (let ((articles (gnus-summary-find-matching
7483                          (cons 'extra header) regexp 'all nil nil
7484                          not-matching)))
7485           (unless articles
7486             (error "Found no matches for \"%s\"" regexp))
7487           (gnus-summary-limit articles))
7488       (gnus-summary-position-point))))
7489
7490 (defun gnus-summary-limit-to-display-predicate ()
7491   "Limit the summary buffer to the predicated in the `display' group parameter."
7492   (interactive)
7493   (unless gnus-newsgroup-display
7494     (error "There is no `display' group parameter"))
7495   (let (articles)
7496     (dolist (number gnus-newsgroup-articles)
7497       (when (funcall gnus-newsgroup-display)
7498         (push number articles)))
7499     (gnus-summary-limit articles))
7500   (gnus-summary-position-point))
7501
7502 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7503 (make-obsolete
7504  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7505
7506 (defun gnus-summary-limit-to-unread (&optional all)
7507   "Limit the summary buffer to articles that are not marked as read.
7508 If ALL is non-nil, limit strictly to unread articles."
7509   (interactive "P")
7510   (if all
7511       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7512     (gnus-summary-limit-to-marks
7513      ;; Concat all the marks that say that an article is read and have
7514      ;; those removed.
7515      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7516            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7517            gnus-low-score-mark gnus-expirable-mark
7518            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7519            gnus-duplicate-mark gnus-souped-mark)
7520      'reverse)))
7521
7522 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7523 (make-obsolete 'gnus-summary-delete-marked-with
7524                'gnus-summary-limit-exclude-marks)
7525
7526 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7527   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7528 If REVERSE, limit the summary buffer to articles that are marked
7529 with MARKS.  MARKS can either be a string of marks or a list of marks.
7530 Returns how many articles were removed."
7531   (interactive "sMarks: ")
7532   (gnus-summary-limit-to-marks marks t))
7533
7534 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7535   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7536 If REVERSE (the prefix), limit the summary buffer to articles that are
7537 not marked with MARKS.  MARKS can either be a string of marks or a
7538 list of marks.
7539 Returns how many articles were removed."
7540   (interactive "sMarks: \nP")
7541   (prog1
7542       (let ((data gnus-newsgroup-data)
7543             (marks (if (listp marks) marks
7544                      (append marks nil))) ; Transform to list.
7545             articles)
7546         (while data
7547           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7548                   (memq (gnus-data-mark (car data)) marks))
7549             (push (gnus-data-number (car data)) articles))
7550           (setq data (cdr data)))
7551         (gnus-summary-limit articles))
7552     (gnus-summary-position-point)))
7553
7554 (defun gnus-summary-limit-to-score (score)
7555   "Limit to articles with score at or above SCORE."
7556   (interactive "NLimit to articles with score of at least: ")
7557   (let ((data gnus-newsgroup-data)
7558         articles)
7559     (while data
7560       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7561                 score)
7562         (push (gnus-data-number (car data)) articles))
7563       (setq data (cdr data)))
7564     (prog1
7565         (gnus-summary-limit articles)
7566       (gnus-summary-position-point))))
7567
7568 (defun gnus-summary-limit-to-unseen ()
7569   "Limit to unseen articles."
7570   (interactive)
7571   (prog1
7572       (gnus-summary-limit gnus-newsgroup-unseen)
7573     (gnus-summary-position-point)))
7574
7575 (defun gnus-summary-limit-include-thread (id)
7576   "Display all the hidden articles that is in the thread with ID in it.
7577 When called interactively, ID is the Message-ID of the current
7578 article."
7579   (interactive (list (mail-header-id (gnus-summary-article-header))))
7580   (let ((articles (gnus-articles-in-thread
7581                    (gnus-id-to-thread (gnus-root-id id)))))
7582     (prog1
7583         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7584       (gnus-summary-limit-include-matching-articles
7585        "subject"
7586        (regexp-quote (gnus-simplify-subject-re
7587                       (mail-header-subject (gnus-id-to-header id)))))
7588       (gnus-summary-position-point))))
7589
7590 (defun gnus-summary-limit-include-matching-articles (header regexp)
7591   "Display all the hidden articles that have HEADERs that match REGEXP."
7592   (interactive (list (read-string "Match on header: ")
7593                      (read-string "Regexp: ")))
7594   (let ((articles (gnus-find-matching-articles header regexp)))
7595     (prog1
7596         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7597       (gnus-summary-position-point))))
7598
7599 (defun gnus-summary-insert-dormant-articles ()
7600   "Insert all the dormat articles for this group into the current buffer."
7601   (interactive)
7602   (let ((gnus-verbose (max 6 gnus-verbose)))
7603     (if (not gnus-newsgroup-dormant)
7604         (gnus-message 3 "No cached articles for this group")
7605       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7606
7607 (defun gnus-summary-limit-include-dormant ()
7608   "Display all the hidden articles that are marked as dormant.
7609 Note that this command only works on a subset of the articles currently
7610 fetched for this group."
7611   (interactive)
7612   (unless gnus-newsgroup-dormant
7613     (error "There are no dormant articles in this group"))
7614   (prog1
7615       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7616     (gnus-summary-position-point)))
7617
7618 (defun gnus-summary-limit-exclude-dormant ()
7619   "Hide all dormant articles."
7620   (interactive)
7621   (prog1
7622       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7623     (gnus-summary-position-point)))
7624
7625 (defun gnus-summary-limit-exclude-childless-dormant ()
7626   "Hide all dormant articles that have no children."
7627   (interactive)
7628   (let ((data (gnus-data-list t))
7629         articles d children)
7630     ;; Find all articles that are either not dormant or have
7631     ;; children.
7632     (while (setq d (pop data))
7633       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7634                 (and (setq children
7635                            (gnus-article-children (gnus-data-number d)))
7636                      (let (found)
7637                        (while children
7638                          (when (memq (car children) articles)
7639                            (setq children nil
7640                                  found t))
7641                          (pop children))
7642                        found)))
7643         (push (gnus-data-number d) articles)))
7644     ;; Do the limiting.
7645     (prog1
7646         (gnus-summary-limit articles)
7647       (gnus-summary-position-point))))
7648
7649 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7650   "Mark all unread excluded articles as read.
7651 If ALL, mark even excluded ticked and dormants as read."
7652   (interactive "P")
7653   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7654   (let ((articles (gnus-sorted-ndifference
7655                    (sort
7656                     (mapcar (lambda (h) (mail-header-number h))
7657                             gnus-newsgroup-headers)
7658                     '<)
7659                    gnus-newsgroup-limit))
7660         article)
7661     (setq gnus-newsgroup-unreads
7662           (gnus-sorted-intersection gnus-newsgroup-unreads
7663                                     gnus-newsgroup-limit))
7664     (if all
7665         (setq gnus-newsgroup-dormant nil
7666               gnus-newsgroup-marked nil
7667               gnus-newsgroup-reads
7668               (nconc
7669                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7670                gnus-newsgroup-reads))
7671       (while (setq article (pop articles))
7672         (unless (or (memq article gnus-newsgroup-dormant)
7673                     (memq article gnus-newsgroup-marked))
7674           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7675
7676 (defun gnus-summary-limit (articles &optional pop)
7677   (if pop
7678       ;; We pop the previous limit off the stack and use that.
7679       (setq articles (car gnus-newsgroup-limits)
7680             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7681     ;; We use the new limit, so we push the old limit on the stack.
7682     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7683   ;; Set the limit.
7684   (setq gnus-newsgroup-limit articles)
7685   (let ((total (length gnus-newsgroup-data))
7686         (data (gnus-data-find-list (gnus-summary-article-number)))
7687         (gnus-summary-mark-below nil)   ; Inhibit this.
7688         found)
7689     ;; This will do all the work of generating the new summary buffer
7690     ;; according to the new limit.
7691     (gnus-summary-prepare)
7692     ;; Hide any threads, possibly.
7693     (gnus-summary-maybe-hide-threads)
7694     ;; Try to return to the article you were at, or one in the
7695     ;; neighborhood.
7696     (when data
7697       ;; We try to find some article after the current one.
7698       (while data
7699         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7700           (setq data nil
7701                 found t))
7702         (setq data (cdr data))))
7703     (unless found
7704       ;; If there is no data, that means that we were after the last
7705       ;; article.  The same goes when we can't find any articles
7706       ;; after the current one.
7707       (goto-char (point-max))
7708       (gnus-summary-find-prev))
7709     (gnus-set-mode-line 'summary)
7710     ;; We return how many articles were removed from the summary
7711     ;; buffer as a result of the new limit.
7712     (- total (length gnus-newsgroup-data))))
7713
7714 (defsubst gnus-invisible-cut-children (threads)
7715   (let ((num 0))
7716     (while threads
7717       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7718         (incf num))
7719       (pop threads))
7720     (< num 2)))
7721
7722 (defsubst gnus-cut-thread (thread)
7723   "Go forwards in the thread until we find an article that we want to display."
7724   (when (or (eq gnus-fetch-old-headers 'some)
7725             (eq gnus-fetch-old-headers 'invisible)
7726             (numberp gnus-fetch-old-headers)
7727             (eq gnus-build-sparse-threads 'some)
7728             (eq gnus-build-sparse-threads 'more))
7729     ;; Deal with old-fetched headers and sparse threads.
7730     (while (and
7731             thread
7732             (or
7733              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7734              (gnus-summary-article-ancient-p
7735               (mail-header-number (car thread))))
7736             (if (or (<= (length (cdr thread)) 1)
7737                     (eq gnus-fetch-old-headers 'invisible))
7738                 (setq gnus-newsgroup-limit
7739                       (delq (mail-header-number (car thread))
7740                             gnus-newsgroup-limit)
7741                       thread (cadr thread))
7742               (when (gnus-invisible-cut-children (cdr thread))
7743                 (let ((th (cdr thread)))
7744                   (while th
7745                     (if (memq (mail-header-number (caar th))
7746                               gnus-newsgroup-limit)
7747                         (setq thread (car th)
7748                               th nil)
7749                       (setq th (cdr th))))))))))
7750   thread)
7751
7752 (defun gnus-cut-threads (threads)
7753   "Cut off all uninteresting articles from the beginning of threads."
7754   (when (or (eq gnus-fetch-old-headers 'some)
7755             (eq gnus-fetch-old-headers 'invisible)
7756             (numberp gnus-fetch-old-headers)
7757             (eq gnus-build-sparse-threads 'some)
7758             (eq gnus-build-sparse-threads 'more))
7759     (let ((th threads))
7760       (while th
7761         (setcar th (gnus-cut-thread (car th)))
7762         (setq th (cdr th)))))
7763   ;; Remove nixed out threads.
7764   (delq nil threads))
7765
7766 (defun gnus-summary-initial-limit (&optional show-if-empty)
7767   "Figure out what the initial limit is supposed to be on group entry.
7768 This entails weeding out unwanted dormants, low-scored articles,
7769 fetch-old-headers verbiage, and so on."
7770   ;; Most groups have nothing to remove.
7771   (if (or gnus-inhibit-limiting
7772           (and (null gnus-newsgroup-dormant)
7773                (eq gnus-newsgroup-display 'gnus-not-ignore)
7774                (not (eq gnus-fetch-old-headers 'some))
7775                (not (numberp gnus-fetch-old-headers))
7776                (not (eq gnus-fetch-old-headers 'invisible))
7777                (null gnus-summary-expunge-below)
7778                (not (eq gnus-build-sparse-threads 'some))
7779                (not (eq gnus-build-sparse-threads 'more))
7780                (null gnus-thread-expunge-below)
7781                (not gnus-use-nocem)))
7782       ()                                ; Do nothing.
7783     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7784     (setq gnus-newsgroup-limit nil)
7785     (mapatoms
7786      (lambda (node)
7787        (unless (car (symbol-value node))
7788          ;; These threads have no parents -- they are roots.
7789          (let ((nodes (cdr (symbol-value node)))
7790                thread)
7791            (while nodes
7792              (if (and gnus-thread-expunge-below
7793                       (< (gnus-thread-total-score (car nodes))
7794                          gnus-thread-expunge-below))
7795                  (gnus-expunge-thread (pop nodes))
7796                (setq thread (pop nodes))
7797                (gnus-summary-limit-children thread))))))
7798      gnus-newsgroup-dependencies)
7799     ;; If this limitation resulted in an empty group, we might
7800     ;; pop the previous limit and use it instead.
7801     (when (and (not gnus-newsgroup-limit)
7802                show-if-empty)
7803       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7804     gnus-newsgroup-limit))
7805
7806 (defun gnus-summary-limit-children (thread)
7807   "Return 1 if this subthread is visible and 0 if it is not."
7808   ;; First we get the number of visible children to this thread.  This
7809   ;; is done by recursing down the thread using this function, so this
7810   ;; will really go down to a leaf article first, before slowly
7811   ;; working its way up towards the root.
7812   (when thread
7813     (let* ((max-lisp-eval-depth 5000)
7814            (children
7815            (if (cdr thread)
7816                (apply '+ (mapcar 'gnus-summary-limit-children
7817                                  (cdr thread)))
7818              0))
7819           (number (mail-header-number (car thread)))
7820           score)
7821       (if (and
7822            (not (memq number gnus-newsgroup-marked))
7823            (or
7824             ;; If this article is dormant and has absolutely no visible
7825             ;; children, then this article isn't visible.
7826             (and (memq number gnus-newsgroup-dormant)
7827                  (zerop children))
7828             ;; If this is "fetch-old-headered" and there is no
7829             ;; visible children, then we don't want this article.
7830             (and (or (eq gnus-fetch-old-headers 'some)
7831                      (numberp gnus-fetch-old-headers))
7832                  (gnus-summary-article-ancient-p number)
7833                  (zerop children))
7834             ;; If this is "fetch-old-headered" and `invisible', then
7835             ;; we don't want this article.
7836             (and (eq gnus-fetch-old-headers 'invisible)
7837                  (gnus-summary-article-ancient-p number))
7838             ;; If this is a sparsely inserted article with no children,
7839             ;; we don't want it.
7840             (and (eq gnus-build-sparse-threads 'some)
7841                  (gnus-summary-article-sparse-p number)
7842                  (zerop children))
7843             ;; If we use expunging, and this article is really
7844             ;; low-scored, then we don't want this article.
7845             (when (and gnus-summary-expunge-below
7846                        (< (setq score
7847                                 (or (cdr (assq number gnus-newsgroup-scored))
7848                                     gnus-summary-default-score))
7849                           gnus-summary-expunge-below))
7850               ;; We increase the expunge-tally here, but that has
7851               ;; nothing to do with the limits, really.
7852               (incf gnus-newsgroup-expunged-tally)
7853               ;; We also mark as read here, if that's wanted.
7854               (when (and gnus-summary-mark-below
7855                          (< score gnus-summary-mark-below))
7856                 (setq gnus-newsgroup-unreads
7857                       (delq number gnus-newsgroup-unreads))
7858                 (if gnus-newsgroup-auto-expire
7859                     (push number gnus-newsgroup-expirable)
7860                   (push (cons number gnus-low-score-mark)
7861                         gnus-newsgroup-reads)))
7862               t)
7863             ;; Do the `display' group parameter.
7864             (and gnus-newsgroup-display
7865                  (not (funcall gnus-newsgroup-display)))
7866             ;; Check NoCeM things.
7867             (if (and gnus-use-nocem
7868                      (gnus-nocem-unwanted-article-p
7869                       (mail-header-id (car thread))))
7870                 (progn
7871                   (setq gnus-newsgroup-unreads
7872                         (delq number gnus-newsgroup-unreads))
7873                   t))))
7874           ;; Nope, invisible article.
7875           0
7876         ;; Ok, this article is to be visible, so we add it to the limit
7877         ;; and return 1.
7878         (push number gnus-newsgroup-limit)
7879         1))))
7880
7881 (defun gnus-expunge-thread (thread)
7882   "Mark all articles in THREAD as read."
7883   (let* ((number (mail-header-number (car thread))))
7884     (incf gnus-newsgroup-expunged-tally)
7885     ;; We also mark as read here, if that's wanted.
7886     (setq gnus-newsgroup-unreads
7887           (delq number gnus-newsgroup-unreads))
7888     (if gnus-newsgroup-auto-expire
7889         (push number gnus-newsgroup-expirable)
7890       (push (cons number gnus-low-score-mark)
7891             gnus-newsgroup-reads)))
7892   ;; Go recursively through all subthreads.
7893   (mapcar 'gnus-expunge-thread (cdr thread)))
7894
7895 ;; Summary article oriented commands
7896
7897 (defun gnus-summary-refer-parent-article (n)
7898   "Refer parent article N times.
7899 If N is negative, go to ancestor -N instead.
7900 The difference between N and the number of articles fetched is returned."
7901   (interactive "p")
7902   (let ((skip 1)
7903         error header ref)
7904     (when (not (natnump n))
7905       (setq skip (abs n)
7906             n 1))
7907     (while (and (> n 0)
7908                 (not error))
7909       (setq header (gnus-summary-article-header))
7910       (if (and (eq (mail-header-number header)
7911                    (cdr gnus-article-current))
7912                (equal gnus-newsgroup-name
7913                       (car gnus-article-current)))
7914           ;; If we try to find the parent of the currently
7915           ;; displayed article, then we take a look at the actual
7916           ;; References header, since this is slightly more
7917           ;; reliable than the References field we got from the
7918           ;; server.
7919           (save-excursion
7920             (set-buffer gnus-original-article-buffer)
7921             (nnheader-narrow-to-headers)
7922             (unless (setq ref (message-fetch-field "references"))
7923               (setq ref (message-fetch-field "in-reply-to")))
7924             (widen))
7925         (setq ref
7926               ;; It's not the current article, so we take a bet on
7927               ;; the value we got from the server.
7928               (mail-header-references header)))
7929       (if (and ref
7930                (not (equal ref "")))
7931           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7932             (gnus-message 1 "Couldn't find parent"))
7933         (gnus-message 1 "No references in article %d"
7934                       (gnus-summary-article-number))
7935         (setq error t))
7936       (decf n))
7937     (gnus-summary-position-point)
7938     n))
7939
7940 (defun gnus-summary-refer-references ()
7941   "Fetch all articles mentioned in the References header.
7942 Return the number of articles fetched."
7943   (interactive)
7944   (let ((ref (mail-header-references (gnus-summary-article-header)))
7945         (current (gnus-summary-article-number))
7946         (n 0))
7947     (if (or (not ref)
7948             (equal ref ""))
7949         (error "No References in the current article")
7950       ;; For each Message-ID in the References header...
7951       (while (string-match "<[^>]*>" ref)
7952         (incf n)
7953         ;; ... fetch that article.
7954         (gnus-summary-refer-article
7955          (prog1 (match-string 0 ref)
7956            (setq ref (substring ref (match-end 0))))))
7957       (gnus-summary-goto-subject current)
7958       (gnus-summary-position-point)
7959       n)))
7960
7961 (defun gnus-summary-refer-thread (&optional limit)
7962   "Fetch all articles in the current thread.
7963 If LIMIT (the numerical prefix), fetch that many old headers instead
7964 of what's specified by the `gnus-refer-thread-limit' variable."
7965   (interactive "P")
7966   (let ((id (mail-header-id (gnus-summary-article-header)))
7967         (limit (if limit (prefix-numeric-value limit)
7968                  gnus-refer-thread-limit)))
7969     ;; We want to fetch LIMIT *old* headers, but we also have to
7970     ;; re-fetch all the headers in the current buffer, because many of
7971     ;; them may be undisplayed.  So we adjust LIMIT.
7972     (when (numberp limit)
7973       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7974     (unless (eq gnus-fetch-old-headers 'invisible)
7975       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7976       ;; Retrieve the headers and read them in.
7977       (if (eq (gnus-retrieve-headers
7978                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7979               'nov)
7980           (gnus-build-all-threads)
7981         (error "Can't fetch thread from backends that don't support NOV"))
7982       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7983     (gnus-summary-limit-include-thread id)))
7984
7985 (defun gnus-summary-refer-article (message-id)
7986   "Fetch an article specified by MESSAGE-ID."
7987   (interactive "sMessage-ID: ")
7988   (when (and (stringp message-id)
7989              (not (zerop (length message-id))))
7990     ;; Construct the correct Message-ID if necessary.
7991     ;; Suggested by tale@pawl.rpi.edu.
7992     (unless (string-match "^<" message-id)
7993       (setq message-id (concat "<" message-id)))
7994     (unless (string-match ">$" message-id)
7995       (setq message-id (concat message-id ">")))
7996     (let* ((header (gnus-id-to-header message-id))
7997            (sparse (and header
7998                         (gnus-summary-article-sparse-p
7999                          (mail-header-number header))
8000                         (memq (mail-header-number header)
8001                               gnus-newsgroup-limit)))
8002            number)
8003       (cond
8004        ;; If the article is present in the buffer we just go to it.
8005        ((and header
8006              (or (not (gnus-summary-article-sparse-p
8007                        (mail-header-number header)))
8008                  sparse))
8009         (prog1
8010             (gnus-summary-goto-article
8011              (mail-header-number header) nil t)
8012           (when sparse
8013             (gnus-summary-update-article (mail-header-number header)))))
8014        (t
8015         ;; We fetch the article.
8016         (catch 'found
8017           (dolist (gnus-override-method (gnus-refer-article-methods))
8018             (gnus-check-server gnus-override-method)
8019             ;; Fetch the header, and display the article.
8020             (when (setq number (gnus-summary-insert-subject message-id))
8021               (gnus-summary-select-article nil nil nil number)
8022               (throw 'found t)))
8023           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8024
8025 (defun gnus-refer-article-methods ()
8026   "Return a list of referable methods."
8027   (cond
8028    ;; No method, so we default to current and native.
8029    ((null gnus-refer-article-method)
8030     (list gnus-current-select-method gnus-select-method))
8031    ;; Current.
8032    ((eq 'current gnus-refer-article-method)
8033     (list gnus-current-select-method))
8034    ;; List of select methods.
8035    ((not (and (symbolp (car gnus-refer-article-method))
8036               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8037     (let (out)
8038       (dolist (method gnus-refer-article-method)
8039         (push (if (eq 'current method)
8040                   gnus-current-select-method
8041                 method)
8042               out))
8043       (nreverse out)))
8044    ;; One single select method.
8045    (t
8046     (list gnus-refer-article-method))))
8047
8048 (defun gnus-summary-edit-parameters ()
8049   "Edit the group parameters of the current group."
8050   (interactive)
8051   (gnus-group-edit-group gnus-newsgroup-name 'params))
8052
8053 (defun gnus-summary-customize-parameters ()
8054   "Customize the group parameters of the current group."
8055   (interactive)
8056   (gnus-group-customize gnus-newsgroup-name))
8057
8058 (defun gnus-summary-enter-digest-group (&optional force)
8059   "Enter an nndoc group based on the current article.
8060 If FORCE, force a digest interpretation.  If not, try
8061 to guess what the document format is."
8062   (interactive "P")
8063   (let ((conf gnus-current-window-configuration))
8064     (save-excursion
8065       (gnus-summary-select-article))
8066     (setq gnus-current-window-configuration conf)
8067     (let* ((name (format "%s-%d"
8068                          (gnus-group-prefixed-name
8069                           gnus-newsgroup-name (list 'nndoc ""))
8070                          (save-excursion
8071                            (set-buffer gnus-summary-buffer)
8072                            gnus-current-article)))
8073            (ogroup gnus-newsgroup-name)
8074            (params (append (gnus-info-params (gnus-get-info ogroup))
8075                            (list (cons 'to-group ogroup))
8076                            (list (cons 'save-article-group ogroup))))
8077            (case-fold-search t)
8078            (buf (current-buffer))
8079            dig to-address)
8080       (save-excursion
8081         (set-buffer gnus-original-article-buffer)
8082         ;; Have the digest group inherit the main mail address of
8083         ;; the parent article.
8084         (when (setq to-address (or (gnus-fetch-field "reply-to")
8085                                    (gnus-fetch-field "from")))
8086           (setq params (append
8087                         (list (cons 'to-address
8088                                     (funcall gnus-decode-encoded-word-function
8089                                              to-address))))))
8090         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8091         (insert-buffer-substring gnus-original-article-buffer)
8092         ;; Remove lines that may lead nndoc to misinterpret the
8093         ;; document type.
8094         (narrow-to-region
8095          (goto-char (point-min))
8096          (or (search-forward "\n\n" nil t) (point)))
8097         (goto-char (point-min))
8098         (delete-matching-lines "^Path:\\|^From ")
8099         (widen))
8100       (unwind-protect
8101           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8102                     (gnus-newsgroup-ephemeral-ignored-charsets
8103                      gnus-newsgroup-ignored-charsets))
8104                 (gnus-group-read-ephemeral-group
8105                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8106                               (nndoc-article-type
8107                                ,(if force 'mbox 'guess)))
8108                  t nil nil nil
8109                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8110                                                         "ADAPT")))))
8111               ;; Make all postings to this group go to the parent group.
8112               (nconc (gnus-info-params (gnus-get-info name))
8113                      params)
8114             ;; Couldn't select this doc group.
8115             (switch-to-buffer buf)
8116             (gnus-set-global-variables)
8117             (gnus-configure-windows 'summary)
8118             (gnus-message 3 "Article couldn't be entered?"))
8119         (kill-buffer dig)))))
8120
8121 (defun gnus-summary-read-document (n)
8122   "Open a new group based on the current article(s).
8123 This will allow you to read digests and other similar
8124 documents as newsgroups.
8125 Obeys the standard process/prefix convention."
8126   (interactive "P")
8127   (let* ((articles (gnus-summary-work-articles n))
8128          (ogroup gnus-newsgroup-name)
8129          (params (append (gnus-info-params (gnus-get-info ogroup))
8130                          (list (cons 'to-group ogroup))))
8131          article group egroup groups vgroup)
8132     (while (setq article (pop articles))
8133       (setq group (format "%s-%d" gnus-newsgroup-name article))
8134       (gnus-summary-remove-process-mark article)
8135       (when (gnus-summary-display-article article)
8136         (save-excursion
8137           (with-temp-buffer
8138             (insert-buffer-substring gnus-original-article-buffer)
8139             ;; Remove some headers that may lead nndoc to make
8140             ;; the wrong guess.
8141             (message-narrow-to-head)
8142             (goto-char (point-min))
8143             (delete-matching-lines "^\\(Path\\):\\|^From ")
8144             (widen)
8145             (if (setq egroup
8146                       (gnus-group-read-ephemeral-group
8147                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8148                                      (nndoc-article-type guess))
8149                        t nil t))
8150                 (progn
8151                   ;; Make all postings to this group go to the parent group.
8152                   (nconc (gnus-info-params (gnus-get-info egroup))
8153                          params)
8154                   (push egroup groups))
8155               ;; Couldn't select this doc group.
8156               (gnus-error 3 "Article couldn't be entered"))))))
8157     ;; Now we have selected all the documents.
8158     (cond
8159      ((not groups)
8160       (error "None of the articles could be interpreted as documents"))
8161      ((gnus-group-read-ephemeral-group
8162        (setq vgroup (format
8163                      "nnvirtual:%s-%s" gnus-newsgroup-name
8164                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8165        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8166        t
8167        (cons (current-buffer) 'summary)))
8168      (t
8169       (error "Couldn't select virtual nndoc group")))))
8170
8171 (defun gnus-summary-isearch-article (&optional regexp-p)
8172   "Do incremental search forward on the current article.
8173 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8174   (interactive "P")
8175   (let* ((gnus-inhibit-treatment t)
8176          (old (gnus-summary-select-article)))
8177     (gnus-configure-windows 'article)
8178     (gnus-eval-in-buffer-window gnus-article-buffer
8179       (save-restriction
8180         (widen)
8181         (when (eq 'old old)
8182           (gnus-article-show-all-headers))
8183         (goto-char (point-min))
8184         (isearch-forward regexp-p)))))
8185
8186 (defun gnus-summary-search-article-forward (regexp &optional backward)
8187   "Search for an article containing REGEXP forward.
8188 If BACKWARD, search backward instead."
8189   (interactive
8190    (list (read-string
8191           (format "Search article %s (regexp%s): "
8192                   (if current-prefix-arg "backward" "forward")
8193                   (if gnus-last-search-regexp
8194                       (concat ", default " gnus-last-search-regexp)
8195                     "")))
8196          current-prefix-arg))
8197   (if (string-equal regexp "")
8198       (setq regexp (or gnus-last-search-regexp ""))
8199     (setq gnus-last-search-regexp regexp)
8200     (setq gnus-article-before-search gnus-current-article))
8201   ;; Intentionally set gnus-last-article.
8202   (setq gnus-last-article gnus-article-before-search)
8203   (let ((gnus-last-article gnus-last-article))
8204     (if (gnus-summary-search-article regexp backward)
8205         (gnus-summary-show-thread)
8206       (error "Search failed: \"%s\"" regexp))))
8207
8208 (defun gnus-summary-search-article-backward (regexp)
8209   "Search for an article containing REGEXP backward."
8210   (interactive
8211    (list (read-string
8212           (format "Search article backward (regexp%s): "
8213                   (if gnus-last-search-regexp
8214                       (concat ", default " gnus-last-search-regexp)
8215                     "")))))
8216   (gnus-summary-search-article-forward regexp 'backward))
8217
8218 (eval-when-compile
8219   (defmacro gnus-summary-search-article-position-point (regexp backward)
8220     "Dehighlight the last matched text and goto the beginning position."
8221     (` (if (and gnus-summary-search-article-matched-data
8222                 (let ((text (caddr gnus-summary-search-article-matched-data))
8223                       (inhibit-read-only t)
8224                       buffer-read-only)
8225                   (delete-region
8226                    (goto-char (car gnus-summary-search-article-matched-data))
8227                    (cadr gnus-summary-search-article-matched-data))
8228                   (insert text)
8229                   (string-match (, regexp) text)))
8230            (if (, backward) (beginning-of-line) (end-of-line))
8231          (goto-char (if (, backward) (point-max) (point-min))))))
8232
8233   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8234     "Place point where X-Face image is displayed."
8235     (if (featurep 'xemacs)
8236         (` (let ((end (if (search-forward "\n\n" nil t)
8237                           (goto-char (1- (point)))
8238                         (point-min)))
8239                  extent)
8240              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8241              (unless (and (re-search-forward "^From:" end t)
8242                           (setq extent (extent-at (point)))
8243                           (extent-begin-glyph extent))
8244                (goto-char (, opoint)))))
8245       (` (let ((end (if (search-forward "\n\n" nil t)
8246                         (goto-char (1- (point)))
8247                       (point-min)))
8248                (start (or (search-backward "\n\n" nil t) (point-min))))
8249            (goto-char
8250             (or (text-property-any start end 'x-face-image t);; x-face-e21
8251                 (text-property-any start end 'x-face-mule-bitmap-image t)
8252                 (, opoint)))))))
8253
8254   (defmacro gnus-summary-search-article-highlight-matched-text
8255     (backward treated x-face)
8256     "Highlight matched text in the function `gnus-summary-search-article'."
8257     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8258              (end (set-marker (make-marker) (match-end 0)))
8259              (inhibit-read-only t)
8260              buffer-read-only)
8261          (unless treated
8262            (let ((,@
8263                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8264                     (mapcar
8265                      (lambda (item) (setq items (delq item items)))
8266                      '(gnus-treat-buttonize
8267                        gnus-treat-fill-article
8268                        gnus-treat-fill-long-lines
8269                        gnus-treat-emphasize
8270                        gnus-treat-highlight-headers
8271                        gnus-treat-highlight-citation
8272                        gnus-treat-highlight-signature
8273                        gnus-treat-overstrike
8274                        gnus-treat-display-xface
8275                        gnus-treat-buttonize-head
8276                        gnus-treat-decode-article-as-default-mime-charset))
8277                     (static-if (featurep 'xemacs)
8278                         items
8279                       (cons '(x-face-mule-delete-x-face-field
8280                               (quote never))
8281                             items))))
8282                  (gnus-treat-display-xface
8283                   (when (, x-face) gnus-treat-display-xface)))
8284              (gnus-article-prepare-mime-display)))
8285          (goto-char (if (, backward) start end))
8286          (when (, x-face)
8287            (gnus-summary-search-article-highlight-goto-x-face (point)))
8288          (setq gnus-summary-search-article-matched-data
8289                (list start end (buffer-substring start end)))
8290          (unless (eq start end);; matched text has been deleted. :-<
8291            (put-text-property start end 'face
8292                               (or (find-face 'isearch)
8293                                   'secondary-selection))))))
8294   )
8295
8296 (defun gnus-summary-search-article (regexp &optional backward)
8297   "Search for an article containing REGEXP.
8298 Optional argument BACKWARD means do search for backward.
8299 `gnus-select-article-hook' is not called during the search."
8300   ;; We have to require this here to make sure that the following
8301   ;; dynamic binding isn't shadowed by autoloading.
8302   (require 'gnus-async)
8303   (require 'gnus-art)
8304   (let ((gnus-select-article-hook nil)  ;Disable hook.
8305         (gnus-article-prepare-hook nil)
8306         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8307         (gnus-use-article-prefetch nil)
8308         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8309         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8310         (sum (current-buffer))
8311         (found nil)
8312         point treated)
8313     (gnus-save-hidden-threads
8314       (static-if (featurep 'xemacs)
8315           (let ((gnus-inhibit-treatment t))
8316             (setq treated (eq 'old (gnus-summary-select-article)))
8317             (when (and treated
8318                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8319                                  (window-live-p (get-buffer-window
8320                                                  gnus-article-buffer t)))))
8321               (gnus-summary-select-article nil t)
8322               (setq treated nil)))
8323         (let ((gnus-inhibit-treatment t)
8324               (x-face-mule-delete-x-face-field 'never))
8325           (setq treated (eq 'old (gnus-summary-select-article)))
8326           (when (and treated
8327                      (not
8328                       (and (gnus-buffer-live-p gnus-article-buffer)
8329                            (window-live-p (get-buffer-window
8330                                            gnus-article-buffer t))
8331                            (or (not (string-match "^\\^X-Face:" regexp))
8332                                (with-current-buffer gnus-article-buffer
8333                                  gnus-summary-search-article-matched-data)))))
8334             (gnus-summary-select-article nil t)
8335             (setq treated nil))))
8336       (set-buffer gnus-article-buffer)
8337       (widen)
8338       (if treated
8339           (progn
8340             (gnus-article-show-all-headers)
8341             (gnus-summary-search-article-position-point regexp backward))
8342         (goto-char (if backward (point-max) (point-min))))
8343       (while (not found)
8344         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8345         (if (if backward
8346                 (re-search-backward regexp nil t)
8347               (re-search-forward regexp nil t))
8348             ;; We found the regexp.
8349             (progn
8350               (gnus-summary-search-article-highlight-matched-text
8351                backward treated (string-match "^\\^X-Face:" regexp))
8352               (setq found 'found)
8353               (forward-line
8354                (/ (- 2 (window-height
8355                         (get-buffer-window gnus-article-buffer t)))
8356                   2))
8357               (set-window-start
8358                (get-buffer-window (current-buffer))
8359                (point))
8360               (set-buffer sum)
8361               (setq point (point)))
8362           ;; We didn't find it, so we go to the next article.
8363           (set-buffer sum)
8364           (setq found 'not)
8365           (while (eq found 'not)
8366             (if (not (if backward (gnus-summary-find-prev)
8367                        (gnus-summary-find-next)))
8368                 ;; No more articles.
8369                 (setq found t)
8370               ;; Select the next article and adjust point.
8371               (unless (gnus-summary-article-sparse-p
8372                        (gnus-summary-article-number))
8373                 (setq found nil)
8374                 (let ((gnus-inhibit-treatment t))
8375                   (gnus-summary-select-article))
8376                 (setq treated nil)
8377                 (set-buffer gnus-article-buffer)
8378                 (widen)
8379                 (goto-char (if backward (point-max) (point-min))))))))
8380       (gnus-message 7 ""))
8381     ;; Return whether we found the regexp.
8382     (when (eq found 'found)
8383       (goto-char point)
8384       (gnus-summary-show-thread)
8385       (gnus-summary-goto-subject gnus-current-article)
8386       (gnus-summary-position-point)
8387       t)))
8388
8389 (defun gnus-find-matching-articles (header regexp)
8390   "Return a list of all articles that match REGEXP on HEADER.
8391 This search includes all articles in the current group that Gnus has
8392 fetched headers for, whether they are displayed or not."
8393   (let ((articles nil)
8394         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8395         (case-fold-search t))
8396     (dolist (header gnus-newsgroup-headers)
8397       (when (string-match regexp (funcall func header))
8398         (push (mail-header-number header) articles)))
8399     (nreverse articles)))
8400
8401 (defun gnus-summary-find-matching (header regexp &optional backward unread
8402                                           not-case-fold not-matching)
8403   "Return a list of all articles that match REGEXP on HEADER.
8404 The search stars on the current article and goes forwards unless
8405 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8406 If UNREAD is non-nil, only unread articles will
8407 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8408 in the comparisons. If NOT-MATCHING, return a list of all articles that
8409 not match REGEXP on HEADER."
8410   (let ((case-fold-search (not not-case-fold))
8411         articles d func)
8412     (if (consp header)
8413         (if (eq (car header) 'extra)
8414             (setq func
8415                   `(lambda (h)
8416                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8417                          "")))
8418           (error "%s is an invalid header" header))
8419       (unless (fboundp (intern (concat "mail-header-" header)))
8420         (error "%s is not a valid header" header))
8421       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8422     (dolist (d (if (eq backward 'all)
8423                    gnus-newsgroup-data
8424                  (gnus-data-find-list
8425                   (gnus-summary-article-number)
8426                   (gnus-data-list backward))))
8427       (when (and (or (not unread)       ; We want all articles...
8428                      (gnus-data-unread-p d)) ; Or just unreads.
8429                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8430                  (if not-matching
8431                      (not (string-match
8432                            regexp
8433                            (funcall func (gnus-data-header d))))
8434                    (string-match regexp
8435                                  (funcall func (gnus-data-header d)))))
8436         (push (gnus-data-number d) articles))) ; Success!
8437     (nreverse articles)))
8438
8439 (defun gnus-summary-execute-command (header regexp command &optional backward)
8440   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8441 If HEADER is an empty string (or nil), the match is done on the entire
8442 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8443   (interactive
8444    (list (let ((completion-ignore-case t))
8445            (completing-read
8446             "Header name: "
8447             (mapcar (lambda (header) (list (format "%s" header)))
8448                     (append
8449                      '("Number" "Subject" "From" "Lines" "Date"
8450                        "Message-ID" "Xref" "References" "Body")
8451                      gnus-extra-headers))
8452             nil 'require-match))
8453          (read-string "Regexp: ")
8454          (read-key-sequence "Command: ")
8455          current-prefix-arg))
8456   (when (equal header "Body")
8457     (setq header ""))
8458   ;; Hidden thread subtrees must be searched as well.
8459   (gnus-summary-show-all-threads)
8460   ;; We don't want to change current point nor window configuration.
8461   (save-excursion
8462     (save-window-excursion
8463       (let (gnus-visual
8464             gnus-treat-strip-trailing-blank-lines
8465             gnus-treat-strip-leading-blank-lines
8466             gnus-treat-strip-multiple-blank-lines
8467             gnus-treat-hide-boring-headers
8468             gnus-treat-fold-newsgroups
8469             gnus-article-prepare-hook)
8470         (gnus-message 6 "Executing %s..." (key-description command))
8471         ;; We'd like to execute COMMAND interactively so as to give arguments.
8472         (gnus-execute header regexp
8473                       `(call-interactively ',(key-binding command))
8474                       backward)
8475         (gnus-message 6 "Executing %s...done" (key-description command))))))
8476
8477 (defun gnus-summary-beginning-of-article ()
8478   "Scroll the article back to the beginning."
8479   (interactive)
8480   (gnus-summary-select-article)
8481   (gnus-configure-windows 'article)
8482   (gnus-eval-in-buffer-window gnus-article-buffer
8483     (widen)
8484     (goto-char (point-min))
8485     (when gnus-page-broken
8486       (gnus-narrow-to-page))))
8487
8488 (defun gnus-summary-end-of-article ()
8489   "Scroll to the end of the article."
8490   (interactive)
8491   (gnus-summary-select-article)
8492   (gnus-configure-windows 'article)
8493   (gnus-eval-in-buffer-window gnus-article-buffer
8494     (widen)
8495     (goto-char (point-max))
8496     (recenter -3)
8497     (when gnus-page-broken
8498       (gnus-narrow-to-page))))
8499
8500 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8501   "Truncate to LEN and quote all \"(\"'s in STRING."
8502   (gnus-replace-in-string (if (and len (> (length string) len))
8503                               (substring string 0 len)
8504                             string)
8505                           "[()]" "\\\\\\&"))
8506
8507 (defun gnus-summary-print-article (&optional filename n)
8508   "Generate and print a PostScript image of the N next (mail) articles.
8509
8510 If N is negative, print the N previous articles.  If N is nil and articles
8511 have been marked with the process mark, print these instead.
8512
8513 If the optional first argument FILENAME is nil, send the image to the
8514 printer.  If FILENAME is a string, save the PostScript image in a file with
8515 that name.  If FILENAME is a number, prompt the user for the name of the file
8516 to save in."
8517   (interactive (list (ps-print-preprint current-prefix-arg)))
8518   (dolist (article (gnus-summary-work-articles n))
8519     (gnus-summary-select-article nil nil 'pseudo article)
8520     (gnus-eval-in-buffer-window gnus-article-buffer
8521       (gnus-print-buffer))
8522     (gnus-summary-remove-process-mark article))
8523   (ps-despool filename))
8524
8525 (defun gnus-print-buffer ()
8526   (let ((buffer (generate-new-buffer " *print*")))
8527     (unwind-protect
8528         (progn
8529           (copy-to-buffer buffer (point-min) (point-max))
8530           (set-buffer buffer)
8531           (gnus-article-delete-invisible-text)
8532           (gnus-remove-text-with-property 'gnus-decoration)
8533           (when (gnus-visual-p 'article-highlight 'highlight)
8534             ;; Copy-to-buffer doesn't copy overlay.  So redo
8535             ;; highlight.
8536             (let ((gnus-article-buffer buffer))
8537               (gnus-article-highlight-citation t)
8538               (gnus-article-highlight-signature)))
8539           (let ((ps-left-header
8540                  (list
8541                   (concat "("
8542                           (gnus-summary-print-truncate-and-quote
8543                            (mail-header-subject gnus-current-headers)
8544                            66) ")")
8545                   (concat "("
8546                           (gnus-summary-print-truncate-and-quote
8547                            (mail-header-from gnus-current-headers)
8548                            45) ")")))
8549                 (ps-right-header
8550                  (list
8551                   "/pagenumberstring load"
8552                   (concat "("
8553                           (mail-header-date gnus-current-headers) ")"))))
8554             (gnus-run-hooks 'gnus-ps-print-hook)
8555             (save-excursion
8556               (if window-system
8557                   (ps-spool-buffer-with-faces)
8558                 (ps-spool-buffer)))))
8559       (kill-buffer buffer))))
8560
8561 (defun gnus-summary-show-article (&optional arg)
8562   "Force redisplaying of the current article.
8563 If ARG (the prefix) is a number, show the article with the charset
8564 defined in `gnus-summary-show-article-charset-alist', or the charset
8565 input.
8566 If ARG (the prefix) is non-nil and not a number, show the raw article
8567 without any article massaging functions being run.  Normally, the key strokes
8568 are `C-u g'."
8569   (interactive "P")
8570   (cond
8571    ((numberp arg)
8572     (gnus-summary-show-article t)
8573     (let* ((gnus-newsgroup-charset
8574             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8575                 (mm-read-coding-system
8576                  "View as charset: " ;; actually it is coding system.
8577                  (save-excursion
8578                    (set-buffer gnus-article-buffer)
8579                    (mm-detect-coding-region (point) (point-max))))))
8580            (default-mime-charset gnus-newsgroup-charset)
8581            (gnus-newsgroup-ignored-charsets 'gnus-all))
8582       (gnus-summary-select-article nil 'force)
8583       (let ((deps gnus-newsgroup-dependencies)
8584             head header lines)
8585         (save-excursion
8586           (set-buffer gnus-original-article-buffer)
8587           (save-restriction
8588             (message-narrow-to-head)
8589             (setq head (buffer-string))
8590             (goto-char (point-min))
8591             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8592               (goto-char (point-max))
8593               (widen)
8594               (setq lines (1- (count-lines (point) (point-max))))))
8595           (with-temp-buffer
8596             (insert (format "211 %d Article retrieved.\n"
8597                             (cdr gnus-article-current)))
8598             (insert head)
8599             (if lines (insert (format "Lines: %d\n" lines)))
8600             (insert ".\n")
8601             (let ((nntp-server-buffer (current-buffer)))
8602               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8603         (gnus-data-set-header
8604          (gnus-data-find (cdr gnus-article-current))
8605          header)
8606         (gnus-summary-update-article-line
8607          (cdr gnus-article-current) header)
8608         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8609           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8610    ((not arg)
8611     ;; Select the article the normal way.
8612     (gnus-summary-select-article nil 'force))
8613    (t
8614     ;; We have to require this here to make sure that the following
8615     ;; dynamic binding isn't shadowed by autoloading.
8616     (require 'gnus-async)
8617     (require 'gnus-art)
8618     ;; Bind the article treatment functions to nil.
8619     (let ((gnus-have-all-headers t)
8620           gnus-article-prepare-hook
8621           gnus-article-decode-hook
8622           gnus-break-pages
8623           gnus-show-mime
8624           (gnus-inhibit-treatment t))
8625       (gnus-summary-select-article nil 'force))))
8626   (gnus-summary-goto-subject gnus-current-article)
8627   (gnus-summary-position-point))
8628
8629 (defun gnus-summary-show-raw-article ()
8630   "Show the raw article without any article massaging functions being run."
8631   (interactive)
8632   (gnus-summary-show-article t))
8633
8634 (defun gnus-summary-verbose-headers (&optional arg)
8635   "Toggle permanent full header display.
8636 If ARG is a positive number, turn header display on.
8637 If ARG is a negative number, turn header display off."
8638   (interactive "P")
8639   (setq gnus-show-all-headers
8640         (cond ((or (not (numberp arg))
8641                    (zerop arg))
8642                (not gnus-show-all-headers))
8643               ((natnump arg)
8644                t)))
8645   (gnus-summary-show-article))
8646
8647 (defun gnus-summary-toggle-header (&optional arg)
8648   "Show the headers if they are hidden, or hide them if they are shown.
8649 If ARG is a positive number, show the entire header.
8650 If ARG is a negative number, hide the unwanted header lines."
8651   (interactive "P")
8652   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8653                      (get-buffer-window gnus-article-buffer t))))
8654     (with-current-buffer gnus-article-buffer
8655       (widen)
8656       (article-narrow-to-head)
8657       (let* ((buffer-read-only nil)
8658              (inhibit-point-motion-hooks t)
8659              (hidden (if (numberp arg)
8660                          (>= arg 0)
8661                        (gnus-article-hidden-text-p 'headers)))
8662              s e)
8663         (delete-region (point-min) (point-max))
8664         (with-current-buffer gnus-original-article-buffer
8665           (goto-char (setq s (point-min)))
8666           (setq e (if (search-forward "\n\n" nil t)
8667                       (1- (point))
8668                     (point-max))))
8669         (insert-buffer-substring gnus-original-article-buffer s e)
8670         (article-decode-encoded-words)
8671         (if hidden
8672             (let ((gnus-treat-hide-headers nil)
8673                   (gnus-treat-hide-boring-headers nil))
8674               (gnus-delete-wash-type 'headers)
8675               (gnus-treat-article 'head))
8676           (gnus-treat-article 'head))
8677         (widen)
8678         (if window
8679             (set-window-start window (goto-char (point-min))))
8680         (setq gnus-page-broken
8681               (when gnus-break-pages
8682                 (gnus-narrow-to-page)
8683                 t))
8684         (gnus-set-mode-line 'article)))))
8685
8686 (defun gnus-summary-show-all-headers ()
8687   "Make all header lines visible."
8688   (interactive)
8689   (gnus-summary-toggle-header 1))
8690
8691 (defun gnus-summary-toggle-mime (&optional arg)
8692   "Toggle MIME processing.
8693 If ARG is a positive number, turn MIME processing on."
8694   (interactive "P")
8695   (setq gnus-show-mime
8696         (if (null arg)
8697             (not gnus-show-mime)
8698           (> (prefix-numeric-value arg) 0)))
8699   (gnus-summary-select-article t 'force))
8700
8701 (defun gnus-summary-caesar-message (&optional arg)
8702   "Caesar rotate the current article by 13.
8703 The numerical prefix specifies how many places to rotate each letter
8704 forward."
8705   (interactive "P")
8706   (gnus-summary-select-article)
8707   (let ((mail-header-separator ""))
8708     (gnus-eval-in-buffer-window gnus-article-buffer
8709       (save-restriction
8710         (widen)
8711         (let ((start (window-start))
8712               buffer-read-only)
8713           (message-caesar-buffer-body arg)
8714           (set-window-start (get-buffer-window (current-buffer)) start))))))
8715
8716 (autoload 'unmorse-region "morse"
8717   "Convert morse coded text in region to ordinary ASCII text."
8718   t)
8719
8720 (defun gnus-summary-morse-message (&optional arg)
8721   "Morse decode the current article."
8722   (interactive "P")
8723   (gnus-summary-select-article)
8724   (let ((mail-header-separator ""))
8725     (gnus-eval-in-buffer-window gnus-article-buffer
8726       (save-excursion
8727         (save-restriction
8728           (widen)
8729           (let ((pos (window-start))
8730                 buffer-read-only)
8731             (goto-char (point-min))
8732             (when (message-goto-body)
8733               (gnus-narrow-to-body))
8734             (goto-char (point-min))
8735             (while (re-search-forward "·" (point-max) t)
8736               (replace-match "."))
8737             (unmorse-region (point-min) (point-max))
8738             (widen)
8739             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8740
8741 (defun gnus-summary-stop-page-breaking ()
8742   "Stop page breaking in the current article."
8743   (interactive)
8744   (gnus-summary-select-article)
8745   (gnus-eval-in-buffer-window gnus-article-buffer
8746     (widen)
8747     (when (gnus-visual-p 'page-marker)
8748       (let ((buffer-read-only nil))
8749         (gnus-remove-text-with-property 'gnus-prev)
8750         (gnus-remove-text-with-property 'gnus-next))
8751       (setq gnus-page-broken nil))))
8752
8753 (defun gnus-summary-move-article (&optional n to-newsgroup
8754                                             select-method action)
8755   "Move the current article to a different newsgroup.
8756 If N is a positive number, move the N next articles.
8757 If N is a negative number, move the N previous articles.
8758 If N is nil and any articles have been marked with the process mark,
8759 move those articles instead.
8760 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8761 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8762 re-spool using this method.
8763
8764 When called interactively with TO-NEWSGROUP being nil, the value of
8765 the variable `gnus-move-split-methods' is used for finding a default
8766 for the target newsgroup.
8767
8768 For this function to work, both the current newsgroup and the
8769 newsgroup that you want to move to have to support the `request-move'
8770 and `request-accept' functions.
8771
8772 ACTION can be either `move' (the default), `crosspost' or `copy'."
8773   (interactive "P")
8774   (unless action
8775     (setq action 'move))
8776   ;; Check whether the source group supports the required functions.
8777   (cond ((and (eq action 'move)
8778               (not (gnus-check-backend-function
8779                     'request-move-article gnus-newsgroup-name)))
8780          (error "The current group does not support article moving"))
8781         ((and (eq action 'crosspost)
8782               (not (gnus-check-backend-function
8783                     'request-replace-article gnus-newsgroup-name)))
8784          (error "The current group does not support article editing")))
8785   (let ((articles (gnus-summary-work-articles n))
8786         (prefix (if (gnus-check-backend-function
8787                      'request-move-article gnus-newsgroup-name)
8788                     (gnus-group-real-prefix gnus-newsgroup-name)
8789                   ""))
8790         (names '((move "Move" "Moving")
8791                  (copy "Copy" "Copying")
8792                  (crosspost "Crosspost" "Crossposting")))
8793         (copy-buf (save-excursion
8794                     (nnheader-set-temp-buffer " *copy article*")))
8795         (default-marks gnus-article-mark-lists)
8796         (no-expire-marks (delete '(expirable . expire)
8797                                  (copy-sequence gnus-article-mark-lists)))
8798         art-group to-method new-xref article to-groups)
8799     (unless (assq action names)
8800       (error "Unknown action %s" action))
8801     ;; Read the newsgroup name.
8802     (when (and (not to-newsgroup)
8803                (not select-method))
8804       (if (and gnus-move-split-methods
8805                (not
8806                 (and (memq gnus-current-article articles)
8807                      (gnus-buffer-live-p gnus-original-article-buffer))))
8808           ;; When `gnus-move-split-methods' is non-nil, we have to
8809           ;; select an article to give `gnus-read-move-group-name' an
8810           ;; opportunity to suggest an appropriate default.  However,
8811           ;; we needn't render or mark the article.
8812           (let ((gnus-display-mime-function nil)
8813                 (gnus-article-prepare-hook nil)
8814                 (gnus-mark-article-hook nil))
8815             (gnus-summary-select-article nil nil nil (car articles))))
8816       (setq to-newsgroup
8817             (gnus-read-move-group-name
8818              (cadr (assq action names))
8819              (symbol-value (intern (format "gnus-current-%s-group" action)))
8820              articles prefix))
8821       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8822     (setq to-method (or select-method
8823                         (gnus-server-to-method
8824                          (gnus-group-method to-newsgroup))))
8825     ;; Check the method we are to move this article to...
8826     (unless (gnus-check-backend-function
8827              'request-accept-article (car to-method))
8828       (error "%s does not support article copying" (car to-method)))
8829     (unless (gnus-check-server to-method)
8830       (error "Can't open server %s" (car to-method)))
8831     (gnus-message 6 "%s to %s: %s..."
8832                   (caddr (assq action names))
8833                   (or (car select-method) to-newsgroup) articles)
8834     (while articles
8835       (setq article (pop articles))
8836       (setq
8837        art-group
8838        (cond
8839         ;; Move the article.
8840         ((eq action 'move)
8841          ;; Remove this article from future suppression.
8842          (gnus-dup-unsuppress-article article)
8843          (gnus-request-move-article
8844           article                       ; Article to move
8845           gnus-newsgroup-name           ; From newsgroup
8846           (nth 1 (gnus-find-method-for-group
8847                   gnus-newsgroup-name)) ; Server
8848           (list 'gnus-request-accept-article
8849                 to-newsgroup (list 'quote select-method)
8850                 (not articles) t)       ; Accept form
8851           (not articles)))              ; Only save nov last time
8852         ;; Copy the article.
8853         ((eq action 'copy)
8854          (save-excursion
8855            (set-buffer copy-buf)
8856            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8857              (gnus-request-accept-article
8858               to-newsgroup select-method (not articles) t))))
8859         ;; Crosspost the article.
8860         ((eq action 'crosspost)
8861          (let ((xref (message-tokenize-header
8862                       (mail-header-xref (gnus-summary-article-header article))
8863                       " ")))
8864            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8865                                   ":" (number-to-string article)))
8866            (unless xref
8867              (setq xref (list (system-name))))
8868            (setq new-xref
8869                  (concat
8870                   (mapconcat 'identity
8871                              (delete "Xref:" (delete new-xref xref))
8872                              " ")
8873                   " " new-xref))
8874            (save-excursion
8875              (set-buffer copy-buf)
8876              ;; First put the article in the destination group.
8877              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8878              (when (consp (setq art-group
8879                                 (gnus-request-accept-article
8880                                  to-newsgroup select-method (not articles))))
8881                (setq new-xref (concat new-xref " " (car art-group)
8882                                       ":"
8883                                       (number-to-string (cdr art-group))))
8884                ;; Now we have the new Xrefs header, so we insert
8885                ;; it and replace the new article.
8886                (nnheader-replace-header "Xref" new-xref)
8887                (gnus-request-replace-article
8888                 (cdr art-group) to-newsgroup (current-buffer))
8889                art-group))))))
8890       (cond
8891        ((not art-group)
8892         (gnus-message 1 "Couldn't %s article %s: %s"
8893                       (cadr (assq action names)) article
8894                       (nnheader-get-report (car to-method))))
8895        ((eq art-group 'junk)
8896         (when (eq action 'move)
8897           (gnus-summary-mark-article article gnus-canceled-mark)
8898           (gnus-message 4 "Deleted article %s" article)))
8899        (t
8900         (let* ((pto-group (gnus-group-prefixed-name
8901                            (car art-group) to-method))
8902                (entry
8903                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8904                (info (nth 2 entry))
8905                (to-group (gnus-info-group info))
8906                to-marks)
8907           ;; Update the group that has been moved to.
8908           (when (and info
8909                      (memq action '(move copy)))
8910             (unless (member to-group to-groups)
8911               (push to-group to-groups))
8912
8913             (unless (memq article gnus-newsgroup-unreads)
8914               (push 'read to-marks)
8915               (gnus-info-set-read
8916                info (gnus-add-to-range (gnus-info-read info)
8917                                        (list (cdr art-group)))))
8918
8919             ;; See whether the article is to be put in the cache.
8920             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8921                              default-marks
8922                            no-expire-marks))
8923                   (to-article (cdr art-group)))
8924
8925               ;; Enter the article into the cache in the new group,
8926               ;; if that is required.
8927               (when gnus-use-cache
8928                 (gnus-cache-possibly-enter-article
8929                  to-group to-article
8930                  (let ((header (copy-sequence
8931                                 (gnus-summary-article-header article))))
8932                    (mail-header-set-number header to-article)
8933                    header)
8934                  (memq article gnus-newsgroup-marked)
8935                  (memq article gnus-newsgroup-dormant)
8936                  (memq article gnus-newsgroup-unreads)))
8937
8938               (when gnus-preserve-marks
8939                 ;; Copy any marks over to the new group.
8940                 (when (and (equal to-group gnus-newsgroup-name)
8941                            (not (memq article gnus-newsgroup-unreads)))
8942                   ;; Mark this article as read in this group.
8943                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8944                   (setcdr (gnus-active to-group) to-article)
8945                   (setcdr gnus-newsgroup-active to-article))
8946
8947                 (while marks
8948                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8949                     (when (memq article (symbol-value
8950                                          (intern (format "gnus-newsgroup-%s"
8951                                                          (caar marks)))))
8952                       (push (cdar marks) to-marks)
8953                       ;; If the other group is the same as this group,
8954                       ;; then we have to add the mark to the list.
8955                       (when (equal to-group gnus-newsgroup-name)
8956                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8957                              (cons to-article
8958                                    (symbol-value
8959                                     (intern (format "gnus-newsgroup-%s"
8960                                                     (caar marks)))))))
8961                       ;; Copy the marks to other group.
8962                       (gnus-add-marked-articles
8963                        to-group (cdar marks) (list to-article) info)))
8964                   (setq marks (cdr marks)))
8965
8966                 (gnus-request-set-mark
8967                  to-group (list (list (list to-article) 'add to-marks))))
8968
8969               (gnus-dribble-enter
8970                (concat "(gnus-group-set-info '"
8971                        (gnus-prin1-to-string (gnus-get-info to-group))
8972                        ")"))))
8973
8974           ;; Update the Xref header in this article to point to
8975           ;; the new crossposted article we have just created.
8976           (when (eq action 'crosspost)
8977             (save-excursion
8978               (set-buffer copy-buf)
8979               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8980               (nnheader-replace-header "Xref" new-xref)
8981               (gnus-request-replace-article
8982                article gnus-newsgroup-name (current-buffer)))))
8983
8984         ;;;!!!Why is this necessary?
8985         (set-buffer gnus-summary-buffer)
8986
8987         (gnus-summary-goto-subject article)
8988         (when (eq action 'move)
8989           (gnus-summary-mark-article article gnus-canceled-mark))))
8990       (gnus-summary-remove-process-mark article))
8991     ;; Re-activate all groups that have been moved to.
8992     (save-excursion
8993       (set-buffer gnus-group-buffer)
8994       (let ((gnus-group-marked to-groups))
8995         (gnus-group-get-new-news-this-group nil t)))
8996
8997     (gnus-kill-buffer copy-buf)
8998     (gnus-summary-position-point)
8999     (gnus-set-mode-line 'summary)))
9000
9001 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9002   "Move the current article to a different newsgroup.
9003 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9004 When called interactively, if TO-NEWSGROUP is nil, use the value of
9005 the variable `gnus-move-split-methods' for finding a default target
9006 newsgroup.
9007 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9008 re-spool using this method."
9009   (interactive "P")
9010   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9011
9012 (defun gnus-summary-crosspost-article (&optional n)
9013   "Crosspost the current article to some other group."
9014   (interactive "P")
9015   (gnus-summary-move-article n nil nil 'crosspost))
9016
9017 (defcustom gnus-summary-respool-default-method nil
9018   "Default method type for respooling an article.
9019 If nil, use to the current newsgroup method."
9020   :type 'symbol
9021   :group 'gnus-summary-mail)
9022
9023 (defcustom gnus-summary-display-while-building nil
9024   "If not-nil, show and update the summary buffer as it's being built.
9025 If the value is t, update the buffer after every line is inserted.  If
9026 the value is an integer (N), update the display every N lines."
9027   :group 'gnus-thread
9028   :type '(choice (const :tag "off" nil)
9029                  number
9030                  (const :tag "frequently" t)))
9031
9032 (defun gnus-summary-respool-article (&optional n method)
9033   "Respool the current article.
9034 The article will be squeezed through the mail spooling process again,
9035 which means that it will be put in some mail newsgroup or other
9036 depending on `nnmail-split-methods'.
9037 If N is a positive number, respool the N next articles.
9038 If N is a negative number, respool the N previous articles.
9039 If N is nil and any articles have been marked with the process mark,
9040 respool those articles instead.
9041
9042 Respooling can be done both from mail groups and \"real\" newsgroups.
9043 In the former case, the articles in question will be moved from the
9044 current group into whatever groups they are destined to.  In the
9045 latter case, they will be copied into the relevant groups."
9046   (interactive
9047    (list current-prefix-arg
9048          (let* ((methods (gnus-methods-using 'respool))
9049                 (methname
9050                  (symbol-name (or gnus-summary-respool-default-method
9051                                   (car (gnus-find-method-for-group
9052                                         gnus-newsgroup-name)))))
9053                 (method
9054                  (gnus-completing-read-with-default
9055                   methname "What backend do you want to use when respooling?"
9056                   methods nil t nil 'gnus-mail-method-history))
9057                 ms)
9058            (cond
9059             ((zerop (length (setq ms (gnus-servers-using-backend
9060                                       (intern method)))))
9061              (list (intern method) ""))
9062             ((= 1 (length ms))
9063              (car ms))
9064             (t
9065              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9066                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9067                            ms-alist))))))))
9068   (unless method
9069     (error "No method given for respooling"))
9070   (if (assoc (symbol-name
9071               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9072              (gnus-methods-using 'respool))
9073       (gnus-summary-move-article n nil method)
9074     (gnus-summary-copy-article n nil method)))
9075
9076 (defun gnus-summary-import-article (file &optional edit)
9077   "Import an arbitrary file into a mail newsgroup."
9078   (interactive "fImport file: \nP")
9079   (let ((group gnus-newsgroup-name)
9080         (now (current-time))
9081         atts lines group-art)
9082     (unless (gnus-check-backend-function 'request-accept-article group)
9083       (error "%s does not support article importing" group))
9084     (or (file-readable-p file)
9085         (not (file-regular-p file))
9086         (error "Can't read %s" file))
9087     (save-excursion
9088       (set-buffer (gnus-get-buffer-create " *import file*"))
9089       (erase-buffer)
9090       (nnheader-insert-file-contents file)
9091       (goto-char (point-min))
9092       (if (nnheader-article-p)
9093           (save-restriction
9094             (goto-char (point-min))
9095             (search-forward "\n\n" nil t)
9096             (narrow-to-region (point-min) (1- (point)))
9097             (goto-char (point-min))
9098             (unless (re-search-forward "^date:" nil t)
9099               (goto-char (point-max))
9100               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9101         ;; This doesn't look like an article, so we fudge some headers.
9102         (setq atts (file-attributes file)
9103               lines (count-lines (point-min) (point-max)))
9104         (insert "From: " (read-string "From: ") "\n"
9105                 "Subject: " (read-string "Subject: ") "\n"
9106                 "Date: " (message-make-date (nth 5 atts)) "\n"
9107                 "Message-ID: " (message-make-message-id) "\n"
9108                 "Lines: " (int-to-string lines) "\n"
9109                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9110       (setq group-art (gnus-request-accept-article group nil t))
9111       (kill-buffer (current-buffer)))
9112     (setq gnus-newsgroup-active (gnus-activate-group group))
9113     (forward-line 1)
9114     (gnus-summary-goto-article (cdr group-art) nil t)
9115     (when edit
9116       (gnus-summary-edit-article))))
9117
9118 (defun gnus-summary-create-article ()
9119   "Create an article in a mail newsgroup."
9120   (interactive)
9121   (let ((group gnus-newsgroup-name)
9122         (now (current-time))
9123         group-art)
9124     (unless (gnus-check-backend-function 'request-accept-article group)
9125       (error "%s does not support article importing" group))
9126     (save-excursion
9127       (set-buffer (gnus-get-buffer-create " *import file*"))
9128       (erase-buffer)
9129       (goto-char (point-min))
9130       ;; This doesn't look like an article, so we fudge some headers.
9131       (insert "From: " (read-string "From: ") "\n"
9132               "Subject: " (read-string "Subject: ") "\n"
9133               "Date: " (message-make-date now) "\n"
9134               "Message-ID: " (message-make-message-id) "\n")
9135       (setq group-art (gnus-request-accept-article group nil t))
9136       (kill-buffer (current-buffer)))
9137     (setq gnus-newsgroup-active (gnus-activate-group group))
9138     (forward-line 1)
9139     (gnus-summary-goto-article (cdr group-art) nil t)
9140     (gnus-summary-edit-article)))
9141
9142 (defun gnus-summary-article-posted-p ()
9143   "Say whether the current (mail) article is available from news as well.
9144 This will be the case if the article has both been mailed and posted."
9145   (interactive)
9146   (let ((id (mail-header-references (gnus-summary-article-header)))
9147         (gnus-override-method (car (gnus-refer-article-methods))))
9148     (if (gnus-request-head id "")
9149         (gnus-message 2 "The current message was found on %s"
9150                       gnus-override-method)
9151       (gnus-message 2 "The current message couldn't be found on %s"
9152                     gnus-override-method)
9153       nil)))
9154
9155 (defun gnus-summary-expire-articles (&optional now)
9156   "Expire all articles that are marked as expirable in the current group."
9157   (interactive)
9158   (when (gnus-check-backend-function
9159          'request-expire-articles gnus-newsgroup-name)
9160     ;; This backend supports expiry.
9161     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9162            (expirable (if total
9163                           (progn
9164                             ;; We need to update the info for
9165                             ;; this group for `gnus-list-of-read-articles'
9166                             ;; to give us the right answer.
9167                             (gnus-run-hooks 'gnus-exit-group-hook)
9168                             (gnus-summary-update-info)
9169                             (gnus-list-of-read-articles gnus-newsgroup-name))
9170                         (setq gnus-newsgroup-expirable
9171                               (sort gnus-newsgroup-expirable '<))))
9172            (expiry-wait (if now 'immediate
9173                           (gnus-group-find-parameter
9174                            gnus-newsgroup-name 'expiry-wait)))
9175            (nnmail-expiry-target
9176             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9177                 nnmail-expiry-target))
9178            es)
9179       (when expirable
9180         ;; There are expirable articles in this group, so we run them
9181         ;; through the expiry process.
9182         (gnus-message 6 "Expiring articles...")
9183         (unless (gnus-check-group gnus-newsgroup-name)
9184           (error "Can't open server for %s" gnus-newsgroup-name))
9185         ;; The list of articles that weren't expired is returned.
9186         (save-excursion
9187           (if expiry-wait
9188               (let ((nnmail-expiry-wait-function nil)
9189                     (nnmail-expiry-wait expiry-wait))
9190                 (setq es (gnus-request-expire-articles
9191                           expirable gnus-newsgroup-name)))
9192             (setq es (gnus-request-expire-articles
9193                       expirable gnus-newsgroup-name)))
9194           (unless total
9195             (setq gnus-newsgroup-expirable es))
9196           ;; We go through the old list of expirable, and mark all
9197           ;; really expired articles as nonexistent.
9198           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9199             (let ((gnus-use-cache nil))
9200               (dolist (article expirable)
9201                 (when (and (not (memq article es))
9202                            (gnus-data-find article))
9203                   (gnus-summary-mark-article article gnus-canceled-mark))))))
9204         (gnus-message 6 "Expiring articles...done")))))
9205
9206 (defun gnus-summary-expire-articles-now ()
9207   "Expunge all expirable articles in the current group.
9208 This means that *all* articles that are marked as expirable will be
9209 deleted forever, right now."
9210   (interactive)
9211   (or gnus-expert-user
9212       (gnus-yes-or-no-p
9213        "Are you really, really, really sure you want to delete all these messages? ")
9214       (error "Phew!"))
9215   (gnus-summary-expire-articles t))
9216
9217 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9218 (defun gnus-summary-delete-article (&optional n)
9219   "Delete the N next (mail) articles.
9220 This command actually deletes articles.  This is not a marking
9221 command.  The article will disappear forever from your life, never to
9222 return.
9223 If N is negative, delete backwards.
9224 If N is nil and articles have been marked with the process mark,
9225 delete these instead."
9226   (interactive "P")
9227   (unless (gnus-check-backend-function 'request-expire-articles
9228                                        gnus-newsgroup-name)
9229     (error "The current newsgroup does not support article deletion"))
9230   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9231     (error "Couldn't open server"))
9232   ;; Compute the list of articles to delete.
9233   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9234         (nnmail-expiry-target 'delete)
9235         not-deleted)
9236     (if (and gnus-novice-user
9237              (not (gnus-yes-or-no-p
9238                    (format "Do you really want to delete %s forever? "
9239                            (if (> (length articles) 1)
9240                                (format "these %s articles" (length articles))
9241                              "this article")))))
9242         ()
9243       ;; Delete the articles.
9244       (setq not-deleted (gnus-request-expire-articles
9245                          articles gnus-newsgroup-name 'force))
9246       (while articles
9247         (gnus-summary-remove-process-mark (car articles))
9248         ;; The backend might not have been able to delete the article
9249         ;; after all.
9250         (unless (memq (car articles) not-deleted)
9251           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9252         (setq articles (cdr articles)))
9253       (when not-deleted
9254         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9255     (gnus-summary-position-point)
9256     (gnus-set-mode-line 'summary)
9257     not-deleted))
9258
9259 (defun gnus-summary-edit-article (&optional force)
9260   "Edit the current article.
9261 This will have permanent effect only in mail groups.
9262 If FORCE is non-nil, allow editing of articles even in read-only
9263 groups."
9264   (interactive "P")
9265   (save-excursion
9266     (set-buffer gnus-summary-buffer)
9267     (let ((mail-parse-charset gnus-newsgroup-charset)
9268           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9269       (gnus-set-global-variables)
9270       (when (and (not force)
9271                  (gnus-group-read-only-p))
9272         (error "The current newsgroup does not support article editing"))
9273       (gnus-summary-show-article t)
9274       (gnus-article-edit-article
9275        'ignore
9276        `(lambda (no-highlight)
9277           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9278                 (message-options message-options)
9279                 (message-options-set-recipient)
9280                 (mail-parse-ignored-charsets
9281                  ',gnus-newsgroup-ignored-charsets))
9282             (gnus-summary-edit-article-done
9283              ,(or (mail-header-references gnus-current-headers) "")
9284              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9285
9286 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9287
9288 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9289                                                  no-highlight)
9290   "Make edits to the current article permanent."
9291   (interactive)
9292   (save-excursion
9293     ;; The buffer restriction contains the entire article if it exists.
9294     (when (article-goto-body)
9295       (let ((lines (count-lines (point) (point-max)))
9296             (length (- (point-max) (point)))
9297             (case-fold-search t)
9298             (body (copy-marker (point))))
9299         (goto-char (point-min))
9300         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9301           (delete-region (match-beginning 1) (match-end 1))
9302           (insert (number-to-string length)))
9303         (goto-char (point-min))
9304         (when (re-search-forward
9305                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9306           (delete-region (match-beginning 1) (match-end 1))
9307           (insert (number-to-string length)))
9308         (goto-char (point-min))
9309         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9310           (delete-region (match-beginning 1) (match-end 1))
9311           (insert (number-to-string lines))))))
9312   ;; Replace the article.
9313   (let ((buf (current-buffer)))
9314     (with-temp-buffer
9315       (insert-buffer-substring buf)
9316
9317       (if (and (not read-only)
9318                (not (gnus-request-replace-article
9319                      (cdr gnus-article-current) (car gnus-article-current)
9320                      (current-buffer) t)))
9321           (error "Couldn't replace article")
9322         ;; Update the summary buffer.
9323         (if (and references
9324                  (equal (message-tokenize-header references " ")
9325                         (message-tokenize-header
9326                          (or (message-fetch-field "references") "") " ")))
9327             ;; We only have to update this line.
9328             (save-excursion
9329               (save-restriction
9330                 (message-narrow-to-head)
9331                 (let ((head (buffer-string))
9332                       header)
9333                   (with-temp-buffer
9334                     (insert (format "211 %d Article retrieved.\n"
9335                                     (cdr gnus-article-current)))
9336                     (insert head)
9337                     (insert ".\n")
9338                     (let ((nntp-server-buffer (current-buffer)))
9339                       (setq header (car (gnus-get-newsgroup-headers
9340                                          nil t))))
9341                     (save-excursion
9342                       (set-buffer gnus-summary-buffer)
9343                       (gnus-data-set-header
9344                        (gnus-data-find (cdr gnus-article-current))
9345                        header)
9346                       (gnus-summary-update-article-line
9347                        (cdr gnus-article-current) header)
9348                       (if (gnus-summary-goto-subject
9349                            (cdr gnus-article-current) nil t)
9350                           (gnus-summary-update-secondary-mark
9351                            (cdr gnus-article-current))))))))
9352           ;; Update threads.
9353           (set-buffer (or buffer gnus-summary-buffer))
9354           (gnus-summary-update-article (cdr gnus-article-current))
9355           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9356               (gnus-summary-update-secondary-mark
9357                (cdr gnus-article-current))))
9358         ;; Prettify the article buffer again.
9359         (unless no-highlight
9360           (save-excursion
9361             (set-buffer gnus-article-buffer)
9362             ;;;!!! Fix this -- article should be rehighlighted.
9363             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9364             (set-buffer gnus-original-article-buffer)
9365             (gnus-request-article
9366              (cdr gnus-article-current)
9367              (car gnus-article-current) (current-buffer))))
9368         ;; Prettify the summary buffer line.
9369         (when (gnus-visual-p 'summary-highlight 'highlight)
9370           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9371
9372 (defun gnus-summary-edit-wash (key)
9373   "Perform editing command KEY in the article buffer."
9374   (interactive
9375    (list
9376     (progn
9377       (message "%s" (concat (this-command-keys) "- "))
9378       (read-char))))
9379   (message "")
9380   (gnus-summary-edit-article)
9381   (execute-kbd-macro (concat (this-command-keys) key))
9382   (gnus-article-edit-done))
9383
9384 ;;; Respooling
9385
9386 (defun gnus-summary-respool-query (&optional silent trace)
9387   "Query where the respool algorithm would put this article."
9388   (interactive)
9389   (let (gnus-mark-article-hook)
9390     (gnus-summary-select-article)
9391     (save-excursion
9392       (set-buffer gnus-original-article-buffer)
9393       (save-restriction
9394         (message-narrow-to-head)
9395         (let ((groups (nnmail-article-group 'identity trace)))
9396           (unless silent
9397             (if groups
9398                 (message "This message would go to %s"
9399                          (mapconcat 'car groups ", "))
9400               (message "This message would go to no groups"))
9401             groups))))))
9402
9403 (defun gnus-summary-respool-trace ()
9404   "Trace where the respool algorithm would put this article.
9405 Display a buffer showing all fancy splitting patterns which matched."
9406   (interactive)
9407   (gnus-summary-respool-query nil t))
9408
9409 ;; Summary marking commands.
9410
9411 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9412   "Mark articles which has the same subject as read, and then select the next.
9413 If UNMARK is positive, remove any kind of mark.
9414 If UNMARK is negative, tick articles."
9415   (interactive "P")
9416   (when unmark
9417     (setq unmark (prefix-numeric-value unmark)))
9418   (let ((count
9419          (gnus-summary-mark-same-subject
9420           (gnus-summary-article-subject) unmark)))
9421     ;; Select next unread article.  If auto-select-same mode, should
9422     ;; select the first unread article.
9423     (gnus-summary-next-article t (and gnus-auto-select-same
9424                                       (gnus-summary-article-subject)))
9425     (gnus-message 7 "%d article%s marked as %s"
9426                   count (if (= count 1) " is" "s are")
9427                   (if unmark "unread" "read"))))
9428
9429 (defun gnus-summary-kill-same-subject (&optional unmark)
9430   "Mark articles which has the same subject as read.
9431 If UNMARK is positive, remove any kind of mark.
9432 If UNMARK is negative, tick articles."
9433   (interactive "P")
9434   (when unmark
9435     (setq unmark (prefix-numeric-value unmark)))
9436   (let ((count
9437          (gnus-summary-mark-same-subject
9438           (gnus-summary-article-subject) unmark)))
9439     ;; If marked as read, go to next unread subject.
9440     (when (null unmark)
9441       ;; Go to next unread subject.
9442       (gnus-summary-next-subject 1 t))
9443     (gnus-message 7 "%d articles are marked as %s"
9444                   count (if unmark "unread" "read"))))
9445
9446 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9447   "Mark articles with same SUBJECT as read, and return marked number.
9448 If optional argument UNMARK is positive, remove any kinds of marks.
9449 If optional argument UNMARK is negative, mark articles as unread instead."
9450   (let ((count 1))
9451     (save-excursion
9452       (cond
9453        ((null unmark)                   ; Mark as read.
9454         (while (and
9455                 (progn
9456                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9457                   (gnus-summary-show-thread) t)
9458                 (gnus-summary-find-subject subject))
9459           (setq count (1+ count))))
9460        ((> unmark 0)                    ; Tick.
9461         (while (and
9462                 (progn
9463                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9464                   (gnus-summary-show-thread) t)
9465                 (gnus-summary-find-subject subject))
9466           (setq count (1+ count))))
9467        (t                               ; Mark as unread.
9468         (while (and
9469                 (progn
9470                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9471                   (gnus-summary-show-thread) t)
9472                 (gnus-summary-find-subject subject))
9473           (setq count (1+ count)))))
9474       (gnus-set-mode-line 'summary)
9475       ;; Return the number of marked articles.
9476       count)))
9477
9478 (defun gnus-summary-mark-as-processable (n &optional unmark)
9479   "Set the process mark on the next N articles.
9480 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9481 the process mark instead.  The difference between N and the actual
9482 number of articles marked is returned."
9483   (interactive "P")
9484   (if (and (null n) (gnus-region-active-p))
9485       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9486     (setq n (prefix-numeric-value n))
9487     (let ((backward (< n 0))
9488           (n (abs n)))
9489       (while (and
9490               (> n 0)
9491               (if unmark
9492                   (gnus-summary-remove-process-mark
9493                    (gnus-summary-article-number))
9494                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9495               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9496         (setq n (1- n)))
9497       (when (/= 0 n)
9498         (gnus-message 7 "No more articles"))
9499       (gnus-summary-recenter)
9500       (gnus-summary-position-point)
9501       n)))
9502
9503 (defun gnus-summary-unmark-as-processable (n)
9504   "Remove the process mark from the next N articles.
9505 If N is negative, unmark backward instead.  The difference between N and
9506 the actual number of articles unmarked is returned."
9507   (interactive "P")
9508   (gnus-summary-mark-as-processable n t))
9509
9510 (defun gnus-summary-unmark-all-processable ()
9511   "Remove the process mark from all articles."
9512   (interactive)
9513   (save-excursion
9514     (while gnus-newsgroup-processable
9515       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9516   (gnus-summary-position-point))
9517
9518 (defun gnus-summary-add-mark (article type)
9519   "Mark ARTICLE with a mark of TYPE."
9520   (let ((vtype (car (assq type gnus-article-mark-lists)))
9521         var)
9522     (if (not vtype)
9523         (error "No such mark type: %s" type)
9524       (setq var (intern (format "gnus-newsgroup-%s" type)))
9525       (set var (cons article (symbol-value var)))
9526       (if (memq type '(processable cached replied forwarded recent saved))
9527           (gnus-summary-update-secondary-mark article)
9528         ;;; !!! This is bogus.  We should find out what primary
9529         ;;; !!! mark we want to set.
9530         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9531
9532 (defun gnus-summary-mark-as-expirable (n)
9533   "Mark N articles forward as expirable.
9534 If N is negative, mark backward instead.  The difference between N and
9535 the actual number of articles marked is returned."
9536   (interactive "p")
9537   (gnus-summary-mark-forward n gnus-expirable-mark))
9538
9539 (defun gnus-summary-mark-as-spam (n)
9540   "Mark N articles forward as spam.
9541 If N is negative, mark backward instead.  The difference between N and
9542 the actual number of articles marked is returned."
9543   (interactive "p")
9544   (gnus-summary-mark-forward n gnus-spam-mark))
9545
9546 (defun gnus-summary-mark-article-as-replied (article)
9547   "Mark ARTICLE as replied to and update the summary line.
9548 ARTICLE can also be a list of articles."
9549   (interactive (list (gnus-summary-article-number)))
9550   (let ((articles (if (listp article) article (list article))))
9551     (dolist (article articles)
9552       (unless (numberp article)
9553         (error "%s is not a number" article))
9554       (push article gnus-newsgroup-replied)
9555       (let ((buffer-read-only nil))
9556         (when (gnus-summary-goto-subject article nil t)
9557           (gnus-summary-update-secondary-mark article))))))
9558
9559 (defun gnus-summary-mark-article-as-forwarded (article)
9560   "Mark ARTICLE as forwarded and update the summary line.
9561 ARTICLE can also be a list of articles."
9562   (let ((articles (if (listp article) article (list article))))
9563     (dolist (article articles)
9564       (push article gnus-newsgroup-forwarded)
9565       (let ((buffer-read-only nil))
9566         (when (gnus-summary-goto-subject article nil t)
9567           (gnus-summary-update-secondary-mark article))))))
9568
9569 (defun gnus-summary-set-bookmark (article)
9570   "Set a bookmark in current article."
9571   (interactive (list (gnus-summary-article-number)))
9572   (when (or (not (get-buffer gnus-article-buffer))
9573             (not gnus-current-article)
9574             (not gnus-article-current)
9575             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9576     (error "No current article selected"))
9577   ;; Remove old bookmark, if one exists.
9578   (gnus-pull article gnus-newsgroup-bookmarks)
9579   ;; Set the new bookmark, which is on the form
9580   ;; (article-number . line-number-in-body).
9581   (push
9582    (cons article
9583          (save-excursion
9584            (set-buffer gnus-article-buffer)
9585            (count-lines
9586             (min (point)
9587                  (save-excursion
9588                    (article-goto-body)
9589                    (point)))
9590             (point))))
9591    gnus-newsgroup-bookmarks)
9592   (gnus-message 6 "A bookmark has been added to the current article."))
9593
9594 (defun gnus-summary-remove-bookmark (article)
9595   "Remove the bookmark from the current article."
9596   (interactive (list (gnus-summary-article-number)))
9597   ;; Remove old bookmark, if one exists.
9598   (if (not (assq article gnus-newsgroup-bookmarks))
9599       (gnus-message 6 "No bookmark in current article.")
9600     (gnus-pull article gnus-newsgroup-bookmarks)
9601     (gnus-message 6 "Removed bookmark.")))
9602
9603 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9604 (defun gnus-summary-mark-as-dormant (n)
9605   "Mark N articles forward as dormant.
9606 If N is negative, mark backward instead.  The difference between N and
9607 the actual number of articles marked is returned."
9608   (interactive "p")
9609   (gnus-summary-mark-forward n gnus-dormant-mark))
9610
9611 (defun gnus-summary-set-process-mark (article)
9612   "Set the process mark on ARTICLE and update the summary line."
9613   (setq gnus-newsgroup-processable
9614         (cons article
9615               (delq article gnus-newsgroup-processable)))
9616   (when (gnus-summary-goto-subject article)
9617     (gnus-summary-show-thread)
9618     (gnus-summary-goto-subject article)
9619     (gnus-summary-update-secondary-mark article)))
9620
9621 (defun gnus-summary-remove-process-mark (article)
9622   "Remove the process mark from ARTICLE and update the summary line."
9623   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9624   (when (gnus-summary-goto-subject article)
9625     (gnus-summary-show-thread)
9626     (gnus-summary-goto-subject article)
9627     (gnus-summary-update-secondary-mark article)))
9628
9629 (defun gnus-summary-set-saved-mark (article)
9630   "Set the process mark on ARTICLE and update the summary line."
9631   (push article gnus-newsgroup-saved)
9632   (when (gnus-summary-goto-subject article)
9633     (gnus-summary-update-secondary-mark article)))
9634
9635 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9636   "Mark N articles as read forwards.
9637 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9638 The difference between N and the actual number of articles marked is
9639 returned.
9640 If NO-EXPIRE, auto-expiry will be inhibited."
9641   (interactive "p")
9642   (gnus-summary-show-thread)
9643   (let ((backward (< n 0))
9644         (gnus-summary-goto-unread
9645          (and gnus-summary-goto-unread
9646               (not (eq gnus-summary-goto-unread 'never))
9647               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9648                                     gnus-ticked-mark gnus-dormant-mark)))))
9649         (n (abs n))
9650         (mark (or mark gnus-del-mark)))
9651     (while (and (> n 0)
9652                 (gnus-summary-mark-article nil mark no-expire)
9653                 (zerop (gnus-summary-next-subject
9654                         (if backward -1 1)
9655                         (and gnus-summary-goto-unread
9656                              (not (eq gnus-summary-goto-unread 'never)))
9657                         t)))
9658       (setq n (1- n)))
9659     (when (/= 0 n)
9660       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9661     (gnus-summary-recenter)
9662     (gnus-summary-position-point)
9663     (gnus-set-mode-line 'summary)
9664     n))
9665
9666 (defun gnus-summary-mark-article-as-read (mark)
9667   "Mark the current article quickly as read with MARK."
9668   (let ((article (gnus-summary-article-number)))
9669     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9670     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9671     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9672     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9673     (push (cons article mark) gnus-newsgroup-reads)
9674     ;; Possibly remove from cache, if that is used.
9675     (when gnus-use-cache
9676       (gnus-cache-enter-remove-article article))
9677     ;; Allow the backend to change the mark.
9678     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9679     ;; Check for auto-expiry.
9680     (when (and gnus-newsgroup-auto-expire
9681                (memq mark gnus-auto-expirable-marks))
9682       (setq mark gnus-expirable-mark)
9683       ;; Let the backend know about the mark change.
9684       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9685       (push article gnus-newsgroup-expirable))
9686     ;; Set the mark in the buffer.
9687     (gnus-summary-update-mark mark 'unread)
9688     t))
9689
9690 (defun gnus-summary-mark-article-as-unread (mark)
9691   "Mark the current article quickly as unread with MARK."
9692   (let* ((article (gnus-summary-article-number))
9693          (old-mark (gnus-summary-article-mark article)))
9694     ;; Allow the backend to change the mark.
9695     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9696     (if (eq mark old-mark)
9697         t
9698       (if (<= article 0)
9699           (progn
9700             (gnus-error 1 "Can't mark negative article numbers")
9701             nil)
9702         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9703         (setq gnus-newsgroup-spam-marked
9704               (delq article gnus-newsgroup-spam-marked))
9705         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9706         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9707         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9708         (cond ((= mark gnus-ticked-mark)
9709                (setq gnus-newsgroup-marked
9710                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9711                                               article)))
9712               ((= mark gnus-spam-mark)
9713                (setq gnus-newsgroup-spam-marked
9714                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9715                                               article)))
9716               ((= mark gnus-dormant-mark)
9717                (setq gnus-newsgroup-dormant
9718                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9719                                               article)))
9720               (t
9721                (setq gnus-newsgroup-unreads
9722                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9723                                               article))))
9724         (gnus-pull article gnus-newsgroup-reads)
9725
9726         ;; See whether the article is to be put in the cache.
9727         (and gnus-use-cache
9728              (vectorp (gnus-summary-article-header article))
9729              (save-excursion
9730                (gnus-cache-possibly-enter-article
9731                 gnus-newsgroup-name article
9732                 (gnus-summary-article-header article)
9733                 (= mark gnus-ticked-mark)
9734                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9735
9736         ;; Fix the mark.
9737         (gnus-summary-update-mark mark 'unread)
9738         t))))
9739
9740 (defun gnus-summary-mark-article (&optional article mark no-expire)
9741   "Mark ARTICLE with MARK.  MARK can be any character.
9742 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9743 `??' (dormant) and `?E' (expirable).
9744 If MARK is nil, then the default character `?r' is used.
9745 If ARTICLE is nil, then the article on the current line will be
9746 marked.
9747 If NO-EXPIRE, auto-expiry will be inhibited."
9748   ;; The mark might be a string.
9749   (when (stringp mark)
9750     (setq mark (aref mark 0)))
9751   ;; If no mark is given, then we check auto-expiring.
9752   (when (null mark)
9753     (setq mark gnus-del-mark))
9754   (when (and (not no-expire)
9755              gnus-newsgroup-auto-expire
9756              (memq mark gnus-auto-expirable-marks))
9757     (setq mark gnus-expirable-mark))
9758   (let ((article (or article (gnus-summary-article-number)))
9759         (old-mark (gnus-summary-article-mark article)))
9760     ;; Allow the backend to change the mark.
9761     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9762     (if (eq mark old-mark)
9763         t
9764       (unless article
9765         (error "No article on current line"))
9766       (if (not (if (or (= mark gnus-unread-mark)
9767                        (= mark gnus-ticked-mark)
9768                        (= mark gnus-spam-mark)
9769                        (= mark gnus-dormant-mark))
9770                    (gnus-mark-article-as-unread article mark)
9771                  (gnus-mark-article-as-read article mark)))
9772           t
9773         ;; See whether the article is to be put in the cache.
9774         (and gnus-use-cache
9775              (not (= mark gnus-canceled-mark))
9776              (vectorp (gnus-summary-article-header article))
9777              (save-excursion
9778                (gnus-cache-possibly-enter-article
9779                 gnus-newsgroup-name article
9780                 (gnus-summary-article-header article)
9781                 (= mark gnus-ticked-mark)
9782                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9783
9784         (when (gnus-summary-goto-subject article nil t)
9785           (let ((buffer-read-only nil))
9786             (gnus-summary-show-thread)
9787             ;; Fix the mark.
9788             (gnus-summary-update-mark mark 'unread)
9789             t))))))
9790
9791 (defun gnus-summary-update-secondary-mark (article)
9792   "Update the secondary (read, process, cache) mark."
9793   (gnus-summary-update-mark
9794    (cond ((memq article gnus-newsgroup-processable)
9795           gnus-process-mark)
9796          ((memq article gnus-newsgroup-cached)
9797           gnus-cached-mark)
9798          ((memq article gnus-newsgroup-replied)
9799           gnus-replied-mark)
9800          ((memq article gnus-newsgroup-forwarded)
9801           gnus-forwarded-mark)
9802          ((memq article gnus-newsgroup-saved)
9803           gnus-saved-mark)
9804          ((memq article gnus-newsgroup-recent)
9805           gnus-recent-mark)
9806          ((memq article gnus-newsgroup-unseen)
9807           gnus-unseen-mark)
9808          (t gnus-no-mark))
9809    'replied)
9810   (when (gnus-visual-p 'summary-highlight 'highlight)
9811     (gnus-run-hooks 'gnus-summary-update-hook))
9812   t)
9813
9814 (defun gnus-summary-update-download-mark (article)
9815   "Update the secondary (read, process, cache) mark."
9816   (gnus-summary-update-mark
9817    (cond ((memq article gnus-newsgroup-undownloaded) 
9818           gnus-undownloaded-mark)
9819          (gnus-newsgroup-agentized
9820           gnus-downloaded-mark)
9821          (t
9822           gnus-no-mark))
9823    'download)
9824   (gnus-summary-update-line t)
9825   t)
9826
9827 (defun gnus-summary-update-mark (mark type)
9828   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9829         (buffer-read-only nil))
9830     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9831     (when forward
9832       (when (looking-at "\r")
9833         (incf forward))
9834       (when (<= (+ forward (point)) (point-max))
9835         ;; Go to the right position on the line.
9836         (goto-char (+ forward (point)))
9837         ;; Replace the old mark with the new mark.
9838         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9839         ;; Optionally update the marks by some user rule.
9840         (when (eq type 'unread)
9841           (gnus-data-set-mark
9842            (gnus-data-find (gnus-summary-article-number)) mark)
9843           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9844
9845 (defun gnus-mark-article-as-read (article &optional mark)
9846   "Enter ARTICLE in the pertinent lists and remove it from others."
9847   ;; Make the article expirable.
9848   (let ((mark (or mark gnus-del-mark)))
9849     (setq gnus-newsgroup-expirable
9850           (if (= mark gnus-expirable-mark)
9851               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9852             (delq article gnus-newsgroup-expirable)))
9853     ;; Remove from unread and marked lists.
9854     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9855     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9856     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9857     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9858     (push (cons article mark) gnus-newsgroup-reads)
9859     ;; Possibly remove from cache, if that is used.
9860     (when gnus-use-cache
9861       (gnus-cache-enter-remove-article article))
9862     t))
9863
9864 (defun gnus-mark-article-as-unread (article &optional mark)
9865   "Enter ARTICLE in the pertinent lists and remove it from others."
9866   (let ((mark (or mark gnus-ticked-mark)))
9867     (if (<= article 0)
9868         (progn
9869           (gnus-error 1 "Can't mark negative article numbers")
9870           nil)
9871       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9872             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
9873             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9874             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9875             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9876
9877       ;; Unsuppress duplicates?
9878       (when gnus-suppress-duplicates
9879         (gnus-dup-unsuppress-article article))
9880
9881       (cond ((= mark gnus-ticked-mark)
9882              (setq gnus-newsgroup-marked
9883                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9884             ((= mark gnus-spam-mark)
9885              (setq gnus-newsgroup-spam-marked
9886                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9887                                             article)))
9888             ((= mark gnus-dormant-mark)
9889              (setq gnus-newsgroup-dormant
9890                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9891             (t
9892              (setq gnus-newsgroup-unreads
9893                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9894       (gnus-pull article gnus-newsgroup-reads)
9895       t)))
9896
9897 (defalias 'gnus-summary-mark-as-unread-forward
9898   'gnus-summary-tick-article-forward)
9899 (make-obsolete 'gnus-summary-mark-as-unread-forward
9900                'gnus-summary-tick-article-forward)
9901 (defun gnus-summary-tick-article-forward (n)
9902   "Tick N articles forwards.
9903 If N is negative, tick backwards instead.
9904 The difference between N and the number of articles ticked is returned."
9905   (interactive "p")
9906   (gnus-summary-mark-forward n gnus-ticked-mark))
9907
9908 (defalias 'gnus-summary-mark-as-unread-backward
9909   'gnus-summary-tick-article-backward)
9910 (make-obsolete 'gnus-summary-mark-as-unread-backward
9911                'gnus-summary-tick-article-backward)
9912 (defun gnus-summary-tick-article-backward (n)
9913   "Tick N articles backwards.
9914 The difference between N and the number of articles ticked is returned."
9915   (interactive "p")
9916   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9917
9918 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9919 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9920 (defun gnus-summary-tick-article (&optional article clear-mark)
9921   "Mark current article as unread.
9922 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9923 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9924   (interactive)
9925   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9926                                        gnus-ticked-mark)))
9927
9928 (defun gnus-summary-mark-as-read-forward (n)
9929   "Mark N articles as read forwards.
9930 If N is negative, mark backwards instead.
9931 The difference between N and the actual number of articles marked is
9932 returned."
9933   (interactive "p")
9934   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9935
9936 (defun gnus-summary-mark-as-read-backward (n)
9937   "Mark the N articles as read backwards.
9938 The difference between N and the actual number of articles marked is
9939 returned."
9940   (interactive "p")
9941   (gnus-summary-mark-forward
9942    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9943
9944 (defun gnus-summary-mark-as-read (&optional article mark)
9945   "Mark current article as read.
9946 ARTICLE specifies the article to be marked as read.
9947 MARK specifies a string to be inserted at the beginning of the line."
9948   (gnus-summary-mark-article article mark))
9949
9950 (defun gnus-summary-clear-mark-forward (n)
9951   "Clear marks from N articles forward.
9952 If N is negative, clear backward instead.
9953 The difference between N and the number of marks cleared is returned."
9954   (interactive "p")
9955   (gnus-summary-mark-forward n gnus-unread-mark))
9956
9957 (defun gnus-summary-clear-mark-backward (n)
9958   "Clear marks from N articles backward.
9959 The difference between N and the number of marks cleared is returned."
9960   (interactive "p")
9961   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9962
9963 (defun gnus-summary-mark-unread-as-read ()
9964   "Intended to be used by `gnus-summary-mark-article-hook'."
9965   (when (memq gnus-current-article gnus-newsgroup-unreads)
9966     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9967
9968 (defun gnus-summary-mark-read-and-unread-as-read ()
9969   "Intended to be used by `gnus-summary-mark-article-hook'."
9970   (let ((mark (gnus-summary-article-mark)))
9971     (when (or (gnus-unread-mark-p mark)
9972               (gnus-read-mark-p mark))
9973       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9974
9975 (defun gnus-summary-mark-unread-as-ticked ()
9976   "Intended to be used by `gnus-summary-mark-article-hook'."
9977   (when (memq gnus-current-article gnus-newsgroup-unreads)
9978     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9979
9980 (defun gnus-summary-mark-region-as-read (point mark all)
9981   "Mark all unread articles between point and mark as read.
9982 If given a prefix, mark all articles between point and mark as read,
9983 even ticked and dormant ones."
9984   (interactive "r\nP")
9985   (save-excursion
9986     (let (article)
9987       (goto-char point)
9988       (beginning-of-line)
9989       (while (and
9990               (< (point) mark)
9991               (progn
9992                 (when (or all
9993                           (memq (setq article (gnus-summary-article-number))
9994                                 gnus-newsgroup-unreads))
9995                   (gnus-summary-mark-article article gnus-del-mark))
9996                 t)
9997               (gnus-summary-find-next))))))
9998
9999 (defun gnus-summary-mark-below (score mark)
10000   "Mark articles with score less than SCORE with MARK."
10001   (interactive "P\ncMark: ")
10002   (setq score (if score
10003                   (prefix-numeric-value score)
10004                 (or gnus-summary-default-score 0)))
10005   (save-excursion
10006     (set-buffer gnus-summary-buffer)
10007     (goto-char (point-min))
10008     (while
10009         (progn
10010           (and (< (gnus-summary-article-score) score)
10011                (gnus-summary-mark-article nil mark))
10012           (gnus-summary-find-next)))))
10013
10014 (defun gnus-summary-kill-below (&optional score)
10015   "Mark articles with score below SCORE as read."
10016   (interactive "P")
10017   (gnus-summary-mark-below score gnus-killed-mark))
10018
10019 (defun gnus-summary-clear-above (&optional score)
10020   "Clear all marks from articles with score above SCORE."
10021   (interactive "P")
10022   (gnus-summary-mark-above score gnus-unread-mark))
10023
10024 (defun gnus-summary-tick-above (&optional score)
10025   "Tick all articles with score above SCORE."
10026   (interactive "P")
10027   (gnus-summary-mark-above score gnus-ticked-mark))
10028
10029 (defun gnus-summary-mark-above (score mark)
10030   "Mark articles with score over SCORE with MARK."
10031   (interactive "P\ncMark: ")
10032   (setq score (if score
10033                   (prefix-numeric-value score)
10034                 (or gnus-summary-default-score 0)))
10035   (save-excursion
10036     (set-buffer gnus-summary-buffer)
10037     (goto-char (point-min))
10038     (while (and (progn
10039                   (when (> (gnus-summary-article-score) score)
10040                     (gnus-summary-mark-article nil mark))
10041                   t)
10042                 (gnus-summary-find-next)))))
10043
10044 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10045 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10046 (defun gnus-summary-limit-include-expunged (&optional no-error)
10047   "Display all the hidden articles that were expunged for low scores."
10048   (interactive)
10049   (let ((buffer-read-only nil))
10050     (let ((scored gnus-newsgroup-scored)
10051           headers h)
10052       (while scored
10053         (unless (gnus-summary-article-header (caar scored))
10054           (and (setq h (gnus-number-to-header (caar scored)))
10055                (< (cdar scored) gnus-summary-expunge-below)
10056                (push h headers)))
10057         (setq scored (cdr scored)))
10058       (if (not headers)
10059           (when (not no-error)
10060             (error "No expunged articles hidden"))
10061         (goto-char (point-min))
10062         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10063         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10064         (mapcar (lambda (x) (push (mail-header-number x)
10065                                   gnus-newsgroup-limit))
10066                 headers)
10067         (gnus-summary-prepare-unthreaded (nreverse headers))
10068         (goto-char (point-min))
10069         (gnus-summary-position-point)
10070         t))))
10071
10072 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10073   "Mark all unread articles in this newsgroup as read.
10074 If prefix argument ALL is non-nil, ticked and dormant articles will
10075 also be marked as read.
10076 If QUIETLY is non-nil, no questions will be asked.
10077 If TO-HERE is non-nil, it should be a point in the buffer.  All
10078 articles before (after, if REVERSE is set) this point will be marked as read.
10079 Note that this function will only catch up the unread article
10080 in the current summary buffer limitation.
10081 The number of articles marked as read is returned."
10082   (interactive "P")
10083   (prog1
10084       (save-excursion
10085         (when (or quietly
10086                   (not gnus-interactive-catchup) ;Without confirmation?
10087                   gnus-expert-user
10088                   (gnus-y-or-n-p
10089                    (if all
10090                        "Mark absolutely all articles as read? "
10091                      "Mark all unread articles as read? ")))
10092           (if (and not-mark
10093                    (not gnus-newsgroup-adaptive)
10094                    (not gnus-newsgroup-auto-expire)
10095                    (not gnus-suppress-duplicates)
10096                    (or (not gnus-use-cache)
10097                        (eq gnus-use-cache 'passive)))
10098               (progn
10099                 (when all
10100                   (setq gnus-newsgroup-marked nil
10101                         gnus-newsgroup-spam-marked nil
10102                         gnus-newsgroup-dormant nil))
10103                 (setq gnus-newsgroup-unreads
10104                       (gnus-sorted-nunion
10105                        (gnus-intersection gnus-newsgroup-unreads
10106                                           gnus-newsgroup-downloadable)
10107                        gnus-newsgroup-unfetched)))
10108             ;; We actually mark all articles as canceled, which we
10109             ;; have to do when using auto-expiry or adaptive scoring.
10110             (gnus-summary-show-all-threads)
10111             (if (and to-here reverse)
10112                 (progn
10113                   (goto-char to-here)
10114                   (while (and
10115                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
10116                           (gnus-summary-find-next (not all)))))
10117               (when (gnus-summary-first-subject (not all))
10118                 (while (and
10119                         (if to-here (< (point) to-here) t)
10120                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10121                         (gnus-summary-find-next (not all))))))
10122             (gnus-set-mode-line 'summary))
10123           t))
10124     (gnus-summary-position-point)))
10125
10126 (defun gnus-summary-catchup-to-here (&optional all)
10127   "Mark all unticked articles before the current one as read.
10128 If ALL is non-nil, also mark ticked and dormant articles as read."
10129   (interactive "P")
10130   (save-excursion
10131     (gnus-save-hidden-threads
10132       (let ((beg (point)))
10133         ;; We check that there are unread articles.
10134         (when (or all (gnus-summary-find-prev))
10135           (gnus-summary-catchup all t beg)))))
10136   (gnus-summary-position-point))
10137
10138 (defun gnus-summary-catchup-from-here (&optional all)
10139   "Mark all unticked articles after the current one as read.
10140 If ALL is non-nil, also mark ticked and dormant articles as read."
10141   (interactive "P")
10142   (save-excursion
10143     (gnus-save-hidden-threads
10144       (let ((beg (point)))
10145         ;; We check that there are unread articles.
10146         (when (or all (gnus-summary-find-next))
10147           (gnus-summary-catchup all t beg nil t)))))
10148   (gnus-summary-position-point))
10149
10150 (defun gnus-summary-catchup-all (&optional quietly)
10151   "Mark all articles in this newsgroup as read.
10152 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10153 instead, which marks only unread articles as read."
10154   (interactive "P")
10155   (gnus-summary-catchup t quietly))
10156
10157 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10158   "Mark all unread articles in this group as read, then exit.
10159 If prefix argument ALL is non-nil, all articles are marked as read.
10160 If QUIETLY is non-nil, no questions will be asked."
10161   (interactive "P")
10162   (when (gnus-summary-catchup all quietly nil 'fast)
10163     ;; Select next newsgroup or exit.
10164     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10165              (eq gnus-auto-select-next 'quietly))
10166         (gnus-summary-next-group nil)
10167       (gnus-summary-exit))))
10168
10169 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10170   "Mark all articles in this newsgroup as read, and then exit.
10171 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10172 instead, which marks only unread articles as read."
10173   (interactive "P")
10174   (gnus-summary-catchup-and-exit t quietly))
10175
10176 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10177   "Mark all articles in this group as read and select the next group.
10178 If given a prefix, mark all articles, unread as well as ticked, as
10179 read."
10180   (interactive "P")
10181   (save-excursion
10182     (gnus-summary-catchup all))
10183   (gnus-summary-next-group))
10184
10185 ;;;
10186 ;;; with article
10187 ;;;
10188
10189 (defmacro gnus-with-article (article &rest forms)
10190   "Select ARTICLE and perform FORMS in the original article buffer.
10191 Then replace the article with the result."
10192   `(progn
10193      ;; We don't want the article to be marked as read.
10194      (let (gnus-mark-article-hook)
10195        (gnus-summary-select-article t t nil ,article))
10196      (set-buffer gnus-original-article-buffer)
10197      ,@forms
10198      (if (not (gnus-check-backend-function
10199                'request-replace-article (car gnus-article-current)))
10200          (gnus-message 5 "Read-only group; not replacing")
10201        (unless (gnus-request-replace-article
10202                 ,article (car gnus-article-current)
10203                 (current-buffer) t)
10204          (error "Couldn't replace article")))
10205      ;; The cache and backlog have to be flushed somewhat.
10206      (when gnus-keep-backlog
10207        (gnus-backlog-remove-article
10208         (car gnus-article-current) (cdr gnus-article-current)))
10209      (when gnus-use-cache
10210        (gnus-cache-update-article
10211         (car gnus-article-current) (cdr gnus-article-current)))))
10212
10213 (put 'gnus-with-article 'lisp-indent-function 1)
10214 (put 'gnus-with-article 'edebug-form-spec '(form body))
10215
10216 ;; Thread-based commands.
10217
10218 (defun gnus-summary-articles-in-thread (&optional article)
10219   "Return a list of all articles in the current thread.
10220 If ARTICLE is non-nil, return all articles in the thread that starts
10221 with that article."
10222   (let* ((article (or article (gnus-summary-article-number)))
10223          (data (gnus-data-find-list article))
10224          (top-level (gnus-data-level (car data)))
10225          (top-subject
10226           (cond ((null gnus-thread-operation-ignore-subject)
10227                  (gnus-simplify-subject-re
10228                   (mail-header-subject (gnus-data-header (car data)))))
10229                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10230                  (gnus-simplify-subject-fuzzy
10231                   (mail-header-subject (gnus-data-header (car data)))))
10232                 (t nil)))
10233          (end-point (save-excursion
10234                       (if (gnus-summary-go-to-next-thread)
10235                           (point) (point-max))))
10236          articles)
10237     (while (and data
10238                 (< (gnus-data-pos (car data)) end-point))
10239       (when (or (not top-subject)
10240                 (string= top-subject
10241                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10242                              (gnus-simplify-subject-fuzzy
10243                               (mail-header-subject
10244                                (gnus-data-header (car data))))
10245                            (gnus-simplify-subject-re
10246                             (mail-header-subject
10247                              (gnus-data-header (car data)))))))
10248         (push (gnus-data-number (car data)) articles))
10249       (unless (and (setq data (cdr data))
10250                    (> (gnus-data-level (car data)) top-level))
10251         (setq data nil)))
10252     ;; Return the list of articles.
10253     (nreverse articles)))
10254
10255 (defun gnus-summary-rethread-current ()
10256   "Rethread the thread the current article is part of."
10257   (interactive)
10258   (let* ((gnus-show-threads t)
10259          (article (gnus-summary-article-number))
10260          (id (mail-header-id (gnus-summary-article-header)))
10261          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10262     (unless id
10263       (error "No article on the current line"))
10264     (gnus-rebuild-thread id)
10265     (gnus-summary-goto-subject article)))
10266
10267 (defun gnus-summary-reparent-thread ()
10268   "Make the current article child of the marked (or previous) article.
10269
10270 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10271 is non-nil or the Subject: of both articles are the same."
10272   (interactive)
10273   (unless (not (gnus-group-read-only-p))
10274     (error "The current newsgroup does not support article editing"))
10275   (unless (<= (length gnus-newsgroup-processable) 1)
10276     (error "No more than one article may be marked"))
10277   (save-window-excursion
10278     (let ((gnus-article-buffer " *reparent*")
10279           (current-article (gnus-summary-article-number))
10280           ;; First grab the marked article, otherwise one line up.
10281           (parent-article (if (not (null gnus-newsgroup-processable))
10282                               (car gnus-newsgroup-processable)
10283                             (save-excursion
10284                               (if (eq (forward-line -1) 0)
10285                                   (gnus-summary-article-number)
10286                                 (error "Beginning of summary buffer"))))))
10287       (unless (not (eq current-article parent-article))
10288         (error "An article may not be self-referential"))
10289       (let ((message-id (mail-header-id
10290                          (gnus-summary-article-header parent-article))))
10291         (unless (and message-id (not (equal message-id "")))
10292           (error "No message-id in desired parent"))
10293         (gnus-with-article current-article
10294           (save-restriction
10295             (goto-char (point-min))
10296             (message-narrow-to-head)
10297             (if (re-search-forward "^References: " nil t)
10298                 (progn
10299                   (re-search-forward "^[^ \t]" nil t)
10300                   (forward-line -1)
10301                   (end-of-line)
10302                   (insert " " message-id))
10303               (insert "References: " message-id "\n"))))
10304         (set-buffer gnus-summary-buffer)
10305         (gnus-summary-unmark-all-processable)
10306         (gnus-summary-update-article current-article)
10307         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10308             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10309         (gnus-summary-rethread-current)
10310         (gnus-message 3 "Article %d is now the child of article %d"
10311                       current-article parent-article)))))
10312
10313 (defun gnus-summary-toggle-threads (&optional arg)
10314   "Toggle showing conversation threads.
10315 If ARG is positive number, turn showing conversation threads on."
10316   (interactive "P")
10317   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10318     (setq gnus-show-threads
10319           (if (null arg) (not gnus-show-threads)
10320             (> (prefix-numeric-value arg) 0)))
10321     (gnus-summary-prepare)
10322     (gnus-summary-goto-subject current)
10323     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10324     (gnus-summary-position-point)))
10325
10326 (defun gnus-summary-show-all-threads ()
10327   "Show all threads."
10328   (interactive)
10329   (save-excursion
10330     (let ((buffer-read-only nil))
10331       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10332   (gnus-summary-position-point))
10333
10334 (defun gnus-summary-show-thread ()
10335   "Show thread subtrees.
10336 Returns nil if no thread was there to be shown."
10337   (interactive)
10338   (let ((buffer-read-only nil)
10339         (orig (point))
10340         ;; first goto end then to beg, to have point at beg after let
10341         (end (progn (end-of-line) (point)))
10342         (beg (progn (beginning-of-line) (point))))
10343     (prog1
10344         ;; Any hidden lines here?
10345         (search-forward "\r" end t)
10346       (subst-char-in-region beg end ?\^M ?\n t)
10347       (goto-char orig)
10348       (gnus-summary-position-point))))
10349
10350 (defun gnus-summary-maybe-hide-threads ()
10351   "If requested, hide the threads that should be hidden."
10352   (when (and gnus-show-threads
10353              gnus-thread-hide-subtree)
10354     (gnus-summary-hide-all-threads
10355      (if (or (consp gnus-thread-hide-subtree)
10356              (gnus-functionp gnus-thread-hide-subtree))
10357          (gnus-make-predicate gnus-thread-hide-subtree)
10358        nil))))
10359
10360 ;;; Hiding predicates.
10361
10362 (defun gnus-article-unread-p (header)
10363   (memq (mail-header-number header) gnus-newsgroup-unreads))
10364
10365 (defun gnus-article-unseen-p (header)
10366   (memq (mail-header-number header) gnus-newsgroup-unseen))
10367
10368 (defun gnus-map-articles (predicate articles)
10369   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10370   (apply 'gnus-or (mapcar predicate
10371                           (mapcar 'gnus-summary-article-header articles))))
10372
10373 (defun gnus-summary-hide-all-threads (&optional predicate)
10374   "Hide all thread subtrees.
10375 If PREDICATE is supplied, threads that satisfy this predicate
10376 will not be hidden."
10377   (interactive)
10378   (save-excursion
10379     (goto-char (point-min))
10380     (let ((end nil))
10381       (while (not end)
10382         (when (or (not predicate)
10383                   (gnus-map-articles
10384                    predicate (gnus-summary-article-children)))
10385             (gnus-summary-hide-thread))
10386         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10387   (gnus-summary-position-point))
10388
10389 (defun gnus-summary-hide-thread ()
10390   "Hide thread subtrees.
10391 If PREDICATE is supplied, threads that satisfy this predicate
10392 will not be hidden.
10393 Returns nil if no threads were there to be hidden."
10394   (interactive)
10395   (let ((buffer-read-only nil)
10396         (start (point))
10397         (article (gnus-summary-article-number)))
10398     (goto-char start)
10399     ;; Go forward until either the buffer ends or the subthread
10400     ;; ends.
10401     (when (and (not (eobp))
10402                (or (zerop (gnus-summary-next-thread 1 t))
10403                    (goto-char (point-max))))
10404       (prog1
10405           (if (and (> (point) start)
10406                    (search-backward "\n" start t))
10407               (progn
10408                 (subst-char-in-region start (point) ?\n ?\^M)
10409                 (gnus-summary-goto-subject article))
10410             (goto-char start)
10411             nil)))))
10412
10413 (defun gnus-summary-go-to-next-thread (&optional previous)
10414   "Go to the same level (or less) next thread.
10415 If PREVIOUS is non-nil, go to previous thread instead.
10416 Return the article number moved to, or nil if moving was impossible."
10417   (let ((level (gnus-summary-thread-level))
10418         (way (if previous -1 1))
10419         (beg (point)))
10420     (forward-line way)
10421     (while (and (not (eobp))
10422                 (< level (gnus-summary-thread-level)))
10423       (forward-line way))
10424     (if (eobp)
10425         (progn
10426           (goto-char beg)
10427           nil)
10428       (setq beg (point))
10429       (prog1
10430           (gnus-summary-article-number)
10431         (goto-char beg)))))
10432
10433 (defun gnus-summary-next-thread (n &optional silent)
10434   "Go to the same level next N'th thread.
10435 If N is negative, search backward instead.
10436 Returns the difference between N and the number of skips actually
10437 done.
10438
10439 If SILENT, don't output messages."
10440   (interactive "p")
10441   (let ((backward (< n 0))
10442         (n (abs n)))
10443     (while (and (> n 0)
10444                 (gnus-summary-go-to-next-thread backward))
10445       (decf n))
10446     (unless silent
10447       (gnus-summary-position-point))
10448     (when (and (not silent) (/= 0 n))
10449       (gnus-message 7 "No more threads"))
10450     n))
10451
10452 (defun gnus-summary-prev-thread (n)
10453   "Go to the same level previous N'th thread.
10454 Returns the difference between N and the number of skips actually
10455 done."
10456   (interactive "p")
10457   (gnus-summary-next-thread (- n)))
10458
10459 (defun gnus-summary-go-down-thread ()
10460   "Go down one level in the current thread."
10461   (let ((children (gnus-summary-article-children)))
10462     (when children
10463       (gnus-summary-goto-subject (car children)))))
10464
10465 (defun gnus-summary-go-up-thread ()
10466   "Go up one level in the current thread."
10467   (let ((parent (gnus-summary-article-parent)))
10468     (when parent
10469       (gnus-summary-goto-subject parent))))
10470
10471 (defun gnus-summary-down-thread (n)
10472   "Go down thread N steps.
10473 If N is negative, go up instead.
10474 Returns the difference between N and how many steps down that were
10475 taken."
10476   (interactive "p")
10477   (let ((up (< n 0))
10478         (n (abs n)))
10479     (while (and (> n 0)
10480                 (if up (gnus-summary-go-up-thread)
10481                   (gnus-summary-go-down-thread)))
10482       (setq n (1- n)))
10483     (gnus-summary-position-point)
10484     (when (/= 0 n)
10485       (gnus-message 7 "Can't go further"))
10486     n))
10487
10488 (defun gnus-summary-up-thread (n)
10489   "Go up thread N steps.
10490 If N is negative, go down instead.
10491 Returns the difference between N and how many steps down that were
10492 taken."
10493   (interactive "p")
10494   (gnus-summary-down-thread (- n)))
10495
10496 (defun gnus-summary-top-thread ()
10497   "Go to the top of the thread."
10498   (interactive)
10499   (while (gnus-summary-go-up-thread))
10500   (gnus-summary-article-number))
10501
10502 (defun gnus-summary-kill-thread (&optional unmark)
10503   "Mark articles under current thread as read.
10504 If the prefix argument is positive, remove any kinds of marks.
10505 If the prefix argument is negative, tick articles instead."
10506   (interactive "P")
10507   (when unmark
10508     (setq unmark (prefix-numeric-value unmark)))
10509   (let ((articles (gnus-summary-articles-in-thread)))
10510     (save-excursion
10511       ;; Expand the thread.
10512       (gnus-summary-show-thread)
10513       ;; Mark all the articles.
10514       (while articles
10515         (gnus-summary-goto-subject (car articles))
10516         (cond ((null unmark)
10517                (gnus-summary-mark-article-as-read gnus-killed-mark))
10518               ((> unmark 0)
10519                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10520               (t
10521                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10522         (setq articles (cdr articles))))
10523     ;; Hide killed subtrees.
10524     (and (null unmark)
10525          gnus-thread-hide-killed
10526          (gnus-summary-hide-thread))
10527     ;; If marked as read, go to next unread subject.
10528     (when (null unmark)
10529       ;; Go to next unread subject.
10530       (gnus-summary-next-subject 1 t)))
10531   (gnus-set-mode-line 'summary))
10532
10533 ;; Summary sorting commands
10534
10535 (defun gnus-summary-sort-by-number (&optional reverse)
10536   "Sort the summary buffer by article number.
10537 Argument REVERSE means reverse order."
10538   (interactive "P")
10539   (gnus-summary-sort 'number reverse))
10540
10541 (defun gnus-summary-sort-by-random (&optional reverse)
10542   "Randomize the order in the summary buffer.
10543 Argument REVERSE means to randomize in reverse order."
10544   (interactive "P")
10545   (gnus-summary-sort 'random reverse))
10546
10547 (defun gnus-summary-sort-by-author (&optional reverse)
10548   "Sort the summary buffer by author name alphabetically.
10549 If `case-fold-search' is non-nil, case of letters is ignored.
10550 Argument REVERSE means reverse order."
10551   (interactive "P")
10552   (gnus-summary-sort 'author reverse))
10553
10554 (defun gnus-summary-sort-by-subject (&optional reverse)
10555   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10556 If `case-fold-search' is non-nil, case of letters is ignored.
10557 Argument REVERSE means reverse order."
10558   (interactive "P")
10559   (gnus-summary-sort 'subject reverse))
10560
10561 (defun gnus-summary-sort-by-date (&optional reverse)
10562   "Sort the summary buffer by date.
10563 Argument REVERSE means reverse order."
10564   (interactive "P")
10565   (gnus-summary-sort 'date reverse))
10566
10567 (defun gnus-summary-sort-by-score (&optional reverse)
10568   "Sort the summary buffer by score.
10569 Argument REVERSE means reverse order."
10570   (interactive "P")
10571   (gnus-summary-sort 'score reverse))
10572
10573 (defun gnus-summary-sort-by-lines (&optional reverse)
10574   "Sort the summary buffer by the number of lines.
10575 Argument REVERSE means reverse order."
10576   (interactive "P")
10577   (gnus-summary-sort 'lines reverse))
10578
10579 (defun gnus-summary-sort-by-chars (&optional reverse)
10580   "Sort the summary buffer by article length.
10581 Argument REVERSE means reverse order."
10582   (interactive "P")
10583   (gnus-summary-sort 'chars reverse))
10584
10585 (defun gnus-summary-sort-by-original (&optional reverse)
10586   "Sort the summary buffer using the default sorting method.
10587 Argument REVERSE means reverse order."
10588   (interactive "P")
10589   (let* ((buffer-read-only)
10590          (gnus-summary-prepare-hook nil))
10591     ;; We do the sorting by regenerating the threads.
10592     (gnus-summary-prepare)
10593     ;; Hide subthreads if needed.
10594     (gnus-summary-maybe-hide-threads)))
10595
10596 (defun gnus-summary-sort (predicate reverse)
10597   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10598   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10599          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10600          (gnus-thread-sort-functions
10601           (if (not reverse)
10602               thread
10603             `(lambda (t1 t2)
10604                (,thread t2 t1))))
10605          (gnus-sort-gathered-threads-function
10606           gnus-thread-sort-functions)
10607          (gnus-article-sort-functions
10608           (if (not reverse)
10609               article
10610             `(lambda (t1 t2)
10611                (,article t2 t1))))
10612          (buffer-read-only)
10613          (gnus-summary-prepare-hook nil))
10614     ;; We do the sorting by regenerating the threads.
10615     (gnus-summary-prepare)
10616     ;; Hide subthreads if needed.
10617     (gnus-summary-maybe-hide-threads)))
10618
10619 ;; Summary saving commands.
10620
10621 (defun gnus-summary-save-article (&optional n not-saved)
10622   "Save the current article using the default saver function.
10623 If N is a positive number, save the N next articles.
10624 If N is a negative number, save the N previous articles.
10625 If N is nil and any articles have been marked with the process mark,
10626 save those articles instead.
10627 The variable `gnus-default-article-saver' specifies the saver function."
10628   (interactive "P")
10629   (let* ((articles (gnus-summary-work-articles n))
10630          (save-buffer (save-excursion
10631                         (nnheader-set-temp-buffer " *Gnus Save*")))
10632          (num (length articles))
10633          header file)
10634     (dolist (article articles)
10635       (setq header (gnus-summary-article-header article))
10636       (if (not (vectorp header))
10637           ;; This is a pseudo-article.
10638           (if (assq 'name header)
10639               (gnus-copy-file (cdr (assq 'name header)))
10640             (gnus-message 1 "Article %d is unsaveable" article))
10641         ;; This is a real article.
10642         (save-window-excursion
10643           (let ((gnus-display-mime-function nil)
10644                 (gnus-article-prepare-hook nil))
10645             (gnus-summary-select-article t nil nil article)))
10646         (save-excursion
10647           (set-buffer save-buffer)
10648           (erase-buffer)
10649           (insert-buffer-substring gnus-original-article-buffer))
10650         (setq file (gnus-article-save save-buffer file num))
10651         (gnus-summary-remove-process-mark article)
10652         (unless not-saved
10653           (gnus-summary-set-saved-mark article))))
10654     (gnus-kill-buffer save-buffer)
10655     (gnus-summary-position-point)
10656     (gnus-set-mode-line 'summary)
10657     n))
10658
10659 (defun gnus-summary-pipe-output (&optional arg headers)
10660   "Pipe the current article to a subprocess.
10661 If N is a positive number, pipe the N next articles.
10662 If N is a negative number, pipe the N previous articles.
10663 If N is nil and any articles have been marked with the process mark,
10664 pipe those articles instead.
10665 If HEADERS (the symbolic prefix), include the headers, too."
10666   (interactive (gnus-interactive "P\ny"))
10667   (require 'gnus-art)
10668   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10669         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10670     (gnus-summary-save-article arg t))
10671   (let ((buffer (get-buffer "*Shell Command Output*")))
10672     (when (and buffer
10673                (not (zerop (buffer-size buffer))))
10674       (gnus-configure-windows 'pipe))))
10675
10676 (defun gnus-summary-save-article-mail (&optional arg)
10677   "Append the current article to an mail file.
10678 If N is a positive number, save the N next articles.
10679 If N is a negative number, save the N previous articles.
10680 If N is nil and any articles have been marked with the process mark,
10681 save those articles instead."
10682   (interactive "P")
10683   (require 'gnus-art)
10684   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10685     (gnus-summary-save-article arg)))
10686
10687 (defun gnus-summary-save-article-rmail (&optional arg)
10688   "Append the current article to an rmail file.
10689 If N is a positive number, save the N next articles.
10690 If N is a negative number, save the N previous articles.
10691 If N is nil and any articles have been marked with the process mark,
10692 save those articles instead."
10693   (interactive "P")
10694   (require 'gnus-art)
10695   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10696     (gnus-summary-save-article arg)))
10697
10698 (defun gnus-summary-save-article-file (&optional arg)
10699   "Append the current article to a 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-file))
10707     (gnus-summary-save-article arg)))
10708
10709 (defun gnus-summary-write-article-file (&optional arg)
10710   "Write the current article to a file, deleting the previous 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-write-to-file))
10718     (gnus-summary-save-article arg)))
10719
10720 (defun gnus-summary-save-article-body-file (&optional arg)
10721   "Append the current article body 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-body-in-file))
10729     (gnus-summary-save-article arg)))
10730
10731 (defun gnus-summary-muttprint (&optional arg)
10732   "Print the current article using Muttprint.
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-pipe-to-muttprint))
10740     (gnus-summary-save-article arg t)))
10741
10742 (defun gnus-summary-pipe-message (program)
10743   "Pipe the current article through PROGRAM."
10744   (interactive "sProgram: ")
10745   (gnus-summary-select-article)
10746   (let ((mail-header-separator ""))
10747     (gnus-eval-in-buffer-window gnus-article-buffer
10748       (save-restriction
10749         (widen)
10750         (let ((start (window-start))
10751               buffer-read-only)
10752           (message-pipe-buffer-body program)
10753           (set-window-start (get-buffer-window (current-buffer)) start))))))
10754
10755 (defun gnus-get-split-value (methods)
10756   "Return a value based on the split METHODS."
10757   (let (split-name method result match)
10758     (when methods
10759       (save-excursion
10760         (set-buffer gnus-original-article-buffer)
10761         (save-restriction
10762           (nnheader-narrow-to-headers)
10763           (while (and methods (not split-name))
10764             (goto-char (point-min))
10765             (setq method (pop methods))
10766             (setq match (car method))
10767             (when (cond
10768                    ((stringp match)
10769                     ;; Regular expression.
10770                     (ignore-errors
10771                       (re-search-forward match nil t)))
10772                    ((gnus-functionp match)
10773                     ;; Function.
10774                     (save-restriction
10775                       (widen)
10776                       (setq result (funcall match gnus-newsgroup-name))))
10777                    ((consp match)
10778                     ;; Form.
10779                     (save-restriction
10780                       (widen)
10781                       (setq result (eval match)))))
10782               (setq split-name (cdr method))
10783               (cond ((stringp result)
10784                      (push (expand-file-name
10785                             result gnus-article-save-directory)
10786                            split-name))
10787                     ((consp result)
10788                      (setq split-name (append result split-name)))))))))
10789     (nreverse split-name)))
10790
10791 (defun gnus-valid-move-group-p (group)
10792   (and (boundp group)
10793        (symbol-name group)
10794        (symbol-value group)
10795        (gnus-get-function (gnus-find-method-for-group
10796                            (symbol-name group)) 'request-accept-article t)))
10797
10798 (defun gnus-read-move-group-name (prompt default articles prefix)
10799   "Read a group name."
10800   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10801          (minibuffer-confirm-incomplete nil) ; XEmacs
10802          (prom
10803           (format "%s %s to:"
10804                   prompt
10805                   (if (> (length articles) 1)
10806                       (format "these %d articles" (length articles))
10807                     "this article")))
10808          (to-newsgroup
10809           (cond
10810            ((null split-name)
10811             (gnus-completing-read-with-default
10812              default prom
10813              gnus-active-hashtb
10814              'gnus-valid-move-group-p
10815              nil prefix
10816              'gnus-group-history))
10817            ((= 1 (length split-name))
10818             (gnus-completing-read-with-default
10819              (car split-name) prom
10820              gnus-active-hashtb
10821              'gnus-valid-move-group-p
10822              nil nil
10823              'gnus-group-history))
10824            (t
10825             (gnus-completing-read-with-default
10826              nil prom
10827              (mapcar (lambda (el) (list el))
10828                      (nreverse split-name))
10829              nil nil nil
10830              'gnus-group-history))))
10831          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10832     (when to-newsgroup
10833       (if (or (string= to-newsgroup "")
10834               (string= to-newsgroup prefix))
10835           (setq to-newsgroup default))
10836       (unless to-newsgroup
10837         (error "No group name entered"))
10838       (or (gnus-active to-newsgroup)
10839           (gnus-activate-group to-newsgroup nil nil to-method)
10840           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10841                                      to-newsgroup))
10842               (or (and (gnus-request-create-group to-newsgroup to-method)
10843                        (gnus-activate-group
10844                         to-newsgroup nil nil to-method)
10845                        (gnus-subscribe-group to-newsgroup))
10846                   (error "Couldn't create group %s" to-newsgroup)))
10847           (error "No such group: %s" to-newsgroup)))
10848     to-newsgroup))
10849
10850 (defun gnus-summary-save-parts (type dir n &optional reverse)
10851   "Save parts matching TYPE to DIR.
10852 If REVERSE, save parts that do not match TYPE."
10853   (interactive
10854    (list (read-string "Save parts of type: "
10855                       (or (car gnus-summary-save-parts-type-history)
10856                           gnus-summary-save-parts-default-mime)
10857                       'gnus-summary-save-parts-type-history)
10858          (setq gnus-summary-save-parts-last-directory
10859                (read-file-name "Save to directory: "
10860                                gnus-summary-save-parts-last-directory
10861                                nil t))
10862          current-prefix-arg))
10863   (gnus-summary-iterate n
10864     (let ((gnus-display-mime-function nil)
10865           (gnus-inhibit-treatment t))
10866       (gnus-summary-select-article))
10867     (save-excursion
10868       (set-buffer gnus-article-buffer)
10869       (let ((handles (or gnus-article-mime-handles
10870                          (mm-dissect-buffer nil gnus-article-loose-mime)
10871                          (and gnus-article-emulate-mime
10872                               (mm-uu-dissect)))))
10873         (when handles
10874           (gnus-summary-save-parts-1 type dir handles reverse)
10875           (unless gnus-article-mime-handles ;; Don't destroy this case.
10876             (mm-destroy-parts handles)))))))
10877
10878 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10879   (if (stringp (car handle))
10880       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10881               (cdr handle))
10882     (when (if reverse
10883               (not (string-match type (mm-handle-media-type handle)))
10884             (string-match type (mm-handle-media-type handle)))
10885       (let ((file (expand-file-name
10886                    (file-name-nondirectory
10887                     (or
10888                      (mail-content-type-get
10889                       (mm-handle-disposition handle) 'filename)
10890                      (concat gnus-newsgroup-name
10891                              "." (number-to-string
10892                                   (cdr gnus-article-current)))))
10893                    dir)))
10894         (unless (file-exists-p file)
10895           (mm-save-part-to-file handle file))))))
10896
10897 ;; Summary extract commands
10898
10899 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10900   (let ((buffer-read-only nil)
10901         (article (gnus-summary-article-number))
10902         after-article b e)
10903     (unless (gnus-summary-goto-subject article)
10904       (error "No such article: %d" article))
10905     (gnus-summary-position-point)
10906     ;; If all commands are to be bunched up on one line, we collect
10907     ;; them here.
10908     (unless gnus-view-pseudos-separately
10909       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10910             files action)
10911         (while ps
10912           (setq action (cdr (assq 'action (car ps))))
10913           (setq files (list (cdr (assq 'name (car ps)))))
10914           (while (and ps (cdr ps)
10915                       (string= (or action "1")
10916                                (or (cdr (assq 'action (cadr ps))) "2")))
10917             (push (cdr (assq 'name (cadr ps))) files)
10918             (setcdr ps (cddr ps)))
10919           (when files
10920             (when (not (string-match "%s" action))
10921               (push " " files))
10922             (push " " files)
10923             (when (assq 'execute (car ps))
10924               (setcdr (assq 'execute (car ps))
10925                       (funcall (if (string-match "%s" action)
10926                                    'format 'concat)
10927                                action
10928                                (mapconcat
10929                                 (lambda (f)
10930                                   (if (equal f " ")
10931                                       f
10932                                     (gnus-quote-arg-for-sh-or-csh f)))
10933                                 files " ")))))
10934           (setq ps (cdr ps)))))
10935     (if (and gnus-view-pseudos (not not-view))
10936         (while pslist
10937           (when (assq 'execute (car pslist))
10938             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10939                                   (eq gnus-view-pseudos 'not-confirm)))
10940           (setq pslist (cdr pslist)))
10941       (save-excursion
10942         (while pslist
10943           (setq after-article (or (cdr (assq 'article (car pslist)))
10944                                   (gnus-summary-article-number)))
10945           (gnus-summary-goto-subject after-article)
10946           (forward-line 1)
10947           (setq b (point))
10948           (insert "    " (file-name-nondirectory
10949                           (cdr (assq 'name (car pslist))))
10950                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10951           (setq e (point))
10952           (forward-line -1)             ; back to `b'
10953           (gnus-add-text-properties
10954            b (1- e) (list 'gnus-number gnus-reffed-article-number
10955                           gnus-mouse-face-prop gnus-mouse-face))
10956           (gnus-data-enter
10957            after-article gnus-reffed-article-number
10958            gnus-unread-mark b (car pslist) 0 (- e b))
10959           (setq gnus-newsgroup-unreads
10960                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10961                                          gnus-reffed-article-number))
10962           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10963           (setq pslist (cdr pslist)))))))
10964
10965 (defun gnus-pseudos< (p1 p2)
10966   (let ((c1 (cdr (assq 'action p1)))
10967         (c2 (cdr (assq 'action p2))))
10968     (and c1 c2 (string< c1 c2))))
10969
10970 (defun gnus-request-pseudo-article (props)
10971   (cond ((assq 'execute props)
10972          (gnus-execute-command (cdr (assq 'execute props)))))
10973   (let ((gnus-current-article (gnus-summary-article-number)))
10974     (gnus-run-hooks 'gnus-mark-article-hook)))
10975
10976 (defun gnus-execute-command (command &optional automatic)
10977   (save-excursion
10978     (gnus-article-setup-buffer)
10979     (set-buffer gnus-article-buffer)
10980     (setq buffer-read-only nil)
10981     (let ((command (if automatic command
10982                      (read-string "Command: " (cons command 0)))))
10983       (erase-buffer)
10984       (insert "$ " command "\n\n")
10985       (if gnus-view-pseudo-asynchronously
10986           (start-process "gnus-execute" (current-buffer) shell-file-name
10987                          shell-command-switch command)
10988         (call-process shell-file-name nil t nil
10989                       shell-command-switch command)))))
10990
10991 ;; Summary kill commands.
10992
10993 (defun gnus-summary-edit-global-kill (article)
10994   "Edit the \"global\" kill file."
10995   (interactive (list (gnus-summary-article-number)))
10996   (gnus-group-edit-global-kill article))
10997
10998 (defun gnus-summary-edit-local-kill ()
10999   "Edit a local kill file applied to the current newsgroup."
11000   (interactive)
11001   (setq gnus-current-headers (gnus-summary-article-header))
11002   (gnus-group-edit-local-kill
11003    (gnus-summary-article-number) gnus-newsgroup-name))
11004
11005 ;;; Header reading.
11006
11007 (defun gnus-read-header (id &optional header)
11008   "Read the headers of article ID and enter them into the Gnus system."
11009   (let ((group gnus-newsgroup-name)
11010         (gnus-override-method
11011          (or
11012           gnus-override-method
11013           (and (gnus-news-group-p gnus-newsgroup-name)
11014                (car (gnus-refer-article-methods)))))
11015         where)
11016     ;; First we check to see whether the header in question is already
11017     ;; fetched.
11018     (if (stringp id)
11019         ;; This is a Message-ID.
11020         (setq header (or header (gnus-id-to-header id)))
11021       ;; This is an article number.
11022       (setq header (or header (gnus-summary-article-header id))))
11023     (if (and header
11024              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11025         ;; We have found the header.
11026         header
11027       ;; If this is a sparse article, we have to nix out its
11028       ;; previous entry in the thread hashtb.
11029       (when (and header
11030                  (gnus-summary-article-sparse-p (mail-header-number header)))
11031         (let* ((parent (gnus-parent-id (mail-header-references header)))
11032                (thread (and parent (gnus-id-to-thread parent))))
11033           (when thread
11034             (delq (assq header thread) thread))))
11035       ;; We have to really fetch the header to this article.
11036       (save-excursion
11037         (set-buffer nntp-server-buffer)
11038         (when (setq where (gnus-request-head id group))
11039           (nnheader-fold-continuation-lines)
11040           (goto-char (point-max))
11041           (insert ".\n")
11042           (goto-char (point-min))
11043           (insert "211 ")
11044           (princ (cond
11045                   ((numberp id) id)
11046                   ((cdr where) (cdr where))
11047                   (header (mail-header-number header))
11048                   (t gnus-reffed-article-number))
11049                  (current-buffer))
11050           (insert " Article retrieved.\n"))
11051         (if (or (not where)
11052                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11053             ()                          ; Malformed head.
11054           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11055             (when (and (stringp id)
11056                        (not (string= (gnus-group-real-name group)
11057                                      (car where))))
11058               ;; If we fetched by Message-ID and the article came
11059               ;; from a different group, we fudge some bogus article
11060               ;; numbers for this article.
11061               (mail-header-set-number header gnus-reffed-article-number))
11062             (save-excursion
11063               (set-buffer gnus-summary-buffer)
11064               (decf gnus-reffed-article-number)
11065               (gnus-remove-header (mail-header-number header))
11066               (push header gnus-newsgroup-headers)
11067               (setq gnus-current-headers header)
11068               (push (mail-header-number header) gnus-newsgroup-limit)))
11069           header)))))
11070
11071 (defun gnus-remove-header (number)
11072   "Remove header NUMBER from `gnus-newsgroup-headers'."
11073   (if (and gnus-newsgroup-headers
11074            (= number (mail-header-number (car gnus-newsgroup-headers))))
11075       (pop gnus-newsgroup-headers)
11076     (let ((headers gnus-newsgroup-headers))
11077       (while (and (cdr headers)
11078                   (not (= number (mail-header-number (cadr headers)))))
11079         (pop headers))
11080       (when (cdr headers)
11081         (setcdr headers (cddr headers))))))
11082
11083 ;;;
11084 ;;; summary highlights
11085 ;;;
11086
11087 (defun gnus-highlight-selected-summary ()
11088   "Highlight selected article in summary buffer."
11089   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11090   (when gnus-summary-selected-face
11091     (save-excursion
11092       (let* ((beg (progn (beginning-of-line) (point)))
11093              (end (progn (end-of-line) (point)))
11094              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11095              (from (if (get-text-property beg gnus-mouse-face-prop)
11096                        beg
11097                      (or (next-single-property-change
11098                           beg gnus-mouse-face-prop nil end)
11099                          beg)))
11100              (to
11101               (if (= from end)
11102                   (- from 2)
11103                 (or (next-single-property-change
11104                      from gnus-mouse-face-prop nil end)
11105                     end))))
11106         ;; If no mouse-face prop on line we will have to = from = end,
11107         ;; so we highlight the entire line instead.
11108         (when (= (+ to 2) from)
11109           (setq from beg)
11110           (setq to end))
11111         (if gnus-newsgroup-selected-overlay
11112             ;; Move old overlay.
11113             (gnus-move-overlay
11114              gnus-newsgroup-selected-overlay from to (current-buffer))
11115           ;; Create new overlay.
11116           (gnus-overlay-put
11117            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11118            'face gnus-summary-selected-face))))))
11119
11120 (defvar gnus-summary-highlight-line-cached nil)
11121 (defvar gnus-summary-highlight-line-trigger nil)
11122
11123 (defun gnus-summary-highlight-line-0 ()
11124   (if (and (eq gnus-summary-highlight-line-trigger 
11125                gnus-summary-highlight)
11126            gnus-summary-highlight-line-cached)
11127       gnus-summary-highlight-line-cached
11128     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11129           gnus-summary-highlight-line-cached
11130           (let* ((cond (list 'cond))
11131                  (c cond)
11132                  (list gnus-summary-highlight))
11133             (while list
11134               (setcdr c (cons (list (caar list) (list 'quote (cdar list))) nil))
11135               (setq c (cdr c)
11136                     list (cdr list)))
11137             (gnus-byte-compile (list 'lambda nil cond))))))
11138
11139 (defun gnus-summary-highlight-line ()
11140   "Highlight current line according to `gnus-summary-highlight'."
11141   (let* ((beg (gnus-point-at-bol))
11142          (article (or (gnus-summary-article-number) gnus-current-article))
11143          (score (or (cdr (assq article
11144                                gnus-newsgroup-scored))
11145                     gnus-summary-default-score 0))
11146          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11147          (inhibit-read-only t)
11148          (default gnus-summary-default-score)
11149          (default-high gnus-summary-default-high-score)
11150          (default-low gnus-summary-default-low-score)
11151          (uncached (memq article gnus-newsgroup-undownloaded))
11152          (downloaded (not uncached)))
11153     (let ((face (funcall (gnus-summary-highlight-line-0))))
11154       (unless (eq face (get-text-property beg 'face))
11155         (gnus-put-text-property-excluding-characters-with-faces
11156          beg (gnus-point-at-eol) 'face
11157          (setq face (if (boundp face) (symbol-value face) face)))
11158         (when gnus-summary-highlight-line-function
11159           (funcall gnus-summary-highlight-line-function article face))))))
11160
11161 (defun gnus-update-read-articles (group unread &optional compute)
11162   "Update the list of read articles in GROUP.
11163 UNREAD is a sorted list."
11164   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
11165          (entry (gnus-gethash group gnus-newsrc-hashtb))
11166          (info (nth 2 entry))
11167          (prev 1)
11168          read)
11169     (if (or (not info) (not active))
11170         ;; There is no info on this group if it was, in fact,
11171         ;; killed.  Gnus stores no information on killed groups, so
11172         ;; there's nothing to be done.
11173         ;; One could store the information somewhere temporarily,
11174         ;; perhaps...  Hmmm...
11175         ()
11176       ;; Remove any negative articles numbers.
11177       (while (and unread (< (car unread) 0))
11178         (setq unread (cdr unread)))
11179       ;; Remove any expired article numbers
11180       (while (and unread (< (car unread) (car active)))
11181         (setq unread (cdr unread)))
11182       ;; Compute the ranges of read articles by looking at the list of
11183       ;; unread articles.
11184       (while unread
11185         (when (/= (car unread) prev)
11186           (push (if (= prev (1- (car unread))) prev
11187                   (cons prev (1- (car unread))))
11188                 read))
11189         (setq prev (1+ (car unread)))
11190         (setq unread (cdr unread)))
11191       (when (<= prev (cdr active))
11192         (push (cons prev (cdr active)) read))
11193       (setq read (if (> (length read) 1) (nreverse read) read))
11194       (if compute
11195           read
11196         (save-excursion
11197           (let (setmarkundo)
11198             ;; Propagate the read marks to the backend.
11199             (when (gnus-check-backend-function 'request-set-mark group)
11200               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11201                     (add (gnus-remove-from-range read (gnus-info-read info))))
11202                 (when (or add del)
11203                   (unless (gnus-check-group group)
11204                     (error "Can't open server for %s" group))
11205                   (gnus-request-set-mark
11206                    group (delq nil (list (if add (list add 'add '(read)))
11207                                          (if del (list del 'del '(read))))))
11208                   (setq setmarkundo
11209                         `(gnus-request-set-mark
11210                           ,group
11211                           ',(delq nil (list
11212                                        (if del (list del 'add '(read)))
11213                                        (if add (list add 'del '(read))))))))))
11214             (set-buffer gnus-group-buffer)
11215             (gnus-undo-register
11216               `(progn
11217                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11218                  (gnus-info-set-read ',info ',(gnus-info-read info))
11219                  (gnus-get-unread-articles-in-group ',info
11220                                                     (gnus-active ,group))
11221                  (gnus-group-update-group ,group t)
11222                  ,setmarkundo))))
11223         ;; Enter this list into the group info.
11224         (gnus-info-set-read info read)
11225         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11226         (gnus-get-unread-articles-in-group info (gnus-active group))
11227         t))))
11228
11229 (defun gnus-offer-save-summaries ()
11230   "Offer to save all active summary buffers."
11231   (let (buffers)
11232     ;; Go through all buffers and find all summaries.
11233     (dolist (buffer (buffer-list))
11234       (when (and (setq buffer (buffer-name buffer))
11235                  (string-match "Summary" buffer)
11236                  (save-excursion
11237                    (set-buffer buffer)
11238                    ;; We check that this is, indeed, a summary buffer.
11239                    (and (eq major-mode 'gnus-summary-mode)
11240                         ;; Also make sure this isn't bogus.
11241                         gnus-newsgroup-prepared
11242                         ;; Also make sure that this isn't a
11243                         ;; dead summary buffer.
11244                         (not gnus-dead-summary-mode))))
11245         (push buffer buffers)))
11246     ;; Go through all these summary buffers and offer to save them.
11247     (when buffers
11248       (save-excursion
11249         (map-y-or-n-p
11250          "Update summary buffer %s? "
11251          (lambda (buf)
11252            (switch-to-buffer buf)
11253            (gnus-summary-exit))
11254          buffers)))))
11255
11256
11257 ;;; @ for mime-partial
11258 ;;;
11259
11260 (defun gnus-request-partial-message ()
11261   (save-excursion
11262     (let ((number (gnus-summary-article-number))
11263           (group gnus-newsgroup-name)
11264           (mother gnus-article-buffer))
11265       (set-buffer (get-buffer-create " *Partial Article*"))
11266       (erase-buffer)
11267       (setq mime-preview-buffer mother)
11268       (gnus-request-article-this-buffer number group)
11269       (mime-parse-buffer)
11270       )))
11271
11272 (autoload 'mime-combine-message/partial-pieces-automatically
11273   "mime-partial"
11274   "Internal method to combine message/partial messages automatically.")
11275
11276 (mime-add-condition
11277  'action '((type . message)(subtype . partial)
11278            (major-mode . gnus-original-article-mode)
11279            (method . mime-combine-message/partial-pieces-automatically)
11280            (summary-buffer-exp . gnus-summary-buffer)
11281            (request-partial-message-method . gnus-request-partial-message)
11282            ))
11283
11284
11285 ;;; @ for message/rfc822
11286 ;;;
11287
11288 (defun gnus-mime-extract-message/rfc822 (entity situation)
11289   "Burst a forwarded article."
11290   (save-excursion
11291     (set-buffer gnus-summary-buffer)
11292     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11293                                    gnus-newsgroup-name 'gnus-group-history))
11294            (gnus-group-marked (list group))
11295            article info)
11296       (with-temp-buffer
11297         (mime-insert-entity-content entity)
11298         (setq article (gnus-request-accept-article group)))
11299       (when (and (consp article)
11300                  (numberp (setq article (cdr article))))
11301         (setq info (gnus-get-info group))
11302         (gnus-info-set-read info
11303                             (gnus-remove-from-range (gnus-info-read info)
11304                                                     (list article)))
11305         (when (string-equal group gnus-newsgroup-name)
11306           (forward-line 1)
11307           (let (gnus-show-threads)
11308             (gnus-summary-goto-subject article t))
11309           (gnus-summary-clear-mark-forward 1))
11310         (set-buffer gnus-group-buffer)
11311         (gnus-group-get-new-news-this-group nil t)))))
11312
11313 (mime-add-condition
11314  'action '((type . message)(subtype . rfc822)
11315            (major-mode . gnus-original-article-mode)
11316            (method . gnus-mime-extract-message/rfc822)
11317            (mode . "extract")
11318            ))
11319
11320 (mime-add-condition
11321  'action '((type . message)(subtype . news)
11322            (major-mode . gnus-original-article-mode)
11323            (method . gnus-mime-extract-message/rfc822)
11324            (mode . "extract")
11325            ))
11326
11327 (defun gnus-mime-extract-multipart (entity situation)
11328   (let ((children (mime-entity-children entity))
11329         mime-acting-situation-to-override
11330         f)
11331     (while children
11332       (mime-play-entity (car children)
11333                         (cons (assq 'mode situation)
11334                               mime-acting-situation-to-override))
11335       (setq children (cdr children)))
11336     (if (setq f (cdr (assq 'after-method
11337                            mime-acting-situation-to-override)))
11338         (eval f)
11339       )))
11340
11341 (mime-add-condition
11342  'action '((type . multipart)
11343            (method . gnus-mime-extract-multipart)
11344            (mode . "extract")
11345            )
11346  'with-default)
11347
11348
11349 ;;; @ end
11350 ;;;
11351
11352 (defun gnus-summary-inherit-default-charset ()
11353   "Import `default-mime-charset' from summary buffer.
11354 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11355 of FLIM is used."
11356   (if (buffer-live-p gnus-summary-buffer)
11357       (let (d-m-c d-m-c-u)
11358         (with-current-buffer gnus-summary-buffer
11359           (setq d-m-c (if (local-variable-p 'default-mime-charset
11360                                             gnus-summary-buffer)
11361                           default-mime-charset
11362                         t)
11363                 ;; LIMIT
11364                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11365                                               gnus-summary-buffer)
11366                             (symbol-value 'default-mime-charset-unlimited)
11367                           t)))
11368         (if (eq t d-m-c)
11369             (kill-local-variable 'default-mime-charset)
11370           (set (make-local-variable 'default-mime-charset) d-m-c))
11371         (if (eq t d-m-c-u)
11372             (kill-local-variable 'default-mime-charset-unlimited)
11373           (set (make-local-variable 'default-mime-charset-unlimited)
11374                d-m-c-u)))))
11375
11376 (defun gnus-summary-setup-default-charset ()
11377   "Setup newsgroup default charset."
11378   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11379       (progn
11380         (setq gnus-newsgroup-charset nil)
11381         (set (make-local-variable 'default-mime-charset) nil)
11382         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11383           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11384     (let ((ignored-charsets
11385            (or gnus-newsgroup-ephemeral-ignored-charsets
11386                (append
11387                 (and gnus-newsgroup-name
11388                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11389                 gnus-newsgroup-ignored-charsets)))
11390           charset)
11391       (setq gnus-newsgroup-charset
11392             (or gnus-newsgroup-ephemeral-charset
11393                 (when (and gnus-newsgroup-name
11394                            (setq charset (gnus-parameter-charset
11395                                           gnus-newsgroup-name)))
11396                   (make-local-variable 'default-mime-charset)
11397                   (setq default-mime-charset charset))
11398                 gnus-default-charset))
11399       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11400            ignored-charsets))))
11401
11402 ;;;
11403 ;;; Mime Commands
11404 ;;;
11405
11406 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11407   "Display the current article buffer fully MIME-buttonized.
11408 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11409 treated as multipart/mixed."
11410   (interactive "P")
11411   (require 'gnus-art)
11412   (let ((gnus-unbuttonized-mime-types nil)
11413         (gnus-mime-display-multipart-as-mixed show-all-parts))
11414     (gnus-summary-show-article)))
11415
11416 (defun gnus-summary-repair-multipart (article)
11417   "Add a Content-Type header to a multipart article without one."
11418   (interactive (list (gnus-summary-article-number)))
11419   (gnus-with-article article
11420     (message-narrow-to-head)
11421     (message-remove-header "Mime-Version")
11422     (goto-char (point-max))
11423     (insert "Mime-Version: 1.0\n")
11424     (widen)
11425     (when (search-forward "\n--" nil t)
11426       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11427         (message-narrow-to-head)
11428         (message-remove-header "Content-Type")
11429         (goto-char (point-max))
11430         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11431                         separator))
11432         (widen))))
11433   (let (gnus-mark-article-hook)
11434     (gnus-summary-select-article t t nil article)))
11435
11436 (defun gnus-summary-toggle-display-buttonized ()
11437   "Toggle the buttonizing of the article buffer."
11438   (interactive)
11439   (require 'gnus-art)
11440   (if (setq gnus-inhibit-mime-unbuttonizing
11441             (not gnus-inhibit-mime-unbuttonizing))
11442       (let ((gnus-unbuttonized-mime-types nil))
11443         (gnus-summary-show-article))
11444     (gnus-summary-show-article)))
11445
11446 ;;;
11447 ;;; Intelli-mouse commmands
11448 ;;;
11449
11450 (defun gnus-wheel-summary-scroll (event)
11451   (interactive "e")
11452   (let ((amount (if (memq 'shift (event-modifiers event))
11453                     (car gnus-wheel-scroll-amount)
11454                   (cdr gnus-wheel-scroll-amount)))
11455         (direction (- (* (static-if (featurep 'xemacs)
11456                              (event-button event)
11457                            (cond ((eq 'mouse-4 (event-basic-type event))
11458                                   4)
11459                                  ((eq 'mouse-5 (event-basic-type event))
11460                                   5)))
11461                          2) 9))
11462         edge)
11463     (gnus-summary-scroll-up (* amount direction))
11464     (when (gnus-eval-in-buffer-window gnus-article-buffer
11465             (save-restriction
11466               (widen)
11467               (and (if (< 0 direction)
11468                        (gnus-article-next-page 0)
11469                      (gnus-article-prev-page 0)
11470                      (bobp))
11471                    (if (setq edge (get-text-property
11472                                    (point-min) 'gnus-wheel-edge))
11473                        (setq edge (* edge direction))
11474                      (setq edge -1))
11475                    (or (plusp edge)
11476                        (let ((buffer-read-only nil)
11477                              (inhibit-read-only t))
11478                          (put-text-property (point-min) (point-max)
11479                                             'gnus-wheel-edge direction)
11480                          nil))
11481                    (or (> edge gnus-wheel-edge-resistance)
11482                        (let ((buffer-read-only nil)
11483                              (inhibit-read-only t))
11484                          (put-text-property (point-min) (point-max)
11485                                             'gnus-wheel-edge
11486                                             (* (1+ edge) direction))
11487                          nil))
11488                    (eq last-command 'gnus-wheel-summary-scroll))))
11489       (gnus-summary-next-article nil nil (minusp direction)))))
11490
11491 (defun gnus-wheel-install ()
11492   "Enable mouse wheel support on summary window."
11493   (when gnus-use-wheel
11494     (let ((keys
11495            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11496       (dolist (key keys)
11497         (define-key gnus-summary-mode-map key
11498           'gnus-wheel-summary-scroll)))))
11499
11500 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11501
11502 ;;;
11503 ;;; Traditional PGP commmands
11504 ;;;
11505
11506 (defun gnus-summary-decrypt-article (&optional force)
11507   "Decrypt the current article in traditional PGP way.
11508 This will have permanent effect only in mail groups.
11509 If FORCE is non-nil, allow editing of articles even in read-only
11510 groups."
11511   (interactive "P")
11512   (gnus-summary-select-article t)
11513   (gnus-eval-in-buffer-window gnus-article-buffer
11514     (save-excursion
11515       (save-restriction
11516         (widen)
11517         (goto-char (point-min))
11518         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11519           (error "Not a traditional PGP message!"))
11520         (let ((armor-start (match-beginning 0)))
11521           (if (and (pgg-decrypt-region armor-start (point-max))
11522                    (or force (not (gnus-group-read-only-p))))
11523               (let ((inhibit-read-only t)
11524                     buffer-read-only)
11525                 (delete-region armor-start
11526                                (progn
11527                                  (re-search-forward "^-+END PGP" nil t)
11528                                  (beginning-of-line 2)
11529                                  (point)))
11530                 (insert-buffer-substring pgg-output-buffer))))))))
11531
11532 (defun gnus-summary-verify-article ()
11533   "Verify the current article in traditional PGP way."
11534   (interactive)
11535   (save-excursion
11536     (set-buffer gnus-original-article-buffer)
11537     (goto-char (point-min))
11538     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11539       (error "Not a traditional PGP message!"))
11540     (re-search-forward "^-+END PGP" nil t)
11541     (beginning-of-line 2)
11542     (call-interactively (function pgg-verify-region))))
11543
11544 ;;;
11545 ;;; Generic summary marking commands
11546 ;;;
11547
11548 (defvar gnus-summary-marking-alist
11549   '((read gnus-del-mark "d")
11550     (unread gnus-unread-mark "u")
11551     (ticked gnus-ticked-mark "!")
11552     (dormant gnus-dormant-mark "?")
11553     (expirable gnus-expirable-mark "e"))
11554   "An alist of names/marks/keystrokes.")
11555
11556 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11557 (defvar gnus-summary-mark-map)
11558
11559 (defun gnus-summary-make-all-marking-commands ()
11560   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11561   (dolist (elem gnus-summary-marking-alist)
11562     (apply 'gnus-summary-make-marking-command elem)))
11563
11564 (defun gnus-summary-make-marking-command (name mark keystroke)
11565   (let ((map (make-sparse-keymap)))
11566     (define-key gnus-summary-generic-mark-map keystroke map)
11567     (dolist (lway `((next "next" next nil "n")
11568                     (next-unread "next unread" next t "N")
11569                     (prev "previous" prev nil "p")
11570                     (prev-unread "previous unread" prev t "P")
11571                     (nomove "" nil nil ,keystroke)))
11572       (let ((func (gnus-summary-make-marking-command-1
11573                    mark (car lway) lway name)))
11574         (setq func (eval func))
11575         (define-key map (nth 4 lway) func)))))
11576
11577 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11578   `(defun ,(intern
11579             (format "gnus-summary-put-mark-as-%s%s"
11580                     name (if (eq way 'nomove)
11581                              ""
11582                            (concat "-" (symbol-name way)))))
11583      (n)
11584      ,(format
11585        "Mark the current article as %s%s.
11586 If N, the prefix, then repeat N times.
11587 If N is negative, move in reverse order.
11588 The difference between N and the actual number of articles marked is
11589 returned."
11590        name (car (cdr lway)))
11591      (interactive "p")
11592      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11593
11594 (defun gnus-summary-generic-mark (n mark move unread)
11595   "Mark N articles with MARK."
11596   (unless (eq major-mode 'gnus-summary-mode)
11597     (error "This command can only be used in the summary buffer"))
11598   (gnus-summary-show-thread)
11599   (let ((nummove
11600          (cond
11601           ((eq move 'next) 1)
11602           ((eq move 'prev) -1)
11603           (t 0))))
11604     (if (zerop nummove)
11605         (setq n 1)
11606       (when (< n 0)
11607         (setq n (abs n)
11608               nummove (* -1 nummove))))
11609     (while (and (> n 0)
11610                 (gnus-summary-mark-article nil mark)
11611                 (zerop (gnus-summary-next-subject nummove unread t)))
11612       (setq n (1- n)))
11613     (when (/= 0 n)
11614       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11615     (gnus-summary-recenter)
11616     (gnus-summary-position-point)
11617     (gnus-set-mode-line 'summary)
11618     n))
11619
11620 (defun gnus-summary-insert-articles (articles)
11621   (when (setq articles
11622               (gnus-sorted-difference articles
11623                                       (mapcar (lambda (h)
11624                                                 (mail-header-number h))
11625                                               gnus-newsgroup-headers)))
11626     (setq gnus-newsgroup-headers
11627           (merge 'list
11628                  gnus-newsgroup-headers
11629                  (gnus-fetch-headers articles)
11630                  'gnus-article-sort-by-number))
11631     ;; Suppress duplicates?
11632     (when gnus-suppress-duplicates
11633       (gnus-dup-suppress-articles))
11634
11635     ;; We might want to build some more threads first.
11636     (when (and gnus-fetch-old-headers
11637                (eq gnus-headers-retrieved-by 'nov))
11638       (if (eq gnus-fetch-old-headers 'invisible)
11639           (gnus-build-all-threads)
11640         (gnus-build-old-threads)))
11641     ;; Let the Gnus agent mark articles as read.
11642     (when gnus-agent
11643       (gnus-agent-get-undownloaded-list))
11644     ;; Remove list identifiers from subject
11645     (when gnus-list-identifiers
11646       (gnus-summary-remove-list-identifiers))
11647     ;; First and last article in this newsgroup.
11648     (when gnus-newsgroup-headers
11649       (setq gnus-newsgroup-begin
11650             (mail-header-number (car gnus-newsgroup-headers))
11651             gnus-newsgroup-end
11652             (mail-header-number
11653              (gnus-last-element gnus-newsgroup-headers))))
11654     (when gnus-use-scoring
11655       (gnus-possibly-score-headers))))
11656
11657 (defun gnus-summary-insert-old-articles (&optional all)
11658   "Insert all old articles in this group.
11659 If ALL is non-nil, already read articles become readable.
11660 If ALL is a number, fetch this number of articles."
11661   (interactive "P")
11662   (prog1
11663       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11664             older len)
11665         (setq older
11666               ;; Some nntp servers lie about their active range.  When
11667               ;; this happens, the active range can be in the millions.
11668               ;; Use a compressed range to avoid creating a huge list.
11669               (gnus-range-difference (list gnus-newsgroup-active) old))
11670         (setq len (gnus-range-length older))
11671         (cond
11672          ((null older) nil)
11673          ((numberp all)
11674           (if (< all len)
11675               (let ((older-range (nreverse older)))
11676                 (setq older nil)
11677
11678                 (while (> all 0)
11679                   (let* ((r (pop older-range))
11680                          (min (if (numberp r) r (car r)))
11681                          (max (if (numberp r) r (cdr r))))
11682                     (while (and (<= min max)
11683                                 (> all 0))
11684                       (push max older)
11685                       (setq all (1- all)
11686                             max (1- max))))))
11687             (setq older (gnus-uncompress-range older))))
11688          (all
11689           (setq older (gnus-uncompress-range older)))
11690          (t
11691           (when (and (numberp gnus-large-newsgroup)
11692                    (> len gnus-large-newsgroup))
11693               (let* ((cursor-in-echo-area nil)
11694                      (initial (gnus-parameter-large-newsgroup-initial
11695                                gnus-newsgroup-name))
11696                      (input
11697                       (read-string
11698                        (format
11699                         "How many articles from %s (%s %d): "
11700                         (gnus-limit-string
11701                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11702                         (if initial "max" "default")
11703                         len)
11704                        (if initial
11705                            (cons (number-to-string initial)
11706                                  0)))))
11707                 (unless (string-match "^[ \t]*$" input)
11708                   (setq all (string-to-number input))
11709                   (if (< all len)
11710                       (let ((older-range (nreverse older)))
11711                         (setq older nil)
11712
11713                         (while (> all 0)
11714                           (let* ((r (pop older-range))
11715                                  (min (if (numberp r) r (car r)))
11716                                  (max (if (numberp r) r (cdr r))))
11717                             (while (and (<= min max)
11718                                         (> all 0))
11719                               (push max older)
11720                               (setq all (1- all)
11721                                     max (1- max))))))))))
11722           (setq older (gnus-uncompress-range older))))
11723         (if (not older)
11724             (message "No old news.")
11725           (gnus-summary-insert-articles older)
11726           (gnus-summary-limit (gnus-sorted-nunion old older))))
11727     (gnus-summary-position-point)))
11728
11729 (defun gnus-summary-insert-new-articles ()
11730   "Insert all new articles in this group."
11731   (interactive)
11732   (prog1
11733       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11734             (old-active gnus-newsgroup-active)
11735             (nnmail-fetched-sources (list t))
11736             i new)
11737         (setq gnus-newsgroup-active
11738               (gnus-activate-group gnus-newsgroup-name 'scan))
11739         (setq i (cdr gnus-newsgroup-active))
11740         (while (> i (cdr old-active))
11741           (push i new)
11742           (decf i))
11743         (if (not new)
11744             (message "No gnus is bad news.")
11745           (gnus-summary-insert-articles new)
11746           (setq gnus-newsgroup-unreads
11747                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11748           (gnus-summary-limit (gnus-sorted-nunion old new))))
11749     (gnus-summary-position-point)))
11750
11751 (gnus-summary-make-all-marking-commands)
11752
11753 (gnus-ems-redefine)
11754
11755 (provide 'gnus-sum)
11756
11757 (run-hooks 'gnus-sum-load-hook)
11758
11759 ;;; gnus-sum.el ends here