Synch with Oort Gnus.
[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
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 ;; Recursive :-(.
42 ;; (require 'gnus-art)
43 (require 'nnoo)
44 (require 'mime-view)
45
46 (eval-when-compile
47   (require 'mime-play)
48   (require 'static))
49
50 (eval-and-compile
51   (autoload 'pgg-decrypt-region "pgg" nil t)
52   (autoload 'pgg-verify-region "pgg" nil t))
53
54 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
55 (autoload 'gnus-cache-write-active "gnus-cache")
56 (autoload 'gnus-set-summary-default-charset "gnus-i18n" nil t)
57 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
58 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
59 (autoload 'mm-uu-dissect "mm-uu")
60
61 (defcustom gnus-kill-summary-on-exit t
62   "*If non-nil, kill the summary buffer when you exit from it.
63 If nil, the summary will become a \"*Dead Summary*\" buffer, and
64 it will be killed sometime later."
65   :group 'gnus-summary-exit
66   :type 'boolean)
67
68 (defcustom gnus-fetch-old-headers nil
69   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
70 If an unread article in the group refers to an older, already read (or
71 just marked as read) article, the old article will not normally be
72 displayed in the Summary buffer.  If this variable is non-nil, Gnus
73 will attempt to grab the headers to the old articles, and thereby
74 build complete threads.  If it has the value `some', only enough
75 headers to connect otherwise loose threads will be displayed.  This
76 variable can also be a number.  In that case, no more than that number
77 of old headers will be fetched.  If it has the value `invisible', all
78 old headers will be fetched, but none will be displayed.
79
80 The server has to support NOV for any of this to work."
81   :group 'gnus-thread
82   :type '(choice (const :tag "off" nil)
83                  (const some)
84                  number
85                  (sexp :menu-tag "other" t)))
86
87 (defcustom gnus-refer-thread-limit 200
88   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
89 If t, fetch all the available old headers."
90   :group 'gnus-thread
91   :type '(choice number
92                  (sexp :menu-tag "other" t)))
93
94 (defcustom gnus-summary-make-false-root 'adopt
95   "*nil means that Gnus won't gather loose threads.
96 If the root of a thread has expired or been read in a previous
97 session, the information necessary to build a complete thread has been
98 lost.  Instead of having many small sub-threads from this original thread
99 scattered all over the summary buffer, Gnus can gather them.
100
101 If non-nil, Gnus will try to gather all loose sub-threads from an
102 original thread into one large thread.
103
104 If this variable is non-nil, it should be one of `none', `adopt',
105 `dummy' or `empty'.
106
107 If this variable is `none', Gnus will not make a false root, but just
108 present the sub-threads after another.
109 If this variable is `dummy', Gnus will create a dummy root that will
110 have all the sub-threads as children.
111 If this variable is `adopt', Gnus will make one of the \"children\"
112 the parent and mark all the step-children as such.
113 If this variable is `empty', the \"children\" are printed with empty
114 subject fields.  (Or rather, they will be printed with a string
115 given by the `gnus-summary-same-subject' variable.)"
116   :group 'gnus-thread
117   :type '(choice (const :tag "off" nil)
118                  (const none)
119                  (const dummy)
120                  (const adopt)
121                  (const empty)))
122
123 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
124   "*A regexp to match subjects to be excluded from loose thread gathering.
125 As loose thread gathering is done on subjects only, that means that
126 there can be many false gatherings performed.  By rooting out certain
127 common subjects, gathering might become saner."
128   :group 'gnus-thread
129   :type 'regexp)
130
131 (defcustom gnus-summary-gather-subject-limit nil
132   "*Maximum length of subject comparisons when gathering loose threads.
133 Use nil to compare full subjects.  Setting this variable to a low
134 number will help gather threads that have been corrupted by
135 newsreaders chopping off subject lines, but it might also mean that
136 unrelated articles that have subject that happen to begin with the
137 same few characters will be incorrectly gathered.
138
139 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
140 comparing subjects."
141   :group 'gnus-thread
142   :type '(choice (const :tag "off" nil)
143                  (const fuzzy)
144                  (sexp :menu-tag "on" t)))
145
146 (defcustom gnus-simplify-subject-functions nil
147   "List of functions taking a string argument that simplify subjects.
148 The functions are applied recursively.
149
150 Useful functions to put in this list include: `gnus-simplify-subject-re',
151 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
152   :group 'gnus-thread
153   :type '(repeat function))
154
155 (defcustom gnus-simplify-ignored-prefixes nil
156   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
157   :group 'gnus-thread
158   :type '(choice (const :tag "off" nil)
159                  regexp))
160
161 (defcustom gnus-build-sparse-threads nil
162   "*If non-nil, fill in the gaps in threads.
163 If `some', only fill in the gaps that are needed to tie loose threads
164 together.  If `more', fill in all leaf nodes that Gnus can find.  If
165 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
166   :group 'gnus-thread
167   :type '(choice (const :tag "off" nil)
168                  (const some)
169                  (const more)
170                  (sexp :menu-tag "all" t)))
171
172 (defcustom gnus-summary-thread-gathering-function
173   'gnus-gather-threads-by-subject
174   "*Function used for gathering loose threads.
175 There are two pre-defined functions: `gnus-gather-threads-by-subject',
176 which only takes Subjects into consideration; and
177 `gnus-gather-threads-by-references', which compared the References
178 headers of the articles to find matches."
179   :group 'gnus-thread
180   :type '(radio (function-item gnus-gather-threads-by-subject)
181                 (function-item gnus-gather-threads-by-references)
182                 (function :tag "other")))
183
184 (defcustom gnus-summary-same-subject ""
185   "*String indicating that the current article has the same subject as the previous.
186 This variable will only be used if the value of
187 `gnus-summary-make-false-root' is `empty'."
188   :group 'gnus-summary-format
189   :type 'string)
190
191 (defcustom gnus-summary-goto-unread t
192   "*If t, many commands will go to the next unread article.
193 This applies to marking commands as well as other commands that
194 \"naturally\" select the next article, like, for instance, `SPC' at
195 the end of an article.
196
197 If nil, the marking commands do NOT go to the next unread article
198 (they go to the next article instead).  If `never', commands that
199 usually go to the next unread article, will go to the next article,
200 whether it is read or not."
201   :group 'gnus-summary-marks
202   :link '(custom-manual "(gnus)Setting Marks")
203   :type '(choice (const :tag "off" nil)
204                  (const never)
205                  (sexp :menu-tag "on" t)))
206
207 (defcustom gnus-summary-default-score 0
208   "*Default article score level.
209 All scores generated by the score files will be added to this score.
210 If this variable is nil, scoring will be disabled."
211   :group 'gnus-score-default
212   :type '(choice (const :tag "disable")
213                  integer))
214
215 (defcustom gnus-summary-default-high-score 0
216   "*Default threshold for a high scored article.
217 An article will be highlighted as high scored if its score is greater
218 than this score."
219   :group 'gnus-score-default
220   :type 'integer)
221
222 (defcustom gnus-summary-default-low-score 0
223   "*Default threshold for a low scored article.
224 An article will be highlighted as low scored if its score is smaller
225 than this score."
226   :group 'gnus-score-default
227   :type 'integer)
228
229 (defcustom gnus-summary-zcore-fuzz 0
230   "*Fuzziness factor for the zcore in the summary buffer.
231 Articles with scores closer than this to `gnus-summary-default-score'
232 will not be marked."
233   :group 'gnus-summary-format
234   :type 'integer)
235
236 (defcustom gnus-simplify-subject-fuzzy-regexp nil
237   "*Strings to be removed when doing fuzzy matches.
238 This can either be a regular expression or list of regular expressions
239 that will be removed from subject strings if fuzzy subject
240 simplification is selected."
241   :group 'gnus-thread
242   :type '(repeat regexp))
243
244 (defcustom gnus-show-threads t
245   "*If non-nil, display threads in summary mode."
246   :group 'gnus-thread
247   :type 'boolean)
248
249 (defcustom gnus-thread-hide-subtree nil
250   "*If non-nil, hide all threads initially.
251 If threads are hidden, you have to run the command
252 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
253 to expose hidden threads."
254   :group 'gnus-thread
255   :type 'boolean)
256
257 (defcustom gnus-thread-hide-killed t
258   "*If non-nil, hide killed threads automatically."
259   :group 'gnus-thread
260   :type 'boolean)
261
262 (defcustom gnus-thread-ignore-subject t
263   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
264 If nil, articles that have different subjects from their parents will
265 start separate threads."
266   :group 'gnus-thread
267   :type 'boolean)
268
269 (defcustom gnus-thread-operation-ignore-subject t
270   "*If non-nil, subjects will be ignored when doing thread commands.
271 This affects commands like `gnus-summary-kill-thread' and
272 `gnus-summary-lower-thread'.
273
274 If this variable is nil, articles in the same thread with different
275 subjects will not be included in the operation in question.  If this
276 variable is `fuzzy', only articles that have subjects that are fuzzily
277 equal will be included."
278   :group 'gnus-thread
279   :type '(choice (const :tag "off" nil)
280                  (const fuzzy)
281                  (sexp :tag "on" t)))
282
283 (defcustom gnus-thread-indent-level 4
284   "*Number that says how much each sub-thread should be indented."
285   :group 'gnus-thread
286   :type 'integer)
287
288 (defcustom gnus-auto-extend-newsgroup t
289   "*If non-nil, extend newsgroup forward and backward when requested."
290   :group 'gnus-summary-choose
291   :type 'boolean)
292
293 (defcustom gnus-auto-select-first t
294   "*If nil, don't select the first unread article when entering a group.
295 If this variable is `best', select the highest-scored unread article
296 in the group.  If t, select the first unread article.
297
298 This variable can also be a function to place point on a likely
299 subject line.  Useful values include `gnus-summary-first-unread-subject',
300 `gnus-summary-first-unread-article' and
301 `gnus-summary-best-unread-article'.
302
303 If you want to prevent automatic selection of the first unread article
304 in some newsgroups, set the variable to nil in
305 `gnus-select-group-hook'."
306   :group 'gnus-group-select
307   :type '(choice (const :tag "none" nil)
308                  (const best)
309                  (sexp :menu-tag "first" t)
310                  (function-item gnus-summary-first-unread-subject)
311                  (function-item gnus-summary-first-unread-article)
312                  (function-item gnus-summary-best-unread-article)))
313
314 (defcustom gnus-dont-select-after-jump-to-other-group nil
315   "If non-nil, don't select the first unread article after entering the
316 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
317 it is depend on the value of `gnus-auto-select-first' whether to select
318 or not."
319   :group 'gnus-group-select
320   :type 'boolean)
321
322 (defcustom gnus-auto-select-next t
323   "*If non-nil, offer to go to the next group from the end of the previous.
324 If the value is t and the next newsgroup is empty, Gnus will exit
325 summary mode and go back to group mode.  If the value is neither nil
326 nor t, Gnus will select the following unread newsgroup.  In
327 particular, if the value is the symbol `quietly', the next unread
328 newsgroup will be selected without any confirmation, and if it is
329 `almost-quietly', the next group will be selected without any
330 confirmation if you are located on the last article in the group.
331 Finally, if this variable is `slightly-quietly', the `Z n' command
332 will go to the next group without confirmation."
333   :group 'gnus-summary-maneuvering
334   :type '(choice (const :tag "off" nil)
335                  (const quietly)
336                  (const almost-quietly)
337                  (const slightly-quietly)
338                  (sexp :menu-tag "on" t)))
339
340 (defcustom gnus-auto-select-same nil
341   "*If non-nil, select the next article with the same subject.
342 If there are no more articles with the same subject, go to
343 the first unread article."
344   :group 'gnus-summary-maneuvering
345   :type 'boolean)
346
347 (defcustom gnus-summary-check-current nil
348   "*If non-nil, consider the current article when moving.
349 The \"unread\" movement commands will stay on the same line if the
350 current article is unread."
351   :group 'gnus-summary-maneuvering
352   :type 'boolean)
353
354 (defcustom gnus-auto-center-summary t
355   "*If non-nil, always center the current summary buffer.
356 In particular, if `vertical' do only vertical recentering.  If non-nil
357 and non-`vertical', do both horizontal and vertical recentering."
358   :group 'gnus-summary-maneuvering
359   :type '(choice (const :tag "none" nil)
360                  (const vertical)
361                  (integer :tag "height")
362                  (sexp :menu-tag "both" t)))
363
364 (defcustom gnus-show-all-headers nil
365   "*If non-nil, don't hide any headers."
366   :group 'gnus-article-hiding
367   :group 'gnus-article-headers
368   :type 'boolean)
369
370 (defcustom gnus-summary-ignore-duplicates nil
371   "*If non-nil, ignore articles with identical Message-ID headers."
372   :group 'gnus-summary
373   :type 'boolean)
374
375 (defcustom gnus-single-article-buffer t
376   "*If non-nil, display all articles in the same buffer.
377 If nil, each group will get its own article buffer."
378   :group 'gnus-article-various
379   :type 'boolean)
380
381 (defcustom gnus-break-pages t
382   "*If non-nil, do page breaking on articles.
383 The page delimiter is specified by the `gnus-page-delimiter'
384 variable."
385   :group 'gnus-article-various
386   :type 'boolean)
387
388 (defcustom gnus-show-mime t
389   "*If non-nil, do mime processing of articles.
390 The articles will simply be fed to the function given by
391 `gnus-article-display-method-for-mime'."
392   :group 'gnus-article-mime
393   :type 'boolean)
394
395 (defcustom gnus-move-split-methods nil
396   "*Variable used to suggest where articles are to be moved to.
397 It uses the same syntax as the `gnus-split-methods' variable.
398 However, whereas `gnus-split-methods' specifies file names as targets,
399 this variable specifies group names."
400   :group 'gnus-summary-mail
401   :type '(repeat (choice (list :value (fun) function)
402                          (cons :value ("" "") regexp (repeat string))
403                          (sexp :value nil))))
404
405 (defcustom gnus-unread-mark ?\ ;;;Whitespace
406   "*Mark used for unread articles."
407   :group 'gnus-summary-marks
408   :type 'character)
409
410 (defcustom gnus-ticked-mark ?!
411   "*Mark used for ticked articles."
412   :group 'gnus-summary-marks
413   :type 'character)
414
415 (defcustom gnus-dormant-mark ??
416   "*Mark used for dormant articles."
417   :group 'gnus-summary-marks
418   :type 'character)
419
420 (defcustom gnus-del-mark ?r
421   "*Mark used for del'd articles."
422   :group 'gnus-summary-marks
423   :type 'character)
424
425 (defcustom gnus-read-mark ?R
426   "*Mark used for read articles."
427   :group 'gnus-summary-marks
428   :type 'character)
429
430 (defcustom gnus-expirable-mark ?E
431   "*Mark used for expirable articles."
432   :group 'gnus-summary-marks
433   :type 'character)
434
435 (defcustom gnus-killed-mark ?K
436   "*Mark used for killed articles."
437   :group 'gnus-summary-marks
438   :type 'character)
439
440 (defcustom gnus-souped-mark ?F
441   "*Mark used for souped articles."
442   :group 'gnus-summary-marks
443   :type 'character)
444
445 (defcustom gnus-kill-file-mark ?X
446   "*Mark used for articles killed by kill files."
447   :group 'gnus-summary-marks
448   :type 'character)
449
450 (defcustom gnus-low-score-mark ?Y
451   "*Mark used for articles with a low score."
452   :group 'gnus-summary-marks
453   :type 'character)
454
455 (defcustom gnus-catchup-mark ?C
456   "*Mark used for articles that are caught up."
457   :group 'gnus-summary-marks
458   :type 'character)
459
460 (defcustom gnus-replied-mark ?A
461   "*Mark used for articles that have been replied to."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-forwarded-mark ?O
466   "*Mark used for articles that have been forwarded."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-recent-mark ?N
471   "*Mark used for articles that are recent."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-cached-mark ?*
476   "*Mark used for articles that are in the cache."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-saved-mark ?S
481   "*Mark used for articles that have been saved to."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-no-mark ?\ ;;;Whitespace
486   "*Mark used for articles that have no other secondary mark."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-ancient-mark ?O
491   "*Mark used for ancient articles."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-sparse-mark ?Q
496   "*Mark used for sparsely reffed articles."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-canceled-mark ?G
501   "*Mark used for canceled articles."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-duplicate-mark ?M
506   "*Mark used for duplicate articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-undownloaded-mark ?@
511   "*Mark used for articles that weren't downloaded."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-downloadable-mark ?%
516   "*Mark used for articles that are to be downloaded."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-unsendable-mark ?=
521   "*Mark used for articles that won't be sent."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-score-over-mark ?+
526   "*Score mark used for articles with high scores."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-score-below-mark ?-
531   "*Score mark used for articles with low scores."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
536   "*There is no thread under the article."
537   :group 'gnus-summary-marks
538   :type 'character)
539
540 (defcustom gnus-not-empty-thread-mark ?=
541   "*There is a thread under the article."
542   :group 'gnus-summary-marks
543   :type 'character)
544
545 (defcustom gnus-view-pseudo-asynchronously nil
546   "*If non-nil, Gnus will view pseudo-articles asynchronously."
547   :group 'gnus-extract-view
548   :type 'boolean)
549
550 (defcustom gnus-auto-expirable-marks
551   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
552         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
553         gnus-souped-mark gnus-duplicate-mark)
554   "*The list of marks converted into expiration if a group is auto-expirable."
555   :version "21.1"
556   :group 'gnus-summary
557   :type '(repeat character))
558
559 (defcustom gnus-inhibit-user-auto-expire t
560   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
561   :version "21.1"
562   :group 'gnus-summary
563   :type 'boolean)
564
565 (defcustom gnus-view-pseudos nil
566   "*If `automatic', pseudo-articles will be viewed automatically.
567 If `not-confirm', pseudos will be viewed automatically, and the user
568 will not be asked to confirm the command."
569   :group 'gnus-extract-view
570   :type '(choice (const :tag "off" nil)
571                  (const automatic)
572                  (const not-confirm)))
573
574 (defcustom gnus-view-pseudos-separately t
575   "*If non-nil, one pseudo-article will be created for each file to be viewed.
576 If nil, all files that use the same viewing command will be given as a
577 list of parameters to that command."
578   :group 'gnus-extract-view
579   :type 'boolean)
580
581 (defcustom gnus-insert-pseudo-articles t
582   "*If non-nil, insert pseudo-articles when decoding articles."
583   :group 'gnus-extract-view
584   :type 'boolean)
585
586 (defcustom gnus-summary-dummy-line-format
587   "  %(:                          :%) %S\n"
588   "*The format specification for the dummy roots in the summary buffer.
589 It works along the same lines as a normal formatting string,
590 with some simple extensions.
591
592 %S  The subject"
593   :group 'gnus-threading
594   :type 'string)
595
596 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
597   "*The format specification for the summary mode line.
598 It works along the same lines as a normal formatting string,
599 with some simple extensions:
600
601 %G  Group name
602 %p  Unprefixed group name
603 %A  Current article number
604 %z  Current article score
605 %V  Gnus version
606 %U  Number of unread articles in the group
607 %e  Number of unselected articles in the group
608 %Z  A string with unread/unselected article counts
609 %g  Shortish group name
610 %S  Subject of the current article
611 %u  User-defined spec
612 %s  Current score file name
613 %d  Number of dormant articles
614 %r  Number of articles that have been marked as read in this session
615 %E  Number of articles expunged by the score files"
616   :group 'gnus-summary-format
617   :type 'string)
618
619 (defcustom gnus-list-identifiers nil
620   "Regexp that matches list identifiers to be removed from subject.
621 This can also be a list of regexps."
622   :version "21.1"
623   :group 'gnus-summary-format
624   :group 'gnus-article-hiding
625   :type '(choice (const :tag "none" nil)
626                  (regexp :value ".*")
627                  (repeat :value (".*") regexp)))
628
629 (defcustom gnus-summary-mark-below 0
630   "*Mark all articles with a score below this variable as read.
631 This variable is local to each summary buffer and usually set by the
632 score file."
633   :group 'gnus-score-default
634   :type 'integer)
635
636 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
637   "*List of functions used for sorting articles in the summary buffer.
638
639 Each function takes two articles and returns non-nil if the first
640 article should be sorted before the other.  If you use more than one
641 function, the primary sort function should be the last.  You should
642 probably always include `gnus-article-sort-by-number' in the list of
643 sorting functions -- preferably first.  Also note that sorting by date
644 is often much slower than sorting by number, and the sorting order is
645 very similar.  (Sorting by date means sorting by the time the message
646 was sent, sorting by number means sorting by arrival time.)
647
648 Ready-made functions include `gnus-article-sort-by-number',
649 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
650 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
651
652 When threading is turned on, the variable `gnus-thread-sort-functions'
653 controls how articles are sorted."
654   :group 'gnus-summary-sort
655   :type '(repeat (choice (function-item gnus-article-sort-by-number)
656                          (function-item gnus-article-sort-by-author)
657                          (function-item gnus-article-sort-by-subject)
658                          (function-item gnus-article-sort-by-date)
659                          (function-item gnus-article-sort-by-score)
660                          (function :tag "other"))))
661
662 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
663   "*List of functions used for sorting threads in the summary buffer.
664 By default, threads are sorted by article number.
665
666 Each function takes two threads and returns non-nil if the first
667 thread should be sorted before the other.  If you use more than one
668 function, the primary sort function should be the last.  You should
669 probably always include `gnus-thread-sort-by-number' in the list of
670 sorting functions -- preferably first.  Also note that sorting by date
671 is often much slower than sorting by number, and the sorting order is
672 very similar.  (Sorting by date means sorting by the time the message
673 was sent, sorting by number means sorting by arrival time.)
674
675 Ready-made functions include `gnus-thread-sort-by-number',
676 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
677 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
678 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
679
680 When threading is turned off, the variable
681 `gnus-article-sort-functions' controls how articles are sorted."
682   :group 'gnus-summary-sort
683   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
684                          (function-item gnus-thread-sort-by-author)
685                          (function-item gnus-thread-sort-by-subject)
686                          (function-item gnus-thread-sort-by-date)
687                          (function-item gnus-thread-sort-by-score)
688                          (function-item gnus-thread-sort-by-total-score)
689                          (function :tag "other"))))
690
691 (defcustom gnus-thread-score-function '+
692   "*Function used for calculating the total score of a thread.
693
694 The function is called with the scores of the article and each
695 subthread and should then return the score of the thread.
696
697 Some functions you can use are `+', `max', or `min'."
698   :group 'gnus-summary-sort
699   :type 'function)
700
701 (defcustom gnus-summary-expunge-below nil
702   "All articles that have a score less than this variable will be expunged.
703 This variable is local to the summary buffers."
704   :group 'gnus-score-default
705   :type '(choice (const :tag "off" nil)
706                  integer))
707
708 (defcustom gnus-thread-expunge-below nil
709   "All threads that have a total score less than this variable will be expunged.
710 See `gnus-thread-score-function' for en explanation of what a
711 \"thread score\" is.
712
713 This variable is local to the summary buffers."
714   :group 'gnus-threading
715   :group 'gnus-score-default
716   :type '(choice (const :tag "off" nil)
717                  integer))
718
719 (defcustom gnus-summary-mode-hook nil
720   "*A hook for Gnus summary mode.
721 This hook is run before any variables are set in the summary buffer."
722   :options '(turn-on-gnus-mailing-list-mode)
723   :group 'gnus-summary-various
724   :type 'hook)
725
726 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
727 (when (featurep 'xemacs)
728   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
729   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
730   (add-hook 'gnus-summary-mode-hook
731             'gnus-xmas-switch-horizontal-scrollbar-off))
732
733 (defcustom gnus-summary-menu-hook nil
734   "*Hook run after the creation of the summary mode menu."
735   :group 'gnus-summary-visual
736   :type 'hook)
737
738 (defcustom gnus-summary-exit-hook nil
739   "*A hook called on exit from the summary buffer.
740 It will be called with point in the group buffer."
741   :group 'gnus-summary-exit
742   :type 'hook)
743
744 (defcustom gnus-summary-prepare-hook nil
745   "*A hook called after the summary buffer has been generated.
746 If you want to modify the summary buffer, you can use this hook."
747   :group 'gnus-summary-various
748   :type 'hook)
749
750 (defcustom gnus-summary-prepared-hook nil
751   "*A hook called as the last thing after the summary buffer has been generated."
752   :group 'gnus-summary-various
753   :type 'hook)
754
755 (defcustom gnus-summary-generate-hook nil
756   "*A hook run just before generating the summary buffer.
757 This hook is commonly used to customize threading variables and the
758 like."
759   :group 'gnus-summary-various
760   :type 'hook)
761
762 (defcustom gnus-select-group-hook nil
763   "*A hook called when a newsgroup is selected.
764
765 If you'd like to simplify subjects like the
766 `gnus-summary-next-same-subject' command does, you can use the
767 following hook:
768
769  (setq gnus-select-group-hook
770       (list
771         (lambda ()
772           (mapcar (lambda (header)
773                      (mail-header-set-subject
774                       header
775                       (gnus-simplify-subject
776                        (mail-header-subject header) 're-only)))
777                   gnus-newsgroup-headers))))"
778   :group 'gnus-group-select
779   :type 'hook)
780
781 (defcustom gnus-select-article-hook nil
782   "*A hook called when an article is selected."
783   :group 'gnus-summary-choose
784   :type 'hook)
785
786 (defcustom gnus-visual-mark-article-hook
787   (list 'gnus-highlight-selected-summary)
788   "*Hook run after selecting an article in the summary buffer.
789 It is meant to be used for highlighting the article in some way.  It
790 is not run if `gnus-visual' is nil."
791   :group 'gnus-summary-visual
792   :type 'hook)
793
794 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
795   "*A hook called before parsing the headers."
796   :group 'gnus-various
797   :type 'hook)
798
799 (defcustom gnus-exit-group-hook nil
800   "*A hook called when exiting summary mode.
801 This hook is not called from the non-updating exit commands like `Q'."
802   :group 'gnus-various
803   :type 'hook)
804
805 (defcustom gnus-summary-update-hook
806   (list 'gnus-summary-highlight-line)
807   "*A hook called when a summary line is changed.
808 The hook will not be called if `gnus-visual' is nil.
809
810 The default function `gnus-summary-highlight-line' will
811 highlight the line according to the `gnus-summary-highlight'
812 variable."
813   :group 'gnus-summary-visual
814   :type 'hook)
815
816 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
817   "*A hook called when an article is selected for the first time.
818 The hook is intended to mark an article as read (or unread)
819 automatically when it is selected."
820   :group 'gnus-summary-choose
821   :type 'hook)
822
823 (defcustom gnus-group-no-more-groups-hook nil
824   "*A hook run when returning to group mode having no more (unread) groups."
825   :group 'gnus-group-select
826   :type 'hook)
827
828 (defcustom gnus-ps-print-hook nil
829   "*A hook run before ps-printing something from Gnus."
830   :group 'gnus-summary
831   :type 'hook)
832
833 (defcustom gnus-summary-display-arrow
834   (and (fboundp 'display-graphic-p)
835        (display-graphic-p))
836   "*If non-nil, display an arrow highlighting the current article."
837   :version "21.1"
838   :group 'gnus-summary
839   :type 'boolean)
840
841 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
842   "Face used for highlighting the current article in the summary buffer."
843   :group 'gnus-summary-visual
844   :type 'face)
845
846 (defcustom gnus-summary-highlight
847   '(((= mark gnus-canceled-mark)
848      . gnus-summary-cancelled-face)
849     ((and (> score default-high)
850           (or (= mark gnus-dormant-mark)
851               (= mark gnus-ticked-mark)))
852      . gnus-summary-high-ticked-face)
853     ((and (< score default-low)
854           (or (= mark gnus-dormant-mark)
855               (= mark gnus-ticked-mark)))
856      . gnus-summary-low-ticked-face)
857     ((or (= mark gnus-dormant-mark)
858          (= mark gnus-ticked-mark))
859      . gnus-summary-normal-ticked-face)
860     ((and (> score default-high) (= mark gnus-ancient-mark))
861      . gnus-summary-high-ancient-face)
862     ((and (< score default-low) (= mark gnus-ancient-mark))
863      . gnus-summary-low-ancient-face)
864     ((= mark gnus-ancient-mark)
865      . gnus-summary-normal-ancient-face)
866     ((and (> score default-high) (= mark gnus-unread-mark))
867      . gnus-summary-high-unread-face)
868     ((and (< score default-low) (= mark gnus-unread-mark))
869      . gnus-summary-low-unread-face)
870     ((= mark gnus-unread-mark)
871      . gnus-summary-normal-unread-face)
872     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
873                                                   gnus-undownloaded-mark)))
874      . gnus-summary-high-unread-face)
875     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
876                                                  gnus-undownloaded-mark)))
877      . gnus-summary-low-unread-face)
878     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
879           (memq article gnus-newsgroup-unreads))
880      . gnus-summary-normal-unread-face)
881     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
882      . gnus-summary-normal-read-face)
883     ((> score default-high)
884      . gnus-summary-high-read-face)
885     ((< score default-low)
886      . gnus-summary-low-read-face)
887     (t
888      . gnus-summary-normal-read-face))
889   "*Controls the highlighting of summary buffer lines.
890
891 A list of (FORM . FACE) pairs.  When deciding how a a particular
892 summary line should be displayed, each form is evaluated.  The content
893 of the face field after the first true form is used.  You can change
894 how those summary lines are displayed, by editing the face field.
895
896 You can use the following variables in the FORM field.
897
898 score:        The article's score
899 default:      The default article score.
900 default-high: The default score for high scored articles.
901 default-low:  The default score for low scored articles.
902 below:        The score below which articles are automatically marked as read.
903 mark:         The articles mark."
904   :group 'gnus-summary-visual
905   :type '(repeat (cons (sexp :tag "Form" nil)
906                        face)))
907
908 (defcustom gnus-alter-header-function nil
909   "Function called to allow alteration of article header structures.
910 The function is called with one parameter, the article header vector,
911 which it may alter in any way.")
912
913 (defvar gnus-decode-encoded-word-function
914   (mime-find-field-decoder 'From 'nov)
915   "Variable that says which function should be used to decode a string with encoded words.")
916
917 (defcustom gnus-extra-headers nil
918   "*Extra headers to parse."
919   :version "21.1"
920   :group 'gnus-summary
921   :type '(repeat symbol))
922
923 (defcustom gnus-ignored-from-addresses
924   (and user-mail-address (regexp-quote user-mail-address))
925   "*Regexp of From headers that may be suppressed in favor of To headers."
926   :version "21.1"
927   :group 'gnus-summary
928   :type 'regexp)
929
930 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
931   "List of charsets that should be ignored.
932 When these charsets are used in the \"charset\" parameter, the
933 default charset will be used instead."
934   :version "21.1"
935   :type '(repeat symbol)
936   :group 'gnus-charset)
937
938 (gnus-define-group-parameter
939  ignored-charsets
940  :type list
941  :function-document
942  "Return the ignored charsets of GROUP."
943  :variable gnus-group-ignored-charsets-alist
944  :variable-default
945  '(("alt\\.chinese\\.text" iso-8859-1))
946  :variable-document
947  "Alist of regexps (to match group names) and charsets that should be ignored.
948 When these charsets are used in the \"charset\" parameter, the
949 default charset will be used instead."
950  :variable-group gnus-charset
951  :variable-type '(repeat (cons (regexp :tag "Group")
952                                (repeat symbol)))
953  :parameter-type '(choice :tag "Ignored charsets"
954                           :value nil
955                           (repeat (symbol)))
956  :parameter-document       "\
957 List of charsets that should be ignored.
958
959 When these charsets are used in the \"charset\" parameter, the
960 default charset will be used instead.")
961
962 (defcustom gnus-group-highlight-words-alist nil
963   "Alist of group regexps and highlight regexps.
964 This variable uses the same syntax as `gnus-emphasis-alist'."
965   :version "21.1"
966   :type '(repeat (cons (regexp :tag "Group")
967                        (repeat (list (regexp :tag "Highlight regexp")
968                                      (number :tag "Group for entire word" 0)
969                                      (number :tag "Group for displayed part" 0)
970                                      (symbol :tag "Face"
971                                              gnus-emphasis-highlight-words)))))
972   :group 'gnus-summary-visual)
973
974 (defcustom gnus-use-wheel nil
975   "Use Intelli-mouse on summary movement"
976   :type 'boolean
977   :group 'gnus-summary-maneuvering)
978
979 (defcustom gnus-wheel-scroll-amount '(5 . 1)
980   "Amount to scroll messages by spinning the mouse wheel.
981 This is actually a cons cell, where the first item is the amount to scroll
982 on a normal wheel event, and the second is the amount to scroll when the
983 wheel is moved with the shift key depressed."
984   :type '(cons (integer :tag "Shift") integer)
985   :group 'gnus-summary-maneuvering)
986
987 (defcustom gnus-wheel-edge-resistance 2
988   "How hard it should be to change the current article
989 by moving the mouse over the edge of the article window."
990   :type 'integer
991   :group 'gnus-summary-maneuvering)
992
993 (defcustom gnus-summary-show-article-charset-alist
994   nil
995   "Alist of number and charset.
996 The article will be shown with the charset corresponding to the
997 numbered argument.
998 For example: ((1 . cn-gb-2312) (2 . big5))."
999   :version "21.1"
1000   :type '(repeat (cons (number :tag "Argument" 1)
1001                        (symbol :tag "Charset")))
1002   :group 'gnus-charset)
1003
1004 (defcustom gnus-preserve-marks t
1005   "Whether marks are preserved when moving, copying and respooling messages."
1006   :version "21.1"
1007   :type 'boolean
1008   :group 'gnus-summary-marks)
1009
1010 (defcustom gnus-alter-articles-to-read-function nil
1011   "Function to be called to alter the list of articles to be selected."
1012   :type '(choice (const nil) function)
1013   :group 'gnus-summary)
1014
1015 (defcustom gnus-orphan-score nil
1016   "*All orphans get this score added.  Set in the score file."
1017   :group 'gnus-score-default
1018   :type '(choice (const nil)
1019                  integer))
1020
1021 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1022   "*A regexp to match MIME parts when saving multiple parts of a message
1023 with gnus-summary-save-parts (X m). This regexp will be used by default
1024 when prompting the user for which type of files to save."
1025   :group 'gnus-summary
1026   :type 'regexp)
1027
1028
1029 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1030   "*A regexp to match MIME parts when saving multiple parts of a message
1031 with gnus-summary-save-parts (X m). This regexp will be used by default
1032 when prompting the user for which type of files to save."
1033   :group 'gnus-summary
1034   :type 'regexp)
1035
1036 (defcustom gnus-read-all-available-headers nil
1037   "Whether Gnus should parse all headers made available to it.
1038 This is mostly relevant for slow backends where the user may
1039 wish to widen the summary buffer to include all headers
1040 that were fetched.  Say, for nnultimate groups."
1041   :group 'gnus-summary
1042   :type '(choice boolean regexp))
1043
1044 ;;; Internal variables
1045
1046 (defvar gnus-article-mime-handles nil)
1047 (defvar gnus-article-decoded-p nil)
1048 (defvar gnus-article-charset nil)
1049 (defvar gnus-article-ignored-charsets nil)
1050 (defvar gnus-scores-exclude-files nil)
1051 (defvar gnus-page-broken nil)
1052 (defvar gnus-inhibit-mime-unbuttonizing nil)
1053
1054 (defvar gnus-original-article nil)
1055 (defvar gnus-article-internal-prepare-hook nil)
1056 (defvar gnus-newsgroup-process-stack nil)
1057
1058 (defvar gnus-thread-indent-array nil)
1059 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1060 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1061   "Function called to sort the articles within a thread after it has been gathered together.")
1062
1063 (defvar gnus-summary-save-parts-type-history nil)
1064 (defvar gnus-summary-save-parts-last-directory nil)
1065
1066 (defvar gnus-summary-save-parts-type-history nil)
1067 (defvar gnus-summary-save-parts-last-directory nil)
1068
1069 ;; Avoid highlighting in kill files.
1070 (defvar gnus-summary-inhibit-highlight nil)
1071 (defvar gnus-newsgroup-selected-overlay nil)
1072 (defvar gnus-inhibit-limiting nil)
1073 (defvar gnus-newsgroup-adaptive-score-file nil)
1074 (defvar gnus-current-score-file nil)
1075 (defvar gnus-current-move-group nil)
1076 (defvar gnus-current-copy-group nil)
1077 (defvar gnus-current-crosspost-group nil)
1078
1079 (defvar gnus-newsgroup-dependencies nil)
1080 (defvar gnus-newsgroup-adaptive nil)
1081 (defvar gnus-summary-display-article-function nil)
1082 (defvar gnus-summary-highlight-line-function nil
1083   "Function called after highlighting a summary line.")
1084
1085 (defvar gnus-summary-line-format-alist
1086   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1087     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1088     (?s gnus-tmp-subject-or-nil ?s)
1089     (?n gnus-tmp-name ?s)
1090     (?A (std11-address-string
1091          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1092     (?a (or (std11-full-name-string
1093              (car (mime-entity-read-field gnus-tmp-header 'From)))
1094             gnus-tmp-from) ?s)
1095     (?F gnus-tmp-from ?s)
1096     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1097     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1098     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1099     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1100     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1101     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1102     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1103     (?L gnus-tmp-lines ?s)
1104     (?I gnus-tmp-indentation ?s)
1105     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1106     (?R gnus-tmp-replied ?c)
1107     (?\[ gnus-tmp-opening-bracket ?c)
1108     (?\] gnus-tmp-closing-bracket ?c)
1109     (?\> (make-string gnus-tmp-level ? ) ?s)
1110     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1111     (?i gnus-tmp-score ?d)
1112     (?z gnus-tmp-score-char ?c)
1113     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1114     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1115     (?U gnus-tmp-unread ?c)
1116     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header) ?s)
1117     (?t (gnus-summary-number-of-articles-in-thread
1118          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1119         ?d)
1120     (?e (gnus-summary-number-of-articles-in-thread
1121          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1122         ?c)
1123     (?u gnus-tmp-user-defined ?s)
1124     (?P (gnus-pick-line-number) ?d)
1125     (?B gnus-tmp-thread-tree-header-string ?s))
1126   "An alist of format specifications that can appear in summary lines.
1127 These are paired with what variables they correspond with, along with
1128 the type of the variable (string, integer, character, etc).")
1129
1130 (defvar gnus-summary-dummy-line-format-alist
1131   `((?S gnus-tmp-subject ?s)
1132     (?N gnus-tmp-number ?d)
1133     (?u gnus-tmp-user-defined ?s)))
1134
1135 (defvar gnus-summary-mode-line-format-alist
1136   `((?G gnus-tmp-group-name ?s)
1137     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1138     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1139     (?A gnus-tmp-article-number ?d)
1140     (?Z gnus-tmp-unread-and-unselected ?s)
1141     (?V gnus-version ?s)
1142     (?U gnus-tmp-unread-and-unticked ?d)
1143     (?S gnus-tmp-subject ?s)
1144     (?e gnus-tmp-unselected ?d)
1145     (?u gnus-tmp-user-defined ?s)
1146     (?d (length gnus-newsgroup-dormant) ?d)
1147     (?t (length gnus-newsgroup-marked) ?d)
1148     (?r (length gnus-newsgroup-reads) ?d)
1149     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1150     (?E gnus-newsgroup-expunged-tally ?d)
1151     (?s (gnus-current-score-file-nondirectory) ?s)))
1152
1153 (defvar gnus-last-search-regexp nil
1154   "Default regexp for article search command.")
1155
1156 (defvar gnus-summary-search-article-matched-data nil
1157   "Last matched data of article search command.  It is the local variable
1158 in `gnus-article-buffer' which consists of the list of start position,
1159 end position and text.")
1160
1161 (defvar gnus-last-shell-command nil
1162   "Default shell command on article.")
1163
1164 (defvar gnus-newsgroup-begin nil)
1165 (defvar gnus-newsgroup-end nil)
1166 (defvar gnus-newsgroup-last-rmail nil)
1167 (defvar gnus-newsgroup-last-mail nil)
1168 (defvar gnus-newsgroup-last-folder nil)
1169 (defvar gnus-newsgroup-last-file nil)
1170 (defvar gnus-newsgroup-auto-expire nil)
1171 (defvar gnus-newsgroup-active nil)
1172
1173 (defvar gnus-newsgroup-data nil)
1174 (defvar gnus-newsgroup-data-reverse nil)
1175 (defvar gnus-newsgroup-limit nil)
1176 (defvar gnus-newsgroup-limits nil)
1177
1178 (defvar gnus-newsgroup-unreads nil
1179   "List of unread articles in the current newsgroup.")
1180
1181 (defvar gnus-newsgroup-unselected nil
1182   "List of unselected unread articles in the current newsgroup.")
1183
1184 (defvar gnus-newsgroup-reads nil
1185   "Alist of read articles and article marks in the current newsgroup.")
1186
1187 (defvar gnus-newsgroup-expunged-tally nil)
1188
1189 (defvar gnus-newsgroup-marked nil
1190   "List of ticked articles in the current newsgroup (a subset of unread art).")
1191
1192 (defvar gnus-newsgroup-killed nil
1193   "List of ranges of articles that have been through the scoring process.")
1194
1195 (defvar gnus-newsgroup-cached nil
1196   "List of articles that come from the article cache.")
1197
1198 (defvar gnus-newsgroup-saved nil
1199   "List of articles that have been saved.")
1200
1201 (defvar gnus-newsgroup-kill-headers nil)
1202
1203 (defvar gnus-newsgroup-replied nil
1204   "List of articles that have been replied to in the current newsgroup.")
1205
1206 (defvar gnus-newsgroup-forwarded nil
1207   "List of articles that have been forwarded in the current newsgroup.")
1208
1209 (defvar gnus-newsgroup-recent nil
1210   "List of articles that have are recent in the current newsgroup.")
1211
1212 (defvar gnus-newsgroup-expirable nil
1213   "List of articles in the current newsgroup that can be expired.")
1214
1215 (defvar gnus-newsgroup-processable nil
1216   "List of articles in the current newsgroup that can be processed.")
1217
1218 (defvar gnus-newsgroup-downloadable nil
1219   "List of articles in the current newsgroup that can be processed.")
1220
1221 (defvar gnus-newsgroup-undownloaded nil
1222   "List of articles in the current newsgroup that haven't been downloaded..")
1223
1224 (defvar gnus-newsgroup-unsendable nil
1225   "List of articles in the current newsgroup that won't be sent.")
1226
1227 (defvar gnus-newsgroup-bookmarks nil
1228   "List of articles in the current newsgroup that have bookmarks.")
1229
1230 (defvar gnus-newsgroup-dormant nil
1231   "List of dormant articles in the current newsgroup.")
1232
1233 (defvar gnus-newsgroup-scored nil
1234   "List of scored articles in the current newsgroup.")
1235
1236 (defvar gnus-newsgroup-incorporated nil
1237   "List of incorporated articles in the current newsgroup.")
1238
1239 (defvar gnus-newsgroup-headers nil
1240   "List of article headers in the current newsgroup.")
1241
1242 (defvar gnus-newsgroup-threads nil)
1243
1244 (defvar gnus-newsgroup-prepared nil
1245   "Whether the current group has been prepared properly.")
1246
1247 (defvar gnus-newsgroup-ancient nil
1248   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1249
1250 (defvar gnus-newsgroup-sparse nil)
1251
1252 (defvar gnus-current-article nil)
1253 (defvar gnus-article-current nil)
1254 (defvar gnus-current-headers nil)
1255 (defvar gnus-have-all-headers nil)
1256 (defvar gnus-last-article nil)
1257 (defvar gnus-newsgroup-history nil)
1258 (defvar gnus-newsgroup-charset nil)
1259 (defvar gnus-newsgroup-ephemeral-charset nil)
1260 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1261
1262 (defvar gnus-article-before-search nil)
1263
1264 (defconst gnus-summary-local-variables
1265   '(gnus-newsgroup-name
1266     gnus-newsgroup-begin gnus-newsgroup-end
1267     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1268     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1269     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1270     gnus-newsgroup-unselected gnus-newsgroup-marked
1271     gnus-newsgroup-reads gnus-newsgroup-saved
1272     gnus-newsgroup-replied gnus-newsgroup-forwarded
1273     gnus-newsgroup-recent
1274     gnus-newsgroup-expirable
1275     gnus-newsgroup-processable gnus-newsgroup-killed
1276     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1277     gnus-newsgroup-unsendable
1278     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1279     gnus-newsgroup-headers gnus-newsgroup-threads
1280     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1281     gnus-current-article gnus-current-headers gnus-have-all-headers
1282     gnus-last-article gnus-article-internal-prepare-hook
1283     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1284     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1285     gnus-thread-expunge-below
1286     gnus-score-alist gnus-current-score-file
1287     (gnus-summary-expunge-below . global)
1288     (gnus-summary-mark-below . global)
1289     (gnus-orphan-score . global)
1290     gnus-newsgroup-active gnus-scores-exclude-files
1291     gnus-newsgroup-history gnus-newsgroup-ancient
1292     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1293     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1294     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1295     (gnus-newsgroup-expunged-tally . 0)
1296     gnus-cache-removable-articles gnus-newsgroup-cached
1297     gnus-newsgroup-data gnus-newsgroup-data-reverse
1298     gnus-newsgroup-limit gnus-newsgroup-limits
1299     gnus-newsgroup-charset
1300     gnus-newsgroup-incorporated)
1301   "Variables that are buffer-local to the summary buffers.")
1302
1303 (defvar gnus-newsgroup-variables nil
1304   "Variables that have separate values in the newsgroups.")
1305
1306 ;; Byte-compiler warning.
1307 (eval-when-compile (defvar gnus-article-mode-map))
1308
1309 ;; Subject simplification.
1310
1311 (defun gnus-simplify-whitespace (str)
1312   "Remove excessive whitespace from STR."
1313   (let ((mystr str))
1314     ;; Multiple spaces.
1315     (while (string-match "[ \t][ \t]+" mystr)
1316       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1317                           " "
1318                           (substring mystr (match-end 0)))))
1319     ;; Leading spaces.
1320     (when (string-match "^[ \t]+" mystr)
1321       (setq mystr (substring mystr (match-end 0))))
1322     ;; Trailing spaces.
1323     (when (string-match "[ \t]+$" mystr)
1324       (setq mystr (substring mystr 0 (match-beginning 0))))
1325     mystr))
1326
1327 (defsubst gnus-simplify-subject-re (subject)
1328   "Remove \"Re:\" from subject lines."
1329   (if (string-match message-subject-re-regexp subject)
1330       (substring subject (match-end 0))
1331     subject))
1332
1333 (defun gnus-simplify-subject (subject &optional re-only)
1334   "Remove `Re:' and words in parentheses.
1335 If RE-ONLY is non-nil, strip leading `Re:'s only."
1336   (let ((case-fold-search t))           ;Ignore case.
1337     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1338     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1339       (setq subject (substring subject (match-end 0))))
1340     ;; Remove uninteresting prefixes.
1341     (when (and (not re-only)
1342                gnus-simplify-ignored-prefixes
1343                (string-match gnus-simplify-ignored-prefixes subject))
1344       (setq subject (substring subject (match-end 0))))
1345     ;; Remove words in parentheses from end.
1346     (unless re-only
1347       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1348         (setq subject (substring subject 0 (match-beginning 0)))))
1349     ;; Return subject string.
1350     subject))
1351
1352 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1353 ;; all whitespace.
1354 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1355   (goto-char (point-min))
1356   (while (re-search-forward regexp nil t)
1357     (replace-match (or newtext ""))))
1358
1359 (defun gnus-simplify-buffer-fuzzy ()
1360   "Simplify string in the buffer fuzzily.
1361 The string in the accessible portion of the current buffer is simplified.
1362 It is assumed to be a single-line subject.
1363 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1364 matter is removed.  Additional things can be deleted by setting
1365 `gnus-simplify-subject-fuzzy-regexp'."
1366   (let ((case-fold-search t)
1367         (modified-tick))
1368     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1369
1370     (while (not (eq modified-tick (buffer-modified-tick)))
1371       (setq modified-tick (buffer-modified-tick))
1372       (cond
1373        ((listp gnus-simplify-subject-fuzzy-regexp)
1374         (mapcar 'gnus-simplify-buffer-fuzzy-step
1375                 gnus-simplify-subject-fuzzy-regexp))
1376        (gnus-simplify-subject-fuzzy-regexp
1377         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1378       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1379       (gnus-simplify-buffer-fuzzy-step
1380        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1381       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1382
1383     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1384     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1385     (gnus-simplify-buffer-fuzzy-step " $")
1386     (gnus-simplify-buffer-fuzzy-step "^ +")))
1387
1388 (defun gnus-simplify-subject-fuzzy (subject)
1389   "Simplify a subject string fuzzily.
1390 See `gnus-simplify-buffer-fuzzy' for details."
1391   (save-excursion
1392     (gnus-set-work-buffer)
1393     (let ((case-fold-search t))
1394       ;; Remove uninteresting prefixes.
1395       (when (and gnus-simplify-ignored-prefixes
1396                  (string-match gnus-simplify-ignored-prefixes subject))
1397         (setq subject (substring subject (match-end 0))))
1398       (insert subject)
1399       (inline (gnus-simplify-buffer-fuzzy))
1400       (buffer-string))))
1401
1402 (defsubst gnus-simplify-subject-fully (subject)
1403   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1404   (cond
1405    (gnus-simplify-subject-functions
1406     (gnus-map-function gnus-simplify-subject-functions subject))
1407    ((null gnus-summary-gather-subject-limit)
1408     (gnus-simplify-subject-re subject))
1409    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1410     (gnus-simplify-subject-fuzzy subject))
1411    ((numberp gnus-summary-gather-subject-limit)
1412     (gnus-limit-string (gnus-simplify-subject-re subject)
1413                        gnus-summary-gather-subject-limit))
1414    (t
1415     subject)))
1416
1417 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1418   "Check whether two subjects are equal.
1419 If optional argument simple-first is t, first argument is already
1420 simplified."
1421   (cond
1422    ((null simple-first)
1423     (equal (gnus-simplify-subject-fully s1)
1424            (gnus-simplify-subject-fully s2)))
1425    (t
1426     (equal s1
1427            (gnus-simplify-subject-fully s2)))))
1428
1429 (defun gnus-summary-bubble-group ()
1430   "Increase the score of the current group.
1431 This is a handy function to add to `gnus-summary-exit-hook' to
1432 increase the score of each group you read."
1433   (gnus-group-add-score gnus-newsgroup-name))
1434
1435 \f
1436 ;;;
1437 ;;; Gnus summary mode
1438 ;;;
1439
1440 (put 'gnus-summary-mode 'mode-class 'special)
1441
1442 (defvar gnus-article-commands-menu)
1443
1444 (when t
1445   ;; Non-orthogonal keys
1446
1447   (gnus-define-keys gnus-summary-mode-map
1448     " " gnus-summary-next-page
1449     "\177" gnus-summary-prev-page
1450     [delete] gnus-summary-prev-page
1451     [backspace] gnus-summary-prev-page
1452     "\r" gnus-summary-scroll-up
1453     "\M-\r" gnus-summary-scroll-down
1454     "n" gnus-summary-next-unread-article
1455     "p" gnus-summary-prev-unread-article
1456     "N" gnus-summary-next-article
1457     "P" gnus-summary-prev-article
1458     "\M-\C-n" gnus-summary-next-same-subject
1459     "\M-\C-p" gnus-summary-prev-same-subject
1460     "\M-n" gnus-summary-next-unread-subject
1461     "\M-p" gnus-summary-prev-unread-subject
1462     "." gnus-summary-first-unread-article
1463     "," gnus-summary-best-unread-article
1464     "\M-s" gnus-summary-search-article-forward
1465     "\M-r" gnus-summary-search-article-backward
1466     "<" gnus-summary-beginning-of-article
1467     ">" gnus-summary-end-of-article
1468     "j" gnus-summary-goto-article
1469     "^" gnus-summary-refer-parent-article
1470     "\M-^" gnus-summary-refer-article
1471     "u" gnus-summary-tick-article-forward
1472     "!" gnus-summary-tick-article-forward
1473     "U" gnus-summary-tick-article-backward
1474     "d" gnus-summary-mark-as-read-forward
1475     "D" gnus-summary-mark-as-read-backward
1476     "E" gnus-summary-mark-as-expirable
1477     "\M-u" gnus-summary-clear-mark-forward
1478     "\M-U" gnus-summary-clear-mark-backward
1479     "k" gnus-summary-kill-same-subject-and-select
1480     "\C-k" gnus-summary-kill-same-subject
1481     "\M-\C-k" gnus-summary-kill-thread
1482     "\M-\C-l" gnus-summary-lower-thread
1483     "e" gnus-summary-edit-article
1484     "#" gnus-summary-mark-as-processable
1485     "\M-#" gnus-summary-unmark-as-processable
1486     "\M-\C-t" gnus-summary-toggle-threads
1487     "\M-\C-s" gnus-summary-show-thread
1488     "\M-\C-h" gnus-summary-hide-thread
1489     "\M-\C-f" gnus-summary-next-thread
1490     "\M-\C-b" gnus-summary-prev-thread
1491     [(meta down)] gnus-summary-next-thread
1492     [(meta up)] gnus-summary-prev-thread
1493     "\M-\C-u" gnus-summary-up-thread
1494     "\M-\C-d" gnus-summary-down-thread
1495     "&" gnus-summary-execute-command
1496     "c" gnus-summary-catchup-and-exit
1497     "\C-w" gnus-summary-mark-region-as-read
1498     "\C-t" gnus-summary-toggle-truncation
1499     "?" gnus-summary-mark-as-dormant
1500     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1501     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1502     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1503     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1504     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1505     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1506     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1507     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1508     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1509     "=" gnus-summary-expand-window
1510     "\C-x\C-s" gnus-summary-reselect-current-group
1511     "\M-g" gnus-summary-rescan-group
1512     "w" gnus-summary-stop-page-breaking
1513     "\C-c\C-r" gnus-summary-caesar-message
1514     "\M-t" gnus-summary-toggle-mime
1515     "f" gnus-summary-followup
1516     "F" gnus-summary-followup-with-original
1517     "C" gnus-summary-cancel-article
1518     "r" gnus-summary-reply
1519     "R" gnus-summary-reply-with-original
1520     "\C-c\C-f" gnus-summary-mail-forward
1521     "o" gnus-summary-save-article
1522     "\C-o" gnus-summary-save-article-mail
1523     "|" gnus-summary-pipe-output
1524     "\M-k" gnus-summary-edit-local-kill
1525     "\M-K" gnus-summary-edit-global-kill
1526     ;; "V" gnus-version
1527     "\C-c\C-d" gnus-summary-describe-group
1528     "q" gnus-summary-exit
1529     "Q" gnus-summary-exit-no-update
1530     "\C-c\C-i" gnus-info-find-node
1531     gnus-mouse-2 gnus-mouse-pick-article
1532     "m" gnus-summary-mail-other-window
1533     "a" gnus-summary-post-news
1534     "x" gnus-summary-limit-to-unread
1535     "s" gnus-summary-isearch-article
1536     "t" gnus-article-toggle-headers
1537     "g" gnus-summary-show-article
1538     "l" gnus-summary-goto-last-article
1539     "v" gnus-summary-preview-mime-message
1540     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1541     "\C-d" gnus-summary-enter-digest-group
1542     "\M-\C-d" gnus-summary-read-document
1543     "\M-\C-e" gnus-summary-edit-parameters
1544     "\M-\C-a" gnus-summary-customize-parameters
1545     "\C-c\C-b" gnus-bug
1546     "*" gnus-cache-enter-article
1547     "\M-*" gnus-cache-remove-article
1548     "\M-&" gnus-summary-universal-argument
1549     "\C-l" gnus-recenter
1550     "I" gnus-summary-increase-score
1551     "L" gnus-summary-lower-score
1552     "\M-i" gnus-symbolic-argument
1553     "h" gnus-summary-select-article-buffer
1554
1555     "V" gnus-summary-score-map
1556     "X" gnus-uu-extract-map
1557     "S" gnus-summary-send-map)
1558
1559   ;; Sort of orthogonal keymap
1560   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1561     "t" gnus-summary-tick-article-forward
1562     "!" gnus-summary-tick-article-forward
1563     "d" gnus-summary-mark-as-read-forward
1564     "r" gnus-summary-mark-as-read-forward
1565     "c" gnus-summary-clear-mark-forward
1566     " " gnus-summary-clear-mark-forward
1567     "e" gnus-summary-mark-as-expirable
1568     "x" gnus-summary-mark-as-expirable
1569     "?" gnus-summary-mark-as-dormant
1570     "b" gnus-summary-set-bookmark
1571     "B" gnus-summary-remove-bookmark
1572     "#" gnus-summary-mark-as-processable
1573     "\M-#" gnus-summary-unmark-as-processable
1574     "S" gnus-summary-limit-include-expunged
1575     "C" gnus-summary-catchup
1576     "H" gnus-summary-catchup-to-here
1577     "h" gnus-summary-catchup-from-here
1578     "\C-c" gnus-summary-catchup-all
1579     "k" gnus-summary-kill-same-subject-and-select
1580     "K" gnus-summary-kill-same-subject
1581     "P" gnus-uu-mark-map)
1582
1583   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1584     "c" gnus-summary-clear-above
1585     "u" gnus-summary-tick-above
1586     "m" gnus-summary-mark-above
1587     "k" gnus-summary-kill-below)
1588
1589   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1590     "/" gnus-summary-limit-to-subject
1591     "n" gnus-summary-limit-to-articles
1592     "w" gnus-summary-pop-limit
1593     "s" gnus-summary-limit-to-subject
1594     "a" gnus-summary-limit-to-author
1595     "u" gnus-summary-limit-to-unread
1596     "m" gnus-summary-limit-to-marks
1597     "M" gnus-summary-limit-exclude-marks
1598     "v" gnus-summary-limit-to-score
1599     "*" gnus-summary-limit-include-cached
1600     "D" gnus-summary-limit-include-dormant
1601     "T" gnus-summary-limit-include-thread
1602     "d" gnus-summary-limit-exclude-dormant
1603     "t" gnus-summary-limit-to-age
1604     "x" gnus-summary-limit-to-extra
1605     "E" gnus-summary-limit-include-expunged
1606     "c" gnus-summary-limit-exclude-childless-dormant
1607     "C" gnus-summary-limit-mark-excluded-as-read
1608     "o" gnus-summary-insert-old-articles
1609     "N" gnus-summary-insert-new-articles)
1610
1611   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1612     "n" gnus-summary-next-unread-article
1613     "p" gnus-summary-prev-unread-article
1614     "N" gnus-summary-next-article
1615     "P" gnus-summary-prev-article
1616     "\C-n" gnus-summary-next-same-subject
1617     "\C-p" gnus-summary-prev-same-subject
1618     "\M-n" gnus-summary-next-unread-subject
1619     "\M-p" gnus-summary-prev-unread-subject
1620     "f" gnus-summary-first-unread-article
1621     "b" gnus-summary-best-unread-article
1622     "j" gnus-summary-goto-article
1623     "g" gnus-summary-goto-subject
1624     "l" gnus-summary-goto-last-article
1625     "o" gnus-summary-pop-article)
1626
1627   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1628     "k" gnus-summary-kill-thread
1629     "l" gnus-summary-lower-thread
1630     "i" gnus-summary-raise-thread
1631     "T" gnus-summary-toggle-threads
1632     "t" gnus-summary-rethread-current
1633     "^" gnus-summary-reparent-thread
1634     "s" gnus-summary-show-thread
1635     "S" gnus-summary-show-all-threads
1636     "h" gnus-summary-hide-thread
1637     "H" gnus-summary-hide-all-threads
1638     "n" gnus-summary-next-thread
1639     "p" gnus-summary-prev-thread
1640     "u" gnus-summary-up-thread
1641     "o" gnus-summary-top-thread
1642     "d" gnus-summary-down-thread
1643     "#" gnus-uu-mark-thread
1644     "\M-#" gnus-uu-unmark-thread)
1645
1646   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1647     "g" gnus-summary-prepare
1648     "c" gnus-summary-insert-cached-articles)
1649
1650   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1651     "c" gnus-summary-catchup-and-exit
1652     "C" gnus-summary-catchup-all-and-exit
1653     "E" gnus-summary-exit-no-update
1654     "J" gnus-summary-jump-to-other-group
1655     "Q" gnus-summary-exit
1656     "Z" gnus-summary-exit
1657     "n" gnus-summary-catchup-and-goto-next-group
1658     "R" gnus-summary-reselect-current-group
1659     "G" gnus-summary-rescan-group
1660     "N" gnus-summary-next-group
1661     "s" gnus-summary-save-newsrc
1662     "P" gnus-summary-prev-group)
1663
1664   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1665     " " gnus-summary-next-page
1666     "n" gnus-summary-next-page
1667     "\177" gnus-summary-prev-page
1668     [delete] gnus-summary-prev-page
1669     "p" gnus-summary-prev-page
1670     "\r" gnus-summary-scroll-up
1671     "\M-\r" gnus-summary-scroll-down
1672     "<" gnus-summary-beginning-of-article
1673     ">" gnus-summary-end-of-article
1674     "b" gnus-summary-beginning-of-article
1675     "e" gnus-summary-end-of-article
1676     "^" gnus-summary-refer-parent-article
1677     "r" gnus-summary-refer-parent-article
1678     "D" gnus-summary-enter-digest-group
1679     "R" gnus-summary-refer-references
1680     "T" gnus-summary-refer-thread
1681     "g" gnus-summary-show-article
1682     "s" gnus-summary-isearch-article
1683     "P" gnus-summary-print-article
1684     "M" gnus-mailing-list-insinuate
1685     "t" gnus-article-babel)
1686
1687   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1688     "b" gnus-article-add-buttons
1689     "B" gnus-article-add-buttons-to-head
1690     "o" gnus-article-treat-overstrike
1691     "e" gnus-article-emphasize
1692     "w" gnus-article-fill-cited-article
1693     "Q" gnus-article-fill-long-lines
1694     "C" gnus-article-capitalize-sentences
1695     "c" gnus-article-remove-cr
1696     "Z" gnus-article-decode-HZ
1697     "f" gnus-article-display-x-face
1698     "l" gnus-summary-stop-page-breaking
1699     "r" gnus-summary-caesar-message
1700     "t" gnus-article-toggle-headers
1701     "v" gnus-summary-verbose-headers
1702     "m" gnus-summary-toggle-mime
1703     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1704     "p" gnus-article-verify-x-pgp-sig
1705     "d" gnus-article-treat-dumbquotes
1706     "s" gnus-smiley-display)
1707
1708   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1709     "a" gnus-article-hide
1710     "h" gnus-article-toggle-headers
1711     "b" gnus-article-hide-boring-headers
1712     "s" gnus-article-hide-signature
1713     "c" gnus-article-hide-citation
1714     "C" gnus-article-hide-citation-in-followups
1715     "l" gnus-article-hide-list-identifiers
1716     "p" gnus-article-hide-pgp
1717     "B" gnus-article-strip-banner
1718     "P" gnus-article-hide-pem
1719     "\C-c" gnus-article-hide-citation-maybe)
1720
1721   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1722     "a" gnus-article-highlight
1723     "h" gnus-article-highlight-headers
1724     "c" gnus-article-highlight-citation
1725     "s" gnus-article-highlight-signature)
1726
1727   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1728     "z" gnus-article-date-ut
1729     "u" gnus-article-date-ut
1730     "l" gnus-article-date-local
1731     "p" gnus-article-date-english
1732     "e" gnus-article-date-lapsed
1733     "o" gnus-article-date-original
1734     "i" gnus-article-date-iso8601
1735     "s" gnus-article-date-user)
1736
1737   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1738     "t" gnus-article-remove-trailing-blank-lines
1739     "l" gnus-article-strip-leading-blank-lines
1740     "m" gnus-article-strip-multiple-blank-lines
1741     "a" gnus-article-strip-blank-lines
1742     "A" gnus-article-strip-all-blank-lines
1743     "s" gnus-article-strip-leading-space
1744     "e" gnus-article-strip-trailing-space
1745     "w" gnus-article-remove-leading-whitespace)
1746
1747   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1748     "v" gnus-version
1749     "f" gnus-summary-fetch-faq
1750     "d" gnus-summary-describe-group
1751     "h" gnus-summary-describe-briefly
1752     "i" gnus-info-find-node)
1753
1754   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1755     "e" gnus-summary-expire-articles
1756     "\M-\C-e" gnus-summary-expire-articles-now
1757     "\177" gnus-summary-delete-article
1758     [delete] gnus-summary-delete-article
1759     [backspace] gnus-summary-delete-article
1760     "m" gnus-summary-move-article
1761     "r" gnus-summary-respool-article
1762     "w" gnus-summary-edit-article
1763     "c" gnus-summary-copy-article
1764     "B" gnus-summary-crosspost-article
1765     "q" gnus-summary-respool-query
1766     "t" gnus-summary-respool-trace
1767     "i" gnus-summary-import-article
1768     "I" gnus-summary-create-article
1769     "p" gnus-summary-article-posted-p)
1770
1771   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1772     "o" gnus-summary-save-article
1773     "m" gnus-summary-save-article-mail
1774     "F" gnus-summary-write-article-file
1775     "r" gnus-summary-save-article-rmail
1776     "f" gnus-summary-save-article-file
1777     "b" gnus-summary-save-article-body-file
1778     "h" gnus-summary-save-article-folder
1779     "v" gnus-summary-save-article-vm
1780     "p" gnus-summary-pipe-output
1781     "s" gnus-soup-add-article)
1782
1783   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1784     "b" gnus-summary-display-buttonized
1785     "m" gnus-summary-repair-multipart
1786     "v" gnus-article-view-part
1787     "o" gnus-article-save-part
1788     "c" gnus-article-copy-part
1789     "C" gnus-article-view-part-as-charset
1790     "e" gnus-article-externalize-part
1791     "E" gnus-article-encrypt-body
1792     "i" gnus-article-inline-part
1793     "|" gnus-article-pipe-part))
1794
1795 (defvar gnus-article-post-menu nil)
1796
1797 (defun gnus-summary-make-menu-bar ()
1798   (gnus-turn-off-edit-menu 'summary)
1799
1800   (unless (boundp 'gnus-summary-misc-menu)
1801
1802     (easy-menu-define
1803      gnus-summary-kill-menu gnus-summary-mode-map ""
1804      (cons
1805       "Score"
1806       (nconc
1807        (list
1808         ["Customize" gnus-score-customize t])
1809        (gnus-make-score-map 'increase)
1810        (gnus-make-score-map 'lower)
1811        '(("Mark"
1812           ["Kill below" gnus-summary-kill-below t]
1813           ["Mark above" gnus-summary-mark-above t]
1814           ["Tick above" gnus-summary-tick-above t]
1815           ["Clear above" gnus-summary-clear-above t])
1816          ["Current score" gnus-summary-current-score t]
1817          ["Set score" gnus-summary-set-score t]
1818          ["Switch current score file..." gnus-score-change-score-file t]
1819          ["Set mark below..." gnus-score-set-mark-below t]
1820          ["Set expunge below..." gnus-score-set-expunge-below t]
1821          ["Edit current score file" gnus-score-edit-current-scores t]
1822          ["Edit score file" gnus-score-edit-file t]
1823          ["Trace score" gnus-score-find-trace t]
1824          ["Find words" gnus-score-find-favourite-words t]
1825          ["Rescore buffer" gnus-summary-rescore t]
1826          ["Increase score..." gnus-summary-increase-score t]
1827          ["Lower score..." gnus-summary-lower-score t]))))
1828
1829     ;; Define both the Article menu in the summary buffer and the equivalent
1830     ;; Commands menu in the article buffer here for consistency.
1831     (let ((innards
1832            `(("Hide"
1833               ["All" gnus-article-hide t]
1834               ["Headers" gnus-article-toggle-headers t]
1835               ["Signature" gnus-article-hide-signature t]
1836               ["Citation" gnus-article-hide-citation t]
1837               ["List identifiers" gnus-article-hide-list-identifiers t]
1838               ["PGP" gnus-article-hide-pgp t]
1839               ["Banner" gnus-article-strip-banner t]
1840               ["Boring headers" gnus-article-hide-boring-headers t])
1841              ("Highlight"
1842               ["All" gnus-article-highlight t]
1843               ["Headers" gnus-article-highlight-headers t]
1844               ["Signature" gnus-article-highlight-signature t]
1845               ["Citation" gnus-article-highlight-citation t])
1846              ("Date"
1847               ["Local" gnus-article-date-local t]
1848               ["ISO8601" gnus-article-date-iso8601 t]
1849               ["UT" gnus-article-date-ut t]
1850               ["Original" gnus-article-date-original t]
1851               ["Lapsed" gnus-article-date-lapsed t]
1852               ["User-defined" gnus-article-date-user t])
1853              ("Washing"
1854               ("Remove Blanks"
1855                ["Leading" gnus-article-strip-leading-blank-lines t]
1856                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1857                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1858                ["All of the above" gnus-article-strip-blank-lines t]
1859                ["All" gnus-article-strip-all-blank-lines t]
1860                ["Leading space" gnus-article-strip-leading-space t]
1861                ["Trailing space" gnus-article-strip-trailing-space t]
1862                ["Leading space in headers"
1863                 gnus-article-remove-leading-whitespace t])
1864               ["Overstrike" gnus-article-treat-overstrike t]
1865               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1866               ["Emphasis" gnus-article-emphasize t]
1867               ["Word wrap" gnus-article-fill-cited-article t]
1868               ["Fill long lines" gnus-article-fill-long-lines t]
1869               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1870               ["CR" gnus-article-remove-cr t]
1871               ["Show X-Face" gnus-article-display-x-face t]
1872               ["Rot 13" gnus-summary-caesar-message
1873                ,@(if (featurep 'xemacs) '(t)
1874                    '(:help "\"Caesar rotate\" article by 13"))]
1875               ["Unix pipe" gnus-summary-pipe-message t]
1876               ["Add buttons" gnus-article-add-buttons t]
1877               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1878               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1879               ["Toggle MIME" gnus-summary-toggle-mime t]
1880               ["Verbose header" gnus-summary-verbose-headers t]
1881               ["Toggle header" gnus-summary-toggle-header t]
1882               ["Toggle smileys" gnus-smiley-display t]
1883               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1884               ["HZ" gnus-article-decode-HZ t])
1885              ("Output"
1886               ["Save in default format" gnus-summary-save-article
1887                ,@(if (featurep 'xemacs) '(t)
1888                    '(:help "Save article using default method"))]
1889               ["Save in file" gnus-summary-save-article-file
1890                ,@(if (featurep 'xemacs) '(t)
1891                    '(:help "Save article in file"))]
1892               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1893               ["Save in MH folder" gnus-summary-save-article-folder t]
1894               ["Save in VM folder" gnus-summary-save-article-vm t]
1895               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1896               ["Save body in file" gnus-summary-save-article-body-file t]
1897               ["Pipe through a filter" gnus-summary-pipe-output t]
1898               ["Add to SOUP packet" gnus-soup-add-article t]
1899               ["Print" gnus-summary-print-article t])
1900              ("Backend"
1901               ["Respool article..." gnus-summary-respool-article t]
1902               ["Move article..." gnus-summary-move-article
1903                (gnus-check-backend-function
1904                 'request-move-article gnus-newsgroup-name)]
1905               ["Copy article..." gnus-summary-copy-article t]
1906               ["Crosspost article..." gnus-summary-crosspost-article
1907                (gnus-check-backend-function
1908                 'request-replace-article gnus-newsgroup-name)]
1909               ["Import file..." gnus-summary-import-article t]
1910               ["Create article..." gnus-summary-create-article t]
1911               ["Check if posted" gnus-summary-article-posted-p t]
1912               ["Edit article" gnus-summary-edit-article
1913                (not (gnus-group-read-only-p))]
1914               ["Delete article" gnus-summary-delete-article
1915                (gnus-check-backend-function
1916                 'request-expire-articles gnus-newsgroup-name)]
1917               ["Query respool" gnus-summary-respool-query t]
1918               ["Trace respool" gnus-summary-respool-trace t]
1919               ["Delete expirable articles" gnus-summary-expire-articles-now
1920                (gnus-check-backend-function
1921                 'request-expire-articles gnus-newsgroup-name)])
1922              ("Extract"
1923               ["Uudecode" gnus-uu-decode-uu
1924                ,@(if (featurep 'xemacs) '(t)
1925                    '(:help "Decode uuencoded article(s)"))]
1926               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1927               ["Unshar" gnus-uu-decode-unshar t]
1928               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1929               ["Save" gnus-uu-decode-save t]
1930               ["Binhex" gnus-uu-decode-binhex t]
1931               ["Postscript" gnus-uu-decode-postscript t])
1932              ("Cache"
1933               ["Enter article" gnus-cache-enter-article t]
1934               ["Remove article" gnus-cache-remove-article t])
1935              ["Translate" gnus-article-babel t]
1936              ["Select article buffer" gnus-summary-select-article-buffer t]
1937              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1938              ["Isearch article..." gnus-summary-isearch-article t]
1939              ["Beginning of the article" gnus-summary-beginning-of-article t]
1940              ["End of the article" gnus-summary-end-of-article t]
1941              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1942              ["Fetch referenced articles" gnus-summary-refer-references t]
1943              ["Fetch current thread" gnus-summary-refer-thread t]
1944              ["Fetch article with id..." gnus-summary-refer-article t]
1945              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
1946              ["Redisplay" gnus-summary-show-article t]
1947              ["Raw article" gnus-summary-show-raw-article t])))
1948       (easy-menu-define
1949        gnus-summary-article-menu gnus-summary-mode-map ""
1950        (cons "Article" innards))
1951
1952       (if (not (keymapp gnus-summary-article-menu))
1953           (easy-menu-define
1954            gnus-article-commands-menu gnus-article-mode-map ""
1955            (cons "Commands" innards))
1956         ;; in Emacs, don't share menu.
1957         (setq gnus-article-commands-menu
1958               (copy-keymap gnus-summary-article-menu))
1959         (define-key gnus-article-mode-map [menu-bar commands]
1960           (cons "Commands" gnus-article-commands-menu))))
1961
1962     (easy-menu-define
1963      gnus-summary-thread-menu gnus-summary-mode-map ""
1964      '("Threads"
1965        ["Toggle threading" gnus-summary-toggle-threads t]
1966        ["Hide threads" gnus-summary-hide-all-threads t]
1967        ["Show threads" gnus-summary-show-all-threads t]
1968        ["Hide thread" gnus-summary-hide-thread t]
1969        ["Show thread" gnus-summary-show-thread t]
1970        ["Go to next thread" gnus-summary-next-thread t]
1971        ["Go to previous thread" gnus-summary-prev-thread t]
1972        ["Go down thread" gnus-summary-down-thread t]
1973        ["Go up thread" gnus-summary-up-thread t]
1974        ["Top of thread" gnus-summary-top-thread t]
1975        ["Mark thread as read" gnus-summary-kill-thread t]
1976        ["Lower thread score" gnus-summary-lower-thread t]
1977        ["Raise thread score" gnus-summary-raise-thread t]
1978        ["Rethread current" gnus-summary-rethread-current t]))
1979
1980     (easy-menu-define
1981      gnus-summary-post-menu gnus-summary-mode-map ""
1982      `("Post"
1983        ["Post an article" gnus-summary-post-news
1984         ,@(if (featurep 'xemacs) '(t)
1985             '(:help "Post an article"))]
1986        ["Followup" gnus-summary-followup
1987         ,@(if (featurep 'xemacs) '(t)
1988             '(:help "Post followup to this article"))]
1989        ["Followup and yank" gnus-summary-followup-with-original
1990         ,@(if (featurep 'xemacs) '(t)
1991             '(:help "Post followup to this article, quoting its contents"))]
1992        ["Supersede article" gnus-summary-supersede-article t]
1993        ["Cancel article" gnus-summary-cancel-article
1994         ,@(if (featurep 'xemacs) '(t)
1995             '(:help "Cancel an article you posted"))]
1996        ["Reply" gnus-summary-reply t]
1997        ["Reply and yank" gnus-summary-reply-with-original t]
1998        ["Wide reply" gnus-summary-wide-reply t]
1999        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2000         ,@(if (featurep 'xemacs) '(t)
2001             '(:help "Mail a reply, quoting this article"))]
2002        ["Mail forward" gnus-summary-mail-forward t]
2003        ["Post forward" gnus-summary-post-forward t]
2004        ["Digest and mail" gnus-summary-digest-mail-forward t]
2005        ["Digest and post" gnus-summary-digest-post-forward t]
2006        ["Resend message" gnus-summary-resend-message t]
2007        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2008        ["Send a mail" gnus-summary-mail-other-window t]
2009        ["Uuencode and post" gnus-uu-post-news
2010         ,@(if (featurep 'xemacs) '(t)
2011             '(:help "Post a uuencoded article"))]
2012        ["Followup via news" gnus-summary-followup-to-mail t]
2013        ["Followup via news and yank"
2014         gnus-summary-followup-to-mail-with-original t]
2015        ;;("Draft"
2016        ;;["Send" gnus-summary-send-draft t]
2017        ;;["Send bounced" gnus-resend-bounced-mail t])
2018        ))
2019
2020     (cond
2021      ((not (keymapp gnus-summary-post-menu))
2022       (setq gnus-article-post-menu gnus-summary-post-menu))
2023      ((not gnus-article-post-menu)
2024       ;; Don't share post menu.
2025       (setq gnus-article-post-menu
2026             (copy-keymap gnus-summary-post-menu))))
2027     (define-key gnus-article-mode-map [menu-bar post]
2028       (cons "Post" gnus-article-post-menu))
2029
2030     (easy-menu-define
2031      gnus-summary-misc-menu gnus-summary-mode-map ""
2032      `("Gnus"
2033        ("Mark Read"
2034         ["Mark as read" gnus-summary-mark-as-read-forward t]
2035         ["Mark same subject and select"
2036          gnus-summary-kill-same-subject-and-select t]
2037         ["Mark same subject" gnus-summary-kill-same-subject t]
2038         ["Catchup" gnus-summary-catchup
2039          ,@(if (featurep 'xemacs) '(t)
2040              '(:help "Mark unread articles in this group as read"))]
2041         ["Catchup all" gnus-summary-catchup-all t]
2042         ["Catchup to here" gnus-summary-catchup-to-here t]
2043         ["Catchup from here" gnus-summary-catchup-from-here t]
2044         ["Catchup region" gnus-summary-mark-region-as-read t]
2045         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2046        ("Mark Various"
2047         ["Tick" gnus-summary-tick-article-forward t]
2048         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2049         ["Remove marks" gnus-summary-clear-mark-forward t]
2050         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2051         ["Set bookmark" gnus-summary-set-bookmark t]
2052         ["Remove bookmark" gnus-summary-remove-bookmark t])
2053        ("Mark Limit"
2054         ["Marks..." gnus-summary-limit-to-marks t]
2055         ["Subject..." gnus-summary-limit-to-subject t]
2056         ["Author..." gnus-summary-limit-to-author t]
2057         ["Age..." gnus-summary-limit-to-age t]
2058         ["Extra..." gnus-summary-limit-to-extra t]
2059         ["Score" gnus-summary-limit-to-score t]
2060         ["Unread" gnus-summary-limit-to-unread t]
2061         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2062         ["Articles" gnus-summary-limit-to-articles t]
2063         ["Pop limit" gnus-summary-pop-limit t]
2064         ["Show dormant" gnus-summary-limit-include-dormant t]
2065         ["Hide childless dormant"
2066          gnus-summary-limit-exclude-childless-dormant t]
2067         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2068         ["Hide marked" gnus-summary-limit-exclude-marks t]
2069         ["Show expunged" gnus-summary-limit-include-expunged t])
2070        ("Process Mark"
2071         ["Set mark" gnus-summary-mark-as-processable t]
2072         ["Remove mark" gnus-summary-unmark-as-processable t]
2073         ["Remove all marks" gnus-summary-unmark-all-processable t]
2074         ["Mark above" gnus-uu-mark-over t]
2075         ["Mark series" gnus-uu-mark-series t]
2076         ["Mark region" gnus-uu-mark-region t]
2077         ["Unmark region" gnus-uu-unmark-region t]
2078         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2079         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2080         ["Mark all" gnus-uu-mark-all t]
2081         ["Mark buffer" gnus-uu-mark-buffer t]
2082         ["Mark sparse" gnus-uu-mark-sparse t]
2083         ["Mark thread" gnus-uu-mark-thread t]
2084         ["Unmark thread" gnus-uu-unmark-thread t]
2085         ("Process Mark Sets"
2086          ["Kill" gnus-summary-kill-process-mark t]
2087          ["Yank" gnus-summary-yank-process-mark
2088           gnus-newsgroup-process-stack]
2089          ["Save" gnus-summary-save-process-mark t]))
2090        ("Scroll article"
2091         ["Page forward" gnus-summary-next-page
2092          ,@(if (featurep 'xemacs) '(t)
2093              '(:help "Show next page of article"))]
2094         ["Page backward" gnus-summary-prev-page
2095          ,@(if (featurep 'xemacs) '(t)
2096              '(:help "Show previous page of article"))]
2097         ["Line forward" gnus-summary-scroll-up t])
2098        ("Move"
2099         ["Next unread article" gnus-summary-next-unread-article t]
2100         ["Previous unread article" gnus-summary-prev-unread-article t]
2101         ["Next article" gnus-summary-next-article t]
2102         ["Previous article" gnus-summary-prev-article t]
2103         ["Next unread subject" gnus-summary-next-unread-subject t]
2104         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2105         ["Next article same subject" gnus-summary-next-same-subject t]
2106         ["Previous article same subject" gnus-summary-prev-same-subject t]
2107         ["First unread article" gnus-summary-first-unread-article t]
2108         ["Best unread article" gnus-summary-best-unread-article t]
2109         ["Go to subject number..." gnus-summary-goto-subject t]
2110         ["Go to article number..." gnus-summary-goto-article t]
2111         ["Go to the last article" gnus-summary-goto-last-article t]
2112         ["Pop article off history" gnus-summary-pop-article t])
2113        ("Sort"
2114         ["Sort by number" gnus-summary-sort-by-number t]
2115         ["Sort by author" gnus-summary-sort-by-author t]
2116         ["Sort by subject" gnus-summary-sort-by-subject t]
2117         ["Sort by date" gnus-summary-sort-by-date t]
2118         ["Sort by score" gnus-summary-sort-by-score t]
2119         ["Sort by lines" gnus-summary-sort-by-lines t]
2120         ["Sort by characters" gnus-summary-sort-by-chars t]
2121         ["Original sort" gnus-summary-sort-by-original t])
2122        ("Help"
2123         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2124         ["Describe group" gnus-summary-describe-group t]
2125         ["Read manual" gnus-info-find-node t])
2126        ("Modes"
2127         ["Pick and read" gnus-pick-mode t]
2128         ["Binary" gnus-binary-mode t])
2129        ("Regeneration"
2130         ["Regenerate" gnus-summary-prepare t]
2131         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2132         ["Toggle threading" gnus-summary-toggle-threads t])
2133        ["See old articles" gnus-summary-insert-old-articles t]
2134        ["See new articles" gnus-summary-insert-new-articles t]
2135        ["Filter articles..." gnus-summary-execute-command t]
2136        ["Run command on subjects..." gnus-summary-universal-argument t]
2137        ["Search articles forward..." gnus-summary-search-article-forward t]
2138        ["Search articles backward..." gnus-summary-search-article-backward t]
2139        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2140        ["Expand window" gnus-summary-expand-window t]
2141        ["Expire expirable articles" gnus-summary-expire-articles
2142         (gnus-check-backend-function
2143          'request-expire-articles gnus-newsgroup-name)]
2144        ["Edit local kill file" gnus-summary-edit-local-kill t]
2145        ["Edit main kill file" gnus-summary-edit-global-kill t]
2146        ["Edit group parameters" gnus-summary-edit-parameters t]
2147        ["Customize group parameters" gnus-summary-customize-parameters t]
2148        ["Send a bug report" gnus-bug t]
2149        ("Exit"
2150         ["Catchup and exit" gnus-summary-catchup-and-exit
2151          ,@(if (featurep 'xemacs) '(t)
2152              '(:help "Mark unread articles in this group as read, then exit"))]
2153         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2154         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2155         ["Exit group" gnus-summary-exit
2156          ,@(if (featurep 'xemacs) '(t)
2157              '(:help "Exit current group, return to group selection mode"))]
2158         ["Exit group without updating" gnus-summary-exit-no-update t]
2159         ["Exit and goto next group" gnus-summary-next-group t]
2160         ["Exit and goto prev group" gnus-summary-prev-group t]
2161         ["Reselect group" gnus-summary-reselect-current-group t]
2162         ["Rescan group" gnus-summary-rescan-group t]
2163         ["Update dribble" gnus-summary-save-newsrc t])))
2164
2165     (gnus-run-hooks 'gnus-summary-menu-hook)))
2166
2167 (defvar gnus-summary-tool-bar-map nil)
2168
2169 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2170 (defun gnus-summary-make-tool-bar ()
2171   (if (and (fboundp 'tool-bar-add-item-from-menu)
2172            (default-value 'tool-bar-mode)
2173            (not gnus-summary-tool-bar-map))
2174       (setq gnus-summary-tool-bar-map
2175             (let ((tool-bar-map (make-sparse-keymap))
2176                   (load-path (mm-image-load-path)))
2177               (tool-bar-add-item-from-menu
2178                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2179               (tool-bar-add-item-from-menu
2180                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2181               (tool-bar-add-item-from-menu
2182                'gnus-summary-post-news "post" gnus-summary-mode-map)
2183               (tool-bar-add-item-from-menu
2184                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2185               (tool-bar-add-item-from-menu
2186                'gnus-summary-followup "followup" gnus-summary-mode-map)
2187               (tool-bar-add-item-from-menu
2188                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2189               (tool-bar-add-item-from-menu
2190                'gnus-summary-reply "reply" gnus-summary-mode-map)
2191               (tool-bar-add-item-from-menu
2192                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2193               (tool-bar-add-item-from-menu
2194                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2195               (tool-bar-add-item-from-menu
2196                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2197               (tool-bar-add-item-from-menu
2198                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2199               (tool-bar-add-item-from-menu
2200                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2201               (tool-bar-add-item-from-menu
2202                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2203               (tool-bar-add-item-from-menu
2204                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2205               (tool-bar-add-item-from-menu
2206                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2207               tool-bar-map)))
2208   (if gnus-summary-tool-bar-map
2209       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2210
2211 (defun gnus-score-set-default (var value)
2212   "A version of set that updates the GNU Emacs menu-bar."
2213   (set var value)
2214   ;; It is the message that forces the active status to be updated.
2215   (message ""))
2216
2217 (defun gnus-make-score-map (type)
2218   "Make a summary score map of type TYPE."
2219   (if t
2220       nil
2221     (let ((headers '(("author" "from" string)
2222                      ("subject" "subject" string)
2223                      ("article body" "body" string)
2224                      ("article head" "head" string)
2225                      ("xref" "xref" string)
2226                      ("extra header" "extra" string)
2227                      ("lines" "lines" number)
2228                      ("followups to author" "followup" string)))
2229           (types '((number ("less than" <)
2230                            ("greater than" >)
2231                            ("equal" =))
2232                    (string ("substring" s)
2233                            ("exact string" e)
2234                            ("fuzzy string" f)
2235                            ("regexp" r))))
2236           (perms '(("temporary" (current-time-string))
2237                    ("permanent" nil)
2238                    ("immediate" now)))
2239           header)
2240       (list
2241        (apply
2242         'nconc
2243         (list
2244          (if (eq type 'lower)
2245              "Lower score"
2246            "Increase score"))
2247         (let (outh)
2248           (while headers
2249             (setq header (car headers))
2250             (setq outh
2251                   (cons
2252                    (apply
2253                     'nconc
2254                     (list (car header))
2255                     (let ((ts (cdr (assoc (nth 2 header) types)))
2256                           outt)
2257                       (while ts
2258                         (setq outt
2259                               (cons
2260                                (apply
2261                                 'nconc
2262                                 (list (caar ts))
2263                                 (let ((ps perms)
2264                                       outp)
2265                                   (while ps
2266                                     (setq outp
2267                                           (cons
2268                                            (vector
2269                                             (caar ps)
2270                                             (list
2271                                              'gnus-summary-score-entry
2272                                              (nth 1 header)
2273                                              (if (or (string= (nth 1 header)
2274                                                               "head")
2275                                                      (string= (nth 1 header)
2276                                                               "body"))
2277                                                  ""
2278                                                (list 'gnus-summary-header
2279                                                      (nth 1 header)))
2280                                              (list 'quote (nth 1 (car ts)))
2281                                              (list 'gnus-score-delta-default
2282                                                    nil)
2283                                              (nth 1 (car ps))
2284                                              t)
2285                                             t)
2286                                            outp))
2287                                     (setq ps (cdr ps)))
2288                                   (list (nreverse outp))))
2289                                outt))
2290                         (setq ts (cdr ts)))
2291                       (list (nreverse outt))))
2292                    outh))
2293             (setq headers (cdr headers)))
2294           (list (nreverse outh))))))))
2295
2296 \f
2297
2298 (defun gnus-summary-mode (&optional group)
2299   "Major mode for reading articles.
2300
2301 All normal editing commands are switched off.
2302 \\<gnus-summary-mode-map>
2303 Each line in this buffer represents one article.  To read an
2304 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2305 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2306 respectively.
2307
2308 You can also post articles and send mail from this buffer.  To
2309 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2310 of an article, type `\\[gnus-summary-reply]'.
2311
2312 There are approx. one gazillion commands you can execute in this
2313 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2314
2315 The following commands are available:
2316
2317 \\{gnus-summary-mode-map}"
2318   (interactive)
2319   (kill-all-local-variables)
2320   (when (gnus-visual-p 'summary-menu 'menu)
2321     (gnus-summary-make-menu-bar)
2322     (gnus-summary-make-tool-bar))
2323   (gnus-summary-make-local-variables)
2324   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2325     (gnus-summary-make-local-variables))
2326   (gnus-make-thread-indent-array)
2327   (gnus-simplify-mode-line)
2328   (setq major-mode 'gnus-summary-mode)
2329   (setq mode-name "Summary")
2330   (make-local-variable 'minor-mode-alist)
2331   (use-local-map gnus-summary-mode-map)
2332   (buffer-disable-undo)
2333   (setq buffer-read-only t)             ;Disable modification
2334   (setq truncate-lines t)
2335   (setq selective-display t)
2336   (setq selective-display-ellipses t)   ;Display `...'
2337   (gnus-summary-set-display-table)
2338   (gnus-set-default-directory)
2339   (setq gnus-newsgroup-name group)
2340   (unless (gnus-news-group-p group)
2341     (setq gnus-newsgroup-incorporated
2342           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2343   (make-local-variable 'gnus-summary-line-format)
2344   (make-local-variable 'gnus-summary-line-format-spec)
2345   (make-local-variable 'gnus-summary-dummy-line-format)
2346   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2347   (make-local-variable 'gnus-summary-mark-positions)
2348   (make-local-hook 'pre-command-hook)
2349   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2350   (gnus-run-hooks 'gnus-summary-mode-hook)
2351   (turn-on-gnus-mailing-list-mode)
2352   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2353   (gnus-update-summary-mark-positions))
2354
2355 (defun gnus-summary-make-local-variables ()
2356   "Make all the local summary buffer variables."
2357   (let (global)
2358     (dolist (local gnus-summary-local-variables)
2359       (if (consp local)
2360           (progn
2361             (if (eq (cdr local) 'global)
2362                 ;; Copy the global value of the variable.
2363                 (setq global (symbol-value (car local)))
2364               ;; Use the value from the list.
2365               (setq global (eval (cdr local))))
2366             (set (make-local-variable (car local)) global))
2367         ;; Simple nil-valued local variable.
2368         (set (make-local-variable local) nil)))))
2369
2370 (defun gnus-summary-clear-local-variables ()
2371   (let ((locals gnus-summary-local-variables))
2372     (while locals
2373       (if (consp (car locals))
2374           (and (vectorp (caar locals))
2375                (set (caar locals) nil))
2376         (and (vectorp (car locals))
2377              (set (car locals) nil)))
2378       (setq locals (cdr locals)))))
2379
2380 ;; Summary data functions.
2381
2382 (defmacro gnus-data-number (data)
2383   `(car ,data))
2384
2385 (defmacro gnus-data-set-number (data number)
2386   `(setcar ,data ,number))
2387
2388 (defmacro gnus-data-mark (data)
2389   `(nth 1 ,data))
2390
2391 (defmacro gnus-data-set-mark (data mark)
2392   `(setcar (nthcdr 1 ,data) ,mark))
2393
2394 (defmacro gnus-data-pos (data)
2395   `(nth 2 ,data))
2396
2397 (defmacro gnus-data-set-pos (data pos)
2398   `(setcar (nthcdr 2 ,data) ,pos))
2399
2400 (defmacro gnus-data-header (data)
2401   `(nth 3 ,data))
2402
2403 (defmacro gnus-data-set-header (data header)
2404   `(setcar (nthcdr 3 ,data) ,header))
2405
2406 (defmacro gnus-data-level (data)
2407   `(nth 4 ,data))
2408
2409 (defmacro gnus-data-unread-p (data)
2410   `(= (nth 1 ,data) gnus-unread-mark))
2411
2412 (defmacro gnus-data-read-p (data)
2413   `(/= (nth 1 ,data) gnus-unread-mark))
2414
2415 (defmacro gnus-data-pseudo-p (data)
2416   `(consp (nth 3 ,data)))
2417
2418 (defmacro gnus-data-find (number)
2419   `(assq ,number gnus-newsgroup-data))
2420
2421 (defmacro gnus-data-find-list (number &optional data)
2422   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2423      (memq (assq ,number bdata)
2424            bdata)))
2425
2426 (defmacro gnus-data-make (number mark pos header level)
2427   `(list ,number ,mark ,pos ,header ,level))
2428
2429 (defun gnus-data-enter (after-article number mark pos header level offset)
2430   (let ((data (gnus-data-find-list after-article)))
2431     (unless data
2432       (error "No such article: %d" after-article))
2433     (setcdr data (cons (gnus-data-make number mark pos header level)
2434                        (cdr data)))
2435     (setq gnus-newsgroup-data-reverse nil)
2436     (gnus-data-update-list (cddr data) offset)))
2437
2438 (defun gnus-data-enter-list (after-article list &optional offset)
2439   (when list
2440     (let ((data (and after-article (gnus-data-find-list after-article)))
2441           (ilist list))
2442       (if (not (or data
2443                    after-article))
2444           (let ((odata gnus-newsgroup-data))
2445             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2446             (when offset
2447               (gnus-data-update-list odata offset)))
2448         ;; Find the last element in the list to be spliced into the main
2449         ;; list.
2450         (while (cdr list)
2451           (setq list (cdr list)))
2452         (if (not data)
2453             (progn
2454               (setcdr list gnus-newsgroup-data)
2455               (setq gnus-newsgroup-data ilist)
2456               (when offset
2457                 (gnus-data-update-list (cdr list) offset)))
2458           (setcdr list (cdr data))
2459           (setcdr data ilist)
2460           (when offset
2461             (gnus-data-update-list (cdr list) offset))))
2462       (setq gnus-newsgroup-data-reverse nil))))
2463
2464 (defun gnus-data-remove (article &optional offset)
2465   (let ((data gnus-newsgroup-data))
2466     (if (= (gnus-data-number (car data)) article)
2467         (progn
2468           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2469                 gnus-newsgroup-data-reverse nil)
2470           (when offset
2471             (gnus-data-update-list gnus-newsgroup-data offset)))
2472       (while (cdr data)
2473         (when (= (gnus-data-number (cadr data)) article)
2474           (setcdr data (cddr data))
2475           (when offset
2476             (gnus-data-update-list (cdr data) offset))
2477           (setq data nil
2478                 gnus-newsgroup-data-reverse nil))
2479         (setq data (cdr data))))))
2480
2481 (defmacro gnus-data-list (backward)
2482   `(if ,backward
2483        (or gnus-newsgroup-data-reverse
2484            (setq gnus-newsgroup-data-reverse
2485                  (reverse gnus-newsgroup-data)))
2486      gnus-newsgroup-data))
2487
2488 (defun gnus-data-update-list (data offset)
2489   "Add OFFSET to the POS of all data entries in DATA."
2490   (setq gnus-newsgroup-data-reverse nil)
2491   (while data
2492     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2493     (setq data (cdr data))))
2494
2495 (defun gnus-summary-article-pseudo-p (article)
2496   "Say whether this article is a pseudo article or not."
2497   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2498
2499 (defmacro gnus-summary-article-sparse-p (article)
2500   "Say whether this article is a sparse article or not."
2501   `(memq ,article gnus-newsgroup-sparse))
2502
2503 (defmacro gnus-summary-article-ancient-p (article)
2504   "Say whether this article is a sparse article or not."
2505   `(memq ,article gnus-newsgroup-ancient))
2506
2507 (defun gnus-article-parent-p (number)
2508   "Say whether this article is a parent or not."
2509   (let ((data (gnus-data-find-list number)))
2510     (and (cdr data)                     ; There has to be an article after...
2511          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2512             (gnus-data-level (nth 1 data))))))
2513
2514 (defun gnus-article-children (number)
2515   "Return a list of all children to NUMBER."
2516   (let* ((data (gnus-data-find-list number))
2517          (level (gnus-data-level (car data)))
2518          children)
2519     (setq data (cdr data))
2520     (while (and data
2521                 (= (gnus-data-level (car data)) (1+ level)))
2522       (push (gnus-data-number (car data)) children)
2523       (setq data (cdr data)))
2524     children))
2525
2526 (defmacro gnus-summary-skip-intangible ()
2527   "If the current article is intangible, then jump to a different article."
2528   '(let ((to (get-text-property (point) 'gnus-intangible)))
2529      (and to (gnus-summary-goto-subject to))))
2530
2531 (defmacro gnus-summary-article-intangible-p ()
2532   "Say whether this article is intangible or not."
2533   '(get-text-property (point) 'gnus-intangible))
2534
2535 (defun gnus-article-read-p (article)
2536   "Say whether ARTICLE is read or not."
2537   (not (or (memq article gnus-newsgroup-marked)
2538            (memq article gnus-newsgroup-unreads)
2539            (memq article gnus-newsgroup-unselected)
2540            (memq article gnus-newsgroup-dormant))))
2541
2542 ;; Some summary mode macros.
2543
2544 (defmacro gnus-summary-article-number ()
2545   "The article number of the article on the current line.
2546 If there isn's an article number here, then we return the current
2547 article number."
2548   '(progn
2549      (gnus-summary-skip-intangible)
2550      (or (get-text-property (point) 'gnus-number)
2551          (gnus-summary-last-subject))))
2552
2553 (defmacro gnus-summary-article-header (&optional number)
2554   "Return the header of article NUMBER."
2555   `(gnus-data-header (gnus-data-find
2556                       ,(or number '(gnus-summary-article-number)))))
2557
2558 (defmacro gnus-summary-thread-level (&optional number)
2559   "Return the level of thread that starts with article NUMBER."
2560   `(if (and (eq gnus-summary-make-false-root 'dummy)
2561             (get-text-property (point) 'gnus-intangible))
2562        0
2563      (gnus-data-level (gnus-data-find
2564                        ,(or number '(gnus-summary-article-number))))))
2565
2566 (defmacro gnus-summary-article-mark (&optional number)
2567   "Return the mark of article NUMBER."
2568   `(gnus-data-mark (gnus-data-find
2569                     ,(or number '(gnus-summary-article-number)))))
2570
2571 (defmacro gnus-summary-article-pos (&optional number)
2572   "Return the position of the line of article NUMBER."
2573   `(gnus-data-pos (gnus-data-find
2574                    ,(or number '(gnus-summary-article-number)))))
2575
2576 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2577 (defmacro gnus-summary-article-subject (&optional number)
2578   "Return current subject string or nil if nothing."
2579   `(let ((headers
2580           ,(if number
2581                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2582              '(gnus-data-header (assq (gnus-summary-article-number)
2583                                       gnus-newsgroup-data)))))
2584      (and headers
2585           (vectorp headers)
2586           (mail-header-subject headers))))
2587
2588 (defmacro gnus-summary-article-score (&optional number)
2589   "Return current article score."
2590   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2591                   gnus-newsgroup-scored))
2592        gnus-summary-default-score 0))
2593
2594 (defun gnus-summary-article-children (&optional number)
2595   "Return a list of article numbers that are children of article NUMBER."
2596   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2597          (level (gnus-data-level (car data)))
2598          l children)
2599     (while (and (setq data (cdr data))
2600                 (> (setq l (gnus-data-level (car data))) level))
2601       (and (= (1+ level) l)
2602            (push (gnus-data-number (car data))
2603                  children)))
2604     (nreverse children)))
2605
2606 (defun gnus-summary-article-parent (&optional number)
2607   "Return the article number of the parent of article NUMBER."
2608   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2609                                     (gnus-data-list t)))
2610          (level (gnus-data-level (car data))))
2611     (if (zerop level)
2612         ()                              ; This is a root.
2613       ;; We search until we find an article with a level less than
2614       ;; this one.  That function has to be the parent.
2615       (while (and (setq data (cdr data))
2616                   (not (< (gnus-data-level (car data)) level))))
2617       (and data (gnus-data-number (car data))))))
2618
2619 (defun gnus-unread-mark-p (mark)
2620   "Say whether MARK is the unread mark."
2621   (= mark gnus-unread-mark))
2622
2623 (defun gnus-read-mark-p (mark)
2624   "Say whether MARK is one of the marks that mark as read.
2625 This is all marks except unread, ticked, dormant, and expirable."
2626   (not (or (= mark gnus-unread-mark)
2627            (= mark gnus-ticked-mark)
2628            (= mark gnus-dormant-mark)
2629            (= mark gnus-expirable-mark))))
2630
2631 (defmacro gnus-article-mark (number)
2632   "Return the MARK of article NUMBER.
2633 This macro should only be used when computing the mark the \"first\"
2634 time; i.e., when generating the summary lines.  After that,
2635 `gnus-summary-article-mark' should be used to examine the
2636 marks of articles."
2637   `(cond
2638     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2639     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2640     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2641     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2642     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2643     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2644     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2645     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2646            gnus-ancient-mark))))
2647
2648 ;; Saving hidden threads.
2649
2650 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2651 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2652
2653 (defmacro gnus-save-hidden-threads (&rest forms)
2654   "Save hidden threads, eval FORMS, and restore the hidden threads."
2655   (let ((config (make-symbol "config")))
2656     `(let ((,config (gnus-hidden-threads-configuration)))
2657        (unwind-protect
2658            (save-excursion
2659              ,@forms)
2660          (gnus-restore-hidden-threads-configuration ,config)))))
2661
2662 (defun gnus-data-compute-positions ()
2663   "Compute the positions of all articles."
2664   (setq gnus-newsgroup-data-reverse nil)
2665   (let ((data gnus-newsgroup-data))
2666     (save-excursion
2667       (gnus-save-hidden-threads
2668         (gnus-summary-show-all-threads)
2669         (goto-char (point-min))
2670         (while data
2671           (while (get-text-property (point) 'gnus-intangible)
2672             (forward-line 1))
2673           (gnus-data-set-pos (car data) (+ (point) 3))
2674           (setq data (cdr data))
2675           (forward-line 1))))))
2676
2677 (defun gnus-hidden-threads-configuration ()
2678   "Return the current hidden threads configuration."
2679   (save-excursion
2680     (let (config)
2681       (goto-char (point-min))
2682       (while (search-forward "\r" nil t)
2683         (push (1- (point)) config))
2684       config)))
2685
2686 (defun gnus-restore-hidden-threads-configuration (config)
2687   "Restore hidden threads configuration from CONFIG."
2688   (save-excursion
2689     (let (point buffer-read-only)
2690       (while (setq point (pop config))
2691         (when (and (< point (point-max))
2692                    (goto-char point)
2693                    (eq (char-after) ?\n))
2694           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2695
2696 ;; Various summary mode internalish functions.
2697
2698 (defun gnus-mouse-pick-article (e)
2699   (interactive "e")
2700   (mouse-set-point e)
2701   (gnus-summary-next-page nil t))
2702
2703 (defun gnus-summary-set-display-table ()
2704   "Change the display table.
2705 Odd characters have a tendency to mess
2706 up nicely formatted displays - we make all possible glyphs
2707 display only a single character."
2708
2709   ;; We start from the standard display table, if any.
2710   (let ((table (or (copy-sequence standard-display-table)
2711                    (make-display-table)))
2712         (i 32))
2713     ;; Nix out all the control chars...
2714     (while (>= (setq i (1- i)) 0)
2715       (aset table i [??]))
2716     ;; ... but not newline and cr, of course.  (cr is necessary for the
2717     ;; selective display).
2718     (aset table ?\n nil)
2719     (aset table ?\r nil)
2720     ;; We keep TAB as well.
2721     (aset table ?\t nil)
2722     ;; We nix out any glyphs over 126 that are not set already.
2723     (let ((i 256))
2724       (while (>= (setq i (1- i)) 127)
2725         ;; Only modify if the entry is nil.
2726         (unless (aref table i)
2727           (aset table i [??]))))
2728     (setq buffer-display-table table)))
2729
2730 (defun gnus-summary-set-article-display-arrow (pos)
2731   "Update the overlay arrow to point to line at position POS."
2732   (when (and gnus-summary-display-arrow
2733              (boundp 'overlay-arrow-position)
2734              (boundp 'overlay-arrow-string))
2735     (save-excursion
2736       (goto-char pos)
2737       (beginning-of-line)
2738       (unless overlay-arrow-position
2739         (setq overlay-arrow-position (make-marker)))
2740       (setq overlay-arrow-string "=>"
2741             overlay-arrow-position (set-marker overlay-arrow-position
2742                                                (point)
2743                                                (current-buffer))))))
2744
2745 (defun gnus-summary-buffer-name (group)
2746   "Return the summary buffer name of GROUP."
2747   (concat "*Summary " group "*"))
2748
2749 (defun gnus-summary-setup-buffer (group)
2750   "Initialize summary buffer."
2751   (let ((buffer (gnus-summary-buffer-name group)))
2752     (if (get-buffer buffer)
2753         (progn
2754           (set-buffer buffer)
2755           (setq gnus-summary-buffer (current-buffer))
2756           (not gnus-newsgroup-prepared))
2757       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2758       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2759       (gnus-summary-mode group)
2760       (when gnus-carpal
2761         (gnus-carpal-setup-buffer 'summary))
2762       (unless gnus-single-article-buffer
2763         (make-local-variable 'gnus-article-buffer)
2764         (make-local-variable 'gnus-article-current)
2765         (make-local-variable 'gnus-original-article-buffer))
2766       (setq gnus-newsgroup-name group)
2767       ;; Set any local variables in the group parameters.
2768       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2769       t)))
2770
2771 (defun gnus-set-global-variables ()
2772   "Set the global equivalents of the buffer-local variables.
2773 They are set to the latest values they had.  These reflect the summary
2774 buffer that was in action when the last article was fetched."
2775   (when (eq major-mode 'gnus-summary-mode)
2776     (setq gnus-summary-buffer (current-buffer))
2777     (let ((name gnus-newsgroup-name)
2778           (marked gnus-newsgroup-marked)
2779           (unread gnus-newsgroup-unreads)
2780           (headers gnus-current-headers)
2781           (data gnus-newsgroup-data)
2782           (summary gnus-summary-buffer)
2783           (article-buffer gnus-article-buffer)
2784           (original gnus-original-article-buffer)
2785           (gac gnus-article-current)
2786           (reffed gnus-reffed-article-number)
2787           (score-file gnus-current-score-file)
2788           (default-charset gnus-newsgroup-charset)
2789           vlist)
2790       (let ((locals gnus-newsgroup-variables))
2791         (while locals
2792           (if (consp (car locals))
2793               (push (eval (caar locals)) vlist)
2794             (push (eval (car locals)) vlist))
2795           (setq locals (cdr locals)))
2796         (setq vlist (nreverse vlist)))
2797       (save-excursion
2798         (set-buffer gnus-group-buffer)
2799         (setq gnus-newsgroup-name name
2800               gnus-newsgroup-marked marked
2801               gnus-newsgroup-unreads unread
2802               gnus-current-headers headers
2803               gnus-newsgroup-data data
2804               gnus-article-current gac
2805               gnus-summary-buffer summary
2806               gnus-article-buffer article-buffer
2807               gnus-original-article-buffer original
2808               gnus-reffed-article-number reffed
2809               gnus-current-score-file score-file
2810               gnus-newsgroup-charset default-charset)
2811         (let ((locals gnus-newsgroup-variables))
2812           (while locals
2813             (if (consp (car locals))
2814                 (set (caar locals) (pop vlist))
2815               (set (car locals) (pop vlist)))
2816             (setq locals (cdr locals))))
2817         ;; The article buffer also has local variables.
2818         (when (gnus-buffer-live-p gnus-article-buffer)
2819           (set-buffer gnus-article-buffer)
2820           (setq gnus-summary-buffer summary))))))
2821
2822 (defun gnus-summary-article-unread-p (article)
2823   "Say whether ARTICLE is unread or not."
2824   (memq article gnus-newsgroup-unreads))
2825
2826 (defun gnus-summary-first-article-p (&optional article)
2827   "Return whether ARTICLE is the first article in the buffer."
2828   (if (not (setq article (or article (gnus-summary-article-number))))
2829       nil
2830     (eq article (caar gnus-newsgroup-data))))
2831
2832 (defun gnus-summary-last-article-p (&optional article)
2833   "Return whether ARTICLE is the last article in the buffer."
2834   (if (not (setq article (or article (gnus-summary-article-number))))
2835       ;; All non-existent numbers are the last article.  :-)
2836       t
2837     (not (cdr (gnus-data-find-list article)))))
2838
2839 (defun gnus-make-thread-indent-array ()
2840   (let ((n 200))
2841     (unless (and gnus-thread-indent-array
2842                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2843       (setq gnus-thread-indent-array (make-vector 201 "")
2844             gnus-thread-indent-array-level gnus-thread-indent-level)
2845       (while (>= n 0)
2846         (aset gnus-thread-indent-array n
2847               (make-string (* n gnus-thread-indent-level) ? ))
2848         (setq n (1- n))))))
2849
2850 (defun gnus-update-summary-mark-positions ()
2851   "Compute where the summary marks are to go."
2852   (save-excursion
2853     (when (gnus-buffer-exists-p gnus-summary-buffer)
2854       (set-buffer gnus-summary-buffer))
2855     (let ((gnus-replied-mark 129)
2856           (gnus-score-below-mark 130)
2857           (gnus-score-over-mark 130)
2858           (gnus-download-mark 131)
2859           (spec gnus-summary-line-format-spec)
2860           gnus-visual pos)
2861       (save-excursion
2862         (gnus-set-work-buffer)
2863         (let ((gnus-summary-line-format-spec spec)
2864               (gnus-newsgroup-downloadable '((0 . t))))
2865           (gnus-summary-insert-line
2866            (make-full-mail-header 0 "" "nobody"
2867                                   "05 Apr 2001 23:33:09 +0400"
2868                                   "" "" 0 0 "" nil)
2869            0 nil 128 t nil "" nil 1)
2870           (goto-char (point-min))
2871           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2872                                              (- (point) 2)))))
2873           (goto-char (point-min))
2874           (push (cons 'replied (and (search-forward "\201" nil t)
2875                                     (- (point) 2)))
2876                 pos)
2877           (goto-char (point-min))
2878           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2879                 pos)
2880           (goto-char (point-min))
2881           (push (cons 'download
2882                       (and (search-forward "\203" nil t) (- (point) 2)))
2883                 pos)))
2884       (setq gnus-summary-mark-positions pos))))
2885
2886 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2887   "Insert a dummy root in the summary buffer."
2888   (beginning-of-line)
2889   (gnus-add-text-properties
2890    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2891    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2892
2893 (defun gnus-summary-from-or-to-or-newsgroups (header)
2894   (let ((to (cdr (assq 'To (mail-header-extra header))))
2895         (newsgroups (cdr (assq 'Newsgroups (mail-header-extra header))))
2896         (default-mime-charset (with-current-buffer gnus-summary-buffer
2897                                 default-mime-charset)))
2898     (cond
2899      ((and to
2900            gnus-ignored-from-addresses
2901            (string-match gnus-ignored-from-addresses
2902                          (mail-header-from header)))
2903       (concat "-> "
2904               (or (car (funcall gnus-extract-address-components
2905                                 (funcall
2906                                  gnus-decode-encoded-word-function to)))
2907                   (funcall gnus-decode-encoded-word-function to))))
2908      ((and newsgroups
2909            gnus-ignored-from-addresses
2910            (string-match gnus-ignored-from-addresses
2911                          (mail-header-from header)))
2912       (concat "=> " newsgroups))
2913      (t
2914       (or (car (funcall gnus-extract-address-components
2915                         (mail-header-from header)))
2916           (mail-header-from header))))))
2917
2918 (defun gnus-summary-insert-line (gnus-tmp-header
2919                                  gnus-tmp-level gnus-tmp-current
2920                                  gnus-tmp-unread gnus-tmp-replied
2921                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2922                                  &optional gnus-tmp-dummy gnus-tmp-score
2923                                  gnus-tmp-process)
2924   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2925          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2926          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2927          (gnus-tmp-score-char
2928           (if (or (null gnus-summary-default-score)
2929                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2930                       gnus-summary-zcore-fuzz))
2931               ?\ ;;;Whitespace
2932             (if (< gnus-tmp-score gnus-summary-default-score)
2933                 gnus-score-below-mark gnus-score-over-mark)))
2934          (gnus-tmp-replied
2935           (cond (gnus-tmp-process gnus-process-mark)
2936                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2937                  gnus-cached-mark)
2938                 (gnus-tmp-replied gnus-replied-mark)
2939                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2940                  gnus-saved-mark)
2941                 (t gnus-no-mark)))
2942          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2943          (gnus-tmp-name
2944           (cond
2945            ((string-match "<[^>]+> *$" gnus-tmp-from)
2946             (let ((beg (match-beginning 0)))
2947               (or (and (string-match "^\".+\"" gnus-tmp-from)
2948                        (substring gnus-tmp-from 1 (1- (match-end 0))))
2949                   (substring gnus-tmp-from 0 beg))))
2950            ((string-match "(.+)" gnus-tmp-from)
2951             (substring gnus-tmp-from
2952                        (1+ (match-beginning 0)) (1- (match-end 0))))
2953            (t gnus-tmp-from)))
2954          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2955          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2956          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2957          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2958          (buffer-read-only nil))
2959     (when (string= gnus-tmp-name "")
2960       (setq gnus-tmp-name gnus-tmp-from))
2961     (unless (numberp gnus-tmp-lines)
2962       (setq gnus-tmp-lines -1))
2963     (when (= gnus-tmp-lines -1)
2964       (setq gnus-tmp-lines "?"))
2965     (gnus-put-text-property-excluding-characters-with-faces
2966      (point)
2967      (progn (eval gnus-summary-line-format-spec) (point))
2968      'gnus-number gnus-tmp-number)
2969     (when (gnus-visual-p 'summary-highlight 'highlight)
2970       (forward-line -1)
2971       (gnus-run-hooks 'gnus-summary-update-hook)
2972       (forward-line 1))))
2973
2974 (defun gnus-summary-update-line (&optional dont-update)
2975   "Update summary line after change."
2976   (when (and gnus-summary-default-score
2977              (not gnus-summary-inhibit-highlight))
2978     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2979            (article (gnus-summary-article-number))
2980            (score (gnus-summary-article-score article)))
2981       (unless dont-update
2982         (if (and gnus-summary-mark-below
2983                  (< (gnus-summary-article-score)
2984                     gnus-summary-mark-below))
2985             ;; This article has a low score, so we mark it as read.
2986             (when (memq article gnus-newsgroup-unreads)
2987               (gnus-summary-mark-article-as-read gnus-low-score-mark))
2988           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2989             ;; This article was previously marked as read on account
2990             ;; of a low score, but now it has risen, so we mark it as
2991             ;; unread.
2992             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2993         (gnus-summary-update-mark
2994          (if (or (null gnus-summary-default-score)
2995                  (<= (abs (- score gnus-summary-default-score))
2996                      gnus-summary-zcore-fuzz))
2997              ?\ ;;;Whitespace
2998            (if (< score gnus-summary-default-score)
2999                gnus-score-below-mark gnus-score-over-mark))
3000          'score))
3001       ;; Do visual highlighting.
3002       (when (gnus-visual-p 'summary-highlight 'highlight)
3003         (gnus-run-hooks 'gnus-summary-update-hook)))))
3004
3005 (defvar gnus-tmp-new-adopts nil)
3006
3007 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3008   "Return the number of articles in THREAD.
3009 This may be 0 in some cases -- if none of the articles in
3010 the thread are to be displayed."
3011   (let* ((number
3012           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3013           (cond
3014            ((not (listp thread))
3015             1)
3016            ((and (consp thread) (cdr thread))
3017             (apply
3018              '+ 1 (mapcar
3019                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3020            ((null thread)
3021             1)
3022            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3023             1)
3024            (t 0))))
3025     (when (and level (zerop level) gnus-tmp-new-adopts)
3026       (incf number
3027             (apply '+ (mapcar
3028                        'gnus-summary-number-of-articles-in-thread
3029                        gnus-tmp-new-adopts))))
3030     (if char
3031         (if (> number 1) gnus-not-empty-thread-mark
3032           gnus-empty-thread-mark)
3033       number)))
3034
3035 (defun gnus-summary-set-local-parameters (group)
3036   "Go through the local params of GROUP and set all variable specs in that list."
3037   (let ((params (gnus-group-find-parameter group))
3038         (vars '(quit-config))           ; Ignore quit-config.
3039         elem)
3040     (while params
3041       (setq elem (car params)
3042             params (cdr params))
3043       (and (consp elem)                 ; Has to be a cons.
3044            (consp (cdr elem))           ; The cdr has to be a list.
3045            (symbolp (car elem))         ; Has to be a symbol in there.
3046            (not (memq (car elem) vars))
3047            (ignore-errors               ; So we set it.
3048              (push (car elem) vars)
3049              (make-local-variable (car elem))
3050              (set (car elem) (eval (nth 1 elem))))))))
3051
3052 (defun gnus-summary-read-group (group &optional show-all no-article
3053                                       kill-buffer no-display backward
3054                                       select-articles)
3055   "Start reading news in newsgroup GROUP.
3056 If SHOW-ALL is non-nil, already read articles are also listed.
3057 If NO-ARTICLE is non-nil, no article is selected initially.
3058 If NO-DISPLAY, don't generate a summary buffer."
3059   (let (result)
3060     (while (and group
3061                 (null (setq result
3062                             (let ((gnus-auto-select-next nil))
3063                               (or (gnus-summary-read-group-1
3064                                    group show-all no-article
3065                                    kill-buffer no-display
3066                                    select-articles)
3067                                   (setq show-all nil
3068                                         select-articles nil)))))
3069                 (eq gnus-auto-select-next 'quietly))
3070       (set-buffer gnus-group-buffer)
3071       ;; The entry function called above goes to the next
3072       ;; group automatically, so we go two groups back
3073       ;; if we are searching for the previous group.
3074       (when backward
3075         (gnus-group-prev-unread-group 2))
3076       (if (not (equal group (gnus-group-group-name)))
3077           (setq group (gnus-group-group-name))
3078         (setq group nil)))
3079     result))
3080
3081 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3082   "Directly jump to the other GROUP from summary buffer.
3083 If SHOW-ALL is non-nil, already read articles are also listed."
3084   (interactive
3085    (if (eq gnus-summary-buffer (current-buffer))
3086        (list (completing-read
3087               "Group: " gnus-active-hashtb nil t
3088               (when (and gnus-newsgroup-name
3089                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3090                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3091               'gnus-group-history)
3092              current-prefix-arg)
3093      (error "%s must be invoked from a gnus summary buffer." this-command)))
3094   (unless (or (zerop (length group))
3095               (and gnus-newsgroup-name
3096                    (string-equal gnus-newsgroup-name group)))
3097     (gnus-summary-exit)
3098     (gnus-summary-read-group group show-all
3099                              gnus-dont-select-after-jump-to-other-group)))
3100
3101 (defun gnus-summary-read-group-1 (group show-all no-article
3102                                         kill-buffer no-display
3103                                         &optional select-articles)
3104   ;; Killed foreign groups can't be entered.
3105   ;;  (when (and (not (gnus-group-native-p group))
3106   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3107   ;;    (error "Dead non-native groups can't be entered"))
3108   (gnus-message 5 "Retrieving newsgroup: %s..."
3109                 (gnus-group-decoded-name group))
3110   (let* ((new-group (gnus-summary-setup-buffer group))
3111          (quit-config (gnus-group-quit-config group))
3112          (did-select (and new-group (gnus-select-newsgroup
3113                                      group show-all select-articles))))
3114     (cond
3115      ;; This summary buffer exists already, so we just select it.
3116      ((not new-group)
3117       (gnus-set-global-variables)
3118       (when kill-buffer
3119         (gnus-kill-or-deaden-summary kill-buffer))
3120       (gnus-configure-windows 'summary 'force)
3121       (gnus-set-mode-line 'summary)
3122       (gnus-summary-position-point)
3123       (message "")
3124       t)
3125      ;; We couldn't select this group.
3126      ((null did-select)
3127       (when (and (eq major-mode 'gnus-summary-mode)
3128                  (not (equal (current-buffer) kill-buffer)))
3129         (kill-buffer (current-buffer))
3130         (if (not quit-config)
3131             (progn
3132               ;; Update the info -- marks might need to be removed,
3133               ;; for instance.
3134               (gnus-summary-update-info)
3135               (set-buffer gnus-group-buffer)
3136               (gnus-group-jump-to-group group)
3137               (gnus-group-next-unread-group 1))
3138           (gnus-handle-ephemeral-exit quit-config)))
3139       (let ((grpinfo (gnus-get-info group)))
3140         (if (null (gnus-info-read grpinfo))
3141             (gnus-message 3 "Group %s contains no messages"
3142                           (gnus-group-decoded-name group))
3143           (gnus-message 3 "Can't select group")))
3144       nil)
3145      ;; The user did a `C-g' while prompting for number of articles,
3146      ;; so we exit this group.
3147      ((eq did-select 'quit)
3148       (and (eq major-mode 'gnus-summary-mode)
3149            (not (equal (current-buffer) kill-buffer))
3150            (kill-buffer (current-buffer)))
3151       (when kill-buffer
3152         (gnus-kill-or-deaden-summary kill-buffer))
3153       (if (not quit-config)
3154           (progn
3155             (set-buffer gnus-group-buffer)
3156             (gnus-group-jump-to-group group)
3157             (gnus-group-next-unread-group 1)
3158             (gnus-configure-windows 'group 'force))
3159         (gnus-handle-ephemeral-exit quit-config))
3160       ;; Finally signal the quit.
3161       (signal 'quit nil))
3162      ;; The group was successfully selected.
3163      (t
3164       (gnus-set-global-variables)
3165       ;; Save the active value in effect when the group was entered.
3166       (setq gnus-newsgroup-active
3167             (gnus-copy-sequence
3168              (gnus-active gnus-newsgroup-name)))
3169       ;; You can change the summary buffer in some way with this hook.
3170       (gnus-run-hooks 'gnus-select-group-hook)
3171       (gnus-update-format-specifications
3172        nil 'summary 'summary-mode 'summary-dummy)
3173       (gnus-update-summary-mark-positions)
3174       ;; Do score processing.
3175       (when gnus-use-scoring
3176         (gnus-possibly-score-headers))
3177       ;; Check whether to fill in the gaps in the threads.
3178       (when gnus-build-sparse-threads
3179         (gnus-build-sparse-threads))
3180       ;; Find the initial limit.
3181       (if gnus-show-threads
3182           (if show-all
3183               (let ((gnus-newsgroup-dormant nil))
3184                 (gnus-summary-initial-limit show-all))
3185             (gnus-summary-initial-limit show-all))
3186         ;; When untreaded, all articles are always shown.
3187         (setq gnus-newsgroup-limit
3188               (mapcar
3189                (lambda (header) (mail-header-number header))
3190                gnus-newsgroup-headers)))
3191       ;; Generate the summary buffer.
3192       (unless no-display
3193         (gnus-summary-prepare))
3194       (when gnus-use-trees
3195         (gnus-tree-open group)
3196         (setq gnus-summary-highlight-line-function
3197               'gnus-tree-highlight-article))
3198       ;; If the summary buffer is empty, but there are some low-scored
3199       ;; articles or some excluded dormants, we include these in the
3200       ;; buffer.
3201       (when (and (zerop (buffer-size))
3202                  (not no-display))
3203         (cond (gnus-newsgroup-dormant
3204                (gnus-summary-limit-include-dormant))
3205               ((and gnus-newsgroup-scored show-all)
3206                (gnus-summary-limit-include-expunged t))))
3207       ;; Function `gnus-apply-kill-file' must be called in this hook.
3208       (gnus-run-hooks 'gnus-apply-kill-hook)
3209       (if (and (zerop (buffer-size))
3210                (not no-display))
3211           (progn
3212             ;; This newsgroup is empty.
3213             (gnus-summary-catchup-and-exit nil t)
3214             (gnus-message 6 "No unread news")
3215             (when kill-buffer
3216               (gnus-kill-or-deaden-summary kill-buffer))
3217             ;; Return nil from this function.
3218             nil)
3219         ;; Hide conversation thread subtrees.  We cannot do this in
3220         ;; gnus-summary-prepare-hook since kill processing may not
3221         ;; work with hidden articles.
3222         (and gnus-show-threads
3223              gnus-thread-hide-subtree
3224              (gnus-summary-hide-all-threads))
3225         (when kill-buffer
3226           (gnus-kill-or-deaden-summary kill-buffer))
3227         ;; Show first unread article if requested.
3228         (if (and (not no-article)
3229                  (not no-display)
3230                  gnus-newsgroup-unreads
3231                  gnus-auto-select-first)
3232             (progn
3233               (gnus-configure-windows 'summary)
3234               (cond
3235                ((eq gnus-auto-select-first 'best)
3236                 (gnus-summary-best-unread-article))
3237                ((eq gnus-auto-select-first t)
3238                 (gnus-summary-first-unread-article))
3239                ((gnus-functionp gnus-auto-select-first)
3240                 (funcall gnus-auto-select-first))))
3241           ;; Don't select any articles, just move point to the first
3242           ;; article in the group.
3243           (goto-char (point-min))
3244           (gnus-summary-position-point)
3245           (gnus-configure-windows 'summary 'force)
3246           (gnus-set-mode-line 'summary))
3247         (when (get-buffer-window gnus-group-buffer t)
3248           ;; Gotta use windows, because recenter does weird stuff if
3249           ;; the current buffer ain't the displayed window.
3250           (let ((owin (selected-window)))
3251             (select-window (get-buffer-window gnus-group-buffer t))
3252             (when (gnus-group-goto-group group)
3253               (recenter))
3254             (select-window owin)))
3255         ;; Mark this buffer as "prepared".
3256         (setq gnus-newsgroup-prepared t)
3257         (gnus-run-hooks 'gnus-summary-prepared-hook)
3258         t)))))
3259
3260 (defun gnus-summary-prepare ()
3261   "Generate the summary buffer."
3262   (interactive)
3263   (let ((buffer-read-only nil))
3264     (erase-buffer)
3265     (setq gnus-newsgroup-data nil
3266           gnus-newsgroup-data-reverse nil)
3267     (gnus-run-hooks 'gnus-summary-generate-hook)
3268     ;; Generate the buffer, either with threads or without.
3269     (when gnus-newsgroup-headers
3270       (gnus-summary-prepare-threads
3271        (if gnus-show-threads
3272            (gnus-sort-gathered-threads
3273             (funcall gnus-summary-thread-gathering-function
3274                      (gnus-sort-threads
3275                       (gnus-cut-threads (gnus-make-threads)))))
3276          ;; Unthreaded display.
3277          (gnus-sort-articles gnus-newsgroup-headers))))
3278     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3279     ;; Call hooks for modifying summary buffer.
3280     (goto-char (point-min))
3281     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3282
3283 (defsubst gnus-general-simplify-subject (subject)
3284   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3285   (setq subject
3286         (cond
3287          ;; Truncate the subject.
3288          (gnus-simplify-subject-functions
3289           (gnus-map-function gnus-simplify-subject-functions subject))
3290          ((numberp gnus-summary-gather-subject-limit)
3291           (setq subject (gnus-simplify-subject-re subject))
3292           (if (> (length subject) gnus-summary-gather-subject-limit)
3293               (substring subject 0 gnus-summary-gather-subject-limit)
3294             subject))
3295          ;; Fuzzily simplify it.
3296          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3297           (gnus-simplify-subject-fuzzy subject))
3298          ;; Just remove the leading "Re:".
3299          (t
3300           (gnus-simplify-subject-re subject))))
3301
3302   (if (and gnus-summary-gather-exclude-subject
3303            (string-match gnus-summary-gather-exclude-subject subject))
3304       nil                               ; This article shouldn't be gathered
3305     subject))
3306
3307 (defun gnus-summary-simplify-subject-query ()
3308   "Query where the respool algorithm would put this article."
3309   (interactive)
3310   (gnus-summary-select-article)
3311   (message "%s"
3312            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3313
3314 (defun gnus-gather-threads-by-subject (threads)
3315   "Gather threads by looking at Subject headers."
3316   (if (not gnus-summary-make-false-root)
3317       threads
3318     (let ((hashtb (gnus-make-hashtable 1024))
3319           (prev threads)
3320           (result threads)
3321           subject hthread whole-subject)
3322       (while threads
3323         (setq subject (gnus-general-simplify-subject
3324                        (setq whole-subject (mail-header-subject
3325                                             (caar threads)))))
3326         (when subject
3327           (if (setq hthread (gnus-gethash subject hashtb))
3328               (progn
3329                 ;; We enter a dummy root into the thread, if we
3330                 ;; haven't done that already.
3331                 (unless (stringp (caar hthread))
3332                   (setcar hthread (list whole-subject (car hthread))))
3333                 ;; We add this new gathered thread to this gathered
3334                 ;; thread.
3335                 (setcdr (car hthread)
3336                         (nconc (cdar hthread) (list (car threads))))
3337                 ;; Remove it from the list of threads.
3338                 (setcdr prev (cdr threads))
3339                 (setq threads prev))
3340             ;; Enter this thread into the hash table.
3341             (gnus-sethash subject threads hashtb)))
3342         (setq prev threads)
3343         (setq threads (cdr threads)))
3344       result)))
3345
3346 (defun gnus-gather-threads-by-references (threads)
3347   "Gather threads by looking at References headers."
3348   (let ((idhashtb (gnus-make-hashtable 1024))
3349         (thhashtb (gnus-make-hashtable 1024))
3350         (prev threads)
3351         (result threads)
3352         ids references id gthread gid entered ref)
3353     (while threads
3354       (when (setq references (mail-header-references (caar threads)))
3355         (setq id (mail-header-id (caar threads))
3356               ids (gnus-split-references references)
3357               entered nil)
3358         (while (setq ref (pop ids))
3359           (setq ids (delete ref ids))
3360           (if (not (setq gid (gnus-gethash ref idhashtb)))
3361               (progn
3362                 (gnus-sethash ref id idhashtb)
3363                 (gnus-sethash id threads thhashtb))
3364             (setq gthread (gnus-gethash gid thhashtb))
3365             (unless entered
3366               ;; We enter a dummy root into the thread, if we
3367               ;; haven't done that already.
3368               (unless (stringp (caar gthread))
3369                 (setcar gthread (list (mail-header-subject (caar gthread))
3370                                       (car gthread))))
3371               ;; We add this new gathered thread to this gathered
3372               ;; thread.
3373               (setcdr (car gthread)
3374                       (nconc (cdar gthread) (list (car threads)))))
3375             ;; Add it into the thread hash table.
3376             (gnus-sethash id gthread thhashtb)
3377             (setq entered t)
3378             ;; Remove it from the list of threads.
3379             (setcdr prev (cdr threads))
3380             (setq threads prev))))
3381       (setq prev threads)
3382       (setq threads (cdr threads)))
3383     result))
3384
3385 (defun gnus-sort-gathered-threads (threads)
3386   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3387   (let ((result threads))
3388     (while threads
3389       (when (stringp (caar threads))
3390         (setcdr (car threads)
3391                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3392       (setq threads (cdr threads)))
3393     result))
3394
3395 (defun gnus-thread-loop-p (root thread)
3396   "Say whether ROOT is in THREAD."
3397   (let ((stack (list thread))
3398         (infloop 0)
3399         th)
3400     (while (setq thread (pop stack))
3401       (setq th (cdr thread))
3402       (while (and th
3403                   (not (eq (caar th) root)))
3404         (pop th))
3405       (if th
3406           ;; We have found a loop.
3407           (let (ref-dep)
3408             (setcdr thread (delq (car th) (cdr thread)))
3409             (if (boundp (setq ref-dep (intern "none"
3410                                               gnus-newsgroup-dependencies)))
3411                 (setcdr (symbol-value ref-dep)
3412                         (nconc (cdr (symbol-value ref-dep))
3413                                (list (car th))))
3414               (set ref-dep (list nil (car th))))
3415             (setq infloop 1
3416                   stack nil))
3417         ;; Push all the subthreads onto the stack.
3418         (push (cdr thread) stack)))
3419     infloop))
3420
3421 (defun gnus-make-threads ()
3422   "Go through the dependency hashtb and find the roots.  Return all threads."
3423   (let (threads)
3424     (while (catch 'infloop
3425              (mapatoms
3426               (lambda (refs)
3427                 ;; Deal with self-referencing References loops.
3428                 (when (and (car (symbol-value refs))
3429                            (not (zerop
3430                                  (apply
3431                                   '+
3432                                   (mapcar
3433                                    (lambda (thread)
3434                                      (gnus-thread-loop-p
3435                                       (car (symbol-value refs)) thread))
3436                                    (cdr (symbol-value refs)))))))
3437                   (setq threads nil)
3438                   (throw 'infloop t))
3439                 (unless (car (symbol-value refs))
3440                   ;; These threads do not refer back to any other articles,
3441                   ;; so they're roots.
3442                   (setq threads (append (cdr (symbol-value refs)) threads))))
3443               gnus-newsgroup-dependencies)))
3444     threads))
3445
3446 ;; Build the thread tree.
3447 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3448   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3449
3450 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3451 if it was already present.
3452
3453 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3454 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3455 Message-IDs will be renamed be renamed to a unique Message-ID before
3456 being entered.
3457
3458 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3459   (let* ((id (mail-header-id header))
3460          (id-dep (and id (intern id dependencies)))
3461          ref ref-dep ref-header)
3462     ;; Enter this `header' in the `dependencies' table.
3463     (cond
3464      ((not id-dep)
3465       (setq header nil))
3466      ;; The first two cases do the normal part: enter a new `header'
3467      ;; in the `dependencies' table.
3468      ((not (boundp id-dep))
3469       (set id-dep (list header)))
3470      ((null (car (symbol-value id-dep)))
3471       (setcar (symbol-value id-dep) header))
3472
3473      ;; From here the `header' was already present in the
3474      ;; `dependencies' table.
3475      (force-new
3476       ;; Overrides an existing entry;
3477       ;; just set the header part of the entry.
3478       (setcar (symbol-value id-dep) header))
3479
3480      ;; Renames the existing `header' to a unique Message-ID.
3481      ((not gnus-summary-ignore-duplicates)
3482       ;; An article with this Message-ID has already been seen.
3483       ;; We rename the Message-ID.
3484       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3485            (list header))
3486       (mail-header-set-id header id))
3487
3488      ;; The last case ignores an existing entry, except it adds any
3489      ;; additional Xrefs (in case the two articles came from different
3490      ;; servers.
3491      ;; Also sets `header' to `nil' meaning that the `dependencies'
3492      ;; table was *not* modified.
3493      (t
3494       (mail-header-set-xref
3495        (car (symbol-value id-dep))
3496        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3497                    "")
3498                (or (mail-header-xref header) "")))
3499       (setq header nil)))
3500
3501     (when header
3502       ;; First check if that we are not creating a References loop.
3503       (setq ref (gnus-parent-id (mail-header-references header)))
3504       (while (and ref
3505                   (setq ref-dep (intern-soft ref dependencies))
3506                   (boundp ref-dep)
3507                   (setq ref-header (car (symbol-value ref-dep))))
3508         (if (string= id ref)
3509             ;; Yuk!  This is a reference loop.  Make the article be a
3510             ;; root article.
3511             (progn
3512               (mail-header-set-references (car (symbol-value id-dep)) "none")
3513               (setq ref nil))
3514           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3515       (setq ref (gnus-parent-id (mail-header-references header)))
3516       (setq ref-dep (intern (or ref "none") dependencies))
3517       (if (boundp ref-dep)
3518           (setcdr (symbol-value ref-dep)
3519                   (nconc (cdr (symbol-value ref-dep))
3520                          (list (symbol-value id-dep))))
3521         (set ref-dep (list nil (symbol-value id-dep)))))
3522     header))
3523
3524 (defun gnus-build-sparse-threads ()
3525   (let ((headers gnus-newsgroup-headers)
3526         (mail-parse-charset gnus-newsgroup-charset)
3527         (gnus-summary-ignore-duplicates t)
3528         header references generation relations
3529         subject child end new-child date)
3530     ;; First we create an alist of generations/relations, where
3531     ;; generations is how much we trust the relation, and the relation
3532     ;; is parent/child.
3533     (gnus-message 7 "Making sparse threads...")
3534     (save-excursion
3535       (nnheader-set-temp-buffer " *gnus sparse threads*")
3536       (while (setq header (pop headers))
3537         (when (and (setq references (mail-header-references header))
3538                    (not (string= references "")))
3539           (insert references)
3540           (setq child (mail-header-id header)
3541                 subject (mail-header-subject header)
3542                 date (mail-header-date header)
3543                 generation 0)
3544           (while (search-backward ">" nil t)
3545             (setq end (1+ (point)))
3546             (when (search-backward "<" nil t)
3547               (setq new-child (buffer-substring (point) end))
3548               (push (list (incf generation)
3549                           child (setq child new-child)
3550                           subject date)
3551                     relations)))
3552           (when child
3553             (push (list (1+ generation) child nil subject) relations))
3554           (erase-buffer)))
3555       (kill-buffer (current-buffer)))
3556     ;; Sort over trustworthiness.
3557     (mapcar
3558      (lambda (relation)
3559        (when (gnus-dependencies-add-header
3560               (make-full-mail-header-from-decoded-header
3561                gnus-reffed-article-number
3562                (nth 3 relation) "" (or (nth 4 relation) "")
3563                (nth 1 relation)
3564                (or (nth 2 relation) "") 0 0 "")
3565               gnus-newsgroup-dependencies nil)
3566          (push gnus-reffed-article-number gnus-newsgroup-limit)
3567          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3568          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3569                gnus-newsgroup-reads)
3570          (decf gnus-reffed-article-number)))
3571      (sort relations 'car-less-than-car))
3572     (gnus-message 7 "Making sparse threads...done")))
3573
3574 (defun gnus-build-old-threads ()
3575   ;; Look at all the articles that refer back to old articles, and
3576   ;; fetch the headers for the articles that aren't there.  This will
3577   ;; build complete threads - if the roots haven't been expired by the
3578   ;; server, that is.
3579   (let ((mail-parse-charset gnus-newsgroup-charset)
3580         id heads)
3581     (mapatoms
3582      (lambda (refs)
3583        (when (not (car (symbol-value refs)))
3584          (setq heads (cdr (symbol-value refs)))
3585          (while heads
3586            (if (memq (mail-header-number (caar heads))
3587                      gnus-newsgroup-dormant)
3588                (setq heads (cdr heads))
3589              (setq id (symbol-name refs))
3590              (while (and (setq id (gnus-build-get-header id))
3591                          (not (car (gnus-id-to-thread id)))))
3592              (setq heads nil)))))
3593      gnus-newsgroup-dependencies)))
3594
3595 ;; This function has to be called with point after the article number
3596 ;; on the beginning of the line.
3597 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3598   (let ((eol (gnus-point-at-eol))
3599         (buffer (current-buffer))
3600         header)
3601
3602     ;; overview: [num subject from date id refs chars lines misc]
3603     (unwind-protect
3604         (progn
3605           (narrow-to-region (point) eol)
3606           (unless (eobp)
3607             (forward-char))
3608
3609           (setq header
3610                 (make-full-mail-header
3611                  number                         ; number
3612                  (nnheader-nov-field)           ; subject
3613                  (nnheader-nov-field)           ; from
3614                  (nnheader-nov-field)           ; date
3615                  (nnheader-nov-read-message-id) ; id
3616                  (nnheader-nov-field)           ; refs
3617                  (nnheader-nov-read-integer)    ; chars
3618                  (nnheader-nov-read-integer)    ; lines
3619                  (unless (eobp)
3620                    (if (looking-at "Xref: ")
3621                        (goto-char (match-end 0)))
3622                    (nnheader-nov-field))        ; Xref
3623                  (nnheader-nov-parse-extra))))  ; extra
3624
3625       (widen))
3626
3627     (when gnus-alter-header-function
3628       (funcall gnus-alter-header-function header))
3629     (gnus-dependencies-add-header header dependencies force-new)))
3630
3631 (defun gnus-build-get-header (id)
3632   "Look through the buffer of NOV lines and find the header to ID.
3633 Enter this line into the dependencies hash table, and return
3634 the id of the parent article (if any)."
3635   (let ((deps gnus-newsgroup-dependencies)
3636         found header)
3637     (prog1
3638         (save-excursion
3639           (set-buffer nntp-server-buffer)
3640           (let ((case-fold-search nil))
3641             (goto-char (point-min))
3642             (while (and (not found)
3643                         (search-forward id nil t))
3644               (beginning-of-line)
3645               (setq found (looking-at
3646                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3647                                    (regexp-quote id))))
3648               (or found (beginning-of-line 2)))
3649             (when found
3650               (beginning-of-line)
3651               (and
3652                (setq header (gnus-nov-parse-line
3653                              (read (current-buffer)) deps))
3654                (gnus-parent-id (mail-header-references header))))))
3655       (when header
3656         (let ((number (mail-header-number header)))
3657           (push number gnus-newsgroup-limit)
3658           (push header gnus-newsgroup-headers)
3659           (if (memq number gnus-newsgroup-unselected)
3660               (progn
3661                 (push number gnus-newsgroup-unreads)
3662                 (setq gnus-newsgroup-unselected
3663                       (delq number gnus-newsgroup-unselected)))
3664             (push number gnus-newsgroup-ancient)))))))
3665
3666 (defun gnus-build-all-threads ()
3667   "Read all the headers."
3668   (let ((gnus-summary-ignore-duplicates t)
3669         (mail-parse-charset gnus-newsgroup-charset)
3670         (dependencies gnus-newsgroup-dependencies)
3671         header article)
3672     (save-excursion
3673       (set-buffer nntp-server-buffer)
3674       (let ((case-fold-search nil))
3675         (goto-char (point-min))
3676         (while (not (eobp))
3677           (ignore-errors
3678             (setq article (read (current-buffer))
3679                   header (gnus-nov-parse-line article dependencies)))
3680           (when header
3681             (save-excursion
3682               (set-buffer gnus-summary-buffer)
3683               (push header gnus-newsgroup-headers)
3684               (if (memq (setq article (mail-header-number header))
3685                         gnus-newsgroup-unselected)
3686                   (progn
3687                     (push article gnus-newsgroup-unreads)
3688                     (setq gnus-newsgroup-unselected
3689                           (delq article gnus-newsgroup-unselected)))
3690                 (push article gnus-newsgroup-ancient)))
3691             (forward-line 1)))))))
3692
3693 (defun gnus-summary-update-article-line (article header)
3694   "Update the line for ARTICLE using HEADERS."
3695   (let* ((id (mail-header-id header))
3696          (thread (gnus-id-to-thread id)))
3697     (unless thread
3698       (error "Article in no thread"))
3699     ;; Update the thread.
3700     (setcar thread header)
3701     (gnus-summary-goto-subject article)
3702     (let* ((datal (gnus-data-find-list article))
3703            (data (car datal))
3704            (length (when (cdr datal)
3705                      (- (gnus-data-pos data)
3706                         (gnus-data-pos (cadr datal)))))
3707            (buffer-read-only nil)
3708            (level (gnus-summary-thread-level)))
3709       (gnus-delete-line)
3710       (gnus-summary-insert-line
3711        header level nil (gnus-article-mark article)
3712        (memq article gnus-newsgroup-replied)
3713        (memq article gnus-newsgroup-expirable)
3714        ;; Only insert the Subject string when it's different
3715        ;; from the previous Subject string.
3716        (if (and
3717             gnus-show-threads
3718             (gnus-subject-equal
3719              (condition-case ()
3720                  (mail-header-subject
3721                   (gnus-data-header
3722                    (cadr
3723                     (gnus-data-find-list
3724                      article
3725                      (gnus-data-list t)))))
3726                ;; Error on the side of excessive subjects.
3727                (error ""))
3728              (mail-header-subject header)))
3729            ""
3730          (mail-header-subject header))
3731        nil (cdr (assq article gnus-newsgroup-scored))
3732        (memq article gnus-newsgroup-processable))
3733       (when length
3734         (gnus-data-update-list
3735          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3736
3737 (defun gnus-summary-update-article (article &optional iheader)
3738   "Update ARTICLE in the summary buffer."
3739   (set-buffer gnus-summary-buffer)
3740   (let* ((header (gnus-summary-article-header article))
3741          (id (mail-header-id header))
3742          (data (gnus-data-find article))
3743          (thread (gnus-id-to-thread id))
3744          (references (mail-header-references header))
3745          (parent
3746           (gnus-id-to-thread
3747            (or (gnus-parent-id
3748                 (when (and references
3749                            (not (equal "" references)))
3750                   references))
3751                "none")))
3752          (buffer-read-only nil)
3753          (old (car thread)))
3754     (when thread
3755       (unless iheader
3756         (setcar thread nil)
3757         (when parent
3758           (delq thread parent)))
3759       (if (gnus-summary-insert-subject id header)
3760           ;; Set the (possibly) new article number in the data structure.
3761           (gnus-data-set-number data (gnus-id-to-article id))
3762         (setcar thread old)
3763         nil))))
3764
3765 (defun gnus-rebuild-thread (id &optional line)
3766   "Rebuild the thread containing ID.
3767 If LINE, insert the rebuilt thread starting on line LINE."
3768   (let ((buffer-read-only nil)
3769         old-pos current thread data)
3770     (if (not gnus-show-threads)
3771         (setq thread (list (car (gnus-id-to-thread id))))
3772       ;; Get the thread this article is part of.
3773       (setq thread (gnus-remove-thread id)))
3774     (setq old-pos (gnus-point-at-bol))
3775     (setq current (save-excursion
3776                     (and (re-search-backward "[\r\n]" nil t)
3777                          (gnus-summary-article-number))))
3778     ;; If this is a gathered thread, we have to go some re-gathering.
3779     (when (stringp (car thread))
3780       (let ((subject (car thread))
3781             roots thr)
3782         (setq thread (cdr thread))
3783         (while thread
3784           (unless (memq (setq thr (gnus-id-to-thread
3785                                    (gnus-root-id
3786                                     (mail-header-id (caar thread)))))
3787                         roots)
3788             (push thr roots))
3789           (setq thread (cdr thread)))
3790         ;; We now have all (unique) roots.
3791         (if (= (length roots) 1)
3792             ;; All the loose roots are now one solid root.
3793             (setq thread (car roots))
3794           (setq thread (cons subject (gnus-sort-threads roots))))))
3795     (let (threads)
3796       ;; We then insert this thread into the summary buffer.
3797       (when line
3798         (goto-char (point-min))
3799         (forward-line (1- line)))
3800       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3801         (if gnus-show-threads
3802             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3803           (gnus-summary-prepare-unthreaded thread))
3804         (setq data (nreverse gnus-newsgroup-data))
3805         (setq threads gnus-newsgroup-threads))
3806       ;; We splice the new data into the data structure.
3807       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3808       ;;!!! then we want to insert at the beginning of the buffer.
3809       ;;!!! That happens to be true with Gnus now, but that may
3810       ;;!!! change in the future.  Perhaps.
3811       (gnus-data-enter-list
3812        (if line nil current) data (- (point) old-pos))
3813       (setq gnus-newsgroup-threads
3814             (nconc threads gnus-newsgroup-threads))
3815       (gnus-data-compute-positions))))
3816
3817 (defun gnus-number-to-header (number)
3818   "Return the header for article NUMBER."
3819   (let ((headers gnus-newsgroup-headers))
3820     (while (and headers
3821                 (not (= number (mail-header-number (car headers)))))
3822       (pop headers))
3823     (when headers
3824       (car headers))))
3825
3826 (defun gnus-parent-headers (in-headers &optional generation)
3827   "Return the headers of the GENERATIONeth parent of HEADERS."
3828   (unless generation
3829     (setq generation 1))
3830   (let ((parent t)
3831         (headers in-headers)
3832         references)
3833     (while (and parent
3834                 (not (zerop generation))
3835                 (setq references (mail-header-references headers)))
3836       (setq headers (if (and references
3837                              (setq parent (gnus-parent-id references)))
3838                         (car (gnus-id-to-thread parent))
3839                       nil))
3840       (decf generation))
3841     (and (not (eq headers in-headers))
3842          headers)))
3843
3844 (defun gnus-id-to-thread (id)
3845   "Return the (sub-)thread where ID appears."
3846   (gnus-gethash id gnus-newsgroup-dependencies))
3847
3848 (defun gnus-id-to-article (id)
3849   "Return the article number of ID."
3850   (let ((thread (gnus-id-to-thread id)))
3851     (when (and thread
3852                (car thread))
3853       (mail-header-number (car thread)))))
3854
3855 (defun gnus-id-to-header (id)
3856   "Return the article headers of ID."
3857   (car (gnus-id-to-thread id)))
3858
3859 (defun gnus-article-displayed-root-p (article)
3860   "Say whether ARTICLE is a root(ish) article."
3861   (let ((level (gnus-summary-thread-level article))
3862         (refs (mail-header-references  (gnus-summary-article-header article)))
3863         particle)
3864     (cond
3865      ((null level) nil)
3866      ((zerop level) t)
3867      ((null refs) t)
3868      ((null (gnus-parent-id refs)) t)
3869      ((and (= 1 level)
3870            (null (setq particle (gnus-id-to-article
3871                                  (gnus-parent-id refs))))
3872            (null (gnus-summary-thread-level particle)))))))
3873
3874 (defun gnus-root-id (id)
3875   "Return the id of the root of the thread where ID appears."
3876   (let (last-id prev)
3877     (while (and id (setq prev (car (gnus-id-to-thread id))))
3878       (setq last-id id
3879             id (gnus-parent-id (mail-header-references prev))))
3880     last-id))
3881
3882 (defun gnus-articles-in-thread (thread)
3883   "Return the list of articles in THREAD."
3884   (cons (mail-header-number (car thread))
3885         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3886
3887 (defun gnus-remove-thread (id &optional dont-remove)
3888   "Remove the thread that has ID in it."
3889   (let (headers thread last-id)
3890     ;; First go up in this thread until we find the root.
3891     (setq last-id (gnus-root-id id)
3892           headers (message-flatten-list (gnus-id-to-thread last-id)))
3893     ;; We have now found the real root of this thread.  It might have
3894     ;; been gathered into some loose thread, so we have to search
3895     ;; through the threads to find the thread we wanted.
3896     (let ((threads gnus-newsgroup-threads)
3897           sub)
3898       (while threads
3899         (setq sub (car threads))
3900         (if (stringp (car sub))
3901             ;; This is a gathered thread, so we look at the roots
3902             ;; below it to find whether this article is in this
3903             ;; gathered root.
3904             (progn
3905               (setq sub (cdr sub))
3906               (while sub
3907                 (when (member (caar sub) headers)
3908                   (setq thread (car threads)
3909                         threads nil
3910                         sub nil))
3911                 (setq sub (cdr sub))))
3912           ;; It's an ordinary thread, so we check it.
3913           (when (eq (car sub) (car headers))
3914             (setq thread sub
3915                   threads nil)))
3916         (setq threads (cdr threads)))
3917       ;; If this article is in no thread, then it's a root.
3918       (if thread
3919           (unless dont-remove
3920             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3921         (setq thread (gnus-id-to-thread last-id)))
3922       (when thread
3923         (prog1
3924             thread                      ; We return this thread.
3925           (unless dont-remove
3926             (if (stringp (car thread))
3927                 (progn
3928                   ;; If we use dummy roots, then we have to remove the
3929                   ;; dummy root as well.
3930                   (when (eq gnus-summary-make-false-root 'dummy)
3931                     ;; We go to the dummy root by going to
3932                     ;; the first sub-"thread", and then one line up.
3933                     (gnus-summary-goto-article
3934                      (mail-header-number (caadr thread)))
3935                     (forward-line -1)
3936                     (gnus-delete-line)
3937                     (gnus-data-compute-positions))
3938                   (setq thread (cdr thread))
3939                   (while thread
3940                     (gnus-remove-thread-1 (car thread))
3941                     (setq thread (cdr thread))))
3942               (gnus-remove-thread-1 thread))))))))
3943
3944 (defun gnus-remove-thread-1 (thread)
3945   "Remove the thread THREAD recursively."
3946   (let ((number (mail-header-number (pop thread)))
3947         d)
3948     (setq thread (reverse thread))
3949     (while thread
3950       (gnus-remove-thread-1 (pop thread)))
3951     (when (setq d (gnus-data-find number))
3952       (goto-char (gnus-data-pos d))
3953       (gnus-summary-show-thread)
3954       (gnus-data-remove
3955        number
3956        (- (gnus-point-at-bol)
3957           (prog1
3958               (1+ (gnus-point-at-eol))
3959             (gnus-delete-line)))))))
3960
3961 (defun gnus-sort-threads-1 (threads func)
3962   (sort (mapcar (lambda (thread)
3963                   (cons (car thread)
3964                         (and (cdr thread)
3965                              (gnus-sort-threads-1 (cdr thread) func))))
3966                 threads) func))
3967
3968 (defun gnus-sort-threads (threads)
3969   "Sort THREADS."
3970   (if (not gnus-thread-sort-functions)
3971       threads
3972     (gnus-message 8 "Sorting threads...")
3973     (prog1
3974         (gnus-sort-threads-1
3975          threads
3976          (gnus-make-sort-function gnus-thread-sort-functions))
3977       (gnus-message 8 "Sorting threads...done"))))
3978
3979 (defun gnus-sort-articles (articles)
3980   "Sort ARTICLES."
3981   (when gnus-article-sort-functions
3982     (gnus-message 7 "Sorting articles...")
3983     (prog1
3984         (setq gnus-newsgroup-headers
3985               (sort articles (gnus-make-sort-function
3986                               gnus-article-sort-functions)))
3987       (gnus-message 7 "Sorting articles...done"))))
3988
3989 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3990 (defmacro gnus-thread-header (thread)
3991   "Return header of first article in THREAD.
3992 Note that THREAD must never, ever be anything else than a variable -
3993 using some other form will lead to serious barfage."
3994   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3995   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
3996   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
3997         (vector thread) 2))
3998
3999 (defsubst gnus-article-sort-by-number (h1 h2)
4000   "Sort articles by article number."
4001   (< (mail-header-number h1)
4002      (mail-header-number h2)))
4003
4004 (defun gnus-thread-sort-by-number (h1 h2)
4005   "Sort threads by root article number."
4006   (gnus-article-sort-by-number
4007    (gnus-thread-header h1) (gnus-thread-header h2)))
4008
4009 (defsubst gnus-article-sort-by-lines (h1 h2)
4010   "Sort articles by article Lines header."
4011   (< (mail-header-lines h1)
4012      (mail-header-lines h2)))
4013
4014 (defun gnus-thread-sort-by-lines (h1 h2)
4015   "Sort threads by root article Lines header."
4016   (gnus-article-sort-by-lines
4017    (gnus-thread-header h1) (gnus-thread-header h2)))
4018
4019 (defsubst gnus-article-sort-by-chars (h1 h2)
4020   "Sort articles by octet length."
4021   (< (mail-header-chars h1)
4022      (mail-header-chars h2)))
4023
4024 (defun gnus-thread-sort-by-chars (h1 h2)
4025   "Sort threads by root article octet length."
4026   (gnus-article-sort-by-chars
4027    (gnus-thread-header h1) (gnus-thread-header h2)))
4028
4029 (defsubst gnus-article-sort-by-author (h1 h2)
4030   "Sort articles by root author."
4031   (string-lessp
4032    (let ((addr (car (mime-entity-read-field h1 'From))))
4033      (or (std11-full-name-string addr)
4034          (std11-address-string addr)
4035          ""))
4036    (let ((addr (car (mime-entity-read-field h2 'From))))
4037      (or (std11-full-name-string addr)
4038          (std11-address-string addr)
4039          ""))
4040    ))
4041
4042 (defun gnus-thread-sort-by-author (h1 h2)
4043   "Sort threads by root author."
4044   (gnus-article-sort-by-author
4045    (gnus-thread-header h1)  (gnus-thread-header h2)))
4046
4047 (defsubst gnus-article-sort-by-subject (h1 h2)
4048   "Sort articles by root subject."
4049   (string-lessp
4050    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4051    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4052
4053 (defun gnus-thread-sort-by-subject (h1 h2)
4054   "Sort threads by root subject."
4055   (gnus-article-sort-by-subject
4056    (gnus-thread-header h1) (gnus-thread-header h2)))
4057
4058 (defsubst gnus-article-sort-by-date (h1 h2)
4059   "Sort articles by root article date."
4060   (time-less-p
4061    (gnus-date-get-time (mail-header-date h1))
4062    (gnus-date-get-time (mail-header-date h2))))
4063
4064 (defun gnus-thread-sort-by-date (h1 h2)
4065   "Sort threads by root article date."
4066   (gnus-article-sort-by-date
4067    (gnus-thread-header h1) (gnus-thread-header h2)))
4068
4069 (defsubst gnus-article-sort-by-score (h1 h2)
4070   "Sort articles by root article score.
4071 Unscored articles will be counted as having a score of zero."
4072   (> (or (cdr (assq (mail-header-number h1)
4073                     gnus-newsgroup-scored))
4074          gnus-summary-default-score 0)
4075      (or (cdr (assq (mail-header-number h2)
4076                     gnus-newsgroup-scored))
4077          gnus-summary-default-score 0)))
4078
4079 (defun gnus-thread-sort-by-score (h1 h2)
4080   "Sort threads by root article score."
4081   (gnus-article-sort-by-score
4082    (gnus-thread-header h1) (gnus-thread-header h2)))
4083
4084 (defun gnus-thread-sort-by-total-score (h1 h2)
4085   "Sort threads by the sum of all scores in the thread.
4086 Unscored articles will be counted as having a score of zero."
4087   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4088
4089 (defun gnus-thread-total-score (thread)
4090   ;; This function find the total score of THREAD.
4091   (cond ((null thread)
4092          0)
4093         ((consp thread)
4094          (if (stringp (car thread))
4095              (apply gnus-thread-score-function 0
4096                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4097            (gnus-thread-total-score-1 thread)))
4098         (t
4099          (gnus-thread-total-score-1 (list thread)))))
4100
4101 (defun gnus-thread-total-score-1 (root)
4102   ;; This function find the total score of the thread below ROOT.
4103   (setq root (car root))
4104   (apply gnus-thread-score-function
4105          (or (append
4106               (mapcar 'gnus-thread-total-score
4107                       (cdr (gnus-id-to-thread (mail-header-id root))))
4108               (when (> (mail-header-number root) 0)
4109                 (list (or (cdr (assq (mail-header-number root)
4110                                      gnus-newsgroup-scored))
4111                           gnus-summary-default-score 0))))
4112              (list gnus-summary-default-score)
4113              '(0))))
4114
4115 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4116 (defvar gnus-tmp-prev-subject nil)
4117 (defvar gnus-tmp-false-parent nil)
4118 (defvar gnus-tmp-root-expunged nil)
4119 (defvar gnus-tmp-dummy-line nil)
4120
4121 (eval-when-compile (defvar gnus-tmp-header))
4122 (defun gnus-extra-header (type &optional header)
4123   "Return the extra header of TYPE."
4124   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4125       ""))
4126
4127 (defvar gnus-tmp-thread-tree-header-string "")
4128
4129 (defvar gnus-sum-thread-tree-root "> "
4130   "With %B spec, used for the root of a thread.
4131 If nil, use subject instead.")
4132 (defvar gnus-sum-thread-tree-single-indent ""
4133   "With %B spec, used for a thread with just one message.
4134 If nil, use subject instead.")
4135 (defvar gnus-sum-thread-tree-vertical "| "
4136   "With %B spec, used for drawing a vertical line.")
4137 (defvar gnus-sum-thread-tree-indent "  "
4138   "With %B spec, used for indenting.")
4139 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4140   "With %B spec, used for a leaf with brothers.")
4141 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4142   "With %B spec, used for a leaf without brothers.")
4143
4144 (defun gnus-summary-prepare-threads (threads)
4145   "Prepare summary buffer from THREADS and indentation LEVEL.
4146 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4147 or a straight list of headers."
4148   (gnus-message 7 "Generating summary...")
4149
4150   (setq gnus-newsgroup-threads threads)
4151   (beginning-of-line)
4152
4153   (let ((gnus-tmp-level 0)
4154         (default-score (or gnus-summary-default-score 0))
4155         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4156         thread number subject stack state gnus-tmp-gathered beg-match
4157         new-roots gnus-tmp-new-adopts thread-end
4158         gnus-tmp-header gnus-tmp-unread
4159         gnus-tmp-replied gnus-tmp-subject-or-nil
4160         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4161         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4162         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4163         tree-stack)
4164
4165     (setq gnus-tmp-prev-subject nil)
4166
4167     (if (vectorp (car threads))
4168         ;; If this is a straight (sic) list of headers, then a
4169         ;; threaded summary display isn't required, so we just create
4170         ;; an unthreaded one.
4171         (gnus-summary-prepare-unthreaded threads)
4172
4173       ;; Do the threaded display.
4174
4175       (while (or threads stack gnus-tmp-new-adopts new-roots)
4176
4177         (if (and (= gnus-tmp-level 0)
4178                  (or (not stack)
4179                      (= (caar stack) 0))
4180                  (not gnus-tmp-false-parent)
4181                  (or gnus-tmp-new-adopts new-roots))
4182             (if gnus-tmp-new-adopts
4183                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4184                       thread (list (car gnus-tmp-new-adopts))
4185                       gnus-tmp-header (caar thread)
4186                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4187               (when new-roots
4188                 (setq thread (list (car new-roots))
4189                       gnus-tmp-header (caar thread)
4190                       new-roots (cdr new-roots))))
4191
4192           (if threads
4193               ;; If there are some threads, we do them before the
4194               ;; threads on the stack.
4195               (setq thread threads
4196                     gnus-tmp-header (caar thread))
4197             ;; There were no current threads, so we pop something off
4198             ;; the stack.
4199             (setq state (car stack)
4200                   gnus-tmp-level (car state)
4201                   tree-stack (cadr state)
4202                   thread (caddr state)
4203                   stack (cdr stack)
4204                   gnus-tmp-header (caar thread))))
4205
4206         (setq gnus-tmp-false-parent nil)
4207         (setq gnus-tmp-root-expunged nil)
4208         (setq thread-end nil)
4209
4210         (if (stringp gnus-tmp-header)
4211             ;; The header is a dummy root.
4212             (cond
4213              ((eq gnus-summary-make-false-root 'adopt)
4214               ;; We let the first article adopt the rest.
4215               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4216                                                (cddar thread)))
4217               (setq gnus-tmp-gathered
4218                     (nconc (mapcar
4219                             (lambda (h) (mail-header-number (car h)))
4220                             (cddar thread))
4221                            gnus-tmp-gathered))
4222               (setq thread (cons (list (caar thread)
4223                                        (cadar thread))
4224                                  (cdr thread)))
4225               (setq gnus-tmp-level -1
4226                     gnus-tmp-false-parent t))
4227              ((eq gnus-summary-make-false-root 'empty)
4228               ;; We print adopted articles with empty subject fields.
4229               (setq gnus-tmp-gathered
4230                     (nconc (mapcar
4231                             (lambda (h) (mail-header-number (car h)))
4232                             (cddar thread))
4233                            gnus-tmp-gathered))
4234               (setq gnus-tmp-level -1))
4235              ((eq gnus-summary-make-false-root 'dummy)
4236               ;; We remember that we probably want to output a dummy
4237               ;; root.
4238               (setq gnus-tmp-dummy-line gnus-tmp-header)
4239               (setq gnus-tmp-prev-subject gnus-tmp-header))
4240              (t
4241               ;; We do not make a root for the gathered
4242               ;; sub-threads at all.
4243               (setq gnus-tmp-level -1)))
4244
4245           (setq number (mail-header-number gnus-tmp-header)
4246                 subject (mail-header-subject gnus-tmp-header))
4247
4248           (cond
4249            ;; If the thread has changed subject, we might want to make
4250            ;; this subthread into a root.
4251            ((and (null gnus-thread-ignore-subject)
4252                  (not (zerop gnus-tmp-level))
4253                  gnus-tmp-prev-subject
4254                  (not (inline
4255                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4256             (setq new-roots (nconc new-roots (list (car thread)))
4257                   thread-end t
4258                   gnus-tmp-header nil))
4259            ;; If the article lies outside the current limit,
4260            ;; then we do not display it.
4261            ((not (memq number gnus-newsgroup-limit))
4262             (setq gnus-tmp-gathered
4263                   (nconc (mapcar
4264                           (lambda (h) (mail-header-number (car h)))
4265                           (cdar thread))
4266                          gnus-tmp-gathered))
4267             (setq gnus-tmp-new-adopts (if (cdar thread)
4268                                           (append gnus-tmp-new-adopts
4269                                                   (cdar thread))
4270                                         gnus-tmp-new-adopts)
4271                   thread-end t
4272                   gnus-tmp-header nil)
4273             (when (zerop gnus-tmp-level)
4274               (setq gnus-tmp-root-expunged t)))
4275            ;; Perhaps this article is to be marked as read?
4276            ((and gnus-summary-mark-below
4277                  (< (or (cdr (assq number gnus-newsgroup-scored))
4278                         default-score)
4279                     gnus-summary-mark-below)
4280                  ;; Don't touch sparse articles.
4281                  (not (gnus-summary-article-sparse-p number))
4282                  (not (gnus-summary-article-ancient-p number)))
4283             (setq gnus-newsgroup-unreads
4284                   (delq number gnus-newsgroup-unreads))
4285             (if gnus-newsgroup-auto-expire
4286                 (push number gnus-newsgroup-expirable)
4287               (push (cons number gnus-low-score-mark)
4288                     gnus-newsgroup-reads))))
4289
4290           (when gnus-tmp-header
4291             ;; We may have an old dummy line to output before this
4292             ;; article.
4293             (when (and gnus-tmp-dummy-line
4294                        (gnus-subject-equal
4295                         gnus-tmp-dummy-line
4296                         (mail-header-subject gnus-tmp-header)))
4297               (gnus-summary-insert-dummy-line
4298                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4299               (setq gnus-tmp-dummy-line nil))
4300
4301             ;; Compute the mark.
4302             (setq gnus-tmp-unread (gnus-article-mark number))
4303
4304             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4305                                   gnus-tmp-header gnus-tmp-level)
4306                   gnus-newsgroup-data)
4307
4308             ;; Actually insert the line.
4309             (setq
4310              gnus-tmp-subject-or-nil
4311              (cond
4312               ((and gnus-thread-ignore-subject
4313                     gnus-tmp-prev-subject
4314                     (not (inline (gnus-subject-equal
4315                                   gnus-tmp-prev-subject subject))))
4316                subject)
4317               ((zerop gnus-tmp-level)
4318                (if (and (eq gnus-summary-make-false-root 'empty)
4319                         (memq number gnus-tmp-gathered)
4320                         gnus-tmp-prev-subject
4321                         (inline (gnus-subject-equal
4322                                  gnus-tmp-prev-subject subject)))
4323                    gnus-summary-same-subject
4324                  subject))
4325               (t gnus-summary-same-subject)))
4326             (if (and (eq gnus-summary-make-false-root 'adopt)
4327                      (= gnus-tmp-level 1)
4328                      (memq number gnus-tmp-gathered))
4329                 (setq gnus-tmp-opening-bracket ?\<
4330                       gnus-tmp-closing-bracket ?\>)
4331               (setq gnus-tmp-opening-bracket ?\[
4332                     gnus-tmp-closing-bracket ?\]))
4333             (setq
4334              gnus-tmp-indentation
4335              (aref gnus-thread-indent-array gnus-tmp-level)
4336              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4337              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4338                                 gnus-summary-default-score 0)
4339              gnus-tmp-score-char
4340              (if (or (null gnus-summary-default-score)
4341                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4342                          gnus-summary-zcore-fuzz))
4343                  ?\ ;;;Whitespace
4344                (if (< gnus-tmp-score gnus-summary-default-score)
4345                    gnus-score-below-mark gnus-score-over-mark))
4346              gnus-tmp-replied
4347              (cond ((memq number gnus-newsgroup-processable)
4348                     gnus-process-mark)
4349                    ((memq number gnus-newsgroup-cached)
4350                     gnus-cached-mark)
4351                    ((memq number gnus-newsgroup-replied)
4352                     gnus-replied-mark)
4353                    ((memq number gnus-newsgroup-forwarded)
4354                     gnus-forwarded-mark)
4355                    ((memq number gnus-newsgroup-saved)
4356                     gnus-saved-mark)
4357                    ((memq number gnus-newsgroup-recent)
4358                     gnus-recent-mark)
4359                    (t gnus-no-mark))
4360              gnus-tmp-from (mail-header-from gnus-tmp-header)
4361              gnus-tmp-name
4362              (cond
4363               ((string-match "<[^>]+> *$" gnus-tmp-from)
4364                (setq beg-match (match-beginning 0))
4365                (or (and (string-match "^\".+\"" gnus-tmp-from)
4366                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4367                    (substring gnus-tmp-from 0 beg-match)))
4368               ((string-match "(.+)" gnus-tmp-from)
4369                (substring gnus-tmp-from
4370                           (1+ (match-beginning 0)) (1- (match-end 0))))
4371               (t gnus-tmp-from))
4372              gnus-tmp-thread-tree-header-string
4373              (cond
4374               ((not gnus-show-threads) "")
4375               ((zerop gnus-tmp-level)
4376                (if (cdar thread)
4377                    (or gnus-sum-thread-tree-root subject)
4378                  (or gnus-sum-thread-tree-single-indent subject)))
4379               (t
4380                (concat (apply 'concat
4381                               (mapcar (lambda (item)
4382                                         (if (= item 1)
4383                                             gnus-sum-thread-tree-vertical
4384                                           gnus-sum-thread-tree-indent))
4385                                       (cdr (reverse tree-stack))))
4386                        (if (nth 1 thread)
4387                            gnus-sum-thread-tree-leaf-with-other
4388                          gnus-sum-thread-tree-single-leaf)))))
4389             (when (string= gnus-tmp-name "")
4390               (setq gnus-tmp-name gnus-tmp-from))
4391             (unless (numberp gnus-tmp-lines)
4392               (setq gnus-tmp-lines -1))
4393             (when (= gnus-tmp-lines -1)
4394               (setq gnus-tmp-lines "?"))
4395             (gnus-put-text-property
4396              (point)
4397              (progn (eval gnus-summary-line-format-spec) (point))
4398              'gnus-number number)
4399             (when gnus-visual-p
4400               (forward-line -1)
4401               (gnus-run-hooks 'gnus-summary-update-hook)
4402               (forward-line 1))
4403
4404             (setq gnus-tmp-prev-subject subject)))
4405
4406         (when (nth 1 thread)
4407           (push (list (max 0 gnus-tmp-level)
4408                       (copy-list tree-stack)
4409                       (nthcdr 1 thread))
4410                 stack))
4411         (push (if (nth 1 thread) 1 0) tree-stack)
4412         (incf gnus-tmp-level)
4413         (setq threads (if thread-end nil (cdar thread)))
4414         (unless threads
4415           (setq gnus-tmp-level 0)))))
4416   (gnus-message 7 "Generating summary...done"))
4417
4418 (defun gnus-summary-prepare-unthreaded (headers)
4419   "Generate an unthreaded summary buffer based on HEADERS."
4420   (let (header number mark)
4421
4422     (beginning-of-line)
4423
4424     (while headers
4425       ;; We may have to root out some bad articles...
4426       (when (memq (setq number (mail-header-number
4427                                 (setq header (pop headers))))
4428                   gnus-newsgroup-limit)
4429         ;; Mark article as read when it has a low score.
4430         (when (and gnus-summary-mark-below
4431                    (< (or (cdr (assq number gnus-newsgroup-scored))
4432                           gnus-summary-default-score 0)
4433                       gnus-summary-mark-below)
4434                    (not (gnus-summary-article-ancient-p number)))
4435           (setq gnus-newsgroup-unreads
4436                 (delq number gnus-newsgroup-unreads))
4437           (if gnus-newsgroup-auto-expire
4438               (push number gnus-newsgroup-expirable)
4439             (push (cons number gnus-low-score-mark)
4440                   gnus-newsgroup-reads)))
4441
4442         (setq mark (gnus-article-mark number))
4443         (push (gnus-data-make number mark (1+ (point)) header 0)
4444               gnus-newsgroup-data)
4445         (gnus-summary-insert-line
4446          header 0 number
4447          mark (memq number gnus-newsgroup-replied)
4448          (memq number gnus-newsgroup-expirable)
4449          (mail-header-subject header) nil
4450          (cdr (assq number gnus-newsgroup-scored))
4451          (memq number gnus-newsgroup-processable))))))
4452
4453 (defun gnus-summary-remove-list-identifiers ()
4454   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4455   (let ((regexp (if (consp gnus-list-identifiers)
4456                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4457                   gnus-list-identifiers))
4458         changed subject)
4459     (when regexp
4460       (dolist (header gnus-newsgroup-headers)
4461         (setq subject (mail-header-subject header)
4462               changed nil)
4463         (while (string-match
4464                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4465                 subject)
4466           (setq subject
4467                 (concat (substring subject 0 (match-beginning 2))
4468                         (substring subject (match-end 0)))
4469                 changed t))
4470         (when (and changed
4471                    (string-match
4472                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4473           (setq subject
4474                 (concat (substring subject 0 (match-beginning 1))
4475                         (substring subject (match-end 1)))))
4476         (when changed
4477           (mail-header-set-subject header subject))))))
4478
4479 (defun gnus-fetch-headers (articles)
4480   "Fetch headers of ARTICLES."
4481   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4482     (gnus-message 5 "Fetching headers for %s..." name)
4483     (prog1
4484         (if (eq 'nov
4485                 (setq gnus-headers-retrieved-by
4486                       (gnus-retrieve-headers
4487                        articles gnus-newsgroup-name
4488                        ;; We might want to fetch old headers, but
4489                        ;; not if there is only 1 article.
4490                        (and (or (and
4491                                  (not (eq gnus-fetch-old-headers 'some))
4492                                  (not (numberp gnus-fetch-old-headers)))
4493                                 (> (length articles) 1))
4494                             gnus-fetch-old-headers))))
4495             (gnus-get-newsgroup-headers-xover
4496              articles nil nil gnus-newsgroup-name t)
4497           (gnus-get-newsgroup-headers))
4498       (gnus-message 5 "Fetching headers for %s...done" name))))
4499
4500 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4501   "Select newsgroup GROUP.
4502 If READ-ALL is non-nil, all articles in the group are selected.
4503 If SELECT-ARTICLES, only select those articles from GROUP."
4504   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4505          ;;!!! Dirty hack; should be removed.
4506          (gnus-summary-ignore-duplicates
4507           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4508               t
4509             gnus-summary-ignore-duplicates))
4510          (info (nth 2 entry))
4511          articles fetched-articles cached)
4512
4513     (unless (gnus-check-server
4514              (setq gnus-current-select-method
4515                    (gnus-find-method-for-group group)))
4516       (error "Couldn't open server"))
4517
4518     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4519         (gnus-activate-group group)     ; Or we can activate it...
4520         (progn                          ; Or we bug out.
4521           (when (equal major-mode 'gnus-summary-mode)
4522             (kill-buffer (current-buffer)))
4523           (error "Couldn't activate group %s: %s"
4524                  group (gnus-status-message group))))
4525
4526     (unless (gnus-request-group group t)
4527       (when (equal major-mode 'gnus-summary-mode)
4528         (kill-buffer (current-buffer)))
4529       (error "Couldn't request group %s: %s"
4530              group (gnus-status-message group)))
4531
4532     (setq gnus-newsgroup-name group)
4533     (setq gnus-newsgroup-unselected nil)
4534     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4535     (gnus-summary-setup-default-charset)
4536
4537     ;; Adjust and set lists of article marks.
4538     (when info
4539       (gnus-adjust-marked-articles info))
4540
4541     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4542     (when (gnus-virtual-group-p group)
4543       (setq cached gnus-newsgroup-cached))
4544
4545     (setq gnus-newsgroup-unreads
4546           (gnus-set-difference
4547            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4548            gnus-newsgroup-dormant))
4549
4550     (setq gnus-newsgroup-processable nil)
4551
4552     (gnus-update-read-articles group gnus-newsgroup-unreads)
4553
4554     (if (setq articles select-articles)
4555         (setq gnus-newsgroup-unselected
4556               (gnus-sorted-intersection
4557                gnus-newsgroup-unreads
4558                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4559       (setq articles (gnus-articles-to-read group read-all)))
4560
4561     (cond
4562      ((null articles)
4563       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4564       'quit)
4565      ((eq articles 0) nil)
4566      (t
4567       ;; Init the dependencies hash table.
4568       (setq gnus-newsgroup-dependencies
4569             (gnus-make-hashtable (length articles)))
4570       (gnus-set-global-variables)
4571       ;; Retrieve the headers and read them in.
4572       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4573
4574       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4575       (when cached
4576         (setq gnus-newsgroup-cached cached))
4577
4578       ;; Suppress duplicates?
4579       (when gnus-suppress-duplicates
4580         (gnus-dup-suppress-articles))
4581
4582       ;; Set the initial limit.
4583       (setq gnus-newsgroup-limit (copy-sequence articles))
4584       ;; Remove canceled articles from the list of unread articles.
4585       (setq gnus-newsgroup-unreads
4586             (gnus-set-sorted-intersection
4587              gnus-newsgroup-unreads
4588              (setq fetched-articles
4589                    (mapcar (lambda (headers) (mail-header-number headers))
4590                            gnus-newsgroup-headers))))
4591       ;; Removed marked articles that do not exist.
4592       (gnus-update-missing-marks
4593        (gnus-sorted-complement fetched-articles articles))
4594       ;; We might want to build some more threads first.
4595       (when (and gnus-fetch-old-headers
4596                  (eq gnus-headers-retrieved-by 'nov))
4597         (if (eq gnus-fetch-old-headers 'invisible)
4598             (gnus-build-all-threads)
4599           (gnus-build-old-threads)))
4600       ;; Let the Gnus agent mark articles as read.
4601       (when gnus-agent
4602         (gnus-agent-get-undownloaded-list))
4603       ;; Remove list identifiers from subject
4604       (when gnus-list-identifiers
4605         (gnus-summary-remove-list-identifiers))
4606       ;; Check whether auto-expire is to be done in this group.
4607       (setq gnus-newsgroup-auto-expire
4608             (gnus-group-auto-expirable-p group))
4609       ;; Set up the article buffer now, if necessary.
4610       (unless gnus-single-article-buffer
4611         (gnus-article-setup-buffer))
4612       ;; First and last article in this newsgroup.
4613       (when gnus-newsgroup-headers
4614         (setq gnus-newsgroup-begin
4615               (mail-header-number (car gnus-newsgroup-headers))
4616               gnus-newsgroup-end
4617               (mail-header-number
4618                (gnus-last-element gnus-newsgroup-headers))))
4619       ;; GROUP is successfully selected.
4620       (or gnus-newsgroup-headers t)))))
4621
4622 (defun gnus-articles-to-read (group &optional read-all)
4623   "Find out what articles the user wants to read."
4624   (let* ((articles
4625           ;; Select all articles if `read-all' is non-nil, or if there
4626           ;; are no unread articles.
4627           (if (or read-all
4628                   (and (zerop (length gnus-newsgroup-marked))
4629                        (zerop (length gnus-newsgroup-unreads)))
4630                   (eq (gnus-group-find-parameter group 'display)
4631                       'all))
4632               (or
4633                (gnus-uncompress-range (gnus-active group))
4634                (gnus-cache-articles-in-group group))
4635             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4636                           (copy-sequence gnus-newsgroup-unreads))
4637                   '<)))
4638          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4639          (scored (length scored-list))
4640          (number (length articles))
4641          (marked (+ (length gnus-newsgroup-marked)
4642                     (length gnus-newsgroup-dormant)))
4643          (select
4644           (cond
4645            ((numberp read-all)
4646             read-all)
4647            (t
4648             (condition-case ()
4649                 (cond
4650                  ((and (or (<= scored marked) (= scored number))
4651                        (natnump gnus-large-newsgroup)
4652                        (> number gnus-large-newsgroup))
4653                   (let* ((cursor-in-echo-area nil)
4654                          (input
4655                           (read-from-minibuffer
4656                            (format
4657                             "How many articles from %s (max %d): "
4658                             (gnus-limit-string
4659                              (gnus-group-decoded-name gnus-newsgroup-name)
4660                              35)
4661                             number)
4662                            (cons (number-to-string gnus-large-newsgroup)
4663                                  0))))
4664                     (if (string-match "^[ \t]*$" input)
4665                         number
4666                       input)))
4667                  ((and (> scored marked) (< scored number)
4668                        (> (- scored number) 20))
4669                   (let ((input
4670                          (read-string
4671                           (format "%s %s (%d scored, %d total): "
4672                                   "How many articles from"
4673                                   (gnus-group-decoded-name group)
4674                                   scored number))))
4675                     (if (string-match "^[ \t]*$" input)
4676                         number input)))
4677                  (t number))
4678               (quit
4679                (message "Quit getting the articles to read")
4680                nil))))))
4681     (setq select (if (stringp select) (string-to-number select) select))
4682     (if (or (null select) (zerop select))
4683         select
4684       (if (and (not (zerop scored)) (<= (abs select) scored))
4685           (progn
4686             (setq articles (sort scored-list '<))
4687             (setq number (length articles)))
4688         (setq articles (copy-sequence articles)))
4689
4690       (when (< (abs select) number)
4691         (if (< select 0)
4692             ;; Select the N oldest articles.
4693             (setcdr (nthcdr (1- (abs select)) articles) nil)
4694           ;; Select the N most recent articles.
4695           (setq articles (nthcdr (- number select) articles))))
4696       (setq gnus-newsgroup-unselected
4697             (gnus-sorted-intersection
4698              gnus-newsgroup-unreads
4699              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4700       (when gnus-alter-articles-to-read-function
4701         (setq gnus-newsgroup-unreads
4702               (sort
4703                (funcall gnus-alter-articles-to-read-function
4704                         gnus-newsgroup-name gnus-newsgroup-unreads)
4705                '<)))
4706       articles)))
4707
4708 (defun gnus-killed-articles (killed articles)
4709   (let (out)
4710     (while articles
4711       (when (inline (gnus-member-of-range (car articles) killed))
4712         (push (car articles) out))
4713       (setq articles (cdr articles)))
4714     out))
4715
4716 (defun gnus-uncompress-marks (marks)
4717   "Uncompress the mark ranges in MARKS."
4718   (let ((uncompressed '(score bookmark))
4719         out)
4720     (while marks
4721       (if (memq (caar marks) uncompressed)
4722           (push (car marks) out)
4723         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4724       (setq marks (cdr marks)))
4725     out))
4726
4727 (defun gnus-adjust-marked-articles (info)
4728   "Set all article lists and remove all marks that are no longer valid."
4729   (let* ((marked-lists (gnus-info-marks info))
4730          (active (gnus-active (gnus-info-group info)))
4731          (min (car active))
4732          (max (cdr active))
4733          (types gnus-article-mark-lists)
4734          (uncompressed '(score bookmark killed))
4735          marks var articles article mark)
4736
4737     (while marked-lists
4738       (setq marks (pop marked-lists))
4739       (set (setq var (intern (format "gnus-newsgroup-%s"
4740                                      (car (rassq (setq mark (car marks))
4741                                                  types)))))
4742            (if (memq (car marks) uncompressed) (cdr marks)
4743              (gnus-uncompress-range (cdr marks))))
4744
4745       (setq articles (symbol-value var))
4746
4747       ;; All articles have to be subsets of the active articles.
4748       (cond
4749        ;; Adjust "simple" lists.
4750        ((memq mark '(tick dormant expire reply save))
4751         (while articles
4752           (when (or (< (setq article (pop articles)) min) (> article max))
4753             (set var (delq article (symbol-value var))))))
4754        ;; Adjust assocs.
4755        ((memq mark uncompressed)
4756         (when (not (listp (cdr (symbol-value var))))
4757           (set var (list (symbol-value var))))
4758         (when (not (listp (cdr articles)))
4759           (setq articles (list articles)))
4760         (while articles
4761           (when (or (not (consp (setq article (pop articles))))
4762                     (< (car article) min)
4763                     (> (car article) max))
4764             (set var (delq article (symbol-value var))))))))))
4765
4766 (defun gnus-update-missing-marks (missing)
4767   "Go through the list of MISSING articles and remove them from the mark lists."
4768   (when missing
4769     (let ((types gnus-article-mark-lists)
4770           var m)
4771       ;; Go through all types.
4772       (while types
4773         (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
4774         (when (symbol-value var)
4775           ;; This list has articles.  So we delete all missing articles
4776           ;; from it.
4777           (setq m missing)
4778           (while m
4779             (set var (delq (pop m) (symbol-value var)))))))))
4780
4781 (defun gnus-update-marks ()
4782   "Enter the various lists of marked articles into the newsgroup info list."
4783   (let ((types gnus-article-mark-lists)
4784         (info (gnus-get-info gnus-newsgroup-name))
4785         (uncompressed '(score bookmark killed))
4786         type list newmarked symbol delta-marks)
4787     (when info
4788       ;; Add all marks lists to the list of marks lists.
4789       (while (setq type (pop types))
4790         (setq list (symbol-value
4791                     (setq symbol
4792                           (intern (format "gnus-newsgroup-%s"
4793                                           (car type))))))
4794
4795         (when list
4796           ;; Get rid of the entries of the articles that have the
4797           ;; default score.
4798           (when (and (eq (cdr type) 'score)
4799                      gnus-save-score
4800                      list)
4801             (let* ((arts list)
4802                    (prev (cons nil list))
4803                    (all prev))
4804               (while arts
4805                 (if (or (not (consp (car arts)))
4806                         (= (cdar arts) gnus-summary-default-score))
4807                     (setcdr prev (cdr arts))
4808                   (setq prev arts))
4809                 (setq arts (cdr arts)))
4810               (setq list (cdr all)))))
4811
4812         (unless (memq (cdr type) uncompressed)
4813           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4814
4815         (when (gnus-check-backend-function
4816                'request-set-mark gnus-newsgroup-name)
4817           ;; propagate flags to server, with the following exceptions:
4818           ;; uncompressed:s are not proper flags (they are cons cells)
4819           ;; cache is a internal gnus flag
4820           ;; download are local to one gnus installation (well)
4821           ;; unsend are for nndraft groups only
4822           ;; xxx: generality of this?  this suits nnimap anyway
4823           (unless (memq (cdr type) (append '(cache download unsend)
4824                                            uncompressed))
4825             (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4826                    (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4827                    (add (gnus-remove-from-range
4828                          (gnus-copy-sequence list) old)))
4829               (when add
4830                 (push (list add 'add (list (cdr type))) delta-marks))
4831               (when del
4832                 (push (list del 'del (list (cdr type))) delta-marks)))))
4833
4834         (when list
4835           (push (cons (cdr type) list) newmarked)))
4836
4837       (when delta-marks
4838         (unless (gnus-check-group gnus-newsgroup-name)
4839           (error "Can't open server for %s" gnus-newsgroup-name))
4840         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
4841
4842       ;; Enter these new marks into the info of the group.
4843       (if (nthcdr 3 info)
4844           (setcar (nthcdr 3 info) newmarked)
4845         ;; Add the marks lists to the end of the info.
4846         (when newmarked
4847           (setcdr (nthcdr 2 info) (list newmarked))))
4848
4849       ;; Cut off the end of the info if there's nothing else there.
4850       (let ((i 5))
4851         (while (and (> i 2)
4852                     (not (nth i info)))
4853           (when (nthcdr (decf i) info)
4854             (setcdr (nthcdr i info) nil)))))))
4855
4856 (defun gnus-set-mode-line (where)
4857   "Set the mode line of the article or summary buffers.
4858 If WHERE is `summary', the summary mode line format will be used."
4859   ;; Is this mode line one we keep updated?
4860   (when (and (memq where gnus-updated-mode-lines)
4861              (symbol-value
4862               (intern (format "gnus-%s-mode-line-format-spec" where))))
4863     (let (mode-string)
4864       (save-excursion
4865         ;; We evaluate this in the summary buffer since these
4866         ;; variables are buffer-local to that buffer.
4867         (set-buffer gnus-summary-buffer)
4868         ;; We bind all these variables that are used in the `eval' form
4869         ;; below.
4870         (let* ((mformat (symbol-value
4871                          (intern
4872                           (format "gnus-%s-mode-line-format-spec" where))))
4873                (gnus-tmp-group-name (gnus-group-decoded-name
4874                                      gnus-newsgroup-name))
4875                (gnus-tmp-article-number (or gnus-current-article 0))
4876                (gnus-tmp-unread gnus-newsgroup-unreads)
4877                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
4878                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
4879                (gnus-tmp-unread-and-unselected
4880                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
4881                             (zerop gnus-tmp-unselected))
4882                        "")
4883                       ((zerop gnus-tmp-unselected)
4884                        (format "{%d more}" gnus-tmp-unread-and-unticked))
4885                       (t (format "{%d(+%d) more}"
4886                                  gnus-tmp-unread-and-unticked
4887                                  gnus-tmp-unselected))))
4888                (gnus-tmp-subject
4889                 (if (and gnus-current-headers
4890                          (vectorp gnus-current-headers))
4891                     (gnus-mode-string-quote
4892                      (mail-header-subject gnus-current-headers))
4893                   ""))
4894                bufname-length max-len
4895                gnus-tmp-header);; passed as argument to any user-format-funcs
4896           (setq mode-string (eval mformat))
4897           (setq bufname-length (if (string-match "%b" mode-string)
4898                                    (- (length
4899                                        (buffer-name
4900                                         (if (eq where 'summary)
4901                                             nil
4902                                           (get-buffer gnus-article-buffer))))
4903                                       2)
4904                                  0))
4905           (setq max-len (max 4 (if gnus-mode-non-string-length
4906                                    (- (window-width)
4907                                       gnus-mode-non-string-length
4908                                       bufname-length)
4909                                  (length mode-string))))
4910           ;; We might have to chop a bit of the string off...
4911           (when (> (length mode-string) max-len)
4912             (setq mode-string
4913                   (concat (gnus-truncate-string mode-string (- max-len 3))
4914                           "...")))
4915           ;; Pad the mode string a bit.
4916           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
4917       ;; Update the mode line.
4918       (setq mode-line-buffer-identification
4919             (gnus-mode-line-buffer-identification (list mode-string)))
4920       (set-buffer-modified-p t))))
4921
4922 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
4923   "Go through the HEADERS list and add all Xrefs to a hash table.
4924 The resulting hash table is returned, or nil if no Xrefs were found."
4925   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
4926          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
4927          (xref-hashtb (gnus-make-hashtable))
4928          start group entry number xrefs header)
4929     (while headers
4930       (setq header (pop headers))
4931       (when (and (setq xrefs (mail-header-xref header))
4932                  (not (memq (setq number (mail-header-number header))
4933                             unreads)))
4934         (setq start 0)
4935         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4936           (setq start (match-end 0))
4937           (setq group (if prefix
4938                           (concat prefix (substring xrefs (match-beginning 1)
4939                                                     (match-end 1)))
4940                         (substring xrefs (match-beginning 1) (match-end 1))))
4941           (setq number
4942                 (string-to-int (substring xrefs (match-beginning 2)
4943                                           (match-end 2))))
4944           (if (setq entry (gnus-gethash group xref-hashtb))
4945               (setcdr entry (cons number (cdr entry)))
4946             (gnus-sethash group (cons number nil) xref-hashtb)))))
4947     (and start xref-hashtb)))
4948
4949 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4950   "Look through all the headers and mark the Xrefs as read."
4951   (let ((virtual (gnus-virtual-group-p from-newsgroup))
4952         name entry info xref-hashtb idlist method nth4)
4953     (save-excursion
4954       (set-buffer gnus-group-buffer)
4955       (when (setq xref-hashtb
4956                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
4957         (mapatoms
4958          (lambda (group)
4959            (unless (string= from-newsgroup (setq name (symbol-name group)))
4960              (setq idlist (symbol-value group))
4961              ;; Dead groups are not updated.
4962              (and (prog1
4963                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4964                             info (nth 2 entry))
4965                     (when (stringp (setq nth4 (gnus-info-method info)))
4966                       (setq nth4 (gnus-server-to-method nth4))))
4967                   ;; Only do the xrefs if the group has the same
4968                   ;; select method as the group we have just read.
4969                   (or (gnus-methods-equal-p
4970                        nth4 (gnus-find-method-for-group from-newsgroup))
4971                       virtual
4972                       (equal nth4 (setq method (gnus-find-method-for-group
4973                                                 from-newsgroup)))
4974                       (and (equal (car nth4) (car method))
4975                            (equal (nth 1 nth4) (nth 1 method))))
4976                   gnus-use-cross-reference
4977                   (or (not (eq gnus-use-cross-reference t))
4978                       virtual
4979                       ;; Only do cross-references on subscribed
4980                       ;; groups, if that is what is wanted.
4981                       (<= (gnus-info-level info) gnus-level-subscribed))
4982                   (gnus-group-make-articles-read name idlist))))
4983          xref-hashtb)))))
4984
4985 (defun gnus-compute-read-articles (group articles)
4986   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4987          (info (nth 2 entry))
4988          (active (gnus-active group))
4989          ninfo)
4990     (when entry
4991       ;; First peel off all invalid article numbers.
4992       (when active
4993         (let ((ids articles)
4994               id first)
4995           (while (setq id (pop ids))
4996             (when (and first (> id (cdr active)))
4997               ;; We'll end up in this situation in one particular
4998               ;; obscure situation.  If you re-scan a group and get
4999               ;; a new article that is cross-posted to a different
5000               ;; group that has not been re-scanned, you might get
5001               ;; crossposted article that has a higher number than
5002               ;; Gnus believes possible.  So we re-activate this
5003               ;; group as well.  This might mean doing the
5004               ;; crossposting thingy will *increase* the number
5005               ;; of articles in some groups.  Tsk, tsk.
5006               (setq active (or (gnus-activate-group group) active)))
5007             (when (or (> id (cdr active))
5008                       (< id (car active)))
5009               (setq articles (delq id articles))))))
5010       ;; If the read list is nil, we init it.
5011       (if (and active
5012                (null (gnus-info-read info))
5013                (> (car active) 1))
5014           (setq ninfo (cons 1 (1- (car active))))
5015         (setq ninfo (gnus-info-read info)))
5016       ;; Then we add the read articles to the range.
5017       (gnus-add-to-range
5018        ninfo (setq articles (sort articles '<))))))
5019
5020 (defun gnus-group-make-articles-read (group articles)
5021   "Update the info of GROUP to say that ARTICLES are read."
5022   (let* ((num 0)
5023          (entry (gnus-gethash group gnus-newsrc-hashtb))
5024          (info (nth 2 entry))
5025          (active (gnus-active group))
5026          range)
5027     (when entry
5028       (setq range (gnus-compute-read-articles group articles))
5029       (save-excursion
5030         (set-buffer gnus-group-buffer)
5031         (gnus-undo-register
5032           `(progn
5033              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5034              (gnus-info-set-read ',info ',(gnus-info-read info))
5035              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5036              (gnus-group-update-group ,group t))))
5037       ;; Add the read articles to the range.
5038       (gnus-info-set-read info range)
5039       ;; Then we have to re-compute how many unread
5040       ;; articles there are in this group.
5041       (when active
5042         (cond
5043          ((not range)
5044           (setq num (- (1+ (cdr active)) (car active))))
5045          ((not (listp (cdr range)))
5046           (setq num (- (cdr active) (- (1+ (cdr range))
5047                                        (car range)))))
5048          (t
5049           (while range
5050             (if (numberp (car range))
5051                 (setq num (1+ num))
5052               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5053             (setq range (cdr range)))
5054           (setq num (- (cdr active) num))))
5055         ;; Update the number of unread articles.
5056         (setcar entry num)
5057         ;; Update the group buffer.
5058         (gnus-group-update-group group t)))))
5059
5060 (defvar gnus-newsgroup-none-id 0)
5061
5062 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5063   (let ((cur nntp-server-buffer)
5064         (dependencies
5065          (or dependencies
5066              (save-excursion (set-buffer gnus-summary-buffer)
5067                              gnus-newsgroup-dependencies)))
5068         headers id end ref
5069         (mail-parse-charset gnus-newsgroup-charset)
5070         (mail-parse-ignored-charsets
5071          (save-excursion (condition-case nil
5072                              (set-buffer gnus-summary-buffer)
5073                            (error))
5074                          gnus-newsgroup-ignored-charsets)))
5075     (save-excursion
5076       (set-buffer nntp-server-buffer)
5077       ;; Translate all TAB characters into SPACE characters.
5078       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5079       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5080       (gnus-run-hooks 'gnus-parse-headers-hook)
5081       (let ((case-fold-search t)
5082             in-reply-to header p lines chars ctype)
5083         (goto-char (point-min))
5084         ;; Search to the beginning of the next header.  Error messages
5085         ;; do not begin with 2 or 3.
5086         (while (re-search-forward "^[23][0-9]+ " nil t)
5087           (setq id nil
5088                 ref nil)
5089           ;; This implementation of this function, with nine
5090           ;; search-forwards instead of the one re-search-forward and
5091           ;; a case (which basically was the old function) is actually
5092           ;; about twice as fast, even though it looks messier.  You
5093           ;; can't have everything, I guess.  Speed and elegance
5094           ;; doesn't always go hand in hand.
5095           (setq
5096            header
5097            (make-full-mail-header
5098             ;; Number.
5099             (prog1
5100                 (read cur)
5101               (end-of-line)
5102               (setq p (point))
5103               (narrow-to-region (point)
5104                                 (or (and (search-forward "\n.\n" nil t)
5105                                          (- (point) 2))
5106                                     (point))))
5107             ;; Subject.
5108             (progn
5109               (goto-char p)
5110               (if (search-forward "\nsubject:" nil t)
5111                   (nnheader-header-value)
5112                 "(none)"))
5113             ;; From.
5114             (progn
5115               (goto-char p)
5116               (if (search-forward "\nfrom:" nil t)
5117                   (nnheader-header-value)
5118                 "(nobody)"))
5119             ;; Date.
5120             (progn
5121               (goto-char p)
5122               (if (search-forward "\ndate:" nil t)
5123                   (nnheader-header-value) ""))
5124             ;; Message-ID.
5125             (progn
5126               (goto-char p)
5127               (setq id (if (re-search-forward
5128                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5129                            ;; We do it this way to make sure the Message-ID
5130                            ;; is (somewhat) syntactically valid.
5131                            (buffer-substring (match-beginning 1)
5132                                              (match-end 1))
5133                          ;; If there was no message-id, we just fake one
5134                          ;; to make subsequent routines simpler.
5135                          (nnheader-generate-fake-message-id))))
5136             ;; References.
5137             (progn
5138               (goto-char p)
5139               (if (search-forward "\nreferences:" nil t)
5140                   (progn
5141                     (setq end (point))
5142                     (prog1
5143                         (nnheader-header-value)
5144                       (setq ref
5145                             (buffer-substring
5146                              (progn
5147                                ;; (end-of-line)
5148                                (search-backward ">" end t)
5149                                (1+ (point)))
5150                              (progn
5151                                (search-backward "<" end t)
5152                                (point))))))
5153                 ;; Get the references from the in-reply-to header if there
5154                 ;; were no references and the in-reply-to header looks
5155                 ;; promising.
5156                 (if (and (search-forward "\nin-reply-to:" nil t)
5157                          (setq in-reply-to (nnheader-header-value))
5158                          (string-match "<[^>]+>" in-reply-to))
5159                     (let (ref2)
5160                       (setq ref (substring in-reply-to (match-beginning 0)
5161                                            (match-end 0)))
5162                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5163                         (setq ref2 (substring in-reply-to (match-beginning 0)
5164                                               (match-end 0)))
5165                         (when (> (length ref2) (length ref))
5166                           (setq ref ref2)))
5167                       ref)
5168                   (setq ref nil))))
5169             ;; Chars.
5170             (progn
5171               (goto-char p)
5172               (if (search-forward "\nchars: " nil t)
5173                   (if (numberp (setq chars (ignore-errors (read cur))))
5174                       chars -1)
5175                 -1))
5176             ;; Lines.
5177             (progn
5178               (goto-char p)
5179               (if (search-forward "\nlines: " nil t)
5180                   (if (numberp (setq lines (ignore-errors (read cur))))
5181                       lines -1)
5182                 -1))
5183             ;; Xref.
5184             (progn
5185               (goto-char p)
5186               (and (search-forward "\nxref:" nil t)
5187                    (nnheader-header-value)))
5188             ;; Extra.
5189             (when gnus-extra-headers
5190               (let ((extra gnus-extra-headers)
5191                     out)
5192                 (while extra
5193                   (goto-char p)
5194                   (when (search-forward
5195                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5196                     (push (cons (car extra) (nnheader-header-value)) out))
5197                   (pop extra))
5198                 out))))
5199           (goto-char p)
5200           (if (and (search-forward "\ncontent-type: " nil t)
5201                    (setq ctype (nnheader-header-value)))
5202               (mime-entity-set-content-type-internal
5203                header (mime-parse-Content-Type ctype)))
5204           (when (equal id ref)
5205             (setq ref nil))
5206
5207           (when gnus-alter-header-function
5208             (funcall gnus-alter-header-function header)
5209             (setq id (mail-header-id header)
5210                   ref (gnus-parent-id (mail-header-references header))))
5211
5212           (when (setq header
5213                       (gnus-dependencies-add-header
5214                        header dependencies force-new))
5215             (push header headers))
5216           (goto-char (point-max))
5217           (widen))
5218         (nreverse headers)))))
5219
5220 ;; Goes through the xover lines and returns a list of vectors
5221 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5222                                                   force-new dependencies
5223                                                   group also-fetch-heads)
5224   "Parse the news overview data in the server buffer.
5225 Return a list of headers that match SEQUENCE (see
5226 `nntp-retrieve-headers')."
5227   ;; Get the Xref when the users reads the articles since most/some
5228   ;; NNTP servers do not include Xrefs when using XOVER.
5229   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5230   (let ((mail-parse-charset gnus-newsgroup-charset)
5231         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5232         (cur nntp-server-buffer)
5233         (dependencies (or dependencies gnus-newsgroup-dependencies))
5234         (allp (cond
5235                ((eq gnus-read-all-available-headers t)
5236                 t)
5237                ((stringp gnus-read-all-available-headers)
5238                 (string-match gnus-read-all-available-headers group))
5239                (t
5240                 nil)))
5241         number headers header)
5242     (save-excursion
5243       (set-buffer nntp-server-buffer)
5244       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5245       ;; Allow the user to mangle the headers before parsing them.
5246       (gnus-run-hooks 'gnus-parse-headers-hook)
5247       (goto-char (point-min))
5248       (while (not (eobp))
5249         (condition-case ()
5250             (while (and (or sequence allp)
5251                         (not (eobp)))
5252               (setq number (read cur))
5253               (when (not allp)
5254                 (while (and sequence
5255                             (< (car sequence) number))
5256                   (setq sequence (cdr sequence))))
5257               (when (and (or allp
5258                              (and sequence
5259                                   (eq number (car sequence))))
5260                          (progn
5261                            (setq sequence (cdr sequence))
5262                            (setq header (inline
5263                                           (gnus-nov-parse-line
5264                                            number dependencies force-new)))))
5265                 (push header headers))
5266               (forward-line 1))
5267           (error
5268            (gnus-error 4 "Strange nov line (%d)"
5269                        (count-lines (point-min) (point)))))
5270         (forward-line 1))
5271       ;; A common bug in inn is that if you have posted an article and
5272       ;; then retrieves the active file, it will answer correctly --
5273       ;; the new article is included.  However, a NOV entry for the
5274       ;; article may not have been generated yet, so this may fail.
5275       ;; We work around this problem by retrieving the last few
5276       ;; headers using HEAD.
5277       (if (or (not also-fetch-heads)
5278               (not sequence))
5279           ;; We (probably) got all the headers.
5280           (nreverse headers)
5281         (let ((gnus-nov-is-evil t))
5282           (nconc
5283            (nreverse headers)
5284            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5285              (gnus-get-newsgroup-headers))))))))
5286
5287 (defun gnus-article-get-xrefs ()
5288   "Fill in the Xref value in `gnus-current-headers', if necessary.
5289 This is meant to be called in `gnus-article-internal-prepare-hook'."
5290   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5291                                  gnus-current-headers)))
5292     (or (not gnus-use-cross-reference)
5293         (not headers)
5294         (and (mail-header-xref headers)
5295              (not (string= (mail-header-xref headers) "")))
5296         (let ((case-fold-search t)
5297               xref)
5298           (save-restriction
5299             (nnheader-narrow-to-headers)
5300             (goto-char (point-min))
5301             (when (or (and (not (eobp))
5302                            (eq (downcase (char-after)) ?x)
5303                            (looking-at "Xref:"))
5304                       (search-forward "\nXref:" nil t))
5305               (goto-char (1+ (match-end 0)))
5306               (setq xref (buffer-substring (point)
5307                                            (progn (end-of-line) (point))))
5308               (mail-header-set-xref headers xref)))))))
5309
5310 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5311   "Find article ID and insert the summary line for that article.
5312 OLD-HEADER can either be a header or a line number to insert
5313 the subject line on."
5314   (let* ((line (and (numberp old-header) old-header))
5315          (old-header (and (vectorp old-header) old-header))
5316          (header (cond ((and old-header use-old-header)
5317                         old-header)
5318                        ((and (numberp id)
5319                              (gnus-number-to-header id))
5320                         (gnus-number-to-header id))
5321                        (t
5322                         (gnus-read-header id))))
5323          (number (and (numberp id) id))
5324          d)
5325     (when header
5326       ;; Rebuild the thread that this article is part of and go to the
5327       ;; article we have fetched.
5328       (when (and (not gnus-show-threads)
5329                  old-header)
5330         (when (and number
5331                    (setq d (gnus-data-find (mail-header-number old-header))))
5332           (goto-char (gnus-data-pos d))
5333           (gnus-data-remove
5334            number
5335            (- (gnus-point-at-bol)
5336               (prog1
5337                   (1+ (gnus-point-at-eol))
5338                 (gnus-delete-line))))))
5339       (when old-header
5340         (mail-header-set-number header (mail-header-number old-header)))
5341       (setq gnus-newsgroup-sparse
5342             (delq (setq number (mail-header-number header))
5343                   gnus-newsgroup-sparse))
5344       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5345       (push number gnus-newsgroup-limit)
5346       (gnus-rebuild-thread (mail-header-id header) line)
5347       (gnus-summary-goto-subject number nil t))
5348     (when (and (numberp number)
5349                (> number 0))
5350       ;; We have to update the boundaries even if we can't fetch the
5351       ;; article if ID is a number -- so that the next `P' or `N'
5352       ;; command will fetch the previous (or next) article even
5353       ;; if the one we tried to fetch this time has been canceled.
5354       (when (> number gnus-newsgroup-end)
5355         (setq gnus-newsgroup-end number))
5356       (when (< number gnus-newsgroup-begin)
5357         (setq gnus-newsgroup-begin number))
5358       (setq gnus-newsgroup-unselected
5359             (delq number gnus-newsgroup-unselected)))
5360     ;; Report back a success?
5361     (and header (mail-header-number header))))
5362
5363 ;;; Process/prefix in the summary buffer
5364
5365 (defun gnus-summary-work-articles (n)
5366   "Return a list of articles to be worked upon.
5367 The prefix argument, the list of process marked articles, and the
5368 current article will be taken into consideration."
5369   (save-excursion
5370     (set-buffer gnus-summary-buffer)
5371     (cond
5372      (n
5373       ;; A numerical prefix has been given.
5374       (setq n (prefix-numeric-value n))
5375       (let ((backward (< n 0))
5376             (n (abs (prefix-numeric-value n)))
5377             articles article)
5378         (save-excursion
5379           (while
5380               (and (> n 0)
5381                    (push (setq article (gnus-summary-article-number))
5382                          articles)
5383                    (if backward
5384                        (gnus-summary-find-prev nil article)
5385                      (gnus-summary-find-next nil article)))
5386             (decf n)))
5387         (nreverse articles)))
5388      ((and (gnus-region-active-p) (mark))
5389       (message "region active")
5390       ;; Work on the region between point and mark.
5391       (let ((max (max (point) (mark)))
5392             articles article)
5393         (save-excursion
5394           (goto-char (min (point) (mark)))
5395           (while
5396               (and
5397                (push (setq article (gnus-summary-article-number)) articles)
5398                (gnus-summary-find-next nil article)
5399                (< (point) max)))
5400           (nreverse articles))))
5401      (gnus-newsgroup-processable
5402       ;; There are process-marked articles present.
5403       ;; Save current state.
5404       (gnus-summary-save-process-mark)
5405       ;; Return the list.
5406       (reverse gnus-newsgroup-processable))
5407      (t
5408       ;; Just return the current article.
5409       (list (gnus-summary-article-number))))))
5410
5411 (defmacro gnus-summary-iterate (arg &rest forms)
5412   "Iterate over the process/prefixed articles and do FORMS.
5413 ARG is the interactive prefix given to the command.  FORMS will be
5414 executed with point over the summary line of the articles."
5415   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5416     `(let ((,articles (gnus-summary-work-articles ,arg)))
5417        (while ,articles
5418          (gnus-summary-goto-subject (car ,articles))
5419          ,@forms
5420          (pop ,articles)))))
5421
5422 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5423 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5424
5425 (defun gnus-summary-save-process-mark ()
5426   "Push the current set of process marked articles on the stack."
5427   (interactive)
5428   (push (copy-sequence gnus-newsgroup-processable)
5429         gnus-newsgroup-process-stack))
5430
5431 (defun gnus-summary-kill-process-mark ()
5432   "Push the current set of process marked articles on the stack and unmark."
5433   (interactive)
5434   (gnus-summary-save-process-mark)
5435   (gnus-summary-unmark-all-processable))
5436
5437 (defun gnus-summary-yank-process-mark ()
5438   "Pop the last process mark state off the stack and restore it."
5439   (interactive)
5440   (unless gnus-newsgroup-process-stack
5441     (error "Empty mark stack"))
5442   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5443
5444 (defun gnus-summary-process-mark-set (set)
5445   "Make SET into the current process marked articles."
5446   (gnus-summary-unmark-all-processable)
5447   (while set
5448     (gnus-summary-set-process-mark (pop set))))
5449
5450 ;;; Searching and stuff
5451
5452 (defun gnus-summary-search-group (&optional backward use-level)
5453   "Search for next unread newsgroup.
5454 If optional argument BACKWARD is non-nil, search backward instead."
5455   (save-excursion
5456     (set-buffer gnus-group-buffer)
5457     (when (gnus-group-search-forward
5458            backward nil (if use-level (gnus-group-group-level) nil))
5459       (gnus-group-group-name))))
5460
5461 (defun gnus-summary-best-group (&optional exclude-group)
5462   "Find the name of the best unread group.
5463 If EXCLUDE-GROUP, do not go to this group."
5464   (save-excursion
5465     (set-buffer gnus-group-buffer)
5466     (save-excursion
5467       (gnus-group-best-unread-group exclude-group))))
5468
5469 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5470   (if backward (gnus-summary-find-prev)
5471     (let* ((dummy (gnus-summary-article-intangible-p))
5472            (article (or article (gnus-summary-article-number)))
5473            (arts (gnus-data-find-list article))
5474            result)
5475       (when (and (not dummy)
5476                  (or (not gnus-summary-check-current)
5477                      (not unread)
5478                      (not (gnus-data-unread-p (car arts)))))
5479         (setq arts (cdr arts)))
5480       (when (setq result
5481                   (if unread
5482                       (progn
5483                         (while arts
5484                           (when (or (and undownloaded
5485                                          (eq gnus-undownloaded-mark
5486                                              (gnus-data-mark (car arts))))
5487                                     (gnus-data-unread-p (car arts)))
5488                             (setq result (car arts)
5489                                   arts nil))
5490                           (setq arts (cdr arts)))
5491                         result)
5492                     (car arts)))
5493         (goto-char (gnus-data-pos result))
5494         (gnus-data-number result)))))
5495
5496 (defun gnus-summary-find-prev (&optional unread article)
5497   (let* ((eobp (eobp))
5498          (article (or article (gnus-summary-article-number)))
5499          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5500          result)
5501     (when (and (not eobp)
5502                (or (not gnus-summary-check-current)
5503                    (not unread)
5504                    (not (gnus-data-unread-p (car arts)))))
5505       (setq arts (cdr arts)))
5506     (when (setq result
5507                 (if unread
5508                     (progn
5509                       (while arts
5510                         (when (gnus-data-unread-p (car arts))
5511                           (setq result (car arts)
5512                                 arts nil))
5513                         (setq arts (cdr arts)))
5514                       result)
5515                   (car arts)))
5516       (goto-char (gnus-data-pos result))
5517       (gnus-data-number result))))
5518
5519 (defun gnus-summary-find-subject (subject &optional unread backward article)
5520   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5521          (article (or article (gnus-summary-article-number)))
5522          (articles (gnus-data-list backward))
5523          (arts (gnus-data-find-list article articles))
5524          result)
5525     (when (or (not gnus-summary-check-current)
5526               (not unread)
5527               (not (gnus-data-unread-p (car arts))))
5528       (setq arts (cdr arts)))
5529     (while arts
5530       (and (or (not unread)
5531                (gnus-data-unread-p (car arts)))
5532            (vectorp (gnus-data-header (car arts)))
5533            (gnus-subject-equal
5534             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5535            (setq result (car arts)
5536                  arts nil))
5537       (setq arts (cdr arts)))
5538     (and result
5539          (goto-char (gnus-data-pos result))
5540          (gnus-data-number result))))
5541
5542 (defun gnus-summary-search-forward (&optional unread subject backward)
5543   "Search forward for an article.
5544 If UNREAD, look for unread articles.  If SUBJECT, look for
5545 articles with that subject.  If BACKWARD, search backward instead."
5546   (cond (subject (gnus-summary-find-subject subject unread backward))
5547         (backward (gnus-summary-find-prev unread))
5548         (t (gnus-summary-find-next unread))))
5549
5550 (defun gnus-recenter (&optional n)
5551   "Center point in window and redisplay frame.
5552 Also do horizontal recentering."
5553   (interactive "P")
5554   (when (and gnus-auto-center-summary
5555              (not (eq gnus-auto-center-summary 'vertical)))
5556     (gnus-horizontal-recenter))
5557   (recenter n))
5558
5559 (defun gnus-summary-recenter ()
5560   "Center point in the summary window.
5561 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5562 displayed, no centering will be performed."
5563   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5564   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5565   (interactive)
5566   (let* ((top (cond ((< (window-height) 4) 0)
5567                     ((< (window-height) 7) 1)
5568                     (t (if (numberp gnus-auto-center-summary)
5569                            gnus-auto-center-summary
5570                          2))))
5571          (height (1- (window-height)))
5572          (bottom (save-excursion (goto-char (point-max))
5573                                  (forward-line (- height))
5574                                  (point)))
5575          (window (get-buffer-window (current-buffer))))
5576     ;; The user has to want it.
5577     (when gnus-auto-center-summary
5578       (when (get-buffer-window gnus-article-buffer)
5579         ;; Only do recentering when the article buffer is displayed,
5580         ;; Set the window start to either `bottom', which is the biggest
5581         ;; possible valid number, or the second line from the top,
5582         ;; whichever is the least.
5583         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5584           (if (> bottom top-pos)
5585               ;; Keep the second line from the top visible
5586               (set-window-start window top-pos t)
5587             ;; Try to keep the bottom line visible; if it's partially
5588             ;; obscured, either scroll one more line to make it fully
5589             ;; visible, or revert to using TOP-POS.
5590             (save-excursion
5591               (goto-char (point-max))
5592               (forward-line -1)
5593               (let ((last-line-start (point)))
5594                 (goto-char bottom)
5595                 (set-window-start window (point) t)
5596                 (when (not (pos-visible-in-window-p last-line-start window))
5597                   (forward-line 1)
5598                   (set-window-start window (min (point) top-pos) t)))))))
5599       ;; Do horizontal recentering while we're at it.
5600       (when (and (get-buffer-window (current-buffer) t)
5601                  (not (eq gnus-auto-center-summary 'vertical)))
5602         (let ((selected (selected-window)))
5603           (select-window (get-buffer-window (current-buffer) t))
5604           (gnus-summary-position-point)
5605           (gnus-horizontal-recenter)
5606           (select-window selected))))))
5607
5608 (defun gnus-summary-jump-to-group (newsgroup)
5609   "Move point to NEWSGROUP in group mode buffer."
5610   ;; Keep update point of group mode buffer if visible.
5611   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5612       (save-window-excursion
5613         ;; Take care of tree window mode.
5614         (when (get-buffer-window gnus-group-buffer)
5615           (pop-to-buffer gnus-group-buffer))
5616         (gnus-group-jump-to-group newsgroup))
5617     (save-excursion
5618       ;; Take care of tree window mode.
5619       (if (get-buffer-window gnus-group-buffer)
5620           (pop-to-buffer gnus-group-buffer)
5621         (set-buffer gnus-group-buffer))
5622       (gnus-group-jump-to-group newsgroup))))
5623
5624 ;; This function returns a list of article numbers based on the
5625 ;; difference between the ranges of read articles in this group and
5626 ;; the range of active articles.
5627 (defun gnus-list-of-unread-articles (group)
5628   (let* ((read (gnus-info-read (gnus-get-info group)))
5629          (active (or (gnus-active group) (gnus-activate-group group)))
5630          (last (cdr active))
5631          first nlast unread)
5632     ;; If none are read, then all are unread.
5633     (if (not read)
5634         (setq first (car active))
5635       ;; If the range of read articles is a single range, then the
5636       ;; first unread article is the article after the last read
5637       ;; article.  Sounds logical, doesn't it?
5638       (if (and (not (listp (cdr read)))
5639                (or (< (car read) (car active))
5640                    (progn (setq read (list read))
5641                           nil)))
5642           (setq first (max (car active) (1+ (cdr read))))
5643         ;; `read' is a list of ranges.
5644         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5645                                   (caar read)))
5646                   1)
5647           (setq first (car active)))
5648         (while read
5649           (when first
5650             (while (< first nlast)
5651               (push first unread)
5652               (setq first (1+ first))))
5653           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5654           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5655           (setq read (cdr read)))))
5656     ;; And add the last unread articles.
5657     (while (<= first last)
5658       (push first unread)
5659       (setq first (1+ first)))
5660     ;; Return the list of unread articles.
5661     (delq 0 (nreverse unread))))
5662
5663 (defun gnus-list-of-read-articles (group)
5664   "Return a list of unread, unticked and non-dormant articles."
5665   (let* ((info (gnus-get-info group))
5666          (marked (gnus-info-marks info))
5667          (active (gnus-active group)))
5668     (and info active
5669          (gnus-set-difference
5670           (gnus-sorted-complement
5671            (gnus-uncompress-range active)
5672            (gnus-list-of-unread-articles group))
5673           (append
5674            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5675            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5676
5677 ;; Various summary commands
5678
5679 (defun gnus-summary-select-article-buffer ()
5680   "Reconfigure windows to show article buffer."
5681   (interactive)
5682   (if (not (gnus-buffer-live-p gnus-article-buffer))
5683       (error "There is no article buffer for this summary buffer")
5684     (gnus-configure-windows 'article)
5685     (select-window (get-buffer-window gnus-article-buffer))))
5686
5687 (defun gnus-summary-universal-argument (arg)
5688   "Perform any operation on all articles that are process/prefixed."
5689   (interactive "P")
5690   (let ((articles (gnus-summary-work-articles arg))
5691         func article)
5692     (if (eq
5693          (setq
5694           func
5695           (key-binding
5696            (read-key-sequence
5697             (substitute-command-keys
5698              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5699          'undefined)
5700         (gnus-error 1 "Undefined key")
5701       (save-excursion
5702         (while articles
5703           (gnus-summary-goto-subject (setq article (pop articles)))
5704           (let (gnus-newsgroup-processable)
5705             (command-execute func))
5706           (gnus-summary-remove-process-mark article)))))
5707   (gnus-summary-position-point))
5708
5709 (defun gnus-summary-toggle-truncation (&optional arg)
5710   "Toggle truncation of summary lines.
5711 With arg, turn line truncation on iff arg is positive."
5712   (interactive "P")
5713   (setq truncate-lines
5714         (if (null arg) (not truncate-lines)
5715           (> (prefix-numeric-value arg) 0)))
5716   (redraw-display))
5717
5718 (defun gnus-summary-reselect-current-group (&optional all rescan)
5719   "Exit and then reselect the current newsgroup.
5720 The prefix argument ALL means to select all articles."
5721   (interactive "P")
5722   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5723     (error "Ephemeral groups can't be reselected"))
5724   (let ((current-subject (gnus-summary-article-number))
5725         (group gnus-newsgroup-name))
5726     (setq gnus-newsgroup-begin nil)
5727     (gnus-summary-exit)
5728     ;; We have to adjust the point of group mode buffer because
5729     ;; point was moved to the next unread newsgroup by exiting.
5730     (gnus-summary-jump-to-group group)
5731     (when rescan
5732       (save-excursion
5733         (save-window-excursion
5734           ;; Don't show group contents.
5735           (set-window-start (selected-window) (point-max))
5736           (gnus-group-get-new-news-this-group 1))))
5737     (gnus-group-read-group all t)
5738     (gnus-summary-goto-subject current-subject nil t)))
5739
5740 (defun gnus-summary-rescan-group (&optional all)
5741   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5742   (interactive "P")
5743   (gnus-summary-reselect-current-group all t))
5744
5745 (defun gnus-summary-update-info (&optional non-destructive)
5746   (save-excursion
5747     (let ((group gnus-newsgroup-name))
5748       (when group
5749         (when gnus-newsgroup-kill-headers
5750           (setq gnus-newsgroup-killed
5751                 (gnus-compress-sequence
5752                  (nconc
5753                   (gnus-set-sorted-intersection
5754                    (gnus-uncompress-range gnus-newsgroup-killed)
5755                    (setq gnus-newsgroup-unselected
5756                          (sort gnus-newsgroup-unselected '<)))
5757                   (setq gnus-newsgroup-unreads
5758                         (sort gnus-newsgroup-unreads '<)))
5759                  t)))
5760         (unless (listp (cdr gnus-newsgroup-killed))
5761           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5762         (let ((headers gnus-newsgroup-headers))
5763           ;; Set the new ranges of read articles.
5764           (save-excursion
5765             (set-buffer gnus-group-buffer)
5766             (gnus-undo-force-boundary))
5767           (gnus-update-read-articles
5768            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5769           ;; Set the current article marks.
5770           (let ((gnus-newsgroup-scored
5771                  (if (and (not gnus-save-score)
5772                           (not non-destructive))
5773                      nil
5774                    gnus-newsgroup-scored)))
5775             (save-excursion
5776               (gnus-update-marks)))
5777           ;; Do the cross-ref thing.
5778           (when gnus-use-cross-reference
5779             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5780           ;; Do not switch windows but change the buffer to work.
5781           (set-buffer gnus-group-buffer)
5782           (unless (gnus-ephemeral-group-p group)
5783             (gnus-group-update-group group)))))))
5784
5785 (defun gnus-summary-save-newsrc (&optional force)
5786   "Save the current number of read/marked articles in the dribble buffer.
5787 The dribble buffer will then be saved.
5788 If FORCE (the prefix), also save the .newsrc file(s)."
5789   (interactive "P")
5790   (gnus-summary-update-info t)
5791   (if force
5792       (gnus-save-newsrc-file)
5793     (gnus-dribble-save)))
5794
5795 (defun gnus-summary-exit (&optional temporary)
5796   "Exit reading current newsgroup, and then return to group selection mode.
5797 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5798   (interactive)
5799   (gnus-set-global-variables)
5800   (gnus-kill-save-kill-buffer)
5801   (gnus-async-halt-prefetch)
5802   (let* ((group gnus-newsgroup-name)
5803          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5804          (mode major-mode)
5805          (group-point nil)
5806          (buf (current-buffer)))
5807     (unless quit-config
5808       ;; Do adaptive scoring, and possibly save score files.
5809       (when gnus-newsgroup-adaptive
5810         (gnus-score-adaptive))
5811       (when gnus-use-scoring
5812         (gnus-score-save)))
5813     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5814     ;; If we have several article buffers, we kill them at exit.
5815     (unless gnus-single-article-buffer
5816       (gnus-kill-buffer gnus-original-article-buffer)
5817       (setq gnus-article-current nil))
5818     (when gnus-use-cache
5819       (gnus-cache-possibly-remove-articles)
5820       (gnus-cache-save-buffers))
5821     (gnus-async-prefetch-remove-group group)
5822     (when gnus-suppress-duplicates
5823       (gnus-dup-enter-articles))
5824     (when gnus-use-trees
5825       (gnus-tree-close group))
5826     (when gnus-use-cache
5827       (gnus-cache-write-active))
5828     ;; Remove entries for this group.
5829     (nnmail-purge-split-history (gnus-group-real-name group))
5830     ;; Make all changes in this group permanent.
5831     (unless quit-config
5832       (gnus-run-hooks 'gnus-exit-group-hook)
5833       (gnus-summary-update-info))
5834     (gnus-close-group group)
5835     ;; Make sure where we were, and go to next newsgroup.
5836     (set-buffer gnus-group-buffer)
5837     (unless quit-config
5838       (gnus-group-jump-to-group group))
5839     (gnus-run-hooks 'gnus-summary-exit-hook)
5840     (unless (or quit-config
5841                 ;; If this group has disappeared from the summary
5842                 ;; buffer, don't skip forwards.
5843                 (not (string= group (gnus-group-group-name))))
5844       (gnus-group-next-unread-group 1))
5845     (setq group-point (point))
5846     (if temporary
5847         nil                             ;Nothing to do.
5848       ;; If we have several article buffers, we kill them at exit.
5849       (unless gnus-single-article-buffer
5850         (gnus-kill-buffer gnus-article-buffer)
5851         (gnus-kill-buffer gnus-original-article-buffer)
5852         (setq gnus-article-current nil))
5853       (set-buffer buf)
5854       (if (not gnus-kill-summary-on-exit)
5855           (progn
5856             (gnus-deaden-summary)
5857             (setq mode nil))
5858         ;; We set all buffer-local variables to nil.  It is unclear why
5859         ;; this is needed, but if we don't, buffer-local variables are
5860         ;; not garbage-collected, it seems.  This would the lead to en
5861         ;; ever-growing Emacs.
5862         (gnus-summary-clear-local-variables)
5863         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5864           (gnus-summary-clear-local-variables))
5865         (when (get-buffer gnus-article-buffer)
5866           (bury-buffer gnus-article-buffer))
5867         ;; We clear the global counterparts of the buffer-local
5868         ;; variables as well, just to be on the safe side.
5869         (set-buffer gnus-group-buffer)
5870         (gnus-summary-clear-local-variables)
5871         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5872           (gnus-summary-clear-local-variables)))
5873       (setq gnus-current-select-method gnus-select-method)
5874       (pop-to-buffer gnus-group-buffer)
5875       (if (not quit-config)
5876           (progn
5877             (goto-char group-point)
5878             (gnus-configure-windows 'group 'force)
5879             (unless (pos-visible-in-window-p)
5880               (forward-line (/ (static-if (featurep 'xemacs)
5881                                    (window-displayed-height)
5882                                  (1- (window-height)))
5883                                -2))
5884               (set-window-start (selected-window) (point))
5885               (goto-char group-point)))
5886         (gnus-handle-ephemeral-exit quit-config))
5887       ;; Return to group mode buffer.
5888       (when (eq mode 'gnus-summary-mode)
5889         (gnus-kill-buffer buf))
5890       ;; Clear the current group name.
5891       (unless quit-config
5892         (setq gnus-newsgroup-name nil)))))
5893
5894 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
5895 (defun gnus-summary-exit-no-update (&optional no-questions)
5896   "Quit reading current newsgroup without updating read article info."
5897   (interactive)
5898   (let* ((group gnus-newsgroup-name)
5899          (quit-config (gnus-group-quit-config group)))
5900     (when (or no-questions
5901               gnus-expert-user
5902               (gnus-y-or-n-p "Discard changes to this group and exit? "))
5903       (gnus-async-halt-prefetch)
5904       (mapcar 'funcall
5905               (delq 'gnus-summary-expire-articles
5906                     (copy-sequence gnus-summary-prepare-exit-hook)))
5907       ;; If we have several article buffers, we kill them at exit.
5908       (unless gnus-single-article-buffer
5909         (gnus-kill-buffer gnus-article-buffer)
5910         (gnus-kill-buffer gnus-original-article-buffer)
5911         (setq gnus-article-current nil))
5912       (if (not gnus-kill-summary-on-exit)
5913           (gnus-deaden-summary)
5914         (gnus-close-group group)
5915         (gnus-summary-clear-local-variables)
5916         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5917           (gnus-summary-clear-local-variables))
5918         (set-buffer gnus-group-buffer)
5919         (gnus-summary-clear-local-variables)
5920         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5921           (gnus-summary-clear-local-variables))
5922         (when (get-buffer gnus-summary-buffer)
5923           (kill-buffer gnus-summary-buffer)))
5924       (unless gnus-single-article-buffer
5925         (setq gnus-article-current nil))
5926       (when gnus-use-trees
5927         (gnus-tree-close group))
5928       (gnus-async-prefetch-remove-group group)
5929       (when (get-buffer gnus-article-buffer)
5930         (bury-buffer gnus-article-buffer))
5931       ;; Return to the group buffer.
5932       (gnus-configure-windows 'group 'force)
5933       ;; Clear the current group name.
5934       (setq gnus-newsgroup-name nil)
5935       (when (equal (gnus-group-group-name) group)
5936         (gnus-group-next-unread-group 1))
5937       (when quit-config
5938         (gnus-handle-ephemeral-exit quit-config)))))
5939
5940 (defun gnus-handle-ephemeral-exit (quit-config)
5941   "Handle movement when leaving an ephemeral group.
5942 The state which existed when entering the ephemeral is reset."
5943   (if (not (buffer-name (car quit-config)))
5944       (gnus-configure-windows 'group 'force)
5945     (set-buffer (car quit-config))
5946     (cond ((eq major-mode 'gnus-summary-mode)
5947            (gnus-set-global-variables))
5948           ((eq major-mode 'gnus-article-mode)
5949            (save-excursion
5950              ;; The `gnus-summary-buffer' variable may point
5951              ;; to the old summary buffer when using a single
5952              ;; article buffer.
5953              (unless (gnus-buffer-live-p gnus-summary-buffer)
5954                (set-buffer gnus-group-buffer))
5955              (set-buffer gnus-summary-buffer)
5956              (gnus-set-global-variables))))
5957     (if (or (eq (cdr quit-config) 'article)
5958             (eq (cdr quit-config) 'pick))
5959         (progn
5960           ;; The current article may be from the ephemeral group
5961           ;; thus it is best that we reload this article
5962           (gnus-summary-show-article)
5963           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
5964               (gnus-configure-windows 'pick 'force)
5965             (gnus-configure-windows (cdr quit-config) 'force)))
5966       (gnus-configure-windows (cdr quit-config) 'force))
5967     (when (eq major-mode 'gnus-summary-mode)
5968       (gnus-summary-next-subject 1 nil t)
5969       (gnus-summary-recenter)
5970       (gnus-summary-position-point))))
5971
5972 (defun gnus-summary-preview-mime-message ()
5973   "MIME decode and play this message."
5974   (interactive)
5975   (let ((gnus-break-pages nil)
5976         (gnus-show-mime t))
5977     (gnus-summary-select-article gnus-show-all-headers t))
5978   (select-window (get-buffer-window gnus-article-buffer)))
5979
5980 ;;; Dead summaries.
5981
5982 (defvar gnus-dead-summary-mode-map nil)
5983
5984 (unless gnus-dead-summary-mode-map
5985   (setq gnus-dead-summary-mode-map (make-keymap))
5986   (suppress-keymap gnus-dead-summary-mode-map)
5987   (substitute-key-definition
5988    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
5989   (let ((keys '("\C-d" "\r" "\177" [delete])))
5990     (while keys
5991       (define-key gnus-dead-summary-mode-map
5992         (pop keys) 'gnus-summary-wake-up-the-dead))))
5993
5994 (defvar gnus-dead-summary-mode nil
5995   "Minor mode for Gnus summary buffers.")
5996
5997 (defun gnus-dead-summary-mode (&optional arg)
5998   "Minor mode for Gnus summary buffers."
5999   (interactive "P")
6000   (when (eq major-mode 'gnus-summary-mode)
6001     (make-local-variable 'gnus-dead-summary-mode)
6002     (setq gnus-dead-summary-mode
6003           (if (null arg) (not gnus-dead-summary-mode)
6004             (> (prefix-numeric-value arg) 0)))
6005     (when gnus-dead-summary-mode
6006       (gnus-add-minor-mode
6007        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6008
6009 (defun gnus-deaden-summary ()
6010   "Make the current summary buffer into a dead summary buffer."
6011   ;; Kill any previous dead summary buffer.
6012   (when (and gnus-dead-summary
6013              (buffer-name gnus-dead-summary))
6014     (save-excursion
6015       (set-buffer gnus-dead-summary)
6016       (when gnus-dead-summary-mode
6017         (kill-buffer (current-buffer)))))
6018   ;; Make this the current dead summary.
6019   (setq gnus-dead-summary (current-buffer))
6020   (gnus-dead-summary-mode 1)
6021   (let ((name (buffer-name)))
6022     (when (string-match "Summary" name)
6023       (rename-buffer
6024        (concat (substring name 0 (match-beginning 0)) "Dead "
6025                (substring name (match-beginning 0)))
6026        t)
6027       (bury-buffer))))
6028
6029 (defun gnus-kill-or-deaden-summary (buffer)
6030   "Kill or deaden the summary BUFFER."
6031   (save-excursion
6032     (when (and (buffer-name buffer)
6033                (not gnus-single-article-buffer))
6034       (save-excursion
6035         (set-buffer buffer)
6036         (gnus-kill-buffer gnus-article-buffer)
6037         (gnus-kill-buffer gnus-original-article-buffer)))
6038     (cond (gnus-kill-summary-on-exit
6039            (when (and gnus-use-trees
6040                       (gnus-buffer-exists-p buffer))
6041              (save-excursion
6042                (set-buffer buffer)
6043                (gnus-tree-close gnus-newsgroup-name)))
6044            (gnus-kill-buffer buffer))
6045           ((gnus-buffer-exists-p buffer)
6046            (save-excursion
6047              (set-buffer buffer)
6048              (gnus-deaden-summary))))))
6049
6050 (defun gnus-summary-wake-up-the-dead (&rest args)
6051   "Wake up the dead summary buffer."
6052   (interactive)
6053   (gnus-dead-summary-mode -1)
6054   (let ((name (buffer-name)))
6055     (when (string-match "Dead " name)
6056       (rename-buffer
6057        (concat (substring name 0 (match-beginning 0))
6058                (substring name (match-end 0)))
6059        t)))
6060   (gnus-message 3 "This dead summary is now alive again"))
6061
6062 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6063 (defun gnus-summary-fetch-faq (&optional faq-dir)
6064   "Fetch the FAQ for the current group.
6065 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6066 in."
6067   (interactive
6068    (list
6069     (when current-prefix-arg
6070       (completing-read
6071        "Faq dir: " (and (listp gnus-group-faq-directory)
6072                         (mapcar (lambda (file) (list file))
6073                                 gnus-group-faq-directory))))))
6074   (let (gnus-faq-buffer)
6075     (when (setq gnus-faq-buffer
6076                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6077       (gnus-configure-windows 'summary-faq))))
6078
6079 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6080 (defun gnus-summary-describe-group (&optional force)
6081   "Describe the current newsgroup."
6082   (interactive "P")
6083   (gnus-group-describe-group force gnus-newsgroup-name))
6084
6085 (defun gnus-summary-describe-briefly ()
6086   "Describe summary mode commands briefly."
6087   (interactive)
6088   (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")))
6089
6090 ;; Walking around group mode buffer from summary mode.
6091
6092 (defun gnus-summary-next-group (&optional no-article target-group backward)
6093   "Exit current newsgroup and then select next unread newsgroup.
6094 If prefix argument NO-ARTICLE is non-nil, no article is selected
6095 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6096 previous group instead."
6097   (interactive "P")
6098   ;; Stop pre-fetching.
6099   (gnus-async-halt-prefetch)
6100   (let ((current-group gnus-newsgroup-name)
6101         (current-buffer (current-buffer))
6102         entered)
6103     ;; First we semi-exit this group to update Xrefs and all variables.
6104     ;; We can't do a real exit, because the window conf must remain
6105     ;; the same in case the user is prompted for info, and we don't
6106     ;; want the window conf to change before that...
6107     (gnus-summary-exit t)
6108     (while (not entered)
6109       ;; Then we find what group we are supposed to enter.
6110       (set-buffer gnus-group-buffer)
6111       (gnus-group-jump-to-group current-group)
6112       (setq target-group
6113             (or target-group
6114                 (if (eq gnus-keep-same-level 'best)
6115                     (gnus-summary-best-group gnus-newsgroup-name)
6116                   (gnus-summary-search-group backward gnus-keep-same-level))))
6117       (if (not target-group)
6118           ;; There are no further groups, so we return to the group
6119           ;; buffer.
6120           (progn
6121             (gnus-message 5 "Returning to the group buffer")
6122             (setq entered t)
6123             (when (gnus-buffer-live-p current-buffer)
6124               (set-buffer current-buffer)
6125               (gnus-summary-exit))
6126             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6127         ;; We try to enter the target group.
6128         (gnus-group-jump-to-group target-group)
6129         (let ((unreads (gnus-group-group-unread)))
6130           (if (and (or (eq t unreads)
6131                        (and unreads (not (zerop unreads))))
6132                    (gnus-summary-read-group
6133                     target-group nil no-article
6134                     (and (buffer-name current-buffer) current-buffer)
6135                     nil backward))
6136               (setq entered t)
6137             (setq current-group target-group
6138                   target-group nil)))))))
6139
6140 (defun gnus-summary-prev-group (&optional no-article)
6141   "Exit current newsgroup and then select previous unread newsgroup.
6142 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6143   (interactive "P")
6144   (gnus-summary-next-group no-article nil t))
6145
6146 ;; Walking around summary lines.
6147
6148 (defun gnus-summary-first-subject (&optional unread undownloaded)
6149   "Go to the first unread subject.
6150 If UNREAD is non-nil, go to the first unread article.
6151 Returns the article selected or nil if there are no unread articles."
6152   (interactive "P")
6153   (prog1
6154       (cond
6155        ;; Empty summary.
6156        ((null gnus-newsgroup-data)
6157         (gnus-message 3 "No articles in the group")
6158         nil)
6159        ;; Pick the first article.
6160        ((not unread)
6161         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6162         (gnus-data-number (car gnus-newsgroup-data)))
6163        ;; No unread articles.
6164        ((null gnus-newsgroup-unreads)
6165         (gnus-message 3 "No more unread articles")
6166         nil)
6167        ;; Find the first unread article.
6168        (t
6169         (let ((data gnus-newsgroup-data))
6170           (while (and data
6171                       (and (not (and undownloaded
6172                                      (eq gnus-undownloaded-mark
6173                                          (gnus-data-mark (car data)))))
6174                            (not (gnus-data-unread-p (car data)))))
6175             (setq data (cdr data)))
6176           (when data
6177             (goto-char (gnus-data-pos (car data)))
6178             (gnus-data-number (car data))))))
6179     (gnus-summary-position-point)))
6180
6181 (defun gnus-summary-next-subject (n &optional unread dont-display)
6182   "Go to next N'th summary line.
6183 If N is negative, go to the previous N'th subject line.
6184 If UNREAD is non-nil, only unread articles are selected.
6185 The difference between N and the actual number of steps taken is
6186 returned."
6187   (interactive "p")
6188   (let ((backward (< n 0))
6189         (n (abs n)))
6190     (while (and (> n 0)
6191                 (if backward
6192                     (gnus-summary-find-prev unread)
6193                   (gnus-summary-find-next unread)))
6194       (unless (zerop (setq n (1- n)))
6195         (gnus-summary-show-thread)))
6196     (when (/= 0 n)
6197       (gnus-message 7 "No more%s articles"
6198                     (if unread " unread" "")))
6199     (unless dont-display
6200       (gnus-summary-recenter)
6201       (gnus-summary-position-point))
6202     n))
6203
6204 (defun gnus-summary-next-unread-subject (n)
6205   "Go to next N'th unread summary line."
6206   (interactive "p")
6207   (gnus-summary-next-subject n t))
6208
6209 (defun gnus-summary-prev-subject (n &optional unread)
6210   "Go to previous N'th summary line.
6211 If optional argument UNREAD is non-nil, only unread article is selected."
6212   (interactive "p")
6213   (gnus-summary-next-subject (- n) unread))
6214
6215 (defun gnus-summary-prev-unread-subject (n)
6216   "Go to previous N'th unread summary line."
6217   (interactive "p")
6218   (gnus-summary-next-subject (- n) t))
6219
6220 (defun gnus-summary-goto-subject (article &optional force silent)
6221   "Go the subject line of ARTICLE.
6222 If FORCE, also allow jumping to articles not currently shown."
6223   (interactive "nArticle number: ")
6224   (let ((b (point))
6225         (data (gnus-data-find article)))
6226     ;; We read in the article if we have to.
6227     (and (not data)
6228          force
6229          (gnus-summary-insert-subject
6230           article
6231           (if (or (numberp force) (vectorp force)) force)
6232           t)
6233          (setq data (gnus-data-find article)))
6234     (goto-char b)
6235     (if (not data)
6236         (progn
6237           (unless silent
6238             (gnus-message 3 "Can't find article %d" article))
6239           nil)
6240       (let ((pt (gnus-data-pos data)))
6241         (goto-char pt)
6242         (gnus-summary-set-article-display-arrow pt))
6243       (gnus-summary-position-point)
6244       article)))
6245
6246 ;; Walking around summary lines with displaying articles.
6247
6248 (defun gnus-summary-expand-window (&optional arg)
6249   "Make the summary buffer take up the entire Emacs frame.
6250 Given a prefix, will force an `article' buffer configuration."
6251   (interactive "P")
6252   (if arg
6253       (gnus-configure-windows 'article 'force)
6254     (gnus-configure-windows 'summary 'force)))
6255
6256 (defun gnus-summary-display-article (article &optional all-header)
6257   "Display ARTICLE in article buffer."
6258   (when (gnus-buffer-live-p gnus-article-buffer)
6259     (with-current-buffer gnus-article-buffer
6260       (set-buffer-multibyte t)))
6261   (gnus-set-global-variables)
6262   (when (gnus-buffer-live-p gnus-article-buffer)
6263     (with-current-buffer gnus-article-buffer
6264       (setq gnus-article-charset gnus-newsgroup-charset)
6265       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)))
6266   (if (null article)
6267       nil
6268     (prog1
6269         (if gnus-summary-display-article-function
6270             (funcall gnus-summary-display-article-function article all-header)
6271           (gnus-article-prepare article all-header))
6272       (with-current-buffer gnus-article-buffer
6273         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6274              nil))
6275       (gnus-run-hooks 'gnus-select-article-hook)
6276       (when (and gnus-current-article
6277                  (not (zerop gnus-current-article)))
6278         (gnus-summary-goto-subject gnus-current-article))
6279       (gnus-summary-recenter)
6280       (when (and gnus-use-trees gnus-show-threads)
6281         (gnus-possibly-generate-tree article)
6282         (gnus-highlight-selected-tree article))
6283       ;; Successfully display article.
6284       (gnus-article-set-window-start
6285        (cdr (assq article gnus-newsgroup-bookmarks))))))
6286
6287 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6288   "Select the current article.
6289 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6290 non-nil, the article will be re-fetched even if it already present in
6291 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6292 be displayed."
6293   ;; Make sure we are in the summary buffer to work around bbdb bug.
6294   (unless (eq major-mode 'gnus-summary-mode)
6295     (set-buffer gnus-summary-buffer))
6296   (let ((article (or article (gnus-summary-article-number)))
6297         (all-headers (not (not all-headers))) ;Must be T or NIL.
6298         gnus-summary-display-article-function)
6299     (and (not pseudo)
6300          (gnus-summary-article-pseudo-p article)
6301          (error "This is a pseudo-article"))
6302     (save-excursion
6303       (set-buffer gnus-summary-buffer)
6304       (if (or (and gnus-single-article-buffer
6305                    (or (null gnus-current-article)
6306                        (null gnus-article-current)
6307                        (null (get-buffer gnus-article-buffer))
6308                        (not (eq article (cdr gnus-article-current)))
6309                        (not (equal (car gnus-article-current)
6310                                    gnus-newsgroup-name))))
6311               (and (not gnus-single-article-buffer)
6312                    (or (null gnus-current-article)
6313                        (not (eq gnus-current-article article))))
6314               force)
6315           ;; The requested article is different from the current article.
6316           (progn
6317             (gnus-summary-display-article article all-headers)
6318             (when (or all-headers gnus-show-all-headers)
6319               (gnus-article-show-all-headers))
6320             (gnus-article-set-window-start
6321              (cdr (assq article gnus-newsgroup-bookmarks)))
6322             article)
6323         (when (or all-headers gnus-show-all-headers)
6324           (gnus-article-show-all-headers))
6325         'old))))
6326
6327 (defun gnus-summary-force-verify-and-decrypt ()
6328   (interactive)
6329   (let ((mm-verify-option 'known)
6330         (mm-decrypt-option 'known))
6331     (gnus-summary-select-article nil 'force)))
6332
6333 (defun gnus-summary-set-current-mark (&optional current-mark)
6334   "Obsolete function."
6335   nil)
6336
6337 (defun gnus-summary-next-article (&optional unread subject backward push)
6338   "Select the next article.
6339 If UNREAD, only unread articles are selected.
6340 If SUBJECT, only articles with SUBJECT are selected.
6341 If BACKWARD, the previous article is selected instead of the next."
6342   (interactive "P")
6343   (cond
6344    ;; Is there such an article?
6345    ((and (gnus-summary-search-forward unread subject backward)
6346          (or (gnus-summary-display-article (gnus-summary-article-number))
6347              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6348     (gnus-summary-position-point))
6349    ;; If not, we try the first unread, if that is wanted.
6350    ((and subject
6351          gnus-auto-select-same
6352          (gnus-summary-first-unread-article))
6353     (gnus-summary-position-point)
6354     (gnus-message 6 "Wrapped"))
6355    ;; Try to get next/previous article not displayed in this group.
6356    ((and gnus-auto-extend-newsgroup
6357          (not unread) (not subject))
6358     (gnus-summary-goto-article
6359      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6360      nil (count-lines (point-min) (point))))
6361    ;; Go to next/previous group.
6362    (t
6363     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6364       (gnus-summary-jump-to-group gnus-newsgroup-name))
6365     (let ((cmd last-command-char)
6366           (point
6367            (save-excursion
6368              (set-buffer gnus-group-buffer)
6369              (point)))
6370           (group
6371            (if (eq gnus-keep-same-level 'best)
6372                (gnus-summary-best-group gnus-newsgroup-name)
6373              (gnus-summary-search-group backward gnus-keep-same-level))))
6374       ;; For some reason, the group window gets selected.  We change
6375       ;; it back.
6376       (select-window (get-buffer-window (current-buffer)))
6377       ;; Select next unread newsgroup automagically.
6378       (cond
6379        ((or (not gnus-auto-select-next)
6380             (not cmd))
6381         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6382        ((or (eq gnus-auto-select-next 'quietly)
6383             (and (eq gnus-auto-select-next 'slightly-quietly)
6384                  push)
6385             (and (eq gnus-auto-select-next 'almost-quietly)
6386                  (gnus-summary-last-article-p)))
6387         ;; Select quietly.
6388         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6389             (gnus-summary-exit)
6390           (gnus-message 7 "No more%s articles (%s)..."
6391                         (if unread " unread" "")
6392                         (if group (concat "selecting " group)
6393                           "exiting"))
6394           (gnus-summary-next-group nil group backward)))
6395        (t
6396         (when (gnus-key-press-event-p last-input-event)
6397           (gnus-summary-walk-group-buffer
6398            gnus-newsgroup-name cmd unread backward point))))))))
6399
6400 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6401   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6402                       (?\C-p (gnus-group-prev-unread-group 1))))
6403         (cursor-in-echo-area t)
6404         keve key group ended)
6405     (save-excursion
6406       (set-buffer gnus-group-buffer)
6407       (goto-char start)
6408       (setq group
6409             (if (eq gnus-keep-same-level 'best)
6410                 (gnus-summary-best-group gnus-newsgroup-name)
6411               (gnus-summary-search-group backward gnus-keep-same-level))))
6412     (while (not ended)
6413       (gnus-message
6414        5 "No more%s articles%s" (if unread " unread" "")
6415        (if (and group
6416                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6417            (format " (Type %s for %s [%s])"
6418                    (single-key-description cmd) group
6419                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6420          (format " (Type %s to exit %s)"
6421                  (single-key-description cmd)
6422                  gnus-newsgroup-name)))
6423       ;; Confirm auto selection.
6424       (setq key (car (setq keve (gnus-read-event-char))))
6425       (setq ended t)
6426       (cond
6427        ((assq key keystrokes)
6428         (let ((obuf (current-buffer)))
6429           (switch-to-buffer gnus-group-buffer)
6430           (when group
6431             (gnus-group-jump-to-group group))
6432           (eval (cadr (assq key keystrokes)))
6433           (setq group (gnus-group-group-name))
6434           (switch-to-buffer obuf))
6435         (setq ended nil))
6436        ((equal key cmd)
6437         (if (or (not group)
6438                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6439             (gnus-summary-exit)
6440           (gnus-summary-next-group nil group backward)))
6441        (t
6442         (push (cdr keve) unread-command-events))))))
6443
6444 (defun gnus-summary-next-unread-article ()
6445   "Select unread article after current one."
6446   (interactive)
6447   (gnus-summary-next-article
6448    (or (not (eq gnus-summary-goto-unread 'never))
6449        (gnus-summary-last-article-p (gnus-summary-article-number)))
6450    (and gnus-auto-select-same
6451         (gnus-summary-article-subject))))
6452
6453 (defun gnus-summary-prev-article (&optional unread subject)
6454   "Select the article after the current one.
6455 If UNREAD is non-nil, only unread articles are selected."
6456   (interactive "P")
6457   (gnus-summary-next-article unread subject t))
6458
6459 (defun gnus-summary-prev-unread-article ()
6460   "Select unread article before current one."
6461   (interactive)
6462   (gnus-summary-prev-article
6463    (or (not (eq gnus-summary-goto-unread 'never))
6464        (gnus-summary-first-article-p (gnus-summary-article-number)))
6465    (and gnus-auto-select-same
6466         (gnus-summary-article-subject))))
6467
6468 (defun gnus-summary-next-page (&optional lines circular)
6469   "Show next page of the selected article.
6470 If at the end of the current article, select the next article.
6471 LINES says how many lines should be scrolled up.
6472
6473 If CIRCULAR is non-nil, go to the start of the article instead of
6474 selecting the next article when reaching the end of the current
6475 article."
6476   (interactive "P")
6477   (setq gnus-summary-buffer (current-buffer))
6478   (gnus-set-global-variables)
6479   (let ((article (gnus-summary-article-number))
6480         (article-window (get-buffer-window gnus-article-buffer t))
6481         endp)
6482     ;; If the buffer is empty, we have no article.
6483     (unless article
6484       (error "No article to select"))
6485     (gnus-configure-windows 'article)
6486     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6487         (if (and (eq gnus-summary-goto-unread 'never)
6488                  (not (gnus-summary-last-article-p article)))
6489             (gnus-summary-next-article)
6490           (gnus-summary-next-unread-article))
6491       (if (or (null gnus-current-article)
6492               (null gnus-article-current)
6493               (/= article (cdr gnus-article-current))
6494               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6495           ;; Selected subject is different from current article's.
6496           (gnus-summary-display-article article)
6497         (when article-window
6498           (gnus-eval-in-buffer-window gnus-article-buffer
6499             (setq endp (gnus-article-next-page lines)))
6500           (when endp
6501             (cond (circular
6502                    (gnus-summary-beginning-of-article))
6503                   (lines
6504                    (gnus-message 3 "End of message"))
6505                   ((null lines)
6506                    (if (and (eq gnus-summary-goto-unread 'never)
6507                             (not (gnus-summary-last-article-p article)))
6508                        (gnus-summary-next-article)
6509                      (gnus-summary-next-unread-article))))))))
6510     (gnus-summary-recenter)
6511     (gnus-summary-position-point)))
6512
6513 (defun gnus-summary-prev-page (&optional lines move)
6514   "Show previous page of selected article.
6515 Argument LINES specifies lines to be scrolled down.
6516 If MOVE, move to the previous unread article if point is at
6517 the beginning of the buffer."
6518   (interactive "P")
6519   (let ((article (gnus-summary-article-number))
6520         (article-window (get-buffer-window gnus-article-buffer t))
6521         endp)
6522     (gnus-configure-windows 'article)
6523     (if (or (null gnus-current-article)
6524             (null gnus-article-current)
6525             (/= article (cdr gnus-article-current))
6526             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6527         ;; Selected subject is different from current article's.
6528         (gnus-summary-display-article article)
6529       (gnus-summary-recenter)
6530       (when article-window
6531         (gnus-eval-in-buffer-window gnus-article-buffer
6532           (setq endp (gnus-article-prev-page lines)))
6533         (when (and move endp)
6534           (cond (lines
6535                  (gnus-message 3 "Beginning of message"))
6536                 ((null lines)
6537                  (if (and (eq gnus-summary-goto-unread 'never)
6538                           (not (gnus-summary-first-article-p article)))
6539                      (gnus-summary-prev-article)
6540                    (gnus-summary-prev-unread-article))))))))
6541   (gnus-summary-position-point))
6542
6543 (defun gnus-summary-prev-page-or-article (&optional lines)
6544   "Show previous page of selected article.
6545 Argument LINES specifies lines to be scrolled down.
6546 If at the beginning of the article, go to the next article."
6547   (interactive "P")
6548   (gnus-summary-prev-page lines t))
6549
6550 (defun gnus-summary-scroll-up (lines)
6551   "Scroll up (or down) one line current article.
6552 Argument LINES specifies lines to be scrolled up (or down if negative)."
6553   (interactive "p")
6554   (gnus-configure-windows 'article)
6555   (gnus-summary-show-thread)
6556   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6557     (gnus-eval-in-buffer-window gnus-article-buffer
6558       (cond ((> lines 0)
6559              (when (gnus-article-next-page lines)
6560                (gnus-message 3 "End of message")))
6561             ((< lines 0)
6562              (gnus-article-prev-page (- lines))))))
6563   (gnus-summary-recenter)
6564   (gnus-summary-position-point))
6565
6566 (defun gnus-summary-scroll-down (lines)
6567   "Scroll down (or up) one line current article.
6568 Argument LINES specifies lines to be scrolled down (or up if negative)."
6569   (interactive "p")
6570   (gnus-summary-scroll-up (- lines)))
6571
6572 (defun gnus-summary-next-same-subject ()
6573   "Select next article which has the same subject as current one."
6574   (interactive)
6575   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6576
6577 (defun gnus-summary-prev-same-subject ()
6578   "Select previous article which has the same subject as current one."
6579   (interactive)
6580   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6581
6582 (defun gnus-summary-next-unread-same-subject ()
6583   "Select next unread article which has the same subject as current one."
6584   (interactive)
6585   (gnus-summary-next-article t (gnus-summary-article-subject)))
6586
6587 (defun gnus-summary-prev-unread-same-subject ()
6588   "Select previous unread article which has the same subject as current one."
6589   (interactive)
6590   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6591
6592 (defun gnus-summary-first-unread-article ()
6593   "Select the first unread article.
6594 Return nil if there are no unread articles."
6595   (interactive)
6596   (prog1
6597       (when (gnus-summary-first-subject t)
6598         (gnus-summary-show-thread)
6599         (gnus-summary-first-subject t)
6600         (gnus-summary-display-article (gnus-summary-article-number)))
6601     (gnus-summary-position-point)))
6602
6603 (defun gnus-summary-first-unread-subject ()
6604   "Place the point on the subject line of the first unread article.
6605 Return nil if there are no unread articles."
6606   (interactive)
6607   (prog1
6608       (when (gnus-summary-first-subject t)
6609         (gnus-summary-show-thread)
6610         (gnus-summary-first-subject t))
6611     (gnus-summary-position-point)))
6612
6613 (defun gnus-summary-first-article ()
6614   "Select the first article.
6615 Return nil if there are no articles."
6616   (interactive)
6617   (prog1
6618       (when (gnus-summary-first-subject)
6619         (gnus-summary-show-thread)
6620         (gnus-summary-first-subject)
6621         (gnus-summary-display-article (gnus-summary-article-number)))
6622     (gnus-summary-position-point)))
6623
6624 (defun gnus-summary-best-unread-article ()
6625   "Select the unread article with the highest score."
6626   (interactive)
6627   (let ((best -1000000)
6628         (data gnus-newsgroup-data)
6629         article score)
6630     (while data
6631       (and (gnus-data-unread-p (car data))
6632            (> (setq score
6633                     (gnus-summary-article-score (gnus-data-number (car data))))
6634               best)
6635            (setq best score
6636                  article (gnus-data-number (car data))))
6637       (setq data (cdr data)))
6638     (prog1
6639         (if article
6640             (gnus-summary-goto-article article)
6641           (error "No unread articles"))
6642       (gnus-summary-position-point))))
6643
6644 (defun gnus-summary-last-subject ()
6645   "Go to the last displayed subject line in the group."
6646   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6647     (when article
6648       (gnus-summary-goto-subject article))))
6649
6650 (defun gnus-summary-goto-article (article &optional all-headers force)
6651   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6652 If ALL-HEADERS is non-nil, no header lines are hidden.
6653 If FORCE, go to the article even if it isn't displayed.  If FORCE
6654 is a number, it is the line the article is to be displayed on."
6655   (interactive
6656    (list
6657     (completing-read
6658      "Article number or Message-ID: "
6659      (mapcar (lambda (number) (list (int-to-string number)))
6660              gnus-newsgroup-limit))
6661     current-prefix-arg
6662     t))
6663   (prog1
6664       (if (and (stringp article)
6665                (string-match "@" article))
6666           (gnus-summary-refer-article article)
6667         (when (stringp article)
6668           (setq article (string-to-number article)))
6669         (if (gnus-summary-goto-subject article force)
6670             (gnus-summary-display-article article all-headers)
6671           (gnus-message 4 "Couldn't go to article %s" article) nil))
6672     (gnus-summary-position-point)))
6673
6674 (defun gnus-summary-goto-last-article ()
6675   "Go to the previously read article."
6676   (interactive)
6677   (prog1
6678       (when gnus-last-article
6679         (gnus-summary-goto-article gnus-last-article nil t))
6680     (gnus-summary-position-point)))
6681
6682 (defun gnus-summary-pop-article (number)
6683   "Pop one article off the history and go to the previous.
6684 NUMBER articles will be popped off."
6685   (interactive "p")
6686   (let (to)
6687     (setq gnus-newsgroup-history
6688           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6689     (if to
6690         (gnus-summary-goto-article (car to) nil t)
6691       (error "Article history empty")))
6692   (gnus-summary-position-point))
6693
6694 ;; Summary commands and functions for limiting the summary buffer.
6695
6696 (defun gnus-summary-limit-to-articles (n)
6697   "Limit the summary buffer to the next N articles.
6698 If not given a prefix, use the process marked articles instead."
6699   (interactive "P")
6700   (prog1
6701       (let ((articles (gnus-summary-work-articles n)))
6702         (setq gnus-newsgroup-processable nil)
6703         (gnus-summary-limit articles))
6704     (gnus-summary-position-point)))
6705
6706 (defun gnus-summary-pop-limit (&optional total)
6707   "Restore the previous limit.
6708 If given a prefix, remove all limits."
6709   (interactive "P")
6710   (when total
6711     (setq gnus-newsgroup-limits
6712           (list (mapcar (lambda (h) (mail-header-number h))
6713                         gnus-newsgroup-headers))))
6714   (unless gnus-newsgroup-limits
6715     (error "No limit to pop"))
6716   (prog1
6717       (gnus-summary-limit nil 'pop)
6718     (gnus-summary-position-point)))
6719
6720 (defun gnus-summary-limit-to-subject (subject &optional header)
6721   "Limit the summary buffer to articles that have subjects that match a regexp."
6722   (interactive "sLimit to subject (regexp): ")
6723   (unless header
6724     (setq header "subject"))
6725   (when (not (equal "" subject))
6726     (prog1
6727         (let ((articles (gnus-summary-find-matching
6728                          (or header "subject") subject 'all)))
6729           (unless articles
6730             (error "Found no matches for \"%s\"" subject))
6731           (gnus-summary-limit articles))
6732       (gnus-summary-position-point))))
6733
6734 (defun gnus-summary-limit-to-author (from)
6735   "Limit the summary buffer to articles that have authors that match a regexp."
6736   (interactive "sLimit to author (regexp): ")
6737   (gnus-summary-limit-to-subject from "from"))
6738
6739 (defun gnus-summary-limit-to-age (age &optional younger-p)
6740   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6741 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6742 articles that are younger than AGE days."
6743   (interactive
6744    (let ((younger current-prefix-arg)
6745          (days-got nil)
6746          days)
6747      (while (not days-got)
6748        (setq days (if younger
6749                       (read-string "Limit to articles within (in days): ")
6750                     (read-string "Limit to articles older than (in days): ")))
6751        (when (> (length days) 0)
6752          (setq days (read days)))
6753        (if (numberp days)
6754            (setq days-got t)
6755          (message "Please enter a number.")
6756          (sleep-for 1)))
6757      (list days younger)))
6758   (prog1
6759       (let ((data gnus-newsgroup-data)
6760             (cutoff (days-to-time age))
6761             articles d date is-younger)
6762         (while (setq d (pop data))
6763           (when (and (vectorp (gnus-data-header d))
6764                      (setq date (mail-header-date (gnus-data-header d))))
6765             (setq is-younger (time-less-p
6766                               (time-since (condition-case ()
6767                                               (date-to-time date)
6768                                             (error '(0 0))))
6769                               cutoff))
6770             (when (if younger-p
6771                       is-younger
6772                     (not is-younger))
6773               (push (gnus-data-number d) articles))))
6774         (gnus-summary-limit (nreverse articles)))
6775     (gnus-summary-position-point)))
6776
6777 (defun gnus-summary-limit-to-extra (header regexp)
6778   "Limit the summary buffer to articles that match an 'extra' header."
6779   (interactive
6780    (let ((header
6781           (intern
6782            (gnus-completing-read
6783             (symbol-name (car gnus-extra-headers))
6784             "Limit extra header:"
6785             (mapcar (lambda (x)
6786                       (cons (symbol-name x) x))
6787                     gnus-extra-headers)
6788             nil
6789             t))))
6790      (list header
6791            (read-string (format "Limit to header %s (regexp): " header)))))
6792   (when (not (equal "" regexp))
6793     (prog1
6794         (let ((articles (gnus-summary-find-matching
6795                          (cons 'extra header) regexp 'all)))
6796           (unless articles
6797             (error "Found no matches for \"%s\"" regexp))
6798           (gnus-summary-limit articles))
6799       (gnus-summary-position-point))))
6800
6801 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6802 (make-obsolete
6803  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6804
6805 (defun gnus-summary-limit-to-unread (&optional all)
6806   "Limit the summary buffer to articles that are not marked as read.
6807 If ALL is non-nil, limit strictly to unread articles."
6808   (interactive "P")
6809   (if all
6810       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6811     (gnus-summary-limit-to-marks
6812      ;; Concat all the marks that say that an article is read and have
6813      ;; those removed.
6814      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6815            gnus-killed-mark gnus-kill-file-mark
6816            gnus-low-score-mark gnus-expirable-mark
6817            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6818            gnus-duplicate-mark gnus-souped-mark)
6819      'reverse)))
6820
6821 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6822 (make-obsolete 'gnus-summary-delete-marked-with
6823                'gnus-summary-limit-exlude-marks)
6824
6825 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6826   "Exclude articles that are marked with MARKS (e.g. \"DK\").
6827 If REVERSE, limit the summary buffer to articles that are marked
6828 with MARKS.  MARKS can either be a string of marks or a list of marks.
6829 Returns how many articles were removed."
6830   (interactive "sMarks: ")
6831   (gnus-summary-limit-to-marks marks t))
6832
6833 (defun gnus-summary-limit-to-marks (marks &optional reverse)
6834   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6835 If REVERSE (the prefix), limit the summary buffer to articles that are
6836 not marked with MARKS.  MARKS can either be a string of marks or a
6837 list of marks.
6838 Returns how many articles were removed."
6839   (interactive "sMarks: \nP")
6840   (prog1
6841       (let ((data gnus-newsgroup-data)
6842             (marks (if (listp marks) marks
6843                      (append marks nil))) ; Transform to list.
6844             articles)
6845         (while data
6846           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6847                   (memq (gnus-data-mark (car data)) marks))
6848             (push (gnus-data-number (car data)) articles))
6849           (setq data (cdr data)))
6850         (gnus-summary-limit articles))
6851     (gnus-summary-position-point)))
6852
6853 (defun gnus-summary-limit-to-score (&optional score)
6854   "Limit to articles with score at or above SCORE."
6855   (interactive "P")
6856   (setq score (if score
6857                   (prefix-numeric-value score)
6858                 (or gnus-summary-default-score 0)))
6859   (let ((data gnus-newsgroup-data)
6860         articles)
6861     (while data
6862       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6863                 score)
6864         (push (gnus-data-number (car data)) articles))
6865       (setq data (cdr data)))
6866     (prog1
6867         (gnus-summary-limit articles)
6868       (gnus-summary-position-point))))
6869
6870 (defun gnus-summary-limit-include-thread (id)
6871   "Display all the hidden articles that is in the thread with ID in it.
6872 When called interactively, ID is the Message-ID of the current
6873 article."
6874   (interactive (list (mail-header-id (gnus-summary-article-header))))
6875   (let ((articles (gnus-articles-in-thread
6876                    (gnus-id-to-thread (gnus-root-id id)))))
6877     (prog1
6878         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6879       (gnus-summary-limit-include-matching-articles
6880        "subject"
6881        (regexp-quote (gnus-simplify-subject-re
6882                       (mail-header-subject (gnus-id-to-header id)))))
6883       (gnus-summary-position-point))))
6884
6885 (defun gnus-summary-limit-include-matching-articles (header regexp)
6886   "Display all the hidden articles that have HEADERs that match REGEXP."
6887   (interactive (list (read-string "Match on header: ")
6888                      (read-string "Regexp: ")))
6889   (let ((articles (gnus-find-matching-articles header regexp)))
6890     (prog1
6891         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6892       (gnus-summary-position-point))))
6893
6894 (defun gnus-summary-limit-include-dormant ()
6895   "Display all the hidden articles that are marked as dormant.
6896 Note that this command only works on a subset of the articles currently
6897 fetched for this group."
6898   (interactive)
6899   (unless gnus-newsgroup-dormant
6900     (error "There are no dormant articles in this group"))
6901   (prog1
6902       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
6903     (gnus-summary-position-point)))
6904
6905 (defun gnus-summary-limit-exclude-dormant ()
6906   "Hide all dormant articles."
6907   (interactive)
6908   (prog1
6909       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
6910     (gnus-summary-position-point)))
6911
6912 (defun gnus-summary-limit-exclude-childless-dormant ()
6913   "Hide all dormant articles that have no children."
6914   (interactive)
6915   (let ((data (gnus-data-list t))
6916         articles d children)
6917     ;; Find all articles that are either not dormant or have
6918     ;; children.
6919     (while (setq d (pop data))
6920       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
6921                 (and (setq children
6922                            (gnus-article-children (gnus-data-number d)))
6923                      (let (found)
6924                        (while children
6925                          (when (memq (car children) articles)
6926                            (setq children nil
6927                                  found t))
6928                          (pop children))
6929                        found)))
6930         (push (gnus-data-number d) articles)))
6931     ;; Do the limiting.
6932     (prog1
6933         (gnus-summary-limit articles)
6934       (gnus-summary-position-point))))
6935
6936 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
6937   "Mark all unread excluded articles as read.
6938 If ALL, mark even excluded ticked and dormants as read."
6939   (interactive "P")
6940   (let ((articles (gnus-sorted-complement
6941                    (sort
6942                     (mapcar (lambda (h) (mail-header-number h))
6943                             gnus-newsgroup-headers)
6944                     '<)
6945                    (sort gnus-newsgroup-limit '<)))
6946         article)
6947     (setq gnus-newsgroup-unreads
6948           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
6949     (if all
6950         (setq gnus-newsgroup-dormant nil
6951               gnus-newsgroup-marked nil
6952               gnus-newsgroup-reads
6953               (nconc
6954                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
6955                gnus-newsgroup-reads))
6956       (while (setq article (pop articles))
6957         (unless (or (memq article gnus-newsgroup-dormant)
6958                     (memq article gnus-newsgroup-marked))
6959           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
6960
6961 (defun gnus-summary-limit (articles &optional pop)
6962   (if pop
6963       ;; We pop the previous limit off the stack and use that.
6964       (setq articles (car gnus-newsgroup-limits)
6965             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
6966     ;; We use the new limit, so we push the old limit on the stack.
6967     (push gnus-newsgroup-limit gnus-newsgroup-limits))
6968   ;; Set the limit.
6969   (setq gnus-newsgroup-limit articles)
6970   (let ((total (length gnus-newsgroup-data))
6971         (data (gnus-data-find-list (gnus-summary-article-number)))
6972         (gnus-summary-mark-below nil)   ; Inhibit this.
6973         found)
6974     ;; This will do all the work of generating the new summary buffer
6975     ;; according to the new limit.
6976     (gnus-summary-prepare)
6977     ;; Hide any threads, possibly.
6978     (and gnus-show-threads
6979          gnus-thread-hide-subtree
6980          (gnus-summary-hide-all-threads))
6981     ;; Try to return to the article you were at, or one in the
6982     ;; neighborhood.
6983     (when data
6984       ;; We try to find some article after the current one.
6985       (while data
6986         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
6987           (setq data nil
6988                 found t))
6989         (setq data (cdr data))))
6990     (unless found
6991       ;; If there is no data, that means that we were after the last
6992       ;; article.  The same goes when we can't find any articles
6993       ;; after the current one.
6994       (goto-char (point-max))
6995       (gnus-summary-find-prev))
6996     (gnus-set-mode-line 'summary)
6997     ;; We return how many articles were removed from the summary
6998     ;; buffer as a result of the new limit.
6999     (- total (length gnus-newsgroup-data))))
7000
7001 (defsubst gnus-invisible-cut-children (threads)
7002   (let ((num 0))
7003     (while threads
7004       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7005         (incf num))
7006       (pop threads))
7007     (< num 2)))
7008
7009 (defsubst gnus-cut-thread (thread)
7010   "Go forwards in the thread until we find an article that we want to display."
7011   (when (or (eq gnus-fetch-old-headers 'some)
7012             (eq gnus-fetch-old-headers 'invisible)
7013             (numberp gnus-fetch-old-headers)
7014             (eq gnus-build-sparse-threads 'some)
7015             (eq gnus-build-sparse-threads 'more))
7016     ;; Deal with old-fetched headers and sparse threads.
7017     (while (and
7018             thread
7019             (or
7020              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7021              (gnus-summary-article-ancient-p
7022               (mail-header-number (car thread))))
7023             (if (or (<= (length (cdr thread)) 1)
7024                     (eq gnus-fetch-old-headers 'invisible))
7025                 (setq gnus-newsgroup-limit
7026                       (delq (mail-header-number (car thread))
7027                             gnus-newsgroup-limit)
7028                       thread (cadr thread))
7029               (when (gnus-invisible-cut-children (cdr thread))
7030                 (let ((th (cdr thread)))
7031                   (while th
7032                     (if (memq (mail-header-number (caar th))
7033                               gnus-newsgroup-limit)
7034                         (setq thread (car th)
7035                               th nil)
7036                       (setq th (cdr th))))))))))
7037   thread)
7038
7039 (defun gnus-cut-threads (threads)
7040   "Cut off all uninteresting articles from the beginning of threads."
7041   (when (or (eq gnus-fetch-old-headers 'some)
7042             (eq gnus-fetch-old-headers 'invisible)
7043             (numberp gnus-fetch-old-headers)
7044             (eq gnus-build-sparse-threads 'some)
7045             (eq gnus-build-sparse-threads 'more))
7046     (let ((th threads))
7047       (while th
7048         (setcar th (gnus-cut-thread (car th)))
7049         (setq th (cdr th)))))
7050   ;; Remove nixed out threads.
7051   (delq nil threads))
7052
7053 (defun gnus-summary-initial-limit (&optional show-if-empty)
7054   "Figure out what the initial limit is supposed to be on group entry.
7055 This entails weeding out unwanted dormants, low-scored articles,
7056 fetch-old-headers verbiage, and so on."
7057   ;; Most groups have nothing to remove.
7058   (if (or gnus-inhibit-limiting
7059           (and (null gnus-newsgroup-dormant)
7060                (not (eq gnus-fetch-old-headers 'some))
7061                (not (numberp gnus-fetch-old-headers))
7062                (not (eq gnus-fetch-old-headers 'invisible))
7063                (null gnus-summary-expunge-below)
7064                (not (eq gnus-build-sparse-threads 'some))
7065                (not (eq gnus-build-sparse-threads 'more))
7066                (null gnus-thread-expunge-below)
7067                (not gnus-use-nocem)))
7068       ()                                ; Do nothing.
7069     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7070     (setq gnus-newsgroup-limit nil)
7071     (mapatoms
7072      (lambda (node)
7073        (unless (car (symbol-value node))
7074          ;; These threads have no parents -- they are roots.
7075          (let ((nodes (cdr (symbol-value node)))
7076                thread)
7077            (while nodes
7078              (if (and gnus-thread-expunge-below
7079                       (< (gnus-thread-total-score (car nodes))
7080                          gnus-thread-expunge-below))
7081                  (gnus-expunge-thread (pop nodes))
7082                (setq thread (pop nodes))
7083                (gnus-summary-limit-children thread))))))
7084      gnus-newsgroup-dependencies)
7085     ;; If this limitation resulted in an empty group, we might
7086     ;; pop the previous limit and use it instead.
7087     (when (and (not gnus-newsgroup-limit)
7088                show-if-empty)
7089       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7090     gnus-newsgroup-limit))
7091
7092 (defun gnus-summary-limit-children (thread)
7093   "Return 1 if this subthread is visible and 0 if it is not."
7094   ;; First we get the number of visible children to this thread.  This
7095   ;; is done by recursing down the thread using this function, so this
7096   ;; will really go down to a leaf article first, before slowly
7097   ;; working its way up towards the root.
7098   (when thread
7099     (let ((children
7100            (if (cdr thread)
7101                (apply '+ (mapcar 'gnus-summary-limit-children
7102                                  (cdr thread)))
7103              0))
7104           (number (mail-header-number (car thread)))
7105           score)
7106       (if (and
7107            (not (memq number gnus-newsgroup-marked))
7108            (or
7109             ;; If this article is dormant and has absolutely no visible
7110             ;; children, then this article isn't visible.
7111             (and (memq number gnus-newsgroup-dormant)
7112                  (zerop children))
7113             ;; If this is "fetch-old-headered" and there is no
7114             ;; visible children, then we don't want this article.
7115             (and (or (eq gnus-fetch-old-headers 'some)
7116                      (numberp gnus-fetch-old-headers))
7117                  (gnus-summary-article-ancient-p number)
7118                  (zerop children))
7119             ;; If this is "fetch-old-headered" and `invisible', then
7120             ;; we don't want this article.
7121             (and (eq gnus-fetch-old-headers 'invisible)
7122                  (gnus-summary-article-ancient-p number))
7123             ;; If this is a sparsely inserted article with no children,
7124             ;; we don't want it.
7125             (and (eq gnus-build-sparse-threads 'some)
7126                  (gnus-summary-article-sparse-p number)
7127                  (zerop children))
7128             ;; If we use expunging, and this article is really
7129             ;; low-scored, then we don't want this article.
7130             (when (and gnus-summary-expunge-below
7131                        (< (setq score
7132                                 (or (cdr (assq number gnus-newsgroup-scored))
7133                                     gnus-summary-default-score))
7134                           gnus-summary-expunge-below))
7135               ;; We increase the expunge-tally here, but that has
7136               ;; nothing to do with the limits, really.
7137               (incf gnus-newsgroup-expunged-tally)
7138               ;; We also mark as read here, if that's wanted.
7139               (when (and gnus-summary-mark-below
7140                          (< score gnus-summary-mark-below))
7141                 (setq gnus-newsgroup-unreads
7142                       (delq number gnus-newsgroup-unreads))
7143                 (if gnus-newsgroup-auto-expire
7144                     (push number gnus-newsgroup-expirable)
7145                   (push (cons number gnus-low-score-mark)
7146                         gnus-newsgroup-reads)))
7147               t)
7148             ;; Check NoCeM things.
7149             (if (and gnus-use-nocem
7150                      (gnus-nocem-unwanted-article-p
7151                       (mail-header-id (car thread))))
7152                 (progn
7153                   (setq gnus-newsgroup-unreads
7154                         (delq number gnus-newsgroup-unreads))
7155                   t))))
7156           ;; Nope, invisible article.
7157           0
7158         ;; Ok, this article is to be visible, so we add it to the limit
7159         ;; and return 1.
7160         (push number gnus-newsgroup-limit)
7161         1))))
7162
7163 (defun gnus-expunge-thread (thread)
7164   "Mark all articles in THREAD as read."
7165   (let* ((number (mail-header-number (car thread))))
7166     (incf gnus-newsgroup-expunged-tally)
7167     ;; We also mark as read here, if that's wanted.
7168     (setq gnus-newsgroup-unreads
7169           (delq number gnus-newsgroup-unreads))
7170     (if gnus-newsgroup-auto-expire
7171         (push number gnus-newsgroup-expirable)
7172       (push (cons number gnus-low-score-mark)
7173             gnus-newsgroup-reads)))
7174   ;; Go recursively through all subthreads.
7175   (mapcar 'gnus-expunge-thread (cdr thread)))
7176
7177 ;; Summary article oriented commands
7178
7179 (defun gnus-summary-refer-parent-article (n)
7180   "Refer parent article N times.
7181 If N is negative, go to ancestor -N instead.
7182 The difference between N and the number of articles fetched is returned."
7183   (interactive "p")
7184   (let ((skip 1)
7185         error header ref)
7186     (when (not (natnump n))
7187       (setq skip (abs n)
7188             n 1))
7189     (while (and (> n 0)
7190                 (not error))
7191       (setq header (gnus-summary-article-header))
7192       (if (and (eq (mail-header-number header)
7193                    (cdr gnus-article-current))
7194                (equal gnus-newsgroup-name
7195                       (car gnus-article-current)))
7196           ;; If we try to find the parent of the currently
7197           ;; displayed article, then we take a look at the actual
7198           ;; References header, since this is slightly more
7199           ;; reliable than the References field we got from the
7200           ;; server.
7201           (save-excursion
7202             (set-buffer gnus-original-article-buffer)
7203             (nnheader-narrow-to-headers)
7204             (unless (setq ref (message-fetch-field "references"))
7205               (setq ref (message-fetch-field "in-reply-to")))
7206             (widen))
7207         (setq ref
7208               ;; It's not the current article, so we take a bet on
7209               ;; the value we got from the server.
7210               (mail-header-references header)))
7211       (if (and ref
7212                (not (equal ref "")))
7213           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7214             (gnus-message 1 "Couldn't find parent"))
7215         (gnus-message 1 "No references in article %d"
7216                       (gnus-summary-article-number))
7217         (setq error t))
7218       (decf n))
7219     (gnus-summary-position-point)
7220     n))
7221
7222 (defun gnus-summary-refer-references ()
7223   "Fetch all articles mentioned in the References header.
7224 Return the number of articles fetched."
7225   (interactive)
7226   (let ((ref (mail-header-references (gnus-summary-article-header)))
7227         (current (gnus-summary-article-number))
7228         (n 0))
7229     (if (or (not ref)
7230             (equal ref ""))
7231         (error "No References in the current article")
7232       ;; For each Message-ID in the References header...
7233       (while (string-match "<[^>]*>" ref)
7234         (incf n)
7235         ;; ... fetch that article.
7236         (gnus-summary-refer-article
7237          (prog1 (match-string 0 ref)
7238            (setq ref (substring ref (match-end 0))))))
7239       (gnus-summary-goto-subject current)
7240       (gnus-summary-position-point)
7241       n)))
7242
7243 (defun gnus-summary-refer-thread (&optional limit)
7244   "Fetch all articles in the current thread.
7245 If LIMIT (the numerical prefix), fetch that many old headers instead
7246 of what's specified by the `gnus-refer-thread-limit' variable."
7247   (interactive "P")
7248   (let ((id (mail-header-id (gnus-summary-article-header)))
7249         (limit (if limit (prefix-numeric-value limit)
7250                  gnus-refer-thread-limit)))
7251     ;; We want to fetch LIMIT *old* headers, but we also have to
7252     ;; re-fetch all the headers in the current buffer, because many of
7253     ;; them may be undisplayed.  So we adjust LIMIT.
7254     (when (numberp limit)
7255       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7256     (unless (eq gnus-fetch-old-headers 'invisible)
7257       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7258       ;; Retrieve the headers and read them in.
7259       (if (eq (gnus-retrieve-headers
7260                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7261               'nov)
7262           (gnus-build-all-threads)
7263         (error "Can't fetch thread from backends that don't support NOV"))
7264       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7265     (gnus-summary-limit-include-thread id)))
7266
7267 (defun gnus-summary-refer-article (message-id)
7268   "Fetch an article specified by MESSAGE-ID."
7269   (interactive "sMessage-ID: ")
7270   (when (and (stringp message-id)
7271              (not (zerop (length message-id))))
7272     ;; Construct the correct Message-ID if necessary.
7273     ;; Suggested by tale@pawl.rpi.edu.
7274     (unless (string-match "^<" message-id)
7275       (setq message-id (concat "<" message-id)))
7276     (unless (string-match ">$" message-id)
7277       (setq message-id (concat message-id ">")))
7278     (let* ((header (gnus-id-to-header message-id))
7279            (sparse (and header
7280                         (gnus-summary-article-sparse-p
7281                          (mail-header-number header))
7282                         (memq (mail-header-number header)
7283                               gnus-newsgroup-limit)))
7284            number)
7285       (cond
7286        ;; If the article is present in the buffer we just go to it.
7287        ((and header
7288              (or (not (gnus-summary-article-sparse-p
7289                        (mail-header-number header)))
7290                  sparse))
7291         (prog1
7292             (gnus-summary-goto-article
7293              (mail-header-number header) nil t)
7294           (when sparse
7295             (gnus-summary-update-article (mail-header-number header)))))
7296        (t
7297         ;; We fetch the article.
7298         (catch 'found
7299           (dolist (gnus-override-method (gnus-refer-article-methods))
7300             (gnus-check-server gnus-override-method)
7301             ;; Fetch the header, and display the article.
7302             (when (setq number (gnus-summary-insert-subject message-id))
7303               (gnus-summary-select-article nil nil nil number)
7304               (throw 'found t)))
7305           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7306
7307 (defun gnus-refer-article-methods ()
7308   "Return a list of referrable methods."
7309   (cond
7310    ;; No method, so we default to current and native.
7311    ((null gnus-refer-article-method)
7312     (list gnus-current-select-method gnus-select-method))
7313    ;; Current.
7314    ((eq 'current gnus-refer-article-method)
7315     (list gnus-current-select-method))
7316    ;; List of select methods.
7317    ((not (and (symbolp (car gnus-refer-article-method))
7318               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7319     (let (out)
7320       (dolist (method gnus-refer-article-method)
7321         (push (if (eq 'current method)
7322                   gnus-current-select-method
7323                 method)
7324               out))
7325       (nreverse out)))
7326    ;; One single select method.
7327    (t
7328     (list gnus-refer-article-method))))
7329
7330 (defun gnus-summary-edit-parameters ()
7331   "Edit the group parameters of the current group."
7332   (interactive)
7333   (gnus-group-edit-group gnus-newsgroup-name 'params))
7334
7335 (defun gnus-summary-customize-parameters ()
7336   "Customize the group parameters of the current group."
7337   (interactive)
7338   (gnus-group-customize gnus-newsgroup-name))
7339
7340 (defun gnus-summary-enter-digest-group (&optional force)
7341   "Enter an nndoc group based on the current article.
7342 If FORCE, force a digest interpretation.  If not, try
7343 to guess what the document format is."
7344   (interactive "P")
7345   (let ((conf gnus-current-window-configuration))
7346     (save-excursion
7347       (gnus-summary-select-article))
7348     (setq gnus-current-window-configuration conf)
7349     (let* ((name (format "%s-%d"
7350                          (gnus-group-prefixed-name
7351                           gnus-newsgroup-name (list 'nndoc ""))
7352                          (save-excursion
7353                            (set-buffer gnus-summary-buffer)
7354                            gnus-current-article)))
7355            (ogroup gnus-newsgroup-name)
7356            (params (append (gnus-info-params (gnus-get-info ogroup))
7357                            (list (cons 'to-group ogroup))
7358                            (list (cons 'save-article-group ogroup))))
7359            (case-fold-search t)
7360            (buf (current-buffer))
7361            dig to-address)
7362       (save-excursion
7363         (set-buffer gnus-original-article-buffer)
7364         ;; Have the digest group inherit the main mail address of
7365         ;; the parent article.
7366         (when (setq to-address (or (message-fetch-field "reply-to")
7367                                    (message-fetch-field "from")))
7368           (setq params (append
7369                         (list (cons 'to-address
7370                                     (funcall gnus-decode-encoded-word-function
7371                                              to-address))))))
7372         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7373         (insert-buffer-substring gnus-original-article-buffer)
7374         ;; Remove lines that may lead nndoc to misinterpret the
7375         ;; document type.
7376         (narrow-to-region
7377          (goto-char (point-min))
7378          (or (search-forward "\n\n" nil t) (point)))
7379         (goto-char (point-min))
7380         (delete-matching-lines "^Path:\\|^From ")
7381         (widen))
7382       (unwind-protect
7383           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7384                     (gnus-newsgroup-ephemeral-ignored-charsets
7385                      gnus-newsgroup-ignored-charsets))
7386                 (gnus-group-read-ephemeral-group
7387                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7388                               (nndoc-article-type
7389                                ,(if force 'mbox 'guess))) t))
7390               ;; Make all postings to this group go to the parent group.
7391               (nconc (gnus-info-params (gnus-get-info name))
7392                      params)
7393             ;; Couldn't select this doc group.
7394             (switch-to-buffer buf)
7395             (gnus-set-global-variables)
7396             (gnus-configure-windows 'summary)
7397             (gnus-message 3 "Article couldn't be entered?"))
7398         (kill-buffer dig)))))
7399
7400 (defun gnus-summary-read-document (n)
7401   "Open a new group based on the current article(s).
7402 This will allow you to read digests and other similar
7403 documents as newsgroups.
7404 Obeys the standard process/prefix convention."
7405   (interactive "P")
7406   (let* ((articles (gnus-summary-work-articles n))
7407          (ogroup gnus-newsgroup-name)
7408          (params (append (gnus-info-params (gnus-get-info ogroup))
7409                          (list (cons 'to-group ogroup))))
7410          article group egroup groups vgroup)
7411     (while (setq article (pop articles))
7412       (setq group (format "%s-%d" gnus-newsgroup-name article))
7413       (gnus-summary-remove-process-mark article)
7414       (when (gnus-summary-display-article article)
7415         (save-excursion
7416           (with-temp-buffer
7417             (insert-buffer-substring gnus-original-article-buffer)
7418             ;; Remove some headers that may lead nndoc to make
7419             ;; the wrong guess.
7420             (message-narrow-to-head)
7421             (goto-char (point-min))
7422             (delete-matching-lines "^\\(Path\\):\\|^From ")
7423             (widen)
7424             (if (setq egroup
7425                       (gnus-group-read-ephemeral-group
7426                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7427                                      (nndoc-article-type guess))
7428                        t nil t))
7429                 (progn
7430                   ;; Make all postings to this group go to the parent group.
7431                   (nconc (gnus-info-params (gnus-get-info egroup))
7432                          params)
7433                   (push egroup groups))
7434               ;; Couldn't select this doc group.
7435               (gnus-error 3 "Article couldn't be entered"))))))
7436     ;; Now we have selected all the documents.
7437     (cond
7438      ((not groups)
7439       (error "None of the articles could be interpreted as documents"))
7440      ((gnus-group-read-ephemeral-group
7441        (setq vgroup (format
7442                      "nnvirtual:%s-%s" gnus-newsgroup-name
7443                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7444        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7445        t
7446        (cons (current-buffer) 'summary)))
7447      (t
7448       (error "Couldn't select virtual nndoc group")))))
7449
7450 (defun gnus-summary-isearch-article (&optional regexp-p)
7451   "Do incremental search forward on the current article.
7452 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7453   (interactive "P")
7454   (let* ((gnus-inhibit-treatment t)
7455          (old (gnus-summary-select-article)))
7456     (gnus-configure-windows 'article)
7457     (gnus-eval-in-buffer-window gnus-article-buffer
7458       (save-restriction
7459         (widen)
7460         (when (eq 'old old)
7461           (gnus-article-show-all-headers))
7462         (goto-char (point-min))
7463         (isearch-forward regexp-p)))))
7464
7465 (defun gnus-summary-search-article-forward (regexp &optional backward)
7466   "Search for an article containing REGEXP forward.
7467 If BACKWARD, search backward instead."
7468   (interactive
7469    (list (read-string
7470           (format "Search article %s (regexp%s): "
7471                   (if current-prefix-arg "backward" "forward")
7472                   (if gnus-last-search-regexp
7473                       (concat ", default " gnus-last-search-regexp)
7474                     "")))
7475          current-prefix-arg))
7476   (if (string-equal regexp "")
7477       (setq regexp (or gnus-last-search-regexp ""))
7478     (setq gnus-last-search-regexp regexp)
7479     (setq gnus-article-before-search gnus-current-article))
7480   ;; Intentionally set gnus-last-article.
7481   (setq gnus-last-article gnus-article-before-search)
7482   (let ((gnus-last-article gnus-last-article))
7483     (if (gnus-summary-search-article regexp backward)
7484         (gnus-summary-show-thread)
7485       (error "Search failed: \"%s\"" regexp))))
7486
7487 (defun gnus-summary-search-article-backward (regexp)
7488   "Search for an article containing REGEXP backward."
7489   (interactive
7490    (list (read-string
7491           (format "Search article backward (regexp%s): "
7492                   (if gnus-last-search-regexp
7493                       (concat ", default " gnus-last-search-regexp)
7494                     "")))))
7495   (gnus-summary-search-article-forward regexp 'backward))
7496
7497 (eval-when-compile
7498   (defmacro gnus-summary-search-article-position-point (regexp backward)
7499     "Dehighlight the last matched text and goto the beginning position."
7500     (` (if (and gnus-summary-search-article-matched-data
7501                 (let ((text (caddr gnus-summary-search-article-matched-data))
7502                       (inhibit-read-only t)
7503                       buffer-read-only)
7504                   (delete-region
7505                    (goto-char (car gnus-summary-search-article-matched-data))
7506                    (cadr gnus-summary-search-article-matched-data))
7507                   (insert text)
7508                   (string-match (, regexp) text)))
7509            (if (, backward) (beginning-of-line) (end-of-line))
7510          (goto-char (if (, backward) (point-max) (point-min))))))
7511
7512   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7513     "Place point where X-Face image is displayed."
7514     (if (featurep 'xemacs)
7515         (` (let ((end (if (search-forward "\n\n" nil t)
7516                           (goto-char (1- (point)))
7517                         (point-min)))
7518                  extent)
7519              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7520              (unless (and (re-search-forward "^From:" end t)
7521                           (setq extent (extent-at (point)))
7522                           (extent-begin-glyph extent))
7523                (goto-char (, opoint)))))
7524       (` (let ((end (if (search-forward "\n\n" nil t)
7525                         (goto-char (1- (point)))
7526                       (point-min)))
7527                (start (or (search-backward "\n\n" nil t) (point-min))))
7528            (goto-char
7529             (or (text-property-any start end 'x-face-image t);; x-face-e21
7530                 (text-property-any start end 'x-face-mule-bitmap-image t)
7531                 (, opoint)))))))
7532
7533   (defmacro gnus-summary-search-article-highlight-matched-text
7534     (backward treated x-face)
7535     "Highlight matched text in the function `gnus-summary-search-article'."
7536     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
7537              (end (set-marker (make-marker) (match-end 0)))
7538              (inhibit-read-only t)
7539              buffer-read-only)
7540          (unless treated
7541            (let ((,@
7542                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
7543                     (mapcar
7544                      (lambda (item) (setq items (delq item items)))
7545                      '(gnus-treat-buttonize
7546                        gnus-treat-fill-article
7547                        gnus-treat-fill-long-lines
7548                        gnus-treat-emphasize
7549                        gnus-treat-highlight-headers
7550                        gnus-treat-highlight-citation
7551                        gnus-treat-highlight-signature
7552                        gnus-treat-overstrike
7553                        gnus-treat-display-xface
7554                        gnus-treat-buttonize-head
7555                        gnus-treat-decode-article-as-default-mime-charset))
7556                     (static-if (featurep 'xemacs)
7557                         items
7558                       (cons '(x-face-mule-delete-x-face-field
7559                               (quote never))
7560                             items))))
7561                  (gnus-treat-display-xface
7562                   (when (, x-face) gnus-treat-display-xface)))
7563              (gnus-article-prepare-mime-display)))
7564          (goto-char (if (, backward) start end))
7565          (when (, x-face)
7566            (gnus-summary-search-article-highlight-goto-x-face (point)))
7567          (setq gnus-summary-search-article-matched-data
7568                (list start end (buffer-substring start end)))
7569          (unless (eq start end);; matched text has been deleted. :-<
7570            (put-text-property start end 'face
7571                               (or (find-face 'isearch)
7572                                   'secondary-selection))))))
7573   )
7574
7575 (defun gnus-summary-search-article (regexp &optional backward)
7576   "Search for an article containing REGEXP.
7577 Optional argument BACKWARD means do search for backward.
7578 `gnus-select-article-hook' is not called during the search."
7579   ;; We have to require this here to make sure that the following
7580   ;; dynamic binding isn't shadowed by autoloading.
7581   (require 'gnus-async)
7582   (require 'gnus-art)
7583   (let ((gnus-select-article-hook nil)  ;Disable hook.
7584         (gnus-article-prepare-hook nil)
7585         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7586         (gnus-use-article-prefetch nil)
7587         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7588         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7589         (sum (current-buffer))
7590         (found nil)
7591         point treated)
7592     (gnus-save-hidden-threads
7593       (static-if (featurep 'xemacs)
7594           (let ((gnus-inhibit-treatment t))
7595             (setq treated (eq 'old (gnus-summary-select-article)))
7596             (when (and treated
7597                        (not (and (gnus-buffer-live-p gnus-article-buffer)
7598                                  (window-live-p (get-buffer-window
7599                                                  gnus-article-buffer t)))))
7600               (gnus-summary-select-article nil t)
7601               (setq treated nil)))
7602         (let ((gnus-inhibit-treatment t)
7603               (x-face-mule-delete-x-face-field 'never))
7604           (setq treated (eq 'old (gnus-summary-select-article)))
7605           (when (and treated
7606                      (not
7607                       (and (gnus-buffer-live-p gnus-article-buffer)
7608                            (window-live-p (get-buffer-window
7609                                            gnus-article-buffer t))
7610                            (or (not (string-match "^\\^X-Face:" regexp))
7611                                (with-current-buffer gnus-article-buffer
7612                                  gnus-summary-search-article-matched-data)))))
7613             (gnus-summary-select-article nil t)
7614             (setq treated nil))))
7615       (set-buffer gnus-article-buffer)
7616       (widen)
7617       (if treated
7618           (progn
7619             (gnus-article-show-all-headers)
7620             (gnus-summary-search-article-position-point regexp backward))
7621         (goto-char (if backward (point-max) (point-min))))
7622       (while (not found)
7623         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7624         (if (if backward
7625                 (re-search-backward regexp nil t)
7626               (re-search-forward regexp nil t))
7627             ;; We found the regexp.
7628             (progn
7629               (gnus-summary-search-article-highlight-matched-text
7630                backward treated (string-match "^\\^X-Face:" regexp))
7631               (setq found 'found)
7632               (forward-line
7633                (/ (- 2 (window-height
7634                         (get-buffer-window gnus-article-buffer t)))
7635                   2))
7636               (set-window-start
7637                (get-buffer-window (current-buffer))
7638                (point))
7639               (set-buffer sum)
7640               (setq point (point)))
7641           ;; We didn't find it, so we go to the next article.
7642           (set-buffer sum)
7643           (setq found 'not)
7644           (while (eq found 'not)
7645             (if (not (if backward (gnus-summary-find-prev)
7646                        (gnus-summary-find-next)))
7647                 ;; No more articles.
7648                 (setq found t)
7649               ;; Select the next article and adjust point.
7650               (unless (gnus-summary-article-sparse-p
7651                        (gnus-summary-article-number))
7652                 (setq found nil)
7653                 (let ((gnus-inhibit-treatment t))
7654                   (gnus-summary-select-article))
7655                 (setq treated nil)
7656                 (set-buffer gnus-article-buffer)
7657                 (widen)
7658                 (goto-char (if backward (point-max) (point-min))))))))
7659       (gnus-message 7 ""))
7660     ;; Return whether we found the regexp.
7661     (when (eq found 'found)
7662       (goto-char point)
7663       (gnus-summary-show-thread)
7664       (gnus-summary-goto-subject gnus-current-article)
7665       (gnus-summary-position-point)
7666       t)))
7667
7668 (defun gnus-find-matching-articles (header regexp)
7669   "Return a list of all articles that match REGEXP on HEADER.
7670 This search includes all articles in the current group that Gnus has
7671 fetched headers for, whether they are displayed or not."
7672   (let ((articles nil)
7673         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
7674         (case-fold-search t))
7675     (dolist (header gnus-newsgroup-headers)
7676       (when (string-match regexp (funcall func header))
7677         (push (mail-header-number header) articles)))
7678     (nreverse articles)))
7679
7680 (defun gnus-summary-find-matching (header regexp &optional backward unread
7681                                           not-case-fold)
7682   "Return a list of all articles that match REGEXP on HEADER.
7683 The search stars on the current article and goes forwards unless
7684 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7685 If UNREAD is non-nil, only unread articles will
7686 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7687 in the comparisons."
7688   (let ((case-fold-search (not not-case-fold))
7689         articles d func)
7690     (if (consp header)
7691         (if (eq (car header) 'extra)
7692             (setq func
7693                   `(lambda (h)
7694                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7695                          "")))
7696           (error "%s is an invalid header" header))
7697       (unless (fboundp (intern (concat "mail-header-" header)))
7698         (error "%s is not a valid header" header))
7699       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7700     (dolist (d (if (eq backward 'all)
7701                    gnus-newsgroup-data
7702                  (gnus-data-find-list
7703                   (gnus-summary-article-number)
7704                   (gnus-data-list backward))))
7705       (when (and (or (not unread)       ; We want all articles...
7706                      (gnus-data-unread-p d)) ; Or just unreads.
7707                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
7708                  (string-match regexp
7709                                (funcall func (gnus-data-header d)))) ; Match.
7710         (push (gnus-data-number d) articles))) ; Success!
7711     (nreverse articles)))
7712
7713 (defun gnus-summary-execute-command (header regexp command &optional backward)
7714   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7715 If HEADER is an empty string (or nil), the match is done on the entire
7716 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7717   (interactive
7718    (list (let ((completion-ignore-case t))
7719            (completing-read
7720             "Header name: "
7721             (mapcar (lambda (header) (list (format "%s" header)))
7722                     (append
7723                      '("Number" "Subject" "From" "Lines" "Date"
7724                        "Message-ID" "Xref" "References" "Body")
7725                      gnus-extra-headers))
7726             nil 'require-match))
7727          (read-string "Regexp: ")
7728          (read-key-sequence "Command: ")
7729          current-prefix-arg))
7730   (when (equal header "Body")
7731     (setq header ""))
7732   ;; Hidden thread subtrees must be searched as well.
7733   (gnus-summary-show-all-threads)
7734   ;; We don't want to change current point nor window configuration.
7735   (save-excursion
7736     (save-window-excursion
7737       (gnus-message 6 "Executing %s..." (key-description command))
7738       ;; We'd like to execute COMMAND interactively so as to give arguments.
7739       (gnus-execute header regexp
7740                     `(call-interactively ',(key-binding command))
7741                     backward)
7742       (gnus-message 6 "Executing %s...done" (key-description command)))))
7743
7744 (defun gnus-summary-beginning-of-article ()
7745   "Scroll the article back to the beginning."
7746   (interactive)
7747   (gnus-summary-select-article)
7748   (gnus-configure-windows 'article)
7749   (gnus-eval-in-buffer-window gnus-article-buffer
7750     (widen)
7751     (goto-char (point-min))
7752     (when gnus-page-broken
7753       (gnus-narrow-to-page))))
7754
7755 (defun gnus-summary-end-of-article ()
7756   "Scroll to the end of the article."
7757   (interactive)
7758   (gnus-summary-select-article)
7759   (gnus-configure-windows 'article)
7760   (gnus-eval-in-buffer-window gnus-article-buffer
7761     (widen)
7762     (goto-char (point-max))
7763     (recenter -3)
7764     (when gnus-page-broken
7765       (gnus-narrow-to-page))))
7766
7767 (defun gnus-summary-print-article (&optional filename n)
7768   "Generate and print a PostScript image of the N next (mail) articles.
7769
7770 If N is negative, print the N previous articles.  If N is nil and articles
7771 have been marked with the process mark, print these instead.
7772
7773 If the optional first argument FILENAME is nil, send the image to the
7774 printer.  If FILENAME is a string, save the PostScript image in a file with
7775 that name.  If FILENAME is a number, prompt the user for the name of the file
7776 to save in."
7777   (interactive (list (ps-print-preprint current-prefix-arg)))
7778   (dolist (article (gnus-summary-work-articles n))
7779     (gnus-summary-select-article nil nil 'pseudo article)
7780     (gnus-eval-in-buffer-window gnus-article-buffer
7781       (let ((buffer (generate-new-buffer " *print*")))
7782         (unwind-protect
7783             (progn
7784               (copy-to-buffer buffer (point-min) (point-max))
7785               (set-buffer buffer)
7786               (gnus-article-delete-invisible-text)
7787               (when (gnus-visual-p 'article-highlight 'highlight)
7788                 ;; Copy-to-buffer doesn't copy overlay.  So redo
7789                 ;; highlight.
7790                 (let ((gnus-article-buffer buffer))
7791                   (gnus-article-highlight-citation t)
7792                   (gnus-article-highlight-signature)))
7793               (let ((ps-left-header
7794                      (list
7795                       (concat "("
7796                               (mail-header-subject gnus-current-headers) ")")
7797                       (concat "("
7798                               (mail-header-from gnus-current-headers) ")")))
7799                     (ps-right-header
7800                      (list
7801                       "/pagenumberstring load"
7802                       (concat "("
7803                               (mail-header-date gnus-current-headers) ")"))))
7804                 (gnus-run-hooks 'gnus-ps-print-hook)
7805                 (save-excursion
7806                   (if window-system
7807                       (ps-spool-buffer-with-faces)
7808                     (ps-spool-buffer)))))
7809           (kill-buffer buffer))))
7810     (gnus-summary-remove-process-mark article))
7811   (ps-despool filename))
7812
7813 (defun gnus-summary-show-article (&optional arg)
7814   "Force re-fetching of the current article.
7815 If ARG (the prefix) is a number, show the article with the charset
7816 defined in `gnus-summary-show-article-charset-alist', or the charset
7817 inputed.
7818 If ARG (the prefix) is non-nil and not a number, show the raw article
7819 without any article massaging functions being run."
7820   (interactive "P")
7821   (cond
7822    ((numberp arg)
7823     (let ((gnus-newsgroup-charset
7824            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7825                (mm-read-coding-system "Charset: ")))
7826           (gnus-newsgroup-ignored-charsets 'gnus-all))
7827       (gnus-summary-select-article nil 'force)
7828       (let ((deps gnus-newsgroup-dependencies)
7829             head header)
7830         (save-excursion
7831           (set-buffer gnus-original-article-buffer)
7832           (save-restriction
7833             (message-narrow-to-head)
7834             (setq head (buffer-string)))
7835           (with-temp-buffer
7836             (insert (format "211 %d Article retrieved.\n"
7837                             (cdr gnus-article-current)))
7838             (insert head)
7839             (insert ".\n")
7840             (let ((nntp-server-buffer (current-buffer)))
7841               (setq header (car (gnus-get-newsgroup-headers deps t))))))
7842         (gnus-data-set-header
7843          (gnus-data-find (cdr gnus-article-current))
7844          header)
7845         (gnus-summary-update-article-line
7846          (cdr gnus-article-current) header)
7847         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
7848             (gnus-summary-update-secondary-mark
7849              (cdr gnus-article-current))))))
7850    ((not arg)
7851     ;; Select the article the normal way.
7852     (gnus-summary-select-article nil 'force))
7853    (t
7854     ;; We have to require this here to make sure that the following
7855     ;; dynamic binding isn't shadowed by autoloading.
7856     (require 'gnus-async)
7857     (require 'gnus-art)
7858     ;; Bind the article treatment functions to nil.
7859     (let ((gnus-have-all-headers t)
7860           gnus-article-prepare-hook
7861           gnus-article-decode-hook
7862           gnus-break-pages
7863           gnus-show-mime
7864           (gnus-inhibit-treatment t))
7865       (gnus-summary-select-article nil 'force))))
7866   (gnus-summary-goto-subject gnus-current-article)
7867   (gnus-summary-position-point))
7868
7869 (defun gnus-summary-show-raw-article ()
7870   "Show the raw article without any article massaging functions being run."
7871   (interactive)
7872   (gnus-summary-show-article t))
7873
7874 (defun gnus-summary-verbose-headers (&optional arg)
7875   "Toggle permanent full header display.
7876 If ARG is a positive number, turn header display on.
7877 If ARG is a negative number, turn header display off."
7878   (interactive "P")
7879   (setq gnus-show-all-headers
7880         (cond ((or (not (numberp arg))
7881                    (zerop arg))
7882                (not gnus-show-all-headers))
7883               ((natnump arg)
7884                t)))
7885   (gnus-summary-show-article))
7886
7887 (defun gnus-summary-toggle-header (&optional arg)
7888   "Show the headers if they are hidden, or hide them if they are shown.
7889 If ARG is a positive number, show the entire header.
7890 If ARG is a negative number, hide the unwanted header lines."
7891   (interactive "P")
7892   (save-excursion
7893     (set-buffer gnus-article-buffer)
7894     (save-restriction
7895       (let* ((buffer-read-only nil)
7896              (inhibit-point-motion-hooks t)
7897              hidden e)
7898         (setq hidden
7899               (if (numberp arg)
7900                   (>= arg 0)
7901                 (save-restriction
7902                   (article-narrow-to-head)
7903                   (gnus-article-hidden-text-p 'headers))))
7904         (goto-char (point-min))
7905         (when (search-forward "\n\n" nil t)
7906           (delete-region (point-min) (1- (point))))
7907         (goto-char (point-min))
7908         (save-excursion
7909           (set-buffer gnus-original-article-buffer)
7910           (goto-char (point-min))
7911           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
7912         (insert-buffer-substring gnus-original-article-buffer 1 e)
7913         (save-restriction
7914           (narrow-to-region (point-min) (point))
7915           (article-decode-encoded-words)
7916           (if  hidden
7917               (let ((gnus-treat-hide-headers nil)
7918                     (gnus-treat-hide-boring-headers nil))
7919                 (setq gnus-article-wash-types
7920                       (delq 'headers gnus-article-wash-types))
7921                 (gnus-treat-article 'head))
7922             (gnus-treat-article 'head)))
7923         (gnus-set-mode-line 'article)))))
7924
7925 (defun gnus-summary-show-all-headers ()
7926   "Make all header lines visible."
7927   (interactive)
7928   (gnus-summary-toggle-header 1))
7929
7930 (defun gnus-summary-toggle-mime (&optional arg)
7931   "Toggle MIME processing.
7932 If ARG is a positive number, turn MIME processing on."
7933   (interactive "P")
7934   (setq gnus-show-mime
7935         (if (null arg)
7936             (not gnus-show-mime)
7937           (> (prefix-numeric-value arg) 0)))
7938   (gnus-summary-select-article t 'force))
7939
7940 (defun gnus-summary-caesar-message (&optional arg)
7941   "Caesar rotate the current article by 13.
7942 The numerical prefix specifies how many places to rotate each letter
7943 forward."
7944   (interactive "P")
7945   (gnus-summary-select-article)
7946   (let ((mail-header-separator ""))
7947     (gnus-eval-in-buffer-window gnus-article-buffer
7948       (save-restriction
7949         (widen)
7950         (let ((start (window-start))
7951               buffer-read-only)
7952           (message-caesar-buffer-body arg)
7953           (set-window-start (get-buffer-window (current-buffer)) start))))))
7954
7955 (defun gnus-summary-stop-page-breaking ()
7956   "Stop page breaking in the current article."
7957   (interactive)
7958   (gnus-summary-select-article)
7959   (gnus-eval-in-buffer-window gnus-article-buffer
7960     (widen)
7961     (when (gnus-visual-p 'page-marker)
7962       (let ((buffer-read-only nil))
7963         (gnus-remove-text-with-property 'gnus-prev)
7964         (gnus-remove-text-with-property 'gnus-next))
7965       (setq gnus-page-broken nil))))
7966
7967 (defun gnus-summary-move-article (&optional n to-newsgroup
7968                                             select-method action)
7969   "Move the current article to a different newsgroup.
7970 If N is a positive number, move the N next articles.
7971 If N is a negative number, move the N previous articles.
7972 If N is nil and any articles have been marked with the process mark,
7973 move those articles instead.
7974 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7975 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7976 re-spool using this method.
7977
7978 For this function to work, both the current newsgroup and the
7979 newsgroup that you want to move to have to support the `request-move'
7980 and `request-accept' functions.
7981
7982 ACTION can be either `move' (the default), `crosspost' or `copy'."
7983   (interactive "P")
7984   (unless action
7985     (setq action 'move))
7986   ;; Disable marking as read.
7987   (let (gnus-mark-article-hook)
7988     (save-window-excursion
7989       (gnus-summary-select-article)))
7990   ;; Check whether the source group supports the required functions.
7991   (cond ((and (eq action 'move)
7992               (not (gnus-check-backend-function
7993                     'request-move-article gnus-newsgroup-name)))
7994          (error "The current group does not support article moving"))
7995         ((and (eq action 'crosspost)
7996               (not (gnus-check-backend-function
7997                     'request-replace-article gnus-newsgroup-name)))
7998          (error "The current group does not support article editing")))
7999   (let ((articles (gnus-summary-work-articles n))
8000         (prefix (if (gnus-check-backend-function
8001                      'request-move-article gnus-newsgroup-name)
8002                     (gnus-group-real-prefix gnus-newsgroup-name)
8003                   ""))
8004         (names '((move "Move" "Moving")
8005                  (copy "Copy" "Copying")
8006                  (crosspost "Crosspost" "Crossposting")))
8007         (copy-buf (save-excursion
8008                     (nnheader-set-temp-buffer " *copy article*")))
8009         (default-marks gnus-article-mark-lists)
8010         (no-expire-marks (delete '(expirable . expire)
8011                                  (copy-sequence gnus-article-mark-lists)))
8012         art-group to-method new-xref article to-groups)
8013     (unless (assq action names)
8014       (error "Unknown action %s" action))
8015     ;; Read the newsgroup name.
8016     (when (and (not to-newsgroup)
8017                (not select-method))
8018       (setq to-newsgroup
8019             (gnus-read-move-group-name
8020              (cadr (assq action names))
8021              (symbol-value (intern (format "gnus-current-%s-group" action)))
8022              articles prefix))
8023       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8024     (setq to-method (or select-method
8025                         (gnus-server-to-method
8026                          (gnus-group-method to-newsgroup))))
8027     ;; Check the method we are to move this article to...
8028     (unless (gnus-check-backend-function
8029              'request-accept-article (car to-method))
8030       (error "%s does not support article copying" (car to-method)))
8031     (unless (gnus-check-server to-method)
8032       (error "Can't open server %s" (car to-method)))
8033     (gnus-message 6 "%s to %s: %s..."
8034                   (caddr (assq action names))
8035                   (or (car select-method) to-newsgroup) articles)
8036     (while articles
8037       (setq article (pop articles))
8038       (setq
8039        art-group
8040        (cond
8041         ;; Move the article.
8042         ((eq action 'move)
8043          ;; Remove this article from future suppression.
8044          (gnus-dup-unsuppress-article article)
8045          (gnus-request-move-article
8046           article                       ; Article to move
8047           gnus-newsgroup-name           ; From newsgroup
8048           (nth 1 (gnus-find-method-for-group
8049                   gnus-newsgroup-name)) ; Server
8050           (list 'gnus-request-accept-article
8051                 to-newsgroup (list 'quote select-method)
8052                 (not articles) t)       ; Accept form
8053           (not articles)))              ; Only save nov last time
8054         ;; Copy the article.
8055         ((eq action 'copy)
8056          (save-excursion
8057            (set-buffer copy-buf)
8058            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8059              (gnus-request-accept-article
8060               to-newsgroup select-method (not articles) t))))
8061         ;; Crosspost the article.
8062         ((eq action 'crosspost)
8063          (let ((xref (message-tokenize-header
8064                       (mail-header-xref (gnus-summary-article-header article))
8065                       " ")))
8066            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8067                                   ":" article))
8068            (unless xref
8069              (setq xref (list (system-name))))
8070            (setq new-xref
8071                  (concat
8072                   (mapconcat 'identity
8073                              (delete "Xref:" (delete new-xref xref))
8074                              " ")
8075                   " " new-xref))
8076            (save-excursion
8077              (set-buffer copy-buf)
8078              ;; First put the article in the destination group.
8079              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8080              (when (consp (setq art-group
8081                                 (gnus-request-accept-article
8082                                  to-newsgroup select-method (not articles))))
8083                (setq new-xref (concat new-xref " " (car art-group)
8084                                       ":" (cdr art-group)))
8085                ;; Now we have the new Xrefs header, so we insert
8086                ;; it and replace the new article.
8087                (nnheader-replace-header "Xref" new-xref)
8088                (gnus-request-replace-article
8089                 (cdr art-group) to-newsgroup (current-buffer))
8090                art-group))))))
8091       (cond
8092        ((not art-group)
8093         (gnus-message 1 "Couldn't %s article %s: %s"
8094                       (cadr (assq action names)) article
8095                       (nnheader-get-report (car to-method))))
8096        ((eq art-group 'junk)
8097         (when (eq action 'move)
8098           (gnus-summary-mark-article article gnus-canceled-mark)
8099           (gnus-message 4 "Deleted article %s" article)))
8100        (t
8101         (let* ((pto-group (gnus-group-prefixed-name
8102                            (car art-group) to-method))
8103                (entry
8104                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8105                (info (nth 2 entry))
8106                (to-group (gnus-info-group info))
8107                to-marks)
8108           ;; Update the group that has been moved to.
8109           (when (and info
8110                      (memq action '(move copy)))
8111             (unless (member to-group to-groups)
8112               (push to-group to-groups))
8113
8114             (unless (memq article gnus-newsgroup-unreads)
8115               (push 'read to-marks)
8116               (gnus-info-set-read
8117                info (gnus-add-to-range (gnus-info-read info)
8118                                        (list (cdr art-group)))))
8119
8120             ;; See whether the article is to be put in the cache.
8121             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8122                              default-marks
8123                            no-expire-marks))
8124                   (to-article (cdr art-group)))
8125
8126               ;; Enter the article into the cache in the new group,
8127               ;; if that is required.
8128               (when gnus-use-cache
8129                 (gnus-cache-possibly-enter-article
8130                  to-group to-article
8131                  (let ((header (copy-sequence
8132                                 (gnus-summary-article-header article))))
8133                    (mail-header-set-number header to-article)
8134                    header)
8135                  (memq article gnus-newsgroup-marked)
8136                  (memq article gnus-newsgroup-dormant)
8137                  (memq article gnus-newsgroup-unreads)))
8138
8139               (when gnus-preserve-marks
8140                 ;; Copy any marks over to the new group.
8141                 (when (and (equal to-group gnus-newsgroup-name)
8142                            (not (memq article gnus-newsgroup-unreads)))
8143                   ;; Mark this article as read in this group.
8144                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8145                   (setcdr (gnus-active to-group) to-article)
8146                   (setcdr gnus-newsgroup-active to-article))
8147
8148                 (while marks
8149                   (when (memq article (symbol-value
8150                                        (intern (format "gnus-newsgroup-%s"
8151                                                        (caar marks)))))
8152                     (push (cdar marks) to-marks)
8153                     ;; If the other group is the same as this group,
8154                     ;; then we have to add the mark to the list.
8155                     (when (equal to-group gnus-newsgroup-name)
8156                       (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8157                            (cons to-article
8158                                  (symbol-value
8159                                   (intern (format "gnus-newsgroup-%s"
8160                                                   (caar marks)))))))
8161                     ;; Copy the marks to other group.
8162                     (gnus-add-marked-articles
8163                      to-group (cdar marks) (list to-article) info))
8164                   (setq marks (cdr marks)))
8165
8166                 (gnus-request-set-mark to-group (list (list (list to-article)
8167                                                             'set
8168                                                             to-marks))))
8169
8170               (gnus-dribble-enter
8171                (concat "(gnus-group-set-info '"
8172                        (gnus-prin1-to-string (gnus-get-info to-group))
8173                        ")"))))
8174
8175           ;; Update the Xref header in this article to point to
8176           ;; the new crossposted article we have just created.
8177           (when (eq action 'crosspost)
8178             (save-excursion
8179               (set-buffer copy-buf)
8180               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8181               (nnheader-replace-header "Xref" new-xref)
8182               (gnus-request-replace-article
8183                article gnus-newsgroup-name (current-buffer)))))
8184
8185         ;;;!!!Why is this necessary?
8186         (set-buffer gnus-summary-buffer)
8187
8188         (gnus-summary-goto-subject article)
8189         (when (eq action 'move)
8190           (gnus-summary-mark-article article gnus-canceled-mark))))
8191       (gnus-summary-remove-process-mark article))
8192     ;; Re-activate all groups that have been moved to.
8193     (while to-groups
8194       (save-excursion
8195         (set-buffer gnus-group-buffer)
8196         (when (gnus-group-goto-group (car to-groups) t)
8197           (gnus-group-get-new-news-this-group 1 t))
8198         (pop to-groups)))
8199
8200     (gnus-kill-buffer copy-buf)
8201     (gnus-summary-position-point)
8202     (gnus-set-mode-line 'summary)))
8203
8204 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8205   "Move the current article to a different newsgroup.
8206 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8207 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8208 re-spool using this method."
8209   (interactive "P")
8210   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8211
8212 (defun gnus-summary-crosspost-article (&optional n)
8213   "Crosspost the current article to some other group."
8214   (interactive "P")
8215   (gnus-summary-move-article n nil nil 'crosspost))
8216
8217 (defcustom gnus-summary-respool-default-method nil
8218   "Default method for respooling an article.
8219 If nil, use to the current newsgroup method."
8220   :type '(choice (gnus-select-method :value (nnml ""))
8221                  (const nil))
8222   :group 'gnus-summary-mail)
8223
8224 (defun gnus-summary-respool-article (&optional n method)
8225   "Respool the current article.
8226 The article will be squeezed through the mail spooling process again,
8227 which means that it will be put in some mail newsgroup or other
8228 depending on `nnmail-split-methods'.
8229 If N is a positive number, respool the N next articles.
8230 If N is a negative number, respool the N previous articles.
8231 If N is nil and any articles have been marked with the process mark,
8232 respool those articles instead.
8233
8234 Respooling can be done both from mail groups and \"real\" newsgroups.
8235 In the former case, the articles in question will be moved from the
8236 current group into whatever groups they are destined to.  In the
8237 latter case, they will be copied into the relevant groups."
8238   (interactive
8239    (list current-prefix-arg
8240          (let* ((methods (gnus-methods-using 'respool))
8241                 (methname
8242                  (symbol-name (or gnus-summary-respool-default-method
8243                                   (car (gnus-find-method-for-group
8244                                         gnus-newsgroup-name)))))
8245                 (method
8246                  (gnus-completing-read
8247                   methname "What backend do you want to use when respooling?"
8248                   methods nil t nil 'gnus-mail-method-history))
8249                 ms)
8250            (cond
8251             ((zerop (length (setq ms (gnus-servers-using-backend
8252                                       (intern method)))))
8253              (list (intern method) ""))
8254             ((= 1 (length ms))
8255              (car ms))
8256             (t
8257              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8258                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8259                            ms-alist))))))))
8260   (unless method
8261     (error "No method given for respooling"))
8262   (if (assoc (symbol-name
8263               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8264              (gnus-methods-using 'respool))
8265       (gnus-summary-move-article n nil method)
8266     (gnus-summary-copy-article n nil method)))
8267
8268 (defun gnus-summary-import-article (file &optional edit)
8269   "Import an arbitrary file into a mail newsgroup."
8270   (interactive "fImport file: \nP")
8271   (let ((group gnus-newsgroup-name)
8272         (now (current-time))
8273         atts lines group-art)
8274     (unless (gnus-check-backend-function 'request-accept-article group)
8275       (error "%s does not support article importing" group))
8276     (or (file-readable-p file)
8277         (not (file-regular-p file))
8278         (error "Can't read %s" file))
8279     (save-excursion
8280       (set-buffer (gnus-get-buffer-create " *import file*"))
8281       (erase-buffer)
8282       (nnheader-insert-file-contents file)
8283       (goto-char (point-min))
8284       (if (nnheader-article-p)
8285           (save-restriction
8286             (goto-char (point-min))
8287             (search-forward "\n\n" nil t)
8288             (narrow-to-region (point-min) (1- (point)))
8289             (goto-char (point-min))
8290             (unless (re-search-forward "^date:" nil t)
8291               (goto-char (point-max))
8292               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8293         ;; This doesn't look like an article, so we fudge some headers.
8294         (setq atts (file-attributes file)
8295               lines (count-lines (point-min) (point-max)))
8296         (insert "From: " (read-string "From: ") "\n"
8297                 "Subject: " (read-string "Subject: ") "\n"
8298                 "Date: " (message-make-date (nth 5 atts)) "\n"
8299                 "Message-ID: " (message-make-message-id) "\n"
8300                 "Lines: " (int-to-string lines) "\n"
8301                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8302       (setq group-art (gnus-request-accept-article group nil t))
8303       (kill-buffer (current-buffer)))
8304     (setq gnus-newsgroup-active (gnus-activate-group group))
8305     (forward-line 1)
8306     (gnus-summary-goto-article (cdr group-art) nil t)
8307     (when edit
8308       (gnus-summary-edit-article))))
8309
8310 (defun gnus-summary-create-article ()
8311   "Create an article in a mail newsgroup."
8312   (interactive)
8313   (let ((group gnus-newsgroup-name)
8314         (now (current-time))
8315         group-art)
8316     (unless (gnus-check-backend-function 'request-accept-article group)
8317       (error "%s does not support article importing" group))
8318     (save-excursion
8319       (set-buffer (gnus-get-buffer-create " *import file*"))
8320       (erase-buffer)
8321       (goto-char (point-min))
8322       ;; This doesn't look like an article, so we fudge some headers.
8323       (insert "From: " (read-string "From: ") "\n"
8324               "Subject: " (read-string "Subject: ") "\n"
8325               "Date: " (message-make-date now) "\n"
8326               "Message-ID: " (message-make-message-id) "\n")
8327       (setq group-art (gnus-request-accept-article group nil t))
8328       (kill-buffer (current-buffer)))
8329     (setq gnus-newsgroup-active (gnus-activate-group group))
8330     (forward-line 1)
8331     (gnus-summary-goto-article (cdr group-art) nil t)
8332     (gnus-summary-edit-article)))
8333
8334 (defun gnus-summary-article-posted-p ()
8335   "Say whether the current (mail) article is available from news as well.
8336 This will be the case if the article has both been mailed and posted."
8337   (interactive)
8338   (let ((id (mail-header-references (gnus-summary-article-header)))
8339         (gnus-override-method (car (gnus-refer-article-methods))))
8340     (if (gnus-request-head id "")
8341         (gnus-message 2 "The current message was found on %s"
8342                       gnus-override-method)
8343       (gnus-message 2 "The current message couldn't be found on %s"
8344                     gnus-override-method)
8345       nil)))
8346
8347 (defun gnus-summary-expire-articles (&optional now)
8348   "Expire all articles that are marked as expirable in the current group."
8349   (interactive)
8350   (when (gnus-check-backend-function
8351          'request-expire-articles gnus-newsgroup-name)
8352     ;; This backend supports expiry.
8353     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8354            (expirable (if total
8355                           (progn
8356                             ;; We need to update the info for
8357                             ;; this group for `gnus-list-of-read-articles'
8358                             ;; to give us the right answer.
8359                             (gnus-run-hooks 'gnus-exit-group-hook)
8360                             (gnus-summary-update-info)
8361                             (gnus-list-of-read-articles gnus-newsgroup-name))
8362                         (setq gnus-newsgroup-expirable
8363                               (sort gnus-newsgroup-expirable '<))))
8364            (expiry-wait (if now 'immediate
8365                           (gnus-group-find-parameter
8366                            gnus-newsgroup-name 'expiry-wait)))
8367            (nnmail-expiry-target
8368             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8369                 nnmail-expiry-target))
8370            es)
8371       (when expirable
8372         ;; There are expirable articles in this group, so we run them
8373         ;; through the expiry process.
8374         (gnus-message 6 "Expiring articles...")
8375         (unless (gnus-check-group gnus-newsgroup-name)
8376           (error "Can't open server for %s" gnus-newsgroup-name))
8377         ;; The list of articles that weren't expired is returned.
8378         (save-excursion
8379           (if expiry-wait
8380               (let ((nnmail-expiry-wait-function nil)
8381                     (nnmail-expiry-wait expiry-wait))
8382                 (setq es (gnus-request-expire-articles
8383                           expirable gnus-newsgroup-name)))
8384             (setq es (gnus-request-expire-articles
8385                       expirable gnus-newsgroup-name)))
8386           (unless total
8387             (setq gnus-newsgroup-expirable es))
8388           ;; We go through the old list of expirable, and mark all
8389           ;; really expired articles as nonexistent.
8390           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8391             (let ((gnus-use-cache nil))
8392               (while expirable
8393                 (unless (memq (car expirable) es)
8394                   (when (gnus-data-find (car expirable))
8395                     (gnus-summary-mark-article
8396                      (car expirable) gnus-canceled-mark)))
8397                 (setq expirable (cdr expirable))))))
8398         (gnus-message 6 "Expiring articles...done")))))
8399
8400 (defun gnus-summary-expire-articles-now ()
8401   "Expunge all expirable articles in the current group.
8402 This means that *all* articles that are marked as expirable will be
8403 deleted forever, right now."
8404   (interactive)
8405   (or gnus-expert-user
8406       (gnus-yes-or-no-p
8407        "Are you really, really, really sure you want to delete all these messages? ")
8408       (error "Phew!"))
8409   (gnus-summary-expire-articles t))
8410
8411 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8412 (defun gnus-summary-delete-article (&optional n)
8413   "Delete the N next (mail) articles.
8414 This command actually deletes articles.  This is not a marking
8415 command.  The article will disappear forever from your life, never to
8416 return.
8417 If N is negative, delete backwards.
8418 If N is nil and articles have been marked with the process mark,
8419 delete these instead."
8420   (interactive "P")
8421   (unless (gnus-check-backend-function 'request-expire-articles
8422                                        gnus-newsgroup-name)
8423     (error "The current newsgroup does not support article deletion"))
8424   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8425     (error "Couldn't open server"))
8426   ;; Compute the list of articles to delete.
8427   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8428         not-deleted)
8429     (if (and gnus-novice-user
8430              (not (gnus-yes-or-no-p
8431                    (format "Do you really want to delete %s forever? "
8432                            (if (> (length articles) 1)
8433                                (format "these %s articles" (length articles))
8434                              "this article")))))
8435         ()
8436       ;; Delete the articles.
8437       (setq not-deleted (gnus-request-expire-articles
8438                          articles gnus-newsgroup-name 'force))
8439       (while articles
8440         (gnus-summary-remove-process-mark (car articles))
8441         ;; The backend might not have been able to delete the article
8442         ;; after all.
8443         (unless (memq (car articles) not-deleted)
8444           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8445         (setq articles (cdr articles)))
8446       (when not-deleted
8447         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8448     (gnus-summary-position-point)
8449     (gnus-set-mode-line 'summary)
8450     not-deleted))
8451
8452 (defun gnus-summary-edit-article (&optional force)
8453   "Edit the current article.
8454 This will have permanent effect only in mail groups.
8455 If FORCE is non-nil, allow editing of articles even in read-only
8456 groups."
8457   (interactive "P")
8458   (save-excursion
8459     (set-buffer gnus-summary-buffer)
8460     (let ((mail-parse-charset gnus-newsgroup-charset)
8461           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8462       (gnus-set-global-variables)
8463       (when (and (not force)
8464                  (gnus-group-read-only-p))
8465         (error "The current newsgroup does not support article editing"))
8466       (gnus-summary-show-article t)
8467       (gnus-article-edit-article
8468        'ignore
8469        `(lambda (no-highlight)
8470           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8471                 (message-options message-options)
8472                 (message-options-set-recipient)
8473                 (mail-parse-ignored-charsets
8474                  ',gnus-newsgroup-ignored-charsets))
8475             (gnus-summary-edit-article-done
8476              ,(or (mail-header-references gnus-current-headers) "")
8477              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8478
8479 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8480
8481 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8482                                                  no-highlight)
8483   "Make edits to the current article permanent."
8484   (interactive)
8485   (save-excursion
8486     ;; The buffer restriction contains the entire article if it exists.
8487     (when (article-goto-body)
8488       (let ((lines (count-lines (point) (point-max)))
8489             (length (- (point-max) (point)))
8490             (case-fold-search t)
8491             (body (copy-marker (point))))
8492         (goto-char (point-min))
8493         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8494           (delete-region (match-beginning 1) (match-end 1))
8495           (insert (number-to-string length)))
8496         (goto-char (point-min))
8497         (when (re-search-forward
8498                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8499           (delete-region (match-beginning 1) (match-end 1))
8500           (insert (number-to-string length)))
8501         (goto-char (point-min))
8502         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8503           (delete-region (match-beginning 1) (match-end 1))
8504           (insert (number-to-string lines))))))
8505   ;; Replace the article.
8506   (let ((buf (current-buffer)))
8507     (with-temp-buffer
8508       (insert-buffer-substring buf)
8509
8510       (if (and (not read-only)
8511                (not (gnus-request-replace-article
8512                      (cdr gnus-article-current) (car gnus-article-current)
8513                      (current-buffer) t)))
8514           (error "Couldn't replace article")
8515         ;; Update the summary buffer.
8516         (if (and references
8517                  (equal (message-tokenize-header references " ")
8518                         (message-tokenize-header
8519                          (or (message-fetch-field "references") "") " ")))
8520             ;; We only have to update this line.
8521             (save-excursion
8522               (save-restriction
8523                 (message-narrow-to-head)
8524                 (let ((head (buffer-string))
8525                       header)
8526                   (with-temp-buffer
8527                     (insert (format "211 %d Article retrieved.\n"
8528                                     (cdr gnus-article-current)))
8529                     (insert head)
8530                     (insert ".\n")
8531                     (let ((nntp-server-buffer (current-buffer)))
8532                       (setq header (car (gnus-get-newsgroup-headers
8533                                          (save-excursion
8534                                            (set-buffer gnus-summary-buffer)
8535                                            gnus-newsgroup-dependencies)
8536                                          t))))
8537                     (save-excursion
8538                       (set-buffer gnus-summary-buffer)
8539                       (gnus-data-set-header
8540                        (gnus-data-find (cdr gnus-article-current))
8541                        header)
8542                       (gnus-summary-update-article-line
8543                        (cdr gnus-article-current) header)
8544                       (if (gnus-summary-goto-subject
8545                            (cdr gnus-article-current) nil t)
8546                           (gnus-summary-update-secondary-mark
8547                            (cdr gnus-article-current))))))))
8548           ;; Update threads.
8549           (set-buffer (or buffer gnus-summary-buffer))
8550           (gnus-summary-update-article (cdr gnus-article-current))
8551           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8552               (gnus-summary-update-secondary-mark
8553                (cdr gnus-article-current))))
8554         ;; Prettify the article buffer again.
8555         (unless no-highlight
8556           (save-excursion
8557             (set-buffer gnus-article-buffer)
8558             ;;;!!! Fix this -- article should be rehighlighted.
8559             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8560             (set-buffer gnus-original-article-buffer)
8561             (gnus-request-article
8562              (cdr gnus-article-current)
8563              (car gnus-article-current) (current-buffer))))
8564         ;; Prettify the summary buffer line.
8565         (when (gnus-visual-p 'summary-highlight 'highlight)
8566           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8567
8568 (defun gnus-summary-edit-wash (key)
8569   "Perform editing command KEY in the article buffer."
8570   (interactive
8571    (list
8572     (progn
8573       (message "%s" (concat (this-command-keys) "- "))
8574       (read-char))))
8575   (message "")
8576   (gnus-summary-edit-article)
8577   (execute-kbd-macro (concat (this-command-keys) key))
8578   (gnus-article-edit-done))
8579
8580 ;;; Respooling
8581
8582 (defun gnus-summary-respool-query (&optional silent trace)
8583   "Query where the respool algorithm would put this article."
8584   (interactive)
8585   (let (gnus-mark-article-hook)
8586     (gnus-summary-select-article)
8587     (save-excursion
8588       (set-buffer gnus-original-article-buffer)
8589       (save-restriction
8590         (message-narrow-to-head)
8591         (let ((groups (nnmail-article-group 'identity trace)))
8592           (unless silent
8593             (if groups
8594                 (message "This message would go to %s"
8595                          (mapconcat 'car groups ", "))
8596               (message "This message would go to no groups"))
8597             groups))))))
8598
8599 (defun gnus-summary-respool-trace ()
8600   "Trace where the respool algorithm would put this article.
8601 Display a buffer showing all fancy splitting patterns which matched."
8602   (interactive)
8603   (gnus-summary-respool-query nil t))
8604
8605 ;; Summary marking commands.
8606
8607 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8608   "Mark articles which has the same subject as read, and then select the next.
8609 If UNMARK is positive, remove any kind of mark.
8610 If UNMARK is negative, tick articles."
8611   (interactive "P")
8612   (when unmark
8613     (setq unmark (prefix-numeric-value unmark)))
8614   (let ((count
8615          (gnus-summary-mark-same-subject
8616           (gnus-summary-article-subject) unmark)))
8617     ;; Select next unread article.  If auto-select-same mode, should
8618     ;; select the first unread article.
8619     (gnus-summary-next-article t (and gnus-auto-select-same
8620                                       (gnus-summary-article-subject)))
8621     (gnus-message 7 "%d article%s marked as %s"
8622                   count (if (= count 1) " is" "s are")
8623                   (if unmark "unread" "read"))))
8624
8625 (defun gnus-summary-kill-same-subject (&optional unmark)
8626   "Mark articles which has the same subject as read.
8627 If UNMARK is positive, remove any kind of mark.
8628 If UNMARK is negative, tick articles."
8629   (interactive "P")
8630   (when unmark
8631     (setq unmark (prefix-numeric-value unmark)))
8632   (let ((count
8633          (gnus-summary-mark-same-subject
8634           (gnus-summary-article-subject) unmark)))
8635     ;; If marked as read, go to next unread subject.
8636     (when (null unmark)
8637       ;; Go to next unread subject.
8638       (gnus-summary-next-subject 1 t))
8639     (gnus-message 7 "%d articles are marked as %s"
8640                   count (if unmark "unread" "read"))))
8641
8642 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8643   "Mark articles with same SUBJECT as read, and return marked number.
8644 If optional argument UNMARK is positive, remove any kinds of marks.
8645 If optional argument UNMARK is negative, mark articles as unread instead."
8646   (let ((count 1))
8647     (save-excursion
8648       (cond
8649        ((null unmark)                   ; Mark as read.
8650         (while (and
8651                 (progn
8652                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8653                   (gnus-summary-show-thread) t)
8654                 (gnus-summary-find-subject subject))
8655           (setq count (1+ count))))
8656        ((> unmark 0)                    ; Tick.
8657         (while (and
8658                 (progn
8659                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8660                   (gnus-summary-show-thread) t)
8661                 (gnus-summary-find-subject subject))
8662           (setq count (1+ count))))
8663        (t                               ; Mark as unread.
8664         (while (and
8665                 (progn
8666                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8667                   (gnus-summary-show-thread) t)
8668                 (gnus-summary-find-subject subject))
8669           (setq count (1+ count)))))
8670       (gnus-set-mode-line 'summary)
8671       ;; Return the number of marked articles.
8672       count)))
8673
8674 (defun gnus-summary-mark-as-processable (n &optional unmark)
8675   "Set the process mark on the next N articles.
8676 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8677 the process mark instead.  The difference between N and the actual
8678 number of articles marked is returned."
8679   (interactive "P")
8680   (if (and (null n) (gnus-region-active-p))
8681       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
8682     (setq n (prefix-numeric-value n))
8683     (let ((backward (< n 0))
8684           (n (abs n)))
8685       (while (and
8686               (> n 0)
8687               (if unmark
8688                   (gnus-summary-remove-process-mark
8689                    (gnus-summary-article-number))
8690                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
8691               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8692         (setq n (1- n)))
8693       (when (/= 0 n)
8694         (gnus-message 7 "No more articles"))
8695       (gnus-summary-recenter)
8696       (gnus-summary-position-point)
8697       n)))
8698
8699 (defun gnus-summary-unmark-as-processable (n)
8700   "Remove the process mark from the next N articles.
8701 If N is negative, unmark backward instead.  The difference between N and
8702 the actual number of articles unmarked is returned."
8703   (interactive "P")
8704   (gnus-summary-mark-as-processable n t))
8705
8706 (defun gnus-summary-unmark-all-processable ()
8707   "Remove the process mark from all articles."
8708   (interactive)
8709   (save-excursion
8710     (while gnus-newsgroup-processable
8711       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8712   (gnus-summary-position-point))
8713
8714 (defun gnus-summary-add-mark (article type)
8715   "Mark ARTICLE with a mark of TYPE."
8716   (let ((vtype (car (assq type gnus-article-mark-lists)))
8717         var)
8718     (if (not vtype)
8719         (error "No such mark type: %s" type)
8720       (setq var (intern (format "gnus-newsgroup-%s" type)))
8721       (set var (cons article (symbol-value var)))
8722       (if (memq type '(processable cached replied forwarded recent saved))
8723           (gnus-summary-update-secondary-mark article)
8724         ;;; !!! This is bogus.  We should find out what primary
8725         ;;; !!! mark we want to set.
8726         (gnus-summary-update-mark gnus-del-mark 'unread)))))
8727
8728 (defun gnus-summary-mark-as-expirable (n)
8729   "Mark N articles forward as expirable.
8730 If N is negative, mark backward instead.  The difference between N and
8731 the actual number of articles marked is returned."
8732   (interactive "p")
8733   (gnus-summary-mark-forward n gnus-expirable-mark))
8734
8735 (defun gnus-summary-mark-article-as-replied (article)
8736   "Mark ARTICLE as replied to and update the summary line.
8737 ARTICLE can also be a list of articles."
8738   (interactive (list (gnus-summary-article-number)))
8739   (let ((articles (if (listp article) article (list article))))
8740     (dolist (article articles)
8741       (push article gnus-newsgroup-replied)
8742       (let ((buffer-read-only nil))
8743         (when (gnus-summary-goto-subject article nil t)
8744           (gnus-summary-update-secondary-mark article))))))
8745
8746 (defun gnus-summary-mark-article-as-forwarded (article)
8747   "Mark ARTICLE as forwarded and update the summary line.
8748 ARTICLE can also be a list of articles."
8749   (let ((articles (if (listp article) article (list article))))
8750     (dolist (article articles)
8751       (push article gnus-newsgroup-forwarded)
8752       (let ((buffer-read-only nil))
8753         (when (gnus-summary-goto-subject article nil t)
8754           (gnus-summary-update-secondary-mark article))))))
8755
8756 (defun gnus-summary-set-bookmark (article)
8757   "Set a bookmark in current article."
8758   (interactive (list (gnus-summary-article-number)))
8759   (when (or (not (get-buffer gnus-article-buffer))
8760             (not gnus-current-article)
8761             (not gnus-article-current)
8762             (not (equal gnus-newsgroup-name (car gnus-article-current))))
8763     (error "No current article selected"))
8764   ;; Remove old bookmark, if one exists.
8765   (let ((old (assq article gnus-newsgroup-bookmarks)))
8766     (when old
8767       (setq gnus-newsgroup-bookmarks
8768             (delq old gnus-newsgroup-bookmarks))))
8769   ;; Set the new bookmark, which is on the form
8770   ;; (article-number . line-number-in-body).
8771   (push
8772    (cons article
8773          (save-excursion
8774            (set-buffer gnus-article-buffer)
8775            (count-lines
8776             (min (point)
8777                  (save-excursion
8778                    (goto-char (point-min))
8779                    (search-forward "\n\n" nil t)
8780                    (point)))
8781             (point))))
8782    gnus-newsgroup-bookmarks)
8783   (gnus-message 6 "A bookmark has been added to the current article."))
8784
8785 (defun gnus-summary-remove-bookmark (article)
8786   "Remove the bookmark from the current article."
8787   (interactive (list (gnus-summary-article-number)))
8788   ;; Remove old bookmark, if one exists.
8789   (let ((old (assq article gnus-newsgroup-bookmarks)))
8790     (if old
8791         (progn
8792           (setq gnus-newsgroup-bookmarks
8793                 (delq old gnus-newsgroup-bookmarks))
8794           (gnus-message 6 "Removed bookmark."))
8795       (gnus-message 6 "No bookmark in current article."))))
8796
8797 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8798 (defun gnus-summary-mark-as-dormant (n)
8799   "Mark N articles forward as dormant.
8800 If N is negative, mark backward instead.  The difference between N and
8801 the actual number of articles marked is returned."
8802   (interactive "p")
8803   (gnus-summary-mark-forward n gnus-dormant-mark))
8804
8805 (defun gnus-summary-set-process-mark (article)
8806   "Set the process mark on ARTICLE and update the summary line."
8807   (setq gnus-newsgroup-processable
8808         (cons article
8809               (delq article gnus-newsgroup-processable)))
8810   (when (gnus-summary-goto-subject article)
8811     (gnus-summary-show-thread)
8812     (gnus-summary-goto-subject article)
8813     (gnus-summary-update-secondary-mark article)))
8814
8815 (defun gnus-summary-remove-process-mark (article)
8816   "Remove the process mark from ARTICLE and update the summary line."
8817   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
8818   (when (gnus-summary-goto-subject article)
8819     (gnus-summary-show-thread)
8820     (gnus-summary-goto-subject article)
8821     (gnus-summary-update-secondary-mark article)))
8822
8823 (defun gnus-summary-set-saved-mark (article)
8824   "Set the process mark on ARTICLE and update the summary line."
8825   (push article gnus-newsgroup-saved)
8826   (when (gnus-summary-goto-subject article)
8827     (gnus-summary-update-secondary-mark article)))
8828
8829 (defun gnus-summary-mark-forward (n &optional mark no-expire)
8830   "Mark N articles as read forwards.
8831 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
8832 The difference between N and the actual number of articles marked is
8833 returned.
8834 Iff NO-EXPIRE, auto-expiry will be inhibited."
8835   (interactive "p")
8836   (gnus-summary-show-thread)
8837   (let ((backward (< n 0))
8838         (gnus-summary-goto-unread
8839          (and gnus-summary-goto-unread
8840               (not (eq gnus-summary-goto-unread 'never))
8841               (not (memq mark (list gnus-unread-mark
8842                                     gnus-ticked-mark gnus-dormant-mark)))))
8843         (n (abs n))
8844         (mark (or mark gnus-del-mark)))
8845     (while (and (> n 0)
8846                 (gnus-summary-mark-article nil mark no-expire)
8847                 (zerop (gnus-summary-next-subject
8848                         (if backward -1 1)
8849                         (and gnus-summary-goto-unread
8850                              (not (eq gnus-summary-goto-unread 'never)))
8851                         t)))
8852       (setq n (1- n)))
8853     (when (/= 0 n)
8854       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
8855     (gnus-summary-recenter)
8856     (gnus-summary-position-point)
8857     (gnus-set-mode-line 'summary)
8858     n))
8859
8860 (defun gnus-summary-mark-article-as-read (mark)
8861   "Mark the current article quickly as read with MARK."
8862   (let ((article (gnus-summary-article-number)))
8863     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8864     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8865     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8866     (push (cons article mark) gnus-newsgroup-reads)
8867     ;; Possibly remove from cache, if that is used.
8868     (when gnus-use-cache
8869       (gnus-cache-enter-remove-article article))
8870     ;; Allow the backend to change the mark.
8871     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8872     ;; Check for auto-expiry.
8873     (when (and gnus-newsgroup-auto-expire
8874                (memq mark gnus-auto-expirable-marks))
8875       (setq mark gnus-expirable-mark)
8876       ;; Let the backend know about the mark change.
8877       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8878       (push article gnus-newsgroup-expirable))
8879     ;; Set the mark in the buffer.
8880     (gnus-summary-update-mark mark 'unread)
8881     t))
8882
8883 (defun gnus-summary-mark-article-as-unread (mark)
8884   "Mark the current article quickly as unread with MARK."
8885   (let* ((article (gnus-summary-article-number))
8886          (old-mark (gnus-summary-article-mark article)))
8887     ;; Allow the backend to change the mark.
8888     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8889     (if (eq mark old-mark)
8890         t
8891       (if (<= article 0)
8892           (progn
8893             (gnus-error 1 "Can't mark negative article numbers")
8894             nil)
8895         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8896         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8897         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
8898         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
8899         (cond ((= mark gnus-ticked-mark)
8900                (push article gnus-newsgroup-marked))
8901               ((= mark gnus-dormant-mark)
8902                (push article gnus-newsgroup-dormant))
8903               (t
8904                (push article gnus-newsgroup-unreads)))
8905         (gnus-pull article gnus-newsgroup-reads)
8906
8907         ;; See whether the article is to be put in the cache.
8908         (and gnus-use-cache
8909              (vectorp (gnus-summary-article-header article))
8910              (save-excursion
8911                (gnus-cache-possibly-enter-article
8912                 gnus-newsgroup-name article
8913                 (gnus-summary-article-header article)
8914                 (= mark gnus-ticked-mark)
8915                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8916
8917         ;; Fix the mark.
8918         (gnus-summary-update-mark mark 'unread)
8919         t))))
8920
8921 (defun gnus-summary-mark-article (&optional article mark no-expire)
8922   "Mark ARTICLE with MARK.  MARK can be any character.
8923 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
8924 `??' (dormant) and `?E' (expirable).
8925 If MARK is nil, then the default character `?r' is used.
8926 If ARTICLE is nil, then the article on the current line will be
8927 marked.
8928 Iff NO-EXPIRE, auto-expiry will be inhibited."
8929   ;; The mark might be a string.
8930   (when (stringp mark)
8931     (setq mark (aref mark 0)))
8932   ;; If no mark is given, then we check auto-expiring.
8933   (when (null mark)
8934     (setq mark gnus-del-mark))
8935   (when (and (not no-expire)
8936              gnus-newsgroup-auto-expire
8937              (memq mark gnus-auto-expirable-marks))
8938     (setq mark gnus-expirable-mark))
8939   (let ((article (or article (gnus-summary-article-number)))
8940         (old-mark (gnus-summary-article-mark article)))
8941     ;; Allow the backend to change the mark.
8942     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8943     (if (eq mark old-mark)
8944         t
8945       (unless article
8946         (error "No article on current line"))
8947       (if (not (if (or (= mark gnus-unread-mark)
8948                        (= mark gnus-ticked-mark)
8949                        (= mark gnus-dormant-mark))
8950                    (gnus-mark-article-as-unread article mark)
8951                  (gnus-mark-article-as-read article mark)))
8952           t
8953         ;; See whether the article is to be put in the cache.
8954         (and gnus-use-cache
8955              (not (= mark gnus-canceled-mark))
8956              (vectorp (gnus-summary-article-header article))
8957              (save-excursion
8958                (gnus-cache-possibly-enter-article
8959                 gnus-newsgroup-name article
8960                 (gnus-summary-article-header article)
8961                 (= mark gnus-ticked-mark)
8962                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8963
8964         (when (gnus-summary-goto-subject article nil t)
8965           (let ((buffer-read-only nil))
8966             (gnus-summary-show-thread)
8967             ;; Fix the mark.
8968             (gnus-summary-update-mark mark 'unread)
8969             t))))))
8970
8971 (defun gnus-summary-update-secondary-mark (article)
8972   "Update the secondary (read, process, cache) mark."
8973   (gnus-summary-update-mark
8974    (cond ((memq article gnus-newsgroup-processable)
8975           gnus-process-mark)
8976          ((memq article gnus-newsgroup-cached)
8977           gnus-cached-mark)
8978          ((memq article gnus-newsgroup-replied)
8979           gnus-replied-mark)
8980          ((memq article gnus-newsgroup-forwarded)
8981           gnus-forwarded-mark)
8982          ((memq article gnus-newsgroup-saved)
8983           gnus-saved-mark)
8984          ((memq article gnus-newsgroup-recent)
8985           gnus-recent-mark)
8986          (t gnus-no-mark))
8987    'replied)
8988   (when (gnus-visual-p 'summary-highlight 'highlight)
8989     (gnus-run-hooks 'gnus-summary-update-hook))
8990   t)
8991
8992 (defun gnus-summary-update-mark (mark type)
8993   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
8994         (buffer-read-only nil))
8995     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
8996     (when forward
8997       (when (looking-at "\r")
8998         (incf forward))
8999       (when (<= (+ forward (point)) (point-max))
9000         ;; Go to the right position on the line.
9001         (goto-char (+ forward (point)))
9002         ;; Replace the old mark with the new mark.
9003         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9004         ;; Optionally update the marks by some user rule.
9005         (when (eq type 'unread)
9006           (gnus-data-set-mark
9007            (gnus-data-find (gnus-summary-article-number)) mark)
9008           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9009
9010 (defun gnus-mark-article-as-read (article &optional mark)
9011   "Enter ARTICLE in the pertinent lists and remove it from others."
9012   ;; Make the article expirable.
9013   (let ((mark (or mark gnus-del-mark)))
9014     (if (= mark gnus-expirable-mark)
9015         (push article gnus-newsgroup-expirable)
9016       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9017     ;; Remove from unread and marked lists.
9018     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9019     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9020     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9021     (push (cons article mark) gnus-newsgroup-reads)
9022     ;; Possibly remove from cache, if that is used.
9023     (when gnus-use-cache
9024       (gnus-cache-enter-remove-article article))
9025     t))
9026
9027 (defun gnus-mark-article-as-unread (article &optional mark)
9028   "Enter ARTICLE in the pertinent lists and remove it from others."
9029   (let ((mark (or mark gnus-ticked-mark)))
9030     (if (<= article 0)
9031         (progn
9032           (gnus-error 1 "Can't mark negative article numbers")
9033           nil)
9034       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9035             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9036             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9037             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9038
9039       ;; Unsuppress duplicates?
9040       (when gnus-suppress-duplicates
9041         (gnus-dup-unsuppress-article article))
9042
9043       (cond ((= mark gnus-ticked-mark)
9044              (push article gnus-newsgroup-marked))
9045             ((= mark gnus-dormant-mark)
9046              (push article gnus-newsgroup-dormant))
9047             (t
9048              (push article gnus-newsgroup-unreads)))
9049       (gnus-pull article gnus-newsgroup-reads)
9050       t)))
9051
9052 (defalias 'gnus-summary-mark-as-unread-forward
9053   'gnus-summary-tick-article-forward)
9054 (make-obsolete 'gnus-summary-mark-as-unread-forward
9055                'gnus-summary-tick-article-forward)
9056 (defun gnus-summary-tick-article-forward (n)
9057   "Tick N articles forwards.
9058 If N is negative, tick backwards instead.
9059 The difference between N and the number of articles ticked is returned."
9060   (interactive "p")
9061   (gnus-summary-mark-forward n gnus-ticked-mark))
9062
9063 (defalias 'gnus-summary-mark-as-unread-backward
9064   'gnus-summary-tick-article-backward)
9065 (make-obsolete 'gnus-summary-mark-as-unread-backward
9066                'gnus-summary-tick-article-backward)
9067 (defun gnus-summary-tick-article-backward (n)
9068   "Tick N articles backwards.
9069 The difference between N and the number of articles ticked is returned."
9070   (interactive "p")
9071   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9072
9073 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9074 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9075 (defun gnus-summary-tick-article (&optional article clear-mark)
9076   "Mark current article as unread.
9077 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9078 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9079   (interactive)
9080   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9081                                        gnus-ticked-mark)))
9082
9083 (defun gnus-summary-mark-as-read-forward (n)
9084   "Mark N articles as read forwards.
9085 If N is negative, mark backwards instead.
9086 The difference between N and the actual number of articles marked is
9087 returned."
9088   (interactive "p")
9089   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9090
9091 (defun gnus-summary-mark-as-read-backward (n)
9092   "Mark the N articles as read backwards.
9093 The difference between N and the actual number of articles marked is
9094 returned."
9095   (interactive "p")
9096   (gnus-summary-mark-forward
9097    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9098
9099 (defun gnus-summary-mark-as-read (&optional article mark)
9100   "Mark current article as read.
9101 ARTICLE specifies the article to be marked as read.
9102 MARK specifies a string to be inserted at the beginning of the line."
9103   (gnus-summary-mark-article article mark))
9104
9105 (defun gnus-summary-clear-mark-forward (n)
9106   "Clear marks from N articles forward.
9107 If N is negative, clear backward instead.
9108 The difference between N and the number of marks cleared is returned."
9109   (interactive "p")
9110   (gnus-summary-mark-forward n gnus-unread-mark))
9111
9112 (defun gnus-summary-clear-mark-backward (n)
9113   "Clear marks from N articles backward.
9114 The difference between N and the number of marks cleared is returned."
9115   (interactive "p")
9116   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9117
9118 (defun gnus-summary-mark-unread-as-read ()
9119   "Intended to be used by `gnus-summary-mark-article-hook'."
9120   (when (memq gnus-current-article gnus-newsgroup-unreads)
9121     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9122
9123 (defun gnus-summary-mark-read-and-unread-as-read ()
9124   "Intended to be used by `gnus-summary-mark-article-hook'."
9125   (let ((mark (gnus-summary-article-mark)))
9126     (when (or (gnus-unread-mark-p mark)
9127               (gnus-read-mark-p mark))
9128       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9129
9130 (defun gnus-summary-mark-unread-as-ticked ()
9131   "Intended to be used by `gnus-summary-mark-article-hook'."
9132   (when (memq gnus-current-article gnus-newsgroup-unreads)
9133     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9134
9135 (defun gnus-summary-mark-region-as-read (point mark all)
9136   "Mark all unread articles between point and mark as read.
9137 If given a prefix, mark all articles between point and mark as read,
9138 even ticked and dormant ones."
9139   (interactive "r\nP")
9140   (save-excursion
9141     (let (article)
9142       (goto-char point)
9143       (beginning-of-line)
9144       (while (and
9145               (< (point) mark)
9146               (progn
9147                 (when (or all
9148                           (memq (setq article (gnus-summary-article-number))
9149                                 gnus-newsgroup-unreads))
9150                   (gnus-summary-mark-article article gnus-del-mark))
9151                 t)
9152               (gnus-summary-find-next))))))
9153
9154 (defun gnus-summary-mark-below (score mark)
9155   "Mark articles with score less than SCORE with MARK."
9156   (interactive "P\ncMark: ")
9157   (setq score (if score
9158                   (prefix-numeric-value score)
9159                 (or gnus-summary-default-score 0)))
9160   (save-excursion
9161     (set-buffer gnus-summary-buffer)
9162     (goto-char (point-min))
9163     (while
9164         (progn
9165           (and (< (gnus-summary-article-score) score)
9166                (gnus-summary-mark-article nil mark))
9167           (gnus-summary-find-next)))))
9168
9169 (defun gnus-summary-kill-below (&optional score)
9170   "Mark articles with score below SCORE as read."
9171   (interactive "P")
9172   (gnus-summary-mark-below score gnus-killed-mark))
9173
9174 (defun gnus-summary-clear-above (&optional score)
9175   "Clear all marks from articles with score above SCORE."
9176   (interactive "P")
9177   (gnus-summary-mark-above score gnus-unread-mark))
9178
9179 (defun gnus-summary-tick-above (&optional score)
9180   "Tick all articles with score above SCORE."
9181   (interactive "P")
9182   (gnus-summary-mark-above score gnus-ticked-mark))
9183
9184 (defun gnus-summary-mark-above (score mark)
9185   "Mark articles with score over SCORE with MARK."
9186   (interactive "P\ncMark: ")
9187   (setq score (if score
9188                   (prefix-numeric-value score)
9189                 (or gnus-summary-default-score 0)))
9190   (save-excursion
9191     (set-buffer gnus-summary-buffer)
9192     (goto-char (point-min))
9193     (while (and (progn
9194                   (when (> (gnus-summary-article-score) score)
9195                     (gnus-summary-mark-article nil mark))
9196                   t)
9197                 (gnus-summary-find-next)))))
9198
9199 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9200 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9201 (defun gnus-summary-limit-include-expunged (&optional no-error)
9202   "Display all the hidden articles that were expunged for low scores."
9203   (interactive)
9204   (let ((buffer-read-only nil))
9205     (let ((scored gnus-newsgroup-scored)
9206           headers h)
9207       (while scored
9208         (unless (gnus-summary-article-header (caar scored))
9209           (and (setq h (gnus-number-to-header (caar scored)))
9210                (< (cdar scored) gnus-summary-expunge-below)
9211                (push h headers)))
9212         (setq scored (cdr scored)))
9213       (if (not headers)
9214           (when (not no-error)
9215             (error "No expunged articles hidden"))
9216         (goto-char (point-min))
9217         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9218         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9219         (mapcar (lambda (x) (push (mail-header-number x)
9220                                   gnus-newsgroup-limit))
9221                 headers)
9222         (gnus-summary-prepare-unthreaded (nreverse headers))
9223         (goto-char (point-min))
9224         (gnus-summary-position-point)
9225         t))))
9226
9227 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9228   "Mark all unread articles in this newsgroup as read.
9229 If prefix argument ALL is non-nil, ticked and dormant articles will
9230 also be marked as read.
9231 If QUIETLY is non-nil, no questions will be asked.
9232 If TO-HERE is non-nil, it should be a point in the buffer.  All
9233 articles before (after, if REVERSE is set) this point will be marked as read.
9234 Note that this function will only catch up the unread article
9235 in the current summary buffer limitation.
9236 The number of articles marked as read is returned."
9237   (interactive "P")
9238   (prog1
9239       (save-excursion
9240         (when (or quietly
9241                   (not gnus-interactive-catchup) ;Without confirmation?
9242                   gnus-expert-user
9243                   (gnus-y-or-n-p
9244                    (if all
9245                        "Mark absolutely all articles as read? "
9246                      "Mark all unread articles as read? ")))
9247           (if (and not-mark
9248                    (not gnus-newsgroup-adaptive)
9249                    (not gnus-newsgroup-auto-expire)
9250                    (not gnus-suppress-duplicates)
9251                    (or (not gnus-use-cache)
9252                        (eq gnus-use-cache 'passive)))
9253               (progn
9254                 (when all
9255                   (setq gnus-newsgroup-marked nil
9256                         gnus-newsgroup-dormant nil))
9257                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9258             ;; We actually mark all articles as canceled, which we
9259             ;; have to do when using auto-expiry or adaptive scoring.
9260             (gnus-summary-show-all-threads)
9261             (if (and to-here reverse)
9262                 (progn
9263                   (goto-char to-here)
9264                   (while (and
9265                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9266                           (gnus-summary-find-next (not all) nil nil t))))
9267               (when (gnus-summary-first-subject (not all) t)
9268                 (while (and
9269                         (if to-here (< (point) to-here) t)
9270                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9271                         (gnus-summary-find-next (not all) nil nil t)))))
9272             (gnus-set-mode-line 'summary))
9273           t))
9274     (gnus-summary-position-point)))
9275
9276 (defun gnus-summary-catchup-to-here (&optional all)
9277   "Mark all unticked articles before the current one as read.
9278 If ALL is non-nil, also mark ticked and dormant articles as read."
9279   (interactive "P")
9280   (save-excursion
9281     (gnus-save-hidden-threads
9282       (let ((beg (point)))
9283         ;; We check that there are unread articles.
9284         (when (or all (gnus-summary-find-prev))
9285           (gnus-summary-catchup all t beg)))))
9286   (gnus-summary-position-point))
9287
9288 (defun gnus-summary-catchup-from-here (&optional all)
9289   "Mark all unticked articles after the current one as read.
9290 If ALL is non-nil, also mark ticked and dormant articles as read."
9291   (interactive "P")
9292   (save-excursion
9293     (gnus-save-hidden-threads
9294       (let ((beg (point)))
9295         ;; We check that there are unread articles.
9296         (when (or all (gnus-summary-find-next))
9297           (gnus-summary-catchup all t beg nil t)))))
9298   (gnus-summary-position-point))
9299
9300 (defun gnus-summary-catchup-all (&optional quietly)
9301   "Mark all articles in this newsgroup as read."
9302   (interactive "P")
9303   (gnus-summary-catchup t quietly))
9304
9305 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9306   "Mark all unread articles in this group as read, then exit.
9307 If prefix argument ALL is non-nil, all articles are marked as read.
9308 If QUIETLY is non-nil, no questions will be asked."
9309   (interactive "P")
9310   (when (gnus-summary-catchup all quietly nil 'fast)
9311     ;; Select next newsgroup or exit.
9312     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9313              (eq gnus-auto-select-next 'quietly))
9314         (gnus-summary-next-group nil)
9315       (gnus-summary-exit))))
9316
9317 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9318   "Mark all articles in this newsgroup as read, and then exit."
9319   (interactive "P")
9320   (gnus-summary-catchup-and-exit t quietly))
9321
9322 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9323   "Mark all articles in this group as read and select the next group.
9324 If given a prefix, mark all articles, unread as well as ticked, as
9325 read."
9326   (interactive "P")
9327   (save-excursion
9328     (gnus-summary-catchup all))
9329   (gnus-summary-next-group))
9330
9331 ;;;
9332 ;;; with article
9333 ;;;
9334
9335 (defmacro gnus-with-article (article &rest forms)
9336   "Select ARTICLE and perform FORMS in the original article buffer.
9337 Then replace the article with the result."
9338   `(progn
9339      ;; We don't want the article to be marked as read.
9340      (let (gnus-mark-article-hook)
9341        (gnus-summary-select-article t t nil ,article))
9342      (set-buffer gnus-original-article-buffer)
9343      ,@forms
9344      (if (not (gnus-check-backend-function
9345                'request-replace-article (car gnus-article-current)))
9346          (gnus-message 5 "Read-only group; not replacing")
9347        (unless (gnus-request-replace-article
9348                 ,article (car gnus-article-current)
9349                 (current-buffer) t)
9350          (error "Couldn't replace article")))
9351      ;; The cache and backlog have to be flushed somewhat.
9352      (when gnus-keep-backlog
9353        (gnus-backlog-remove-article
9354         (car gnus-article-current) (cdr gnus-article-current)))
9355      (when gnus-use-cache
9356        (gnus-cache-update-article
9357         (car gnus-article-current) (cdr gnus-article-current)))))
9358
9359 (put 'gnus-with-article 'lisp-indent-function 1)
9360 (put 'gnus-with-article 'edebug-form-spec '(form body))
9361
9362 ;; Thread-based commands.
9363
9364 (defun gnus-summary-articles-in-thread (&optional article)
9365   "Return a list of all articles in the current thread.
9366 If ARTICLE is non-nil, return all articles in the thread that starts
9367 with that article."
9368   (let* ((article (or article (gnus-summary-article-number)))
9369          (data (gnus-data-find-list article))
9370          (top-level (gnus-data-level (car data)))
9371          (top-subject
9372           (cond ((null gnus-thread-operation-ignore-subject)
9373                  (gnus-simplify-subject-re
9374                   (mail-header-subject (gnus-data-header (car data)))))
9375                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9376                  (gnus-simplify-subject-fuzzy
9377                   (mail-header-subject (gnus-data-header (car data)))))
9378                 (t nil)))
9379          (end-point (save-excursion
9380                       (if (gnus-summary-go-to-next-thread)
9381                           (point) (point-max))))
9382          articles)
9383     (while (and data
9384                 (< (gnus-data-pos (car data)) end-point))
9385       (when (or (not top-subject)
9386                 (string= top-subject
9387                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9388                              (gnus-simplify-subject-fuzzy
9389                               (mail-header-subject
9390                                (gnus-data-header (car data))))
9391                            (gnus-simplify-subject-re
9392                             (mail-header-subject
9393                              (gnus-data-header (car data)))))))
9394         (push (gnus-data-number (car data)) articles))
9395       (unless (and (setq data (cdr data))
9396                    (> (gnus-data-level (car data)) top-level))
9397         (setq data nil)))
9398     ;; Return the list of articles.
9399     (nreverse articles)))
9400
9401 (defun gnus-summary-rethread-current ()
9402   "Rethread the thread the current article is part of."
9403   (interactive)
9404   (let* ((gnus-show-threads t)
9405          (article (gnus-summary-article-number))
9406          (id (mail-header-id (gnus-summary-article-header)))
9407          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9408     (unless id
9409       (error "No article on the current line"))
9410     (gnus-rebuild-thread id)
9411     (gnus-summary-goto-subject article)))
9412
9413 (defun gnus-summary-reparent-thread ()
9414   "Make the current article child of the marked (or previous) article.
9415
9416 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9417 is non-nil or the Subject: of both articles are the same."
9418   (interactive)
9419   (unless (not (gnus-group-read-only-p))
9420     (error "The current newsgroup does not support article editing"))
9421   (unless (<= (length gnus-newsgroup-processable) 1)
9422     (error "No more than one article may be marked"))
9423   (save-window-excursion
9424     (let ((gnus-article-buffer " *reparent*")
9425           (current-article (gnus-summary-article-number))
9426           ;; First grab the marked article, otherwise one line up.
9427           (parent-article (if (not (null gnus-newsgroup-processable))
9428                               (car gnus-newsgroup-processable)
9429                             (save-excursion
9430                               (if (eq (forward-line -1) 0)
9431                                   (gnus-summary-article-number)
9432                                 (error "Beginning of summary buffer"))))))
9433       (unless (not (eq current-article parent-article))
9434         (error "An article may not be self-referential"))
9435       (let ((message-id (mail-header-id
9436                          (gnus-summary-article-header parent-article))))
9437         (unless (and message-id (not (equal message-id "")))
9438           (error "No message-id in desired parent"))
9439         (gnus-with-article current-article
9440           (save-restriction
9441             (goto-char (point-min))
9442             (message-narrow-to-head)
9443             (if (re-search-forward "^References: " nil t)
9444                 (progn
9445                   (re-search-forward "^[^ \t]" nil t)
9446                   (forward-line -1)
9447                   (end-of-line)
9448                   (insert " " message-id))
9449               (insert "References: " message-id "\n"))))
9450         (set-buffer gnus-summary-buffer)
9451         (gnus-summary-unmark-all-processable)
9452         (gnus-summary-update-article current-article)
9453         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9454             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9455         (gnus-summary-rethread-current)
9456         (gnus-message 3 "Article %d is now the child of article %d"
9457                       current-article parent-article)))))
9458
9459 (defun gnus-summary-toggle-threads (&optional arg)
9460   "Toggle showing conversation threads.
9461 If ARG is positive number, turn showing conversation threads on."
9462   (interactive "P")
9463   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9464     (setq gnus-show-threads
9465           (if (null arg) (not gnus-show-threads)
9466             (> (prefix-numeric-value arg) 0)))
9467     (gnus-summary-prepare)
9468     (gnus-summary-goto-subject current)
9469     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9470     (gnus-summary-position-point)))
9471
9472 (defun gnus-summary-show-all-threads ()
9473   "Show all threads."
9474   (interactive)
9475   (save-excursion
9476     (let ((buffer-read-only nil))
9477       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9478   (gnus-summary-position-point))
9479
9480 (defun gnus-summary-show-thread ()
9481   "Show thread subtrees.
9482 Returns nil if no thread was there to be shown."
9483   (interactive)
9484   (let ((buffer-read-only nil)
9485         (orig (point))
9486         ;; first goto end then to beg, to have point at beg after let
9487         (end (progn (end-of-line) (point)))
9488         (beg (progn (beginning-of-line) (point))))
9489     (prog1
9490         ;; Any hidden lines here?
9491         (search-forward "\r" end t)
9492       (subst-char-in-region beg end ?\^M ?\n t)
9493       (goto-char orig)
9494       (gnus-summary-position-point))))
9495
9496 (defun gnus-summary-hide-all-threads ()
9497   "Hide all thread subtrees."
9498   (interactive)
9499   (save-excursion
9500     (goto-char (point-min))
9501     (gnus-summary-hide-thread)
9502     (while (zerop (gnus-summary-next-thread 1 t))
9503       (gnus-summary-hide-thread)))
9504   (gnus-summary-position-point))
9505
9506 (defun gnus-summary-hide-thread ()
9507   "Hide thread subtrees.
9508 Returns nil if no threads were there to be hidden."
9509   (interactive)
9510   (let ((buffer-read-only nil)
9511         (start (point))
9512         (article (gnus-summary-article-number)))
9513     (goto-char start)
9514     ;; Go forward until either the buffer ends or the subthread
9515     ;; ends.
9516     (when (and (not (eobp))
9517                (or (zerop (gnus-summary-next-thread 1 t))
9518                    (goto-char (point-max))))
9519       (prog1
9520           (if (and (> (point) start)
9521                    (search-backward "\n" start t))
9522               (progn
9523                 (subst-char-in-region start (point) ?\n ?\^M)
9524                 (gnus-summary-goto-subject article))
9525             (goto-char start)
9526             nil)))))
9527
9528 (defun gnus-summary-go-to-next-thread (&optional previous)
9529   "Go to the same level (or less) next thread.
9530 If PREVIOUS is non-nil, go to previous thread instead.
9531 Return the article number moved to, or nil if moving was impossible."
9532   (let ((level (gnus-summary-thread-level))
9533         (way (if previous -1 1))
9534         (beg (point)))
9535     (forward-line way)
9536     (while (and (not (eobp))
9537                 (< level (gnus-summary-thread-level)))
9538       (forward-line way))
9539     (if (eobp)
9540         (progn
9541           (goto-char beg)
9542           nil)
9543       (setq beg (point))
9544       (prog1
9545           (gnus-summary-article-number)
9546         (goto-char beg)))))
9547
9548 (defun gnus-summary-next-thread (n &optional silent)
9549   "Go to the same level next N'th thread.
9550 If N is negative, search backward instead.
9551 Returns the difference between N and the number of skips actually
9552 done.
9553
9554 If SILENT, don't output messages."
9555   (interactive "p")
9556   (let ((backward (< n 0))
9557         (n (abs n)))
9558     (while (and (> n 0)
9559                 (gnus-summary-go-to-next-thread backward))
9560       (decf n))
9561     (unless silent
9562       (gnus-summary-position-point))
9563     (when (and (not silent) (/= 0 n))
9564       (gnus-message 7 "No more threads"))
9565     n))
9566
9567 (defun gnus-summary-prev-thread (n)
9568   "Go to the same level previous N'th thread.
9569 Returns the difference between N and the number of skips actually
9570 done."
9571   (interactive "p")
9572   (gnus-summary-next-thread (- n)))
9573
9574 (defun gnus-summary-go-down-thread ()
9575   "Go down one level in the current thread."
9576   (let ((children (gnus-summary-article-children)))
9577     (when children
9578       (gnus-summary-goto-subject (car children)))))
9579
9580 (defun gnus-summary-go-up-thread ()
9581   "Go up one level in the current thread."
9582   (let ((parent (gnus-summary-article-parent)))
9583     (when parent
9584       (gnus-summary-goto-subject parent))))
9585
9586 (defun gnus-summary-down-thread (n)
9587   "Go down thread N steps.
9588 If N is negative, go up instead.
9589 Returns the difference between N and how many steps down that were
9590 taken."
9591   (interactive "p")
9592   (let ((up (< n 0))
9593         (n (abs n)))
9594     (while (and (> n 0)
9595                 (if up (gnus-summary-go-up-thread)
9596                   (gnus-summary-go-down-thread)))
9597       (setq n (1- n)))
9598     (gnus-summary-position-point)
9599     (when (/= 0 n)
9600       (gnus-message 7 "Can't go further"))
9601     n))
9602
9603 (defun gnus-summary-up-thread (n)
9604   "Go up thread N steps.
9605 If N is negative, go down instead.
9606 Returns the difference between N and how many steps down that were
9607 taken."
9608   (interactive "p")
9609   (gnus-summary-down-thread (- n)))
9610
9611 (defun gnus-summary-top-thread ()
9612   "Go to the top of the thread."
9613   (interactive)
9614   (while (gnus-summary-go-up-thread))
9615   (gnus-summary-article-number))
9616
9617 (defun gnus-summary-kill-thread (&optional unmark)
9618   "Mark articles under current thread as read.
9619 If the prefix argument is positive, remove any kinds of marks.
9620 If the prefix argument is negative, tick articles instead."
9621   (interactive "P")
9622   (when unmark
9623     (setq unmark (prefix-numeric-value unmark)))
9624   (let ((articles (gnus-summary-articles-in-thread)))
9625     (save-excursion
9626       ;; Expand the thread.
9627       (gnus-summary-show-thread)
9628       ;; Mark all the articles.
9629       (while articles
9630         (gnus-summary-goto-subject (car articles))
9631         (cond ((null unmark)
9632                (gnus-summary-mark-article-as-read gnus-killed-mark))
9633               ((> unmark 0)
9634                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9635               (t
9636                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9637         (setq articles (cdr articles))))
9638     ;; Hide killed subtrees.
9639     (and (null unmark)
9640          gnus-thread-hide-killed
9641          (gnus-summary-hide-thread))
9642     ;; If marked as read, go to next unread subject.
9643     (when (null unmark)
9644       ;; Go to next unread subject.
9645       (gnus-summary-next-subject 1 t)))
9646   (gnus-set-mode-line 'summary))
9647
9648 ;; Summary sorting commands
9649
9650 (defun gnus-summary-sort-by-number (&optional reverse)
9651   "Sort the summary buffer by article number.
9652 Argument REVERSE means reverse order."
9653   (interactive "P")
9654   (gnus-summary-sort 'number reverse))
9655
9656 (defun gnus-summary-sort-by-author (&optional reverse)
9657   "Sort the summary buffer by author name alphabetically.
9658 If `case-fold-search' is non-nil, case of letters is ignored.
9659 Argument REVERSE means reverse order."
9660   (interactive "P")
9661   (gnus-summary-sort 'author reverse))
9662
9663 (defun gnus-summary-sort-by-subject (&optional reverse)
9664   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9665 If `case-fold-search' is non-nil, case of letters is ignored.
9666 Argument REVERSE means reverse order."
9667   (interactive "P")
9668   (gnus-summary-sort 'subject reverse))
9669
9670 (defun gnus-summary-sort-by-date (&optional reverse)
9671   "Sort the summary buffer by date.
9672 Argument REVERSE means reverse order."
9673   (interactive "P")
9674   (gnus-summary-sort 'date reverse))
9675
9676 (defun gnus-summary-sort-by-score (&optional reverse)
9677   "Sort the summary buffer by score.
9678 Argument REVERSE means reverse order."
9679   (interactive "P")
9680   (gnus-summary-sort 'score reverse))
9681
9682 (defun gnus-summary-sort-by-lines (&optional reverse)
9683   "Sort the summary buffer by the number of lines.
9684 Argument REVERSE means reverse order."
9685   (interactive "P")
9686   (gnus-summary-sort 'lines reverse))
9687
9688 (defun gnus-summary-sort-by-chars (&optional reverse)
9689   "Sort the summary buffer by article length.
9690 Argument REVERSE means reverse order."
9691   (interactive "P")
9692   (gnus-summary-sort 'chars reverse))
9693
9694 (defun gnus-summary-sort-by-original (&optional reverse)
9695   "Sort the summary buffer using the default sorting method.
9696 Argument REVERSE means reverse order."
9697   (interactive "P")
9698   (let* ((buffer-read-only)
9699          (gnus-summary-prepare-hook nil))
9700     ;; We do the sorting by regenerating the threads.
9701     (gnus-summary-prepare)
9702     ;; Hide subthreads if needed.
9703     (when (and gnus-show-threads gnus-thread-hide-subtree)
9704       (gnus-summary-hide-all-threads))))
9705
9706 (defun gnus-summary-sort (predicate reverse)
9707   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
9708   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9709          (article (intern (format "gnus-article-sort-by-%s" predicate)))
9710          (gnus-thread-sort-functions
9711           (if (not reverse)
9712               thread
9713             `(lambda (t1 t2)
9714                (,thread t2 t1))))
9715          (gnus-sort-gathered-threads-function
9716           gnus-thread-sort-functions)
9717          (gnus-article-sort-functions
9718           (if (not reverse)
9719               article
9720             `(lambda (t1 t2)
9721                (,article t2 t1))))
9722          (buffer-read-only)
9723          (gnus-summary-prepare-hook nil))
9724     ;; We do the sorting by regenerating the threads.
9725     (gnus-summary-prepare)
9726     ;; Hide subthreads if needed.
9727     (when (and gnus-show-threads gnus-thread-hide-subtree)
9728       (gnus-summary-hide-all-threads))))
9729
9730 ;; Summary saving commands.
9731
9732 (defun gnus-summary-save-article (&optional n not-saved)
9733   "Save the current article using the default saver function.
9734 If N is a positive number, save the N next articles.
9735 If N is a negative number, save the N previous articles.
9736 If N is nil and any articles have been marked with the process mark,
9737 save those articles instead.
9738 The variable `gnus-default-article-saver' specifies the saver function."
9739   (interactive "P")
9740   (let* ((articles (gnus-summary-work-articles n))
9741          (save-buffer (save-excursion
9742                         (nnheader-set-temp-buffer " *Gnus Save*")))
9743          (num (length articles))
9744          header file)
9745     (dolist (article articles)
9746       (setq header (gnus-summary-article-header article))
9747       (if (not (vectorp header))
9748           ;; This is a pseudo-article.
9749           (if (assq 'name header)
9750               (gnus-copy-file (cdr (assq 'name header)))
9751             (gnus-message 1 "Article %d is unsaveable" article))
9752         ;; This is a real article.
9753         (save-window-excursion
9754           (gnus-summary-select-article t nil nil article))
9755         (save-excursion
9756           (set-buffer save-buffer)
9757           (erase-buffer)
9758           (insert-buffer-substring gnus-original-article-buffer))
9759         (setq file (gnus-article-save save-buffer file num))
9760         (gnus-summary-remove-process-mark article)
9761         (unless not-saved
9762           (gnus-summary-set-saved-mark article))))
9763     (gnus-kill-buffer save-buffer)
9764     (gnus-summary-position-point)
9765     (gnus-set-mode-line 'summary)
9766     n))
9767
9768 (defun gnus-summary-pipe-output (&optional arg)
9769   "Pipe the current article to a subprocess.
9770 If N is a positive number, pipe the N next articles.
9771 If N is a negative number, pipe the N previous articles.
9772 If N is nil and any articles have been marked with the process mark,
9773 pipe those articles instead."
9774   (interactive "P")
9775   (require 'gnus-art)
9776   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
9777     (gnus-summary-save-article arg t))
9778   (let ((buffer (get-buffer "*Shell Command Output*")))
9779     (if (and buffer
9780              (with-current-buffer buffer (> (point-max) (point-min))))
9781         (gnus-configure-windows 'pipe))))
9782
9783 (defun gnus-summary-save-article-mail (&optional arg)
9784   "Append the current article to an mail file.
9785 If N is a positive number, save the N next articles.
9786 If N is a negative number, save the N previous articles.
9787 If N is nil and any articles have been marked with the process mark,
9788 save those articles instead."
9789   (interactive "P")
9790   (require 'gnus-art)
9791   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
9792     (gnus-summary-save-article arg)))
9793
9794 (defun gnus-summary-save-article-rmail (&optional arg)
9795   "Append the current article to an rmail file.
9796 If N is a positive number, save the N next articles.
9797 If N is a negative number, save the N previous articles.
9798 If N is nil and any articles have been marked with the process mark,
9799 save those articles instead."
9800   (interactive "P")
9801   (require 'gnus-art)
9802   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
9803     (gnus-summary-save-article arg)))
9804
9805 (defun gnus-summary-save-article-file (&optional arg)
9806   "Append the current article to a file.
9807 If N is a positive number, save the N next articles.
9808 If N is a negative number, save the N previous articles.
9809 If N is nil and any articles have been marked with the process mark,
9810 save those articles instead."
9811   (interactive "P")
9812   (require 'gnus-art)
9813   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
9814     (gnus-summary-save-article arg)))
9815
9816 (defun gnus-summary-write-article-file (&optional arg)
9817   "Write the current article to a file, deleting the previous file.
9818 If N is a positive number, save the N next articles.
9819 If N is a negative number, save the N previous articles.
9820 If N is nil and any articles have been marked with the process mark,
9821 save those articles instead."
9822   (interactive "P")
9823   (require 'gnus-art)
9824   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
9825     (gnus-summary-save-article arg)))
9826
9827 (defun gnus-summary-save-article-body-file (&optional arg)
9828   "Append the current article body to a file.
9829 If N is a positive number, save the N next articles.
9830 If N is a negative number, save the N previous articles.
9831 If N is nil and any articles have been marked with the process mark,
9832 save those articles instead."
9833   (interactive "P")
9834   (require 'gnus-art)
9835   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
9836     (gnus-summary-save-article arg)))
9837
9838 (defun gnus-summary-pipe-message (program)
9839   "Pipe the current article through PROGRAM."
9840   (interactive "sProgram: ")
9841   (gnus-summary-select-article)
9842   (let ((mail-header-separator ""))
9843     (gnus-eval-in-buffer-window gnus-article-buffer
9844       (save-restriction
9845         (widen)
9846         (let ((start (window-start))
9847               buffer-read-only)
9848           (message-pipe-buffer-body program)
9849           (set-window-start (get-buffer-window (current-buffer)) start))))))
9850
9851 (defun gnus-get-split-value (methods)
9852   "Return a value based on the split METHODS."
9853   (let (split-name method result match)
9854     (when methods
9855       (save-excursion
9856         (set-buffer gnus-original-article-buffer)
9857         (save-restriction
9858           (nnheader-narrow-to-headers)
9859           (while (and methods (not split-name))
9860             (goto-char (point-min))
9861             (setq method (pop methods))
9862             (setq match (car method))
9863             (when (cond
9864                    ((stringp match)
9865                     ;; Regular expression.
9866                     (ignore-errors
9867                       (re-search-forward match nil t)))
9868                    ((gnus-functionp match)
9869                     ;; Function.
9870                     (save-restriction
9871                       (widen)
9872                       (setq result (funcall match gnus-newsgroup-name))))
9873                    ((consp match)
9874                     ;; Form.
9875                     (save-restriction
9876                       (widen)
9877                       (setq result (eval match)))))
9878               (setq split-name (cdr method))
9879               (cond ((stringp result)
9880                      (push (expand-file-name
9881                             result gnus-article-save-directory)
9882                            split-name))
9883                     ((consp result)
9884                      (setq split-name (append result split-name)))))))))
9885     (nreverse split-name)))
9886
9887 (defun gnus-valid-move-group-p (group)
9888   (and (boundp group)
9889        (symbol-name group)
9890        (symbol-value group)
9891        (gnus-get-function (gnus-find-method-for-group
9892                            (symbol-name group)) 'request-accept-article t)))
9893
9894 (defun gnus-read-move-group-name (prompt default articles prefix)
9895   "Read a group name."
9896   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
9897          (minibuffer-confirm-incomplete nil) ; XEmacs
9898          (prom
9899           (format "%s %s to:"
9900                   prompt
9901                   (if (> (length articles) 1)
9902                       (format "these %d articles" (length articles))
9903                     "this article")))
9904          (to-newsgroup
9905           (cond
9906            ((null split-name)
9907             (gnus-completing-read default prom
9908                                   gnus-active-hashtb
9909                                   'gnus-valid-move-group-p
9910                                   nil prefix
9911                                   'gnus-group-history))
9912            ((= 1 (length split-name))
9913             (gnus-completing-read (car split-name) prom
9914                                   gnus-active-hashtb
9915                                   'gnus-valid-move-group-p
9916                                   nil nil
9917                                   'gnus-group-history))
9918            (t
9919             (gnus-completing-read nil prom
9920                                   (mapcar (lambda (el) (list el))
9921                                           (nreverse split-name))
9922                                   nil nil nil
9923                                   'gnus-group-history))))
9924          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
9925     (when to-newsgroup
9926       (if (or (string= to-newsgroup "")
9927               (string= to-newsgroup prefix))
9928           (setq to-newsgroup default))
9929       (unless to-newsgroup
9930         (error "No group name entered"))
9931       (or (gnus-active to-newsgroup)
9932           (gnus-activate-group to-newsgroup nil nil to-method)
9933           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
9934                                      to-newsgroup))
9935               (or (and (gnus-request-create-group to-newsgroup to-method)
9936                        (gnus-activate-group
9937                         to-newsgroup nil nil to-method)
9938                        (gnus-subscribe-group to-newsgroup))
9939                   (error "Couldn't create group %s" to-newsgroup)))
9940           (error "No such group: %s" to-newsgroup)))
9941     to-newsgroup))
9942
9943 (defun gnus-summary-save-parts (type dir n &optional reverse)
9944   "Save parts matching TYPE to DIR.
9945 If REVERSE, save parts that do not match TYPE."
9946   (interactive
9947    (list (read-string "Save parts of type: "
9948                       (or (car gnus-summary-save-parts-type-history)
9949                           gnus-summary-save-parts-default-mime)
9950                       'gnus-summary-save-parts-type-history)
9951          (setq gnus-summary-save-parts-last-directory
9952                (read-file-name "Save to directory: "
9953                                gnus-summary-save-parts-last-directory
9954                                nil t))
9955          current-prefix-arg))
9956   (gnus-summary-iterate n
9957     (let ((gnus-display-mime-function nil)
9958           (gnus-inhibit-treatment t))
9959       (gnus-summary-select-article))
9960     (save-excursion
9961       (set-buffer gnus-article-buffer)
9962       (let ((handles (or gnus-article-mime-handles
9963                          (mm-dissect-buffer) (mm-uu-dissect))))
9964         (when handles
9965           (gnus-summary-save-parts-1 type dir handles reverse)
9966           (unless gnus-article-mime-handles ;; Don't destroy this case.
9967             (mm-destroy-parts handles)))))))
9968
9969 (defun gnus-summary-save-parts-1 (type dir handle reverse)
9970   (if (stringp (car handle))
9971       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
9972               (cdr handle))
9973     (when (if reverse
9974               (not (string-match type (mm-handle-media-type handle)))
9975             (string-match type (mm-handle-media-type handle)))
9976       (let ((file (expand-file-name
9977                    (file-name-nondirectory
9978                     (or
9979                      (mail-content-type-get
9980                       (mm-handle-disposition handle) 'filename)
9981                      (concat gnus-newsgroup-name
9982                              "." (number-to-string
9983                                   (cdr gnus-article-current)))))
9984                    dir)))
9985         (unless (file-exists-p file)
9986           (mm-save-part-to-file handle file))))))
9987
9988 ;; Summary extract commands
9989
9990 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
9991   (let ((buffer-read-only nil)
9992         (article (gnus-summary-article-number))
9993         after-article b e)
9994     (unless (gnus-summary-goto-subject article)
9995       (error "No such article: %d" article))
9996     (gnus-summary-position-point)
9997     ;; If all commands are to be bunched up on one line, we collect
9998     ;; them here.
9999     (unless gnus-view-pseudos-separately
10000       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10001             files action)
10002         (while ps
10003           (setq action (cdr (assq 'action (car ps))))
10004           (setq files (list (cdr (assq 'name (car ps)))))
10005           (while (and ps (cdr ps)
10006                       (string= (or action "1")
10007                                (or (cdr (assq 'action (cadr ps))) "2")))
10008             (push (cdr (assq 'name (cadr ps))) files)
10009             (setcdr ps (cddr ps)))
10010           (when files
10011             (when (not (string-match "%s" action))
10012               (push " " files))
10013             (push " " files)
10014             (when (assq 'execute (car ps))
10015               (setcdr (assq 'execute (car ps))
10016                       (funcall (if (string-match "%s" action)
10017                                    'format 'concat)
10018                                action
10019                                (mapconcat
10020                                 (lambda (f)
10021                                   (if (equal f " ")
10022                                       f
10023                                     (gnus-quote-arg-for-sh-or-csh f)))
10024                                 files " ")))))
10025           (setq ps (cdr ps)))))
10026     (if (and gnus-view-pseudos (not not-view))
10027         (while pslist
10028           (when (assq 'execute (car pslist))
10029             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10030                                   (eq gnus-view-pseudos 'not-confirm)))
10031           (setq pslist (cdr pslist)))
10032       (save-excursion
10033         (while pslist
10034           (setq after-article (or (cdr (assq 'article (car pslist)))
10035                                   (gnus-summary-article-number)))
10036           (gnus-summary-goto-subject after-article)
10037           (forward-line 1)
10038           (setq b (point))
10039           (insert "    " (file-name-nondirectory
10040                           (cdr (assq 'name (car pslist))))
10041                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10042           (setq e (point))
10043           (forward-line -1)             ; back to `b'
10044           (gnus-add-text-properties
10045            b (1- e) (list 'gnus-number gnus-reffed-article-number
10046                           gnus-mouse-face-prop gnus-mouse-face))
10047           (gnus-data-enter
10048            after-article gnus-reffed-article-number
10049            gnus-unread-mark b (car pslist) 0 (- e b))
10050           (push gnus-reffed-article-number gnus-newsgroup-unreads)
10051           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10052           (setq pslist (cdr pslist)))))))
10053
10054 (defun gnus-pseudos< (p1 p2)
10055   (let ((c1 (cdr (assq 'action p1)))
10056         (c2 (cdr (assq 'action p2))))
10057     (and c1 c2 (string< c1 c2))))
10058
10059 (defun gnus-request-pseudo-article (props)
10060   (cond ((assq 'execute props)
10061          (gnus-execute-command (cdr (assq 'execute props)))))
10062   (let ((gnus-current-article (gnus-summary-article-number)))
10063     (gnus-run-hooks 'gnus-mark-article-hook)))
10064
10065 (defun gnus-execute-command (command &optional automatic)
10066   (save-excursion
10067     (gnus-article-setup-buffer)
10068     (set-buffer gnus-article-buffer)
10069     (setq buffer-read-only nil)
10070     (let ((command (if automatic command
10071                      (read-string "Command: " (cons command 0)))))
10072       (erase-buffer)
10073       (insert "$ " command "\n\n")
10074       (if gnus-view-pseudo-asynchronously
10075           (start-process "gnus-execute" (current-buffer) shell-file-name
10076                          shell-command-switch command)
10077         (call-process shell-file-name nil t nil
10078                       shell-command-switch command)))))
10079
10080 ;; Summary kill commands.
10081
10082 (defun gnus-summary-edit-global-kill (article)
10083   "Edit the \"global\" kill file."
10084   (interactive (list (gnus-summary-article-number)))
10085   (gnus-group-edit-global-kill article))
10086
10087 (defun gnus-summary-edit-local-kill ()
10088   "Edit a local kill file applied to the current newsgroup."
10089   (interactive)
10090   (setq gnus-current-headers (gnus-summary-article-header))
10091   (gnus-group-edit-local-kill
10092    (gnus-summary-article-number) gnus-newsgroup-name))
10093
10094 ;;; Header reading.
10095
10096 (defun gnus-read-header (id &optional header)
10097   "Read the headers of article ID and enter them into the Gnus system."
10098   (let ((group gnus-newsgroup-name)
10099         (gnus-override-method
10100          (or
10101           gnus-override-method
10102           (and (gnus-news-group-p gnus-newsgroup-name)
10103                (car (gnus-refer-article-methods)))))
10104         where)
10105     ;; First we check to see whether the header in question is already
10106     ;; fetched.
10107     (if (stringp id)
10108         ;; This is a Message-ID.
10109         (setq header (or header (gnus-id-to-header id)))
10110       ;; This is an article number.
10111       (setq header (or header (gnus-summary-article-header id))))
10112     (if (and header
10113              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10114         ;; We have found the header.
10115         header
10116       ;; If this is a sparse article, we have to nix out its
10117       ;; previous entry in the thread hashtb.
10118       (when (and header
10119                  (gnus-summary-article-sparse-p (mail-header-number header)))
10120         (let* ((parent (gnus-parent-id (mail-header-references header)))
10121                (thread (and parent (gnus-id-to-thread parent))))
10122           (when thread
10123             (delq (assq header thread) thread))))
10124       ;; We have to really fetch the header to this article.
10125       (save-excursion
10126         (set-buffer nntp-server-buffer)
10127         (when (setq where (gnus-request-head id group))
10128           (nnheader-fold-continuation-lines)
10129           (goto-char (point-max))
10130           (insert ".\n")
10131           (goto-char (point-min))
10132           (insert "211 ")
10133           (princ (cond
10134                   ((numberp id) id)
10135                   ((cdr where) (cdr where))
10136                   (header (mail-header-number header))
10137                   (t gnus-reffed-article-number))
10138                  (current-buffer))
10139           (insert " Article retrieved.\n"))
10140         (if (or (not where)
10141                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10142             ()                          ; Malformed head.
10143           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10144             (when (and (stringp id)
10145                        (not (string= (gnus-group-real-name group)
10146                                      (car where))))
10147               ;; If we fetched by Message-ID and the article came
10148               ;; from a different group, we fudge some bogus article
10149               ;; numbers for this article.
10150               (mail-header-set-number header gnus-reffed-article-number))
10151             (save-excursion
10152               (set-buffer gnus-summary-buffer)
10153               (decf gnus-reffed-article-number)
10154               (gnus-remove-header (mail-header-number header))
10155               (push header gnus-newsgroup-headers)
10156               (setq gnus-current-headers header)
10157               (push (mail-header-number header) gnus-newsgroup-limit)))
10158           header)))))
10159
10160 (defun gnus-remove-header (number)
10161   "Remove header NUMBER from `gnus-newsgroup-headers'."
10162   (if (and gnus-newsgroup-headers
10163            (= number (mail-header-number (car gnus-newsgroup-headers))))
10164       (pop gnus-newsgroup-headers)
10165     (let ((headers gnus-newsgroup-headers))
10166       (while (and (cdr headers)
10167                   (not (= number (mail-header-number (cadr headers)))))
10168         (pop headers))
10169       (when (cdr headers)
10170         (setcdr headers (cddr headers))))))
10171
10172 ;;;
10173 ;;; summary highlights
10174 ;;;
10175
10176 (defun gnus-highlight-selected-summary ()
10177   "Highlight selected article in summary buffer."
10178   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10179   (when gnus-summary-selected-face
10180     (save-excursion
10181       (let* ((beg (progn (beginning-of-line) (point)))
10182              (end (progn (end-of-line) (point)))
10183              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10184              (from (if (get-text-property beg gnus-mouse-face-prop)
10185                        beg
10186                      (or (next-single-property-change
10187                           beg gnus-mouse-face-prop nil end)
10188                          beg)))
10189              (to
10190               (if (= from end)
10191                   (- from 2)
10192                 (or (next-single-property-change
10193                      from gnus-mouse-face-prop nil end)
10194                     end))))
10195         ;; If no mouse-face prop on line we will have to = from = end,
10196         ;; so we highlight the entire line instead.
10197         (when (= (+ to 2) from)
10198           (setq from beg)
10199           (setq to end))
10200         (if gnus-newsgroup-selected-overlay
10201             ;; Move old overlay.
10202             (gnus-move-overlay
10203              gnus-newsgroup-selected-overlay from to (current-buffer))
10204           ;; Create new overlay.
10205           (gnus-overlay-put
10206            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10207            'face gnus-summary-selected-face))))))
10208
10209 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10210 (defun gnus-summary-highlight-line ()
10211   "Highlight current line according to `gnus-summary-highlight'."
10212   (let* ((list gnus-summary-highlight)
10213          (p (point))
10214          (end (progn (end-of-line) (point)))
10215          ;; now find out where the line starts and leave point there.
10216          (beg (progn (beginning-of-line) (point)))
10217          (article (gnus-summary-article-number))
10218          (score (or (cdr (assq (or article gnus-current-article)
10219                                gnus-newsgroup-scored))
10220                     gnus-summary-default-score 0))
10221          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10222          (inhibit-read-only t))
10223     ;; Eval the cars of the lists until we find a match.
10224     (let ((default gnus-summary-default-score)
10225           (default-high gnus-summary-default-high-score)
10226           (default-low gnus-summary-default-low-score))
10227       (while (and list
10228                   (not (eval (caar list))))
10229         (setq list (cdr list))))
10230     (let ((face (cdar list)))
10231       (unless (eq face (get-text-property beg 'face))
10232         (gnus-put-text-property-excluding-characters-with-faces
10233          beg end 'face
10234          (setq face (if (boundp face) (symbol-value face) face)))
10235         (when gnus-summary-highlight-line-function
10236           (funcall gnus-summary-highlight-line-function article face))))
10237     (goto-char p)))
10238
10239 (defun gnus-update-read-articles (group unread &optional compute)
10240   "Update the list of read articles in GROUP."
10241   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10242          (entry (gnus-gethash group gnus-newsrc-hashtb))
10243          (info (nth 2 entry))
10244          (prev 1)
10245          (unread (sort (copy-sequence unread) '<))
10246          read)
10247     (if (or (not info) (not active))
10248         ;; There is no info on this group if it was, in fact,
10249         ;; killed.  Gnus stores no information on killed groups, so
10250         ;; there's nothing to be done.
10251         ;; One could store the information somewhere temporarily,
10252         ;; perhaps...  Hmmm...
10253         ()
10254       ;; Remove any negative articles numbers.
10255       (while (and unread (< (car unread) 0))
10256         (setq unread (cdr unread)))
10257       ;; Remove any expired article numbers
10258       (while (and unread (< (car unread) (car active)))
10259         (setq unread (cdr unread)))
10260       ;; Compute the ranges of read articles by looking at the list of
10261       ;; unread articles.
10262       (while unread
10263         (when (/= (car unread) prev)
10264           (push (if (= prev (1- (car unread))) prev
10265                   (cons prev (1- (car unread))))
10266                 read))
10267         (setq prev (1+ (car unread)))
10268         (setq unread (cdr unread)))
10269       (when (<= prev (cdr active))
10270         (push (cons prev (cdr active)) read))
10271       (setq read (if (> (length read) 1) (nreverse read) read))
10272       (if compute
10273           read
10274         (save-excursion
10275           (let (setmarkundo)
10276             ;; Propagate the read marks to the backend.
10277             (when (gnus-check-backend-function 'request-set-mark group)
10278               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10279                     (add (gnus-remove-from-range read (gnus-info-read info))))
10280                 (when (or add del)
10281                   (unless (gnus-check-group group)
10282                     (error "Can't open server for %s" group))
10283                   (gnus-request-set-mark
10284                    group (delq nil (list (if add (list add 'add '(read)))
10285                                          (if del (list del 'del '(read))))))
10286                   (setq setmarkundo
10287                         `(gnus-request-set-mark
10288                           ,group
10289                           ',(delq nil (list
10290                                        (if del (list del 'add '(read)))
10291                                        (if add (list add 'del '(read))))))))))
10292             (set-buffer gnus-group-buffer)
10293             (gnus-undo-register
10294               `(progn
10295                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10296                  (gnus-info-set-read ',info ',(gnus-info-read info))
10297                  (gnus-get-unread-articles-in-group ',info
10298                                                     (gnus-active ,group))
10299                  (gnus-group-update-group ,group t)
10300                  ,setmarkundo))))
10301         ;; Enter this list into the group info.
10302         (gnus-info-set-read info read)
10303         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10304         (gnus-get-unread-articles-in-group info (gnus-active group))
10305         t))))
10306
10307 (defun gnus-offer-save-summaries ()
10308   "Offer to save all active summary buffers."
10309   (let (buffers)
10310     ;; Go through all buffers and find all summaries.
10311     (dolist (buffer (buffer-list))
10312       (when (and (setq buffer (buffer-name buffer))
10313                  (string-match "Summary" buffer)
10314                  (save-excursion
10315                    (set-buffer buffer)
10316                    ;; We check that this is, indeed, a summary buffer.
10317                    (and (eq major-mode 'gnus-summary-mode)
10318                         ;; Also make sure this isn't bogus.
10319                         gnus-newsgroup-prepared
10320                         ;; Also make sure that this isn't a
10321                         ;; dead summary buffer.
10322                         (not gnus-dead-summary-mode))))
10323         (push buffer buffers)))
10324     ;; Go through all these summary buffers and offer to save them.
10325     (when buffers
10326       (save-excursion
10327         (map-y-or-n-p
10328          "Update summary buffer %s? "
10329          (lambda (buf)
10330            (switch-to-buffer buf)
10331            (gnus-summary-exit))
10332          buffers)))))
10333
10334
10335 ;;; @ for mime-partial
10336 ;;;
10337
10338 (defun gnus-request-partial-message ()
10339   (save-excursion
10340     (let ((number (gnus-summary-article-number))
10341           (group gnus-newsgroup-name)
10342           (mother gnus-article-buffer))
10343       (set-buffer (get-buffer-create " *Partial Article*"))
10344       (erase-buffer)
10345       (setq mime-preview-buffer mother)
10346       (gnus-request-article-this-buffer number group)
10347       (mime-parse-buffer)
10348       )))
10349
10350 (autoload 'mime-combine-message/partial-pieces-automatically
10351   "mime-partial"
10352   "Internal method to combine message/partial messages automatically.")
10353
10354 (mime-add-condition
10355  'action '((type . message)(subtype . partial)
10356            (major-mode . gnus-original-article-mode)
10357            (method . mime-combine-message/partial-pieces-automatically)
10358            (summary-buffer-exp . gnus-summary-buffer)
10359            (request-partial-message-method . gnus-request-partial-message)
10360            ))
10361
10362
10363 ;;; @ for message/rfc822
10364 ;;;
10365
10366 (defun gnus-mime-extract-message/rfc822 (entity situation)
10367   (let (group article num cwin swin cur)
10368     (with-temp-buffer
10369       (mime-insert-entity-content entity)
10370       (setq group (or (cdr (assq 'group situation))
10371                       (completing-read "Group: "
10372                                        gnus-active-hashtb
10373                                        nil
10374                                        (gnus-read-active-file-p)
10375                                        gnus-newsgroup-name))
10376             article (gnus-request-accept-article group)))
10377     (when (and (consp article)
10378                (numberp (setq article (cdr article))))
10379       (setq num (1+ (or (cdr (assq 'number situation)) 0))
10380             cwin (get-buffer-window (current-buffer) t))
10381       (save-window-excursion
10382         (if (setq swin (get-buffer-window gnus-summary-buffer t))
10383             (select-window swin)
10384           (set-buffer gnus-summary-buffer))
10385         (setq cur gnus-current-article)
10386         (forward-line num)
10387         (let (gnus-show-threads)
10388           (gnus-summary-goto-subject article t))
10389         (gnus-summary-clear-mark-forward 1)
10390         (gnus-summary-goto-subject cur))
10391       (when (and cwin (window-frame cwin))
10392         (select-frame (window-frame cwin)))
10393       (when (boundp 'mime-acting-situation-to-override)
10394         (set-alist 'mime-acting-situation-to-override
10395                    'group
10396                    group)
10397         (set-alist 'mime-acting-situation-to-override
10398                    'after-method
10399                    `(progn
10400                       (save-current-buffer
10401                         (set-buffer gnus-group-buffer)
10402                         (gnus-activate-group ,group))
10403                       (gnus-summary-goto-article ,cur
10404                                                  gnus-show-all-headers)))
10405         (set-alist 'mime-acting-situation-to-override
10406                    'number num)))))
10407
10408 (mime-add-condition
10409  'action '((type . message)(subtype . rfc822)
10410            (major-mode . gnus-original-article-mode)
10411            (method . gnus-mime-extract-message/rfc822)
10412            (mode . "extract")
10413            ))
10414
10415 (mime-add-condition
10416  'action '((type . message)(subtype . news)
10417            (major-mode . gnus-original-article-mode)
10418            (method . gnus-mime-extract-message/rfc822)
10419            (mode . "extract")
10420            ))
10421
10422 (defun gnus-mime-extract-multipart (entity situation)
10423   (let ((children (mime-entity-children entity))
10424         mime-acting-situation-to-override
10425         f)
10426     (while children
10427       (mime-play-entity (car children)
10428                         (cons (assq 'mode situation)
10429                               mime-acting-situation-to-override))
10430       (setq children (cdr children)))
10431     (if (setq f (cdr (assq 'after-method
10432                            mime-acting-situation-to-override)))
10433         (eval f)
10434       )))
10435
10436 (mime-add-condition
10437  'action '((type . multipart)
10438            (method . gnus-mime-extract-multipart)
10439            (mode . "extract")
10440            )
10441  'with-default)
10442
10443
10444 ;;; @ end
10445 ;;;
10446
10447 (defun gnus-summary-setup-default-charset ()
10448   "Setup newsgroup default charset."
10449   (if (equal gnus-newsgroup-name "nndraft:drafts")
10450       (setq gnus-newsgroup-charset nil)
10451     (let* ((ignored-charsets
10452             (or gnus-newsgroup-ephemeral-ignored-charsets
10453                 (append
10454                  (and gnus-newsgroup-name
10455                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10456                  gnus-newsgroup-ignored-charsets))))
10457       (setq gnus-newsgroup-charset
10458             (or gnus-newsgroup-ephemeral-charset
10459                 (and gnus-newsgroup-name
10460                      (gnus-parameter-charset gnus-newsgroup-name))
10461                 gnus-default-charset))
10462       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10463            ignored-charsets))))
10464
10465 ;;;
10466 ;;; Mime Commands
10467 ;;;
10468
10469 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10470   "Display the current article buffer fully MIME-buttonized.
10471 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10472 treated as multipart/mixed."
10473   (interactive "P")
10474   (require 'gnus-art)
10475   (let ((gnus-unbuttonized-mime-types nil)
10476         (gnus-mime-display-multipart-as-mixed show-all-parts))
10477     (gnus-summary-show-article)))
10478
10479 (defun gnus-summary-repair-multipart (article)
10480   "Add a Content-Type header to a multipart article without one."
10481   (interactive (list (gnus-summary-article-number)))
10482   (gnus-with-article article
10483     (message-narrow-to-head)
10484     (message-remove-header "Mime-Version")
10485     (goto-char (point-max))
10486     (insert "Mime-Version: 1.0\n")
10487     (widen)
10488     (when (search-forward "\n--" nil t)
10489       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10490         (message-narrow-to-head)
10491         (message-remove-header "Content-Type")
10492         (goto-char (point-max))
10493         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10494                         separator))
10495         (widen))))
10496   (let (gnus-mark-article-hook)
10497     (gnus-summary-select-article t t nil article)))
10498
10499 (defun gnus-summary-toggle-display-buttonized ()
10500   "Toggle the buttonizing of the article buffer."
10501   (interactive)
10502   (require 'gnus-art)
10503   (if (setq gnus-inhibit-mime-unbuttonizing
10504             (not gnus-inhibit-mime-unbuttonizing))
10505       (let ((gnus-unbuttonized-mime-types nil))
10506         (gnus-summary-show-article))
10507     (gnus-summary-show-article)))
10508
10509 ;;;
10510 ;;; Intelli-mouse commmands
10511 ;;;
10512
10513 (defun gnus-wheel-summary-scroll (event)
10514   (interactive "e")
10515   (let ((amount (if (memq 'shift (event-modifiers event))
10516                     (car gnus-wheel-scroll-amount)
10517                   (cdr gnus-wheel-scroll-amount)))
10518         (direction (- (* (static-if (featurep 'xemacs)
10519                              (event-button event)
10520                            (cond ((eq 'mouse-4 (event-basic-type event))
10521                                   4)
10522                                  ((eq 'mouse-5 (event-basic-type event))
10523                                   5)))
10524                          2) 9))
10525         edge)
10526     (gnus-summary-scroll-up (* amount direction))
10527     (when (gnus-eval-in-buffer-window gnus-article-buffer
10528             (save-restriction
10529               (widen)
10530               (and (if (< 0 direction)
10531                        (gnus-article-next-page 0)
10532                      (gnus-article-prev-page 0)
10533                      (bobp))
10534                    (if (setq edge (get-text-property
10535                                    (point-min) 'gnus-wheel-edge))
10536                        (setq edge (* edge direction))
10537                      (setq edge -1))
10538                    (or (plusp edge)
10539                        (let ((buffer-read-only nil)
10540                              (inhibit-read-only t))
10541                          (put-text-property (point-min) (point-max)
10542                                             'gnus-wheel-edge direction)
10543                          nil))
10544                    (or (> edge gnus-wheel-edge-resistance)
10545                        (let ((buffer-read-only nil)
10546                              (inhibit-read-only t))
10547                          (put-text-property (point-min) (point-max)
10548                                             'gnus-wheel-edge
10549                                             (* (1+ edge) direction))
10550                          nil))
10551                    (eq last-command 'gnus-wheel-summary-scroll))))
10552       (gnus-summary-next-article nil nil (minusp direction)))))
10553
10554 (defun gnus-wheel-install ()
10555   "Enable mouse wheel support on summary window."
10556   (when gnus-use-wheel
10557     (let ((keys
10558            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
10559       (dolist (key keys)
10560         (define-key gnus-summary-mode-map key
10561           'gnus-wheel-summary-scroll)))))
10562
10563 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
10564
10565 ;;;
10566 ;;; Traditional PGP commmands
10567 ;;;
10568
10569 (defun gnus-summary-decrypt-article (&optional force)
10570   "Decrypt the current article in traditional PGP way.
10571 This will have permanent effect only in mail groups.
10572 If FORCE is non-nil, allow editing of articles even in read-only
10573 groups."
10574   (interactive "P")
10575   (gnus-summary-select-article t)
10576   (gnus-eval-in-buffer-window gnus-article-buffer
10577     (save-excursion
10578       (save-restriction
10579         (widen)
10580         (goto-char (point-min))
10581         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
10582           (error "Not a traditional PGP message!"))
10583         (let ((armor-start (match-beginning 0)))
10584           (if (and (pgg-decrypt-region armor-start (point-max))
10585                    (or force (not (gnus-group-read-only-p))))
10586               (let ((inhibit-read-only t)
10587                     buffer-read-only)
10588                 (delete-region armor-start
10589                                (progn
10590                                  (re-search-forward "^-+END PGP" nil t)
10591                                  (beginning-of-line 2)
10592                                  (point)))
10593                 (insert-buffer-substring pgg-output-buffer))))))))
10594
10595 (defun gnus-summary-verify-article ()
10596   "Verify the current article in traditional PGP way."
10597   (interactive)
10598   (save-excursion
10599     (set-buffer gnus-original-article-buffer)
10600     (goto-char (point-min))
10601     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
10602       (error "Not a traditional PGP message!"))
10603     (re-search-forward "^-+END PGP" nil t)
10604     (beginning-of-line 2)
10605     (call-interactively (function pgg-verify-region))))
10606
10607 ;;;
10608 ;;; Generic summary marking commands
10609 ;;;
10610
10611 (defvar gnus-summary-marking-alist
10612   '((read gnus-del-mark "d")
10613     (unread gnus-unread-mark "u")
10614     (ticked gnus-ticked-mark "!")
10615     (dormant gnus-dormant-mark "?")
10616     (expirable gnus-expirable-mark "e"))
10617   "An alist of names/marks/keystrokes.")
10618
10619 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10620 (defvar gnus-summary-mark-map)
10621
10622 (defun gnus-summary-make-all-marking-commands ()
10623   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10624   (dolist (elem gnus-summary-marking-alist)
10625     (apply 'gnus-summary-make-marking-command elem)))
10626
10627 (defun gnus-summary-make-marking-command (name mark keystroke)
10628   (let ((map (make-sparse-keymap)))
10629     (define-key gnus-summary-generic-mark-map keystroke map)
10630     (dolist (lway `((next "next" next nil "n")
10631                     (next-unread "next unread" next t "N")
10632                     (prev "previous" prev nil "p")
10633                     (prev-unread "previous unread" prev t "P")
10634                     (nomove "" nil nil ,keystroke)))
10635       (let ((func (gnus-summary-make-marking-command-1
10636                    mark (car lway) lway name)))
10637         (setq func (eval func))
10638         (define-key map (nth 4 lway) func)))))
10639
10640 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10641   `(defun ,(intern
10642             (format "gnus-summary-put-mark-as-%s%s"
10643                     name (if (eq way 'nomove)
10644                              ""
10645                            (concat "-" (symbol-name way)))))
10646      (n)
10647      ,(format
10648        "Mark the current article as %s%s.
10649 If N, the prefix, then repeat N times.
10650 If N is negative, move in reverse order.
10651 The difference between N and the actual number of articles marked is
10652 returned."
10653        name (car (cdr lway)))
10654      (interactive "p")
10655      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10656
10657 (defun gnus-summary-generic-mark (n mark move unread)
10658   "Mark N articles with MARK."
10659   (unless (eq major-mode 'gnus-summary-mode)
10660     (error "This command can only be used in the summary buffer"))
10661   (gnus-summary-show-thread)
10662   (let ((nummove
10663          (cond
10664           ((eq move 'next) 1)
10665           ((eq move 'prev) -1)
10666           (t 0))))
10667     (if (zerop nummove)
10668         (setq n 1)
10669       (when (< n 0)
10670         (setq n (abs n)
10671               nummove (* -1 nummove))))
10672     (while (and (> n 0)
10673                 (gnus-summary-mark-article nil mark)
10674                 (zerop (gnus-summary-next-subject nummove unread t)))
10675       (setq n (1- n)))
10676     (when (/= 0 n)
10677       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10678     (gnus-summary-recenter)
10679     (gnus-summary-position-point)
10680     (gnus-set-mode-line 'summary)
10681     n))
10682
10683 (defun gnus-summary-insert-articles (articles)
10684   (when (setq articles
10685               (gnus-set-difference articles
10686                                    (mapcar (lambda (h) (mail-header-number h))
10687                                            gnus-newsgroup-headers)))
10688     (setq gnus-newsgroup-headers
10689           (merge 'list
10690                  gnus-newsgroup-headers
10691                  (gnus-fetch-headers articles)
10692                  'gnus-article-sort-by-number))
10693     ;; Suppress duplicates?
10694     (when gnus-suppress-duplicates
10695       (gnus-dup-suppress-articles))
10696
10697     ;; We might want to build some more threads first.
10698     (when (and gnus-fetch-old-headers
10699                (eq gnus-headers-retrieved-by 'nov))
10700       (if (eq gnus-fetch-old-headers 'invisible)
10701           (gnus-build-all-threads)
10702         (gnus-build-old-threads)))
10703     ;; Let the Gnus agent mark articles as read.
10704     (when gnus-agent
10705       (gnus-agent-get-undownloaded-list))
10706     ;; Remove list identifiers from subject
10707     (when gnus-list-identifiers
10708       (gnus-summary-remove-list-identifiers))
10709     ;; First and last article in this newsgroup.
10710     (when gnus-newsgroup-headers
10711       (setq gnus-newsgroup-begin
10712             (mail-header-number (car gnus-newsgroup-headers))
10713             gnus-newsgroup-end
10714             (mail-header-number
10715              (gnus-last-element gnus-newsgroup-headers))))
10716     (when gnus-use-scoring
10717       (gnus-possibly-score-headers))))
10718
10719 (defun gnus-summary-insert-old-articles (&optional all)
10720   "Insert all old articles in this group.
10721 If ALL is non-nil, already read articles become readable.
10722 If ALL is a number, fetch this number of articles."
10723   (interactive "P")
10724   (prog1
10725       (let ((old (mapcar 'car gnus-newsgroup-data))
10726             (i (car gnus-newsgroup-active))
10727             older len)
10728         (while (<= i (cdr gnus-newsgroup-active))
10729           (or (memq i old) (push i older))
10730           (incf i))
10731         (setq len (length older))
10732         (cond
10733          ((null older) nil)
10734          ((numberp all)
10735           (if (< all len)
10736               (setq older (subseq older 0 all))))
10737          (all nil)
10738          (t
10739           (if (and (numberp gnus-large-newsgroup)
10740                    (> len gnus-large-newsgroup))
10741               (let ((input
10742                      (read-string
10743                       (format
10744                        "How many articles from %s (default %d): "
10745                        (gnus-limit-string
10746                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
10747                        len))))
10748                 (unless (string-match "^[ \t]*$" input)
10749                   (setq all (string-to-number input))
10750                   (if (< all len)
10751                       (setq older (subseq older 0 all))))))))
10752         (if (not older)
10753             (message "No old news.")
10754           (gnus-summary-insert-articles older)
10755           (gnus-summary-limit (gnus-union older old))))
10756     (gnus-summary-position-point)))
10757
10758 (defun gnus-summary-insert-new-articles ()
10759   "Insert all new articles in this group."
10760   (interactive)
10761   (prog1
10762       (let ((old (mapcar 'car gnus-newsgroup-data))
10763             (old-active gnus-newsgroup-active)
10764             (nnmail-fetched-sources (list t))
10765             i new)
10766         (setq gnus-newsgroup-active
10767               (gnus-activate-group gnus-newsgroup-name 'scan))
10768         (setq i (1+ (cdr old-active)))
10769         (while (<= i (cdr gnus-newsgroup-active))
10770           (push i new)
10771           (incf i))
10772         (if (not new)
10773             (message "No gnus is bad news.")
10774           (setq new (nreverse new))
10775           (gnus-summary-insert-articles new)
10776           (setq gnus-newsgroup-unreads
10777                 (append gnus-newsgroup-unreads new))
10778           (gnus-summary-limit (gnus-union old new))))
10779     (gnus-summary-position-point)))
10780
10781 (gnus-summary-make-all-marking-commands)
10782
10783 (gnus-ems-redefine)
10784
10785 (provide 'gnus-sum)
10786
10787 (run-hooks 'gnus-sum-load-hook)
10788
10789 ;;; gnus-sum.el ends here