9ebc67656d46c84db087477d3a525dbff1f3d6f9
[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
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-set-summary-default-charset "gnus-i18n" nil t)
55 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
56 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58 (autoload 'gnus-article-outlook-deuglify-article "deuglify" 
59   "Deuglify broken Outlook (Express) articles and redisplay."
60   t)
61
62 (defcustom gnus-kill-summary-on-exit t
63   "*If non-nil, kill the summary buffer when you exit from it.
64 If nil, the summary will become a \"*Dead Summary*\" buffer, and
65 it will be killed sometime later."
66   :group 'gnus-summary-exit
67   :type 'boolean)
68
69 (defcustom gnus-fetch-old-headers nil
70   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
71 If an unread article in the group refers to an older, already read (or
72 just marked as read) article, the old article will not normally be
73 displayed in the Summary buffer.  If this variable is non-nil, Gnus
74 will attempt to grab the headers to the old articles, and thereby
75 build complete threads.  If it has the value `some', only enough
76 headers to connect otherwise loose threads will be displayed.  This
77 variable can also be a number.  In that case, no more than that number
78 of old headers will be fetched.  If it has the value `invisible', all
79 old headers will be fetched, but none will be displayed.
80
81 The server has to support NOV for any of this to work."
82   :group 'gnus-thread
83   :type '(choice (const :tag "off" nil)
84                  (const some)
85                  number
86                  (sexp :menu-tag "other" t)))
87
88 (defcustom gnus-refer-thread-limit 200
89   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
90 If t, fetch all the available old headers."
91   :group 'gnus-thread
92   :type '(choice number
93                  (sexp :menu-tag "other" t)))
94
95 (defcustom gnus-summary-make-false-root 'adopt
96   "*nil means that Gnus won't gather loose threads.
97 If the root of a thread has expired or been read in a previous
98 session, the information necessary to build a complete thread has been
99 lost.  Instead of having many small sub-threads from this original thread
100 scattered all over the summary buffer, Gnus can gather them.
101
102 If non-nil, Gnus will try to gather all loose sub-threads from an
103 original thread into one large thread.
104
105 If this variable is non-nil, it should be one of `none', `adopt',
106 `dummy' or `empty'.
107
108 If this variable is `none', Gnus will not make a false root, but just
109 present the sub-threads after another.
110 If this variable is `dummy', Gnus will create a dummy root that will
111 have all the sub-threads as children.
112 If this variable is `adopt', Gnus will make one of the \"children\"
113 the parent and mark all the step-children as such.
114 If this variable is `empty', the \"children\" are printed with empty
115 subject fields.  (Or rather, they will be printed with a string
116 given by the `gnus-summary-same-subject' variable.)"
117   :group 'gnus-thread
118   :type '(choice (const :tag "off" nil)
119                  (const none)
120                  (const dummy)
121                  (const adopt)
122                  (const empty)))
123
124 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
125   "*A regexp to match subjects to be excluded from loose thread gathering.
126 As loose thread gathering is done on subjects only, that means that
127 there can be many false gatherings performed.  By rooting out certain
128 common subjects, gathering might become saner."
129   :group 'gnus-thread
130   :type 'regexp)
131
132 (defcustom gnus-summary-gather-subject-limit nil
133   "*Maximum length of subject comparisons when gathering loose threads.
134 Use nil to compare full subjects.  Setting this variable to a low
135 number will help gather threads that have been corrupted by
136 newsreaders chopping off subject lines, but it might also mean that
137 unrelated articles that have subject that happen to begin with the
138 same few characters will be incorrectly gathered.
139
140 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
141 comparing subjects."
142   :group 'gnus-thread
143   :type '(choice (const :tag "off" nil)
144                  (const fuzzy)
145                  (sexp :menu-tag "on" t)))
146
147 (defcustom gnus-simplify-subject-functions nil
148   "List of functions taking a string argument that simplify subjects.
149 The functions are applied recursively.
150
151 Useful functions to put in this list include: `gnus-simplify-subject-re',
152 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
153   :group 'gnus-thread
154   :type '(repeat function))
155
156 (defcustom gnus-simplify-ignored-prefixes nil
157   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
158   :group 'gnus-thread
159   :type '(choice (const :tag "off" nil)
160                  regexp))
161
162 (defcustom gnus-build-sparse-threads nil
163   "*If non-nil, fill in the gaps in threads.
164 If `some', only fill in the gaps that are needed to tie loose threads
165 together.  If `more', fill in all leaf nodes that Gnus can find.  If
166 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  (const some)
170                  (const more)
171                  (sexp :menu-tag "all" t)))
172
173 (defcustom gnus-summary-thread-gathering-function
174   'gnus-gather-threads-by-subject
175   "*Function used for gathering loose threads.
176 There are two pre-defined functions: `gnus-gather-threads-by-subject',
177 which only takes Subjects into consideration; and
178 `gnus-gather-threads-by-references', which compared the References
179 headers of the articles to find matches."
180   :group 'gnus-thread
181   :type '(radio (function-item gnus-gather-threads-by-subject)
182                 (function-item gnus-gather-threads-by-references)
183                 (function :tag "other")))
184
185 (defcustom gnus-summary-same-subject ""
186   "*String indicating that the current article has the same subject as the previous.
187 This variable will only be used if the value of
188 `gnus-summary-make-false-root' is `empty'."
189   :group 'gnus-summary-format
190   :type 'string)
191
192 (defcustom gnus-summary-goto-unread t
193   "*If t, many commands will go to the next unread article.
194 This applies to marking commands as well as other commands that
195 \"naturally\" select the next article, like, for instance, `SPC' at
196 the end of an article.
197
198 If nil, the marking commands do NOT go to the next unread article
199 (they go to the next article instead).  If `never', commands that
200 usually go to the next unread article, will go to the next article,
201 whether it is read or not."
202   :group 'gnus-summary-marks
203   :link '(custom-manual "(gnus)Setting Marks")
204   :type '(choice (const :tag "off" nil)
205                  (const never)
206                  (sexp :menu-tag "on" t)))
207
208 (defcustom gnus-summary-default-score 0
209   "*Default article score level.
210 All scores generated by the score files will be added to this score.
211 If this variable is nil, scoring will be disabled."
212   :group 'gnus-score-default
213   :type '(choice (const :tag "disable")
214                  integer))
215
216 (defcustom gnus-summary-default-high-score 0
217   "*Default threshold for a high scored article.
218 An article will be highlighted as high scored if its score is greater
219 than this score."
220   :group 'gnus-score-default
221   :type 'integer)
222
223 (defcustom gnus-summary-default-low-score 0
224   "*Default threshold for a low scored article.
225 An article will be highlighted as low scored if its score is smaller
226 than this score."
227   :group 'gnus-score-default
228   :type 'integer)
229
230 (defcustom gnus-summary-zcore-fuzz 0
231   "*Fuzziness factor for the zcore in the summary buffer.
232 Articles with scores closer than this to `gnus-summary-default-score'
233 will not be marked."
234   :group 'gnus-summary-format
235   :type 'integer)
236
237 (defcustom gnus-simplify-subject-fuzzy-regexp nil
238   "*Strings to be removed when doing fuzzy matches.
239 This can either be a regular expression or list of regular expressions
240 that will be removed from subject strings if fuzzy subject
241 simplification is selected."
242   :group 'gnus-thread
243   :type '(repeat regexp))
244
245 (defcustom gnus-show-threads t
246   "*If non-nil, display threads in summary mode."
247   :group 'gnus-thread
248   :type 'boolean)
249
250 (defcustom gnus-thread-hide-subtree nil
251   "*If non-nil, hide all threads initially.
252 This can be a predicate specifier which says which threads to hide.
253 If threads are hidden, you have to run the command
254 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
255 to expose hidden threads."
256   :group 'gnus-thread
257   :type 'boolean)
258
259 (defcustom gnus-thread-hide-killed t
260   "*If non-nil, hide killed threads automatically."
261   :group 'gnus-thread
262   :type 'boolean)
263
264 (defcustom gnus-thread-ignore-subject t
265   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
266 If nil, articles that have different subjects from their parents will
267 start separate threads."
268   :group 'gnus-thread
269   :type 'boolean)
270
271 (defcustom gnus-thread-operation-ignore-subject t
272   "*If non-nil, subjects will be ignored when doing thread commands.
273 This affects commands like `gnus-summary-kill-thread' and
274 `gnus-summary-lower-thread'.
275
276 If this variable is nil, articles in the same thread with different
277 subjects will not be included in the operation in question.  If this
278 variable is `fuzzy', only articles that have subjects that are fuzzily
279 equal will be included."
280   :group 'gnus-thread
281   :type '(choice (const :tag "off" nil)
282                  (const fuzzy)
283                  (sexp :tag "on" t)))
284
285 (defcustom gnus-thread-indent-level 4
286   "*Number that says how much each sub-thread should be indented."
287   :group 'gnus-thread
288   :type 'integer)
289
290 (defcustom gnus-auto-extend-newsgroup t
291   "*If non-nil, extend newsgroup forward and backward when requested."
292   :group 'gnus-summary-choose
293   :type 'boolean)
294
295 (defcustom gnus-auto-select-first t
296   "*If non-nil, select the article under point.
297 Which article this is is controlled by the `gnus-auto-select-subject'
298 variable.
299
300 If you want to prevent automatic selection of articles in some
301 newsgroups, set the variable to nil in `gnus-select-group-hook'."
302   :group 'gnus-group-select
303   :type '(choice (const :tag "none" nil)
304                  (sexp :menu-tag "first" t)))
305
306 (defcustom gnus-auto-select-subject 'unread
307   "*Says what subject to place under point when entering a group.
308
309 This variable can either be the symbols `first' (place point on the
310 first subject), `unread' (place point on the subject line of the first
311 unread article), `best' (place point on the subject line of the
312 higest-scored article), `unseen' (place point on the subject line of
313 the first unseen article), 'unseen-or-unread' (place point on the subject
314 line of the first unseen article or, if all article have been seen, on the
315 subject line of the first unread article), or a function to be called to
316 place point on some subject line."
317   :group 'gnus-group-select
318   :type '(choice (const best)
319                  (const unread)
320                  (const first)
321                  (const unseen)
322                  (const unseen-or-unread)))
323
324 (defcustom gnus-dont-select-after-jump-to-other-group nil
325   "If non-nil, don't select the first unread article after entering the
326 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
327 it is depend on the value of `gnus-auto-select-first' whether to select
328 or not."
329   :group 'gnus-group-select
330   :type 'boolean)
331
332 (defcustom gnus-auto-select-next t
333   "*If non-nil, offer to go to the next group from the end of the previous.
334 If the value is t and the next newsgroup is empty, Gnus will exit
335 summary mode and go back to group mode.  If the value is neither nil
336 nor t, Gnus will select the following unread newsgroup.  In
337 particular, if the value is the symbol `quietly', the next unread
338 newsgroup will be selected without any confirmation, and if it is
339 `almost-quietly', the next group will be selected without any
340 confirmation if you are located on the last article in the group.
341 Finally, if this variable is `slightly-quietly', the `Z n' command
342 will go to the next group without confirmation."
343   :group 'gnus-summary-maneuvering
344   :type '(choice (const :tag "off" nil)
345                  (const quietly)
346                  (const almost-quietly)
347                  (const slightly-quietly)
348                  (sexp :menu-tag "on" t)))
349
350 (defcustom gnus-auto-select-same nil
351   "*If non-nil, select the next article with the same subject.
352 If there are no more articles with the same subject, go to
353 the first unread article."
354   :group 'gnus-summary-maneuvering
355   :type 'boolean)
356
357 (defcustom gnus-summary-check-current nil
358   "*If non-nil, consider the current article when moving.
359 The \"unread\" movement commands will stay on the same line if the
360 current article is unread."
361   :group 'gnus-summary-maneuvering
362   :type 'boolean)
363
364 (defcustom gnus-auto-center-summary t
365   "*If non-nil, always center the current summary buffer.
366 In particular, if `vertical' do only vertical recentering.  If non-nil
367 and non-`vertical', do both horizontal and vertical recentering."
368   :group 'gnus-summary-maneuvering
369   :type '(choice (const :tag "none" nil)
370                  (const vertical)
371                  (integer :tag "height")
372                  (sexp :menu-tag "both" t)))
373
374 (defcustom gnus-show-all-headers nil
375   "*If non-nil, don't hide any headers."
376   :group 'gnus-article-hiding
377   :group 'gnus-article-headers
378   :type 'boolean)
379
380 (defcustom gnus-summary-ignore-duplicates nil
381   "*If non-nil, ignore articles with identical Message-ID headers."
382   :group 'gnus-summary
383   :type 'boolean)
384
385 (defcustom gnus-single-article-buffer t
386   "*If non-nil, display all articles in the same buffer.
387 If nil, each group will get its own article buffer."
388   :group 'gnus-article-various
389   :type 'boolean)
390
391 (defcustom gnus-break-pages t
392   "*If non-nil, do page breaking on articles.
393 The page delimiter is specified by the `gnus-page-delimiter'
394 variable."
395   :group 'gnus-article-various
396   :type 'boolean)
397
398 (defcustom gnus-show-mime t
399   "*If non-nil, do mime processing of articles.
400 The articles will simply be fed to the function given by
401 `gnus-article-display-method-for-mime'."
402   :group 'gnus-article-mime
403   :type 'boolean)
404
405 (defcustom gnus-move-split-methods nil
406   "*Variable used to suggest where articles are to be moved to.
407 It uses the same syntax as the `gnus-split-methods' variable.
408 However, whereas `gnus-split-methods' specifies file names as targets,
409 this variable specifies group names."
410   :group 'gnus-summary-mail
411   :type '(repeat (choice (list :value (fun) function)
412                          (cons :value ("" "") regexp (repeat string))
413                          (sexp :value nil))))
414
415 (defcustom gnus-unread-mark ?\ ;;;Whitespace
416   "*Mark used for unread articles."
417   :group 'gnus-summary-marks
418   :type 'character)
419
420 (defcustom gnus-ticked-mark ?!
421   "*Mark used for ticked articles."
422   :group 'gnus-summary-marks
423   :type 'character)
424
425 (defcustom gnus-dormant-mark ??
426   "*Mark used for dormant articles."
427   :group 'gnus-summary-marks
428   :type 'character)
429
430 (defcustom gnus-del-mark ?r
431   "*Mark used for del'd articles."
432   :group 'gnus-summary-marks
433   :type 'character)
434
435 (defcustom gnus-read-mark ?R
436   "*Mark used for read articles."
437   :group 'gnus-summary-marks
438   :type 'character)
439
440 (defcustom gnus-expirable-mark ?E
441   "*Mark used for expirable articles."
442   :group 'gnus-summary-marks
443   :type 'character)
444
445 (defcustom gnus-killed-mark ?K
446   "*Mark used for killed articles."
447   :group 'gnus-summary-marks
448   :type 'character)
449
450 (defcustom gnus-souped-mark ?F
451   "*Mark used for souped articles."
452   :group 'gnus-summary-marks
453   :type 'character)
454
455 (defcustom gnus-kill-file-mark ?X
456   "*Mark used for articles killed by kill files."
457   :group 'gnus-summary-marks
458   :type 'character)
459
460 (defcustom gnus-low-score-mark ?Y
461   "*Mark used for articles with a low score."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-catchup-mark ?C
466   "*Mark used for articles that are caught up."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-replied-mark ?A
471   "*Mark used for articles that have been replied to."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-forwarded-mark ?F
476   "*Mark used for articles that have been forwarded."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-recent-mark ?N
481   "*Mark used for articles that are recent."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-cached-mark ?*
486   "*Mark used for articles that are in the cache."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-saved-mark ?S
491   "*Mark used for articles that have been saved."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-unseen-mark ?.
496   "*Mark used for articles that haven't been seen."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-no-mark ?\ ;;;Whitespace
501   "*Mark used for articles that have no other secondary mark."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-ancient-mark ?O
506   "*Mark used for ancient articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-sparse-mark ?Q
511   "*Mark used for sparsely reffed articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-canceled-mark ?G
516   "*Mark used for canceled articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-duplicate-mark ?M
521   "*Mark used for duplicate articles."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-undownloaded-mark ?@
526   "*Mark used for articles that weren't downloaded."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-downloadable-mark ?%
531   "*Mark used for articles that are to be downloaded."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-unsendable-mark ?=
536   "*Mark used for articles that won't be sent."
537   :group 'gnus-summary-marks
538   :type 'character)
539
540 (defcustom gnus-score-over-mark ?+
541   "*Score mark used for articles with high scores."
542   :group 'gnus-summary-marks
543   :type 'character)
544
545 (defcustom gnus-score-below-mark ?-
546   "*Score mark used for articles with low scores."
547   :group 'gnus-summary-marks
548   :type 'character)
549
550 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
551   "*There is no thread under the article."
552   :group 'gnus-summary-marks
553   :type 'character)
554
555 (defcustom gnus-not-empty-thread-mark ?=
556   "*There is a thread under the article."
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-view-pseudo-asynchronously nil
561   "*If non-nil, Gnus will view pseudo-articles asynchronously."
562   :group 'gnus-extract-view
563   :type 'boolean)
564
565 (defcustom gnus-auto-expirable-marks
566   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
567         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
568         gnus-souped-mark gnus-duplicate-mark)
569   "*The list of marks converted into expiration if a group is auto-expirable."
570   :version "21.1"
571   :group 'gnus-summary
572   :type '(repeat character))
573
574 (defcustom gnus-inhibit-user-auto-expire t
575   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
576   :version "21.1"
577   :group 'gnus-summary
578   :type 'boolean)
579
580 (defcustom gnus-view-pseudos nil
581   "*If `automatic', pseudo-articles will be viewed automatically.
582 If `not-confirm', pseudos will be viewed automatically, and the user
583 will not be asked to confirm the command."
584   :group 'gnus-extract-view
585   :type '(choice (const :tag "off" nil)
586                  (const automatic)
587                  (const not-confirm)))
588
589 (defcustom gnus-view-pseudos-separately t
590   "*If non-nil, one pseudo-article will be created for each file to be viewed.
591 If nil, all files that use the same viewing command will be given as a
592 list of parameters to that command."
593   :group 'gnus-extract-view
594   :type 'boolean)
595
596 (defcustom gnus-insert-pseudo-articles t
597   "*If non-nil, insert pseudo-articles when decoding articles."
598   :group 'gnus-extract-view
599   :type 'boolean)
600
601 (defcustom gnus-summary-dummy-line-format
602   "  %(:                          :%) %S\n"
603   "*The format specification for the dummy roots in the summary buffer.
604 It works along the same lines as a normal formatting string,
605 with some simple extensions.
606
607 %S  The subject
608
609 General format specifiers can also be used.
610 See (gnus)Formatting Variables."
611   :link '(custom-manual "(gnus)Formatting Variables")
612   :group 'gnus-threading
613   :type 'string)
614
615 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
616   "*The format specification for the summary mode line.
617 It works along the same lines as a normal formatting string,
618 with some simple extensions:
619
620 %G  Group name
621 %p  Unprefixed group name
622 %A  Current article number
623 %z  Current article score
624 %V  Gnus version
625 %U  Number of unread articles in the group
626 %e  Number of unselected articles in the group
627 %Z  A string with unread/unselected article counts
628 %g  Shortish group name
629 %S  Subject of the current article
630 %u  User-defined spec
631 %s  Current score file name
632 %d  Number of dormant articles
633 %r  Number of articles that have been marked as read in this session
634 %E  Number of articles expunged by the score files"
635   :group 'gnus-summary-format
636   :type 'string)
637
638 (defcustom gnus-list-identifiers nil
639   "Regexp that matches list identifiers to be removed from subject.
640 This can also be a list of regexps."
641   :version "21.1"
642   :group 'gnus-summary-format
643   :group 'gnus-article-hiding
644   :type '(choice (const :tag "none" nil)
645                  (regexp :value ".*")
646                  (repeat :value (".*") regexp)))
647
648 (defcustom gnus-summary-mark-below 0
649   "*Mark all articles with a score below this variable as read.
650 This variable is local to each summary buffer and usually set by the
651 score file."
652   :group 'gnus-score-default
653   :type 'integer)
654
655 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
656   "*List of functions used for sorting articles in the summary buffer.
657
658 Each function takes two articles and returns non-nil if the first
659 article should be sorted before the other.  If you use more than one
660 function, the primary sort function should be the last.  You should
661 probably always include `gnus-article-sort-by-number' in the list of
662 sorting functions -- preferably first.  Also note that sorting by date
663 is often much slower than sorting by number, and the sorting order is
664 very similar.  (Sorting by date means sorting by the time the message
665 was sent, sorting by number means sorting by arrival time.)
666
667 Ready-made functions include `gnus-article-sort-by-number',
668 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
669 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
670
671 When threading is turned on, the variable `gnus-thread-sort-functions'
672 controls how articles are sorted."
673   :group 'gnus-summary-sort
674   :type '(repeat (choice (function-item gnus-article-sort-by-number)
675                          (function-item gnus-article-sort-by-author)
676                          (function-item gnus-article-sort-by-subject)
677                          (function-item gnus-article-sort-by-date)
678                          (function-item gnus-article-sort-by-score)
679                          (function :tag "other"))))
680
681 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
682   "*List of functions used for sorting threads in the summary buffer.
683 By default, threads are sorted by article number.
684
685 Each function takes two threads and returns non-nil if the first
686 thread should be sorted before the other.  If you use more than one
687 function, the primary sort function should be the last.  You should
688 probably always include `gnus-thread-sort-by-number' in the list of
689 sorting functions -- preferably first.  Also note that sorting by date
690 is often much slower than sorting by number, and the sorting order is
691 very similar.  (Sorting by date means sorting by the time the message
692 was sent, sorting by number means sorting by arrival time.)
693
694 Ready-made functions include `gnus-thread-sort-by-number',
695 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
696 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
697 `gnus-thread-sort-by-most-recent-number',
698 `gnus-thread-sort-by-most-recent-date', and
699 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
700
701 When threading is turned off, the variable
702 `gnus-article-sort-functions' controls how articles are sorted."
703   :group 'gnus-summary-sort
704   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
705                          (function-item gnus-thread-sort-by-author)
706                          (function-item gnus-thread-sort-by-subject)
707                          (function-item gnus-thread-sort-by-date)
708                          (function-item gnus-thread-sort-by-score)
709                          (function-item gnus-thread-sort-by-total-score)
710                          (function :tag "other"))))
711
712 (defcustom gnus-thread-score-function '+
713   "*Function used for calculating the total score of a thread.
714
715 The function is called with the scores of the article and each
716 subthread and should then return the score of the thread.
717
718 Some functions you can use are `+', `max', or `min'."
719   :group 'gnus-summary-sort
720   :type 'function)
721
722 (defcustom gnus-summary-expunge-below nil
723   "All articles that have a score less than this variable will be expunged.
724 This variable is local to the summary buffers."
725   :group 'gnus-score-default
726   :type '(choice (const :tag "off" nil)
727                  integer))
728
729 (defcustom gnus-thread-expunge-below nil
730   "All threads that have a total score less than this variable will be expunged.
731 See `gnus-thread-score-function' for en explanation of what a
732 \"thread score\" is.
733
734 This variable is local to the summary buffers."
735   :group 'gnus-threading
736   :group 'gnus-score-default
737   :type '(choice (const :tag "off" nil)
738                  integer))
739
740 (defcustom gnus-summary-mode-hook nil
741   "*A hook for Gnus summary mode.
742 This hook is run before any variables are set in the summary buffer."
743   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
744   :group 'gnus-summary-various
745   :type 'hook)
746
747 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
748 (when (featurep 'xemacs)
749   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
750   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
751   (add-hook 'gnus-summary-mode-hook
752             'gnus-xmas-switch-horizontal-scrollbar-off))
753
754 (defcustom gnus-summary-menu-hook nil
755   "*Hook run after the creation of the summary mode menu."
756   :group 'gnus-summary-visual
757   :type 'hook)
758
759 (defcustom gnus-summary-exit-hook nil
760   "*A hook called on exit from the summary buffer.
761 It will be called with point in the group buffer."
762   :group 'gnus-summary-exit
763   :type 'hook)
764
765 (defcustom gnus-summary-prepare-hook nil
766   "*A hook called after the summary buffer has been generated.
767 If you want to modify the summary buffer, you can use this hook."
768   :group 'gnus-summary-various
769   :type 'hook)
770
771 (defcustom gnus-summary-prepared-hook nil
772   "*A hook called as the last thing after the summary buffer has been generated."
773   :group 'gnus-summary-various
774   :type 'hook)
775
776 (defcustom gnus-summary-generate-hook nil
777   "*A hook run just before generating the summary buffer.
778 This hook is commonly used to customize threading variables and the
779 like."
780   :group 'gnus-summary-various
781   :type 'hook)
782
783 (defcustom gnus-select-group-hook nil
784   "*A hook called when a newsgroup is selected.
785
786 If you'd like to simplify subjects like the
787 `gnus-summary-next-same-subject' command does, you can use the
788 following hook:
789
790  (add-hook gnus-select-group-hook
791            (lambda ()
792              (mapcar (lambda (header)
793                        (mail-header-set-subject
794                         header
795                         (gnus-simplify-subject
796                          (mail-header-subject header) 're-only)))
797                      gnus-newsgroup-headers)))"
798   :group 'gnus-group-select
799   :type 'hook)
800
801 (defcustom gnus-select-article-hook nil
802   "*A hook called when an article is selected."
803   :group 'gnus-summary-choose
804   :type 'hook)
805
806 (defcustom gnus-visual-mark-article-hook
807   (list 'gnus-highlight-selected-summary)
808   "*Hook run after selecting an article in the summary buffer.
809 It is meant to be used for highlighting the article in some way.  It
810 is not run if `gnus-visual' is nil."
811   :group 'gnus-summary-visual
812   :type 'hook)
813
814 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
815   "*A hook called before parsing the headers."
816   :group 'gnus-various
817   :type 'hook)
818
819 (defcustom gnus-exit-group-hook nil
820   "*A hook called when exiting summary mode.
821 This hook is not called from the non-updating exit commands like `Q'."
822   :group 'gnus-various
823   :type 'hook)
824
825 (defcustom gnus-summary-update-hook
826   (list 'gnus-summary-highlight-line)
827   "*A hook called when a summary line is changed.
828 The hook will not be called if `gnus-visual' is nil.
829
830 The default function `gnus-summary-highlight-line' will
831 highlight the line according to the `gnus-summary-highlight'
832 variable."
833   :group 'gnus-summary-visual
834   :type 'hook)
835
836 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
837   "*A hook called when an article is selected for the first time.
838 The hook is intended to mark an article as read (or unread)
839 automatically when it is selected."
840   :group 'gnus-summary-choose
841   :type 'hook)
842
843 (defcustom gnus-group-no-more-groups-hook nil
844   "*A hook run when returning to group mode having no more (unread) groups."
845   :group 'gnus-group-select
846   :type 'hook)
847
848 (defcustom gnus-ps-print-hook nil
849   "*A hook run before ps-printing something from Gnus."
850   :group 'gnus-summary
851   :type 'hook)
852
853 (defcustom gnus-summary-display-arrow
854   (and (fboundp 'display-graphic-p)
855        (display-graphic-p))
856   "*If non-nil, display an arrow highlighting the current article."
857   :version "21.1"
858   :group 'gnus-summary
859   :type 'boolean)
860
861 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
862   "Face used for highlighting the current article in the summary buffer."
863   :group 'gnus-summary-visual
864   :type 'face)
865
866 (defcustom gnus-summary-highlight
867   '(((= mark gnus-canceled-mark)
868      . gnus-summary-cancelled-face)
869     ((and (> score default-high)
870           (or (= mark gnus-dormant-mark)
871               (= mark gnus-ticked-mark)))
872      . gnus-summary-high-ticked-face)
873     ((and (< score default-low)
874           (or (= mark gnus-dormant-mark)
875               (= mark gnus-ticked-mark)))
876      . gnus-summary-low-ticked-face)
877     ((or (= mark gnus-dormant-mark)
878          (= mark gnus-ticked-mark))
879      . gnus-summary-normal-ticked-face)
880     ((and (> score default-high) (= mark gnus-ancient-mark))
881      . gnus-summary-high-ancient-face)
882     ((and (< score default-low) (= mark gnus-ancient-mark))
883      . gnus-summary-low-ancient-face)
884     ((= mark gnus-ancient-mark)
885      . gnus-summary-normal-ancient-face)
886     ((and (> score default-high) (= mark gnus-unread-mark))
887      . gnus-summary-high-unread-face)
888     ((and (< score default-low) (= mark gnus-unread-mark))
889      . gnus-summary-low-unread-face)
890     ((= mark gnus-unread-mark)
891      . gnus-summary-normal-unread-face)
892     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
893                                                   gnus-undownloaded-mark)))
894      . gnus-summary-high-unread-face)
895     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
896                                                  gnus-undownloaded-mark)))
897      . gnus-summary-low-unread-face)
898     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
899           (memq article gnus-newsgroup-unreads))
900      . gnus-summary-normal-unread-face)
901     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
902      . gnus-summary-normal-read-face)
903     ((> score default-high)
904      . gnus-summary-high-read-face)
905     ((< score default-low)
906      . gnus-summary-low-read-face)
907     (t
908      . gnus-summary-normal-read-face))
909   "*Controls the highlighting of summary buffer lines.
910
911 A list of (FORM . FACE) pairs.  When deciding how a a particular
912 summary line should be displayed, each form is evaluated.  The content
913 of the face field after the first true form is used.  You can change
914 how those summary lines are displayed, by editing the face field.
915
916 You can use the following variables in the FORM field.
917
918 score:        The article's score
919 default:      The default article score.
920 default-high: The default score for high scored articles.
921 default-low:  The default score for low scored articles.
922 below:        The score below which articles are automatically marked as read.
923 mark:         The articles mark."
924   :group 'gnus-summary-visual
925   :type '(repeat (cons (sexp :tag "Form" nil)
926                        face)))
927
928 (defcustom gnus-alter-header-function nil
929   "Function called to allow alteration of article header structures.
930 The function is called with one parameter, the article header vector,
931 which it may alter in any way.")
932
933 (defvar gnus-decode-encoded-word-function
934   (mime-find-field-decoder 'From 'nov)
935   "Variable that says which function should be used to decode a string with encoded words.")
936
937 (defcustom gnus-extra-headers '(To Newsgroups)
938   "*Extra headers to parse."
939   :version "21.1"
940   :group 'gnus-summary
941   :type '(repeat symbol))
942
943 (defcustom gnus-ignored-from-addresses
944   (and user-mail-address (regexp-quote user-mail-address))
945   "*Regexp of From headers that may be suppressed in favor of To headers."
946   :version "21.1"
947   :group 'gnus-summary
948   :type 'regexp)
949
950 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
951   "List of charsets that should be ignored.
952 When these charsets are used in the \"charset\" parameter, the
953 default charset will be used instead."
954   :version "21.1"
955   :type '(repeat symbol)
956   :group 'gnus-charset)
957
958 (gnus-define-group-parameter
959  ignored-charsets
960  :type list
961  :function-document
962  "Return the ignored charsets of GROUP."
963  :variable gnus-group-ignored-charsets-alist
964  :variable-default
965  '(("alt\\.chinese\\.text" iso-8859-1))
966  :variable-document
967  "Alist of regexps (to match group names) and charsets that should be ignored.
968 When these charsets are used in the \"charset\" parameter, the
969 default charset will be used instead."
970  :variable-group gnus-charset
971  :variable-type '(repeat (cons (regexp :tag "Group")
972                                (repeat symbol)))
973  :parameter-type '(choice :tag "Ignored charsets"
974                           :value nil
975                           (repeat (symbol)))
976  :parameter-document       "\
977 List of charsets that should be ignored.
978
979 When these charsets are used in the \"charset\" parameter, the
980 default charset will be used instead.")
981
982 (defcustom gnus-group-highlight-words-alist nil
983   "Alist of group regexps and highlight regexps.
984 This variable uses the same syntax as `gnus-emphasis-alist'."
985   :version "21.1"
986   :type '(repeat (cons (regexp :tag "Group")
987                        (repeat (list (regexp :tag "Highlight regexp")
988                                      (number :tag "Group for entire word" 0)
989                                      (number :tag "Group for displayed part" 0)
990                                      (symbol :tag "Face"
991                                              gnus-emphasis-highlight-words)))))
992   :group 'gnus-summary-visual)
993
994 (defcustom gnus-use-wheel nil
995   "Use Intelli-mouse on summary movement"
996   :type 'boolean
997   :group 'gnus-summary-maneuvering)
998
999 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1000   "Amount to scroll messages by spinning the mouse wheel.
1001 This is actually a cons cell, where the first item is the amount to scroll
1002 on a normal wheel event, and the second is the amount to scroll when the
1003 wheel is moved with the shift key depressed."
1004   :type '(cons (integer :tag "Shift") integer)
1005   :group 'gnus-summary-maneuvering)
1006
1007 (defcustom gnus-wheel-edge-resistance 2
1008   "How hard it should be to change the current article
1009 by moving the mouse over the edge of the article window."
1010   :type 'integer
1011   :group 'gnus-summary-maneuvering)
1012
1013 (defcustom gnus-summary-show-article-charset-alist
1014   nil
1015   "Alist of number and charset.
1016 The article will be shown with the charset corresponding to the
1017 numbered argument.
1018 For example: ((1 . cn-gb-2312) (2 . big5))."
1019   :version "21.1"
1020   :type '(repeat (cons (number :tag "Argument" 1)
1021                        (symbol :tag "Charset")))
1022   :group 'gnus-charset)
1023
1024 (defcustom gnus-preserve-marks t
1025   "Whether marks are preserved when moving, copying and respooling messages."
1026   :version "21.1"
1027   :type 'boolean
1028   :group 'gnus-summary-marks)
1029
1030 (defcustom gnus-alter-articles-to-read-function nil
1031   "Function to be called to alter the list of articles to be selected."
1032   :type '(choice (const nil) function)
1033   :group 'gnus-summary)
1034
1035 (defcustom gnus-orphan-score nil
1036   "*All orphans get this score added.  Set in the score file."
1037   :group 'gnus-score-default
1038   :type '(choice (const nil)
1039                  integer))
1040
1041 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1042   "*A regexp to match MIME parts when saving multiple parts of a message
1043 with gnus-summary-save-parts (X m). This regexp will be used by default
1044 when prompting the user for which type of files to save."
1045   :group 'gnus-summary
1046   :type 'regexp)
1047
1048
1049 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1050   "*A regexp to match MIME parts when saving multiple parts of a message
1051 with gnus-summary-save-parts (X m). This regexp will be used by default
1052 when prompting the user for which type of files to save."
1053   :group 'gnus-summary
1054   :type 'regexp)
1055
1056 (defcustom gnus-read-all-available-headers nil
1057   "Whether Gnus should parse all headers made available to it.
1058 This is mostly relevant for slow backends where the user may
1059 wish to widen the summary buffer to include all headers
1060 that were fetched.  Say, for nnultimate groups."
1061   :group 'gnus-summary
1062   :type '(choice boolean regexp))
1063
1064 (defcustom gnus-summary-muttprint-program "muttprint"
1065   "Command (and optional arguments) used to run Muttprint."
1066   :version "21.3"
1067   :group 'gnus-summary
1068   :type 'string)
1069
1070 (defcustom gnus-article-loose-mime nil
1071   "If non-nil, don't require MIME-Version header.
1072 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1073 supply the MIME-Version header or deliberately strip it From the mail.
1074 Set it to non-nil, Gnus will treat some articles as MIME even if
1075 the MIME-Version header is missed."
1076   :version "21.3"
1077   :type 'boolean
1078   :group 'gnus-article)
1079
1080 ;;; Internal variables
1081
1082 (defvar gnus-summary-display-cache nil)
1083 (defvar gnus-article-mime-handles nil)
1084 (defvar gnus-article-decoded-p nil)
1085 (defvar gnus-article-charset nil)
1086 (defvar gnus-article-ignored-charsets nil)
1087 (defvar gnus-scores-exclude-files nil)
1088 (defvar gnus-page-broken nil)
1089 (defvar gnus-inhibit-mime-unbuttonizing nil)
1090
1091 (defvar gnus-original-article nil)
1092 (defvar gnus-article-internal-prepare-hook nil)
1093 (defvar gnus-newsgroup-process-stack nil)
1094
1095 (defvar gnus-thread-indent-array nil)
1096 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1097 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1098   "Function called to sort the articles within a thread after it has been gathered together.")
1099
1100 (defvar gnus-summary-save-parts-type-history nil)
1101 (defvar gnus-summary-save-parts-last-directory nil)
1102
1103 (defvar gnus-summary-save-parts-type-history nil)
1104 (defvar gnus-summary-save-parts-last-directory nil)
1105
1106 ;; Avoid highlighting in kill files.
1107 (defvar gnus-summary-inhibit-highlight nil)
1108 (defvar gnus-newsgroup-selected-overlay nil)
1109 (defvar gnus-inhibit-limiting nil)
1110 (defvar gnus-newsgroup-adaptive-score-file nil)
1111 (defvar gnus-current-score-file nil)
1112 (defvar gnus-current-move-group nil)
1113 (defvar gnus-current-copy-group nil)
1114 (defvar gnus-current-crosspost-group nil)
1115 (defvar gnus-newsgroup-display nil)
1116
1117 (defvar gnus-newsgroup-dependencies nil)
1118 (defvar gnus-newsgroup-adaptive nil)
1119 (defvar gnus-summary-display-article-function nil)
1120 (defvar gnus-summary-highlight-line-function nil
1121   "Function called after highlighting a summary line.")
1122
1123 (defvar gnus-summary-line-format-alist
1124   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1125     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1126     (?s gnus-tmp-subject-or-nil ?s)
1127     (?n gnus-tmp-name ?s)
1128     (?A (std11-address-string
1129          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1130     (?a (or (std11-full-name-string
1131              (car (mime-entity-read-field gnus-tmp-header 'From)))
1132             gnus-tmp-from) ?s)
1133     (?F gnus-tmp-from ?s)
1134     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1135     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1136     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1137     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1138     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1139     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1140     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1141     (?L gnus-tmp-lines ?s)
1142     (?I gnus-tmp-indentation ?s)
1143     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1144     (?R gnus-tmp-replied ?c)
1145     (?\[ gnus-tmp-opening-bracket ?c)
1146     (?\] gnus-tmp-closing-bracket ?c)
1147     (?\> (make-string gnus-tmp-level ? ) ?s)
1148     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1149     (?i gnus-tmp-score ?d)
1150     (?z gnus-tmp-score-char ?c)
1151     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1152     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1153     (?U gnus-tmp-unread ?c)
1154     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1155         ?s)
1156     (?t (gnus-summary-number-of-articles-in-thread
1157          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1158         ?d)
1159     (?e (gnus-summary-number-of-articles-in-thread
1160          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1161         ?c)
1162     (?u gnus-tmp-user-defined ?s)
1163     (?P (gnus-pick-line-number) ?d)
1164     (?B gnus-tmp-thread-tree-header-string ?s)
1165     (user-date (gnus-user-date
1166                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1167   "An alist of format specifications that can appear in summary lines.
1168 These are paired with what variables they correspond with, along with
1169 the type of the variable (string, integer, character, etc).")
1170
1171 (defvar gnus-summary-dummy-line-format-alist
1172   `((?S gnus-tmp-subject ?s)
1173     (?N gnus-tmp-number ?d)
1174     (?u gnus-tmp-user-defined ?s)))
1175
1176 (defvar gnus-summary-mode-line-format-alist
1177   `((?G gnus-tmp-group-name ?s)
1178     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1179     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1180     (?A gnus-tmp-article-number ?d)
1181     (?Z gnus-tmp-unread-and-unselected ?s)
1182     (?V gnus-version ?s)
1183     (?U gnus-tmp-unread-and-unticked ?d)
1184     (?S gnus-tmp-subject ?s)
1185     (?e gnus-tmp-unselected ?d)
1186     (?u gnus-tmp-user-defined ?s)
1187     (?d (length gnus-newsgroup-dormant) ?d)
1188     (?t (length gnus-newsgroup-marked) ?d)
1189     (?r (length gnus-newsgroup-reads) ?d)
1190     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1191     (?E gnus-newsgroup-expunged-tally ?d)
1192     (?s (gnus-current-score-file-nondirectory) ?s)))
1193
1194 (defvar gnus-last-search-regexp nil
1195   "Default regexp for article search command.")
1196
1197 (defvar gnus-summary-search-article-matched-data nil
1198   "Last matched data of article search command.  It is the local variable
1199 in `gnus-article-buffer' which consists of the list of start position,
1200 end position and text.")
1201
1202 (defvar gnus-last-shell-command nil
1203   "Default shell command on article.")
1204
1205 (defvar gnus-newsgroup-begin nil)
1206 (defvar gnus-newsgroup-end nil)
1207 (defvar gnus-newsgroup-last-rmail nil)
1208 (defvar gnus-newsgroup-last-mail nil)
1209 (defvar gnus-newsgroup-last-folder nil)
1210 (defvar gnus-newsgroup-last-file nil)
1211 (defvar gnus-newsgroup-auto-expire nil)
1212 (defvar gnus-newsgroup-active nil)
1213
1214 (defvar gnus-newsgroup-data nil)
1215 (defvar gnus-newsgroup-data-reverse nil)
1216 (defvar gnus-newsgroup-limit nil)
1217 (defvar gnus-newsgroup-limits nil)
1218
1219 (defvar gnus-newsgroup-unreads nil
1220   "Sorted list of unread articles in the current newsgroup.")
1221
1222 (defvar gnus-newsgroup-unselected nil
1223   "Sorted list of unselected unread articles in the current newsgroup.")
1224
1225 (defvar gnus-newsgroup-reads nil
1226   "Alist of read articles and article marks in the current newsgroup.")
1227
1228 (defvar gnus-newsgroup-expunged-tally nil)
1229
1230 (defvar gnus-newsgroup-marked nil
1231   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1232
1233 (defvar gnus-newsgroup-killed nil
1234   "List of ranges of articles that have been through the scoring process.")
1235
1236 (defvar gnus-newsgroup-cached nil
1237   "Sorted list of articles that come from the article cache.")
1238
1239 (defvar gnus-newsgroup-saved nil
1240   "List of articles that have been saved.")
1241
1242 (defvar gnus-newsgroup-kill-headers nil)
1243
1244 (defvar gnus-newsgroup-replied nil
1245   "List of articles that have been replied to in the current newsgroup.")
1246
1247 (defvar gnus-newsgroup-forwarded nil
1248   "List of articles that have been forwarded in the current newsgroup.")
1249
1250 (defvar gnus-newsgroup-recent nil
1251   "List of articles that have are recent in the current newsgroup.")
1252
1253 (defvar gnus-newsgroup-expirable nil
1254   "Sorted list of articles in the current newsgroup that can be expired.")
1255
1256 (defvar gnus-newsgroup-processable nil
1257   "List of articles in the current newsgroup that can be processed.")
1258
1259 (defvar gnus-newsgroup-downloadable nil
1260   "Sorted list of articles in the current newsgroup that can be processed.")
1261
1262 (defvar gnus-newsgroup-undownloaded nil
1263   "List of articles in the current newsgroup that haven't been downloaded..")
1264
1265 (defvar gnus-newsgroup-unsendable nil
1266   "List of articles in the current newsgroup that won't be sent.")
1267
1268 (defvar gnus-newsgroup-bookmarks nil
1269   "List of articles in the current newsgroup that have bookmarks.")
1270
1271 (defvar gnus-newsgroup-dormant nil
1272   "Sorted list of dormant articles in the current newsgroup.")
1273
1274 (defvar gnus-newsgroup-unseen nil
1275   "List of unseen articles in the current newsgroup.")
1276
1277 (defvar gnus-newsgroup-seen nil
1278   "Range of seen articles in the current newsgroup.")
1279
1280 (defvar gnus-newsgroup-articles nil
1281   "List of articles in the current newsgroup.")
1282
1283 (defvar gnus-newsgroup-scored nil
1284   "List of scored articles in the current newsgroup.")
1285
1286 (defvar gnus-newsgroup-incorporated nil
1287   "List of incorporated articles in the current newsgroup.")
1288
1289 (defvar gnus-newsgroup-headers nil
1290   "List of article headers in the current newsgroup.")
1291
1292 (defvar gnus-newsgroup-threads nil)
1293
1294 (defvar gnus-newsgroup-prepared nil
1295   "Whether the current group has been prepared properly.")
1296
1297 (defvar gnus-newsgroup-ancient nil
1298   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1299
1300 (defvar gnus-newsgroup-sparse nil)
1301
1302 (defvar gnus-current-article nil)
1303 (defvar gnus-article-current nil)
1304 (defvar gnus-current-headers nil)
1305 (defvar gnus-have-all-headers nil)
1306 (defvar gnus-last-article nil)
1307 (defvar gnus-newsgroup-history nil)
1308 (defvar gnus-newsgroup-charset nil)
1309 (defvar gnus-newsgroup-ephemeral-charset nil)
1310 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1311
1312 (defvar gnus-article-before-search nil)
1313
1314 (defconst gnus-summary-local-variables
1315   '(gnus-newsgroup-name
1316     gnus-newsgroup-begin gnus-newsgroup-end
1317     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1318     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1319     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1320     gnus-newsgroup-unselected gnus-newsgroup-marked
1321     gnus-newsgroup-reads gnus-newsgroup-saved
1322     gnus-newsgroup-replied gnus-newsgroup-forwarded
1323     gnus-newsgroup-recent
1324     gnus-newsgroup-expirable
1325     gnus-newsgroup-processable gnus-newsgroup-killed
1326     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1327     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1328     gnus-newsgroup-seen gnus-newsgroup-articles
1329     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1330     gnus-newsgroup-headers gnus-newsgroup-threads
1331     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1332     gnus-current-article gnus-current-headers gnus-have-all-headers
1333     gnus-last-article gnus-article-internal-prepare-hook
1334     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1335     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1336     gnus-thread-expunge-below
1337     gnus-score-alist gnus-current-score-file
1338     (gnus-summary-expunge-below . global)
1339     (gnus-summary-mark-below . global)
1340     (gnus-orphan-score . global)
1341     gnus-newsgroup-active gnus-scores-exclude-files
1342     gnus-newsgroup-history gnus-newsgroup-ancient
1343     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1344     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1345     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1346     (gnus-newsgroup-expunged-tally . 0)
1347     gnus-cache-removable-articles gnus-newsgroup-cached
1348     gnus-newsgroup-data gnus-newsgroup-data-reverse
1349     gnus-newsgroup-limit gnus-newsgroup-limits
1350     gnus-newsgroup-charset gnus-newsgroup-display
1351     gnus-newsgroup-incorporated)
1352   "Variables that are buffer-local to the summary buffers.")
1353
1354 (defvar gnus-newsgroup-variables nil
1355   "A list of variables that have separate values in different newsgroups.
1356 A list of newsgroup (summary buffer) local variables, or cons of
1357 variables and their default values (when the default values are not
1358 nil), that should be made global while the summary buffer is active.
1359 These variables can be used to set variables in the group parameters
1360 while still allowing them to affect operations done in other
1361 buffers. For example:
1362
1363 \(setq gnus-newsgroup-variables
1364      '(message-use-followup-to
1365        (gnus-visible-headers .
1366          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1367 ")
1368
1369 ;; Byte-compiler warning.
1370 (eval-when-compile (defvar gnus-article-mode-map))
1371
1372 ;; Subject simplification.
1373
1374 (defun gnus-simplify-whitespace (str)
1375   "Remove excessive whitespace from STR."
1376   (let ((mystr str))
1377     ;; Multiple spaces.
1378     (while (string-match "[ \t][ \t]+" mystr)
1379       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1380                           " "
1381                           (substring mystr (match-end 0)))))
1382     ;; Leading spaces.
1383     (when (string-match "^[ \t]+" mystr)
1384       (setq mystr (substring mystr (match-end 0))))
1385     ;; Trailing spaces.
1386     (when (string-match "[ \t]+$" mystr)
1387       (setq mystr (substring mystr 0 (match-beginning 0))))
1388     mystr))
1389
1390 (defsubst gnus-simplify-subject-re (subject)
1391   "Remove \"Re:\" from subject lines."
1392   (if (string-match message-subject-re-regexp subject)
1393       (substring subject (match-end 0))
1394     subject))
1395
1396 (defun gnus-simplify-subject (subject &optional re-only)
1397   "Remove `Re:' and words in parentheses.
1398 If RE-ONLY is non-nil, strip leading `Re:'s only."
1399   (let ((case-fold-search t))           ;Ignore case.
1400     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1401     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1402       (setq subject (substring subject (match-end 0))))
1403     ;; Remove uninteresting prefixes.
1404     (when (and (not re-only)
1405                gnus-simplify-ignored-prefixes
1406                (string-match gnus-simplify-ignored-prefixes subject))
1407       (setq subject (substring subject (match-end 0))))
1408     ;; Remove words in parentheses from end.
1409     (unless re-only
1410       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1411         (setq subject (substring subject 0 (match-beginning 0)))))
1412     ;; Return subject string.
1413     subject))
1414
1415 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1416 ;; all whitespace.
1417 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1418   (goto-char (point-min))
1419   (while (re-search-forward regexp nil t)
1420     (replace-match (or newtext ""))))
1421
1422 (defun gnus-simplify-buffer-fuzzy ()
1423   "Simplify string in the buffer fuzzily.
1424 The string in the accessible portion of the current buffer is simplified.
1425 It is assumed to be a single-line subject.
1426 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1427 matter is removed.  Additional things can be deleted by setting
1428 `gnus-simplify-subject-fuzzy-regexp'."
1429   (let ((case-fold-search t)
1430         (modified-tick))
1431     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1432
1433     (while (not (eq modified-tick (buffer-modified-tick)))
1434       (setq modified-tick (buffer-modified-tick))
1435       (cond
1436        ((listp gnus-simplify-subject-fuzzy-regexp)
1437         (mapcar 'gnus-simplify-buffer-fuzzy-step
1438                 gnus-simplify-subject-fuzzy-regexp))
1439        (gnus-simplify-subject-fuzzy-regexp
1440         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1441       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1442       (gnus-simplify-buffer-fuzzy-step
1443        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1444       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1445
1446     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1447     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1448     (gnus-simplify-buffer-fuzzy-step " $")
1449     (gnus-simplify-buffer-fuzzy-step "^ +")))
1450
1451 (defun gnus-simplify-subject-fuzzy (subject)
1452   "Simplify a subject string fuzzily.
1453 See `gnus-simplify-buffer-fuzzy' for details."
1454   (save-excursion
1455     (gnus-set-work-buffer)
1456     (let ((case-fold-search t))
1457       ;; Remove uninteresting prefixes.
1458       (when (and gnus-simplify-ignored-prefixes
1459                  (string-match gnus-simplify-ignored-prefixes subject))
1460         (setq subject (substring subject (match-end 0))))
1461       (insert subject)
1462       (inline (gnus-simplify-buffer-fuzzy))
1463       (buffer-string))))
1464
1465 (defsubst gnus-simplify-subject-fully (subject)
1466   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1467   (cond
1468    (gnus-simplify-subject-functions
1469     (gnus-map-function gnus-simplify-subject-functions subject))
1470    ((null gnus-summary-gather-subject-limit)
1471     (gnus-simplify-subject-re subject))
1472    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1473     (gnus-simplify-subject-fuzzy subject))
1474    ((numberp gnus-summary-gather-subject-limit)
1475     (gnus-limit-string (gnus-simplify-subject-re subject)
1476                        gnus-summary-gather-subject-limit))
1477    (t
1478     subject)))
1479
1480 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1481   "Check whether two subjects are equal.
1482 If optional argument simple-first is t, first argument is already
1483 simplified."
1484   (cond
1485    ((null simple-first)
1486     (equal (gnus-simplify-subject-fully s1)
1487            (gnus-simplify-subject-fully s2)))
1488    (t
1489     (equal s1
1490            (gnus-simplify-subject-fully s2)))))
1491
1492 (defun gnus-summary-bubble-group ()
1493   "Increase the score of the current group.
1494 This is a handy function to add to `gnus-summary-exit-hook' to
1495 increase the score of each group you read."
1496   (gnus-group-add-score gnus-newsgroup-name))
1497
1498 \f
1499 ;;;
1500 ;;; Gnus summary mode
1501 ;;;
1502
1503 (put 'gnus-summary-mode 'mode-class 'special)
1504
1505 (defvar gnus-article-commands-menu)
1506
1507 (when t
1508   ;; Non-orthogonal keys
1509
1510   (gnus-define-keys gnus-summary-mode-map
1511     " " gnus-summary-next-page
1512     "\177" gnus-summary-prev-page
1513     [delete] gnus-summary-prev-page
1514     [backspace] gnus-summary-prev-page
1515     "\r" gnus-summary-scroll-up
1516     "\M-\r" gnus-summary-scroll-down
1517     "n" gnus-summary-next-unread-article
1518     "p" gnus-summary-prev-unread-article
1519     "N" gnus-summary-next-article
1520     "P" gnus-summary-prev-article
1521     "\M-\C-n" gnus-summary-next-same-subject
1522     "\M-\C-p" gnus-summary-prev-same-subject
1523     "\M-n" gnus-summary-next-unread-subject
1524     "\M-p" gnus-summary-prev-unread-subject
1525     "." gnus-summary-first-unread-article
1526     "," gnus-summary-best-unread-article
1527     "\M-s" gnus-summary-search-article-forward
1528     "\M-r" gnus-summary-search-article-backward
1529     "<" gnus-summary-beginning-of-article
1530     ">" gnus-summary-end-of-article
1531     "j" gnus-summary-goto-article
1532     "^" gnus-summary-refer-parent-article
1533     "\M-^" gnus-summary-refer-article
1534     "u" gnus-summary-tick-article-forward
1535     "!" gnus-summary-tick-article-forward
1536     "U" gnus-summary-tick-article-backward
1537     "d" gnus-summary-mark-as-read-forward
1538     "D" gnus-summary-mark-as-read-backward
1539     "E" gnus-summary-mark-as-expirable
1540     "\M-u" gnus-summary-clear-mark-forward
1541     "\M-U" gnus-summary-clear-mark-backward
1542     "k" gnus-summary-kill-same-subject-and-select
1543     "\C-k" gnus-summary-kill-same-subject
1544     "\M-\C-k" gnus-summary-kill-thread
1545     "\M-\C-l" gnus-summary-lower-thread
1546     "e" gnus-summary-edit-article
1547     "#" gnus-summary-mark-as-processable
1548     "\M-#" gnus-summary-unmark-as-processable
1549     "\M-\C-t" gnus-summary-toggle-threads
1550     "\M-\C-s" gnus-summary-show-thread
1551     "\M-\C-h" gnus-summary-hide-thread
1552     "\M-\C-f" gnus-summary-next-thread
1553     "\M-\C-b" gnus-summary-prev-thread
1554     [(meta down)] gnus-summary-next-thread
1555     [(meta up)] gnus-summary-prev-thread
1556     "\M-\C-u" gnus-summary-up-thread
1557     "\M-\C-d" gnus-summary-down-thread
1558     "&" gnus-summary-execute-command
1559     "c" gnus-summary-catchup-and-exit
1560     "\C-w" gnus-summary-mark-region-as-read
1561     "\C-t" gnus-summary-toggle-truncation
1562     "?" gnus-summary-mark-as-dormant
1563     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1564     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1565     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1566     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1567     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1568     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1569     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1570     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1571     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1572     "=" gnus-summary-expand-window
1573     "\C-x\C-s" gnus-summary-reselect-current-group
1574     "\M-g" gnus-summary-rescan-group
1575     "w" gnus-summary-stop-page-breaking
1576     "\C-c\C-r" gnus-summary-caesar-message
1577     "\M-t" gnus-summary-toggle-mime
1578     "f" gnus-summary-followup
1579     "F" gnus-summary-followup-with-original
1580     "C" gnus-summary-cancel-article
1581     "r" gnus-summary-reply
1582     "R" gnus-summary-reply-with-original
1583     "\C-c\C-f" gnus-summary-mail-forward
1584     "o" gnus-summary-save-article
1585     "\C-o" gnus-summary-save-article-mail
1586     "|" gnus-summary-pipe-output
1587     "\M-k" gnus-summary-edit-local-kill
1588     "\M-K" gnus-summary-edit-global-kill
1589     ;; "V" gnus-version
1590     "\C-c\C-d" gnus-summary-describe-group
1591     "q" gnus-summary-exit
1592     "Q" gnus-summary-exit-no-update
1593     "\C-c\C-i" gnus-info-find-node
1594     gnus-mouse-2 gnus-mouse-pick-article
1595     "m" gnus-summary-mail-other-window
1596     "a" gnus-summary-post-news
1597     "i" gnus-summary-news-other-window
1598     "x" gnus-summary-limit-to-unread
1599     "s" gnus-summary-isearch-article
1600     "t" gnus-article-toggle-headers
1601     "g" gnus-summary-show-article
1602     "l" gnus-summary-goto-last-article
1603     "v" gnus-summary-preview-mime-message
1604     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1605     "\C-d" gnus-summary-enter-digest-group
1606     "\M-\C-d" gnus-summary-read-document
1607     "\M-\C-e" gnus-summary-edit-parameters
1608     "\M-\C-a" gnus-summary-customize-parameters
1609     "\C-c\C-b" gnus-bug
1610     "\C-c\C-n" gnus-namazu-search
1611     "*" gnus-cache-enter-article
1612     "\M-*" gnus-cache-remove-article
1613     "\M-&" gnus-summary-universal-argument
1614     "\C-l" gnus-recenter
1615     "I" gnus-summary-increase-score
1616     "L" gnus-summary-lower-score
1617     "\M-i" gnus-symbolic-argument
1618     "h" gnus-summary-select-article-buffer
1619
1620     "V" gnus-summary-score-map
1621     "X" gnus-uu-extract-map
1622     "S" gnus-summary-send-map)
1623
1624   ;; Sort of orthogonal keymap
1625   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1626     "t" gnus-summary-tick-article-forward
1627     "!" gnus-summary-tick-article-forward
1628     "d" gnus-summary-mark-as-read-forward
1629     "r" gnus-summary-mark-as-read-forward
1630     "c" gnus-summary-clear-mark-forward
1631     " " gnus-summary-clear-mark-forward
1632     "e" gnus-summary-mark-as-expirable
1633     "x" gnus-summary-mark-as-expirable
1634     "?" gnus-summary-mark-as-dormant
1635     "b" gnus-summary-set-bookmark
1636     "B" gnus-summary-remove-bookmark
1637     "#" gnus-summary-mark-as-processable
1638     "\M-#" gnus-summary-unmark-as-processable
1639     "S" gnus-summary-limit-include-expunged
1640     "C" gnus-summary-catchup
1641     "H" gnus-summary-catchup-to-here
1642     "h" gnus-summary-catchup-from-here
1643     "\C-c" gnus-summary-catchup-all
1644     "k" gnus-summary-kill-same-subject-and-select
1645     "K" gnus-summary-kill-same-subject
1646     "P" gnus-uu-mark-map)
1647
1648   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1649     "c" gnus-summary-clear-above
1650     "u" gnus-summary-tick-above
1651     "m" gnus-summary-mark-above
1652     "k" gnus-summary-kill-below)
1653
1654   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1655     "/" gnus-summary-limit-to-subject
1656     "n" gnus-summary-limit-to-articles
1657     "w" gnus-summary-pop-limit
1658     "s" gnus-summary-limit-to-subject
1659     "a" gnus-summary-limit-to-author
1660     "u" gnus-summary-limit-to-unread
1661     "m" gnus-summary-limit-to-marks
1662     "M" gnus-summary-limit-exclude-marks
1663     "v" gnus-summary-limit-to-score
1664     "*" gnus-summary-limit-include-cached
1665     "D" gnus-summary-limit-include-dormant
1666     "T" gnus-summary-limit-include-thread
1667     "d" gnus-summary-limit-exclude-dormant
1668     "t" gnus-summary-limit-to-age
1669     "x" gnus-summary-limit-to-extra
1670     "p" gnus-summary-limit-to-display-predicate
1671     "E" gnus-summary-limit-include-expunged
1672     "c" gnus-summary-limit-exclude-childless-dormant
1673     "C" gnus-summary-limit-mark-excluded-as-read
1674     "o" gnus-summary-insert-old-articles
1675     "N" gnus-summary-insert-new-articles)
1676
1677   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1678     "n" gnus-summary-next-unread-article
1679     "p" gnus-summary-prev-unread-article
1680     "N" gnus-summary-next-article
1681     "P" gnus-summary-prev-article
1682     "\C-n" gnus-summary-next-same-subject
1683     "\C-p" gnus-summary-prev-same-subject
1684     "\M-n" gnus-summary-next-unread-subject
1685     "\M-p" gnus-summary-prev-unread-subject
1686     "f" gnus-summary-first-unread-article
1687     "b" gnus-summary-best-unread-article
1688     "j" gnus-summary-goto-article
1689     "g" gnus-summary-goto-subject
1690     "l" gnus-summary-goto-last-article
1691     "o" gnus-summary-pop-article)
1692
1693   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1694     "k" gnus-summary-kill-thread
1695     "l" gnus-summary-lower-thread
1696     "i" gnus-summary-raise-thread
1697     "T" gnus-summary-toggle-threads
1698     "t" gnus-summary-rethread-current
1699     "^" gnus-summary-reparent-thread
1700     "s" gnus-summary-show-thread
1701     "S" gnus-summary-show-all-threads
1702     "h" gnus-summary-hide-thread
1703     "H" gnus-summary-hide-all-threads
1704     "n" gnus-summary-next-thread
1705     "p" gnus-summary-prev-thread
1706     "u" gnus-summary-up-thread
1707     "o" gnus-summary-top-thread
1708     "d" gnus-summary-down-thread
1709     "#" gnus-uu-mark-thread
1710     "\M-#" gnus-uu-unmark-thread)
1711
1712   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1713     "g" gnus-summary-prepare
1714     "c" gnus-summary-insert-cached-articles)
1715
1716   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1717     "c" gnus-summary-catchup-and-exit
1718     "C" gnus-summary-catchup-all-and-exit
1719     "E" gnus-summary-exit-no-update
1720     "J" gnus-summary-jump-to-other-group
1721     "Q" gnus-summary-exit
1722     "Z" gnus-summary-exit
1723     "n" gnus-summary-catchup-and-goto-next-group
1724     "R" gnus-summary-reselect-current-group
1725     "G" gnus-summary-rescan-group
1726     "N" gnus-summary-next-group
1727     "s" gnus-summary-save-newsrc
1728     "P" gnus-summary-prev-group)
1729
1730   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1731     " " gnus-summary-next-page
1732     "n" gnus-summary-next-page
1733     "\177" gnus-summary-prev-page
1734     [delete] gnus-summary-prev-page
1735     "p" gnus-summary-prev-page
1736     "\r" gnus-summary-scroll-up
1737     "\M-\r" gnus-summary-scroll-down
1738     "<" gnus-summary-beginning-of-article
1739     ">" gnus-summary-end-of-article
1740     "b" gnus-summary-beginning-of-article
1741     "e" gnus-summary-end-of-article
1742     "^" gnus-summary-refer-parent-article
1743     "r" gnus-summary-refer-parent-article
1744     "D" gnus-summary-enter-digest-group
1745     "R" gnus-summary-refer-references
1746     "T" gnus-summary-refer-thread
1747     "g" gnus-summary-show-article
1748     "s" gnus-summary-isearch-article
1749     "P" gnus-summary-print-article
1750     "M" gnus-mailing-list-insinuate
1751     "t" gnus-article-babel)
1752
1753   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1754     "b" gnus-article-add-buttons
1755     "B" gnus-article-add-buttons-to-head
1756     "o" gnus-article-treat-overstrike
1757     "e" gnus-article-emphasize
1758     "w" gnus-article-fill-cited-article
1759     "Q" gnus-article-fill-long-lines
1760     "C" gnus-article-capitalize-sentences
1761     "c" gnus-article-remove-cr
1762     "Z" gnus-article-decode-HZ
1763     "h" gnus-article-wash-html
1764     "u" gnus-article-unsplit-urls
1765     "f" gnus-article-display-x-face
1766     "l" gnus-summary-stop-page-breaking
1767     "r" gnus-summary-caesar-message
1768     "t" gnus-article-toggle-headers
1769     "g" gnus-treat-smiley
1770     "v" gnus-summary-verbose-headers
1771     "m" gnus-summary-toggle-mime
1772     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1773     "p" gnus-article-verify-x-pgp-sig
1774     "d" gnus-article-treat-dumbquotes
1775     "k" gnus-article-outlook-deuglify-article)
1776
1777   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1778     "a" gnus-article-hide
1779     "h" gnus-article-toggle-headers
1780     "b" gnus-article-hide-boring-headers
1781     "s" gnus-article-hide-signature
1782     "c" gnus-article-hide-citation
1783     "C" gnus-article-hide-citation-in-followups
1784     "l" gnus-article-hide-list-identifiers
1785     "p" gnus-article-hide-pgp
1786     "B" gnus-article-strip-banner
1787     "P" gnus-article-hide-pem
1788     "\C-c" gnus-article-hide-citation-maybe)
1789
1790   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1791     "a" gnus-article-highlight
1792     "h" gnus-article-highlight-headers
1793     "c" gnus-article-highlight-citation
1794     "s" gnus-article-highlight-signature)
1795
1796   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1797     "f" gnus-article-treat-fold-headers
1798     "u" gnus-article-treat-unfold-headers
1799     "n" gnus-article-treat-fold-newsgroups)
1800
1801   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1802     "x" gnus-article-display-x-face
1803     "s" gnus-treat-smiley
1804     "D" gnus-article-remove-images
1805     "f" gnus-treat-from-picon
1806     "m" gnus-treat-mail-picon
1807     "n" gnus-treat-newsgroups-picon)
1808
1809   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1810     "z" gnus-article-date-ut
1811     "u" gnus-article-date-ut
1812     "l" gnus-article-date-local
1813     "p" gnus-article-date-english
1814     "e" gnus-article-date-lapsed
1815     "o" gnus-article-date-original
1816     "i" gnus-article-date-iso8601
1817     "s" gnus-article-date-user)
1818
1819   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1820     "t" gnus-article-remove-trailing-blank-lines
1821     "l" gnus-article-strip-leading-blank-lines
1822     "m" gnus-article-strip-multiple-blank-lines
1823     "a" gnus-article-strip-blank-lines
1824     "A" gnus-article-strip-all-blank-lines
1825     "s" gnus-article-strip-leading-space
1826     "e" gnus-article-strip-trailing-space
1827     "w" gnus-article-remove-leading-whitespace)
1828
1829   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1830     "v" gnus-version
1831     "f" gnus-summary-fetch-faq
1832     "d" gnus-summary-describe-group
1833     "h" gnus-summary-describe-briefly
1834     "i" gnus-info-find-node)
1835
1836   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1837     "e" gnus-summary-expire-articles
1838     "\M-\C-e" gnus-summary-expire-articles-now
1839     "\177" gnus-summary-delete-article
1840     [delete] gnus-summary-delete-article
1841     [backspace] gnus-summary-delete-article
1842     "m" gnus-summary-move-article
1843     "r" gnus-summary-respool-article
1844     "w" gnus-summary-edit-article
1845     "c" gnus-summary-copy-article
1846     "B" gnus-summary-crosspost-article
1847     "q" gnus-summary-respool-query
1848     "t" gnus-summary-respool-trace
1849     "i" gnus-summary-import-article
1850     "I" gnus-summary-create-article
1851     "p" gnus-summary-article-posted-p)
1852
1853   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1854     "o" gnus-summary-save-article
1855     "m" gnus-summary-save-article-mail
1856     "F" gnus-summary-write-article-file
1857     "r" gnus-summary-save-article-rmail
1858     "f" gnus-summary-save-article-file
1859     "b" gnus-summary-save-article-body-file
1860     "h" gnus-summary-save-article-folder
1861     "v" gnus-summary-save-article-vm
1862     "p" gnus-summary-pipe-output
1863     "P" gnus-summary-muttprint
1864     "s" gnus-soup-add-article)
1865
1866   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1867     "b" gnus-summary-display-buttonized
1868     "m" gnus-summary-repair-multipart
1869     "v" gnus-article-view-part
1870     "o" gnus-article-save-part
1871     "c" gnus-article-copy-part
1872     "C" gnus-article-view-part-as-charset
1873     "e" gnus-article-view-part-externally
1874     "E" gnus-article-encrypt-body
1875     "i" gnus-article-inline-part
1876     "|" gnus-article-pipe-part)
1877
1878   (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1879     "p" gnus-summary-mark-as-processable
1880     "u" gnus-summary-unmark-as-processable
1881     "U" gnus-summary-unmark-all-processable
1882     "v" gnus-uu-mark-over
1883     "s" gnus-uu-mark-series
1884     "r" gnus-uu-mark-region
1885     "g" gnus-uu-unmark-region
1886     "R" gnus-uu-mark-by-regexp
1887     "G" gnus-uu-unmark-by-regexp
1888     "t" gnus-uu-mark-thread
1889     "T" gnus-uu-unmark-thread
1890     "a" gnus-uu-mark-all
1891     "b" gnus-uu-mark-buffer
1892     "S" gnus-uu-mark-sparse
1893     "k" gnus-summary-kill-process-mark
1894     "y" gnus-summary-yank-process-mark
1895     "w" gnus-summary-save-process-mark
1896     "i" gnus-uu-invert-processable)
1897
1898   (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1899     ;;"x" gnus-uu-extract-any
1900     "m" gnus-summary-save-parts
1901     "u" gnus-uu-decode-uu
1902     "U" gnus-uu-decode-uu-and-save
1903     "s" gnus-uu-decode-unshar
1904     "S" gnus-uu-decode-unshar-and-save
1905     "o" gnus-uu-decode-save
1906     "O" gnus-uu-decode-save
1907     "b" gnus-uu-decode-binhex
1908     "B" gnus-uu-decode-binhex
1909     "p" gnus-uu-decode-postscript
1910     "P" gnus-uu-decode-postscript-and-save)
1911
1912   (gnus-define-keys
1913       (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1914     "u" gnus-uu-decode-uu-view
1915     "U" gnus-uu-decode-uu-and-save-view
1916     "s" gnus-uu-decode-unshar-view
1917     "S" gnus-uu-decode-unshar-and-save-view
1918     "o" gnus-uu-decode-save-view
1919     "O" gnus-uu-decode-save-view
1920     "b" gnus-uu-decode-binhex-view
1921     "B" gnus-uu-decode-binhex-view
1922     "p" gnus-uu-decode-postscript-view
1923     "P" gnus-uu-decode-postscript-and-save-view))
1924
1925 (defvar gnus-article-post-menu nil)
1926
1927 (defun gnus-summary-make-menu-bar ()
1928   (gnus-turn-off-edit-menu 'summary)
1929
1930   (unless (boundp 'gnus-summary-misc-menu)
1931
1932     (easy-menu-define
1933      gnus-summary-kill-menu gnus-summary-mode-map ""
1934      (cons
1935       "Score"
1936       (nconc
1937        (list
1938         ["Customize" gnus-score-customize t])
1939        (gnus-make-score-map 'increase)
1940        (gnus-make-score-map 'lower)
1941        '(("Mark"
1942           ["Kill below" gnus-summary-kill-below t]
1943           ["Mark above" gnus-summary-mark-above t]
1944           ["Tick above" gnus-summary-tick-above t]
1945           ["Clear above" gnus-summary-clear-above t])
1946          ["Current score" gnus-summary-current-score t]
1947          ["Set score" gnus-summary-set-score t]
1948          ["Switch current score file..." gnus-score-change-score-file t]
1949          ["Set mark below..." gnus-score-set-mark-below t]
1950          ["Set expunge below..." gnus-score-set-expunge-below t]
1951          ["Edit current score file" gnus-score-edit-current-scores t]
1952          ["Edit score file" gnus-score-edit-file t]
1953          ["Trace score" gnus-score-find-trace t]
1954          ["Find words" gnus-score-find-favourite-words t]
1955          ["Rescore buffer" gnus-summary-rescore t]
1956          ["Increase score..." gnus-summary-increase-score t]
1957          ["Lower score..." gnus-summary-lower-score t]))))
1958
1959     ;; Define both the Article menu in the summary buffer and the
1960     ;; equivalent Commands menu in the article buffer here for
1961     ;; consistency.
1962     (let ((innards
1963            `(("Hide"
1964               ["All" gnus-article-hide t]
1965               ["Headers" gnus-article-toggle-headers t]
1966               ["Signature" gnus-article-hide-signature t]
1967               ["Citation" gnus-article-hide-citation t]
1968               ["List identifiers" gnus-article-hide-list-identifiers t]
1969               ["PGP" gnus-article-hide-pgp t]
1970               ["Banner" gnus-article-strip-banner t]
1971               ["Boring headers" gnus-article-hide-boring-headers t])
1972              ("Highlight"
1973               ["All" gnus-article-highlight t]
1974               ["Headers" gnus-article-highlight-headers t]
1975               ["Signature" gnus-article-highlight-signature t]
1976               ["Citation" gnus-article-highlight-citation t])
1977              ("Date"
1978               ["Local" gnus-article-date-local t]
1979               ["ISO8601" gnus-article-date-iso8601 t]
1980               ["UT" gnus-article-date-ut t]
1981               ["Original" gnus-article-date-original t]
1982               ["Lapsed" gnus-article-date-lapsed t]
1983               ["User-defined" gnus-article-date-user t])
1984              ("Display"
1985               ["Remove images" gnus-article-remove-images t]
1986               ["Toggle smiley" gnus-treat-smiley t]
1987               ["Show X-Face" gnus-article-display-x-face t]
1988               ["Show picons in From" gnus-treat-from-picon t]
1989               ["Show picons in mail headers" gnus-treat-mail-picon t]
1990               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1991              ("Washing"
1992               ("Remove Blanks"
1993                ["Leading" gnus-article-strip-leading-blank-lines t]
1994                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1995                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1996                ["All of the above" gnus-article-strip-blank-lines t]
1997                ["All" gnus-article-strip-all-blank-lines t]
1998                ["Leading space" gnus-article-strip-leading-space t]
1999                ["Trailing space" gnus-article-strip-trailing-space t]
2000                ["Leading space in headers"
2001                 gnus-article-remove-leading-whitespace t])
2002               ["Overstrike" gnus-article-treat-overstrike t]
2003               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2004               ["Emphasis" gnus-article-emphasize t]
2005               ["Word wrap" gnus-article-fill-cited-article t]
2006               ["Fill long lines" gnus-article-fill-long-lines t]
2007               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2008               ["CR" gnus-article-remove-cr t]
2009               ["Rot 13" gnus-summary-caesar-message
2010                ,@(if (featurep 'xemacs) '(t)
2011                    '(:help "\"Caesar rotate\" article by 13"))]
2012               ["Unix pipe" gnus-summary-pipe-message t]
2013               ["Add buttons" gnus-article-add-buttons t]
2014               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2015               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2016               ["Toggle MIME" gnus-summary-toggle-mime t]
2017               ["Verbose header" gnus-summary-verbose-headers t]
2018               ["Toggle header" gnus-summary-toggle-header t]
2019               ["Unfold headers" gnus-article-treat-unfold-headers t]
2020               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2021               ["Html" gnus-article-wash-html t]
2022               ["URLs" gnus-article-unsplit-urls t]
2023               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2024               ["HZ" gnus-article-decode-HZ t]
2025               ["OutlooK deuglify" gnus-article-outlook-deuglify-article t]
2026               )
2027              ("Output"
2028               ["Save in default format" gnus-summary-save-article
2029                ,@(if (featurep 'xemacs) '(t)
2030                    '(:help "Save article using default method"))]
2031               ["Save in file" gnus-summary-save-article-file
2032                ,@(if (featurep 'xemacs) '(t)
2033                    '(:help "Save article in file"))]
2034               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2035               ["Save in MH folder" gnus-summary-save-article-folder t]
2036               ["Save in VM folder" gnus-summary-save-article-vm t]
2037               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2038               ["Save body in file" gnus-summary-save-article-body-file t]
2039               ["Pipe through a filter" gnus-summary-pipe-output t]
2040               ["Add to SOUP packet" gnus-soup-add-article t]
2041               ["Print with Muttprint" gnus-summary-muttprint t]
2042               ["Print" gnus-summary-print-article t])
2043              ("Backend"
2044               ["Respool article..." gnus-summary-respool-article t]
2045               ["Move article..." gnus-summary-move-article
2046                (gnus-check-backend-function
2047                 'request-move-article gnus-newsgroup-name)]
2048               ["Copy article..." gnus-summary-copy-article t]
2049               ["Crosspost article..." gnus-summary-crosspost-article
2050                (gnus-check-backend-function
2051                 'request-replace-article gnus-newsgroup-name)]
2052               ["Import file..." gnus-summary-import-article t]
2053               ["Create article..." gnus-summary-create-article t]
2054               ["Check if posted" gnus-summary-article-posted-p t]
2055               ["Edit article" gnus-summary-edit-article
2056                (not (gnus-group-read-only-p))]
2057               ["Delete article" gnus-summary-delete-article
2058                (gnus-check-backend-function
2059                 'request-expire-articles gnus-newsgroup-name)]
2060               ["Query respool" gnus-summary-respool-query t]
2061               ["Trace respool" gnus-summary-respool-trace t]
2062               ["Delete expirable articles" gnus-summary-expire-articles-now
2063                (gnus-check-backend-function
2064                 'request-expire-articles gnus-newsgroup-name)])
2065              ("Extract"
2066               ["Uudecode" gnus-uu-decode-uu
2067                ,@(if (featurep 'xemacs) '(t)
2068                    '(:help "Decode uuencoded article(s)"))]
2069               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2070               ["Unshar" gnus-uu-decode-unshar t]
2071               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2072               ["Save" gnus-uu-decode-save t]
2073               ["Binhex" gnus-uu-decode-binhex t]
2074               ["Postscript" gnus-uu-decode-postscript t])
2075              ("Cache"
2076               ["Enter article" gnus-cache-enter-article t]
2077               ["Remove article" gnus-cache-remove-article t])
2078              ["Translate" gnus-article-babel t]
2079              ["Select article buffer" gnus-summary-select-article-buffer t]
2080              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2081              ["Isearch article..." gnus-summary-isearch-article t]
2082              ["Beginning of the article" gnus-summary-beginning-of-article t]
2083              ["End of the article" gnus-summary-end-of-article t]
2084              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2085              ["Fetch referenced articles" gnus-summary-refer-references t]
2086              ["Fetch current thread" gnus-summary-refer-thread t]
2087              ["Fetch article with id..." gnus-summary-refer-article t]
2088              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2089              ["Redisplay" gnus-summary-show-article t]
2090              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2091       (easy-menu-define
2092        gnus-summary-article-menu gnus-summary-mode-map ""
2093        (cons "Article" innards))
2094
2095       (if (not (keymapp gnus-summary-article-menu))
2096           (easy-menu-define
2097            gnus-article-commands-menu gnus-article-mode-map ""
2098            (cons "Commands" innards))
2099         ;; in Emacs, don't share menu.
2100         (setq gnus-article-commands-menu
2101               (copy-keymap gnus-summary-article-menu))
2102         (define-key gnus-article-mode-map [menu-bar commands]
2103           (cons "Commands" gnus-article-commands-menu))))
2104
2105     (easy-menu-define
2106      gnus-summary-thread-menu gnus-summary-mode-map ""
2107      '("Threads"
2108        ["Toggle threading" gnus-summary-toggle-threads t]
2109        ["Hide threads" gnus-summary-hide-all-threads t]
2110        ["Show threads" gnus-summary-show-all-threads t]
2111        ["Hide thread" gnus-summary-hide-thread t]
2112        ["Show thread" gnus-summary-show-thread t]
2113        ["Go to next thread" gnus-summary-next-thread t]
2114        ["Go to previous thread" gnus-summary-prev-thread t]
2115        ["Go down thread" gnus-summary-down-thread t]
2116        ["Go up thread" gnus-summary-up-thread t]
2117        ["Top of thread" gnus-summary-top-thread t]
2118        ["Mark thread as read" gnus-summary-kill-thread t]
2119        ["Lower thread score" gnus-summary-lower-thread t]
2120        ["Raise thread score" gnus-summary-raise-thread t]
2121        ["Rethread current" gnus-summary-rethread-current t]))
2122
2123     (easy-menu-define
2124      gnus-summary-post-menu gnus-summary-mode-map ""
2125      `("Post"
2126        ["Send a message (mail or news)" gnus-summary-post-news
2127         ,@(if (featurep 'xemacs) '(t)
2128             '(:help "Post an article"))]
2129        ["Followup" gnus-summary-followup
2130         ,@(if (featurep 'xemacs) '(t)
2131             '(:help "Post followup to this article"))]
2132        ["Followup and yank" gnus-summary-followup-with-original
2133         ,@(if (featurep 'xemacs) '(t)
2134             '(:help "Post followup to this article, quoting its contents"))]
2135        ["Supersede article" gnus-summary-supersede-article t]
2136        ["Cancel article" gnus-summary-cancel-article
2137         ,@(if (featurep 'xemacs) '(t)
2138             '(:help "Cancel an article you posted"))]
2139        ["Reply" gnus-summary-reply t]
2140        ["Reply and yank" gnus-summary-reply-with-original t]
2141        ["Wide reply" gnus-summary-wide-reply t]
2142        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2143         ,@(if (featurep 'xemacs) '(t)
2144             '(:help "Mail a reply, quoting this article"))]
2145        ["Very wide reply" gnus-summary-very-wide-reply t]
2146        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2147         ,@(if (featurep 'xemacs) '(t)
2148             '(:help "Mail a very wide reply, quoting this article"))]
2149        ["Mail forward" gnus-summary-mail-forward t]
2150        ["Post forward" gnus-summary-post-forward t]
2151        ["Digest and mail" gnus-summary-digest-mail-forward t]
2152        ["Digest and post" gnus-summary-digest-post-forward t]
2153        ["Resend message" gnus-summary-resend-message t]
2154        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2155        ["Send a mail" gnus-summary-mail-other-window t]
2156        ["Create a local message" gnus-summary-news-other-window t]
2157        ["Uuencode and post" gnus-uu-post-news
2158         ,@(if (featurep 'xemacs) '(t)
2159             '(:help "Post a uuencoded article"))]
2160        ["Followup via news" gnus-summary-followup-to-mail t]
2161        ["Followup via news and yank"
2162         gnus-summary-followup-to-mail-with-original t]
2163        ;;("Draft"
2164        ;;["Send" gnus-summary-send-draft t]
2165        ;;["Send bounced" gnus-resend-bounced-mail t])
2166        ))
2167
2168     (cond
2169      ((not (keymapp gnus-summary-post-menu))
2170       (setq gnus-article-post-menu gnus-summary-post-menu))
2171      ((not gnus-article-post-menu)
2172       ;; Don't share post menu.
2173       (setq gnus-article-post-menu
2174             (copy-keymap gnus-summary-post-menu))))
2175     (define-key gnus-article-mode-map [menu-bar post]
2176       (cons "Post" gnus-article-post-menu))
2177
2178     (easy-menu-define
2179      gnus-summary-misc-menu gnus-summary-mode-map ""
2180      `("Gnus"
2181        ("Mark Read"
2182         ["Mark as read" gnus-summary-mark-as-read-forward t]
2183         ["Mark same subject and select"
2184          gnus-summary-kill-same-subject-and-select t]
2185         ["Mark same subject" gnus-summary-kill-same-subject t]
2186         ["Catchup" gnus-summary-catchup
2187          ,@(if (featurep 'xemacs) '(t)
2188              '(:help "Mark unread articles in this group as read"))]
2189         ["Catchup all" gnus-summary-catchup-all t]
2190         ["Catchup to here" gnus-summary-catchup-to-here t]
2191         ["Catchup from here" gnus-summary-catchup-from-here t]
2192         ["Catchup region" gnus-summary-mark-region-as-read t]
2193         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2194        ("Mark Various"
2195         ["Tick" gnus-summary-tick-article-forward t]
2196         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2197         ["Remove marks" gnus-summary-clear-mark-forward t]
2198         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2199         ["Set bookmark" gnus-summary-set-bookmark t]
2200         ["Remove bookmark" gnus-summary-remove-bookmark t])
2201        ("Limit to"
2202         ["Marks..." gnus-summary-limit-to-marks t]
2203         ["Subject..." gnus-summary-limit-to-subject t]
2204         ["Author..." gnus-summary-limit-to-author t]
2205         ["Age..." gnus-summary-limit-to-age t]
2206         ["Extra..." gnus-summary-limit-to-extra t]
2207         ["Score" gnus-summary-limit-to-score t]
2208         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2209         ["Unread" gnus-summary-limit-to-unread t]
2210         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2211         ["Articles" gnus-summary-limit-to-articles t]
2212         ["Pop limit" gnus-summary-pop-limit t]
2213         ["Show dormant" gnus-summary-limit-include-dormant t]
2214         ["Hide childless dormant"
2215          gnus-summary-limit-exclude-childless-dormant t]
2216         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2217         ["Hide marked" gnus-summary-limit-exclude-marks t]
2218         ["Show expunged" gnus-summary-limit-include-expunged t])
2219        ("Process Mark"
2220         ["Set mark" gnus-summary-mark-as-processable t]
2221         ["Remove mark" gnus-summary-unmark-as-processable t]
2222         ["Remove all marks" gnus-summary-unmark-all-processable t]
2223         ["Mark above" gnus-uu-mark-over t]
2224         ["Mark series" gnus-uu-mark-series t]
2225         ["Mark region" gnus-uu-mark-region t]
2226         ["Unmark region" gnus-uu-unmark-region t]
2227         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2228         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2229         ["Mark all" gnus-uu-mark-all t]
2230         ["Mark buffer" gnus-uu-mark-buffer t]
2231         ["Mark sparse" gnus-uu-mark-sparse t]
2232         ["Mark thread" gnus-uu-mark-thread t]
2233         ["Unmark thread" gnus-uu-unmark-thread t]
2234         ("Process Mark Sets"
2235          ["Kill" gnus-summary-kill-process-mark t]
2236          ["Yank" gnus-summary-yank-process-mark
2237           gnus-newsgroup-process-stack]
2238          ["Save" gnus-summary-save-process-mark t]))
2239        ("Scroll article"
2240         ["Page forward" gnus-summary-next-page
2241          ,@(if (featurep 'xemacs) '(t)
2242              '(:help "Show next page of article"))]
2243         ["Page backward" gnus-summary-prev-page
2244          ,@(if (featurep 'xemacs) '(t)
2245              '(:help "Show previous page of article"))]
2246         ["Line forward" gnus-summary-scroll-up t])
2247        ("Move"
2248         ["Next unread article" gnus-summary-next-unread-article t]
2249         ["Previous unread article" gnus-summary-prev-unread-article t]
2250         ["Next article" gnus-summary-next-article t]
2251         ["Previous article" gnus-summary-prev-article t]
2252         ["Next unread subject" gnus-summary-next-unread-subject t]
2253         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2254         ["Next article same subject" gnus-summary-next-same-subject t]
2255         ["Previous article same subject" gnus-summary-prev-same-subject t]
2256         ["First unread article" gnus-summary-first-unread-article t]
2257         ["Best unread article" gnus-summary-best-unread-article t]
2258         ["Go to subject number..." gnus-summary-goto-subject t]
2259         ["Go to article number..." gnus-summary-goto-article t]
2260         ["Go to the last article" gnus-summary-goto-last-article t]
2261         ["Pop article off history" gnus-summary-pop-article t])
2262        ("Sort"
2263         ["Sort by number" gnus-summary-sort-by-number t]
2264         ["Sort by author" gnus-summary-sort-by-author t]
2265         ["Sort by subject" gnus-summary-sort-by-subject t]
2266         ["Sort by date" gnus-summary-sort-by-date t]
2267         ["Sort by score" gnus-summary-sort-by-score t]
2268         ["Sort by lines" gnus-summary-sort-by-lines t]
2269         ["Sort by characters" gnus-summary-sort-by-chars t]
2270         ["Original sort" gnus-summary-sort-by-original t])
2271        ("Help"
2272         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2273         ["Describe group" gnus-summary-describe-group t]
2274         ["Read manual" gnus-info-find-node t])
2275        ("Modes"
2276         ["Pick and read" gnus-pick-mode t]
2277         ["Binary" gnus-binary-mode t])
2278        ("Regeneration"
2279         ["Regenerate" gnus-summary-prepare t]
2280         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2281         ["Toggle threading" gnus-summary-toggle-threads t])
2282        ["See old articles" gnus-summary-insert-old-articles t]
2283        ["See new articles" gnus-summary-insert-new-articles t]
2284        ["Filter articles..." gnus-summary-execute-command t]
2285        ["Run command on subjects..." gnus-summary-universal-argument t]
2286        ["Search articles forward..." gnus-summary-search-article-forward t]
2287        ["Search articles backward..." gnus-summary-search-article-backward t]
2288        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2289        ["Expand window" gnus-summary-expand-window t]
2290        ["Expire expirable articles" gnus-summary-expire-articles
2291         (gnus-check-backend-function
2292          'request-expire-articles gnus-newsgroup-name)]
2293        ["Edit local kill file" gnus-summary-edit-local-kill t]
2294        ["Edit main kill file" gnus-summary-edit-global-kill t]
2295        ["Edit group parameters" gnus-summary-edit-parameters t]
2296        ["Customize group parameters" gnus-summary-customize-parameters t]
2297        ["Send a bug report" gnus-bug t]
2298        ("Exit"
2299         ["Catchup and exit" gnus-summary-catchup-and-exit
2300          ,@(if (featurep 'xemacs) '(t)
2301              '(:help "Mark unread articles in this group as read, then exit"))]
2302         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2303         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2304         ["Exit group" gnus-summary-exit
2305          ,@(if (featurep 'xemacs) '(t)
2306              '(:help "Exit current group, return to group selection mode"))]
2307         ["Exit group without updating" gnus-summary-exit-no-update t]
2308         ["Exit and goto next group" gnus-summary-next-group t]
2309         ["Exit and goto prev group" gnus-summary-prev-group t]
2310         ["Reselect group" gnus-summary-reselect-current-group t]
2311         ["Rescan group" gnus-summary-rescan-group t]
2312         ["Update dribble" gnus-summary-save-newsrc t])))
2313
2314     (gnus-run-hooks 'gnus-summary-menu-hook)))
2315
2316 (defvar gnus-summary-tool-bar-map nil)
2317
2318 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2319 (defun gnus-summary-make-tool-bar ()
2320   (if (and (fboundp 'tool-bar-add-item-from-menu)
2321            (default-value 'tool-bar-mode)
2322            (not gnus-summary-tool-bar-map))
2323       (setq gnus-summary-tool-bar-map
2324             (let ((tool-bar-map (make-sparse-keymap))
2325                   (load-path (mm-image-load-path)))
2326               (tool-bar-add-item-from-menu
2327                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2328               (tool-bar-add-item-from-menu
2329                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2330               (tool-bar-add-item-from-menu
2331                'gnus-summary-post-news "post" gnus-summary-mode-map)
2332               (tool-bar-add-item-from-menu
2333                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2334               (tool-bar-add-item-from-menu
2335                'gnus-summary-followup "followup" gnus-summary-mode-map)
2336               (tool-bar-add-item-from-menu
2337                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2338               (tool-bar-add-item-from-menu
2339                'gnus-summary-reply "reply" gnus-summary-mode-map)
2340               (tool-bar-add-item-from-menu
2341                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2342               (tool-bar-add-item-from-menu
2343                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2344               (tool-bar-add-item-from-menu
2345                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2346               (tool-bar-add-item-from-menu
2347                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2348               (tool-bar-add-item-from-menu
2349                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2350               (tool-bar-add-item-from-menu
2351                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2352               (tool-bar-add-item-from-menu
2353                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2354               (tool-bar-add-item-from-menu
2355                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2356               tool-bar-map)))
2357   (if gnus-summary-tool-bar-map
2358       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2359
2360 (defun gnus-score-set-default (var value)
2361   "A version of set that updates the GNU Emacs menu-bar."
2362   (set var value)
2363   ;; It is the message that forces the active status to be updated.
2364   (message ""))
2365
2366 (defun gnus-make-score-map (type)
2367   "Make a summary score map of type TYPE."
2368   (if t
2369       nil
2370     (let ((headers '(("author" "from" string)
2371                      ("subject" "subject" string)
2372                      ("article body" "body" string)
2373                      ("article head" "head" string)
2374                      ("xref" "xref" string)
2375                      ("extra header" "extra" string)
2376                      ("lines" "lines" number)
2377                      ("followups to author" "followup" string)))
2378           (types '((number ("less than" <)
2379                            ("greater than" >)
2380                            ("equal" =))
2381                    (string ("substring" s)
2382                            ("exact string" e)
2383                            ("fuzzy string" f)
2384                            ("regexp" r))))
2385           (perms '(("temporary" (current-time-string))
2386                    ("permanent" nil)
2387                    ("immediate" now)))
2388           header)
2389       (list
2390        (apply
2391         'nconc
2392         (list
2393          (if (eq type 'lower)
2394              "Lower score"
2395            "Increase score"))
2396         (let (outh)
2397           (while headers
2398             (setq header (car headers))
2399             (setq outh
2400                   (cons
2401                    (apply
2402                     'nconc
2403                     (list (car header))
2404                     (let ((ts (cdr (assoc (nth 2 header) types)))
2405                           outt)
2406                       (while ts
2407                         (setq outt
2408                               (cons
2409                                (apply
2410                                 'nconc
2411                                 (list (caar ts))
2412                                 (let ((ps perms)
2413                                       outp)
2414                                   (while ps
2415                                     (setq outp
2416                                           (cons
2417                                            (vector
2418                                             (caar ps)
2419                                             (list
2420                                              'gnus-summary-score-entry
2421                                              (nth 1 header)
2422                                              (if (or (string= (nth 1 header)
2423                                                               "head")
2424                                                      (string= (nth 1 header)
2425                                                               "body"))
2426                                                  ""
2427                                                (list 'gnus-summary-header
2428                                                      (nth 1 header)))
2429                                              (list 'quote (nth 1 (car ts)))
2430                                              (list 'gnus-score-delta-default
2431                                                    nil)
2432                                              (nth 1 (car ps))
2433                                              t)
2434                                             t)
2435                                            outp))
2436                                     (setq ps (cdr ps)))
2437                                   (list (nreverse outp))))
2438                                outt))
2439                         (setq ts (cdr ts)))
2440                       (list (nreverse outt))))
2441                    outh))
2442             (setq headers (cdr headers)))
2443           (list (nreverse outh))))))))
2444
2445 \f
2446
2447 (defun gnus-summary-mode (&optional group)
2448   "Major mode for reading articles.
2449
2450 All normal editing commands are switched off.
2451 \\<gnus-summary-mode-map>
2452 Each line in this buffer represents one article.  To read an
2453 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2454 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2455 respectively.
2456
2457 You can also post articles and send mail from this buffer.  To
2458 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2459 of an article, type `\\[gnus-summary-reply]'.
2460
2461 There are approx. one gazillion commands you can execute in this
2462 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2463
2464 The following commands are available:
2465
2466 \\{gnus-summary-mode-map}"
2467   (interactive)
2468   (kill-all-local-variables)
2469   (when (gnus-visual-p 'summary-menu 'menu)
2470     (gnus-summary-make-menu-bar)
2471     (gnus-summary-make-tool-bar))
2472   (gnus-summary-make-local-variables)
2473   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2474     (gnus-summary-make-local-variables))
2475   (gnus-make-thread-indent-array)
2476   (gnus-simplify-mode-line)
2477   (setq major-mode 'gnus-summary-mode)
2478   (setq mode-name "Summary")
2479   (make-local-variable 'minor-mode-alist)
2480   (use-local-map gnus-summary-mode-map)
2481   (buffer-disable-undo)
2482   (setq buffer-read-only t)             ;Disable modification
2483   (setq truncate-lines t)
2484   (setq selective-display t)
2485   (setq selective-display-ellipses t)   ;Display `...'
2486   (gnus-summary-set-display-table)
2487   (gnus-set-default-directory)
2488   (setq gnus-newsgroup-name group)
2489   (unless (gnus-news-group-p group)
2490     (setq gnus-newsgroup-incorporated
2491           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2492   (make-local-variable 'gnus-summary-line-format)
2493   (make-local-variable 'gnus-summary-line-format-spec)
2494   (make-local-variable 'gnus-summary-dummy-line-format)
2495   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2496   (make-local-variable 'gnus-summary-mark-positions)
2497   (make-local-hook 'pre-command-hook)
2498   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2499   (gnus-run-hooks 'gnus-summary-mode-hook)
2500   (turn-on-gnus-mailing-list-mode)
2501   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2502   (gnus-update-summary-mark-positions))
2503
2504 (defun gnus-summary-make-local-variables ()
2505   "Make all the local summary buffer variables."
2506   (let (global)
2507     (dolist (local gnus-summary-local-variables)
2508       (if (consp local)
2509           (progn
2510             (if (eq (cdr local) 'global)
2511                 ;; Copy the global value of the variable.
2512                 (setq global (symbol-value (car local)))
2513               ;; Use the value from the list.
2514               (setq global (eval (cdr local))))
2515             (set (make-local-variable (car local)) global))
2516         ;; Simple nil-valued local variable.
2517         (set (make-local-variable local) nil)))))
2518
2519 (defun gnus-summary-clear-local-variables ()
2520   (let ((locals gnus-summary-local-variables))
2521     (while locals
2522       (if (consp (car locals))
2523           (and (vectorp (caar locals))
2524                (set (caar locals) nil))
2525         (and (vectorp (car locals))
2526              (set (car locals) nil)))
2527       (setq locals (cdr locals)))))
2528
2529 ;; Summary data functions.
2530
2531 (defmacro gnus-data-number (data)
2532   `(car ,data))
2533
2534 (defmacro gnus-data-set-number (data number)
2535   `(setcar ,data ,number))
2536
2537 (defmacro gnus-data-mark (data)
2538   `(nth 1 ,data))
2539
2540 (defmacro gnus-data-set-mark (data mark)
2541   `(setcar (nthcdr 1 ,data) ,mark))
2542
2543 (defmacro gnus-data-pos (data)
2544   `(nth 2 ,data))
2545
2546 (defmacro gnus-data-set-pos (data pos)
2547   `(setcar (nthcdr 2 ,data) ,pos))
2548
2549 (defmacro gnus-data-header (data)
2550   `(nth 3 ,data))
2551
2552 (defmacro gnus-data-set-header (data header)
2553   `(setcar (nthcdr 3 ,data) ,header))
2554
2555 (defmacro gnus-data-level (data)
2556   `(nth 4 ,data))
2557
2558 (defmacro gnus-data-unread-p (data)
2559   `(= (nth 1 ,data) gnus-unread-mark))
2560
2561 (defmacro gnus-data-read-p (data)
2562   `(/= (nth 1 ,data) gnus-unread-mark))
2563
2564 (defmacro gnus-data-pseudo-p (data)
2565   `(consp (nth 3 ,data)))
2566
2567 (defmacro gnus-data-find (number)
2568   `(assq ,number gnus-newsgroup-data))
2569
2570 (defmacro gnus-data-find-list (number &optional data)
2571   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2572      (memq (assq ,number bdata)
2573            bdata)))
2574
2575 (defmacro gnus-data-make (number mark pos header level)
2576   `(list ,number ,mark ,pos ,header ,level))
2577
2578 (defun gnus-data-enter (after-article number mark pos header level offset)
2579   (let ((data (gnus-data-find-list after-article)))
2580     (unless data
2581       (error "No such article: %d" after-article))
2582     (setcdr data (cons (gnus-data-make number mark pos header level)
2583                        (cdr data)))
2584     (setq gnus-newsgroup-data-reverse nil)
2585     (gnus-data-update-list (cddr data) offset)))
2586
2587 (defun gnus-data-enter-list (after-article list &optional offset)
2588   (when list
2589     (let ((data (and after-article (gnus-data-find-list after-article)))
2590           (ilist list))
2591       (if (not (or data
2592                    after-article))
2593           (let ((odata gnus-newsgroup-data))
2594             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2595             (when offset
2596               (gnus-data-update-list odata offset)))
2597         ;; Find the last element in the list to be spliced into the main
2598         ;; list.
2599         (while (cdr list)
2600           (setq list (cdr list)))
2601         (if (not data)
2602             (progn
2603               (setcdr list gnus-newsgroup-data)
2604               (setq gnus-newsgroup-data ilist)
2605               (when offset
2606                 (gnus-data-update-list (cdr list) offset)))
2607           (setcdr list (cdr data))
2608           (setcdr data ilist)
2609           (when offset
2610             (gnus-data-update-list (cdr list) offset))))
2611       (setq gnus-newsgroup-data-reverse nil))))
2612
2613 (defun gnus-data-remove (article &optional offset)
2614   (let ((data gnus-newsgroup-data))
2615     (if (= (gnus-data-number (car data)) article)
2616         (progn
2617           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2618                 gnus-newsgroup-data-reverse nil)
2619           (when offset
2620             (gnus-data-update-list gnus-newsgroup-data offset)))
2621       (while (cdr data)
2622         (when (= (gnus-data-number (cadr data)) article)
2623           (setcdr data (cddr data))
2624           (when offset
2625             (gnus-data-update-list (cdr data) offset))
2626           (setq data nil
2627                 gnus-newsgroup-data-reverse nil))
2628         (setq data (cdr data))))))
2629
2630 (defmacro gnus-data-list (backward)
2631   `(if ,backward
2632        (or gnus-newsgroup-data-reverse
2633            (setq gnus-newsgroup-data-reverse
2634                  (reverse gnus-newsgroup-data)))
2635      gnus-newsgroup-data))
2636
2637 (defun gnus-data-update-list (data offset)
2638   "Add OFFSET to the POS of all data entries in DATA."
2639   (setq gnus-newsgroup-data-reverse nil)
2640   (while data
2641     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2642     (setq data (cdr data))))
2643
2644 (defun gnus-summary-article-pseudo-p (article)
2645   "Say whether this article is a pseudo article or not."
2646   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2647
2648 (defmacro gnus-summary-article-sparse-p (article)
2649   "Say whether this article is a sparse article or not."
2650   `(memq ,article gnus-newsgroup-sparse))
2651
2652 (defmacro gnus-summary-article-ancient-p (article)
2653   "Say whether this article is a sparse article or not."
2654   `(memq ,article gnus-newsgroup-ancient))
2655
2656 (defun gnus-article-parent-p (number)
2657   "Say whether this article is a parent or not."
2658   (let ((data (gnus-data-find-list number)))
2659     (and (cdr data)                     ; There has to be an article after...
2660          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2661             (gnus-data-level (nth 1 data))))))
2662
2663 (defun gnus-article-children (number)
2664   "Return a list of all children to NUMBER."
2665   (let* ((data (gnus-data-find-list number))
2666          (level (gnus-data-level (car data)))
2667          children)
2668     (setq data (cdr data))
2669     (while (and data
2670                 (= (gnus-data-level (car data)) (1+ level)))
2671       (push (gnus-data-number (car data)) children)
2672       (setq data (cdr data)))
2673     children))
2674
2675 (defmacro gnus-summary-skip-intangible ()
2676   "If the current article is intangible, then jump to a different article."
2677   '(let ((to (get-text-property (point) 'gnus-intangible)))
2678      (and to (gnus-summary-goto-subject to))))
2679
2680 (defmacro gnus-summary-article-intangible-p ()
2681   "Say whether this article is intangible or not."
2682   '(get-text-property (point) 'gnus-intangible))
2683
2684 (defun gnus-article-read-p (article)
2685   "Say whether ARTICLE is read or not."
2686   (not (or (memq article gnus-newsgroup-marked)
2687            (memq article gnus-newsgroup-unreads)
2688            (memq article gnus-newsgroup-unselected)
2689            (memq article gnus-newsgroup-dormant))))
2690
2691 ;; Some summary mode macros.
2692
2693 (defmacro gnus-summary-article-number ()
2694   "The article number of the article on the current line.
2695 If there isn's an article number here, then we return the current
2696 article number."
2697   '(progn
2698      (gnus-summary-skip-intangible)
2699      (or (get-text-property (point) 'gnus-number)
2700          (gnus-summary-last-subject))))
2701
2702 (defmacro gnus-summary-article-header (&optional number)
2703   "Return the header of article NUMBER."
2704   `(gnus-data-header (gnus-data-find
2705                       ,(or number '(gnus-summary-article-number)))))
2706
2707 (defmacro gnus-summary-thread-level (&optional number)
2708   "Return the level of thread that starts with article NUMBER."
2709   `(if (and (eq gnus-summary-make-false-root 'dummy)
2710             (get-text-property (point) 'gnus-intangible))
2711        0
2712      (gnus-data-level (gnus-data-find
2713                        ,(or number '(gnus-summary-article-number))))))
2714
2715 (defmacro gnus-summary-article-mark (&optional number)
2716   "Return the mark of article NUMBER."
2717   `(gnus-data-mark (gnus-data-find
2718                     ,(or number '(gnus-summary-article-number)))))
2719
2720 (defmacro gnus-summary-article-pos (&optional number)
2721   "Return the position of the line of article NUMBER."
2722   `(gnus-data-pos (gnus-data-find
2723                    ,(or number '(gnus-summary-article-number)))))
2724
2725 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2726 (defmacro gnus-summary-article-subject (&optional number)
2727   "Return current subject string or nil if nothing."
2728   `(let ((headers
2729           ,(if number
2730                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2731              '(gnus-data-header (assq (gnus-summary-article-number)
2732                                       gnus-newsgroup-data)))))
2733      (and headers
2734           (vectorp headers)
2735           (mail-header-subject headers))))
2736
2737 (defmacro gnus-summary-article-score (&optional number)
2738   "Return current article score."
2739   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2740                   gnus-newsgroup-scored))
2741        gnus-summary-default-score 0))
2742
2743 (defun gnus-summary-article-children (&optional number)
2744   "Return a list of article numbers that are children of article NUMBER."
2745   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2746          (level (gnus-data-level (car data)))
2747          l children)
2748     (while (and (setq data (cdr data))
2749                 (> (setq l (gnus-data-level (car data))) level))
2750       (and (= (1+ level) l)
2751            (push (gnus-data-number (car data))
2752                  children)))
2753     (nreverse children)))
2754
2755 (defun gnus-summary-article-parent (&optional number)
2756   "Return the article number of the parent of article NUMBER."
2757   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2758                                     (gnus-data-list t)))
2759          (level (gnus-data-level (car data))))
2760     (if (zerop level)
2761         ()                              ; This is a root.
2762       ;; We search until we find an article with a level less than
2763       ;; this one.  That function has to be the parent.
2764       (while (and (setq data (cdr data))
2765                   (not (< (gnus-data-level (car data)) level))))
2766       (and data (gnus-data-number (car data))))))
2767
2768 (defun gnus-unread-mark-p (mark)
2769   "Say whether MARK is the unread mark."
2770   (= mark gnus-unread-mark))
2771
2772 (defun gnus-read-mark-p (mark)
2773   "Say whether MARK is one of the marks that mark as read.
2774 This is all marks except unread, ticked, dormant, and expirable."
2775   (not (or (= mark gnus-unread-mark)
2776            (= mark gnus-ticked-mark)
2777            (= mark gnus-dormant-mark)
2778            (= mark gnus-expirable-mark))))
2779
2780 (defmacro gnus-article-mark (number)
2781   "Return the MARK of article NUMBER.
2782 This macro should only be used when computing the mark the \"first\"
2783 time; i.e., when generating the summary lines.  After that,
2784 `gnus-summary-article-mark' should be used to examine the
2785 marks of articles."
2786   `(cond
2787     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2788     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2789     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2790     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2791     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2792     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2793     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2794     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2795            gnus-ancient-mark))))
2796
2797 ;; Saving hidden threads.
2798
2799 (defmacro gnus-save-hidden-threads (&rest forms)
2800   "Save hidden threads, eval FORMS, and restore the hidden threads."
2801   (let ((config (make-symbol "config")))
2802     `(let ((,config (gnus-hidden-threads-configuration)))
2803        (unwind-protect
2804            (save-excursion
2805              ,@forms)
2806          (gnus-restore-hidden-threads-configuration ,config)))))
2807 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2808 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2809
2810 (defun gnus-data-compute-positions ()
2811   "Compute the positions of all articles."
2812   (setq gnus-newsgroup-data-reverse nil)
2813   (let ((data gnus-newsgroup-data))
2814     (save-excursion
2815       (gnus-save-hidden-threads
2816         (gnus-summary-show-all-threads)
2817         (goto-char (point-min))
2818         (while data
2819           (while (get-text-property (point) 'gnus-intangible)
2820             (forward-line 1))
2821           (gnus-data-set-pos (car data) (+ (point) 3))
2822           (setq data (cdr data))
2823           (forward-line 1))))))
2824
2825 (defun gnus-hidden-threads-configuration ()
2826   "Return the current hidden threads configuration."
2827   (save-excursion
2828     (let (config)
2829       (goto-char (point-min))
2830       (while (search-forward "\r" nil t)
2831         (push (1- (point)) config))
2832       config)))
2833
2834 (defun gnus-restore-hidden-threads-configuration (config)
2835   "Restore hidden threads configuration from CONFIG."
2836   (save-excursion
2837     (let (point buffer-read-only)
2838       (while (setq point (pop config))
2839         (when (and (< point (point-max))
2840                    (goto-char point)
2841                    (eq (char-after) ?\n))
2842           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2843
2844 ;; Various summary mode internalish functions.
2845
2846 (defun gnus-mouse-pick-article (e)
2847   (interactive "e")
2848   (mouse-set-point e)
2849   (gnus-summary-next-page nil t))
2850
2851 (defun gnus-summary-set-display-table ()
2852   "Change the display table.
2853 Odd characters have a tendency to mess
2854 up nicely formatted displays - we make all possible glyphs
2855 display only a single character."
2856
2857   ;; We start from the standard display table, if any.
2858   (let ((table (or (copy-sequence standard-display-table)
2859                    (make-display-table)))
2860         (i 32))
2861     ;; Nix out all the control chars...
2862     (while (>= (setq i (1- i)) 0)
2863       (aset table i [??]))
2864     ;; ... but not newline and cr, of course.  (cr is necessary for the
2865     ;; selective display).
2866     (aset table ?\n nil)
2867     (aset table ?\r nil)
2868     ;; We keep TAB as well.
2869     (aset table ?\t nil)
2870     ;; We nix out any glyphs over 126 that are not set already.
2871     (let ((i 256))
2872       (while (>= (setq i (1- i)) 127)
2873         ;; Only modify if the entry is nil.
2874         (unless (aref table i)
2875           (aset table i [??]))))
2876     (setq buffer-display-table table)))
2877
2878 (defun gnus-summary-set-article-display-arrow (pos)
2879   "Update the overlay arrow to point to line at position POS."
2880   (when (and gnus-summary-display-arrow
2881              (boundp 'overlay-arrow-position)
2882              (boundp 'overlay-arrow-string))
2883     (save-excursion
2884       (goto-char pos)
2885       (beginning-of-line)
2886       (unless overlay-arrow-position
2887         (setq overlay-arrow-position (make-marker)))
2888       (setq overlay-arrow-string "=>"
2889             overlay-arrow-position (set-marker overlay-arrow-position
2890                                                (point)
2891                                                (current-buffer))))))
2892
2893 (defun gnus-summary-buffer-name (group)
2894   "Return the summary buffer name of GROUP."
2895   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2896
2897 (defun gnus-summary-setup-buffer (group)
2898   "Initialize summary buffer."
2899   (let ((buffer (gnus-summary-buffer-name group))
2900         (dead-name (concat "*Dead Summary "
2901                            (gnus-group-decoded-name group) "*")))
2902     ;; If a dead summary buffer exists, we kill it.
2903     (when (gnus-buffer-live-p dead-name)
2904       (gnus-kill-buffer dead-name))
2905     (if (get-buffer buffer)
2906         (progn
2907           (set-buffer buffer)
2908           (setq gnus-summary-buffer (current-buffer))
2909           (not gnus-newsgroup-prepared))
2910       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2911       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2912       (gnus-summary-mode group)
2913       (when gnus-carpal
2914         (gnus-carpal-setup-buffer 'summary))
2915       (unless gnus-single-article-buffer
2916         (make-local-variable 'gnus-article-buffer)
2917         (make-local-variable 'gnus-article-current)
2918         (make-local-variable 'gnus-original-article-buffer))
2919       (setq gnus-newsgroup-name group)
2920       ;; Set any local variables in the group parameters.
2921       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2922       t)))
2923
2924 (defun gnus-set-global-variables ()
2925   "Set the global equivalents of the buffer-local variables.
2926 They are set to the latest values they had.  These reflect the summary
2927 buffer that was in action when the last article was fetched."
2928   (when (eq major-mode 'gnus-summary-mode)
2929     (setq gnus-summary-buffer (current-buffer))
2930     (let ((name gnus-newsgroup-name)
2931           (marked gnus-newsgroup-marked)
2932           (unread gnus-newsgroup-unreads)
2933           (headers gnus-current-headers)
2934           (data gnus-newsgroup-data)
2935           (summary gnus-summary-buffer)
2936           (article-buffer gnus-article-buffer)
2937           (original gnus-original-article-buffer)
2938           (gac gnus-article-current)
2939           (reffed gnus-reffed-article-number)
2940           (score-file gnus-current-score-file)
2941           (default-charset gnus-newsgroup-charset)
2942           vlist)
2943       (let ((locals gnus-newsgroup-variables))
2944         (while locals
2945           (if (consp (car locals))
2946               (push (eval (caar locals)) vlist)
2947             (push (eval (car locals)) vlist))
2948           (setq locals (cdr locals)))
2949         (setq vlist (nreverse vlist)))
2950       (save-excursion
2951         (set-buffer gnus-group-buffer)
2952         (setq gnus-newsgroup-name name
2953               gnus-newsgroup-marked marked
2954               gnus-newsgroup-unreads unread
2955               gnus-current-headers headers
2956               gnus-newsgroup-data data
2957               gnus-article-current gac
2958               gnus-summary-buffer summary
2959               gnus-article-buffer article-buffer
2960               gnus-original-article-buffer original
2961               gnus-reffed-article-number reffed
2962               gnus-current-score-file score-file
2963               gnus-newsgroup-charset default-charset)
2964         (let ((locals gnus-newsgroup-variables))
2965           (while locals
2966             (if (consp (car locals))
2967                 (set (caar locals) (pop vlist))
2968               (set (car locals) (pop vlist)))
2969             (setq locals (cdr locals))))
2970         ;; The article buffer also has local variables.
2971         (when (gnus-buffer-live-p gnus-article-buffer)
2972           (set-buffer gnus-article-buffer)
2973           (setq gnus-summary-buffer summary))))))
2974
2975 (defun gnus-summary-article-unread-p (article)
2976   "Say whether ARTICLE is unread or not."
2977   (memq article gnus-newsgroup-unreads))
2978
2979 (defun gnus-summary-first-article-p (&optional article)
2980   "Return whether ARTICLE is the first article in the buffer."
2981   (if (not (setq article (or article (gnus-summary-article-number))))
2982       nil
2983     (eq article (caar gnus-newsgroup-data))))
2984
2985 (defun gnus-summary-last-article-p (&optional article)
2986   "Return whether ARTICLE is the last article in the buffer."
2987   (if (not (setq article (or article (gnus-summary-article-number))))
2988       ;; All non-existent numbers are the last article.  :-)
2989       t
2990     (not (cdr (gnus-data-find-list article)))))
2991
2992 (defun gnus-make-thread-indent-array ()
2993   (let ((n 200))
2994     (unless (and gnus-thread-indent-array
2995                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2996       (setq gnus-thread-indent-array (make-vector 201 "")
2997             gnus-thread-indent-array-level gnus-thread-indent-level)
2998       (while (>= n 0)
2999         (aset gnus-thread-indent-array n
3000               (make-string (* n gnus-thread-indent-level) ? ))
3001         (setq n (1- n))))))
3002
3003 (defun gnus-update-summary-mark-positions ()
3004   "Compute where the summary marks are to go."
3005   (save-excursion
3006     (when (gnus-buffer-exists-p gnus-summary-buffer)
3007       (set-buffer gnus-summary-buffer))
3008     (let ((gnus-replied-mark 129)
3009           (gnus-score-below-mark 130)
3010           (gnus-score-over-mark 130)
3011           (gnus-download-mark 131)
3012           (spec gnus-summary-line-format-spec)
3013           gnus-visual pos)
3014       (save-excursion
3015         (gnus-set-work-buffer)
3016         (let ((gnus-summary-line-format-spec spec)
3017               (gnus-newsgroup-downloadable '((0 . t))))
3018           (gnus-summary-insert-line
3019            (make-full-mail-header 0 "" "nobody"
3020                                   "05 Apr 2001 23:33:09 +0400"
3021                                   "" "" 0 0 "" nil)
3022            0 nil 128 t nil "" nil 1)
3023           (goto-char (point-min))
3024           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3025                                              (- (point) 2)))))
3026           (goto-char (point-min))
3027           (push (cons 'replied (and (search-forward "\201" nil t)
3028                                     (- (point) 2)))
3029                 pos)
3030           (goto-char (point-min))
3031           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
3032                 pos)
3033           (goto-char (point-min))
3034           (push (cons 'download
3035                       (and (search-forward "\203" nil t) (- (point) 2)))
3036                 pos)))
3037       (setq gnus-summary-mark-positions pos))))
3038
3039 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3040   "Insert a dummy root in the summary buffer."
3041   (beginning-of-line)
3042   (gnus-add-text-properties
3043    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3044    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3045
3046 (defun gnus-summary-extract-address-component (from)
3047   (or (car (funcall gnus-extract-address-components from))
3048       from))
3049
3050 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3051   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3052                                 default-mime-charset)))
3053     ;; Is it really necessary to do this next part for each summary line?
3054     ;; Luckily, doesn't seem to slow things down much.
3055     (or
3056      (and gnus-ignored-from-addresses
3057           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3058           (let ((extra-headers (mail-header-extra header))
3059                 to
3060                 newsgroups)
3061             (cond
3062              ((setq to (cdr (assq 'To extra-headers)))
3063               (concat "-> "
3064                       (inline
3065                         (gnus-summary-extract-address-component
3066                          (funcall gnus-decode-encoded-word-function to)))))
3067              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3068               (concat "=> " newsgroups)))))
3069      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3070
3071 (defun gnus-summary-insert-line (gnus-tmp-header
3072                                  gnus-tmp-level gnus-tmp-current
3073                                  gnus-tmp-unread gnus-tmp-replied
3074                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3075                                  &optional gnus-tmp-dummy gnus-tmp-score
3076                                  gnus-tmp-process)
3077   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3078          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3079          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3080          (gnus-tmp-score-char
3081           (if (or (null gnus-summary-default-score)
3082                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3083                       gnus-summary-zcore-fuzz))
3084               ?\ ;;;Whitespace
3085             (if (< gnus-tmp-score gnus-summary-default-score)
3086                 gnus-score-below-mark gnus-score-over-mark)))
3087          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3088          (gnus-tmp-replied
3089           (cond (gnus-tmp-process gnus-process-mark)
3090                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3091                  gnus-cached-mark)
3092                 (gnus-tmp-replied gnus-replied-mark)
3093                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3094                  gnus-forwarded-mark)
3095                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3096                  gnus-saved-mark)
3097                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3098                  gnus-recent-mark)
3099                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3100                  gnus-unseen-mark)
3101                 (t gnus-no-mark)))
3102          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3103          (gnus-tmp-name
3104           (cond
3105            ((string-match "<[^>]+> *$" gnus-tmp-from)
3106             (let ((beg (match-beginning 0)))
3107               (or (and (string-match "^\".+\"" gnus-tmp-from)
3108                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3109                   (substring gnus-tmp-from 0 beg))))
3110            ((string-match "(.+)" gnus-tmp-from)
3111             (substring gnus-tmp-from
3112                        (1+ (match-beginning 0)) (1- (match-end 0))))
3113            (t gnus-tmp-from)))
3114          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3115          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3116          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3117          (buffer-read-only nil))
3118     (when (string= gnus-tmp-name "")
3119       (setq gnus-tmp-name gnus-tmp-from))
3120     (unless (numberp gnus-tmp-lines)
3121       (setq gnus-tmp-lines -1))
3122     (if (= gnus-tmp-lines -1)
3123         (setq gnus-tmp-lines "?")
3124       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3125     (gnus-put-text-property-excluding-characters-with-faces
3126      (point)
3127      (progn (eval gnus-summary-line-format-spec) (point))
3128      'gnus-number gnus-tmp-number)
3129     (when (gnus-visual-p 'summary-highlight 'highlight)
3130       (forward-line -1)
3131       (gnus-run-hooks 'gnus-summary-update-hook)
3132       (forward-line 1))))
3133
3134 (defun gnus-summary-update-line (&optional dont-update)
3135   "Update summary line after change."
3136   (when (and gnus-summary-default-score
3137              (not gnus-summary-inhibit-highlight))
3138     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3139            (article (gnus-summary-article-number))
3140            (score (gnus-summary-article-score article)))
3141       (unless dont-update
3142         (if (and gnus-summary-mark-below
3143                  (< (gnus-summary-article-score)
3144                     gnus-summary-mark-below))
3145             ;; This article has a low score, so we mark it as read.
3146             (when (memq article gnus-newsgroup-unreads)
3147               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3148           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3149             ;; This article was previously marked as read on account
3150             ;; of a low score, but now it has risen, so we mark it as
3151             ;; unread.
3152             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3153         (gnus-summary-update-mark
3154          (if (or (null gnus-summary-default-score)
3155                  (<= (abs (- score gnus-summary-default-score))
3156                      gnus-summary-zcore-fuzz))
3157              ?\ ;;;Whitespace
3158            (if (< score gnus-summary-default-score)
3159                gnus-score-below-mark gnus-score-over-mark))
3160          'score))
3161       ;; Do visual highlighting.
3162       (when (gnus-visual-p 'summary-highlight 'highlight)
3163         (gnus-run-hooks 'gnus-summary-update-hook)))))
3164
3165 (defvar gnus-tmp-new-adopts nil)
3166
3167 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3168   "Return the number of articles in THREAD.
3169 This may be 0 in some cases -- if none of the articles in
3170 the thread are to be displayed."
3171   (let* ((number
3172           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3173           (cond
3174            ((not (listp thread))
3175             1)
3176            ((and (consp thread) (cdr thread))
3177             (apply
3178              '+ 1 (mapcar
3179                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3180            ((null thread)
3181             1)
3182            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3183             1)
3184            (t 0))))
3185     (when (and level (zerop level) gnus-tmp-new-adopts)
3186       (incf number
3187             (apply '+ (mapcar
3188                        'gnus-summary-number-of-articles-in-thread
3189                        gnus-tmp-new-adopts))))
3190     (if char
3191         (if (> number 1) gnus-not-empty-thread-mark
3192           gnus-empty-thread-mark)
3193       number)))
3194
3195 (defun gnus-summary-set-local-parameters (group)
3196   "Go through the local params of GROUP and set all variable specs in that list."
3197   (let ((params (gnus-group-find-parameter group))
3198         (vars '(quit-config))           ; Ignore quit-config.
3199         elem)
3200     (while params
3201       (setq elem (car params)
3202             params (cdr params))
3203       (and (consp elem)                 ; Has to be a cons.
3204            (consp (cdr elem))           ; The cdr has to be a list.
3205            (symbolp (car elem))         ; Has to be a symbol in there.
3206            (not (memq (car elem) vars))
3207            (ignore-errors               ; So we set it.
3208              (push (car elem) vars)
3209              (make-local-variable (car elem))
3210              (set (car elem) (eval (nth 1 elem))))))))
3211
3212 (defun gnus-summary-read-group (group &optional show-all no-article
3213                                       kill-buffer no-display backward
3214                                       select-articles)
3215   "Start reading news in newsgroup GROUP.
3216 If SHOW-ALL is non-nil, already read articles are also listed.
3217 If NO-ARTICLE is non-nil, no article is selected initially.
3218 If NO-DISPLAY, don't generate a summary buffer."
3219   (let (result)
3220     (while (and group
3221                 (null (setq result
3222                             (let ((gnus-auto-select-next nil))
3223                               (or (gnus-summary-read-group-1
3224                                    group show-all no-article
3225                                    kill-buffer no-display
3226                                    select-articles)
3227                                   (setq show-all nil
3228                                         select-articles nil)))))
3229                 (eq gnus-auto-select-next 'quietly))
3230       (set-buffer gnus-group-buffer)
3231       ;; The entry function called above goes to the next
3232       ;; group automatically, so we go two groups back
3233       ;; if we are searching for the previous group.
3234       (when backward
3235         (gnus-group-prev-unread-group 2))
3236       (if (not (equal group (gnus-group-group-name)))
3237           (setq group (gnus-group-group-name))
3238         (setq group nil)))
3239     result))
3240
3241 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3242   "Directly jump to the other GROUP from summary buffer.
3243 If SHOW-ALL is non-nil, already read articles are also listed."
3244   (interactive
3245    (if (eq gnus-summary-buffer (current-buffer))
3246        (list (completing-read
3247               "Group: " gnus-active-hashtb nil t
3248               (when (and gnus-newsgroup-name
3249                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3250                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3251               'gnus-group-history)
3252              current-prefix-arg)
3253      (error "%s must be invoked from a gnus summary buffer." this-command)))
3254   (unless (or (zerop (length group))
3255               (and gnus-newsgroup-name
3256                    (string-equal gnus-newsgroup-name group)))
3257     (gnus-summary-exit)
3258     (gnus-summary-read-group group show-all
3259                              gnus-dont-select-after-jump-to-other-group)))
3260
3261 (defun gnus-summary-read-group-1 (group show-all no-article
3262                                         kill-buffer no-display
3263                                         &optional select-articles)
3264   ;; Killed foreign groups can't be entered.
3265   ;;  (when (and (not (gnus-group-native-p group))
3266   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3267   ;;    (error "Dead non-native groups can't be entered"))
3268   (gnus-message 5 "Retrieving newsgroup: %s..."
3269                 (gnus-group-decoded-name group))
3270   (let* ((new-group (gnus-summary-setup-buffer group))
3271          (quit-config (gnus-group-quit-config group))
3272          (did-select (and new-group (gnus-select-newsgroup
3273                                      group show-all select-articles))))
3274     (cond
3275      ;; This summary buffer exists already, so we just select it.
3276      ((not new-group)
3277       (gnus-set-global-variables)
3278       (when kill-buffer
3279         (gnus-kill-or-deaden-summary kill-buffer))
3280       (gnus-configure-windows 'summary 'force)
3281       (gnus-set-mode-line 'summary)
3282       (gnus-summary-position-point)
3283       (message "")
3284       t)
3285      ;; We couldn't select this group.
3286      ((null did-select)
3287       (when (and (eq major-mode 'gnus-summary-mode)
3288                  (not (equal (current-buffer) kill-buffer)))
3289         (kill-buffer (current-buffer))
3290         (if (not quit-config)
3291             (progn
3292               ;; Update the info -- marks might need to be removed,
3293               ;; for instance.
3294               (gnus-summary-update-info)
3295               (set-buffer gnus-group-buffer)
3296               (gnus-group-jump-to-group group)
3297               (gnus-group-next-unread-group 1))
3298           (gnus-handle-ephemeral-exit quit-config)))
3299       (let ((grpinfo (gnus-get-info group)))
3300         (if (null (gnus-info-read grpinfo))
3301             (gnus-message 3 "Group %s contains no messages"
3302                           (gnus-group-decoded-name group))
3303           (gnus-message 3 "Can't select group")))
3304       nil)
3305      ;; The user did a `C-g' while prompting for number of articles,
3306      ;; so we exit this group.
3307      ((eq did-select 'quit)
3308       (and (eq major-mode 'gnus-summary-mode)
3309            (not (equal (current-buffer) kill-buffer))
3310            (kill-buffer (current-buffer)))
3311       (when kill-buffer
3312         (gnus-kill-or-deaden-summary kill-buffer))
3313       (if (not quit-config)
3314           (progn
3315             (set-buffer gnus-group-buffer)
3316             (gnus-group-jump-to-group group)
3317             (gnus-group-next-unread-group 1)
3318             (gnus-configure-windows 'group 'force))
3319         (gnus-handle-ephemeral-exit quit-config))
3320       ;; Finally signal the quit.
3321       (signal 'quit nil))
3322      ;; The group was successfully selected.
3323      (t
3324       (gnus-set-global-variables)
3325       ;; Save the active value in effect when the group was entered.
3326       (setq gnus-newsgroup-active
3327             (gnus-copy-sequence
3328              (gnus-active gnus-newsgroup-name)))
3329       ;; You can change the summary buffer in some way with this hook.
3330       (gnus-run-hooks 'gnus-select-group-hook)
3331       (gnus-update-format-specifications
3332        nil 'summary 'summary-mode 'summary-dummy)
3333       (gnus-update-summary-mark-positions)
3334       ;; Do score processing.
3335       (when gnus-use-scoring
3336         (gnus-possibly-score-headers))
3337       ;; Check whether to fill in the gaps in the threads.
3338       (when gnus-build-sparse-threads
3339         (gnus-build-sparse-threads))
3340       ;; Find the initial limit.
3341       (if gnus-show-threads
3342           (if show-all
3343               (let ((gnus-newsgroup-dormant nil))
3344                 (gnus-summary-initial-limit show-all))
3345             (gnus-summary-initial-limit show-all))
3346         ;; When untreaded, all articles are always shown.
3347         (setq gnus-newsgroup-limit
3348               (mapcar
3349                (lambda (header) (mail-header-number header))
3350                gnus-newsgroup-headers)))
3351       ;; Generate the summary buffer.
3352       (unless no-display
3353         (gnus-summary-prepare))
3354       (when gnus-use-trees
3355         (gnus-tree-open group)
3356         (setq gnus-summary-highlight-line-function
3357               'gnus-tree-highlight-article))
3358       ;; If the summary buffer is empty, but there are some low-scored
3359       ;; articles or some excluded dormants, we include these in the
3360       ;; buffer.
3361       (when (and (zerop (buffer-size))
3362                  (not no-display))
3363         (cond (gnus-newsgroup-dormant
3364                (gnus-summary-limit-include-dormant))
3365               ((and gnus-newsgroup-scored show-all)
3366                (gnus-summary-limit-include-expunged t))))
3367       ;; Function `gnus-apply-kill-file' must be called in this hook.
3368       (gnus-run-hooks 'gnus-apply-kill-hook)
3369       (if (and (zerop (buffer-size))
3370                (not no-display))
3371           (progn
3372             ;; This newsgroup is empty.
3373             (gnus-summary-catchup-and-exit nil t)
3374             (gnus-message 6 "No unread news")
3375             (when kill-buffer
3376               (gnus-kill-or-deaden-summary kill-buffer))
3377             ;; Return nil from this function.
3378             nil)
3379         ;; Hide conversation thread subtrees.  We cannot do this in
3380         ;; gnus-summary-prepare-hook since kill processing may not
3381         ;; work with hidden articles.
3382         (gnus-summary-maybe-hide-threads)
3383         (when kill-buffer
3384           (gnus-kill-or-deaden-summary kill-buffer))
3385         (gnus-summary-auto-select-subject)
3386         ;; Show first unread article if requested.
3387         (if (and (not no-article)
3388                  (not no-display)
3389                  gnus-newsgroup-unreads
3390                  gnus-auto-select-first)
3391             (progn
3392               (gnus-configure-windows 'summary)
3393               (let ((art (gnus-summary-article-number)))
3394                 (unless (or (memq art gnus-newsgroup-undownloaded)
3395                             (memq art gnus-newsgroup-downloadable))
3396                   (gnus-summary-goto-article art))))
3397           ;; Don't select any articles.
3398           (gnus-summary-position-point)
3399           (gnus-configure-windows 'summary 'force)
3400           (gnus-set-mode-line 'summary))
3401         (when (get-buffer-window gnus-group-buffer t)
3402           ;; Gotta use windows, because recenter does weird stuff if
3403           ;; the current buffer ain't the displayed window.
3404           (let ((owin (selected-window)))
3405             (select-window (get-buffer-window gnus-group-buffer t))
3406             (when (gnus-group-goto-group group)
3407               (recenter))
3408             (select-window owin)))
3409         ;; Mark this buffer as "prepared".
3410         (setq gnus-newsgroup-prepared t)
3411         (gnus-run-hooks 'gnus-summary-prepared-hook)
3412         t)))))
3413
3414 (defun gnus-summary-auto-select-subject ()
3415   "Select the subject line on initial group entry."
3416   (goto-char (point-min))
3417   (cond
3418    ((eq gnus-auto-select-subject 'best)
3419     (gnus-summary-best-unread-subject))
3420    ((eq gnus-auto-select-subject 'unread)
3421     (gnus-summary-first-unread-subject))
3422    ((eq gnus-auto-select-subject 'unseen)
3423     (gnus-summary-first-unseen-subject))
3424    ((eq gnus-auto-select-subject 'unseen-or-unread)
3425     (gnus-summary-first-unseen-or-unread-subject))
3426    ((eq gnus-auto-select-subject 'first)
3427     ;; Do nothing.
3428     )
3429    ((gnus-functionp gnus-auto-select-subject)
3430     (funcall gnus-auto-select-subject))))
3431
3432 (defun gnus-summary-prepare ()
3433   "Generate the summary buffer."
3434   (interactive)
3435   (let ((buffer-read-only nil))
3436     (erase-buffer)
3437     (setq gnus-newsgroup-data nil
3438           gnus-newsgroup-data-reverse nil)
3439     (gnus-run-hooks 'gnus-summary-generate-hook)
3440     ;; Generate the buffer, either with threads or without.
3441     (when gnus-newsgroup-headers
3442       (gnus-summary-prepare-threads
3443        (if gnus-show-threads
3444            (gnus-sort-gathered-threads
3445             (funcall gnus-summary-thread-gathering-function
3446                      (gnus-sort-threads
3447                       (gnus-cut-threads (gnus-make-threads)))))
3448          ;; Unthreaded display.
3449          (gnus-sort-articles gnus-newsgroup-headers))))
3450     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3451     ;; Call hooks for modifying summary buffer.
3452     (goto-char (point-min))
3453     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3454
3455 (defsubst gnus-general-simplify-subject (subject)
3456   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3457   (setq subject
3458         (cond
3459          ;; Truncate the subject.
3460          (gnus-simplify-subject-functions
3461           (gnus-map-function gnus-simplify-subject-functions subject))
3462          ((numberp gnus-summary-gather-subject-limit)
3463           (setq subject (gnus-simplify-subject-re subject))
3464           (if (> (length subject) gnus-summary-gather-subject-limit)
3465               (substring subject 0 gnus-summary-gather-subject-limit)
3466             subject))
3467          ;; Fuzzily simplify it.
3468          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3469           (gnus-simplify-subject-fuzzy subject))
3470          ;; Just remove the leading "Re:".
3471          (t
3472           (gnus-simplify-subject-re subject))))
3473
3474   (if (and gnus-summary-gather-exclude-subject
3475            (string-match gnus-summary-gather-exclude-subject subject))
3476       nil                               ; This article shouldn't be gathered
3477     subject))
3478
3479 (defun gnus-summary-simplify-subject-query ()
3480   "Query where the respool algorithm would put this article."
3481   (interactive)
3482   (gnus-summary-select-article)
3483   (message "%s"
3484            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3485
3486 (defun gnus-gather-threads-by-subject (threads)
3487   "Gather threads by looking at Subject headers."
3488   (if (not gnus-summary-make-false-root)
3489       threads
3490     (let ((hashtb (gnus-make-hashtable 1024))
3491           (prev threads)
3492           (result threads)
3493           subject hthread whole-subject)
3494       (while threads
3495         (setq subject (gnus-general-simplify-subject
3496                        (setq whole-subject (mail-header-subject
3497                                             (caar threads)))))
3498         (when subject
3499           (if (setq hthread (gnus-gethash subject hashtb))
3500               (progn
3501                 ;; We enter a dummy root into the thread, if we
3502                 ;; haven't done that already.
3503                 (unless (stringp (caar hthread))
3504                   (setcar hthread (list whole-subject (car hthread))))
3505                 ;; We add this new gathered thread to this gathered
3506                 ;; thread.
3507                 (setcdr (car hthread)
3508                         (nconc (cdar hthread) (list (car threads))))
3509                 ;; Remove it from the list of threads.
3510                 (setcdr prev (cdr threads))
3511                 (setq threads prev))
3512             ;; Enter this thread into the hash table.
3513             (gnus-sethash subject threads hashtb)))
3514         (setq prev threads)
3515         (setq threads (cdr threads)))
3516       result)))
3517
3518 (defun gnus-gather-threads-by-references (threads)
3519   "Gather threads by looking at References headers."
3520   (let ((idhashtb (gnus-make-hashtable 1024))
3521         (thhashtb (gnus-make-hashtable 1024))
3522         (prev threads)
3523         (result threads)
3524         ids references id gthread gid entered ref)
3525     (while threads
3526       (when (setq references (mail-header-references (caar threads)))
3527         (setq id (mail-header-id (caar threads))
3528               ids (inline (gnus-split-references references))
3529               entered nil)
3530         (while (setq ref (pop ids))
3531           (setq ids (delete ref ids))
3532           (if (not (setq gid (gnus-gethash ref idhashtb)))
3533               (progn
3534                 (gnus-sethash ref id idhashtb)
3535                 (gnus-sethash id threads thhashtb))
3536             (setq gthread (gnus-gethash gid thhashtb))
3537             (unless entered
3538               ;; We enter a dummy root into the thread, if we
3539               ;; haven't done that already.
3540               (unless (stringp (caar gthread))
3541                 (setcar gthread (list (mail-header-subject (caar gthread))
3542                                       (car gthread))))
3543               ;; We add this new gathered thread to this gathered
3544               ;; thread.
3545               (setcdr (car gthread)
3546                       (nconc (cdar gthread) (list (car threads)))))
3547             ;; Add it into the thread hash table.
3548             (gnus-sethash id gthread thhashtb)
3549             (setq entered t)
3550             ;; Remove it from the list of threads.
3551             (setcdr prev (cdr threads))
3552             (setq threads prev))))
3553       (setq prev threads)
3554       (setq threads (cdr threads)))
3555     result))
3556
3557 (defun gnus-sort-gathered-threads (threads)
3558   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3559   (let ((result threads))
3560     (while threads
3561       (when (stringp (caar threads))
3562         (setcdr (car threads)
3563                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3564       (setq threads (cdr threads)))
3565     result))
3566
3567 (defun gnus-thread-loop-p (root thread)
3568   "Say whether ROOT is in THREAD."
3569   (let ((stack (list thread))
3570         (infloop 0)
3571         th)
3572     (while (setq thread (pop stack))
3573       (setq th (cdr thread))
3574       (while (and th
3575                   (not (eq (caar th) root)))
3576         (pop th))
3577       (if th
3578           ;; We have found a loop.
3579           (let (ref-dep)
3580             (setcdr thread (delq (car th) (cdr thread)))
3581             (if (boundp (setq ref-dep (intern "none"
3582                                               gnus-newsgroup-dependencies)))
3583                 (setcdr (symbol-value ref-dep)
3584                         (nconc (cdr (symbol-value ref-dep))
3585                                (list (car th))))
3586               (set ref-dep (list nil (car th))))
3587             (setq infloop 1
3588                   stack nil))
3589         ;; Push all the subthreads onto the stack.
3590         (push (cdr thread) stack)))
3591     infloop))
3592
3593 (defun gnus-make-threads ()
3594   "Go through the dependency hashtb and find the roots.  Return all threads."
3595   (let (threads)
3596     (while (catch 'infloop
3597              (mapatoms
3598               (lambda (refs)
3599                 ;; Deal with self-referencing References loops.
3600                 (when (and (car (symbol-value refs))
3601                            (not (zerop
3602                                  (apply
3603                                   '+
3604                                   (mapcar
3605                                    (lambda (thread)
3606                                      (gnus-thread-loop-p
3607                                       (car (symbol-value refs)) thread))
3608                                    (cdr (symbol-value refs)))))))
3609                   (setq threads nil)
3610                   (throw 'infloop t))
3611                 (unless (car (symbol-value refs))
3612                   ;; These threads do not refer back to any other articles,
3613                   ;; so they're roots.
3614                   (setq threads (append (cdr (symbol-value refs)) threads))))
3615               gnus-newsgroup-dependencies)))
3616     threads))
3617
3618 ;; Build the thread tree.
3619 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3620   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3621
3622 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3623 if it was already present.
3624
3625 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3626 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3627 Message-IDs will be renamed to a unique Message-ID before being
3628 entered.
3629
3630 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3631   (let* ((id (mail-header-id header))
3632          (id-dep (and id (intern id dependencies)))
3633          ref ref-dep ref-header replaced)
3634     ;; Enter this `header' in the `dependencies' table.
3635     (cond
3636      ((not id-dep)
3637       (setq header nil))
3638      ;; The first two cases do the normal part: enter a new `header'
3639      ;; in the `dependencies' table.
3640      ((not (boundp id-dep))
3641       (set id-dep (list header)))
3642      ((null (car (symbol-value id-dep)))
3643       (setcar (symbol-value id-dep) header))
3644
3645      ;; From here the `header' was already present in the
3646      ;; `dependencies' table.
3647      (force-new
3648       ;; Overrides an existing entry;
3649       ;; just set the header part of the entry.
3650       (setcar (symbol-value id-dep) header)
3651       (setq replaced t))
3652
3653      ;; Renames the existing `header' to a unique Message-ID.
3654      ((not gnus-summary-ignore-duplicates)
3655       ;; An article with this Message-ID has already been seen.
3656       ;; We rename the Message-ID.
3657       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3658            (list header))
3659       (mail-header-set-id header id))
3660
3661      ;; The last case ignores an existing entry, except it adds any
3662      ;; additional Xrefs (in case the two articles came from different
3663      ;; servers.
3664      ;; Also sets `header' to `nil' meaning that the `dependencies'
3665      ;; table was *not* modified.
3666      (t
3667       (mail-header-set-xref
3668        (car (symbol-value id-dep))
3669        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3670                    "")
3671                (or (mail-header-xref header) "")))
3672       (setq header nil)))
3673
3674     (when (and header (not replaced))
3675       ;; First check that we are not creating a References loop.
3676       (setq ref (gnus-parent-id (mail-header-references header)))
3677       (while (and ref
3678                   (setq ref-dep (intern-soft ref dependencies))
3679                   (boundp ref-dep)
3680                   (setq ref-header (car (symbol-value ref-dep))))
3681         (if (string= id ref)
3682             ;; Yuk!  This is a reference loop.  Make the article be a
3683             ;; root article.
3684             (progn
3685               (mail-header-set-references (car (symbol-value id-dep)) "none")
3686               (setq ref nil))
3687           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3688       (setq ref (gnus-parent-id (mail-header-references header)))
3689       (setq ref-dep (intern (or ref "none") dependencies))
3690       (if (boundp ref-dep)
3691           (setcdr (symbol-value ref-dep)
3692                   (nconc (cdr (symbol-value ref-dep))
3693                          (list (symbol-value id-dep))))
3694         (set ref-dep (list nil (symbol-value id-dep)))))
3695     header))
3696
3697 (defun gnus-extract-message-id-from-in-reply-to (string)
3698   (if (string-match "<[^>]+>" string)
3699       (substring string (match-beginning 0) (match-end 0))
3700     nil))
3701
3702 (defun gnus-build-sparse-threads ()
3703   (let ((headers gnus-newsgroup-headers)
3704         (mail-parse-charset gnus-newsgroup-charset)
3705         (gnus-summary-ignore-duplicates t)
3706         header references generation relations
3707         subject child end new-child date)
3708     ;; First we create an alist of generations/relations, where
3709     ;; generations is how much we trust the relation, and the relation
3710     ;; is parent/child.
3711     (gnus-message 7 "Making sparse threads...")
3712     (save-excursion
3713       (nnheader-set-temp-buffer " *gnus sparse threads*")
3714       (while (setq header (pop headers))
3715         (when (and (setq references (mail-header-references header))
3716                    (not (string= references "")))
3717           (insert references)
3718           (setq child (mail-header-id header)
3719                 subject (mail-header-subject header)
3720                 date (mail-header-date header)
3721                 generation 0)
3722           (while (search-backward ">" nil t)
3723             (setq end (1+ (point)))
3724             (when (search-backward "<" nil t)
3725               (setq new-child (buffer-substring (point) end))
3726               (push (list (incf generation)
3727                           child (setq child new-child)
3728                           subject date)
3729                     relations)))
3730           (when child
3731             (push (list (1+ generation) child nil subject) relations))
3732           (erase-buffer)))
3733       (kill-buffer (current-buffer)))
3734     ;; Sort over trustworthiness.
3735     (mapcar
3736      (lambda (relation)
3737        (when (gnus-dependencies-add-header
3738               (make-full-mail-header-from-decoded-header
3739                gnus-reffed-article-number
3740                (nth 3 relation) "" (or (nth 4 relation) "")
3741                (nth 1 relation)
3742                (or (nth 2 relation) "") 0 0 "")
3743               gnus-newsgroup-dependencies nil)
3744          (push gnus-reffed-article-number gnus-newsgroup-limit)
3745          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3746          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3747                gnus-newsgroup-reads)
3748          (decf gnus-reffed-article-number)))
3749      (sort relations 'car-less-than-car))
3750     (gnus-message 7 "Making sparse threads...done")))
3751
3752 (defun gnus-build-old-threads ()
3753   ;; Look at all the articles that refer back to old articles, and
3754   ;; fetch the headers for the articles that aren't there.  This will
3755   ;; build complete threads - if the roots haven't been expired by the
3756   ;; server, that is.
3757   (let ((mail-parse-charset gnus-newsgroup-charset)
3758         id heads)
3759     (mapatoms
3760      (lambda (refs)
3761        (when (not (car (symbol-value refs)))
3762          (setq heads (cdr (symbol-value refs)))
3763          (while heads
3764            (if (memq (mail-header-number (caar heads))
3765                      gnus-newsgroup-dormant)
3766                (setq heads (cdr heads))
3767              (setq id (symbol-name refs))
3768              (while (and (setq id (gnus-build-get-header id))
3769                          (not (car (gnus-id-to-thread id)))))
3770              (setq heads nil)))))
3771      gnus-newsgroup-dependencies)))
3772
3773 ;; This function has to be called with point after the article number
3774 ;; on the beginning of the line.
3775 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3776   (let ((eol (gnus-point-at-eol))
3777         (buffer (current-buffer))
3778         header references in-reply-to)
3779
3780     ;; overview: [num subject from date id refs chars lines misc]
3781     (unwind-protect
3782         (progn
3783           (narrow-to-region (point) eol)
3784           (unless (eobp)
3785             (forward-char))
3786
3787           (setq header
3788                 (make-full-mail-header
3789                  number                         ; number
3790                  (nnheader-nov-field)           ; subject
3791                  (nnheader-nov-field)           ; from
3792                  (nnheader-nov-field)           ; date
3793                  (nnheader-nov-read-message-id) ; id
3794                  (nnheader-nov-field)           ; refs
3795                  (nnheader-nov-read-integer)    ; chars
3796                  (nnheader-nov-read-integer)    ; lines
3797                  (unless (eobp)
3798                    (if (looking-at "Xref: ")
3799                        (goto-char (match-end 0)))
3800                    (nnheader-nov-field))        ; Xref
3801                  (nnheader-nov-parse-extra))))  ; extra
3802
3803       (widen))
3804
3805     (when (and (string= references "")
3806                (setq in-reply-to (mail-header-extra header))
3807                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3808       (mail-header-set-references
3809        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3810
3811     (when gnus-alter-header-function
3812       (funcall gnus-alter-header-function header))
3813     (gnus-dependencies-add-header header dependencies force-new)))
3814
3815 (defun gnus-build-get-header (id)
3816   "Look through the buffer of NOV lines and find the header to ID.
3817 Enter this line into the dependencies hash table, and return
3818 the id of the parent article (if any)."
3819   (let ((deps gnus-newsgroup-dependencies)
3820         found header)
3821     (prog1
3822         (save-excursion
3823           (set-buffer nntp-server-buffer)
3824           (let ((case-fold-search nil))
3825             (goto-char (point-min))
3826             (while (and (not found)
3827                         (search-forward id nil t))
3828               (beginning-of-line)
3829               (setq found (looking-at
3830                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3831                                    (regexp-quote id))))
3832               (or found (beginning-of-line 2)))
3833             (when found
3834               (beginning-of-line)
3835               (and
3836                (setq header (gnus-nov-parse-line
3837                              (read (current-buffer)) deps))
3838                (gnus-parent-id (mail-header-references header))))))
3839       (when header
3840         (let ((number (mail-header-number header)))
3841           (push number gnus-newsgroup-limit)
3842           (push header gnus-newsgroup-headers)
3843           (if (memq number gnus-newsgroup-unselected)
3844               (progn
3845                 (setq gnus-newsgroup-unreads
3846                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3847                                                number))
3848                 (setq gnus-newsgroup-unselected
3849                       (delq number gnus-newsgroup-unselected)))
3850             (push number gnus-newsgroup-ancient)))))))
3851
3852 (defun gnus-build-all-threads ()
3853   "Read all the headers."
3854   (let ((gnus-summary-ignore-duplicates t)
3855         (mail-parse-charset gnus-newsgroup-charset)
3856         (dependencies gnus-newsgroup-dependencies)
3857         header article)
3858     (save-excursion
3859       (set-buffer nntp-server-buffer)
3860       (let ((case-fold-search nil))
3861         (goto-char (point-min))
3862         (while (not (eobp))
3863           (ignore-errors
3864             (setq article (read (current-buffer))
3865                   header (gnus-nov-parse-line article dependencies)))
3866           (when header
3867             (save-excursion
3868               (set-buffer gnus-summary-buffer)
3869               (push header gnus-newsgroup-headers)
3870               (if (memq (setq article (mail-header-number header))
3871                         gnus-newsgroup-unselected)
3872                   (progn
3873                     (setq gnus-newsgroup-unreads
3874                           (gnus-add-to-sorted-list
3875                            gnus-newsgroup-unreads article))
3876                     (setq gnus-newsgroup-unselected
3877                           (delq article gnus-newsgroup-unselected)))
3878                 (push article gnus-newsgroup-ancient)))
3879             (forward-line 1)))))))
3880
3881 (defun gnus-summary-update-article-line (article header)
3882   "Update the line for ARTICLE using HEADERS."
3883   (let* ((id (mail-header-id header))
3884          (thread (gnus-id-to-thread id)))
3885     (unless thread
3886       (error "Article in no thread"))
3887     ;; Update the thread.
3888     (setcar thread header)
3889     (gnus-summary-goto-subject article)
3890     (let* ((datal (gnus-data-find-list article))
3891            (data (car datal))
3892            (length (when (cdr datal)
3893                      (- (gnus-data-pos data)
3894                         (gnus-data-pos (cadr datal)))))
3895            (buffer-read-only nil)
3896            (level (gnus-summary-thread-level)))
3897       (gnus-delete-line)
3898       (gnus-summary-insert-line
3899        header level nil (gnus-article-mark article)
3900        (memq article gnus-newsgroup-replied)
3901        (memq article gnus-newsgroup-expirable)
3902        ;; Only insert the Subject string when it's different
3903        ;; from the previous Subject string.
3904        (if (and
3905             gnus-show-threads
3906             (gnus-subject-equal
3907              (condition-case ()
3908                  (mail-header-subject
3909                   (gnus-data-header
3910                    (cadr
3911                     (gnus-data-find-list
3912                      article
3913                      (gnus-data-list t)))))
3914                ;; Error on the side of excessive subjects.
3915                (error ""))
3916              (mail-header-subject header)))
3917            ""
3918          (mail-header-subject header))
3919        nil (cdr (assq article gnus-newsgroup-scored))
3920        (memq article gnus-newsgroup-processable))
3921       (when length
3922         (gnus-data-update-list
3923          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3924
3925 (defun gnus-summary-update-article (article &optional iheader)
3926   "Update ARTICLE in the summary buffer."
3927   (set-buffer gnus-summary-buffer)
3928   (let* ((header (gnus-summary-article-header article))
3929          (id (mail-header-id header))
3930          (data (gnus-data-find article))
3931          (thread (gnus-id-to-thread id))
3932          (references (mail-header-references header))
3933          (parent
3934           (gnus-id-to-thread
3935            (or (gnus-parent-id
3936                 (when (and references
3937                            (not (equal "" references)))
3938                   references))
3939                "none")))
3940          (buffer-read-only nil)
3941          (old (car thread)))
3942     (when thread
3943       (unless iheader
3944         (setcar thread nil)
3945         (when parent
3946           (delq thread parent)))
3947       (if (gnus-summary-insert-subject id header)
3948           ;; Set the (possibly) new article number in the data structure.
3949           (gnus-data-set-number data (gnus-id-to-article id))
3950         (setcar thread old)
3951         nil))))
3952
3953 (defun gnus-rebuild-thread (id &optional line)
3954   "Rebuild the thread containing ID.
3955 If LINE, insert the rebuilt thread starting on line LINE."
3956   (let ((buffer-read-only nil)
3957         old-pos current thread data)
3958     (if (not gnus-show-threads)
3959         (setq thread (list (car (gnus-id-to-thread id))))
3960       ;; Get the thread this article is part of.
3961       (setq thread (gnus-remove-thread id)))
3962     (setq old-pos (gnus-point-at-bol))
3963     (setq current (save-excursion
3964                     (and (re-search-backward "[\r\n]" nil t)
3965                          (gnus-summary-article-number))))
3966     ;; If this is a gathered thread, we have to go some re-gathering.
3967     (when (stringp (car thread))
3968       (let ((subject (car thread))
3969             roots thr)
3970         (setq thread (cdr thread))
3971         (while thread
3972           (unless (memq (setq thr (gnus-id-to-thread
3973                                    (gnus-root-id
3974                                     (mail-header-id (caar thread)))))
3975                         roots)
3976             (push thr roots))
3977           (setq thread (cdr thread)))
3978         ;; We now have all (unique) roots.
3979         (if (= (length roots) 1)
3980             ;; All the loose roots are now one solid root.
3981             (setq thread (car roots))
3982           (setq thread (cons subject (gnus-sort-threads roots))))))
3983     (let (threads)
3984       ;; We then insert this thread into the summary buffer.
3985       (when line
3986         (goto-char (point-min))
3987         (forward-line (1- line)))
3988       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3989         (if gnus-show-threads
3990             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3991           (gnus-summary-prepare-unthreaded thread))
3992         (setq data (nreverse gnus-newsgroup-data))
3993         (setq threads gnus-newsgroup-threads))
3994       ;; We splice the new data into the data structure.
3995       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3996       ;;!!! then we want to insert at the beginning of the buffer.
3997       ;;!!! That happens to be true with Gnus now, but that may
3998       ;;!!! change in the future.  Perhaps.
3999       (gnus-data-enter-list
4000        (if line nil current) data (- (point) old-pos))
4001       (setq gnus-newsgroup-threads
4002             (nconc threads gnus-newsgroup-threads))
4003       (gnus-data-compute-positions))))
4004
4005 (defun gnus-number-to-header (number)
4006   "Return the header for article NUMBER."
4007   (let ((headers gnus-newsgroup-headers))
4008     (while (and headers
4009                 (not (= number (mail-header-number (car headers)))))
4010       (pop headers))
4011     (when headers
4012       (car headers))))
4013
4014 (defun gnus-parent-headers (in-headers &optional generation)
4015   "Return the headers of the GENERATIONeth parent of HEADERS."
4016   (unless generation
4017     (setq generation 1))
4018   (let ((parent t)
4019         (headers in-headers)
4020         references)
4021     (while (and parent
4022                 (not (zerop generation))
4023                 (setq references (mail-header-references headers)))
4024       (setq headers (if (and references
4025                              (setq parent (gnus-parent-id references)))
4026                         (car (gnus-id-to-thread parent))
4027                       nil))
4028       (decf generation))
4029     (and (not (eq headers in-headers))
4030          headers)))
4031
4032 (defun gnus-id-to-thread (id)
4033   "Return the (sub-)thread where ID appears."
4034   (gnus-gethash id gnus-newsgroup-dependencies))
4035
4036 (defun gnus-id-to-article (id)
4037   "Return the article number of ID."
4038   (let ((thread (gnus-id-to-thread id)))
4039     (when (and thread
4040                (car thread))
4041       (mail-header-number (car thread)))))
4042
4043 (defun gnus-id-to-header (id)
4044   "Return the article headers of ID."
4045   (car (gnus-id-to-thread id)))
4046
4047 (defun gnus-article-displayed-root-p (article)
4048   "Say whether ARTICLE is a root(ish) article."
4049   (let ((level (gnus-summary-thread-level article))
4050         (refs (mail-header-references  (gnus-summary-article-header article)))
4051         particle)
4052     (cond
4053      ((null level) nil)
4054      ((zerop level) t)
4055      ((null refs) t)
4056      ((null (gnus-parent-id refs)) t)
4057      ((and (= 1 level)
4058            (null (setq particle (gnus-id-to-article
4059                                  (gnus-parent-id refs))))
4060            (null (gnus-summary-thread-level particle)))))))
4061
4062 (defun gnus-root-id (id)
4063   "Return the id of the root of the thread where ID appears."
4064   (let (last-id prev)
4065     (while (and id (setq prev (car (gnus-id-to-thread id))))
4066       (setq last-id id
4067             id (gnus-parent-id (mail-header-references prev))))
4068     last-id))
4069
4070 (defun gnus-articles-in-thread (thread)
4071   "Return the list of articles in THREAD."
4072   (cons (mail-header-number (car thread))
4073         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4074
4075 (defun gnus-remove-thread (id &optional dont-remove)
4076   "Remove the thread that has ID in it."
4077   (let (headers thread last-id)
4078     ;; First go up in this thread until we find the root.
4079     (setq last-id (gnus-root-id id)
4080           headers (message-flatten-list (gnus-id-to-thread last-id)))
4081     ;; We have now found the real root of this thread.  It might have
4082     ;; been gathered into some loose thread, so we have to search
4083     ;; through the threads to find the thread we wanted.
4084     (let ((threads gnus-newsgroup-threads)
4085           sub)
4086       (while threads
4087         (setq sub (car threads))
4088         (if (stringp (car sub))
4089             ;; This is a gathered thread, so we look at the roots
4090             ;; below it to find whether this article is in this
4091             ;; gathered root.
4092             (progn
4093               (setq sub (cdr sub))
4094               (while sub
4095                 (when (member (caar sub) headers)
4096                   (setq thread (car threads)
4097                         threads nil
4098                         sub nil))
4099                 (setq sub (cdr sub))))
4100           ;; It's an ordinary thread, so we check it.
4101           (when (eq (car sub) (car headers))
4102             (setq thread sub
4103                   threads nil)))
4104         (setq threads (cdr threads)))
4105       ;; If this article is in no thread, then it's a root.
4106       (if thread
4107           (unless dont-remove
4108             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4109         (setq thread (gnus-id-to-thread last-id)))
4110       (when thread
4111         (prog1
4112             thread                      ; We return this thread.
4113           (unless dont-remove
4114             (if (stringp (car thread))
4115                 (progn
4116                   ;; If we use dummy roots, then we have to remove the
4117                   ;; dummy root as well.
4118                   (when (eq gnus-summary-make-false-root 'dummy)
4119                     ;; We go to the dummy root by going to
4120                     ;; the first sub-"thread", and then one line up.
4121                     (gnus-summary-goto-article
4122                      (mail-header-number (caadr thread)))
4123                     (forward-line -1)
4124                     (gnus-delete-line)
4125                     (gnus-data-compute-positions))
4126                   (setq thread (cdr thread))
4127                   (while thread
4128                     (gnus-remove-thread-1 (car thread))
4129                     (setq thread (cdr thread))))
4130               (gnus-remove-thread-1 thread))))))))
4131
4132 (defun gnus-remove-thread-1 (thread)
4133   "Remove the thread THREAD recursively."
4134   (let ((number (mail-header-number (pop thread)))
4135         d)
4136     (setq thread (reverse thread))
4137     (while thread
4138       (gnus-remove-thread-1 (pop thread)))
4139     (when (setq d (gnus-data-find number))
4140       (goto-char (gnus-data-pos d))
4141       (gnus-summary-show-thread)
4142       (gnus-data-remove
4143        number
4144        (- (gnus-point-at-bol)
4145           (prog1
4146               (1+ (gnus-point-at-eol))
4147             (gnus-delete-line)))))))
4148
4149 (defun gnus-sort-threads-1 (threads func)
4150   (sort (mapcar (lambda (thread)
4151                   (cons (car thread)
4152                         (and (cdr thread)
4153                              (gnus-sort-threads-1 (cdr thread) func))))
4154                 threads) func))
4155
4156 (defun gnus-sort-threads (threads)
4157   "Sort THREADS."
4158   (if (not gnus-thread-sort-functions)
4159       threads
4160     (gnus-message 8 "Sorting threads...")
4161     (prog1
4162         (gnus-sort-threads-1
4163          threads
4164          (gnus-make-sort-function gnus-thread-sort-functions))
4165       (gnus-message 8 "Sorting threads...done"))))
4166
4167 (defun gnus-sort-articles (articles)
4168   "Sort ARTICLES."
4169   (when gnus-article-sort-functions
4170     (gnus-message 7 "Sorting articles...")
4171     (prog1
4172         (setq gnus-newsgroup-headers
4173               (sort articles (gnus-make-sort-function
4174                               gnus-article-sort-functions)))
4175       (gnus-message 7 "Sorting articles...done"))))
4176
4177 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4178 (defmacro gnus-thread-header (thread)
4179   "Return header of first article in THREAD.
4180 Note that THREAD must never, ever be anything else than a variable -
4181 using some other form will lead to serious barfage."
4182   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4183   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4184   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4185         (vector thread) 2))
4186
4187 (defsubst gnus-article-sort-by-number (h1 h2)
4188   "Sort articles by article number."
4189   (< (mail-header-number h1)
4190      (mail-header-number h2)))
4191
4192 (defun gnus-thread-sort-by-number (h1 h2)
4193   "Sort threads by root article number."
4194   (gnus-article-sort-by-number
4195    (gnus-thread-header h1) (gnus-thread-header h2)))
4196
4197 (defsubst gnus-article-sort-by-lines (h1 h2)
4198   "Sort articles by article Lines header."
4199   (< (mail-header-lines h1)
4200      (mail-header-lines h2)))
4201
4202 (defun gnus-thread-sort-by-lines (h1 h2)
4203   "Sort threads by root article Lines header."
4204   (gnus-article-sort-by-lines
4205    (gnus-thread-header h1) (gnus-thread-header h2)))
4206
4207 (defsubst gnus-article-sort-by-chars (h1 h2)
4208   "Sort articles by octet length."
4209   (< (mail-header-chars h1)
4210      (mail-header-chars h2)))
4211
4212 (defun gnus-thread-sort-by-chars (h1 h2)
4213   "Sort threads by root article octet length."
4214   (gnus-article-sort-by-chars
4215    (gnus-thread-header h1) (gnus-thread-header h2)))
4216
4217 (defsubst gnus-article-sort-by-author (h1 h2)
4218   "Sort articles by root author."
4219   (string-lessp
4220    (let ((addr (car (mime-entity-read-field h1 'From))))
4221      (or (std11-full-name-string addr)
4222          (std11-address-string addr)
4223          ""))
4224    (let ((addr (car (mime-entity-read-field h2 'From))))
4225      (or (std11-full-name-string addr)
4226          (std11-address-string addr)
4227          ""))
4228    ))
4229
4230 (defun gnus-thread-sort-by-author (h1 h2)
4231   "Sort threads by root author."
4232   (gnus-article-sort-by-author
4233    (gnus-thread-header h1)  (gnus-thread-header h2)))
4234
4235 (defsubst gnus-article-sort-by-subject (h1 h2)
4236   "Sort articles by root subject."
4237   (string-lessp
4238    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4239    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4240
4241 (defun gnus-thread-sort-by-subject (h1 h2)
4242   "Sort threads by root subject."
4243   (gnus-article-sort-by-subject
4244    (gnus-thread-header h1) (gnus-thread-header h2)))
4245
4246 (defsubst gnus-article-sort-by-date (h1 h2)
4247   "Sort articles by root article date."
4248   (time-less-p
4249    (gnus-date-get-time (mail-header-date h1))
4250    (gnus-date-get-time (mail-header-date h2))))
4251
4252 (defun gnus-thread-sort-by-date (h1 h2)
4253   "Sort threads by root article date."
4254   (gnus-article-sort-by-date
4255    (gnus-thread-header h1) (gnus-thread-header h2)))
4256
4257 (defsubst gnus-article-sort-by-score (h1 h2)
4258   "Sort articles by root article score.
4259 Unscored articles will be counted as having a score of zero."
4260   (> (or (cdr (assq (mail-header-number h1)
4261                     gnus-newsgroup-scored))
4262          gnus-summary-default-score 0)
4263      (or (cdr (assq (mail-header-number h2)
4264                     gnus-newsgroup-scored))
4265          gnus-summary-default-score 0)))
4266
4267 (defun gnus-thread-sort-by-score (h1 h2)
4268   "Sort threads by root article score."
4269   (gnus-article-sort-by-score
4270    (gnus-thread-header h1) (gnus-thread-header h2)))
4271
4272 (defun gnus-thread-sort-by-total-score (h1 h2)
4273   "Sort threads by the sum of all scores in the thread.
4274 Unscored articles will be counted as having a score of zero."
4275   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4276
4277 (defun gnus-thread-total-score (thread)
4278   ;; This function find the total score of THREAD.
4279   (cond
4280    ((null thread)
4281     0)
4282    ((consp thread)
4283     (if (stringp (car thread))
4284         (apply gnus-thread-score-function 0
4285                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4286       (gnus-thread-total-score-1 thread)))
4287    (t
4288     (gnus-thread-total-score-1 (list thread)))))
4289
4290 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4291   "Sort threads such that the thread with the most recently arrived article comes first."
4292   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4293
4294 (defun gnus-thread-highest-number (thread)
4295   "Return the highest article number in THREAD."
4296   (apply 'max (mapcar (lambda (header)
4297                         (mail-header-number header))
4298                       (message-flatten-list thread))))
4299
4300 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4301   "Sort threads such that the thread with the most recently dated article comes first."
4302   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4303
4304 (defun gnus-thread-latest-date (thread)
4305   "Return the highest article date in THREAD."
4306   (let ((previous-time 0))
4307     (apply 'max (mapcar
4308                  (lambda (header)
4309                    (setq previous-time
4310                          (time-to-seconds
4311                           (mail-header-parse-date
4312                            (condition-case ()
4313                                (mail-header-date header)
4314                              (error previous-time))))))
4315                  (sort
4316                   (message-flatten-list thread)
4317                   (lambda (h1 h2)
4318                     (< (mail-header-number h1)
4319                        (mail-header-number h2))))))))
4320
4321 (defun gnus-thread-total-score-1 (root)
4322   ;; This function find the total score of the thread below ROOT.
4323   (setq root (car root))
4324   (apply gnus-thread-score-function
4325          (or (append
4326               (mapcar 'gnus-thread-total-score
4327                       (cdr (gnus-id-to-thread (mail-header-id root))))
4328               (when (> (mail-header-number root) 0)
4329                 (list (or (cdr (assq (mail-header-number root)
4330                                      gnus-newsgroup-scored))
4331                           gnus-summary-default-score 0))))
4332              (list gnus-summary-default-score)
4333              '(0))))
4334
4335 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4336 (defvar gnus-tmp-prev-subject nil)
4337 (defvar gnus-tmp-false-parent nil)
4338 (defvar gnus-tmp-root-expunged nil)
4339 (defvar gnus-tmp-dummy-line nil)
4340
4341 (eval-when-compile (defvar gnus-tmp-header))
4342 (defun gnus-extra-header (type &optional header)
4343   "Return the extra header of TYPE."
4344   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4345       ""))
4346
4347 (defvar gnus-tmp-thread-tree-header-string "")
4348
4349 (defvar gnus-sum-thread-tree-root "> "
4350   "With %B spec, used for the root of a thread.
4351 If nil, use subject instead.")
4352 (defvar gnus-sum-thread-tree-single-indent ""
4353   "With %B spec, used for a thread with just one message.
4354 If nil, use subject instead.")
4355 (defvar gnus-sum-thread-tree-vertical "| "
4356   "With %B spec, used for drawing a vertical line.")
4357 (defvar gnus-sum-thread-tree-indent "  "
4358   "With %B spec, used for indenting.")
4359 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4360   "With %B spec, used for a leaf with brothers.")
4361 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4362   "With %B spec, used for a leaf without brothers.")
4363
4364 (defun gnus-summary-prepare-threads (threads)
4365   "Prepare summary buffer from THREADS and indentation LEVEL.
4366 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4367 or a straight list of headers."
4368   (gnus-message 7 "Generating summary...")
4369
4370   (setq gnus-newsgroup-threads threads)
4371   (beginning-of-line)
4372
4373   (let ((gnus-tmp-level 0)
4374         (default-score (or gnus-summary-default-score 0))
4375         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4376         thread number subject stack state gnus-tmp-gathered beg-match
4377         new-roots gnus-tmp-new-adopts thread-end
4378         gnus-tmp-header gnus-tmp-unread
4379         gnus-tmp-replied gnus-tmp-subject-or-nil
4380         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4381         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4382         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4383         tree-stack)
4384
4385     (setq gnus-tmp-prev-subject nil)
4386
4387     (if (vectorp (car threads))
4388         ;; If this is a straight (sic) list of headers, then a
4389         ;; threaded summary display isn't required, so we just create
4390         ;; an unthreaded one.
4391         (gnus-summary-prepare-unthreaded threads)
4392
4393       ;; Do the threaded display.
4394
4395       (while (or threads stack gnus-tmp-new-adopts new-roots)
4396
4397         (if (and (= gnus-tmp-level 0)
4398                  (or (not stack)
4399                      (= (caar stack) 0))
4400                  (not gnus-tmp-false-parent)
4401                  (or gnus-tmp-new-adopts new-roots))
4402             (if gnus-tmp-new-adopts
4403                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4404                       thread (list (car gnus-tmp-new-adopts))
4405                       gnus-tmp-header (caar thread)
4406                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4407               (when new-roots
4408                 (setq thread (list (car new-roots))
4409                       gnus-tmp-header (caar thread)
4410                       new-roots (cdr new-roots))))
4411
4412           (if threads
4413               ;; If there are some threads, we do them before the
4414               ;; threads on the stack.
4415               (setq thread threads
4416                     gnus-tmp-header (caar thread))
4417             ;; There were no current threads, so we pop something off
4418             ;; the stack.
4419             (setq state (car stack)
4420                   gnus-tmp-level (car state)
4421                   tree-stack (cadr state)
4422                   thread (caddr state)
4423                   stack (cdr stack)
4424                   gnus-tmp-header (caar thread))))
4425
4426         (setq gnus-tmp-false-parent nil)
4427         (setq gnus-tmp-root-expunged nil)
4428         (setq thread-end nil)
4429
4430         (if (stringp gnus-tmp-header)
4431             ;; The header is a dummy root.
4432             (cond
4433              ((eq gnus-summary-make-false-root 'adopt)
4434               ;; We let the first article adopt the rest.
4435               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4436                                                (cddar thread)))
4437               (setq gnus-tmp-gathered
4438                     (nconc (mapcar
4439                             (lambda (h) (mail-header-number (car h)))
4440                             (cddar thread))
4441                            gnus-tmp-gathered))
4442               (setq thread (cons (list (caar thread)
4443                                        (cadar thread))
4444                                  (cdr thread)))
4445               (setq gnus-tmp-level -1
4446                     gnus-tmp-false-parent t))
4447              ((eq gnus-summary-make-false-root 'empty)
4448               ;; We print adopted articles with empty subject fields.
4449               (setq gnus-tmp-gathered
4450                     (nconc (mapcar
4451                             (lambda (h) (mail-header-number (car h)))
4452                             (cddar thread))
4453                            gnus-tmp-gathered))
4454               (setq gnus-tmp-level -1))
4455              ((eq gnus-summary-make-false-root 'dummy)
4456               ;; We remember that we probably want to output a dummy
4457               ;; root.
4458               (setq gnus-tmp-dummy-line gnus-tmp-header)
4459               (setq gnus-tmp-prev-subject gnus-tmp-header))
4460              (t
4461               ;; We do not make a root for the gathered
4462               ;; sub-threads at all.
4463               (setq gnus-tmp-level -1)))
4464
4465           (setq number (mail-header-number gnus-tmp-header)
4466                 subject (mail-header-subject gnus-tmp-header))
4467
4468           (cond
4469            ;; If the thread has changed subject, we might want to make
4470            ;; this subthread into a root.
4471            ((and (null gnus-thread-ignore-subject)
4472                  (not (zerop gnus-tmp-level))
4473                  gnus-tmp-prev-subject
4474                  (not (inline
4475                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4476             (setq new-roots (nconc new-roots (list (car thread)))
4477                   thread-end t
4478                   gnus-tmp-header nil))
4479            ;; If the article lies outside the current limit,
4480            ;; then we do not display it.
4481            ((not (memq number gnus-newsgroup-limit))
4482             (setq gnus-tmp-gathered
4483                   (nconc (mapcar
4484                           (lambda (h) (mail-header-number (car h)))
4485                           (cdar thread))
4486                          gnus-tmp-gathered))
4487             (setq gnus-tmp-new-adopts (if (cdar thread)
4488                                           (append gnus-tmp-new-adopts
4489                                                   (cdar thread))
4490                                         gnus-tmp-new-adopts)
4491                   thread-end t
4492                   gnus-tmp-header nil)
4493             (when (zerop gnus-tmp-level)
4494               (setq gnus-tmp-root-expunged t)))
4495            ;; Perhaps this article is to be marked as read?
4496            ((and gnus-summary-mark-below
4497                  (< (or (cdr (assq number gnus-newsgroup-scored))
4498                         default-score)
4499                     gnus-summary-mark-below)
4500                  ;; Don't touch sparse articles.
4501                  (not (gnus-summary-article-sparse-p number))
4502                  (not (gnus-summary-article-ancient-p number)))
4503             (setq gnus-newsgroup-unreads
4504                   (delq number gnus-newsgroup-unreads))
4505             (if gnus-newsgroup-auto-expire
4506                 (setq gnus-newsgroup-expirable
4507                       (gnus-add-to-sorted-list
4508                        gnus-newsgroup-expirable number))
4509               (push (cons number gnus-low-score-mark)
4510                     gnus-newsgroup-reads))))
4511
4512           (when gnus-tmp-header
4513             ;; We may have an old dummy line to output before this
4514             ;; article.
4515             (when (and gnus-tmp-dummy-line
4516                        (gnus-subject-equal
4517                         gnus-tmp-dummy-line
4518                         (mail-header-subject gnus-tmp-header)))
4519               (gnus-summary-insert-dummy-line
4520                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4521               (setq gnus-tmp-dummy-line nil))
4522
4523             ;; Compute the mark.
4524             (setq gnus-tmp-unread (gnus-article-mark number))
4525
4526             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4527                                   gnus-tmp-header gnus-tmp-level)
4528                   gnus-newsgroup-data)
4529
4530             ;; Actually insert the line.
4531             (setq
4532              gnus-tmp-subject-or-nil
4533              (cond
4534               ((and gnus-thread-ignore-subject
4535                     gnus-tmp-prev-subject
4536                     (not (inline (gnus-subject-equal
4537                                   gnus-tmp-prev-subject subject))))
4538                subject)
4539               ((zerop gnus-tmp-level)
4540                (if (and (eq gnus-summary-make-false-root 'empty)
4541                         (memq number gnus-tmp-gathered)
4542                         gnus-tmp-prev-subject
4543                         (inline (gnus-subject-equal
4544                                  gnus-tmp-prev-subject subject)))
4545                    gnus-summary-same-subject
4546                  subject))
4547               (t gnus-summary-same-subject)))
4548             (if (and (eq gnus-summary-make-false-root 'adopt)
4549                      (= gnus-tmp-level 1)
4550                      (memq number gnus-tmp-gathered))
4551                 (setq gnus-tmp-opening-bracket ?\<
4552                       gnus-tmp-closing-bracket ?\>)
4553               (setq gnus-tmp-opening-bracket ?\[
4554                     gnus-tmp-closing-bracket ?\]))
4555             (setq
4556              gnus-tmp-indentation
4557              (aref gnus-thread-indent-array gnus-tmp-level)
4558              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4559              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4560                                 gnus-summary-default-score 0)
4561              gnus-tmp-score-char
4562              (if (or (null gnus-summary-default-score)
4563                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4564                          gnus-summary-zcore-fuzz))
4565                  ?\ ;;;Whitespace
4566                (if (< gnus-tmp-score gnus-summary-default-score)
4567                    gnus-score-below-mark gnus-score-over-mark))
4568              gnus-tmp-replied
4569              (cond ((memq number gnus-newsgroup-processable)
4570                     gnus-process-mark)
4571                    ((memq number gnus-newsgroup-cached)
4572                     gnus-cached-mark)
4573                    ((memq number gnus-newsgroup-replied)
4574                     gnus-replied-mark)
4575                    ((memq number gnus-newsgroup-forwarded)
4576                     gnus-forwarded-mark)
4577                    ((memq number gnus-newsgroup-saved)
4578                     gnus-saved-mark)
4579                    ((memq number gnus-newsgroup-recent)
4580                     gnus-recent-mark)
4581                    ((memq number gnus-newsgroup-unseen)
4582                     gnus-unseen-mark)
4583                    (t gnus-no-mark))
4584              gnus-tmp-from (mail-header-from gnus-tmp-header)
4585              gnus-tmp-name
4586              (cond
4587               ((string-match "<[^>]+> *$" gnus-tmp-from)
4588                (setq beg-match (match-beginning 0))
4589                (or (and (string-match "^\".+\"" gnus-tmp-from)
4590                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4591                    (substring gnus-tmp-from 0 beg-match)))
4592               ((string-match "(.+)" gnus-tmp-from)
4593                (substring gnus-tmp-from
4594                           (1+ (match-beginning 0)) (1- (match-end 0))))
4595               (t gnus-tmp-from))
4596              gnus-tmp-thread-tree-header-string
4597              (cond
4598               ((not gnus-show-threads) "")
4599               ((zerop gnus-tmp-level)
4600                (if (cdar thread)
4601                    (or gnus-sum-thread-tree-root subject)
4602                  (or gnus-sum-thread-tree-single-indent subject)))
4603               (t
4604                (concat (apply 'concat
4605                               (mapcar (lambda (item)
4606                                         (if (= item 1)
4607                                             gnus-sum-thread-tree-vertical
4608                                           gnus-sum-thread-tree-indent))
4609                                       (cdr (reverse tree-stack))))
4610                        (if (nth 1 thread)
4611                            gnus-sum-thread-tree-leaf-with-other
4612                          gnus-sum-thread-tree-single-leaf)))))
4613             (when (string= gnus-tmp-name "")
4614               (setq gnus-tmp-name gnus-tmp-from))
4615             (unless (numberp gnus-tmp-lines)
4616               (setq gnus-tmp-lines -1))
4617             (if (= gnus-tmp-lines -1)
4618                 (setq gnus-tmp-lines "?")
4619               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4620             (gnus-put-text-property
4621              (point)
4622              (progn (eval gnus-summary-line-format-spec) (point))
4623              'gnus-number number)
4624             (when gnus-visual-p
4625               (forward-line -1)
4626               (gnus-run-hooks 'gnus-summary-update-hook)
4627               (forward-line 1))
4628
4629             (setq gnus-tmp-prev-subject subject)))
4630
4631         (when (nth 1 thread)
4632           (push (list (max 0 gnus-tmp-level)
4633                       (copy-list tree-stack)
4634                       (nthcdr 1 thread))
4635                 stack))
4636         (push (if (nth 1 thread) 1 0) tree-stack)
4637         (incf gnus-tmp-level)
4638         (setq threads (if thread-end nil (cdar thread)))
4639         (unless threads
4640           (setq gnus-tmp-level 0)))))
4641   (gnus-message 7 "Generating summary...done"))
4642
4643 (defun gnus-summary-prepare-unthreaded (headers)
4644   "Generate an unthreaded summary buffer based on HEADERS."
4645   (let (header number mark)
4646
4647     (beginning-of-line)
4648
4649     (while headers
4650       ;; We may have to root out some bad articles...
4651       (when (memq (setq number (mail-header-number
4652                                 (setq header (pop headers))))
4653                   gnus-newsgroup-limit)
4654         ;; Mark article as read when it has a low score.
4655         (when (and gnus-summary-mark-below
4656                    (< (or (cdr (assq number gnus-newsgroup-scored))
4657                           gnus-summary-default-score 0)
4658                       gnus-summary-mark-below)
4659                    (not (gnus-summary-article-ancient-p number)))
4660           (setq gnus-newsgroup-unreads
4661                 (delq number gnus-newsgroup-unreads))
4662           (if gnus-newsgroup-auto-expire
4663               (push number gnus-newsgroup-expirable)
4664             (push (cons number gnus-low-score-mark)
4665                   gnus-newsgroup-reads)))
4666
4667         (setq mark (gnus-article-mark number))
4668         (push (gnus-data-make number mark (1+ (point)) header 0)
4669               gnus-newsgroup-data)
4670         (gnus-summary-insert-line
4671          header 0 number
4672          mark (memq number gnus-newsgroup-replied)
4673          (memq number gnus-newsgroup-expirable)
4674          (mail-header-subject header) nil
4675          (cdr (assq number gnus-newsgroup-scored))
4676          (memq number gnus-newsgroup-processable))))))
4677
4678 (defun gnus-summary-remove-list-identifiers ()
4679   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4680   (let ((regexp (if (consp gnus-list-identifiers)
4681                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4682                   gnus-list-identifiers))
4683         changed subject)
4684     (when regexp
4685       (dolist (header gnus-newsgroup-headers)
4686         (setq subject (mail-header-subject header)
4687               changed nil)
4688         (while (string-match
4689                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4690                 subject)
4691           (setq subject
4692                 (concat (substring subject 0 (match-beginning 2))
4693                         (substring subject (match-end 0)))
4694                 changed t))
4695         (when (and changed
4696                    (string-match
4697                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4698           (setq subject
4699                 (concat (substring subject 0 (match-beginning 1))
4700                         (substring subject (match-end 1)))))
4701         (when changed
4702           (mail-header-set-subject header subject))))))
4703
4704 (defun gnus-fetch-headers (articles)
4705   "Fetch headers of ARTICLES."
4706   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4707     (gnus-message 5 "Fetching headers for %s..." name)
4708     (prog1
4709         (if (eq 'nov
4710                 (setq gnus-headers-retrieved-by
4711                       (gnus-retrieve-headers
4712                        articles gnus-newsgroup-name
4713                        ;; We might want to fetch old headers, but
4714                        ;; not if there is only 1 article.
4715                        (and (or (and
4716                                  (not (eq gnus-fetch-old-headers 'some))
4717                                  (not (numberp gnus-fetch-old-headers)))
4718                                 (> (length articles) 1))
4719                             gnus-fetch-old-headers))))
4720             (gnus-get-newsgroup-headers-xover
4721              articles nil nil gnus-newsgroup-name t)
4722           (gnus-get-newsgroup-headers))
4723       (gnus-message 5 "Fetching headers for %s...done" name))))
4724
4725 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4726   "Select newsgroup GROUP.
4727 If READ-ALL is non-nil, all articles in the group are selected.
4728 If SELECT-ARTICLES, only select those articles from GROUP."
4729   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4730          ;;!!! Dirty hack; should be removed.
4731          (gnus-summary-ignore-duplicates
4732           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4733               t
4734             gnus-summary-ignore-duplicates))
4735          (info (nth 2 entry))
4736          articles fetched-articles cached)
4737
4738     (unless (gnus-check-server
4739              (set (make-local-variable 'gnus-current-select-method)
4740                   (gnus-find-method-for-group group)))
4741       (error "Couldn't open server"))
4742
4743     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4744         (gnus-activate-group group)     ; Or we can activate it...
4745         (progn                          ; Or we bug out.
4746           (when (equal major-mode 'gnus-summary-mode)
4747             (kill-buffer (current-buffer)))
4748           (error "Couldn't activate group %s: %s"
4749                  group (gnus-status-message group))))
4750
4751     (unless (gnus-request-group group t)
4752       (when (equal major-mode 'gnus-summary-mode)
4753         (kill-buffer (current-buffer)))
4754       (error "Couldn't request group %s: %s"
4755              group (gnus-status-message group)))
4756
4757     (setq gnus-newsgroup-name group
4758           gnus-newsgroup-unselected nil
4759           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4760
4761     (let ((display (gnus-group-find-parameter group 'display)))
4762       (setq gnus-newsgroup-display
4763             (cond
4764              ((not (zerop (or (car-safe read-all) 0)))
4765               ;; The user entered the group with C-u SPC/RET, let's show
4766               ;; all articles.
4767               'gnus-not-ignore)
4768              ((eq display 'all)
4769               'gnus-not-ignore)
4770              ((arrayp display)
4771               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4772              ((numberp display)
4773               ;; The following is probably the "correct" solution, but
4774               ;; it makes Gnus fetch all headers and then limit the
4775               ;; articles (which is slow), so instead we hack the
4776               ;; select-articles parameter instead. -- Simon Josefsson
4777               ;; <jas@kth.se>
4778               ;;
4779               ;; (gnus-byte-compile
4780               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4781               ;;                         display)))))
4782               (setq select-articles
4783                     (gnus-uncompress-range
4784                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4785                              (if (> tmp 0)
4786                                  tmp
4787                                1))
4788                            (cdr (gnus-active group)))))
4789               nil)
4790              (t
4791               nil))))
4792
4793     (gnus-summary-setup-default-charset)
4794
4795     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4796     (when (gnus-virtual-group-p group)
4797       (setq cached gnus-newsgroup-cached))
4798
4799     (setq gnus-newsgroup-unreads
4800           (gnus-sorted-ndifference
4801            (gnus-sorted-ndifference gnus-newsgroup-unreads
4802                                     gnus-newsgroup-marked)
4803            gnus-newsgroup-dormant))
4804
4805     (setq gnus-newsgroup-processable nil)
4806
4807     (gnus-update-read-articles group gnus-newsgroup-unreads)
4808
4809     ;; Adjust and set lists of article marks.
4810     (when info
4811       (gnus-adjust-marked-articles info))
4812
4813     (if (setq articles select-articles)
4814         (setq gnus-newsgroup-unselected
4815               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4816       (setq articles (gnus-articles-to-read group read-all)))
4817
4818     (cond
4819      ((null articles)
4820       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4821       'quit)
4822      ((eq articles 0) nil)
4823      (t
4824       ;; Init the dependencies hash table.
4825       (setq gnus-newsgroup-dependencies
4826             (gnus-make-hashtable (length articles)))
4827       (gnus-set-global-variables)
4828       ;; Retrieve the headers and read them in.
4829       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4830
4831       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4832       (when cached
4833         (setq gnus-newsgroup-cached cached))
4834
4835       ;; Suppress duplicates?
4836       (when gnus-suppress-duplicates
4837         (gnus-dup-suppress-articles))
4838
4839       ;; Set the initial limit.
4840       (setq gnus-newsgroup-limit (copy-sequence articles))
4841       ;; Remove canceled articles from the list of unread articles.
4842       (setq fetched-articles
4843             (mapcar (lambda (headers) (mail-header-number headers))
4844                     gnus-newsgroup-headers))
4845       (setq gnus-newsgroup-articles fetched-articles)
4846       (setq gnus-newsgroup-unreads
4847             (gnus-sorted-nintersection
4848              gnus-newsgroup-unreads fetched-articles))
4849       (gnus-compute-unseen-list)
4850
4851       ;; Removed marked articles that do not exist.
4852       (gnus-update-missing-marks
4853        (gnus-sorted-difference articles fetched-articles))
4854       ;; We might want to build some more threads first.
4855       (when (and gnus-fetch-old-headers
4856                  (eq gnus-headers-retrieved-by 'nov))
4857         (if (eq gnus-fetch-old-headers 'invisible)
4858             (gnus-build-all-threads)
4859           (gnus-build-old-threads)))
4860       ;; Let the Gnus agent mark articles as read.
4861       (when gnus-agent
4862         (gnus-agent-get-undownloaded-list))
4863       ;; Remove list identifiers from subject
4864       (when gnus-list-identifiers
4865         (gnus-summary-remove-list-identifiers))
4866       ;; Check whether auto-expire is to be done in this group.
4867       (setq gnus-newsgroup-auto-expire
4868             (gnus-group-auto-expirable-p group))
4869       ;; Set up the article buffer now, if necessary.
4870       (unless gnus-single-article-buffer
4871         (gnus-article-setup-buffer))
4872       ;; First and last article in this newsgroup.
4873       (when gnus-newsgroup-headers
4874         (setq gnus-newsgroup-begin
4875               (mail-header-number (car gnus-newsgroup-headers))
4876               gnus-newsgroup-end
4877               (mail-header-number
4878                (gnus-last-element gnus-newsgroup-headers))))
4879       ;; GROUP is successfully selected.
4880       (or gnus-newsgroup-headers t)))))
4881
4882 (defun gnus-compute-unseen-list ()
4883   ;; The `seen' marks are treated specially.
4884   (if (not gnus-newsgroup-seen)
4885       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4886     (setq gnus-newsgroup-unseen
4887           (gnus-inverse-list-range-intersection
4888            gnus-newsgroup-articles gnus-newsgroup-seen))))
4889
4890 (defun gnus-summary-display-make-predicate (display)
4891   (require 'gnus-agent)
4892   (when (= (length display) 1)
4893     (setq display (car display)))
4894   (unless gnus-summary-display-cache
4895     (dolist (elem (append '((unread . unread)
4896                             (read . read)
4897                             (unseen . unseen))
4898                           gnus-article-mark-lists))
4899       (push (cons (cdr elem)
4900                   (gnus-byte-compile
4901                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4902             gnus-summary-display-cache)))
4903   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
4904         (gnus-category-predicate-cache gnus-summary-display-cache))
4905     (gnus-get-predicate display)))
4906
4907 ;; Uses the dynamically bound `number' variable.
4908 (defvar number)
4909 (defun gnus-article-marked-p (type &optional article)
4910   (let ((article (or article number)))
4911     (cond
4912      ((eq type 'tick)
4913       (memq article gnus-newsgroup-marked))
4914      ((eq type 'unsend)
4915       (memq article gnus-newsgroup-unsendable))
4916      ((eq type 'undownload)
4917       (memq article gnus-newsgroup-undownloaded))
4918      ((eq type 'download)
4919       (memq article gnus-newsgroup-downloadable))
4920      ((eq type 'unread)
4921       (memq article gnus-newsgroup-unreads))
4922      ((eq type 'read)
4923       (memq article gnus-newsgroup-reads))
4924      ((eq type 'dormant)
4925       (memq article gnus-newsgroup-dormant) )
4926      ((eq type 'expire)
4927       (memq article gnus-newsgroup-expirable))
4928      ((eq type 'reply)
4929       (memq article gnus-newsgroup-replied))
4930      ((eq type 'killed)
4931       (memq article gnus-newsgroup-killed))
4932      ((eq type 'bookmark)
4933       (assq article gnus-newsgroup-bookmarks))
4934      ((eq type 'score)
4935       (assq article gnus-newsgroup-scored))
4936      ((eq type 'save)
4937       (memq article gnus-newsgroup-saved))
4938      ((eq type 'cache)
4939       (memq article gnus-newsgroup-cached))
4940      ((eq type 'forward)
4941       (memq article gnus-newsgroup-forwarded))
4942      ((eq type 'seen)
4943       (not (memq article gnus-newsgroup-unseen)))
4944      ((eq type 'recent)
4945       (memq article gnus-newsgroup-recent))
4946      (t t))))
4947
4948 (defun gnus-articles-to-read (group &optional read-all)
4949   "Find out what articles the user wants to read."
4950   (let* ((articles
4951           ;; Select all articles if `read-all' is non-nil, or if there
4952           ;; are no unread articles.
4953           (if (or read-all
4954                   (and (zerop (length gnus-newsgroup-marked))
4955                        (zerop (length gnus-newsgroup-unreads)))
4956                   ;; Fetch all if the predicate is non-nil.
4957                   gnus-newsgroup-display)
4958               ;; We want to select the headers for all the articles in
4959               ;; the group, so we select either all the active
4960               ;; articles in the group, or (if that's nil), the
4961               ;; articles in the cache.
4962               (or
4963                (gnus-uncompress-range (gnus-active group))
4964                (gnus-cache-articles-in-group group))
4965             ;; Select only the "normal" subset of articles.
4966             (gnus-sorted-nunion
4967              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
4968              gnus-newsgroup-unreads)))
4969          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4970          (scored (length scored-list))
4971          (number (length articles))
4972          (marked (+ (length gnus-newsgroup-marked)
4973                     (length gnus-newsgroup-dormant)))
4974          (select
4975           (cond
4976            ((numberp read-all)
4977             read-all)
4978            ((numberp gnus-newsgroup-display)
4979             gnus-newsgroup-display)
4980            (t
4981             (condition-case ()
4982                 (cond
4983                  ((and (or (<= scored marked) (= scored number))
4984                        (natnump gnus-large-newsgroup)
4985                        (> number gnus-large-newsgroup))
4986                   (let* ((cursor-in-echo-area nil)
4987                          (input
4988                           (read-from-minibuffer
4989                            (format
4990                             "How many articles from %s (max %d): "
4991                             (gnus-limit-string
4992                              (gnus-group-decoded-name gnus-newsgroup-name)
4993                              35)
4994                             number)
4995                            (cons (number-to-string gnus-large-newsgroup)
4996                                  0))))
4997                     (if (string-match "^[ \t]*$" input)
4998                         number
4999                       input)))
5000                  ((and (> scored marked) (< scored number)
5001                        (> (- scored number) 20))
5002                   (let ((input
5003                          (read-string
5004                           (format "%s %s (%d scored, %d total): "
5005                                   "How many articles from"
5006                                   (gnus-group-decoded-name group)
5007                                   scored number))))
5008                     (if (string-match "^[ \t]*$" input)
5009                         number input)))
5010                  (t number))
5011               (quit
5012                (message "Quit getting the articles to read")
5013                nil))))))
5014     (setq select (if (stringp select) (string-to-number select) select))
5015     (if (or (null select) (zerop select))
5016         select
5017       (if (and (not (zerop scored)) (<= (abs select) scored))
5018           (progn
5019             (setq articles (sort scored-list '<))
5020             (setq number (length articles)))
5021         (setq articles (copy-sequence articles)))
5022
5023       (when (< (abs select) number)
5024         (if (< select 0)
5025             ;; Select the N oldest articles.
5026             (setcdr (nthcdr (1- (abs select)) articles) nil)
5027           ;; Select the N most recent articles.
5028           (setq articles (nthcdr (- number select) articles))))
5029       (setq gnus-newsgroup-unselected
5030             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5031       (when gnus-alter-articles-to-read-function
5032         (setq gnus-newsgroup-unreads
5033               (sort
5034                (funcall gnus-alter-articles-to-read-function
5035                         gnus-newsgroup-name gnus-newsgroup-unreads)
5036                '<)))
5037       articles)))
5038
5039 (defun gnus-killed-articles (killed articles)
5040   (let (out)
5041     (while articles
5042       (when (inline (gnus-member-of-range (car articles) killed))
5043         (push (car articles) out))
5044       (setq articles (cdr articles)))
5045     out))
5046
5047 (defun gnus-uncompress-marks (marks)
5048   "Uncompress the mark ranges in MARKS."
5049   (let ((uncompressed '(score bookmark))
5050         out)
5051     (while marks
5052       (if (memq (caar marks) uncompressed)
5053           (push (car marks) out)
5054         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5055       (setq marks (cdr marks)))
5056     out))
5057
5058 (defun gnus-article-mark-to-type (mark)
5059   "Return the type of MARK."
5060   (or (cadr (assq mark gnus-article-special-mark-lists))
5061       'list))
5062
5063 (defun gnus-article-unpropagatable-p (mark)
5064   "Return whether MARK should be propagated to backend."
5065   (memq mark gnus-article-unpropagated-mark-lists))
5066
5067 (defun gnus-adjust-marked-articles (info)
5068   "Set all article lists and remove all marks that are no longer valid."
5069   (let* ((marked-lists (gnus-info-marks info))
5070          (active (gnus-active (gnus-info-group info)))
5071          (min (car active))
5072          (max (cdr active))
5073          (types gnus-article-mark-lists)
5074          marks var articles article mark mark-type)
5075
5076     (dolist (marks marked-lists)
5077       (setq mark (car marks)
5078             mark-type (gnus-article-mark-to-type mark)
5079             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5080
5081       ;; We set the variable according to the type of the marks list,
5082       ;; and then adjust the marks to a subset of the active articles.
5083       (cond
5084        ;; Adjust "simple" lists.
5085        ((eq mark-type 'list)
5086         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5087         (when (memq mark '(tick dormant expire reply save))
5088           (while articles
5089             (when (or (< (setq article (pop articles)) min) (> article max))
5090               (set var (delq article (symbol-value var)))))))
5091        ;; Adjust assocs.
5092        ((eq mark-type 'tuple)
5093         (set var (setq articles (cdr marks)))
5094         (when (not (listp (cdr (symbol-value var))))
5095           (set var (list (symbol-value var))))
5096         (when (not (listp (cdr articles)))
5097           (setq articles (list articles)))
5098         (while articles
5099           (when (or (not (consp (setq article (pop articles))))
5100                     (< (car article) min)
5101                     (> (car article) max))
5102             (set var (delq article (symbol-value var))))))
5103        ;; Adjust ranges (sloppily).
5104        ((eq mark-type 'range)
5105         (cond
5106          ((eq mark 'seen)
5107           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5108           ;; It should be (seen (NUM1 . NUM2)).
5109           (when (numberp (cddr marks))
5110             (setcdr marks (list (cdr marks))))
5111           (setq articles (cdr marks))
5112           (while (and articles
5113                       (or (and (consp (car articles))
5114                                (> min (cdar articles)))
5115                           (and (numberp (car articles))
5116                                (> min (car articles)))))
5117             (pop articles))
5118           (set var articles))))))))
5119
5120 (defun gnus-update-missing-marks (missing)
5121   "Go through the list of MISSING articles and remove them from the mark lists."
5122   (when missing
5123     (let (var m)
5124       ;; Go through all types.
5125       (dolist (elem gnus-article-mark-lists)
5126         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5127           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5128           (when (symbol-value var)
5129             ;; This list has articles.  So we delete all missing
5130             ;; articles from it.
5131             (setq m missing)
5132             (while m
5133               (set var (delq (pop m) (symbol-value var))))))))))
5134
5135 (defun gnus-update-marks ()
5136   "Enter the various lists of marked articles into the newsgroup info list."
5137   (let ((types gnus-article-mark-lists)
5138         (info (gnus-get-info gnus-newsgroup-name))
5139         type list newmarked symbol delta-marks)
5140     (when info
5141       ;; Add all marks lists to the list of marks lists.
5142       (while (setq type (pop types))
5143         (setq list (symbol-value
5144                     (setq symbol
5145                           (intern (format "gnus-newsgroup-%s" (car type))))))
5146
5147         (when list
5148           ;; Get rid of the entries of the articles that have the
5149           ;; default score.
5150           (when (and (eq (cdr type) 'score)
5151                      gnus-save-score
5152                      list)
5153             (let* ((arts list)
5154                    (prev (cons nil list))
5155                    (all prev))
5156               (while arts
5157                 (if (or (not (consp (car arts)))
5158                         (= (cdar arts) gnus-summary-default-score))
5159                     (setcdr prev (cdr arts))
5160                   (setq prev arts))
5161                 (setq arts (cdr arts)))
5162               (setq list (cdr all)))))
5163
5164         (when (eq (cdr type) 'seen)
5165           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5166
5167         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5168           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5169
5170         (when (and (gnus-check-backend-function
5171                     'request-set-mark gnus-newsgroup-name)
5172                    (not (gnus-article-unpropagatable-p (cdr type))))
5173           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5174                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5175                  (add (gnus-remove-from-range
5176                        (gnus-copy-sequence list) old)))
5177             (when add
5178               (push (list add 'add (list (cdr type))) delta-marks))
5179             (when del
5180               (push (list del 'del (list (cdr type))) delta-marks))))
5181
5182         (when list
5183           (push (cons (cdr type) list) newmarked)))
5184
5185       (when delta-marks
5186         (unless (gnus-check-group gnus-newsgroup-name)
5187           (error "Can't open server for %s" gnus-newsgroup-name))
5188         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5189
5190       ;; Enter these new marks into the info of the group.
5191       (if (nthcdr 3 info)
5192           (setcar (nthcdr 3 info) newmarked)
5193         ;; Add the marks lists to the end of the info.
5194         (when newmarked
5195           (setcdr (nthcdr 2 info) (list newmarked))))
5196
5197       ;; Cut off the end of the info if there's nothing else there.
5198       (let ((i 5))
5199         (while (and (> i 2)
5200                     (not (nth i info)))
5201           (when (nthcdr (decf i) info)
5202             (setcdr (nthcdr i info) nil)))))))
5203
5204 (defun gnus-set-mode-line (where)
5205   "Set the mode line of the article or summary buffers.
5206 If WHERE is `summary', the summary mode line format will be used."
5207   ;; Is this mode line one we keep updated?
5208   (when (and (memq where gnus-updated-mode-lines)
5209              (symbol-value
5210               (intern (format "gnus-%s-mode-line-format-spec" where))))
5211     (let (mode-string)
5212       (save-excursion
5213         ;; We evaluate this in the summary buffer since these
5214         ;; variables are buffer-local to that buffer.
5215         (set-buffer gnus-summary-buffer)
5216         ;; We bind all these variables that are used in the `eval' form
5217         ;; below.
5218         (let* ((mformat (symbol-value
5219                          (intern
5220                           (format "gnus-%s-mode-line-format-spec" where))))
5221                (gnus-tmp-group-name (gnus-group-decoded-name
5222                                      gnus-newsgroup-name))
5223                (gnus-tmp-article-number (or gnus-current-article 0))
5224                (gnus-tmp-unread gnus-newsgroup-unreads)
5225                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5226                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5227                (gnus-tmp-unread-and-unselected
5228                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5229                             (zerop gnus-tmp-unselected))
5230                        "")
5231                       ((zerop gnus-tmp-unselected)
5232                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5233                       (t (format "{%d(+%d) more}"
5234                                  gnus-tmp-unread-and-unticked
5235                                  gnus-tmp-unselected))))
5236                (gnus-tmp-subject
5237                 (if (and gnus-current-headers
5238                          (vectorp gnus-current-headers))
5239                     (gnus-mode-string-quote
5240                      (mail-header-subject gnus-current-headers))
5241                   ""))
5242                bufname-length max-len
5243                gnus-tmp-header);; passed as argument to any user-format-funcs
5244           (setq mode-string (eval mformat))
5245           (setq bufname-length (if (string-match "%b" mode-string)
5246                                    (- (length
5247                                        (buffer-name
5248                                         (if (eq where 'summary)
5249                                             nil
5250                                           (get-buffer gnus-article-buffer))))
5251                                       2)
5252                                  0))
5253           (setq max-len (max 4 (if gnus-mode-non-string-length
5254                                    (- (window-width)
5255                                       gnus-mode-non-string-length
5256                                       bufname-length)
5257                                  (length mode-string))))
5258           ;; We might have to chop a bit of the string off...
5259           (when (> (length mode-string) max-len)
5260             (setq mode-string
5261                   (concat (gnus-truncate-string mode-string (- max-len 3))
5262                           "...")))
5263           ;; Pad the mode string a bit.
5264           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5265       ;; Update the mode line.
5266       (setq mode-line-buffer-identification
5267             (gnus-mode-line-buffer-identification (list mode-string)))
5268       (set-buffer-modified-p t))))
5269
5270 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5271   "Go through the HEADERS list and add all Xrefs to a hash table.
5272 The resulting hash table is returned, or nil if no Xrefs were found."
5273   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5274          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5275          (xref-hashtb (gnus-make-hashtable))
5276          start group entry number xrefs header)
5277     (while headers
5278       (setq header (pop headers))
5279       (when (and (setq xrefs (mail-header-xref header))
5280                  (not (memq (setq number (mail-header-number header))
5281                             unreads)))
5282         (setq start 0)
5283         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5284           (setq start (match-end 0))
5285           (setq group (if prefix
5286                           (concat prefix (substring xrefs (match-beginning 1)
5287                                                     (match-end 1)))
5288                         (substring xrefs (match-beginning 1) (match-end 1))))
5289           (setq number
5290                 (string-to-int (substring xrefs (match-beginning 2)
5291                                           (match-end 2))))
5292           (if (setq entry (gnus-gethash group xref-hashtb))
5293               (setcdr entry (cons number (cdr entry)))
5294             (gnus-sethash group (cons number nil) xref-hashtb)))))
5295     (and start xref-hashtb)))
5296
5297 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5298   "Look through all the headers and mark the Xrefs as read."
5299   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5300         name entry info xref-hashtb idlist method nth4)
5301     (save-excursion
5302       (set-buffer gnus-group-buffer)
5303       (when (setq xref-hashtb
5304                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5305         (mapatoms
5306          (lambda (group)
5307            (unless (string= from-newsgroup (setq name (symbol-name group)))
5308              (setq idlist (symbol-value group))
5309              ;; Dead groups are not updated.
5310              (and (prog1
5311                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5312                             info (nth 2 entry))
5313                     (when (stringp (setq nth4 (gnus-info-method info)))
5314                       (setq nth4 (gnus-server-to-method nth4))))
5315                   ;; Only do the xrefs if the group has the same
5316                   ;; select method as the group we have just read.
5317                   (or (gnus-methods-equal-p
5318                        nth4 (gnus-find-method-for-group from-newsgroup))
5319                       virtual
5320                       (equal nth4 (setq method (gnus-find-method-for-group
5321                                                 from-newsgroup)))
5322                       (and (equal (car nth4) (car method))
5323                            (equal (nth 1 nth4) (nth 1 method))))
5324                   gnus-use-cross-reference
5325                   (or (not (eq gnus-use-cross-reference t))
5326                       virtual
5327                       ;; Only do cross-references on subscribed
5328                       ;; groups, if that is what is wanted.
5329                       (<= (gnus-info-level info) gnus-level-subscribed))
5330                   (gnus-group-make-articles-read name idlist))))
5331          xref-hashtb)))))
5332
5333 (defun gnus-compute-read-articles (group articles)
5334   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5335          (info (nth 2 entry))
5336          (active (gnus-active group))
5337          ninfo)
5338     (when entry
5339       ;; First peel off all invalid article numbers.
5340       (when active
5341         (let ((ids articles)
5342               id first)
5343           (while (setq id (pop ids))
5344             (when (and first (> id (cdr active)))
5345               ;; We'll end up in this situation in one particular
5346               ;; obscure situation.  If you re-scan a group and get
5347               ;; a new article that is cross-posted to a different
5348               ;; group that has not been re-scanned, you might get
5349               ;; crossposted article that has a higher number than
5350               ;; Gnus believes possible.  So we re-activate this
5351               ;; group as well.  This might mean doing the
5352               ;; crossposting thingy will *increase* the number
5353               ;; of articles in some groups.  Tsk, tsk.
5354               (setq active (or (gnus-activate-group group) active)))
5355             (when (or (> id (cdr active))
5356                       (< id (car active)))
5357               (setq articles (delq id articles))))))
5358       ;; If the read list is nil, we init it.
5359       (if (and active
5360                (null (gnus-info-read info))
5361                (> (car active) 1))
5362           (setq ninfo (cons 1 (1- (car active))))
5363         (setq ninfo (gnus-info-read info)))
5364       ;; Then we add the read articles to the range.
5365       (gnus-add-to-range
5366        ninfo (setq articles (sort articles '<))))))
5367
5368 (defun gnus-group-make-articles-read (group articles)
5369   "Update the info of GROUP to say that ARTICLES are read."
5370   (let* ((num 0)
5371          (entry (gnus-gethash group gnus-newsrc-hashtb))
5372          (info (nth 2 entry))
5373          (active (gnus-active group))
5374          range)
5375     (when entry
5376       (setq range (gnus-compute-read-articles group articles))
5377       (save-excursion
5378         (set-buffer gnus-group-buffer)
5379         (gnus-undo-register
5380           `(progn
5381              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5382              (gnus-info-set-read ',info ',(gnus-info-read info))
5383              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5384              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5385              (gnus-group-update-group ,group t))))
5386       ;; Add the read articles to the range.
5387       (gnus-info-set-read info range)
5388       (gnus-request-set-mark group (list (list range 'add '(read))))
5389       ;; Then we have to re-compute how many unread
5390       ;; articles there are in this group.
5391       (when active
5392         (cond
5393          ((not range)
5394           (setq num (- (1+ (cdr active)) (car active))))
5395          ((not (listp (cdr range)))
5396           (setq num (- (cdr active) (- (1+ (cdr range))
5397                                        (car range)))))
5398          (t
5399           (while range
5400             (if (numberp (car range))
5401                 (setq num (1+ num))
5402               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5403             (setq range (cdr range)))
5404           (setq num (- (cdr active) num))))
5405         ;; Update the number of unread articles.
5406         (setcar entry num)
5407         ;; Update the group buffer.
5408         (gnus-group-update-group group t)))))
5409
5410 (defvar gnus-newsgroup-none-id 0)
5411
5412 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5413   (let ((cur nntp-server-buffer)
5414         (dependencies
5415          (or dependencies
5416              (save-excursion (set-buffer gnus-summary-buffer)
5417                              gnus-newsgroup-dependencies)))
5418         headers id end ref
5419         (mail-parse-charset gnus-newsgroup-charset)
5420         (mail-parse-ignored-charsets
5421          (save-excursion (condition-case nil
5422                              (set-buffer gnus-summary-buffer)
5423                            (error))
5424                          gnus-newsgroup-ignored-charsets)))
5425     (save-excursion
5426       (set-buffer nntp-server-buffer)
5427       ;; Translate all TAB characters into SPACE characters.
5428       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5429       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5430       (gnus-run-hooks 'gnus-parse-headers-hook)
5431       (let ((case-fold-search t)
5432             in-reply-to header p lines chars ctype)
5433         (goto-char (point-min))
5434         ;; Search to the beginning of the next header.  Error messages
5435         ;; do not begin with 2 or 3.
5436         (while (re-search-forward "^[23][0-9]+ " nil t)
5437           (setq id nil
5438                 ref nil)
5439           ;; This implementation of this function, with nine
5440           ;; search-forwards instead of the one re-search-forward and
5441           ;; a case (which basically was the old function) is actually
5442           ;; about twice as fast, even though it looks messier.  You
5443           ;; can't have everything, I guess.  Speed and elegance
5444           ;; doesn't always go hand in hand.
5445           (setq
5446            header
5447            (make-full-mail-header
5448             ;; Number.
5449             (prog1
5450                 (read cur)
5451               (end-of-line)
5452               (setq p (point))
5453               (narrow-to-region (point)
5454                                 (or (and (search-forward "\n.\n" nil t)
5455                                          (- (point) 2))
5456                                     (point))))
5457             ;; Subject.
5458             (progn
5459               (goto-char p)
5460               (if (search-forward "\nsubject:" nil t)
5461                   (nnheader-header-value)
5462                 "(none)"))
5463             ;; From.
5464             (progn
5465               (goto-char p)
5466               (if (search-forward "\nfrom:" nil t)
5467                   (nnheader-header-value)
5468                 "(nobody)"))
5469             ;; Date.
5470             (progn
5471               (goto-char p)
5472               (if (search-forward "\ndate:" nil t)
5473                   (nnheader-header-value) ""))
5474             ;; Message-ID.
5475             (progn
5476               (goto-char p)
5477               (setq id (if (re-search-forward
5478                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5479                            ;; We do it this way to make sure the Message-ID
5480                            ;; is (somewhat) syntactically valid.
5481                            (buffer-substring (match-beginning 1)
5482                                              (match-end 1))
5483                          ;; If there was no message-id, we just fake one
5484                          ;; to make subsequent routines simpler.
5485                          (nnheader-generate-fake-message-id))))
5486             ;; References.
5487             (progn
5488               (goto-char p)
5489               (if (search-forward "\nreferences:" nil t)
5490                   (progn
5491                     (setq end (point))
5492                     (prog1
5493                         (nnheader-header-value)
5494                       (setq ref
5495                             (buffer-substring
5496                              (progn
5497                                ;; (end-of-line)
5498                                (search-backward ">" end t)
5499                                (1+ (point)))
5500                              (progn
5501                                (search-backward "<" end t)
5502                                (point))))))
5503                 ;; Get the references from the in-reply-to header if there
5504                 ;; were no references and the in-reply-to header looks
5505                 ;; promising.
5506                 (if (and (search-forward "\nin-reply-to:" nil t)
5507                          (setq in-reply-to (nnheader-header-value))
5508                          (string-match "<[^>]+>" in-reply-to))
5509                     (let (ref2)
5510                       (setq ref (substring in-reply-to (match-beginning 0)
5511                                            (match-end 0)))
5512                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5513                         (setq ref2 (substring in-reply-to (match-beginning 0)
5514                                               (match-end 0)))
5515                         (when (> (length ref2) (length ref))
5516                           (setq ref ref2)))
5517                       ref)
5518                   (setq ref nil))))
5519             ;; Chars.
5520             (progn
5521               (goto-char p)
5522               (if (search-forward "\nchars: " nil t)
5523                   (if (numberp (setq chars (ignore-errors (read cur))))
5524                       chars -1)
5525                 -1))
5526             ;; Lines.
5527             (progn
5528               (goto-char p)
5529               (if (search-forward "\nlines: " nil t)
5530                   (if (numberp (setq lines (ignore-errors (read cur))))
5531                       lines -1)
5532                 -1))
5533             ;; Xref.
5534             (progn
5535               (goto-char p)
5536               (and (search-forward "\nxref:" nil t)
5537                    (nnheader-header-value)))
5538             ;; Extra.
5539             (when gnus-extra-headers
5540               (let ((extra gnus-extra-headers)
5541                     out)
5542                 (while extra
5543                   (goto-char p)
5544                   (when (search-forward
5545                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5546                     (push (cons (car extra) (nnheader-header-value)) out))
5547                   (pop extra))
5548                 out))))
5549           (goto-char p)
5550           (if (and (search-forward "\ncontent-type: " nil t)
5551                    (setq ctype (nnheader-header-value)))
5552               (mime-entity-set-content-type-internal
5553                header (mime-parse-Content-Type ctype)))
5554           (when (equal id ref)
5555             (setq ref nil))
5556
5557           (when gnus-alter-header-function
5558             (funcall gnus-alter-header-function header)
5559             (setq id (mail-header-id header)
5560                   ref (gnus-parent-id (mail-header-references header))))
5561
5562           (when (setq header
5563                       (gnus-dependencies-add-header
5564                        header dependencies force-new))
5565             (push header headers))
5566           (goto-char (point-max))
5567           (widen))
5568         (nreverse headers)))))
5569
5570 ;; Goes through the xover lines and returns a list of vectors
5571 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5572                                                   force-new dependencies
5573                                                   group also-fetch-heads)
5574   "Parse the news overview data in the server buffer.
5575 Return a list of headers that match SEQUENCE (see
5576 `nntp-retrieve-headers')."
5577   ;; Get the Xref when the users reads the articles since most/some
5578   ;; NNTP servers do not include Xrefs when using XOVER.
5579   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5580   (let ((mail-parse-charset gnus-newsgroup-charset)
5581         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5582         (cur nntp-server-buffer)
5583         (dependencies (or dependencies gnus-newsgroup-dependencies))
5584         (allp (cond
5585                ((eq gnus-read-all-available-headers t)
5586                 t)
5587                ((stringp gnus-read-all-available-headers)
5588                 (string-match gnus-read-all-available-headers group))
5589                (t
5590                 nil)))
5591         number headers header)
5592     (save-excursion
5593       (set-buffer nntp-server-buffer)
5594       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5595       ;; Allow the user to mangle the headers before parsing them.
5596       (gnus-run-hooks 'gnus-parse-headers-hook)
5597       (goto-char (point-min))
5598       (gnus-parse-without-error
5599         (while (and (or sequence allp)
5600                     (not (eobp)))
5601           (setq number (read cur))
5602           (when (not allp)
5603             (while (and sequence
5604                         (< (car sequence) number))
5605               (setq sequence (cdr sequence))))
5606           (when (and (or allp
5607                          (and sequence
5608                               (eq number (car sequence))))
5609                      (progn
5610                        (setq sequence (cdr sequence))
5611                        (setq header (inline
5612                                       (gnus-nov-parse-line
5613                                        number dependencies force-new)))))
5614             (push header headers))
5615           (forward-line 1)))
5616       ;; A common bug in inn is that if you have posted an article and
5617       ;; then retrieves the active file, it will answer correctly --
5618       ;; the new article is included.  However, a NOV entry for the
5619       ;; article may not have been generated yet, so this may fail.
5620       ;; We work around this problem by retrieving the last few
5621       ;; headers using HEAD.
5622       (if (or (not also-fetch-heads)
5623               (not sequence))
5624           ;; We (probably) got all the headers.
5625           (nreverse headers)
5626         (let ((gnus-nov-is-evil t))
5627           (nconc
5628            (nreverse headers)
5629            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5630              (gnus-get-newsgroup-headers))))))))
5631
5632 (defun gnus-article-get-xrefs ()
5633   "Fill in the Xref value in `gnus-current-headers', if necessary.
5634 This is meant to be called in `gnus-article-internal-prepare-hook'."
5635   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5636                                  gnus-current-headers)))
5637     (or (not gnus-use-cross-reference)
5638         (not headers)
5639         (and (mail-header-xref headers)
5640              (not (string= (mail-header-xref headers) "")))
5641         (let ((case-fold-search t)
5642               xref)
5643           (save-restriction
5644             (nnheader-narrow-to-headers)
5645             (goto-char (point-min))
5646             (when (or (and (not (eobp))
5647                            (eq (downcase (char-after)) ?x)
5648                            (looking-at "Xref:"))
5649                       (search-forward "\nXref:" nil t))
5650               (goto-char (1+ (match-end 0)))
5651               (setq xref (buffer-substring (point)
5652                                            (progn (end-of-line) (point))))
5653               (mail-header-set-xref headers xref)))))))
5654
5655 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5656   "Find article ID and insert the summary line for that article.
5657 OLD-HEADER can either be a header or a line number to insert
5658 the subject line on."
5659   (let* ((line (and (numberp old-header) old-header))
5660          (old-header (and (vectorp old-header) old-header))
5661          (header (cond ((and old-header use-old-header)
5662                         old-header)
5663                        ((and (numberp id)
5664                              (gnus-number-to-header id))
5665                         (gnus-number-to-header id))
5666                        (t
5667                         (gnus-read-header id))))
5668          (number (and (numberp id) id))
5669          d)
5670     (when header
5671       ;; Rebuild the thread that this article is part of and go to the
5672       ;; article we have fetched.
5673       (when (and (not gnus-show-threads)
5674                  old-header)
5675         (when (and number
5676                    (setq d (gnus-data-find (mail-header-number old-header))))
5677           (goto-char (gnus-data-pos d))
5678           (gnus-data-remove
5679            number
5680            (- (gnus-point-at-bol)
5681               (prog1
5682                   (1+ (gnus-point-at-eol))
5683                 (gnus-delete-line))))))
5684       (when old-header
5685         (mail-header-set-number header (mail-header-number old-header)))
5686       (setq gnus-newsgroup-sparse
5687             (delq (setq number (mail-header-number header))
5688                   gnus-newsgroup-sparse))
5689       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5690       (push number gnus-newsgroup-limit)
5691       (gnus-rebuild-thread (mail-header-id header) line)
5692       (gnus-summary-goto-subject number nil t))
5693     (when (and (numberp number)
5694                (> number 0))
5695       ;; We have to update the boundaries even if we can't fetch the
5696       ;; article if ID is a number -- so that the next `P' or `N'
5697       ;; command will fetch the previous (or next) article even
5698       ;; if the one we tried to fetch this time has been canceled.
5699       (when (> number gnus-newsgroup-end)
5700         (setq gnus-newsgroup-end number))
5701       (when (< number gnus-newsgroup-begin)
5702         (setq gnus-newsgroup-begin number))
5703       (setq gnus-newsgroup-unselected
5704             (delq number gnus-newsgroup-unselected)))
5705     ;; Report back a success?
5706     (and header (mail-header-number header))))
5707
5708 ;;; Process/prefix in the summary buffer
5709
5710 (defun gnus-summary-work-articles (n)
5711   "Return a list of articles to be worked upon.
5712 The prefix argument, the list of process marked articles, and the
5713 current article will be taken into consideration."
5714   (save-excursion
5715     (set-buffer gnus-summary-buffer)
5716     (cond
5717      (n
5718       ;; A numerical prefix has been given.
5719       (setq n (prefix-numeric-value n))
5720       (let ((backward (< n 0))
5721             (n (abs (prefix-numeric-value n)))
5722             articles article)
5723         (save-excursion
5724           (while
5725               (and (> n 0)
5726                    (push (setq article (gnus-summary-article-number))
5727                          articles)
5728                    (if backward
5729                        (gnus-summary-find-prev nil article)
5730                      (gnus-summary-find-next nil article)))
5731             (decf n)))
5732         (nreverse articles)))
5733      ((and (gnus-region-active-p) (mark))
5734       (message "region active")
5735       ;; Work on the region between point and mark.
5736       (let ((max (max (point) (mark)))
5737             articles article)
5738         (save-excursion
5739           (goto-char (min (point) (mark)))
5740           (while
5741               (and
5742                (push (setq article (gnus-summary-article-number)) articles)
5743                (gnus-summary-find-next nil article)
5744                (< (point) max)))
5745           (nreverse articles))))
5746      (gnus-newsgroup-processable
5747       ;; There are process-marked articles present.
5748       ;; Save current state.
5749       (gnus-summary-save-process-mark)
5750       ;; Return the list.
5751       (reverse gnus-newsgroup-processable))
5752      (t
5753       ;; Just return the current article.
5754       (list (gnus-summary-article-number))))))
5755
5756 (defmacro gnus-summary-iterate (arg &rest forms)
5757   "Iterate over the process/prefixed articles and do FORMS.
5758 ARG is the interactive prefix given to the command.  FORMS will be
5759 executed with point over the summary line of the articles."
5760   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5761     `(let ((,articles (gnus-summary-work-articles ,arg)))
5762        (while ,articles
5763          (gnus-summary-goto-subject (car ,articles))
5764          ,@forms
5765          (pop ,articles)))))
5766
5767 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5768 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5769
5770 (defun gnus-summary-save-process-mark ()
5771   "Push the current set of process marked articles on the stack."
5772   (interactive)
5773   (push (copy-sequence gnus-newsgroup-processable)
5774         gnus-newsgroup-process-stack))
5775
5776 (defun gnus-summary-kill-process-mark ()
5777   "Push the current set of process marked articles on the stack and unmark."
5778   (interactive)
5779   (gnus-summary-save-process-mark)
5780   (gnus-summary-unmark-all-processable))
5781
5782 (defun gnus-summary-yank-process-mark ()
5783   "Pop the last process mark state off the stack and restore it."
5784   (interactive)
5785   (unless gnus-newsgroup-process-stack
5786     (error "Empty mark stack"))
5787   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5788
5789 (defun gnus-summary-process-mark-set (set)
5790   "Make SET into the current process marked articles."
5791   (gnus-summary-unmark-all-processable)
5792   (while set
5793     (gnus-summary-set-process-mark (pop set))))
5794
5795 ;;; Searching and stuff
5796
5797 (defun gnus-summary-search-group (&optional backward use-level)
5798   "Search for next unread newsgroup.
5799 If optional argument BACKWARD is non-nil, search backward instead."
5800   (save-excursion
5801     (set-buffer gnus-group-buffer)
5802     (when (gnus-group-search-forward
5803            backward nil (if use-level (gnus-group-group-level) nil))
5804       (gnus-group-group-name))))
5805
5806 (defun gnus-summary-best-group (&optional exclude-group)
5807   "Find the name of the best unread group.
5808 If EXCLUDE-GROUP, do not go to this group."
5809   (save-excursion
5810     (set-buffer gnus-group-buffer)
5811     (save-excursion
5812       (gnus-group-best-unread-group exclude-group))))
5813
5814 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5815   (if backward (gnus-summary-find-prev)
5816     (let* ((dummy (gnus-summary-article-intangible-p))
5817            (article (or article (gnus-summary-article-number)))
5818            (arts (gnus-data-find-list article))
5819            result)
5820       (when (and (not dummy)
5821                  (or (not gnus-summary-check-current)
5822                      (not unread)
5823                      (not (gnus-data-unread-p (car arts)))))
5824         (setq arts (cdr arts)))
5825       (when (setq result
5826                   (if unread
5827                       (progn
5828                         (while arts
5829                           (when (or (and undownloaded
5830                                          (eq gnus-undownloaded-mark
5831                                              (gnus-data-mark (car arts))))
5832                                     (gnus-data-unread-p (car arts)))
5833                             (setq result (car arts)
5834                                   arts nil))
5835                           (setq arts (cdr arts)))
5836                         result)
5837                     (car arts)))
5838         (goto-char (gnus-data-pos result))
5839         (gnus-data-number result)))))
5840
5841 (defun gnus-summary-find-prev (&optional unread article)
5842   (let* ((eobp (eobp))
5843          (article (or article (gnus-summary-article-number)))
5844          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5845          result)
5846     (when (and (not eobp)
5847                (or (not gnus-summary-check-current)
5848                    (not unread)
5849                    (not (gnus-data-unread-p (car arts)))))
5850       (setq arts (cdr arts)))
5851     (when (setq result
5852                 (if unread
5853                     (progn
5854                       (while arts
5855                         (when (gnus-data-unread-p (car arts))
5856                           (setq result (car arts)
5857                                 arts nil))
5858                         (setq arts (cdr arts)))
5859                       result)
5860                   (car arts)))
5861       (goto-char (gnus-data-pos result))
5862       (gnus-data-number result))))
5863
5864 (defun gnus-summary-find-subject (subject &optional unread backward article)
5865   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5866          (article (or article (gnus-summary-article-number)))
5867          (articles (gnus-data-list backward))
5868          (arts (gnus-data-find-list article articles))
5869          result)
5870     (when (or (not gnus-summary-check-current)
5871               (not unread)
5872               (not (gnus-data-unread-p (car arts))))
5873       (setq arts (cdr arts)))
5874     (while arts
5875       (and (or (not unread)
5876                (gnus-data-unread-p (car arts)))
5877            (vectorp (gnus-data-header (car arts)))
5878            (gnus-subject-equal
5879             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5880            (setq result (car arts)
5881                  arts nil))
5882       (setq arts (cdr arts)))
5883     (and result
5884          (goto-char (gnus-data-pos result))
5885          (gnus-data-number result))))
5886
5887 (defun gnus-summary-search-forward (&optional unread subject backward)
5888   "Search forward for an article.
5889 If UNREAD, look for unread articles.  If SUBJECT, look for
5890 articles with that subject.  If BACKWARD, search backward instead."
5891   (cond (subject (gnus-summary-find-subject subject unread backward))
5892         (backward (gnus-summary-find-prev unread))
5893         (t (gnus-summary-find-next unread))))
5894
5895 (defun gnus-recenter (&optional n)
5896   "Center point in window and redisplay frame.
5897 Also do horizontal recentering."
5898   (interactive "P")
5899   (when (and gnus-auto-center-summary
5900              (not (eq gnus-auto-center-summary 'vertical)))
5901     (gnus-horizontal-recenter))
5902   (recenter n))
5903
5904 (defun gnus-summary-recenter ()
5905   "Center point in the summary window.
5906 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5907 displayed, no centering will be performed."
5908   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5909   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5910   (interactive)
5911   (let* ((top (cond ((< (window-height) 4) 0)
5912                     ((< (window-height) 7) 1)
5913                     (t (if (numberp gnus-auto-center-summary)
5914                            gnus-auto-center-summary
5915                          2))))
5916          (height (1- (window-height)))
5917          (bottom (save-excursion (goto-char (point-max))
5918                                  (forward-line (- height))
5919                                  (point)))
5920          (window (get-buffer-window (current-buffer))))
5921     ;; The user has to want it.
5922     (when gnus-auto-center-summary
5923       (when (get-buffer-window gnus-article-buffer)
5924         ;; Only do recentering when the article buffer is displayed,
5925         ;; Set the window start to either `bottom', which is the biggest
5926         ;; possible valid number, or the second line from the top,
5927         ;; whichever is the least.
5928         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5929           (if (> bottom top-pos)
5930               ;; Keep the second line from the top visible
5931               (set-window-start window top-pos t)
5932             ;; Try to keep the bottom line visible; if it's partially
5933             ;; obscured, either scroll one more line to make it fully
5934             ;; visible, or revert to using TOP-POS.
5935             (save-excursion
5936               (goto-char (point-max))
5937               (forward-line -1)
5938               (let ((last-line-start (point)))
5939                 (goto-char bottom)
5940                 (set-window-start window (point) t)
5941                 (when (not (pos-visible-in-window-p last-line-start window))
5942                   (forward-line 1)
5943                   (set-window-start window (min (point) top-pos) t)))))))
5944       ;; Do horizontal recentering while we're at it.
5945       (when (and (get-buffer-window (current-buffer) t)
5946                  (not (eq gnus-auto-center-summary 'vertical)))
5947         (let ((selected (selected-window)))
5948           (select-window (get-buffer-window (current-buffer) t))
5949           (gnus-summary-position-point)
5950           (gnus-horizontal-recenter)
5951           (select-window selected))))))
5952
5953 (defun gnus-summary-jump-to-group (newsgroup)
5954   "Move point to NEWSGROUP in group mode buffer."
5955   ;; Keep update point of group mode buffer if visible.
5956   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5957       (save-window-excursion
5958         ;; Take care of tree window mode.
5959         (when (get-buffer-window gnus-group-buffer)
5960           (pop-to-buffer gnus-group-buffer))
5961         (gnus-group-jump-to-group newsgroup))
5962     (save-excursion
5963       ;; Take care of tree window mode.
5964       (if (get-buffer-window gnus-group-buffer)
5965           (pop-to-buffer gnus-group-buffer)
5966         (set-buffer gnus-group-buffer))
5967       (gnus-group-jump-to-group newsgroup))))
5968
5969 ;; This function returns a list of article numbers based on the
5970 ;; difference between the ranges of read articles in this group and
5971 ;; the range of active articles.
5972 (defun gnus-list-of-unread-articles (group)
5973   (let* ((read (gnus-info-read (gnus-get-info group)))
5974          (active (or (gnus-active group) (gnus-activate-group group)))
5975          (last (cdr active))
5976          first nlast unread)
5977     ;; If none are read, then all are unread.
5978     (if (not read)
5979         (setq first (car active))
5980       ;; If the range of read articles is a single range, then the
5981       ;; first unread article is the article after the last read
5982       ;; article.  Sounds logical, doesn't it?
5983       (if (and (not (listp (cdr read)))
5984                (or (< (car read) (car active))
5985                    (progn (setq read (list read))
5986                           nil)))
5987           (setq first (max (car active) (1+ (cdr read))))
5988         ;; `read' is a list of ranges.
5989         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5990                                   (caar read)))
5991                   1)
5992           (setq first (car active)))
5993         (while read
5994           (when first
5995             (while (< first nlast)
5996               (push first unread)
5997               (setq first (1+ first))))
5998           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5999           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6000           (setq read (cdr read)))))
6001     ;; And add the last unread articles.
6002     (while (<= first last)
6003       (push first unread)
6004       (setq first (1+ first)))
6005     ;; Return the list of unread articles.
6006     (delq 0 (nreverse unread))))
6007
6008 (defun gnus-list-of-read-articles (group)
6009   "Return a list of unread, unticked and non-dormant articles."
6010   (let* ((info (gnus-get-info group))
6011          (marked (gnus-info-marks info))
6012          (active (gnus-active group)))
6013     (and info active
6014          (gnus-list-range-difference
6015           (gnus-list-range-difference
6016            (gnus-sorted-complement
6017             (gnus-uncompress-range active)
6018             (gnus-list-of-unread-articles group))
6019            (cdr (assq 'dormant marked)))
6020           (cdr (assq 'tick marked))))))
6021
6022 ;; Various summary commands
6023
6024 (defun gnus-summary-select-article-buffer ()
6025   "Reconfigure windows to show article buffer."
6026   (interactive)
6027   (if (not (gnus-buffer-live-p gnus-article-buffer))
6028       (error "There is no article buffer for this summary buffer")
6029     (gnus-configure-windows 'article)
6030     (select-window (get-buffer-window gnus-article-buffer))))
6031
6032 (defun gnus-summary-universal-argument (arg)
6033   "Perform any operation on all articles that are process/prefixed."
6034   (interactive "P")
6035   (let ((articles (gnus-summary-work-articles arg))
6036         func article)
6037     (if (eq
6038          (setq
6039           func
6040           (key-binding
6041            (read-key-sequence
6042             (substitute-command-keys
6043              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6044          'undefined)
6045         (gnus-error 1 "Undefined key")
6046       (save-excursion
6047         (while articles
6048           (gnus-summary-goto-subject (setq article (pop articles)))
6049           (let (gnus-newsgroup-processable)
6050             (command-execute func))
6051           (gnus-summary-remove-process-mark article)))))
6052   (gnus-summary-position-point))
6053
6054 (defun gnus-summary-toggle-truncation (&optional arg)
6055   "Toggle truncation of summary lines.
6056 With arg, turn line truncation on iff arg is positive."
6057   (interactive "P")
6058   (setq truncate-lines
6059         (if (null arg) (not truncate-lines)
6060           (> (prefix-numeric-value arg) 0)))
6061   (redraw-display))
6062
6063 (defun gnus-summary-reselect-current-group (&optional all rescan)
6064   "Exit and then reselect the current newsgroup.
6065 The prefix argument ALL means to select all articles."
6066   (interactive "P")
6067   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6068     (error "Ephemeral groups can't be reselected"))
6069   (let ((current-subject (gnus-summary-article-number))
6070         (group gnus-newsgroup-name))
6071     (setq gnus-newsgroup-begin nil)
6072     (gnus-summary-exit)
6073     ;; We have to adjust the point of group mode buffer because
6074     ;; point was moved to the next unread newsgroup by exiting.
6075     (gnus-summary-jump-to-group group)
6076     (when rescan
6077       (save-excursion
6078         (save-window-excursion
6079           ;; Don't show group contents.
6080           (set-window-start (selected-window) (point-max))
6081           (gnus-group-get-new-news-this-group 1))))
6082     (gnus-group-read-group all t)
6083     (gnus-summary-goto-subject current-subject nil t)))
6084
6085 (defun gnus-summary-rescan-group (&optional all)
6086   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6087   (interactive "P")
6088   (gnus-summary-reselect-current-group all t))
6089
6090 (defun gnus-summary-update-info (&optional non-destructive)
6091   (save-excursion
6092     (let ((group gnus-newsgroup-name))
6093       (when group
6094         (when gnus-newsgroup-kill-headers
6095           (setq gnus-newsgroup-killed
6096                 (gnus-compress-sequence
6097                  (gnus-sorted-union
6098                   (gnus-list-range-intersection
6099                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6100                   gnus-newsgroup-unreads)
6101                  t)))
6102         (unless (listp (cdr gnus-newsgroup-killed))
6103           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6104         (let ((headers gnus-newsgroup-headers))
6105           ;; Set the new ranges of read articles.
6106           (save-excursion
6107             (set-buffer gnus-group-buffer)
6108             (gnus-undo-force-boundary))
6109           (gnus-update-read-articles
6110            group (gnus-sorted-union
6111                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6112           ;; Set the current article marks.
6113           (let ((gnus-newsgroup-scored
6114                  (if (and (not gnus-save-score)
6115                           (not non-destructive))
6116                      nil
6117                    gnus-newsgroup-scored)))
6118             (save-excursion
6119               (gnus-update-marks)))
6120           ;; Do the cross-ref thing.
6121           (when gnus-use-cross-reference
6122             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6123           ;; Do not switch windows but change the buffer to work.
6124           (set-buffer gnus-group-buffer)
6125           (unless (gnus-ephemeral-group-p group)
6126             (gnus-group-update-group group)))))))
6127
6128 (defun gnus-summary-save-newsrc (&optional force)
6129   "Save the current number of read/marked articles in the dribble buffer.
6130 The dribble buffer will then be saved.
6131 If FORCE (the prefix), also save the .newsrc file(s)."
6132   (interactive "P")
6133   (gnus-summary-update-info t)
6134   (if force
6135       (gnus-save-newsrc-file)
6136     (gnus-dribble-save)))
6137
6138 (defun gnus-summary-exit (&optional temporary)
6139   "Exit reading current newsgroup, and then return to group selection mode.
6140 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6141   (interactive)
6142   (gnus-set-global-variables)
6143   (gnus-kill-save-kill-buffer)
6144   (gnus-async-halt-prefetch)
6145   (let* ((group gnus-newsgroup-name)
6146          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6147          (mode major-mode)
6148          (group-point nil)
6149          (buf (current-buffer)))
6150     (unless quit-config
6151       ;; Do adaptive scoring, and possibly save score files.
6152       (when gnus-newsgroup-adaptive
6153         (gnus-score-adaptive))
6154       (when gnus-use-scoring
6155         (gnus-score-save)))
6156     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6157     ;; If we have several article buffers, we kill them at exit.
6158     (unless gnus-single-article-buffer
6159       (gnus-kill-buffer gnus-original-article-buffer)
6160       (setq gnus-article-current nil))
6161     (when gnus-use-cache
6162       (gnus-cache-possibly-remove-articles)
6163       (gnus-cache-save-buffers))
6164     (gnus-async-prefetch-remove-group group)
6165     (when gnus-suppress-duplicates
6166       (gnus-dup-enter-articles))
6167     (when gnus-use-trees
6168       (gnus-tree-close group))
6169     (when gnus-use-cache
6170       (gnus-cache-write-active))
6171     ;; Remove entries for this group.
6172     (nnmail-purge-split-history (gnus-group-real-name group))
6173     ;; Make all changes in this group permanent.
6174     (unless quit-config
6175       (gnus-run-hooks 'gnus-exit-group-hook)
6176       (gnus-summary-update-info))
6177     (gnus-close-group group)
6178     ;; Make sure where we were, and go to next newsgroup.
6179     (set-buffer gnus-group-buffer)
6180     (unless quit-config
6181       (gnus-group-jump-to-group group))
6182     (gnus-run-hooks 'gnus-summary-exit-hook)
6183     (unless (or quit-config
6184                 ;; If this group has disappeared from the summary
6185                 ;; buffer, don't skip forwards.
6186                 (not (string= group (gnus-group-group-name))))
6187       (gnus-group-next-unread-group 1))
6188     (setq group-point (point))
6189     (if temporary
6190         nil                             ;Nothing to do.
6191       ;; If we have several article buffers, we kill them at exit.
6192       (unless gnus-single-article-buffer
6193         (gnus-kill-buffer gnus-article-buffer)
6194         (gnus-kill-buffer gnus-original-article-buffer)
6195         (setq gnus-article-current nil))
6196       (set-buffer buf)
6197       (if (not gnus-kill-summary-on-exit)
6198           (progn
6199             (gnus-deaden-summary)
6200             (setq mode nil))
6201         ;; We set all buffer-local variables to nil.  It is unclear why
6202         ;; this is needed, but if we don't, buffer-local variables are
6203         ;; not garbage-collected, it seems.  This would the lead to en
6204         ;; ever-growing Emacs.
6205         (gnus-summary-clear-local-variables)
6206         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6207           (gnus-summary-clear-local-variables))
6208         (when (get-buffer gnus-article-buffer)
6209           (bury-buffer gnus-article-buffer))
6210         ;; We clear the global counterparts of the buffer-local
6211         ;; variables as well, just to be on the safe side.
6212         (set-buffer gnus-group-buffer)
6213         (gnus-summary-clear-local-variables)
6214         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6215           (gnus-summary-clear-local-variables)))
6216       (setq gnus-current-select-method gnus-select-method)
6217       (pop-to-buffer gnus-group-buffer)
6218       (if (not quit-config)
6219           (progn
6220             (goto-char group-point)
6221             (gnus-configure-windows 'group 'force)
6222             (unless (pos-visible-in-window-p)
6223               (forward-line (/ (static-if (featurep 'xemacs)
6224                                    (window-displayed-height)
6225                                  (1- (window-height)))
6226                                -2))
6227               (set-window-start (selected-window) (point))
6228               (goto-char group-point)))
6229         (gnus-handle-ephemeral-exit quit-config))
6230       ;; Return to group mode buffer.
6231       (when (eq mode 'gnus-summary-mode)
6232         (gnus-kill-buffer buf))
6233       ;; Clear the current group name.
6234       (unless quit-config
6235         (setq gnus-newsgroup-name nil)))))
6236
6237 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6238 (defun gnus-summary-exit-no-update (&optional no-questions)
6239   "Quit reading current newsgroup without updating read article info."
6240   (interactive)
6241   (let* ((group gnus-newsgroup-name)
6242          (quit-config (gnus-group-quit-config group)))
6243     (when (or no-questions
6244               gnus-expert-user
6245               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6246       (gnus-async-halt-prefetch)
6247       (mapcar 'funcall
6248               (delq 'gnus-summary-expire-articles
6249                     (copy-sequence gnus-summary-prepare-exit-hook)))
6250       ;; If we have several article buffers, we kill them at exit.
6251       (unless gnus-single-article-buffer
6252         (gnus-kill-buffer gnus-article-buffer)
6253         (gnus-kill-buffer gnus-original-article-buffer)
6254         (setq gnus-article-current nil))
6255       (if (not gnus-kill-summary-on-exit)
6256           (gnus-deaden-summary)
6257         (gnus-close-group group)
6258         (gnus-summary-clear-local-variables)
6259         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6260           (gnus-summary-clear-local-variables))
6261         (set-buffer gnus-group-buffer)
6262         (gnus-summary-clear-local-variables)
6263         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6264           (gnus-summary-clear-local-variables))
6265         (when (get-buffer gnus-summary-buffer)
6266           (kill-buffer gnus-summary-buffer)))
6267       (unless gnus-single-article-buffer
6268         (setq gnus-article-current nil))
6269       (when gnus-use-trees
6270         (gnus-tree-close group))
6271       (gnus-async-prefetch-remove-group group)
6272       (when (get-buffer gnus-article-buffer)
6273         (bury-buffer gnus-article-buffer))
6274       ;; Return to the group buffer.
6275       (gnus-configure-windows 'group 'force)
6276       ;; Clear the current group name.
6277       (setq gnus-newsgroup-name nil)
6278       (when (equal (gnus-group-group-name) group)
6279         (gnus-group-next-unread-group 1))
6280       (when quit-config
6281         (gnus-handle-ephemeral-exit quit-config)))))
6282
6283 (defun gnus-handle-ephemeral-exit (quit-config)
6284   "Handle movement when leaving an ephemeral group.
6285 The state which existed when entering the ephemeral is reset."
6286   (if (not (buffer-name (car quit-config)))
6287       (gnus-configure-windows 'group 'force)
6288     (set-buffer (car quit-config))
6289     (cond ((eq major-mode 'gnus-summary-mode)
6290            (gnus-set-global-variables))
6291           ((eq major-mode 'gnus-article-mode)
6292            (save-excursion
6293              ;; The `gnus-summary-buffer' variable may point
6294              ;; to the old summary buffer when using a single
6295              ;; article buffer.
6296              (unless (gnus-buffer-live-p gnus-summary-buffer)
6297                (set-buffer gnus-group-buffer))
6298              (set-buffer gnus-summary-buffer)
6299              (gnus-set-global-variables))))
6300     (if (or (eq (cdr quit-config) 'article)
6301             (eq (cdr quit-config) 'pick))
6302         (progn
6303           ;; The current article may be from the ephemeral group
6304           ;; thus it is best that we reload this article
6305           (gnus-summary-show-article)
6306           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6307               (gnus-configure-windows 'pick 'force)
6308             (gnus-configure-windows (cdr quit-config) 'force)))
6309       (gnus-configure-windows (cdr quit-config) 'force))
6310     (when (eq major-mode 'gnus-summary-mode)
6311       (gnus-summary-next-subject 1 nil t)
6312       (gnus-summary-recenter)
6313       (gnus-summary-position-point))))
6314
6315 (defun gnus-summary-preview-mime-message ()
6316   "MIME decode and play this message."
6317   (interactive)
6318   (let ((gnus-break-pages nil)
6319         (gnus-show-mime t))
6320     (gnus-summary-select-article gnus-show-all-headers t))
6321   (let ((w (get-buffer-window gnus-article-buffer)))
6322     (when w
6323       (select-window (get-buffer-window gnus-article-buffer)))))
6324
6325 ;;; Dead summaries.
6326
6327 (defvar gnus-dead-summary-mode-map nil)
6328
6329 (unless gnus-dead-summary-mode-map
6330   (setq gnus-dead-summary-mode-map (make-keymap))
6331   (suppress-keymap gnus-dead-summary-mode-map)
6332   (substitute-key-definition
6333    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6334   (dolist (key '("\C-d" "\r" "\177" [delete]))
6335     (define-key gnus-dead-summary-mode-map
6336       key 'gnus-summary-wake-up-the-dead))
6337   (dolist (key '("q" "Q"))
6338     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6339
6340 (defvar gnus-dead-summary-mode nil
6341   "Minor mode for Gnus summary buffers.")
6342
6343 (defun gnus-dead-summary-mode (&optional arg)
6344   "Minor mode for Gnus summary buffers."
6345   (interactive "P")
6346   (when (eq major-mode 'gnus-summary-mode)
6347     (make-local-variable 'gnus-dead-summary-mode)
6348     (setq gnus-dead-summary-mode
6349           (if (null arg) (not gnus-dead-summary-mode)
6350             (> (prefix-numeric-value arg) 0)))
6351     (when gnus-dead-summary-mode
6352       (gnus-add-minor-mode
6353        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6354
6355 (defun gnus-deaden-summary ()
6356   "Make the current summary buffer into a dead summary buffer."
6357   ;; Kill any previous dead summary buffer.
6358   (when (and gnus-dead-summary
6359              (buffer-name gnus-dead-summary))
6360     (save-excursion
6361       (set-buffer gnus-dead-summary)
6362       (when gnus-dead-summary-mode
6363         (kill-buffer (current-buffer)))))
6364   ;; Make this the current dead summary.
6365   (setq gnus-dead-summary (current-buffer))
6366   (gnus-dead-summary-mode 1)
6367   (let ((name (buffer-name)))
6368     (when (string-match "Summary" name)
6369       (rename-buffer
6370        (concat (substring name 0 (match-beginning 0)) "Dead "
6371                (substring name (match-beginning 0)))
6372        t)
6373       (bury-buffer))))
6374
6375 (defun gnus-kill-or-deaden-summary (buffer)
6376   "Kill or deaden the summary BUFFER."
6377   (save-excursion
6378     (when (and (buffer-name buffer)
6379                (not gnus-single-article-buffer))
6380       (save-excursion
6381         (set-buffer buffer)
6382         (gnus-kill-buffer gnus-article-buffer)
6383         (gnus-kill-buffer gnus-original-article-buffer)))
6384     (cond
6385      ;; Kill the buffer.
6386      (gnus-kill-summary-on-exit
6387       (when (and gnus-use-trees
6388                  (gnus-buffer-exists-p buffer))
6389         (save-excursion
6390           (set-buffer buffer)
6391           (gnus-tree-close gnus-newsgroup-name)))
6392       (gnus-kill-buffer buffer))
6393      ;; Deaden the buffer.
6394      ((gnus-buffer-exists-p buffer)
6395       (save-excursion
6396         (set-buffer buffer)
6397         (gnus-deaden-summary))))))
6398
6399 (defun gnus-summary-wake-up-the-dead (&rest args)
6400   "Wake up the dead summary buffer."
6401   (interactive)
6402   (gnus-dead-summary-mode -1)
6403   (let ((name (buffer-name)))
6404     (when (string-match "Dead " name)
6405       (rename-buffer
6406        (concat (substring name 0 (match-beginning 0))
6407                (substring name (match-end 0)))
6408        t)))
6409   (gnus-message 3 "This dead summary is now alive again"))
6410
6411 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6412 (defun gnus-summary-fetch-faq (&optional faq-dir)
6413   "Fetch the FAQ for the current group.
6414 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6415 in."
6416   (interactive
6417    (list
6418     (when current-prefix-arg
6419       (completing-read
6420        "Faq dir: " (and (listp gnus-group-faq-directory)
6421                         (mapcar (lambda (file) (list file))
6422                                 gnus-group-faq-directory))))))
6423   (let (gnus-faq-buffer)
6424     (when (setq gnus-faq-buffer
6425                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6426       (gnus-configure-windows 'summary-faq))))
6427
6428 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6429 (defun gnus-summary-describe-group (&optional force)
6430   "Describe the current newsgroup."
6431   (interactive "P")
6432   (gnus-group-describe-group force gnus-newsgroup-name))
6433
6434 (defun gnus-summary-describe-briefly ()
6435   "Describe summary mode commands briefly."
6436   (interactive)
6437   (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")))
6438
6439 ;; Walking around group mode buffer from summary mode.
6440
6441 (defun gnus-summary-next-group (&optional no-article target-group backward)
6442   "Exit current newsgroup and then select next unread newsgroup.
6443 If prefix argument NO-ARTICLE is non-nil, no article is selected
6444 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6445 previous group instead."
6446   (interactive "P")
6447   ;; Stop pre-fetching.
6448   (gnus-async-halt-prefetch)
6449   (let ((current-group gnus-newsgroup-name)
6450         (current-buffer (current-buffer))
6451         entered)
6452     ;; First we semi-exit this group to update Xrefs and all variables.
6453     ;; We can't do a real exit, because the window conf must remain
6454     ;; the same in case the user is prompted for info, and we don't
6455     ;; want the window conf to change before that...
6456     (gnus-summary-exit t)
6457     (while (not entered)
6458       ;; Then we find what group we are supposed to enter.
6459       (set-buffer gnus-group-buffer)
6460       (gnus-group-jump-to-group current-group)
6461       (setq target-group
6462             (or target-group
6463                 (if (eq gnus-keep-same-level 'best)
6464                     (gnus-summary-best-group gnus-newsgroup-name)
6465                   (gnus-summary-search-group backward gnus-keep-same-level))))
6466       (if (not target-group)
6467           ;; There are no further groups, so we return to the group
6468           ;; buffer.
6469           (progn
6470             (gnus-message 5 "Returning to the group buffer")
6471             (setq entered t)
6472             (when (gnus-buffer-live-p current-buffer)
6473               (set-buffer current-buffer)
6474               (gnus-summary-exit))
6475             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6476         ;; We try to enter the target group.
6477         (gnus-group-jump-to-group target-group)
6478         (let ((unreads (gnus-group-group-unread)))
6479           (if (and (or (eq t unreads)
6480                        (and unreads (not (zerop unreads))))
6481                    (gnus-summary-read-group
6482                     target-group nil no-article
6483                     (and (buffer-name current-buffer) current-buffer)
6484                     nil backward))
6485               (setq entered t)
6486             (setq current-group target-group
6487                   target-group nil)))))))
6488
6489 (defun gnus-summary-prev-group (&optional no-article)
6490   "Exit current newsgroup and then select previous unread newsgroup.
6491 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6492   (interactive "P")
6493   (gnus-summary-next-group no-article nil t))
6494
6495 ;; Walking around summary lines.
6496
6497 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6498   "Go to the first unread subject.
6499 If UNREAD is non-nil, go to the first unread article.
6500 Returns the article selected or nil if there are no unread articles."
6501   (interactive "P")
6502   (prog1
6503       (cond
6504        ;; Empty summary.
6505        ((null gnus-newsgroup-data)
6506         (gnus-message 3 "No articles in the group")
6507         nil)
6508        ;; Pick the first article.
6509        ((not unread)
6510         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6511         (gnus-data-number (car gnus-newsgroup-data)))
6512        ;; No unread articles.
6513        ((null gnus-newsgroup-unreads)
6514         (gnus-message 3 "No more unread articles")
6515         nil)
6516        ;; Find the first unread article.
6517        (t
6518         (let ((data gnus-newsgroup-data))
6519           (while (and data
6520                       (and (not (and undownloaded
6521                                      (eq gnus-undownloaded-mark
6522                                          (gnus-data-mark (car data)))))
6523                            (if unseen
6524                                (or (not (memq
6525                                          (gnus-data-number (car data))
6526                                          gnus-newsgroup-unseen))
6527                                    (not (gnus-data-unread-p (car data))))
6528                              (not (gnus-data-unread-p (car data))))))
6529             (setq data (cdr data)))
6530           (when data
6531             (goto-char (gnus-data-pos (car data)))
6532             (gnus-data-number (car data))))))
6533     (gnus-summary-position-point)))
6534
6535 (defun gnus-summary-next-subject (n &optional unread dont-display)
6536   "Go to next N'th summary line.
6537 If N is negative, go to the previous N'th subject line.
6538 If UNREAD is non-nil, only unread articles are selected.
6539 The difference between N and the actual number of steps taken is
6540 returned."
6541   (interactive "p")
6542   (let ((backward (< n 0))
6543         (n (abs n)))
6544     (while (and (> n 0)
6545                 (if backward
6546                     (gnus-summary-find-prev unread)
6547                   (gnus-summary-find-next unread)))
6548       (unless (zerop (setq n (1- n)))
6549         (gnus-summary-show-thread)))
6550     (when (/= 0 n)
6551       (gnus-message 7 "No more%s articles"
6552                     (if unread " unread" "")))
6553     (unless dont-display
6554       (gnus-summary-recenter)
6555       (gnus-summary-position-point))
6556     n))
6557
6558 (defun gnus-summary-next-unread-subject (n)
6559   "Go to next N'th unread summary line."
6560   (interactive "p")
6561   (gnus-summary-next-subject n t))
6562
6563 (defun gnus-summary-prev-subject (n &optional unread)
6564   "Go to previous N'th summary line.
6565 If optional argument UNREAD is non-nil, only unread article is selected."
6566   (interactive "p")
6567   (gnus-summary-next-subject (- n) unread))
6568
6569 (defun gnus-summary-prev-unread-subject (n)
6570   "Go to previous N'th unread summary line."
6571   (interactive "p")
6572   (gnus-summary-next-subject (- n) t))
6573
6574 (defun gnus-summary-goto-subject (article &optional force silent)
6575   "Go the subject line of ARTICLE.
6576 If FORCE, also allow jumping to articles not currently shown."
6577   (interactive "nArticle number: ")
6578   (unless (numberp article)
6579     (error "Article %s is not a number" article))
6580   (let ((b (point))
6581         (data (gnus-data-find article)))
6582     ;; We read in the article if we have to.
6583     (and (not data)
6584          force
6585          (gnus-summary-insert-subject
6586           article
6587           (if (or (numberp force) (vectorp force)) force)
6588           t)
6589          (setq data (gnus-data-find article)))
6590     (goto-char b)
6591     (if (not data)
6592         (progn
6593           (unless silent
6594             (gnus-message 3 "Can't find article %d" article))
6595           nil)
6596       (let ((pt (gnus-data-pos data)))
6597         (goto-char pt)
6598         (gnus-summary-set-article-display-arrow pt))
6599       (gnus-summary-position-point)
6600       article)))
6601
6602 ;; Walking around summary lines with displaying articles.
6603
6604 (defun gnus-summary-expand-window (&optional arg)
6605   "Make the summary buffer take up the entire Emacs frame.
6606 Given a prefix, will force an `article' buffer configuration."
6607   (interactive "P")
6608   (if arg
6609       (gnus-configure-windows 'article 'force)
6610     (gnus-configure-windows 'summary 'force)))
6611
6612 (defun gnus-summary-display-article (article &optional all-header)
6613   "Display ARTICLE in article buffer."
6614   (when (gnus-buffer-live-p gnus-article-buffer)
6615     (with-current-buffer gnus-article-buffer
6616       (set-buffer-multibyte t)))
6617   (gnus-set-global-variables)
6618   (when (gnus-buffer-live-p gnus-article-buffer)
6619     (with-current-buffer gnus-article-buffer
6620       (setq gnus-article-charset gnus-newsgroup-charset)
6621       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6622       (set-buffer-multibyte t)))
6623   (if (null article)
6624       nil
6625     (prog1
6626         (if gnus-summary-display-article-function
6627             (funcall gnus-summary-display-article-function article all-header)
6628           (gnus-article-prepare article all-header))
6629       (with-current-buffer gnus-article-buffer
6630         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6631              nil))
6632       (gnus-run-hooks 'gnus-select-article-hook)
6633       (when (and gnus-current-article
6634                  (not (zerop gnus-current-article)))
6635         (gnus-summary-goto-subject gnus-current-article))
6636       (gnus-summary-recenter)
6637       (when (and gnus-use-trees gnus-show-threads)
6638         (gnus-possibly-generate-tree article)
6639         (gnus-highlight-selected-tree article))
6640       ;; Successfully display article.
6641       (gnus-article-set-window-start
6642        (cdr (assq article gnus-newsgroup-bookmarks))))))
6643
6644 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6645   "Select the current article.
6646 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6647 non-nil, the article will be re-fetched even if it already present in
6648 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6649 be displayed."
6650   ;; Make sure we are in the summary buffer to work around bbdb bug.
6651   (unless (eq major-mode 'gnus-summary-mode)
6652     (set-buffer gnus-summary-buffer))
6653   (let ((article (or article (gnus-summary-article-number)))
6654         (all-headers (not (not all-headers))) ;Must be T or NIL.
6655         gnus-summary-display-article-function)
6656     (and (not pseudo)
6657          (gnus-summary-article-pseudo-p article)
6658          (error "This is a pseudo-article"))
6659     (save-excursion
6660       (set-buffer gnus-summary-buffer)
6661       (if (or (and gnus-single-article-buffer
6662                    (or (null gnus-current-article)
6663                        (null gnus-article-current)
6664                        (null (get-buffer gnus-article-buffer))
6665                        (not (eq article (cdr gnus-article-current)))
6666                        (not (equal (car gnus-article-current)
6667                                    gnus-newsgroup-name))))
6668               (and (not gnus-single-article-buffer)
6669                    (or (null gnus-current-article)
6670                        (not (eq gnus-current-article article))))
6671               force)
6672           ;; The requested article is different from the current article.
6673           (progn
6674             (gnus-summary-display-article article all-headers)
6675             (gnus-article-set-window-start
6676              (cdr (assq article gnus-newsgroup-bookmarks)))
6677             article)
6678         'old))))
6679
6680 (defun gnus-summary-force-verify-and-decrypt ()
6681   (interactive)
6682   (let ((mm-verify-option 'known)
6683         (mm-decrypt-option 'known))
6684     (gnus-summary-select-article nil 'force)))
6685
6686 (defun gnus-summary-set-current-mark (&optional current-mark)
6687   "Obsolete function."
6688   nil)
6689
6690 (defun gnus-summary-next-article (&optional unread subject backward push)
6691   "Select the next article.
6692 If UNREAD, only unread articles are selected.
6693 If SUBJECT, only articles with SUBJECT are selected.
6694 If BACKWARD, the previous article is selected instead of the next."
6695   (interactive "P")
6696   (cond
6697    ;; Is there such an article?
6698    ((and (gnus-summary-search-forward unread subject backward)
6699          (or (gnus-summary-display-article (gnus-summary-article-number))
6700              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6701     (gnus-summary-position-point))
6702    ;; If not, we try the first unread, if that is wanted.
6703    ((and subject
6704          gnus-auto-select-same
6705          (gnus-summary-first-unread-article))
6706     (gnus-summary-position-point)
6707     (gnus-message 6 "Wrapped"))
6708    ;; Try to get next/previous article not displayed in this group.
6709    ((and gnus-auto-extend-newsgroup
6710          (not unread) (not subject))
6711     (gnus-summary-goto-article
6712      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6713      nil (count-lines (point-min) (point))))
6714    ;; Go to next/previous group.
6715    (t
6716     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6717       (gnus-summary-jump-to-group gnus-newsgroup-name))
6718     (let ((cmd last-command-char)
6719           (point
6720            (save-excursion
6721              (set-buffer gnus-group-buffer)
6722              (point)))
6723           (group
6724            (if (eq gnus-keep-same-level 'best)
6725                (gnus-summary-best-group gnus-newsgroup-name)
6726              (gnus-summary-search-group backward gnus-keep-same-level))))
6727       ;; For some reason, the group window gets selected.  We change
6728       ;; it back.
6729       (select-window (get-buffer-window (current-buffer)))
6730       ;; Select next unread newsgroup automagically.
6731       (cond
6732        ((or (not gnus-auto-select-next)
6733             (not cmd))
6734         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6735        ((or (eq gnus-auto-select-next 'quietly)
6736             (and (eq gnus-auto-select-next 'slightly-quietly)
6737                  push)
6738             (and (eq gnus-auto-select-next 'almost-quietly)
6739                  (gnus-summary-last-article-p)))
6740         ;; Select quietly.
6741         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6742             (gnus-summary-exit)
6743           (gnus-message 7 "No more%s articles (%s)..."
6744                         (if unread " unread" "")
6745                         (if group (concat "selecting " group)
6746                           "exiting"))
6747           (gnus-summary-next-group nil group backward)))
6748        (t
6749         (when (gnus-key-press-event-p last-input-event)
6750           (gnus-summary-walk-group-buffer
6751            gnus-newsgroup-name cmd unread backward point))))))))
6752
6753 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6754   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6755                       (?\C-p (gnus-group-prev-unread-group 1))))
6756         (cursor-in-echo-area t)
6757         keve key group ended)
6758     (save-excursion
6759       (set-buffer gnus-group-buffer)
6760       (goto-char start)
6761       (setq group
6762             (if (eq gnus-keep-same-level 'best)
6763                 (gnus-summary-best-group gnus-newsgroup-name)
6764               (gnus-summary-search-group backward gnus-keep-same-level))))
6765     (while (not ended)
6766       (gnus-message
6767        5 "No more%s articles%s" (if unread " unread" "")
6768        (if (and group
6769                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6770            (format " (Type %s for %s [%s])"
6771                    (single-key-description cmd) group
6772                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6773          (format " (Type %s to exit %s)"
6774                  (single-key-description cmd)
6775                  gnus-newsgroup-name)))
6776       ;; Confirm auto selection.
6777       (setq key (car (setq keve (gnus-read-event-char))))
6778       (setq ended t)
6779       (cond
6780        ((assq key keystrokes)
6781         (let ((obuf (current-buffer)))
6782           (switch-to-buffer gnus-group-buffer)
6783           (when group
6784             (gnus-group-jump-to-group group))
6785           (eval (cadr (assq key keystrokes)))
6786           (setq group (gnus-group-group-name))
6787           (switch-to-buffer obuf))
6788         (setq ended nil))
6789        ((equal key cmd)
6790         (if (or (not group)
6791                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6792             (gnus-summary-exit)
6793           (gnus-summary-next-group nil group backward)))
6794        (t
6795         (push (cdr keve) unread-command-events))))))
6796
6797 (defun gnus-summary-next-unread-article ()
6798   "Select unread article after current one."
6799   (interactive)
6800   (gnus-summary-next-article
6801    (or (not (eq gnus-summary-goto-unread 'never))
6802        (gnus-summary-last-article-p (gnus-summary-article-number)))
6803    (and gnus-auto-select-same
6804         (gnus-summary-article-subject))))
6805
6806 (defun gnus-summary-prev-article (&optional unread subject)
6807   "Select the article after the current one.
6808 If UNREAD is non-nil, only unread articles are selected."
6809   (interactive "P")
6810   (gnus-summary-next-article unread subject t))
6811
6812 (defun gnus-summary-prev-unread-article ()
6813   "Select unread article before current one."
6814   (interactive)
6815   (gnus-summary-prev-article
6816    (or (not (eq gnus-summary-goto-unread 'never))
6817        (gnus-summary-first-article-p (gnus-summary-article-number)))
6818    (and gnus-auto-select-same
6819         (gnus-summary-article-subject))))
6820
6821 (defun gnus-summary-next-page (&optional lines circular)
6822   "Show next page of the selected article.
6823 If at the end of the current article, select the next article.
6824 LINES says how many lines should be scrolled up.
6825
6826 If CIRCULAR is non-nil, go to the start of the article instead of
6827 selecting the next article when reaching the end of the current
6828 article."
6829   (interactive "P")
6830   (setq gnus-summary-buffer (current-buffer))
6831   (gnus-set-global-variables)
6832   (let ((article (gnus-summary-article-number))
6833         (article-window (get-buffer-window gnus-article-buffer t))
6834         endp)
6835     ;; If the buffer is empty, we have no article.
6836     (unless article
6837       (error "No article to select"))
6838     (gnus-configure-windows 'article)
6839     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6840         (if (and (eq gnus-summary-goto-unread 'never)
6841                  (not (gnus-summary-last-article-p article)))
6842             (gnus-summary-next-article)
6843           (gnus-summary-next-unread-article))
6844       (if (or (null gnus-current-article)
6845               (null gnus-article-current)
6846               (/= article (cdr gnus-article-current))
6847               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6848           ;; Selected subject is different from current article's.
6849           (gnus-summary-display-article article)
6850         (when article-window
6851           (gnus-eval-in-buffer-window gnus-article-buffer
6852             (setq endp (gnus-article-next-page lines)))
6853           (when endp
6854             (cond (circular
6855                    (gnus-summary-beginning-of-article))
6856                   (lines
6857                    (gnus-message 3 "End of message"))
6858                   ((null lines)
6859                    (if (and (eq gnus-summary-goto-unread 'never)
6860                             (not (gnus-summary-last-article-p article)))
6861                        (gnus-summary-next-article)
6862                      (gnus-summary-next-unread-article))))))))
6863     (gnus-summary-recenter)
6864     (gnus-summary-position-point)))
6865
6866 (defun gnus-summary-prev-page (&optional lines move)
6867   "Show previous page of selected article.
6868 Argument LINES specifies lines to be scrolled down.
6869 If MOVE, move to the previous unread article if point is at
6870 the beginning of the buffer."
6871   (interactive "P")
6872   (let ((article (gnus-summary-article-number))
6873         (article-window (get-buffer-window gnus-article-buffer t))
6874         endp)
6875     (gnus-configure-windows 'article)
6876     (if (or (null gnus-current-article)
6877             (null gnus-article-current)
6878             (/= article (cdr gnus-article-current))
6879             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6880         ;; Selected subject is different from current article's.
6881         (gnus-summary-display-article article)
6882       (gnus-summary-recenter)
6883       (when article-window
6884         (gnus-eval-in-buffer-window gnus-article-buffer
6885           (setq endp (gnus-article-prev-page lines)))
6886         (when (and move endp)
6887           (cond (lines
6888                  (gnus-message 3 "Beginning of message"))
6889                 ((null lines)
6890                  (if (and (eq gnus-summary-goto-unread 'never)
6891                           (not (gnus-summary-first-article-p article)))
6892                      (gnus-summary-prev-article)
6893                    (gnus-summary-prev-unread-article))))))))
6894   (gnus-summary-position-point))
6895
6896 (defun gnus-summary-prev-page-or-article (&optional lines)
6897   "Show previous page of selected article.
6898 Argument LINES specifies lines to be scrolled down.
6899 If at the beginning of the article, go to the next article."
6900   (interactive "P")
6901   (gnus-summary-prev-page lines t))
6902
6903 (defun gnus-summary-scroll-up (lines)
6904   "Scroll up (or down) one line current article.
6905 Argument LINES specifies lines to be scrolled up (or down if negative)."
6906   (interactive "p")
6907   (gnus-configure-windows 'article)
6908   (gnus-summary-show-thread)
6909   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6910     (gnus-eval-in-buffer-window gnus-article-buffer
6911       (cond ((> lines 0)
6912              (when (gnus-article-next-page lines)
6913                (gnus-message 3 "End of message")))
6914             ((< lines 0)
6915              (gnus-article-prev-page (- lines))))))
6916   (gnus-summary-recenter)
6917   (gnus-summary-position-point))
6918
6919 (defun gnus-summary-scroll-down (lines)
6920   "Scroll down (or up) one line current article.
6921 Argument LINES specifies lines to be scrolled down (or up if negative)."
6922   (interactive "p")
6923   (gnus-summary-scroll-up (- lines)))
6924
6925 (defun gnus-summary-next-same-subject ()
6926   "Select next article which has the same subject as current one."
6927   (interactive)
6928   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6929
6930 (defun gnus-summary-prev-same-subject ()
6931   "Select previous article which has the same subject as current one."
6932   (interactive)
6933   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6934
6935 (defun gnus-summary-next-unread-same-subject ()
6936   "Select next unread article which has the same subject as current one."
6937   (interactive)
6938   (gnus-summary-next-article t (gnus-summary-article-subject)))
6939
6940 (defun gnus-summary-prev-unread-same-subject ()
6941   "Select previous unread article which has the same subject as current one."
6942   (interactive)
6943   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6944
6945 (defun gnus-summary-first-unread-article ()
6946   "Select the first unread article.
6947 Return nil if there are no unread articles."
6948   (interactive)
6949   (prog1
6950       (when (gnus-summary-first-subject t)
6951         (gnus-summary-show-thread)
6952         (gnus-summary-first-subject t)
6953         (gnus-summary-display-article (gnus-summary-article-number)))
6954     (gnus-summary-position-point)))
6955
6956 (defun gnus-summary-first-unread-subject ()
6957   "Place the point on the subject line of the first unread article.
6958 Return nil if there are no unread articles."
6959   (interactive)
6960   (prog1
6961       (when (gnus-summary-first-subject t)
6962         (gnus-summary-show-thread)
6963         (gnus-summary-first-subject t))
6964     (gnus-summary-position-point)))
6965
6966 (defun gnus-summary-first-unseen-subject ()
6967   "Place the point on the subject line of the first unseen article.
6968 Return nil if there are no unseen articles."
6969   (interactive)
6970   (prog1
6971       (when (gnus-summary-first-subject t t t)
6972         (gnus-summary-show-thread)
6973         (gnus-summary-first-subject t t t))
6974     (gnus-summary-position-point)))
6975
6976 (defun gnus-summary-first-unseen-or-unread-subject ()
6977   "Place the point on the subject line of the first unseen article.
6978 Return nil if there are no unseen articles."
6979   (interactive)
6980   (prog1
6981       (unless (when (gnus-summary-first-subject t t t)
6982                 (gnus-summary-show-thread)
6983                 (gnus-summary-first-subject t t t))
6984         (when (gnus-summary-first-subject t)
6985           (gnus-summary-show-thread)
6986           (gnus-summary-first-subject t)))
6987     (gnus-summary-position-point)))
6988
6989 (defun gnus-summary-first-article ()
6990   "Select the first article.
6991 Return nil if there are no articles."
6992   (interactive)
6993   (prog1
6994       (when (gnus-summary-first-subject)
6995         (gnus-summary-show-thread)
6996         (gnus-summary-first-subject)
6997         (gnus-summary-display-article (gnus-summary-article-number)))
6998     (gnus-summary-position-point)))
6999
7000 (defun gnus-summary-best-unread-article (&optional arg)
7001   "Select the unread article with the highest score.
7002 If given a prefix argument, select the next unread article that has a
7003 score higher than the default score."
7004   (interactive "P")
7005   (let ((article (if arg
7006                      (gnus-summary-better-unread-subject)
7007                    (gnus-summary-best-unread-subject))))
7008     (if article
7009         (gnus-summary-goto-article article)
7010       (error "No unread articles"))))
7011
7012 (defun gnus-summary-best-unread-subject ()
7013   "Select the unread subject with the highest score."
7014   (interactive)
7015   (let ((best -1000000)
7016         (data gnus-newsgroup-data)
7017         article score)
7018     (while data
7019       (and (gnus-data-unread-p (car data))
7020            (> (setq score
7021                     (gnus-summary-article-score (gnus-data-number (car data))))
7022               best)
7023            (setq best score
7024                  article (gnus-data-number (car data))))
7025       (setq data (cdr data)))
7026     (when article
7027       (gnus-summary-goto-subject article))
7028     (gnus-summary-position-point)
7029     article))
7030
7031 (defun gnus-summary-better-unread-subject ()
7032   "Select the first unread subject that has a score over the default score."
7033   (interactive)
7034   (let ((data gnus-newsgroup-data)
7035         article score)
7036     (while (and (setq article (gnus-data-number (car data)))
7037                 (or (gnus-data-read-p (car data))
7038                     (not (> (gnus-summary-article-score article)
7039                             gnus-summary-default-score))))
7040       (setq data (cdr data)))
7041     (when article
7042       (gnus-summary-goto-subject article))
7043     (gnus-summary-position-point)
7044     article))
7045
7046 (defun gnus-summary-last-subject ()
7047   "Go to the last displayed subject line in the group."
7048   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7049     (when article
7050       (gnus-summary-goto-subject article))))
7051
7052 (defun gnus-summary-goto-article (article &optional all-headers force)
7053   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7054 If ALL-HEADERS is non-nil, no header lines are hidden.
7055 If FORCE, go to the article even if it isn't displayed.  If FORCE
7056 is a number, it is the line the article is to be displayed on."
7057   (interactive
7058    (list
7059     (completing-read
7060      "Article number or Message-ID: "
7061      (mapcar (lambda (number) (list (int-to-string number)))
7062              gnus-newsgroup-limit))
7063     current-prefix-arg
7064     t))
7065   (prog1
7066       (if (and (stringp article)
7067                (string-match "@" article))
7068           (gnus-summary-refer-article article)
7069         (when (stringp article)
7070           (setq article (string-to-number article)))
7071         (if (gnus-summary-goto-subject article force)
7072             (gnus-summary-display-article article all-headers)
7073           (gnus-message 4 "Couldn't go to article %s" article) nil))
7074     (gnus-summary-position-point)))
7075
7076 (defun gnus-summary-goto-last-article ()
7077   "Go to the previously read article."
7078   (interactive)
7079   (prog1
7080       (when gnus-last-article
7081         (gnus-summary-goto-article gnus-last-article nil t))
7082     (gnus-summary-position-point)))
7083
7084 (defun gnus-summary-pop-article (number)
7085   "Pop one article off the history and go to the previous.
7086 NUMBER articles will be popped off."
7087   (interactive "p")
7088   (let (to)
7089     (setq gnus-newsgroup-history
7090           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7091     (if to
7092         (gnus-summary-goto-article (car to) nil t)
7093       (error "Article history empty")))
7094   (gnus-summary-position-point))
7095
7096 ;; Summary commands and functions for limiting the summary buffer.
7097
7098 (defun gnus-summary-limit-to-articles (n)
7099   "Limit the summary buffer to the next N articles.
7100 If not given a prefix, use the process marked articles instead."
7101   (interactive "P")
7102   (prog1
7103       (let ((articles (gnus-summary-work-articles n)))
7104         (setq gnus-newsgroup-processable nil)
7105         (gnus-summary-limit articles))
7106     (gnus-summary-position-point)))
7107
7108 (defun gnus-summary-pop-limit (&optional total)
7109   "Restore the previous limit.
7110 If given a prefix, remove all limits."
7111   (interactive "P")
7112   (when total
7113     (setq gnus-newsgroup-limits
7114           (list (mapcar (lambda (h) (mail-header-number h))
7115                         gnus-newsgroup-headers))))
7116   (unless gnus-newsgroup-limits
7117     (error "No limit to pop"))
7118   (prog1
7119       (gnus-summary-limit nil 'pop)
7120     (gnus-summary-position-point)))
7121
7122 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7123   "Limit the summary buffer to articles that have subjects that match a regexp.
7124 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7125   (interactive
7126    (list (read-string (if current-prefix-arg
7127                           "Exclude subject (regexp): "
7128                         "Limit to subject (regexp): "))
7129          nil current-prefix-arg))
7130   (unless header
7131     (setq header "subject"))
7132   (when (not (equal "" subject))
7133     (prog1
7134         (let ((articles (gnus-summary-find-matching
7135                          (or header "subject") subject 'all nil nil
7136                          not-matching)))
7137           (unless articles
7138             (error "Found no matches for \"%s\"" subject))
7139           (gnus-summary-limit articles))
7140       (gnus-summary-position-point))))
7141
7142 (defun gnus-summary-limit-to-author (from &optional not-matching)
7143   "Limit the summary buffer to articles that have authors that match a regexp.
7144 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7145   (interactive
7146    (list (read-string (if current-prefix-arg
7147                           "Exclude author (regexp): "
7148                         "Limit to author (regexp): "))
7149          current-prefix-arg))
7150   (gnus-summary-limit-to-subject from "from" not-matching))
7151
7152 (defun gnus-summary-limit-to-age (age &optional younger-p)
7153   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7154 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7155 articles that are younger than AGE days."
7156   (interactive
7157    (let ((younger current-prefix-arg)
7158          (days-got nil)
7159          days)
7160      (while (not days-got)
7161        (setq days (if younger
7162                       (read-string "Limit to articles within (in days): ")
7163                     (read-string "Limit to articles older than (in days): ")))
7164        (when (> (length days) 0)
7165          (setq days (read days)))
7166        (if (numberp days)
7167            (progn
7168              (setq days-got t)
7169              (if (< days 0)
7170                  (progn
7171                    (setq younger (not younger))
7172                    (setq days (* days -1)))))
7173          (message "Please enter a number.")
7174          (sleep-for 1)))
7175      (list days younger)))
7176   (prog1
7177       (let ((data gnus-newsgroup-data)
7178             (cutoff (days-to-time age))
7179             articles d date is-younger)
7180         (while (setq d (pop data))
7181           (when (and (vectorp (gnus-data-header d))
7182                      (setq date (mail-header-date (gnus-data-header d))))
7183             (setq is-younger (time-less-p
7184                               (time-since (condition-case ()
7185                                               (date-to-time date)
7186                                             (error '(0 0))))
7187                               cutoff))
7188             (when (if younger-p
7189                       is-younger
7190                     (not is-younger))
7191               (push (gnus-data-number d) articles))))
7192         (gnus-summary-limit (nreverse articles)))
7193     (gnus-summary-position-point)))
7194
7195 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7196   "Limit the summary buffer to articles that match an 'extra' header."
7197   (interactive
7198    (let ((header
7199           (intern
7200            (gnus-completing-read-with-default
7201             (symbol-name (car gnus-extra-headers))
7202             (if current-prefix-arg
7203                 "Exclude extra header:"
7204               "Limit extra header:")
7205             (mapcar (lambda (x)
7206                       (cons (symbol-name x) x))
7207                     gnus-extra-headers)
7208             nil
7209             t))))
7210      (list header
7211            (read-string (format "%s header %s (regexp): "
7212                                 (if current-prefix-arg "Exclude" "Limit to")
7213                                 header))
7214            current-prefix-arg)))
7215   (when (not (equal "" regexp))
7216     (prog1
7217         (let ((articles (gnus-summary-find-matching
7218                          (cons 'extra header) regexp 'all nil nil
7219                          not-matching)))
7220           (unless articles
7221             (error "Found no matches for \"%s\"" regexp))
7222           (gnus-summary-limit articles))
7223       (gnus-summary-position-point))))
7224
7225 (defun gnus-summary-limit-to-display-predicate ()
7226   "Limit the summary buffer to the predicated in the `display' group parameter."
7227   (interactive)
7228   (unless gnus-newsgroup-display
7229     (error "There is no `display' group parameter"))
7230   (let (articles)
7231     (dolist (number gnus-newsgroup-articles)
7232       (when (funcall gnus-newsgroup-display)
7233         (push number articles)))
7234     (gnus-summary-limit articles))
7235   (gnus-summary-position-point))
7236
7237 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7238 (make-obsolete
7239  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7240
7241 (defun gnus-summary-limit-to-unread (&optional all)
7242   "Limit the summary buffer to articles that are not marked as read.
7243 If ALL is non-nil, limit strictly to unread articles."
7244   (interactive "P")
7245   (if all
7246       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7247     (gnus-summary-limit-to-marks
7248      ;; Concat all the marks that say that an article is read and have
7249      ;; those removed.
7250      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7251            gnus-killed-mark gnus-kill-file-mark
7252            gnus-low-score-mark gnus-expirable-mark
7253            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7254            gnus-duplicate-mark gnus-souped-mark)
7255      'reverse)))
7256
7257 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7258 (make-obsolete 'gnus-summary-delete-marked-with
7259                'gnus-summary-limit-exlude-marks)
7260
7261 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7262   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7263 If REVERSE, limit the summary buffer to articles that are marked
7264 with MARKS.  MARKS can either be a string of marks or a list of marks.
7265 Returns how many articles were removed."
7266   (interactive "sMarks: ")
7267   (gnus-summary-limit-to-marks marks t))
7268
7269 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7270   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7271 If REVERSE (the prefix), limit the summary buffer to articles that are
7272 not marked with MARKS.  MARKS can either be a string of marks or a
7273 list of marks.
7274 Returns how many articles were removed."
7275   (interactive "sMarks: \nP")
7276   (prog1
7277       (let ((data gnus-newsgroup-data)
7278             (marks (if (listp marks) marks
7279                      (append marks nil))) ; Transform to list.
7280             articles)
7281         (while data
7282           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7283                   (memq (gnus-data-mark (car data)) marks))
7284             (push (gnus-data-number (car data)) articles))
7285           (setq data (cdr data)))
7286         (gnus-summary-limit articles))
7287     (gnus-summary-position-point)))
7288
7289 (defun gnus-summary-limit-to-score (score)
7290   "Limit to articles with score at or above SCORE."
7291   (interactive "NLimit to articles with score of at least: ")
7292   (let ((data gnus-newsgroup-data)
7293         articles)
7294     (while data
7295       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7296                 score)
7297         (push (gnus-data-number (car data)) articles))
7298       (setq data (cdr data)))
7299     (prog1
7300         (gnus-summary-limit articles)
7301       (gnus-summary-position-point))))
7302
7303 (defun gnus-summary-limit-include-thread (id)
7304   "Display all the hidden articles that is in the thread with ID in it.
7305 When called interactively, ID is the Message-ID of the current
7306 article."
7307   (interactive (list (mail-header-id (gnus-summary-article-header))))
7308   (let ((articles (gnus-articles-in-thread
7309                    (gnus-id-to-thread (gnus-root-id id)))))
7310     (prog1
7311         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7312       (gnus-summary-limit-include-matching-articles
7313        "subject"
7314        (regexp-quote (gnus-simplify-subject-re
7315                       (mail-header-subject (gnus-id-to-header id)))))
7316       (gnus-summary-position-point))))
7317
7318 (defun gnus-summary-limit-include-matching-articles (header regexp)
7319   "Display all the hidden articles that have HEADERs that match REGEXP."
7320   (interactive (list (read-string "Match on header: ")
7321                      (read-string "Regexp: ")))
7322   (let ((articles (gnus-find-matching-articles header regexp)))
7323     (prog1
7324         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7325       (gnus-summary-position-point))))
7326
7327 (defun gnus-summary-limit-include-dormant ()
7328   "Display all the hidden articles that are marked as dormant.
7329 Note that this command only works on a subset of the articles currently
7330 fetched for this group."
7331   (interactive)
7332   (unless gnus-newsgroup-dormant
7333     (error "There are no dormant articles in this group"))
7334   (prog1
7335       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7336     (gnus-summary-position-point)))
7337
7338 (defun gnus-summary-limit-exclude-dormant ()
7339   "Hide all dormant articles."
7340   (interactive)
7341   (prog1
7342       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7343     (gnus-summary-position-point)))
7344
7345 (defun gnus-summary-limit-exclude-childless-dormant ()
7346   "Hide all dormant articles that have no children."
7347   (interactive)
7348   (let ((data (gnus-data-list t))
7349         articles d children)
7350     ;; Find all articles that are either not dormant or have
7351     ;; children.
7352     (while (setq d (pop data))
7353       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7354                 (and (setq children
7355                            (gnus-article-children (gnus-data-number d)))
7356                      (let (found)
7357                        (while children
7358                          (when (memq (car children) articles)
7359                            (setq children nil
7360                                  found t))
7361                          (pop children))
7362                        found)))
7363         (push (gnus-data-number d) articles)))
7364     ;; Do the limiting.
7365     (prog1
7366         (gnus-summary-limit articles)
7367       (gnus-summary-position-point))))
7368
7369 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7370   "Mark all unread excluded articles as read.
7371 If ALL, mark even excluded ticked and dormants as read."
7372   (interactive "P")
7373   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7374   (let ((articles (gnus-sorted-ndifference
7375                    (sort
7376                     (mapcar (lambda (h) (mail-header-number h))
7377                             gnus-newsgroup-headers)
7378                     '<)
7379                    gnus-newsgroup-limit))
7380         article)
7381     (setq gnus-newsgroup-unreads
7382           (gnus-sorted-intersection gnus-newsgroup-unreads
7383                                     gnus-newsgroup-limit))
7384     (if all
7385         (setq gnus-newsgroup-dormant nil
7386               gnus-newsgroup-marked nil
7387               gnus-newsgroup-reads
7388               (nconc
7389                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7390                gnus-newsgroup-reads))
7391       (while (setq article (pop articles))
7392         (unless (or (memq article gnus-newsgroup-dormant)
7393                     (memq article gnus-newsgroup-marked))
7394           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7395
7396 (defun gnus-summary-limit (articles &optional pop)
7397   (if pop
7398       ;; We pop the previous limit off the stack and use that.
7399       (setq articles (car gnus-newsgroup-limits)
7400             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7401     ;; We use the new limit, so we push the old limit on the stack.
7402     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7403   ;; Set the limit.
7404   (setq gnus-newsgroup-limit articles)
7405   (let ((total (length gnus-newsgroup-data))
7406         (data (gnus-data-find-list (gnus-summary-article-number)))
7407         (gnus-summary-mark-below nil)   ; Inhibit this.
7408         found)
7409     ;; This will do all the work of generating the new summary buffer
7410     ;; according to the new limit.
7411     (gnus-summary-prepare)
7412     ;; Hide any threads, possibly.
7413     (gnus-summary-maybe-hide-threads)
7414     ;; Try to return to the article you were at, or one in the
7415     ;; neighborhood.
7416     (when data
7417       ;; We try to find some article after the current one.
7418       (while data
7419         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7420           (setq data nil
7421                 found t))
7422         (setq data (cdr data))))
7423     (unless found
7424       ;; If there is no data, that means that we were after the last
7425       ;; article.  The same goes when we can't find any articles
7426       ;; after the current one.
7427       (goto-char (point-max))
7428       (gnus-summary-find-prev))
7429     (gnus-set-mode-line 'summary)
7430     ;; We return how many articles were removed from the summary
7431     ;; buffer as a result of the new limit.
7432     (- total (length gnus-newsgroup-data))))
7433
7434 (defsubst gnus-invisible-cut-children (threads)
7435   (let ((num 0))
7436     (while threads
7437       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7438         (incf num))
7439       (pop threads))
7440     (< num 2)))
7441
7442 (defsubst gnus-cut-thread (thread)
7443   "Go forwards in the thread until we find an article that we want to display."
7444   (when (or (eq gnus-fetch-old-headers 'some)
7445             (eq gnus-fetch-old-headers 'invisible)
7446             (numberp gnus-fetch-old-headers)
7447             (eq gnus-build-sparse-threads 'some)
7448             (eq gnus-build-sparse-threads 'more))
7449     ;; Deal with old-fetched headers and sparse threads.
7450     (while (and
7451             thread
7452             (or
7453              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7454              (gnus-summary-article-ancient-p
7455               (mail-header-number (car thread))))
7456             (if (or (<= (length (cdr thread)) 1)
7457                     (eq gnus-fetch-old-headers 'invisible))
7458                 (setq gnus-newsgroup-limit
7459                       (delq (mail-header-number (car thread))
7460                             gnus-newsgroup-limit)
7461                       thread (cadr thread))
7462               (when (gnus-invisible-cut-children (cdr thread))
7463                 (let ((th (cdr thread)))
7464                   (while th
7465                     (if (memq (mail-header-number (caar th))
7466                               gnus-newsgroup-limit)
7467                         (setq thread (car th)
7468                               th nil)
7469                       (setq th (cdr th))))))))))
7470   thread)
7471
7472 (defun gnus-cut-threads (threads)
7473   "Cut off all uninteresting articles from the beginning of threads."
7474   (when (or (eq gnus-fetch-old-headers 'some)
7475             (eq gnus-fetch-old-headers 'invisible)
7476             (numberp gnus-fetch-old-headers)
7477             (eq gnus-build-sparse-threads 'some)
7478             (eq gnus-build-sparse-threads 'more))
7479     (let ((th threads))
7480       (while th
7481         (setcar th (gnus-cut-thread (car th)))
7482         (setq th (cdr th)))))
7483   ;; Remove nixed out threads.
7484   (delq nil threads))
7485
7486 (defun gnus-summary-initial-limit (&optional show-if-empty)
7487   "Figure out what the initial limit is supposed to be on group entry.
7488 This entails weeding out unwanted dormants, low-scored articles,
7489 fetch-old-headers verbiage, and so on."
7490   ;; Most groups have nothing to remove.
7491   (if (or gnus-inhibit-limiting
7492           (and (null gnus-newsgroup-dormant)
7493                (eq gnus-newsgroup-display 'gnus-not-ignore)
7494                (not (eq gnus-fetch-old-headers 'some))
7495                (not (numberp gnus-fetch-old-headers))
7496                (not (eq gnus-fetch-old-headers 'invisible))
7497                (null gnus-summary-expunge-below)
7498                (not (eq gnus-build-sparse-threads 'some))
7499                (not (eq gnus-build-sparse-threads 'more))
7500                (null gnus-thread-expunge-below)
7501                (not gnus-use-nocem)))
7502       ()                                ; Do nothing.
7503     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7504     (setq gnus-newsgroup-limit nil)
7505     (mapatoms
7506      (lambda (node)
7507        (unless (car (symbol-value node))
7508          ;; These threads have no parents -- they are roots.
7509          (let ((nodes (cdr (symbol-value node)))
7510                thread)
7511            (while nodes
7512              (if (and gnus-thread-expunge-below
7513                       (< (gnus-thread-total-score (car nodes))
7514                          gnus-thread-expunge-below))
7515                  (gnus-expunge-thread (pop nodes))
7516                (setq thread (pop nodes))
7517                (gnus-summary-limit-children thread))))))
7518      gnus-newsgroup-dependencies)
7519     ;; If this limitation resulted in an empty group, we might
7520     ;; pop the previous limit and use it instead.
7521     (when (and (not gnus-newsgroup-limit)
7522                show-if-empty)
7523       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7524     gnus-newsgroup-limit))
7525
7526 (defun gnus-summary-limit-children (thread)
7527   "Return 1 if this subthread is visible and 0 if it is not."
7528   ;; First we get the number of visible children to this thread.  This
7529   ;; is done by recursing down the thread using this function, so this
7530   ;; will really go down to a leaf article first, before slowly
7531   ;; working its way up towards the root.
7532   (when thread
7533     (let ((children
7534            (if (cdr thread)
7535                (apply '+ (mapcar 'gnus-summary-limit-children
7536                                  (cdr thread)))
7537              0))
7538           (number (mail-header-number (car thread)))
7539           score)
7540       (if (and
7541            (not (memq number gnus-newsgroup-marked))
7542            (or
7543             ;; If this article is dormant and has absolutely no visible
7544             ;; children, then this article isn't visible.
7545             (and (memq number gnus-newsgroup-dormant)
7546                  (zerop children))
7547             ;; If this is "fetch-old-headered" and there is no
7548             ;; visible children, then we don't want this article.
7549             (and (or (eq gnus-fetch-old-headers 'some)
7550                      (numberp gnus-fetch-old-headers))
7551                  (gnus-summary-article-ancient-p number)
7552                  (zerop children))
7553             ;; If this is "fetch-old-headered" and `invisible', then
7554             ;; we don't want this article.
7555             (and (eq gnus-fetch-old-headers 'invisible)
7556                  (gnus-summary-article-ancient-p number))
7557             ;; If this is a sparsely inserted article with no children,
7558             ;; we don't want it.
7559             (and (eq gnus-build-sparse-threads 'some)
7560                  (gnus-summary-article-sparse-p number)
7561                  (zerop children))
7562             ;; If we use expunging, and this article is really
7563             ;; low-scored, then we don't want this article.
7564             (when (and gnus-summary-expunge-below
7565                        (< (setq score
7566                                 (or (cdr (assq number gnus-newsgroup-scored))
7567                                     gnus-summary-default-score))
7568                           gnus-summary-expunge-below))
7569               ;; We increase the expunge-tally here, but that has
7570               ;; nothing to do with the limits, really.
7571               (incf gnus-newsgroup-expunged-tally)
7572               ;; We also mark as read here, if that's wanted.
7573               (when (and gnus-summary-mark-below
7574                          (< score gnus-summary-mark-below))
7575                 (setq gnus-newsgroup-unreads
7576                       (delq number gnus-newsgroup-unreads))
7577                 (if gnus-newsgroup-auto-expire
7578                     (push number gnus-newsgroup-expirable)
7579                   (push (cons number gnus-low-score-mark)
7580                         gnus-newsgroup-reads)))
7581               t)
7582             ;; Do the `display' group parameter.
7583             (and gnus-newsgroup-display
7584                  (not (funcall gnus-newsgroup-display)))
7585             ;; Check NoCeM things.
7586             (if (and gnus-use-nocem
7587                      (gnus-nocem-unwanted-article-p
7588                       (mail-header-id (car thread))))
7589                 (progn
7590                   (setq gnus-newsgroup-unreads
7591                         (delq number gnus-newsgroup-unreads))
7592                   t))))
7593           ;; Nope, invisible article.
7594           0
7595         ;; Ok, this article is to be visible, so we add it to the limit
7596         ;; and return 1.
7597         (push number gnus-newsgroup-limit)
7598         1))))
7599
7600 (defun gnus-expunge-thread (thread)
7601   "Mark all articles in THREAD as read."
7602   (let* ((number (mail-header-number (car thread))))
7603     (incf gnus-newsgroup-expunged-tally)
7604     ;; We also mark as read here, if that's wanted.
7605     (setq gnus-newsgroup-unreads
7606           (delq number gnus-newsgroup-unreads))
7607     (if gnus-newsgroup-auto-expire
7608         (push number gnus-newsgroup-expirable)
7609       (push (cons number gnus-low-score-mark)
7610             gnus-newsgroup-reads)))
7611   ;; Go recursively through all subthreads.
7612   (mapcar 'gnus-expunge-thread (cdr thread)))
7613
7614 ;; Summary article oriented commands
7615
7616 (defun gnus-summary-refer-parent-article (n)
7617   "Refer parent article N times.
7618 If N is negative, go to ancestor -N instead.
7619 The difference between N and the number of articles fetched is returned."
7620   (interactive "p")
7621   (let ((skip 1)
7622         error header ref)
7623     (when (not (natnump n))
7624       (setq skip (abs n)
7625             n 1))
7626     (while (and (> n 0)
7627                 (not error))
7628       (setq header (gnus-summary-article-header))
7629       (if (and (eq (mail-header-number header)
7630                    (cdr gnus-article-current))
7631                (equal gnus-newsgroup-name
7632                       (car gnus-article-current)))
7633           ;; If we try to find the parent of the currently
7634           ;; displayed article, then we take a look at the actual
7635           ;; References header, since this is slightly more
7636           ;; reliable than the References field we got from the
7637           ;; server.
7638           (save-excursion
7639             (set-buffer gnus-original-article-buffer)
7640             (nnheader-narrow-to-headers)
7641             (unless (setq ref (message-fetch-field "references"))
7642               (setq ref (message-fetch-field "in-reply-to")))
7643             (widen))
7644         (setq ref
7645               ;; It's not the current article, so we take a bet on
7646               ;; the value we got from the server.
7647               (mail-header-references header)))
7648       (if (and ref
7649                (not (equal ref "")))
7650           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7651             (gnus-message 1 "Couldn't find parent"))
7652         (gnus-message 1 "No references in article %d"
7653                       (gnus-summary-article-number))
7654         (setq error t))
7655       (decf n))
7656     (gnus-summary-position-point)
7657     n))
7658
7659 (defun gnus-summary-refer-references ()
7660   "Fetch all articles mentioned in the References header.
7661 Return the number of articles fetched."
7662   (interactive)
7663   (let ((ref (mail-header-references (gnus-summary-article-header)))
7664         (current (gnus-summary-article-number))
7665         (n 0))
7666     (if (or (not ref)
7667             (equal ref ""))
7668         (error "No References in the current article")
7669       ;; For each Message-ID in the References header...
7670       (while (string-match "<[^>]*>" ref)
7671         (incf n)
7672         ;; ... fetch that article.
7673         (gnus-summary-refer-article
7674          (prog1 (match-string 0 ref)
7675            (setq ref (substring ref (match-end 0))))))
7676       (gnus-summary-goto-subject current)
7677       (gnus-summary-position-point)
7678       n)))
7679
7680 (defun gnus-summary-refer-thread (&optional limit)
7681   "Fetch all articles in the current thread.
7682 If LIMIT (the numerical prefix), fetch that many old headers instead
7683 of what's specified by the `gnus-refer-thread-limit' variable."
7684   (interactive "P")
7685   (let ((id (mail-header-id (gnus-summary-article-header)))
7686         (limit (if limit (prefix-numeric-value limit)
7687                  gnus-refer-thread-limit)))
7688     ;; We want to fetch LIMIT *old* headers, but we also have to
7689     ;; re-fetch all the headers in the current buffer, because many of
7690     ;; them may be undisplayed.  So we adjust LIMIT.
7691     (when (numberp limit)
7692       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7693     (unless (eq gnus-fetch-old-headers 'invisible)
7694       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7695       ;; Retrieve the headers and read them in.
7696       (if (eq (gnus-retrieve-headers
7697                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7698               'nov)
7699           (gnus-build-all-threads)
7700         (error "Can't fetch thread from backends that don't support NOV"))
7701       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7702     (gnus-summary-limit-include-thread id)))
7703
7704 (defun gnus-summary-refer-article (message-id)
7705   "Fetch an article specified by MESSAGE-ID."
7706   (interactive "sMessage-ID: ")
7707   (when (and (stringp message-id)
7708              (not (zerop (length message-id))))
7709     ;; Construct the correct Message-ID if necessary.
7710     ;; Suggested by tale@pawl.rpi.edu.
7711     (unless (string-match "^<" message-id)
7712       (setq message-id (concat "<" message-id)))
7713     (unless (string-match ">$" message-id)
7714       (setq message-id (concat message-id ">")))
7715     (let* ((header (gnus-id-to-header message-id))
7716            (sparse (and header
7717                         (gnus-summary-article-sparse-p
7718                          (mail-header-number header))
7719                         (memq (mail-header-number header)
7720                               gnus-newsgroup-limit)))
7721            number)
7722       (cond
7723        ;; If the article is present in the buffer we just go to it.
7724        ((and header
7725              (or (not (gnus-summary-article-sparse-p
7726                        (mail-header-number header)))
7727                  sparse))
7728         (prog1
7729             (gnus-summary-goto-article
7730              (mail-header-number header) nil t)
7731           (when sparse
7732             (gnus-summary-update-article (mail-header-number header)))))
7733        (t
7734         ;; We fetch the article.
7735         (catch 'found
7736           (dolist (gnus-override-method (gnus-refer-article-methods))
7737             (gnus-check-server gnus-override-method)
7738             ;; Fetch the header, and display the article.
7739             (when (setq number (gnus-summary-insert-subject message-id))
7740               (gnus-summary-select-article nil nil nil number)
7741               (throw 'found t)))
7742           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7743
7744 (defun gnus-refer-article-methods ()
7745   "Return a list of referrable methods."
7746   (cond
7747    ;; No method, so we default to current and native.
7748    ((null gnus-refer-article-method)
7749     (list gnus-current-select-method gnus-select-method))
7750    ;; Current.
7751    ((eq 'current gnus-refer-article-method)
7752     (list gnus-current-select-method))
7753    ;; List of select methods.
7754    ((not (and (symbolp (car gnus-refer-article-method))
7755               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7756     (let (out)
7757       (dolist (method gnus-refer-article-method)
7758         (push (if (eq 'current method)
7759                   gnus-current-select-method
7760                 method)
7761               out))
7762       (nreverse out)))
7763    ;; One single select method.
7764    (t
7765     (list gnus-refer-article-method))))
7766
7767 (defun gnus-summary-edit-parameters ()
7768   "Edit the group parameters of the current group."
7769   (interactive)
7770   (gnus-group-edit-group gnus-newsgroup-name 'params))
7771
7772 (defun gnus-summary-customize-parameters ()
7773   "Customize the group parameters of the current group."
7774   (interactive)
7775   (gnus-group-customize gnus-newsgroup-name))
7776
7777 (defun gnus-summary-enter-digest-group (&optional force)
7778   "Enter an nndoc group based on the current article.
7779 If FORCE, force a digest interpretation.  If not, try
7780 to guess what the document format is."
7781   (interactive "P")
7782   (let ((conf gnus-current-window-configuration))
7783     (save-excursion
7784       (gnus-summary-select-article))
7785     (setq gnus-current-window-configuration conf)
7786     (let* ((name (format "%s-%d"
7787                          (gnus-group-prefixed-name
7788                           gnus-newsgroup-name (list 'nndoc ""))
7789                          (save-excursion
7790                            (set-buffer gnus-summary-buffer)
7791                            gnus-current-article)))
7792            (ogroup gnus-newsgroup-name)
7793            (params (append (gnus-info-params (gnus-get-info ogroup))
7794                            (list (cons 'to-group ogroup))
7795                            (list (cons 'save-article-group ogroup))))
7796            (case-fold-search t)
7797            (buf (current-buffer))
7798            dig to-address)
7799       (save-excursion
7800         (set-buffer gnus-original-article-buffer)
7801         ;; Have the digest group inherit the main mail address of
7802         ;; the parent article.
7803         (when (setq to-address (or (message-fetch-field "reply-to")
7804                                    (message-fetch-field "from")))
7805           (setq params (append
7806                         (list (cons 'to-address
7807                                     (funcall gnus-decode-encoded-word-function
7808                                              to-address))))))
7809         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7810         (insert-buffer-substring gnus-original-article-buffer)
7811         ;; Remove lines that may lead nndoc to misinterpret the
7812         ;; document type.
7813         (narrow-to-region
7814          (goto-char (point-min))
7815          (or (search-forward "\n\n" nil t) (point)))
7816         (goto-char (point-min))
7817         (delete-matching-lines "^Path:\\|^From ")
7818         (widen))
7819       (unwind-protect
7820           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7821                     (gnus-newsgroup-ephemeral-ignored-charsets
7822                      gnus-newsgroup-ignored-charsets))
7823                 (gnus-group-read-ephemeral-group
7824                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7825                               (nndoc-article-type
7826                                ,(if force 'mbox 'guess)))
7827                  t nil nil nil
7828                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7829                                                         "ADAPT")))))
7830               ;; Make all postings to this group go to the parent group.
7831               (nconc (gnus-info-params (gnus-get-info name))
7832                      params)
7833             ;; Couldn't select this doc group.
7834             (switch-to-buffer buf)
7835             (gnus-set-global-variables)
7836             (gnus-configure-windows 'summary)
7837             (gnus-message 3 "Article couldn't be entered?"))
7838         (kill-buffer dig)))))
7839
7840 (defun gnus-summary-read-document (n)
7841   "Open a new group based on the current article(s).
7842 This will allow you to read digests and other similar
7843 documents as newsgroups.
7844 Obeys the standard process/prefix convention."
7845   (interactive "P")
7846   (let* ((articles (gnus-summary-work-articles n))
7847          (ogroup gnus-newsgroup-name)
7848          (params (append (gnus-info-params (gnus-get-info ogroup))
7849                          (list (cons 'to-group ogroup))))
7850          article group egroup groups vgroup)
7851     (while (setq article (pop articles))
7852       (setq group (format "%s-%d" gnus-newsgroup-name article))
7853       (gnus-summary-remove-process-mark article)
7854       (when (gnus-summary-display-article article)
7855         (save-excursion
7856           (with-temp-buffer
7857             (insert-buffer-substring gnus-original-article-buffer)
7858             ;; Remove some headers that may lead nndoc to make
7859             ;; the wrong guess.
7860             (message-narrow-to-head)
7861             (goto-char (point-min))
7862             (delete-matching-lines "^\\(Path\\):\\|^From ")
7863             (widen)
7864             (if (setq egroup
7865                       (gnus-group-read-ephemeral-group
7866                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7867                                      (nndoc-article-type guess))
7868                        t nil t))
7869                 (progn
7870                   ;; Make all postings to this group go to the parent group.
7871                   (nconc (gnus-info-params (gnus-get-info egroup))
7872                          params)
7873                   (push egroup groups))
7874               ;; Couldn't select this doc group.
7875               (gnus-error 3 "Article couldn't be entered"))))))
7876     ;; Now we have selected all the documents.
7877     (cond
7878      ((not groups)
7879       (error "None of the articles could be interpreted as documents"))
7880      ((gnus-group-read-ephemeral-group
7881        (setq vgroup (format
7882                      "nnvirtual:%s-%s" gnus-newsgroup-name
7883                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7884        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7885        t
7886        (cons (current-buffer) 'summary)))
7887      (t
7888       (error "Couldn't select virtual nndoc group")))))
7889
7890 (defun gnus-summary-isearch-article (&optional regexp-p)
7891   "Do incremental search forward on the current article.
7892 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7893   (interactive "P")
7894   (let* ((gnus-inhibit-treatment t)
7895          (old (gnus-summary-select-article)))
7896     (gnus-configure-windows 'article)
7897     (gnus-eval-in-buffer-window gnus-article-buffer
7898       (save-restriction
7899         (widen)
7900         (when (eq 'old old)
7901           (gnus-article-show-all-headers))
7902         (goto-char (point-min))
7903         (isearch-forward regexp-p)))))
7904
7905 (defun gnus-summary-search-article-forward (regexp &optional backward)
7906   "Search for an article containing REGEXP forward.
7907 If BACKWARD, search backward instead."
7908   (interactive
7909    (list (read-string
7910           (format "Search article %s (regexp%s): "
7911                   (if current-prefix-arg "backward" "forward")
7912                   (if gnus-last-search-regexp
7913                       (concat ", default " gnus-last-search-regexp)
7914                     "")))
7915          current-prefix-arg))
7916   (if (string-equal regexp "")
7917       (setq regexp (or gnus-last-search-regexp ""))
7918     (setq gnus-last-search-regexp regexp)
7919     (setq gnus-article-before-search gnus-current-article))
7920   ;; Intentionally set gnus-last-article.
7921   (setq gnus-last-article gnus-article-before-search)
7922   (let ((gnus-last-article gnus-last-article))
7923     (if (gnus-summary-search-article regexp backward)
7924         (gnus-summary-show-thread)
7925       (error "Search failed: \"%s\"" regexp))))
7926
7927 (defun gnus-summary-search-article-backward (regexp)
7928   "Search for an article containing REGEXP backward."
7929   (interactive
7930    (list (read-string
7931           (format "Search article backward (regexp%s): "
7932                   (if gnus-last-search-regexp
7933                       (concat ", default " gnus-last-search-regexp)
7934                     "")))))
7935   (gnus-summary-search-article-forward regexp 'backward))
7936
7937 (eval-when-compile
7938   (defmacro gnus-summary-search-article-position-point (regexp backward)
7939     "Dehighlight the last matched text and goto the beginning position."
7940     (` (if (and gnus-summary-search-article-matched-data
7941                 (let ((text (caddr gnus-summary-search-article-matched-data))
7942                       (inhibit-read-only t)
7943                       buffer-read-only)
7944                   (delete-region
7945                    (goto-char (car gnus-summary-search-article-matched-data))
7946                    (cadr gnus-summary-search-article-matched-data))
7947                   (insert text)
7948                   (string-match (, regexp) text)))
7949            (if (, backward) (beginning-of-line) (end-of-line))
7950          (goto-char (if (, backward) (point-max) (point-min))))))
7951
7952   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7953     "Place point where X-Face image is displayed."
7954     (if (featurep 'xemacs)
7955         (` (let ((end (if (search-forward "\n\n" nil t)
7956                           (goto-char (1- (point)))
7957                         (point-min)))
7958                  extent)
7959              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7960              (unless (and (re-search-forward "^From:" end t)
7961                           (setq extent (extent-at (point)))
7962                           (extent-begin-glyph extent))
7963                (goto-char (, opoint)))))
7964       (` (let ((end (if (search-forward "\n\n" nil t)
7965                         (goto-char (1- (point)))
7966                       (point-min)))
7967                (start (or (search-backward "\n\n" nil t) (point-min))))
7968            (goto-char
7969             (or (text-property-any start end 'x-face-image t);; x-face-e21
7970                 (text-property-any start end 'x-face-mule-bitmap-image t)
7971                 (, opoint)))))))
7972
7973   (defmacro gnus-summary-search-article-highlight-matched-text
7974     (backward treated x-face)
7975     "Highlight matched text in the function `gnus-summary-search-article'."
7976     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
7977              (end (set-marker (make-marker) (match-end 0)))
7978              (inhibit-read-only t)
7979              buffer-read-only)
7980          (unless treated
7981            (let ((,@
7982                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
7983                     (mapcar
7984                      (lambda (item) (setq items (delq item items)))
7985                      '(gnus-treat-buttonize
7986                        gnus-treat-fill-article
7987                        gnus-treat-fill-long-lines
7988                        gnus-treat-emphasize
7989                        gnus-treat-highlight-headers
7990                        gnus-treat-highlight-citation
7991                        gnus-treat-highlight-signature
7992                        gnus-treat-overstrike
7993                        gnus-treat-display-xface
7994                        gnus-treat-buttonize-head
7995                        gnus-treat-decode-article-as-default-mime-charset))
7996                     (static-if (featurep 'xemacs)
7997                         items
7998                       (cons '(x-face-mule-delete-x-face-field
7999                               (quote never))
8000                             items))))
8001                  (gnus-treat-display-xface
8002                   (when (, x-face) gnus-treat-display-xface)))
8003              (gnus-article-prepare-mime-display)))
8004          (goto-char (if (, backward) start end))
8005          (when (, x-face)
8006            (gnus-summary-search-article-highlight-goto-x-face (point)))
8007          (setq gnus-summary-search-article-matched-data
8008                (list start end (buffer-substring start end)))
8009          (unless (eq start end);; matched text has been deleted. :-<
8010            (put-text-property start end 'face
8011                               (or (find-face 'isearch)
8012                                   'secondary-selection))))))
8013   )
8014
8015 (defun gnus-summary-search-article (regexp &optional backward)
8016   "Search for an article containing REGEXP.
8017 Optional argument BACKWARD means do search for backward.
8018 `gnus-select-article-hook' is not called during the search."
8019   ;; We have to require this here to make sure that the following
8020   ;; dynamic binding isn't shadowed by autoloading.
8021   (require 'gnus-async)
8022   (require 'gnus-art)
8023   (let ((gnus-select-article-hook nil)  ;Disable hook.
8024         (gnus-article-prepare-hook nil)
8025         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8026         (gnus-use-article-prefetch nil)
8027         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8028         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8029         (sum (current-buffer))
8030         (found nil)
8031         point treated)
8032     (gnus-save-hidden-threads
8033       (static-if (featurep 'xemacs)
8034           (let ((gnus-inhibit-treatment t))
8035             (setq treated (eq 'old (gnus-summary-select-article)))
8036             (when (and treated
8037                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8038                                  (window-live-p (get-buffer-window
8039                                                  gnus-article-buffer t)))))
8040               (gnus-summary-select-article nil t)
8041               (setq treated nil)))
8042         (let ((gnus-inhibit-treatment t)
8043               (x-face-mule-delete-x-face-field 'never))
8044           (setq treated (eq 'old (gnus-summary-select-article)))
8045           (when (and treated
8046                      (not
8047                       (and (gnus-buffer-live-p gnus-article-buffer)
8048                            (window-live-p (get-buffer-window
8049                                            gnus-article-buffer t))
8050                            (or (not (string-match "^\\^X-Face:" regexp))
8051                                (with-current-buffer gnus-article-buffer
8052                                  gnus-summary-search-article-matched-data)))))
8053             (gnus-summary-select-article nil t)
8054             (setq treated nil))))
8055       (set-buffer gnus-article-buffer)
8056       (widen)
8057       (if treated
8058           (progn
8059             (gnus-article-show-all-headers)
8060             (gnus-summary-search-article-position-point regexp backward))
8061         (goto-char (if backward (point-max) (point-min))))
8062       (while (not found)
8063         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8064         (if (if backward
8065                 (re-search-backward regexp nil t)
8066               (re-search-forward regexp nil t))
8067             ;; We found the regexp.
8068             (progn
8069               (gnus-summary-search-article-highlight-matched-text
8070                backward treated (string-match "^\\^X-Face:" regexp))
8071               (setq found 'found)
8072               (forward-line
8073                (/ (- 2 (window-height
8074                         (get-buffer-window gnus-article-buffer t)))
8075                   2))
8076               (set-window-start
8077                (get-buffer-window (current-buffer))
8078                (point))
8079               (set-buffer sum)
8080               (setq point (point)))
8081           ;; We didn't find it, so we go to the next article.
8082           (set-buffer sum)
8083           (setq found 'not)
8084           (while (eq found 'not)
8085             (if (not (if backward (gnus-summary-find-prev)
8086                        (gnus-summary-find-next)))
8087                 ;; No more articles.
8088                 (setq found t)
8089               ;; Select the next article and adjust point.
8090               (unless (gnus-summary-article-sparse-p
8091                        (gnus-summary-article-number))
8092                 (setq found nil)
8093                 (let ((gnus-inhibit-treatment t))
8094                   (gnus-summary-select-article))
8095                 (setq treated nil)
8096                 (set-buffer gnus-article-buffer)
8097                 (widen)
8098                 (goto-char (if backward (point-max) (point-min))))))))
8099       (gnus-message 7 ""))
8100     ;; Return whether we found the regexp.
8101     (when (eq found 'found)
8102       (goto-char point)
8103       (gnus-summary-show-thread)
8104       (gnus-summary-goto-subject gnus-current-article)
8105       (gnus-summary-position-point)
8106       t)))
8107
8108 (defun gnus-find-matching-articles (header regexp)
8109   "Return a list of all articles that match REGEXP on HEADER.
8110 This search includes all articles in the current group that Gnus has
8111 fetched headers for, whether they are displayed or not."
8112   (let ((articles nil)
8113         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8114         (case-fold-search t))
8115     (dolist (header gnus-newsgroup-headers)
8116       (when (string-match regexp (funcall func header))
8117         (push (mail-header-number header) articles)))
8118     (nreverse articles)))
8119
8120 (defun gnus-summary-find-matching (header regexp &optional backward unread
8121                                           not-case-fold not-matching)
8122   "Return a list of all articles that match REGEXP on HEADER.
8123 The search stars on the current article and goes forwards unless
8124 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8125 If UNREAD is non-nil, only unread articles will
8126 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8127 in the comparisons. If NOT-MATCHING, return a list of all articles that
8128 not match REGEXP on HEADER."
8129   (let ((case-fold-search (not not-case-fold))
8130         articles d func)
8131     (if (consp header)
8132         (if (eq (car header) 'extra)
8133             (setq func
8134                   `(lambda (h)
8135                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8136                          "")))
8137           (error "%s is an invalid header" header))
8138       (unless (fboundp (intern (concat "mail-header-" header)))
8139         (error "%s is not a valid header" header))
8140       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8141     (dolist (d (if (eq backward 'all)
8142                    gnus-newsgroup-data
8143                  (gnus-data-find-list
8144                   (gnus-summary-article-number)
8145                   (gnus-data-list backward))))
8146       (when (and (or (not unread)       ; We want all articles...
8147                      (gnus-data-unread-p d)) ; Or just unreads.
8148                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8149                  (if not-matching
8150                      (not (string-match
8151                            regexp
8152                            (funcall func (gnus-data-header d))))
8153                    (string-match regexp
8154                                  (funcall func (gnus-data-header d)))))
8155         (push (gnus-data-number d) articles))) ; Success!
8156     (nreverse articles)))
8157
8158 (defun gnus-summary-execute-command (header regexp command &optional backward)
8159   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8160 If HEADER is an empty string (or nil), the match is done on the entire
8161 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8162   (interactive
8163    (list (let ((completion-ignore-case t))
8164            (completing-read
8165             "Header name: "
8166             (mapcar (lambda (header) (list (format "%s" header)))
8167                     (append
8168                      '("Number" "Subject" "From" "Lines" "Date"
8169                        "Message-ID" "Xref" "References" "Body")
8170                      gnus-extra-headers))
8171             nil 'require-match))
8172          (read-string "Regexp: ")
8173          (read-key-sequence "Command: ")
8174          current-prefix-arg))
8175   (when (equal header "Body")
8176     (setq header ""))
8177   ;; Hidden thread subtrees must be searched as well.
8178   (gnus-summary-show-all-threads)
8179   ;; We don't want to change current point nor window configuration.
8180   (save-excursion
8181     (save-window-excursion
8182       (gnus-message 6 "Executing %s..." (key-description command))
8183       ;; We'd like to execute COMMAND interactively so as to give arguments.
8184       (gnus-execute header regexp
8185                     `(call-interactively ',(key-binding command))
8186                     backward)
8187       (gnus-message 6 "Executing %s...done" (key-description command)))))
8188
8189 (defun gnus-summary-beginning-of-article ()
8190   "Scroll the article back to the beginning."
8191   (interactive)
8192   (gnus-summary-select-article)
8193   (gnus-configure-windows 'article)
8194   (gnus-eval-in-buffer-window gnus-article-buffer
8195     (widen)
8196     (goto-char (point-min))
8197     (when gnus-page-broken
8198       (gnus-narrow-to-page))))
8199
8200 (defun gnus-summary-end-of-article ()
8201   "Scroll to the end of the article."
8202   (interactive)
8203   (gnus-summary-select-article)
8204   (gnus-configure-windows 'article)
8205   (gnus-eval-in-buffer-window gnus-article-buffer
8206     (widen)
8207     (goto-char (point-max))
8208     (recenter -3)
8209     (when gnus-page-broken
8210       (gnus-narrow-to-page))))
8211
8212 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8213   "Truncate to LEN and quote all \"(\"'s in STRING."
8214   (gnus-replace-in-string (if (and len (> (length string) len))
8215                               (substring string 0 len)
8216                             string)
8217                           "[()]" "\\\\\\&"))
8218
8219 (defun gnus-summary-print-article (&optional filename n)
8220   "Generate and print a PostScript image of the N next (mail) articles.
8221
8222 If N is negative, print the N previous articles.  If N is nil and articles
8223 have been marked with the process mark, print these instead.
8224
8225 If the optional first argument FILENAME is nil, send the image to the
8226 printer.  If FILENAME is a string, save the PostScript image in a file with
8227 that name.  If FILENAME is a number, prompt the user for the name of the file
8228 to save in."
8229   (interactive (list (ps-print-preprint current-prefix-arg)))
8230   (dolist (article (gnus-summary-work-articles n))
8231     (gnus-summary-select-article nil nil 'pseudo article)
8232     (gnus-eval-in-buffer-window gnus-article-buffer
8233       (gnus-print-buffer))
8234     (gnus-summary-remove-process-mark article))
8235   (ps-despool filename))
8236
8237 (defun gnus-print-buffer ()
8238   (let ((buffer (generate-new-buffer " *print*")))
8239     (unwind-protect
8240         (progn
8241           (copy-to-buffer buffer (point-min) (point-max))
8242           (set-buffer buffer)
8243           (gnus-article-delete-invisible-text)
8244           (when (gnus-visual-p 'article-highlight 'highlight)
8245             ;; Copy-to-buffer doesn't copy overlay.  So redo
8246             ;; highlight.
8247             (let ((gnus-article-buffer buffer))
8248               (gnus-article-highlight-citation t)
8249               (gnus-article-highlight-signature)))
8250           (let ((ps-left-header
8251                  (list
8252                   (concat "("
8253                           (gnus-summary-print-truncate-and-quote
8254                            (mail-header-subject gnus-current-headers)
8255                            66) ")")
8256                   (concat "("
8257                           (gnus-summary-print-truncate-and-quote
8258                            (mail-header-from gnus-current-headers)
8259                            45) ")")))
8260                 (ps-right-header
8261                  (list
8262                   "/pagenumberstring load"
8263                   (concat "("
8264                           (mail-header-date gnus-current-headers) ")"))))
8265             (gnus-run-hooks 'gnus-ps-print-hook)
8266             (save-excursion
8267               (if window-system
8268                   (ps-spool-buffer-with-faces)
8269                 (ps-spool-buffer)))))
8270       (kill-buffer buffer))))
8271
8272 (defun gnus-summary-show-article (&optional arg)
8273   "Force redisplaying of the current article.
8274 If ARG (the prefix) is a number, show the article with the charset
8275 defined in `gnus-summary-show-article-charset-alist', or the charset
8276 input.
8277 If ARG (the prefix) is non-nil and not a number, show the raw article
8278 without any article massaging functions being run.  Normally, the key strokes
8279 are `C-u g'."
8280   (interactive "P")
8281   (cond
8282    ((numberp arg)
8283     (gnus-summary-show-article t)
8284     (let* ((gnus-newsgroup-charset
8285             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8286                 (mm-read-coding-system
8287                  "View as charset: " ;; actually it is coding system.
8288                  (save-excursion
8289                    (set-buffer gnus-article-buffer)
8290                    (mm-detect-coding-region (point) (point-max))))))
8291            (default-mime-charset gnus-newsgroup-charset)
8292            (gnus-newsgroup-ignored-charsets 'gnus-all))
8293       (gnus-summary-select-article nil 'force)
8294       (let ((deps gnus-newsgroup-dependencies)
8295             head header lines)
8296         (save-excursion
8297           (set-buffer gnus-original-article-buffer)
8298           (save-restriction
8299             (message-narrow-to-head)
8300             (setq head (buffer-string))
8301             (goto-char (point-min))
8302             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8303               (goto-char (point-max))
8304               (widen)
8305               (setq lines (1- (count-lines (point) (point-max))))))
8306           (with-temp-buffer
8307             (insert (format "211 %d Article retrieved.\n"
8308                             (cdr gnus-article-current)))
8309             (insert head)
8310             (if lines (insert (format "Lines: %d\n" lines)))
8311             (insert ".\n")
8312             (let ((nntp-server-buffer (current-buffer)))
8313               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8314         (gnus-data-set-header
8315          (gnus-data-find (cdr gnus-article-current))
8316          header)
8317         (gnus-summary-update-article-line
8318          (cdr gnus-article-current) header)
8319         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8320           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8321    ((not arg)
8322     ;; Select the article the normal way.
8323     (gnus-summary-select-article nil 'force))
8324    (t
8325     ;; We have to require this here to make sure that the following
8326     ;; dynamic binding isn't shadowed by autoloading.
8327     (require 'gnus-async)
8328     (require 'gnus-art)
8329     ;; Bind the article treatment functions to nil.
8330     (let ((gnus-have-all-headers t)
8331           gnus-article-prepare-hook
8332           gnus-article-decode-hook
8333           gnus-break-pages
8334           gnus-show-mime
8335           (gnus-inhibit-treatment t))
8336       (gnus-summary-select-article nil 'force))))
8337   (gnus-summary-goto-subject gnus-current-article)
8338   (gnus-summary-position-point))
8339
8340 (defun gnus-summary-show-raw-article ()
8341   "Show the raw article without any article massaging functions being run."
8342   (interactive)
8343   (gnus-summary-show-article t))
8344
8345 (defun gnus-summary-verbose-headers (&optional arg)
8346   "Toggle permanent full header display.
8347 If ARG is a positive number, turn header display on.
8348 If ARG is a negative number, turn header display off."
8349   (interactive "P")
8350   (setq gnus-show-all-headers
8351         (cond ((or (not (numberp arg))
8352                    (zerop arg))
8353                (not gnus-show-all-headers))
8354               ((natnump arg)
8355                t)))
8356   (gnus-summary-show-article))
8357
8358 (defun gnus-summary-toggle-header (&optional arg)
8359   "Show the headers if they are hidden, or hide them if they are shown.
8360 If ARG is a positive number, show the entire header.
8361 If ARG is a negative number, hide the unwanted header lines."
8362   (interactive "P")
8363   (save-excursion
8364     (set-buffer gnus-article-buffer)
8365     (save-restriction
8366       (let* ((buffer-read-only nil)
8367              (inhibit-point-motion-hooks t)
8368              hidden e)
8369         (save-restriction
8370           (article-narrow-to-head)
8371           (setq e (point-max)
8372                 hidden (if (numberp arg)
8373                            (>= arg 0)
8374                          (gnus-article-hidden-text-p 'headers))))
8375         (delete-region (point-min) e)
8376         (goto-char (point-min))
8377         (save-excursion
8378           (set-buffer gnus-original-article-buffer)
8379           (goto-char (point-min))
8380           (setq e (search-forward "\n\n" nil t)
8381                 e (if e (1- e) (point-max))))
8382         (insert-buffer-substring gnus-original-article-buffer 1 e)
8383         (save-restriction
8384           (narrow-to-region (point-min) (point))
8385           (article-decode-encoded-words)
8386           (if  hidden
8387               (let ((gnus-treat-hide-headers nil)
8388                     (gnus-treat-hide-boring-headers nil))
8389                 (gnus-delete-wash-type 'headers)
8390                 (gnus-treat-article 'head))
8391             (gnus-treat-article 'head)))
8392         (gnus-set-mode-line 'article)))))
8393
8394 (defun gnus-summary-show-all-headers ()
8395   "Make all header lines visible."
8396   (interactive)
8397   (gnus-summary-toggle-header 1))
8398
8399 (defun gnus-summary-toggle-mime (&optional arg)
8400   "Toggle MIME processing.
8401 If ARG is a positive number, turn MIME processing on."
8402   (interactive "P")
8403   (setq gnus-show-mime
8404         (if (null arg)
8405             (not gnus-show-mime)
8406           (> (prefix-numeric-value arg) 0)))
8407   (gnus-summary-select-article t 'force))
8408
8409 (defun gnus-summary-caesar-message (&optional arg)
8410   "Caesar rotate the current article by 13.
8411 The numerical prefix specifies how many places to rotate each letter
8412 forward."
8413   (interactive "P")
8414   (gnus-summary-select-article)
8415   (let ((mail-header-separator ""))
8416     (gnus-eval-in-buffer-window gnus-article-buffer
8417       (save-restriction
8418         (widen)
8419         (let ((start (window-start))
8420               buffer-read-only)
8421           (message-caesar-buffer-body arg)
8422           (set-window-start (get-buffer-window (current-buffer)) start))))))
8423
8424 (defun gnus-summary-stop-page-breaking ()
8425   "Stop page breaking in the current article."
8426   (interactive)
8427   (gnus-summary-select-article)
8428   (gnus-eval-in-buffer-window gnus-article-buffer
8429     (widen)
8430     (when (gnus-visual-p 'page-marker)
8431       (let ((buffer-read-only nil))
8432         (gnus-remove-text-with-property 'gnus-prev)
8433         (gnus-remove-text-with-property 'gnus-next))
8434       (setq gnus-page-broken nil))))
8435
8436 (defun gnus-summary-move-article (&optional n to-newsgroup
8437                                             select-method action)
8438   "Move the current article to a different newsgroup.
8439 If N is a positive number, move the N next articles.
8440 If N is a negative number, move the N previous articles.
8441 If N is nil and any articles have been marked with the process mark,
8442 move those articles instead.
8443 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8444 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8445 re-spool using this method.
8446
8447 For this function to work, both the current newsgroup and the
8448 newsgroup that you want to move to have to support the `request-move'
8449 and `request-accept' functions.
8450
8451 ACTION can be either `move' (the default), `crosspost' or `copy'."
8452   (interactive "P")
8453   (unless action
8454     (setq action 'move))
8455   ;; Check whether the source group supports the required functions.
8456   (cond ((and (eq action 'move)
8457               (not (gnus-check-backend-function
8458                     'request-move-article gnus-newsgroup-name)))
8459          (error "The current group does not support article moving"))
8460         ((and (eq action 'crosspost)
8461               (not (gnus-check-backend-function
8462                     'request-replace-article gnus-newsgroup-name)))
8463          (error "The current group does not support article editing")))
8464   (let ((articles (gnus-summary-work-articles n))
8465         (prefix (if (gnus-check-backend-function
8466                      'request-move-article gnus-newsgroup-name)
8467                     (gnus-group-real-prefix gnus-newsgroup-name)
8468                   ""))
8469         (names '((move "Move" "Moving")
8470                  (copy "Copy" "Copying")
8471                  (crosspost "Crosspost" "Crossposting")))
8472         (copy-buf (save-excursion
8473                     (nnheader-set-temp-buffer " *copy article*")))
8474         (default-marks gnus-article-mark-lists)
8475         (no-expire-marks (delete '(expirable . expire)
8476                                  (copy-sequence gnus-article-mark-lists)))
8477         art-group to-method new-xref article to-groups)
8478     (unless (assq action names)
8479       (error "Unknown action %s" action))
8480     ;; Read the newsgroup name.
8481     (when (and (not to-newsgroup)
8482                (not select-method))
8483       (if (and gnus-move-split-methods
8484                (not
8485                 (and (memq gnus-current-article articles)
8486                      (gnus-buffer-live-p gnus-original-article-buffer))))
8487           ;; When `gnus-move-split-methods' is non-nil, we have to
8488           ;; select an article to give `gnus-read-move-group-name' an
8489           ;; opportunity to suggest an appropriate default.  However,
8490           ;; we needn't render or mark the article.
8491           (let ((gnus-display-mime-function nil)
8492                 (gnus-article-prepare-hook nil)
8493                 (gnus-mark-article-hook nil))
8494             (gnus-summary-select-article nil nil nil (car articles))))
8495       (setq to-newsgroup
8496             (gnus-read-move-group-name
8497              (cadr (assq action names))
8498              (symbol-value (intern (format "gnus-current-%s-group" action)))
8499              articles prefix))
8500       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8501     (setq to-method (or select-method
8502                         (gnus-server-to-method
8503                          (gnus-group-method to-newsgroup))))
8504     ;; Check the method we are to move this article to...
8505     (unless (gnus-check-backend-function
8506              'request-accept-article (car to-method))
8507       (error "%s does not support article copying" (car to-method)))
8508     (unless (gnus-check-server to-method)
8509       (error "Can't open server %s" (car to-method)))
8510     (gnus-message 6 "%s to %s: %s..."
8511                   (caddr (assq action names))
8512                   (or (car select-method) to-newsgroup) articles)
8513     (while articles
8514       (setq article (pop articles))
8515       (setq
8516        art-group
8517        (cond
8518         ;; Move the article.
8519         ((eq action 'move)
8520          ;; Remove this article from future suppression.
8521          (gnus-dup-unsuppress-article article)
8522          (gnus-request-move-article
8523           article                       ; Article to move
8524           gnus-newsgroup-name           ; From newsgroup
8525           (nth 1 (gnus-find-method-for-group
8526                   gnus-newsgroup-name)) ; Server
8527           (list 'gnus-request-accept-article
8528                 to-newsgroup (list 'quote select-method)
8529                 (not articles) t)       ; Accept form
8530           (not articles)))              ; Only save nov last time
8531         ;; Copy the article.
8532         ((eq action 'copy)
8533          (save-excursion
8534            (set-buffer copy-buf)
8535            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8536              (gnus-request-accept-article
8537               to-newsgroup select-method (not articles) t))))
8538         ;; Crosspost the article.
8539         ((eq action 'crosspost)
8540          (let ((xref (message-tokenize-header
8541                       (mail-header-xref (gnus-summary-article-header article))
8542                       " ")))
8543            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8544                                   ":" (number-to-string article)))
8545            (unless xref
8546              (setq xref (list (system-name))))
8547            (setq new-xref
8548                  (concat
8549                   (mapconcat 'identity
8550                              (delete "Xref:" (delete new-xref xref))
8551                              " ")
8552                   " " new-xref))
8553            (save-excursion
8554              (set-buffer copy-buf)
8555              ;; First put the article in the destination group.
8556              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8557              (when (consp (setq art-group
8558                                 (gnus-request-accept-article
8559                                  to-newsgroup select-method (not articles))))
8560                (setq new-xref (concat new-xref " " (car art-group)
8561                                       ":"
8562                                       (number-to-string (cdr art-group))))
8563                ;; Now we have the new Xrefs header, so we insert
8564                ;; it and replace the new article.
8565                (nnheader-replace-header "Xref" new-xref)
8566                (gnus-request-replace-article
8567                 (cdr art-group) to-newsgroup (current-buffer))
8568                art-group))))))
8569       (cond
8570        ((not art-group)
8571         (gnus-message 1 "Couldn't %s article %s: %s"
8572                       (cadr (assq action names)) article
8573                       (nnheader-get-report (car to-method))))
8574        ((eq art-group 'junk)
8575         (when (eq action 'move)
8576           (gnus-summary-mark-article article gnus-canceled-mark)
8577           (gnus-message 4 "Deleted article %s" article)))
8578        (t
8579         (let* ((pto-group (gnus-group-prefixed-name
8580                            (car art-group) to-method))
8581                (entry
8582                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8583                (info (nth 2 entry))
8584                (to-group (gnus-info-group info))
8585                to-marks)
8586           ;; Update the group that has been moved to.
8587           (when (and info
8588                      (memq action '(move copy)))
8589             (unless (member to-group to-groups)
8590               (push to-group to-groups))
8591
8592             (unless (memq article gnus-newsgroup-unreads)
8593               (push 'read to-marks)
8594               (gnus-info-set-read
8595                info (gnus-add-to-range (gnus-info-read info)
8596                                        (list (cdr art-group)))))
8597
8598             ;; See whether the article is to be put in the cache.
8599             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8600                              default-marks
8601                            no-expire-marks))
8602                   (to-article (cdr art-group)))
8603
8604               ;; Enter the article into the cache in the new group,
8605               ;; if that is required.
8606               (when gnus-use-cache
8607                 (gnus-cache-possibly-enter-article
8608                  to-group to-article
8609                  (let ((header (copy-sequence
8610                                 (gnus-summary-article-header article))))
8611                    (mail-header-set-number header to-article)
8612                    header)
8613                  (memq article gnus-newsgroup-marked)
8614                  (memq article gnus-newsgroup-dormant)
8615                  (memq article gnus-newsgroup-unreads)))
8616
8617               (when gnus-preserve-marks
8618                 ;; Copy any marks over to the new group.
8619                 (when (and (equal to-group gnus-newsgroup-name)
8620                            (not (memq article gnus-newsgroup-unreads)))
8621                   ;; Mark this article as read in this group.
8622                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8623                   (setcdr (gnus-active to-group) to-article)
8624                   (setcdr gnus-newsgroup-active to-article))
8625
8626                 (while marks
8627                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8628                     (when (memq article (symbol-value
8629                                          (intern (format "gnus-newsgroup-%s"
8630                                                          (caar marks)))))
8631                       (push (cdar marks) to-marks)
8632                       ;; If the other group is the same as this group,
8633                       ;; then we have to add the mark to the list.
8634                       (when (equal to-group gnus-newsgroup-name)
8635                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8636                              (cons to-article
8637                                    (symbol-value
8638                                     (intern (format "gnus-newsgroup-%s"
8639                                                     (caar marks)))))))
8640                       ;; Copy the marks to other group.
8641                       (gnus-add-marked-articles
8642                        to-group (cdar marks) (list to-article) info)))
8643                   (setq marks (cdr marks)))
8644
8645                 (gnus-request-set-mark to-group (list (list (list to-article)
8646                                                             'add
8647                                                             to-marks))))
8648
8649               (gnus-dribble-enter
8650                (concat "(gnus-group-set-info '"
8651                        (gnus-prin1-to-string (gnus-get-info to-group))
8652                        ")"))))
8653
8654           ;; Update the Xref header in this article to point to
8655           ;; the new crossposted article we have just created.
8656           (when (eq action 'crosspost)
8657             (save-excursion
8658               (set-buffer copy-buf)
8659               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8660               (nnheader-replace-header "Xref" new-xref)
8661               (gnus-request-replace-article
8662                article gnus-newsgroup-name (current-buffer)))))
8663
8664         ;;;!!!Why is this necessary?
8665         (set-buffer gnus-summary-buffer)
8666
8667         (gnus-summary-goto-subject article)
8668         (when (eq action 'move)
8669           (gnus-summary-mark-article article gnus-canceled-mark))))
8670       (gnus-summary-remove-process-mark article))
8671     ;; Re-activate all groups that have been moved to.
8672     (save-excursion
8673       (set-buffer gnus-group-buffer)
8674       (let ((gnus-group-marked to-groups))
8675         (gnus-group-get-new-news-this-group nil t)))
8676
8677     (gnus-kill-buffer copy-buf)
8678     (gnus-summary-position-point)
8679     (gnus-set-mode-line 'summary)))
8680
8681 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8682   "Move the current article to a different newsgroup.
8683 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8684 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8685 re-spool using this method."
8686   (interactive "P")
8687   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8688
8689 (defun gnus-summary-crosspost-article (&optional n)
8690   "Crosspost the current article to some other group."
8691   (interactive "P")
8692   (gnus-summary-move-article n nil nil 'crosspost))
8693
8694 (defcustom gnus-summary-respool-default-method nil
8695   "Default method type for respooling an article.
8696 If nil, use to the current newsgroup method."
8697   :type 'symbol
8698   :group 'gnus-summary-mail)
8699
8700 (defun gnus-summary-respool-article (&optional n method)
8701   "Respool the current article.
8702 The article will be squeezed through the mail spooling process again,
8703 which means that it will be put in some mail newsgroup or other
8704 depending on `nnmail-split-methods'.
8705 If N is a positive number, respool the N next articles.
8706 If N is a negative number, respool the N previous articles.
8707 If N is nil and any articles have been marked with the process mark,
8708 respool those articles instead.
8709
8710 Respooling can be done both from mail groups and \"real\" newsgroups.
8711 In the former case, the articles in question will be moved from the
8712 current group into whatever groups they are destined to.  In the
8713 latter case, they will be copied into the relevant groups."
8714   (interactive
8715    (list current-prefix-arg
8716          (let* ((methods (gnus-methods-using 'respool))
8717                 (methname
8718                  (symbol-name (or gnus-summary-respool-default-method
8719                                   (car (gnus-find-method-for-group
8720                                         gnus-newsgroup-name)))))
8721                 (method
8722                  (gnus-completing-read-with-default
8723                   methname "What backend do you want to use when respooling?"
8724                   methods nil t nil 'gnus-mail-method-history))
8725                 ms)
8726            (cond
8727             ((zerop (length (setq ms (gnus-servers-using-backend
8728                                       (intern method)))))
8729              (list (intern method) ""))
8730             ((= 1 (length ms))
8731              (car ms))
8732             (t
8733              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8734                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8735                            ms-alist))))))))
8736   (unless method
8737     (error "No method given for respooling"))
8738   (if (assoc (symbol-name
8739               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8740              (gnus-methods-using 'respool))
8741       (gnus-summary-move-article n nil method)
8742     (gnus-summary-copy-article n nil method)))
8743
8744 (defun gnus-summary-import-article (file &optional edit)
8745   "Import an arbitrary file into a mail newsgroup."
8746   (interactive "fImport file: \nP")
8747   (let ((group gnus-newsgroup-name)
8748         (now (current-time))
8749         atts lines group-art)
8750     (unless (gnus-check-backend-function 'request-accept-article group)
8751       (error "%s does not support article importing" group))
8752     (or (file-readable-p file)
8753         (not (file-regular-p file))
8754         (error "Can't read %s" file))
8755     (save-excursion
8756       (set-buffer (gnus-get-buffer-create " *import file*"))
8757       (erase-buffer)
8758       (nnheader-insert-file-contents file)
8759       (goto-char (point-min))
8760       (if (nnheader-article-p)
8761           (save-restriction
8762             (goto-char (point-min))
8763             (search-forward "\n\n" nil t)
8764             (narrow-to-region (point-min) (1- (point)))
8765             (goto-char (point-min))
8766             (unless (re-search-forward "^date:" nil t)
8767               (goto-char (point-max))
8768               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8769         ;; This doesn't look like an article, so we fudge some headers.
8770         (setq atts (file-attributes file)
8771               lines (count-lines (point-min) (point-max)))
8772         (insert "From: " (read-string "From: ") "\n"
8773                 "Subject: " (read-string "Subject: ") "\n"
8774                 "Date: " (message-make-date (nth 5 atts)) "\n"
8775                 "Message-ID: " (message-make-message-id) "\n"
8776                 "Lines: " (int-to-string lines) "\n"
8777                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8778       (setq group-art (gnus-request-accept-article group nil t))
8779       (kill-buffer (current-buffer)))
8780     (setq gnus-newsgroup-active (gnus-activate-group group))
8781     (forward-line 1)
8782     (gnus-summary-goto-article (cdr group-art) nil t)
8783     (when edit
8784       (gnus-summary-edit-article))))
8785
8786 (defun gnus-summary-create-article ()
8787   "Create an article in a mail newsgroup."
8788   (interactive)
8789   (let ((group gnus-newsgroup-name)
8790         (now (current-time))
8791         group-art)
8792     (unless (gnus-check-backend-function 'request-accept-article group)
8793       (error "%s does not support article importing" group))
8794     (save-excursion
8795       (set-buffer (gnus-get-buffer-create " *import file*"))
8796       (erase-buffer)
8797       (goto-char (point-min))
8798       ;; This doesn't look like an article, so we fudge some headers.
8799       (insert "From: " (read-string "From: ") "\n"
8800               "Subject: " (read-string "Subject: ") "\n"
8801               "Date: " (message-make-date now) "\n"
8802               "Message-ID: " (message-make-message-id) "\n")
8803       (setq group-art (gnus-request-accept-article group nil t))
8804       (kill-buffer (current-buffer)))
8805     (setq gnus-newsgroup-active (gnus-activate-group group))
8806     (forward-line 1)
8807     (gnus-summary-goto-article (cdr group-art) nil t)
8808     (gnus-summary-edit-article)))
8809
8810 (defun gnus-summary-article-posted-p ()
8811   "Say whether the current (mail) article is available from news as well.
8812 This will be the case if the article has both been mailed and posted."
8813   (interactive)
8814   (let ((id (mail-header-references (gnus-summary-article-header)))
8815         (gnus-override-method (car (gnus-refer-article-methods))))
8816     (if (gnus-request-head id "")
8817         (gnus-message 2 "The current message was found on %s"
8818                       gnus-override-method)
8819       (gnus-message 2 "The current message couldn't be found on %s"
8820                     gnus-override-method)
8821       nil)))
8822
8823 (defun gnus-summary-expire-articles (&optional now)
8824   "Expire all articles that are marked as expirable in the current group."
8825   (interactive)
8826   (when (gnus-check-backend-function
8827          'request-expire-articles gnus-newsgroup-name)
8828     ;; This backend supports expiry.
8829     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8830            (expirable (if total
8831                           (progn
8832                             ;; We need to update the info for
8833                             ;; this group for `gnus-list-of-read-articles'
8834                             ;; to give us the right answer.
8835                             (gnus-run-hooks 'gnus-exit-group-hook)
8836                             (gnus-summary-update-info)
8837                             (gnus-list-of-read-articles gnus-newsgroup-name))
8838                         (setq gnus-newsgroup-expirable
8839                               (sort gnus-newsgroup-expirable '<))))
8840            (expiry-wait (if now 'immediate
8841                           (gnus-group-find-parameter
8842                            gnus-newsgroup-name 'expiry-wait)))
8843            (nnmail-expiry-target
8844             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8845                 nnmail-expiry-target))
8846            es)
8847       (when expirable
8848         ;; There are expirable articles in this group, so we run them
8849         ;; through the expiry process.
8850         (gnus-message 6 "Expiring articles...")
8851         (unless (gnus-check-group gnus-newsgroup-name)
8852           (error "Can't open server for %s" gnus-newsgroup-name))
8853         ;; The list of articles that weren't expired is returned.
8854         (save-excursion
8855           (if expiry-wait
8856               (let ((nnmail-expiry-wait-function nil)
8857                     (nnmail-expiry-wait expiry-wait))
8858                 (setq es (gnus-request-expire-articles
8859                           expirable gnus-newsgroup-name)))
8860             (setq es (gnus-request-expire-articles
8861                       expirable gnus-newsgroup-name)))
8862           (unless total
8863             (setq gnus-newsgroup-expirable es))
8864           ;; We go through the old list of expirable, and mark all
8865           ;; really expired articles as nonexistent.
8866           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8867             (let ((gnus-use-cache nil))
8868               (dolist (article expirable)
8869                 (when (and (not (memq article es))
8870                            (gnus-data-find article))
8871                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8872         (gnus-message 6 "Expiring articles...done")))))
8873
8874 (defun gnus-summary-expire-articles-now ()
8875   "Expunge all expirable articles in the current group.
8876 This means that *all* articles that are marked as expirable will be
8877 deleted forever, right now."
8878   (interactive)
8879   (or gnus-expert-user
8880       (gnus-yes-or-no-p
8881        "Are you really, really, really sure you want to delete all these messages? ")
8882       (error "Phew!"))
8883   (gnus-summary-expire-articles t))
8884
8885 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8886 (defun gnus-summary-delete-article (&optional n)
8887   "Delete the N next (mail) articles.
8888 This command actually deletes articles.  This is not a marking
8889 command.  The article will disappear forever from your life, never to
8890 return.
8891 If N is negative, delete backwards.
8892 If N is nil and articles have been marked with the process mark,
8893 delete these instead."
8894   (interactive "P")
8895   (unless (gnus-check-backend-function 'request-expire-articles
8896                                        gnus-newsgroup-name)
8897     (error "The current newsgroup does not support article deletion"))
8898   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8899     (error "Couldn't open server"))
8900   ;; Compute the list of articles to delete.
8901   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8902         not-deleted)
8903     (if (and gnus-novice-user
8904              (not (gnus-yes-or-no-p
8905                    (format "Do you really want to delete %s forever? "
8906                            (if (> (length articles) 1)
8907                                (format "these %s articles" (length articles))
8908                              "this article")))))
8909         ()
8910       ;; Delete the articles.
8911       (setq not-deleted (gnus-request-expire-articles
8912                          articles gnus-newsgroup-name 'force))
8913       (while articles
8914         (gnus-summary-remove-process-mark (car articles))
8915         ;; The backend might not have been able to delete the article
8916         ;; after all.
8917         (unless (memq (car articles) not-deleted)
8918           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8919         (setq articles (cdr articles)))
8920       (when not-deleted
8921         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8922     (gnus-summary-position-point)
8923     (gnus-set-mode-line 'summary)
8924     not-deleted))
8925
8926 (defun gnus-summary-edit-article (&optional force)
8927   "Edit the current article.
8928 This will have permanent effect only in mail groups.
8929 If FORCE is non-nil, allow editing of articles even in read-only
8930 groups."
8931   (interactive "P")
8932   (save-excursion
8933     (set-buffer gnus-summary-buffer)
8934     (let ((mail-parse-charset gnus-newsgroup-charset)
8935           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8936       (gnus-set-global-variables)
8937       (when (and (not force)
8938                  (gnus-group-read-only-p))
8939         (error "The current newsgroup does not support article editing"))
8940       (gnus-summary-show-article t)
8941       (gnus-article-edit-article
8942        'ignore
8943        `(lambda (no-highlight)
8944           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8945                 (message-options message-options)
8946                 (message-options-set-recipient)
8947                 (mail-parse-ignored-charsets
8948                  ',gnus-newsgroup-ignored-charsets))
8949             (gnus-summary-edit-article-done
8950              ,(or (mail-header-references gnus-current-headers) "")
8951              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8952
8953 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8954
8955 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8956                                                  no-highlight)
8957   "Make edits to the current article permanent."
8958   (interactive)
8959   (save-excursion
8960     ;; The buffer restriction contains the entire article if it exists.
8961     (when (article-goto-body)
8962       (let ((lines (count-lines (point) (point-max)))
8963             (length (- (point-max) (point)))
8964             (case-fold-search t)
8965             (body (copy-marker (point))))
8966         (goto-char (point-min))
8967         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8968           (delete-region (match-beginning 1) (match-end 1))
8969           (insert (number-to-string length)))
8970         (goto-char (point-min))
8971         (when (re-search-forward
8972                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8973           (delete-region (match-beginning 1) (match-end 1))
8974           (insert (number-to-string length)))
8975         (goto-char (point-min))
8976         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8977           (delete-region (match-beginning 1) (match-end 1))
8978           (insert (number-to-string lines))))))
8979   ;; Replace the article.
8980   (let ((buf (current-buffer)))
8981     (with-temp-buffer
8982       (insert-buffer-substring buf)
8983
8984       (if (and (not read-only)
8985                (not (gnus-request-replace-article
8986                      (cdr gnus-article-current) (car gnus-article-current)
8987                      (current-buffer) t)))
8988           (error "Couldn't replace article")
8989         ;; Update the summary buffer.
8990         (if (and references
8991                  (equal (message-tokenize-header references " ")
8992                         (message-tokenize-header
8993                          (or (message-fetch-field "references") "") " ")))
8994             ;; We only have to update this line.
8995             (save-excursion
8996               (save-restriction
8997                 (message-narrow-to-head)
8998                 (let ((head (buffer-string))
8999                       header)
9000                   (with-temp-buffer
9001                     (insert (format "211 %d Article retrieved.\n"
9002                                     (cdr gnus-article-current)))
9003                     (insert head)
9004                     (insert ".\n")
9005                     (let ((nntp-server-buffer (current-buffer)))
9006                       (setq header (car (gnus-get-newsgroup-headers
9007                                          nil t))))
9008                     (save-excursion
9009                       (set-buffer gnus-summary-buffer)
9010                       (gnus-data-set-header
9011                        (gnus-data-find (cdr gnus-article-current))
9012                        header)
9013                       (gnus-summary-update-article-line
9014                        (cdr gnus-article-current) header)
9015                       (if (gnus-summary-goto-subject
9016                            (cdr gnus-article-current) nil t)
9017                           (gnus-summary-update-secondary-mark
9018                            (cdr gnus-article-current))))))))
9019           ;; Update threads.
9020           (set-buffer (or buffer gnus-summary-buffer))
9021           (gnus-summary-update-article (cdr gnus-article-current))
9022           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9023               (gnus-summary-update-secondary-mark
9024                (cdr gnus-article-current))))
9025         ;; Prettify the article buffer again.
9026         (unless no-highlight
9027           (save-excursion
9028             (set-buffer gnus-article-buffer)
9029             ;;;!!! Fix this -- article should be rehighlighted.
9030             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9031             (set-buffer gnus-original-article-buffer)
9032             (gnus-request-article
9033              (cdr gnus-article-current)
9034              (car gnus-article-current) (current-buffer))))
9035         ;; Prettify the summary buffer line.
9036         (when (gnus-visual-p 'summary-highlight 'highlight)
9037           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9038
9039 (defun gnus-summary-edit-wash (key)
9040   "Perform editing command KEY in the article buffer."
9041   (interactive
9042    (list
9043     (progn
9044       (message "%s" (concat (this-command-keys) "- "))
9045       (read-char))))
9046   (message "")
9047   (gnus-summary-edit-article)
9048   (execute-kbd-macro (concat (this-command-keys) key))
9049   (gnus-article-edit-done))
9050
9051 ;;; Respooling
9052
9053 (defun gnus-summary-respool-query (&optional silent trace)
9054   "Query where the respool algorithm would put this article."
9055   (interactive)
9056   (let (gnus-mark-article-hook)
9057     (gnus-summary-select-article)
9058     (save-excursion
9059       (set-buffer gnus-original-article-buffer)
9060       (save-restriction
9061         (message-narrow-to-head)
9062         (let ((groups (nnmail-article-group 'identity trace)))
9063           (unless silent
9064             (if groups
9065                 (message "This message would go to %s"
9066                          (mapconcat 'car groups ", "))
9067               (message "This message would go to no groups"))
9068             groups))))))
9069
9070 (defun gnus-summary-respool-trace ()
9071   "Trace where the respool algorithm would put this article.
9072 Display a buffer showing all fancy splitting patterns which matched."
9073   (interactive)
9074   (gnus-summary-respool-query nil t))
9075
9076 ;; Summary marking commands.
9077
9078 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9079   "Mark articles which has the same subject as read, and then select the next.
9080 If UNMARK is positive, remove any kind of mark.
9081 If UNMARK is negative, tick articles."
9082   (interactive "P")
9083   (when unmark
9084     (setq unmark (prefix-numeric-value unmark)))
9085   (let ((count
9086          (gnus-summary-mark-same-subject
9087           (gnus-summary-article-subject) unmark)))
9088     ;; Select next unread article.  If auto-select-same mode, should
9089     ;; select the first unread article.
9090     (gnus-summary-next-article t (and gnus-auto-select-same
9091                                       (gnus-summary-article-subject)))
9092     (gnus-message 7 "%d article%s marked as %s"
9093                   count (if (= count 1) " is" "s are")
9094                   (if unmark "unread" "read"))))
9095
9096 (defun gnus-summary-kill-same-subject (&optional unmark)
9097   "Mark articles which has the same subject as read.
9098 If UNMARK is positive, remove any kind of mark.
9099 If UNMARK is negative, tick articles."
9100   (interactive "P")
9101   (when unmark
9102     (setq unmark (prefix-numeric-value unmark)))
9103   (let ((count
9104          (gnus-summary-mark-same-subject
9105           (gnus-summary-article-subject) unmark)))
9106     ;; If marked as read, go to next unread subject.
9107     (when (null unmark)
9108       ;; Go to next unread subject.
9109       (gnus-summary-next-subject 1 t))
9110     (gnus-message 7 "%d articles are marked as %s"
9111                   count (if unmark "unread" "read"))))
9112
9113 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9114   "Mark articles with same SUBJECT as read, and return marked number.
9115 If optional argument UNMARK is positive, remove any kinds of marks.
9116 If optional argument UNMARK is negative, mark articles as unread instead."
9117   (let ((count 1))
9118     (save-excursion
9119       (cond
9120        ((null unmark)                   ; Mark as read.
9121         (while (and
9122                 (progn
9123                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9124                   (gnus-summary-show-thread) t)
9125                 (gnus-summary-find-subject subject))
9126           (setq count (1+ count))))
9127        ((> unmark 0)                    ; Tick.
9128         (while (and
9129                 (progn
9130                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9131                   (gnus-summary-show-thread) t)
9132                 (gnus-summary-find-subject subject))
9133           (setq count (1+ count))))
9134        (t                               ; Mark as unread.
9135         (while (and
9136                 (progn
9137                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9138                   (gnus-summary-show-thread) t)
9139                 (gnus-summary-find-subject subject))
9140           (setq count (1+ count)))))
9141       (gnus-set-mode-line 'summary)
9142       ;; Return the number of marked articles.
9143       count)))
9144
9145 (defun gnus-summary-mark-as-processable (n &optional unmark)
9146   "Set the process mark on the next N articles.
9147 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9148 the process mark instead.  The difference between N and the actual
9149 number of articles marked is returned."
9150   (interactive "P")
9151   (if (and (null n) (gnus-region-active-p))
9152       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9153     (setq n (prefix-numeric-value n))
9154     (let ((backward (< n 0))
9155           (n (abs n)))
9156       (while (and
9157               (> n 0)
9158               (if unmark
9159                   (gnus-summary-remove-process-mark
9160                    (gnus-summary-article-number))
9161                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9162               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9163         (setq n (1- n)))
9164       (when (/= 0 n)
9165         (gnus-message 7 "No more articles"))
9166       (gnus-summary-recenter)
9167       (gnus-summary-position-point)
9168       n)))
9169
9170 (defun gnus-summary-unmark-as-processable (n)
9171   "Remove the process mark from the next N articles.
9172 If N is negative, unmark backward instead.  The difference between N and
9173 the actual number of articles unmarked is returned."
9174   (interactive "P")
9175   (gnus-summary-mark-as-processable n t))
9176
9177 (defun gnus-summary-unmark-all-processable ()
9178   "Remove the process mark from all articles."
9179   (interactive)
9180   (save-excursion
9181     (while gnus-newsgroup-processable
9182       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9183   (gnus-summary-position-point))
9184
9185 (defun gnus-summary-add-mark (article type)
9186   "Mark ARTICLE with a mark of TYPE."
9187   (let ((vtype (car (assq type gnus-article-mark-lists)))
9188         var)
9189     (if (not vtype)
9190         (error "No such mark type: %s" type)
9191       (setq var (intern (format "gnus-newsgroup-%s" type)))
9192       (set var (cons article (symbol-value var)))
9193       (if (memq type '(processable cached replied forwarded recent saved))
9194           (gnus-summary-update-secondary-mark article)
9195         ;;; !!! This is bogus.  We should find out what primary
9196         ;;; !!! mark we want to set.
9197         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9198
9199 (defun gnus-summary-mark-as-expirable (n)
9200   "Mark N articles forward as expirable.
9201 If N is negative, mark backward instead.  The difference between N and
9202 the actual number of articles marked is returned."
9203   (interactive "p")
9204   (gnus-summary-mark-forward n gnus-expirable-mark))
9205
9206 (defun gnus-summary-mark-article-as-replied (article)
9207   "Mark ARTICLE as replied to and update the summary line.
9208 ARTICLE can also be a list of articles."
9209   (interactive (list (gnus-summary-article-number)))
9210   (let ((articles (if (listp article) article (list article))))
9211     (dolist (article articles)
9212       (push article gnus-newsgroup-replied)
9213       (let ((buffer-read-only nil))
9214         (when (gnus-summary-goto-subject article nil t)
9215           (gnus-summary-update-secondary-mark article))))))
9216
9217 (defun gnus-summary-mark-article-as-forwarded (article)
9218   "Mark ARTICLE as forwarded and update the summary line.
9219 ARTICLE can also be a list of articles."
9220   (let ((articles (if (listp article) article (list article))))
9221     (dolist (article articles)
9222       (push article gnus-newsgroup-forwarded)
9223       (let ((buffer-read-only nil))
9224         (when (gnus-summary-goto-subject article nil t)
9225           (gnus-summary-update-secondary-mark article))))))
9226
9227 (defun gnus-summary-set-bookmark (article)
9228   "Set a bookmark in current article."
9229   (interactive (list (gnus-summary-article-number)))
9230   (when (or (not (get-buffer gnus-article-buffer))
9231             (not gnus-current-article)
9232             (not gnus-article-current)
9233             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9234     (error "No current article selected"))
9235   ;; Remove old bookmark, if one exists.
9236   (let ((old (assq article gnus-newsgroup-bookmarks)))
9237     (when old
9238       (setq gnus-newsgroup-bookmarks
9239             (delq old gnus-newsgroup-bookmarks))))
9240   ;; Set the new bookmark, which is on the form
9241   ;; (article-number . line-number-in-body).
9242   (push
9243    (cons article
9244          (save-excursion
9245            (set-buffer gnus-article-buffer)
9246            (count-lines
9247             (min (point)
9248                  (save-excursion
9249                    (goto-char (point-min))
9250                    (search-forward "\n\n" nil t)
9251                    (point)))
9252             (point))))
9253    gnus-newsgroup-bookmarks)
9254   (gnus-message 6 "A bookmark has been added to the current article."))
9255
9256 (defun gnus-summary-remove-bookmark (article)
9257   "Remove the bookmark from the current article."
9258   (interactive (list (gnus-summary-article-number)))
9259   ;; Remove old bookmark, if one exists.
9260   (let ((old (assq article gnus-newsgroup-bookmarks)))
9261     (if old
9262         (progn
9263           (setq gnus-newsgroup-bookmarks
9264                 (delq old gnus-newsgroup-bookmarks))
9265           (gnus-message 6 "Removed bookmark."))
9266       (gnus-message 6 "No bookmark in current article."))))
9267
9268 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9269 (defun gnus-summary-mark-as-dormant (n)
9270   "Mark N articles forward as dormant.
9271 If N is negative, mark backward instead.  The difference between N and
9272 the actual number of articles marked is returned."
9273   (interactive "p")
9274   (gnus-summary-mark-forward n gnus-dormant-mark))
9275
9276 (defun gnus-summary-set-process-mark (article)
9277   "Set the process mark on ARTICLE and update the summary line."
9278   (setq gnus-newsgroup-processable
9279         (cons article
9280               (delq article gnus-newsgroup-processable)))
9281   (when (gnus-summary-goto-subject article)
9282     (gnus-summary-show-thread)
9283     (gnus-summary-goto-subject article)
9284     (gnus-summary-update-secondary-mark article)))
9285
9286 (defun gnus-summary-remove-process-mark (article)
9287   "Remove the process mark from ARTICLE and update the summary line."
9288   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9289   (when (gnus-summary-goto-subject article)
9290     (gnus-summary-show-thread)
9291     (gnus-summary-goto-subject article)
9292     (gnus-summary-update-secondary-mark article)))
9293
9294 (defun gnus-summary-set-saved-mark (article)
9295   "Set the process mark on ARTICLE and update the summary line."
9296   (push article gnus-newsgroup-saved)
9297   (when (gnus-summary-goto-subject article)
9298     (gnus-summary-update-secondary-mark article)))
9299
9300 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9301   "Mark N articles as read forwards.
9302 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9303 The difference between N and the actual number of articles marked is
9304 returned.
9305 Iff NO-EXPIRE, auto-expiry will be inhibited."
9306   (interactive "p")
9307   (gnus-summary-show-thread)
9308   (let ((backward (< n 0))
9309         (gnus-summary-goto-unread
9310          (and gnus-summary-goto-unread
9311               (not (eq gnus-summary-goto-unread 'never))
9312               (not (memq mark (list gnus-unread-mark
9313                                     gnus-ticked-mark gnus-dormant-mark)))))
9314         (n (abs n))
9315         (mark (or mark gnus-del-mark)))
9316     (while (and (> n 0)
9317                 (gnus-summary-mark-article nil mark no-expire)
9318                 (zerop (gnus-summary-next-subject
9319                         (if backward -1 1)
9320                         (and gnus-summary-goto-unread
9321                              (not (eq gnus-summary-goto-unread 'never)))
9322                         t)))
9323       (setq n (1- n)))
9324     (when (/= 0 n)
9325       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9326     (gnus-summary-recenter)
9327     (gnus-summary-position-point)
9328     (gnus-set-mode-line 'summary)
9329     n))
9330
9331 (defun gnus-summary-mark-article-as-read (mark)
9332   "Mark the current article quickly as read with MARK."
9333   (let ((article (gnus-summary-article-number)))
9334     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9335     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9336     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9337     (push (cons article mark) gnus-newsgroup-reads)
9338     ;; Possibly remove from cache, if that is used.
9339     (when gnus-use-cache
9340       (gnus-cache-enter-remove-article article))
9341     ;; Allow the backend to change the mark.
9342     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9343     ;; Check for auto-expiry.
9344     (when (and gnus-newsgroup-auto-expire
9345                (memq mark gnus-auto-expirable-marks))
9346       (setq mark gnus-expirable-mark)
9347       ;; Let the backend know about the mark change.
9348       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9349       (push article gnus-newsgroup-expirable))
9350     ;; Set the mark in the buffer.
9351     (gnus-summary-update-mark mark 'unread)
9352     t))
9353
9354 (defun gnus-summary-mark-article-as-unread (mark)
9355   "Mark the current article quickly as unread with MARK."
9356   (let* ((article (gnus-summary-article-number))
9357          (old-mark (gnus-summary-article-mark article)))
9358     ;; Allow the backend to change the mark.
9359     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9360     (if (eq mark old-mark)
9361         t
9362       (if (<= article 0)
9363           (progn
9364             (gnus-error 1 "Can't mark negative article numbers")
9365             nil)
9366         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9367         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9368         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9369         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9370         (cond ((= mark gnus-ticked-mark)
9371                (setq gnus-newsgroup-marked
9372                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9373                                               article)))
9374               ((= mark gnus-dormant-mark)
9375                (setq gnus-newsgroup-dormant
9376                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9377                                               article)))
9378               (t
9379                (setq gnus-newsgroup-unreads
9380                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9381                                               article))))
9382         (gnus-pull article gnus-newsgroup-reads)
9383
9384         ;; See whether the article is to be put in the cache.
9385         (and gnus-use-cache
9386              (vectorp (gnus-summary-article-header article))
9387              (save-excursion
9388                (gnus-cache-possibly-enter-article
9389                 gnus-newsgroup-name article
9390                 (gnus-summary-article-header article)
9391                 (= mark gnus-ticked-mark)
9392                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9393
9394         ;; Fix the mark.
9395         (gnus-summary-update-mark mark 'unread)
9396         t))))
9397
9398 (defun gnus-summary-mark-article (&optional article mark no-expire)
9399   "Mark ARTICLE with MARK.  MARK can be any character.
9400 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9401 `??' (dormant) and `?E' (expirable).
9402 If MARK is nil, then the default character `?r' is used.
9403 If ARTICLE is nil, then the article on the current line will be
9404 marked.
9405 Iff NO-EXPIRE, auto-expiry will be inhibited."
9406   ;; The mark might be a string.
9407   (when (stringp mark)
9408     (setq mark (aref mark 0)))
9409   ;; If no mark is given, then we check auto-expiring.
9410   (when (null mark)
9411     (setq mark gnus-del-mark))
9412   (when (and (not no-expire)
9413              gnus-newsgroup-auto-expire
9414              (memq mark gnus-auto-expirable-marks))
9415     (setq mark gnus-expirable-mark))
9416   (let ((article (or article (gnus-summary-article-number)))
9417         (old-mark (gnus-summary-article-mark article)))
9418     ;; Allow the backend to change the mark.
9419     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9420     (if (eq mark old-mark)
9421         t
9422       (unless article
9423         (error "No article on current line"))
9424       (if (not (if (or (= mark gnus-unread-mark)
9425                        (= mark gnus-ticked-mark)
9426                        (= mark gnus-dormant-mark))
9427                    (gnus-mark-article-as-unread article mark)
9428                  (gnus-mark-article-as-read article mark)))
9429           t
9430         ;; See whether the article is to be put in the cache.
9431         (and gnus-use-cache
9432              (not (= mark gnus-canceled-mark))
9433              (vectorp (gnus-summary-article-header article))
9434              (save-excursion
9435                (gnus-cache-possibly-enter-article
9436                 gnus-newsgroup-name article
9437                 (gnus-summary-article-header article)
9438                 (= mark gnus-ticked-mark)
9439                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9440
9441         (when (gnus-summary-goto-subject article nil t)
9442           (let ((buffer-read-only nil))
9443             (gnus-summary-show-thread)
9444             ;; Fix the mark.
9445             (gnus-summary-update-mark mark 'unread)
9446             t))))))
9447
9448 (defun gnus-summary-update-secondary-mark (article)
9449   "Update the secondary (read, process, cache) mark."
9450   (gnus-summary-update-mark
9451    (cond ((memq article gnus-newsgroup-processable)
9452           gnus-process-mark)
9453          ((memq article gnus-newsgroup-cached)
9454           gnus-cached-mark)
9455          ((memq article gnus-newsgroup-replied)
9456           gnus-replied-mark)
9457          ((memq article gnus-newsgroup-forwarded)
9458           gnus-forwarded-mark)
9459          ((memq article gnus-newsgroup-saved)
9460           gnus-saved-mark)
9461          ((memq article gnus-newsgroup-recent)
9462           gnus-recent-mark)
9463          ((memq article gnus-newsgroup-unseen)
9464           gnus-unseen-mark)
9465          (t gnus-no-mark))
9466    'replied)
9467   (when (gnus-visual-p 'summary-highlight 'highlight)
9468     (gnus-run-hooks 'gnus-summary-update-hook))
9469   t)
9470
9471 (defun gnus-summary-update-mark (mark type)
9472   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9473         (buffer-read-only nil))
9474     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9475     (when forward
9476       (when (looking-at "\r")
9477         (incf forward))
9478       (when (<= (+ forward (point)) (point-max))
9479         ;; Go to the right position on the line.
9480         (goto-char (+ forward (point)))
9481         ;; Replace the old mark with the new mark.
9482         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9483         ;; Optionally update the marks by some user rule.
9484         (when (eq type 'unread)
9485           (gnus-data-set-mark
9486            (gnus-data-find (gnus-summary-article-number)) mark)
9487           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9488
9489 (defun gnus-mark-article-as-read (article &optional mark)
9490   "Enter ARTICLE in the pertinent lists and remove it from others."
9491   ;; Make the article expirable.
9492   (let ((mark (or mark gnus-del-mark)))
9493     (setq gnus-newsgroup-expirable
9494           (if (= mark gnus-expirable-mark)
9495               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9496             (delq article gnus-newsgroup-expirable)))
9497     ;; Remove from unread and marked lists.
9498     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9499     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9500     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9501     (push (cons article mark) gnus-newsgroup-reads)
9502     ;; Possibly remove from cache, if that is used.
9503     (when gnus-use-cache
9504       (gnus-cache-enter-remove-article article))
9505     t))
9506
9507 (defun gnus-mark-article-as-unread (article &optional mark)
9508   "Enter ARTICLE in the pertinent lists and remove it from others."
9509   (let ((mark (or mark gnus-ticked-mark)))
9510     (if (<= article 0)
9511         (progn
9512           (gnus-error 1 "Can't mark negative article numbers")
9513           nil)
9514       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9515             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9516             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9517             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9518
9519       ;; Unsuppress duplicates?
9520       (when gnus-suppress-duplicates
9521         (gnus-dup-unsuppress-article article))
9522
9523       (cond ((= mark gnus-ticked-mark)
9524              (setq gnus-newsgroup-marked
9525                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9526             ((= mark gnus-dormant-mark)
9527              (setq gnus-newsgroup-dormant
9528                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9529             (t
9530              (setq gnus-newsgroup-unreads
9531                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9532       (gnus-pull article gnus-newsgroup-reads)
9533       t)))
9534
9535 (defalias 'gnus-summary-mark-as-unread-forward
9536   'gnus-summary-tick-article-forward)
9537 (make-obsolete 'gnus-summary-mark-as-unread-forward
9538                'gnus-summary-tick-article-forward)
9539 (defun gnus-summary-tick-article-forward (n)
9540   "Tick N articles forwards.
9541 If N is negative, tick backwards instead.
9542 The difference between N and the number of articles ticked is returned."
9543   (interactive "p")
9544   (gnus-summary-mark-forward n gnus-ticked-mark))
9545
9546 (defalias 'gnus-summary-mark-as-unread-backward
9547   'gnus-summary-tick-article-backward)
9548 (make-obsolete 'gnus-summary-mark-as-unread-backward
9549                'gnus-summary-tick-article-backward)
9550 (defun gnus-summary-tick-article-backward (n)
9551   "Tick N articles backwards.
9552 The difference between N and the number of articles ticked is returned."
9553   (interactive "p")
9554   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9555
9556 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9557 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9558 (defun gnus-summary-tick-article (&optional article clear-mark)
9559   "Mark current article as unread.
9560 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9561 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9562   (interactive)
9563   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9564                                        gnus-ticked-mark)))
9565
9566 (defun gnus-summary-mark-as-read-forward (n)
9567   "Mark N articles as read forwards.
9568 If N is negative, mark backwards instead.
9569 The difference between N and the actual number of articles marked is
9570 returned."
9571   (interactive "p")
9572   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9573
9574 (defun gnus-summary-mark-as-read-backward (n)
9575   "Mark the N articles as read backwards.
9576 The difference between N and the actual number of articles marked is
9577 returned."
9578   (interactive "p")
9579   (gnus-summary-mark-forward
9580    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9581
9582 (defun gnus-summary-mark-as-read (&optional article mark)
9583   "Mark current article as read.
9584 ARTICLE specifies the article to be marked as read.
9585 MARK specifies a string to be inserted at the beginning of the line."
9586   (gnus-summary-mark-article article mark))
9587
9588 (defun gnus-summary-clear-mark-forward (n)
9589   "Clear marks from N articles forward.
9590 If N is negative, clear backward instead.
9591 The difference between N and the number of marks cleared is returned."
9592   (interactive "p")
9593   (gnus-summary-mark-forward n gnus-unread-mark))
9594
9595 (defun gnus-summary-clear-mark-backward (n)
9596   "Clear marks from N articles backward.
9597 The difference between N and the number of marks cleared is returned."
9598   (interactive "p")
9599   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9600
9601 (defun gnus-summary-mark-unread-as-read ()
9602   "Intended to be used by `gnus-summary-mark-article-hook'."
9603   (when (memq gnus-current-article gnus-newsgroup-unreads)
9604     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9605
9606 (defun gnus-summary-mark-read-and-unread-as-read ()
9607   "Intended to be used by `gnus-summary-mark-article-hook'."
9608   (let ((mark (gnus-summary-article-mark)))
9609     (when (or (gnus-unread-mark-p mark)
9610               (gnus-read-mark-p mark))
9611       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9612
9613 (defun gnus-summary-mark-unread-as-ticked ()
9614   "Intended to be used by `gnus-summary-mark-article-hook'."
9615   (when (memq gnus-current-article gnus-newsgroup-unreads)
9616     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9617
9618 (defun gnus-summary-mark-region-as-read (point mark all)
9619   "Mark all unread articles between point and mark as read.
9620 If given a prefix, mark all articles between point and mark as read,
9621 even ticked and dormant ones."
9622   (interactive "r\nP")
9623   (save-excursion
9624     (let (article)
9625       (goto-char point)
9626       (beginning-of-line)
9627       (while (and
9628               (< (point) mark)
9629               (progn
9630                 (when (or all
9631                           (memq (setq article (gnus-summary-article-number))
9632                                 gnus-newsgroup-unreads))
9633                   (gnus-summary-mark-article article gnus-del-mark))
9634                 t)
9635               (gnus-summary-find-next))))))
9636
9637 (defun gnus-summary-mark-below (score mark)
9638   "Mark articles with score less than SCORE with MARK."
9639   (interactive "P\ncMark: ")
9640   (setq score (if score
9641                   (prefix-numeric-value score)
9642                 (or gnus-summary-default-score 0)))
9643   (save-excursion
9644     (set-buffer gnus-summary-buffer)
9645     (goto-char (point-min))
9646     (while
9647         (progn
9648           (and (< (gnus-summary-article-score) score)
9649                (gnus-summary-mark-article nil mark))
9650           (gnus-summary-find-next)))))
9651
9652 (defun gnus-summary-kill-below (&optional score)
9653   "Mark articles with score below SCORE as read."
9654   (interactive "P")
9655   (gnus-summary-mark-below score gnus-killed-mark))
9656
9657 (defun gnus-summary-clear-above (&optional score)
9658   "Clear all marks from articles with score above SCORE."
9659   (interactive "P")
9660   (gnus-summary-mark-above score gnus-unread-mark))
9661
9662 (defun gnus-summary-tick-above (&optional score)
9663   "Tick all articles with score above SCORE."
9664   (interactive "P")
9665   (gnus-summary-mark-above score gnus-ticked-mark))
9666
9667 (defun gnus-summary-mark-above (score mark)
9668   "Mark articles with score over SCORE with MARK."
9669   (interactive "P\ncMark: ")
9670   (setq score (if score
9671                   (prefix-numeric-value score)
9672                 (or gnus-summary-default-score 0)))
9673   (save-excursion
9674     (set-buffer gnus-summary-buffer)
9675     (goto-char (point-min))
9676     (while (and (progn
9677                   (when (> (gnus-summary-article-score) score)
9678                     (gnus-summary-mark-article nil mark))
9679                   t)
9680                 (gnus-summary-find-next)))))
9681
9682 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9683 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9684 (defun gnus-summary-limit-include-expunged (&optional no-error)
9685   "Display all the hidden articles that were expunged for low scores."
9686   (interactive)
9687   (let ((buffer-read-only nil))
9688     (let ((scored gnus-newsgroup-scored)
9689           headers h)
9690       (while scored
9691         (unless (gnus-summary-article-header (caar scored))
9692           (and (setq h (gnus-number-to-header (caar scored)))
9693                (< (cdar scored) gnus-summary-expunge-below)
9694                (push h headers)))
9695         (setq scored (cdr scored)))
9696       (if (not headers)
9697           (when (not no-error)
9698             (error "No expunged articles hidden"))
9699         (goto-char (point-min))
9700         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9701         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9702         (mapcar (lambda (x) (push (mail-header-number x)
9703                                   gnus-newsgroup-limit))
9704                 headers)
9705         (gnus-summary-prepare-unthreaded (nreverse headers))
9706         (goto-char (point-min))
9707         (gnus-summary-position-point)
9708         t))))
9709
9710 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9711   "Mark all unread articles in this newsgroup as read.
9712 If prefix argument ALL is non-nil, ticked and dormant articles will
9713 also be marked as read.
9714 If QUIETLY is non-nil, no questions will be asked.
9715 If TO-HERE is non-nil, it should be a point in the buffer.  All
9716 articles before (after, if REVERSE is set) this point will be marked as read.
9717 Note that this function will only catch up the unread article
9718 in the current summary buffer limitation.
9719 The number of articles marked as read is returned."
9720   (interactive "P")
9721   (prog1
9722       (save-excursion
9723         (when (or quietly
9724                   (not gnus-interactive-catchup) ;Without confirmation?
9725                   gnus-expert-user
9726                   (gnus-y-or-n-p
9727                    (if all
9728                        "Mark absolutely all articles as read? "
9729                      "Mark all unread articles as read? ")))
9730           (if (and not-mark
9731                    (not gnus-newsgroup-adaptive)
9732                    (not gnus-newsgroup-auto-expire)
9733                    (not gnus-suppress-duplicates)
9734                    (or (not gnus-use-cache)
9735                        (eq gnus-use-cache 'passive)))
9736               (progn
9737                 (when all
9738                   (setq gnus-newsgroup-marked nil
9739                         gnus-newsgroup-dormant nil))
9740                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9741             ;; We actually mark all articles as canceled, which we
9742             ;; have to do when using auto-expiry or adaptive scoring.
9743             (gnus-summary-show-all-threads)
9744             (if (and to-here reverse)
9745                 (progn
9746                   (goto-char to-here)
9747                   (while (and
9748                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9749                           (gnus-summary-find-next (not all) nil nil t))))
9750               (when (gnus-summary-first-subject (not all) t)
9751                 (while (and
9752                         (if to-here (< (point) to-here) t)
9753                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9754                         (gnus-summary-find-next (not all) nil nil t)))))
9755             (gnus-set-mode-line 'summary))
9756           t))
9757     (gnus-summary-position-point)))
9758
9759 (defun gnus-summary-catchup-to-here (&optional all)
9760   "Mark all unticked articles before the current one as read.
9761 If ALL is non-nil, also mark ticked and dormant articles as read."
9762   (interactive "P")
9763   (save-excursion
9764     (gnus-save-hidden-threads
9765       (let ((beg (point)))
9766         ;; We check that there are unread articles.
9767         (when (or all (gnus-summary-find-prev))
9768           (gnus-summary-catchup all t beg)))))
9769   (gnus-summary-position-point))
9770
9771 (defun gnus-summary-catchup-from-here (&optional all)
9772   "Mark all unticked articles after the current one as read.
9773 If ALL is non-nil, also mark ticked and dormant articles as read."
9774   (interactive "P")
9775   (save-excursion
9776     (gnus-save-hidden-threads
9777       (let ((beg (point)))
9778         ;; We check that there are unread articles.
9779         (when (or all (gnus-summary-find-next))
9780           (gnus-summary-catchup all t beg nil t)))))
9781   (gnus-summary-position-point))
9782
9783 (defun gnus-summary-catchup-all (&optional quietly)
9784   "Mark all articles in this newsgroup as read."
9785   (interactive "P")
9786   (gnus-summary-catchup t quietly))
9787
9788 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9789   "Mark all unread articles in this group as read, then exit.
9790 If prefix argument ALL is non-nil, all articles are marked as read.
9791 If QUIETLY is non-nil, no questions will be asked."
9792   (interactive "P")
9793   (when (gnus-summary-catchup all quietly nil 'fast)
9794     ;; Select next newsgroup or exit.
9795     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9796              (eq gnus-auto-select-next 'quietly))
9797         (gnus-summary-next-group nil)
9798       (gnus-summary-exit))))
9799
9800 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9801   "Mark all articles in this newsgroup as read, and then exit."
9802   (interactive "P")
9803   (gnus-summary-catchup-and-exit t quietly))
9804
9805 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9806   "Mark all articles in this group as read and select the next group.
9807 If given a prefix, mark all articles, unread as well as ticked, as
9808 read."
9809   (interactive "P")
9810   (save-excursion
9811     (gnus-summary-catchup all))
9812   (gnus-summary-next-group))
9813
9814 ;;;
9815 ;;; with article
9816 ;;;
9817
9818 (defmacro gnus-with-article (article &rest forms)
9819   "Select ARTICLE and perform FORMS in the original article buffer.
9820 Then replace the article with the result."
9821   `(progn
9822      ;; We don't want the article to be marked as read.
9823      (let (gnus-mark-article-hook)
9824        (gnus-summary-select-article t t nil ,article))
9825      (set-buffer gnus-original-article-buffer)
9826      ,@forms
9827      (if (not (gnus-check-backend-function
9828                'request-replace-article (car gnus-article-current)))
9829          (gnus-message 5 "Read-only group; not replacing")
9830        (unless (gnus-request-replace-article
9831                 ,article (car gnus-article-current)
9832                 (current-buffer) t)
9833          (error "Couldn't replace article")))
9834      ;; The cache and backlog have to be flushed somewhat.
9835      (when gnus-keep-backlog
9836        (gnus-backlog-remove-article
9837         (car gnus-article-current) (cdr gnus-article-current)))
9838      (when gnus-use-cache
9839        (gnus-cache-update-article
9840         (car gnus-article-current) (cdr gnus-article-current)))))
9841
9842 (put 'gnus-with-article 'lisp-indent-function 1)
9843 (put 'gnus-with-article 'edebug-form-spec '(form body))
9844
9845 ;; Thread-based commands.
9846
9847 (defun gnus-summary-articles-in-thread (&optional article)
9848   "Return a list of all articles in the current thread.
9849 If ARTICLE is non-nil, return all articles in the thread that starts
9850 with that article."
9851   (let* ((article (or article (gnus-summary-article-number)))
9852          (data (gnus-data-find-list article))
9853          (top-level (gnus-data-level (car data)))
9854          (top-subject
9855           (cond ((null gnus-thread-operation-ignore-subject)
9856                  (gnus-simplify-subject-re
9857                   (mail-header-subject (gnus-data-header (car data)))))
9858                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9859                  (gnus-simplify-subject-fuzzy
9860                   (mail-header-subject (gnus-data-header (car data)))))
9861                 (t nil)))
9862          (end-point (save-excursion
9863                       (if (gnus-summary-go-to-next-thread)
9864                           (point) (point-max))))
9865          articles)
9866     (while (and data
9867                 (< (gnus-data-pos (car data)) end-point))
9868       (when (or (not top-subject)
9869                 (string= top-subject
9870                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9871                              (gnus-simplify-subject-fuzzy
9872                               (mail-header-subject
9873                                (gnus-data-header (car data))))
9874                            (gnus-simplify-subject-re
9875                             (mail-header-subject
9876                              (gnus-data-header (car data)))))))
9877         (push (gnus-data-number (car data)) articles))
9878       (unless (and (setq data (cdr data))
9879                    (> (gnus-data-level (car data)) top-level))
9880         (setq data nil)))
9881     ;; Return the list of articles.
9882     (nreverse articles)))
9883
9884 (defun gnus-summary-rethread-current ()
9885   "Rethread the thread the current article is part of."
9886   (interactive)
9887   (let* ((gnus-show-threads t)
9888          (article (gnus-summary-article-number))
9889          (id (mail-header-id (gnus-summary-article-header)))
9890          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9891     (unless id
9892       (error "No article on the current line"))
9893     (gnus-rebuild-thread id)
9894     (gnus-summary-goto-subject article)))
9895
9896 (defun gnus-summary-reparent-thread ()
9897   "Make the current article child of the marked (or previous) article.
9898
9899 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9900 is non-nil or the Subject: of both articles are the same."
9901   (interactive)
9902   (unless (not (gnus-group-read-only-p))
9903     (error "The current newsgroup does not support article editing"))
9904   (unless (<= (length gnus-newsgroup-processable) 1)
9905     (error "No more than one article may be marked"))
9906   (save-window-excursion
9907     (let ((gnus-article-buffer " *reparent*")
9908           (current-article (gnus-summary-article-number))
9909           ;; First grab the marked article, otherwise one line up.
9910           (parent-article (if (not (null gnus-newsgroup-processable))
9911                               (car gnus-newsgroup-processable)
9912                             (save-excursion
9913                               (if (eq (forward-line -1) 0)
9914                                   (gnus-summary-article-number)
9915                                 (error "Beginning of summary buffer"))))))
9916       (unless (not (eq current-article parent-article))
9917         (error "An article may not be self-referential"))
9918       (let ((message-id (mail-header-id
9919                          (gnus-summary-article-header parent-article))))
9920         (unless (and message-id (not (equal message-id "")))
9921           (error "No message-id in desired parent"))
9922         (gnus-with-article current-article
9923           (save-restriction
9924             (goto-char (point-min))
9925             (message-narrow-to-head)
9926             (if (re-search-forward "^References: " nil t)
9927                 (progn
9928                   (re-search-forward "^[^ \t]" nil t)
9929                   (forward-line -1)
9930                   (end-of-line)
9931                   (insert " " message-id))
9932               (insert "References: " message-id "\n"))))
9933         (set-buffer gnus-summary-buffer)
9934         (gnus-summary-unmark-all-processable)
9935         (gnus-summary-update-article current-article)
9936         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9937             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9938         (gnus-summary-rethread-current)
9939         (gnus-message 3 "Article %d is now the child of article %d"
9940                       current-article parent-article)))))
9941
9942 (defun gnus-summary-toggle-threads (&optional arg)
9943   "Toggle showing conversation threads.
9944 If ARG is positive number, turn showing conversation threads on."
9945   (interactive "P")
9946   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9947     (setq gnus-show-threads
9948           (if (null arg) (not gnus-show-threads)
9949             (> (prefix-numeric-value arg) 0)))
9950     (gnus-summary-prepare)
9951     (gnus-summary-goto-subject current)
9952     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9953     (gnus-summary-position-point)))
9954
9955 (defun gnus-summary-show-all-threads ()
9956   "Show all threads."
9957   (interactive)
9958   (save-excursion
9959     (let ((buffer-read-only nil))
9960       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9961   (gnus-summary-position-point))
9962
9963 (defun gnus-summary-show-thread ()
9964   "Show thread subtrees.
9965 Returns nil if no thread was there to be shown."
9966   (interactive)
9967   (let ((buffer-read-only nil)
9968         (orig (point))
9969         ;; first goto end then to beg, to have point at beg after let
9970         (end (progn (end-of-line) (point)))
9971         (beg (progn (beginning-of-line) (point))))
9972     (prog1
9973         ;; Any hidden lines here?
9974         (search-forward "\r" end t)
9975       (subst-char-in-region beg end ?\^M ?\n t)
9976       (goto-char orig)
9977       (gnus-summary-position-point))))
9978
9979 (defun gnus-summary-maybe-hide-threads ()
9980   "If requested, hide the threads that should be hidden."
9981   (when (and gnus-show-threads
9982              gnus-thread-hide-subtree)
9983     (gnus-summary-hide-all-threads
9984      (if (or (consp gnus-thread-hide-subtree)
9985              (gnus-functionp gnus-thread-hide-subtree))
9986          (gnus-make-predicate gnus-thread-hide-subtree)
9987        nil))))
9988
9989 ;;; Hiding predicates.
9990
9991 (defun gnus-article-unread-p (header)
9992   (memq (mail-header-number header) gnus-newsgroup-unreads))
9993
9994 (defun gnus-article-unseen-p (header)
9995   (memq (mail-header-number header) gnus-newsgroup-unseen))
9996
9997 (defun gnus-map-articles (predicate articles)
9998   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
9999   (apply 'gnus-or (mapcar predicate
10000                           (mapcar 'gnus-summary-article-header articles))))
10001
10002 (defun gnus-summary-hide-all-threads (&optional predicate)
10003   "Hide all thread subtrees.
10004 If PREDICATE is supplied, threads that satisfy this predicate
10005 will not be hidden."
10006   (interactive)
10007   (save-excursion
10008     (goto-char (point-min))
10009     (let ((end nil))
10010       (while (not end)
10011         (when (or (not predicate)
10012                   (gnus-map-articles
10013                    predicate (gnus-summary-article-children)))
10014             (gnus-summary-hide-thread))
10015         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10016   (gnus-summary-position-point))
10017
10018 (defun gnus-summary-hide-thread ()
10019   "Hide thread subtrees.
10020 If PREDICATE is supplied, threads that satisfy this predicate
10021 will not be hidden.
10022 Returns nil if no threads were there to be hidden."
10023   (interactive)
10024   (let ((buffer-read-only nil)
10025         (start (point))
10026         (article (gnus-summary-article-number)))
10027     (goto-char start)
10028     ;; Go forward until either the buffer ends or the subthread
10029     ;; ends.
10030     (when (and (not (eobp))
10031                (or (zerop (gnus-summary-next-thread 1 t))
10032                    (goto-char (point-max))))
10033       (prog1
10034           (if (and (> (point) start)
10035                    (search-backward "\n" start t))
10036               (progn
10037                 (subst-char-in-region start (point) ?\n ?\^M)
10038                 (gnus-summary-goto-subject article))
10039             (goto-char start)
10040             nil)))))
10041
10042 (defun gnus-summary-go-to-next-thread (&optional previous)
10043   "Go to the same level (or less) next thread.
10044 If PREVIOUS is non-nil, go to previous thread instead.
10045 Return the article number moved to, or nil if moving was impossible."
10046   (let ((level (gnus-summary-thread-level))
10047         (way (if previous -1 1))
10048         (beg (point)))
10049     (forward-line way)
10050     (while (and (not (eobp))
10051                 (< level (gnus-summary-thread-level)))
10052       (forward-line way))
10053     (if (eobp)
10054         (progn
10055           (goto-char beg)
10056           nil)
10057       (setq beg (point))
10058       (prog1
10059           (gnus-summary-article-number)
10060         (goto-char beg)))))
10061
10062 (defun gnus-summary-next-thread (n &optional silent)
10063   "Go to the same level next N'th thread.
10064 If N is negative, search backward instead.
10065 Returns the difference between N and the number of skips actually
10066 done.
10067
10068 If SILENT, don't output messages."
10069   (interactive "p")
10070   (let ((backward (< n 0))
10071         (n (abs n)))
10072     (while (and (> n 0)
10073                 (gnus-summary-go-to-next-thread backward))
10074       (decf n))
10075     (unless silent
10076       (gnus-summary-position-point))
10077     (when (and (not silent) (/= 0 n))
10078       (gnus-message 7 "No more threads"))
10079     n))
10080
10081 (defun gnus-summary-prev-thread (n)
10082   "Go to the same level previous N'th thread.
10083 Returns the difference between N and the number of skips actually
10084 done."
10085   (interactive "p")
10086   (gnus-summary-next-thread (- n)))
10087
10088 (defun gnus-summary-go-down-thread ()
10089   "Go down one level in the current thread."
10090   (let ((children (gnus-summary-article-children)))
10091     (when children
10092       (gnus-summary-goto-subject (car children)))))
10093
10094 (defun gnus-summary-go-up-thread ()
10095   "Go up one level in the current thread."
10096   (let ((parent (gnus-summary-article-parent)))
10097     (when parent
10098       (gnus-summary-goto-subject parent))))
10099
10100 (defun gnus-summary-down-thread (n)
10101   "Go down thread N steps.
10102 If N is negative, go up instead.
10103 Returns the difference between N and how many steps down that were
10104 taken."
10105   (interactive "p")
10106   (let ((up (< n 0))
10107         (n (abs n)))
10108     (while (and (> n 0)
10109                 (if up (gnus-summary-go-up-thread)
10110                   (gnus-summary-go-down-thread)))
10111       (setq n (1- n)))
10112     (gnus-summary-position-point)
10113     (when (/= 0 n)
10114       (gnus-message 7 "Can't go further"))
10115     n))
10116
10117 (defun gnus-summary-up-thread (n)
10118   "Go up thread N steps.
10119 If N is negative, go down instead.
10120 Returns the difference between N and how many steps down that were
10121 taken."
10122   (interactive "p")
10123   (gnus-summary-down-thread (- n)))
10124
10125 (defun gnus-summary-top-thread ()
10126   "Go to the top of the thread."
10127   (interactive)
10128   (while (gnus-summary-go-up-thread))
10129   (gnus-summary-article-number))
10130
10131 (defun gnus-summary-kill-thread (&optional unmark)
10132   "Mark articles under current thread as read.
10133 If the prefix argument is positive, remove any kinds of marks.
10134 If the prefix argument is negative, tick articles instead."
10135   (interactive "P")
10136   (when unmark
10137     (setq unmark (prefix-numeric-value unmark)))
10138   (let ((articles (gnus-summary-articles-in-thread)))
10139     (save-excursion
10140       ;; Expand the thread.
10141       (gnus-summary-show-thread)
10142       ;; Mark all the articles.
10143       (while articles
10144         (gnus-summary-goto-subject (car articles))
10145         (cond ((null unmark)
10146                (gnus-summary-mark-article-as-read gnus-killed-mark))
10147               ((> unmark 0)
10148                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10149               (t
10150                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10151         (setq articles (cdr articles))))
10152     ;; Hide killed subtrees.
10153     (and (null unmark)
10154          gnus-thread-hide-killed
10155          (gnus-summary-hide-thread))
10156     ;; If marked as read, go to next unread subject.
10157     (when (null unmark)
10158       ;; Go to next unread subject.
10159       (gnus-summary-next-subject 1 t)))
10160   (gnus-set-mode-line 'summary))
10161
10162 ;; Summary sorting commands
10163
10164 (defun gnus-summary-sort-by-number (&optional reverse)
10165   "Sort the summary buffer by article number.
10166 Argument REVERSE means reverse order."
10167   (interactive "P")
10168   (gnus-summary-sort 'number reverse))
10169
10170 (defun gnus-summary-sort-by-author (&optional reverse)
10171   "Sort the summary buffer by author name alphabetically.
10172 If `case-fold-search' is non-nil, case of letters is ignored.
10173 Argument REVERSE means reverse order."
10174   (interactive "P")
10175   (gnus-summary-sort 'author reverse))
10176
10177 (defun gnus-summary-sort-by-subject (&optional reverse)
10178   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10179 If `case-fold-search' is non-nil, case of letters is ignored.
10180 Argument REVERSE means reverse order."
10181   (interactive "P")
10182   (gnus-summary-sort 'subject reverse))
10183
10184 (defun gnus-summary-sort-by-date (&optional reverse)
10185   "Sort the summary buffer by date.
10186 Argument REVERSE means reverse order."
10187   (interactive "P")
10188   (gnus-summary-sort 'date reverse))
10189
10190 (defun gnus-summary-sort-by-score (&optional reverse)
10191   "Sort the summary buffer by score.
10192 Argument REVERSE means reverse order."
10193   (interactive "P")
10194   (gnus-summary-sort 'score reverse))
10195
10196 (defun gnus-summary-sort-by-lines (&optional reverse)
10197   "Sort the summary buffer by the number of lines.
10198 Argument REVERSE means reverse order."
10199   (interactive "P")
10200   (gnus-summary-sort 'lines reverse))
10201
10202 (defun gnus-summary-sort-by-chars (&optional reverse)
10203   "Sort the summary buffer by article length.
10204 Argument REVERSE means reverse order."
10205   (interactive "P")
10206   (gnus-summary-sort 'chars reverse))
10207
10208 (defun gnus-summary-sort-by-original (&optional reverse)
10209   "Sort the summary buffer using the default sorting method.
10210 Argument REVERSE means reverse order."
10211   (interactive "P")
10212   (let* ((buffer-read-only)
10213          (gnus-summary-prepare-hook nil))
10214     ;; We do the sorting by regenerating the threads.
10215     (gnus-summary-prepare)
10216     ;; Hide subthreads if needed.
10217     (gnus-summary-maybe-hide-threads)))
10218
10219 (defun gnus-summary-sort (predicate reverse)
10220   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10221   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10222          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10223          (gnus-thread-sort-functions
10224           (if (not reverse)
10225               thread
10226             `(lambda (t1 t2)
10227                (,thread t2 t1))))
10228          (gnus-sort-gathered-threads-function
10229           gnus-thread-sort-functions)
10230          (gnus-article-sort-functions
10231           (if (not reverse)
10232               article
10233             `(lambda (t1 t2)
10234                (,article t2 t1))))
10235          (buffer-read-only)
10236          (gnus-summary-prepare-hook nil))
10237     ;; We do the sorting by regenerating the threads.
10238     (gnus-summary-prepare)
10239     ;; Hide subthreads if needed.
10240     (gnus-summary-maybe-hide-threads)))
10241
10242 ;; Summary saving commands.
10243
10244 (defun gnus-summary-save-article (&optional n not-saved)
10245   "Save the current article using the default saver function.
10246 If N is a positive number, save the N next articles.
10247 If N is a negative number, save the N previous articles.
10248 If N is nil and any articles have been marked with the process mark,
10249 save those articles instead.
10250 The variable `gnus-default-article-saver' specifies the saver function."
10251   (interactive "P")
10252   (let* ((articles (gnus-summary-work-articles n))
10253          (save-buffer (save-excursion
10254                         (nnheader-set-temp-buffer " *Gnus Save*")))
10255          (num (length articles))
10256          header file)
10257     (dolist (article articles)
10258       (setq header (gnus-summary-article-header article))
10259       (if (not (vectorp header))
10260           ;; This is a pseudo-article.
10261           (if (assq 'name header)
10262               (gnus-copy-file (cdr (assq 'name header)))
10263             (gnus-message 1 "Article %d is unsaveable" article))
10264         ;; This is a real article.
10265         (save-window-excursion
10266           (let ((gnus-display-mime-function nil)
10267                 (gnus-article-prepare-hook nil))
10268             (gnus-summary-select-article t nil nil article)))
10269         (save-excursion
10270           (set-buffer save-buffer)
10271           (erase-buffer)
10272           (insert-buffer-substring gnus-original-article-buffer))
10273         (setq file (gnus-article-save save-buffer file num))
10274         (gnus-summary-remove-process-mark article)
10275         (unless not-saved
10276           (gnus-summary-set-saved-mark article))))
10277     (gnus-kill-buffer save-buffer)
10278     (gnus-summary-position-point)
10279     (gnus-set-mode-line 'summary)
10280     n))
10281
10282 (defun gnus-summary-pipe-output (&optional arg)
10283   "Pipe the current article to a subprocess.
10284 If N is a positive number, pipe the N next articles.
10285 If N is a negative number, pipe the N previous articles.
10286 If N is nil and any articles have been marked with the process mark,
10287 pipe those articles instead."
10288   (interactive "P")
10289   (require 'gnus-art)
10290   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10291     (gnus-summary-save-article arg t))
10292   (let ((buffer (get-buffer "*Shell Command Output*")))
10293     (if (and buffer
10294              (with-current-buffer buffer (> (point-max) (point-min))))
10295         (gnus-configure-windows 'pipe))))
10296
10297 (defun gnus-summary-save-article-mail (&optional arg)
10298   "Append the current article to an mail file.
10299 If N is a positive number, save the N next articles.
10300 If N is a negative number, save the N previous articles.
10301 If N is nil and any articles have been marked with the process mark,
10302 save those articles instead."
10303   (interactive "P")
10304   (require 'gnus-art)
10305   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10306     (gnus-summary-save-article arg)))
10307
10308 (defun gnus-summary-save-article-rmail (&optional arg)
10309   "Append the current article to an rmail file.
10310 If N is a positive number, save the N next articles.
10311 If N is a negative number, save the N previous articles.
10312 If N is nil and any articles have been marked with the process mark,
10313 save those articles instead."
10314   (interactive "P")
10315   (require 'gnus-art)
10316   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10317     (gnus-summary-save-article arg)))
10318
10319 (defun gnus-summary-save-article-file (&optional arg)
10320   "Append the current article to a file.
10321 If N is a positive number, save the N next articles.
10322 If N is a negative number, save the N previous articles.
10323 If N is nil and any articles have been marked with the process mark,
10324 save those articles instead."
10325   (interactive "P")
10326   (require 'gnus-art)
10327   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10328     (gnus-summary-save-article arg)))
10329
10330 (defun gnus-summary-write-article-file (&optional arg)
10331   "Write the current article to a file, deleting the previous file.
10332 If N is a positive number, save the N next articles.
10333 If N is a negative number, save the N previous articles.
10334 If N is nil and any articles have been marked with the process mark,
10335 save those articles instead."
10336   (interactive "P")
10337   (require 'gnus-art)
10338   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10339     (gnus-summary-save-article arg)))
10340
10341 (defun gnus-summary-save-article-body-file (&optional arg)
10342   "Append the current article body to a file.
10343 If N is a positive number, save the N next articles.
10344 If N is a negative number, save the N previous articles.
10345 If N is nil and any articles have been marked with the process mark,
10346 save those articles instead."
10347   (interactive "P")
10348   (require 'gnus-art)
10349   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10350     (gnus-summary-save-article arg)))
10351
10352 (defun gnus-summary-muttprint (&optional arg)
10353   "Print the current article using Muttprint.
10354 If N is a positive number, save the N next articles.
10355 If N is a negative number, save the N previous articles.
10356 If N is nil and any articles have been marked with the process mark,
10357 save those articles instead."
10358   (interactive "P")
10359   (require 'gnus-art)
10360   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10361     (gnus-summary-save-article arg t)))
10362
10363 (defun gnus-summary-pipe-message (program)
10364   "Pipe the current article through PROGRAM."
10365   (interactive "sProgram: ")
10366   (gnus-summary-select-article)
10367   (let ((mail-header-separator ""))
10368     (gnus-eval-in-buffer-window gnus-article-buffer
10369       (save-restriction
10370         (widen)
10371         (let ((start (window-start))
10372               buffer-read-only)
10373           (message-pipe-buffer-body program)
10374           (set-window-start (get-buffer-window (current-buffer)) start))))))
10375
10376 (defun gnus-get-split-value (methods)
10377   "Return a value based on the split METHODS."
10378   (let (split-name method result match)
10379     (when methods
10380       (save-excursion
10381         (set-buffer gnus-original-article-buffer)
10382         (save-restriction
10383           (nnheader-narrow-to-headers)
10384           (while (and methods (not split-name))
10385             (goto-char (point-min))
10386             (setq method (pop methods))
10387             (setq match (car method))
10388             (when (cond
10389                    ((stringp match)
10390                     ;; Regular expression.
10391                     (ignore-errors
10392                       (re-search-forward match nil t)))
10393                    ((gnus-functionp match)
10394                     ;; Function.
10395                     (save-restriction
10396                       (widen)
10397                       (setq result (funcall match gnus-newsgroup-name))))
10398                    ((consp match)
10399                     ;; Form.
10400                     (save-restriction
10401                       (widen)
10402                       (setq result (eval match)))))
10403               (setq split-name (cdr method))
10404               (cond ((stringp result)
10405                      (push (expand-file-name
10406                             result gnus-article-save-directory)
10407                            split-name))
10408                     ((consp result)
10409                      (setq split-name (append result split-name)))))))))
10410     (nreverse split-name)))
10411
10412 (defun gnus-valid-move-group-p (group)
10413   (and (boundp group)
10414        (symbol-name group)
10415        (symbol-value group)
10416        (gnus-get-function (gnus-find-method-for-group
10417                            (symbol-name group)) 'request-accept-article t)))
10418
10419 (defun gnus-read-move-group-name (prompt default articles prefix)
10420   "Read a group name."
10421   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10422          (minibuffer-confirm-incomplete nil) ; XEmacs
10423          (prom
10424           (format "%s %s to:"
10425                   prompt
10426                   (if (> (length articles) 1)
10427                       (format "these %d articles" (length articles))
10428                     "this article")))
10429          (to-newsgroup
10430           (cond
10431            ((null split-name)
10432             (gnus-completing-read-with-default
10433              default prom
10434              gnus-active-hashtb
10435              'gnus-valid-move-group-p
10436              nil prefix
10437              'gnus-group-history))
10438            ((= 1 (length split-name))
10439             (gnus-completing-read-with-default
10440              (car split-name) prom
10441              gnus-active-hashtb
10442              'gnus-valid-move-group-p
10443              nil nil
10444              'gnus-group-history))
10445            (t
10446             (gnus-completing-read-with-default
10447              nil prom
10448              (mapcar (lambda (el) (list el))
10449                      (nreverse split-name))
10450              nil nil nil
10451              'gnus-group-history))))
10452          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10453     (when to-newsgroup
10454       (if (or (string= to-newsgroup "")
10455               (string= to-newsgroup prefix))
10456           (setq to-newsgroup default))
10457       (unless to-newsgroup
10458         (error "No group name entered"))
10459       (or (gnus-active to-newsgroup)
10460           (gnus-activate-group to-newsgroup nil nil to-method)
10461           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10462                                      to-newsgroup))
10463               (or (and (gnus-request-create-group to-newsgroup to-method)
10464                        (gnus-activate-group
10465                         to-newsgroup nil nil to-method)
10466                        (gnus-subscribe-group to-newsgroup))
10467                   (error "Couldn't create group %s" to-newsgroup)))
10468           (error "No such group: %s" to-newsgroup)))
10469     to-newsgroup))
10470
10471 (defun gnus-summary-save-parts (type dir n &optional reverse)
10472   "Save parts matching TYPE to DIR.
10473 If REVERSE, save parts that do not match TYPE."
10474   (interactive
10475    (list (read-string "Save parts of type: "
10476                       (or (car gnus-summary-save-parts-type-history)
10477                           gnus-summary-save-parts-default-mime)
10478                       'gnus-summary-save-parts-type-history)
10479          (setq gnus-summary-save-parts-last-directory
10480                (read-file-name "Save to directory: "
10481                                gnus-summary-save-parts-last-directory
10482                                nil t))
10483          current-prefix-arg))
10484   (gnus-summary-iterate n
10485     (let ((gnus-display-mime-function nil)
10486           (gnus-inhibit-treatment t))
10487       (gnus-summary-select-article))
10488     (save-excursion
10489       (set-buffer gnus-article-buffer)
10490       (let ((handles (or gnus-article-mime-handles
10491                          (mm-dissect-buffer nil gnus-article-loose-mime)
10492                          (mm-uu-dissect))))
10493         (when handles
10494           (gnus-summary-save-parts-1 type dir handles reverse)
10495           (unless gnus-article-mime-handles ;; Don't destroy this case.
10496             (mm-destroy-parts handles)))))))
10497
10498 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10499   (if (stringp (car handle))
10500       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10501               (cdr handle))
10502     (when (if reverse
10503               (not (string-match type (mm-handle-media-type handle)))
10504             (string-match type (mm-handle-media-type handle)))
10505       (let ((file (expand-file-name
10506                    (file-name-nondirectory
10507                     (or
10508                      (mail-content-type-get
10509                       (mm-handle-disposition handle) 'filename)
10510                      (concat gnus-newsgroup-name
10511                              "." (number-to-string
10512                                   (cdr gnus-article-current)))))
10513                    dir)))
10514         (unless (file-exists-p file)
10515           (mm-save-part-to-file handle file))))))
10516
10517 ;; Summary extract commands
10518
10519 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10520   (let ((buffer-read-only nil)
10521         (article (gnus-summary-article-number))
10522         after-article b e)
10523     (unless (gnus-summary-goto-subject article)
10524       (error "No such article: %d" article))
10525     (gnus-summary-position-point)
10526     ;; If all commands are to be bunched up on one line, we collect
10527     ;; them here.
10528     (unless gnus-view-pseudos-separately
10529       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10530             files action)
10531         (while ps
10532           (setq action (cdr (assq 'action (car ps))))
10533           (setq files (list (cdr (assq 'name (car ps)))))
10534           (while (and ps (cdr ps)
10535                       (string= (or action "1")
10536                                (or (cdr (assq 'action (cadr ps))) "2")))
10537             (push (cdr (assq 'name (cadr ps))) files)
10538             (setcdr ps (cddr ps)))
10539           (when files
10540             (when (not (string-match "%s" action))
10541               (push " " files))
10542             (push " " files)
10543             (when (assq 'execute (car ps))
10544               (setcdr (assq 'execute (car ps))
10545                       (funcall (if (string-match "%s" action)
10546                                    'format 'concat)
10547                                action
10548                                (mapconcat
10549                                 (lambda (f)
10550                                   (if (equal f " ")
10551                                       f
10552                                     (gnus-quote-arg-for-sh-or-csh f)))
10553                                 files " ")))))
10554           (setq ps (cdr ps)))))
10555     (if (and gnus-view-pseudos (not not-view))
10556         (while pslist
10557           (when (assq 'execute (car pslist))
10558             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10559                                   (eq gnus-view-pseudos 'not-confirm)))
10560           (setq pslist (cdr pslist)))
10561       (save-excursion
10562         (while pslist
10563           (setq after-article (or (cdr (assq 'article (car pslist)))
10564                                   (gnus-summary-article-number)))
10565           (gnus-summary-goto-subject after-article)
10566           (forward-line 1)
10567           (setq b (point))
10568           (insert "    " (file-name-nondirectory
10569                           (cdr (assq 'name (car pslist))))
10570                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10571           (setq e (point))
10572           (forward-line -1)             ; back to `b'
10573           (gnus-add-text-properties
10574            b (1- e) (list 'gnus-number gnus-reffed-article-number
10575                           gnus-mouse-face-prop gnus-mouse-face))
10576           (gnus-data-enter
10577            after-article gnus-reffed-article-number
10578            gnus-unread-mark b (car pslist) 0 (- e b))
10579           (setq gnus-newsgroup-unreads
10580                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10581                                          gnus-reffed-article-number))
10582           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10583           (setq pslist (cdr pslist)))))))
10584
10585 (defun gnus-pseudos< (p1 p2)
10586   (let ((c1 (cdr (assq 'action p1)))
10587         (c2 (cdr (assq 'action p2))))
10588     (and c1 c2 (string< c1 c2))))
10589
10590 (defun gnus-request-pseudo-article (props)
10591   (cond ((assq 'execute props)
10592          (gnus-execute-command (cdr (assq 'execute props)))))
10593   (let ((gnus-current-article (gnus-summary-article-number)))
10594     (gnus-run-hooks 'gnus-mark-article-hook)))
10595
10596 (defun gnus-execute-command (command &optional automatic)
10597   (save-excursion
10598     (gnus-article-setup-buffer)
10599     (set-buffer gnus-article-buffer)
10600     (setq buffer-read-only nil)
10601     (let ((command (if automatic command
10602                      (read-string "Command: " (cons command 0)))))
10603       (erase-buffer)
10604       (insert "$ " command "\n\n")
10605       (if gnus-view-pseudo-asynchronously
10606           (start-process "gnus-execute" (current-buffer) shell-file-name
10607                          shell-command-switch command)
10608         (call-process shell-file-name nil t nil
10609                       shell-command-switch command)))))
10610
10611 ;; Summary kill commands.
10612
10613 (defun gnus-summary-edit-global-kill (article)
10614   "Edit the \"global\" kill file."
10615   (interactive (list (gnus-summary-article-number)))
10616   (gnus-group-edit-global-kill article))
10617
10618 (defun gnus-summary-edit-local-kill ()
10619   "Edit a local kill file applied to the current newsgroup."
10620   (interactive)
10621   (setq gnus-current-headers (gnus-summary-article-header))
10622   (gnus-group-edit-local-kill
10623    (gnus-summary-article-number) gnus-newsgroup-name))
10624
10625 ;;; Header reading.
10626
10627 (defun gnus-read-header (id &optional header)
10628   "Read the headers of article ID and enter them into the Gnus system."
10629   (let ((group gnus-newsgroup-name)
10630         (gnus-override-method
10631          (or
10632           gnus-override-method
10633           (and (gnus-news-group-p gnus-newsgroup-name)
10634                (car (gnus-refer-article-methods)))))
10635         where)
10636     ;; First we check to see whether the header in question is already
10637     ;; fetched.
10638     (if (stringp id)
10639         ;; This is a Message-ID.
10640         (setq header (or header (gnus-id-to-header id)))
10641       ;; This is an article number.
10642       (setq header (or header (gnus-summary-article-header id))))
10643     (if (and header
10644              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10645         ;; We have found the header.
10646         header
10647       ;; If this is a sparse article, we have to nix out its
10648       ;; previous entry in the thread hashtb.
10649       (when (and header
10650                  (gnus-summary-article-sparse-p (mail-header-number header)))
10651         (let* ((parent (gnus-parent-id (mail-header-references header)))
10652                (thread (and parent (gnus-id-to-thread parent))))
10653           (when thread
10654             (delq (assq header thread) thread))))
10655       ;; We have to really fetch the header to this article.
10656       (save-excursion
10657         (set-buffer nntp-server-buffer)
10658         (when (setq where (gnus-request-head id group))
10659           (nnheader-fold-continuation-lines)
10660           (goto-char (point-max))
10661           (insert ".\n")
10662           (goto-char (point-min))
10663           (insert "211 ")
10664           (princ (cond
10665                   ((numberp id) id)
10666                   ((cdr where) (cdr where))
10667                   (header (mail-header-number header))
10668                   (t gnus-reffed-article-number))
10669                  (current-buffer))
10670           (insert " Article retrieved.\n"))
10671         (if (or (not where)
10672                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10673             ()                          ; Malformed head.
10674           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10675             (when (and (stringp id)
10676                        (not (string= (gnus-group-real-name group)
10677                                      (car where))))
10678               ;; If we fetched by Message-ID and the article came
10679               ;; from a different group, we fudge some bogus article
10680               ;; numbers for this article.
10681               (mail-header-set-number header gnus-reffed-article-number))
10682             (save-excursion
10683               (set-buffer gnus-summary-buffer)
10684               (decf gnus-reffed-article-number)
10685               (gnus-remove-header (mail-header-number header))
10686               (push header gnus-newsgroup-headers)
10687               (setq gnus-current-headers header)
10688               (push (mail-header-number header) gnus-newsgroup-limit)))
10689           header)))))
10690
10691 (defun gnus-remove-header (number)
10692   "Remove header NUMBER from `gnus-newsgroup-headers'."
10693   (if (and gnus-newsgroup-headers
10694            (= number (mail-header-number (car gnus-newsgroup-headers))))
10695       (pop gnus-newsgroup-headers)
10696     (let ((headers gnus-newsgroup-headers))
10697       (while (and (cdr headers)
10698                   (not (= number (mail-header-number (cadr headers)))))
10699         (pop headers))
10700       (when (cdr headers)
10701         (setcdr headers (cddr headers))))))
10702
10703 ;;;
10704 ;;; summary highlights
10705 ;;;
10706
10707 (defun gnus-highlight-selected-summary ()
10708   "Highlight selected article in summary buffer."
10709   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10710   (when gnus-summary-selected-face
10711     (save-excursion
10712       (let* ((beg (progn (beginning-of-line) (point)))
10713              (end (progn (end-of-line) (point)))
10714              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10715              (from (if (get-text-property beg gnus-mouse-face-prop)
10716                        beg
10717                      (or (next-single-property-change
10718                           beg gnus-mouse-face-prop nil end)
10719                          beg)))
10720              (to
10721               (if (= from end)
10722                   (- from 2)
10723                 (or (next-single-property-change
10724                      from gnus-mouse-face-prop nil end)
10725                     end))))
10726         ;; If no mouse-face prop on line we will have to = from = end,
10727         ;; so we highlight the entire line instead.
10728         (when (= (+ to 2) from)
10729           (setq from beg)
10730           (setq to end))
10731         (if gnus-newsgroup-selected-overlay
10732             ;; Move old overlay.
10733             (gnus-move-overlay
10734              gnus-newsgroup-selected-overlay from to (current-buffer))
10735           ;; Create new overlay.
10736           (gnus-overlay-put
10737            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10738            'face gnus-summary-selected-face))))))
10739
10740 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10741 (defun gnus-summary-highlight-line ()
10742   "Highlight current line according to `gnus-summary-highlight'."
10743   (let* ((list gnus-summary-highlight)
10744          (p (point))
10745          (end (progn (end-of-line) (point)))
10746          ;; now find out where the line starts and leave point there.
10747          (beg (progn (beginning-of-line) (point)))
10748          (article (gnus-summary-article-number))
10749          (score (or (cdr (assq (or article gnus-current-article)
10750                                gnus-newsgroup-scored))
10751                     gnus-summary-default-score 0))
10752          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10753          (inhibit-read-only t))
10754     ;; Eval the cars of the lists until we find a match.
10755     (let ((default gnus-summary-default-score)
10756           (default-high gnus-summary-default-high-score)
10757           (default-low gnus-summary-default-low-score))
10758       (while (and list
10759                   (not (eval (caar list))))
10760         (setq list (cdr list))))
10761     (let ((face (cdar list)))
10762       (unless (eq face (get-text-property beg 'face))
10763         (gnus-put-text-property-excluding-characters-with-faces
10764          beg end 'face
10765          (setq face (if (boundp face) (symbol-value face) face)))
10766         (when gnus-summary-highlight-line-function
10767           (funcall gnus-summary-highlight-line-function article face))))
10768     (goto-char p)))
10769
10770 (defun gnus-update-read-articles (group unread &optional compute)
10771   "Update the list of read articles in GROUP.
10772 UNREAD is a sorted list."
10773   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10774          (entry (gnus-gethash group gnus-newsrc-hashtb))
10775          (info (nth 2 entry))
10776          (prev 1)
10777          read)
10778     (if (or (not info) (not active))
10779         ;; There is no info on this group if it was, in fact,
10780         ;; killed.  Gnus stores no information on killed groups, so
10781         ;; there's nothing to be done.
10782         ;; One could store the information somewhere temporarily,
10783         ;; perhaps...  Hmmm...
10784         ()
10785       ;; Remove any negative articles numbers.
10786       (while (and unread (< (car unread) 0))
10787         (setq unread (cdr unread)))
10788       ;; Remove any expired article numbers
10789       (while (and unread (< (car unread) (car active)))
10790         (setq unread (cdr unread)))
10791       ;; Compute the ranges of read articles by looking at the list of
10792       ;; unread articles.
10793       (while unread
10794         (when (/= (car unread) prev)
10795           (push (if (= prev (1- (car unread))) prev
10796                   (cons prev (1- (car unread))))
10797                 read))
10798         (setq prev (1+ (car unread)))
10799         (setq unread (cdr unread)))
10800       (when (<= prev (cdr active))
10801         (push (cons prev (cdr active)) read))
10802       (setq read (if (> (length read) 1) (nreverse read) read))
10803       (if compute
10804           read
10805         (save-excursion
10806           (let (setmarkundo)
10807             ;; Propagate the read marks to the backend.
10808             (when (gnus-check-backend-function 'request-set-mark group)
10809               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10810                     (add (gnus-remove-from-range read (gnus-info-read info))))
10811                 (when (or add del)
10812                   (unless (gnus-check-group group)
10813                     (error "Can't open server for %s" group))
10814                   (gnus-request-set-mark
10815                    group (delq nil (list (if add (list add 'add '(read)))
10816                                          (if del (list del 'del '(read))))))
10817                   (setq setmarkundo
10818                         `(gnus-request-set-mark
10819                           ,group
10820                           ',(delq nil (list
10821                                        (if del (list del 'add '(read)))
10822                                        (if add (list add 'del '(read))))))))))
10823             (set-buffer gnus-group-buffer)
10824             (gnus-undo-register
10825               `(progn
10826                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10827                  (gnus-info-set-read ',info ',(gnus-info-read info))
10828                  (gnus-get-unread-articles-in-group ',info
10829                                                     (gnus-active ,group))
10830                  (gnus-group-update-group ,group t)
10831                  ,setmarkundo))))
10832         ;; Enter this list into the group info.
10833         (gnus-info-set-read info read)
10834         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10835         (gnus-get-unread-articles-in-group info (gnus-active group))
10836         t))))
10837
10838 (defun gnus-offer-save-summaries ()
10839   "Offer to save all active summary buffers."
10840   (let (buffers)
10841     ;; Go through all buffers and find all summaries.
10842     (dolist (buffer (buffer-list))
10843       (when (and (setq buffer (buffer-name buffer))
10844                  (string-match "Summary" buffer)
10845                  (save-excursion
10846                    (set-buffer buffer)
10847                    ;; We check that this is, indeed, a summary buffer.
10848                    (and (eq major-mode 'gnus-summary-mode)
10849                         ;; Also make sure this isn't bogus.
10850                         gnus-newsgroup-prepared
10851                         ;; Also make sure that this isn't a
10852                         ;; dead summary buffer.
10853                         (not gnus-dead-summary-mode))))
10854         (push buffer buffers)))
10855     ;; Go through all these summary buffers and offer to save them.
10856     (when buffers
10857       (save-excursion
10858         (map-y-or-n-p
10859          "Update summary buffer %s? "
10860          (lambda (buf)
10861            (switch-to-buffer buf)
10862            (gnus-summary-exit))
10863          buffers)))))
10864
10865
10866 ;;; @ for mime-partial
10867 ;;;
10868
10869 (defun gnus-request-partial-message ()
10870   (save-excursion
10871     (let ((number (gnus-summary-article-number))
10872           (group gnus-newsgroup-name)
10873           (mother gnus-article-buffer))
10874       (set-buffer (get-buffer-create " *Partial Article*"))
10875       (erase-buffer)
10876       (setq mime-preview-buffer mother)
10877       (gnus-request-article-this-buffer number group)
10878       (mime-parse-buffer)
10879       )))
10880
10881 (autoload 'mime-combine-message/partial-pieces-automatically
10882   "mime-partial"
10883   "Internal method to combine message/partial messages automatically.")
10884
10885 (mime-add-condition
10886  'action '((type . message)(subtype . partial)
10887            (major-mode . gnus-original-article-mode)
10888            (method . mime-combine-message/partial-pieces-automatically)
10889            (summary-buffer-exp . gnus-summary-buffer)
10890            (request-partial-message-method . gnus-request-partial-message)
10891            ))
10892
10893
10894 ;;; @ for message/rfc822
10895 ;;;
10896
10897 (defun gnus-mime-extract-message/rfc822 (entity situation)
10898   "Burst a forwarded article."
10899   (save-excursion
10900     (set-buffer gnus-summary-buffer)
10901     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
10902                                    gnus-newsgroup-name 'gnus-group-history))
10903            (gnus-group-marked (list group))
10904            article info)
10905       (with-temp-buffer
10906         (mime-insert-entity-content entity)
10907         (setq article (gnus-request-accept-article group)))
10908       (when (and (consp article)
10909                  (numberp (setq article (cdr article))))
10910         (setq info (gnus-get-info group))
10911         (gnus-info-set-read info
10912                             (gnus-remove-from-range (gnus-info-read info)
10913                                                     (list article)))
10914         (when (string-equal group gnus-newsgroup-name)
10915           (forward-line 1)
10916           (let (gnus-show-threads)
10917             (gnus-summary-goto-subject article t))
10918           (gnus-summary-clear-mark-forward 1))
10919         (set-buffer gnus-group-buffer)
10920         (gnus-group-get-new-news-this-group nil t)))))
10921
10922 (mime-add-condition
10923  'action '((type . message)(subtype . rfc822)
10924            (major-mode . gnus-original-article-mode)
10925            (method . gnus-mime-extract-message/rfc822)
10926            (mode . "extract")
10927            ))
10928
10929 (mime-add-condition
10930  'action '((type . message)(subtype . news)
10931            (major-mode . gnus-original-article-mode)
10932            (method . gnus-mime-extract-message/rfc822)
10933            (mode . "extract")
10934            ))
10935
10936 (defun gnus-mime-extract-multipart (entity situation)
10937   (let ((children (mime-entity-children entity))
10938         mime-acting-situation-to-override
10939         f)
10940     (while children
10941       (mime-play-entity (car children)
10942                         (cons (assq 'mode situation)
10943                               mime-acting-situation-to-override))
10944       (setq children (cdr children)))
10945     (if (setq f (cdr (assq 'after-method
10946                            mime-acting-situation-to-override)))
10947         (eval f)
10948       )))
10949
10950 (mime-add-condition
10951  'action '((type . multipart)
10952            (method . gnus-mime-extract-multipart)
10953            (mode . "extract")
10954            )
10955  'with-default)
10956
10957
10958 ;;; @ end
10959 ;;;
10960
10961 (defun gnus-summary-setup-default-charset ()
10962   "Setup newsgroup default charset."
10963   (if (equal gnus-newsgroup-name "nndraft:drafts")
10964       (setq gnus-newsgroup-charset nil)
10965     (let* ((ignored-charsets
10966             (or gnus-newsgroup-ephemeral-ignored-charsets
10967                 (append
10968                  (and gnus-newsgroup-name
10969                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10970                  gnus-newsgroup-ignored-charsets))))
10971       (setq gnus-newsgroup-charset
10972             (or gnus-newsgroup-ephemeral-charset
10973                 (and gnus-newsgroup-name
10974                      (gnus-parameter-charset gnus-newsgroup-name))
10975                 gnus-default-charset))
10976       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10977            ignored-charsets))))
10978
10979 ;;;
10980 ;;; Mime Commands
10981 ;;;
10982
10983 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10984   "Display the current article buffer fully MIME-buttonized.
10985 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10986 treated as multipart/mixed."
10987   (interactive "P")
10988   (require 'gnus-art)
10989   (let ((gnus-unbuttonized-mime-types nil)
10990         (gnus-mime-display-multipart-as-mixed show-all-parts))
10991     (gnus-summary-show-article)))
10992
10993 (defun gnus-summary-repair-multipart (article)
10994   "Add a Content-Type header to a multipart article without one."
10995   (interactive (list (gnus-summary-article-number)))
10996   (gnus-with-article article
10997     (message-narrow-to-head)
10998     (message-remove-header "Mime-Version")
10999     (goto-char (point-max))
11000     (insert "Mime-Version: 1.0\n")
11001     (widen)
11002     (when (search-forward "\n--" nil t)
11003       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11004         (message-narrow-to-head)
11005         (message-remove-header "Content-Type")
11006         (goto-char (point-max))
11007         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11008                         separator))
11009         (widen))))
11010   (let (gnus-mark-article-hook)
11011     (gnus-summary-select-article t t nil article)))
11012
11013 (defun gnus-summary-toggle-display-buttonized ()
11014   "Toggle the buttonizing of the article buffer."
11015   (interactive)
11016   (require 'gnus-art)
11017   (if (setq gnus-inhibit-mime-unbuttonizing
11018             (not gnus-inhibit-mime-unbuttonizing))
11019       (let ((gnus-unbuttonized-mime-types nil))
11020         (gnus-summary-show-article))
11021     (gnus-summary-show-article)))
11022
11023 ;;;
11024 ;;; Intelli-mouse commmands
11025 ;;;
11026
11027 (defun gnus-wheel-summary-scroll (event)
11028   (interactive "e")
11029   (let ((amount (if (memq 'shift (event-modifiers event))
11030                     (car gnus-wheel-scroll-amount)
11031                   (cdr gnus-wheel-scroll-amount)))
11032         (direction (- (* (static-if (featurep 'xemacs)
11033                              (event-button event)
11034                            (cond ((eq 'mouse-4 (event-basic-type event))
11035                                   4)
11036                                  ((eq 'mouse-5 (event-basic-type event))
11037                                   5)))
11038                          2) 9))
11039         edge)
11040     (gnus-summary-scroll-up (* amount direction))
11041     (when (gnus-eval-in-buffer-window gnus-article-buffer
11042             (save-restriction
11043               (widen)
11044               (and (if (< 0 direction)
11045                        (gnus-article-next-page 0)
11046                      (gnus-article-prev-page 0)
11047                      (bobp))
11048                    (if (setq edge (get-text-property
11049                                    (point-min) 'gnus-wheel-edge))
11050                        (setq edge (* edge direction))
11051                      (setq edge -1))
11052                    (or (plusp edge)
11053                        (let ((buffer-read-only nil)
11054                              (inhibit-read-only t))
11055                          (put-text-property (point-min) (point-max)
11056                                             'gnus-wheel-edge direction)
11057                          nil))
11058                    (or (> edge gnus-wheel-edge-resistance)
11059                        (let ((buffer-read-only nil)
11060                              (inhibit-read-only t))
11061                          (put-text-property (point-min) (point-max)
11062                                             'gnus-wheel-edge
11063                                             (* (1+ edge) direction))
11064                          nil))
11065                    (eq last-command 'gnus-wheel-summary-scroll))))
11066       (gnus-summary-next-article nil nil (minusp direction)))))
11067
11068 (defun gnus-wheel-install ()
11069   "Enable mouse wheel support on summary window."
11070   (when gnus-use-wheel
11071     (let ((keys
11072            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11073       (dolist (key keys)
11074         (define-key gnus-summary-mode-map key
11075           'gnus-wheel-summary-scroll)))))
11076
11077 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11078
11079 ;;;
11080 ;;; Traditional PGP commmands
11081 ;;;
11082
11083 (defun gnus-summary-decrypt-article (&optional force)
11084   "Decrypt the current article in traditional PGP way.
11085 This will have permanent effect only in mail groups.
11086 If FORCE is non-nil, allow editing of articles even in read-only
11087 groups."
11088   (interactive "P")
11089   (gnus-summary-select-article t)
11090   (gnus-eval-in-buffer-window gnus-article-buffer
11091     (save-excursion
11092       (save-restriction
11093         (widen)
11094         (goto-char (point-min))
11095         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11096           (error "Not a traditional PGP message!"))
11097         (let ((armor-start (match-beginning 0)))
11098           (if (and (pgg-decrypt-region armor-start (point-max))
11099                    (or force (not (gnus-group-read-only-p))))
11100               (let ((inhibit-read-only t)
11101                     buffer-read-only)
11102                 (delete-region armor-start
11103                                (progn
11104                                  (re-search-forward "^-+END PGP" nil t)
11105                                  (beginning-of-line 2)
11106                                  (point)))
11107                 (insert-buffer-substring pgg-output-buffer))))))))
11108
11109 (defun gnus-summary-verify-article ()
11110   "Verify the current article in traditional PGP way."
11111   (interactive)
11112   (save-excursion
11113     (set-buffer gnus-original-article-buffer)
11114     (goto-char (point-min))
11115     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11116       (error "Not a traditional PGP message!"))
11117     (re-search-forward "^-+END PGP" nil t)
11118     (beginning-of-line 2)
11119     (call-interactively (function pgg-verify-region))))
11120
11121 ;;;
11122 ;;; Generic summary marking commands
11123 ;;;
11124
11125 (defvar gnus-summary-marking-alist
11126   '((read gnus-del-mark "d")
11127     (unread gnus-unread-mark "u")
11128     (ticked gnus-ticked-mark "!")
11129     (dormant gnus-dormant-mark "?")
11130     (expirable gnus-expirable-mark "e"))
11131   "An alist of names/marks/keystrokes.")
11132
11133 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11134 (defvar gnus-summary-mark-map)
11135
11136 (defun gnus-summary-make-all-marking-commands ()
11137   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11138   (dolist (elem gnus-summary-marking-alist)
11139     (apply 'gnus-summary-make-marking-command elem)))
11140
11141 (defun gnus-summary-make-marking-command (name mark keystroke)
11142   (let ((map (make-sparse-keymap)))
11143     (define-key gnus-summary-generic-mark-map keystroke map)
11144     (dolist (lway `((next "next" next nil "n")
11145                     (next-unread "next unread" next t "N")
11146                     (prev "previous" prev nil "p")
11147                     (prev-unread "previous unread" prev t "P")
11148                     (nomove "" nil nil ,keystroke)))
11149       (let ((func (gnus-summary-make-marking-command-1
11150                    mark (car lway) lway name)))
11151         (setq func (eval func))
11152         (define-key map (nth 4 lway) func)))))
11153
11154 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11155   `(defun ,(intern
11156             (format "gnus-summary-put-mark-as-%s%s"
11157                     name (if (eq way 'nomove)
11158                              ""
11159                            (concat "-" (symbol-name way)))))
11160      (n)
11161      ,(format
11162        "Mark the current article as %s%s.
11163 If N, the prefix, then repeat N times.
11164 If N is negative, move in reverse order.
11165 The difference between N and the actual number of articles marked is
11166 returned."
11167        name (car (cdr lway)))
11168      (interactive "p")
11169      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11170
11171 (defun gnus-summary-generic-mark (n mark move unread)
11172   "Mark N articles with MARK."
11173   (unless (eq major-mode 'gnus-summary-mode)
11174     (error "This command can only be used in the summary buffer"))
11175   (gnus-summary-show-thread)
11176   (let ((nummove
11177          (cond
11178           ((eq move 'next) 1)
11179           ((eq move 'prev) -1)
11180           (t 0))))
11181     (if (zerop nummove)
11182         (setq n 1)
11183       (when (< n 0)
11184         (setq n (abs n)
11185               nummove (* -1 nummove))))
11186     (while (and (> n 0)
11187                 (gnus-summary-mark-article nil mark)
11188                 (zerop (gnus-summary-next-subject nummove unread t)))
11189       (setq n (1- n)))
11190     (when (/= 0 n)
11191       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11192     (gnus-summary-recenter)
11193     (gnus-summary-position-point)
11194     (gnus-set-mode-line 'summary)
11195     n))
11196
11197 (defun gnus-summary-insert-articles (articles)
11198   (when (setq articles
11199               (gnus-sorted-difference articles
11200                                       (mapcar (lambda (h)
11201                                                 (mail-header-number h))
11202                                               gnus-newsgroup-headers)))
11203     (setq gnus-newsgroup-headers
11204           (merge 'list
11205                  gnus-newsgroup-headers
11206                  (gnus-fetch-headers articles)
11207                  'gnus-article-sort-by-number))
11208     ;; Suppress duplicates?
11209     (when gnus-suppress-duplicates
11210       (gnus-dup-suppress-articles))
11211
11212     ;; We might want to build some more threads first.
11213     (when (and gnus-fetch-old-headers
11214                (eq gnus-headers-retrieved-by 'nov))
11215       (if (eq gnus-fetch-old-headers 'invisible)
11216           (gnus-build-all-threads)
11217         (gnus-build-old-threads)))
11218     ;; Let the Gnus agent mark articles as read.
11219     (when gnus-agent
11220       (gnus-agent-get-undownloaded-list))
11221     ;; Remove list identifiers from subject
11222     (when gnus-list-identifiers
11223       (gnus-summary-remove-list-identifiers))
11224     ;; First and last article in this newsgroup.
11225     (when gnus-newsgroup-headers
11226       (setq gnus-newsgroup-begin
11227             (mail-header-number (car gnus-newsgroup-headers))
11228             gnus-newsgroup-end
11229             (mail-header-number
11230              (gnus-last-element gnus-newsgroup-headers))))
11231     (when gnus-use-scoring
11232       (gnus-possibly-score-headers))))
11233
11234 (defun gnus-summary-insert-old-articles (&optional all)
11235   "Insert all old articles in this group.
11236 If ALL is non-nil, already read articles become readable.
11237 If ALL is a number, fetch this number of articles."
11238   (interactive "P")
11239   (prog1
11240       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11241             older len)
11242         (setq older
11243               (gnus-sorted-difference
11244                (gnus-uncompress-range (list gnus-newsgroup-active))
11245                old))
11246         (setq len (length older))
11247         (cond
11248          ((null older) nil)
11249          ((numberp all)
11250           (if (< all len)
11251               (setq older (last older all))))
11252          (all nil)
11253          (t
11254           (if (and (numberp gnus-large-newsgroup)
11255                    (> len gnus-large-newsgroup))
11256               (let ((input
11257                      (read-string
11258                       (format
11259                        "How many articles from %s (default %d): "
11260                        (gnus-limit-string
11261                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
11262                        len))))
11263                 (unless (string-match "^[ \t]*$" input)
11264                   (setq all (string-to-number input))
11265                   (if (< all len)
11266                       (setq older (last older all))))))))
11267         (if (not older)
11268             (message "No old news.")
11269           (gnus-summary-insert-articles older)
11270           (gnus-summary-limit (gnus-sorted-nunion old older))))
11271     (gnus-summary-position-point)))
11272
11273 (defun gnus-summary-insert-new-articles ()
11274   "Insert all new articles in this group."
11275   (interactive)
11276   (prog1
11277       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11278             (old-active gnus-newsgroup-active)
11279             (nnmail-fetched-sources (list t))
11280             i new)
11281         (setq gnus-newsgroup-active
11282               (gnus-activate-group gnus-newsgroup-name 'scan))
11283         (setq i (1+ (cdr old-active)))
11284         (while (<= i (cdr gnus-newsgroup-active))
11285           (push i new)
11286           (incf i))
11287         (if (not new)
11288             (message "No gnus is bad news.")
11289           (setq new (nreverse new))
11290           (gnus-summary-insert-articles new)
11291           (setq gnus-newsgroup-unreads
11292                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11293           (gnus-summary-limit (gnus-sorted-nunion old new))))
11294     (gnus-summary-position-point)))
11295
11296 (gnus-summary-make-all-marking-commands)
11297
11298 (gnus-ems-redefine)
11299
11300 (provide 'gnus-sum)
11301
11302 (run-hooks 'gnus-sum-load-hook)
11303
11304 ;;; gnus-sum.el ends here